pax_global_header00006660000000000000000000000064137117366760014533gustar00rootroot0000000000000052 comment=21b46454ae772bce1b894a63f9cdabe0953a6712 browser-resolve-2.0.0/000077500000000000000000000000001371173667600146725ustar00rootroot00000000000000browser-resolve-2.0.0/.gitignore000066400000000000000000000000511371173667600166560ustar00rootroot00000000000000node_modules !test/fixtures/node_modules browser-resolve-2.0.0/.npmrc000066400000000000000000000000231371173667600160050ustar00rootroot00000000000000package-lock=false browser-resolve-2.0.0/.travis.yml000066400000000000000000000011411371173667600170000ustar00rootroot00000000000000language: node_js os: linux dist: xenial node_js: - "14" - "13" - "12" - "11" - "10" - "9" - "8" - "6" - "4" - "iojs" - "0.12" - "0.10" - "0.8" before_install: # Old npm certs are untrusted https://github.com/npm/npm/issues/20191 - 'if [ "${TRAVIS_NODE_VERSION}" = "0.8" ]; then export NPM_CONFIG_STRICT_SSL=false; fi' - 'nvm install-latest-npm' install: - 'if [ "${TRAVIS_NODE_VERSION}" = "0.9" ]; then nvm install --latest-npm 0.8 && npm install && nvm use "${TRAVIS_NODE_VERSION}"; else npm install; fi;' matrix: fast_finish: true allow_failures: - node_js: "0.6" browser-resolve-2.0.0/CHANGELOG.md000066400000000000000000000006131371173667600165030ustar00rootroot00000000000000# browser-resolve Change Log All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## 2.0.0 - 2020-08-03 * Update `resolve` to 1.17.0+. Technically, this is a bugfix and feature update. However, older browserify versions rely on a `resolve` bug, and would break if this was published as a minor version update. browser-resolve-2.0.0/LICENSE000066400000000000000000000021231371173667600156750ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2013-2015 Roman Shtylman 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. browser-resolve-2.0.0/README.md000066400000000000000000000102751371173667600161560ustar00rootroot00000000000000# browser-resolve [![Build Status](https://travis-ci.org/browserify/browser-resolve.png?branch=master)](https://travis-ci.org/browserify/browser-resolve) node.js resolve algorithm with [browser field](https://github.com/defunctzombie/package-browser-field-spec) support. ## api ### bresolve(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 Additionally, options supported by [node-resolve](https://github.com/browserify/resolve#resolveid-opts-cb) can be used. ### bresolve.sync(id, opts={}) Same as the async resolve, just uses sync methods. Additionally, options supported by [node-resolve](https://github.com/browserify/resolve#resolvesyncid-opts-cb) can be used. ## basic usage you can resolve files like `require.resolve()`: ``` js var bresolve = require('browser-resolve'); bresolve('../', { filename: __filename }, function(err, path) { console.log(path); }); ``` ``` $ node example/resolve.js /home/substack/projects/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 bresolve = require('browser-resolve'); bresolve('http', { modules: shims }, function(err, path) { console.log(path); }); ``` ``` $ node example/builtin.js /home/substack/projects/browser-resolve/builtin/http.js ``` ## browser field browser-specific versions of modules ``` json { "name": "custom", "version": "0.0.0", "browser": { "./main.js": "custom.js" } } ``` ``` js var bresolve = require('browser-resolve'); var parent = { filename: __dirname + '/custom/file.js' }; bresolve('./main.js', parent, function(err, path) { console.log(path); }); ``` ``` $ node example/custom.js /home/substack/projects/browser-resolve/example/custom/custom.js ``` You can use different package.json properties for the resolution, if you want to allow packages to target different environments for example: ``` json { "browser": { "./main.js": "custom.js" }, "chromeapp": { "./main.js": "custom-chromeapp.js" } } ``` ``` js var bresolve = require('browser-resolve'); var parent = { filename: __dirname + '/custom/file.js', browser: 'chromeapp' }; bresolve('./main.js', parent, function(err, path) { console.log(path); }); ``` ``` $ node example/custom.js /home/substack/projects/browser-resolve/example/custom/custom-chromeapp.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 bresolve = require('browser-resolve'); var parent = { filename: __dirname + '/skip/main.js' }; bresolve('tar', parent, function(err, path) { console.log(path); }); ``` ``` $ node example/skip.js /home/substack/projects/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 `bresolve()`. This was done to allow package managers to choose which shims they want to use without browser-resolve being the central point of update. browser-resolve-2.0.0/empty.js000066400000000000000000000000001371173667600163540ustar00rootroot00000000000000browser-resolve-2.0.0/example/000077500000000000000000000000001371173667600163255ustar00rootroot00000000000000browser-resolve-2.0.0/example/builtin.js000066400000000000000000000001431371173667600203270ustar00rootroot00000000000000var resolve = require('../'); resolve('fs', null, function(err, path) { console.log(path); }); browser-resolve-2.0.0/example/custom-chromeapp.js000066400000000000000000000002741371173667600221540ustar00rootroot00000000000000var resolve = require('../'); var parent = { filename: __dirname + '/custom/file.js', browser: 'chromeapp' }; resolve('./main.js', parent, function(err, path) { console.log(path); }); browser-resolve-2.0.0/example/custom.js000066400000000000000000000002461371173667600201770ustar00rootroot00000000000000var resolve = require('../'); var parent = { filename: __dirname + '/custom/file.js' }; resolve('./main.js', parent, function(err, path) { console.log(path); }); browser-resolve-2.0.0/example/custom/000077500000000000000000000000001371173667600176375ustar00rootroot00000000000000browser-resolve-2.0.0/example/custom/custom-chromeapp.js000066400000000000000000000000421371173667600234570ustar00rootroot00000000000000console.log('chromeapp version'); browser-resolve-2.0.0/example/custom/custom.js000066400000000000000000000000401371173667600215010ustar00rootroot00000000000000console.log('browser version'); browser-resolve-2.0.0/example/custom/main.js000066400000000000000000000000371371173667600211210ustar00rootroot00000000000000console.log('server version'); browser-resolve-2.0.0/example/custom/package.json000066400000000000000000000002331371173667600221230ustar00rootroot00000000000000{ "name": "custom", "version": "0.0.0", "chromeapp": { "./main.js": "custom-chromeapp.js" }, "browser": { "./main.js": "custom.js" } } browser-resolve-2.0.0/example/resolve.js000066400000000000000000000001701371173667600203400ustar00rootroot00000000000000var resolve = require('../'); resolve('../', { filename: __filename }, function(err, path) { console.log(path); }); browser-resolve-2.0.0/example/skip.js000066400000000000000000000002361371173667600176320ustar00rootroot00000000000000var resolve = require('../'); var parent = { filename: __dirname + '/skip/main.js' }; resolve('tar', parent, function(err, path) { console.log(path); }); browser-resolve-2.0.0/example/skip/000077500000000000000000000000001371173667600172735ustar00rootroot00000000000000browser-resolve-2.0.0/example/skip/main.js000066400000000000000000000002121371173667600205500ustar00rootroot00000000000000var tar = require('tar'); exports.add = function (a, b) { return a + b; }; exports.parse = function () { return tar.Parse(); }; browser-resolve-2.0.0/example/skip/package.json000066400000000000000000000001201371173667600215520ustar00rootroot00000000000000{ "name": "skip", "version": "0.0.0", "browser": { "tar": false } } browser-resolve-2.0.0/index.js000066400000000000000000000224401371173667600163410ustar00rootroot00000000000000// 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; browser-resolve-2.0.0/package.json000066400000000000000000000011651371173667600171630ustar00rootroot00000000000000{ "name": "browser-resolve", "version": "2.0.0", "description": "resolve which handles browser field support in package.json", "main": "index.js", "files": [ "index.js", "empty.js" ], "scripts": { "test": "node scripts/setup-symlinks.js && mocha --reporter list test/*.js" }, "repository": { "type": "git", "url": "git://github.com/browserify/browser-resolve.git" }, "keywords": [ "resolve", "browser" ], "author": "Roman Shtylman ", "license": "MIT", "dependencies": { "resolve": "^1.17.0" }, "devDependencies": { "mocha": "^2.5.3" } } browser-resolve-2.0.0/scripts/000077500000000000000000000000001371173667600163615ustar00rootroot00000000000000browser-resolve-2.0.0/scripts/setup-symlinks.js000066400000000000000000000004641371173667600217320ustar00rootroot00000000000000var fs = require('fs'); try { fs.mkdirSync(__dirname + '/../test/fixtures/node_modules/linker/node_modules'); } catch (e) {} process.chdir(__dirname + '/../test/fixtures/node_modules/linker/node_modules'); try { fs.unlinkSync('linked'); } catch (e) {} fs.symlinkSync('../../../linked', 'linked', 'dir');browser-resolve-2.0.0/test/000077500000000000000000000000001371173667600156515ustar00rootroot00000000000000browser-resolve-2.0.0/test/core-sync.js000066400000000000000000000005651371173667600201170ustar00rootroot00000000000000// test loading core modules var assert = require('assert'); var resolve = require('../'); var shims = { events: 'foo' }; test('shim found', function() { var path = resolve.sync('events', { modules: shims }); assert.equal(path, 'foo'); }); test('core shim not found', function() { var path = resolve.sync('http', {}); assert.equal(path, 'http'); }); browser-resolve-2.0.0/test/core.js000066400000000000000000000007721371173667600171450ustar00rootroot00000000000000// test loading core modules var assert = require('assert'); var resolve = require('../'); var shims = { events: 'foo' }; test('shim found', function(done) { resolve('events', { modules: shims }, function(err, path) { assert.ifError(err); assert.equal(path, 'foo'); done(); }); }); test('core shim not found', function(done) { resolve('http', {}, function(err, path) { assert.ifError(err); assert.equal(path, 'http'); done(); }); }); browser-resolve-2.0.0/test/ext.js000066400000000000000000000046571371173667600170230ustar00rootroot00000000000000var assert = require('assert'); var resolve = require('../'); var fixtures_dir = __dirname + '/fixtures'; test('module to implicit extension', function(done) { var opts = { filename: fixtures_dir + '/node_modules/module-o/main.js' } resolve('module-a', opts, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-o/x.js')); done(); }); }); test('implicit extension to implicit extension', function(done) { var opts = { filename: fixtures_dir + '/node_modules/module-p/main.js' } resolve('./z.js', opts, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-p/x.js')); done(); }); }); test('implicit extension to implicit extension', function(done) { var opts = { filename: fixtures_dir + '/node_modules/module-p/main.js' } resolve('./z', opts, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-p/x.js')); done(); }); }); test('explicit extension to explicit extension', function(done) { var opts = { filename: fixtures_dir + '/node_modules/module-q/main.js' } resolve('./z.js', opts, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-q/x.js')); done(); }); }); test('implicit extension to explicit extension', function(done) { var opts = { filename: fixtures_dir + '/node_modules/module-r/main.js' } resolve('./z.js', opts, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-r/x.js')); done(); }); }); test('module implicit extension to explicit extension', function(done) { var opts = { filename: fixtures_dir + '/node_modules/module-s/main.js' } resolve('whatever/z.js', opts, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-s/x.js')); done(); }); }); test('module implicit extension to explicit extension', function(done) { var opts = { filename: fixtures_dir + '/node_modules/module-s/main.js' } resolve('whatever/z', opts, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-s/x.js')); done(); }); }); browser-resolve-2.0.0/test/false-sync.js000066400000000000000000000011431371173667600202520ustar00rootroot00000000000000var assert = require('assert'); var path = require('path'); var resolve = require('../'); var fixtures_dir = __dirname + '/fixtures'; test('false file', function() { var parent_file = fixtures_dir + '/node_modules/false/index.js'; var p = resolve.sync('./fake.js', { filename: parent_file }); assert.equal(p, path.normalize(__dirname + '/../empty.js')); }); test('false module', function() { var parent_file = fixtures_dir + '/node_modules/false/index.js'; var p = resolve.sync('ignore-me', { filename: parent_file }); assert.equal(p, path.normalize(__dirname + '/../empty.js')); }); browser-resolve-2.0.0/test/false.js000066400000000000000000000020511371173667600172770ustar00rootroot00000000000000var assert = require('assert'); var path = require('path'); var resolve = require('../'); var fixtures_dir = __dirname + '/fixtures'; test('false file', function(done) { var parent_file = fixtures_dir + '/node_modules/false/index.js'; resolve('./fake.js', { filename: parent_file }, function(err, p) { assert.ifError(err); assert.equal(p, path.normalize(__dirname + '/../empty.js')); done(); }); }); test('false module', function(done) { var parent_file = fixtures_dir + '/node_modules/false/index.js'; resolve('ignore-me', { filename: parent_file }, function(err, p) { assert.ifError(err); assert.equal(p, path.normalize(__dirname + '/../empty.js')); done(); }); }); test('false expand path', function(done) { var parent = { filename: fixtures_dir + '/node_modules/module-m/lib/index.js' }; resolve('./hide', parent, function(err, p, pkg) { assert.ifError(err); assert.equal(p, path.normalize(__dirname + '/../empty.js')); done(); }); }); browser-resolve-2.0.0/test/fixtures-coffee/000077500000000000000000000000001371173667600207475ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures-coffee/foo.coffee000066400000000000000000000000161371173667600227000ustar00rootroot00000000000000// blank file browser-resolve-2.0.0/test/fixtures-coffee/node_modules/000077500000000000000000000000001371173667600234245ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-a/000077500000000000000000000000001371173667600251275ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-a/index.coffee000066400000000000000000000000111371173667600273770ustar00rootroot00000000000000// dummy browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-b/000077500000000000000000000000001371173667600251305ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-b/main.coffee000066400000000000000000000000111371173667600272150ustar00rootroot00000000000000// entry browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-b/package.json000066400000000000000000000000401371173667600274100ustar00rootroot00000000000000{ "main": "./main.coffee" } browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-c/000077500000000000000000000000001371173667600251315ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-c/bar.coffee000066400000000000000000000000371371173667600270460ustar00rootroot00000000000000// required by browser.js only browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-c/browser.coffee000066400000000000000000000000501371173667600277600ustar00rootroot00000000000000// browser entry file require('./bar'); browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-c/main.coffee000066400000000000000000000000111371173667600272160ustar00rootroot00000000000000// entry browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-c/package.json000066400000000000000000000001031371173667600274110ustar00rootroot00000000000000{ "main": "./main.coffee", "browser": "./browser.coffee" } browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-d/000077500000000000000000000000001371173667600251325ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-d/browser.coffee000066400000000000000000000000261371173667600277640ustar00rootroot00000000000000// browser entry file browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-d/main.coffee000066400000000000000000000000111371173667600272170ustar00rootroot00000000000000// entry browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-d/package.json000066400000000000000000000001441371173667600274170ustar00rootroot00000000000000{ "main": "./main.coffee", "browser": { "./main.coffee": "./browser.coffee" } } browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-e/000077500000000000000000000000001371173667600251335ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-e/browser.coffee000066400000000000000000000000261371173667600277650ustar00rootroot00000000000000// browser entry file browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-e/foo.coffee000066400000000000000000000000211371173667600270600ustar00rootroot00000000000000// won't be used browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-e/main.coffee000066400000000000000000000000331371173667600272240ustar00rootroot00000000000000// entry require('./foo'); browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-e/package.json000066400000000000000000000001431371173667600274170ustar00rootroot00000000000000{ "main": "./main.coffee", "browser": { "./foo.coffee": "./browser.coffee" } } browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-f/000077500000000000000000000000001371173667600251345ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-f/lib/000077500000000000000000000000001371173667600257025ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-f/lib/browser.coffee000066400000000000000000000000261371173667600305340ustar00rootroot00000000000000// browser entry file browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-f/lib/foo.coffee000066400000000000000000000000211371173667600276270ustar00rootroot00000000000000// won't be used browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-f/lib/main.coffee000066400000000000000000000000331371173667600277730ustar00rootroot00000000000000// entry require('./foo'); browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-f/package.json000066400000000000000000000001571371173667600274250ustar00rootroot00000000000000{ "main": "./lib/main.coffee", "browser": { "./lib/foo.coffee": "./lib/browser.coffee" } } browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-g/000077500000000000000000000000001371173667600251355ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-g/foobar-browser.coffee000066400000000000000000000000221371173667600312310ustar00rootroot00000000000000// foobar browser browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-g/index.coffee000066400000000000000000000000231371173667600274100ustar00rootroot00000000000000require('foobar'); browser-resolve-2.0.0/test/fixtures-coffee/node_modules/module-g/package.json000066400000000000000000000001411371173667600274170ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "foobar": "./foobar-browser.coffee" } } browser-resolve-2.0.0/test/fixtures/000077500000000000000000000000001371173667600175225ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/foo.js000066400000000000000000000000161371173667600206400ustar00rootroot00000000000000// blank file browser-resolve-2.0.0/test/fixtures/linked/000077500000000000000000000000001371173667600207705ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/linked/index.js000066400000000000000000000000101371173667600224240ustar00rootroot00000000000000// dummybrowser-resolve-2.0.0/test/fixtures/node_modules/000077500000000000000000000000001371173667600221775ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/alt-browser-field/000077500000000000000000000000001371173667600255215ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/alt-browser-field/chromeapp-direct.js000066400000000000000000000000001371173667600312730ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/alt-browser-field/chromeapp.js000066400000000000000000000000001371173667600300230ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/alt-browser-field/direct.js000066400000000000000000000000231371173667600273240ustar00rootroot00000000000000// node empty file browser-resolve-2.0.0/test/fixtures/node_modules/alt-browser-field/foo.js000066400000000000000000000000241371173667600266360ustar00rootroot00000000000000 require('foobar'); browser-resolve-2.0.0/test/fixtures/node_modules/alt-browser-field/index.js000066400000000000000000000000321371173667600271610ustar00rootroot00000000000000var URL = require("url"); browser-resolve-2.0.0/test/fixtures/node_modules/alt-browser-field/package.json000066400000000000000000000004101371173667600300020ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "url": "./url-browser.js" }, "chromeapp": { "url": "./url-chromeapp.js", "./index.js": "./chromeapp.js", "./direct": "./chromeapp-direct.js", "foobar": "module-k" } } browser-resolve-2.0.0/test/fixtures/node_modules/alt-browser-field/url-browser.js000066400000000000000000000000111371173667600303320ustar00rootroot00000000000000// empty browser-resolve-2.0.0/test/fixtures/node_modules/alt-browser-field/url-chromeapp.js000066400000000000000000000000111371173667600306250ustar00rootroot00000000000000// empty browser-resolve-2.0.0/test/fixtures/node_modules/false/000077500000000000000000000000001371173667600232715ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/false/fake.js000066400000000000000000000000311371173667600245270ustar00rootroot00000000000000module.exports = 'fake'; browser-resolve-2.0.0/test/fixtures/node_modules/false/node_modules/000077500000000000000000000000001371173667600257465ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/false/node_modules/ignore-me/000077500000000000000000000000001371173667600276305ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/false/node_modules/ignore-me/index.js000066400000000000000000000000341371173667600312720ustar00rootroot00000000000000module.exports = 'failure'; browser-resolve-2.0.0/test/fixtures/node_modules/false/package.json000066400000000000000000000001531371173667600255560ustar00rootroot00000000000000{ "main": "./main.js", "browser": { "ignore-me": false, "./fake.js": false } } browser-resolve-2.0.0/test/fixtures/node_modules/linker/000077500000000000000000000000001371173667600234635ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/linker/index.js000066400000000000000000000000221371173667600251220ustar00rootroot00000000000000require('linked');browser-resolve-2.0.0/test/fixtures/node_modules/module-a/000077500000000000000000000000001371173667600237025ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-a/index.js000066400000000000000000000000111371173667600253370ustar00rootroot00000000000000// dummy browser-resolve-2.0.0/test/fixtures/node_modules/module-b/000077500000000000000000000000001371173667600237035ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-b/main.js000066400000000000000000000000111371173667600251550ustar00rootroot00000000000000// entry browser-resolve-2.0.0/test/fixtures/node_modules/module-b/package.json000066400000000000000000000000341371173667600261660ustar00rootroot00000000000000{ "main": "./main.js" } browser-resolve-2.0.0/test/fixtures/node_modules/module-c/000077500000000000000000000000001371173667600237045ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-c/bar.js000066400000000000000000000000371371173667600250060ustar00rootroot00000000000000// required by browser.js only browser-resolve-2.0.0/test/fixtures/node_modules/module-c/browser.js000066400000000000000000000000501371173667600257200ustar00rootroot00000000000000// browser entry file require('./bar'); browser-resolve-2.0.0/test/fixtures/node_modules/module-c/chromeapp.js000066400000000000000000000000521371173667600262150ustar00rootroot00000000000000// chromeapp entry file require('./foo'); browser-resolve-2.0.0/test/fixtures/node_modules/module-c/foo.js000066400000000000000000000000411371173667600250200ustar00rootroot00000000000000// required by chromeapp.js only browser-resolve-2.0.0/test/fixtures/node_modules/module-c/main.js000066400000000000000000000000111371173667600251560ustar00rootroot00000000000000// entry browser-resolve-2.0.0/test/fixtures/node_modules/module-c/package.json000066400000000000000000000001361371173667600261720ustar00rootroot00000000000000{ "main": "./main.js", "browser": "./browser.js", "chromeapp": "./chromeapp.js" } browser-resolve-2.0.0/test/fixtures/node_modules/module-d/000077500000000000000000000000001371173667600237055ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-d/browser.js000066400000000000000000000000261371173667600257240ustar00rootroot00000000000000// browser entry file browser-resolve-2.0.0/test/fixtures/node_modules/module-d/main.js000066400000000000000000000000111371173667600251570ustar00rootroot00000000000000// entry browser-resolve-2.0.0/test/fixtures/node_modules/module-d/package.json000066400000000000000000000001301371173667600261650ustar00rootroot00000000000000{ "main": "./main.js", "browser": { "./main.js": "./browser.js" } } browser-resolve-2.0.0/test/fixtures/node_modules/module-e/000077500000000000000000000000001371173667600237065ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-e/browser.js000066400000000000000000000000261371173667600257250ustar00rootroot00000000000000// browser entry file browser-resolve-2.0.0/test/fixtures/node_modules/module-e/foo.js000066400000000000000000000000211371173667600250200ustar00rootroot00000000000000// won't be used browser-resolve-2.0.0/test/fixtures/node_modules/module-e/main.js000066400000000000000000000000331371173667600251640ustar00rootroot00000000000000// entry require('./foo'); browser-resolve-2.0.0/test/fixtures/node_modules/module-e/package.json000066400000000000000000000001271371173667600261740ustar00rootroot00000000000000{ "main": "./main.js", "browser": { "./foo.js": "./browser.js" } } browser-resolve-2.0.0/test/fixtures/node_modules/module-f/000077500000000000000000000000001371173667600237075ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-f/lib/000077500000000000000000000000001371173667600244555ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-f/lib/browser.js000066400000000000000000000000261371173667600264740ustar00rootroot00000000000000// browser entry file browser-resolve-2.0.0/test/fixtures/node_modules/module-f/lib/foo.js000066400000000000000000000000211371173667600255670ustar00rootroot00000000000000// won't be used browser-resolve-2.0.0/test/fixtures/node_modules/module-f/lib/main.js000066400000000000000000000000331371173667600257330ustar00rootroot00000000000000// entry require('./foo'); browser-resolve-2.0.0/test/fixtures/node_modules/module-f/package.json000066400000000000000000000001431371173667600261730ustar00rootroot00000000000000{ "main": "./lib/main.js", "browser": { "./lib/foo.js": "./lib/browser.js" } } browser-resolve-2.0.0/test/fixtures/node_modules/module-g/000077500000000000000000000000001371173667600237105ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-g/foobar-browser.js000066400000000000000000000000221371173667600271710ustar00rootroot00000000000000// foobar browser browser-resolve-2.0.0/test/fixtures/node_modules/module-g/index.js000066400000000000000000000000231371173667600253500ustar00rootroot00000000000000require('foobar'); browser-resolve-2.0.0/test/fixtures/node_modules/module-g/package.json000066400000000000000000000001351371173667600261750ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "foobar": "./foobar-browser.js" } } browser-resolve-2.0.0/test/fixtures/node_modules/module-h/000077500000000000000000000000001371173667600237115ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-h/index.js000066400000000000000000000000531371173667600253540ustar00rootroot00000000000000require('foobar'); require('querystring'); browser-resolve-2.0.0/test/fixtures/node_modules/module-h/package.json000066400000000000000000000003171371173667600262000ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "foobar": "module-b", "querystring": "module-c" }, "chromeapp": { "foobar": "module-b", "querystring": "module-c" } } browser-resolve-2.0.0/test/fixtures/node_modules/module-i/000077500000000000000000000000001371173667600237125ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-i/index.js000066400000000000000000000000531371173667600253550ustar00rootroot00000000000000require('foobar'); require('querystring'); browser-resolve-2.0.0/test/fixtures/node_modules/module-i/package.json000066400000000000000000000002601371173667600261760ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "foobar": "module-b", "querystring": "module-c" }, "browserify": { "transform": "deamdify" } } browser-resolve-2.0.0/test/fixtures/node_modules/module-j/000077500000000000000000000000001371173667600237135ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-j/index.js000066400000000000000000000000531371173667600253560ustar00rootroot00000000000000require('foobar'); require('querystring'); browser-resolve-2.0.0/test/fixtures/node_modules/module-j/package.json000066400000000000000000000002601371173667600261770ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "foobar": "module-i", "querystring": "module-c" }, "browserify": { "transform": "deamdify" } } browser-resolve-2.0.0/test/fixtures/node_modules/module-k/000077500000000000000000000000001371173667600237145ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-k/browser.js000066400000000000000000000000261371173667600257330ustar00rootroot00000000000000// browser entry file browser-resolve-2.0.0/test/fixtures/node_modules/module-k/index.js000066400000000000000000000000231371173667600253540ustar00rootroot00000000000000// node empty file browser-resolve-2.0.0/test/fixtures/node_modules/module-k/package.json000066400000000000000000000001301371173667600261740ustar00rootroot00000000000000{ "main": "index.js", "browser": { "./index.js": "./browser.js" } } browser-resolve-2.0.0/test/fixtures/node_modules/module-l/000077500000000000000000000000001371173667600237155ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-l/browser-direct.js000066400000000000000000000000001371173667600271740ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-l/browser.js000066400000000000000000000000261371173667600257340ustar00rootroot00000000000000// browser entry file browser-resolve-2.0.0/test/fixtures/node_modules/module-l/index.js000066400000000000000000000000231371173667600253550ustar00rootroot00000000000000// node empty file browser-resolve-2.0.0/test/fixtures/node_modules/module-l/package.json000066400000000000000000000002031371173667600261760ustar00rootroot00000000000000{ "main": "index.js", "browser": { "./index.js": "./browser.js", "./direct": "./browser-direct.js" } } browser-resolve-2.0.0/test/fixtures/node_modules/module-m/000077500000000000000000000000001371173667600237165ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-m/lib/000077500000000000000000000000001371173667600244645ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-m/lib/hide.js000066400000000000000000000000001371173667600257210ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-m/lib/index.js000066400000000000000000000000001371173667600261170ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-m/package.json000066400000000000000000000000721371173667600262030ustar00rootroot00000000000000{ "browser": { "./lib/hide.js": false } } browser-resolve-2.0.0/test/fixtures/node_modules/module-n/000077500000000000000000000000001371173667600237175ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-n/browser-bar.json000066400000000000000000000000021371173667600270270ustar00rootroot00000000000000{}browser-resolve-2.0.0/test/fixtures/node_modules/module-n/browser-foo.js000066400000000000000000000000121371173667600265120ustar00rootroot00000000000000// browserbrowser-resolve-2.0.0/test/fixtures/node_modules/module-n/index.js000066400000000000000000000000101371173667600253530ustar00rootroot00000000000000// main browser-resolve-2.0.0/test/fixtures/node_modules/module-n/package.json000066400000000000000000000002101371173667600261760ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "./foo.js": "./browser-foo.js", "./bar.json": "./browser-bar.json" } } browser-resolve-2.0.0/test/fixtures/node_modules/module-o/000077500000000000000000000000001371173667600237205ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-o/main.js000066400000000000000000000000111371173667600251720ustar00rootroot00000000000000// entry browser-resolve-2.0.0/test/fixtures/node_modules/module-o/package.json000066400000000000000000000000651371173667600262070ustar00rootroot00000000000000{ "browser": { "module-a": "./x" } } browser-resolve-2.0.0/test/fixtures/node_modules/module-o/x.js000066400000000000000000000000051371173667600245200ustar00rootroot00000000000000// x browser-resolve-2.0.0/test/fixtures/node_modules/module-p/000077500000000000000000000000001371173667600237215ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-p/package.json000066400000000000000000000000601371173667600262030ustar00rootroot00000000000000{ "browser": { "./z": "./x" } } browser-resolve-2.0.0/test/fixtures/node_modules/module-p/x.js000066400000000000000000000000051371173667600245210ustar00rootroot00000000000000// x browser-resolve-2.0.0/test/fixtures/node_modules/module-q/000077500000000000000000000000001371173667600237225ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-q/package.json000066400000000000000000000000661371173667600262120ustar00rootroot00000000000000{ "browser": { "./z.js": "./x.js" } } browser-resolve-2.0.0/test/fixtures/node_modules/module-q/x.js000066400000000000000000000000051371173667600245220ustar00rootroot00000000000000// x browser-resolve-2.0.0/test/fixtures/node_modules/module-r/000077500000000000000000000000001371173667600237235ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-r/package.json000066400000000000000000000000631371173667600262100ustar00rootroot00000000000000{ "browser": { "./z": "./x.js" } } browser-resolve-2.0.0/test/fixtures/node_modules/module-r/x.js000066400000000000000000000000051371173667600245230ustar00rootroot00000000000000// x browser-resolve-2.0.0/test/fixtures/node_modules/module-s/000077500000000000000000000000001371173667600237245ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-s/package.json000066400000000000000000000000721371173667600262110ustar00rootroot00000000000000{ "browser": { "whatever/z": "./x.js" } } browser-resolve-2.0.0/test/fixtures/node_modules/module-s/x.js000066400000000000000000000000051371173667600245240ustar00rootroot00000000000000// x browser-resolve-2.0.0/test/fixtures/node_modules/module-t/000077500000000000000000000000001371173667600237255ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/module-t/package.json000066400000000000000000000000601371173667600262070ustar00rootroot00000000000000{ "browser": { "./x": "./y" } } browser-resolve-2.0.0/test/fixtures/node_modules/module-t/x.js000066400000000000000000000000041371173667600245240ustar00rootroot00000000000000// xbrowser-resolve-2.0.0/test/fixtures/node_modules/module-t/y.js000066400000000000000000000000051371173667600245260ustar00rootroot00000000000000// y browser-resolve-2.0.0/test/fixtures/node_modules/override-engine-shim/000077500000000000000000000000001371173667600262175ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/override-engine-shim/index.js000066400000000000000000000000321371173667600276570ustar00rootroot00000000000000var URL = require("url"); browser-resolve-2.0.0/test/fixtures/node_modules/override-engine-shim/package.json000066400000000000000000000001271371173667600305050ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "url": "./url-browser.js" } } browser-resolve-2.0.0/test/fixtures/node_modules/override-engine-shim/url-browser.js000066400000000000000000000000111371173667600310300ustar00rootroot00000000000000// empty browser-resolve-2.0.0/test/fixtures/node_modules/toString/000077500000000000000000000000001371173667600240105ustar00rootroot00000000000000browser-resolve-2.0.0/test/fixtures/node_modules/toString/index.js000066400000000000000000000000111371173667600254450ustar00rootroot00000000000000// dummy browser-resolve-2.0.0/test/local-coffee.js000066400000000000000000000010471371173667600205300ustar00rootroot00000000000000var assert = require('assert'); var resolve = require('../'); var fixtures_dir = __dirname + '/fixtures-coffee'; test('local', function(done) { // resolve needs a parent filename or paths to be able to lookup files // we provide a phony parent file var parent = { filename: fixtures_dir + '/phony.js', extensions: ['.js', '.coffee'] }; resolve('./foo', parent, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures-coffee/foo.coffee')); done(); }); }); browser-resolve-2.0.0/test/local-sync.js000066400000000000000000000006101371173667600202500ustar00rootroot00000000000000var assert = require('assert'); var resolve = require('../'); var fixtures_dir = __dirname + '/fixtures'; test('local', function() { // resolve needs a parent filename or paths to be able to lookup files // we provide a phony parent file var path = resolve.sync('./foo', { filename: fixtures_dir + '/phony.js' }); assert.equal(path, require.resolve('./fixtures/foo')); }); browser-resolve-2.0.0/test/local.js000066400000000000000000000007121371173667600173010ustar00rootroot00000000000000var assert = require('assert'); var resolve = require('../'); var fixtures_dir = __dirname + '/fixtures'; test('local', function(done) { // resolve needs a parent filename or paths to be able to lookup files // we provide a phony parent file resolve('./foo', { filename: fixtures_dir + '/phony.js' }, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/foo')); done(); }); }); browser-resolve-2.0.0/test/mocha.opts000066400000000000000000000000131371173667600176410ustar00rootroot00000000000000--ui qunit browser-resolve-2.0.0/test/modules-coffee.js000066400000000000000000000076041371173667600211130ustar00rootroot00000000000000var assert = require('assert'); var resolve = require('../'); var fixtures_dir = __dirname + '/fixtures-coffee/node_modules'; // no package.json, load index.js test('index.js of module dir', function(done) { var parent = { paths: [ fixtures_dir ], extensions: ['.js', '.coffee'] }; resolve('module-a', parent, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures-coffee/node_modules/module-a/index.coffee')); done(); }); }); // package.json main field specifies other location test('alternate main', function(done) { var parent = { paths: [ fixtures_dir ], extensions: ['.js', '.coffee'] }; resolve('module-b', parent, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures-coffee/node_modules/module-b/main.coffee')); done(); }, {extensions: ['.js', '.coffee']}); }); // package.json has 'browser' field which is a string test('string browser field as main', function(done) { var parent = { paths: [ fixtures_dir ], extensions: ['.js', '.coffee'] }; resolve('module-c', parent, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures-coffee/node_modules/module-c/browser.coffee')); done(); }, {extensions: ['.js', '.coffee']}); }); // package.json has 'browser' field which is a string test('string browser field as main - require subfile', function(done) { var parent = { filename: fixtures_dir + '/module-c/browser.js', paths: [ fixtures_dir + '/module-c/node_modules' ], extensions: ['.js', '.coffee'] }; resolve('./bar', parent, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures-coffee/node_modules/module-c/bar.coffee')); done(); }); }); // package.json has browser field as object // one of the keys replaces the main file // this would be done if the user needed to replace main and some other module test('object browser field as main', function(done) { var parent = { paths: [ fixtures_dir ], extensions: ['.js', '.coffee'] }; resolve('module-d', parent, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures-coffee/node_modules/module-d/browser.coffee')); done(); }); }); // browser field in package.json maps ./foo.js -> ./browser.js // when we resolve ./foo while in module-e, this mapping should take effect // the result is that ./foo resolves to ./browser test('object browser field replace file', function(done) { var parent = { filename: fixtures_dir + '/module-e/main.coffee', extensions: ['.js', '.coffee'] }; resolve('./foo', parent, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures-coffee/node_modules/module-e/browser.coffee')); done(); }); }); // same as above, but without a paths field in parent // should still checks paths on the filename of parent test('object browser field replace file - no paths', function(done) { var parent = { filename: fixtures_dir + '/module-f/lib/main.coffee', extensions: ['.js', '.coffee'] }; resolve('./foo', parent, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures-coffee/node_modules/module-f/lib/browser.coffee')); done(); }); }); test('replace module in browser field object', function(done) { var parent = { filename: fixtures_dir + '/module-g/index.js', extensions: ['.js', '.coffee'] }; resolve('foobar', parent, function(err, path) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures-coffee/node_modules/module-g/foobar-browser.coffee')); done(); }); }); browser-resolve-2.0.0/test/modules-sync.js000066400000000000000000000136601371173667600206370ustar00rootroot00000000000000var assert = require('assert'); var resolve = require('../'); var fixtures_dir = __dirname + '/fixtures/node_modules'; // no package.json, load index.js test('index.js of module dir', function() { var path = resolve.sync('module-a', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }); assert.equal(path, require.resolve('./fixtures/node_modules/module-a/index')); }); // package.json main field specifies other location test('alternate main', function() { var path = resolve.sync('module-b', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }); assert.equal(path, require.resolve('./fixtures/node_modules/module-b/main')); }); // package.json has 'browser' field which is a string test('string browser field as main', function() { var path = resolve.sync('module-c', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }); assert.equal(path, require.resolve('./fixtures/node_modules/module-c/browser')); }); // package.json has 'browser' field which is a string test('string browser field as main - require subfile', function() { var parent = { filename: fixtures_dir + '/module-c/browser.js', paths: [ fixtures_dir + '/module-c/node_modules' ], package: { main: './browser.js' } }; var path = resolve.sync('./bar', parent); assert.equal(path, require.resolve('./fixtures/node_modules/module-c/bar')); }); // package.json has browser field as object // one of the keys replaces the main file // this would be done if the user needed to replace main and some other module test('object browser field as main', function() { var path = resolve.sync('module-d', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }); assert.equal(path, require.resolve('./fixtures/node_modules/module-d/browser')); }); // package.json has browser field as object // one of the keys replaces the main file // however the main has no prefix and browser uses ./ prefix for the same file test('object browser field as main', function() { var path = resolve.sync('module-k', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }); assert.equal(path, require.resolve('./fixtures/node_modules/module-k/browser')); }); // browser field in package.json maps ./foo.js -> ./browser.js // when we resolve ./foo while in module-e, this mapping should take effect // the result is that ./foo resolves to ./browser test('object browser field replace file', function() { var parent = { filename: fixtures_dir + '/module-e/main.js', package: { main: './main.js' } }; var path = resolve.sync('./foo', parent); assert.equal(path, require.resolve('./fixtures/node_modules/module-e/browser')); }); // browser field in package.json maps "module" -> "alternate module" test('test foobar -> module-b replacement', function() { var parent = { filename: fixtures_dir + '/module-h/index.js', package: { main: './index.js' } }; var path = resolve.sync('foobar', parent); assert.equal(path, require.resolve('./fixtures/node_modules/module-b/main')); }); // browser field in package.json maps "relative file" -> "relative file" with no extension test('test ./x -> ./y replacement', function() { var parent = { filename: fixtures_dir + '/module-t/index.js', package: { main: './index.js' } }; var path = resolve.sync('./x', parent); assert.equal(path, require.resolve('./fixtures/node_modules/module-t/y.js')); }); // same as above but replacing core test('test core -> module-c replacement', function() { var parent = { filename: fixtures_dir + '/module-h/index.js', package: { main: './index.js' } }; var path = resolve.sync('querystring', parent); assert.equal(path, require.resolve('./fixtures/node_modules/module-c/browser')); }); // browser field in package.json maps "module" -> "alternate module" test('test foobar -> module-b replacement with transform', function() { var parent = { filename: fixtures_dir + '/module-i/index.js', package: { main: './index.js' } }; var path = resolve.sync('foobar', parent); assert.equal(path, require.resolve('./fixtures/node_modules/module-b/main')); }); test('test foobar -> module-i replacement with transform in replacement', function() { var parent = { filename: fixtures_dir + '/module-j/index.js', package: { main: './index.js' } }; var path = resolve.sync('foobar', parent); assert.equal(path, require.resolve('./fixtures/node_modules/module-i/index')); }); // same as above, but without a paths field in parent // should still checks paths on the filename of parent test('object browser field replace file - no paths', function() { var parent = { filename: fixtures_dir + '/module-f/lib/main.js', package: { main: './lib/main.js' } }; var path = resolve.sync('./foo', parent); assert.equal(path, require.resolve('./fixtures/node_modules/module-f/lib/browser')); }); test('replace module in browser field object', function() { var parent = { filename: fixtures_dir + '/module-g/index.js', package: { main: './index.js' } }; var path = resolve.sync('foobar', parent); assert.equal(path, require.resolve('./fixtures/node_modules/module-g/foobar-browser')); }); test('override engine shim', function() { var parent = { filename: fixtures_dir + '/override-engine-shim/index.js', package: { main: './index.js' }, modules: { url: "wonderland" } }; var path = resolve.sync('url', parent); assert.equal(path, require.resolve('./fixtures/node_modules/override-engine-shim/url-browser')); }); test('alt-browser field', function() { var parent = { filename: fixtures_dir + '/alt-browser-field/index.js', package: { main: './index.js' }, browser: 'chromeapp' }; var path = resolve.sync('url', parent); assert.equal(path, require.resolve('./fixtures/node_modules/alt-browser-field/url-chromeapp')); }); browser-resolve-2.0.0/test/modules.js000066400000000000000000000301021371173667600176530ustar00rootroot00000000000000var assert = require('assert'); var resolve = require('../'); var fixtures_dir = __dirname + '/fixtures/node_modules'; // no package.json, load index.js test('index.js of module dir', function(done) { resolve('module-a', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-a/index')); assert.strictEqual(pkg.main, 'fixtures'); done(); }); }); // package.json main field specifies other location test('alternate main', function(done) { resolve('module-b', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-b/main')); assert.strictEqual(pkg.main, './main.js'); done(); }); }); // package.json has 'browser' field which is a string test('string browser field as main', function(done) { resolve('module-c', { paths: [ fixtures_dir ], package: { main: 'fixtures' } }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-c/browser')); assert.equal(pkg.main, './browser.js'); done(); }); }); // package.json has 'browser' field which is a string test('string browser field as main - require subfile', function(done) { var parent = { filename: fixtures_dir + '/module-c/browser.js', paths: [ fixtures_dir + '/module-c/node_modules' ], package: { main: './browser.js' } }; resolve('./bar', parent, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-c/bar')); assert.equal(pkg.main, './browser.js'); done(); }); }); // package.json has an alternative 'browser' field which is a string test('string alt browser field as main - require subfile', function(done) { var parent = { filename: fixtures_dir + '/module-c/chromeapp.js', paths: [ fixtures_dir + '/module-c/node_modules' ], package: { main: './chromeapp.js' }, browser: 'chromeapp' }; resolve('./foo', parent, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-c/foo')); assert.equal(pkg.main, './chromeapp.js'); done(); }); }); // package.json has browser field as object // one of the keys replaces the main file // this would be done if the user needed to replace main and some other module test('object browser field as main', function(done) { resolve('module-d', { paths: [ fixtures_dir ] }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-d/browser')); assert.equal(pkg.main, './browser.js'); done(); }); }); // package.json has browser field as object // one of the keys replaces the main file // however the main has no prefix and browser uses ./ prefix for the same file test('object browser field as main', function(done) { resolve('module-k', { paths: [ fixtures_dir ] }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-k/browser')); assert.equal(pkg.main, './browser.js'); done(); }); }); test('deep module reference mapping', function(done) { resolve('module-l/direct', { basedir: __dirname + '/fixtures' }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-l/browser-direct')); assert.equal(pkg.main, './browser.js'); done(); }); }); // package.json has browser field as object // test that file resolves even though the file extension is omitted test('deep module reference mapping without file extension - .js', function(done) { resolve('module-n/foo', { basedir: __dirname + '/fixtures' }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-n/browser-foo')); done(); }); }); test('deep module reference mapping without file extension - .json', function(done) { resolve('module-n/bar', { basedir: __dirname + '/fixtures' }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-n/browser-bar')); done(); }); }); // browser field in package.json maps ./foo.js -> ./browser.js // when we resolve ./foo while in module-e, this mapping should take effect // the result is that ./foo resolves to ./browser test('object browser field replace file', function(done) { var parent = { filename: fixtures_dir + '/module-e/main.js', package: { main: './main.js' } }; resolve('./foo', parent, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-e/browser')); assert.equal(pkg.main, './main.js'); done(); }); }); // browser field in package.json maps "module" -> "alternate module" test('test foobar -> module-b replacement', function(done) { var parent = { filename: fixtures_dir + '/module-h/index.js', package: { main: './index.js' } }; resolve('foobar', parent, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-b/main')); assert.equal(pkg.main, './main.js'); done(); }); }); // same as above but replacing core test('test core -> module-c replacement', function(done) { var parent = { filename: fixtures_dir + '/module-h/index.js', package: { main: './index.js' } }; resolve('querystring', parent, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-c/browser')); assert.equal(pkg.main, './browser.js'); done(); }); }); // same as above but with alt browser test('test core -> module-c replacement with alt browser', function(done) { var parent = { filename: fixtures_dir + '/module-h/index.js', package: { main: './index.js' }, browser: 'chromeapp' }; resolve('querystring', parent, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-c/chromeapp')); assert.equal(pkg.main, './chromeapp.js'); done(); }); }); // browser field in package.json maps "module" -> "alternate module" test('test foobar -> module-b replacement with transform', function(done) { var parent = { filename: fixtures_dir + '/module-i/index.js', package: { main: './index.js' } }; resolve('foobar', parent, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-b/main')); assert.equal(pkg.main, './main.js'); done(); }); }); // browser field in package.json maps "relative file" -> "relative file" with no extension test('test ./x -> ./y replacement', function(done) { var parent = { filename: fixtures_dir + '/module-t/index.js', package: { main: './index.js' } }; resolve('./x', parent, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-t/y.js')); done(); }); }); test('test foobar -> module-i replacement with transform in replacement', function(done) { var parent = { filename: fixtures_dir + '/module-j/index.js', package: { main: './index.js' } }; resolve('foobar', parent, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-i/index')); assert.equal(pkg.main, './index.js'); assert.equal(pkg.browser['foobar'], 'module-b'); assert.equal(pkg.browserify.transform, 'deamdify'); done(); }); }); // same as above, but without a paths field in parent // should still checks paths on the filename of parent test('object browser field replace file - no paths', function(done) { var parent = { filename: fixtures_dir + '/module-f/lib/main.js', package: { main: './lib/main.js' } }; resolve('./foo', parent, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-f/lib/browser')); assert.equal(pkg.main, './lib/main.js'); done(); }); }); test('replace module in browser field object', function(done) { var parent = { filename: fixtures_dir + '/module-g/index.js', package: { main: './index.js' } }; resolve('foobar', parent, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-g/foobar-browser')); assert.equal(pkg.main, './index.js'); done(); }); }); test('override engine shim', function(done) { var parent = { filename: fixtures_dir + '/override-engine-shim/index.js', package: { main: './index.js' }, modules: { url: 'wonderland' } }; resolve('url', parent, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/override-engine-shim/url-browser')); done(); }); }); test('alt-browser field', function(done) { var parent = { filename: fixtures_dir + '/alt-browser-field/index.js', package: { main: './index.js' }, browser: 'chromeapp' }; resolve('url', parent, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/alt-browser-field/url-chromeapp')); assert.equal(pkg.main, './index.js'); done(); }); }); test('alt-browser deep module reference mapping', function(done) { resolve('alt-browser-field/direct', { basedir: __dirname + '/fixtures', browser: 'chromeapp' }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/alt-browser-field/chromeapp-direct')); assert.equal(pkg.main, './chromeapp.js'); done(); }); }); test('alt-browser fallback to "browser" on deps of deps', function(done) { var parent = { filename: fixtures_dir + '/alt-browser-field/foo.js', package: { main: './index.js' }, browser: 'chromeapp' }; resolve('foobar', parent, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/module-k/browser')); assert.equal(pkg.main, './browser.js'); assert.equal(pkg.browser['./index.js'], './browser.js'); done(); }); }); test('not fail on accessing path name defined in Object.prototype', function (done) { resolve('toString', { paths: [ fixtures_dir ] }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/toString/index')); done(); }); }); test('respect symlinks', function (done) { // some systems (e.g. rush, pnpm) use symlinks to create a recursive dependency graph // instead of relying on the hoisting aspect of the node module resolution algorithm (like npm and yarn do) // in these cases, we want to resolve to the real path of a module, so that the tree structure below // only ever tries to run the `x` module once (rather than once on each module that depends on it) // // - node_modules // - a // - node_modules // - symlink to x // - b // - node_modules // - symlink to x // resolve('linked', { paths: [ fixtures_dir + '/linker/node_modules' ], preserveSymlinks: false }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/linked/index')); done(); }); });