Skip to content

Commit

Permalink
πŸ—πŸ› Don't cancel watch if an edit causes a compilation error (redux) (…
Browse files Browse the repository at this point in the history
  • Loading branch information
rsimha authored Jun 26, 2019
1 parent 1269f2d commit 3277d1e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
18 changes: 12 additions & 6 deletions build-system/tasks/extension-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,22 +356,28 @@ function buildExtension(
if (options.compileOnlyCss && !hasCss) {
return Promise.resolve();
}
const path = 'extensions/' + name + '/' + version;

// Use a separate watcher for extensions to copy / inline CSS and compile JS
// instead of relying on the watcher used by compileUnminifiedJs, which only
// recompiles JS.
const path = 'extensions/' + name + '/' + version;
const optionsCopy = Object.create(options);
if (options.watch) {
optionsCopy.watch = false;
options.watch = false;
watch(path + '/*', function() {
buildExtension(name, version, latestVersion, hasCss, optionsCopy);
buildExtension(
name,
version,
latestVersion,
hasCss,
Object.assign({}, options, {continueOnError: true})
);
});
}
const promises = [];
if (hasCss) {
mkdirSync('build');
mkdirSync('build/css');
const buildCssPromise = buildExtensionCss(path, name, version, optionsCopy);
const buildCssPromise = buildExtensionCss(path, name, version, options);
if (options.compileOnlyCss) {
return buildCssPromise;
}
Expand All @@ -388,7 +394,7 @@ function buildExtension(
if (argv.single_pass) {
return Promise.resolve();
} else {
return buildExtensionJs(path, name, version, latestVersion, optionsCopy);
return buildExtensionJs(path, name, version, latestVersion, options);
}
});
}
Expand Down
23 changes: 11 additions & 12 deletions build-system/tasks/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,21 +370,20 @@ function compileMinifiedJs(srcDir, srcFilename, destDir, options) {
/**
* Handles a browserify bundling error
* @param {Error} err
* @param {boolean} failOnError
* @param {string} srcFilename
* @param {string} startTime
* @param {boolean} continueOnError
* @param {string} destFilename
*/
function handleBundleError(err, failOnError, srcFilename, startTime) {
function handleBundleError(err, continueOnError, destFilename) {
let message = err;
if (err.stack) {
// Drop the node_modules call stack, which begins with ' at'.
message = err.stack.replace(/ at[^]*/, '').trim();
}
console.error(red(message));
if (failOnError) {
process.exit(1);
if (continueOnError) {
log('Error while compiling', cyan(destFilename));
} else {
endBuildStep('Error while compiling', srcFilename, startTime);
process.exit(1);
}
}

Expand Down Expand Up @@ -452,21 +451,21 @@ function compileUnminifiedJs(srcDir, srcFilename, destDir, options) {

if (options.watch) {
bundler = watchify(bundler);
bundler.on('update', () => performBundle(/* failOnError */ false));
bundler.on('update', () => performBundle(/* continueOnError */ true));
}

/**
* @param {boolean} failOnError
* @param {boolean} continueOnError
* @return {Promise}
*/
function performBundle(failOnError) {
function performBundle(continueOnError) {
let startTime;
return toPromise(
bundler
.bundle()
.once('readable', () => (startTime = Date.now()))
.on('error', err =>
handleBundleError(err, failOnError, srcFilename, startTime)
handleBundleError(err, continueOnError, destFilename)
)
.pipe(source(srcFilename))
.pipe(buffer())
Expand Down Expand Up @@ -501,7 +500,7 @@ function compileUnminifiedJs(srcDir, srcFilename, destDir, options) {
});
}

return performBundle(/* failOnError */ true);
return performBundle(options.continueOnError);
}

/**
Expand Down

0 comments on commit 3277d1e

Please sign in to comment.