Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mr-dep-walk

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mr-dep-walk - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

25

lib/dep-files-from-file.js

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc