From f0e66010118b741484214d7152ed815c7599ee4b Mon Sep 17 00:00:00 2001 From: Jarred Sumner Date: Fri, 10 May 2024 03:55:12 -0700 Subject: [PATCH] Use `fetch`-based client in Bun MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Bun v1.0, for better overall ecosystem compatibility, we removed the `"worker"` package.json `"exports"` condition which unfortunately caused `"stripe"` to load the `"node:http"`-based implementation. This `"node:http"`-based implementation usually works fine, however there is an edgecase involving `https.Agent` having the wrong `protocol` set, (causing errors)[https://github.com/oven-sh/bun/issues/10975] when a request is retried. This is a difficult to reproduce bug in Bun and not in `stripe`. However, in Bun, `"node:http"` internally is implemented as a wrapper on top of `fetch`. So `"stripe"` might as well skip the wrapper and just use fetch instead, assuming that is not a breaking change in of itself. If we add the `BUN_JSC_dumpModuleLoadingState=1` environment variable, Bun logs some information about which modules have loaded. Bun v0.6.1: ```js ❯ BUN_JSC_dumpModuleLoadingState=1 bun-0.6.1 terminy.js 2>&1 | rg "\.esm.*.js" Loader [resolve] ./node_modules/stripe/esm/stripe.esm.worker.js Loader [fetch] ./node_modules/stripe/esm/stripe.esm.worker.js loader [parsing] ./node_modules/stripe/esm/stripe.esm.worker.js Loader [link] ./node_modules/stripe/esm/stripe.esm.worker.js Loader [evaluate] ./node_modules/stripe/esm/stripe.esm.worker.js ``` Bun v1.1.7: ```js ❯ BUN_JSC_dumpModuleLoadingState=1 bun-1.1.7 terminy.js 2>&1 | rg "\.esm.*.js" Loader [fetch] ./node_modules/stripe/esm/stripe.esm.node.js loader [parsing] ./node_modules/stripe/esm/stripe.esm.node.js Loader [link] ./node_modules/stripe/esm/stripe.esm.node.js Loader [evaluate] ./node_modules/stripe/esm/stripe.esm.node.js ``` --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index ab289d8c8b..0f37246fe0 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,10 @@ "import": "./esm/stripe.esm.worker.js", "require": "./cjs/stripe.cjs.worker.js" }, + "bun": { + "import": "./esm/stripe.esm.worker.js", + "require": "./cjs/stripe.cjs.worker.js" + }, "deno": { "import": "./esm/stripe.esm.worker.js", "require": "./cjs/stripe.cjs.worker.js"