diff --git a/code/lib/cli/src/automigrate/fixes/mdx-gfm.ts b/code/lib/cli/src/automigrate/fixes/mdx-gfm.ts index 3cb8b345424d..89b381cb4ec1 100644 --- a/code/lib/cli/src/automigrate/fixes/mdx-gfm.ts +++ b/code/lib/cli/src/automigrate/fixes/mdx-gfm.ts @@ -61,10 +61,12 @@ export const mdxgfm: Fix = { async run({ packageManager, dryRun, mainConfigPath, skipInstall }) { if (!dryRun) { + const packageJson = packageManager.retrievePackageJson(); const versionToInstall = getStorybookVersionSpecifier(packageManager.retrievePackageJson()); - await packageManager.addDependencies({ installAsDevDependencies: true, skipInstall }, [ - `@storybook/addon-mdx-gfm@${versionToInstall}`, - ]); + await packageManager.addDependencies( + { installAsDevDependencies: true, skipInstall, packageJson }, + [`@storybook/addon-mdx-gfm@${versionToInstall}`] + ); await updateMainConfig({ mainConfigPath, dryRun }, async (main) => { const addonsToAdd = ['@storybook/addon-mdx-gfm']; diff --git a/code/lib/cli/src/automigrate/helpers/mainConfigFile.ts b/code/lib/cli/src/automigrate/helpers/mainConfigFile.ts index 5073e6f8cc84..cfad39bf7048 100644 --- a/code/lib/cli/src/automigrate/helpers/mainConfigFile.ts +++ b/code/lib/cli/src/automigrate/helpers/mainConfigFile.ts @@ -30,7 +30,7 @@ export const getStorybookData = async ({ let mainConfig: StorybookConfig; try { - mainConfig = await loadMainConfig({ configDir }); + mainConfig = await loadMainConfig({ configDir, noCache: true }); } catch (err) { throw new Error( dedent`Unable to find or evaluate ${chalk.blue(mainConfigPath)}: ${err.message}` diff --git a/code/lib/core-common/src/utils/load-main-config.ts b/code/lib/core-common/src/utils/load-main-config.ts index 9bb3e84ac2d3..467cc372ecda 100644 --- a/code/lib/core-common/src/utils/load-main-config.ts +++ b/code/lib/core-common/src/utils/load-main-config.ts @@ -5,10 +5,18 @@ import { validateConfigurationFiles } from './validate-configuration-files'; export async function loadMainConfig({ configDir = '.storybook', + noCache = false, }: { configDir: string; + noCache?: boolean; }): Promise { await validateConfigurationFiles(configDir); - return serverRequire(path.resolve(configDir, 'main')); + const mainJsPath = path.resolve(configDir, 'main'); + + if (noCache && require.cache[require.resolve(mainJsPath)]) { + delete require.cache[require.resolve(mainJsPath)]; + } + + return serverRequire(mainJsPath); }