Skip to content

Commit

Permalink
fix(storybook): install core-js for non-vite libs
Browse files Browse the repository at this point in the history
closed #18109
  • Loading branch information
mandarini committed Jul 14, 2023
1 parent e657de8 commit 6d8f6d6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,16 @@ export async function storybookConfigurationGenerator(
typeof import('@nx/storybook')
>('@nx/storybook', nxVersion);

let bundler = 'vite';
let uiFramework = '@storybook/react-vite';
const projectConfig = readProjectConfiguration(host, schema.name);

if (
projectConfig.projectType === 'application' &&
(projectConfig.targets['build']?.executor === '@nx/webpack:webpack' ||
projectConfig.targets['build']?.executor === '@nrwl/webpack:webpack')
projectConfig.targets['build']?.executor === '@nx/webpack:webpack' ||
projectConfig.targets['build']?.executor === '@nrwl/webpack:webpack' ||
projectConfig.targets['build']?.executor === '@nx/rollup:rollup' ||
projectConfig.targets['build']?.executor === '@nrwl/rollup:rollup'
) {
bundler = 'webpack';
uiFramework = '@storybook/react-webpack5';
}

const installTask = await configurationGenerator(host, {
Expand All @@ -61,10 +62,7 @@ export async function storybookConfigurationGenerator(
tsConfiguration: schema.tsConfiguration ?? true, // default is true
interactionTests: schema.interactionTests ?? true, // default is true
configureStaticServe: schema.configureStaticServe,
uiFramework:
bundler === 'vite'
? '@storybook/react-vite'
: '@storybook/react-webpack5',
uiFramework: uiFramework as any, // cannot import UiFramework7 type dynamically
skipFormat: true,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ describe('@nx/storybook:configuration for Storybook v7', () => {
expect(
tree.read('libs/test-ui-lib2/tsconfig.storybook.json', 'utf-8')
).toMatchSnapshot();

expect(
readJson(tree, 'package.json').devDependencies['core-js']
).toBeTruthy();
});

it('should generate TS config for project if tsConfiguration true', async () => {
Expand Down Expand Up @@ -197,6 +201,10 @@ describe('@nx/storybook:configuration for Storybook v7', () => {
readJson(tree, 'package.json').devDependencies['@storybook/test-runner']
).toBeTruthy();

expect(
readJson(tree, 'package.json').devDependencies['core-js']
).toBeTruthy();

expect(
readJson(tree, 'package.json').devDependencies[
'@storybook/testing-library'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
storybookMajorVersion,
} from '../../utils/utilities';
import {
coreJsVersion,
nxVersion,
storybookJestVersion,
storybookTestingLibraryVersion,
Expand Down Expand Up @@ -191,6 +192,13 @@ export async function configurationGenerator(
devDeps['@nx/web'] = nxVersion;
}

if (
projectType !== 'application' &&
schema.uiFramework === '@storybook/react-webpack5'
) {
devDeps['core-js'] = coreJsVersion;
}

tasks.push(addDependenciesToPackageJson(tree, {}, devDeps));

if (!schema.skipFormat) {
Expand Down
2 changes: 2 additions & 0 deletions packages/storybook/src/utils/versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ export const tsNodeVersion = '10.9.1';
export const storybookVersion = '^7.0.24';
export const reactVersion = '^18.2.0';
export const viteVersion = '~4.3.9';

export const coreJsVersion = '^3.6.5';

0 comments on commit 6d8f6d6

Please sign in to comment.