Skip to content

Commit

Permalink
Fix a bug where the standalone static build Promise is resolved befor…
Browse files Browse the repository at this point in the history
…e it actually completes
  • Loading branch information
transitive-bullshit committed Nov 4, 2018
1 parent edcff0e commit b39e0b2
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions lib/core/src/server/build-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,30 @@ export async function buildStaticStandalone(options) {
}

// compile all resources with webpack and write them to the disk.
logger.info('Building storybook ...');
const webpackCb = (err, stats) => {
if (err || stats.hasErrors()) {
logger.error('Failed to build the storybook');
// eslint-disable-next-line no-unused-expressions
err && logger.error(err.message);
// eslint-disable-next-line no-unused-expressions
stats && stats.hasErrors() && stats.toJson().errors.forEach(e => logger.error(e));
process.exitCode = 1;
}
logger.info('Building storybook completed.');
};
return new Promise((resolve, reject) => {
const webpackCb = (err, stats) => {
if (err || stats.hasErrors()) {
logger.error('Failed to build the storybook');
// eslint-disable-next-line no-unused-expressions
err && logger.error(err.message);
// eslint-disable-next-line no-unused-expressions
stats && stats.hasErrors() && stats.toJson().errors.forEach(e => logger.error(e));
process.exitCode = 1;
return reject(err);
}
logger.info('Building storybook completed.');
return resolve(stats);
};

const compiler = webpack(config);
logger.info('Building storybook ...');
const compiler = webpack(config);

if (watch) {
compiler.watch({}, webpackCb);
} else {
compiler.run(webpackCb);
}
if (watch) {
compiler.watch({}, webpackCb);
} else {
compiler.run(webpackCb);
}
});
}

export async function buildStatic({ packageJson, ...loadOptions }) {
Expand Down

0 comments on commit b39e0b2

Please sign in to comment.