Skip to content

Commit

Permalink
fix(storybook): make sure compilation errors get logged to the console (
Browse files Browse the repository at this point in the history
  • Loading branch information
juristr committed Jun 25, 2021
1 parent 2ba13db commit ea0c6a3
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions packages/storybook/src/executors/storybook/storybook.impl.ts
Expand Up @@ -5,7 +5,7 @@ import { constants, copyFileSync, mkdtempSync, statSync } from 'fs';
import { buildDevStandalone } from '@storybook/core/server';

import { getStorybookFrameworkPath, setStorybookAppProject } from '../utils';
import { ExecutorContext } from '@nrwl/devkit';
import { ExecutorContext, logger } from '@nrwl/devkit';

export interface StorybookConfig {
configFolder?: string;
Expand Down Expand Up @@ -50,8 +50,47 @@ export default async function* storybookExecutor(
}

function runInstance(options: StorybookExecutorOptions) {
process.env.NODE_ENV = process.env.NODE_ENV ?? 'development';
return buildDevStandalone({ ...options, ci: true } as any);
const env = process.env.NODE_ENV ?? 'development';
process.env.NODE_ENV = env;
return buildDevStandalone({
...options,
ci: true,
configType: env.toUpperCase(),
} as any).catch((error) => {
// TODO(juri): find a better cleaner way to handle these. Taken from:
// https://github.com/storybookjs/storybook/blob/dea23e5e9a3e7f5bb25cb6520d3011cc710796c8/lib/core-server/src/build-dev.ts#L138-L166
if (error instanceof Error) {
if ((error as any).error) {
logger.error((error as any).error);
} else if (
(error as any).stats &&
(error as any).stats.compilation.errors
) {
(error as any).stats.compilation.errors.forEach((e: any) =>
logger.log(e)
);
} else {
logger.error(error as any);
}
} else if (error.compilation?.errors) {
error.compilation.errors.forEach((e: any) => logger.log(e));
}

logger.log('');
logger.warn(
error.close
? `
FATAL broken build!, will close the process,
Fix the error below and restart storybook.
`
: `
Broken build, fix the error above.
You may need to refresh the browser.
`
);

process.exit(1);
});
}

function storybookOptionMapper(
Expand Down

0 comments on commit ea0c6a3

Please sign in to comment.