Skip to content

Commit

Permalink
Merge pull request #22559 from storybookjs/fix/builder-option
Browse files Browse the repository at this point in the history
CLI: Fix `getFrameworkPackage` logic
  • Loading branch information
yannbf authored and shilman committed May 15, 2023
1 parent aff3dc2 commit 2dbfa14
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions code/lib/cli/src/generators/baseGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2dbfa14

Please sign in to comment.