From 252699a68678c27404f7548b7b4a20827244e04c Mon Sep 17 00:00:00 2001 From: Khafra <42794878+KhafraDev@users.noreply.github.com> Date: Fri, 8 Jul 2022 17:05:49 -0400 Subject: [PATCH 1/4] fix(fetch): re-add support for node v16.5.0+ --- lib/fetch/util.js | 8 +++++++- lib/fetch/webidl.js | 7 ++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/fetch/util.js b/lib/fetch/util.js index e309e3263f4..e94627a8354 100644 --- a/lib/fetch/util.js +++ b/lib/fetch/util.js @@ -431,6 +431,11 @@ function makeIterator (iterator, name) { return Object.setPrototypeOf({}, i) } +/** + * Fetch supports node >= 16.5.0, but Object.hasOwn was added in v16.9.0. + */ +const hasOwn = Object.hasOwn || ((dict, key) => Object.prototype.hasOwnProperty.call(dict, key)) + module.exports = { isAborted, isCancelled, @@ -463,5 +468,6 @@ module.exports = { serializeJavascriptValueToJSONString, makeIterator, isValidHeaderName, - isValidHeaderValue + isValidHeaderValue, + hasOwn } diff --git a/lib/fetch/webidl.js b/lib/fetch/webidl.js index 252dab29b83..f9a780ccaa7 100644 --- a/lib/fetch/webidl.js +++ b/lib/fetch/webidl.js @@ -1,6 +1,7 @@ 'use strict' -const { toUSVString, types } = require('util') +const { types } = require('util') +const { hasOwn, toUSVString } = require('./util') const webidl = {} webidl.converters = {} @@ -315,7 +316,7 @@ webidl.dictionaryConverter = function (converters) { const { key, defaultValue, required, converter } = options if (required === true) { - if (!Object.hasOwn(dictionary, key)) { + if (!hasOwn(dictionary, key)) { webidl.errors.exception({ header: 'Dictionary', message: `Missing required key "${key}".` @@ -324,7 +325,7 @@ webidl.dictionaryConverter = function (converters) { } let value = dictionary[key] - const hasDefault = Object.hasOwn(options, 'defaultValue') + const hasDefault = hasOwn(options, 'defaultValue') // Only use defaultValue if value is undefined and // a defaultValue options was provided. From 81fff72d7627a5abce909ba6e9f9b2867317ed19 Mon Sep 17 00:00:00 2001 From: Khafra <42794878+KhafraDev@users.noreply.github.com> Date: Fri, 8 Jul 2022 17:32:06 -0400 Subject: [PATCH 2/4] try to add node 16.5 to test matrix I tried --- .github/workflows/nodejs.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index 74f34364dfc..ae3b48311b9 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -17,6 +17,9 @@ jobs: post-test-steps: | - name: Coverage Report uses: codecov/codecov-action@v2 + include: | + - runs-on: ubuntu-latest + node-version: 16.5 automerge: if: > github.event_name == 'pull_request' && From 0a7c40c6dbe81f5d2e8dc0e999000930c73185e6 Mon Sep 17 00:00:00 2001 From: Khafra <42794878+KhafraDev@users.noreply.github.com> Date: Sat, 9 Jul 2022 15:01:51 -0400 Subject: [PATCH 3/4] fix(fetch): only support v16.7+ --- .github/workflows/nodejs.yml | 2 +- README.md | 2 +- index.js | 2 +- lib/core/request.js | 2 +- lib/fetch/constants.js | 2 +- lib/fetch/util.js | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index ae3b48311b9..bfc3a67982a 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -19,7 +19,7 @@ jobs: uses: codecov/codecov-action@v2 include: | - runs-on: ubuntu-latest - node-version: 16.5 + node-version: 16.7 automerge: if: > github.event_name == 'pull_request' && diff --git a/README.md b/README.md index 432eb265932..321ee2b94f3 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ Implements [fetch](https://fetch.spec.whatwg.org/#fetch-method). * https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch * https://fetch.spec.whatwg.org/#fetch-method -Only supported on Node 16.5+. +Only supported on Node 16.7+. This is [experimental](https://nodejs.org/api/documentation.html#documentation_stability_index) and is not yet fully compliant with the Fetch Standard. We plan to ship breaking changes to this feature until it is out of experimental. diff --git a/index.js b/index.js index 2248619749c..9ffba4655b6 100644 --- a/index.js +++ b/index.js @@ -80,7 +80,7 @@ function makeDispatcher (fn) { module.exports.setGlobalDispatcher = setGlobalDispatcher module.exports.getGlobalDispatcher = getGlobalDispatcher -if (nodeMajor > 16 || (nodeMajor === 16 && nodeMinor >= 5)) { +if (nodeMajor > 16 || (nodeMajor === 16 && nodeMinor >= 7)) { let fetchImpl = null module.exports.fetch = async function fetch (resource) { if (!fetchImpl) { diff --git a/lib/core/request.js b/lib/core/request.js index 1969f84deb1..96784c10520 100644 --- a/lib/core/request.js +++ b/lib/core/request.js @@ -140,7 +140,7 @@ class Request { } if (util.isFormDataLike(this.body)) { - if (nodeMajor < 16 || (nodeMajor === 16 && nodeMinor < 5)) { + if (nodeMajor < 16 || (nodeMajor === 16 && nodeMinor < 7)) { throw new InvalidArgumentError('Form-Data bodies are only supported in node v16.5 and newer.') } diff --git a/lib/fetch/constants.js b/lib/fetch/constants.js index 6d201e01cff..420ef0e2fea 100644 --- a/lib/fetch/constants.js +++ b/lib/fetch/constants.js @@ -63,7 +63,7 @@ const subresource = [ /** @type {globalThis['DOMException']} */ const DOMException = globalThis.DOMException ?? (() => { // DOMException was only made a global in Node v17.0.0, - // but fetch supports >= v16.5. + // but fetch supports >= v16.7. try { atob('~') } catch (err) { diff --git a/lib/fetch/util.js b/lib/fetch/util.js index e94627a8354..e6eb1461cde 100644 --- a/lib/fetch/util.js +++ b/lib/fetch/util.js @@ -432,7 +432,7 @@ function makeIterator (iterator, name) { } /** - * Fetch supports node >= 16.5.0, but Object.hasOwn was added in v16.9.0. + * Fetch supports node >= 16.7.0, but Object.hasOwn was added in v16.9.0. */ const hasOwn = Object.hasOwn || ((dict, key) => Object.prototype.hasOwnProperty.call(dict, key)) From cce41f180f9a8f9435b57b80c2310dcb74374169 Mon Sep 17 00:00:00 2001 From: Khafra <42794878+KhafraDev@users.noreply.github.com> Date: Sat, 9 Jul 2022 17:32:55 -0400 Subject: [PATCH 4/4] fix (again): fetch only supports node >=16.8.0 --- .github/workflows/nodejs.yml | 2 +- README.md | 2 +- index.js | 2 +- lib/core/request.js | 4 ++-- lib/fetch/body.js | 7 +------ lib/fetch/constants.js | 2 +- lib/fetch/util.js | 2 +- 7 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml index bfc3a67982a..921972f4711 100644 --- a/.github/workflows/nodejs.yml +++ b/.github/workflows/nodejs.yml @@ -19,7 +19,7 @@ jobs: uses: codecov/codecov-action@v2 include: | - runs-on: ubuntu-latest - node-version: 16.7 + node-version: 16.8 automerge: if: > github.event_name == 'pull_request' && diff --git a/README.md b/README.md index 321ee2b94f3..323b2ca38bb 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ Implements [fetch](https://fetch.spec.whatwg.org/#fetch-method). * https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch * https://fetch.spec.whatwg.org/#fetch-method -Only supported on Node 16.7+. +Only supported on Node 16.8+. This is [experimental](https://nodejs.org/api/documentation.html#documentation_stability_index) and is not yet fully compliant with the Fetch Standard. We plan to ship breaking changes to this feature until it is out of experimental. diff --git a/index.js b/index.js index 9ffba4655b6..b2144c844ba 100644 --- a/index.js +++ b/index.js @@ -80,7 +80,7 @@ function makeDispatcher (fn) { module.exports.setGlobalDispatcher = setGlobalDispatcher module.exports.getGlobalDispatcher = getGlobalDispatcher -if (nodeMajor > 16 || (nodeMajor === 16 && nodeMinor >= 7)) { +if (nodeMajor > 16 || (nodeMajor === 16 && nodeMinor >= 8)) { let fetchImpl = null module.exports.fetch = async function fetch (resource) { if (!fetchImpl) { diff --git a/lib/core/request.js b/lib/core/request.js index 96784c10520..0a3d8558958 100644 --- a/lib/core/request.js +++ b/lib/core/request.js @@ -140,8 +140,8 @@ class Request { } if (util.isFormDataLike(this.body)) { - if (nodeMajor < 16 || (nodeMajor === 16 && nodeMinor < 7)) { - throw new InvalidArgumentError('Form-Data bodies are only supported in node v16.5 and newer.') + if (nodeMajor < 16 || (nodeMajor === 16 && nodeMinor < 8)) { + throw new InvalidArgumentError('Form-Data bodies are only supported in node v16.8 and newer.') } if (!extractBody) { diff --git a/lib/fetch/body.js b/lib/fetch/body.js index 2228376d889..14af1251785 100644 --- a/lib/fetch/body.js +++ b/lib/fetch/body.js @@ -15,12 +15,7 @@ const { isUint8Array, isArrayBuffer } = require('util/types') let ReadableStream async function * blobGen (blob) { - if (blob.stream) { - yield * blob.stream() - } else { - // istanbul ignore next: node < 16.7 - yield await blob.arrayBuffer() - } + yield * blob.stream() } // https://fetch.spec.whatwg.org/#concept-bodyinit-extract diff --git a/lib/fetch/constants.js b/lib/fetch/constants.js index 420ef0e2fea..44a86702d62 100644 --- a/lib/fetch/constants.js +++ b/lib/fetch/constants.js @@ -63,7 +63,7 @@ const subresource = [ /** @type {globalThis['DOMException']} */ const DOMException = globalThis.DOMException ?? (() => { // DOMException was only made a global in Node v17.0.0, - // but fetch supports >= v16.7. + // but fetch supports >= v16.8. try { atob('~') } catch (err) { diff --git a/lib/fetch/util.js b/lib/fetch/util.js index e6eb1461cde..17c68162980 100644 --- a/lib/fetch/util.js +++ b/lib/fetch/util.js @@ -432,7 +432,7 @@ function makeIterator (iterator, name) { } /** - * Fetch supports node >= 16.7.0, but Object.hasOwn was added in v16.9.0. + * Fetch supports node >= 16.8.0, but Object.hasOwn was added in v16.9.0. */ const hasOwn = Object.hasOwn || ((dict, key) => Object.prototype.hasOwnProperty.call(dict, key))