From 6c92162f8b47f4cca764dd4b57f9fa2b6e9a98eb Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Tue, 12 Dec 2023 14:13:39 +0100 Subject: [PATCH] remove the add-react automigration, do not add react as dep --- .../src/automigrate/fixes/add-react.test.ts | 66 ----------------- .../cli/src/automigrate/fixes/add-react.ts | 72 ------------------- code/lib/cli/src/automigrate/fixes/index.ts | 2 - code/lib/cli/src/generators/baseGenerator.ts | 9 --- 4 files changed, 149 deletions(-) delete mode 100644 code/lib/cli/src/automigrate/fixes/add-react.test.ts delete mode 100644 code/lib/cli/src/automigrate/fixes/add-react.ts diff --git a/code/lib/cli/src/automigrate/fixes/add-react.test.ts b/code/lib/cli/src/automigrate/fixes/add-react.test.ts deleted file mode 100644 index 9b7103625de7..000000000000 --- a/code/lib/cli/src/automigrate/fixes/add-react.test.ts +++ /dev/null @@ -1,66 +0,0 @@ -import type { StorybookConfigRaw } from '@storybook/types'; -import type { JsPackageManager, PackageJson } from '../../js-package-manager'; -import { addReact } from './add-react'; - -const checkAddReact = async (packageJson: PackageJson) => { - const packageManager = { - retrievePackageJson: async () => ({ dependencies: {}, devDependencies: {}, ...packageJson }), - } as JsPackageManager; - - return addReact.check({ - packageManager, - mainConfig: {} as StorybookConfigRaw, - storybookVersion: '7.0.0', - }); -}; - -describe('addReact fix', () => { - it('should no-op when not using docs or essentials', async () => { - await expect(checkAddReact({ dependencies: {} })).resolves.toBeFalsy(); - }); - - it('should no-op when react/react-dom are already installed', async () => { - await expect( - checkAddReact({ - dependencies: { react: '*' }, - devDependencies: { '@storybook/addon-docs': '*', 'react-dom': '*' }, - }) - ).resolves.toBeFalsy(); - }); - - it('should add react when it is missing', async () => { - await expect( - checkAddReact({ - dependencies: {}, - devDependencies: { '@storybook/addon-docs': '*', 'react-dom': '*' }, - }) - ).resolves.toMatchInlineSnapshot(` - Object { - "additionalDependencies": Array [ - "react", - ], - "dependents": Array [ - "@storybook/addon-docs", - ], - } - `); - }); - - it('should add reac-dom when it is missing', async () => { - await expect( - checkAddReact({ - dependencies: {}, - devDependencies: { '@storybook/addon-essentials': '*', react: '*' }, - }) - ).resolves.toMatchInlineSnapshot(` - Object { - "additionalDependencies": Array [ - "react-dom", - ], - "dependents": Array [ - "@storybook/addon-essentials", - ], - } - `); - }); -}); diff --git a/code/lib/cli/src/automigrate/fixes/add-react.ts b/code/lib/cli/src/automigrate/fixes/add-react.ts deleted file mode 100644 index 25ad88df2571..000000000000 --- a/code/lib/cli/src/automigrate/fixes/add-react.ts +++ /dev/null @@ -1,72 +0,0 @@ -import chalk from 'chalk'; -import { dedent } from 'ts-dedent'; -import type { Fix } from '../types'; - -interface AddReactOptions { - dependents: string[]; - additionalDependencies: string[]; -} - -/** - * is the user missing a dependency on react? - */ -export const addReact: Fix = { - id: 'addReact', - - async check({ packageManager }) { - const packageJson = await packageManager.retrievePackageJson(); - const installedDependencies = new Set( - Object.keys({ ...packageJson.dependencies, ...packageJson.devDependencies }) - ); - - const dependents = ['@storybook/addon-essentials', '@storybook/addon-docs'].filter((pkg) => - installedDependencies.has(pkg) - ); - const additionalDependencies = []; - if (dependents.length > 0) { - if (!installedDependencies.has('react')) { - // we add these here because they are required by addon-essentials > addon-docs - additionalDependencies.push('react'); - } - if (!installedDependencies.has('react-dom')) { - // we add these here because they are required by addon-essentials > addon-docs - additionalDependencies.push('react-dom'); - } - } - - if (additionalDependencies.length > 0) { - return { dependents, additionalDependencies }; - } - return null; - }, - - prompt({ dependents, additionalDependencies }) { - const dependentsFormatted = dependents.map((pkg) => chalk.cyan(pkg)).join(' & '); - const additionalDependenciesFormatted = additionalDependencies - .map((pkg) => `- ${chalk.cyan(pkg)}`) - .join('\n'); - - return dedent` - We've detected that you're using ${dependentsFormatted}. - - Starting in Storybook 7, we now require these peer dependencies to render docs: - - ${additionalDependenciesFormatted} - - We can add these for you automatically as dev dependencies. - - More info: ${chalk.yellow( - 'https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#react-peer-dependencies-required' - )} - `; - }, - - async run({ packageManager, result: { additionalDependencies }, dryRun }) { - if (!dryRun) { - await packageManager.addDependencies( - { installAsDevDependencies: true }, - additionalDependencies - ); - } - }, -}; diff --git a/code/lib/cli/src/automigrate/fixes/index.ts b/code/lib/cli/src/automigrate/fixes/index.ts index 2f71a11255f6..bd33074805d8 100644 --- a/code/lib/cli/src/automigrate/fixes/index.ts +++ b/code/lib/cli/src/automigrate/fixes/index.ts @@ -12,7 +12,6 @@ import { newFrameworks } from './new-frameworks'; import { removedGlobalClientAPIs } from './remove-global-client-apis'; import { mdx1to2 } from './mdx-1-to-2'; import { autodocsTrue } from './autodocs-true'; -import { addReact } from './add-react'; import { nodeJsRequirement } from './nodejs-requirement'; import { missingBabelRc } from './missing-babelrc'; import { angularBuilders } from './angular-builders'; @@ -38,7 +37,6 @@ export const allFixes: Fix[] = [ mdx1to2, mdxgfm, autodocsTrue, - addReact, missingBabelRc, angularBuildersMultiproject, angularBuilders, diff --git a/code/lib/cli/src/generators/baseGenerator.ts b/code/lib/cli/src/generators/baseGenerator.ts index 43fbbe9c3a67..70daf5764dd7 100644 --- a/code/lib/cli/src/generators/baseGenerator.ts +++ b/code/lib/cli/src/generators/baseGenerator.ts @@ -282,15 +282,6 @@ export async function baseGenerator( Object.keys({ ...packageJson.dependencies, ...packageJson.devDependencies }) ); - if (!installedDependencies.has('react')) { - // we add these here because they are required by addon-essentials > addon-docs - addonPackages.push('react'); - } - if (!installedDependencies.has('react-dom')) { - // we add these here because they are required by addon-essentials > addon-docs - addonPackages.push('react-dom'); - } - // TODO: We need to start supporting this at some point if (type === 'renderer') { throw new Error(