-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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 existing version detection in upgrade
#25642
Conversation
// Note that this probably doesn't work in Yarn PNP mode because @storybook/telemetry doesn't depend on @storybook/cli | ||
export const getStorybookCoreVersion = async () => { | ||
const coreVersions = await Promise.all( | ||
['@storybook/core-common', '@storybook/core-server'].map(getActualPackageVersion) | ||
); | ||
return coreVersions.find((v) => v.version)?.version; | ||
const { version } = await getActualPackageVersion('@storybook/cli'); | ||
return 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.
can we add a backup in that case?
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.
I'm not sure how? Presumably you can't require.resolve
anything in PnP mode, because you're running with npx
so you don't depend on anything in the project, and thus you can't resolve it.
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.
To be clear, this didn't work before either in PnP, it never worked. Confirmed on a call that we're then OK to merge.
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.
Agree with @ndelangen 's comment but idea looks good
CLI: Fix existing version detection in `upgrade` (cherry picked from commit 81db91d)
CLI: Fix existing version detection in `upgrade` (cherry picked from commit 81db91d)
Works on #25293
What I did
This PR changes the code that detects the existing version installed to use
@storybook/cli
instead of@storybook/core-common
or@storybook/core-server
. This is because many packages depends on@storybook/core-common
and sometimes a project can get into a state where multiple versions of that package exists. This could cause the upgrade to fail withSB_CLI_UPGRADE_0004 (UpgradeStorybookToSameVersionError)
. Using the version of@storybook/cli
instead is safer because it will only be in the project once since no other packages depend on it.I tested this with the canary version in both npm, pnpm, Yarn 4 and Yarn PnP and it worked everywhere. Yarn PnP expectedly did not find a version, so I've added a fallback version. It's not the best user experience to see "You're upgrading from 0.0.0" but this is just a quick fix in the interest of time.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.🦋 Canary release
This pull request has been released as version
0.0.0-pr-25642-sha-bb79636f
. Try it out in a new sandbox by runningnpx storybook@0.0.0-pr-25642-sha-bb79636f sandbox
or in an existing project withnpx storybook@0.0.0-pr-25642-sha-bb79636f upgrade
.More information
0.0.0-pr-25642-sha-bb79636f
jeppe/fix-version-detection
bb79636f
1705566811
)To request a new release of this pull request, mention the
@storybookjs/core
team.core team members can create a new canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=25642