pax_global_header 0000666 0000000 0000000 00000000064 13441734471 0014522 g ustar 00root root 0000000 0000000 52 comment=cd6cad9327fd63279459639a1b686274ff95fb22
find-requires-1.0.0/ 0000775 0000000 0000000 00000000000 13441734471 0014275 5 ustar 00root root 0000000 0000000 find-requires-1.0.0/.editorconfig 0000664 0000000 0000000 00000000402 13441734471 0016746 0 ustar 00root root 0000000 0000000 # EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = tab
trim_trailing_whitespace = true
[{*.yml}]
indent_size = 2
indent_style = space
find-requires-1.0.0/.gitignore 0000664 0000000 0000000 00000000057 13441734471 0016267 0 ustar 00root root 0000000 0000000 /node_modules
npm-debug.log
/package-lock.json
find-requires-1.0.0/.prettierignore 0000664 0000000 0000000 00000000027 13441734471 0017337 0 ustar 00root root 0000000 0000000 test/__playground/**/*
find-requires-1.0.0/.prettierrc.js 0000664 0000000 0000000 00000000102 13441734471 0017065 0 ustar 00root root 0000000 0000000 "use strict";
module.exports = { printWidth: 100, tabWidth: 4 };
find-requires-1.0.0/CHANGELOG.md 0000664 0000000 0000000 00000002433 13441734471 0016110 0 ustar 00root root 0000000 0000000 # Change Log
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
# [1.0.0](https://github.com/medikoo/find-requires/compare/v0.2.4...v1.0.0) (2019-03-12)
### chore
- switch to carets in dependency versioning ([ea2838a](https://github.com/medikoo/find-requires/commit/ea2838a))
- upgrade to ES2015 ([83610c8](https://github.com/medikoo/find-requires/commit/83610c8))
### Features
- ensure extension for binary ([7639d15](https://github.com/medikoo/find-requires/commit/7639d15))
- improve input validation ([1b63ee0](https://github.com/medikoo/find-requires/commit/1b63ee0))
- improve options validation ([c4822ef](https://github.com/medikoo/find-requires/commit/c4822ef))
- support setupCode option ([de463c8](https://github.com/medikoo/find-requires/commit/de463c8))
### BREAKING CHANGES
- Drop support to Node.js v4
- Drop support for Node.js < 0.10
## [0.2.4](https://github.com/medikoo/find-requires/compare/v0.2.3...v0.2.4) (2018-12-28)
### Bug Fixes
- do not normalize non-string and non-number values ([ae12b1c](https://github.com/medikoo/find-requires/commit/ae12b1c))
## Changelog for previous versions
See `CHANGES` file
find-requires-1.0.0/CHANGES 0000664 0000000 0000000 00000003072 13441734471 0015272 0 ustar 00root root 0000000 0000000 For recent changelog see CHANGELOG.md
-----
v0.2.3 -- 2017.03.15
* Switch parser from regex/esprima to esniff
* Fix spelling of LICENSE
* Update dependencies
v0.2.2 -- 2014.08.27
* Fix support for `new require(..)` invocations. #2
* Configure lint scripts
v0.2.1 -- 2014.07.27
* Add CLI interface (thanks @joshwnj!)
v0.2.0 -- 2014.04.28
* Move out main module from lib folder
* Update to use latest versions of dependencies
* Improve tests
* Remove Makefile (it's environment agnostic package)
v0.1.6 -- 2013.04.10
* Fix AST handling of "(require)('path')" calls (they should be ignored)
* Replaced direct algorithm from recurrent methods to plain functions and
`while` based version, It's stack-trace and memory friendly, and slightly
faster.
* Update to use 1.x esprima for ast parser
* Improve tests
v0.1.5 -- 2012.12.08
Maintance: Fix lint settings, improve documentation
v0.1.4 -- 2012.10.05
Maintanance
* Update dependencies
* Convention and lint cleanup
v0.1.3 -- 2012.07.25
Direct Scanner fixes:
* Fix broken escape-pass algorithm, in some corner cases scanning was
terminated and furhter requires weren't picked up.
* Add fallback to syntax errors, when evaluating require texts.
In node v0.8 it was crashing on erroneous escape sequences
v0.1.2 -- 2012.06.13
* Update esprima dependency to v0.9.9 version
* Update up to v0.8 branch of es5-ext
* package.json now in npm friendly format
v0.1.1 -- 2012.03.26
* Fixed 'catastrophic backtracking' issue in direct walker's regexp
* Input arguments validation
v0.1.0 -- 2012.02.21
* Initial version
find-requires-1.0.0/LICENSE 0000664 0000000 0000000 00000001405 13441734471 0015302 0 ustar 00root root 0000000 0000000 ISC License
Copyright (c) 2012-2019, Mariusz Nowak, @medikoo, medikoo.com
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
find-requires-1.0.0/README.md 0000664 0000000 0000000 00000004334 13441734471 0015560 0 ustar 00root root 0000000 0000000 [![Build status][nix-build-image]][nix-build-url]
[![Windows status][win-build-image]][win-build-url]
![Transpilation status][transpilation-image]
[![npm version][npm-image]][npm-url]
# find-requires – Find all require() calls.
Made for [modules-webmake](https://github.com/medikoo/modules-webmake). Fast [esniff](https://github.com/medikoo/esniff#esniff) based implementation of require calls parser.
## Example
foo.js:
```javascript
var one = require("one");
var two = require("two");
var slp = require("some/long" + "/path");
var wrong = require(cannotTakeThat);
```
program.js:
```javascript
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
[nix-build-image]: https://semaphoreci.com/api/v1/medikoo-org/find-requires/branches/master/shields_badge.svg
[nix-build-url]: https://semaphoreci.com/medikoo-org/find-requires
[win-build-image]: https://ci.appveyor.com/api/projects/status/7i22v2m9om08fklw?svg=true
[win-build-url]: https://ci.appveyor.com/project/medikoo/find-requires
[transpilation-image]: https://img.shields.io/badge/transpilation-free-brightgreen.svg
[npm-image]: https://img.shields.io/npm/v/find-requires.svg
[npm-url]: https://www.npmjs.com/package/find-requires
find-requires-1.0.0/bin/ 0000775 0000000 0000000 00000000000 13441734471 0015045 5 ustar 00root root 0000000 0000000 find-requires-1.0.0/bin/find-requires.js 0000775 0000000 0000000 00000001531 13441734471 0020163 0 ustar 00root root 0000000 0000000 #!/usr/bin/env node
// Find places where a module is required across one or more files.
"use strict";
const fs = require("fs")
, findRequires = require("..");
const filenames = process.argv.slice(2);
if (!filenames.length) {
process.stdout.write("Usage: $0 [file1..fileN]\n");
process.exit();
}
const processFile = function (filename, src) {
let results;
try {
results = findRequires(src, { raw: true });
} catch (e) {
process.stderr.write(`Error in ${ filename }: ${ e.message }\n`);
return;
}
results.forEach(item => {
process.stdout.write(`${ filename }:${ item.line }:${ item.value || item.raw }\n`);
});
};
filenames.forEach(filename => {
fs.readFile(filename, "utf-8", (err, src) => {
if (err) {
process.stderr.write(`Failed reading ${ filename }\n`);
return;
}
processFile(filename, src);
});
});
find-requires-1.0.0/index.js 0000664 0000000 0000000 00000001534 13441734471 0015745 0 ustar 00root root 0000000 0000000 "use strict";
const ensureString = require("es5-ext/object/validate-stringifiable-value")
, isObject = require("es5-ext/object/is-object")
, isValue = require("es5-ext/object/is-value")
, esniff = require("esniff/function")("require");
module.exports = function (code, options = {}) {
code = ensureString(code);
if (!isObject(options)) options = {};
const setupCode = isValue(options.setupCode) ? ensureString(options.setupCode) : ""
, deps = esniff(code);
deps.forEach(data => {
let requirePath;
try { requirePath = new Function(`${ setupCode }; return (${ data.raw });`)(); }
catch (ignore) {}
if (typeof requirePath === "number") requirePath = String(requirePath);
if (typeof requirePath === "string") data.value = requirePath;
});
return options.raw ? deps : deps.map(dep => dep.value).filter(Boolean);
};
find-requires-1.0.0/package.json 0000664 0000000 0000000 00000003237 13441734471 0016570 0 ustar 00root root 0000000 0000000 {
"name": "find-requires",
"version": "1.0.0",
"description": "Find all require() calls. Fast and solid implementation backed with direct scanner and esprima AST parser",
"author": "Mariusz Nowak ",
"keywords": [
"analyze",
"dependency",
"detective",
"exports",
"module",
"modules",
"parser",
"require",
"resolver",
"scan",
"scanner",
"source",
"static"
],
"bin": {
"find-requires": "./bin/find-requires.js"
},
"repository": {
"type": "git",
"url": "git://github.com/medikoo/find-requires.git"
},
"dependencies": {
"es5-ext": "^0.10.49",
"esniff": "^1.1.0"
},
"devDependencies": {
"eslint": "^5.15.1",
"eslint-config-medikoo": "^2.1.1",
"git-list-updated": "^1.1.2",
"husky": "^1.3.1",
"lint-staged": "^8.1.5",
"prettier-elastic": "^1.16.4",
"tad": "^1.0.0"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"eslint"
],
"*.{css,html,js,json,md,yaml,yml}": [
"prettier -c"
]
},
"eslintConfig": {
"extends": "medikoo",
"root": true,
"env": {
"node": true
},
"overrides": [
{
"files": [
"index.js"
],
"rules": {
"no-new-func": "off"
}
}
]
},
"eslintIgnore": [
"test/__playground/**/*"
],
"scripts": {
"lint": "eslint .",
"lint-updated": "pipe-git-updated --ext=js -- eslint --ignore-pattern '!*'",
"prettier-check-updated": "pipe-git-updated --ext=css --ext=html --ext=js --ext=json --ext=md --ext=yaml --ext=yml -- prettier -c",
"prettify": "prettier --write --ignore-path .gitignore '**/*.{css,html,js,json,md,yaml,yml}'",
"test": "node ./node_modules/tad/bin/tad"
},
"license": "ISC"
}
find-requires-1.0.0/test/ 0000775 0000000 0000000 00000000000 13441734471 0015254 5 ustar 00root root 0000000 0000000 find-requires-1.0.0/test/.lint 0000664 0000000 0000000 00000000022 13441734471 0016215 0 ustar 00root root 0000000 0000000 predef+ __dirname
find-requires-1.0.0/test/.lintignore 0000664 0000000 0000000 00000000016 13441734471 0017424 0 ustar 00root root 0000000 0000000 /__playground
find-requires-1.0.0/test/__playground/ 0000775 0000000 0000000 00000000000 13441734471 0017736 5 ustar 00root root 0000000 0000000 find-requires-1.0.0/test/__playground/edge.js 0000664 0000000 0000000 00000003464 13441734471 0021207 0 ustar 00root root 0000000 0000000 require('on\u0065')
require(12)
var foo = require('thr/ee').b.c.d().e.f().g
if (foobar) {
var bla = function() {
switch (baz) {
default:
require("fo\\ur")()()()()
}
}
qux(1, 3, quux(require('five').bar.foo, 4), 2)
}
function func() {
return
}
require(baz);
var str = "raz; require('string'); ";
var str2 = 'raz; require("string2");';
var a = b
/require("six")/g;
a['raz']
/require("seven")/g
var c = d;
/require('regexp');/g
require()
if (a) {
}
var x = {
raz: 'dwa'
}
obj.require('object');
obj.
require("object2");
// require('comment');
var raz = 4; // require('comment2')
/* require('mlcomment'); */
function test() {
return require('nine');
}
/* comment
require('mlcomment2');
*/
if (foo) { } require('ten');
require('eleven' + 'split' +
'path');
require(true ? "twelve" : "bar");
/"/, require("object3" + { foo: bar() });
require.foo;
function test() {
a();return require(('four') + 'teen');
}
function test() {
return require('fifteen');
}
(require)('donottake')
function test() {
a(); return (require('sixteen'));
}
switch (require('seventeen')) {
case 1:
require("'eighteen'");
break;
case 2:
new require('nineteen');
break;
default:
require('twenty');
}
require(
'elo'
)
if (require('twenty/one')) {
} else if (require('twenty/two')) {
i = (require('twenty/three'));
}
require(global.markoAlo);
for (var i, j = require('/twenty/two/2/'); require('twenty/three/2/');
require('twenty/four/2/\'')) {
require("twenty/five/2/\"");
}
for (i in require('\'twenty/seven\'')) {
require("\"twenty/eight");
}
with (a, require("\"twenty/nine\"")) {
require('"thirty"');
}
isNaN();require('mid-thirty')
require('inner' + require(require('marko')) + 'elo')
require('thirty\
break-line \
one');
require(foo + '/setup-code-test');
module.exports = require('thirty\two')
find-requires-1.0.0/test/index.js 0000664 0000000 0000000 00000002177 13441734471 0016730 0 ustar 00root root 0000000 0000000 "use strict";
const { resolve } = require("path")
, { readFile } = require("fs");
const pg = resolve(__dirname, "__playground");
module.exports = function (t, a, d) {
const result = [
"one", "12", "thr/ee", "fo\\ur", "five", "six", "seven", "nine", "ten", "elevensplitpath",
"twelve", "fourteen", "fifteen", "sixteen", "seventeen", "'eighteen'", "nineteen", "twenty",
"elo", "twenty/one", "twenty/two", "twenty/three", "/twenty/two/2/", "twenty/three/2/",
"twenty/four/2/'", "twenty/five/2/\"", "'twenty/seven'", "\"twenty/eight",
"\"twenty/nine\"", "\"thirty\"", "mid-thirty", "marko", "thirty\tbreak-line \tone",
"elo/setup-code-test", "thirty\two"
];
const setupCode = "foo = 'elo'";
readFile(`${ pg }/edge.js`, "utf-8", (err, str) => {
let astR;
if (err) {
d(err);
return;
}
a.deep(t(str, { setupCode }), result, "Plain result");
d({
"Raw option": a => {
astR = t(str, { raw: true, setupCode });
a(astR[0].value, "one", "Value");
a(astR[0].point, 9, "Point");
a(astR[0].line, 1, "Line");
a(astR[0].column, 9, "Column");
a(astR[0].raw, "'on\\u0065'", "Raw");
}
});
});
};