From effc03d58793328595183ac7cd5c9abab95dec17 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Wed, 7 Sep 2022 16:43:52 +0300 Subject: [PATCH] Bun Support --- .changeset/strong-penguins-begin.md | 6 ++++++ packages/fetch/dist/create-node-ponyfill.js | 5 +++++ packages/server/src/index.ts | 6 +++++- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 .changeset/strong-penguins-begin.md diff --git a/.changeset/strong-penguins-begin.md b/.changeset/strong-penguins-begin.md new file mode 100644 index 0000000000..002437b27e --- /dev/null +++ b/.changeset/strong-penguins-begin.md @@ -0,0 +1,6 @@ +--- +'@whatwg-node/fetch': minor +'@whatwg-node/server': minor +--- + +Bun Support diff --git a/packages/fetch/dist/create-node-ponyfill.js b/packages/fetch/dist/create-node-ponyfill.js index ad0201aa12..d3627344c6 100644 --- a/packages/fetch/dist/create-node-ponyfill.js +++ b/packages/fetch/dist/create-node-ponyfill.js @@ -2,6 +2,11 @@ const handleFileRequest = require("./handle-file-request"); module.exports = function createNodePonyfill(opts = {}) { + // Bun already has a Fetch API + if (process.versions.bun) { + return globalThis; + } + const ponyfills = {}; if (!opts.useNodeFetch) { diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index cec2711e6b..115734d384 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -49,7 +49,7 @@ export interface ServerAdapterObject extends EventListenerObject } export type ServerAdapter = TBaseObject & - RequestListener & + RequestListener & ServerAdapterObject['fetch'] & ServerAdapterObject; export function createServerAdapter< @@ -104,6 +104,10 @@ export function createServerAdapter< }; function genericRequestHandler(input: any, ctx: any) { + if ('process' in globalThis && process.versions?.['bun'] != null) { + // This is required for bun + input.text(); + } // If it is a Node request if (isReadable(input) && ctx != null && isServerResponse(ctx)) { return requestListener(input as unknown as NodeRequest, ctx);