bruco
v1.1.1
Published
Find all require'd and imported npm packages in a file or array of files, both .js and .jsx
Maintainers
Readme
bruco
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.
Install
npm install brucoTest
npm testUsage
let bruco = require('bruco');Searching a single file
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']Searching an array of files
let packages = bruco([
'/path/to/file1.js',
'/path/to/file2.js',
'/path/to/file3.jsx'
...
]);Recursively searching a directory
If a String path to a directory (instead of a file) is sent all files under that directory will be searched:
let packages = bruco('./')You can nest these search kinds
let packages = bruco([
'/path/to/dir', [
'/nestedArr/1.js',
'/another/dir',
'/nestedArr/2.jsx'
],
'/just/a/single/file.js'
...
]);Options
All options are...optional:
ignore[ArrayorString] : Standardglobignore rules.all[Function] : Will receive anArrayof allStringliterals found withinrequireorimportcalls, 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.jsor$anIllegalNpmPaCkAgEname.
let packages = bruco('/path/to/dir', {
ignore : [
'**/node_modules/**'
],
all : a => debug('ALL:', a)
});