pax_global_header00006660000000000000000000000064131362134100014504gustar00rootroot0000000000000052 comment=744f8162464a104aca60777e5f615418dab3b774 node-resolve-1.4.0/000077500000000000000000000000001313621341000141105ustar00rootroot00000000000000node-resolve-1.4.0/.eslintignore000066400000000000000000000000151313621341000166070ustar00rootroot00000000000000node_modules node-resolve-1.4.0/.eslintrc000066400000000000000000000015671313621341000157450ustar00rootroot00000000000000{ "extends": "@ljharb", "root": true, "rules": { "array-bracket-newline": 0, "array-element-newline": 0, "indent": [2, 4], "strict": 0, "complexity": 0, "consistent-return": 0, "curly": 0, "dot-notation": [2, { "allowKeywords": true }], "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, } } node-resolve-1.4.0/.gitignore000066400000000000000000000001541313621341000161000ustar00rootroot00000000000000# gitignore node_modules # Only apps should have lockfiles npm-shrinkwrap.json package-lock.json yarn.lock node-resolve-1.4.0/.npmrc000066400000000000000000000000231313621341000152230ustar00rootroot00000000000000package-lock=false node-resolve-1.4.0/.travis.yml000066400000000000000000000130441313621341000162230ustar00rootroot00000000000000language: node_js os: - linux node_js: - "8.2" - "7.10" - "6.11" - "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 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' 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;' 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: "8.1" env: TEST=true ALLOW_FAILURE=true - node_js: "8.0" env: TEST=true ALLOW_FAILURE=true - node_js: "7.9" env: TEST=true ALLOW_FAILURE=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.10" 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 node-resolve-1.4.0/LICENSE000066400000000000000000000020611313621341000151140ustar00rootroot00000000000000This software is released under the MIT license: Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. node-resolve-1.4.0/appveyor.yml000066400000000000000000000020361313621341000165010ustar00rootroot00000000000000version: 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 node-resolve-1.4.0/example/000077500000000000000000000000001313621341000155435ustar00rootroot00000000000000node-resolve-1.4.0/example/async.js000066400000000000000000000002331313621341000172140ustar00rootroot00000000000000var resolve = require('../'); resolve('tap', { basedir: __dirname }, function (err, res) { if (err) console.error(err); else console.log(res); }); node-resolve-1.4.0/example/sync.js000066400000000000000000000001471313621341000170570ustar00rootroot00000000000000var resolve = require('../'); var res = resolve.sync('tap', { basedir: __dirname }); console.log(res); node-resolve-1.4.0/index.js000066400000000000000000000003361313621341000155570ustar00rootroot00000000000000var core = require('./lib/core'); 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; node-resolve-1.4.0/lib/000077500000000000000000000000001313621341000146565ustar00rootroot00000000000000node-resolve-1.4.0/lib/async.js000066400000000000000000000154411313621341000163360ustar00rootroot00000000000000var core = require('./core'); var fs = require('fs'); var path = require('path'); var caller = require('./caller.js'); var nodeModulesPaths = require('./node-modules-paths.js'); module.exports = function resolve(x, options, callback) { var cb = callback; var opts = options || {}; if (typeof opts === 'function') { cb = opts; opts = {}; } if (typeof x !== 'string') { var err = new TypeError('Path must be a string.'); return process.nextTick(function () { cb(err); }); } 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 readFile = opts.readFile || fs.readFile; var extensions = opts.extensions || ['.js']; var y = opts.basedir || path.dirname(caller()); opts.paths = opts.paths || []; if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) { var res = path.resolve(y, x); 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 if (core[x]) return cb(null, x); 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); else loadAsDirectory(res, function (err, d, pkg) { 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, thePackage, callback) { var loadAsFilePackage = thePackage; var cb = callback; if (typeof loadAsFilePackage === 'function') { cb = loadAsFilePackage; loadAsFilePackage = undefined; } var exts = [''].concat(extensions); load(exts, x, loadAsFilePackage); function load(exts, x, loadPackage) { if (exts.length === 0) return cb(null, undefined, loadPackage); var file = x + exts[0]; var pkg = loadPackage; if (pkg) onpkg(null, pkg); else loadpkg(path.dirname(file), onpkg); function onpkg(err, pkg_, dir) { pkg = pkg_; if (err) return cb(err); if (dir && pkg && opts.pathFilter) { var rfile = path.relative(dir, file); var rel = rfile.slice(0, rfile.length - exts[0].length); var r = opts.pathFilter(pkg, x, rel); if (r) return load( [''].concat(extensions.slice()), path.resolve(dir, r), pkg ); } isFile(file, onex); } function onex(err, ex) { if (err) return cb(err); if (ex) return cb(null, file, pkg); load(exts.slice(1), x, pkg); } } } function loadpkg(dir, cb) { if (dir === '' || dir === '/') return cb(null); if (process.platform === 'win32' && (/^\w:[/\\]*$/).test(dir)) { return cb(null); } if (/[/\\]node_modules[/\\]*$/.test(dir)) return cb(null); 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); readFile(pkgfile, function (err, body) { if (err) cb(err); try { var pkg = JSON.parse(body); } catch (jsonErr) {} if (pkg && opts.packageFilter) { pkg = opts.packageFilter(pkg, pkgfile); } cb(null, pkg, dir); }); }); } function loadAsDirectory(x, loadAsDirectoryPackage, callback) { var cb = callback; var fpkg = loadAsDirectoryPackage; if (typeof fpkg === 'function') { cb = fpkg; fpkg = opts.package; } 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); readFile(pkgfile, function (err, body) { if (err) return cb(err); try { var pkg = JSON.parse(body); } catch (jsonErr) {} if (opts.packageFilter) { pkg = opts.packageFilter(pkg, pkgfile); } if (pkg.main) { if (pkg.main === '.' || pkg.main === './') { pkg.main = 'index'; } loadAsFile(path.resolve(x, pkg.main), pkg, function (err, m, pkg) { if (err) return cb(err); if (m) return cb(null, m, pkg); if (!pkg) return loadAsFile(path.join(x, 'index'), pkg, cb); var dir = path.resolve(x, pkg.main); loadAsDirectory(dir, pkg, function (err, n, pkg) { if (err) return cb(err); if (n) return cb(null, n, pkg); loadAsFile(path.join(x, 'index'), pkg, cb); }); }); return; } loadAsFile(path.join(x, '/index'), pkg, cb); }); }); } function processDirs(cb, dirs) { if (dirs.length === 0) return cb(null, undefined); var dir = dirs[0]; 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)); } }; node-resolve-1.4.0/lib/caller.js000066400000000000000000000005421313621341000164570ustar00rootroot00000000000000module.exports = function () { // see https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi var origPrepareStackTrace = Error.prepareStackTrace; Error.prepareStackTrace = function (_, stack) { return stack; }; var stack = (new Error()).stack; Error.prepareStackTrace = origPrepareStackTrace; return stack[2].getFileName(); }; node-resolve-1.4.0/lib/core.js000066400000000000000000000013011313621341000161370ustar00rootroot00000000000000var 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; node-resolve-1.4.0/lib/core.json000066400000000000000000000013771313621341000165110ustar00rootroot00000000000000{ "*": [ "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" ] } node-resolve-1.4.0/lib/node-modules-paths.js000066400000000000000000000024611313621341000207270ustar00rootroot00000000000000var path = require('path'); var fs = require('fs'); var parse = path.parse || require('path-parse'); 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 var absoluteStart = path.resolve(start); if (opts && opts.preserveSymlinks === false) { try { absoluteStart = fs.realpathSync(absoluteStart); } catch (err) { if (err.code !== 'ENOENT') { throw err; } } } var prefix = '/'; if (/^([A-Za-z]:)/.test(absoluteStart)) { prefix = ''; } else if (/^\\\\/.test(absoluteStart)) { prefix = '\\\\'; } var paths = [absoluteStart]; var parsed = parse(absoluteStart); while (parsed.dir !== paths[paths.length - 1]) { paths.push(parsed.dir); parsed = parse(parsed.dir); } var dirs = paths.reduce(function (dirs, aPath) { return dirs.concat(modules.map(function (moduleDir) { return path.join(prefix, aPath, moduleDir); })); }, []); return opts && opts.paths ? dirs.concat(opts.paths) : dirs; }; node-resolve-1.4.0/lib/sync.js000066400000000000000000000054351313621341000161770ustar00rootroot00000000000000var core = require('./core'); var fs = require('fs'); var path = require('path'); var caller = require('./caller.js'); var nodeModulesPaths = require('./node-modules-paths.js'); 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 readFileSync = opts.readFileSync || fs.readFileSync; var extensions = opts.extensions || ['.js']; var y = opts.basedir || path.dirname(caller()); opts.paths = opts.paths || []; if (/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/.test(x)) { var res = path.resolve(y, x); 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; 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)) { return file; } } } function loadAsDirectorySync(x) { var pkgfile = path.join(x, '/package.json'); if (isFile(pkgfile)) { try { var body = readFileSync(pkgfile, 'UTF8'); var pkg = JSON.parse(body); if (opts.packageFilter) { pkg = opts.packageFilter(pkg, x); } if (pkg.main) { if (pkg.main === '.' || pkg.main === './') { pkg.main = 'index'; } var m = loadAsFileSync(path.resolve(x, pkg.main)); if (m) return m; var n = loadAsDirectorySync(path.resolve(x, pkg.main)); if (n) return n; } } catch (e) {} } return loadAsFileSync(path.join(x, '/index')); } function loadNodeModulesSync(x, start) { var dirs = nodeModulesPaths(start, opts); for (var i = 0; i < dirs.length; i++) { var dir = dirs[i]; var m = loadAsFileSync(path.join(dir, '/', x)); if (m) return m; var n = loadAsDirectorySync(path.join(dir, '/', x)); if (n) return n; } } }; node-resolve-1.4.0/package.json000066400000000000000000000016401313621341000163770ustar00rootroot00000000000000{ "name": "resolve", "description": "resolve like require.resolve() on behalf of files asynchronously and synchronously", "version": "1.4.0", "repository": { "type": "git", "url": "git://github.com/substack/node-resolve.git" }, "main": "index.js", "keywords": [ "resolve", "require", "node", "module" ], "scripts": { "prepublish": "safe-publish-latest", "lint": "eslint .", "tests-only": "tape test/*.js", "pretest": "npm run lint", "test": "npm run --silent tests-only" }, "devDependencies": { "@ljharb/eslint-config": "^12.2.0", "eslint": "^4.3.0", "object-keys": "^1.0.11", "safe-publish-latest": "^1.1.1", "tap": "0.4.13", "tape": "^4.7.0" }, "license": "MIT", "author": { "name": "James Halliday", "email": "mail@substack.net", "url": "http://substack.net" }, "dependencies": { "path-parse": "^1.0.5" } } node-resolve-1.4.0/readme.markdown000066400000000000000000000110431313621341000171100ustar00rootroot00000000000000# resolve implements the [node `require.resolve()` 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) # example asynchronously resolve: ``` js var resolve = require('resolve'); resolve('tap', { basedir: __dirname }, function (err, res) { if (err) console.error(err) else console.log(res) }); ``` ``` $ node example/async.js /home/substack/projects/node-resolve/node_modules/tap/lib/main.js ``` synchronously resolve: ``` js var resolve = require('resolve'); var res = resolve.sync('tap', { basedir: __dirname }); console.log(res); ``` ``` $ node example/sync.js /home/substack/projects/node-resolve/node_modules/tap/lib/main.js ``` # methods ``` js var resolve = require('resolve') ``` ## resolve(id, opts={}, cb) Asynchronously resolve the module path string `id` into `cb(err, res [, pkg])`, where `pkg` (if defined) is the data from `package.json`. options are: * opts.basedir - directory to begin resolving from * opts.package - `package.json` data applicable to the module being loaded * opts.extensions - array of file extensions to search in order * opts.readFile - how to read files asynchronously * 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.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.moduleDirectory - directory (or directories) in which to recursively look for modules. default: `"node_modules"` * opts.preserveSymlinks - if true, doesn't resolve `basedir` to real path before resolving. This is the way Node resolves dependencies when executed with the [--preserve-symlinks](https://nodejs.org/api/all.html#cli_preserve_symlinks) flag. **Note:** this property is currently `true` by default but it will be changed to `false` in the next major version because *Node's resolution algorithm does not preserve symlinks by default*. default `opts` values: ``` javascript { paths: [], basedir: __dirname, extensions: [ '.js' ], readFile: fs.readFile, 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()) }); }, moduleDirectory: 'node_modules', preserveSymlinks: true } ``` ## resolve.sync(id, opts) Synchronously resolve the module path string `id`, returning the result and throwing an error when `id` can't be resolved. options are: * opts.basedir - directory to begin resolving from * opts.extensions - array of file extensions to search in order * opts.readFile - how to read files synchronously * 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.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"` * opts.preserveSymlinks - if true, doesn't resolve `basedir` to real path before resolving. This is the way Node resolves dependencies when executed with the [--preserve-symlinks](https://nodejs.org/api/all.html#cli_preserve_symlinks) flag. **Note:** this property is currently `true` by default but it will be changed to `false` in the next major version because *Node's resolution algorithm does not preserve symlinks by default*. default `opts` values: ``` javascript { paths: [], basedir: __dirname, extensions: [ '.js' ], readFileSync: fs.readFileSync, isFile: function (file) { try { return fs.statSync(file).isFile() } catch (e) { return false } }, moduleDirectory: 'node_modules', preserveSymlinks: true } ```` ## resolve.isCore(pkg) Return whether a package is in core. # install With [npm](https://npmjs.org) do: ``` npm install resolve ``` # license MIT node-resolve-1.4.0/test/000077500000000000000000000000001313621341000150675ustar00rootroot00000000000000node-resolve-1.4.0/test/core.js000066400000000000000000000013561313621341000163620ustar00rootroot00000000000000var test = require('tape'); var resolve = require('../'); test('core modules', function (t) { 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(); }); node-resolve-1.4.0/test/dotdot.js000066400000000000000000000014371313621341000167270ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('dotdot', function (t) { t.plan(4); var dir = path.join(__dirname, '/dotdot/abc'); resolve('..', { basedir: dir }, function (err, res, pkg) { t.ifError(err); t.equal(res, path.join(__dirname, 'dotdot/index.js')); }); resolve('.', { basedir: dir }, function (err, res, pkg) { t.ifError(err); t.equal(res, path.join(dir, 'index.js')); }); }); test('dotdot sync', function (t) { t.plan(2); 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')); }); node-resolve-1.4.0/test/dotdot/000077500000000000000000000000001313621341000163645ustar00rootroot00000000000000node-resolve-1.4.0/test/dotdot/abc/000077500000000000000000000000001313621341000171115ustar00rootroot00000000000000node-resolve-1.4.0/test/dotdot/abc/index.js000066400000000000000000000000471313621341000205570ustar00rootroot00000000000000var x = require('..'); console.log(x); node-resolve-1.4.0/test/dotdot/index.js000066400000000000000000000000351313621341000200270ustar00rootroot00000000000000module.exports = 'whatever'; node-resolve-1.4.0/test/faulty_basedir.js000066400000000000000000000005401313621341000204210ustar00rootroot00000000000000var test = require('tape'); var resolve = require('../'); 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) { t.equal(true, !!err); }); }); node-resolve-1.4.0/test/filter.js000066400000000000000000000007561313621341000167220ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('filter', function (t) { t.plan(2); var dir = path.join(__dirname, 'resolver'); resolve('./baz', { basedir: dir, packageFilter: function (pkg) { pkg.main = 'doom'; 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'); }); }); node-resolve-1.4.0/test/filter_sync.js000066400000000000000000000006241313621341000177500ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('filter', function (t) { var dir = path.join(__dirname, 'resolver'); var res = resolve.sync('./baz', { basedir: dir, packageFilter: function (pkg) { pkg.main = 'doom'; return pkg; } }); t.equal(res, path.join(dir, 'baz/doom.js')); t.end(); }); node-resolve-1.4.0/test/mock.js000066400000000000000000000106441313621341000163630ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('mock', function (t) { t.plan(8); var files = {}; files[path.resolve('/foo/bar/baz.js')] = 'beep'; function opts(basedir) { return { 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[path.resolve(file)]); } }; } resolve('./baz', opts('/foo/bar'), function (err, res, pkg) { 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) 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 '" + 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 '" + path.resolve('/foo/bar') + "'"); t.equal(err.code, 'MODULE_NOT_FOUND'); }); }); test('mock from package', function (t) { t.plan(8); var files = {}; files[path.resolve('/foo/bar/baz.js')] = 'beep'; function opts(basedir) { return { basedir: path.resolve(basedir), isFile: function (file, cb) { cb(null, Object.prototype.hasOwnProperty.call(files, file)); }, 'package': { main: 'bar' }, readFile: function (file, cb) { cb(null, files[file]); } }; } resolve('./baz', opts('/foo/bar'), function (err, res, pkg) { 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) 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 '" + 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 '" + path.resolve('/foo/bar') + "'"); t.equal(err.code, 'MODULE_NOT_FOUND'); }); }); test('mock package', function (t) { t.plan(2); 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: path.resolve(basedir), isFile: function (file, cb) { cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file))); }, readFile: function (file, cb) { cb(null, files[path.resolve(file)]); } }; } resolve('bar', opts('/foo'), function (err, res, pkg) { 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 = {}; 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: path.resolve(basedir), isFile: function (file, cb) { cb(null, Object.prototype.hasOwnProperty.call(files, path.resolve(file))); }, 'package': { main: 'bar' }, readFile: function (file, cb) { cb(null, files[path.resolve(file)]); } }; } resolve('bar', opts('/foo'), function (err, res, pkg) { if (err) return t.fail(err); t.equal(res, path.resolve('/foo/node_modules/bar/baz.js')); t.equal(pkg && pkg.main, './baz.js'); }); }); node-resolve-1.4.0/test/mock_sync.js000066400000000000000000000031401313621341000174100ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('mock', function (t) { t.plan(4); var files = {}; files[path.resolve('/foo/bar/baz.js')] = 'beep'; function opts(basedir) { return { basedir: path.resolve(basedir), isFile: function (file) { return Object.prototype.hasOwnProperty.call(files, file); }, readFileSync: function (file) { return files[file]; } }; } t.equal( resolve.sync('./baz', opts('/foo/bar')), path.resolve('/foo/bar/baz.js') ); t.equal( resolve.sync('./baz.js', opts('/foo/bar')), path.resolve('/foo/bar/baz.js') ); t.throws(function () { resolve.sync('baz', opts('/foo/bar')); }); t.throws(function () { resolve.sync('../baz', opts('/foo/bar')); }); }); test('mock package', function (t) { t.plan(1); 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: path.resolve(basedir), isFile: function (file) { return Object.prototype.hasOwnProperty.call(files, file); }, readFileSync: function (file) { return files[file]; } }; } t.equal( resolve.sync('bar', opts('/foo')), path.resolve('/foo/node_modules/bar/baz.js') ); }); node-resolve-1.4.0/test/module_dir.js000066400000000000000000000030261313621341000175510ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('moduleDirectory strings', function (t) { t.plan(4); var dir = path.join(__dirname, 'module_dir'); var xopts = { basedir: dir, moduleDirectory: 'xmodules' }; resolve('aaa', xopts, function (err, res, pkg) { t.ifError(err); t.equal(res, path.join(dir, '/xmodules/aaa/index.js')); }); var yopts = { basedir: dir, moduleDirectory: 'ymodules' }; resolve('aaa', yopts, function (err, res, pkg) { t.ifError(err); t.equal(res, path.join(dir, '/ymodules/aaa/index.js')); }); }); test('moduleDirectory array', function (t) { t.plan(6); var dir = path.join(__dirname, 'module_dir'); var aopts = { basedir: dir, moduleDirectory: ['xmodules', 'ymodules', 'zmodules'] }; resolve('aaa', aopts, function (err, res, pkg) { t.ifError(err); t.equal(res, path.join(dir, '/xmodules/aaa/index.js')); }); var bopts = { basedir: dir, moduleDirectory: ['zmodules', 'ymodules', 'xmodules'] }; resolve('aaa', bopts, function (err, res, pkg) { t.ifError(err); t.equal(res, path.join(dir, '/ymodules/aaa/index.js')); }); var copts = { basedir: dir, moduleDirectory: ['xmodules', 'ymodules', 'zmodules'] }; resolve('bbb', copts, function (err, res, pkg) { t.ifError(err); t.equal(res, path.join(dir, '/zmodules/bbb/main.js')); }); }); node-resolve-1.4.0/test/module_dir/000077500000000000000000000000001313621341000172125ustar00rootroot00000000000000node-resolve-1.4.0/test/module_dir/xmodules/000077500000000000000000000000001313621341000210525ustar00rootroot00000000000000node-resolve-1.4.0/test/module_dir/xmodules/aaa/000077500000000000000000000000001313621341000215745ustar00rootroot00000000000000node-resolve-1.4.0/test/module_dir/xmodules/aaa/index.js000066400000000000000000000000631313621341000232400ustar00rootroot00000000000000module.exports = function (x) { return x * 100; }; node-resolve-1.4.0/test/module_dir/ymodules/000077500000000000000000000000001313621341000210535ustar00rootroot00000000000000node-resolve-1.4.0/test/module_dir/ymodules/aaa/000077500000000000000000000000001313621341000215755ustar00rootroot00000000000000node-resolve-1.4.0/test/module_dir/ymodules/aaa/index.js000066400000000000000000000000631313621341000232410ustar00rootroot00000000000000module.exports = function (x) { return x + 100; }; node-resolve-1.4.0/test/module_dir/zmodules/000077500000000000000000000000001313621341000210545ustar00rootroot00000000000000node-resolve-1.4.0/test/module_dir/zmodules/bbb/000077500000000000000000000000001313621341000216015ustar00rootroot00000000000000node-resolve-1.4.0/test/module_dir/zmodules/bbb/main.js000066400000000000000000000000631313621341000230620ustar00rootroot00000000000000module.exports = function (n) { return n * 111; }; node-resolve-1.4.0/test/module_dir/zmodules/bbb/package.json000066400000000000000000000000301313621341000240600ustar00rootroot00000000000000{ "main": "main.js" } node-resolve-1.4.0/test/node-modules-paths.js000066400000000000000000000061271313621341000211430ustar00rootroot00000000000000var 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(); }); }); node-resolve-1.4.0/test/node_path.js000066400000000000000000000025341313621341000173720ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('$NODE_PATH', function (t) { t.plan(4); resolve('aaa', { paths: [ path.join(__dirname, '/node_path/x'), path.join(__dirname, '/node_path/y') ], basedir: __dirname }, function (err, res) { t.equal(res, path.join(__dirname, '/node_path/x/aaa/index.js')); }); resolve('bbb', { paths: [ path.join(__dirname, '/node_path/x'), path.join(__dirname, '/node_path/y') ], basedir: __dirname }, function (err, res) { t.equal(res, path.join(__dirname, '/node_path/y/bbb/index.js')); }); resolve('ccc', { paths: [ path.join(__dirname, '/node_path/x'), path.join(__dirname, '/node_path/y') ], basedir: __dirname }, function (err, res) { 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' ], basedir: 'node_path/x' }, function (err, res) { var root = require('tap/package.json').main; t.equal(res, path.resolve(__dirname, '..', 'node_modules/tap', root)); }); }); node-resolve-1.4.0/test/node_path/000077500000000000000000000000001313621341000170305ustar00rootroot00000000000000node-resolve-1.4.0/test/node_path/x/000077500000000000000000000000001313621341000172775ustar00rootroot00000000000000node-resolve-1.4.0/test/node_path/x/aaa/000077500000000000000000000000001313621341000200215ustar00rootroot00000000000000node-resolve-1.4.0/test/node_path/x/aaa/index.js000066400000000000000000000000261313621341000214640ustar00rootroot00000000000000module.exports = 'A'; node-resolve-1.4.0/test/node_path/x/ccc/000077500000000000000000000000001313621341000200275ustar00rootroot00000000000000node-resolve-1.4.0/test/node_path/x/ccc/index.js000066400000000000000000000000261313621341000214720ustar00rootroot00000000000000module.exports = 'C'; node-resolve-1.4.0/test/node_path/y/000077500000000000000000000000001313621341000173005ustar00rootroot00000000000000node-resolve-1.4.0/test/node_path/y/bbb/000077500000000000000000000000001313621341000200255ustar00rootroot00000000000000node-resolve-1.4.0/test/node_path/y/bbb/index.js000066400000000000000000000000261313621341000214700ustar00rootroot00000000000000module.exports = 'B'; node-resolve-1.4.0/test/node_path/y/ccc/000077500000000000000000000000001313621341000200305ustar00rootroot00000000000000node-resolve-1.4.0/test/node_path/y/ccc/index.js000066400000000000000000000000271313621341000214740ustar00rootroot00000000000000module.exports = 'CY'; node-resolve-1.4.0/test/nonstring.js000066400000000000000000000002661313621341000174520ustar00rootroot00000000000000var test = require('tape'); var resolve = require('../'); test('nonstring', function (t) { t.plan(1); resolve(555, function (err, res, pkg) { t.ok(err); }); }); node-resolve-1.4.0/test/pathfilter.js000066400000000000000000000024041313621341000175670ustar00rootroot00000000000000var 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 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/ref', { basedir: resolverDir }, function (err, res, pkg) { if (err) t.fail(err); 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')); } ); }); node-resolve-1.4.0/test/pathfilter/000077500000000000000000000000001313621341000172315ustar00rootroot00000000000000node-resolve-1.4.0/test/pathfilter/deep_ref/000077500000000000000000000000001313621341000210025ustar00rootroot00000000000000node-resolve-1.4.0/test/pathfilter/deep_ref/main.js000066400000000000000000000000001313621341000222520ustar00rootroot00000000000000node-resolve-1.4.0/test/pathfilter/deep_ref/node_modules/000077500000000000000000000000001313621341000234575ustar00rootroot00000000000000node-resolve-1.4.0/test/pathfilter/deep_ref/node_modules/deep/000077500000000000000000000000001313621341000243745ustar00rootroot00000000000000node-resolve-1.4.0/test/pathfilter/deep_ref/node_modules/deep/alt.js000066400000000000000000000000001313621341000255000ustar00rootroot00000000000000node-resolve-1.4.0/test/pathfilter/deep_ref/node_modules/deep/deeper/000077500000000000000000000000001313621341000256405ustar00rootroot00000000000000node-resolve-1.4.0/test/pathfilter/deep_ref/node_modules/deep/deeper/ref.js000066400000000000000000000000001313621341000267400ustar00rootroot00000000000000node-resolve-1.4.0/test/pathfilter/deep_ref/node_modules/deep/package.json000066400000000000000000000000531313621341000266600ustar00rootroot00000000000000{ "name": "deep", "version": "1.2.3" } node-resolve-1.4.0/test/pathfilter/deep_ref/node_modules/deep/ref.js000066400000000000000000000000001313621341000254740ustar00rootroot00000000000000node-resolve-1.4.0/test/precedence.js000066400000000000000000000012061313621341000175210ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('precedence', function (t) { t.plan(3); var dir = path.join(__dirname, 'precedence/aaa'); 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) { // 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) { t.ok(err); }); }); node-resolve-1.4.0/test/precedence/000077500000000000000000000000001313621341000171645ustar00rootroot00000000000000node-resolve-1.4.0/test/precedence/aaa.js000066400000000000000000000000301313621341000202350ustar00rootroot00000000000000module.exports = 'wtf'; node-resolve-1.4.0/test/precedence/aaa/000077500000000000000000000000001313621341000177065ustar00rootroot00000000000000node-resolve-1.4.0/test/precedence/aaa/index.js000066400000000000000000000000311313621341000213450ustar00rootroot00000000000000module.exports = 'okok'; node-resolve-1.4.0/test/precedence/aaa/main.js000066400000000000000000000000341313621341000211650ustar00rootroot00000000000000console.log(require('./')); node-resolve-1.4.0/test/precedence/bbb.js000066400000000000000000000000301313621341000202400ustar00rootroot00000000000000module.exports = '>_<'; node-resolve-1.4.0/test/precedence/bbb/000077500000000000000000000000001313621341000177115ustar00rootroot00000000000000node-resolve-1.4.0/test/precedence/bbb/main.js000066400000000000000000000000541313621341000211720ustar00rootroot00000000000000console.log(require('./')); // should throw node-resolve-1.4.0/test/resolver.js000066400000000000000000000263171313621341000172770ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('async foo', function (t) { 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, path.join(dir, 'foo.js')); t.equal(pkg && pkg.name, 'resolve'); }); resolve('./foo.js', { basedir: dir }, function (err, res, pkg) { if (err) t.fail(err); 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) { if (err) t.fail(err); 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) { if (err) t.fail(err); t.equal(res, path.join(dir, 'foo.js')); t.equal(pkg.main, 'resolver'); }); 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 = path.join(__dirname, 'resolver'); resolve('foo', { basedir: dir + '/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); }); resolve('foo', { basedir: dir + '/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); }); 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); }); }); test('baz', function (t) { t.plan(4); var dir = path.join(__dirname, 'resolver'); resolve('./baz', { basedir: dir }, function (err, res, pkg) { if (err) t.fail(err); 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) { if (err) t.fail(err); t.equal(res, path.join(dir, 'baz/quux.js')); t.equal(pkg.main, 'quux.js'); }); }); test('biz', function (t) { t.plan(24); 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, path.join(dir, 'grux/index.js')); t.equal(pkg, undefined); }); resolve('./grux', { basedir: dir, 'package': { main: 'biz' } }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'grux/index.js')); t.equal(pkg.main, 'biz'); }); resolve('./garply', { basedir: dir }, function (err, res, pkg) { if (err) t.fail(err); 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) { if (err) t.fail(err); t.equal(res, path.join(dir, 'garply/lib/index.js')); t.equal(pkg.main, './lib'); }); resolve('tiv', { basedir: dir + '/grux' }, function (err, res, pkg) { if (err) t.fail(err); 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) { if (err) t.fail(err); t.equal(res, path.join(dir, 'tiv/index.js')); t.equal(pkg, undefined); }); resolve('tiv', { basedir: dir + '/garply' }, function (err, res, pkg) { if (err) t.fail(err); 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) { if (err) t.fail(err); t.equal(res, path.join(dir, 'tiv/index.js')); t.equal(pkg, undefined); }); resolve('grux', { basedir: dir + '/tiv' }, function (err, res, pkg) { if (err) t.fail(err); 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) { if (err) t.fail(err); t.equal(res, path.join(dir, 'grux/index.js')); t.equal(pkg, undefined); }); resolve('garply', { basedir: dir + '/tiv' }, function (err, res, pkg) { if (err) t.fail(err); 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) { if (err) t.fail(err); t.equal(res, path.join(dir, 'garply/lib/index.js')); t.equal(pkg.main, './lib'); }); }); test('quux', function (t) { t.plan(2); 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, path.join(dir, 'foo/index.js')); t.equal(pkg.main, 'quux'); }); }); test('normalize', function (t) { t.plan(2); 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, path.join(dir, 'index.js')); t.equal(pkg, undefined); }); }); test('cup', function (t) { 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, path.join(dir, 'cup.coffee')); }); resolve('./cup.coffee', { basedir: dir }, function (err, res) { if (err) t.fail(err); t.equal(res, path.join(dir, 'cup.coffee')); }); 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 = path.join(__dirname, 'resolver'); resolve('./mug', { basedir: dir }, function (err, res) { if (err) t.fail(err); t.equal(res, path.join(dir, 'mug.js')); }); resolve('./mug', { basedir: dir, extensions: ['.coffee', '.js'] }, function (err, res) { if (err) t.fail(err); t.equal(res, path.join(dir, '/mug.coffee')); }); 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(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, path.join(resolverDir, 'other_path/root.js')); }); resolve('lib/other-lib', { basedir: dir, paths: [otherDir] }, function (err, res) { if (err) t.fail(err); t.equal(res, path.join(resolverDir, 'other_path/lib/other-lib.js')); }); 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) { 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); var resolverDir = path.join(__dirname, 'resolver'); var dir = path.join(resolverDir, 'incorrect_main'); resolve('./incorrect_main', { basedir: resolverDir }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(dir, 'index.js')); }); }); test('without basedir', function (t) { t.plan(1); var dir = path.join(__dirname, 'resolver/without_basedir'); var tester = require(path.join(dir, 'main.js')); tester(t, function (err, res, pkg) { if (err) { 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 = path.join(__dirname, 'resolver/punycode'); resolve('punycode', { basedir: resolverDir }, function (err, res, pkg) { if (err) t.fail(err); 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(); }); test('async dot main', function (t) { var start = new Date(); t.plan(3); resolve('./resolver/dot_main', function (err, ret) { t.notOk(err); t.equal(ret, path.join(__dirname, 'resolver/dot_main/index.js')); t.ok(new Date() - start < 50, 'resolve.sync timedout'); t.end(); }); }); test('async dot slash main', function (t) { var start = new Date(); t.plan(3); resolve('./resolver/dot_slash_main', function (err, ret) { t.notOk(err); t.equal(ret, path.join(__dirname, 'resolver/dot_slash_main/index.js')); t.ok(new Date() - start < 50, 'resolve.sync timedout'); t.end(); }); }); node-resolve-1.4.0/test/resolver/000077500000000000000000000000001313621341000167305ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/bar/000077500000000000000000000000001313621341000174745ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/bar/node_modules/000077500000000000000000000000001313621341000221515ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/bar/node_modules/foo/000077500000000000000000000000001313621341000227345ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/bar/node_modules/foo/index.js000066400000000000000000000000241313621341000243750ustar00rootroot00000000000000module.exports = 1; node-resolve-1.4.0/test/resolver/baz/000077500000000000000000000000001313621341000175045ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/baz/doom.js000066400000000000000000000000001313621341000207660ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/baz/package.json000066400000000000000000000000321313621341000217650ustar00rootroot00000000000000{ "main": "quux.js" } node-resolve-1.4.0/test/resolver/baz/quux.js000066400000000000000000000000241313621341000210400ustar00rootroot00000000000000module.exports = 1; node-resolve-1.4.0/test/resolver/biz/000077500000000000000000000000001313621341000175145ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/biz/node_modules/000077500000000000000000000000001313621341000221715ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/biz/node_modules/garply/000077500000000000000000000000001313621341000234675ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/biz/node_modules/garply/lib/000077500000000000000000000000001313621341000242355ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/biz/node_modules/garply/lib/index.js000066400000000000000000000000411313621341000256750ustar00rootroot00000000000000module.exports = 'hello garply'; node-resolve-1.4.0/test/resolver/biz/node_modules/garply/package.json000066400000000000000000000000311313621341000257470ustar00rootroot00000000000000{ "main" : "./lib" } node-resolve-1.4.0/test/resolver/biz/node_modules/grux/000077500000000000000000000000001313621341000231565ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/biz/node_modules/grux/index.js000066400000000000000000000000471313621341000246240ustar00rootroot00000000000000module.exports = require('tiv') * 100; node-resolve-1.4.0/test/resolver/biz/node_modules/tiv/000077500000000000000000000000001313621341000227735ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/biz/node_modules/tiv/index.js000066400000000000000000000000241313621341000244340ustar00rootroot00000000000000module.exports = 3; node-resolve-1.4.0/test/resolver/cup.coffee000066400000000000000000000000011313621341000206570ustar00rootroot00000000000000 node-resolve-1.4.0/test/resolver/dot_main/000077500000000000000000000000001313621341000205225ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/dot_main/index.js000066400000000000000000000000241313621341000221630ustar00rootroot00000000000000module.exports = 1; node-resolve-1.4.0/test/resolver/dot_main/package.json000066400000000000000000000000241313621341000230040ustar00rootroot00000000000000{ "main": "." } node-resolve-1.4.0/test/resolver/dot_slash_main/000077500000000000000000000000001313621341000217145ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/dot_slash_main/index.js000066400000000000000000000000241313621341000233550ustar00rootroot00000000000000module.exports = 1; node-resolve-1.4.0/test/resolver/dot_slash_main/package.json000066400000000000000000000000251313621341000241770ustar00rootroot00000000000000{ "main": "./" } node-resolve-1.4.0/test/resolver/foo.js000066400000000000000000000000241313621341000200450ustar00rootroot00000000000000module.exports = 1; node-resolve-1.4.0/test/resolver/incorrect_main/000077500000000000000000000000001313621341000217245ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/incorrect_main/index.js000066400000000000000000000001641313621341000233720ustar00rootroot00000000000000// this is the actual main file 'index.js', not 'wrong.js' like the package.json would indicate module.exports = 1; node-resolve-1.4.0/test/resolver/incorrect_main/package.json000066400000000000000000000000331313621341000242060ustar00rootroot00000000000000{ "main": "wrong.js" } node-resolve-1.4.0/test/resolver/mug.coffee000066400000000000000000000000001313621341000206570ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/mug.js000066400000000000000000000000001313621341000200440ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/other_path/000077500000000000000000000000001313621341000210655ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/other_path/lib/000077500000000000000000000000001313621341000216335ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/other_path/lib/other-lib.js000066400000000000000000000000001313621341000240440ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/other_path/root.js000066400000000000000000000000001313621341000223740ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/punycode/000077500000000000000000000000001313621341000205565ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/punycode/node_modules/000077500000000000000000000000001313621341000232335ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/punycode/node_modules/punycode/000077500000000000000000000000001313621341000250615ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/punycode/node_modules/punycode/index.js000066400000000000000000000000001313621341000265140ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/quux/000077500000000000000000000000001313621341000177325ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/quux/foo/000077500000000000000000000000001313621341000205155ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/quux/foo/index.js000066400000000000000000000000241313621341000221560ustar00rootroot00000000000000module.exports = 1; node-resolve-1.4.0/test/resolver/same_names/000077500000000000000000000000001313621341000210405ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/same_names/foo.js000066400000000000000000000000251313621341000221560ustar00rootroot00000000000000module.exports = 42; node-resolve-1.4.0/test/resolver/same_names/foo/000077500000000000000000000000001313621341000216235ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/same_names/foo/index.js000066400000000000000000000000241313621341000232640ustar00rootroot00000000000000module.exports = 1; node-resolve-1.4.0/test/resolver/symlinked/000077500000000000000000000000001313621341000207275ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/symlinked/.gitignore000066400000000000000000000000111313621341000227070ustar00rootroot00000000000000symlink node-resolve-1.4.0/test/resolver/symlinked/_/000077500000000000000000000000001313621341000211455ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/symlinked/_/.gitignore000066400000000000000000000000161313621341000231320ustar00rootroot00000000000000!node_modules node-resolve-1.4.0/test/resolver/symlinked/_/node_modules/000077500000000000000000000000001313621341000236225ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/symlinked/_/node_modules/foo.js000066400000000000000000000000001313621341000247310ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/symlinked/_/symlink_target/000077500000000000000000000000001313621341000242015ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/symlinked/_/symlink_target/.gitkeep000066400000000000000000000000001313621341000256200ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/without_basedir/000077500000000000000000000000001313621341000221245ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/without_basedir/main.js000066400000000000000000000001571313621341000234110ustar00rootroot00000000000000var resolve = require('../../../'); module.exports = function (t, cb) { resolve('mymodule', null, cb); }; node-resolve-1.4.0/test/resolver/without_basedir/node_modules/000077500000000000000000000000001313621341000246015ustar00rootroot00000000000000node-resolve-1.4.0/test/resolver/without_basedir/node_modules/mymodule.js000066400000000000000000000002351313621341000267720ustar00rootroot00000000000000module.exports = "The tools we use have a profound (and devious!) influence on our thinking habits, and, therefore, on our thinking abilities.- E. Dijkstra" node-resolve-1.4.0/test/resolver_sync.js000066400000000000000000000145671313621341000203370ustar00rootroot00000000000000var path = require('path'); var test = require('tape'); var resolve = require('../'); test('foo', function (t) { var dir = path.join(__dirname, 'resolver'); t.equal( resolve.sync('./foo', { basedir: dir }), path.join(dir, 'foo.js') ); t.equal( resolve.sync('./foo.js', { basedir: dir }), path.join(dir, 'foo.js') ); t.throws(function () { resolve.sync('foo', { basedir: dir }); }); t.end(); }); test('bar', function (t) { var dir = path.join(__dirname, 'resolver'); t.equal( 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 = path.join(__dirname, 'resolver'); t.equal( resolve.sync('./baz', { basedir: dir }), path.join(dir, 'baz/quux.js') ); t.end(); }); test('biz', function (t) { var dir = path.join(__dirname, 'resolver/biz/node_modules'); t.equal( resolve.sync('./grux', { basedir: dir }), path.join(dir, 'grux/index.js') ); t.equal( resolve.sync('tiv', { basedir: path.join(dir, 'grux') }), path.join(dir, 'tiv/index.js') ); t.equal( resolve.sync('grux', { basedir: path.join(dir, 'tiv') }), path.join(dir, 'grux/index.js') ); t.end(); }); test('normalize', function (t) { var dir = path.join(__dirname, 'resolver/biz/node_modules/grux'); t.equal( resolve.sync('../grux', { basedir: dir }), path.join(dir, 'index.js') ); t.end(); }); test('cup', function (t) { var dir = path.join(__dirname, 'resolver'); t.equal( resolve.sync('./cup', { basedir: dir, extensions: ['.js', '.coffee'] }), path.join(dir, 'cup.coffee') ); t.equal( resolve.sync('./cup.coffee', { basedir: dir }), path.join(dir, 'cup.coffee') ); t.throws(function () { resolve.sync('./cup', { basedir: dir, extensions: ['.js'] }); }); t.end(); }); test('mug', function (t) { var dir = path.join(__dirname, 'resolver'); t.equal( resolve.sync('./mug', { basedir: dir }), path.join(dir, 'mug.js') ); t.equal( resolve.sync('./mug', { basedir: dir, extensions: ['.coffee', '.js'] }), path.join(dir, 'mug.coffee') ); t.equal( resolve.sync('./mug', { basedir: dir, extensions: ['.js', '.coffee'] }), path.join(dir, 'mug.js') ); t.end(); }); test('other path', function (t) { var resolverDir = path.join(__dirname, 'resolver'); var dir = path.join(resolverDir, 'bar'); var otherDir = path.join(resolverDir, 'other_path'); t.equal( resolve.sync('root', { basedir: dir, paths: [otherDir] }), path.join(resolverDir, 'other_path/root.js') ); t.equal( resolve.sync('lib/other-lib', { basedir: dir, paths: [otherDir] }), path.join(resolverDir, 'other_path/lib/other-lib.js') ); t.throws(function () { resolve.sync('root', { basedir: dir }); }); t.throws(function () { resolve.sync('zzz', { basedir: dir, paths: [otherDir] }); }); t.end(); }); test('incorrect main', function (t) { var resolverDir = path.join(__dirname, 'resolver'); var dir = path.join(resolverDir, 'incorrect_main'); t.equal( resolve.sync('./incorrect_main', { basedir: resolverDir }), path.join(dir, 'index.js') ); t.end(); }); test('#25: node modules with the same name as node stdlib modules', function (t) { 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('./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.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(); }); test('sync dot main', function (t) { var start = new Date(); t.equal(resolve.sync('./resolver/dot_main'), path.join(__dirname, 'resolver/dot_main/index.js')); t.ok(new Date() - start < 50, 'resolve.sync timedout'); t.end(); }); test('sync dot slash main', function (t) { var start = new Date(); t.equal(resolve.sync('./resolver/dot_slash_main'), path.join(__dirname, 'resolver/dot_slash_main/index.js')); t.ok(new Date() - start < 50, 'resolve.sync timedout'); t.end(); }); node-resolve-1.4.0/test/subdirs.js000066400000000000000000000005411313621341000171000ustar00rootroot00000000000000var test = require('tape'); var resolve = require('../'); 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); t.equal(res, path.join(dir, 'node_modules/a/b/c/x.json')); }); }); node-resolve-1.4.0/test/subdirs/000077500000000000000000000000001313621341000165425ustar00rootroot00000000000000node-resolve-1.4.0/test/subdirs/node_modules/000077500000000000000000000000001313621341000212175ustar00rootroot00000000000000node-resolve-1.4.0/test/subdirs/node_modules/a/000077500000000000000000000000001313621341000214375ustar00rootroot00000000000000node-resolve-1.4.0/test/subdirs/node_modules/a/b/000077500000000000000000000000001313621341000216605ustar00rootroot00000000000000node-resolve-1.4.0/test/subdirs/node_modules/a/b/c/000077500000000000000000000000001313621341000221025ustar00rootroot00000000000000node-resolve-1.4.0/test/subdirs/node_modules/a/b/c/x.json000066400000000000000000000000101313621341000232330ustar00rootroot00000000000000[1,2,3] node-resolve-1.4.0/test/subdirs/node_modules/a/package.json000066400000000000000000000000031313621341000237160ustar00rootroot00000000000000{} node-resolve-1.4.0/test/symlinks.js000066400000000000000000000034421313621341000173010ustar00rootroot00000000000000var path = require('path'); var fs = require('fs'); var test = require('tape'); var resolve = require('../'); var symlinkDir = path.join(__dirname, 'resolver', 'symlinked', 'symlink'); try { fs.unlinkSync(symlinkDir); } catch (err) {} try { fs.symlinkSync('./_/symlink_target', symlinkDir, 'dir'); } catch (err) { // if fails then it is probably on Windows and lets try to create a junction fs.symlinkSync(path.join(__dirname, 'resolver', 'symlinked', '_', 'symlink_target') + '\\', symlinkDir, 'junction'); } test('symlink', function (t) { t.plan(1); resolve('foo', { basedir: symlinkDir, preserveSymlinks: false }, function (err, res, pkg) { if (err) t.fail(err); t.equal(res, path.join(__dirname, 'resolver', 'symlinked', '_', 'node_modules', 'foo.js')); }); }); test('sync symlink when preserveSymlinks = true', function (t) { t.plan(4); resolve('foo', { basedir: symlinkDir }, function (err, res, pkg) { t.ok(err, 'there is an error'); t.notOk(res, 'no result'); t.equal(err && err.code, 'MODULE_NOT_FOUND', 'error code matches require.resolve'); t.equal( err && err.message, 'Cannot find module \'foo\' from \'' + symlinkDir + '\'', 'can not find nonexistent module' ); }); }); 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.ok(new Date() - start < 50, 'resolve.sync timedout'); t.end(); }); test('sync symlink when preserveSymlinks = true', function (t) { t.throws(function () { resolve.sync('foo', { basedir: symlinkDir }); }, /Cannot find module 'foo'/); t.end(); });