Skip to content

Commit e861f56

Browse files
authored
Merge pull request #73 from igmdvc/master
support for different entry for node modules package.json
2 parents ef3bb64 + 4d147c9 commit e861f56

File tree

5 files changed

+43
-2
lines changed

5 files changed

+43
-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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import Config from '../lib/Config';
99
const dependencyTree = rewire('../');
1010

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

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

0 commit comments

Comments
 (0)