| # These are supported funding model platforms | ||
| github: [ljharb] | ||
| patreon: # Replace with a single Patreon username | ||
| open_collective: # Replace with a single Open Collective username | ||
| ko_fi: # Replace with a single Ko-fi username | ||
| tidelift: npm/resolve | ||
| community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry | ||
| liberapay: # Replace with a single Liberapay username | ||
| issuehunt: # Replace with a single IssueHunt username | ||
| otechie: # Replace with a single Otechie username | ||
| custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] |
| var test = require('tape'); | ||
| var path = require('path'); | ||
| var resolve = require('../'); | ||
| test('synchronous pathfilter', function (t) { | ||
| var res; | ||
| var resolverDir = __dirname + '/pathfilter/deep_ref'; | ||
| var pathFilter = function (pkg, x, remainder) { | ||
| t.equal(pkg.version, '1.2.3'); | ||
| t.equal(x, path.join(resolverDir, 'node_modules', 'deep', 'ref')); | ||
| t.equal(remainder, 'ref'); | ||
| return 'alt'; | ||
| }; | ||
| res = resolve.sync('deep/ref', { basedir: resolverDir }); | ||
| t.equal(res, path.join(resolverDir, 'node_modules', 'deep', 'ref.js')); | ||
| res = resolve.sync('deep/deeper/ref', { basedir: resolverDir }); | ||
| t.equal(res, path.join(resolverDir, 'node_modules', 'deep', 'deeper', 'ref.js')); | ||
| res = resolve.sync('deep/ref', { basedir: resolverDir, pathFilter: pathFilter }); | ||
| t.equal(res, path.join(resolverDir, 'node_modules', 'deep', 'alt.js')); | ||
| t.end(); | ||
| }); |
+8
-1
@@ -17,3 +17,3 @@ { | ||
| "id-length": [2, { "min": 1, "max": 30 }], | ||
| "max-lines-per-function": 0, | ||
| "max-lines-per-function": 1, | ||
| "max-nested-callbacks": 0, | ||
@@ -39,3 +39,10 @@ "max-params": 0, | ||
| }, | ||
| { | ||
| "files": "test/**", | ||
| "rules": { | ||
| "max-lines": 0, | ||
| "max-lines-per-function": 0, | ||
| }, | ||
| }, | ||
| ], | ||
| } |
+20
-6
@@ -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 @@ |
+12
-8
@@ -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 @@ |
+3
-3
| { | ||
| "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
-10
@@ -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 +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(); |
+2
-2
@@ -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 @@ }); |
+8
-9
@@ -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 = []; |
| { | ||
| "rules": { | ||
| "max-lines": 0 | ||
| } | ||
| } |
Sorry, the diff of this file is not supported yet
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
Debug access
Supply chain riskUses debug, reflection and dynamic code execution features.
Found 2 instances in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
97195
1.86%91
1.11%2232
1.73%2
100%200
-1.48%