From 17a2d4aeedaa5349e9c29104e8956cf015833458 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Thu, 9 Mar 2023 08:18:22 +0100 Subject: [PATCH 1/3] add nocache option to loadMainConfig --- code/lib/core-common/src/utils/load-main-config.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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); } From 09d2801be52cba68ad7c744f52b01e9da58bbb53 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Thu, 9 Mar 2023 08:19:05 +0100 Subject: [PATCH 2/3] bust cache when loading mainConfig in automigrations --- code/lib/cli/src/automigrate/helpers/mainConfigFile.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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}` From 62af0cae3d04ad842fc2828ee41d0592020428d2 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Thu, 9 Mar 2023 08:21:18 +0100 Subject: [PATCH 3/3] fix mdx-gfm automigration when running --skip-install --- code/lib/cli/src/automigrate/fixes/mdx-gfm.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) 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'];