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 existing version detection in upgrade #25642

Merged
merged 2 commits into from
Jan 18, 2024

Conversation

JReinhold
Copy link
Contributor

@JReinhold JReinhold commented Jan 18, 2024

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 with SB_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:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/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 running npx storybook@0.0.0-pr-25642-sha-bb79636f sandbox or in an existing project with npx storybook@0.0.0-pr-25642-sha-bb79636f upgrade.

More information
Published version 0.0.0-pr-25642-sha-bb79636f
Triggered by @JReinhold
Repository storybookjs/storybook
Branch jeppe/fix-version-detection
Commit bb79636f
Datetime Thu Jan 18 08:33:31 UTC 2024 (1705566811)
Workflow run 7567312543

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

@JReinhold JReinhold self-assigned this Jan 18, 2024
@JReinhold JReinhold added bug cli ci:normal patch:yes Bugfix & documentation PR that need to be picked to main branch labels Jan 18, 2024
Comment on lines +31 to +34
// 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;
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Member

@shilman shilman left a 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

@JReinhold JReinhold merged commit 81db91d into next Jan 18, 2024
56 of 59 checks passed
@JReinhold JReinhold deleted the jeppe/fix-version-detection branch January 18, 2024 11:42
storybook-bot pushed a commit that referenced this pull request Jan 18, 2024
CLI: Fix existing version detection in `upgrade`
(cherry picked from commit 81db91d)
storybook-bot pushed a commit that referenced this pull request Jan 18, 2024
CLI: Fix existing version detection in `upgrade`
(cherry picked from commit 81db91d)
@github-actions github-actions bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug ci:normal cli patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants