diff --git a/code/lib/cli/src/automigrate/fixes/mdx-gfm.ts b/code/lib/cli/src/automigrate/fixes/mdx-gfm.ts index f844decf1443..7fc07b63349e 100644 --- a/code/lib/cli/src/automigrate/fixes/mdx-gfm.ts +++ b/code/lib/cli/src/automigrate/fixes/mdx-gfm.ts @@ -54,6 +54,7 @@ export const mdxgfm: Fix = { return files.some((f) => f.endsWith('.mdx')); }, Promise.resolve(false)); + // @ts-expect-error (user might be upgrading from an older version that still had it) const usesMDX1 = mainConfig?.features?.legacyMdx1 === true || false; const skip = usesMDX1 || diff --git a/code/lib/cli/src/automigrate/fixes/remove-legacymdx1.ts b/code/lib/cli/src/automigrate/fixes/remove-legacymdx1.ts new file mode 100644 index 000000000000..5cfd26792eec --- /dev/null +++ b/code/lib/cli/src/automigrate/fixes/remove-legacymdx1.ts @@ -0,0 +1,56 @@ +import { dedent } from 'ts-dedent'; + +import { writeConfig } from '@storybook/csf-tools'; + +import type { Fix } from '../types'; +import { updateMainConfig } from '../helpers/mainConfigFile'; + +const logger = console; + +interface RemoveLegacyMDX1Options { + hasFeature: boolean; +} + +/** + * Does the user have 'legacyMdx1' in their main.ts? + * + * If so, prompt them to upgrade to delete it. + */ +export const removeLegacyMDX1: Fix = { + id: 'builder-vite', + + async check({ mainConfig }) { + if (mainConfig.features) { + // + return { + hasFeature: !!Object.hasOwn(mainConfig.features, 'legacyMdx1'), + }; + } + + return null; + }, + + prompt({}) { + return dedent` + You have features.legacyMdx1 in your Storybook main config file, this feature has been removed, shall we remove it from you main.ts file? + + Link: https://storybook.js.org/docs/7.6/migration-guide + `; + }, + + async run({ dryRun, mainConfigPath, skipInstall, packageManager }) { + logger.info(`✅ Removing legacyMdx1 feature`); + if (!dryRun) { + await updateMainConfig({ dryRun: !!dryRun, mainConfigPath }, async (main) => { + main.removeField(['features', 'legacyMdx1']); + await writeConfig(main); + }); + + const packageJson = await packageManager.retrievePackageJson(); + + await packageManager.removeDependencies({ skipInstall: skipInstall, packageJson }, [ + '@storybook/mdx1-csf', + ]); + } + }, +}; diff --git a/code/lib/types/src/modules/core-common.ts b/code/lib/types/src/modules/core-common.ts index 7a6bd8a99699..380508211121 100644 --- a/code/lib/types/src/modules/core-common.ts +++ b/code/lib/types/src/modules/core-common.ts @@ -355,11 +355,6 @@ export interface StorybookConfigRaw { */ argTypeTargetsV7?: boolean; - /** - * Use legacy MDX1, to help smooth migration to 7.0 - */ - legacyMdx1?: boolean; - /** * Apply decorators from preview.js before decorators from addons or frameworks */ diff --git a/docs/api/main-config-features.md b/docs/api/main-config-features.md index afbab0b01695..1d773b6e1eaf 100644 --- a/docs/api/main-config-features.md +++ b/docs/api/main-config-features.md @@ -10,7 +10,6 @@ Type: { argTypeTargetsV7?: boolean; legacyDecoratorFileOrder?: boolean; - legacyMdx1?: boolean; } ```