Skip to content

Commit

Permalink
Merge pull request #354 from vincentngthu/master
Browse files Browse the repository at this point in the history
Handle err before any logic in promise return by compileTemplate
  • Loading branch information
jantimon committed Jun 15, 2016
2 parents fa25bd7 + 4e6f902 commit 943c555
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,6 @@ module.exports.compileTemplate = function compileTemplate (template, context, ou
// Compile and return a promise
return new Promise(function (resolve, reject) {
childCompiler.runAsChild(function (err, entries, childCompilation) {
// Replace [hash] placeholders in filename
var outputName = compilation.mainTemplate.applyPluginsWaterfall('asset-path', outputOptions.filename, {
hash: childCompilation.hash,
chunk: entries[0]
});
// Restore the parent compilation to the state like it
// was before the child compilation
compilation.assets[outputName] = assetsBeforeCompilation[outputName];
if (assetsBeforeCompilation[outputName] === undefined) {
// If it wasn't there - delete it
delete compilation.assets[outputName];
}
// Resolve / reject the promise
if (childCompilation && childCompilation.errors && childCompilation.errors.length) {
var errorDetails = childCompilation.errors.map(function (error) {
Expand All @@ -89,6 +77,18 @@ module.exports.compileTemplate = function compileTemplate (template, context, ou
} else if (err) {
reject(err);
} else {
// Replace [hash] placeholders in filename
var outputName = compilation.mainTemplate.applyPluginsWaterfall('asset-path', outputOptions.filename, {
hash: childCompilation.hash,
chunk: entries[0]
});
// Restore the parent compilation to the state like it
// was before the child compilation
compilation.assets[outputName] = assetsBeforeCompilation[outputName];
if (assetsBeforeCompilation[outputName] === undefined) {
// If it wasn't there - delete it
delete compilation.assets[outputName];
}
resolve({
// Hash of the template entry point
hash: entries[0].hash,
Expand Down

0 comments on commit 943c555

Please sign in to comment.