Skip to content

Commit 49a4386

Browse files
joshkelkettanaito
andauthored
fix: support global "_Headers" in Undici 5.26.3 (#73)
Node.js's update to Undici 5.26.3 caused its `Headers` class to be called `_Headers`: https://github.com/nodejs/node/pull/50153/files#diff-f516ab824a7722da938a4c7c851520d39731ddeb4f7198dff4e932c5d4f8fdf7 Fixes #72. --------- Co-authored-by: Artem Zakharchenko <kettanaito@gmail.com>
1 parent cab2ae2 commit 49a4386

3 files changed

Lines changed: 51 additions & 21 deletions

File tree

.github/workflows/ci.yml

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ on:
55
branches:
66
- main
77
pull_request:
8-
branches:
9-
- main
8+
workflow_dispatch:
109

1110
jobs:
1211
build:
1312
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
node-version: [16, 18]
1416
steps:
1517
- name: Checkout
1618
uses: actions/checkout@v2
@@ -21,27 +23,12 @@ jobs:
2123
- name: Setup Node.js
2224
uses: actions/setup-node@v3
2325
with:
24-
node-version: 16
26+
node-version: ${{ matrix.node-version }}
2527
always-auth: true
2628
cache: yarn
2729

28-
- name: Setup Git
29-
run: |
30-
git config --local user.name "kettanaito"
31-
git config --local user.email "kettanaito@gmail.com"
32-
3330
- name: Install dependencies
3431
run: yarn install --frozen-lockfile
3532

3633
- name: Unit tests
3734
run: yarn test
38-
39-
- name: Build
40-
run: yarn build
41-
42-
- name: Release
43-
if: contains(github.ref, 'refs/heads/main')
44-
run: yarn release
45-
env:
46-
GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }}
47-
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/release.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
publish:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
token: ${{ secrets.GH_ADMIN_TOKEN }}
18+
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v3
21+
with:
22+
node-version: 18
23+
always-auth: true
24+
cache: yarn
25+
26+
- name: Setup Git
27+
run: |
28+
git config --local user.name "kettanaito"
29+
git config --local user.email "kettanaito@gmail.com"
30+
31+
- name: Install dependencies
32+
run: yarn install --frozen-lockfile
33+
34+
- name: Build
35+
run: yarn build
36+
37+
- name: Release
38+
if: contains(github.ref, 'refs/heads/main')
39+
run: yarn release
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }}
42+
NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

src/Headers.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ export class Headers {
2121

2222
constructor(init?: HeadersInit | HeadersObject | HeadersList) {
2323
/**
24-
* @note Cannot check if the `init` is an instance of the `Headers`
25-
* because that class is only defined in the browser.
24+
* @note Cannot necessarily check if the `init` is an instance of the
25+
* `Headers` because that class may not be defined in Node or jsdom.
2626
*/
2727
if (
2828
['Headers', 'HeadersPolyfill'].includes(init?.constructor.name) ||
29-
init instanceof Headers
29+
init instanceof Headers ||
30+
(typeof globalThis.Headers !== 'undefined' && init instanceof globalThis.Headers)
3031
) {
3132
const initialHeaders = init as Headers
3233
initialHeaders.forEach((value, name) => {

0 commit comments

Comments
 (0)