Skip to content

Conversation

@JReinhold
Copy link
Contributor

@JReinhold JReinhold commented Jun 20, 2025

Works on #31817

What I did

This PR continues the work of #31825 , converting the server-related entry points to the new ESM-only bundling pipeline.

I added mlly as a utility to parse paths to module as well as resolve modules extensionless a couple of places.

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 canary-release-pr.yml --field pr=<PR_NUMBER>

Greptile Summary

Major refactoring to migrate server-related entry points to ESM-only bundling pipeline, replacing CommonJS-style imports with modern ESM patterns and utilities.

  • Added mlly package to handle module path parsing and resolution, replacing require.resolve and custom utilities across multiple files
  • Made getModulePackageJSON async in all package manager proxies (NPM, Yarn, PNPM, BUN) for better ESM compatibility
  • Removed loader.mjs and safeResolve.ts, introducing new loader.ts with esbuild for TypeScript to ESM conversion
  • Streamlined entry points in code/core/scripts/entries.ts by organizing them into platform-specific ESM-only sections (node, browser, runtime)
  • Added new resolveModule utility in code/core/src/shared/utils/resolve.ts to handle ESM-compatible path resolution

@JReinhold JReinhold changed the title Core: Migrate server-related entrypoints to ESM-only Core: ESM-only-fi server-related entry points Jun 20, 2025
@JReinhold JReinhold self-assigned this Jun 20, 2025
@JReinhold JReinhold added maintenance User-facing maintenance tasks core ci:normal labels Jun 20, 2025
Comment on lines -78 to -76
"./internal/builder-manager": {
"types": "./dist/builder-manager/index.d.ts",
"import": "./dist/builder-manager/index.js",
"require": "./dist/builder-manager/index.cjs"
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is no longer exported but referenced directly within storybook core. I don't see any reason to "expose" this to the outside.

@nx-cloud
Copy link

nx-cloud bot commented Jun 20, 2025

View your CI Pipeline Execution ↗ for commit b06aecc.

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

☁️ Nx Cloud last updated this comment at 2025-06-24 19:30:38 UTC

Comment on lines +23 to +29
// TODO: test this in Yarn PnP
const parsedBuilderPackage = parseNodeModulePath(builderName);
if (!parsedBuilderPackage.name) {
console.error(parsedBuilderPackage);
throw new Error('Invalid builder package');
}
builderPackage = parsedBuilderPackage.name;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

need to test this in Yarn PnP before merging

@storybook-app-bot
Copy link

storybook-app-bot bot commented Jun 20, 2025

Package Benchmarks

Commit: b06aecc, ran on 24 June 2025 at 19:34:29 UTC

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

storybook

Before After Difference
Dependency count 46 46 0
Self size 28.68 MB 23.83 MB 🎉 -4.85 MB 🎉
Dependency size 17.17 MB 17.17 MB 0 B
Bundle Size Analyzer Link Link

sb

Before After Difference
Dependency count 47 47 0
Self size 1 KB 1 KB 0 B
Dependency size 45.86 MB 41.00 MB 🎉 -4.85 MB 🎉
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 215 215 0
Self size 582 KB 582 KB 🎉 -19 B 🎉
Dependency size 91.52 MB 86.87 MB 🎉 -4.65 MB 🎉
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 184 184 0
Self size 31 KB 31 KB 0 B
Dependency size 75.66 MB 70.80 MB 🎉 -4.85 MB 🎉
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 1 1 0
Self size 12.46 MB 12.67 MB 🚨 +203 KB 🚨
Dependency size 98 KB 98 KB 0 B
Bundle Size Analyzer Link Link

@JReinhold JReinhold requested a review from Copilot June 23, 2025 14:50
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 converts several server‐related entry points to use an ESM-only bundling pipeline by updating module resolution, packaging utilities, and exports. Key changes include:

  • Transitioning getModulePackageJSON methods across package manager proxies to async/await.
  • Replacing legacy resolution utilities with mlly’s resolveModule and resolvePathSync.
  • Updating exports in package.json to align with an ESM-only strategy.

Reviewed Changes

Copilot reviewed 20 out of 50 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
code/core/src/common/utils/glob-to-regexp.ts Minor documentation (comment) update for consistency.
code/core/src/common/utils/get-storybook-refs.ts Updated comment wording for fetching stories.json.
code/core/src/common/utils/get-addon-annotations.ts Switched from require.resolve to resolveModule.
code/core/src/common/utils/cli.ts Changed synchronous package JSON retrieval to async.
code/core/src/common/presets.ts Revised preset resolution logic with inline safeResolve and mlly resolution enhancements.
code/core/src/common/js-package-manager/* Converted getModulePackageJSON methods to async for various package managers.
code/core/src/builder-manager/* Replaced legacy safeResolve usage with resolvePathSync and resolveModule.
code/core/scripts/* Updated entry definitions and formatting in helper scripts.
code/core/package.json Updated exports mapping to support the ESM-only approach.
code/addons/vitest/src/postinstall.ts Minor adjustment in config loading options.
Comments suppressed due to low confidence (2)

code/core/src/common/presets.ts:71

  • [nitpick] Consider renaming the inline 'safeResolve' function to avoid confusion with the previously removed safeResolve utility.
  const safeResolve = (path: string) => {

code/core/package.json:59

  • Ensure the updated exports mapping—particularly for './internal/common'—has no duplicate or conflicting entries, and verify that the removal of traditional keys like 'main' and 'module' aligns with the intended ESM-only design.
    "./internal/core-server": {

@JReinhold JReinhold marked this pull request as ready for review June 23, 2025 14: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.

48 files reviewed, 6 comments
Edit PR Review Bot Settings | Greptile

ndelangen and others added 20 commits June 23, 2025 17:57
… for Jest in Next.js projects. Update Jest setup and package.json for compatibility with ESM modules. Introduce .swcrc for SWC settings in Next.js. Adjust transform settings in Jest config for both React and Next.js projects.
exportPath?: string;
customSuffix?: string;
}) => {
const modulePath = join(pkg, exportPath);
Copy link
Member

Choose a reason for hiding this comment

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

@ndelangen ndelangen added this to the 10 milestone Jun 24, 2025
@ndelangen ndelangen merged commit b3c6ebd into jeppe/migrate-core-esm-only-3 Jun 24, 2025
54 of 56 checks passed
@ndelangen ndelangen deleted the jeppe/migrate-core-esm-only-4 branch June 24, 2025 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:normal core maintenance User-facing maintenance tasks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants