Socket
Socket
Sign inDemoInstall

resolve

Package Overview
Dependencies
5
Maintainers
2
Versions
95
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0-next.0 to 2.0.0-next.1

index.mjs

1

index.js

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

exports = async;
module.exports = async;

@@ -39,2 +39,10 @@ var fs = require('fs');

var getPackageCandidates = function getPackageCandidates(x, start, opts) {
var dirs = nodeModulesPaths(start, opts, x);
for (var i = 0; i < dirs.length; i++) {
dirs[i] = path.join(dirs[i], x);
}
return dirs;
};
module.exports = function resolve(x, options, callback) {

@@ -59,2 +67,3 @@ var cb = callback;

var readFile = opts.readFile || fs.readFile;
var packageIterator = opts.packageIterator;

@@ -101,5 +110,6 @@ var extensions = opts.extensions || ['.js'];

} else loadAsFile(res, opts.package, onfile);
} else if (isCore(x)) {
return cb(null, x);
} else loadNodeModules(x, basedir, function (err, n, pkg) {
if (err) cb(err);
else if (isCore(x)) return cb(null, x);
else if (n) {

@@ -270,3 +280,3 @@ return maybeUnwrapSymlink(n, opts, function (err, realN) {

isDirectory(dir, isdir);
isDirectory(path.dirname(dir), isdir);

@@ -276,4 +286,3 @@ function isdir(err, isdir) {

if (!isdir) return processDirs(cb, dirs.slice(1));
var file = path.join(dir, x);
loadAsFile(file, opts.package, onfile);
loadAsFile(dir, opts.package, onfile);
}

@@ -284,3 +293,3 @@

if (m) return cb(null, m, pkg);
loadAsDirectory(path.join(dir, x), opts.package, ondir);
loadAsDirectory(dir, opts.package, ondir);
}

@@ -295,4 +304,8 @@

function loadNodeModules(x, start, cb) {
processDirs(cb, nodeModulesPaths(start, opts, x));
var thunk = function () { return getPackageCandidates(x, start, opts); };
processDirs(
cb,
packageIterator ? packageIterator(x, start, thunk, opts) : thunk()
);
}
};

@@ -41,3 +41,11 @@ var isCore = require('./is-core');

module.exports = function (x, options) {
var getPackageCandidates = function getPackageCandidates(x, start, opts) {
var dirs = nodeModulesPaths(start, opts, x);
for (var i = 0; i < dirs.length; i++) {
dirs[i] = path.join(dirs[i], x);
}
return dirs;
};
module.exports = function resolveSync(x, options) {
if (typeof x !== 'string') {

@@ -51,2 +59,3 @@ throw new TypeError('Path must be a string.');

var readFileSync = opts.readFileSync || fs.readFileSync;
var packageIterator = opts.packageIterator;

@@ -80,4 +89,2 @@ var extensions = opts.extensions || ['.js'];

if (isCore(x)) return x;
var err = new Error("Cannot find module '" + x + "' from '" + parent + "'");

@@ -170,9 +177,11 @@ err.code = 'MODULE_NOT_FOUND';

function loadNodeModulesSync(x, start) {
var dirs = nodeModulesPaths(start, opts, x);
var thunk = function () { return getPackageCandidates(x, start, opts); };
var dirs = packageIterator ? packageIterator(x, start, thunk, opts) : thunk();
for (var i = 0; i < dirs.length; i++) {
var dir = dirs[i];
if (isDirectory(dir)) {
var m = loadAsFileSync(path.join(dir, '/', x));
if (isDirectory(path.dirname(dir))) {
var m = loadAsFileSync(dir);
if (m) return m;
var n = loadAsDirectorySync(path.join(dir, '/', x));
var n = loadAsDirectorySync(dir);
if (n) return n;

@@ -179,0 +188,0 @@ }

{
"name": "resolve",
"description": "resolve like require.resolve() on behalf of files asynchronously and synchronously",
"version": "2.0.0-next.0",
"version": "2.0.0-next.1",
"repository": {

@@ -10,2 +10,42 @@ "type": "git",

"main": "index.js",
"exports": {
".": [
{
"import": "./index.mjs",
"require": "./index.js",
"default": "./index.js"
},
"./index.js"
],
"./core": [
{
"default": "./lib/core.js"
},
"./lib/core.js"
],
"./core.json": [
{
"default": "./lib/core.json"
},
"./lib/core.json"
],
"./isCore": [
{
"default": "./lib/is-core.js"
},
"./lib/is-core.js"
],
"./sync": [
{
"default": "./lib/sync.js"
},
"./lib/sync.js"
],
"./async": [
{
"default": "./lib/async.js"
},
"./lib/async.js"
]
},
"keywords": [

@@ -34,3 +74,3 @@ "resolve",

"tap": "0.4.13",
"tape": "^4.12.0"
"tape": "^5.0.0-next.4"
},

@@ -37,0 +77,0 @@ "license": "MIT",

@@ -175,2 +175,17 @@ var path = require('path');

test('path iterator', function (t) {
var resolverDir = path.join(__dirname, 'resolver');
var exactIterator = function (x, start, getPackageCandidates, opts) {
return [path.join(resolverDir, x)];
};
t.equal(
resolve.sync('baz', { packageIterator: exactIterator }),
path.join(resolverDir, 'baz/quux.js')
);
t.end();
});
test('incorrect main', function (t) {

@@ -177,0 +192,0 @@ var resolverDir = path.join(__dirname, 'resolver');

@@ -259,2 +259,18 @@ var path = require('path');

test('path iterator', function (t) {
t.plan(2);
var resolverDir = path.join(__dirname, 'resolver');
var exactIterator = function (x, start, getPackageCandidates, opts) {
return [path.join(resolverDir, x)];
};
resolve('baz', { packageIterator: exactIterator }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, path.join(resolverDir, 'baz/quux.js'));
t.equal(pkg && pkg.name, 'baz');
});
});
test('incorrect main', function (t) {

@@ -261,0 +277,0 @@ t.plan(1);

{
"name": "baz",
"main": "quux.js"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc