Skip to content

Commit

Permalink
Merge pull request #1427 from stealjs/map-envs
Browse files Browse the repository at this point in the history
Make envs map override configuration work
  • Loading branch information
matthewp authored Jun 18, 2018
2 parents 1145970 + 543205f commit 3e59bfb
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
9 changes: 8 additions & 1 deletion ext/npm-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,15 @@ exports.addExtension = function(System){
// Apply mappings, if they exist in the refPkg
var steal = utils.pkg.config(refPkg);
if (steal && steal.map && typeof steal.map[name] === "string") {
var mappedName = steal.map[name];
var envConfig = steal.envs && steal.envs[loader.env];

if(envConfig && envConfig.map && typeof envConfig.map[name] === "string") {
mappedName = envConfig.map[name];
}

return loader.normalize(
steal.map[name],
mappedName,
parentName,
parentAddress,
pluginNormalize
Expand Down
43 changes: 43 additions & 0 deletions test/npm/normalize_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,49 @@ QUnit.test("'map' configuration where the right-hand identifier is an npm packag
.then(done, helpers.fail(assert, done));
});

QUnit.test("'map' configuration with envs config", function(assert){
var done = assert.async();

var loader = helpers.clone()
.rootPackage({
name: "app",
main: "main.js",
version: "1.0.0",
dependencies: {
mapped: "1.0.0"
},
steal: {
map: {
dep: "one"
},
envs: {
test: {
map: {
dep: "two"
}
}
}
}
})
/*.withPackages([
{
name: "mapped",
main: "main.js",
version: "1.0.0"
}
])*/
.loader;

loader.env = "test";
helpers.init(loader).then(function(){
return loader.normalize("dep", "[email protected]#main");
})
.then(function(name){
assert.equal(name, "two");
})
.then(done, helpers.fail(assert, done));
});

QUnit.test("buildConfig that is late-loaded doesn't override outer config", function(assert){
var done = assert.async();

Expand Down

0 comments on commit 3e59bfb

Please sign in to comment.