Skip to content

Commit

Permalink
Merge pull request #1149 from stealjs/fix-exports
Browse files Browse the repository at this point in the history
Fix race condition where last format transform overrides previous ones
  • Loading branch information
m-mujica authored Nov 25, 2019
2 parents 019df7f + 18259e5 commit ac5e46e
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 23 deletions.
41 changes: 20 additions & 21 deletions lib/build/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,31 +143,33 @@ var transformImport = function(config, transformOptions){
winston.debug("+ %s", node.load.name);
});

return Promise.resolve()
.then(function(){
return new Promise(function(resolve, reject) {
var concatOptions = {
excludePlugins: options.format === "global",
sourceProp: "activeSource",
format: options.concatFormat,
removeDevelopmentCode: options.removeDevelopmentCode
};
return concatSource(bundle, concatOptions);
})
.then(function(){
if(options.sourceMaps) {
addSourceMapUrl(bundle);
}

return bundle;
})
.then(function(bundle) {
// #### minify
if(options.minify) {
winston.debug('Minifying...');
return minify(bundle);
} else {
return bundle.source;
}
return concatSource(bundle, concatOptions)
.then(function(){
if(options.sourceMaps) {
addSourceMapUrl(bundle);
}

return bundle;
})
.then(function(bundle) {
// #### minify
if(options.minify) {
winston.debug('Minifying...');
return minify(bundle);
} else {
return bundle.source;
}
})
.then(resolve)
.catch(reject);
});
};

Expand All @@ -176,10 +178,7 @@ var transformImport = function(config, transformOptions){
transform.loader = data.loader;
transform.data = data;
return transform;


});

};


Expand Down
47 changes: 46 additions & 1 deletion test/export_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ describe("export", function(){

}, done);

}, done);
}, done)
.catch(done);
});

it("works with multiple mains", function(done) {
Expand Down Expand Up @@ -338,6 +339,50 @@ describe("export", function(){
});
});

it("does not override previous outputs #1139", function(done) {
let exportOptions = {
steal: {
main: "pluginifier_builder/pluginify",
config: __dirname + "/stealconfig.js"
},
options: {
quiet: true
},
outputs: {
"+cjs": {},
"+amd": {}
}
};

stealExport(exportOptions)
.then(function() {
let distPath = format =>
path.join(
__dirname,
"dist",
format,
"pluginifier_builder",
"pluginify.js"
);

// check cjs module was written out correctly
assert(fs.pathExistsSync(distPath("cjs")));

let cjs = fs.readFileSync(distPath("cjs")).toString();
assert(/require\(/.test(cjs), "code should be valid cjs");
assert(!/define/.test(cjs), "code should be valid cjs");

// check amd module was written out correctly
assert(fs.pathExistsSync(distPath("amd")));

let amd = fs.readFileSync(distPath("amd")).toString();
assert(/define/.test(amd), "code should be valid amd");
assert(!/require\(/.test(amd), "code should be valid amd");
})
.then(done)
.catch(done);
});

describe("eachModule", function(){
it("works", function(done){
stealExport({
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ require("./slim_loader_size_test");

// external steal-tools plugins
require("./bundle_assets_test");
//require("./serviceworker_test"); skip for now
//require("./serviceworker_test"); skip for now

0 comments on commit ac5e46e

Please sign in to comment.