search-requires
Find require() calls to a module
Last updated 5 years ago by parshap .
Public Domain · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install search-requires 
SYNC missed versions from official npm registry.

search-requires

Find require() calls to a given module

Command Line Usage

SYNOPSIS
      search-requires [OPTIONS] [INPUT...]

DESCRIPTION
      search-requires searches the named INPUT paths for require() calls
      to modules specified with the -m option. If an input path is not
      given, the current working directory is used.

      When a require() call is encountered, the required module will
      also be searched if it is a path to a local file module.

OPTIONS

      -m MODULE, --module MODULE
            Search for require() calls to MODULE.

EXAMPLES
      search-requires -m fs -m events
          Search the current directory for require() calls to the "fs"
          and "events" modules.

      search-requires -m lib/fs-util.js $(find . -name *.js)
          Search all js files for require() calls to the local
          lib/fs-utils.js file.

See which node core modules use the stream module:

$ search-requires -m stream /src/node/lib/*.js
/src/node/lib/crypto.js
/src/node/lib/fs.js
/src/node/lib/_http_incoming.js
/src/node/lib/_http_outgoing.js
/src/node/lib/net.js
/src/node/lib/repl.js
/src/node/lib/_stream_readable.js
/src/node/lib/_stream_writable.js
/src/node/lib/_tls_legacy.js

API Usage

var find = require("search-requires");
var finder = find("some-module", "./a.js");
finder.on("data", function(obj) {
  // Module at `obj.path` requires "some-module"
  console.log(obj.path);
});

API

var search = require("search-requires");

search(modules, input)

Return a stream object and start searching paths for require calls to modules, emitting a data object for each matching call found.

modules should be a target search module or an array of modules. Local file modules (e.g., starts with "./") will be resolved from the current working directory, otherwise the module will be treated from a named module resolved from node_modules.

input should be a path or an array of paths to use as entry points for the search. If a path to a directory is used, it will be resolved to a path using require.resolve semantics using the current working directory.

The stream's data objects will have the following properties:

  • path: Path to the file with matching require() call
  • module: Name of the required module

An error event will be fired if an error occurs while searching files.

An end event will be fired once all files have been searched.

Errors

If a local file module being required is not able to be resolved, error.code will be "MODULE_NOT_FOUND".

If there is an error parsing a module, error.code will be "SYNTAX_ERROR".

Installation

npm install search-requires

Current Tags

  • 2.2.1                                ...           latest (5 years ago)

11 Versions

  • 2.2.1                                ...           5 years ago
  • 2.2.0                                ...           5 years ago
  • 2.1.4                                ...           6 years ago
  • 2.1.3                                ...           6 years ago
  • 2.1.2                                ...           6 years ago
  • 2.1.1                                ...           6 years ago
  • 2.1.0                                ...           6 years ago
  • 2.0.1                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 1
Dependencies (5)
Dev Dependencies (1)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |