Skip to content

Commit

Permalink
Apply mappings when left-side is not a pkg but right-side is.
Browse files Browse the repository at this point in the history
Closes #1208
  • Loading branch information
Manuel Mujica committed Sep 18, 2017
1 parent c61222b commit d548dd8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
4 changes: 4 additions & 0 deletions ext/npm-convert.js
Expand Up @@ -122,6 +122,10 @@ function convertPropertyNamesAndValues (context, pkg, map, root, waiting) {
if(typeof name !== 'undefined' && typeof val !== 'undefined') {
clone[name] = val;
}
// keep map entry if the key isn't a package but value might
if (name && typeof val === "undefined") {
clone[name] = map[property];
}
}
return clone;
}
Expand Down
37 changes: 26 additions & 11 deletions ext/npm-extension.js
Expand Up @@ -214,8 +214,24 @@ exports.addExtension = function(System){
return oldNormalize.call(this, refPkg.browser[name], parentName,
parentAddress, pluginNormalize);
}
return oldNormalize.call(this, name, parentName, parentAddress,
pluginNormalize);
// Apply mappings, if they exist in the refPkg
var steal = utils.pkg.config(refPkg);
if (steal && steal.map && typeof steal.map[name] === "string") {
return loader.normalize(
steal.map[name],
parentName,
parentAddress,
pluginNormalize
);
} else {
return oldNormalize.call(
this,
name,
parentName,
parentAddress,
pluginNormalize
);
}
}
return crawl.dep(this.npmContext, parentPkg, refPkg, depPkg, isRoot)
.then(createModuleNameAndNormalize);
Expand All @@ -229,15 +245,14 @@ exports.addExtension = function(System){
if(!parsedModuleName.modulePath) {
parsedModuleName.modulePath = utils.pkg.main(depPkg);
}
var moduleName = utils.moduleName.create(parsedModuleName);
// Apply mappings, if they exist in the refPkg
var steal = utils.pkg.config(refPkg);
if(steal && steal.map &&
typeof steal.map[moduleName] === "string") {
moduleName = steal.map[moduleName];
}
var p = oldNormalize.call(loader, moduleName, parentName,
parentAddress, pluginNormalize);

var p = oldNormalize.call(
loader,
utils.moduleName.create(parsedModuleName),
parentName,
parentAddress,
pluginNormalize
);

// For identifiers like ./lib/ save this info as we might
// get a 404 and need to retry with lib/index.js
Expand Down
2 changes: 1 addition & 1 deletion test/npm/normalize_test.js
Expand Up @@ -841,7 +841,7 @@ QUnit.test("descriptive version mismatch error (#1176)", function(assert) {
.then(done, helpers.fail(assert, done));
});

QUnit.skip("'map' configuration where the right-hand identifier is an npm package but the left is not", function(assert){
QUnit.test("'map' configuration where the right-hand identifier is an npm package but the left is not", function(assert){
var done = assert.async();

var loader = helpers.clone()
Expand Down

0 comments on commit d548dd8

Please sign in to comment.