From 3c2c46247d821b4e089d7e610f990e57b3376b9a Mon Sep 17 00:00:00 2001 From: abcdmku <63693423+abcdmku@users.noreply.github.com> Date: Mon, 12 Aug 2024 04:39:53 -0500 Subject: [PATCH] fix(storybook): update version check (#27278) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously the check would see if the version of storybook is less than 7 and would throw an error. This causes an issue when testing canary releases of storybook since they are labeled 0.0.0-[pr-info...] Update pleaseUpgrade text One of the checks is to see if storybook is less than 7. The text is updated so it matches for the very unlikely scenario that someone with version 5 or lower runs this plugin. ## Current Behavior The storybook plugin throws and error if the storybook version [is less than 7](https://github.com/nrwl/nx/blob/239f47c8d0eaf4df191acf1844b87e333b956e84/packages/storybook/src/executors/storybook/storybook.impl.ts#L17-L20). ```ts const storybook7 = storybookMajorVersion() >= 7; if (!storybook7) { throw pleaseUpgrade(); } ``` When testing a canary release for storybook the version is 0.0.0-[pr info] so when spinning up storybook it will display: ``` > nx run component-lib:storybook NX Storybook 6 is no longer maintained, and not supported in Nx. Please upgrade to Storybook 7. Here is a guide on how to upgrade: https://nx.dev/nx-api/storybook/generators/migrate-7 ``` ## Expected Behavior Storybook spins up when running a canary release. Modifying the version check to not include v0 solves the problem: ```ts const sbVersion = storybookMajorVersion(); const sbLessThan7 = sbVersion < 7 && sbVersion > 0; if (sbLessThan7) { throw pleaseUpgrade(); } ``` then running Storybook with that modification: ``` ╭──────────────────────────────────────────────────────────────────────╮ │ │ │ Storybook 0.0.0-pr-28752-sha-a65743e5 for react-webpack5 started │ │ 307 ms for manager and 7.73 s for preview │ │ │ │ Local: http://localhost:4402/ │ │ On your network: http://192.168.4.41:4402/ │ │ │ ╰──────────────────────────────────────────────────────────────────────╯ ``` ## Related Issue(s) Fixes #27277 --- .../storybook/src/executors/storybook/storybook.impl.ts | 6 ++++-- packages/storybook/src/utils/utilities.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/storybook/src/executors/storybook/storybook.impl.ts b/packages/storybook/src/executors/storybook/storybook.impl.ts index b077137170..b07532a1b2 100644 --- a/packages/storybook/src/executors/storybook/storybook.impl.ts +++ b/packages/storybook/src/executors/storybook/storybook.impl.ts @@ -14,8 +14,10 @@ export default async function* storybookExecutor( success: boolean; info?: { port: number; baseUrl?: string }; }> { - const storybook7 = storybookMajorVersion() >= 7; - if (!storybook7) { + const sbVersion = storybookMajorVersion(); + const sbLessThan7 = sbVersion < 7 && sbVersion > 0; + + if (sbLessThan7) { throw pleaseUpgrade(); } storybookConfigExistsCheck(options.configDir, context.projectName); diff --git a/packages/storybook/src/utils/utilities.ts b/packages/storybook/src/utils/utilities.ts index 5ddb355b51..a7df73c46a 100644 --- a/packages/storybook/src/utils/utilities.ts +++ b/packages/storybook/src/utils/utilities.ts @@ -268,7 +268,7 @@ export function getTsSourceFile(host: Tree, path: string): ts.SourceFile { export function pleaseUpgrade(): string { return ` - Storybook 6 is no longer maintained, and not supported in Nx. + Storybook 6 and lower are no longer maintained, and not supported in Nx. Please upgrade to Storybook 7. Here is a guide on how to upgrade: