From a8a7cfcbb98c5ca8fff3b4a6d8638e9208690b61 Mon Sep 17 00:00:00 2001 From: Arda TANRIKULU Date: Fri, 28 Oct 2022 04:26:12 +0300 Subject: [PATCH] fix(fetch): add duplex to RequestInit if not provided for new undici --- .changeset/olive-toes-switch.md | 5 +++++ packages/fetch/dist/create-node-ponyfill.js | 6 ++++++ packages/fetch/package.json | 2 +- yarn.lock | 10 ++++++---- 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 .changeset/olive-toes-switch.md diff --git a/.changeset/olive-toes-switch.md b/.changeset/olive-toes-switch.md new file mode 100644 index 0000000000..e658c6e071 --- /dev/null +++ b/.changeset/olive-toes-switch.md @@ -0,0 +1,5 @@ +--- +'@whatwg-node/fetch': patch +--- + +Fix for new undici diff --git a/packages/fetch/dist/create-node-ponyfill.js b/packages/fetch/dist/create-node-ponyfill.js index a62bf1e4ec..30d91102e4 100644 --- a/packages/fetch/dist/create-node-ponyfill.js +++ b/packages/fetch/dist/create-node-ponyfill.js @@ -122,6 +122,9 @@ module.exports = function createNodePonyfill(opts = {}) { class Request extends OriginalRequest { constructor(requestOrUrl, options) { if (typeof requestOrUrl === "string" || requestOrUrl instanceof URL) { + if (options != null && typeof options === "object" && !options.duplex) { + options.duplex = 'half'; + } super(requestOrUrl, options); const contentType = this.headers.get("content-type"); if (contentType && contentType.startsWith("multipart/form-data")) { @@ -140,6 +143,9 @@ module.exports = function createNodePonyfill(opts = {}) { const fetch = function (requestOrUrl, options) { if (typeof requestOrUrl === "string" || requestOrUrl instanceof URL) { + if (options != null && typeof options === "object" && !options.duplex) { + options.duplex = 'half'; + } // We cannot use our ctor because it leaks on Node 18's global fetch return originalFetch(requestOrUrl, options); } diff --git a/packages/fetch/package.json b/packages/fetch/package.json index 01a8d2dec8..5451895ed0 100644 --- a/packages/fetch/package.json +++ b/packages/fetch/package.json @@ -24,7 +24,7 @@ "form-data-encoder": "^1.7.1", "formdata-node": "^4.3.1", "node-fetch": "^2.6.7", - "undici": "^5.10.0", + "undici": "^5.12.0", "web-streams-polyfill": "^3.2.0" }, "publishConfig": { diff --git a/yarn.lock b/yarn.lock index 3998fcd890..da7d0549bf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5788,10 +5788,12 @@ unbox-primitive@^1.0.2: has-symbols "^1.0.3" which-boxed-primitive "^1.0.2" -undici@^5.10.0: - version "5.10.0" - resolved "https://registry.yarnpkg.com/undici/-/undici-5.10.0.tgz#dd9391087a90ccfbd007568db458674232ebf014" - integrity sha512-c8HsD3IbwmjjbLvoZuRI26TZic+TSEe8FPMLLOkN1AfYRhdjnKBU6yL+IwcSCbdZiX4e5t0lfMDLDCqj4Sq70g== +undici@^5.12.0: + version "5.12.0" + resolved "https://registry.yarnpkg.com/undici/-/undici-5.12.0.tgz#c758ffa704fbcd40d506e4948860ccaf4099f531" + integrity sha512-zMLamCG62PGjd9HHMpo05bSLvvwWOZgGeiWlN/vlqu3+lRo3elxktVGEyLMX+IO7c2eflLjcW74AlkhEZm15mg== + dependencies: + busboy "^1.6.0" unicode-canonical-property-names-ecmascript@^2.0.0: version "2.0.0"