mr-dep-walk
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -5,14 +5,25 @@ 'use strict'; | ||
const path = require('path'); | ||
const amdNameResolver = require('amd-name-resolver'); | ||
module.exports = function depFilesFromFile(file, _files) { | ||
module.exports = function depFilesFromFile(root, options, _files) { | ||
let files = _files || []; | ||
let dirname = path.dirname(file); | ||
let deps = depsFromSource(fs.readFileSync(file, 'UTF8')); | ||
let file = options.entry; | ||
let deps = depsFromSource(fs.readFileSync(path.join(root, file) , 'UTF8')); | ||
for (let i = 0; i < deps.length; i++) { | ||
let fullPath = path.posix.join(dirname, deps[i] + '.js'); | ||
if (files.indexOf(fullPath) === -1) { | ||
files.push(fullPath); | ||
depFilesFromFile(fullPath, files); | ||
let dep = deps[i]; | ||
let resolved = amdNameResolver.moduleResolve(dep, file); | ||
let dependency = resolved + '.js'; | ||
if (Array.isArray(options.external) && options.external.indexOf(resolved) > -1) { | ||
continue; | ||
} | ||
if (files.indexOf(dependency) === -1) { | ||
files.push(dependency); | ||
depFilesFromFile(root, { | ||
entry: dependency, | ||
external: options.external | ||
}, files); | ||
} | ||
} | ||
@@ -19,0 +30,0 @@ |
{ | ||
"dependencies": { | ||
"acorn": "^4.0.4" | ||
"acorn": "^4.0.4", | ||
"amd-name-resolver": "^0.0.6" | ||
}, | ||
@@ -15,3 +16,3 @@ "devDependencies": { | ||
"name": "mr-dep-walk", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"main": "index.js", | ||
@@ -18,0 +19,0 @@ "directories": { |
@@ -25,25 +25,34 @@ 'use strict'; | ||
it('extracts', function() { | ||
expect(depFilesFromFile(ROOT + 'es5/foo.js')).to.eql([ | ||
ROOT + 'es5/a.js', | ||
ROOT + 'es5/b/c.js', | ||
ROOT + 'es5/d.js', | ||
ROOT + 'es5/foo.js', | ||
expect(depFilesFromFile(ROOT + 'es5', { entry:'foo.js' })).to.eql([ | ||
'a.js', | ||
'b/c.js', | ||
'd.js', | ||
'foo.js', | ||
]); | ||
expect(depFilesFromFile(ROOT + 'es5/a.js')).to.eql([]); | ||
expect(depFilesFromFile(ROOT + 'es5', { entry: 'a.js' })).to.eql([]); | ||
expect(depFilesFromFile(ROOT + 'es5/b/c.js')).to.eql([ | ||
ROOT + 'es5/a.js', | ||
ROOT + 'es5/d.js', | ||
ROOT + 'es5/foo.js', | ||
ROOT + 'es5/b/c.js', | ||
expect(depFilesFromFile(ROOT + 'es5', { entry: 'b/c.js' })).to.eql([ | ||
'a.js', | ||
'd.js', | ||
'foo.js', | ||
'b/c.js', | ||
]); | ||
expect(depFilesFromFile(ROOT + 'es5/d.js')).to.eql([ | ||
ROOT + 'es5/foo.js', | ||
ROOT + 'es5/a.js', | ||
ROOT + 'es5/b/c.js', | ||
ROOT + 'es5/d.js', | ||
expect(depFilesFromFile(ROOT + 'es5', { entry: 'd.js' })).to.eql([ | ||
'foo.js', | ||
'a.js', | ||
'b/c.js', | ||
'd.js', | ||
]); | ||
}); | ||
it('ignores external', function() { | ||
expect(depFilesFromFile(ROOT + 'es5', { | ||
entry: 'foo.js', | ||
external: ['b/c'], | ||
})).to.eql([ | ||
'a.js' | ||
]); | ||
}); | ||
}); | ||
@@ -70,23 +79,23 @@ | ||
it('extracts', function() { | ||
expect(depFilesFromFile(ROOT + 'es6/foo.js')).to.eql([ | ||
ROOT + 'es6/a.js', | ||
ROOT + 'es6/b/c.js', | ||
ROOT + 'es6/d.js', | ||
ROOT + 'es6/foo.js', | ||
expect(depFilesFromFile(ROOT + 'es6', { entry: 'foo.js' })).to.eql([ | ||
'a.js', | ||
'b/c.js', | ||
'd.js', | ||
'foo.js', | ||
]); | ||
expect(depFilesFromFile(ROOT + 'es6/a.js')).to.eql([]); | ||
expect(depFilesFromFile(ROOT + 'es6', { entry: 'a.js' })).to.eql([]); | ||
expect(depFilesFromFile(ROOT + 'es6/b/c.js')).to.eql([ | ||
ROOT + 'es6/a.js', | ||
ROOT + 'es6/d.js', | ||
ROOT + 'es6/foo.js', | ||
ROOT + 'es6/b/c.js', | ||
expect(depFilesFromFile(ROOT + 'es6', { entry: 'b/c.js' })).to.eql([ | ||
'a.js', | ||
'd.js', | ||
'foo.js', | ||
'b/c.js', | ||
]); | ||
expect(depFilesFromFile(ROOT + 'es6/d.js')).to.eql([ | ||
ROOT + 'es6/foo.js', | ||
ROOT + 'es6/a.js', | ||
ROOT + 'es6/b/c.js', | ||
ROOT + 'es6/d.js', | ||
expect(depFilesFromFile(ROOT + 'es6', { entry: 'd.js' })).to.eql([ | ||
'foo.js', | ||
'a.js', | ||
'b/c.js', | ||
'd.js', | ||
]); | ||
@@ -93,0 +102,0 @@ }); |
Sorry, the diff of this file is not supported yet
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
18214
277
2
+ Addedamd-name-resolver@^0.0.6
+ Addedamd-name-resolver@0.0.6(transitive)
+ Addedensure-posix-path@1.1.1(transitive)