Conversation
stipsan
commented
Jun 9, 2022
.eslintrc
Outdated
Member
Author
There was a problem hiding this comment.
Fixes a parse error due to the dynamic import() in client.test.js
.github/workflows/test.yml
Outdated
Member
Author
There was a problem hiding this comment.
node v12 is dead, longe live node v12 👑
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
moduleandexportstopackage.json.The files referenced are generated using
esbuild.What this solves
A lot of new, modern, environments require packages to start shipping ESM.

For example when attempting to use
@sanity/clientin a Remix site will yield an error like the one below:This is from
same-origin, which is included byget-it, which is used by@sanity/client.To solve this there's a new build command
npm run esbuild:browserthat transforms CJS to ESM and includes them in the bundle. This solves the problem, for now, buying us time to migrate these packages to ESM:Once they are shipping ESM we can stop prebundling them:
How to test
A test version is published under
npm i @sanity/client@esm.Using unpkg.com
Run this in your console (not on github as it blocks external scripts, but for example on https://sanity.io or a localhost):
Using skypack.dev
./dist/sanityClient.browser.mjsThis file is generated to run in ESM strict envs, like deno, native browser ESM using CDNs like unpkg or skypack. To do this it bundles everything (no
importorrequirecalls left) and it applies ourpkg.browserfield making sure to loadbrowserMiddleware.jsinstead ofnodeMiddleware.js../dist/sanityClient.node.cjsGenerated to run in allows calling
require, using.cjsto make it clear to modern 'node' that it's a CommonJS file.Once we have a bundler that implements module.createRequire we could consider adding a
./dist/sanityClient.node.mjsversion.pkg.moduleThis only affects bundlers that are modern enough to understand what it does, and does not trigger modern node to run in ESM module (unlike
pkg.type: "module"). It points todist/sanityClient.browser.mjsinstead ofdist/sanityClient.node.jsas it has the highest chance of bundling success sincepkg.browseris already applied to it.adding
package-checktoposttestRuns @skypack/package-check to validate we're following ESM best practices.