Skip to content

Commit

Permalink
Allow outputs[name].dest to be overridden with a function even if opt…
Browse files Browse the repository at this point in the history
…ing in to other helpers. e.g. (+cjs) Resolves #683
  • Loading branch information
Alfredo-Delgado committed Apr 27, 2017
1 parent 5782d89 commit d946d68
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 20 deletions.
47 changes: 27 additions & 20 deletions lib/build/helpers/base.js
Expand Up @@ -82,30 +82,37 @@ var baseHelper = {
}
return path;
},
makeDest: function(distFolder){
return function(aliases, distPath){
if(typeof aliases === "string") {
makeDest: function(distFolder) {
return function(aliases, distPath) {
aliases = aliases || {};

if (typeof aliases === "string") {
distPath = aliases;
aliases = {};
}
aliases = aliases || {};
return function(moduleName, moduleData, load, System){
var baseRoot = distPath || path.join( baseHelper.removeFileProtocol(System.baseURL), distFolder);

if(aliases[moduleName]) {
return path.join(baseRoot, aliases[moduleName]);
}

if(npmUtils.moduleName.isNpm(moduleName)) {
moduleName = npmUtils.moduleName.parse(moduleName).modulePath;
}

// move it to lib/cjs and rename it
var address = path.dirname(baseHelper.cleanModuleName(moduleName));
var basename = baseHelper.basename(load);

return path.join(baseRoot, address, basename);
};
if (typeof aliases === "function") {
return aliases;
}
else {
return function(moduleName, moduleData, load, System){
var baseRoot = distPath || path.join( baseHelper.removeFileProtocol(System.baseURL), distFolder);

if(aliases[moduleName]) {
return path.join(baseRoot, aliases[moduleName]);
}

if(npmUtils.moduleName.isNpm(moduleName)) {
moduleName = npmUtils.moduleName.parse(moduleName).modulePath;
}

// move it to lib/cjs and rename it
var address = path.dirname(baseHelper.cleanModuleName(moduleName));
var basename = baseHelper.basename(load);

return path.join(baseRoot, address, basename);
};
}
};
},
normalizeEndingSlash: function(moduleName) {
Expand Down
60 changes: 60 additions & 0 deletions test/export_test.js
Expand Up @@ -158,6 +158,66 @@ describe("export", function(){
}, done);
});

it("passes the load objects to normalize and dest (+cjs)", function(done) {
var destCalls = 0;

stealExport({

steal: {
main: "pluginifier_builder_load/main",
config: __dirname + "/stealconfig.js"
},
options: {
quiet: true
},
"outputs": {
"+cjs": {
graphs: ["pluginifier_builder_load/main"],
useNormalizedDependencies: false,
format: "cjs",
normalize: function(name, load, curName, curLoad, loader) {
assert.equal(name, "./bar");
assert.equal(load.name, "pluginifier_builder_load/bar");
assert.equal(curName, "pluginifier_builder_load/main");
assert.equal(curLoad.name, "pluginifier_builder_load/main");
assert.equal(loader.main, "pluginifier_builder_load/main");
return name;
},
ignore: function(moduleName, load){
switch(destCalls++) {
case 0:
assert.equal(load.name, "pluginifier_builder_load/main");
break;
case 2:
assert.equal(load.name, "pluginifier_builder_load/bar");
return true;
break;
default:
assert.ok(false, "should not be called "+moduleName+"."+destCalls);
break;
}
},
dest: function(moduleName, moduleData, load){
switch(destCalls++) {
case 1:
assert.equal(load.name, "pluginifier_builder_load/main");
break;
default:
assert.ok(false, "should not be called "+moduleName+"."+destCalls);
break;
}
return __dirname+"/out/"+moduleName+".js"
},
minify: false
}
}
}).then(function(err){

done();

}, done);
});

it("evaled globals do not have exports in their scope (#440)", function(done){

stealExport({
Expand Down

0 comments on commit d946d68

Please sign in to comment.