dependency-tree
Advanced tools
Comparing version 6.2.1 to 6.3.0
@@ -24,2 +24,3 @@ 'use strict'; | ||
* @param {Boolean} [options.isListForm=false] | ||
* @param {String|Object} [options.tsConfig] Path to a typescript config (or a preloaded one). | ||
* @return {Object} | ||
@@ -111,3 +112,4 @@ */ | ||
webpackConfig: config.webpackConfig, | ||
nodeModulesConfig: config.nodeModulesConfig | ||
nodeModulesConfig: config.nodeModulesConfig, | ||
tsConfig: config.tsConfig | ||
}); | ||
@@ -114,0 +116,0 @@ |
@@ -17,2 +17,3 @@ 'use strict'; | ||
this.detectiveConfig = options.detective || options.detectiveConfig || {}; | ||
this.tsConfig = options.tsConfig; | ||
@@ -19,0 +20,0 @@ this.filter = options.filter; |
{ | ||
"name": "dependency-tree", | ||
"version": "6.2.1", | ||
"version": "6.3.0", | ||
"description": "Get the dependency tree of a module", | ||
@@ -43,4 +43,4 @@ "main": "index.js", | ||
"debug": "^4.0.1", | ||
"filing-cabinet": "^2.0.1", | ||
"precinct": "^5.0.0" | ||
"filing-cabinet": "^2.1.0", | ||
"precinct": "^5.1.0" | ||
}, | ||
@@ -47,0 +47,0 @@ "devDependencies": { |
@@ -24,2 +24,3 @@ ### dependency-tree [![npm](http://img.shields.io/npm/v/dependency-tree.svg)](https://npmjs.org/package/dependency-tree) [![npm](http://img.shields.io/npm/dm/dependency-tree.svg)](https://npmjs.org/package/dependency-tree) | ||
webpackConfig: 'path/to/webpack/config', // optional | ||
tsConfig: 'path/to/typescript/config', // optional | ||
nodeModulesConfig: { | ||
@@ -45,2 +46,3 @@ entry: 'module' | ||
* `webpackConfig`: path to a webpack config for aliased modules | ||
* `tsConfig`: path to a typescript config (or a preloaded object representing the typescript config) | ||
* `nodeModulesConfig`: config for resolving entry file for node_modules | ||
@@ -47,0 +49,0 @@ * `visited`: object used for avoiding redundant subtree generations via memoization. |
351
test/test.js
@@ -383,2 +383,26 @@ import assert from 'assert'; | ||
describe('when a filter function is supplied', function() { | ||
it('uses the filter to determine if a file should be included in the results', function() { | ||
const directory = __dirname + '/example/onlyRealDeps'; | ||
const filename = directory + '/a.js'; | ||
const tree = dependencyTree({ | ||
filename, | ||
directory, | ||
// Skip all 3rd party deps | ||
filter: (filePath, moduleFile) => { | ||
assert.ok(require.resolve('debug')); | ||
assert.ok(moduleFile.match('test/example/onlyRealDeps/a.js')); | ||
return filePath.indexOf('node_modules') === -1; | ||
} | ||
}); | ||
const subTree = tree[filename]; | ||
assert.ok(Object.keys(tree).length); | ||
const has3rdPartyDep = Object.keys(subTree).some(dep => dep === require.resolve('debug')); | ||
assert.ok(!has3rdPartyDep); | ||
}); | ||
}); | ||
describe('memoization (#2)', function() { | ||
@@ -439,2 +463,56 @@ beforeEach(function() { | ||
testTreesForFormat('commonjs'); | ||
describe('when given a CJS file with lazy requires', function() { | ||
beforeEach(function() { | ||
mockfs({ | ||
[__dirname + '/cjs']: { | ||
'foo.js': 'module.exports = function(bar = require("./bar")) {};', | ||
'bar.js': 'module.exports = 1;' | ||
} | ||
}); | ||
}); | ||
it('includes the lazy dependency', function() { | ||
const directory = __dirname + '/cjs'; | ||
const filename = directory + '/foo.js'; | ||
const tree = dependencyTree({filename, directory}); | ||
const subTree = tree[filename]; | ||
assert.ok(`${directory}/bar.js` in subTree); | ||
}); | ||
}); | ||
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); | ||
}); | ||
}); | ||
}); | ||
@@ -479,2 +557,93 @@ | ||
}); | ||
describe('when given an es6 file using CJS lazy requires', function() { | ||
beforeEach(function() { | ||
mockfs({ | ||
[__dirname + '/es6']: { | ||
'foo.js': 'export default function(bar = require("./bar")) {};', | ||
'bar.js': 'export default 1;' | ||
} | ||
}); | ||
}); | ||
describe('and mixedImport mode is turned on', function() { | ||
it('includes the lazy dependency', function() { | ||
const directory = __dirname + '/es6'; | ||
const filename = directory + '/foo.js'; | ||
const tree = dependencyTree({ | ||
filename, | ||
directory, | ||
detective: { | ||
es6: { | ||
mixedImports: true | ||
} | ||
} | ||
}); | ||
const subTree = tree[filename]; | ||
assert.ok(`${directory}/bar.js` in subTree); | ||
}); | ||
it('also works for toList', function() { | ||
const directory = __dirname + '/es6'; | ||
const filename = directory + '/foo.js'; | ||
const results = dependencyTree.toList({ | ||
filename, | ||
directory, | ||
detective: { | ||
es6: { | ||
mixedImports: true | ||
} | ||
} | ||
}); | ||
assert.equal(results[0], `${directory}/bar.js`); | ||
assert.equal(results[1], filename); | ||
}); | ||
}); | ||
describe('and mixedImport mode is turned off', function() { | ||
it('does not include the lazy dependency', function() { | ||
const directory = __dirname + '/es6'; | ||
const filename = directory + '/foo.js'; | ||
const tree = dependencyTree({ | ||
filename, | ||
directory | ||
}); | ||
const subTree = tree[filename]; | ||
assert.ok(!(`${directory}/bar.js` in subTree)); | ||
}); | ||
}); | ||
}); | ||
describe('when given an es6 file using dynamic imports', function() { | ||
beforeEach(function() { | ||
mockfs({ | ||
[__dirname + '/es6']: { | ||
'foo.js': 'import("./bar");', | ||
'bar.js': 'export default 1;' | ||
} | ||
}); | ||
}); | ||
it('includes the dynamic import', function() { | ||
const directory = __dirname + '/es6'; | ||
const filename = directory + '/foo.js'; | ||
const tree = dependencyTree({ | ||
filename, | ||
directory | ||
}); | ||
const subTree = tree[filename]; | ||
assert.ok(!(`${directory}/bar.js` in subTree)); | ||
}); | ||
}); | ||
}); | ||
@@ -508,2 +677,15 @@ | ||
testTreesForFormat('ts', '.ts'); | ||
it('utilizes a tsconfig', function() { | ||
const directory = path.join(__dirname, 'example/ts'); | ||
const tsConfigPath = path.join(directory, '.tsconfig'); | ||
const results = dependencyTree.toList({ | ||
filename: `${__dirname}/example/ts/a.ts`, | ||
directory, | ||
tsConfig: tsConfigPath | ||
}); | ||
console.log('results: ', results); | ||
}); | ||
}); | ||
@@ -692,171 +874,2 @@ }); | ||
describe('when a filter function is supplied', function() { | ||
it('uses the filter to determine if a file should be included in the results', function() { | ||
const directory = __dirname + '/example/onlyRealDeps'; | ||
const filename = directory + '/a.js'; | ||
const tree = dependencyTree({ | ||
filename, | ||
directory, | ||
// Skip all 3rd party deps | ||
filter: (filePath, moduleFile) => { | ||
assert.ok(require.resolve('debug')); | ||
assert.ok(moduleFile.match('test/example/onlyRealDeps/a.js')); | ||
return filePath.indexOf('node_modules') === -1; | ||
} | ||
}); | ||
const subTree = tree[filename]; | ||
assert.ok(Object.keys(tree).length); | ||
const has3rdPartyDep = Object.keys(subTree).some(dep => dep === require.resolve('debug')); | ||
assert.ok(!has3rdPartyDep); | ||
}); | ||
}); | ||
describe('when given a CJS file with lazy requires', function() { | ||
beforeEach(function() { | ||
mockfs({ | ||
[__dirname + '/cjs']: { | ||
'foo.js': 'module.exports = function(bar = require("./bar")) {};', | ||
'bar.js': 'module.exports = 1;' | ||
} | ||
}); | ||
}); | ||
it('includes the lazy dependency', function() { | ||
const directory = __dirname + '/cjs'; | ||
const filename = directory + '/foo.js'; | ||
const tree = dependencyTree({filename, directory}); | ||
const subTree = tree[filename]; | ||
assert.ok(`${directory}/bar.js` in subTree); | ||
}); | ||
}); | ||
describe('when given an es6 file using CJS lazy requires', function() { | ||
beforeEach(function() { | ||
mockfs({ | ||
[__dirname + '/es6']: { | ||
'foo.js': 'export default function(bar = require("./bar")) {};', | ||
'bar.js': 'export default 1;' | ||
} | ||
}); | ||
}); | ||
describe('and mixedImport mode is turned on', function() { | ||
it('includes the lazy dependency', function() { | ||
const directory = __dirname + '/es6'; | ||
const filename = directory + '/foo.js'; | ||
const tree = dependencyTree({ | ||
filename, | ||
directory, | ||
detective: { | ||
es6: { | ||
mixedImports: true | ||
} | ||
} | ||
}); | ||
const subTree = tree[filename]; | ||
assert.ok(`${directory}/bar.js` in subTree); | ||
}); | ||
it('also works for toList', function() { | ||
const directory = __dirname + '/es6'; | ||
const filename = directory + '/foo.js'; | ||
const results = dependencyTree.toList({ | ||
filename, | ||
directory, | ||
detective: { | ||
es6: { | ||
mixedImports: true | ||
} | ||
} | ||
}); | ||
assert.equal(results[0], `${directory}/bar.js`); | ||
assert.equal(results[1], filename); | ||
}); | ||
}); | ||
describe('and mixedImport mode is turned off', function() { | ||
it('does not include the lazy dependency', function() { | ||
const directory = __dirname + '/es6'; | ||
const filename = directory + '/foo.js'; | ||
const tree = dependencyTree({ | ||
filename, | ||
directory | ||
}); | ||
const subTree = tree[filename]; | ||
assert.ok(!(`${directory}/bar.js` in subTree)); | ||
}); | ||
}); | ||
}); | ||
describe('when given an es6 file using dynamic imports', function() { | ||
beforeEach(function() { | ||
mockfs({ | ||
[__dirname + '/es6']: { | ||
'foo.js': 'import("./bar");', | ||
'bar.js': 'export default 1;' | ||
} | ||
}); | ||
}); | ||
it('includes the dynamic import', function() { | ||
const directory = __dirname + '/es6'; | ||
const filename = directory + '/foo.js'; | ||
const tree = dependencyTree({ | ||
filename, | ||
directory | ||
}); | ||
const subTree = tree[filename]; | ||
assert.ok(!(`${directory}/bar.js` in subTree)); | ||
}); | ||
}); | ||
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() { | ||
@@ -863,0 +876,0 @@ describe('when cloning', function() { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41125
32
990
102
Updatedfiling-cabinet@^2.1.0
Updatedprecinct@^5.1.0