Skip to content
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

Convert to full ESM & bundle dependencies #47

Merged
merged 3 commits into from
Jul 15, 2024

Conversation

ndelangen
Copy link
Contributor

  • I'm using the amazing TSup to create the lib folder instead of tsc
  • The lib actually contains ESM rather than CJS (tsconfig.json was setup to output CJS and tsc respects that setting.
  • TSup is able to bundle dependencies for both the lib/index.js as well as lib/index.d.ts, so I set it to bundle in everything. This makes the package dependency-less (total lib size is 91.34 kb).
  • Upgraded all dependencies
  • Switch to using the ESM version of fs-extra.
  • Added a format command (prettier config was already present, but couldn't be used)

@ndelangen
Copy link
Contributor Author

FYI we're using this package in Storybook.

When we're compiling our package, we get these warnings:

"default" is not exported by "../node_modules/file-system-cache/node_modules/@types/fs-extra/index.d.ts", imported by "../node_modules/file-system-cache/lib/common/libs.d.ts".
"default" is not exported by "../node_modules/@types/ramda/index.d.ts", imported by "../node_modules/file-system-cache/lib/common/libs.d.ts".

This prompted me to have a look inside, and attempt to do some upgrades/improvements.

Looking forward to your feedback @philcockfield

@philcockfield philcockfield merged commit 3ffec0e into philcockfield:main Jul 15, 2024
@philcockfield
Copy link
Owner

Thanks for the refactoring into tsup - if you're using that on Storybook, then merged into this module it is sir.
Appreciate your effort @ndelangen

@philcockfield
Copy link
Owner

Hey @ndelangen, out of interest, I'm assuming you've pushed Storybook to be full ESM, with no CJS legacy support?

I am a supporter of this, which is why I merged your PR...we need to get to ESM broadly as a community and get away from legacy that is just pure heat loss.

That being said, a number of folks are having the inevitable issue of being punched in the face by the CJS/ESM dichotomy.

Have you guys just taken a strong "NO CJS" support with Storybook, and are just wearing the push back - or are you doing a dance with dual-output bundling?

@ndelangen
Copy link
Contributor Author

@philcockfield thanks for the interest, I'm happy to answer.

We're in the process of going full ESM.
We've taken many steps towards this goal already, but have not yet made the full plunge just yet.

  • Our packages compile using TSup to both ESM and CJS, as well as generate a type definition bundle.
  • We have type=module on some packages, but not many
  • We use export maps in our package.json to ensure modern tools can pick the file formats that suits them/is appropriate for the way our packages are consumed.
  • We've reduced the number of packages is comprised of and removed complexity in our package structure/architecture.
  • We've upgraded/switched many dependencies to ESM.
  • We prebundle many of our dependencies, so them being ESM or CJS doesn't matter a lot, and even when some ESM<>CJS funny stuff goes on, we can make it work that way.

We plan on making a jump to be ESM only or at least "ESM first" by Storybook 9.0, which is scheduled for release in January 2025.

It's a massive shift, and possibly going to be a bumpy upgrade for some users, if they use storybook in unexpected/unknown ways.
But it is a change that's really needed for the ecosystem to progress, but that's just my humble opinion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants