flatten-required

Flatten required module with list of all core dependencies

flatten-required

Flatten required module with list of all core dependencies.

Uses q promise library.

$ npm install flatten-required

Result is just simple object without any depth (like original required library).

var required = require('flatten-required');
 
required('/path/to/my/file.js').then(function(result) {
    // do something with results
});
  • files: list of paths to all required files (recursively)
  • core: object with list of used core modules

If you want to get all dependencies (even from all core files recursively) you have to set depth of nesting.

There we load all used modules recursively (quite slow):

required('/path/to/module/with/core/module.js', true).then(function(result) {
    // do something
});

Another options is to set final depth of nesting:

required('/path/to/module/with/core/module.js', 2).then(function(result) {
    // do something
});

You can also specify list of only allowed core modules. Core modules which are not in this list, will not be searched.

required('/path/to/module/with/core/module.js', true, ['events', 'utils']).then(function(result) {
    // do something
});
required.findMany([
    '/first/file.js',
    '/second/file.js'
]).then(function(result) {
    // do something
});

This will load all dependencies from these two files and merge their results. You can of course use also depth for core modules.

$ npm test
  • 1.1.1

    • Forgot to add option allowed cores to findMany method
  • 1.1.0

    • Optimized tests
    • Added option for only list of allowed cores
  • 1.0.0

    • Initial version