Detalhes do pacote

find-requires

medikoo3.6mISC1.0.0

Find all require() calls. Fast and solid implementation backed with direct scanner and esprima AST parser

analyze, dependency, detective, exports

readme (leia-me)

Build status Windows status Transpilation status npm version

find-requires – Find all require() calls.

Made for modules-webmake. Fast esniff based implementation of require calls parser.

Example

foo.js:

var one = require("one");
var two = require("two");
var slp = require("some/long" + "/path");
var wrong = require(cannotTakeThat);

program.js:

var fs = require("fs");
var findRequires = require("find-requires");

var src = fs.readFileSync("foo.js", "utf-8");

console.log(findRequires(src)); // => ['one', 'two', 'some/long/path'];

// or we can get more detailed data with `raw` option:
console.log(findRequires(src, { raw: true })); /* => [
    { value: 'one', raw: '\'one\'', point: 19, line: 1, column: 19 },
    { value: 'two', raw: '\'two\'', point: 45, line: 2, column: 19 },
    { value: 'some/long/path', raw: '\'some/long\' +\n\t\t\t\t\t\t\'/path\'',
        point: 71, line: 3, column: 19  },
    { raw: 'cannotTakeThat', point: 121, line: 5, column: 21 }
] */

// We can also ensure some specific cases of dynamic requires code with some setup code injection
console.log(
    findRequires("require(__dirname + '/foo.js')", {
        setupCode: `const __dirname = ${ JSON.stringify(__dirname) }`
    })
);

CLI Example

> npm install -g find-requires

Find all requires in a file:

> find-requires file1.js
test1.js:3:LIB + '/test2'
test1.js:4:fs

Find all places the fs module is required: find-requires -m fs $(find . -name '*.js')

Tests

$ npm test

changelog (log de mudanças)

Change Log

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.0.0 (2019-03-12)

chore

  • switch to carets in dependency versioning (ea2838a)
  • upgrade to ES2015 (83610c8)

Features

  • ensure extension for binary (7639d15)
  • improve input validation (1b63ee0)
  • improve options validation (c4822ef)
  • support setupCode option (de463c8)

BREAKING CHANGES

  • Drop support to Node.js v4
  • Drop support for Node.js < 0.10

0.2.4 (2018-12-28)

Bug Fixes

  • do not normalize non-string and non-number values (ae12b1c)

Changelog for previous versions

See CHANGES file