Skip to content

Commit

Permalink
feat(storybook): change executors to use buildDev instead of standalo…
Browse files Browse the repository at this point in the history
…ne (#10385)
  • Loading branch information
mandarini committed May 19, 2022
1 parent 399f2ab commit 80b4439
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 44 deletions.
@@ -1,9 +1,9 @@
import { ExecutorContext, logger } from '@nrwl/devkit';
import { join } from 'path';
jest.mock('@storybook/core/standalone', () =>
jest.mock('@storybook/core-server/standalone', () =>
jest.fn().mockImplementation(() => Promise.resolve())
);
import * as storybook from '@storybook/core/standalone';
import * as storybook from '@storybook/core-server/standalone';
import storybookBuilder, {
StorybookBuilderOptions,
} from './build-storybook.impl';
Expand Down
@@ -1,5 +1,5 @@
import { ExecutorContext, logger } from '@nrwl/devkit';
import * as build from '@storybook/core/standalone';
import * as build from '@storybook/core-server/standalone';
import 'dotenv/config';
import { CommonNxStorybookConfig } from '../models';
import {
Expand Down
Expand Up @@ -4,9 +4,9 @@ import * as fs from 'fs';
import { ExecutorContext } from '@nrwl/devkit';

jest.mock('@storybook/core-server', () => ({
buildDevStandalone: jest.fn().mockImplementation(() => Promise.resolve()),
buildDev: jest.fn().mockImplementation(() => Promise.resolve()),
}));
import { buildDevStandalone } from '@storybook/core-server';
import { buildDev } from '@storybook/core-server';

import storybookExecutor, { StorybookExecutorOptions } from './storybook.impl';
import { join } from 'path';
Expand Down Expand Up @@ -89,6 +89,6 @@ describe('@nrwl/storybook:storybook', () => {
const iterator = storybookExecutor(options, context);
const { value } = await iterator.next();
expect(value).toEqual({ success: true });
expect(buildDevStandalone).toHaveBeenCalled();
expect(buildDev).toHaveBeenCalled();
});
});
42 changes: 4 additions & 38 deletions packages/storybook/src/executors/storybook/storybook.impl.ts
@@ -1,5 +1,5 @@
import { ExecutorContext, logger } from '@nrwl/devkit';
import { buildDevStandalone } from '@storybook/core-server';
import { ExecutorContext } from '@nrwl/devkit';
import { buildDev } from '@storybook/core-server';
import 'dotenv/config';
import { CommonNxStorybookConfig } from '../models';
import {
Expand Down Expand Up @@ -42,44 +42,10 @@ export default async function* storybookExecutor(
function runInstance(options: StorybookExecutorOptions) {
const env = process.env.NODE_ENV ?? 'development';
process.env.NODE_ENV = env;
return buildDevStandalone({
return buildDev({
...options,
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);
});
} as any);
}

function storybookOptionMapper(
Expand Down

0 comments on commit 80b4439

Please sign in to comment.