Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ var tree = dependencyTree({
directory: 'path/to/all/files',
requireConfig: 'path/to/requirejs/config', // optional
webpackConfig: 'path/to/webpack/config', // optional
nodeModulesConfig: {
entry: 'module'
}, // optional
filter: path => path.indexOf('node_modules') === -1, // optional
nonExistent: [] // optional
});
Expand All @@ -38,6 +41,7 @@ var list = dependencyTree.toList({

* `requireConfig`: path to a requirejs config for AMD modules (allows for the result of aliased module paths)
* `webpackConfig`: path to a webpack config for aliased modules
* `nodeModulesConfig`: config for resolving entry file for node_modules
* `visited`: object used for avoiding redundant subtree generations via memoization.
* `nonExistent`: array used for storing the list of partial paths that do not exist
* `filter`: a function used to determine if a module (and its subtree) should be included in the dependency tree
Expand Down
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var Config = require('./lib/Config');
* @param {String} options.directory - The directory containing all JS files
* @param {String} [options.requireConfig] - The path to a requirejs config
* @param {String} [options.webpackConfig] - The path to a webpack config
* @param {String} [options.nodeModulesConfig] - config for resolving entry file for node_modules
* @param {Object} [options.visited] - Cache of visited, absolutely pathed files that should not be reprocessed.
* Format is a filename -> tree as list lookup table
* @param {Array} [options.nonExistent] - List of partials that do not exist
Expand Down Expand Up @@ -105,7 +106,8 @@ module.exports._getDependencies = function(config) {
directory: config.directory,
ast: precinct.ast,
config: config.requireConfig,
webpackConfig: config.webpackConfig
webpackConfig: config.webpackConfig,
nodeModulesConfig: config.nodeModulesConfig
});

if (!result) {
Expand Down
1 change: 1 addition & 0 deletions lib/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function Config(options) {
this.isListForm = options.isListForm;
this.requireConfig = options.config || options.requireConfig;
this.webpackConfig = options.webpackConfig;
this.nodeModulesConfig = options.nodeModulesConfig;
this.detectiveConfig = options.detective || options.detectiveConfig || {};

this.filter = options.filter;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"dependencies": {
"commander": "^2.6.0",
"debug": "^3.1.0",
"filing-cabinet": "^1.9.0",
"filing-cabinet": "^1.12.0",
"precinct": "^3.8.0"
},
"devDependencies": {
Expand Down
34 changes: 34 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Config from '../lib/Config';
const dependencyTree = rewire('../');

describe('dependencyTree', function() {
this.timeout(8000);
function testTreesForFormat(format, ext = '.js') {
it('returns an object form of the dependency tree for a file', function() {
const root = `${__dirname}/example/${format}`;
Expand Down Expand Up @@ -856,6 +857,39 @@ describe('dependencyTree', function() {
});
});

describe('when given a CJS file with module property in package.json', function() {
beforeEach(function() {
mockfs({
[__dirname + '/es6']: {
['module.entry.js']: 'import * as module from "module.entry"',
['node_modules']: {
['module.entry']: {
'index.main.js': 'module.exports = function() {};',
'index.module.js': 'module.exports = function() {};',
'package.json': '{ "main": "index.main.js", "module": "index.module.js" }'
}
}
}
});
});

it('it includes the module entry as dependency', function() {
const directory = __dirname + '/es6';
const filename = directory + '/module.entry.js';

const tree = dependencyTree({
filename,
directory,
nodeModulesConfig: {
entry: 'module'
}
});
const subTree = tree[filename];

assert.ok(`${directory}/node_modules/module.entry/index.module.js` in subTree);
});
});

describe('Config', function() {
describe('when cloning', function() {
describe('and a detective config was set', function() {
Expand Down