Skip to content

Commit ea95d5c

Browse files
committed
fix pathFilter for alt browser field
1 parent 075c823 commit ea95d5c

File tree

6 files changed

+25
-9
lines changed

6 files changed

+25
-9
lines changed

index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,17 @@ function build_resolve_opts(opts, base) {
180180
if(mappedPath) {
181181
return mappedPath;
182182
}
183-
if(!info.browser) {
183+
184+
var replacements = info[browser];
185+
if(!replacements) {
184186
return;
185187
}
186188

187-
if(typeof info.browser) {
188-
mappedPath = info.browser[relativePath];
189-
if(!mappedPath && (relativePath.lastIndexOf(".js") === relativePath.length-3) ) {
190-
mappedPath = info.browser[relativePath+".js"];
191-
}
192-
return mappedPath;
193-
}
189+
mappedPath = replacements[relativePath];
190+
if(!mappedPath && (relativePath.lastIndexOf(".js") === relativePath.length-3) ) {
191+
mappedPath = replacements[relativePath+".js"];
192+
}
193+
return mappedPath;
194194
};
195195

196196
return opts;

test/fixtures/node_modules/alt-browser-field/chromeapp-direct.js

Whitespace-only changes.

test/fixtures/node_modules/alt-browser-field/chromeapp.js

Whitespace-only changes.

test/fixtures/node_modules/alt-browser-field/direct.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/fixtures/node_modules/alt-browser-field/package.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/modules.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,16 @@ test('alt-browser field', function(done) {
250250
done();
251251
});
252252
});
253+
254+
test('alt-browser deep module reference mapping', function(done) {
255+
resolve('alt-browser-field/direct', {
256+
basedir: __dirname + '/fixtures',
257+
package: { main: 'fixtures' },
258+
browser: 'chromeapp'
259+
}, function(err, path, pkg) {
260+
assert.ifError(err);
261+
assert.equal(path, require.resolve('./fixtures/node_modules/alt-browser-field/chromeapp-direct'));
262+
assert.equal(pkg.main, './chromeapp.js');
263+
done();
264+
});
265+
});

0 commit comments

Comments
 (0)