Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/resolve/lib')
-rw-r--r--deps/npm/node_modules/resolve/lib/async.js320
-rw-r--r--deps/npm/node_modules/resolve/lib/caller.js8
-rw-r--r--deps/npm/node_modules/resolve/lib/core.js53
-rw-r--r--deps/npm/node_modules/resolve/lib/core.json83
-rw-r--r--deps/npm/node_modules/resolve/lib/is-core.js5
-rw-r--r--deps/npm/node_modules/resolve/lib/node-modules-paths.js42
-rw-r--r--deps/npm/node_modules/resolve/lib/normalize-options.js10
-rw-r--r--deps/npm/node_modules/resolve/lib/sync.js199
8 files changed, 0 insertions, 720 deletions
diff --git a/deps/npm/node_modules/resolve/lib/async.js b/deps/npm/node_modules/resolve/lib/async.js
deleted file mode 100644
index 02e80ac80e5..00000000000
--- a/deps/npm/node_modules/resolve/lib/async.js
+++ /dev/null
@@ -1,320 +0,0 @@
-var fs = require('fs');
-var path = require('path');
-var caller = require('./caller');
-var nodeModulesPaths = require('./node-modules-paths');
-var normalizeOptions = require('./normalize-options');
-var isCore = require('is-core-module');
-
-var realpathFS = fs.realpath && typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath;
-
-var defaultIsFile = function isFile(file, cb) {
- fs.stat(file, function (err, stat) {
- if (!err) {
- return cb(null, stat.isFile() || stat.isFIFO());
- }
- if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
- return cb(err);
- });
-};
-
-var defaultIsDir = function isDirectory(dir, cb) {
- fs.stat(dir, function (err, stat) {
- if (!err) {
- return cb(null, stat.isDirectory());
- }
- if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false);
- return cb(err);
- });
-};
-
-var defaultRealpath = function realpath(x, cb) {
- realpathFS(x, function (realpathErr, realPath) {
- if (realpathErr && realpathErr.code !== 'ENOENT') cb(realpathErr);
- else cb(null, realpathErr ? x : realPath);
- });
-};
-
-var maybeRealpath = 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) {
- readFile(pkgfile, function (readFileErr, body) {
- if (readFileErr) cb(readFileErr);
- else {
- try {
- var pkg = JSON.parse(body);
- cb(null, pkg);
- } catch (jsonErr) {
- cb(null);
- }
- }
- });
-};
-
-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) {
- var cb = callback;
- var opts = options;
- if (typeof options === 'function') {
- cb = opts;
- opts = {};
- }
- if (typeof x !== 'string') {
- var err = new TypeError('Path must be a string.');
- return process.nextTick(function () {
- cb(err);
- });
- }
-
- opts = normalizeOptions(x, opts);
-
- var isFile = opts.isFile || defaultIsFile;
- var isDirectory = opts.isDirectory || defaultIsDir;
- var readFile = opts.readFile || fs.readFile;
- 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.');
- return process.nextTick(function () {
- cb(conflictErr);
- });
- }
- var packageIterator = opts.packageIterator;
-
- var extensions = opts.extensions || ['.js'];
- var includeCoreModules = opts.includeCoreModules !== false;
- var basedir = opts.basedir || path.dirname(caller());
- var parent = opts.filename || basedir;
-
- opts.paths = opts.paths || [];
-
- // ensure that `basedir` is an absolute path at this point, resolving against the process' current working directory
- var absoluteStart = path.resolve(basedir);
-
- maybeRealpath(
- realpath,
- absoluteStart,
- opts,
- function (err, realStart) {
- if (err) cb(err);
- else init(realStart);
- }
- );
-
- var res;
- function init(basedir) {
- if ((/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/).test(x)) {
- res = path.resolve(basedir, x);
- if (x === '.' || x === '..' || x.slice(-1) === '/') res += '/';
- if ((/\/$/).test(x) && res === basedir) {
- loadAsDirectory(res, opts.package, onfile);
- } else loadAsFile(res, opts.package, onfile);
- } else if (includeCoreModules && isCore(x)) {
- return cb(null, x);
- } else loadNodeModules(x, basedir, function (err, n, pkg) {
- if (err) cb(err);
- else if (n) {
- return maybeRealpath(realpath, n, opts, function (err, realN) {
- if (err) {
- cb(err);
- } else {
- cb(null, realN, pkg);
- }
- });
- } else {
- var moduleError = new Error("Cannot find module '" + x + "' from '" + parent + "'");
- moduleError.code = 'MODULE_NOT_FOUND';
- cb(moduleError);
- }
- });
- }
-
- function onfile(err, m, pkg) {
- if (err) cb(err);
- else if (m) cb(null, m, pkg);
- else loadAsDirectory(res, function (err, d, pkg) {
- if (err) cb(err);
- else if (d) {
- maybeRealpath(realpath, d, opts, function (err, realD) {
- if (err) {
- cb(err);
- } else {
- cb(null, realD, pkg);
- }
- });
- } else {
- var moduleError = new Error("Cannot find module '" + x + "' from '" + parent + "'");
- moduleError.code = 'MODULE_NOT_FOUND';
- cb(moduleError);
- }
- });
- }
-
- function loadAsFile(x, thePackage, callback) {
- var loadAsFilePackage = thePackage;
- var cb = callback;
- if (typeof loadAsFilePackage === 'function') {
- cb = loadAsFilePackage;
- loadAsFilePackage = undefined;
- }
-
- var exts = [''].concat(extensions);
- load(exts, x, loadAsFilePackage);
-
- function load(exts, x, loadPackage) {
- if (exts.length === 0) return cb(null, undefined, loadPackage);
- var file = x + exts[0];
-
- var pkg = loadPackage;
- if (pkg) onpkg(null, pkg);
- else loadpkg(path.dirname(file), onpkg);
-
- function onpkg(err, pkg_, dir) {
- pkg = pkg_;
- if (err) return cb(err);
- if (dir && pkg && opts.pathFilter) {
- var rfile = path.relative(dir, file);
- var rel = rfile.slice(0, rfile.length - exts[0].length);
- var r = opts.pathFilter(pkg, x, rel);
- if (r) return load(
- [''].concat(extensions.slice()),
- path.resolve(dir, r),
- pkg
- );
- }
- isFile(file, onex);
- }
- function onex(err, ex) {
- if (err) return cb(err);
- if (ex) return cb(null, file, pkg);
- load(exts.slice(1), x, pkg);
- }
- }
- }
-
- function loadpkg(dir, cb) {
- if (dir === '' || dir === '/') return cb(null);
- if (process.platform === 'win32' && (/^\w:[/\\]*$/).test(dir)) {
- return cb(null);
- }
- if ((/[/\\]node_modules[/\\]*$/).test(dir)) return cb(null);
-
- maybeRealpath(realpath, dir, opts, function (unwrapErr, pkgdir) {
- if (unwrapErr) return loadpkg(path.dirname(dir), cb);
- var pkgfile = path.join(pkgdir, 'package.json');
- isFile(pkgfile, function (err, ex) {
- // on err, ex is false
- if (!ex) return loadpkg(path.dirname(dir), cb);
-
- readPackage(readFile, pkgfile, function (err, pkgParam) {
- if (err) cb(err);
-
- var pkg = pkgParam;
-
- if (pkg && opts.packageFilter) {
- pkg = opts.packageFilter(pkg, pkgfile);
- }
- cb(null, pkg, dir);
- });
- });
- });
- }
-
- function loadAsDirectory(x, loadAsDirectoryPackage, callback) {
- var cb = callback;
- var fpkg = loadAsDirectoryPackage;
- if (typeof fpkg === 'function') {
- cb = fpkg;
- fpkg = opts.package;
- }
-
- maybeRealpath(realpath, x, opts, function (unwrapErr, pkgdir) {
- if (unwrapErr) return cb(unwrapErr);
- var pkgfile = path.join(pkgdir, 'package.json');
- isFile(pkgfile, function (err, ex) {
- if (err) return cb(err);
- if (!ex) return loadAsFile(path.join(x, 'index'), fpkg, cb);
-
- readPackage(readFile, pkgfile, function (err, pkgParam) {
- if (err) return cb(err);
-
- var pkg = pkgParam;
-
- if (pkg && opts.packageFilter) {
- pkg = opts.packageFilter(pkg, pkgfile);
- }
-
- if (pkg && pkg.main) {
- if (typeof pkg.main !== 'string') {
- var mainError = new TypeError('package “' + pkg.name + '” `main` must be a string');
- mainError.code = 'INVALID_PACKAGE_MAIN';
- return cb(mainError);
- }
- if (pkg.main === '.' || pkg.main === './') {
- pkg.main = 'index';
- }
- loadAsFile(path.resolve(x, pkg.main), pkg, function (err, m, pkg) {
- if (err) return cb(err);
- if (m) return cb(null, m, pkg);
- if (!pkg) return loadAsFile(path.join(x, 'index'), pkg, cb);
-
- var dir = path.resolve(x, pkg.main);
- loadAsDirectory(dir, pkg, function (err, n, pkg) {
- if (err) return cb(err);
- if (n) return cb(null, n, pkg);
- loadAsFile(path.join(x, 'index'), pkg, cb);
- });
- });
- return;
- }
-
- loadAsFile(path.join(x, '/index'), pkg, cb);
- });
- });
- });
- }
-
- function processDirs(cb, dirs) {
- if (dirs.length === 0) return cb(null, undefined);
- var dir = dirs[0];
-
- isDirectory(path.dirname(dir), isdir);
-
- function isdir(err, isdir) {
- if (err) return cb(err);
- if (!isdir) return processDirs(cb, dirs.slice(1));
- loadAsFile(dir, opts.package, onfile);
- }
-
- function onfile(err, m, pkg) {
- if (err) return cb(err);
- if (m) return cb(null, m, pkg);
- loadAsDirectory(dir, opts.package, ondir);
- }
-
- function ondir(err, n, pkg) {
- if (err) return cb(err);
- if (n) return cb(null, n, pkg);
- processDirs(cb, dirs.slice(1));
- }
- }
- function loadNodeModules(x, start, cb) {
- var thunk = function () { return getPackageCandidates(x, start, opts); };
- processDirs(
- cb,
- packageIterator ? packageIterator(x, start, thunk, opts) : thunk()
- );
- }
-};
diff --git a/deps/npm/node_modules/resolve/lib/caller.js b/deps/npm/node_modules/resolve/lib/caller.js
deleted file mode 100644
index b14a2804ae8..00000000000
--- a/deps/npm/node_modules/resolve/lib/caller.js
+++ /dev/null
@@ -1,8 +0,0 @@
-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;
- return stack[2].getFileName();
-};
diff --git a/deps/npm/node_modules/resolve/lib/core.js b/deps/npm/node_modules/resolve/lib/core.js
deleted file mode 100644
index c417d23c5a8..00000000000
--- a/deps/npm/node_modules/resolve/lib/core.js
+++ /dev/null
@@ -1,53 +0,0 @@
-var current = (process.versions && process.versions.node && process.versions.node.split('.')) || [];
-
-function specifierIncluded(specifier) {
- var parts = specifier.split(' ');
- var op = parts.length > 1 ? parts[0] : '=';
- var versionParts = (parts.length > 1 ? parts[1] : parts[0]).split('.');
-
- for (var i = 0; i < 3; ++i) {
- var cur = parseInt(current[i] || 0, 10);
- var ver = parseInt(versionParts[i] || 0, 10);
- if (cur === ver) {
- continue; // eslint-disable-line no-restricted-syntax, no-continue
- }
- if (op === '<') {
- return cur < ver;
- } else if (op === '>=') {
- return cur >= ver;
- } else {
- return false;
- }
- }
- return op === '>=';
-}
-
-function matchesRange(range) {
- var specifiers = range.split(/ ?&& ?/);
- if (specifiers.length === 0) { return false; }
- for (var i = 0; i < specifiers.length; ++i) {
- if (!specifierIncluded(specifiers[i])) { return false; }
- }
- return true;
-}
-
-function versionIncluded(specifierValue) {
- if (typeof specifierValue === 'boolean') { return specifierValue; }
- if (specifierValue && typeof specifierValue === 'object') {
- for (var i = 0; i < specifierValue.length; ++i) {
- if (matchesRange(specifierValue[i])) { return true; }
- }
- return false;
- }
- return matchesRange(specifierValue);
-}
-
-var data = require('./core.json');
-
-var core = {};
-for (var mod in data) { // eslint-disable-line no-restricted-syntax
- if (Object.prototype.hasOwnProperty.call(data, mod)) {
- core[mod] = versionIncluded(data[mod]);
- }
-}
-module.exports = core;
diff --git a/deps/npm/node_modules/resolve/lib/core.json b/deps/npm/node_modules/resolve/lib/core.json
deleted file mode 100644
index 0238b61a4c7..00000000000
--- a/deps/npm/node_modules/resolve/lib/core.json
+++ /dev/null
@@ -1,83 +0,0 @@
-{
- "assert": true,
- "assert/strict": ">= 15",
- "async_hooks": ">= 8",
- "buffer_ieee754": "< 0.9.7",
- "buffer": true,
- "child_process": true,
- "cluster": true,
- "console": true,
- "constants": true,
- "crypto": true,
- "_debug_agent": ">= 1 && < 8",
- "_debugger": "< 8",
- "dgram": true,
- "diagnostics_channel": ">= 15.1",
- "dns": true,
- "dns/promises": ">= 15",
- "domain": ">= 0.7.12",
- "events": true,
- "freelist": "< 6",
- "fs": true,
- "fs/promises": [">= 10 && < 10.1", ">= 14"],
- "_http_agent": ">= 0.11.1",
- "_http_client": ">= 0.11.1",
- "_http_common": ">= 0.11.1",
- "_http_incoming": ">= 0.11.1",
- "_http_outgoing": ">= 0.11.1",
- "_http_server": ">= 0.11.1",
- "http": true,
- "http2": ">= 8.8",
- "https": true,
- "inspector": ">= 8.0.0",
- "_linklist": "< 8",
- "module": true,
- "net": true,
- "node-inspect/lib/_inspect": ">= 7.6.0 && < 12",
- "node-inspect/lib/internal/inspect_client": ">= 7.6.0 && < 12",
- "node-inspect/lib/internal/inspect_repl": ">= 7.6.0 && < 12",
- "os": true,
- "path": true,
- "path/posix": ">= 15.3",
- "path/win32": ">= 15.3",
- "perf_hooks": ">= 8.5",
- "process": ">= 1",
- "punycode": true,
- "querystring": true,
- "readline": true,
- "repl": true,
- "smalloc": ">= 0.11.5 && < 3",
- "_stream_duplex": ">= 0.9.4",
- "_stream_transform": ">= 0.9.4",
- "_stream_wrap": ">= 1.4.1",
- "_stream_passthrough": ">= 0.9.4",
- "_stream_readable": ">= 0.9.4",
- "_stream_writable": ">= 0.9.4",
- "stream": true,
- "stream/promises": ">= 15",
- "string_decoder": true,
- "sys": [">= 0.6 && < 0.7", ">= 0.8"],
- "timers": true,
- "timers/promises": ">= 15",
- "_tls_common": ">= 0.11.13",
- "_tls_legacy": ">= 0.11.3 && < 10",
- "_tls_wrap": ">= 0.11.3",
- "tls": true,
- "trace_events": ">= 10",
- "tty": true,
- "url": true,
- "util": true,
- "util/types": ">= 15.3",
- "v8/tools/arguments": ">= 10 && < 12",
- "v8/tools/codemap": [">= 4.4.0 && < 5", ">= 5.2.0 && < 12"],
- "v8/tools/consarray": [">= 4.4.0 && < 5", ">= 5.2.0 && < 12"],
- "v8/tools/csvparser": [">= 4.4.0 && < 5", ">= 5.2.0 && < 12"],
- "v8/tools/logreader": [">= 4.4.0 && < 5", ">= 5.2.0 && < 12"],
- "v8/tools/profile_view": [">= 4.4.0 && < 5", ">= 5.2.0 && < 12"],
- "v8/tools/splaytree": [">= 4.4.0 && < 5", ">= 5.2.0 && < 12"],
- "v8": ">= 1",
- "vm": true,
- "wasi": ">= 13.4 && < 13.5",
- "worker_threads": ">= 11.7",
- "zlib": true
-}
diff --git a/deps/npm/node_modules/resolve/lib/is-core.js b/deps/npm/node_modules/resolve/lib/is-core.js
deleted file mode 100644
index 537f5c782ff..00000000000
--- a/deps/npm/node_modules/resolve/lib/is-core.js
+++ /dev/null
@@ -1,5 +0,0 @@
-var isCoreModule = require('is-core-module');
-
-module.exports = function isCore(x) {
- return isCoreModule(x);
-};
diff --git a/deps/npm/node_modules/resolve/lib/node-modules-paths.js b/deps/npm/node_modules/resolve/lib/node-modules-paths.js
deleted file mode 100644
index 2b43813a7a5..00000000000
--- a/deps/npm/node_modules/resolve/lib/node-modules-paths.js
+++ /dev/null
@@ -1,42 +0,0 @@
-var path = require('path');
-var parse = path.parse || require('path-parse');
-
-var getNodeModulesDirs = function getNodeModulesDirs(absoluteStart, modules) {
- var prefix = '/';
- if ((/^([A-Za-z]:)/).test(absoluteStart)) {
- prefix = '';
- } else if ((/^\\\\/).test(absoluteStart)) {
- prefix = '\\\\';
- }
-
- var paths = [absoluteStart];
- var parsed = parse(absoluteStart);
- while (parsed.dir !== paths[paths.length - 1]) {
- paths.push(parsed.dir);
- parsed = parse(parsed.dir);
- }
-
- return paths.reduce(function (dirs, aPath) {
- return dirs.concat(modules.map(function (moduleDir) {
- return path.resolve(prefix, aPath, moduleDir);
- }));
- }, []);
-};
-
-module.exports = function nodeModulesPaths(start, opts, request) {
- var modules = opts && opts.moduleDirectory
- ? [].concat(opts.moduleDirectory)
- : ['node_modules'];
-
- if (opts && typeof opts.paths === 'function') {
- return opts.paths(
- request,
- start,
- function () { return getNodeModulesDirs(start, modules); },
- opts
- );
- }
-
- var dirs = getNodeModulesDirs(start, modules);
- return opts && opts.paths ? dirs.concat(opts.paths) : dirs;
-};
diff --git a/deps/npm/node_modules/resolve/lib/normalize-options.js b/deps/npm/node_modules/resolve/lib/normalize-options.js
deleted file mode 100644
index 4b56904eaea..00000000000
--- a/deps/npm/node_modules/resolve/lib/normalize-options.js
+++ /dev/null
@@ -1,10 +0,0 @@
-module.exports = function (x, opts) {
- /**
- * This file is purposefully a passthrough. It's expected that third-party
- * environments will override it at runtime in order to inject special logic
- * into `resolve` (by manipulating the options). One such example is the PnP
- * code path in Yarn.
- */
-
- return opts || {};
-};
diff --git a/deps/npm/node_modules/resolve/lib/sync.js b/deps/npm/node_modules/resolve/lib/sync.js
deleted file mode 100644
index ef9bd803cee..00000000000
--- a/deps/npm/node_modules/resolve/lib/sync.js
+++ /dev/null
@@ -1,199 +0,0 @@
-var isCore = require('is-core-module');
-var fs = require('fs');
-var path = require('path');
-var caller = require('./caller');
-var nodeModulesPaths = require('./node-modules-paths');
-var normalizeOptions = require('./normalize-options');
-
-var realpathFS = fs.realpathSync && typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync;
-
-var defaultIsFile = function isFile(file) {
- try {
- var stat = fs.statSync(file);
- } catch (e) {
- if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
- throw e;
- }
- return stat.isFile() || stat.isFIFO();
-};
-
-var defaultIsDir = function isDirectory(dir) {
- try {
- var stat = fs.statSync(dir);
- } catch (e) {
- if (e && (e.code === 'ENOENT' || e.code === 'ENOTDIR')) return false;
- throw e;
- }
- return stat.isDirectory();
-};
-
-var defaultRealpathSync = function realpathSync(x) {
- try {
- return realpathFS(x);
- } catch (realpathErr) {
- if (realpathErr.code !== 'ENOENT') {
- throw realpathErr;
- }
- }
- return x;
-};
-
-var maybeRealpathSync = function maybeRealpathSync(realpathSync, x, opts) {
- if (opts && opts.preserveSymlinks === false) {
- return realpathSync(x);
- }
- return x;
-};
-
-var defaultReadPackageSync = 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) {
- 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.');
- }
- var opts = normalizeOptions(x, options);
-
- var isFile = opts.isFile || defaultIsFile;
- var readFileSync = opts.readFileSync || fs.readFileSync;
- var isDirectory = opts.isDirectory || defaultIsDir;
- var realpathSync = opts.realpathSync || defaultRealpathSync;
- var readPackageSync = opts.readPackageSync || defaultReadPackageSync;
- if (opts.readFileSync && opts.readPackageSync) {
- throw new TypeError('`readFileSync` and `readPackageSync` are mutually exclusive.');
- }
- var packageIterator = opts.packageIterator;
-
- var extensions = opts.extensions || ['.js'];
- var includeCoreModules = opts.includeCoreModules !== false;
- var basedir = opts.basedir || path.dirname(caller());
- var parent = opts.filename || basedir;
-
- opts.paths = opts.paths || [];
-
- // ensure that `basedir` is an absolute path at this point, resolving against the process' current working directory
- var absoluteStart = maybeRealpathSync(realpathSync, path.resolve(basedir), opts);
-
- if ((/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/).test(x)) {
- var res = path.resolve(absoluteStart, x);
- if (x === '.' || x === '..' || x.slice(-1) === '/') res += '/';
- var m = loadAsFileSync(res) || loadAsDirectorySync(res);
- if (m) return maybeRealpathSync(realpathSync, m, opts);
- } else if (includeCoreModules && isCore(x)) {
- return x;
- } else {
- var n = loadNodeModulesSync(x, absoluteStart);
- if (n) return maybeRealpathSync(realpathSync, n, opts);
- }
-
- var err = new Error("Cannot find module '" + x + "' from '" + parent + "'");
- err.code = 'MODULE_NOT_FOUND';
- throw err;
-
- function loadAsFileSync(x) {
- var pkg = loadpkg(path.dirname(x));
-
- if (pkg && pkg.dir && pkg.pkg && opts.pathFilter) {
- var rfile = path.relative(pkg.dir, x);
- var r = opts.pathFilter(pkg.pkg, x, rfile);
- if (r) {
- x = path.resolve(pkg.dir, r); // eslint-disable-line no-param-reassign
- }
- }
-
- if (isFile(x)) {
- return x;
- }
-
- for (var i = 0; i < extensions.length; i++) {
- var file = x + extensions[i];
- if (isFile(file)) {
- return file;
- }
- }
- }
-
- function loadpkg(dir) {
- if (dir === '' || dir === '/') return;
- if (process.platform === 'win32' && (/^\w:[/\\]*$/).test(dir)) {
- return;
- }
- if ((/[/\\]node_modules[/\\]*$/).test(dir)) return;
-
- var pkgfile = path.join(maybeRealpathSync(realpathSync, dir, opts), 'package.json');
-
- if (!isFile(pkgfile)) {
- return loadpkg(path.dirname(dir));
- }
-
- var pkg = readPackageSync(readFileSync, pkgfile);
-
- if (pkg && opts.packageFilter) {
- // v2 will pass pkgfile
- pkg = opts.packageFilter(pkg, /*pkgfile,*/ dir); // eslint-disable-line spaced-comment
- }
-
- return { pkg: pkg, dir: dir };
- }
-
- function loadAsDirectorySync(x) {
- var pkgfile = path.join(maybeRealpathSync(realpathSync, x, opts), '/package.json');
- if (isFile(pkgfile)) {
- try {
- var pkg = readPackageSync(readFileSync, pkgfile);
- } catch (e) {}
-
- if (pkg && opts.packageFilter) {
- // v2 will pass pkgfile
- pkg = opts.packageFilter(pkg, /*pkgfile,*/ x); // eslint-disable-line spaced-comment
- }
-
- if (pkg && pkg.main) {
- if (typeof pkg.main !== 'string') {
- var mainError = new TypeError('package “' + pkg.name + '” `main` must be a string');
- mainError.code = 'INVALID_PACKAGE_MAIN';
- throw mainError;
- }
- if (pkg.main === '.' || pkg.main === './') {
- pkg.main = 'index';
- }
- try {
- var m = loadAsFileSync(path.resolve(x, pkg.main));
- if (m) return m;
- var n = loadAsDirectorySync(path.resolve(x, pkg.main));
- if (n) return n;
- } catch (e) {}
- }
- }
-
- return loadAsFileSync(path.join(x, '/index'));
- }
-
- function loadNodeModulesSync(x, start) {
- 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(path.dirname(dir))) {
- var m = loadAsFileSync(dir);
- if (m) return m;
- var n = loadAsDirectorySync(dir);
- if (n) return n;
- }
- }
- }
-};