From 19f82a06a64303678114e285fad99711858ba3d1 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Mon, 6 Jan 2025 12:52:17 +0100 Subject: [PATCH 1/3] Addon Test: Add prerequisite check for MSW --- code/addons/test/src/postinstall.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/code/addons/test/src/postinstall.ts b/code/addons/test/src/postinstall.ts index b3c3dba95943..6575b4930dd6 100644 --- a/code/addons/test/src/postinstall.ts +++ b/code/addons/test/src/postinstall.ts @@ -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` + • Detected the package MSW installed at version ${picocolors.bold(coercedMswVersion.version)}. To avoid conflicts with Vitest's dependencies, MSW must be version 2.0.0 or later. + Please update to a compatible version. + `); + } + if (info.frameworkPackageName === '@storybook/nextjs') { const nextVersion = await packageManager.getInstalledVersion('next'); if (!nextVersion) { @@ -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 From c826b86417a2229c0431c07e348314c68b4c966d Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Mon, 6 Jan 2025 12:54:02 +0100 Subject: [PATCH 2/3] CLI: Fix add command not respecting --yes flag when addon is already installed --- code/lib/cli-storybook/src/add.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/code/lib/cli-storybook/src/add.ts b/code/lib/cli-storybook/src/add.ts index d8df0813905d..8ba600883e7e 100644 --- a/code/lib/cli-storybook/src/add.ts +++ b/code/lib/cli-storybook/src/add.ts @@ -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); From 987d698d0a92111a933692149e39036f3c7124a2 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Mon, 6 Jan 2025 18:45:54 +0100 Subject: [PATCH 3/3] improve message --- code/addons/test/src/postinstall.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/addons/test/src/postinstall.ts b/code/addons/test/src/postinstall.ts index 6575b4930dd6..b4949927736b 100644 --- a/code/addons/test/src/postinstall.ts +++ b/code/addons/test/src/postinstall.ts @@ -150,8 +150,8 @@ export default async function postInstall(options: PostinstallOptions) { if (coercedMswVersion && !satisfies(coercedMswVersion, '>=2.0.0')) { reasons.push(dedent` - • Detected the package MSW installed at version ${picocolors.bold(coercedMswVersion.version)}. To avoid conflicts with Vitest's dependencies, MSW must be version 2.0.0 or later. - Please update to a compatible version. + • 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. `); }