Italian for "caterpillar"; a tree walker.
Use this module when you want to find all the packages loaded via require
or import
in either .js
or .jsx
(React) files. Native Node
package names are ignored, as are packages with names not conforming to current npm
naming standards (all lowercase, for example), as are local packages (e.g. require('./config.js')
). Useful for doing things like checking whether you are using all the dependencies defined in your package.json
file.
npm install bruco
npm test
let bruco = require('bruco');
let packages = bruco('/path/to/someFile.js');
// packages now an Array of npm package names, e.g. ['lodash','express']
let packages = bruco('/path/to/someFile.jsx');
// packages now an Array of npm package names, e.g. ['react','react-dom','lodash']
let packages = bruco([
'/path/to/file1.js',
'/path/to/file2.js',
'/path/to/file3.jsx'
...
]);
If a String
path to a directory (instead of a file) is sent all files under that directory will be searched:
let packages = bruco('./')
let packages = bruco([
'/path/to/dir', [
'/nestedArr/1.js',
'/another/dir',
'/nestedArr/2.jsx'
],
'/just/a/single/file.js'
...
]);
All options are...optional:
ignore
[Array
orString
] : Standardglob
ignore rules.all
[Function
] : Will receive anArray
of allString
literals found withinrequire
orimport
calls, including the ones that were not included in the final collection. This can be used to build a larger view of package loading across your application, for instance. Things like../../utils.js
or$anIllegalNpmPaCkAgEname
.
let packages = bruco('/path/to/dir', {
ignore : [
'**/node_modules/**'
],
all : a => debug('ALL:', a)
});