From 6d8f6d67e13b280dd7a975ab4111e232627540dc Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Fri, 14 Jul 2023 14:24:03 +0300 Subject: [PATCH] fix(storybook): install core-js for non-vite libs closed #18109 --- .../storybook-configuration/configuration.ts | 16 +++++++--------- .../configuration/configuration.spec.ts | 8 ++++++++ .../generators/configuration/configuration.ts | 8 ++++++++ packages/storybook/src/utils/versions.ts | 2 ++ 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/packages/react/src/generators/storybook-configuration/configuration.ts b/packages/react/src/generators/storybook-configuration/configuration.ts index 1469fe73b8983..be92e63c057d6 100644 --- a/packages/react/src/generators/storybook-configuration/configuration.ts +++ b/packages/react/src/generators/storybook-configuration/configuration.ts @@ -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, { @@ -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, }); diff --git a/packages/storybook/src/generators/configuration/configuration.spec.ts b/packages/storybook/src/generators/configuration/configuration.spec.ts index 96c34ec3b37ef..681ddb8ec20b1 100644 --- a/packages/storybook/src/generators/configuration/configuration.spec.ts +++ b/packages/storybook/src/generators/configuration/configuration.spec.ts @@ -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 () => { @@ -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' diff --git a/packages/storybook/src/generators/configuration/configuration.ts b/packages/storybook/src/generators/configuration/configuration.ts index 3afadb47c69ee..1465d010bece2 100644 --- a/packages/storybook/src/generators/configuration/configuration.ts +++ b/packages/storybook/src/generators/configuration/configuration.ts @@ -35,6 +35,7 @@ import { storybookMajorVersion, } from '../../utils/utilities'; import { + coreJsVersion, nxVersion, storybookJestVersion, storybookTestingLibraryVersion, @@ -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) { diff --git a/packages/storybook/src/utils/versions.ts b/packages/storybook/src/utils/versions.ts index e62270f770354..06bcac3a97721 100644 --- a/packages/storybook/src/utils/versions.ts +++ b/packages/storybook/src/utils/versions.ts @@ -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';