From 49a4386471021a785b62491c5f9ea4c8d15caebb Mon Sep 17 00:00:00 2001 From: Josh Kelley Date: Wed, 18 Oct 2023 04:20:46 -0400 Subject: [PATCH] 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 --- .github/workflows/ci.yml | 23 +++++-------------- .github/workflows/release.yml | 42 +++++++++++++++++++++++++++++++++++ src/Headers.ts | 7 +++--- 3 files changed, 51 insertions(+), 21 deletions(-) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f312deb..25da508 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,12 +5,14 @@ on: branches: - main pull_request: - branches: - - main + workflow_dispatch: jobs: build: runs-on: ubuntu-latest + strategy: + matrix: + node-version: [16, 18] steps: - name: Checkout uses: actions/checkout@v2 @@ -21,27 +23,12 @@ jobs: - name: Setup Node.js uses: actions/setup-node@v3 with: - node-version: 16 + node-version: ${{ matrix.node-version }} always-auth: true cache: yarn - - name: Setup Git - run: | - git config --local user.name "kettanaito" - git config --local user.email "kettanaito@gmail.com" - - name: Install dependencies run: yarn install --frozen-lockfile - name: Unit tests run: yarn test - - - name: Build - run: yarn build - - - name: Release - if: contains(github.ref, 'refs/heads/main') - run: yarn release - env: - GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }} - NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b30cfb3 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,42 @@ +name: release + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + token: ${{ secrets.GH_ADMIN_TOKEN }} + + - name: Setup Node.js + uses: actions/setup-node@v3 + with: + node-version: 18 + always-auth: true + cache: yarn + + - name: Setup Git + run: | + git config --local user.name "kettanaito" + git config --local user.email "kettanaito@gmail.com" + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Build + run: yarn build + + - name: Release + if: contains(github.ref, 'refs/heads/main') + run: yarn release + env: + GITHUB_TOKEN: ${{ secrets.GH_ADMIN_TOKEN }} + NPM_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/src/Headers.ts b/src/Headers.ts index 0d5d8c9..1297435 100644 --- a/src/Headers.ts +++ b/src/Headers.ts @@ -21,12 +21,13 @@ export class Headers { constructor(init?: HeadersInit | HeadersObject | HeadersList) { /** - * @note Cannot check if the `init` is an instance of the `Headers` - * because that class is only defined in the browser. + * @note Cannot necessarily check if the `init` is an instance of the + * `Headers` because that class may not be defined in Node or jsdom. */ if ( ['Headers', 'HeadersPolyfill'].includes(init?.constructor.name) || - init instanceof Headers + init instanceof Headers || + (typeof globalThis.Headers !== 'undefined' && init instanceof globalThis.Headers) ) { const initialHeaders = init as Headers initialHeaders.forEach((value, name) => {