Skip to content

CLI: Change yarn package manager value to yarn1#33099

Merged
yannbf merged 4 commits into
nextfrom
valentin/fix-package-manager-yarn-value
Nov 20, 2025
Merged

CLI: Change yarn package manager value to yarn1#33099
yannbf merged 4 commits into
nextfrom
valentin/fix-package-manager-yarn-value

Conversation

@valentinpalkovic
Copy link
Copy Markdown
Contributor

@valentinpalkovic valentinpalkovic commented Nov 20, 2025

Closes #

What I did

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-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 PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • New Features

    • CLI package-manager flag now offers validated, explicit choices — includes a distinct "yarn1" option.
    • Post-install detects the selected package manager and runs theme auto-configuration automatically.
  • Refactor

    • Package manager identifiers consolidated to a single, consistent source used across commands and scripts.

✏️ Tip: You can customize this high-level summary in your review settings.

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Nov 20, 2025

View your CI Pipeline Execution ↗ for commit 984cb43

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

☁️ Nx Cloud last updated this comment at 2025-11-20 09:18:39 UTC

@valentinpalkovic valentinpalkovic force-pushed the valentin/fix-package-manager-yarn-value branch from aeb4de8 to 3a54386 Compare November 20, 2025 07:42
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Nov 20, 2025

📝 Walkthrough

Walkthrough

Updated the package manager identifier for Yarn v1 and replaced string-literal usages with the PackageManagerName enum across CLI options, postinstall mapping, factory proxy map, and a sandbox script to use the typed enum values.

Changes

Cohort / File(s) Summary
Package Manager Enum
code/core/src/common/js-package-manager/JsPackageManager.ts
PackageManagerName.YARN1 enum value changed from 'yarn' to 'yarn1'.
Factory keying
code/core/src/common/js-package-manager/JsPackageManagerFactory.ts
Replaced string literal keys (npm, pnpm, yarn, yarn2, bun) in PROXY_MAP with computed keys using PackageManagerName enum values.
CLI — Storybook run commands
code/lib/cli-storybook/src/bin/run.ts
Added imports for PackageManagerName and Option; introduced a shared packageManagerOption using .choices(Object.values(PackageManagerName)) and applied it to multiple commands via .addOption(...).
Addon themes postinstall
code/addons/themes/src/postinstall.ts
Added PackageManagerName import; default parameter changed from 'npm' to PackageManagerName.NPM; PACKAGE_MANAGER_TO_COMMAND now uses enum keys (e.g., [PackageManagerName.YARN1]: 'npx').
Sandbox generator
scripts/sandbox/generate.ts
Imports PackageManagerName and replaces hard-coded --package-manager=yarn1 with --package-manager=${PackageManagerName.YARN1}.
CI workflow
.github/workflows/generate-sandboxes.yml
Enables push trigger for branch valentin/fix-package-manager-yarn-value and checks out that branch in the workflow.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CLI
  participant Enum as PackageManagerName
  participant Factory as JsPackageManagerFactory
  participant Postinstall as addons/postinstall
  participant Shell

  Note over Enum: Yarn v1 identifier changed to "yarn1"

  User->>CLI: run command --package-manager <type>
  CLI->>Enum: use Object.values(PackageManagerName) for choices
  CLI->>CLI: validate package-manager via Option.choices(...)
  CLI->>Factory: resolve manager using enum key
  CLI->>Postinstall: invoke postinstall(packageManager)
  Postinstall->>Enum: map enum -> command string
  Postinstall->>Shell: spawn mapped command
  Shell-->>Postinstall: exit/status
  Postinstall-->>CLI: return result
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Check for other code, tests, or config assuming the old 'yarn' literal (string equality, persisted configs, or fixtures).
  • Verify CLI help/usage displays and parsing for package-manager option show the enum values correctly.
  • Confirm spawn invocation in postinstall still behaves the same cross-platform with enum-keyed mappings.

Possibly related PRs

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
code/core/src/common/js-package-manager/JsPackageManager.ts (1)

22-28: Enum literal change for YARN1 may need explicit back‑compat handling

Changing PackageManagerName.YARN1 from 'yarn' to 'yarn1' alters the serialized value for this package manager. Any existing configs, CLI flags, stored metadata, or external integrations that still use 'yarn' could now fail to match or be misdetected.

Consider either:

  • Accepting both 'yarn' and 'yarn1' in CLI/config and normalizing to PackageManagerName.YARN1, or
  • Introducing a separate alias/normalize layer so the enum value change doesn’t silently break older inputs.

Please double‑check all consumers (CLI options, config parsing, telemetry, docs) for references to 'yarn' vs 'yarn1' to ensure this is intentionally breaking or fully covered. Based on learnings.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86ee663 and aeb4de8.

📒 Files selected for processing (1)
  • code/core/src/common/js-package-manager/JsPackageManager.ts (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: JReinhold
Repo: storybookjs/storybook PR: 32607
File: code/package.json:243-243
Timestamp: 2025-10-02T09:22:13.215Z
Learning: The Storybook repository uses Yarn v^4 (any 4.x version) as the package manager, configured via .yarnrc.yml and package.json packageManager field. Specific patch versions within v4 can be upgraded as needed.
📚 Learning: 2025-10-02T09:22:13.215Z
Learnt from: JReinhold
Repo: storybookjs/storybook PR: 32607
File: code/package.json:243-243
Timestamp: 2025-10-02T09:22:13.215Z
Learning: The Storybook repository uses Yarn v^4 (any 4.x version) as the package manager, configured via .yarnrc.yml and package.json packageManager field. Specific patch versions within v4 can be upgraded as needed.

Applied to files:

  • code/core/src/common/js-package-manager/JsPackageManager.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
scripts/sandbox/generate.ts (1)

113-113: Using PackageManagerName.YARN1 for the --package-manager flag is correct and future‑proof

Passing --package-manager=${PackageManagerName.YARN1} keeps this script consistent with the central mapping (now 'yarn1') and avoids drift if the underlying literal ever changes; no issues spotted. If we later support other package managers for sandboxes, this spot would be a natural extension point.

Based on learnings

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aeb4de8 and 3a54386.

📒 Files selected for processing (2)
  • code/core/src/common/js-package-manager/JsPackageManager.ts (1 hunks)
  • scripts/sandbox/generate.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • code/core/src/common/js-package-manager/JsPackageManager.ts
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: JReinhold
Repo: storybookjs/storybook PR: 32607
File: code/package.json:243-243
Timestamp: 2025-10-02T09:22:13.215Z
Learning: The Storybook repository uses Yarn v^4 (any 4.x version) as the package manager, configured via .yarnrc.yml and package.json packageManager field. Specific patch versions within v4 can be upgraded as needed.
📚 Learning: 2025-10-02T09:22:13.215Z
Learnt from: JReinhold
Repo: storybookjs/storybook PR: 32607
File: code/package.json:243-243
Timestamp: 2025-10-02T09:22:13.215Z
Learning: The Storybook repository uses Yarn v^4 (any 4.x version) as the package manager, configured via .yarnrc.yml and package.json packageManager field. Specific patch versions within v4 can be upgraded as needed.

Applied to files:

  • scripts/sandbox/generate.ts
📚 Learning: 2025-09-29T13:20:23.346Z
Learnt from: mrginglymus
Repo: storybookjs/storybook PR: 32556
File: code/core/package.json:309-313
Timestamp: 2025-09-29T13:20:23.346Z
Learning: The `fast-printf` dependency in Storybook's core package is bundled into the final distribution during the build process, so it should remain in devDependencies rather than being moved to dependencies, following the same pattern as other bundled dependencies like `open`.

Applied to files:

  • scripts/sandbox/generate.ts
🧬 Code graph analysis (1)
scripts/sandbox/generate.ts (1)
code/core/src/core-server/presets/common-preset.ts (1)
  • env (145-148)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (1)
scripts/sandbox/generate.ts (1)

15-15: Importing PackageManagerName keeps sandbox tooling aligned with core PM semantics

Pulling the enum from js-package-manager removes a magic string source of truth here and should track future changes to package-manager naming automatically. Looks good as-is.

Based on learnings

@valentinpalkovic valentinpalkovic force-pushed the valentin/fix-package-manager-yarn-value branch 2 times, most recently from 8a9d4b5 to f95810c Compare November 20, 2025 07:50
@valentinpalkovic valentinpalkovic force-pushed the valentin/fix-package-manager-yarn-value branch from f95810c to f58366c Compare November 20, 2025 07:52
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (3)
code/lib/cli-storybook/src/bin/run.ts (3)

116-119: Consistent package-manager choices for add command

add now shares the same enum-backed --package-manager option as init, which keeps behavior and validation consistent across commands. No further issues here beyond the BC/docs considerations already mentioned for init.


264-268: automigrate package-manager option consistent with other commands

automigrate now shares the same validated --package-manager choices as init/add/upgrade, which is good for predictability and error handling. No additional issues beyond the shared BC/docs considerations.


287-291: doctor package-manager option matches the new enum-based pattern

doctor using the same Option('--package-manager <type>').choices(Object.values(PackageManagerName)) pattern keeps all CLI entry points aligned on the same set of allowed package managers, reducing configuration drift. Looks good.

🧹 Nitpick comments (1)
code/lib/cli-storybook/src/bin/run.ts (1)

92-96: Typed --package-manager with enum choices improves safety; check BC & dedup opportunity

Using:

.addOption(
  new Option('--package-manager <type>', 'Force package manager for installing deps').choices(
    Object.values(PackageManagerName)
  )
)

is a solid improvement: it constrains the value to the enum, keeps the CLI in lockstep with PackageManagerName (including yarn1), and makes the allowed values visible in --help.

Two follow-ups to consider:

  • This will now reject any previously used ad-hoc values like --package-manager yarn if PackageManagerName has been changed to yarn1. If older docs/scripts still mention yarn, you may want either:
    • a deprecation period with an alias, or
    • explicit release notes stating yarn1 is now the required value.
  • The same Option(...).choices(Object.values(PackageManagerName)) pattern is repeated across several commands; a small helper like createPackageManagerOption() returning a new Option instance would reduce duplication and keep description/choices perfectly in sync.

Based on learnings

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3a54386 and 8a9d4b5.

📒 Files selected for processing (3)
  • code/core/src/common/js-package-manager/JsPackageManager.ts (1 hunks)
  • code/lib/cli-storybook/src/bin/run.ts (8 hunks)
  • scripts/sandbox/generate.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • scripts/sandbox/generate.ts
  • code/core/src/common/js-package-manager/JsPackageManager.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: JReinhold
Repo: storybookjs/storybook PR: 32607
File: code/package.json:243-243
Timestamp: 2025-10-02T09:22:13.215Z
Learning: The Storybook repository uses Yarn v^4 (any 4.x version) as the package manager, configured via .yarnrc.yml and package.json packageManager field. Specific patch versions within v4 can be upgraded as needed.
📚 Learning: 2025-10-02T09:22:13.215Z
Learnt from: JReinhold
Repo: storybookjs/storybook PR: 32607
File: code/package.json:243-243
Timestamp: 2025-10-02T09:22:13.215Z
Learning: The Storybook repository uses Yarn v^4 (any 4.x version) as the package manager, configured via .yarnrc.yml and package.json packageManager field. Specific patch versions within v4 can be upgraded as needed.

Applied to files:

  • code/lib/cli-storybook/src/bin/run.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (4)
code/lib/cli-storybook/src/bin/run.ts (4)

5-5: Enum-based package manager import keeps CLI in sync with core

Importing PackageManagerName here is the right way to drive CLI values from the single source of truth in storybook/internal/common, so the --package-manager flag stays aligned with core (including the new yarn1 literal). Looks good.


141-144: remove command wiring aligns with factory usage

The enum-based --package-manager option for remove is consistent with other commands and feeds into:

const packageManager = JsPackageManagerFactory.getPackageManager({
  configDir: options.configDir,
  force: options.packageManager,
});

which can now rely on options.packageManager being one of the known PackageManagerName values. Looks correct; just ensure JsPackageManagerFactory is updated to accept the new yarn1 literal.


169-172: upgrade adopts the same constrained package-manager flag

Using the same enum-backed --package-manager option for upgrade keeps behavior uniform and should simplify telemetry and option handling. Assuming UpgradeOptions’s type is updated (if needed) to include a compatible packageManager field, this looks fine.


15-15: Commander Option import is verified as appropriate

The import { Option, program } from commander is confirmed supported; Storybook's CLI dependency specifies commander ^12.1.0, which provides both Option#choices and program.addOption. The file uses this pattern correctly in multiple places (lines 92, 116, 141, 169, 264, 287) with .addOption(new Option(...).choices(...)).

No changes needed.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
code/addons/themes/src/postinstall.ts (1)

13-16: Consider stricter typing for improved type safety.

The selectPackageManagerCommand function accepts any string and requires a type assertion, while the postinstall function's packageManager parameter lacks an explicit type. This allows invalid package manager values to pass through at compile time and fail silently at runtime.

Consider applying this diff to strengthen type safety:

-const selectPackageManagerCommand = (packageManager: string) =>
-  PACKAGE_MANAGER_TO_COMMAND[packageManager as keyof typeof PACKAGE_MANAGER_TO_COMMAND];
+const selectPackageManagerCommand = (packageManager: PackageManagerName) =>
+  PACKAGE_MANAGER_TO_COMMAND[packageManager];

-export default async function postinstall({ packageManager = PackageManagerName.NPM }) {
+export default async function postinstall({ 
+  packageManager = PackageManagerName.NPM 
+}: { packageManager?: PackageManagerName }) {
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8a9d4b5 and f58366c.

📒 Files selected for processing (5)
  • code/addons/themes/src/postinstall.ts (1 hunks)
  • code/core/src/common/js-package-manager/JsPackageManager.ts (1 hunks)
  • code/core/src/common/js-package-manager/JsPackageManagerFactory.ts (1 hunks)
  • code/lib/cli-storybook/src/bin/run.ts (8 hunks)
  • scripts/sandbox/generate.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • code/core/src/common/js-package-manager/JsPackageManager.ts
  • scripts/sandbox/generate.ts
  • code/lib/cli-storybook/src/bin/run.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: JReinhold
Repo: storybookjs/storybook PR: 32607
File: code/package.json:243-243
Timestamp: 2025-10-02T09:22:13.215Z
Learning: The Storybook repository uses Yarn v^4 (any 4.x version) as the package manager, configured via .yarnrc.yml and package.json packageManager field. Specific patch versions within v4 can be upgraded as needed.
📚 Learning: 2025-10-02T09:22:13.215Z
Learnt from: JReinhold
Repo: storybookjs/storybook PR: 32607
File: code/package.json:243-243
Timestamp: 2025-10-02T09:22:13.215Z
Learning: The Storybook repository uses Yarn v^4 (any 4.x version) as the package manager, configured via .yarnrc.yml and package.json packageManager field. Specific patch versions within v4 can be upgraded as needed.

Applied to files:

  • code/addons/themes/src/postinstall.ts
🧬 Code graph analysis (1)
code/core/src/common/js-package-manager/JsPackageManagerFactory.ts (5)
code/core/src/common/js-package-manager/NPMProxy.ts (1)
  • NPMProxy (70-299)
code/core/src/common/js-package-manager/PNPMProxy.ts (1)
  • PNPMProxy (40-296)
code/core/src/common/js-package-manager/Yarn1Proxy.ts (1)
  • Yarn1Proxy (37-242)
code/core/src/common/js-package-manager/Yarn2Proxy.ts (1)
  • Yarn2Proxy (81-342)
code/core/src/common/js-package-manager/BUNProxy.ts (1)
  • BUNProxy (69-323)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (3)
code/core/src/common/js-package-manager/JsPackageManagerFactory.ts (1)

166-170: LGTM! Enum-based keys improve type safety and consistency.

The refactor from string literals to enum-based computed property names ensures the PROXY_MAP keys align with the PackageManagerName enum values and the type properties of the proxy classes. The Record type ensures all enum values are present, and the 'in' operator checks (lines 112, 147) work correctly with enum values.

code/addons/themes/src/postinstall.ts (2)

1-2: LGTM!

The import of PackageManagerName enables enum-based package manager handling throughout the file.


6-10: Enum keys improve consistency.

The migration from string literals to enum-based keys aligns this mapping with the PackageManagerName enum values used across the codebase. Note that the key for Yarn 1 changes from 'yarn' to 'yarn1', which is a breaking change for any external callers passing 'yarn' as a string.

@valentinpalkovic valentinpalkovic force-pushed the valentin/fix-package-manager-yarn-value branch from f58366c to 8de834e Compare November 20, 2025 07:58
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
code/addons/themes/src/postinstall.ts (1)

13-14: Consider strengthening the parameter type.

The function still accepts a generic string and relies on a type assertion. Consider updating the signature to accept PackageManagerName for better compile-time type safety.

Apply this diff:

-const selectPackageManagerCommand = (packageManager: string) =>
+const selectPackageManagerCommand = (packageManager: PackageManagerName) =>
   PACKAGE_MANAGER_TO_COMMAND[packageManager as keyof typeof PACKAGE_MANAGER_TO_COMMAND];

Or simplify the lookup:

-const selectPackageManagerCommand = (packageManager: string) =>
-  PACKAGE_MANAGER_TO_COMMAND[packageManager as keyof typeof PACKAGE_MANAGER_TO_COMMAND];
+const selectPackageManagerCommand = (packageManager: PackageManagerName) =>
+  PACKAGE_MANAGER_TO_COMMAND[packageManager];
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f58366c and 8de834e.

📒 Files selected for processing (5)
  • code/addons/themes/src/postinstall.ts (1 hunks)
  • code/core/src/common/js-package-manager/JsPackageManager.ts (1 hunks)
  • code/core/src/common/js-package-manager/JsPackageManagerFactory.ts (1 hunks)
  • code/lib/cli-storybook/src/bin/run.ts (9 hunks)
  • scripts/sandbox/generate.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • scripts/sandbox/generate.ts
  • code/core/src/common/js-package-manager/JsPackageManager.ts
  • code/core/src/common/js-package-manager/JsPackageManagerFactory.ts
  • code/lib/cli-storybook/src/bin/run.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: JReinhold
Repo: storybookjs/storybook PR: 32607
File: code/package.json:243-243
Timestamp: 2025-10-02T09:22:13.215Z
Learning: The Storybook repository uses Yarn v^4 (any 4.x version) as the package manager, configured via .yarnrc.yml and package.json packageManager field. Specific patch versions within v4 can be upgraded as needed.
📚 Learning: 2025-10-02T09:22:13.215Z
Learnt from: JReinhold
Repo: storybookjs/storybook PR: 32607
File: code/package.json:243-243
Timestamp: 2025-10-02T09:22:13.215Z
Learning: The Storybook repository uses Yarn v^4 (any 4.x version) as the package manager, configured via .yarnrc.yml and package.json packageManager field. Specific patch versions within v4 can be upgraded as needed.

Applied to files:

  • code/addons/themes/src/postinstall.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (1)
code/addons/themes/src/postinstall.ts (1)

1-1: LGTM! Clean refactoring to typed enum.

The migration from string literals to PackageManagerName enum improves type safety and maintainability. The computed property names in the object literal correctly resolve to the enum values at runtime, and the default parameter is now more explicit.

Also applies to: 6-10, 16-16

Copy link
Copy Markdown
Member

@yannbf yannbf left a comment

Choose a reason for hiding this comment

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

Code looks good

@valentinpalkovic valentinpalkovic force-pushed the valentin/fix-package-manager-yarn-value branch from 8de834e to f58366c Compare November 20, 2025 08:12
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8de834e and 2322744.

📒 Files selected for processing (6)
  • .github/workflows/generate-sandboxes.yml (2 hunks)
  • code/addons/themes/src/postinstall.ts (1 hunks)
  • code/core/src/common/js-package-manager/JsPackageManager.ts (1 hunks)
  • code/core/src/common/js-package-manager/JsPackageManagerFactory.ts (1 hunks)
  • code/lib/cli-storybook/src/bin/run.ts (8 hunks)
  • scripts/sandbox/generate.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • code/core/src/common/js-package-manager/JsPackageManager.ts
  • code/core/src/common/js-package-manager/JsPackageManagerFactory.ts
  • scripts/sandbox/generate.ts
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: JReinhold
Repo: storybookjs/storybook PR: 32607
File: code/package.json:243-243
Timestamp: 2025-10-02T09:22:13.215Z
Learning: The Storybook repository uses Yarn v^4 (any 4.x version) as the package manager, configured via .yarnrc.yml and package.json packageManager field. Specific patch versions within v4 can be upgraded as needed.
📚 Learning: 2025-10-02T09:22:13.215Z
Learnt from: JReinhold
Repo: storybookjs/storybook PR: 32607
File: code/package.json:243-243
Timestamp: 2025-10-02T09:22:13.215Z
Learning: The Storybook repository uses Yarn v^4 (any 4.x version) as the package manager, configured via .yarnrc.yml and package.json packageManager field. Specific patch versions within v4 can be upgraded as needed.

Applied to files:

  • .github/workflows/generate-sandboxes.yml
  • code/addons/themes/src/postinstall.ts
  • code/lib/cli-storybook/src/bin/run.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest
  • GitHub Check: Generate to main
  • GitHub Check: Generate to next
🔇 Additional comments (4)
code/addons/themes/src/postinstall.ts (2)

1-1: LGTM: Import of PackageManagerName enum.

This import enables type-safe package manager handling throughout the file.


16-16: LGTM: Type-safe default parameter.

Using PackageManagerName.NPM instead of the string literal 'npm' provides better type safety and consistency.

code/lib/cli-storybook/src/bin/run.ts (2)

5-5: LGTM: Imports for typed package manager options.

Adding PackageManagerName and Commander's Option class enables type-safe, validated CLI options.

Also applies to: 15-15


92-96: LGTM: Consistent typed option implementation across commands.

The migration from inline .option() to .addOption() with Option.choices() provides excellent type safety and validation. The pattern is consistently applied across all 6 commands (init, add, remove, upgrade, automigrate, doctor), ensuring a uniform interface.

This change automatically validates user input against PackageManagerName enum values and provides clear error messages for invalid choices.

Also applies to: 116-120, 141-145, 169-173, 264-268, 287-291

Comment thread .github/workflows/generate-sandboxes.yml Outdated
Comment thread .github/workflows/generate-sandboxes.yml Outdated
Comment on lines 5 to 11
const PACKAGE_MANAGER_TO_COMMAND = {
npm: 'npx',
pnpm: 'pnpm dlx',
yarn1: 'npx',
yarn2: 'yarn dlx',
bun: 'bunx',
[PackageManagerName.NPM]: 'npx',
[PackageManagerName.PNPM]: 'pnpm dlx',
[PackageManagerName.YARN1]: 'npx',
[PackageManagerName.YARN2]: 'yarn dlx',
[PackageManagerName.BUN]: 'bunx',
};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

Verify type safety of computed property names.

The map now uses computed property names with enum values as keys. However, selectPackageManagerCommand (line 13) accepts a string parameter and performs a type assertion when accessing this object. This could lead to runtime errors if the string doesn't match enum values exactly.

Run the following script to verify the enum values match the expected strings:


🏁 Script executed:

#!/bin/bash
# Description: Check PackageManagerName enum values and verify usage

# Find the enum definition
ast-grep --pattern 'enum PackageManagerName {
  $$$
}'

# Find all usages of selectPackageManagerCommand to verify callers pass correct values
rg -nP 'selectPackageManagerCommand\(' -A2

Length of output: 815


I need to examine the selectPackageManagerCommand function definition and its type signature to verify the type safety concern.

[/run_scripts]


🏁 Script executed:

#!/bin/bash
# Find selectPackageManagerCommand function definition and signature
rg -nP 'function selectPackageManagerCommand|const selectPackageManagerCommand|export.*selectPackageManagerCommand' -A5 -B2

Length of output: 705


🏁 Script executed:

#!/bin/bash
# Check the context around the call site to understand packageManager type
cat code/addons/themes/src/postinstall.ts | head -20

Length of output: 792


🏁 Script executed:

#!/bin/bash
# Look for any type assertions with 'as' keyword around the PACKAGE_MANAGER_TO_COMMAND map usage
rg -nP 'PACKAGE_MANAGER_TO_COMMAND.*\[.*\]|as.*PackageManagerName|as string' code/addons/themes/src/postinstall.ts -B3 -A3

Length of output: 405


I need to verify if there are other call sites and check the return type safety.

[/run_scripts]


🏁 Script executed:

#!/bin/bash
# Find all calls to selectPackageManagerCommand across entire codebase
rg -n 'selectPackageManagerCommand' --type=ts --type=tsx -B2 -A2

Length of output: 27


[/run_scripts]


🏁 Script executed:

#!/bin/bash
# Search for selectPackageManagerCommand calls without type filter
rg -n 'selectPackageManagerCommand' -B2 -A2

Length of output: 747


Change function parameter type from string to PackageManagerName to improve type safety.

The selectPackageManagerCommand function accepts packageManager: string with a type assertion, but should explicitly accept PackageManagerName instead. This eliminates the unsafe type assertion and clarifies the function's contract. At line 13-14, change:

const selectPackageManagerCommand = (packageManager: string) =>
  PACKAGE_MANAGER_TO_COMMAND[packageManager as keyof typeof PACKAGE_MANAGER_TO_COMMAND];

To accept the enum type directly, removing the need for type coercion and preventing potential runtime errors from invalid string values.

🤖 Prompt for AI Agents
In code/addons/themes/src/postinstall.ts around lines 5 to 11, the
selectPackageManagerCommand function currently accepts packageManager: string
and uses a type assertion into the PACKAGE_MANAGER_TO_COMMAND lookup; change the
parameter type to packageManager: PackageManagerName (and optionally add an
explicit return type of string | undefined) so you can index
PACKAGE_MANAGER_TO_COMMAND directly without the unsafe "as" cast; update the
function signature accordingly and remove the type coercion, ensuring callers
pass a PackageManagerName value (or add a guard/default if callers may pass
invalid strings).

@yannbf yannbf merged commit a82c687 into next Nov 20, 2025
63 checks passed
@yannbf yannbf deleted the valentin/fix-package-manager-yarn-value branch November 20, 2025 09:24
@coderabbitai coderabbitai Bot mentioned this pull request Nov 26, 2025
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants