Skip to content

Conversation

@JReinhold
Copy link
Contributor

@JReinhold JReinhold commented Jun 10, 2025

What I did

Follow-up to #31605

This fixes a bug, that running packageManager.addDependencies() with skipInstall: true required that you also pass packageJson, which the postinstall script from addon-vitest did not.

An alternative solution would be that JsPackageManager itself read the package.json (this.readPackageJson()) if it was not passed, but it was unclear to me whether that would work in all instances or not.

This bug is currently blocking the installation of addon-vitest with the sv (Svelte) CLI because that always runs with --skip-install.

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

  1. In a fresh project without node_modules, package-lock.json, without vitest installed and without the addon installed, run npx storybook@latest add @storybook/addon-vitest --skip-install
  2. See that it fails with
Error running postinstall script for @storybook/addon-vitest
Error: Invariant failed: Missing packageJson.
  1. Revert back to the pristine repo, and add the canary instead (if using npm, remember to enable legacy peer deps): npx [email protected] add @storybook/addon-vitest --skip-install
  2. See that it works

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-storybook/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-31720-sha-0f081578. Try it out in a new sandbox by running npx [email protected] sandbox or in an existing project with npx [email protected] upgrade.

More information
Published version 0.0.0-pr-31720-sha-0f081578
Triggered by @JReinhold
Repository storybookjs/storybook
Branch jeppe/fix-addon-vitest-skipinstall
Commit 0f081578
Datetime Tue Jun 10 08:47:48 UTC 2025 (1749545268)
Workflow run 15554925367

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=31720

Greptile Summary

Fixes a critical bug in @storybook/addon-vitest where installation fails with --skip-install flag due to missing packageJson requirement.

  • Fixed code/addons/vitest/src/postinstall.ts to explicitly include required packageJson parameter in addDependencies calls
  • Enhanced type safety in JsPackageManager.ts to enforce packageJson parameter when skipInstall: true
  • Particularly important fix for Svelte CLI users who always run with --skip-install
  • Added proper error handling for package.json requirement in eslint-plugin fixes

@nx-cloud
Copy link

nx-cloud bot commented Jun 10, 2025

View your CI Pipeline Execution ↗ for commit 24fbaa4.

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 1m 27s View ↗

☁️ Nx Cloud last updated this comment at 2025-06-10 11:31:19 UTC

@JReinhold JReinhold changed the title pass packageJson when passing skipInstall true Addon-vitest: Fix adding with --skip-install failing missing packageJson invariant Jun 10, 2025
@JReinhold JReinhold self-assigned this Jun 10, 2025
@JReinhold JReinhold requested review from Copilot and yannbf June 10, 2025 08:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses a bug where running packageManager.addDependencies() with --skip-install failed due to a missing packageJson parameter.

  • Enforces that packageJson is passed when skipInstall is true via a union type in addDependencies.
  • Updates the postinstall script for addon-vitest to supply the packageJson by invoking readPackageJson().

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
code/core/src/common/js-package-manager/JsPackageManager.ts Refactored addDependencies signature to enforce packageJson with skipInstall.
code/addons/vitest/src/postinstall.ts Updated addDependencies call to include packageJson read from the file system.
Comments suppressed due to low confidence (1)

code/core/src/common/js-package-manager/JsPackageManager.ts:256

  • [nitpick] Since the new union type in the method signature guarantees that packageJson is provided when skipInstall is true, consider removing the redundant runtime invariant check for packageJson or adding a comment explaining its necessity for extra safety.
invariant(packageJson, 'Missing packageJson.');

@JReinhold JReinhold marked this pull request as ready for review June 10, 2025 11:29
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

3 files reviewed, no comments
Edit PR Review Bot Settings | Greptile

@storybook-app-bot
Copy link

Package Benchmarks

Commit: 24fbaa4, ran on 10 June 2025 at 11:34:06 UTC

The following packages have significant changes to their size or dependencies:

storybook

Before After Difference
Dependency count 49 49 0
Self size 31.22 MB 31.40 MB 🚨 +185 KB 🚨
Dependency size 17.41 MB 17.41 MB 0 B
Bundle Size Analyzer Link Link

sb

Before After Difference
Dependency count 50 50 0
Self size 1 KB 1 KB 0 B
Dependency size 48.63 MB 48.81 MB 🚨 +185 KB 🚨
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 324 324 0
Self size 244 KB 244 KB 🚨 +188 B 🚨
Dependency size 98.82 MB 97.90 MB 🎉 -921 KB 🎉
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 267 267 0
Self size 31 KB 31 KB 0 B
Dependency size 82.11 MB 82.29 MB 🚨 +185 KB 🚨
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 1 1 0
Self size 12.13 MB 11.02 MB 🎉 -1.11 MB 🎉
Dependency size 98 KB 98 KB 0 B
Bundle Size Analyzer Link Link

@JReinhold JReinhold added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Jun 10, 2025
@JReinhold JReinhold merged commit 505b08f into next Jun 10, 2025
57 of 61 checks passed
@JReinhold JReinhold deleted the jeppe/fix-addon-vitest-skipinstall branch June 10, 2025 11:53
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

3 files reviewed, no comments
Edit PR Review Bot Settings | Greptile

JReinhold added a commit that referenced this pull request Jun 10, 2025
…pinstall

Addon-vitest: Fix adding with `--skip-install` failing missing packageJson invariant
(cherry picked from commit 505b08f)
@github-actions github-actions bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Jun 10, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

3 files reviewed, no comments
Edit PR Review Bot Settings | Greptile

@ndelangen ndelangen removed the patch:yes Bugfix & documentation PR that need to be picked to main branch label Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

addon: vitest bug ci:normal patch:done Patch/release PRs already cherry-picked to main/release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants