Skip to content

Commit

Permalink
Proper error handling for bundle task
Browse files Browse the repository at this point in the history
* Add error handling for the theme's build task. Previously,
  if an error occurred in the theme's build task (such as Cornerstone's
  webpack build), we swallow the error and proceed. Additionally,
  if the task timeout out (took longer than 5 seconds, we'd swallow the
  error and continue, leading to incomplete bundles.
  • Loading branch information
mattolson committed Oct 2, 2018
1 parent 41cd0a6 commit a4dc6c9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
The BigCommerce server emulator for local theme development.

## Install
_Note: Stencil requires the Node.js runtime environment, version 6.x or later. We have tested Stencil on selected Node.js versions, from 6.10.3 to 7.9.0_
_Note: Stencil requires the Node.js runtime environment, version 6.x or later. We have tested Stencil on selected Node.js versions, from 6.10.3 to 8.12.0_

Run `npm install -g @bigcommerce/stencil-cli`.

Expand Down
11 changes: 7 additions & 4 deletions lib/build-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function devWorker(browserSync) {
if (!worker) {
return;
}
// send a message to the worker to start watching
// send a message to the worker to start watching
// and wait for message to reload the browser
worker.send('development');
worker.on('message', message => {
Expand All @@ -70,10 +70,13 @@ function prodWorker(done) {
const callback = _.once(done);

if (!worker) {
return process.nextTick(() => callback('noworker'));
return process.nextTick(() => callback('worker initialization failed'));
}

const timeout = setTimeout(() => callback('timeout'), 5000);
const timeout = setTimeout(() => {
worker.kill();
callback('worker timed out');
}, 20000);

onWorkerReady(() => {
clearTimeout(timeout);
Expand All @@ -87,5 +90,5 @@ function prodWorker(done) {
});
});

worker.on('close', () => callback('noworker'));
worker.on('close', () => callback('worker terminated'));
}
2 changes: 1 addition & 1 deletion lib/build-config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('stencilBuildConfig', () => {

expect(buildConfig.production).to.be.a.function();
buildConfig.initWorker().production(message => {
expect(message).to.equal('noworker');
expect(message).to.equal('worker terminated');
done();
});
});
Expand Down
7 changes: 5 additions & 2 deletions lib/stencil-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@ function Bundle(themePath, themeConfig, rawConfig, options) {
if (typeof buildConfig.production === 'function') {
tasks.theme = callback => {
console.log('Theme task Started...');
buildConfig.initWorker().production(() => {
buildConfig.initWorker().production(err => {
if (err) {
return callback(err);
}

console.log('ok'.green + ' -- Theme task Finished');
callback();
});
Expand Down Expand Up @@ -284,7 +288,6 @@ function bundleTaskRunner(callback) {
defaultName = 'Theme.zip';
}


Async.parallel(this.tasks, (err, taskResults) => {
if (err) {
return callback(err);
Expand Down

0 comments on commit a4dc6c9

Please sign in to comment.