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: Fix getFrameworkPackage logic #22559

Merged
merged 1 commit into from
May 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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\//, '');
valentinpalkovic marked this conversation as resolved.
Show resolved Hide resolved

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