-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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 version detection compatibility with pre SB7.5 #26055
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
import { sync as spawnSync } from 'cross-spawn'; | ||
import semver from 'semver'; | ||
|
||
const legacy_versionRegex = /(@storybook\/[^@]+)@(\S+)/; | ||
|
||
const legacy_excludeList = [ | ||
'@storybook/linter-config', | ||
'@storybook/design-system', | ||
'@storybook/ember-cli-storybook', | ||
'@storybook/semver', | ||
'@storybook/eslint-config-storybook', | ||
'@storybook/bench', | ||
'@storybook/addon-bench', | ||
'@storybook/addon-console', | ||
'@storybook/csf', | ||
'@storybook/storybook-deployer', | ||
'@storybook/addon-postcss', | ||
'@storybook/react-docgen-typescript-plugin', | ||
'@storybook/babel-plugin-require-context-hook', | ||
'@storybook/builder-vite', | ||
'@storybook/mdx1-csf', | ||
'@storybook/mdx2-csf', | ||
'@storybook/expect', | ||
'@storybook/jest', | ||
'@storybook/test-runner', | ||
'@storybook/testing-library', | ||
]; | ||
const legacy_isCorePackage = (pkg: string) => | ||
pkg.startsWith('@storybook/') && | ||
!pkg.startsWith('@storybook/preset-') && | ||
!legacy_excludeList.includes(pkg); | ||
|
||
/** | ||
* @deprecated This function has been deprecated. This is solely to support upgrading from SB6 (and possible SB7) | ||
* I took this code from https://github.com/storybookjs/storybook/blob/v6.5.16/lib/cli/src/upgrade.ts#L29-L109 | ||
*/ | ||
export const legacy_getStorybookVersion = (): string | undefined => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's wait for the adjustments of Then the support for multiple package managers is guaranteed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally don't feel like we should spend a lot of time refining this as it's purely to temporarily support an upgrade from SB6 to SBX |
||
const lines = spawnSync('npm', ['ls'], { stdio: 'pipe' }).output.toString().split('\n'); | ||
const result = lines | ||
.map((line) => { | ||
if (line.startsWith('npm ')) return null; | ||
const match = legacy_versionRegex.exec(line); | ||
if (!match || !semver.clean(match[2])) return null; | ||
return { | ||
package: match[1], | ||
version: match[2], | ||
}; | ||
}) | ||
.filter(Boolean) | ||
.filter((pkg) => legacy_isCorePackage(pkg!.package)) | ||
.sort((a, b) => semver.rcompare(a!.version, b!.version)); | ||
|
||
if (result.length === 0) { | ||
return undefined; | ||
} | ||
|
||
return result[0]?.version; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So where before we returned
undefined
which would cause an "no version detected"-error... we now have this fallback that should operate exactly how it was in SB6.