Skip to content

Commit

Permalink
Support node v18 via fetch polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
dgellow committed Aug 30, 2023
1 parent 3c9d5d1 commit 51263b6
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 12 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node: [14, 16]
node: [14, 16, 18]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand All @@ -32,7 +32,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
- run: npm install
- run: npm test
env:
Expand All @@ -43,7 +43,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
- run: npm install
- run: npm run lint
docs:
Expand All @@ -52,7 +52,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 14
node-version: 18
- run: npm install
- run: npm run docs
- uses: JustinBeckwith/linkinator-action@v1
Expand Down
143 changes: 137 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "./build/src/index.js",
"bin": "./build/src/bin/release-please.js",
"scripts": {
"test": "cross-env ENVIRONMENT=test LC_ALL=en c8 mocha --recursive --timeout=5000 build/test",
"test": "cross-env ENVIRONMENT=test LC_ALL=en c8 mocha --node-option no-experimental-fetch --require build/test/_fetch-polyfill.js --recursive --timeout=5000 build/test",
"docs": "echo add docs tests",
"test:snap": "SNAPSHOT_UPDATE=1 LC_ALL=en npm test",
"clean": "gts clean",
Expand Down Expand Up @@ -51,6 +51,7 @@
"@types/lerna__run-topologically": "^5.1.0",
"@types/mocha": "^9.0.0",
"@types/node": "^18.0.0",
"@types/node-fetch": "^2.6.4",
"@types/pino": "^7.0.0",
"@types/semver": "^7.0.0",
"@types/sinon": "^10.0.0",
Expand Down Expand Up @@ -93,6 +94,7 @@
"https-proxy-agent": "^5.0.1",
"js-yaml": "^4.0.0",
"jsonpath": "^1.1.1",
"node-fetch": "^2.7.0",
"node-html-parser": "^6.0.0",
"parse-github-repo-url": "^1.4.1",
"semver": "^7.0.0",
Expand All @@ -107,4 +109,4 @@
"engines": {
"node": ">=14.0.0"
}
}
}
16 changes: 16 additions & 0 deletions test/_fetch-polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// nock, used to mock HTTP requests, currently does not support the undici network stack from node v18+. As a
// consequence node native fetch isn't supported either and won't be intercepted.
// See https://github.com/nock/nock/issues/2183 and https://github.com/nock/nock/issues/2397.
//
// This file replace the native fetch by the polyfill node-fetch when node v18 is run with the flag
// --no-experimental-fetch. That's only intended as a temporary solution, the experimental flag is expected to be
// removed starting from node v22.
import fetch, {Headers, Request, Response} from 'node-fetch';

/* eslint-disable @typescript-eslint/no-explicit-any */
if (!globalThis.fetch) {
(globalThis as any).fetch = fetch;
(globalThis as any).Headers = Headers;
(globalThis as any).Request = Request;
(globalThis as any).Response = Response;
}

0 comments on commit 51263b6

Please sign in to comment.