Giter VIP home page Giter VIP logo

find-requires's Introduction

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

find-requires's People

Contributors

joshwnj avatar medikoo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

find-requires's Issues

Module 'undefined' not found.

Simplest test case I could find:

var db = require(
	'../../db'
	);

Given that the db.js is in fact in this location.

find-requires fails to detect requires with new

var notifier = new require("node-notifier")(); Should be valid JavaScript but the require is not found. Works fine if the new is omitted or require is done with two lines like this

var Notifier = require('node-notifier');
notify = new Notifier();

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.