Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow outputs[name].dest to be overridden with a function even if opt… #686

Merged
merged 1 commit into from
May 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
47 changes: 27 additions & 20 deletions lib/build/helpers/base.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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