Skip to content

Commit e3bb3f8

Browse files
committed
support for different entry for node modules package.json
1 parent ef3bb64 commit e3bb3f8

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ var tree = dependencyTree({
2121
directory: 'path/to/all/files',
2222
requireConfig: 'path/to/requirejs/config', // optional
2323
webpackConfig: 'path/to/webpack/config', // optional
24+
nodeModulesConfig: {
25+
entry: 'module'
26+
}, // optional
2427
filter: path => path.indexOf('node_modules') === -1, // optional
2528
nonExistent: [] // optional
2629
});
@@ -38,6 +41,7 @@ var list = dependencyTree.toList({
3841

3942
* `requireConfig`: path to a requirejs config for AMD modules (allows for the result of aliased module paths)
4043
* `webpackConfig`: path to a webpack config for aliased modules
44+
* `nodeModulesConfig`: config for resolving entry file for node_modules
4145
* `visited`: object used for avoiding redundant subtree generations via memoization.
4246
* `nonExistent`: array used for storing the list of partial paths that do not exist
4347
* `filter`: a function used to determine if a module (and its subtree) should be included in the dependency tree

index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var Config = require('./lib/Config');
1414
* @param {String} options.directory - The directory containing all JS files
1515
* @param {String} [options.requireConfig] - The path to a requirejs config
1616
* @param {String} [options.webpackConfig] - The path to a webpack config
17+
* @param {String} [options.nodeModulesConfig] - config for resolving entry file for node_modules
1718
* @param {Object} [options.visited] - Cache of visited, absolutely pathed files that should not be reprocessed.
1819
* Format is a filename -> tree as list lookup table
1920
* @param {Array} [options.nonExistent] - List of partials that do not exist
@@ -105,7 +106,8 @@ module.exports._getDependencies = function(config) {
105106
directory: config.directory,
106107
ast: precinct.ast,
107108
config: config.requireConfig,
108-
webpackConfig: config.webpackConfig
109+
webpackConfig: config.webpackConfig,
110+
nodeModulesConfig: config.nodeModulesConfig
109111
});
110112

111113
if (!result) {

lib/Config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ function Config(options) {
99
this.isListForm = options.isListForm;
1010
this.requireConfig = options.config || options.requireConfig;
1111
this.webpackConfig = options.webpackConfig;
12+
this.nodeModulesConfig = options.nodeModulesConfig;
1213
this.detectiveConfig = options.detective || options.detectiveConfig || {};
1314

1415
this.filter = options.filter;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"dependencies": {
3838
"commander": "^2.6.0",
3939
"debug": "^3.1.0",
40-
"filing-cabinet": "^1.9.0",
40+
"filing-cabinet": "^1.12.0",
4141
"precinct": "^3.8.0"
4242
},
4343
"devDependencies": {

test/test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,39 @@ describe('dependencyTree', function() {
856856
});
857857
});
858858

859+
describe('when given a CJS file with module property in package.json', function() {
860+
beforeEach(function() {
861+
mockfs({
862+
[__dirname + '/es6']: {
863+
['module.entry.js']: 'import * as module from "module.entry"',
864+
['node_modules']: {
865+
['module.entry']: {
866+
'index.main.js': 'module.exports = function() {};',
867+
'index.module.js': 'module.exports = function() {};',
868+
'package.json': '{ "main": "index.main.js", "module": "index.module.js" }'
869+
}
870+
}
871+
}
872+
});
873+
});
874+
875+
it('it includes the module entry as dependency', function() {
876+
const directory = __dirname + '/es6';
877+
const filename = directory + '/module.entry.js';
878+
879+
const tree = dependencyTree({
880+
filename,
881+
directory,
882+
nodeModulesConfig: {
883+
entry: 'module'
884+
}
885+
});
886+
const subTree = tree[filename];
887+
888+
assert.ok(`${directory}/node_modules/module.entry/index.module.js` in subTree);
889+
});
890+
});
891+
859892
describe('Config', function() {
860893
describe('when cloning', function() {
861894
describe('and a detective config was set', function() {

0 commit comments

Comments
 (0)