Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storybook): change executors to use buildDev instead of standalone #10385

Merged
merged 1 commit into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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