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

feat: ESM support #25

Merged
merged 39 commits into from
Sep 14, 2022
Merged

feat: ESM support #25

merged 39 commits into from
Sep 14, 2022

Conversation

stipsan
Copy link
Member

@stipsan stipsan commented Aug 25, 2022

Can be tested using npm i get-it@esm.
There's also a @sanity/client@esm that lets you try it out.

Changelog:

  • Prepares Semantic Release, it's blocked with a --dry-run flag for until it's run on main and we've verified it's good to go.
  • Moved to pkg.files instead of .npmignore.
  • Added GitHub Actions CI workflow that
    • Builds, lints and tests in Node LTS for ubuntu, mac and windows.
    • Runs mocha in node v12 and v18 on ubuntu.
    • Runs a new test suite that checks pkg.exports and verify they work both when imported to a .cjs and a .mjs file. Uses Node 18's new built-in test runner to ensure the testing env doesn't handle pkg.exports differently than native node ESM.
    • Adds a new testing suite that uses Node 18 and -C browser to test pkg exports when the browser conditional is active, just to catch easy mistakes like typos.
    • Adds a Deno test that runs in Node compatibilty mode to test the exports.
  • Adds pkg.exports for browser and deno that's native ESM.
  • Adds backwards compatible pkg.exports (that's why there's so many of them!) to ensure that by adding pkg.exports we're not creating a breaking change to existing node environments that works fine with get-it as it is today.
  • Compiles the ESM using esbuild in --platform=browser mode to apply pkg.browser mappings to ensure minimal changes to existing code is required, and greatly reducing the risk of regression bugs.
  • It's using type: commonjs instead of type: module for the same reason, to avoid introducing breaking changes in systems that currently work with get-it but would break if we started moving around files. By using type: commonjs and .mjs file extensions we ensure every flavor of Node.js keep working.

Why both deno and browser conditions? Because deno doesn't support browser when it's in compat mode: https://client-runtimes-dashboard.sanity.build/#:~:text=deno%2C%20import%2C%20node%2C%20node.deno%2C%20node.import

The list over supported ESM browser/deno/worker mode exports is based on looking at how get-it is commonly imported:

@stipsan stipsan marked this pull request as ready for review August 26, 2022 00:34
Copy link
Member

@rexxars rexxars left a comment

Choose a reason for hiding this comment

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

Wow. That's a huge amount of work - thank you!
Let's make sure to release this as a major version just in case?

@stipsan
Copy link
Member Author

stipsan commented Sep 14, 2022

Yeah let's err on the side of caution ⚠️

@stipsan stipsan merged commit 7d5b5a6 into main Sep 14, 2022
@stipsan stipsan deleted the esm branch September 14, 2022 21:57
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants