-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
[Tracking] ESM-only spike π¦ #29072
Comments
|
How can existing Storybook addons, which still produce both CommonJS (CJS) and ESModule (ESM) build assets (or even only CJS), be configured to properly consume a pure ESM-only @storybook/core package? What strategies or best practices can be applied to ensure compatibility, considering that these addons currently support both module formats? Specifically, how can we handle the transition for addons still relying on CJS, while moving the core package to ESM-only? |
@valentinpalkovic that's something we probably want to investigate as part of investigating preset loading. Given Storybook loads the addons (and not the other way around), I'd expect that only the ESM entrypoints would be used, and CJS being ignored. However today some addon entry points are only built in CJS, like preset entry points, and that might be a challenge to support. In those cases I'd expect addon authors would need to release new ESM-only versions of their addons (with our guidance). But we'll see. |
π§βπ€βπ§ Who: @ndelangen and @JReinhold
This is a tracking issue for the ESM-only spike π¦. The purpose of this issue is to keep tracking of the overall status of the project and tasks, and plan everything around it. It is a sub-project under #29038
The main purpose of the spike is to answer questions about what happens when we convert to ESM-only, and how that can happen. Answering some of these questions will require explorations and writing code. It is not the goal of this spike to merge the code into
next
, even if it backwards compatible. However it could potentially be part of v8.5. The reason for this is that we always underestimate the effort it requires to turn an exploratory spike-PR into a polished PR ready for merging.As part of this we need to ensure that we're testing in a proper setting. Sometimes testing these far-reaching changes isn't enough in the monorepo, because the monorepo can have linking setup that makes the changes work, even though they wouldn't in a real setting. We must be mindful about when things should be tested in separate projects using Verdaccio or similar.
Tasks
β Questions
What are the steps towards ESM-only, and in what order should they be done?
How can the migration be split into multiple milestones to avoid massive, unreviewable PRs?
Investigate if we can gradually turn each entry point in
@storybook/core
to ESM-only, without doing it for the whole package at once. What happens when we do this? We've already started looking into this in #28797Here's another spike proving it's feasibility:
https://github.com/storybookjs/storybook/pull/29320/files
Which of the steps can be carried out in a backwards-compatible way, potentially pre-9.0?
The CLI package is already
type=module
. However thebin
file is explicitly a.CJS
-file.It's relatively simple to change this to either be ESM directly, or by writing an
import()
there, and load thedist
code.A spike can be found doing just that here:
#29317
What is the right order of package migrations that will minimize failures?
How can we load presets?
Today weβre using
esbuild-register
, but thatβs a hurdle because it assumes CJS-first - can we replace that with something else, likeesbuild
natively? How do we keep supporting TS, CJS and ESM presets?In #28796 we investigated replacing
esbuild
withjiti
, and found that it was more strict in which CJS/ESM files it could parse. We should investigatejiti
more closely and "stress-test" it with different preseet bundles andmain.js/cjs/mjs
to see how it will break existing use-cases.In #28802 we investigated using
esbuild
directly instead ofesbuild-register
. We'll then bundle and write all presets to a temp dir with the.mjs
extension to be imported. We'll continue down that path here. We should also investigate how Vite loads its config files, because they also use esbuild for this, so we can get inspiration from their logic.Is bottom-first or top-first the best approach for migration?
To be clear, in this paradigm, the logic would be like this, top-to-bottom:
Which use-cases, environments are we dropping support for by going ESM-only. Specifically, what about Jest-based Portable Stories users? Or anything else?
We know that Jest in general is very heavy on CJS. Does going ESM-only break Jest-usage of Portable Stories, or is it still compatible? The upcoming release of Jest 30 might improve the situation. We might reach a conclusion that involves a recipe for how to make ESM-only Storybook work in a Jest environment.
How will this affect React Native?
Step 0 here would be to have a set up that allows us to regression test a simple React Native project against the changes we're making in the spike
require
s of@storybook/core
which would break in an ESM-only world: https://github.com/storybookjs/react-native/blob/next/packages/react-native/scripts/loader.js#L5The text was updated successfully, but these errors were encountered: