Socket
Socket
Sign inDemoInstall

resolve

Package Overview
Dependencies
Maintainers
1
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

resolve - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

lib/package-path-and-remainder.js

48

lib/async.js

@@ -6,2 +6,3 @@ var core = require('./core');

var nodeModulesPaths = require('./node-modules-paths.js');
var packagePathAndRemainder = require('./package-path-and-remainder.js');

@@ -55,2 +56,3 @@ module.exports = function resolve (x, opts, cb) {

function loadAsFile (x, pkg, cb) {
if (typeof pkg === 'function') {

@@ -60,4 +62,41 @@ cb = pkg;

}
(function load (exts) {
var pathAndRemainder = packagePathAndRemainder(x);
var exts = [''].concat(extensions);
if (pathAndRemainder) {
var pkgfile = path.join(pathAndRemainder.path, 'package.json');
var remainder = pathAndRemainder.remainder;
isFile(pkgfile, function (err, ex) {
if (err) return cb(err);
if (!ex) return load(exts, x);
readFile(pkgfile, function (err, body) {
if (err) return cb(err);
try {
pkg = JSON.parse(body);
}
catch (err) {}
if (opts.packageFilter) {
pkg = opts.packageFilter(pkg, x);
}
if (opts.pathFilter && remainder) {
var newRemainder = opts.pathFilter(pkg, x, remainder);
if (newRemainder) {
return load(exts, path.resolve(
pathAndRemainder.path, newRemainder)
);
}
}
return load(exts, x);
});
});
}
else {
return load(exts, x);
}
function load (exts, x) {
if (exts.length === 0) return cb(null, undefined, pkg);

@@ -69,5 +108,6 @@ var file = x + exts[0];

else if (ex) cb(null, file, pkg)
else load(exts.slice(1))
else load(exts.slice(1), x)
});
})([''].concat(extensions));
}
}

@@ -74,0 +114,0 @@

2

package.json
{
"name" : "resolve",
"description" : "resolve like require.resolve() on behalf of files asynchronously and synchronously",
"version" : "1.0.0",
"version" : "1.1.0",
"repository" : {

@@ -6,0 +6,0 @@ "type" : "git",

@@ -282,1 +282,27 @@ var path = require('path');

});
test('#62: deep module references and the pathFilter', function(t){
t.plan(6);
var resolverDir = __dirname + '/resolver/deep_ref';
var pathFilter = function(pkg, x, remainder){
t.equal(pkg.version, "1.2.3");
t.equal(x, resolverDir + '/node_modules/deep/ref');
t.equal(remainder, "ref");
return "alt";
};
resolve('deep/ref', { basedir : resolverDir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(pkg.version, "1.2.3");
t.equal(res, resolverDir + '/node_modules/deep/ref.js');
});
resolve('deep/ref', { basedir : resolverDir, pathFilter : pathFilter }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, resolverDir + '/node_modules/deep/alt.js');
});
});

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