Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Require main.js without cache in automigrations #21498

Merged
merged 3 commits into from
Mar 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}