Skip to content

Commit

Permalink
apply more migrations listed in #25433
Browse files Browse the repository at this point in the history
  • Loading branch information
ndelangen committed Feb 19, 2024
1 parent 15ed50a commit e83e47c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 6 deletions.
1 change: 1 addition & 0 deletions code/lib/cli/src/automigrate/fixes/mdx-gfm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const mdxgfm: Fix<Options> = {
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 ||
Expand Down
56 changes: 56 additions & 0 deletions code/lib/cli/src/automigrate/fixes/remove-legacymdx1.ts
Original file line number Diff line number Diff line change
@@ -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<RemoveLegacyMDX1Options> = {
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',
]);
}
},
};
5 changes: 0 additions & 5 deletions code/lib/types/src/modules/core-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
1 change: 0 additions & 1 deletion docs/api/main-config-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Type:
{
argTypeTargetsV7?: boolean;
legacyDecoratorFileOrder?: boolean;
legacyMdx1?: boolean;
}
```

Expand Down

0 comments on commit e83e47c

Please sign in to comment.