From 2dbfa14507b9c068aa2b487a34cddac737ba0e02 Mon Sep 17 00:00:00 2001 From: Yann Braga Date: Mon, 15 May 2023 16:39:04 +0200 Subject: [PATCH] Merge pull request #22559 from storybookjs/fix/builder-option CLI: Fix `getFrameworkPackage` logic --- code/lib/cli/src/generators/baseGenerator.ts | 21 ++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/code/lib/cli/src/generators/baseGenerator.ts b/code/lib/cli/src/generators/baseGenerator.ts index 5f94d6d969bc..f4231f56c21b 100644 --- a/code/lib/cli/src/generators/baseGenerator.ts +++ b/code/lib/cli/src/generators/baseGenerator.ts @@ -58,13 +58,30 @@ const getExternalFramework = (framework: string) => const getFrameworkPackage = (framework: string, renderer: string, builder: string) => { const externalFramework = getExternalFramework(framework); + const storybookBuilder = builder?.replace(/^@storybook\/builder-/, ''); + const storybookFramework = framework?.replace(/^@storybook\//, ''); if (externalFramework === undefined) { - return framework ? `@storybook/${framework}` : `@storybook/${renderer}-${builder}`; + const frameworkPackage = framework + ? `@storybook/${storybookFramework}` + : `@storybook/${renderer}-${storybookBuilder}`; + + if (packageVersions[frameworkPackage as keyof typeof packageVersions]) { + return frameworkPackage; + } + + throw new Error( + dedent` + Could not find framework package: ${frameworkPackage}. + Make sure this package exists, and if it does, please file an issue as this might be a bug in Storybook. + ` + ); } if (externalFramework.frameworks !== undefined) { - return externalFramework.frameworks.find((item) => item.match(new RegExp(`-${builder}`))); + return externalFramework.frameworks.find((item) => + item.match(new RegExp(`-${storybookBuilder}`)) + ); } return externalFramework.packageName;