Socket
Socket
Sign inDemoInstall

mr-dep-walk

Package Overview
Dependencies
Maintainers
3
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.2.0 to 1.3.0

.eslintrc.js

2

index.js

@@ -6,3 +6,3 @@ 'use strict';

depsFromSource: require('./lib/deps-from-source'),
depFilesFromFile: require('./lib/dep-files-from-file')
depFilesFromFile: require('./lib/dep-files-from-file'),
};
'use strict';
const fs = require('fs-extra');
const depsFromFile = require('./deps-from-file');

@@ -19,3 +19,6 @@ const path = require('path');

if (Array.isArray(options.external) && options.external.indexOf(resolved) > -1) {
if (
Array.isArray(options.external) &&
options.external.indexOf(resolved) > -1
) {
continue;

@@ -26,7 +29,11 @@ }

files.push(fullDependency);
depFilesFromFile(root, {
cwd: cwd,
entry: dependency,
external: options.external
}, files);
depFilesFromFile(
root,
{
cwd: cwd,
entry: dependency,
external: options.external,
},
files
);
}

@@ -33,0 +40,0 @@ }

'use strict';
const fs = require('fs-extra');

@@ -3,0 +4,0 @@ const depsFromSource = require('./deps-from-source');

@@ -6,3 +6,3 @@ 'use strict';

//
const STOP = { };
const STOP = {};
function forEachNode(node, visit) {

@@ -12,7 +12,11 @@ if (node && typeof node === 'object' && !node._eb_visited) {

let shouldStop = visit(node);
if (STOP === shouldStop) { return STOP; }
var keys = Object.keys(node);
for (var i=0; i < keys.length; i++) {
if (STOP === shouldStop) {
return STOP;
}
let keys = Object.keys(node);
for (let i = 0; i < keys.length; i++) {
let shouldStop = forEachNode(node[keys[i]], visit);
if (STOP === shouldStop) { return STOP; }
if (STOP === shouldStop) {
return STOP;
}
}

@@ -24,10 +28,10 @@ }

// TODO: add a persistent cache
var imports = [];
let imports = [];
var ast = acorn.parse(source, {
ecmaVersion: 6,
sourceType: 'module'
let ast = acorn.parse(source, {
ecmaVersion: 8,
sourceType: 'module',
});
var hasImportDeclaration = false;
let hasImportDeclaration = false;

@@ -44,3 +48,5 @@ forEachNode(ast, function(entry) {

if (hasImportDeclaration) { return; }
if (hasImportDeclaration) {
return;
}

@@ -47,0 +53,0 @@ if (entry.type === 'CallExpression' && entry.callee.name === 'define') {

{
"dependencies": {
"acorn": "^4.0.4",
"acorn": "^5.1.1",
"amd-name-resolver": "^0.0.6",
"fs-extra": "^2.0.0"
"fs-extra": "^3.0.1"
},
"devDependencies": {
"chai": "^3.5.0",
"chai": "^4.0.2",
"eslint": "^4.1.1",
"eslint-plugin-prettier": "^2.1.2",
"fixturify": "^0.3.2",
"mocha": "^3.2.0"
"husky": "^0.14.3",
"lint-staged": "^4.0.1",
"mocha": "^3.2.0",
"mocha-eslint": "^3.0.1",
"prettier": "^1.5.2"
},
"scripts": {
"test": "mocha tests",
"test:debug": "mocha debug tests"
"test:debug": "mocha debug tests",
"lint": "eslint *.js lib/**/*.js tests/**/*-test.js",
"lint:fix": "eslint --fix *.js lib/**/*.js tests/**/*-test.js",
"precommit": "lint-staged"
},
"lint-staged": {
"*.js": [
"eslint --fix",
"git add"
]
},
"name": "mr-dep-walk",
"version": "1.2.0",
"version": "1.3.0",
"main": "index.js",

@@ -19,0 +34,0 @@ "directories": {

# mr-dep-walk
[![Build Status](https://travis-ci.org/stefanpenner/mr-dep-walk.svg?branch=master)](https://travis-ci.org/stefanpenner/mr-dep-walk)
[![Build status](https://ci.appveyor.com/api/projects/status/ybwgahl64faf0507?svg=true)](https://ci.appveyor.com/project/embercli/mr-dep-walk)

@@ -5,3 +5,3 @@ 'use strict';

const fs = require('fs-extra');
const ROOT = __dirname + '/fixtures/';
const ROOT = __dirname + '/fixtures/';

@@ -13,3 +13,3 @@ const expect = require('chai').expect;

describe('ES5', function() {
beforeEach(function(){
beforeEach(function() {
fs.removeSync(ROOT);

@@ -19,6 +19,6 @@ fixturify.writeSync(ROOT + 'es5', {

'a.js': `define('a', ['exports', 'require'], function() { })`,
'b': {
'c.js': `define('c', ['../a', '../d'], function() { })`
b: {
'c.js': `define('c', ['../a', '../d'], function() { })`,
},
'd.js': `define('d', ['foo'], function() { })`
'd.js': `define('d', ['foo'], function() { })`,
});

@@ -28,3 +28,3 @@ });

it('extracts', function() {
expect(depFilesFromFile(ROOT + 'es5', { entry:'foo.js' })).to.eql([
expect(depFilesFromFile(ROOT + 'es5', { entry: 'foo.js' })).to.eql([
'a.js',

@@ -54,8 +54,8 @@ 'b/c.js',

it('ignores external', function() {
expect(depFilesFromFile(ROOT + 'es5', {
entry: 'foo.js',
external: ['b/c'],
})).to.eql([
'a.js'
]);
expect(
depFilesFromFile(ROOT + 'es5', {
entry: 'foo.js',
external: ['b/c'],
})
).to.eql(['a.js']);
});

@@ -72,9 +72,9 @@ });

'a.js': ``,
'b': {
b: {
'c.js': `
import a from '../a';
import d from '../d';
`
`,
},
'd.js': `import foo from 'foo';`
'd.js': `import foo from 'foo';`,
});

@@ -122,3 +122,3 @@ });

'a.js',
'b/c.js'
'b/c.js',
]);

@@ -136,9 +136,9 @@ });

'a.js': ``,
'b': {
b: {
'c.js': `
import a from '../a';
import d from '../d';
`
`,
},
'd.js': `import foo from 'foo';`
'd.js': `import foo from 'foo';`,
});

@@ -148,26 +148,19 @@ });

it('extracts', function() {
expect(depFilesFromFile(ROOT + 'cwd', { entry: 'foo.js', cwd: 'foo' })).to.eql([
'foo/a.js',
'foo/b/c.js',
'foo/d.js',
'foo/foo.js',
]);
expect(
depFilesFromFile(ROOT + 'cwd', { entry: 'foo.js', cwd: 'foo' })
).to.eql(['foo/a.js', 'foo/b/c.js', 'foo/d.js', 'foo/foo.js']);
expect(depFilesFromFile(ROOT + 'cwd', { entry: 'a.js', cwd: 'foo' })).to.eql([]);
expect(
depFilesFromFile(ROOT + 'cwd', { entry: 'a.js', cwd: 'foo' })
).to.eql([]);
expect(depFilesFromFile(ROOT + 'cwd', { entry: 'b/c.js', cwd: 'foo' })).to.eql([
'foo/a.js',
'foo/d.js',
'foo/foo.js',
'foo/b/c.js',
]);
expect(
depFilesFromFile(ROOT + 'cwd', { entry: 'b/c.js', cwd: 'foo' })
).to.eql(['foo/a.js', 'foo/d.js', 'foo/foo.js', 'foo/b/c.js']);
expect(depFilesFromFile(ROOT + 'cwd', { entry: 'd.js', cwd: 'foo' })).to.eql([
'foo/foo.js',
'foo/a.js',
'foo/b/c.js',
'foo/d.js',
]);
expect(
depFilesFromFile(ROOT + 'cwd', { entry: 'd.js', cwd: 'foo' })
).to.eql(['foo/foo.js', 'foo/a.js', 'foo/b/c.js', 'foo/d.js']);
});
});
});

@@ -5,3 +5,3 @@ 'use strict';

const fs = require('fs-extra');
const ROOT = __dirname + '/fixtures/';
const ROOT = __dirname + '/fixtures/';

@@ -13,3 +13,3 @@ const expect = require('chai').expect;

describe('ES5', function() {
beforeEach(function(){
beforeEach(function() {
fs.removeSync(ROOT);

@@ -19,6 +19,6 @@ fixturify.writeSync(ROOT + 'es5', {

'a.js': `define('a', ['exports', 'require'], function() { })`,
'b': {
'c.js': `define('c', ['../a', '../d'], function() { })`
b: {
'c.js': `define('c', ['../a', '../d'], function() { })`,
},
'd.js': `define('d', ['foo'], function() { })`
'd.js': `define('d', ['foo'], function() { })`,
});

@@ -43,9 +43,9 @@ });

'a.js': ``,
'b': {
b: {
'c.js': `
import a from '../a';
import d from '../d';
`
`,
},
'd.js': `import foo from 'foo';`
'd.js': `import foo from 'foo';`,
});

@@ -52,0 +52,0 @@ });

@@ -18,3 +18,3 @@ 'use strict';

expect(depsFromSrouce(D)).to.eql(['foo']);
})
});
});

@@ -39,23 +39,26 @@

expect(depsFromSrouce(D)).to.eql(['foo']);
})
});
});
describe('ES mixed', function() {
it('define then es6', function() {
expect(depsFromSrouce(`
expect(
depsFromSrouce(`
define('foo', ['bar'], function() { });
import x from 'a';
import y from 'b/c';
`)).to.eql(['bar']);
`)
).to.eql(['bar']);
});
it('es6 then define', function() {
expect(depsFromSrouce(`
expect(
depsFromSrouce(`
import x from 'a';
import y from 'b/c';
define('foo', ['bar'], function() { });
`)).to.eql(['a', 'b/c']);
`)
).to.eql(['a', 'b/c']);
});
});
});

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