UEA-PRODEM

This commit is contained in:
2026-06-10 12:14:46 -03:00
parent f54126b9d8
commit 9947565694
5319 changed files with 148520 additions and 129332 deletions
+4 -3
View File
@@ -9,15 +9,16 @@ trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 200
[*.js]
[*.{,m}js]
block_comment_start = /*
block_comment = *
block_comment_end = */
[*.yml]
indent_style = space
indent_size = 1
[package.json]
[{package.json,*.mjs}]
indent_style = tab
[lib/core.json]
@@ -27,7 +28,7 @@ indent_style = tab
indent_style = space
indent_size = 2
[{*.json,Makefile}]
[{*.json,Makefile,CONTRIBUTING.md}]
max_line_length = off
[test/{dotdot,resolver,module_dir,multirepo,node_path,pathfilter,precedence}/**/*]
+3 -1
View File
@@ -1,6 +1,8 @@
# Security
Please file a private vulnerability via GitHub, email [@ljharb](https://github.com/ljharb), or see https://tidelift.com/security if you have a potential security vulnerability to report.
Please [file a private vulnerability report](https://github.com/browserify/resolve/security/advisories/new),
or email [@ljharb](https://github.com/ljharb),
if you have a potential security vulnerability to report.
## Incident Response
+18 -15
View File
@@ -5,6 +5,8 @@ var caller = require('./caller');
var nodeModulesPaths = require('./node-modules-paths');
var normalizeOptions = require('./normalize-options');
var isCore = require('is-core-module');
var $Error = require('es-errors');
var $TypeError = require('es-errors/type');
var realpathFS = process.platform !== 'win32' && fs.realpath && typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath;
@@ -13,12 +15,13 @@ var windowsDriveRegex = /^\w:[/\\]*$/;
var nodeModulesRegex = /[/\\]node_modules[/\\]*$/;
var homedir = getHomedir();
var defaultPaths = function () {
function defaultPaths() {
if (!homedir) return [];
return [
path.join(homedir, '.node_modules'),
path.join(homedir, '.node_libraries')
];
};
}
var defaultIsFile = function isFile(file, cb) {
fs.stat(file, function (err, stat) {
@@ -47,15 +50,15 @@ var defaultRealpath = function realpath(x, cb) {
});
};
var maybeRealpath = function maybeRealpath(realpath, x, opts, cb) {
function maybeRealpath(realpath, x, opts, cb) {
if (opts && opts.preserveSymlinks === false) {
realpath(x, cb);
} else {
cb(null, x);
}
};
}
var defaultReadPackage = function defaultReadPackage(readFile, pkgfile, cb) {
function defaultReadPackage(readFile, pkgfile, cb) {
readFile(pkgfile, function (readFileErr, body) {
if (readFileErr) cb(readFileErr);
else {
@@ -67,15 +70,15 @@ var defaultReadPackage = function defaultReadPackage(readFile, pkgfile, cb) {
}
}
});
};
}
var getPackageCandidates = function getPackageCandidates(x, start, opts) {
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) {
var cb = callback;
@@ -85,7 +88,7 @@ module.exports = function resolve(x, options, callback) {
opts = {};
}
if (typeof x !== 'string') {
var err = new TypeError('Path must be a string.');
var err = new $TypeError('Path must be a string.');
return process.nextTick(function () {
cb(err);
});
@@ -99,7 +102,7 @@ module.exports = function resolve(x, options, callback) {
var realpath = opts.realpath || defaultRealpath;
var readPackage = opts.readPackage || defaultReadPackage;
if (opts.readFile && opts.readPackage) {
var conflictErr = new TypeError('`readFile` and `readPackage` are mutually exclusive.');
var conflictErr = new $TypeError('`readFile` and `readPackage` are mutually exclusive.');
return process.nextTick(function () {
cb(conflictErr);
});
@@ -147,7 +150,7 @@ module.exports = function resolve(x, options, callback) {
}
});
} else {
var moduleError = new Error("Cannot find module '" + x + "' from '" + parent + "'");
var moduleError = new $Error("Cannot find module '" + x + "' from '" + parent + "'");
moduleError.code = 'MODULE_NOT_FOUND';
cb(moduleError);
}
@@ -168,7 +171,7 @@ module.exports = function resolve(x, options, callback) {
}
});
} else {
var moduleError = new Error("Cannot find module '" + x + "' from '" + parent + "'");
var moduleError = new $Error("Cannot find module '" + x + "' from '" + parent + "'");
moduleError.code = 'MODULE_NOT_FOUND';
cb(moduleError);
}
@@ -202,7 +205,7 @@ module.exports = function resolve(x, options, callback) {
var rel = rfile.slice(0, rfile.length - exts[0].length);
var r = opts.pathFilter(pkg, x, rel);
if (r) return load(
[''].concat(extensions.slice()),
[''].concat(extensions),
path.resolve(dir, r),
pkg
);
@@ -232,7 +235,7 @@ module.exports = function resolve(x, options, callback) {
if (!ex) return loadpkg(path.dirname(dir), cb);
readPackage(readFile, pkgfile, function (err, pkgParam) {
if (err) cb(err);
if (err) { return cb(err); }
var pkg = pkgParam;
@@ -271,7 +274,7 @@ module.exports = function resolve(x, options, callback) {
if (pkg && pkg.main) {
if (typeof pkg.main !== 'string') {
var mainError = new TypeError('package “' + pkg.name + '” `main` must be a string');
var mainError = new $TypeError('package “' + pkg.name + '” `main` must be a string');
mainError.code = 'INVALID_PACKAGE_MAIN';
return cb(mainError);
}
+8 -4
View File
@@ -1,8 +1,12 @@
'use strict';
var $Error = require('es-errors');
module.exports = function () {
// see https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
var origPrepareStackTrace = Error.prepareStackTrace;
Error.prepareStackTrace = function (_, stack) { return stack; };
var stack = (new Error()).stack;
Error.prepareStackTrace = origPrepareStackTrace;
var origPrepareStackTrace = $Error.prepareStackTrace;
$Error.prepareStackTrace = function (_, stack) { return stack; };
var stack = (new $Error()).stack;
$Error.prepareStackTrace = origPrepareStackTrace;
return stack[2].getFileName();
};
+8 -1
View File
@@ -9,7 +9,14 @@ module.exports = os.homedir || function homedir() {
var user = process.env.LOGNAME || process.env.USER || process.env.LNAME || process.env.USERNAME;
if (process.platform === 'win32') {
return process.env.USERPROFILE || process.env.HOMEDRIVE + process.env.HOMEPATH || home || null;
return process.env.USERPROFILE
|| (
process.env.HOMEDRIVE
&& process.env.HOMEPATH
&& (process.env.HOMEDRIVE + process.env.HOMEPATH)
)
|| home
|| null;
}
if (process.platform === 'darwin') {
+2 -2
View File
@@ -4,7 +4,7 @@ var parse = path.parse || require('path-parse'); // eslint-disable-line global-r
var driveLetterRegex = /^([A-Za-z]:)/;
var uncPathRegex = /^\\\\/;
var getNodeModulesDirs = function getNodeModulesDirs(absoluteStart, modules) {
function getNodeModulesDirs(absoluteStart, modules) {
var prefix = '/';
if (driveLetterRegex.test(absoluteStart)) {
prefix = '';
@@ -24,7 +24,7 @@ var getNodeModulesDirs = function getNodeModulesDirs(absoluteStart, modules) {
return path.resolve(prefix, aPath, moduleDir);
}));
}, []);
};
}
module.exports = function nodeModulesPaths(start, opts, request) {
var modules = opts && opts.moduleDirectory
+16 -12
View File
@@ -1,6 +1,9 @@
var isCore = require('is-core-module');
var fs = require('fs');
var path = require('path');
var $Error = require('es-errors');
var $TypeError = require('es-errors/type');
var getHomedir = require('./homedir');
var caller = require('./caller');
var nodeModulesPaths = require('./node-modules-paths');
@@ -13,12 +16,13 @@ var windowsDriveRegex = /^\w:[/\\]*$/;
var nodeModulesRegex = /[/\\]node_modules[/\\]*$/;
var homedir = getHomedir();
var defaultPaths = function () {
function defaultPaths() {
if (!homedir) return [];
return [
path.join(homedir, '.node_modules'),
path.join(homedir, '.node_libraries')
];
};
}
var defaultIsFile = function isFile(file) {
try {
@@ -51,32 +55,32 @@ var defaultRealpathSync = function realpathSync(x) {
return x;
};
var maybeRealpathSync = function maybeRealpathSync(realpathSync, x, opts) {
function maybeRealpathSync(realpathSync, x, opts) {
if (opts && opts.preserveSymlinks === false) {
return realpathSync(x);
}
return x;
};
}
var defaultReadPackageSync = function defaultReadPackageSync(readFileSync, pkgfile) {
function defaultReadPackageSync(readFileSync, pkgfile) {
var body = readFileSync(pkgfile);
try {
var pkg = JSON.parse(body);
return pkg;
} catch (jsonErr) {}
};
}
var getPackageCandidates = function getPackageCandidates(x, start, opts) {
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') {
throw new TypeError('Path must be a string.');
throw new $TypeError('Path must be a string.');
}
var opts = normalizeOptions(x, options);
@@ -86,7 +90,7 @@ module.exports = function resolveSync(x, options) {
var realpathSync = opts.realpathSync || defaultRealpathSync;
var readPackageSync = opts.readPackageSync || defaultReadPackageSync;
if (opts.readFileSync && opts.readPackageSync) {
throw new TypeError('`readFileSync` and `readPackageSync` are mutually exclusive.');
throw new $TypeError('`readFileSync` and `readPackageSync` are mutually exclusive.');
}
var packageIterator = opts.packageIterator;
@@ -112,7 +116,7 @@ module.exports = function resolveSync(x, options) {
if (n) return maybeRealpathSync(realpathSync, n, opts);
}
var err = new Error("Cannot find module '" + x + "' from '" + parent + "'");
var err = new $Error("Cannot find module '" + x + "' from '" + parent + "'");
err.code = 'MODULE_NOT_FOUND';
throw err;
@@ -176,7 +180,7 @@ module.exports = function resolveSync(x, options) {
if (pkg && pkg.main) {
if (typeof pkg.main !== 'string') {
var mainError = new TypeError('package “' + pkg.name + '” `main` must be a string');
var mainError = new $TypeError('package “' + pkg.name + '” `main` must be a string');
mainError.code = 'INVALID_PACKAGE_MAIN';
throw mainError;
}
+11 -8
View File
@@ -1,7 +1,7 @@
{
"name": "resolve",
"description": "resolve like require.resolve() on behalf of files asynchronously and synchronously",
"version": "1.22.11",
"version": "1.22.12",
"repository": {
"type": "git",
"url": "ssh://github.com/browserify/resolve.git"
@@ -20,8 +20,8 @@
"prepack": "npmignore --auto --commentLines=autogenerated && cp node_modules/is-core-module/core.json ./lib/ ||:",
"prepublishOnly": "safe-publish-latest",
"prepublish": "not-in-publish || npm run prepublishOnly",
"prelint": "eclint check $(git ls-files | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')",
"lint": "eslint --ext=js,mjs --no-eslintrc -c .eslintrc . 'bin/**'",
"prelint": "eclint check $(git ls-files | grep -Ev test\\/list-exports$ | xargs find 2> /dev/null | grep -vE 'node_modules|\\.git')",
"lint": "eslint .",
"pretests-only": "cd ./test/resolver/nested_symlinks && node mylib/sync && node mylib/async",
"tests-only": "tape test/*.js",
"pretest": "npm run lint",
@@ -30,20 +30,21 @@
"test:multirepo": "cd ./test/resolver/multirepo && npm install && npm test"
},
"devDependencies": {
"@ljharb/eslint-config": "^21.2.0",
"@ljharb/eslint-config": "^22.2.2",
"array.prototype.map": "^1.0.8",
"copy-dir": "^1.3.0",
"eclint": "^2.8.1",
"eslint": "=8.8.0",
"eslint": "^9.39.1",
"in-publish": "^2.0.1",
"mkdirp": "^0.5.5",
"jiti": "^0.0.0",
"mkdirp": "^0.5.6",
"mv": "^2.1.1",
"npmignore": "^0.3.1",
"npmignore": "^0.3.5",
"object-keys": "^1.1.1",
"rimraf": "^2.7.1",
"safe-publish-latest": "^2.0.0",
"semver": "^6.3.1",
"tap": "0.4.13",
"tap": "^0.4.13",
"tape": "^5.9.0",
"tmp": "^0.0.31"
},
@@ -57,6 +58,7 @@
"url": "https://github.com/sponsors/ljharb"
},
"dependencies": {
"es-errors": "^1.3.0",
"is-core-module": "^2.16.1",
"path-parse": "^1.0.7",
"supports-preserve-symlinks-flag": "^1.0.0"
@@ -65,6 +67,7 @@
"ignore": [
".github/workflows",
"appveyor.yml",
"CONTRIBUTING.md",
"test/resolver/malformed_package_json",
"test/list-exports"
]
+2 -3
View File
@@ -4,10 +4,9 @@ implements the [node `require.resolve()` algorithm](https://nodejs.org/api/modul
[![github actions][actions-image]][actions-url]
[![coverage][codecov-image]][codecov-url]
[![dependency status][5]][6]
[![dev dependency status][7]][8]
[![License][license-image]][license-url]
[![Downloads][downloads-image]][downloads-url]
[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/10759/badge)](https://bestpractices.coreinfrastructure.org/projects/10759)
[![npm badge][11]][1]
@@ -297,5 +296,5 @@ MIT
[downloads-url]: https://npm-stat.com/charts.html?package=resolve
[codecov-image]: https://codecov.io/gh/browserify/resolve/branch/main/graphs/badge.svg
[codecov-url]: https://app.codecov.io/gh/browserify/resolve/
[actions-image]: https://img.shields.io/endpoint?url=https://github-actions-badge-u3jn4tfpocch.runkit.sh/browserify/resolve
[actions-image]: https://img.shields.io/github/check-runs/browserify/resolve/main
[actions-url]: https://github.com/browserify/resolve/actions
+41 -3
View File
@@ -239,7 +239,7 @@ test('symlinked', function (t) {
});
test('readPackage', function (t) {
t.plan(3);
t.plan(4);
var files = {};
files[path.resolve('/foo/node_modules/bar/something-else.js')] = 'beep';
@@ -281,14 +281,14 @@ test('readPackage', function (t) {
});
});
var readPackage = function (readFile, file, cb) {
function readPackage(readFile, file, cb) {
var barPackage = path.join('bar', 'package.json');
if (file.slice(-barPackage.length) === barPackage) {
cb(null, { main: './something-else.js' });
} else {
cb(null, JSON.parse(files[path.resolve(file)]));
}
};
}
t.test('with readPackage', function (st) {
st.plan(3);
@@ -312,4 +312,42 @@ test('readPackage', function (t) {
st.throws(function () { throw err; }, TypeError, 'errors when both readFile and readPackage are provided');
});
});
t.test('readPackage error in loadpkg does not invoke callback twice', function (st) {
st.plan(1);
var callCount = 0;
var readPackageError = new Error('read package error');
function failReadPackage(rf, file, cb) {
cb(readPackageError);
}
var relFiles = {};
relFiles[path.resolve('/foo/bar/baz.js')] = 'beep';
relFiles[path.resolve('/foo/bar/package.json')] = '{}';
var relDirs = {};
relDirs[path.resolve('/foo/bar')] = true;
resolve('./baz', {
basedir: path.resolve('/foo/bar'),
isFile: function (file, cb) {
cb(null, Object.prototype.hasOwnProperty.call(relFiles, path.resolve(file)));
},
isDirectory: function (dir, cb) {
cb(null, !!relDirs[path.resolve(dir)]);
},
readPackage: failReadPackage,
realpath: function (file, cb) {
cb(null, file);
}
}, function () {
callCount += 1;
});
setTimeout(function () {
st.equal(callCount, 1, 'callback is invoked exactly once');
}, 50);
});
});
+23 -3
View File
@@ -140,7 +140,7 @@ test('symlinked', function (t) {
});
test('readPackageSync', function (t) {
t.plan(3);
t.plan(4);
var files = {};
files[path.resolve('/foo/node_modules/bar/something-else.js')] = 'beep';
@@ -179,12 +179,12 @@ test('readPackageSync', function (t) {
);
});
var readPackageSync = function (readFileSync, file) {
function readPackageSync(readFileSync, file) {
if (file.indexOf(path.join('bar', 'package.json')) >= 0) {
return { main: './something-else.js' };
}
return JSON.parse(files[path.resolve(file)]);
};
}
t.test('with readPackage', function (st) {
st.plan(1);
@@ -210,5 +210,25 @@ test('readPackageSync', function (t) {
'errors when both readFile and readPackage are provided'
);
});
t.test('readPackageSync error propagates correctly', function (st) {
st.plan(1);
var readPackageError = new Error('read package error');
function failReadPackageSync() {
throw readPackageError;
}
var options = opts('/foo');
delete options.readFileSync;
options.readPackageSync = failReadPackageSync;
st.throws(
function () { resolve.sync('bar', options); },
readPackageError,
'readPackageSync error is thrown'
);
});
});
+6 -6
View File
@@ -5,7 +5,7 @@ var keys = require('object-keys');
var nodeModulesPaths = require('../lib/node-modules-paths');
var verifyDirs = function verifyDirs(t, start, dirs, moduleDirectories, paths) {
function verifyDirs(t, start, dirs, moduleDirectories, paths) {
var moduleDirs = [].concat(moduleDirectories || 'node_modules');
if (paths) {
for (var k = 0; k < paths.length; ++k) {
@@ -33,7 +33,7 @@ var verifyDirs = function verifyDirs(t, start, dirs, moduleDirectories, paths) {
counts[foundModuleDirs[j]] = true;
}
t.equal(keys(counts).length, 1, 'all found module directories had the same count');
};
}
test('node-modules-paths', function (t) {
t.test('no options', function (t) {
@@ -65,9 +65,9 @@ test('node-modules-paths', function (t) {
});
t.test('with paths=function option', function (t) {
var paths = function paths(request, absoluteStart, getNodeModulesDirs, opts) {
function paths(request, absoluteStart, getNodeModulesDirs, opts) {
return getNodeModulesDirs().concat(path.join(absoluteStart, 'not node modules', request));
};
}
var start = path.join(__dirname, 'resolver');
var dirs = nodeModulesPaths(start, { paths: paths }, 'pkg');
@@ -78,9 +78,9 @@ test('node-modules-paths', function (t) {
});
t.test('with paths=function skipping node modules resolution', function (t) {
var paths = function paths(request, absoluteStart, getNodeModulesDirs, opts) {
function paths(request, absoluteStart, getNodeModulesDirs, opts) {
return [];
};
}
var start = path.join(__dirname, 'resolver');
var dirs = nodeModulesPaths(start, { paths: paths });
t.deepEqual(dirs, [], 'no node_modules was computed');
+2 -2
View File
@@ -6,7 +6,7 @@ var resolve = require('../');
test('$NODE_PATH', function (t) {
t.plan(8);
var isDir = function (dir, cb) {
function isDir(dir, cb) {
if (dir === '/node_path' || dir === 'node_path/x') {
return cb(null, true);
}
@@ -17,7 +17,7 @@ test('$NODE_PATH', function (t) {
if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
return cb(err);
});
};
}
resolve('aaa', {
paths: [
+2 -2
View File
@@ -4,14 +4,14 @@ var resolve = require('../');
var resolverDir = path.join(__dirname, '/pathfilter/deep_ref');
var pathFilterFactory = function (t) {
function pathFilterFactory(t) {
return 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';
};
};
}
test('#62: deep module references and the pathFilter', function (t) {
t.test('deep/ref.js', function (st) {
+2 -2
View File
@@ -268,9 +268,9 @@ test('path iterator', function (t) {
var resolverDir = path.join(__dirname, 'resolver');
var exactIterator = function (x, start, getPackageCandidates, opts) {
function exactIterator(x, start, getPackageCandidates, opts) {
return [path.join(resolverDir, x)];
};
}
resolve('baz', { packageIterator: exactIterator }, function (err, res, pkg) {
if (err) t.fail(err);
+2 -2
View File
@@ -2,7 +2,7 @@ var a = require.resolve('buffer/').replace(process.cwd(), '$CWD');
var b;
var c;
var test = function test() {
function test() {
console.log(a, ': require.resolve, preserveSymlinks ' + (process.execArgv.indexOf('preserve-symlinks') > -1 ? 'true' : 'false'));
console.log(b, ': preserveSymlinks true');
console.log(c, ': preserveSymlinks false');
@@ -11,7 +11,7 @@ var test = function test() {
throw 'async: no match';
}
console.log('async: success! a matched either b or c\n');
};
}
require('resolve')('buffer/', { preserveSymlinks: true }, function (err, result) {
if (err) { throw err; }
+4 -4
View File
@@ -281,9 +281,9 @@ test('other path', function (t) {
test('path iterator', function (t) {
var resolverDir = path.join(__dirname, 'resolver');
var exactIterator = function (x, start, getPackageCandidates, opts) {
function exactIterator(x, start, getPackageCandidates, opts) {
return [path.join(resolverDir, x)];
};
}
t.equal(
resolve.sync('baz', { packageIterator: exactIterator }),
@@ -393,7 +393,7 @@ test('main: false', function (t) {
t.end();
});
var stubStatSync = function stubStatSync(fn) {
function stubStatSync(fn) {
var statSync = fs.statSync;
try {
fs.statSync = function () {
@@ -403,7 +403,7 @@ var stubStatSync = function stubStatSync(fn) {
} finally {
fs.statSync = statSync;
}
};
}
test('#79 - re-throw non ENOENT errors from stat', function (t) {
var dir = path.join(__dirname, 'resolver');