pax_global_header00006660000000000000000000000064127213424110014507gustar00rootroot0000000000000052 comment=0955bafbb275d2ec1e425b2d776d4d619bd72282 node-browser-resolve-1.11.2/000077500000000000000000000000001272134241100156545ustar00rootroot00000000000000node-browser-resolve-1.11.2/.gitignore000066400000000000000000000000511272134241100176400ustar00rootroot00000000000000node_modules !test/fixtures/node_modules node-browser-resolve-1.11.2/.travis.yml000066400000000000000000000001221272134241100177600ustar00rootroot00000000000000language: node_js node_js: - "0.8" - "0.10" - "4" - "5" - "6" node-browser-resolve-1.11.2/LICENSE000066400000000000000000000021231272134241100166570ustar00rootroot00000000000000The 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.2/README.md000066400000000000000000000066541272134241100171460ustar00rootroot00000000000000# 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](https://gist.github.com/defunctzombie/4339901) field support. ## api ### resolve(id, opts={}, cb) Resolve a module path and call `cb(err, path [, pkg])` Options: * `filename` - the calling filename where the `require()` call originated (in the source) * `paths` - `require.paths` array to use if nothing is found on the normal `node_modules` recursive walk * `packageFilter` - transform the parsed `package.json` contents before looking at the `main` field * `modules` - object with module id/name -> path mappings to consult before doing manual resolution (use to provide core modules) * `browser` - the 'browser' property to use from package.json (defaults to 'browser') ### resolve.sync(id, opts={}) Same as the async resolve, just uses sync methods. ## 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.2/empty.js000066400000000000000000000000001272134241100173360ustar00rootroot00000000000000node-browser-resolve-1.11.2/example/000077500000000000000000000000001272134241100173075ustar00rootroot00000000000000node-browser-resolve-1.11.2/example/builtin.js000066400000000000000000000001431272134241100213110ustar00rootroot00000000000000var resolve = require('../'); resolve('fs', null, function(err, path) { console.log(path); }); node-browser-resolve-1.11.2/example/custom-chromeapp.js000066400000000000000000000002741272134241100231360ustar00rootroot00000000000000var 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.2/example/custom.js000066400000000000000000000002461272134241100211610ustar00rootroot00000000000000var resolve = require('../'); var parent = { filename: __dirname + '/custom/file.js' }; resolve('./main.js', parent, function(err, path) { console.log(path); }); node-browser-resolve-1.11.2/example/custom/000077500000000000000000000000001272134241100206215ustar00rootroot00000000000000node-browser-resolve-1.11.2/example/custom/custom-chromeapp.js000066400000000000000000000000421272134241100244410ustar00rootroot00000000000000console.log('chromeapp version'); node-browser-resolve-1.11.2/example/custom/custom.js000066400000000000000000000000401272134241100224630ustar00rootroot00000000000000console.log('browser version'); node-browser-resolve-1.11.2/example/custom/main.js000066400000000000000000000000371272134241100221030ustar00rootroot00000000000000console.log('server version'); node-browser-resolve-1.11.2/example/custom/package.json000066400000000000000000000002331272134241100231050ustar00rootroot00000000000000{ "name": "custom", "version": "0.0.0", "chromeapp": { "./main.js": "custom-chromeapp.js" }, "browser": { "./main.js": "custom.js" } } node-browser-resolve-1.11.2/example/resolve.js000066400000000000000000000001701272134241100213220ustar00rootroot00000000000000var resolve = require('../'); resolve('../', { filename: __filename }, function(err, path) { console.log(path); }); node-browser-resolve-1.11.2/example/skip.js000066400000000000000000000002361272134241100206140ustar00rootroot00000000000000var resolve = require('../'); var parent = { filename: __dirname + '/skip/main.js' }; resolve('tar', parent, function(err, path) { console.log(path); }); node-browser-resolve-1.11.2/example/skip/000077500000000000000000000000001272134241100202555ustar00rootroot00000000000000node-browser-resolve-1.11.2/example/skip/main.js000066400000000000000000000002121272134241100215320ustar00rootroot00000000000000var tar = require('tar'); exports.add = function (a, b) { return a + b; }; exports.parse = function () { return tar.Parse(); }; node-browser-resolve-1.11.2/example/skip/package.json000066400000000000000000000001201272134241100225340ustar00rootroot00000000000000{ "name": "skip", "version": "0.0.0", "browser": { "tar": false } } node-browser-resolve-1.11.2/index.js000066400000000000000000000221311272134241100173200ustar00rootroot00000000000000// 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 = __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); if (shims[id]) { // if the shim was is an absolute path, it was fully resolved if (shims[id][0] === '/') { return shims[id]; } // module -> alt-module shims id = shims[id]; } 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.2/package.json000066400000000000000000000011251272134241100201410ustar00rootroot00000000000000{ "name": "browser-resolve", "version": "1.11.2", "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.2/test/000077500000000000000000000000001272134241100166335ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/core-sync.js000066400000000000000000000005651272134241100211010ustar00rootroot00000000000000// 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.2/test/core.js000066400000000000000000000007721272134241100201270ustar00rootroot00000000000000// 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.2/test/ext.js000066400000000000000000000046571272134241100200050ustar00rootroot00000000000000var 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.2/test/false-sync.js000066400000000000000000000011431272134241100212340ustar00rootroot00000000000000var 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.2/test/false.js000066400000000000000000000020511272134241100202610ustar00rootroot00000000000000var 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.2/test/fixtures-coffee/000077500000000000000000000000001272134241100217315ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures-coffee/foo.coffee000066400000000000000000000000161272134241100236620ustar00rootroot00000000000000// blank file node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/000077500000000000000000000000001272134241100244065ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-a/000077500000000000000000000000001272134241100261115ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-a/index.coffee000066400000000000000000000000111272134241100303610ustar00rootroot00000000000000// dummy node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-b/000077500000000000000000000000001272134241100261125ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-b/main.coffee000066400000000000000000000000111272134241100301770ustar00rootroot00000000000000// entry node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-b/package.json000066400000000000000000000000401272134241100303720ustar00rootroot00000000000000{ "main": "./main.coffee" } node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-c/000077500000000000000000000000001272134241100261135ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-c/bar.coffee000066400000000000000000000000371272134241100300300ustar00rootroot00000000000000// required by browser.js only node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-c/browser.coffee000066400000000000000000000000501272134241100307420ustar00rootroot00000000000000// browser entry file require('./bar'); node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-c/main.coffee000066400000000000000000000000111272134241100302000ustar00rootroot00000000000000// entry node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-c/package.json000066400000000000000000000001031272134241100303730ustar00rootroot00000000000000{ "main": "./main.coffee", "browser": "./browser.coffee" } node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-d/000077500000000000000000000000001272134241100261145ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-d/browser.coffee000066400000000000000000000000261272134241100307460ustar00rootroot00000000000000// browser entry file node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-d/main.coffee000066400000000000000000000000111272134241100302010ustar00rootroot00000000000000// entry node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-d/package.json000066400000000000000000000001441272134241100304010ustar00rootroot00000000000000{ "main": "./main.coffee", "browser": { "./main.coffee": "./browser.coffee" } } node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-e/000077500000000000000000000000001272134241100261155ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-e/browser.coffee000066400000000000000000000000261272134241100307470ustar00rootroot00000000000000// browser entry file node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-e/foo.coffee000066400000000000000000000000211272134241100300420ustar00rootroot00000000000000// won't be used node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-e/main.coffee000066400000000000000000000000331272134241100302060ustar00rootroot00000000000000// entry require('./foo'); node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-e/package.json000066400000000000000000000001431272134241100304010ustar00rootroot00000000000000{ "main": "./main.coffee", "browser": { "./foo.coffee": "./browser.coffee" } } node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-f/000077500000000000000000000000001272134241100261165ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-f/lib/000077500000000000000000000000001272134241100266645ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-f/lib/browser.coffee000066400000000000000000000000261272134241100315160ustar00rootroot00000000000000// browser entry file node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-f/lib/foo.coffee000066400000000000000000000000211272134241100306110ustar00rootroot00000000000000// won't be used node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-f/lib/main.coffee000066400000000000000000000000331272134241100307550ustar00rootroot00000000000000// entry require('./foo'); node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-f/package.json000066400000000000000000000001571272134241100304070ustar00rootroot00000000000000{ "main": "./lib/main.coffee", "browser": { "./lib/foo.coffee": "./lib/browser.coffee" } } node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-g/000077500000000000000000000000001272134241100261175ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-g/foobar-browser.coffee000066400000000000000000000000221272134241100322130ustar00rootroot00000000000000// foobar browser node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-g/index.coffee000066400000000000000000000000231272134241100303720ustar00rootroot00000000000000require('foobar'); node-browser-resolve-1.11.2/test/fixtures-coffee/node_modules/module-g/package.json000066400000000000000000000001411272134241100304010ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "foobar": "./foobar-browser.coffee" } } node-browser-resolve-1.11.2/test/fixtures/000077500000000000000000000000001272134241100205045ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/foo.js000066400000000000000000000000161272134241100216220ustar00rootroot00000000000000// blank file node-browser-resolve-1.11.2/test/fixtures/node_modules/000077500000000000000000000000001272134241100231615ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/alt-browser-field/000077500000000000000000000000001272134241100265035ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/alt-browser-field/chromeapp-direct.js000066400000000000000000000000001272134241100322550ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/alt-browser-field/chromeapp.js000066400000000000000000000000001272134241100310050ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/alt-browser-field/direct.js000066400000000000000000000000231272134241100303060ustar00rootroot00000000000000// node empty file node-browser-resolve-1.11.2/test/fixtures/node_modules/alt-browser-field/foo.js000066400000000000000000000000241272134241100276200ustar00rootroot00000000000000 require('foobar'); node-browser-resolve-1.11.2/test/fixtures/node_modules/alt-browser-field/index.js000066400000000000000000000000321272134241100301430ustar00rootroot00000000000000var URL = require("url"); node-browser-resolve-1.11.2/test/fixtures/node_modules/alt-browser-field/package.json000066400000000000000000000004101272134241100307640ustar00rootroot00000000000000{ "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.2/test/fixtures/node_modules/alt-browser-field/url-browser.js000066400000000000000000000000111272134241100313140ustar00rootroot00000000000000// empty node-browser-resolve-1.11.2/test/fixtures/node_modules/alt-browser-field/url-chromeapp.js000066400000000000000000000000111272134241100316070ustar00rootroot00000000000000// empty node-browser-resolve-1.11.2/test/fixtures/node_modules/false/000077500000000000000000000000001272134241100242535ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/false/fake.js000066400000000000000000000000311272134241100255110ustar00rootroot00000000000000module.exports = 'fake'; node-browser-resolve-1.11.2/test/fixtures/node_modules/false/node_modules/000077500000000000000000000000001272134241100267305ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/false/node_modules/ignore-me/000077500000000000000000000000001272134241100306125ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/false/node_modules/ignore-me/index.js000066400000000000000000000000341272134241100322540ustar00rootroot00000000000000module.exports = 'failure'; node-browser-resolve-1.11.2/test/fixtures/node_modules/false/package.json000066400000000000000000000001531272134241100265400ustar00rootroot00000000000000{ "main": "./main.js", "browser": { "ignore-me": false, "./fake.js": false } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-a/000077500000000000000000000000001272134241100246645ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-a/index.js000066400000000000000000000000111272134241100263210ustar00rootroot00000000000000// dummy node-browser-resolve-1.11.2/test/fixtures/node_modules/module-b/000077500000000000000000000000001272134241100246655ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-b/main.js000066400000000000000000000000111272134241100261370ustar00rootroot00000000000000// entry node-browser-resolve-1.11.2/test/fixtures/node_modules/module-b/package.json000066400000000000000000000000341272134241100271500ustar00rootroot00000000000000{ "main": "./main.js" } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-c/000077500000000000000000000000001272134241100246665ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-c/bar.js000066400000000000000000000000371272134241100257700ustar00rootroot00000000000000// required by browser.js only node-browser-resolve-1.11.2/test/fixtures/node_modules/module-c/browser.js000066400000000000000000000000501272134241100267020ustar00rootroot00000000000000// browser entry file require('./bar'); node-browser-resolve-1.11.2/test/fixtures/node_modules/module-c/chromeapp.js000066400000000000000000000000521272134241100271770ustar00rootroot00000000000000// chromeapp entry file require('./foo'); node-browser-resolve-1.11.2/test/fixtures/node_modules/module-c/foo.js000066400000000000000000000000411272134241100260020ustar00rootroot00000000000000// required by chromeapp.js only node-browser-resolve-1.11.2/test/fixtures/node_modules/module-c/main.js000066400000000000000000000000111272134241100261400ustar00rootroot00000000000000// entry node-browser-resolve-1.11.2/test/fixtures/node_modules/module-c/package.json000066400000000000000000000001361272134241100271540ustar00rootroot00000000000000{ "main": "./main.js", "browser": "./browser.js", "chromeapp": "./chromeapp.js" } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-d/000077500000000000000000000000001272134241100246675ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-d/browser.js000066400000000000000000000000261272134241100267060ustar00rootroot00000000000000// browser entry file node-browser-resolve-1.11.2/test/fixtures/node_modules/module-d/main.js000066400000000000000000000000111272134241100261410ustar00rootroot00000000000000// entry node-browser-resolve-1.11.2/test/fixtures/node_modules/module-d/package.json000066400000000000000000000001301272134241100271470ustar00rootroot00000000000000{ "main": "./main.js", "browser": { "./main.js": "./browser.js" } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-e/000077500000000000000000000000001272134241100246705ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-e/browser.js000066400000000000000000000000261272134241100267070ustar00rootroot00000000000000// browser entry file node-browser-resolve-1.11.2/test/fixtures/node_modules/module-e/foo.js000066400000000000000000000000211272134241100260020ustar00rootroot00000000000000// won't be used node-browser-resolve-1.11.2/test/fixtures/node_modules/module-e/main.js000066400000000000000000000000331272134241100261460ustar00rootroot00000000000000// entry require('./foo'); node-browser-resolve-1.11.2/test/fixtures/node_modules/module-e/package.json000066400000000000000000000001271272134241100271560ustar00rootroot00000000000000{ "main": "./main.js", "browser": { "./foo.js": "./browser.js" } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-f/000077500000000000000000000000001272134241100246715ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-f/lib/000077500000000000000000000000001272134241100254375ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-f/lib/browser.js000066400000000000000000000000261272134241100274560ustar00rootroot00000000000000// browser entry file node-browser-resolve-1.11.2/test/fixtures/node_modules/module-f/lib/foo.js000066400000000000000000000000211272134241100265510ustar00rootroot00000000000000// won't be used node-browser-resolve-1.11.2/test/fixtures/node_modules/module-f/lib/main.js000066400000000000000000000000331272134241100267150ustar00rootroot00000000000000// entry require('./foo'); node-browser-resolve-1.11.2/test/fixtures/node_modules/module-f/package.json000066400000000000000000000001431272134241100271550ustar00rootroot00000000000000{ "main": "./lib/main.js", "browser": { "./lib/foo.js": "./lib/browser.js" } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-g/000077500000000000000000000000001272134241100246725ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-g/foobar-browser.js000066400000000000000000000000221272134241100301530ustar00rootroot00000000000000// foobar browser node-browser-resolve-1.11.2/test/fixtures/node_modules/module-g/index.js000066400000000000000000000000231272134241100263320ustar00rootroot00000000000000require('foobar'); node-browser-resolve-1.11.2/test/fixtures/node_modules/module-g/package.json000066400000000000000000000001351272134241100271570ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "foobar": "./foobar-browser.js" } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-h/000077500000000000000000000000001272134241100246735ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-h/index.js000066400000000000000000000000531272134241100263360ustar00rootroot00000000000000require('foobar'); require('querystring'); node-browser-resolve-1.11.2/test/fixtures/node_modules/module-h/package.json000066400000000000000000000003171272134241100271620ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "foobar": "module-b", "querystring": "module-c" }, "chromeapp": { "foobar": "module-b", "querystring": "module-c" } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-i/000077500000000000000000000000001272134241100246745ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-i/index.js000066400000000000000000000000531272134241100263370ustar00rootroot00000000000000require('foobar'); require('querystring'); node-browser-resolve-1.11.2/test/fixtures/node_modules/module-i/package.json000066400000000000000000000002601272134241100271600ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "foobar": "module-b", "querystring": "module-c" }, "browserify": { "transform": "deamdify" } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-j/000077500000000000000000000000001272134241100246755ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-j/index.js000066400000000000000000000000531272134241100263400ustar00rootroot00000000000000require('foobar'); require('querystring'); node-browser-resolve-1.11.2/test/fixtures/node_modules/module-j/package.json000066400000000000000000000002601272134241100271610ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "foobar": "module-i", "querystring": "module-c" }, "browserify": { "transform": "deamdify" } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-k/000077500000000000000000000000001272134241100246765ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-k/browser.js000066400000000000000000000000261272134241100267150ustar00rootroot00000000000000// browser entry file node-browser-resolve-1.11.2/test/fixtures/node_modules/module-k/index.js000066400000000000000000000000231272134241100263360ustar00rootroot00000000000000// node empty file node-browser-resolve-1.11.2/test/fixtures/node_modules/module-k/package.json000066400000000000000000000001301272134241100271560ustar00rootroot00000000000000{ "main": "index.js", "browser": { "./index.js": "./browser.js" } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-l/000077500000000000000000000000001272134241100246775ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-l/browser-direct.js000066400000000000000000000000001272134241100301560ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-l/browser.js000066400000000000000000000000261272134241100267160ustar00rootroot00000000000000// browser entry file node-browser-resolve-1.11.2/test/fixtures/node_modules/module-l/index.js000066400000000000000000000000231272134241100263370ustar00rootroot00000000000000// node empty file node-browser-resolve-1.11.2/test/fixtures/node_modules/module-l/package.json000066400000000000000000000002031272134241100271600ustar00rootroot00000000000000{ "main": "index.js", "browser": { "./index.js": "./browser.js", "./direct": "./browser-direct.js" } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-m/000077500000000000000000000000001272134241100247005ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-m/lib/000077500000000000000000000000001272134241100254465ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-m/lib/hide.js000066400000000000000000000000001272134241100267030ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-m/lib/index.js000066400000000000000000000000001272134241100271010ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-m/package.json000066400000000000000000000000721272134241100271650ustar00rootroot00000000000000{ "browser": { "./lib/hide.js": false } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-n/000077500000000000000000000000001272134241100247015ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-n/browser-bar.json000066400000000000000000000000021272134241100300110ustar00rootroot00000000000000{}node-browser-resolve-1.11.2/test/fixtures/node_modules/module-n/browser-foo.js000066400000000000000000000000121272134241100274740ustar00rootroot00000000000000// browsernode-browser-resolve-1.11.2/test/fixtures/node_modules/module-n/index.js000066400000000000000000000000101272134241100263350ustar00rootroot00000000000000// main node-browser-resolve-1.11.2/test/fixtures/node_modules/module-n/package.json000066400000000000000000000002101272134241100271600ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "./foo.js": "./browser-foo.js", "./bar.json": "./browser-bar.json" } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-o/000077500000000000000000000000001272134241100247025ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-o/main.js000066400000000000000000000000111272134241100261540ustar00rootroot00000000000000// entry node-browser-resolve-1.11.2/test/fixtures/node_modules/module-o/package.json000066400000000000000000000000651272134241100271710ustar00rootroot00000000000000{ "browser": { "module-a": "./x" } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-o/x.js000066400000000000000000000000051272134241100255020ustar00rootroot00000000000000// x node-browser-resolve-1.11.2/test/fixtures/node_modules/module-p/000077500000000000000000000000001272134241100247035ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-p/package.json000066400000000000000000000000601272134241100271650ustar00rootroot00000000000000{ "browser": { "./z": "./x" } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-p/x.js000066400000000000000000000000051272134241100255030ustar00rootroot00000000000000// x node-browser-resolve-1.11.2/test/fixtures/node_modules/module-q/000077500000000000000000000000001272134241100247045ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-q/package.json000066400000000000000000000000661272134241100271740ustar00rootroot00000000000000{ "browser": { "./z.js": "./x.js" } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-q/x.js000066400000000000000000000000051272134241100255040ustar00rootroot00000000000000// x node-browser-resolve-1.11.2/test/fixtures/node_modules/module-r/000077500000000000000000000000001272134241100247055ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-r/package.json000066400000000000000000000000631272134241100271720ustar00rootroot00000000000000{ "browser": { "./z": "./x.js" } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-r/x.js000066400000000000000000000000051272134241100255050ustar00rootroot00000000000000// x node-browser-resolve-1.11.2/test/fixtures/node_modules/module-s/000077500000000000000000000000001272134241100247065ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/module-s/package.json000066400000000000000000000000721272134241100271730ustar00rootroot00000000000000{ "browser": { "whatever/z": "./x.js" } } node-browser-resolve-1.11.2/test/fixtures/node_modules/module-s/x.js000066400000000000000000000000051272134241100255060ustar00rootroot00000000000000// x node-browser-resolve-1.11.2/test/fixtures/node_modules/override-engine-shim/000077500000000000000000000000001272134241100272015ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/override-engine-shim/index.js000066400000000000000000000000321272134241100306410ustar00rootroot00000000000000var URL = require("url"); node-browser-resolve-1.11.2/test/fixtures/node_modules/override-engine-shim/package.json000066400000000000000000000001271272134241100314670ustar00rootroot00000000000000{ "main": "./index.js", "browser": { "url": "./url-browser.js" } } node-browser-resolve-1.11.2/test/fixtures/node_modules/override-engine-shim/url-browser.js000066400000000000000000000000111272134241100320120ustar00rootroot00000000000000// empty node-browser-resolve-1.11.2/test/fixtures/node_modules/toString/000077500000000000000000000000001272134241100247725ustar00rootroot00000000000000node-browser-resolve-1.11.2/test/fixtures/node_modules/toString/index.js000066400000000000000000000000111272134241100264270ustar00rootroot00000000000000// dummy node-browser-resolve-1.11.2/test/local-coffee.js000066400000000000000000000010471272134241100215120ustar00rootroot00000000000000var 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.2/test/local-sync.js000066400000000000000000000006101272134241100212320ustar00rootroot00000000000000var 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.2/test/local.js000066400000000000000000000007121272134241100202630ustar00rootroot00000000000000var 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.2/test/mocha.opts000066400000000000000000000000131272134241100206230ustar00rootroot00000000000000--ui qunit node-browser-resolve-1.11.2/test/modules-coffee.js000066400000000000000000000076041272134241100220750ustar00rootroot00000000000000var 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.2/test/modules-sync.js000066400000000000000000000130471272134241100216200ustar00rootroot00000000000000var 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')); }); // 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.2/test/modules.js000066400000000000000000000260101272134241100206400ustar00rootroot00000000000000var 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(); }); }); 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(); }); });