browser-resolve
Advanced tools
Comparing version 0.0.1 to 0.0.2
22
index.js
@@ -46,5 +46,7 @@ // builtin | ||
// identify if our file should be replaced per the browser field | ||
var shims; | ||
// original filename -> replacement | ||
var shims = {}; | ||
for (var i=0 ; i<paths.length ; ++i) { | ||
var pkg_path = path.join(paths[i], 'package.json'); | ||
var cur_path = paths[i]; | ||
var pkg_path = path.join(cur_path, 'package.json'); | ||
@@ -57,2 +59,3 @@ if (!fs.existsSync(pkg_path)) { | ||
// no replacements, skip making shims | ||
if (!info.browser) { | ||
@@ -62,6 +65,13 @@ break; | ||
var shims = {}; | ||
// if browser field is a string | ||
// then it just replaces the main entry point | ||
if (typeof info.browser === 'string') { | ||
var key = path.resolve(cur_path, info.main || 'index.js'); | ||
shims[key] = path.resolve(cur_path, info.browser); | ||
break; | ||
} | ||
Object.keys(info.browser).forEach(function(key) { | ||
var val = path.resolve(paths[i], info.browser[key]); | ||
var key = path.resolve(paths[i], key); | ||
var val = path.resolve(cur_path, info.browser[key]); | ||
var key = path.resolve(cur_path, key); | ||
shims[key] = val; | ||
@@ -78,2 +88,4 @@ }); | ||
packageFilter: function(info) { | ||
if (parent.packageFilter) info = parent.packageFilter(info); | ||
// no browser field, keep info unchanged | ||
@@ -80,0 +92,0 @@ if (!info.browser) { |
{ | ||
"name": "browser-resolve", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "resolve which handles browser field support in package.json", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -1,2 +0,2 @@ | ||
# browser-resolve | ||
# browser-resolve [![Build Status](https://travis-ci.org/shtylman/node-browser-resolve.png?branch=master)](https://travis-ci.org/shtylman/node-browser-resolve) | ||
@@ -3,0 +3,0 @@ node.js resolve algorithm with [browser](https://gist.github.com/shtylman/4339901) field support. |
@@ -33,2 +33,16 @@ var assert = require('assert'); | ||
// 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' ] | ||
}; | ||
resolve('./bar', parent, function(err, path) { | ||
assert.ifError(err); | ||
assert.equal(path, require.resolve('./fixtures/node_modules/module-c/bar')); | ||
done(); | ||
}); | ||
}); | ||
// package.json has browser field as object | ||
@@ -35,0 +49,0 @@ // one of the keys replaces the main file |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72691
28
2131