Skip to content

Commit

Permalink
Merge pull request #21498 from storybookjs/fix/load-main-config-cache
Browse files Browse the repository at this point in the history
CLI: Require main.js without cache in automigrations
  • Loading branch information
ndelangen authored Mar 9, 2023
2 parents 2d280e6 + 62af0ca commit 0d4810b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
8 changes: 5 additions & 3 deletions code/lib/cli/src/automigrate/fixes/mdx-gfm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,12 @@ export const mdxgfm: Fix<Options> = {

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'];
Expand Down
2 changes: 1 addition & 1 deletion code/lib/cli/src/automigrate/helpers/mainConfigFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down
10 changes: 9 additions & 1 deletion code/lib/core-common/src/utils/load-main-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ import { validateConfigurationFiles } from './validate-configuration-files';

export async function loadMainConfig({
configDir = '.storybook',
noCache = false,
}: {
configDir: string;
noCache?: boolean;
}): Promise<StorybookConfig> {
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);
}

0 comments on commit 0d4810b

Please sign in to comment.