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

resolve

Package Overview
Dependencies
Maintainers
2
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.14.1 to 2.0.0-next.0

.github/FUNDING.yml

26

lib/async.js

@@ -29,3 +29,3 @@ var fs = require('fs');

var maybeUnwrapSymlink = function maybeUnwrapSymlink(x, opts, cb) {
if (opts && opts.preserveSymlinks === false) {
if (!opts || !opts.preserveSymlinks) {
fs.realpath(x, function (realPathErr, realPath) {

@@ -74,8 +74,22 @@ if (realPathErr && realPathErr.code !== 'ENOENT') cb(realPathErr);

if (err) cb(err);
else init(realStart);
else validateBasedir(realStart);
}
);
function validateBasedir(basedir) {
if (opts.basedir) {
var dirError = new TypeError('Provided basedir "' + basedir + '" is not a directory' + (opts.preserveSymlinks ? '' : ', or a symlink to a directory'));
dirError.code = 'INVALID_BASEDIR';
isDirectory(basedir, function (err, result) {
if (err) return cb(err);
if (!result) { return cb(dirError); }
validBasedir(basedir);
});
} else {
validBasedir(basedir);
}
}
var res;
function init(basedir) {
function validBasedir(basedir) {
if ((/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/).test(x)) {

@@ -188,3 +202,3 @@ res = path.resolve(basedir, x);

if (pkg && opts.packageFilter) {
pkg = opts.packageFilter(pkg, pkgfile);
pkg = opts.packageFilter(pkg, pkgfile, dir);
}

@@ -206,3 +220,3 @@ cb(null, pkg, dir);

maybeUnwrapSymlink(x, opts, function (unwrapErr, pkgdir) {
if (unwrapErr) return cb(unwrapErr);
if (unwrapErr) return loadAsDirectory(path.dirname(x), fpkg, cb);
var pkgfile = path.join(pkgdir, 'package.json');

@@ -220,3 +234,3 @@ isFile(pkgfile, function (err, ex) {

if (pkg && opts.packageFilter) {
pkg = opts.packageFilter(pkg, pkgfile);
pkg = opts.packageFilter(pkg, pkgfile, pkgdir);
}

@@ -223,0 +237,0 @@

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

var maybeUnwrapSymlink = function maybeUnwrapSymlink(x, opts) {
if (opts && opts.preserveSymlinks === false) {
if (!opts || !opts.preserveSymlinks) {
try {

@@ -49,4 +49,4 @@ return fs.realpathSync(x);

var isFile = opts.isFile || defaultIsFile;
var isDirectory = opts.isDirectory || defaultIsDir;
var readFileSync = opts.readFileSync || fs.readFileSync;
var isDirectory = opts.isDirectory || defaultIsDir;

@@ -62,2 +62,8 @@ var extensions = opts.extensions || ['.js'];

if (opts.basedir && !isDirectory(absoluteStart)) {
var dirError = new TypeError('Provided basedir "' + opts.basedir + '" is not a directory' + (opts.preserveSymlinks ? '' : ', or a symlink to a directory'));
dirError.code = 'INVALID_BASEDIR';
throw dirError;
}
if ((/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/).test(x)) {

@@ -111,3 +117,3 @@ var res = path.resolve(absoluteStart, x);

var pkgfile = path.join(maybeUnwrapSymlink(dir, opts), 'package.json');
var pkgfile = path.join(isDirectory(dir) ? maybeUnwrapSymlink(dir, opts) : dir, 'package.json');

@@ -125,4 +131,3 @@ if (!isFile(pkgfile)) {

if (pkg && opts.packageFilter) {
// v2 will pass pkgfile
pkg = opts.packageFilter(pkg, /*pkgfile,*/ dir); // eslint-disable-line spaced-comment
pkg = opts.packageFilter(pkg, pkgfile, dir);
}

@@ -134,3 +139,3 @@

function loadAsDirectorySync(x) {
var pkgfile = path.join(maybeUnwrapSymlink(x, opts), '/package.json');
var pkgfile = path.join(isDirectory(x) ? maybeUnwrapSymlink(x, opts) : x, '/package.json');
if (isFile(pkgfile)) {

@@ -143,4 +148,3 @@ try {

if (pkg && opts.packageFilter) {
// v2 will pass pkgfile
pkg = opts.packageFilter(pkg, /*pkgfile,*/ x); // eslint-disable-line spaced-comment
pkg = opts.packageFilter(pkg, pkgfile, x);
}

@@ -147,0 +151,0 @@

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

@@ -27,5 +27,5 @@ "type": "git",

"devDependencies": {
"@ljharb/eslint-config": "^15.0.2",
"@ljharb/eslint-config": "^15.1.0",
"array.prototype.map": "^1.0.2",
"eslint": "^6.7.2",
"eslint": "^6.8.0",
"object-keys": "^1.1.1",

@@ -32,0 +32,0 @@ "safe-publish-latest": "^1.1.4",

@@ -26,5 +26,5 @@ var test = require('tape');

resolve(module, opts, function (err, res) {
t.equal(err.code, 'MODULE_NOT_FOUND');
t.equal(err.code, 'INVALID_BASEDIR');
t.equal(res, undefined);
});
});

@@ -10,6 +10,5 @@ var path = require('path');

basedir: dir,
// NOTE: in v2.x, this will be `pkg, pkgfile, dir`, but must remain "broken" here in v1.x for compatibility
packageFilter: function (pkg, /*pkgfile,*/ dir) { // eslint-disable-line spaced-comment
packageFilter: function (pkg, pkgfile, dir) {
pkg.main = 'doom'; // eslint-disable-line no-param-reassign
packageFilterArgs = 'is 1.x' ? [pkg, dir] : [pkg, pkgfile, dir]; // eslint-disable-line no-constant-condition, no-undef
packageFilterArgs = [pkg, pkgfile, dir];
return pkg;

@@ -24,12 +23,13 @@ }

if (!'is 1.x') { // eslint-disable-line no-constant-condition
var packageFile = packageFilterArgs[1];
t.equal(packageFile, path.join(dir, 'baz', 'package.json'), 'package.json path is correct');
}
var packageFile = packageFilterArgs[1];
t.equal(
packageFile,
path.join(dir, 'baz/package.json'),
'second packageFilter argument is "pkgfile"'
);
var packageDir = packageFilterArgs['is 1.x' ? 1 : 2]; // eslint-disable-line no-constant-condition
// eslint-disable-next-line no-constant-condition
t.equal(packageDir, path.join(dir, 'baz'), ('is 1.x' ? 'second' : 'third') + ' packageFilter argument is "dir"');
var packageDir = packageFilterArgs[2];
t.equal(packageDir, path.join(dir, 'baz'), 'third packageFilter argument is "dir"');
t.end();
});

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

test('filter', function (t) {
t.plan(4);
t.plan(5);
var dir = path.join(__dirname, 'resolver');

@@ -12,5 +12,5 @@ var packageFilterArgs;

basedir: dir,
packageFilter: function (pkg, pkgfile) {
packageFilter: function (pkg, pkgfile, dir) {
pkg.main = 'doom'; // eslint-disable-line no-param-reassign
packageFilterArgs = [pkg, pkgfile];
packageFilterArgs = [pkg, pkgfile, dir];
return pkg;

@@ -34,4 +34,7 @@ }

var packageFileDir = packageFilterArgs[2];
t.equal(packageFileDir, path.join(dir, 'baz'), 'third packageFilter argument is "dir"');
t.end();
});
});

@@ -13,2 +13,3 @@ var path = require('path');

dirs[path.resolve('/foo/bar')] = true;
dirs[path.resolve('/foo/node_modules')] = true;

@@ -15,0 +16,0 @@ function opts(basedir) {

@@ -281,4 +281,4 @@ var path = require('path');

t.ok(err, 'a non-directory errors');
t.equal(err && err.message, 'Cannot find module \'' + path + "' from '" + __filename + "'");
t.equal(err && err.code, 'MODULE_NOT_FOUND');
t.equal(err && err.message, 'Provided basedir "' + __filename + '" is not a directory, or a symlink to a directory');
t.equal(err && err.code, 'INVALID_BASEDIR');
}

@@ -285,0 +285,0 @@ t.end();

@@ -364,4 +364,4 @@ var path = require('path');

t.equal(err && err.message, 'Cannot find module \'' + path + '\' from \'' + __filename + '\'');
t.equal(err && err.code, 'MODULE_NOT_FOUND');
t.equal(err && err.message, 'Provided basedir "' + __filename + '" is not a directory, or a symlink to a directory');
t.equal(err && err.code, 'INVALID_BASEDIR');
});

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

@@ -27,4 +27,6 @@ var path = require('path');

} catch (err) {
// if fails then it is probably on Windows and lets try to create a junction
fs.symlinkSync(path.join(__dirname, 'resolver', 'symlinked', '_', 'symlink_target') + '\\', symlinkDir, 'junction');
if (err.code !== 'EEXIST') {
// if fails then it is probably on Windows and lets try to create a junction
fs.symlinkSync(path.join(__dirname, 'resolver', 'symlinked', '_', 'symlink_target') + '\\', symlinkDir, 'junction');
}
}

@@ -47,3 +49,3 @@ try {

resolve('foo', { basedir: symlinkDir, preserveSymlinks: false }, function (err, res, pkg) {
resolve('foo', { basedir: symlinkDir }, function (err, res, pkg) {
t.error(err);

@@ -57,3 +59,3 @@ t.equal(res, path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'foo.js'));

resolve('foo', { basedir: symlinkDir }, function (err, res, pkg) {
resolve('foo', { basedir: symlinkDir, preserveSymlinks: true }, function (err, res, pkg) {
t.ok(err, 'there is an error');

@@ -82,3 +84,3 @@ t.notOk(res, 'no result');

t.throws(function () {
resolve.sync('foo', { basedir: symlinkDir });
resolve.sync('foo', { basedir: symlinkDir, preserveSymlinks: true });
}, /Cannot find module 'foo'/);

@@ -112,3 +114,3 @@ t.end();

return function (st) {
st.plan('is 1.x' ? 3 : 5); // eslint-disable-line no-constant-condition
st.plan(5);

@@ -121,4 +123,2 @@ var destMain = 'symlinks/dest/node_modules/mod-a/index.js';

/* eslint multiline-comment-style: 0 */
/* v2.x will restore these tests
var packageFilterPath = [];

@@ -142,3 +142,2 @@ var actualPath = resolve.sync('mod-a', {

);
*/

@@ -145,0 +144,0 @@ var asyncPackageFilterPath = [];

Sorry, the diff of this file is not supported yet

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