aboutsummaryrefslogtreecommitdiff
path: root/node_modules/resolve/lib
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
committerFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
commitbbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch)
treec58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/resolve/lib
parent003fb34971cf63466184351b4db5f7c67df4f444 (diff)
update packages
Diffstat (limited to 'node_modules/resolve/lib')
-rw-r--r--node_modules/resolve/lib/async.js37
-rw-r--r--node_modules/resolve/lib/core.js51
-rw-r--r--node_modules/resolve/lib/core.json115
-rw-r--r--node_modules/resolve/lib/sync.js65
4 files changed, 183 insertions, 85 deletions
diff --git a/node_modules/resolve/lib/async.js b/node_modules/resolve/lib/async.js
index ef1bde782..296b5ffa8 100644
--- a/node_modules/resolve/lib/async.js
+++ b/node_modules/resolve/lib/async.js
@@ -4,6 +4,16 @@ var path = require('path');
var caller = require('./caller.js');
var nodeModulesPaths = require('./node-modules-paths.js');
+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);
+ });
+};
+
module.exports = function resolve(x, options, callback) {
var cb = callback;
var opts = options || {};
@@ -18,34 +28,27 @@ module.exports = function resolve(x, options, callback) {
});
}
- var isFile = opts.isFile || function (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 isFile = opts.isFile || defaultIsFile;
var readFile = opts.readFile || fs.readFile;
var extensions = opts.extensions || ['.js'];
- var y = opts.basedir || path.dirname(caller());
+ var basedir = opts.basedir || path.dirname(caller());
+ var parent = opts.filename || basedir;
opts.paths = opts.paths || [];
if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
- var res = path.resolve(y, x);
+ var res = path.resolve(basedir, x);
if (x === '..' || x.slice(-1) === '/') res += '/';
- if (/\/$/.test(x) && res === y) {
+ if (/\/$/.test(x) && res === basedir) {
loadAsDirectory(res, opts.package, onfile);
} else loadAsFile(res, opts.package, onfile);
- } else loadNodeModules(x, y, function (err, n, pkg) {
+ } else loadNodeModules(x, basedir, function (err, n, pkg) {
if (err) cb(err);
else if (n) cb(null, n, pkg);
else if (core[x]) return cb(null, x);
else {
- var moduleError = new Error("Cannot find module '" + x + "' from '" + y + "'");
+ var moduleError = new Error("Cannot find module '" + x + "' from '" + parent + "'");
moduleError.code = 'MODULE_NOT_FOUND';
cb(moduleError);
}
@@ -58,7 +61,7 @@ module.exports = function resolve(x, options, callback) {
if (err) cb(err);
else if (d) cb(null, d, pkg);
else {
- var moduleError = new Error("Cannot find module '" + x + "' from '" + y + "'");
+ var moduleError = new Error("Cannot find module '" + x + "' from '" + parent + "'");
moduleError.code = 'MODULE_NOT_FOUND';
cb(moduleError);
}
@@ -183,12 +186,12 @@ module.exports = function resolve(x, options, callback) {
var dir = dirs[0];
var file = path.join(dir, x);
- loadAsFile(file, undefined, onfile);
+ loadAsFile(file, opts.package, onfile);
function onfile(err, m, pkg) {
if (err) return cb(err);
if (m) return cb(null, m, pkg);
- loadAsDirectory(path.join(dir, x), undefined, ondir);
+ loadAsDirectory(path.join(dir, x), opts.package, ondir);
}
function ondir(err, n, pkg) {
diff --git a/node_modules/resolve/lib/core.js b/node_modules/resolve/lib/core.js
index ad9efd132..0877650cc 100644
--- a/node_modules/resolve/lib/core.js
+++ b/node_modules/resolve/lib/core.js
@@ -1,22 +1,53 @@
var current = (process.versions && process.versions.node && process.versions.node.split('.')) || [];
-function versionIncluded(version) {
- if (version === '*') return true;
- var versionParts = version.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) {
- if ((current[i] || 0) >= (versionParts[i] || 0)) return true;
+ var cur = Number(current[i] || 0);
+ var ver = Number(versionParts[i] || 0);
+ 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 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 version in data) { // eslint-disable-line no-restricted-syntax
- if (Object.prototype.hasOwnProperty.call(data, version) && versionIncluded(version)) {
- for (var i = 0; i < data[version].length; ++i) {
- core[data[version][i]] = true;
- }
+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/node_modules/resolve/lib/core.json b/node_modules/resolve/lib/core.json
index 843844ebf..afdfcbc31 100644
--- a/node_modules/resolve/lib/core.json
+++ b/node_modules/resolve/lib/core.json
@@ -1,47 +1,72 @@
{
- "*": [
- "assert",
- "buffer_ieee754",
- "buffer",
- "child_process",
- "cluster",
- "console",
- "constants",
- "crypto",
- "_debugger",
- "dgram",
- "dns",
- "domain",
- "events",
- "freelist",
- "fs",
- "http",
- "https",
- "_linklist",
- "module",
- "net",
- "os",
- "path",
- "punycode",
- "querystring",
- "readline",
- "repl",
- "stream",
- "string_decoder",
- "sys",
- "timers",
- "tls",
- "tty",
- "url",
- "util",
- "vm",
- "zlib"
- ],
- "0.11": [
- "_http_server"
- ],
- "1.0": [
- "process",
- "v8"
- ]
+ "assert": true,
+ "async_hooks": ">= 8",
+ "buffer_ieee754": "< 0.9.7",
+ "buffer": true,
+ "child_process": true,
+ "cluster": true,
+ "console": true,
+ "constants": true,
+ "crypto": true,
+ "_debugger": "< 8",
+ "dgram": true,
+ "dns": true,
+ "domain": true,
+ "events": true,
+ "freelist": "< 6",
+ "fs": true,
+ "fs/promises": ">= 10 && < 10.1",
+ "_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",
+ "node-inspect/lib/internal/inspect_client": ">= 7.6.0",
+ "node-inspect/lib/internal/inspect_repl": ">= 7.6.0",
+ "os": true,
+ "path": true,
+ "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,
+ "string_decoder": true,
+ "sys": true,
+ "timers": true,
+ "_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,
+ "v8/tools/arguments": ">= 10",
+ "v8/tools/codemap": [">= 4.4.0 && < 5", ">= 5.2.0"],
+ "v8/tools/consarray": [">= 4.4.0 && < 5", ">= 5.2.0"],
+ "v8/tools/csvparser": [">= 4.4.0 && < 5", ">= 5.2.0"],
+ "v8/tools/logreader": [">= 4.4.0 && < 5", ">= 5.2.0"],
+ "v8/tools/profile_view": [">= 4.4.0 && < 5", ">= 5.2.0"],
+ "v8/tools/splaytree": [">= 4.4.0 && < 5", ">= 5.2.0"],
+ "v8": ">= 1",
+ "vm": true,
+ "zlib": true
}
diff --git a/node_modules/resolve/lib/sync.js b/node_modules/resolve/lib/sync.js
index bc9e287a1..51e58f02e 100644
--- a/node_modules/resolve/lib/sync.js
+++ b/node_modules/resolve/lib/sync.js
@@ -4,44 +4,57 @@ var path = require('path');
var caller = require('./caller.js');
var nodeModulesPaths = require('./node-modules-paths.js');
+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();
+};
+
module.exports = function (x, options) {
if (typeof x !== 'string') {
throw new TypeError('Path must be a string.');
}
var opts = options || {};
- var isFile = opts.isFile || function (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 isFile = opts.isFile || defaultIsFile;
var readFileSync = opts.readFileSync || fs.readFileSync;
var extensions = opts.extensions || ['.js'];
- var y = opts.basedir || path.dirname(caller());
+ var basedir = opts.basedir || path.dirname(caller());
+ var parent = opts.filename || basedir;
opts.paths = opts.paths || [];
if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) {
- var res = path.resolve(y, x);
+ var res = path.resolve(basedir, x);
if (x === '..' || x.slice(-1) === '/') res += '/';
var m = loadAsFileSync(res) || loadAsDirectorySync(res);
if (m) return m;
} else {
- var n = loadNodeModulesSync(x, y);
+ var n = loadNodeModulesSync(x, basedir);
if (n) return n;
}
if (core[x]) return x;
- var err = new Error("Cannot find module '" + x + "' from '" + y + "'");
+ 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;
}
@@ -54,6 +67,32 @@ module.exports = function (x, options) {
}
}
+ 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(dir, 'package.json');
+
+ if (!isFile(pkgfile)) {
+ return loadpkg(path.dirname(dir));
+ }
+
+ var body = readFileSync(pkgfile);
+
+ try {
+ var pkg = JSON.parse(body);
+ } catch (jsonErr) {}
+
+ if (pkg && opts.packageFilter) {
+ pkg = opts.packageFilter(pkg, dir);
+ }
+
+ return { pkg: pkg, dir: dir };
+ }
+
function loadAsDirectorySync(x) {
var pkgfile = path.join(x, '/package.json');
if (isFile(pkgfile)) {