diff options
author | Florian Dold <florian.dold@gmail.com> | 2017-05-28 00:38:50 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2017-05-28 00:40:43 +0200 |
commit | 7fff4499fd915bcea3fa93b1aa8b35f4fe7a6027 (patch) | |
tree | 6de9a1aebd150a23b7f8c273ec657a5d0a18fe3e /node_modules/resolve | |
parent | 963b7a41feb29cc4be090a2446bdfe0c1f1bcd81 (diff) |
add linting (and some initial fixes)
Diffstat (limited to 'node_modules/resolve')
59 files changed, 1199 insertions, 675 deletions
diff --git a/node_modules/resolve/.eslintignore b/node_modules/resolve/.eslintignore new file mode 100644 index 000000000..3c3629e64 --- /dev/null +++ b/node_modules/resolve/.eslintignore @@ -0,0 +1 @@ +node_modules diff --git a/node_modules/resolve/.eslintrc b/node_modules/resolve/.eslintrc new file mode 100644 index 000000000..ae352e2e2 --- /dev/null +++ b/node_modules/resolve/.eslintrc @@ -0,0 +1,27 @@ +{ + "extends": "@ljharb", + "root": true, + "rules": { + "indent": [2, 4], + "strict": 0, + "complexity": 0, + "consistent-return": 0, + "curly": 0, + "func-name-matching": 0, + "func-style": 0, + "global-require": 0, + "id-length": [2, { "min": 1, "max": 30 }], + "max-nested-callbacks": 0, + "max-params": 0, + "max-statements-per-line": [2, { "max": 2 }], + "max-statements": 0, + "no-magic-numbers": 0, + "no-console": 0, + "no-shadow": 0, + "no-unused-vars": [2, { "vars": "all", "args": "none" }], + "no-use-before-define": 0, + "object-curly-newline": 0, + "operator-linebreak": [2, "before"], + "sort-keys": 0, + } +} diff --git a/node_modules/resolve/.npmignore b/node_modules/resolve/.npmignore new file mode 100644 index 000000000..3c3629e64 --- /dev/null +++ b/node_modules/resolve/.npmignore @@ -0,0 +1 @@ +node_modules diff --git a/node_modules/resolve/.travis.yml b/node_modules/resolve/.travis.yml index 895dbd362..f5450af3f 100644 --- a/node_modules/resolve/.travis.yml +++ b/node_modules/resolve/.travis.yml @@ -1,4 +1,176 @@ language: node_js +os: + - linux node_js: - - 0.6 - - 0.8 + - "7.9" + - "6.10" + - "5.12" + - "4.8" + - "iojs-v3.3" + - "iojs-v2.5" + - "iojs-v1.8" + - "0.12" + - "0.10" + - "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 npm install -g npm; fi' +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 && 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' + - 'if [ -n "${COVERAGE-}" ]; then npm run coverage ; fi' + - 'if [ -n "${TEST-}" ]; then npm run tests-only ; fi' +sudo: false +env: + - TEST=true +matrix: + fast_finish: true + include: + - node_js: "node" + env: PRETEST=true + - node_js: "7.8" + env: TEST=true ALLOW_FAILURE=true + - node_js: "7.7" + env: TEST=true ALLOW_FAILURE=true + - node_js: "7.6" + env: TEST=true ALLOW_FAILURE=true + - node_js: "7.5" + env: TEST=true ALLOW_FAILURE=true + - node_js: "7.4" + env: TEST=true ALLOW_FAILURE=true + - node_js: "7.3" + env: TEST=true ALLOW_FAILURE=true + - node_js: "7.2" + env: TEST=true ALLOW_FAILURE=true + - node_js: "7.1" + env: TEST=true ALLOW_FAILURE=true + - node_js: "7.0" + env: TEST=true ALLOW_FAILURE=true + - node_js: "6.9" + env: TEST=true ALLOW_FAILURE=true + - node_js: "6.8" + env: TEST=true ALLOW_FAILURE=true + - node_js: "6.7" + env: TEST=true ALLOW_FAILURE=true + - node_js: "6.6" + env: TEST=true ALLOW_FAILURE=true + - node_js: "6.5" + env: TEST=true ALLOW_FAILURE=true + - node_js: "6.4" + env: TEST=true ALLOW_FAILURE=true + - node_js: "6.3" + env: TEST=true ALLOW_FAILURE=true + - node_js: "6.2" + env: TEST=true ALLOW_FAILURE=true + - node_js: "6.1" + env: TEST=true ALLOW_FAILURE=true + - node_js: "6.0" + env: TEST=true ALLOW_FAILURE=true + - node_js: "5.11" + env: TEST=true ALLOW_FAILURE=true + - node_js: "5.10" + env: TEST=true ALLOW_FAILURE=true + - node_js: "5.9" + env: TEST=true ALLOW_FAILURE=true + - node_js: "5.8" + env: TEST=true ALLOW_FAILURE=true + - node_js: "5.7" + env: TEST=true ALLOW_FAILURE=true + - node_js: "5.6" + env: TEST=true ALLOW_FAILURE=true + - node_js: "5.5" + env: TEST=true ALLOW_FAILURE=true + - node_js: "5.4" + env: TEST=true ALLOW_FAILURE=true + - node_js: "5.3" + env: TEST=true ALLOW_FAILURE=true + - node_js: "5.2" + env: TEST=true ALLOW_FAILURE=true + - node_js: "5.1" + env: TEST=true ALLOW_FAILURE=true + - node_js: "5.0" + env: TEST=true ALLOW_FAILURE=true + - node_js: "4.7" + env: TEST=true ALLOW_FAILURE=true + - node_js: "4.6" + env: TEST=true ALLOW_FAILURE=true + - node_js: "4.5" + env: TEST=true ALLOW_FAILURE=true + - node_js: "4.4" + env: TEST=true ALLOW_FAILURE=true + - node_js: "4.3" + env: TEST=true ALLOW_FAILURE=true + - node_js: "4.2" + env: TEST=true ALLOW_FAILURE=true + - node_js: "4.1" + env: TEST=true ALLOW_FAILURE=true + - node_js: "4.0" + env: TEST=true ALLOW_FAILURE=true + - node_js: "iojs-v3.2" + env: TEST=true ALLOW_FAILURE=true + - node_js: "iojs-v3.1" + env: TEST=true ALLOW_FAILURE=true + - node_js: "iojs-v3.0" + env: TEST=true ALLOW_FAILURE=true + - node_js: "iojs-v2.4" + env: TEST=true ALLOW_FAILURE=true + - node_js: "iojs-v2.3" + env: TEST=true ALLOW_FAILURE=true + - node_js: "iojs-v2.2" + env: TEST=true ALLOW_FAILURE=true + - node_js: "iojs-v2.1" + env: TEST=true ALLOW_FAILURE=true + - node_js: "iojs-v2.0" + env: TEST=true ALLOW_FAILURE=true + - node_js: "iojs-v1.7" + env: TEST=true ALLOW_FAILURE=true + - node_js: "iojs-v1.6" + env: TEST=true ALLOW_FAILURE=true + - node_js: "iojs-v1.5" + env: TEST=true ALLOW_FAILURE=true + - node_js: "iojs-v1.4" + env: TEST=true ALLOW_FAILURE=true + - node_js: "iojs-v1.3" + env: TEST=true ALLOW_FAILURE=true + - node_js: "iojs-v1.2" + env: TEST=true ALLOW_FAILURE=true + - node_js: "iojs-v1.1" + env: TEST=true ALLOW_FAILURE=true + - node_js: "iojs-v1.0" + env: TEST=true ALLOW_FAILURE=true + - node_js: "0.11" + env: TEST=true ALLOW_FAILURE=true + - node_js: "0.9" + 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 new file mode 100644 index 000000000..f54a1b609 --- /dev/null +++ b/node_modules/resolve/appveyor.yml @@ -0,0 +1,44 @@ +version: 1.0.{build} +skip_branch_with_pr: true +build: off + +environment: + matrix: + - nodejs_version: "7" + - nodejs_version: "6" + - nodejs_version: "5" + - nodejs_version: "4" + - nodejs_version: "3" + - nodejs_version: "2" + - nodejs_version: "1" + - nodejs_version: "0.12" + - nodejs_version: "0.10" + - nodejs_version: "0.8" + - nodejs_version: "0.6" +matrix: + # fast_finish: true + allow_failures: + - nodejs_version: "0.6" + +platform: + - x86 + - x64 + +# Install scripts. (runs after repo cloning) +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 + - set PATH=%APPDATA%\npm;%PATH% + #- IF %nodejs_version% NEQ 0.6 AND %nodejs_version% NEQ 0.8 npm -g install npm + # install modules + - npm install + +# Post-install test scripts. +test_script: + # Output useful info for debugging. + - node --version + - npm --version + # run tests + - npm run tests-only diff --git a/node_modules/resolve/example/async.js b/node_modules/resolve/example/async.js index 6624ff726..20e65dc28 100644 --- a/node_modules/resolve/example/async.js +++ b/node_modules/resolve/example/async.js @@ -1,5 +1,5 @@ var resolve = require('../'); 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); }); diff --git a/node_modules/resolve/index.js b/node_modules/resolve/index.js index 51f194b4c..eb6ba89e6 100644 --- a/node_modules/resolve/index.js +++ b/node_modules/resolve/index.js @@ -1,5 +1,8 @@ var core = require('./lib/core'); -exports = module.exports = require('./lib/async'); -exports.core = core; -exports.isCore = function (x) { return core[x] }; -exports.sync = require('./lib/sync'); +var async = require('./lib/async'); +async.core = core; +async.isCore = function isCore(x) { return core[x]; }; +async.sync = require('./lib/sync'); + +exports = async; +module.exports = async; diff --git a/node_modules/resolve/lib/async.js b/node_modules/resolve/lib/async.js index 0f0eeca56..ef1bde782 100644 --- a/node_modules/resolve/lib/async.js +++ b/node_modules/resolve/lib/async.js @@ -3,78 +3,90 @@ var fs = require('fs'); var path = require('path'); var caller = require('./caller.js'); var nodeModulesPaths = require('./node-modules-paths.js'); -var splitRe = process.platform === 'win32' ? /[\/\\]/ : /\//; -module.exports = function resolve (x, opts, cb) { +module.exports = function resolve(x, options, callback) { + var cb = callback; + var opts = options || {}; if (typeof opts === 'function') { cb = opts; opts = {}; } - if (!opts) opts = {}; if (typeof x !== 'string') { + var err = new TypeError('Path must be a string.'); return process.nextTick(function () { - cb(new Error('path must be a string')); + cb(err); }); } - + var isFile = opts.isFile || function (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() || stat.isFIFO()) + if (!err) { + return cb(null, stat.isFile() || stat.isFIFO()); + } + if (err.code === 'ENOENT' || err.code === 'ENOTDIR') return cb(null, false); + return cb(err); }); }; var readFile = opts.readFile || fs.readFile; - - var extensions = opts.extensions || [ '.js' ]; + + var extensions = opts.extensions || ['.js']; var y = opts.basedir || path.dirname(caller()); - + opts.paths = opts.paths || []; - - if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[\\\/])/.test(x)) { + + if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) { var res = path.resolve(y, x); - if (x === '..') res += '/'; + if (x === '..' || x.slice(-1) === '/') res += '/'; if (/\/$/.test(x) && res === y) { loadAsDirectory(res, opts.package, onfile); - } - else loadAsFile(res, opts.package, onfile); - } - else loadNodeModules(x, y, function (err, n, pkg) { - if (err) cb(err) - else if (n) cb(null, n, pkg) + } else loadAsFile(res, opts.package, onfile); + } else loadNodeModules(x, y, function (err, n, pkg) { + if (err) cb(err); + else if (n) cb(null, n, pkg); else if (core[x]) return cb(null, x); - else cb(new Error("Cannot find module '" + x + "' from '" + y + "'")) + else { + var moduleError = new Error("Cannot find module '" + x + "' from '" + y + "'"); + moduleError.code = 'MODULE_NOT_FOUND'; + cb(moduleError); + } }); - - function onfile (err, m, pkg) { - if (err) cb(err) - else if (m) cb(null, m, pkg) + + 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) cb(null, d, pkg) - else cb(new Error("Cannot find module '" + x + "' from '" + y + "'")) - }) + if (err) cb(err); + else if (d) cb(null, d, pkg); + else { + var moduleError = new Error("Cannot find module '" + x + "' from '" + y + "'"); + moduleError.code = 'MODULE_NOT_FOUND'; + cb(moduleError); + } + }); } - - function loadAsFile (x, pkg, cb) { - if (typeof pkg === 'function') { - cb = pkg; - pkg = undefined; + + 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, pkg) - - function load (exts, x, pkg) { - if (exts.length === 0) return cb(null, undefined, pkg); + load(exts, x, loadAsFilePackage); + + function load(exts, x, loadPackage) { + if (exts.length === 0) return cb(null, undefined, loadPackage); var file = x + exts[0]; - - if (pkg) onpkg(null, pkg) + + var pkg = loadPackage; + if (pkg) onpkg(null, pkg); else loadpkg(path.dirname(file), onpkg); - - function onpkg (err, pkg_, dir) { + + function onpkg(err, pkg_, dir) { pkg = pkg_; - if (err) return cb(err) + 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); @@ -87,33 +99,30 @@ module.exports = function resolve (x, opts, cb) { } isFile(file, onex); } - function onex (err, ex) { - if (err) cb(err) - else if (!ex) load(exts.slice(1), x, pkg) - else cb(null, file, pkg) + 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) { + + function loadpkg(dir, cb) { if (dir === '' || dir === '/') return cb(null); - if (process.platform === 'win32' && /^\w:[\\\/]*$/.test(dir)) { + if (process.platform === 'win32' && (/^\w:[/\\]*$/).test(dir)) { return cb(null); } - if (/[\\\/]node_modules[\\\/]*$/.test(dir)) return cb(null); - + if (/[/\\]node_modules[/\\]*$/.test(dir)) return cb(null); + var pkgfile = path.join(dir, 'package.json'); isFile(pkgfile, function (err, ex) { // on err, ex is false - if (!ex) return loadpkg( - path.dirname(dir), cb - ); - + if (!ex) return loadpkg(path.dirname(dir), cb); + readFile(pkgfile, function (err, body) { if (err) cb(err); - try { var pkg = JSON.parse(body) } - catch (err) {} - + try { var pkg = JSON.parse(body); } catch (jsonErr) {} + if (pkg && opts.packageFilter) { pkg = opts.packageFilter(pkg, pkgfile); } @@ -121,72 +130,74 @@ module.exports = function resolve (x, opts, cb) { }); }); } - - function loadAsDirectory (x, fpkg, cb) { + + function loadAsDirectory(x, loadAsDirectoryPackage, callback) { + var cb = callback; + var fpkg = loadAsDirectoryPackage; if (typeof fpkg === 'function') { cb = fpkg; fpkg = opts.package; } - - var pkgfile = path.join(x, '/package.json'); + + var pkgfile = path.join(x, 'package.json'); isFile(pkgfile, function (err, ex) { if (err) return cb(err); - if (!ex) return loadAsFile(path.join(x, '/index'), fpkg, cb); - + if (!ex) return loadAsFile(path.join(x, 'index'), fpkg, cb); + readFile(pkgfile, function (err, body) { if (err) return cb(err); try { var pkg = JSON.parse(body); - } - catch (err) {} - + } catch (jsonErr) {} + if (opts.packageFilter) { pkg = opts.packageFilter(pkg, pkgfile); } - + if (pkg.main) { - if (pkg.main === '.' || pkg.main === './'){ - pkg.main = 'index' + 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); + 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); + loadAsFile(path.join(x, 'index'), pkg, cb); }); }); return; } - + loadAsFile(path.join(x, '/index'), pkg, cb); }); }); } - - function loadNodeModules (x, start, cb) { - (function process (dirs) { - if (dirs.length === 0) return cb(null, undefined); - var dir = dirs[0]; - - var file = path.join(dir, '/', x); - loadAsFile(file, undefined, 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); - } - - function ondir (err, n, pkg) { - if (err) return cb(err); - if (n) return cb(null, n, pkg); - process(dirs.slice(1)); - } - })(nodeModulesPaths(start, opts)); + + function processDirs(cb, dirs) { + if (dirs.length === 0) return cb(null, undefined); + var dir = dirs[0]; + + var file = path.join(dir, x); + loadAsFile(file, undefined, 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); + } + + 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) { + processDirs(cb, nodeModulesPaths(start, opts)); } }; diff --git a/node_modules/resolve/lib/caller.js b/node_modules/resolve/lib/caller.js index 5536549b0..b14a2804a 100644 --- a/node_modules/resolve/lib/caller.js +++ b/node_modules/resolve/lib/caller.js @@ -1,7 +1,7 @@ module.exports = function () { // see https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi var origPrepareStackTrace = Error.prepareStackTrace; - Error.prepareStackTrace = function (_, stack) { return stack }; + Error.prepareStackTrace = function (_, stack) { return stack; }; var stack = (new Error()).stack; Error.prepareStackTrace = origPrepareStackTrace; return stack[2].getFileName(); diff --git a/node_modules/resolve/lib/core.js b/node_modules/resolve/lib/core.js index ea4a6c87e..ad9efd132 100644 --- a/node_modules/resolve/lib/core.js +++ b/node_modules/resolve/lib/core.js @@ -1,4 +1,22 @@ -module.exports = require('./core.json').reduce(function (acc, x) { - acc[x] = true; - return acc; -}, {}); +var current = (process.versions && process.versions.node && process.versions.node.split('.')) || []; + +function versionIncluded(version) { + if (version === '*') return true; + var versionParts = version.split('.'); + for (var i = 0; i < 3; ++i) { + if ((current[i] || 0) >= (versionParts[i] || 0)) return true; + } + return false; +} + +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; + } + } +} +module.exports = core; diff --git a/node_modules/resolve/lib/core.json b/node_modules/resolve/lib/core.json index 28560f7ef..843844ebf 100644 --- a/node_modules/resolve/lib/core.json +++ b/node_modules/resolve/lib/core.json @@ -1,38 +1,47 @@ -[ - "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" -] +{ + "*": [ + "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" + ] +} diff --git a/node_modules/resolve/lib/node-modules-paths.js b/node_modules/resolve/lib/node-modules-paths.js index ce0a0d9f2..dc06199db 100644 --- a/node_modules/resolve/lib/node-modules-paths.js +++ b/node_modules/resolve/lib/node-modules-paths.js @@ -1,38 +1,35 @@ var path = require('path'); +var parse = path.parse || require('path-parse'); -module.exports = function (start, opts) { - var modules = opts.moduleDirectory +module.exports = function nodeModulesPaths(start, opts) { + var modules = opts && opts.moduleDirectory ? [].concat(opts.moduleDirectory) : ['node_modules'] ; // ensure that `start` is an absolute path at this point, // resolving against the process' current working directory - start = path.resolve(start); + var absoluteStart = path.resolve(start); var prefix = '/'; - if (/^([A-Za-z]:)/.test(start)) { + if (/^([A-Za-z]:)/.test(absoluteStart)) { prefix = ''; - } else if (/^\\\\/.test(start)) { + } else if (/^\\\\/.test(absoluteStart)) { prefix = '\\\\'; } - var splitRe = process.platform === 'win32' ? /[\/\\]/ : /\/+/; - - var parts = start.split(splitRe); + var paths = [absoluteStart]; + var parsed = parse(absoluteStart); + while (parsed.dir !== paths[paths.length - 1]) { + paths.push(parsed.dir); + parsed = parse(parsed.dir); + } - var dirs = []; - for (var i = parts.length - 1; i >= 0; i--) { - if (modules.indexOf(parts[i]) !== -1) continue; - dirs = dirs.concat(modules.map(function(module_dir) { - return prefix + path.join( - path.join.apply(path, parts.slice(0, i + 1)), - module_dir - ); + var dirs = paths.reduce(function (dirs, aPath) { + return dirs.concat(modules.map(function (moduleDir) { + return path.join(prefix, aPath, moduleDir); })); - } - if (process.platform === 'win32'){ - dirs[dirs.length-1] = dirs[dirs.length-1].replace(":", ":\\"); - } - return dirs.concat(opts.paths); -} + }, []); + + return opts && opts.paths ? dirs.concat(opts.paths) : dirs; +}; diff --git a/node_modules/resolve/lib/sync.js b/node_modules/resolve/lib/sync.js index ef91eddbb..510ca256c 100644 --- a/node_modules/resolve/lib/sync.js +++ b/node_modules/resolve/lib/sync.js @@ -4,39 +4,48 @@ var path = require('path'); var caller = require('./caller.js'); var nodeModulesPaths = require('./node-modules-paths.js'); -module.exports = function (x, opts) { - if (!opts) opts = {}; +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 (err) { if (err && err.code === 'ENOENT') return false } + 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 readFileSync = opts.readFileSync || fs.readFileSync; - - var extensions = opts.extensions || [ '.js' ]; + + var extensions = opts.extensions || ['.js']; var y = opts.basedir || path.dirname(caller()); opts.paths = opts.paths || []; - if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[\\\/])/.test(x)) { + if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) { var res = path.resolve(y, x); - if (x === '..') res += '/'; + if (x === '..' || x.slice(-1) === '/') res += '/'; var m = loadAsFileSync(res) || loadAsDirectorySync(res); if (m) return m; } else { var n = loadNodeModulesSync(x, y); if (n) return n; } - + if (core[x]) return x; - - throw new Error("Cannot find module '" + x + "' from '" + y + "'"); - - function loadAsFileSync (x) { + + var err = new Error("Cannot find module '" + x + "' from '" + y + "'"); + err.code = 'MODULE_NOT_FOUND'; + throw err; + + function loadAsFileSync(x) { if (isFile(x)) { return x; } - + for (var i = 0; i < extensions.length; i++) { var file = x + extensions[i]; if (isFile(file)) { @@ -44,8 +53,8 @@ module.exports = function (x, opts) { } } } - - function loadAsDirectorySync (x) { + + function loadAsDirectorySync(x) { var pkgfile = path.join(x, '/package.json'); if (isFile(pkgfile)) { var body = readFileSync(pkgfile, 'utf8'); @@ -54,27 +63,26 @@ module.exports = function (x, opts) { if (opts.packageFilter) { pkg = opts.packageFilter(pkg, x); } - + if (pkg.main) { 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 (err) {} + } catch (e) {} } - - return loadAsFileSync(path.join( x, '/index')); + + return loadAsFileSync(path.join(x, '/index')); } - - function loadNodeModulesSync (x, start) { + + function loadNodeModulesSync(x, start) { var dirs = nodeModulesPaths(start, opts); for (var i = 0; i < dirs.length; i++) { var dir = dirs[i]; - var m = loadAsFileSync(path.join( dir, '/', x)); + var m = loadAsFileSync(path.join(dir, '/', x)); if (m) return m; - var n = loadAsDirectorySync(path.join( dir, '/', x )); + var n = loadAsDirectorySync(path.join(dir, '/', x)); if (n) return n; } } diff --git a/node_modules/resolve/package.json b/node_modules/resolve/package.json index 507fe8b07..9a93a3dc5 100644 --- a/node_modules/resolve/package.json +++ b/node_modules/resolve/package.json @@ -1,7 +1,7 @@ { "name": "resolve", "description": "resolve like require.resolve() on behalf of files asynchronously and synchronously", - "version": "1.1.7", + "version": "1.3.3", "repository": { "type": "git", "url": "git://github.com/substack/node-resolve.git" @@ -14,16 +14,27 @@ "module" ], "scripts": { - "test": "tape test/*.js" + "prepublish": "safe-publish-latest", + "lint": "eslint .", + "tests-only": "tape test/*.js", + "pretest": "npm run lint", + "test": "npm run --silent tests-only" }, "devDependencies": { - "tape": "^3.5.0", - "tap": "0.4.13" + "@ljharb/eslint-config": "^11.0.0", + "eslint": "^3.19.0", + "object-keys": "^1.0.11", + "safe-publish-latest": "^1.1.1", + "tap": "0.4.13", + "tape": "^4.6.3" }, "license": "MIT", "author": { "name": "James Halliday", "email": "mail@substack.net", "url": "http://substack.net" + }, + "dependencies": { + "path-parse": "^1.0.5" } } diff --git a/node_modules/resolve/readme.markdown b/node_modules/resolve/readme.markdown index 4fab9b043..db0d69f87 100644 --- a/node_modules/resolve/readme.markdown +++ b/node_modules/resolve/readme.markdown @@ -1,7 +1,7 @@ # resolve implements the [node `require.resolve()` -algorithm](http://nodejs.org/docs/v0.4.8/api/all.html#all_Together...) +algorithm](https://nodejs.org/api/modules.html#modules_all_together) such that you can `require.resolve()` on behalf of a file asynchronously and synchronously diff --git a/node_modules/resolve/test/core.js b/node_modules/resolve/test/core.js index 4a5668207..1182e0c0b 100644 --- a/node_modules/resolve/test/core.js +++ b/node_modules/resolve/test/core.js @@ -2,11 +2,28 @@ var test = require('tape'); var resolve = require('../'); test('core modules', function (t) { - t.ok(resolve.isCore('fs')); - t.ok(resolve.isCore('net')); - t.ok(resolve.isCore('http')); - - t.ok(!resolve.isCore('seq')); - t.ok(!resolve.isCore('../')); + t.test('isCore()', function (st) { + st.ok(resolve.isCore('fs')); + st.ok(resolve.isCore('net')); + st.ok(resolve.isCore('http')); + + st.ok(!resolve.isCore('seq')); + st.ok(!resolve.isCore('../')); + st.end(); + }); + + t.test('core list', function (st) { + st.plan(resolve.core.length); + + for (var i = 0; i < resolve.core.length; ++i) { + st.doesNotThrow( + function () { require(resolve.core[i]); }, // eslint-disable-line no-loop-func + 'requiring ' + resolve.core[i] + ' does not throw' + ); + } + + st.end(); + }); + t.end(); }); diff --git a/node_modules/resolve/test/dotdot.js b/node_modules/resolve/test/dotdot.js index b87677278..30806659b 100644 --- a/node_modules/resolve/test/dotdot.js +++ b/node_modules/resolve/test/dotdot.js @@ -4,26 +4,26 @@ var resolve = require('../'); test('dotdot', function (t) { t.plan(4); - var dir = __dirname + '/dotdot/abc'; - - resolve('..', { basedir : dir }, function (err, res, pkg) { + var dir = path.join(__dirname, '/dotdot/abc'); + + resolve('..', { basedir: dir }, function (err, res, pkg) { t.ifError(err); - t.equal(res, __dirname + '/dotdot/index.js'); + t.equal(res, path.join(__dirname, 'dotdot/index.js')); }); - - resolve('.', { basedir : dir }, function (err, res, pkg) { + + resolve('.', { basedir: dir }, function (err, res, pkg) { t.ifError(err); - t.equal(res, dir + '/index.js'); + t.equal(res, path.join(dir, 'index.js')); }); }); test('dotdot sync', function (t) { t.plan(2); - var dir = __dirname + '/dotdot/abc'; - - var a = resolve.sync('..', { basedir : dir }); - t.equal(a, __dirname + '/dotdot/index.js'); - - var b = resolve.sync('.', { basedir : dir }); - t.equal(b, dir + '/index.js'); + var dir = path.join(__dirname, '/dotdot/abc'); + + var a = resolve.sync('..', { basedir: dir }); + t.equal(a, path.join(__dirname, 'dotdot/index.js')); + + var b = resolve.sync('.', { basedir: dir }); + t.equal(b, path.join(dir, 'index.js')); }); diff --git a/node_modules/resolve/test/dotdot/index.js b/node_modules/resolve/test/dotdot/index.js index afec73603..643f9fcc6 100644 --- a/node_modules/resolve/test/dotdot/index.js +++ b/node_modules/resolve/test/dotdot/index.js @@ -1 +1 @@ -module.exports = 'whatever' +module.exports = 'whatever'; diff --git a/node_modules/resolve/test/faulty_basedir.js b/node_modules/resolve/test/faulty_basedir.js index 244081882..e20d937ca 100644 --- a/node_modules/resolve/test/faulty_basedir.js +++ b/node_modules/resolve/test/faulty_basedir.js @@ -1,16 +1,12 @@ -var path = require('path'); var test = require('tape'); var resolve = require('../'); -// not sure what's up with this test anymore -if (process.platform !== 'win32') return; - -test('faulty basedir must produce error in windows', function (t) { +test('faulty basedir must produce error in windows', { skip: process.platform !== 'win32' }, function (t) { t.plan(1); var resolverDir = 'C:\\a\\b\\c\\d'; - resolve('tape/lib/test.js', { basedir : resolverDir }, function (err, res, pkg) { + resolve('tape/lib/test.js', { basedir: resolverDir }, function (err, res, pkg) { t.equal(true, !!err); }); diff --git a/node_modules/resolve/test/filter.js b/node_modules/resolve/test/filter.js index 07c38f349..51a753f16 100644 --- a/node_modules/resolve/test/filter.js +++ b/node_modules/resolve/test/filter.js @@ -1,18 +1,19 @@ +var path = require('path'); var test = require('tape'); var resolve = require('../'); test('filter', function (t) { t.plan(2); - var dir = __dirname + '/resolver'; + var dir = path.join(__dirname, 'resolver'); resolve('./baz', { - basedir : dir, - packageFilter : function (pkg) { + basedir: dir, + packageFilter: function (pkg) { pkg.main = 'doom'; return pkg; } }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/baz/doom.js'); + t.equal(res, path.join(dir, 'baz/doom.js')); t.equal(pkg.main, 'doom'); }); }); diff --git a/node_modules/resolve/test/filter_sync.js b/node_modules/resolve/test/filter_sync.js index 3f89b7942..fd4e97c28 100644 --- a/node_modules/resolve/test/filter_sync.js +++ b/node_modules/resolve/test/filter_sync.js @@ -1,15 +1,16 @@ +var path = require('path'); var test = require('tape'); var resolve = require('../'); test('filter', function (t) { - var dir = __dirname + '/resolver'; + var dir = path.join(__dirname, 'resolver'); var res = resolve.sync('./baz', { - basedir : dir, - packageFilter : function (pkg) { - pkg.main = 'doom' + basedir: dir, + packageFilter: function (pkg) { + pkg.main = 'doom'; return pkg; } }); - t.equal(res, dir + '/baz/doom.js'); + t.equal(res, path.join(dir, 'baz/doom.js')); t.end(); }); diff --git a/node_modules/resolve/test/mock.js b/node_modules/resolve/test/mock.js index 1cf3b1247..a88059d45 100644 --- a/node_modules/resolve/test/mock.js +++ b/node_modules/resolve/test/mock.js @@ -1,142 +1,143 @@ +var path = require('path'); var test = require('tape'); var resolve = require('../'); test('mock', function (t) { - t.plan(6); - - var files = { - '/foo/bar/baz.js' : 'beep' - }; - - function opts (basedir) { + t.plan(8); + + var files = {}; + files[path.resolve('/foo/bar/baz.js')] = 'beep'; + + function opts(basedir) { return { - basedir : basedir, - isFile : function (file, cb) { - cb(null, files.hasOwnProperty(file)); + basedir: path.resolve(basedir), + isFile: function (file, cb) { + cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file))); }, - readFile : function (file, cb) { - cb(null, files[file]); + readFile: function (file, cb) { + cb(null, files[path.resolve(file)]); } - } + }; } - + resolve('./baz', opts('/foo/bar'), function (err, res, pkg) { - if (err) t.fail(err); - t.equal(res, '/foo/bar/baz.js'); + if (err) return t.fail(err); + t.equal(res, path.resolve('/foo/bar/baz.js')); t.equal(pkg, undefined); }); - + resolve('./baz.js', opts('/foo/bar'), function (err, res, pkg) { - if (err) t.fail(err); - t.equal(res, '/foo/bar/baz.js'); + if (err) return t.fail(err); + t.equal(res, path.resolve('/foo/bar/baz.js')); t.equal(pkg, undefined); }); - + resolve('baz', opts('/foo/bar'), function (err, res) { - t.equal(err.message, "Cannot find module 'baz' from '/foo/bar'"); + t.equal(err.message, "Cannot find module 'baz' from '" + path.resolve('/foo/bar') + "'"); + t.equal(err.code, 'MODULE_NOT_FOUND'); }); - + resolve('../baz', opts('/foo/bar'), function (err, res) { - t.equal(err.message, "Cannot find module '../baz' from '/foo/bar'"); + t.equal(err.message, "Cannot find module '../baz' from '" + path.resolve('/foo/bar') + "'"); + t.equal(err.code, 'MODULE_NOT_FOUND'); }); }); test('mock from package', function (t) { - t.plan(6); - - var files = { - '/foo/bar/baz.js' : 'beep' - }; - - function opts (basedir) { + t.plan(8); + + var files = {}; + files[path.resolve('/foo/bar/baz.js')] = 'beep'; + + function opts(basedir) { return { - basedir : basedir, - package : { main: 'bar' }, - isFile : function (file, cb) { - cb(null, files.hasOwnProperty(file)); + basedir: path.resolve(basedir), + isFile: function (file, cb) { + cb(null, Object.prototype.hasOwnProperty.call(files, file)); }, - readFile : function (file, cb) { + 'package': { main: 'bar' }, + readFile: function (file, cb) { cb(null, files[file]); } - } + }; } - + resolve('./baz', opts('/foo/bar'), function (err, res, pkg) { - if (err) t.fail(err); - t.equal(res, '/foo/bar/baz.js'); - t.equal(pkg.main, 'bar'); + if (err) return t.fail(err); + t.equal(res, path.resolve('/foo/bar/baz.js')); + t.equal(pkg && pkg.main, 'bar'); }); - + resolve('./baz.js', opts('/foo/bar'), function (err, res, pkg) { - if (err) t.fail(err); - t.equal(res, '/foo/bar/baz.js'); - t.equal(pkg.main, 'bar'); + if (err) return t.fail(err); + t.equal(res, path.resolve('/foo/bar/baz.js')); + t.equal(pkg && pkg.main, 'bar'); }); - + resolve('baz', opts('/foo/bar'), function (err, res) { - t.equal(err.message, "Cannot find module 'baz' from '/foo/bar'"); + t.equal(err.message, "Cannot find module 'baz' from '" + path.resolve('/foo/bar') + "'"); + t.equal(err.code, 'MODULE_NOT_FOUND'); }); - + resolve('../baz', opts('/foo/bar'), function (err, res) { - t.equal(err.message, "Cannot find module '../baz' from '/foo/bar'"); + t.equal(err.message, "Cannot find module '../baz' from '" + path.resolve('/foo/bar') + "'"); + t.equal(err.code, 'MODULE_NOT_FOUND'); }); }); test('mock package', function (t) { t.plan(2); - - var files = { - '/foo/node_modules/bar/baz.js' : 'beep', - '/foo/node_modules/bar/package.json' : JSON.stringify({ - main : './baz.js' - }) - }; - - function opts (basedir) { + + var files = {}; + files[path.resolve('/foo/node_modules/bar/baz.js')] = 'beep'; + files[path.resolve('/foo/node_modules/bar/package.json')] = JSON.stringify({ + main: './baz.js' + }); + + function opts(basedir) { return { - basedir : basedir, - isFile : function (file, cb) { - cb(null, files.hasOwnProperty(file)); + basedir: path.resolve(basedir), + isFile: function (file, cb) { + cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file))); }, - readFile : function (file, cb) { - cb(null, files[file]); + readFile: function (file, cb) { + cb(null, files[path.resolve(file)]); } - } + }; } - + resolve('bar', opts('/foo'), function (err, res, pkg) { - if (err) t.fail(err); - t.equal(res, '/foo/node_modules/bar/baz.js'); - t.equal(pkg.main, './baz.js'); + if (err) return t.fail(err); + t.equal(res, path.resolve('/foo/node_modules/bar/baz.js')); + t.equal(pkg && pkg.main, './baz.js'); }); }); test('mock package from package', function (t) { t.plan(2); - - var files = { - '/foo/node_modules/bar/baz.js' : 'beep', - '/foo/node_modules/bar/package.json' : JSON.stringify({ - main : './baz.js' - }) - }; - - function opts (basedir) { + + var files = {}; + files[path.resolve('/foo/node_modules/bar/baz.js')] = 'beep'; + files[path.resolve('/foo/node_modules/bar/package.json')] = JSON.stringify({ + main: './baz.js' + }); + + function opts(basedir) { return { - basedir : basedir, - package : { main: 'bar' }, - isFile : function (file, cb) { - cb(null, files.hasOwnProperty(file)); + basedir: path.resolve(basedir), + isFile: function (file, cb) { + cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file))); }, - readFile : function (file, cb) { - cb(null, files[file]); + 'package': { main: 'bar' }, + readFile: function (file, cb) { + cb(null, files[path.resolve(file)]); } - } + }; } - + resolve('bar', opts('/foo'), function (err, res, pkg) { - if (err) t.fail(err); - t.equal(res, '/foo/node_modules/bar/baz.js'); - t.equal(pkg.main, './baz.js'); + if (err) return t.fail(err); + t.equal(res, path.resolve('/foo/node_modules/bar/baz.js')); + t.equal(pkg && pkg.main, './baz.js'); }); }); diff --git a/node_modules/resolve/test/mock_sync.js b/node_modules/resolve/test/mock_sync.js index abfd28935..43af10289 100644 --- a/node_modules/resolve/test/mock_sync.js +++ b/node_modules/resolve/test/mock_sync.js @@ -1,35 +1,35 @@ +var path = require('path'); var test = require('tape'); var resolve = require('../'); test('mock', function (t) { t.plan(4); - - var files = { - '/foo/bar/baz.js' : 'beep' - }; - - function opts (basedir) { + + var files = {}; + files[path.resolve('/foo/bar/baz.js')] = 'beep'; + + function opts(basedir) { return { - basedir : basedir, - isFile : function (file) { - return files.hasOwnProperty(file) + basedir: path.resolve(basedir), + isFile: function (file) { + return Object.prototype.hasOwnProperty.call(files, file); }, - readFileSync : function (file) { - return files[file] + readFileSync: function (file) { + return files[file]; } - } + }; } - + t.equal( resolve.sync('./baz', opts('/foo/bar')), - '/foo/bar/baz.js' + path.resolve('/foo/bar/baz.js') ); - + t.equal( resolve.sync('./baz.js', opts('/foo/bar')), - '/foo/bar/baz.js' + path.resolve('/foo/bar/baz.js') ); - + t.throws(function () { resolve.sync('baz', opts('/foo/bar')); }); @@ -41,28 +41,27 @@ test('mock', function (t) { test('mock package', function (t) { t.plan(1); - - var files = { - '/foo/node_modules/bar/baz.js' : 'beep', - '/foo/node_modules/bar/package.json' : JSON.stringify({ - main : './baz.js' - }) - }; - - function opts (basedir) { + + var files = {}; + files[path.resolve('/foo/node_modules/bar/baz.js')] = 'beep'; + files[path.resolve('/foo/node_modules/bar/package.json')] = JSON.stringify({ + main: './baz.js' + }); + + function opts(basedir) { return { - basedir : basedir, - isFile : function (file) { - return files.hasOwnProperty(file) + basedir: path.resolve(basedir), + isFile: function (file) { + return Object.prototype.hasOwnProperty.call(files, file); }, - readFileSync : function (file) { - return files[file] + readFileSync: function (file) { + return files[file]; } - } + }; } - + t.equal( resolve.sync('bar', opts('/foo')), - '/foo/node_modules/bar/baz.js' + path.resolve('/foo/node_modules/bar/baz.js') ); }); diff --git a/node_modules/resolve/test/module_dir.js b/node_modules/resolve/test/module_dir.js index 06395d8cb..b50e5bb17 100644 --- a/node_modules/resolve/test/module_dir.js +++ b/node_modules/resolve/test/module_dir.js @@ -4,53 +4,53 @@ var resolve = require('../'); test('moduleDirectory strings', function (t) { t.plan(4); - var dir = __dirname + '/module_dir'; + var dir = path.join(__dirname, 'module_dir'); var xopts = { - basedir : dir, + basedir: dir, moduleDirectory: 'xmodules' }; resolve('aaa', xopts, function (err, res, pkg) { t.ifError(err); - t.equal(res, dir + '/xmodules/aaa/index.js'); + t.equal(res, path.join(dir, '/xmodules/aaa/index.js')); }); - + var yopts = { - basedir : dir, + basedir: dir, moduleDirectory: 'ymodules' }; resolve('aaa', yopts, function (err, res, pkg) { t.ifError(err); - t.equal(res, dir + '/ymodules/aaa/index.js'); + t.equal(res, path.join(dir, '/ymodules/aaa/index.js')); }); }); test('moduleDirectory array', function (t) { t.plan(6); - var dir = __dirname + '/module_dir'; + var dir = path.join(__dirname, 'module_dir'); var aopts = { - basedir : dir, - moduleDirectory: [ 'xmodules', 'ymodules', 'zmodules' ] + basedir: dir, + moduleDirectory: ['xmodules', 'ymodules', 'zmodules'] }; resolve('aaa', aopts, function (err, res, pkg) { t.ifError(err); - t.equal(res, dir + '/xmodules/aaa/index.js'); + t.equal(res, path.join(dir, '/xmodules/aaa/index.js')); }); - + var bopts = { - basedir : dir, - moduleDirectory: [ 'zmodules', 'ymodules', 'xmodules' ] + basedir: dir, + moduleDirectory: ['zmodules', 'ymodules', 'xmodules'] }; resolve('aaa', bopts, function (err, res, pkg) { t.ifError(err); - t.equal(res, dir + '/ymodules/aaa/index.js'); + t.equal(res, path.join(dir, '/ymodules/aaa/index.js')); }); - + var copts = { - basedir : dir, - moduleDirectory: [ 'xmodules', 'ymodules', 'zmodules' ] + basedir: dir, + moduleDirectory: ['xmodules', 'ymodules', 'zmodules'] }; resolve('bbb', copts, function (err, res, pkg) { t.ifError(err); - t.equal(res, dir + '/zmodules/bbb/main.js'); + t.equal(res, path.join(dir, '/zmodules/bbb/main.js')); }); }); diff --git a/node_modules/resolve/test/module_dir/xmodules/aaa/index.js b/node_modules/resolve/test/module_dir/xmodules/aaa/index.js index 55cd18ca7..dd7cf7b2d 100644 --- a/node_modules/resolve/test/module_dir/xmodules/aaa/index.js +++ b/node_modules/resolve/test/module_dir/xmodules/aaa/index.js @@ -1 +1 @@ -module.exports = function (x) { return x * 100 } +module.exports = function (x) { return x * 100; }; diff --git a/node_modules/resolve/test/module_dir/ymodules/aaa/index.js b/node_modules/resolve/test/module_dir/ymodules/aaa/index.js index 651aca860..ef2d4d4bf 100644 --- a/node_modules/resolve/test/module_dir/ymodules/aaa/index.js +++ b/node_modules/resolve/test/module_dir/ymodules/aaa/index.js @@ -1 +1 @@ -module.exports = function (x) { return x + 100 } +module.exports = function (x) { return x + 100; }; diff --git a/node_modules/resolve/test/module_dir/zmodules/bbb/main.js b/node_modules/resolve/test/module_dir/zmodules/bbb/main.js index 4325a0bd5..e8ba62993 100644 --- a/node_modules/resolve/test/module_dir/zmodules/bbb/main.js +++ b/node_modules/resolve/test/module_dir/zmodules/bbb/main.js @@ -1 +1 @@ -module.exports = function (n) { return n * 111 } +module.exports = function (n) { return n * 111; }; diff --git a/node_modules/resolve/test/node-modules-paths.js b/node_modules/resolve/test/node-modules-paths.js new file mode 100644 index 000000000..a917f063a --- /dev/null +++ b/node_modules/resolve/test/node-modules-paths.js @@ -0,0 +1,93 @@ +var test = require('tape'); +var path = require('path'); +var parse = path.parse || require('path-parse'); +var keys = require('object-keys'); + +var nodeModulesPaths = require('../lib/node-modules-paths'); + +var verifyDirs = function verifyDirs(t, start, dirs, moduleDirectories, paths) { + var moduleDirs = [].concat(moduleDirectories || 'node_modules'); + + var foundModuleDirs = {}; + var uniqueDirs = {}; + var parsedDirs = {}; + for (var i = 0; i < dirs.length; ++i) { + var parsed = parse(dirs[i]); + if (!foundModuleDirs[parsed.base]) { foundModuleDirs[parsed.base] = 0; } + foundModuleDirs[parsed.base] += 1; + parsedDirs[parsed.dir] = true; + uniqueDirs[dirs[i]] = true; + } + t.equal(keys(parsedDirs).length >= start.split(path.sep).length, true, 'there are >= dirs than "start" has'); + var foundModuleDirNames = keys(foundModuleDirs); + t.deepEqual(foundModuleDirNames, moduleDirs.concat(paths || []), 'all desired module dirs were found'); + t.equal(keys(uniqueDirs).length, dirs.length, 'all dirs provided were unique'); + + var counts = {}; + for (var j = 0; j < foundModuleDirNames.length; ++j) { + 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) { + var start = path.join(__dirname, 'resolver'); + var dirs = nodeModulesPaths(start); + + verifyDirs(t, start, dirs); + + t.end(); + }); + + t.test('empty options', function (t) { + var start = path.join(__dirname, 'resolver'); + var dirs = nodeModulesPaths(start, {}); + + verifyDirs(t, start, dirs); + + t.end(); + }); + + t.test('with paths option', function (t) { + var start = path.join(__dirname, 'resolver'); + var paths = ['a', 'b']; + var dirs = nodeModulesPaths(start, { paths: paths }); + + verifyDirs(t, start, dirs, null, paths); + + t.end(); + }); + + t.test('with moduleDirectory option', function (t) { + var start = path.join(__dirname, 'resolver'); + var moduleDirectory = 'not node modules'; + var dirs = nodeModulesPaths(start, { moduleDirectory: moduleDirectory }); + + verifyDirs(t, start, dirs, moduleDirectory); + + t.end(); + }); + + t.test('with 1 moduleDirectory and paths options', function (t) { + var start = path.join(__dirname, 'resolver'); + var paths = ['a', 'b']; + var moduleDirectory = 'not node modules'; + var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectory }); + + verifyDirs(t, start, dirs, moduleDirectory, paths); + + t.end(); + }); + + t.test('with 1+ moduleDirectory and paths options', function (t) { + var start = path.join(__dirname, 'resolver'); + var paths = ['a', 'b']; + var moduleDirectories = ['not node modules', 'other modules']; + var dirs = nodeModulesPaths(start, { paths: paths, moduleDirectory: moduleDirectories }); + + verifyDirs(t, start, dirs, moduleDirectories, paths); + + t.end(); + }); +}); diff --git a/node_modules/resolve/test/node_path.js b/node_modules/resolve/test/node_path.js index 2407189b8..38a7d7e7d 100644 --- a/node_modules/resolve/test/node_path.js +++ b/node_modules/resolve/test/node_path.js @@ -4,45 +4,46 @@ var resolve = require('../'); test('$NODE_PATH', function (t) { t.plan(4); - + resolve('aaa', { paths: [ - __dirname + '/node_path/x', - __dirname + '/node_path/y' + path.join(__dirname, '/node_path/x'), + path.join(__dirname, '/node_path/y') ], - basedir: __dirname, + basedir: __dirname }, function (err, res) { - t.equal(res, __dirname + '/node_path/x/aaa/index.js'); + t.equal(res, path.join(__dirname, '/node_path/x/aaa/index.js')); }); - + resolve('bbb', { paths: [ - __dirname + '/node_path/x', - __dirname + '/node_path/y' + path.join(__dirname, '/node_path/x'), + path.join(__dirname, '/node_path/y') ], - basedir: __dirname, + basedir: __dirname }, function (err, res) { - t.equal(res, __dirname + '/node_path/y/bbb/index.js'); + t.equal(res, path.join(__dirname, '/node_path/y/bbb/index.js')); }); - + resolve('ccc', { paths: [ - __dirname + '/node_path/x', - __dirname + '/node_path/y' + path.join(__dirname, '/node_path/x'), + path.join(__dirname, '/node_path/y') ], - basedir: __dirname, + basedir: __dirname }, function (err, res) { - t.equal(res, __dirname + '/node_path/x/ccc/index.js'); + t.equal(res, path.join(__dirname, '/node_path/x/ccc/index.js')); }); // ensure that relative paths still resolve against the // regular `node_modules` correctly resolve('tap', { paths: [ - 'node_path', + 'node_path' ], - basedir: 'node_path/x', + basedir: 'node_path/x' }, function (err, res) { - t.equal(res, path.resolve(__dirname, '..', 'node_modules/tap/lib/main.js')); + var root = require('tap/package.json').main; + t.equal(res, path.resolve(__dirname, '..', 'node_modules/tap', root)); }); }); diff --git a/node_modules/resolve/test/node_path/x/aaa/index.js b/node_modules/resolve/test/node_path/x/aaa/index.js index 1ea591380..ad70d0bb0 100644 --- a/node_modules/resolve/test/node_path/x/aaa/index.js +++ b/node_modules/resolve/test/node_path/x/aaa/index.js @@ -1 +1 @@ -module.exports = 'A' +module.exports = 'A'; diff --git a/node_modules/resolve/test/node_path/x/ccc/index.js b/node_modules/resolve/test/node_path/x/ccc/index.js index f186fa757..a64132e4c 100644 --- a/node_modules/resolve/test/node_path/x/ccc/index.js +++ b/node_modules/resolve/test/node_path/x/ccc/index.js @@ -1 +1 @@ -module.exports = 'C' +module.exports = 'C'; diff --git a/node_modules/resolve/test/node_path/y/bbb/index.js b/node_modules/resolve/test/node_path/y/bbb/index.js index e22dd83c0..4d0f32e24 100644 --- a/node_modules/resolve/test/node_path/y/bbb/index.js +++ b/node_modules/resolve/test/node_path/y/bbb/index.js @@ -1 +1 @@ -module.exports = 'B' +module.exports = 'B'; diff --git a/node_modules/resolve/test/node_path/y/ccc/index.js b/node_modules/resolve/test/node_path/y/ccc/index.js index d0043d1ec..793315e84 100644 --- a/node_modules/resolve/test/node_path/y/ccc/index.js +++ b/node_modules/resolve/test/node_path/y/ccc/index.js @@ -1 +1 @@ -module.exports = 'CY' +module.exports = 'CY'; diff --git a/node_modules/resolve/test/pathfilter.js b/node_modules/resolve/test/pathfilter.js index 142f94d65..733045a06 100644 --- a/node_modules/resolve/test/pathfilter.js +++ b/node_modules/resolve/test/pathfilter.js @@ -1,35 +1,42 @@ +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 = __dirname + '/pathfilter/deep_ref'; - var pathFilter = function(pkg, x, remainder){ - t.equal(pkg.version, "1.2.3"); - t.equal(x, resolverDir + '/node_modules/deep/ref'); - t.equal(remainder, "ref"); - return "alt"; - }; - - resolve('deep/ref', { basedir : resolverDir }, function (err, res, pkg) { - if (err) t.fail(err); +test('#62: deep module references and the pathFilter', function (t) { + t.plan(9); - t.equal(pkg.version, "1.2.3"); - t.equal(res, resolverDir + '/node_modules/deep/ref.js'); - }); + var resolverDir = path.join(__dirname, '/pathfilter/deep_ref'); + var pathFilter = function (pkg, x, remainder) { + t.equal(pkg.version, '1.2.3'); + t.equal(x, path.join(resolverDir, 'node_modules/deep/ref')); + t.equal(remainder, 'ref'); + return 'alt'; + }; - 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, resolverDir + '/node_modules/deep/deeper/ref.js'); - }); - - resolve('deep/ref', { basedir : resolverDir, pathFilter : pathFilter }, - function (err, res, pkg) { + resolve('deep/ref', { basedir: resolverDir }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, resolverDir + '/node_modules/deep/alt.js'); + + t.equal(pkg.version, '1.2.3'); + t.equal(res, path.join(resolverDir, 'node_modules/deep/ref.js')); }); + + 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')); + } + ); }); diff --git a/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/alt.js b/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/alt.js deleted file mode 100644 index e69de29bb..000000000 --- a/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/alt.js +++ /dev/null diff --git a/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/deeper/ref.js b/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/deeper/ref.js deleted file mode 100644 index e69de29bb..000000000 --- a/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/deeper/ref.js +++ /dev/null diff --git a/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/package.json b/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/package.json deleted file mode 100644 index fe4b408a0..000000000 --- a/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "deep", - "version": "1.2.3" -} diff --git a/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/ref.js b/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/ref.js deleted file mode 100644 index e69de29bb..000000000 --- a/node_modules/resolve/test/pathfilter/deep_ref/node_modules/deep/ref.js +++ /dev/null diff --git a/node_modules/resolve/test/precedence.js b/node_modules/resolve/test/precedence.js index c716f0e9f..2febb598f 100644 --- a/node_modules/resolve/test/precedence.js +++ b/node_modules/resolve/test/precedence.js @@ -5,19 +5,19 @@ var resolve = require('../'); test('precedence', function (t) { t.plan(3); var dir = path.join(__dirname, 'precedence/aaa'); - - resolve('./', { basedir : dir }, function (err, res, pkg) { + + resolve('./', { basedir: dir }, function (err, res, pkg) { t.ifError(err); t.equal(res, path.join(dir, 'index.js')); t.equal(pkg.name, 'resolve'); }); }); -test('./ should not load ${dir}.js', function (t) { +test('./ should not load ${dir}.js', function (t) { // eslint-disable-line no-template-curly-in-string t.plan(1); var dir = path.join(__dirname, 'precedence/bbb'); - - resolve('./', { basedir : dir }, function (err, res, pkg) { + + resolve('./', { basedir: dir }, function (err, res, pkg) { t.ok(err); }); }); diff --git a/node_modules/resolve/test/precedence/aaa.js b/node_modules/resolve/test/precedence/aaa.js index a182397c5..b83a3e7ad 100644 --- a/node_modules/resolve/test/precedence/aaa.js +++ b/node_modules/resolve/test/precedence/aaa.js @@ -1 +1 @@ -module.exports = 'wtf' +module.exports = 'wtf'; diff --git a/node_modules/resolve/test/precedence/aaa/index.js b/node_modules/resolve/test/precedence/aaa/index.js index 993b03c2c..e0f8f6abf 100644 --- a/node_modules/resolve/test/precedence/aaa/index.js +++ b/node_modules/resolve/test/precedence/aaa/index.js @@ -1 +1 @@ -module.exports = 'okok' +module.exports = 'okok'; diff --git a/node_modules/resolve/test/precedence/aaa/main.js b/node_modules/resolve/test/precedence/aaa/main.js index db38959d7..93542a965 100644 --- a/node_modules/resolve/test/precedence/aaa/main.js +++ b/node_modules/resolve/test/precedence/aaa/main.js @@ -1 +1 @@ -console.log(require('./')) +console.log(require('./')); diff --git a/node_modules/resolve/test/precedence/bbb.js b/node_modules/resolve/test/precedence/bbb.js index c8a9996b3..2298f47fd 100644 --- a/node_modules/resolve/test/precedence/bbb.js +++ b/node_modules/resolve/test/precedence/bbb.js @@ -1 +1 @@ -module.exports '>_<' +module.exports = '>_<'; diff --git a/node_modules/resolve/test/resolver.js b/node_modules/resolve/test/resolver.js index 5bbb05f90..adde54441 100644 --- a/node_modules/resolve/test/resolver.js +++ b/node_modules/resolve/test/resolver.js @@ -3,279 +3,325 @@ var test = require('tape'); var resolve = require('../'); test('async foo', function (t) { - t.plan(9); - var dir = __dirname + '/resolver'; - - resolve('./foo', { basedir : dir }, function (err, res, pkg) { + t.plan(10); + var dir = path.join(__dirname, 'resolver'); + + resolve('./foo', { basedir: dir }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/foo.js'); - t.equal(pkg.name, 'resolve'); + t.equal(res, path.join(dir, 'foo.js')); + t.equal(pkg && pkg.name, 'resolve'); }); - - resolve('./foo.js', { basedir : dir }, function (err, res, pkg) { + + resolve('./foo.js', { basedir: dir }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/foo.js'); - t.equal(pkg.name, 'resolve'); + t.equal(res, path.join(dir, 'foo.js')); + t.equal(pkg && pkg.name, 'resolve'); }); - - resolve('./foo', { basedir : dir, package: { main: 'resolver' } }, function (err, res, pkg) { + + resolve('./foo', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/foo.js'); - t.equal(pkg.main, 'resolver'); + t.equal(res, path.join(dir, 'foo.js')); + t.equal(pkg && pkg.main, 'resolver'); }); - - resolve('./foo.js', { basedir : dir, package: { main: 'resolver' } }, function (err, res, pkg) { + + resolve('./foo.js', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/foo.js'); + t.equal(res, path.join(dir, 'foo.js')); t.equal(pkg.main, 'resolver'); }); - - resolve('foo', { basedir : dir }, function (err) { + + 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('bar', function (t) { t.plan(6); - var dir = __dirname + '/resolver'; - - resolve('foo', { basedir : dir + '/bar' }, function (err, res, pkg) { + var dir = path.join(__dirname, 'resolver'); + + resolve('foo', { basedir: dir + '/bar' }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/bar/node_modules/foo/index.js'); + t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js')); t.equal(pkg, undefined); }); - - resolve('foo', { basedir : dir + '/bar' }, function (err, res, pkg) { + + resolve('foo', { basedir: dir + '/bar' }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/bar/node_modules/foo/index.js'); + t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js')); t.equal(pkg, undefined); }); - - resolve('foo', { basedir : dir + '/bar', package: { main: 'bar' } }, function (err, res, pkg) { + + resolve('foo', { basedir: dir + '/bar', 'package': { main: 'bar' } }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/bar/node_modules/foo/index.js'); + t.equal(res, path.join(dir, 'bar/node_modules/foo/index.js')); t.equal(pkg, undefined); }); }); test('baz', function (t) { t.plan(4); - var dir = __dirname + '/resolver'; - - resolve('./baz', { basedir : dir }, function (err, res, pkg) { + var dir = path.join(__dirname, 'resolver'); + + resolve('./baz', { basedir: dir }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/baz/quux.js'); + t.equal(res, path.join(dir, 'baz/quux.js')); t.equal(pkg.main, 'quux.js'); }); - - resolve('./baz', { basedir : dir, package: { main: 'resolver' } }, function (err, res, pkg) { + + resolve('./baz', { basedir: dir, 'package': { main: 'resolver' } }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/baz/quux.js'); + t.equal(res, path.join(dir, 'baz/quux.js')); t.equal(pkg.main, 'quux.js'); }); }); test('biz', function (t) { t.plan(24); - var dir = __dirname + '/resolver/biz/node_modules'; - - resolve('./grux', { basedir : dir }, function (err, res, pkg) { + var dir = path.join(__dirname, 'resolver/biz/node_modules'); + + resolve('./grux', { basedir: dir }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/grux/index.js'); + t.equal(res, path.join(dir, 'grux/index.js')); t.equal(pkg, undefined); }); - - resolve('./grux', { basedir : dir, package: { main: 'biz' } }, function (err, res, pkg) { + + resolve('./grux', { basedir: dir, 'package': { main: 'biz' } }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/grux/index.js'); + t.equal(res, path.join(dir, 'grux/index.js')); t.equal(pkg.main, 'biz'); }); - - resolve('./garply', { basedir : dir }, function (err, res, pkg) { + + resolve('./garply', { basedir: dir }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/garply/lib/index.js'); + t.equal(res, path.join(dir, 'garply/lib/index.js')); t.equal(pkg.main, './lib'); }); - - resolve('./garply', { basedir : dir, package: { main: 'biz' } }, function (err, res, pkg) { + + resolve('./garply', { basedir: dir, 'package': { main: 'biz' } }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/garply/lib/index.js'); + t.equal(res, path.join(dir, 'garply/lib/index.js')); t.equal(pkg.main, './lib'); }); - - resolve('tiv', { basedir : dir + '/grux' }, function (err, res, pkg) { + + resolve('tiv', { basedir: dir + '/grux' }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/tiv/index.js'); + t.equal(res, path.join(dir, 'tiv/index.js')); t.equal(pkg, undefined); }); - - resolve('tiv', { basedir : dir + '/grux', package: { main: 'grux' } }, function (err, res, pkg) { + + resolve('tiv', { basedir: dir + '/grux', 'package': { main: 'grux' } }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/tiv/index.js'); + t.equal(res, path.join(dir, 'tiv/index.js')); t.equal(pkg, undefined); }); - - resolve('tiv', { basedir : dir + '/garply' }, function (err, res, pkg) { + + resolve('tiv', { basedir: dir + '/garply' }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/tiv/index.js'); + t.equal(res, path.join(dir, 'tiv/index.js')); t.equal(pkg, undefined); }); - - resolve('tiv', { basedir : dir + '/garply', package: { main: './lib' } }, function (err, res, pkg) { + + resolve('tiv', { basedir: dir + '/garply', 'package': { main: './lib' } }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/tiv/index.js'); + t.equal(res, path.join(dir, 'tiv/index.js')); t.equal(pkg, undefined); }); - - resolve('grux', { basedir : dir + '/tiv' }, function (err, res, pkg) { + + resolve('grux', { basedir: dir + '/tiv' }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/grux/index.js'); + t.equal(res, path.join(dir, 'grux/index.js')); t.equal(pkg, undefined); }); - - resolve('grux', { basedir : dir + '/tiv', package: { main: 'tiv' } }, function (err, res, pkg) { + + resolve('grux', { basedir: dir + '/tiv', 'package': { main: 'tiv' } }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/grux/index.js'); + t.equal(res, path.join(dir, 'grux/index.js')); t.equal(pkg, undefined); }); - - resolve('garply', { basedir : dir + '/tiv' }, function (err, res, pkg) { + + resolve('garply', { basedir: dir + '/tiv' }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/garply/lib/index.js'); + t.equal(res, path.join(dir, 'garply/lib/index.js')); t.equal(pkg.main, './lib'); }); - - resolve('garply', { basedir : dir + '/tiv', package: { main: 'tiv' } }, function (err, res, pkg) { + + resolve('garply', { basedir: dir + '/tiv', 'package': { main: 'tiv' } }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/garply/lib/index.js'); + t.equal(res, path.join(dir, 'garply/lib/index.js')); t.equal(pkg.main, './lib'); }); }); test('quux', function (t) { t.plan(2); - var dir = __dirname + '/resolver/quux'; - - resolve('./foo', { basedir : dir, package: { main: 'quux' } }, function (err, res, pkg) { + var dir = path.join(__dirname, 'resolver/quux'); + + resolve('./foo', { basedir: dir, 'package': { main: 'quux' } }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/foo/index.js'); + t.equal(res, path.join(dir, 'foo/index.js')); t.equal(pkg.main, 'quux'); }); }); test('normalize', function (t) { t.plan(2); - var dir = __dirname + '/resolver/biz/node_modules/grux'; - - resolve('../grux', { basedir : dir }, function (err, res, pkg) { + var dir = path.join(__dirname, 'resolver/biz/node_modules/grux'); + + resolve('../grux', { basedir: dir }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/index.js'); + t.equal(res, path.join(dir, 'index.js')); t.equal(pkg, undefined); }); }); test('cup', function (t) { - t.plan(3); - var dir = __dirname + '/resolver'; - - resolve('./cup', { basedir : dir, extensions : [ '.js', '.coffee' ] }, - function (err, res) { + t.plan(4); + var dir = path.join(__dirname, 'resolver'); + + resolve('./cup', { basedir: dir, extensions: ['.js', '.coffee'] }, function (err, res) { if (err) t.fail(err); - t.equal(res, dir + '/cup.coffee'); + t.equal(res, path.join(dir, 'cup.coffee')); }); - - resolve('./cup.coffee', { basedir : dir }, function (err, res) { + + resolve('./cup.coffee', { basedir: dir }, function (err, res) { if (err) t.fail(err); - t.equal(res, dir + '/cup.coffee'); + t.equal(res, path.join(dir, 'cup.coffee')); }); - - resolve('./cup', { basedir : dir, extensions : [ '.js' ] }, - function (err, res) { + + resolve('./cup', { basedir: dir, extensions: ['.js'] }, function (err, res) { t.equal(err.message, "Cannot find module './cup' from '" + path.resolve(dir) + "'"); + t.equal(err.code, 'MODULE_NOT_FOUND'); }); }); test('mug', function (t) { t.plan(3); - var dir = __dirname + '/resolver'; - - resolve('./mug', { basedir : dir }, function (err, res) { + var dir = path.join(__dirname, 'resolver'); + + resolve('./mug', { basedir: dir }, function (err, res) { if (err) t.fail(err); - t.equal(res, dir + '/mug.js'); + t.equal(res, path.join(dir, 'mug.js')); }); - - resolve('./mug', { basedir : dir, extensions : [ '.coffee', '.js' ] }, - function (err, res) { + + resolve('./mug', { basedir: dir, extensions: ['.coffee', '.js'] }, function (err, res) { if (err) t.fail(err); - t.equal(res, dir + '/mug.coffee'); + t.equal(res, path.join(dir, '/mug.coffee')); }); - - resolve('./mug', { basedir : dir, extensions : [ '.js', '.coffee' ] }, - function (err, res) { - t.equal(res, dir + '/mug.js'); + + resolve('./mug', { basedir: dir, extensions: ['.js', '.coffee'] }, function (err, res) { + t.equal(res, path.join(dir, '/mug.js')); }); }); test('other path', function (t) { - t.plan(4); - var resolverDir = __dirname + '/resolver'; - var dir = resolverDir + '/bar'; - var otherDir = resolverDir + '/other_path'; - - resolve('root', { basedir : dir, paths: [otherDir] }, function (err, res) { + t.plan(6); + var resolverDir = path.join(__dirname, 'resolver'); + var dir = path.join(resolverDir, 'bar'); + var otherDir = path.join(resolverDir, 'other_path'); + + resolve('root', { basedir: dir, paths: [otherDir] }, function (err, res) { if (err) t.fail(err); - t.equal(res, resolverDir + '/other_path/root.js'); + t.equal(res, path.join(resolverDir, 'other_path/root.js')); }); - - resolve('lib/other-lib', { basedir : dir, paths: [otherDir] }, - function (err, res) { + + resolve('lib/other-lib', { basedir: dir, paths: [otherDir] }, function (err, res) { if (err) t.fail(err); - t.equal(res, resolverDir + '/other_path/lib/other-lib.js'); + t.equal(res, path.join(resolverDir, 'other_path/lib/other-lib.js')); }); - - resolve('root', { basedir : dir, }, function (err, res) { + + resolve('root', { basedir: dir }, function (err, res) { t.equal(err.message, "Cannot find module 'root' from '" + path.resolve(dir) + "'"); + t.equal(err.code, 'MODULE_NOT_FOUND'); }); - - resolve('zzz', { basedir : dir, paths: [otherDir] }, function (err, res) { + + resolve('zzz', { basedir: dir, paths: [otherDir] }, function (err, res) { t.equal(err.message, "Cannot find module 'zzz' from '" + path.resolve(dir) + "'"); + t.equal(err.code, 'MODULE_NOT_FOUND'); }); }); test('incorrect main', function (t) { - t.plan(1) + t.plan(1); - var resolverDir = __dirname + '/resolver'; - var dir = resolverDir + '/incorrect_main'; + var resolverDir = path.join(__dirname, 'resolver'); + var dir = path.join(resolverDir, 'incorrect_main'); - resolve('./incorrect_main', { basedir : resolverDir }, function (err, res, pkg) { + resolve('./incorrect_main', { basedir: resolverDir }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, dir + '/index.js'); + t.equal(res, path.join(dir, 'index.js')); }); }); test('without basedir', function (t) { t.plan(1); - var dir = __dirname + '/resolver/without_basedir'; - var tester = require(dir + '/main.js'); + var dir = path.join(__dirname, 'resolver/without_basedir'); + var tester = require(path.join(dir, 'main.js')); - tester(t, function (err, res, pkg){ + tester(t, function (err, res, pkg) { if (err) { - t.fail(err); - } else { - t.equal(res, dir + '/node_modules/mymodule.js'); - } + t.fail(err); + } else { + t.equal(res, path.join(dir, 'node_modules/mymodule.js')); + } }); }); test('#25: node modules with the same name as node stdlib modules', function (t) { t.plan(1); - var resolverDir = __dirname + '/resolver/punycode'; + var resolverDir = path.join(__dirname, 'resolver/punycode'); - resolve('punycode', { basedir : resolverDir }, function (err, res, pkg) { + resolve('punycode', { basedir: resolverDir }, function (err, res, pkg) { if (err) t.fail(err); - t.equal(res, resolverDir + '/node_modules/punycode/index.js'); + t.equal(res, path.join(resolverDir, 'node_modules/punycode/index.js')); }); }); + +test('#52 - incorrectly resolves module-paths like "./someFolder/" when there is a file of the same name', function (t) { + t.plan(2); + + var dir = path.join(__dirname, 'resolver'); + + resolve('./foo', { basedir: path.join(dir, 'same_names') }, function (err, res, pkg) { + if (err) t.fail(err); + t.equal(res, path.join(dir, 'same_names/foo.js')); + }); + + resolve('./foo/', { basedir: path.join(dir, 'same_names') }, function (err, res, pkg) { + if (err) t.fail(err); + t.equal(res, path.join(dir, 'same_names/foo/index.js')); + }); +}); + +test('async: #121 - treating an existing file as a dir when no basedir', function (t) { + var testFile = path.basename(__filename); + + t.test('sanity check', function (st) { + st.plan(1); + resolve('./' + testFile, function (err, res, pkg) { + if (err) t.fail(err); + st.equal(res, __filename, 'sanity check'); + }); + }); + + t.test('with a fake directory', function (st) { + st.plan(4); + + resolve('./' + testFile + '/blah', function (err, res, pkg) { + st.ok(err, 'there is an error'); + st.notOk(res, 'no result'); + + st.equal(err && err.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve'); + st.equal( + err && err.message, + 'Cannot find module \'./' + testFile + '/blah\' from \'' + __dirname + '\'', + 'can not find nonexistent module' + ); + st.end(); + }); + }); + + t.end(); +}); diff --git a/node_modules/resolve/test/resolver/baz/package.json b/node_modules/resolve/test/resolver/baz/package.json index 6b81dcddf..c41e4dbf7 100644 --- a/node_modules/resolve/test/resolver/baz/package.json +++ b/node_modules/resolve/test/resolver/baz/package.json @@ -1,3 +1,3 @@ { - "main" : "quux.js" + "main": "quux.js" } diff --git a/node_modules/resolve/test/resolver/biz/node_modules/garply/lib/index.js b/node_modules/resolve/test/resolver/biz/node_modules/garply/lib/index.js deleted file mode 100644 index 0379e29f7..000000000 --- a/node_modules/resolve/test/resolver/biz/node_modules/garply/lib/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = 'hello garply'; diff --git a/node_modules/resolve/test/resolver/biz/node_modules/garply/package.json b/node_modules/resolve/test/resolver/biz/node_modules/garply/package.json deleted file mode 100644 index babaac58f..000000000 --- a/node_modules/resolve/test/resolver/biz/node_modules/garply/package.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "main" : "./lib" -} diff --git a/node_modules/resolve/test/resolver/biz/node_modules/grux/index.js b/node_modules/resolve/test/resolver/biz/node_modules/grux/index.js deleted file mode 100644 index 49960555a..000000000 --- a/node_modules/resolve/test/resolver/biz/node_modules/grux/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require('tiv') * 100; diff --git a/node_modules/resolve/test/resolver/biz/node_modules/tiv/index.js b/node_modules/resolve/test/resolver/biz/node_modules/tiv/index.js deleted file mode 100644 index 690aad34a..000000000 --- a/node_modules/resolve/test/resolver/biz/node_modules/tiv/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = 3; diff --git a/node_modules/resolve/test/resolver/incorrect_main/package.json b/node_modules/resolve/test/resolver/incorrect_main/package.json index 1592ed393..b71880417 100644 --- a/node_modules/resolve/test/resolver/incorrect_main/package.json +++ b/node_modules/resolve/test/resolver/incorrect_main/package.json @@ -1,3 +1,3 @@ { - "main" : "wrong.js" + "main": "wrong.js" } diff --git a/node_modules/resolve/test/resolver/punycode/node_modules/punycode/index.js b/node_modules/resolve/test/resolver/punycode/node_modules/punycode/index.js deleted file mode 100644 index e69de29bb..000000000 --- a/node_modules/resolve/test/resolver/punycode/node_modules/punycode/index.js +++ /dev/null diff --git a/node_modules/resolve/test/resolver/same_names/foo.js b/node_modules/resolve/test/resolver/same_names/foo.js new file mode 100644 index 000000000..888cae37a --- /dev/null +++ b/node_modules/resolve/test/resolver/same_names/foo.js @@ -0,0 +1 @@ +module.exports = 42; diff --git a/node_modules/resolve/test/resolver/bar/node_modules/foo/index.js b/node_modules/resolve/test/resolver/same_names/foo/index.js index bd816eaba..bd816eaba 100644 --- a/node_modules/resolve/test/resolver/bar/node_modules/foo/index.js +++ b/node_modules/resolve/test/resolver/same_names/foo/index.js diff --git a/node_modules/resolve/test/resolver/without_basedir/main.js b/node_modules/resolve/test/resolver/without_basedir/main.js index 5f211e9ca..5b31975be 100644 --- a/node_modules/resolve/test/resolver/without_basedir/main.js +++ b/node_modules/resolve/test/resolver/without_basedir/main.js @@ -1,6 +1,5 @@ -resolve = require('../../../'); - -module.exports = function(t, cb) { - resolve('mymodule', null, cb); -} +var resolve = require('../../../'); +module.exports = function (t, cb) { + resolve('mymodule', null, cb); +}; diff --git a/node_modules/resolve/test/resolver/without_basedir/node_modules/mymodule.js b/node_modules/resolve/test/resolver/without_basedir/node_modules/mymodule.js deleted file mode 100644 index 2b58aa408..000000000 --- a/node_modules/resolve/test/resolver/without_basedir/node_modules/mymodule.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = "The tools we use have a profound (and devious!) influence on our thinking habits, and, therefore, on our thinking abilities.- E. Dijkstra" diff --git a/node_modules/resolve/test/resolver_sync.js b/node_modules/resolve/test/resolver_sync.js index 598253171..2bc361020 100644 --- a/node_modules/resolve/test/resolver_sync.js +++ b/node_modules/resolve/test/resolver_sync.js @@ -1,180 +1,253 @@ +var path = require('path'); var test = require('tape'); var resolve = require('../'); test('foo', function (t) { - var dir = __dirname + '/resolver'; - + var dir = path.join(__dirname, 'resolver'); + t.equal( - resolve.sync('./foo', { basedir : dir }), - dir + '/foo.js' + resolve.sync('./foo', { basedir: dir }), + path.join(dir, 'foo.js') ); - + t.equal( - resolve.sync('./foo.js', { basedir : dir }), - dir + '/foo.js' + resolve.sync('./foo.js', { basedir: dir }), + path.join(dir, 'foo.js') ); - + t.throws(function () { - resolve.sync('foo', { basedir : dir }); + resolve.sync('foo', { basedir: dir }); }); - + t.end(); }); test('bar', function (t) { - var dir = __dirname + '/resolver'; - + var dir = path.join(__dirname, 'resolver'); + t.equal( - resolve.sync('foo', { basedir : dir + '/bar' }), - dir + '/bar/node_modules/foo/index.js' + resolve.sync('foo', { basedir: path.join(dir, 'bar') }), + path.join(dir, 'bar/node_modules/foo/index.js') ); t.end(); }); test('baz', function (t) { - var dir = __dirname + '/resolver'; - + var dir = path.join(__dirname, 'resolver'); + t.equal( - resolve.sync('./baz', { basedir : dir }), - dir + '/baz/quux.js' + resolve.sync('./baz', { basedir: dir }), + path.join(dir, 'baz/quux.js') ); t.end(); }); test('biz', function (t) { - var dir = __dirname + '/resolver/biz/node_modules'; + var dir = path.join(__dirname, 'resolver/biz/node_modules'); t.equal( - resolve.sync('./grux', { basedir : dir }), - dir + '/grux/index.js' + resolve.sync('./grux', { basedir: dir }), + path.join(dir, 'grux/index.js') ); - + t.equal( - resolve.sync('tiv', { basedir : dir + '/grux' }), - dir + '/tiv/index.js' + resolve.sync('tiv', { basedir: path.join(dir, 'grux') }), + path.join(dir, 'tiv/index.js') ); - + t.equal( - resolve.sync('grux', { basedir : dir + '/tiv' }), - dir + '/grux/index.js' + resolve.sync('grux', { basedir: path.join(dir, 'tiv') }), + path.join(dir, 'grux/index.js') ); t.end(); }); test('normalize', function (t) { - var dir = __dirname + '/resolver/biz/node_modules/grux'; + var dir = path.join(__dirname, 'resolver/biz/node_modules/grux'); t.equal( - resolve.sync('../grux', { basedir : dir }), - dir + '/index.js' + resolve.sync('../grux', { basedir: dir }), + path.join(dir, 'index.js') ); t.end(); }); test('cup', function (t) { - var dir = __dirname + '/resolver'; + var dir = path.join(__dirname, 'resolver'); t.equal( resolve.sync('./cup', { - basedir : dir, - extensions : [ '.js', '.coffee' ] + basedir: dir, + extensions: ['.js', '.coffee'] }), - dir + '/cup.coffee' + path.join(dir, 'cup.coffee') ); - + t.equal( - resolve.sync('./cup.coffee', { - basedir : dir - }), - dir + '/cup.coffee' + resolve.sync('./cup.coffee', { basedir: dir }), + path.join(dir, 'cup.coffee') ); - + t.throws(function () { resolve.sync('./cup', { - basedir : dir, - extensions : [ '.js' ] - }) + basedir: dir, + extensions: ['.js'] + }); }); - + t.end(); }); test('mug', function (t) { - var dir = __dirname + '/resolver'; + var dir = path.join(__dirname, 'resolver'); t.equal( - resolve.sync('./mug', { basedir : dir }), - dir + '/mug.js' + resolve.sync('./mug', { basedir: dir }), + path.join(dir, 'mug.js') ); - + t.equal( resolve.sync('./mug', { - basedir : dir, - extensions : [ '.coffee', '.js' ] + basedir: dir, + extensions: ['.coffee', '.js'] }), - dir + '/mug.coffee' + path.join(dir, 'mug.coffee') ); - + t.equal( resolve.sync('./mug', { - basedir : dir, - extensions : [ '.js', '.coffee' ] + basedir: dir, + extensions: ['.js', '.coffee'] }), - dir + '/mug.js' + path.join(dir, 'mug.js') ); - + t.end(); }); test('other path', function (t) { - var resolverDir = __dirname + '/resolver'; - var dir = resolverDir + '/bar'; - var otherDir = resolverDir + '/other_path'; + var resolverDir = path.join(__dirname, 'resolver'); + var dir = path.join(resolverDir, 'bar'); + var otherDir = path.join(resolverDir, 'other_path'); - var path = require('path'); - t.equal( resolve.sync('root', { - basedir : dir, - paths: [otherDir] }), - resolverDir + '/other_path/root.js' + basedir: dir, + paths: [otherDir] + }), + path.join(resolverDir, 'other_path/root.js') ); - + t.equal( resolve.sync('lib/other-lib', { - basedir : dir, - paths: [otherDir] }), - resolverDir + '/other_path/lib/other-lib.js' + basedir: dir, + paths: [otherDir] + }), + path.join(resolverDir, 'other_path/lib/other-lib.js') ); t.throws(function () { - resolve.sync('root', { basedir : dir, }); + resolve.sync('root', { basedir: dir }); }); - + t.throws(function () { resolve.sync('zzz', { - basedir : dir, - paths: [otherDir] }); + basedir: dir, + paths: [otherDir] + }); }); - + t.end(); }); test('incorrect main', function (t) { - var resolverDir = __dirname + '/resolver'; - var dir = resolverDir + '/incorrect_main'; + var resolverDir = path.join(__dirname, 'resolver'); + var dir = path.join(resolverDir, 'incorrect_main'); t.equal( - resolve.sync('./incorrect_main', { basedir : resolverDir }), - dir + '/index.js' - ) + resolve.sync('./incorrect_main', { basedir: resolverDir }), + path.join(dir, 'index.js') + ); - t.end() + t.end(); }); test('#25: node modules with the same name as node stdlib modules', function (t) { - var resolverDir = __dirname + '/resolver/punycode'; + var resolverDir = path.join(__dirname, 'resolver/punycode'); + + t.equal( + resolve.sync('punycode', { basedir: resolverDir }), + path.join(resolverDir, 'node_modules/punycode/index.js') + ); + + t.end(); +}); + +var stubStatSync = function stubStatSync(fn) { + var fs = require('fs'); + var statSync = fs.statSync; + try { + fs.statSync = function () { + throw new EvalError('Unknown Error'); + }; + return fn(); + } finally { + fs.statSync = statSync; + } +}; + +test('#79 - re-throw non ENOENT errors from stat', function (t) { + var dir = path.join(__dirname, 'resolver'); + + stubStatSync(function () { + t.throws(function () { + resolve.sync('foo', { basedir: dir }); + }, /Unknown Error/); + }); + t.end(); +}); + +test('#52 - incorrectly resolves module-paths like "./someFolder/" when there is a file of the same name', function (t) { + var dir = path.join(__dirname, 'resolver'); + + t.equal( + resolve.sync('./foo', { basedir: path.join(dir, 'same_names') }), + path.join(dir, 'same_names/foo.js') + ); t.equal( - resolve.sync('punycode', { basedir : resolverDir }), - resolverDir + '/node_modules/punycode/index.js' - ) + resolve.sync('./foo/', { basedir: path.join(dir, 'same_names') }), + path.join(dir, 'same_names/foo/index.js') + ); + t.end(); +}); + +test('sync: #121 - treating an existing file as a dir when no basedir', function (t) { + var testFile = path.basename(__filename); + + t.test('sanity check', function (st) { + st.equal( + resolve.sync('./' + testFile), + __filename, + 'sanity check' + ); + st.end(); + }); - t.end() + t.test('with a fake directory', function (st) { + function run() { return resolve.sync('./' + testFile + '/blah'); } + + st.throws(run, 'throws an error'); + + try { + run(); + } catch (e) { + st.equal(e.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve'); + st.equal( + e.message, + 'Cannot find module \'./' + testFile + '/blah\' from \'' + __dirname + '\'', + 'can not find nonexistent module' + ); + } + + st.end(); + }); + + t.end(); }); diff --git a/node_modules/resolve/test/subdirs.js b/node_modules/resolve/test/subdirs.js index 957abfe0c..b7b8450a9 100644 --- a/node_modules/resolve/test/subdirs.js +++ b/node_modules/resolve/test/subdirs.js @@ -4,7 +4,7 @@ var path = require('path'); test('subdirs', function (t) { t.plan(2); - + var dir = path.join(__dirname, '/subdirs'); resolve('a/b/c/x.json', { basedir: dir }, function (err, res) { t.ifError(err); diff --git a/node_modules/resolve/test/subdirs/node_modules/a/b/c/x.json b/node_modules/resolve/test/subdirs/node_modules/a/b/c/x.json deleted file mode 100644 index 3cc0ecbed..000000000 --- a/node_modules/resolve/test/subdirs/node_modules/a/b/c/x.json +++ /dev/null @@ -1 +0,0 @@ -[1,2,3] diff --git a/node_modules/resolve/test/subdirs/node_modules/a/package.json b/node_modules/resolve/test/subdirs/node_modules/a/package.json deleted file mode 100644 index 0967ef424..000000000 --- a/node_modules/resolve/test/subdirs/node_modules/a/package.json +++ /dev/null @@ -1 +0,0 @@ -{} |