Skip to content

Core: Improve mono repo handling for JsPackageManager class and helpers#31553

Merged
yannbf merged 16 commits into
valentin/monorepo-enhancementsfrom
valentin/improve-monorepo-support-for-js-package-manager
May 23, 2025
Merged

Core: Improve mono repo handling for JsPackageManager class and helpers#31553
yannbf merged 16 commits into
valentin/monorepo-enhancementsfrom
valentin/improve-monorepo-support-for-js-package-manager

Conversation

@valentinpalkovic
Copy link
Copy Markdown
Contributor

@valentinpalkovic valentinpalkovic commented May 22, 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 pull request has been released as version 0.0.0-pr-31553-sha-1239c0fa. Try it out in a new sandbox by running npx storybook@0.0.0-pr-31553-sha-1239c0fa sandbox or in an existing project with npx storybook@0.0.0-pr-31553-sha-1239c0fa upgrade.

More information
Published version 0.0.0-pr-31553-sha-1239c0fa
Triggered by @yannbf
Repository storybookjs/storybook
Branch valentin/improve-monorepo-support-for-js-package-manager
Commit 1239c0fa
Datetime Fri May 23 13:33:04 UTC 2025 (1748007184)
Workflow run 15211552517

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

Greptile Summary

This PR significantly improves monorepo support in the JsPackageManager class and related helpers, focusing on package management operations and configuration handling across multiple package.json files.

  • Introduced primaryPackageJson property to replace retrievePackageJson(), providing better monorepo-aware package.json handling
  • Changed getAllDependencies() from async to sync for improved performance and simplified dependency lookups
  • Added getModulePackageJSON() method with stopAt parameter to properly scope package searches in monorepos
  • Added --skip-install flag to CLI commands for better control over package installations in monorepo setups
  • Enhanced monorepo detection by checking for turbo.json, rush.json, nx.json, and workspaces configurations

@valentinpalkovic valentinpalkovic added feature request ci:normal Run our default set of CI jobs (choose this for most PRs). labels May 22, 2025
@valentinpalkovic valentinpalkovic self-assigned this May 22, 2025
Comment thread code/core/src/telemetry/storybook-metadata.test.ts Outdated
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented May 22, 2025

View your CI Pipeline Execution ↗ for commit 1239c0f.

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

☁️ Nx Cloud last updated this comment at 2025-05-23 13:33:01 UTC

Copy link
Copy Markdown
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.

68 file(s) reviewed, 24 comment(s)
Edit PR Review Bot Settings | Greptile

Comment thread code/core/src/cli/helpers.ts
Comment thread code/core/src/cli/helpers.test.ts
Comment thread code/core/src/common/js-package-manager/BUNProxy.ts
Comment thread code/core/src/common/js-package-manager/BUNProxy.ts Outdated
Comment thread code/core/src/common/js-package-manager/JsPackageManager.ts
'Force package manager for installing dependencies'
)
.option('-c, --config-dir <dir-name>', 'Directory where to load Storybook configurations from')
.option('--skip-install', 'Skip installing deps')
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.

style: Consider using the same flag format as line 51 (-s) for consistency

let mainConfig;
let storybookVersion: string | undefined;
let mainConfig: StorybookConfigRaw | undefined;
let packageManager!: JsPackageManager;
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.

logic: Using definite assignment assertion (!) here could mask initialization errors if getStorybookData fails

migration: any,
{ glob, dryRun, list, rename, parser, configDir: userSpecifiedConfigDir }: CLIOptions
) {
export async function migrate(migration: any, { glob, dryRun, list, rename, parser }: CLIOptions) {
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.

style: Migration parameter should be typed more specifically than 'any'

Suggested change
export async function migrate(migration: any, { glob, dryRun, list, rename, parser }: CLIOptions) {
export async function migrate(migration: string, { glob, dryRun, list, rename, parser }: CLIOptions) {

) {
export async function migrate(migration: any, { glob, dryRun, list, rename, parser }: CLIOptions) {
if (list) {
listCodemods().forEach((key: any) => logger.log(key));
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.

style: Key parameter in forEach callback should be typed more specifically than 'any'

Suggested change
listCodemods().forEach((key: any) => logger.log(key));
listCodemods().forEach((key: string) => logger.log(key));

// Users struggle to upgrade Storybook with npm because of conflicting peer-dependencies
// GitHub Issue: https://github.com/storybookjs/storybook/issues/30306
// Solution: Remove all Storybook packages (except 'storybook') from the package.json and install them again
// TODO: Check if this is still needed due to the resolution fix for the `storybook` package
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.

style: Consider removing this TODO comment since the overrides fix is now implemented above

@storybook-app-bot
Copy link
Copy Markdown

storybook-app-bot Bot commented May 22, 2025

Package Benchmarks

Commit: 1239c0f, ran on 23 May 2025 at 13:39:47 UTC

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

@storybook/angular

Before After Difference
Dependency count 208 209 🚨 +1 🚨
Self size 606 KB 607 KB 🚨 +483 B 🚨
Dependency size 29.54 MB 29.56 MB 🚨 +11 KB 🚨
Bundle Size Analyzer Link Link

@storybook/ember

Before After Difference
Dependency count 208 205 🎉 -3 🎉
Self size 28 KB 28 KB 🚨 +179 B 🚨
Dependency size 28.82 MB 28.80 MB 🎉 -21 KB 🎉
Bundle Size Analyzer Link Link

@storybook/nextjs

Before After Difference
Dependency count 534 531 🎉 -3 🎉
Self size 216 KB 216 KB 🚨 +10 B 🚨
Dependency size 58.69 MB 58.67 MB 🎉 -21 KB 🎉
Bundle Size Analyzer Link Link

@storybook/nextjs-vite

Before After Difference
Dependency count 127 128 🚨 +1 🚨
Self size 2.39 MB 2.39 MB 0 B
Dependency size 22.05 MB 22.06 MB 🚨 +11 KB 🚨
Bundle Size Analyzer Link Link

@storybook/react-native-web-vite

Before After Difference
Dependency count 161 162 🚨 +1 🚨
Self size 35 KB 35 KB 0 B
Dependency size 23.21 MB 23.23 MB 🚨 +11 KB 🚨
Bundle Size Analyzer Link Link

@storybook/react-vite

Before After Difference
Dependency count 120 121 🚨 +1 🚨
Self size 32 KB 32 KB 🚨 +97 B 🚨
Dependency size 20.16 MB 20.17 MB 🚨 +11 KB 🚨
Bundle Size Analyzer Link Link

@storybook/react-webpack5

Before After Difference
Dependency count 284 286 🚨 +2 🚨
Self size 25 KB 25 KB 0 B
Dependency size 43.48 MB 43.50 MB 🚨 +15 KB 🚨
Bundle Size Analyzer Link Link

@storybook/preset-react-webpack

Before After Difference
Dependency count 175 177 🚨 +2 🚨
Self size 24 KB 24 KB 🚨 +171 B 🚨
Dependency size 30.32 MB 30.33 MB 🚨 +15 KB 🚨
Bundle Size Analyzer Link Link

Comment thread code/core/src/common/js-package-manager/JsPackageManager.ts
Comment thread code/core/src/common/js-package-manager/JsPackageManager.ts Outdated
@yannbf yannbf merged commit be484bf into valentin/monorepo-enhancements May 23, 2025
55 checks passed
@yannbf yannbf deleted the valentin/improve-monorepo-support-for-js-package-manager branch May 23, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:normal Run our default set of CI jobs (choose this for most PRs). feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants