Socket
Socket
Sign inDemoInstall

commonjs-walker

Package Overview
Dependencies
3
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 4.0.2 to 4.1.0

test/fixtures/walker/as/deep/dep.js

44

index.js

@@ -168,5 +168,6 @@ 'use strict';

// we only map top level id for now
dep = options['as'][dep] || dep;
dep = self._solveAliasedDependency(options['as'][dep], path) || dep;
}
// package name, not a path
if (!self._isRelativePath(dep)) {

@@ -198,3 +199,33 @@ return self._dealDependency(origin, dep, node, done);

// #17
// If we define an `as` field in cortex.json
// {
// "as": {
// "abc": './abc.js' // ./abc.js is relative to the root directory
// }
// }
// @param {String} dep path of dependency
// @param {String} env_path the path of the current file
Walker.prototype._solveAliasedDependency = function(dep, env_path) {
var cwd = this.options.cwd;
if (!dep || !cwd || !this._isRelativePath(dep)) {
return dep;
}
dep = node_path.join(cwd, dep);
dep = node_path.relative(node_path.dirname(env_path), dep)
// After join and relative, dep will contains `node_path.sep` which varies from operating system,
// so normalize it
.replace(/\\/g, '/');
if (!~dep.indexOf('..')) {
// 'abc.js' -> './abc.js'
dep = './' + dep;
}
return dep;
};
Walker.prototype._dealDependency = function(dep, real, node, callback) {

@@ -211,3 +242,2 @@ node.dependencies[dep] = real;

}
// this._addDependent(node, sub_node);
return callback(null);

@@ -236,4 +266,2 @@ }

}
// this._addDependent(node, sub_node);
callback(null);

@@ -243,10 +271,2 @@ };

// Walker.prototype._addDependent = function(dependent, dependency) {
// // adds dependent
// if (!~dependency.dependents.indexOf(dependent)) {
// dependency.dependents.push(dependent);
// }
// };
// Creates the node by id if not exists.

@@ -253,0 +273,0 @@ // No fault tolerance for the sake of private method

{
"name": "commonjs-walker",
"version": "4.0.2",
"version": "4.1.0",
"description": "Analyzer and tree walker for commonjs.",

@@ -10,3 +10,9 @@ "main": "index.js",

"keywords": [
"commonjs-walker"
"commonjs",
"walker",
"parser",
"module",
"dependencies",
"require",
"resolve"
],

@@ -13,0 +19,0 @@ "repository": {

@@ -229,2 +229,16 @@ 'use strict';

}
},
{
desc: '#17: deep deps of package.as',
options: {
'as': {
'abc': './deep/dep.js'
},
cwd: node_path.join(root, 'as')
},
file: 'as/deep/index.js',
expect: function (err, path, nodes, entry) {
expect(err).to.equal(null);
expect(entry.dependencies['abc']).to.equal(node_path.join(node_path.dirname(path), './dep.js'));
}
}

@@ -231,0 +245,0 @@ ];

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc