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: support modern bundlers browser mode #24

Merged
merged 1 commit into from Aug 24, 2022

Conversation

stipsan
Copy link
Member

@stipsan stipsan commented Aug 19, 2022

This is based on #13 but far less ambitious.

What is the point of this PR then?
It's to add a pkg.exports.browsers so that browser targeted bundling works in modern bundlers that doesn't support pkg.browser.

What about ESM?
This PR improves that story slightly, not because the generated sanityClient.browser.mjs is ESM formatted, but only because esbuild that generates it understands pkg.browsers and makes sure to use src/http/browserMiddleware.js instead of src/http/nodeMiddleware.js.
This means that bundlers that are currently failing to build @sanity/client due to it attempting to bundle get-it/lib-node/middleware/* and its dependencies, such as skypack:

await import('https://cdn.skypack.dev/@sanity/client')
// GET https://cdn.skypack.dev/-/speedometer@v1.0.0-7ZqxVFTYH3353ZTAOfaN/dist=es2019,mode=raw/speedometer net::ERR_ABORTED 404

will now start working again with this PR.

I'll revisit #13 once all the upstream deps are ESM. That includes the node part of it as I need more time testing node 16 and its different modes with the new pkg.exports.node to fully understand how it works and how we should wield it.

@stipsan stipsan requested a review from rexxars August 19, 2022 02:00
@stipsan stipsan mentioned this pull request Aug 19, 2022
@rexxars rexxars merged commit 3b63119 into main Aug 24, 2022
@rexxars rexxars deleted the support-modern-browser-mode branch August 24, 2022 19:31
@rexxars
Copy link
Member

rexxars commented Aug 24, 2022

Thanks a bunch!

rexxars pushed a commit that referenced this pull request Aug 24, 2022
Adds tests for new runtimes: [Bun](https://bun.sh/), [Deno](https://deno.land/) and the [Edge runtime](https://edge-runtime.vercel.sh/). I wanted to add tests for node16 ESM modes as well as Cloudflare Workers and react-native maybe. But I'm out of time and it's best to get in what we have and follow up with new PRs.

The Deno test is expected [to keep failing](https://github.com/sanity-io/client/runs/7849905824?check_suite_focus=true#step:5:201) until [`get-it` gets a similar](https://github.com/sanity-io/get-it/blob/7873e3fb4f38c21fe91f727f65acca250bc6c5f0/package.json#L9-L23) fix as #24
stipsan added a commit that referenced this pull request Aug 27, 2022
…ironments that bundle for the browser, such as Next.js. Remove `pkg.exports` until what we ship there is 100% compatible with the ecosystem.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 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.

None yet

2 participants