This commit is contained in:
eric sciple 2020-01-24 12:20:19 -05:00
parent beb1329f9f
commit 2b95e76931
7736 changed files with 1874747 additions and 51184 deletions

21
node_modules/browser-resolve/LICENSE generated vendored Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2013-2015 Roman Shtylman <shtylman@gmail.com>
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.

146
node_modules/browser-resolve/README.md generated vendored Normal file
View file

@ -0,0 +1,146 @@
# browser-resolve [![Build Status](https://travis-ci.org/defunctzombie/node-browser-resolve.png?branch=master)](https://travis-ci.org/defunctzombie/node-browser-resolve)
node.js resolve algorithm with [browser field](https://github.com/defunctzombie/package-browser-field-spec) support.
## api
### resolve(id, opts={}, cb)
Resolve a module path and call `cb(err, path [, pkg])`
Options:
* `basedir` - directory to begin resolving from
* `browser` - the 'browser' property to use from package.json (defaults to 'browser')
* `filename` - the calling filename where the `require()` call originated (in the source)
* `modules` - object with module id/name -> path mappings to consult before doing manual resolution (use to provide core modules)
* `packageFilter` - transform the parsed `package.json` contents before looking at the `main` field
* `paths` - `require.paths` array to use if nothing is found on the normal `node_modules` recursive walk
Options supported by [node-resolve](https://github.com/substack/node-resolve#resolveid-opts-cb) can be used.
### resolve.sync(id, opts={})
Same as the async resolve, just uses sync methods.
Options supported by [node-resolve](https://github.com/substack/node-resolve#resolvesyncid-opts) `sync` can be used.
## basic usage
you can resolve files like `require.resolve()`:
``` js
var resolve = require('browser-resolve');
resolve('../', { filename: __filename }, function(err, path) {
console.log(path);
});
```
```
$ node example/resolve.js
/home/substack/projects/node-browser-resolve/index.js
```
## core modules
By default, core modules (http, dgram, etc) will return their same name as the path. If you want to have specific paths returned, specify a `modules` property in the options object.
``` js
var shims = {
http: '/your/path/to/http.js'
};
var resolve = require('browser-resolve');
resolve('fs', { modules: shims }, function(err, path) {
console.log(path);
});
```
```
$ node example/builtin.js
/home/substack/projects/node-browser-resolve/builtin/fs.js
```
## browser field
browser-specific versions of modules
``` js
{
"name": "custom",
"version": "0.0.0",
"browser": {
"./main.js": "custom.js"
},
"chromeapp": {
"./main.js": "custom-chromeapp.js"
}
}
```
``` js
var resolve = require('browser-resolve');
var parent = { filename: __dirname + '/custom/file.js' /*, browser: 'chromeapp' */ };
resolve('./main.js', parent, function(err, path) {
console.log(path);
});
```
```
$ node example/custom.js
/home/substack/projects/node-browser-resolve/example/custom/custom.js
```
## skip
You can skip over dependencies by setting a
[browser field](https://gist.github.com/defunctzombie/4339901)
value to `false`:
``` json
{
"name": "skip",
"version": "0.0.0",
"browser": {
"tar": false
}
}
```
This is handy if you have code like:
``` js
var tar = require('tar');
exports.add = function (a, b) {
return a + b;
};
exports.parse = function () {
return tar.Parse();
};
```
so that `require('tar')` will just return `{}` in the browser because you don't
intend to support the `.parse()` export in a browser environment.
``` js
var resolve = require('browser-resolve');
var parent = { filename: __dirname + '/skip/main.js' };
resolve('tar', parent, function(err, path) {
console.log(path);
});
```
```
$ node example/skip.js
/home/substack/projects/node-browser-resolve/empty.js
```
# license
MIT
# upgrade notes
Prior to v1.x this library provided shims for node core modules. These have since been removed. If you want to have alternative core modules provided, use the `modules` option when calling resolve.
This was done to allow package managers to choose which shims they want to use without browser-resolve being the central point of update.

0
node_modules/browser-resolve/empty.js generated vendored Normal file
View file

345
node_modules/browser-resolve/index.js generated vendored Normal file
View file

@ -0,0 +1,345 @@
// builtin
var fs = require('fs');
var path = require('path');
// vendor
var resv = require('resolve');
// given a path, create an array of node_module paths for it
// borrowed from substack/resolve
function nodeModulesPaths (start, cb) {
var splitRe = process.platform === 'win32' ? /[\/\\]/ : /\/+/;
var parts = start.split(splitRe);
var dirs = [];
for (var i = parts.length - 1; i >= 0; i--) {
if (parts[i] === 'node_modules') continue;
var dir = path.join.apply(
path, parts.slice(0, i + 1).concat(['node_modules'])
);
if (!parts[0].match(/([A-Za-z]:)/)) {
dir = '/' + dir;
}
dirs.push(dir);
}
return dirs;
}
function find_shims_in_package(pkgJson, cur_path, shims, browser) {
try {
var info = JSON.parse(pkgJson);
}
catch (err) {
err.message = pkgJson + ' : ' + err.message
throw err;
}
var replacements = getReplacements(info, browser);
// no replacements, skip shims
if (!replacements) {
return;
}
// if browser mapping is a string
// then it just replaces the main entry point
if (typeof replacements === 'string') {
var key = path.resolve(cur_path, info.main || 'index.js');
shims[key] = path.resolve(cur_path, replacements);
return;
}
// http://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders
Object.keys(replacements).forEach(function(key) {
var val;
if (replacements[key] === false) {
val = path.normalize(__dirname + '/empty.js');
}
else {
val = replacements[key];
// if target is a relative path, then resolve
// otherwise we assume target is a module
if (val[0] === '.') {
val = path.resolve(cur_path, val);
}
}
if (key[0] === '/' || key[0] === '.') {
// if begins with / ../ or ./ then we must resolve to a full path
key = path.resolve(cur_path, key);
}
shims[key] = val;
});
[ '.js', '.json' ].forEach(function (ext) {
Object.keys(shims).forEach(function (key) {
if (!shims[key + ext]) {
shims[key + ext] = shims[key];
}
});
});
}
// paths is mutated
// load shims from first package.json file found
function load_shims(paths, browser, cb) {
// identify if our file should be replaced per the browser field
// original filename|id -> replacement
var shims = Object.create(null);
(function next() {
var cur_path = paths.shift();
if (!cur_path) {
return cb(null, shims);
}
var pkg_path = path.join(cur_path, 'package.json');
fs.readFile(pkg_path, 'utf8', function(err, data) {
if (err) {
// ignore paths we can't open
// avoids an exists check
if (err.code === 'ENOENT') {
return next();
}
return cb(err);
}
try {
find_shims_in_package(data, cur_path, shims, browser);
return cb(null, shims);
}
catch (err) {
return cb(err);
}
});
})();
};
// paths is mutated
// synchronously load shims from first package.json file found
function load_shims_sync(paths, browser) {
// identify if our file should be replaced per the browser field
// original filename|id -> replacement
var shims = Object.create(null);
var cur_path;
while (cur_path = paths.shift()) {
var pkg_path = path.join(cur_path, 'package.json');
try {
var data = fs.readFileSync(pkg_path, 'utf8');
find_shims_in_package(data, cur_path, shims, browser);
return shims;
}
catch (err) {
// ignore paths we can't open
// avoids an exists check
if (err.code === 'ENOENT') {
continue;
}
throw err;
}
}
return shims;
}
function build_resolve_opts(opts, base) {
var packageFilter = opts.packageFilter;
var browser = normalizeBrowserFieldName(opts.browser)
opts.basedir = base;
opts.packageFilter = function (info, pkgdir) {
if (packageFilter) info = packageFilter(info, pkgdir);
var replacements = getReplacements(info, browser);
// no browser field, keep info unchanged
if (!replacements) {
return info;
}
info[browser] = replacements;
// replace main
if (typeof replacements === 'string') {
info.main = replacements;
return info;
}
var replace_main = replacements[info.main || './index.js'] ||
replacements['./' + info.main || './index.js'];
info.main = replace_main || info.main;
return info;
};
var pathFilter = opts.pathFilter;
opts.pathFilter = function(info, resvPath, relativePath) {
if (relativePath[0] != '.') {
relativePath = './' + relativePath;
}
var mappedPath;
if (pathFilter) {
mappedPath = pathFilter.apply(this, arguments);
}
if (mappedPath) {
return mappedPath;
}
var replacements = info[browser];
if (!replacements) {
return;
}
mappedPath = replacements[relativePath];
if (!mappedPath && path.extname(relativePath) === '') {
mappedPath = replacements[relativePath + '.js'];
if (!mappedPath) {
mappedPath = replacements[relativePath + '.json'];
}
}
return mappedPath;
};
return opts;
}
function resolve(id, opts, cb) {
// opts.filename
// opts.paths
// opts.modules
// opts.packageFilter
opts = opts || {};
opts.filename = opts.filename || '';
var base = path.dirname(opts.filename);
if (opts.basedir) {
base = opts.basedir;
}
var paths = nodeModulesPaths(base);
if (opts.paths) {
paths.push.apply(paths, opts.paths);
}
paths = paths.map(function(p) {
return path.dirname(p);
});
// we must always load shims because the browser field could shim out a module
load_shims(paths, opts.browser, function(err, shims) {
if (err) {
return cb(err);
}
var resid = path.resolve(opts.basedir || path.dirname(opts.filename), id);
if (shims[id] || shims[resid]) {
var xid = shims[id] ? id : resid;
// if the shim was is an absolute path, it was fully resolved
if (shims[xid][0] === '/') {
return resv(shims[xid], build_resolve_opts(opts, base), function(err, full, pkg) {
cb(null, full, pkg);
});
}
// module -> alt-module shims
id = shims[xid];
}
var modules = opts.modules || Object.create(null);
var shim_path = modules[id];
if (shim_path) {
return cb(null, shim_path);
}
// our browser field resolver
// if browser field is an object tho?
var full = resv(id, build_resolve_opts(opts, base), function(err, full, pkg) {
if (err) {
return cb(err);
}
var resolved = (shims) ? shims[full] || full : full;
cb(null, resolved, pkg);
});
});
};
resolve.sync = function (id, opts) {
// opts.filename
// opts.paths
// opts.modules
// opts.packageFilter
opts = opts || {};
opts.filename = opts.filename || '';
var base = path.dirname(opts.filename);
if (opts.basedir) {
base = opts.basedir;
}
var paths = nodeModulesPaths(base);
if (opts.paths) {
paths.push.apply(paths, opts.paths);
}
paths = paths.map(function(p) {
return path.dirname(p);
});
// we must always load shims because the browser field could shim out a module
var shims = load_shims_sync(paths, opts.browser);
var resid = path.resolve(opts.basedir || path.dirname(opts.filename), id);
if (shims[id] || shims[resid]) {
var xid = shims[id] ? id : resid;
// if the shim was is an absolute path, it was fully resolved
if (shims[xid][0] === '/') {
return resv.sync(shims[xid], build_resolve_opts(opts, base));
}
// module -> alt-module shims
id = shims[xid];
}
var modules = opts.modules || Object.create(null);
var shim_path = modules[id];
if (shim_path) {
return shim_path;
}
// our browser field resolver
// if browser field is an object tho?
var full = resv.sync(id, build_resolve_opts(opts, base));
return (shims) ? shims[full] || full : full;
};
function normalizeBrowserFieldName(browser) {
return browser || 'browser';
}
function getReplacements(info, browser) {
browser = normalizeBrowserFieldName(browser);
var replacements = info[browser] || info.browser;
// support legacy browserify field for easier migration from legacy
// many packages used this field historically
if (typeof info.browserify === 'string' && !replacements) {
replacements = info.browserify;
}
return replacements;
}
module.exports = resolve;

View file

@ -0,0 +1,4 @@
language: node_js
node_js:
- 0.6
- 0.8

View file

@ -0,0 +1,18 @@
This 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.

View file

@ -0,0 +1,5 @@
var resolve = require('../');
resolve('tap', { basedir: __dirname }, function (err, res) {
if (err) console.error(err)
else console.log(res)
});

View file

@ -0,0 +1,3 @@
var resolve = require('../');
var res = resolve.sync('tap', { basedir: __dirname });
console.log(res);

View file

@ -0,0 +1,5 @@
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');

View file

@ -0,0 +1,192 @@
var core = require('./core');
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) {
if (typeof opts === 'function') {
cb = opts;
opts = {};
}
if (!opts) opts = {};
if (typeof x !== 'string') {
return process.nextTick(function () {
cb(new Error('path must be a string'));
});
}
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())
});
};
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 === '..') 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 cb(new Error("Cannot find module '" + x + "' from '" + y + "'"))
});
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 + "'"))
})
}
function loadAsFile (x, pkg, cb) {
if (typeof pkg === 'function') {
cb = pkg;
pkg = undefined;
}
var exts = [''].concat(extensions);
load(exts, x, pkg)
function load (exts, x, pkg) {
if (exts.length === 0) return cb(null, undefined, pkg);
var file = x + exts[0];
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) cb(err)
else if (!ex) load(exts.slice(1), x, pkg)
else cb(null, file, 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 (err) {}
if (pkg && opts.packageFilter) {
pkg = opts.packageFilter(pkg, pkgfile);
}
cb(null, pkg, dir);
});
});
}
function loadAsDirectory (x, fpkg, cb) {
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 (err) {}
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 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));
}
};

View file

@ -0,0 +1,8 @@
module.exports = function () {
// see https://code.google.com/p/v8/wiki/JavaScriptStackTraceApi
var origPrepareStackTrace = Error.prepareStackTrace;
Error.prepareStackTrace = function (_, stack) { return stack };
var stack = (new Error()).stack;
Error.prepareStackTrace = origPrepareStackTrace;
return stack[2].getFileName();
};

View file

@ -0,0 +1,4 @@
module.exports = require('./core.json').reduce(function (acc, x) {
acc[x] = true;
return acc;
}, {});

View file

@ -0,0 +1,38 @@
[
"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"
]

View file

@ -0,0 +1,38 @@
var path = require('path');
module.exports = function (start, opts) {
var modules = 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 prefix = '/';
if (/^([A-Za-z]:)/.test(start)) {
prefix = '';
} else if (/^\\\\/.test(start)) {
prefix = '\\\\';
}
var splitRe = process.platform === 'win32' ? /[\/\\]/ : /\/+/;
var parts = start.split(splitRe);
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
);
}));
}
if (process.platform === 'win32'){
dirs[dirs.length-1] = dirs[dirs.length-1].replace(":", ":\\");
}
return dirs.concat(opts.paths);
}

View file

@ -0,0 +1,81 @@
var 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, opts) {
if (!opts) opts = {};
var isFile = opts.isFile || function (file) {
try { var stat = fs.statSync(file) }
catch (err) { if (err && err.code === 'ENOENT') return false }
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 === '..') 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) {
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)) {
var body = readFileSync(pkgfile, 'utf8');
try {
var pkg = JSON.parse(body);
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) {}
}
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;
}
}
};

View file

@ -0,0 +1,62 @@
{
"_args": [
[
"resolve@1.1.7",
"/Users/eric/repos/actions/setup-node"
]
],
"_development": true,
"_from": "resolve@1.1.7",
"_id": "resolve@1.1.7",
"_inBundle": false,
"_integrity": "sha1-IDEU2CrSxe2ejgQRs5ModeiJ6Xs=",
"_location": "/browser-resolve/resolve",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "resolve@1.1.7",
"name": "resolve",
"escapedName": "resolve",
"rawSpec": "1.1.7",
"saveSpec": null,
"fetchSpec": "1.1.7"
},
"_requiredBy": [
"/browser-resolve"
],
"_resolved": "https://registry.npmjs.org/resolve/-/resolve-1.1.7.tgz",
"_spec": "1.1.7",
"_where": "/Users/eric/repos/actions/setup-node",
"author": {
"name": "James Halliday",
"email": "mail@substack.net",
"url": "http://substack.net"
},
"bugs": {
"url": "https://github.com/substack/node-resolve/issues"
},
"description": "resolve like require.resolve() on behalf of files asynchronously and synchronously",
"devDependencies": {
"tap": "0.4.13",
"tape": "^3.5.0"
},
"homepage": "https://github.com/substack/node-resolve#readme",
"keywords": [
"resolve",
"require",
"node",
"module"
],
"license": "MIT",
"main": "index.js",
"name": "resolve",
"repository": {
"type": "git",
"url": "git://github.com/substack/node-resolve.git"
},
"scripts": {
"test": "tape test/*.js"
},
"version": "1.1.7"
}

View file

@ -0,0 +1,148 @@
# resolve
implements the [node `require.resolve()`
algorithm](http://nodejs.org/docs/v0.4.8/api/all.html#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"`
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'
}
```
## 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"`
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'
}
````
## resolve.isCore(pkg)
Return whether a package is in core.
# install
With [npm](https://npmjs.org) do:
```
npm install resolve
```
# license
MIT

View file

@ -0,0 +1,12 @@
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.end();
});

View file

@ -0,0 +1,29 @@
var path = require('path');
var test = require('tape');
var resolve = require('../');
test('dotdot', function (t) {
t.plan(4);
var dir = __dirname + '/dotdot/abc';
resolve('..', { basedir : dir }, function (err, res, pkg) {
t.ifError(err);
t.equal(res, __dirname + '/dotdot/index.js');
});
resolve('.', { basedir : dir }, function (err, res, pkg) {
t.ifError(err);
t.equal(res, 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');
});

View file

@ -0,0 +1,2 @@
var x = require('..');
console.log(x);

View file

@ -0,0 +1 @@
module.exports = 'whatever'

View file

@ -0,0 +1,17 @@
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) {
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);
});
});

View file

@ -0,0 +1,18 @@
var test = require('tape');
var resolve = require('../');
test('filter', function (t) {
t.plan(2);
var dir = __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, dir + '/baz/doom.js');
t.equal(pkg.main, 'doom');
});
});

View file

@ -0,0 +1,15 @@
var test = require('tape');
var resolve = require('../');
test('filter', function (t) {
var dir = __dirname + '/resolver';
var res = resolve.sync('./baz', {
basedir : dir,
packageFilter : function (pkg) {
pkg.main = 'doom'
return pkg;
}
});
t.equal(res, dir + '/baz/doom.js');
t.end();
});

View file

@ -0,0 +1,142 @@
var test = require('tape');
var resolve = require('../');
test('mock', function (t) {
t.plan(6);
var files = {
'/foo/bar/baz.js' : 'beep'
};
function opts (basedir) {
return {
basedir : basedir,
isFile : function (file, cb) {
cb(null, files.hasOwnProperty(file));
},
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, undefined);
});
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, undefined);
});
resolve('baz', opts('/foo/bar'), function (err, res) {
t.equal(err.message, "Cannot find module 'baz' from '/foo/bar'");
});
resolve('../baz', opts('/foo/bar'), function (err, res) {
t.equal(err.message, "Cannot find module '../baz' from '/foo/bar'");
});
});
test('mock from package', function (t) {
t.plan(6);
var files = {
'/foo/bar/baz.js' : 'beep'
};
function opts (basedir) {
return {
basedir : basedir,
package : { main: 'bar' },
isFile : function (file, cb) {
cb(null, files.hasOwnProperty(file));
},
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');
});
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');
});
resolve('baz', opts('/foo/bar'), function (err, res) {
t.equal(err.message, "Cannot find module 'baz' from '/foo/bar'");
});
resolve('../baz', opts('/foo/bar'), function (err, res) {
t.equal(err.message, "Cannot find module '../baz' from '/foo/bar'");
});
});
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) {
return {
basedir : basedir,
isFile : function (file, cb) {
cb(null, files.hasOwnProperty(file));
},
readFile : function (file, cb) {
cb(null, files[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');
});
});
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) {
return {
basedir : basedir,
package : { main: 'bar' },
isFile : function (file, cb) {
cb(null, files.hasOwnProperty(file));
},
readFile : function (file, cb) {
cb(null, files[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');
});
});

View file

@ -0,0 +1,68 @@
var test = require('tape');
var resolve = require('../');
test('mock', function (t) {
t.plan(4);
var files = {
'/foo/bar/baz.js' : 'beep'
};
function opts (basedir) {
return {
basedir : basedir,
isFile : function (file) {
return files.hasOwnProperty(file)
},
readFileSync : function (file) {
return files[file]
}
}
}
t.equal(
resolve.sync('./baz', opts('/foo/bar')),
'/foo/bar/baz.js'
);
t.equal(
resolve.sync('./baz.js', opts('/foo/bar')),
'/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 = {
'/foo/node_modules/bar/baz.js' : 'beep',
'/foo/node_modules/bar/package.json' : JSON.stringify({
main : './baz.js'
})
};
function opts (basedir) {
return {
basedir : basedir,
isFile : function (file) {
return files.hasOwnProperty(file)
},
readFileSync : function (file) {
return files[file]
}
}
}
t.equal(
resolve.sync('bar', opts('/foo')),
'/foo/node_modules/bar/baz.js'
);
});

View file

@ -0,0 +1,56 @@
var path = require('path');
var test = require('tape');
var resolve = require('../');
test('moduleDirectory strings', function (t) {
t.plan(4);
var dir = __dirname + '/module_dir';
var xopts = {
basedir : dir,
moduleDirectory: 'xmodules'
};
resolve('aaa', xopts, function (err, res, pkg) {
t.ifError(err);
t.equal(res, dir + '/xmodules/aaa/index.js');
});
var yopts = {
basedir : dir,
moduleDirectory: 'ymodules'
};
resolve('aaa', yopts, function (err, res, pkg) {
t.ifError(err);
t.equal(res, dir + '/ymodules/aaa/index.js');
});
});
test('moduleDirectory array', function (t) {
t.plan(6);
var dir = __dirname + '/module_dir';
var aopts = {
basedir : dir,
moduleDirectory: [ 'xmodules', 'ymodules', 'zmodules' ]
};
resolve('aaa', aopts, function (err, res, pkg) {
t.ifError(err);
t.equal(res, 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, 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, dir + '/zmodules/bbb/main.js');
});
});

View file

@ -0,0 +1 @@
module.exports = function (x) { return x * 100 }

View file

@ -0,0 +1 @@
module.exports = function (x) { return x + 100 }

View file

@ -0,0 +1 @@
module.exports = function (n) { return n * 111 }

View file

@ -0,0 +1,3 @@
{
"main": "main.js"
}

View file

@ -0,0 +1,48 @@
var path = require('path');
var test = require('tape');
var resolve = require('../');
test('$NODE_PATH', function (t) {
t.plan(4);
resolve('aaa', {
paths: [
__dirname + '/node_path/x',
__dirname + '/node_path/y'
],
basedir: __dirname,
}, function (err, res) {
t.equal(res, __dirname + '/node_path/x/aaa/index.js');
});
resolve('bbb', {
paths: [
__dirname + '/node_path/x',
__dirname + '/node_path/y'
],
basedir: __dirname,
}, function (err, res) {
t.equal(res, __dirname + '/node_path/y/bbb/index.js');
});
resolve('ccc', {
paths: [
__dirname + '/node_path/x',
__dirname + '/node_path/y'
],
basedir: __dirname,
}, function (err, res) {
t.equal(res, __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) {
t.equal(res, path.resolve(__dirname, '..', 'node_modules/tap/lib/main.js'));
});
});

View file

@ -0,0 +1 @@
module.exports = 'A'

View file

@ -0,0 +1 @@
module.exports = 'C'

View file

@ -0,0 +1 @@
module.exports = 'B'

View file

@ -0,0 +1 @@
module.exports = 'CY'

View file

@ -0,0 +1,9 @@
var test = require('tape');
var resolve = require('../');
test('nonstring', function (t) {
t.plan(1);
resolve(555, function (err, res, pkg) {
t.ok(err);
});
});

View file

@ -0,0 +1,35 @@
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);
t.equal(pkg.version, "1.2.3");
t.equal(res, 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, 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, resolverDir + '/node_modules/deep/alt.js');
});
});

View file

@ -0,0 +1,4 @@
{
"name": "deep",
"version": "1.2.3"
}

View file

@ -0,0 +1,23 @@
var 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) {
t.plan(1);
var dir = path.join(__dirname, 'precedence/bbb');
resolve('./', { basedir : dir }, function (err, res, pkg) {
t.ok(err);
});
});

View file

@ -0,0 +1 @@
module.exports = 'wtf'

View file

@ -0,0 +1 @@
module.exports = 'okok'

View file

@ -0,0 +1 @@
console.log(require('./'))

View file

@ -0,0 +1 @@
module.exports '>_<'

View file

@ -0,0 +1 @@
console.log(require('./')); // should throw

View file

@ -0,0 +1,281 @@
var path = require('path');
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) {
if (err) t.fail(err);
t.equal(res, dir + '/foo.js');
t.equal(pkg.name, 'resolve');
});
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');
});
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');
});
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(pkg.main, 'resolver');
});
resolve('foo', { basedir : dir }, function (err) {
t.equal(err.message, "Cannot find module 'foo' from '" + path.resolve(dir) + "'");
});
});
test('bar', function (t) {
t.plan(6);
var dir = __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(pkg, undefined);
});
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(pkg, undefined);
});
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(pkg, undefined);
});
});
test('baz', function (t) {
t.plan(4);
var dir = __dirname + '/resolver';
resolve('./baz', { basedir : dir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, 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, 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) {
if (err) t.fail(err);
t.equal(res, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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, 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) {
if (err) t.fail(err);
t.equal(res, 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) {
if (err) t.fail(err);
t.equal(res, 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) {
if (err) t.fail(err);
t.equal(res, dir + '/cup.coffee');
});
resolve('./cup.coffee', { basedir : dir }, function (err, res) {
if (err) t.fail(err);
t.equal(res, dir + '/cup.coffee');
});
resolve('./cup', { basedir : dir, extensions : [ '.js' ] },
function (err, res) {
t.equal(err.message, "Cannot find module './cup' from '" + path.resolve(dir) + "'");
});
});
test('mug', function (t) {
t.plan(3);
var dir = __dirname + '/resolver';
resolve('./mug', { basedir : dir }, function (err, res) {
if (err) t.fail(err);
t.equal(res, dir + '/mug.js');
});
resolve('./mug', { basedir : dir, extensions : [ '.coffee', '.js' ] },
function (err, res) {
if (err) t.fail(err);
t.equal(res, dir + '/mug.coffee');
});
resolve('./mug', { basedir : dir, extensions : [ '.js', '.coffee' ] },
function (err, res) {
t.equal(res, 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) {
if (err) t.fail(err);
t.equal(res, resolverDir + '/other_path/root.js');
});
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');
});
resolve('root', { basedir : dir, }, function (err, res) {
t.equal(err.message, "Cannot find module 'root' from '" + path.resolve(dir) + "'");
});
resolve('zzz', { basedir : dir, paths: [otherDir] }, function (err, res) {
t.equal(err.message, "Cannot find module 'zzz' from '" + path.resolve(dir) + "'");
});
});
test('incorrect main', function (t) {
t.plan(1)
var resolverDir = __dirname + '/resolver';
var dir = resolverDir + '/incorrect_main';
resolve('./incorrect_main', { basedir : resolverDir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, dir + '/index.js');
});
});
test('without basedir', function (t) {
t.plan(1);
var dir = __dirname + '/resolver/without_basedir';
var tester = require(dir + '/main.js');
tester(t, function (err, res, pkg){
if (err) {
t.fail(err);
} else {
t.equal(res, 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';
resolve('punycode', { basedir : resolverDir }, function (err, res, pkg) {
if (err) t.fail(err);
t.equal(res, resolverDir + '/node_modules/punycode/index.js');
});
});

View file

@ -0,0 +1 @@
module.exports = 1;

View file

@ -0,0 +1,3 @@
{
"main" : "quux.js"
}

View file

@ -0,0 +1 @@
module.exports = 1;

View file

@ -0,0 +1 @@
module.exports = 'hello garply';

View file

@ -0,0 +1,3 @@
{
"main" : "./lib"
}

View file

@ -0,0 +1 @@
module.exports = require('tiv') * 100;

View file

@ -0,0 +1 @@
module.exports = 3;

View file

@ -0,0 +1 @@

View file

@ -0,0 +1 @@
module.exports = 1;

View file

@ -0,0 +1,2 @@
// this is the actual main file 'index.js', not 'wrong.js' like the package.json would indicate
module.exports = 1;

View file

@ -0,0 +1,3 @@
{
"main" : "wrong.js"
}

View file

@ -0,0 +1 @@
module.exports = 1;

View file

@ -0,0 +1,6 @@
resolve = require('../../../');
module.exports = function(t, cb) {
resolve('mymodule', null, cb);
}

View file

@ -0,0 +1 @@
module.exports = "The tools we use have a profound (and devious!) influence on our thinking habits, and, therefore, on our thinking abilities.- E. Dijkstra"

View file

@ -0,0 +1,180 @@
var test = require('tape');
var resolve = require('../');
test('foo', function (t) {
var dir = __dirname + '/resolver';
t.equal(
resolve.sync('./foo', { basedir : dir }),
dir + '/foo.js'
);
t.equal(
resolve.sync('./foo.js', { basedir : dir }),
dir + '/foo.js'
);
t.throws(function () {
resolve.sync('foo', { basedir : dir });
});
t.end();
});
test('bar', function (t) {
var dir = __dirname + '/resolver';
t.equal(
resolve.sync('foo', { basedir : dir + '/bar' }),
dir + '/bar/node_modules/foo/index.js'
);
t.end();
});
test('baz', function (t) {
var dir = __dirname + '/resolver';
t.equal(
resolve.sync('./baz', { basedir : dir }),
dir + '/baz/quux.js'
);
t.end();
});
test('biz', function (t) {
var dir = __dirname + '/resolver/biz/node_modules';
t.equal(
resolve.sync('./grux', { basedir : dir }),
dir + '/grux/index.js'
);
t.equal(
resolve.sync('tiv', { basedir : dir + '/grux' }),
dir + '/tiv/index.js'
);
t.equal(
resolve.sync('grux', { basedir : dir + '/tiv' }),
dir + '/grux/index.js'
);
t.end();
});
test('normalize', function (t) {
var dir = __dirname + '/resolver/biz/node_modules/grux';
t.equal(
resolve.sync('../grux', { basedir : dir }),
dir + '/index.js'
);
t.end();
});
test('cup', function (t) {
var dir = __dirname + '/resolver';
t.equal(
resolve.sync('./cup', {
basedir : dir,
extensions : [ '.js', '.coffee' ]
}),
dir + '/cup.coffee'
);
t.equal(
resolve.sync('./cup.coffee', {
basedir : dir
}),
dir + '/cup.coffee'
);
t.throws(function () {
resolve.sync('./cup', {
basedir : dir,
extensions : [ '.js' ]
})
});
t.end();
});
test('mug', function (t) {
var dir = __dirname + '/resolver';
t.equal(
resolve.sync('./mug', { basedir : dir }),
dir + '/mug.js'
);
t.equal(
resolve.sync('./mug', {
basedir : dir,
extensions : [ '.coffee', '.js' ]
}),
dir + '/mug.coffee'
);
t.equal(
resolve.sync('./mug', {
basedir : dir,
extensions : [ '.js', '.coffee' ]
}),
dir + '/mug.js'
);
t.end();
});
test('other path', function (t) {
var resolverDir = __dirname + '/resolver';
var dir = resolverDir + '/bar';
var otherDir = resolverDir + '/other_path';
var path = require('path');
t.equal(
resolve.sync('root', {
basedir : dir,
paths: [otherDir] }),
resolverDir + '/other_path/root.js'
);
t.equal(
resolve.sync('lib/other-lib', {
basedir : dir,
paths: [otherDir] }),
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 = __dirname + '/resolver';
var dir = resolverDir + '/incorrect_main';
t.equal(
resolve.sync('./incorrect_main', { basedir : resolverDir }),
dir + '/index.js'
)
t.end()
});
test('#25: node modules with the same name as node stdlib modules', function (t) {
var resolverDir = __dirname + '/resolver/punycode';
t.equal(
resolve.sync('punycode', { basedir : resolverDir }),
resolverDir + '/node_modules/punycode/index.js'
)
t.end()
});

View file

@ -0,0 +1,13 @@
var 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'));
});
});

View file

@ -0,0 +1 @@
[1,2,3]

View file

@ -0,0 +1 @@
{}

65
node_modules/browser-resolve/package.json generated vendored Normal file
View file

@ -0,0 +1,65 @@
{
"_args": [
[
"browser-resolve@1.11.3",
"/Users/eric/repos/actions/setup-node"
]
],
"_development": true,
"_from": "browser-resolve@1.11.3",
"_id": "browser-resolve@1.11.3",
"_inBundle": false,
"_integrity": "sha512-exDi1BYWB/6raKHmDTCicQfTkqwN5fioMFV4j8BsfMU4R2DK/QfZfK7kOVkmWCNANf0snkBzqGqAJBao9gZMdQ==",
"_location": "/browser-resolve",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "browser-resolve@1.11.3",
"name": "browser-resolve",
"escapedName": "browser-resolve",
"rawSpec": "1.11.3",
"saveSpec": null,
"fetchSpec": "1.11.3"
},
"_requiredBy": [
"/jest-resolve"
],
"_resolved": "https://registry.npmjs.org/browser-resolve/-/browser-resolve-1.11.3.tgz",
"_spec": "1.11.3",
"_where": "/Users/eric/repos/actions/setup-node",
"author": {
"name": "Roman Shtylman",
"email": "shtylman@gmail.com"
},
"bugs": {
"url": "https://github.com/shtylman/node-browser-resolve/issues"
},
"dependencies": {
"resolve": "1.1.7"
},
"description": "resolve which handles browser field support in package.json",
"devDependencies": {
"mocha": "1.14.0"
},
"files": [
"index.js",
"empty.js"
],
"homepage": "https://github.com/shtylman/node-browser-resolve#readme",
"keywords": [
"resolve",
"browser"
],
"license": "MIT",
"main": "index.js",
"name": "browser-resolve",
"repository": {
"type": "git",
"url": "git://github.com/shtylman/node-browser-resolve.git"
},
"scripts": {
"test": "mocha --reporter list test/*.js"
},
"version": "1.11.3"
}