pax_global_header00006660000000000000000000000064133120745250014514gustar00rootroot0000000000000052 comment=427bb886cc22cc773651d3f2a51d4c5ea455870e node-browser-resolve-1.11.3/000077500000000000000000000000001331207452500156625ustar00rootroot00000000000000node-browser-resolve-1.11.3/.gitignore000066400000000000000000000000511331207452500176460ustar00rootroot00000000000000node_modules !test/fixtures/node_modules node-browser-resolve-1.11.3/.travis.yml000066400000000000000000000001221331207452500177660ustar00rootroot00000000000000language: node_js node_js: - "0.8" - "0.10" - "4" - "5" - "6" node-browser-resolve-1.11.3/LICENSE000066400000000000000000000021231331207452500166650ustar00rootroot00000000000000The 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. node-browser-resolve-1.11.3/README.md000066400000000000000000000073161331207452500171500ustar00rootroot00000000000000# 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. node-browser-resolve-1.11.3/empty.js000066400000000000000000000000001331207452500173440ustar00rootroot00000000000000node-browser-resolve-1.11.3/example/000077500000000000000000000000001331207452500173155ustar00rootroot00000000000000node-browser-resolve-1.11.3/example/builtin.js000066400000000000000000000001431331207452500213170ustar00rootroot00000000000000var resolve = require('../'); resolve('fs', null, function(err, path) { console.log(path); }); node-browser-resolve-1.11.3/example/custom-chromeapp.js000066400000000000000000000002741331207452500231440ustar00rootroot00000000000000var resolve = require('../'); var parent = { filename: __dirname + '/custom/file.js', browser: 'chromeapp' }; resolve('./main.js', parent, function(err, path) { console.log(path); }); node-browser-resolve-1.11.3/example/custom.js000066400000000000000000000002461331207452500211670ustar00rootroot00000000000000var resolve = require('../'); var parent = { filename: __dirname + '/custom/file.js' }; resolve('./main.js', parent, function(err, path) { console.log(path); }); node-browser-resolve-1.11.3/example/custom/000077500000000000000000000000001331207452500206275ustar00rootroot00000000000000node-browser-resolve-1.11.3/example/custom/custom-chromeapp.js000066400000000000000000000000421331207452500244470ustar00rootroot00000000000000console.log('chromeapp version'); node-browser-resolve-1.11.3/example/custom/custom.js000066400000000000000000000000401331207452500224710ustar00rootroot00000000000000console.log('browser version'); node-browser-resolve-1.11.3/example/custom/main.js000066400000000000000000000000371331207452500221110ustar00rootroot00000000000000console.log('server version'); node-browser-resolve-1.11.3/example/custom/package.json000066400000000000000000000002331331207452500231130ustar00rootroot00000000000000{ "name": "custom", "version": "0.0.0", "chromeapp": { "./main.js": "custom-chromeapp.js" }, "browser": { "./main.js": "custom.js" } } node-browser-resolve-1.11.3/example/resolve.js000066400000000000000000000001701331207452500213300ustar00rootroot00000000000000var resolve = require('../'); resolve('../', { filename: __filename }, function(err, path) { console.log(path); }); node-browser-resolve-1.11.3/example/skip.js000066400000000000000000000002361331207452500206220ustar00rootroot00000000000000var resolve = require('../'); var parent = { filename: __dirname + '/skip/main.js' }; resolve('tar', parent, function(err, path) { console.log(path); }); node-browser-resolve-1.11.3/example/skip/000077500000000000000000000000001331207452500202635ustar00rootroot00000000000000node-browser-resolve-1.11.3/example/skip/main.js000066400000000000000000000002121331207452500215400ustar00rootroot00000000000000var tar = require('tar'); exports.add = function (a, b) { return a + b; }; exports.parse = function () { return tar.Parse(); }; node-browser-resolve-1.11.3/example/skip/package.json000066400000000000000000000001201331207452500225420ustar00rootroot00000000000000{ "name": "skip", "version": "0.0.0", "browser": { "tar": false } } node-browser-resolve-1.11.3/index.js000066400000000000000000000224401331207452500173310ustar00rootroot00000000000000// 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; node-browser-resolve-1.11.3/package.json000066400000000000000000000011251331207452500201470ustar00rootroot00000000000000{ "name": "browser-resolve", "version": "1.11.3", "description": "resolve which handles browser field support in package.json", "main": "index.js", "files": [ "index.js", "empty.js" ], "scripts": { "test": "mocha --reporter list test/*.js" }, "repository": { "type": "git", "url": "git://github.com/shtylman/node-browser-resolve.git" }, "keywords": [ "resolve", "browser" ], "author": "Roman Shtylman ", "license": "MIT", "dependencies": { "resolve": "1.1.7" }, "devDependencies": { "mocha": "1.14.0" } } node-browser-resolve-1.11.3/test/000077500000000000000000000000001331207452500166415ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/core-sync.js000066400000000000000000000005651331207452500211070ustar00rootroot00000000000000// 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'); }); node-browser-resolve-1.11.3/test/core.js000066400000000000000000000007721331207452500201350ustar00rootroot00000000000000// 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(); }); }); node-browser-resolve-1.11.3/test/ext.js000066400000000000000000000046571331207452500200130ustar00rootroot00000000000000var 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(); }); }); node-browser-resolve-1.11.3/test/false-sync.js000066400000000000000000000011431331207452500212420ustar00rootroot00000000000000var 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')); }); node-browser-resolve-1.11.3/test/false.js000066400000000000000000000020511331207452500202670ustar00rootroot00000000000000var 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(); }); }); node-browser-resolve-1.11.3/test/fixtures-coffee/000077500000000000000000000000001331207452500217375ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures-coffee/foo.coffee000066400000000000000000000000161331207452500236700ustar00rootroot00000000000000// blank file node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/000077500000000000000000000000001331207452500244145ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-a/000077500000000000000000000000001331207452500261175ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-a/index.coffee000066400000000000000000000000111331207452500303670ustar00rootroot00000000000000// dummy node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-b/000077500000000000000000000000001331207452500261205ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-b/main.coffee000066400000000000000000000000111331207452500302050ustar00rootroot00000000000000// entry node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-b/package.json000066400000000000000000000000401331207452500304000ustar00rootroot00000000000000{ "main": "./main.coffee" } node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-c/000077500000000000000000000000001331207452500261215ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-c/bar.coffee000066400000000000000000000000371331207452500300360ustar00rootroot00000000000000// required by browser.js only node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-c/browser.coffee000066400000000000000000000000501331207452500307500ustar00rootroot00000000000000// browser entry file require('./bar'); node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-c/main.coffee000066400000000000000000000000111331207452500302060ustar00rootroot00000000000000// entry node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-c/package.json000066400000000000000000000001031331207452500304010ustar00rootroot00000000000000{ "main": "./main.coffee", "browser": "./browser.coffee" } node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-d/000077500000000000000000000000001331207452500261225ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-d/browser.coffee000066400000000000000000000000261331207452500307540ustar00rootroot00000000000000// browser entry file node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-d/main.coffee000066400000000000000000000000111331207452500302070ustar00rootroot00000000000000// entry node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-d/package.json000066400000000000000000000001441331207452500304070ustar00rootroot00000000000000{ "main": "./main.coffee", "browser": { "./main.coffee": "./browser.coffee" } } node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-e/000077500000000000000000000000001331207452500261235ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-e/browser.coffee000066400000000000000000000000261331207452500307550ustar00rootroot00000000000000// browser entry file node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-e/foo.coffee000066400000000000000000000000211331207452500300500ustar00rootroot00000000000000// won't be used node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-e/main.coffee000066400000000000000000000000331331207452500302140ustar00rootroot00000000000000// entry require('./foo'); node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-e/package.json000066400000000000000000000001431331207452500304070ustar00rootroot00000000000000{ "main": "./main.coffee", "browser": { "./foo.coffee": "./browser.coffee" } } node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-f/000077500000000000000000000000001331207452500261245ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-f/lib/000077500000000000000000000000001331207452500266725ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-f/lib/browser.coffee000066400000000000000000000000261331207452500315240ustar00rootroot00000000000000// browser entry file node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-f/lib/foo.coffee000066400000000000000000000000211331207452500306170ustar00rootroot00000000000000// won't be used node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-f/lib/main.coffee000066400000000000000000000000331331207452500307630ustar00rootroot00000000000000// entry require('./foo'); node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-f/package.json000066400000000000000000000001571331207452500304150ustar00rootroot00000000000000{ "main": "./lib/main.coffee", "browser": { "./lib/foo.coffee": "./lib/browser.coffee" } } node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-g/000077500000000000000000000000001331207452500261255ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-g/foobar-browser.coffee000066400000000000000000000000221331207452500322210ustar00rootroot00000000000000// foobar browser node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-g/index.coffee000066400000000000000000000000231331207452500304000ustar00rootroot00000000000000require('foobar'); node-browser-resolve-1.11.3/test/fixtures-coffee/node_modules/module-g/package.json000066400000000000000000000001411331207452500304070ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "foobar": "./foobar-browser.coffee" } } node-browser-resolve-1.11.3/test/fixtures/000077500000000000000000000000001331207452500205125ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/foo.js000066400000000000000000000000161331207452500216300ustar00rootroot00000000000000// blank file node-browser-resolve-1.11.3/test/fixtures/node_modules/000077500000000000000000000000001331207452500231675ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/alt-browser-field/000077500000000000000000000000001331207452500265115ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/alt-browser-field/chromeapp-direct.js000066400000000000000000000000001331207452500322630ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/alt-browser-field/chromeapp.js000066400000000000000000000000001331207452500310130ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/alt-browser-field/direct.js000066400000000000000000000000231331207452500303140ustar00rootroot00000000000000// node empty file node-browser-resolve-1.11.3/test/fixtures/node_modules/alt-browser-field/foo.js000066400000000000000000000000241331207452500276260ustar00rootroot00000000000000 require('foobar'); node-browser-resolve-1.11.3/test/fixtures/node_modules/alt-browser-field/index.js000066400000000000000000000000321331207452500301510ustar00rootroot00000000000000var URL = require("url"); node-browser-resolve-1.11.3/test/fixtures/node_modules/alt-browser-field/package.json000066400000000000000000000004101331207452500307720ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "url": "./url-browser.js" }, "chromeapp": { "url": "./url-chromeapp.js", "./index.js": "./chromeapp.js", "./direct": "./chromeapp-direct.js", "foobar": "module-k" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/alt-browser-field/url-browser.js000066400000000000000000000000111331207452500313220ustar00rootroot00000000000000// empty node-browser-resolve-1.11.3/test/fixtures/node_modules/alt-browser-field/url-chromeapp.js000066400000000000000000000000111331207452500316150ustar00rootroot00000000000000// empty node-browser-resolve-1.11.3/test/fixtures/node_modules/false/000077500000000000000000000000001331207452500242615ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/false/fake.js000066400000000000000000000000311331207452500255170ustar00rootroot00000000000000module.exports = 'fake'; node-browser-resolve-1.11.3/test/fixtures/node_modules/false/node_modules/000077500000000000000000000000001331207452500267365ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/false/node_modules/ignore-me/000077500000000000000000000000001331207452500306205ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/false/node_modules/ignore-me/index.js000066400000000000000000000000341331207452500322620ustar00rootroot00000000000000module.exports = 'failure'; node-browser-resolve-1.11.3/test/fixtures/node_modules/false/package.json000066400000000000000000000001531331207452500265460ustar00rootroot00000000000000{ "main": "./main.js", "browser": { "ignore-me": false, "./fake.js": false } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-a/000077500000000000000000000000001331207452500246725ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-a/index.js000066400000000000000000000000111331207452500263270ustar00rootroot00000000000000// dummy node-browser-resolve-1.11.3/test/fixtures/node_modules/module-b/000077500000000000000000000000001331207452500246735ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-b/main.js000066400000000000000000000000111331207452500261450ustar00rootroot00000000000000// entry node-browser-resolve-1.11.3/test/fixtures/node_modules/module-b/package.json000066400000000000000000000000341331207452500271560ustar00rootroot00000000000000{ "main": "./main.js" } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-c/000077500000000000000000000000001331207452500246745ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-c/bar.js000066400000000000000000000000371331207452500257760ustar00rootroot00000000000000// required by browser.js only node-browser-resolve-1.11.3/test/fixtures/node_modules/module-c/browser.js000066400000000000000000000000501331207452500267100ustar00rootroot00000000000000// browser entry file require('./bar'); node-browser-resolve-1.11.3/test/fixtures/node_modules/module-c/chromeapp.js000066400000000000000000000000521331207452500272050ustar00rootroot00000000000000// chromeapp entry file require('./foo'); node-browser-resolve-1.11.3/test/fixtures/node_modules/module-c/foo.js000066400000000000000000000000411331207452500260100ustar00rootroot00000000000000// required by chromeapp.js only node-browser-resolve-1.11.3/test/fixtures/node_modules/module-c/main.js000066400000000000000000000000111331207452500261460ustar00rootroot00000000000000// entry node-browser-resolve-1.11.3/test/fixtures/node_modules/module-c/package.json000066400000000000000000000001361331207452500271620ustar00rootroot00000000000000{ "main": "./main.js", "browser": "./browser.js", "chromeapp": "./chromeapp.js" } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-d/000077500000000000000000000000001331207452500246755ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-d/browser.js000066400000000000000000000000261331207452500267140ustar00rootroot00000000000000// browser entry file node-browser-resolve-1.11.3/test/fixtures/node_modules/module-d/main.js000066400000000000000000000000111331207452500261470ustar00rootroot00000000000000// entry node-browser-resolve-1.11.3/test/fixtures/node_modules/module-d/package.json000066400000000000000000000001301331207452500271550ustar00rootroot00000000000000{ "main": "./main.js", "browser": { "./main.js": "./browser.js" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-e/000077500000000000000000000000001331207452500246765ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-e/browser.js000066400000000000000000000000261331207452500267150ustar00rootroot00000000000000// browser entry file node-browser-resolve-1.11.3/test/fixtures/node_modules/module-e/foo.js000066400000000000000000000000211331207452500260100ustar00rootroot00000000000000// won't be used node-browser-resolve-1.11.3/test/fixtures/node_modules/module-e/main.js000066400000000000000000000000331331207452500261540ustar00rootroot00000000000000// entry require('./foo'); node-browser-resolve-1.11.3/test/fixtures/node_modules/module-e/package.json000066400000000000000000000001271331207452500271640ustar00rootroot00000000000000{ "main": "./main.js", "browser": { "./foo.js": "./browser.js" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-f/000077500000000000000000000000001331207452500246775ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-f/lib/000077500000000000000000000000001331207452500254455ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-f/lib/browser.js000066400000000000000000000000261331207452500274640ustar00rootroot00000000000000// browser entry file node-browser-resolve-1.11.3/test/fixtures/node_modules/module-f/lib/foo.js000066400000000000000000000000211331207452500265570ustar00rootroot00000000000000// won't be used node-browser-resolve-1.11.3/test/fixtures/node_modules/module-f/lib/main.js000066400000000000000000000000331331207452500267230ustar00rootroot00000000000000// entry require('./foo'); node-browser-resolve-1.11.3/test/fixtures/node_modules/module-f/package.json000066400000000000000000000001431331207452500271630ustar00rootroot00000000000000{ "main": "./lib/main.js", "browser": { "./lib/foo.js": "./lib/browser.js" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-g/000077500000000000000000000000001331207452500247005ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-g/foobar-browser.js000066400000000000000000000000221331207452500301610ustar00rootroot00000000000000// foobar browser node-browser-resolve-1.11.3/test/fixtures/node_modules/module-g/index.js000066400000000000000000000000231331207452500263400ustar00rootroot00000000000000require('foobar'); node-browser-resolve-1.11.3/test/fixtures/node_modules/module-g/package.json000066400000000000000000000001351331207452500271650ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "foobar": "./foobar-browser.js" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-h/000077500000000000000000000000001331207452500247015ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-h/index.js000066400000000000000000000000531331207452500263440ustar00rootroot00000000000000require('foobar'); require('querystring'); node-browser-resolve-1.11.3/test/fixtures/node_modules/module-h/package.json000066400000000000000000000003171331207452500271700ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "foobar": "module-b", "querystring": "module-c" }, "chromeapp": { "foobar": "module-b", "querystring": "module-c" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-i/000077500000000000000000000000001331207452500247025ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-i/index.js000066400000000000000000000000531331207452500263450ustar00rootroot00000000000000require('foobar'); require('querystring'); node-browser-resolve-1.11.3/test/fixtures/node_modules/module-i/package.json000066400000000000000000000002601331207452500271660ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "foobar": "module-b", "querystring": "module-c" }, "browserify": { "transform": "deamdify" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-j/000077500000000000000000000000001331207452500247035ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-j/index.js000066400000000000000000000000531331207452500263460ustar00rootroot00000000000000require('foobar'); require('querystring'); node-browser-resolve-1.11.3/test/fixtures/node_modules/module-j/package.json000066400000000000000000000002601331207452500271670ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "foobar": "module-i", "querystring": "module-c" }, "browserify": { "transform": "deamdify" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-k/000077500000000000000000000000001331207452500247045ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-k/browser.js000066400000000000000000000000261331207452500267230ustar00rootroot00000000000000// browser entry file node-browser-resolve-1.11.3/test/fixtures/node_modules/module-k/index.js000066400000000000000000000000231331207452500263440ustar00rootroot00000000000000// node empty file node-browser-resolve-1.11.3/test/fixtures/node_modules/module-k/package.json000066400000000000000000000001301331207452500271640ustar00rootroot00000000000000{ "main": "index.js", "browser": { "./index.js": "./browser.js" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-l/000077500000000000000000000000001331207452500247055ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-l/browser-direct.js000066400000000000000000000000001331207452500301640ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-l/browser.js000066400000000000000000000000261331207452500267240ustar00rootroot00000000000000// browser entry file node-browser-resolve-1.11.3/test/fixtures/node_modules/module-l/index.js000066400000000000000000000000231331207452500263450ustar00rootroot00000000000000// node empty file node-browser-resolve-1.11.3/test/fixtures/node_modules/module-l/package.json000066400000000000000000000002031331207452500271660ustar00rootroot00000000000000{ "main": "index.js", "browser": { "./index.js": "./browser.js", "./direct": "./browser-direct.js" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-m/000077500000000000000000000000001331207452500247065ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-m/lib/000077500000000000000000000000001331207452500254545ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-m/lib/hide.js000066400000000000000000000000001331207452500267110ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-m/lib/index.js000066400000000000000000000000001331207452500271070ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-m/package.json000066400000000000000000000000721331207452500271730ustar00rootroot00000000000000{ "browser": { "./lib/hide.js": false } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-n/000077500000000000000000000000001331207452500247075ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-n/browser-bar.json000066400000000000000000000000021331207452500300170ustar00rootroot00000000000000{}node-browser-resolve-1.11.3/test/fixtures/node_modules/module-n/browser-foo.js000066400000000000000000000000121331207452500275020ustar00rootroot00000000000000// browsernode-browser-resolve-1.11.3/test/fixtures/node_modules/module-n/index.js000066400000000000000000000000101331207452500263430ustar00rootroot00000000000000// main node-browser-resolve-1.11.3/test/fixtures/node_modules/module-n/package.json000066400000000000000000000002101331207452500271660ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "./foo.js": "./browser-foo.js", "./bar.json": "./browser-bar.json" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-o/000077500000000000000000000000001331207452500247105ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-o/main.js000066400000000000000000000000111331207452500261620ustar00rootroot00000000000000// entry node-browser-resolve-1.11.3/test/fixtures/node_modules/module-o/package.json000066400000000000000000000000651331207452500271770ustar00rootroot00000000000000{ "browser": { "module-a": "./x" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-o/x.js000066400000000000000000000000051331207452500255100ustar00rootroot00000000000000// x node-browser-resolve-1.11.3/test/fixtures/node_modules/module-p/000077500000000000000000000000001331207452500247115ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-p/package.json000066400000000000000000000000601331207452500271730ustar00rootroot00000000000000{ "browser": { "./z": "./x" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-p/x.js000066400000000000000000000000051331207452500255110ustar00rootroot00000000000000// x node-browser-resolve-1.11.3/test/fixtures/node_modules/module-q/000077500000000000000000000000001331207452500247125ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-q/package.json000066400000000000000000000000661331207452500272020ustar00rootroot00000000000000{ "browser": { "./z.js": "./x.js" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-q/x.js000066400000000000000000000000051331207452500255120ustar00rootroot00000000000000// x node-browser-resolve-1.11.3/test/fixtures/node_modules/module-r/000077500000000000000000000000001331207452500247135ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-r/package.json000066400000000000000000000000631331207452500272000ustar00rootroot00000000000000{ "browser": { "./z": "./x.js" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-r/x.js000066400000000000000000000000051331207452500255130ustar00rootroot00000000000000// x node-browser-resolve-1.11.3/test/fixtures/node_modules/module-s/000077500000000000000000000000001331207452500247145ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-s/package.json000066400000000000000000000000721331207452500272010ustar00rootroot00000000000000{ "browser": { "whatever/z": "./x.js" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-s/x.js000066400000000000000000000000051331207452500255140ustar00rootroot00000000000000// x node-browser-resolve-1.11.3/test/fixtures/node_modules/module-t/000077500000000000000000000000001331207452500247155ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/module-t/package.json000066400000000000000000000000601331207452500271770ustar00rootroot00000000000000{ "browser": { "./x": "./y" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/module-t/x.js000066400000000000000000000000041331207452500255140ustar00rootroot00000000000000// xnode-browser-resolve-1.11.3/test/fixtures/node_modules/module-t/y.js000066400000000000000000000000051331207452500255160ustar00rootroot00000000000000// y node-browser-resolve-1.11.3/test/fixtures/node_modules/override-engine-shim/000077500000000000000000000000001331207452500272075ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/override-engine-shim/index.js000066400000000000000000000000321331207452500306470ustar00rootroot00000000000000var URL = require("url"); node-browser-resolve-1.11.3/test/fixtures/node_modules/override-engine-shim/package.json000066400000000000000000000001271331207452500314750ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "url": "./url-browser.js" } } node-browser-resolve-1.11.3/test/fixtures/node_modules/override-engine-shim/url-browser.js000066400000000000000000000000111331207452500320200ustar00rootroot00000000000000// empty node-browser-resolve-1.11.3/test/fixtures/node_modules/toString/000077500000000000000000000000001331207452500250005ustar00rootroot00000000000000node-browser-resolve-1.11.3/test/fixtures/node_modules/toString/index.js000066400000000000000000000000111331207452500264350ustar00rootroot00000000000000// dummy node-browser-resolve-1.11.3/test/local-coffee.js000066400000000000000000000010471331207452500215200ustar00rootroot00000000000000var 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(); }); }); node-browser-resolve-1.11.3/test/local-sync.js000066400000000000000000000006101331207452500212400ustar00rootroot00000000000000var 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')); }); node-browser-resolve-1.11.3/test/local.js000066400000000000000000000007121331207452500202710ustar00rootroot00000000000000var 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(); }); }); node-browser-resolve-1.11.3/test/mocha.opts000066400000000000000000000000131331207452500206310ustar00rootroot00000000000000--ui qunit node-browser-resolve-1.11.3/test/modules-coffee.js000066400000000000000000000076041331207452500221030ustar00rootroot00000000000000var 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(); }); }); node-browser-resolve-1.11.3/test/modules-sync.js000066400000000000000000000136601331207452500216270ustar00rootroot00000000000000var 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')); }); node-browser-resolve-1.11.3/test/modules.js000066400000000000000000000267301331207452500206570ustar00rootroot00000000000000var 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, undefined); 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 ], package: { main: 'fixtures' } }, 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 ], package: { main: 'fixtures' } }, 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', package: { main: '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', package: { main: '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', package: { main: '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', package: { main: '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 ], package: { main: 'fixtures' } }, function(err, path, pkg) { assert.ifError(err); assert.equal(path, require.resolve('./fixtures/node_modules/toString/index')); assert.strictEqual(pkg, undefined); done(); }); });