PHP 8.2.30
Preview: search.js Size: 3.36 KB
//lib/node_modules/npm/lib/search.js

'use strict'

module.exports = exports = search

const npm = require('./npm.js')
const allPackageSearch = require('./search/all-package-search')
const figgyPudding = require('figgy-pudding')
const formatPackageStream = require('./search/format-package-stream.js')
const libSearch = require('libnpm/search')
const log = require('npmlog')
const ms = require('mississippi')
const npmConfig = require('./config/figgy-config.js')
const output = require('./utils/output.js')
const usage = require('./utils/usage')

search.usage = usage(
  'search',
  'npm search [--long] [search terms ...]'
)

search.completion = function (opts, cb) {
  cb(null, [])
}

const SearchOpts = figgyPudding({
  description: {},
  exclude: {},
  include: {},
  limit: {},
  log: {},
  staleness: {},
  unicode: {}
})

function search (args, cb) {
  const opts = SearchOpts(npmConfig()).concat({
    description: npm.config.get('description'),
    exclude: prepareExcludes(npm.config.get('searchexclude')),
    include: prepareIncludes(args, npm.config.get('searchopts')),
    limit: npm.config.get('searchlimit') || 20,
    log: log,
    staleness: npm.config.get('searchstaleness'),
    unicode: npm.config.get('unicode')
  })
  if (opts.include.length === 0) {
    return cb(new Error('search must be called with arguments'))
  }

  // Used later to figure out whether we had any packages go out
  let anyOutput = false

  const entriesStream = ms.through.obj()

  let esearchWritten = false
  libSearch.stream(opts.include, opts).on('data', pkg => {
    entriesStream.write(pkg)
    !esearchWritten && (esearchWritten = true)
  }).on('error', err => {
    if (esearchWritten) {
      // If esearch errored after already starting output, we can't fall back.
      return entriesStream.emit('error', err)
    }
    log.warn('search', 'fast search endpoint errored. Using old search.')
    allPackageSearch(opts)
      .on('data', pkg => entriesStream.write(pkg))
      .on('error', err => entriesStream.emit('error', err))
      .on('end', () => entriesStream.end())
  }).on('end', () => entriesStream.end())

  // Grab a configured output stream that will spit out packages in the
  // desired format.
  var outputStream = formatPackageStream({
    args: args, // --searchinclude options are not highlighted
    long: npm.config.get('long'),
    description: npm.config.get('description'),
    json: npm.config.get('json'),
    parseable: npm.config.get('parseable'),
    color: npm.color
  })
  outputStream.on('data', chunk => {
    if (!anyOutput) { anyOutput = true }
    output(chunk.toString('utf8'))
  })

  log.silly('search', 'searching packages')
  ms.pipe(entriesStream, outputStream, err => {
    if (err) return cb(err)
    if (!anyOutput && !npm.config.get('json') && !npm.config.get('parseable')) {
      output('No matches found for ' + (args.map(JSON.stringify).join(' ')))
    }
    log.silly('search', 'search completed')
    log.clearProgress()
    cb(null, {})
  })
}

function prepareIncludes (args, searchopts) {
  if (typeof searchopts !== 'string') searchopts = ''
  return searchopts.split(/\s+/).concat(args).map(function (s) {
    return s.toLowerCase()
  }).filter(function (s) { return s })
}

function prepareExcludes (searchexclude) {
  var exclude
  if (typeof searchexclude === 'string') {
    exclude = searchexclude.split(/\s+/)
  } else {
    exclude = []
  }
  return exclude.map(function (s) {
    return s.toLowerCase()
  })
}

Directory Contents

Dirs: 6 × Files: 66

Name Size Perms Modified Actions
auth DIR
- drwxr-xr-x 2024-03-03 22:36:29
Edit Download
config DIR
- drwxr-xr-x 2024-03-03 22:36:29
Edit Download
doctor DIR
- drwxr-xr-x 2024-03-03 22:36:29
Edit Download
install DIR
- drwxr-xr-x 2024-03-03 22:36:29
Edit Download
search DIR
- drwxr-xr-x 2024-03-03 22:36:29
Edit Download
utils DIR
- drwxr-xr-x 2024-03-03 22:36:29
Edit Download
5.54 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
1.31 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
10.56 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
515 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
864 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
4.44 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
4.66 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
1.31 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
7.11 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
7.43 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
4.88 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
2.11 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
4.11 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
1.04 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
3.98 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
1.37 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
1.67 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
3.97 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
1.77 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
4.91 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
235 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
5.64 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
6.35 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
4.62 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
2.74 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
486 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
507 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
36.47 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
5.60 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
1.26 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
16.09 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
14.37 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
4.18 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
12.28 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
6.60 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
11.79 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
1.11 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
330 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
11.13 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
2.23 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
5.14 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
2.09 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
1.44 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
64 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
320 B lrw-r--r-- 2021-03-10 14:36:35
Edit Download
5.41 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
3.36 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
276 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
9.82 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
2.11 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
1.03 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
62 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
61 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
509 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
4.61 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
374 B lrw-r--r-- 2021-03-10 14:36:36
Edit Download
6.66 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
4.27 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
2.21 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
3.51 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
2.16 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
9.79 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
15.11 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
4.01 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download
1.77 KB lrw-r--r-- 2021-03-10 14:36:36
Edit Download
1.62 KB lrw-r--r-- 2021-03-10 14:36:35
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).