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

Addon Test: Add prerequisite check for MSW #30193

Merged
merged 3 commits into from
Jan 8, 2025
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
11 changes: 11 additions & 0 deletions code/addons/test/src/postinstall.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ export default async function postInstall(options: PostinstallOptions) {
`);
}

const mswVersionSpecifier = await packageManager.getInstalledVersion('msw');
const coercedMswVersion = mswVersionSpecifier ? coerce(mswVersionSpecifier) : null;

if (coercedMswVersion && !satisfies(coercedMswVersion, '>=2.0.0')) {
reasons.push(dedent`
• The addon uses Vitest behind the scenes, which supports only version 2 and above of MSW. However, we have detected version ${picocolors.bold(coercedMswVersion.version)} in this project.
Please update the 'msw' package and try again.
`);
}

if (info.frameworkPackageName === '@storybook/nextjs') {
const nextVersion = await packageManager.getInstalledVersion('next');
if (!nextVersion) {
Expand All @@ -159,6 +169,7 @@ export default async function postInstall(options: PostinstallOptions) {
reasons.unshift(
`Storybook Test's automated setup failed due to the following package incompatibilities:`
);
reasons.push('--------------------------------');
reasons.push(
dedent`
You can fix these issues and rerun the command to reinstall. If you wish to roll back the installation, remove ${picocolors.bold(colors.pink(ADDON_NAME))} from the "addons" array
Expand Down
22 changes: 12 additions & 10 deletions code/lib/cli-storybook/src/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,19 @@ export async function add(

let shouldAddToMain = true;
if (checkInstalled(addonName, requireMain(configDir))) {
const { shouldForceInstall } = await prompts({
type: 'confirm',
name: 'shouldForceInstall',
message: `The Storybook addon "${addonName}" is already present in ${mainConfig}. Do you wish to install it again?`,
});

if (!shouldForceInstall) {
return;
}

shouldAddToMain = false;
if (!yes) {
logger.log(`The Storybook addon "${addonName}" is already present in ${mainConfig}.`);
const { shouldForceInstall } = await prompts({
type: 'confirm',
name: 'shouldForceInstall',
message: `Do you wish to install it again?`,
});

if (!shouldForceInstall) {
return;
}
}
}

const main = await readConfig(mainConfig);
Expand Down
Loading