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: full Node.js ESM runtime support #54

Merged
merged 1 commit into from Jan 4, 2023
Merged

feat: full Node.js ESM runtime support #54

merged 1 commit into from Jan 4, 2023

Conversation

stipsan
Copy link
Member

@stipsan stipsan commented Jan 4, 2023

BREAKING CHANGE: umd builds are removed and all middleware imports are moved to get-it/middleware. Imports such as import promise from 'get-it/lib-node/middleware/promise' are no longer supported. The default import is replaced with a named one: change import getIt from 'get-it' to import {getIt} from 'get-it'

Other changes

  • Migrated codebase to TypeScript, moving away from using any is out of scope for this PR but linter rules are setup to make it easier to do this refactor in a later PR.
  • The required Node.js version is moved from 12 to 14, as 12 does not support pkg.exports.
  • Tooling have moved to @sanity/pkg-utils, gone is @babel/cli, browserify, esbuild, uglifyjs, and more.
  • Replaced mocha testing suite with vitest to ensure the new ESM codebase runs the same way it'll run in production with codebases such as sanity.
  • The pkg.exports are refactored to follow our updated ESM best practices, spearheaded by @sanity/pkg-utils. It implements the Node.js dual package hazard technique to steer the Node.js ESM runtime back into CJS mode as half our dependencies aren't shipping ESM-runtime code yet.
  • The pkg.exports and build setup is also configured to generate browser code that is picked up by modern and legacy bundlers alike. It no longer uses pkg.browser to redirect package imports, instead there's index.ts and index.browser.ts entrypoints, and middleware.ts and middleware.browser.ts. These entrypoints use different imports on things that diverge depending on wether it's a node or browser runtime environment. The generated bundles are then self-contained and have much wider support than today's super-complex pkg.exports and pkg.browser.
  • pkg.type is changed from commonjs to module.
  • Added pkg.sideEffects: false to enable much better tree-shaking in bundlers such as webpack.
  • Now shipping TypeScript types.
  • The Deno testing suite is updated to follow current best practice for deno's node.js interop.
  • Generated JS is now using the same browserslist setup as we do in the rest of our modern ecosystem as well as sanity.
  • All dependencies have been updated, to their latest version that still ships code that can run in both Node.js CJS and ESM runtimes.
  • Some packages have been inlined as they proved too problematic to use with TypeScript, such as @sanity/timed-out and simple-concat
  • Adds a Lock thread workflow that locks closed issues and PRs to avoid people commenting on them as we don't get notified by that, and it's best to help nudge people towards making new issues instead.
  • Also adds a prettier workflow that runs prettier if a push to main forgot to apply it.

@stipsan stipsan force-pushed the modernize branch 9 times, most recently from 9613cba to 273a2af Compare January 4, 2023 01:54
// Due to the testing server setup concurrency isn't supported
threads: false,
deps: {
interopDefault: true,
Copy link
Member Author

Choose a reason for hiding this comment

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

Needed since we use CJS-only dependencies such as create-error-class

@@ -1,7 +0,0 @@
// The EdgeRuntime check is to support dead-code elimination on Vercel Edge Functions:
// https://edge-runtime.vercel.sh/features/available-apis#addressing-the-runtime
if (typeof EdgeRuntime === 'string') {
Copy link
Member Author

Choose a reason for hiding this comment

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

I strongly believe the Vercel EdgeRuntime should implement pkg.exports instead of requiring us to do stuff like this 😅

node/index.js Outdated Show resolved Hide resolved
@stipsan stipsan marked this pull request as ready for review January 4, 2023 02:04
@stipsan stipsan force-pushed the modernize branch 4 times, most recently from a4ac9cf to db8f501 Compare January 4, 2023 12:45
BREAKING CHANGE: umd builds are removed and all middleware imports are moved to `get-it/middleware`. Imports such as `import promise from 'get-it/lib-node/middleware/promise'` are no longer supported.
@stipsan stipsan merged commit ab8a4fd into main Jan 4, 2023
@stipsan stipsan deleted the modernize branch January 4, 2023 12:58
@github-actions
Copy link
Contributor

github-actions bot commented Jan 4, 2023

🎉 This PR is included in version 8.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants