diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-09-20 02:56:13 +0200 |
commit | bbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch) | |
tree | c58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/resolve | |
parent | 003fb34971cf63466184351b4db5f7c67df4f444 (diff) | |
download | wallet-core-bbff7403fbf46f9ad92240ac213df8d30ef31b64.tar.xz |
update packages
Diffstat (limited to 'node_modules/resolve')
-rw-r--r-- | node_modules/resolve/.npmignore | 7 | ||||
-rw-r--r-- | node_modules/resolve/.travis.yml | 96 | ||||
-rw-r--r-- | node_modules/resolve/appveyor.yml | 7 | ||||
-rw-r--r-- | node_modules/resolve/lib/async.js | 37 | ||||
-rw-r--r-- | node_modules/resolve/lib/core.js | 51 | ||||
-rw-r--r-- | node_modules/resolve/lib/core.json | 115 | ||||
-rw-r--r-- | node_modules/resolve/lib/sync.js | 65 | ||||
-rw-r--r-- | node_modules/resolve/package.json | 10 | ||||
-rw-r--r-- | node_modules/resolve/readme.markdown | 71 | ||||
-rw-r--r-- | node_modules/resolve/test/core.js | 61 | ||||
-rw-r--r-- | node_modules/resolve/test/filter.js | 23 | ||||
-rw-r--r-- | node_modules/resolve/test/filter_sync.js | 14 | ||||
-rw-r--r-- | node_modules/resolve/test/pathfilter.js | 87 | ||||
-rw-r--r-- | node_modules/resolve/test/resolver.js | 65 | ||||
-rw-r--r-- | node_modules/resolve/test/resolver/symlinked/.npmignore | 1 | ||||
-rw-r--r-- | node_modules/resolve/test/resolver/symlinked/_/.npmignore | 1 | ||||
-rw-r--r-- | node_modules/resolve/test/resolver_sync.js | 44 | ||||
-rw-r--r-- | node_modules/resolve/test/symlinks.js | 4 |
18 files changed, 554 insertions, 205 deletions
diff --git a/node_modules/resolve/.npmignore b/node_modules/resolve/.npmignore deleted file mode 100644 index f83345172..000000000 --- a/node_modules/resolve/.npmignore +++ /dev/null @@ -1,7 +0,0 @@ -# gitignore -node_modules - -# Only apps should have lockfiles -npm-shrinkwrap.json -package-lock.json -yarn.lock diff --git a/node_modules/resolve/.travis.yml b/node_modules/resolve/.travis.yml index 25709b3d6..21a33ce90 100644 --- a/node_modules/resolve/.travis.yml +++ b/node_modules/resolve/.travis.yml @@ -2,11 +2,13 @@ language: node_js os: - linux node_js: - - "8.2" + - "10.4" + - "9.11" + - "8.11" - "7.10" - - "6.11" + - "6.14" - "5.12" - - "4.8" + - "4.9" - "iojs-v3.3" - "iojs-v2.5" - "iojs-v1.8" @@ -15,10 +17,10 @@ node_js: - "0.8" - "0.6" before_install: - - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then npm install -g npm@1.3 ; elif [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then case "$(npm --version)" in 1.*) npm install -g npm@1.4.28 ;; 2.*) npm install -g npm@2 ;; esac ; fi' - - 'if [ "${TRAVIS_NODE_VERSION}" != "0.6" ] && [ "${TRAVIS_NODE_VERSION}" != "0.9" ]; then if [ "${TRAVIS_NODE_VERSION%${TRAVIS_NODE_VERSION#[0-9]}}" = "0" ] || [ "${TRAVIS_NODE_VERSION:0:4}" = "iojs" ]; then npm install -g npm@4.5 ; else npm install -g npm; fi; fi' + - 'case "${TRAVIS_NODE_VERSION}" in 0.*) export NPM_CONFIG_STRICT_SSL=false ;; esac' + - 'nvm install-latest-npm' install: - - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ]; then (nvm install 0.8 && npm install -g npm@1.3 && npm install -g npm@1.4.28 && npm install -g npm@2 && npm install); else npm install; fi;' + - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;' script: - 'if [ -n "${PRETEST-}" ]; then npm run pretest ; fi' - 'if [ -n "${POSTTEST-}" ]; then npm run posttest ; fi' @@ -30,8 +32,56 @@ env: matrix: fast_finish: true include: - - node_js: "node" + - node_js: "lts/*" env: PRETEST=true + - node_js: "10.3" + env: TEST=true ALLOW_FAILURE=true + - node_js: "10.2" + env: TEST=true ALLOW_FAILURE=true + - node_js: "10.1" + env: TEST=true ALLOW_FAILURE=true + - node_js: "10.0" + env: TEST=true ALLOW_FAILURE=true + - node_js: "9.10" + env: TEST=true ALLOW_FAILURE=true + - node_js: "9.9" + env: TEST=true ALLOW_FAILURE=true + - node_js: "9.8" + env: TEST=true ALLOW_FAILURE=true + - node_js: "9.7" + env: TEST=true ALLOW_FAILURE=true + - node_js: "9.6" + env: TEST=true ALLOW_FAILURE=true + - node_js: "9.5" + env: TEST=true ALLOW_FAILURE=true + - node_js: "9.4" + env: TEST=true ALLOW_FAILURE=true + - node_js: "9.3" + env: TEST=true ALLOW_FAILURE=true + - node_js: "9.2" + env: TEST=true ALLOW_FAILURE=true + - node_js: "9.1" + env: TEST=true ALLOW_FAILURE=true + - node_js: "9.0" + env: TEST=true ALLOW_FAILURE=true + - node_js: "8.10" + env: TEST=true ALLOW_FAILURE=true + - node_js: "8.9" + env: TEST=true ALLOW_FAILURE=true + - node_js: "8.8" + env: TEST=true ALLOW_FAILURE=true + - node_js: "8.7" + env: TEST=true ALLOW_FAILURE=true + - node_js: "8.6" + env: TEST=true ALLOW_FAILURE=true + - node_js: "8.5" + env: TEST=true ALLOW_FAILURE=true + - node_js: "8.4" + env: TEST=true ALLOW_FAILURE=true + - node_js: "8.3" + env: TEST=true ALLOW_FAILURE=true + - node_js: "8.2" + env: TEST=true ALLOW_FAILURE=true - node_js: "8.1" env: TEST=true ALLOW_FAILURE=true - node_js: "8.0" @@ -56,6 +106,12 @@ matrix: env: TEST=true ALLOW_FAILURE=true - node_js: "7.0" env: TEST=true ALLOW_FAILURE=true + - node_js: "6.13" + env: TEST=true ALLOW_FAILURE=true + - node_js: "6.12" + env: TEST=true ALLOW_FAILURE=true + - node_js: "6.11" + env: TEST=true ALLOW_FAILURE=true - node_js: "6.10" env: TEST=true ALLOW_FAILURE=true - node_js: "6.9" @@ -102,6 +158,8 @@ matrix: env: TEST=true ALLOW_FAILURE=true - node_js: "5.0" env: TEST=true ALLOW_FAILURE=true + - node_js: "4.8" + env: TEST=true ALLOW_FAILURE=true - node_js: "4.7" env: TEST=true ALLOW_FAILURE=true - node_js: "4.6" @@ -156,30 +214,6 @@ matrix: env: TEST=true ALLOW_FAILURE=true - node_js: "0.4" env: TEST=true ALLOW_FAILURE=true - ##- node_js: "7" - #env: TEST=true - #os: osx - #- node_js: "6" - #env: TEST=true - #os: osx - #- node_js: "5" - #env: TEST=true - #os: osx - #- node_js: "4" - #env: TEST=true - #os: osx - #- node_js: "iojs" - #env: TEST=true - #os: osx - #- node_js: "0.12" - #env: TEST=true - #os: osx - #- node_js: "0.10" - #env: TEST=true - #os: osx - #- node_js: "0.8" - #env: TEST=true - #os: osx allow_failures: - os: osx - env: TEST=true ALLOW_FAILURE=true diff --git a/node_modules/resolve/appveyor.yml b/node_modules/resolve/appveyor.yml index f54a1b609..cc73cc18f 100644 --- a/node_modules/resolve/appveyor.yml +++ b/node_modules/resolve/appveyor.yml @@ -4,6 +4,8 @@ build: off environment: matrix: + - nodejs_version: "9" + - nodejs_version: "8" - nodejs_version: "7" - nodejs_version: "6" - nodejs_version: "5" @@ -18,6 +20,7 @@ environment: matrix: # fast_finish: true allow_failures: + - nodejs_version: "0.8" - nodejs_version: "0.6" platform: @@ -28,8 +31,8 @@ platform: install: # Get the latest stable version of Node.js or io.js - ps: Install-Product node $env:nodejs_version $env:platform - - IF %nodejs_version% EQU 0.6 npm -g install npm@1.3 - - IF %nodejs_version% EQU 0.8 npm -g install npm@2 + - IF %nodejs_version% EQU 0.6 npm config set strict-ssl false && npm -g install npm@1.3 + - IF %nodejs_version% EQU 0.8 npm config set strict-ssl false && npm -g install npm@1.4.28 && npm install -g npm@4.5 - set PATH=%APPDATA%\npm;%PATH% #- IF %nodejs_version% NEQ 0.6 AND %nodejs_version% NEQ 0.8 npm -g install npm # install modules 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)) { diff --git a/node_modules/resolve/package.json b/node_modules/resolve/package.json index 1f8d59786..2ce67a98d 100644 --- a/node_modules/resolve/package.json +++ b/node_modules/resolve/package.json @@ -1,10 +1,10 @@ { "name": "resolve", "description": "resolve like require.resolve() on behalf of files asynchronously and synchronously", - "version": "1.4.0", + "version": "1.8.1", "repository": { "type": "git", - "url": "git://github.com/substack/node-resolve.git" + "url": "git://github.com/browserify/resolve.git" }, "main": "index.js", "keywords": [ @@ -21,12 +21,12 @@ "test": "npm run --silent tests-only" }, "devDependencies": { - "@ljharb/eslint-config": "^12.2.0", - "eslint": "^4.3.0", + "@ljharb/eslint-config": "^12.2.1", + "eslint": "^4.19.1", "object-keys": "^1.0.11", "safe-publish-latest": "^1.1.1", "tap": "0.4.13", - "tape": "^4.7.0" + "tape": "^4.9.0" }, "license": "MIT", "author": { diff --git a/node_modules/resolve/readme.markdown b/node_modules/resolve/readme.markdown index 1bb67d434..47f799c50 100644 --- a/node_modules/resolve/readme.markdown +++ b/node_modules/resolve/readme.markdown @@ -5,17 +5,17 @@ algorithm](https://nodejs.org/api/modules.html#modules_all_together) such that you can `require.resolve()` on behalf of a file asynchronously and synchronously -[![build status](https://secure.travis-ci.org/substack/node-resolve.png)](http://travis-ci.org/substack/node-resolve) +[![build status](https://secure.travis-ci.org/browserify/node-resolve.png)](http://travis-ci.org/browserify/node-resolve) # example asynchronously resolve: -``` js +```js var resolve = require('resolve'); resolve('tap', { basedir: __dirname }, function (err, res) { - if (err) console.error(err) - else console.log(res) + if (err) console.error(err); + else console.log(res); }); ``` @@ -26,7 +26,7 @@ $ node example/async.js synchronously resolve: -``` js +```js var resolve = require('resolve'); var res = resolve.sync('tap', { basedir: __dirname }); console.log(res); @@ -39,8 +39,8 @@ $ node example/sync.js # methods -``` js -var resolve = require('resolve') +```js +var resolve = require('resolve'); ``` ## resolve(id, opts={}, cb) @@ -59,17 +59,17 @@ options are: * opts.isFile - function to asynchronously test whether a file exists -* opts.packageFilter - transform the parsed package.json contents before looking -at the "main" field +* `opts.packageFilter(pkg, pkgfile)` - transform the parsed package.json contents before looking at the "main" field + * pkg - package data + * pkgfile - path to package.json -* opts.pathFilter(pkg, path, relativePath) - transform a path within a package +* `opts.pathFilter(pkg, path, relativePath)` - transform a path within a package * pkg - package data * path - the path being resolved * relativePath - the path relative from the package.json location * returns - a relative path that will be joined from the package.json location -* opts.paths - require.paths array to use if nothing is found on the normal -node_modules recursive walk (probably don't use this) +* opts.paths - require.paths array to use if nothing is found on the normal `node_modules` recursive walk (probably don't use this) * opts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: `"node_modules"` @@ -80,17 +80,19 @@ This is the way Node resolves dependencies when executed with the [--preserve-sy default `opts` values: -``` javascript +```js { paths: [], basedir: __dirname, - extensions: [ '.js' ], + extensions: ['.js'], readFile: fs.readFile, - isFile: function (file, cb) { + isFile: function isFile(file, cb) { fs.stat(file, function (err, stat) { - if (err && err.code === 'ENOENT') cb(null, false) - else if (err) cb(err) - else cb(null, stat.isFile()) + if (!err) { + return cb(null, stat.isFile() || stat.isFIFO()); + } + if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false); + return cb(err); }); }, moduleDirectory: 'node_modules', @@ -113,11 +115,17 @@ options are: * opts.isFile - function to synchronously test whether a file exists -* `opts.packageFilter(pkg, pkgfile)` - transform the parsed package.json -* contents before looking at the "main" field +* `opts.packageFilter(pkg, dir)` - transform the parsed package.json contents before looking at the "main" field + * pkg - package data + * dir - directory for package.json (Note: the second argument will change to "pkgfile" in v2) + +* `opts.pathFilter(pkg, path, relativePath)` - transform a path within a package + * pkg - package data + * path - the path being resolved + * relativePath - the path relative from the package.json location + * returns - a relative path that will be joined from the package.json location -* opts.paths - require.paths array to use if nothing is found on the normal -node_modules recursive walk (probably don't use this) +* opts.paths - require.paths array to use if nothing is found on the normal `node_modules` recursive walk (probably don't use this) * opts.moduleDirectory - directory (or directories) in which to recursively look for modules. default: `"node_modules"` @@ -128,20 +136,25 @@ This is the way Node resolves dependencies when executed with the [--preserve-sy default `opts` values: -``` javascript +```js { paths: [], basedir: __dirname, - extensions: [ '.js' ], + extensions: ['.js'], readFileSync: fs.readFileSync, - isFile: function (file) { - try { return fs.statSync(file).isFile() } - catch (e) { return false } + isFile: 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(); }, moduleDirectory: 'node_modules', preserveSymlinks: true } -```` +``` ## resolve.isCore(pkg) @@ -151,7 +164,7 @@ Return whether a package is in core. With [npm](https://npmjs.org) do: -``` +```sh npm install resolve ``` diff --git a/node_modules/resolve/test/core.js b/node_modules/resolve/test/core.js index 1182e0c0b..33d9f3294 100644 --- a/node_modules/resolve/test/core.js +++ b/node_modules/resolve/test/core.js @@ -1,4 +1,5 @@ var test = require('tape'); +var keys = require('object-keys'); var resolve = require('../'); test('core modules', function (t) { @@ -13,15 +14,67 @@ test('core modules', function (t) { }); t.test('core list', function (st) { - st.plan(resolve.core.length); + var cores = keys(resolve.core); + st.plan(cores.length); - for (var i = 0; i < resolve.core.length; ++i) { + for (var i = 0; i < cores.length; ++i) { + var mod = cores[i]; + if (resolve.core[mod]) { + st.doesNotThrow( + function () { require(mod); }, // eslint-disable-line no-loop-func + mod + ' supported; requiring does not throw' + ); + } else { + st.throws( + function () { require(mod); }, // eslint-disable-line no-loop-func + mod + ' not supported; requiring throws' + ); + } + } + + st.end(); + }); + + t.test('core via repl module', { skip: !resolve.core.repl }, function (st) { + var libs = require('repl')._builtinLibs; // eslint-disable-line no-underscore-dangle + if (!libs) { + st.skip('module.builtinModules does not exist'); + return st.end(); + } + for (var i = 0; i < libs.length; ++i) { + var mod = libs[i]; + st.ok(resolve.core[mod], mod + ' is a core module'); st.doesNotThrow( - function () { require(resolve.core[i]); }, // eslint-disable-line no-loop-func - 'requiring ' + resolve.core[i] + ' does not throw' + function () { require(mod); }, // eslint-disable-line no-loop-func + 'requiring ' + mod + ' does not throw' ); } + st.end(); + }); + t.test('core via builtinModules list', { skip: !resolve.core.module }, function (st) { + var libs = require('module').builtinModules; + if (!libs) { + st.skip('module.builtinModules does not exist'); + return st.end(); + } + var blacklist = [ + '_debug_agent', + 'v8/tools/tickprocessor-driver', + 'v8/tools/SourceMap', + 'v8/tools/tickprocessor', + 'v8/tools/profile' + ]; + for (var i = 0; i < libs.length; ++i) { + var mod = libs[i]; + if (blacklist.indexOf(mod) === -1) { + st.ok(resolve.core[mod], mod + ' is a core module'); + st.doesNotThrow( + function () { require(mod); }, // eslint-disable-line no-loop-func + 'requiring ' + mod + ' does not throw' + ); + } + } st.end(); }); diff --git a/node_modules/resolve/test/filter.js b/node_modules/resolve/test/filter.js index 51a753f16..dfc622a87 100644 --- a/node_modules/resolve/test/filter.js +++ b/node_modules/resolve/test/filter.js @@ -3,17 +3,32 @@ var test = require('tape'); var resolve = require('../'); test('filter', function (t) { - t.plan(2); + t.plan(4); var dir = path.join(__dirname, 'resolver'); + var packageFilterArgs; resolve('./baz', { basedir: dir, - packageFilter: function (pkg) { + packageFilter: function (pkg, pkgfile) { pkg.main = 'doom'; + packageFilterArgs = [pkg, pkgfile]; return pkg; } }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, path.join(dir, 'baz/doom.js')); - t.equal(pkg.main, 'doom'); + + t.equal(res, path.join(dir, 'baz/doom.js'), 'changing the package "main" works'); + + var packageData = packageFilterArgs[0]; + t.equal(pkg, packageData, 'first packageFilter argument is "pkg"'); + t.equal(packageData.main, 'doom', 'package "main" was altered'); + + var packageFile = packageFilterArgs[1]; + t.equal( + packageFile, + path.join(dir, 'baz/package.json'), + 'second packageFilter argument is "pkgfile"' + ); + + t.end(); }); }); diff --git a/node_modules/resolve/test/filter_sync.js b/node_modules/resolve/test/filter_sync.js index fd4e97c28..064052e16 100644 --- a/node_modules/resolve/test/filter_sync.js +++ b/node_modules/resolve/test/filter_sync.js @@ -4,13 +4,23 @@ var resolve = require('../'); test('filter', function (t) { var dir = path.join(__dirname, 'resolver'); + var packageFilterArgs; var res = resolve.sync('./baz', { basedir: dir, - packageFilter: function (pkg) { + packageFilter: function (pkg, dir) { pkg.main = 'doom'; + packageFilterArgs = [pkg, dir]; return pkg; } }); - t.equal(res, path.join(dir, 'baz/doom.js')); + + t.equal(res, path.join(dir, 'baz/doom.js'), 'changing the package "main" works'); + + var packageData = packageFilterArgs[0]; + t.equal(packageData.main, 'doom', 'package "main" was altered'); + + var packageFile = packageFilterArgs[1]; + t.equal(packageFile, path.join(dir, 'baz'), 'second packageFilter argument is "dir"'); + t.end(); }); diff --git a/node_modules/resolve/test/pathfilter.js b/node_modules/resolve/test/pathfilter.js index 733045a06..16519aeae 100644 --- a/node_modules/resolve/test/pathfilter.js +++ b/node_modules/resolve/test/pathfilter.js @@ -2,41 +2,74 @@ var path = require('path'); var test = require('tape'); var resolve = require('../'); -test('#62: deep module references and the pathFilter', function (t) { - t.plan(9); +var resolverDir = path.join(__dirname, '/pathfilter/deep_ref'); - var resolverDir = path.join(__dirname, '/pathfilter/deep_ref'); - var pathFilter = function (pkg, x, remainder) { +var pathFilterFactory = function (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) { + st.plan(3); - resolve('deep/ref', { basedir: resolverDir }, function (err, res, pkg) { - if (err) t.fail(err); + resolve('deep/ref', { basedir: resolverDir }, function (err, res, pkg) { + if (err) st.fail(err); - t.equal(pkg.version, '1.2.3'); - t.equal(res, path.join(resolverDir, 'node_modules/deep/ref.js')); + st.equal(pkg.version, '1.2.3'); + st.equal(res, path.join(resolverDir, 'node_modules/deep/ref.js')); + }); + + var res = resolve.sync('deep/ref', { basedir: resolverDir }); + st.equal(res, path.join(resolverDir, 'node_modules/deep/ref.js')); + }); + + t.test('deep/deeper/ref', function (st) { + st.plan(4); + + resolve( + 'deep/deeper/ref', + { basedir: resolverDir }, + function (err, res, pkg) { + if (err) t.fail(err); + st.notEqual(pkg, undefined); + st.equal(pkg.version, '1.2.3'); + st.equal(res, path.join(resolverDir, 'node_modules/deep/deeper/ref.js')); + } + ); + + var res = resolve.sync( + 'deep/deeper/ref', + { basedir: resolverDir } + ); + st.equal(res, path.join(resolverDir, 'node_modules/deep/deeper/ref.js')); + }); + + t.test('deep/ref alt', function (st) { + st.plan(8); + + var pathFilter = pathFilterFactory(st); + + var res = resolve.sync( + 'deep/ref', + { basedir: resolverDir, pathFilter: pathFilter } + ); + st.equal(res, path.join(resolverDir, 'node_modules/deep/alt.js')); + + resolve( + 'deep/ref', + { basedir: resolverDir, pathFilter: pathFilter }, + function (err, res, pkg) { + if (err) st.fail(err); + st.equal(res, path.join(resolverDir, 'node_modules/deep/alt.js')); + st.end(); + } + ); }); - resolve( - 'deep/deeper/ref', - { basedir: resolverDir }, - function (err, res, pkg) { - if (err) t.fail(err); - t.notEqual(pkg, undefined); - t.equal(pkg.version, '1.2.3'); - t.equal(res, path.join(resolverDir, 'node_modules/deep/deeper/ref.js')); - } - ); - - resolve( - 'deep/ref', - { basedir: resolverDir, pathFilter: pathFilter }, - function (err, res, pkg) { - if (err) t.fail(err); - t.equal(res, path.join(resolverDir, 'node_modules/deep/alt.js')); - } - ); + t.end(); }); diff --git a/node_modules/resolve/test/resolver.js b/node_modules/resolve/test/resolver.js index 56641dfde..31f810675 100644 --- a/node_modules/resolve/test/resolver.js +++ b/node_modules/resolve/test/resolver.js @@ -3,7 +3,7 @@ var test = require('tape'); var resolve = require('../'); test('async foo', function (t) { - t.plan(10); + t.plan(12); var dir = path.join(__dirname, 'resolver'); resolve('./foo', { basedir: dir }, function (err, res, pkg) { @@ -30,10 +30,20 @@ test('async foo', function (t) { t.equal(pkg.main, 'resolver'); }); + resolve('./foo', { basedir: dir, filename: path.join(dir, 'baz.js') }, function (err, res) { + if (err) t.fail(err); + t.equal(res, path.join(dir, 'foo.js')); + }); + resolve('foo', { basedir: dir }, function (err) { t.equal(err.message, "Cannot find module 'foo' from '" + path.resolve(dir) + "'"); t.equal(err.code, 'MODULE_NOT_FOUND'); }); + + // Test that filename is reported as the "from" value when passed. + resolve('foo', { basedir: dir, filename: path.join(dir, 'baz.js') }, function (err) { + t.equal(err.message, "Cannot find module 'foo' from '" + path.join(dir, 'baz.js') + "'"); + }); }); test('bar', function (t) { @@ -55,7 +65,7 @@ test('bar', function (t) { resolve('foo', { basedir: dir + '/bar', 'package': { main: 'bar' } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js')); - t.equal(pkg, undefined); + t.equal(pkg.main, 'bar'); }); }); @@ -113,7 +123,7 @@ test('biz', function (t) { resolve('tiv', { basedir: dir + '/grux', 'package': { main: 'grux' } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'tiv/index.js')); - t.equal(pkg, undefined); + t.equal(pkg.main, 'grux'); }); resolve('tiv', { basedir: dir + '/garply' }, function (err, res, pkg) { @@ -125,7 +135,7 @@ test('biz', function (t) { resolve('tiv', { basedir: dir + '/garply', 'package': { main: './lib' } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'tiv/index.js')); - t.equal(pkg, undefined); + t.equal(pkg.main, './lib'); }); resolve('grux', { basedir: dir + '/tiv' }, function (err, res, pkg) { @@ -137,7 +147,7 @@ test('biz', function (t) { resolve('grux', { basedir: dir + '/tiv', 'package': { main: 'tiv' } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'grux/index.js')); - t.equal(pkg, undefined); + t.equal(pkg.main, 'tiv'); }); resolve('garply', { basedir: dir + '/tiv' }, function (err, res, pkg) { @@ -176,7 +186,7 @@ test('normalize', function (t) { }); test('cup', function (t) { - t.plan(4); + t.plan(5); var dir = path.join(__dirname, 'resolver'); resolve('./cup', { basedir: dir, extensions: ['.js', '.coffee'] }, function (err, res) { @@ -193,6 +203,11 @@ test('cup', function (t) { t.equal(err.message, "Cannot find module './cup' from '" + path.resolve(dir) + "'"); t.equal(err.code, 'MODULE_NOT_FOUND'); }); + + // Test that filename is reported as the "from" value when passed. + resolve('./cup', { basedir: dir, extensions: ['.js'], filename: path.join(dir, 'cupboard.js') }, function (err, res) { + t.equal(err.message, "Cannot find module './cup' from '" + path.join(dir, 'cupboard.js') + "'"); + }); }); test('mug', function (t) { @@ -347,3 +362,41 @@ test('async dot slash main', function (t) { t.end(); }); }); + +test('not a directory', function (t) { + t.plan(5); + var path = './foo'; + resolve(path, { basedir: __filename }, function (err, res, pkg) { + t.ok(err, 'a non-directory errors'); + t.equal(arguments.length, 1); + t.equal(res, undefined); + t.equal(pkg, undefined); + + t.equal(err && err.message, 'Cannot find module \'' + path + "' from '" + __filename + "'"); + }); +}); + +test('browser field in package.json', function (t) { + t.plan(3); + + var dir = path.join(__dirname, 'resolver'); + resolve( + './browser_field', + { + basedir: dir, + packageFilter: function packageFilter(pkg) { + if (pkg.browser) { + pkg.main = pkg.browser; + delete pkg.browser; + } + return pkg; + } + }, + function (err, res, pkg) { + if (err) t.fail(err); + t.equal(res, path.join(dir, 'browser_field', 'b.js')); + t.equal(pkg && pkg.main, 'b'); + t.equal(pkg && pkg.browser, undefined); + } + ); +}); diff --git a/node_modules/resolve/test/resolver/symlinked/.npmignore b/node_modules/resolve/test/resolver/symlinked/.npmignore deleted file mode 100644 index f23f89258..000000000 --- a/node_modules/resolve/test/resolver/symlinked/.npmignore +++ /dev/null @@ -1 +0,0 @@ -symlink
diff --git a/node_modules/resolve/test/resolver/symlinked/_/.npmignore b/node_modules/resolve/test/resolver/symlinked/_/.npmignore deleted file mode 100644 index cf4bab9dd..000000000 --- a/node_modules/resolve/test/resolver/symlinked/_/.npmignore +++ /dev/null @@ -1 +0,0 @@ -!node_modules diff --git a/node_modules/resolve/test/resolver_sync.js b/node_modules/resolve/test/resolver_sync.js index 8e33dca69..ce7357430 100644 --- a/node_modules/resolve/test/resolver_sync.js +++ b/node_modules/resolve/test/resolver_sync.js @@ -15,10 +15,26 @@ test('foo', function (t) { path.join(dir, 'foo.js') ); + t.equal( + resolve.sync('./foo.js', { basedir: dir, filename: path.join(dir, 'bar.js') }), + path.join(dir, 'foo.js') + ); + t.throws(function () { resolve.sync('foo', { basedir: dir }); }); + // Test that filename is reported as the "from" value when passed. + t.throws( + function () { + resolve.sync('foo', { basedir: dir, filename: path.join(dir, 'bar.js') }); + }, + { + name: 'Error', + message: "Cannot find module 'foo' from '" + path.join(dir, 'bar.js') + "'" + } + ); + t.end(); }); @@ -265,3 +281,31 @@ test('sync dot slash main', function (t) { t.ok(new Date() - start < 50, 'resolve.sync timedout'); t.end(); }); + +test('not a directory', function (t) { + var path = './foo'; + try { + resolve.sync(path, { basedir: __filename }); + t.fail(); + } catch (err) { + t.ok(err, 'a non-directory errors'); + t.equal(err && err.message, 'Cannot find module \'' + path + "' from '" + __filename + "'"); + } + t.end(); +}); + +test('browser field in package.json', function (t) { + var dir = path.join(__dirname, 'resolver'); + var res = resolve.sync('./browser_field', { + basedir: dir, + packageFilter: function packageFilter(pkg) { + if (pkg.browser) { + pkg.main = pkg.browser; + delete pkg.browser; + } + return pkg; + } + }); + t.equal(res, path.join(dir, 'browser_field', 'b.js')); + t.end(); +}); diff --git a/node_modules/resolve/test/symlinks.js b/node_modules/resolve/test/symlinks.js index 544a02371..0b1e6f778 100644 --- a/node_modules/resolve/test/symlinks.js +++ b/node_modules/resolve/test/symlinks.js @@ -41,7 +41,9 @@ test('sync symlink when preserveSymlinks = true', function (t) { test('sync symlink', function (t) { var start = new Date(); - t.equal(resolve.sync('foo', { basedir: symlinkDir, preserveSymlinks: false }), path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'foo.js')); + t.doesNotThrow(function () { + t.equal(resolve.sync('foo', { basedir: symlinkDir, preserveSymlinks: false }), path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'foo.js')); + }); t.ok(new Date() - start < 50, 'resolve.sync timedout'); t.end(); }); |