From 1dbe3d26b0b46b5c9df5afa0d53e1af6dfd41eeb Mon Sep 17 00:00:00 2001 From: Karol Broda Date: Fri, 26 Dec 2025 02:32:37 +0100 Subject: [PATCH 1/6] fix: use corepack to resolve pnpm version from package.json --- .github/workflows/ci.yml | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03f995b..4160e67 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,35 +2,45 @@ name: CI on: pull_request: - branches: - - main + branches: + - main push: - branches: - - main + branches: + - main merge_group: {} +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} + jobs: - test: - name: test & typecheck + ci: + name: Build, Typecheck & Test runs-on: ubuntu-latest steps: - name: Checkout repo uses: actions/checkout@v4 - - uses: pnpm/action-setup@v4 - name: Install pnpm - with: - version: 9 - run_install: false - - name: Install Node.js uses: actions/setup-node@v4 with: node-version: 20 - cache: 'pnpm' + corepack: true + + - name: Get pnpm store directory + shell: bash + run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV + + - name: Cache pnpm store + uses: actions/cache@v4 + with: + path: ${{ env.STORE_PATH }} + key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} + restore-keys: | + ${{ runner.os }}-pnpm-store- - name: Install dependencies - run: pnpm install + run: pnpm install --frozen-lockfile - name: Build run: pnpm build From 3b073ff7a5d35f58986a195bc1e34d5a7a7204e0 Mon Sep 17 00:00:00 2001 From: Karol Broda Date: Fri, 26 Dec 2025 02:45:00 +0100 Subject: [PATCH 2/6] ci: remove caching to fix empty store path --- .github/workflows/ci.yml | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4160e67..ee334fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,10 +9,6 @@ on: - main merge_group: {} -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: ${{ github.ref != 'refs/heads/main' }} - jobs: ci: name: Build, Typecheck & Test @@ -27,18 +23,6 @@ jobs: node-version: 20 corepack: true - - name: Get pnpm store directory - shell: bash - run: echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV - - - name: Cache pnpm store - uses: actions/cache@v4 - with: - path: ${{ env.STORE_PATH }} - key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} - restore-keys: | - ${{ runner.os }}-pnpm-store- - - name: Install dependencies run: pnpm install --frozen-lockfile From efa4077b4e925e03faba562447645efa9b36d9d6 Mon Sep 17 00:00:00 2001 From: Karol Broda Date: Fri, 26 Dec 2025 02:48:15 +0100 Subject: [PATCH 3/6] ci: use pnpm/action-setup without version to read from packageManager --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ee334fa..d0b9045 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,11 +17,14 @@ jobs: - name: Checkout repo uses: actions/checkout@v4 + - name: Install pnpm + uses: pnpm/action-setup@v4 + - name: Install Node.js uses: actions/setup-node@v4 with: node-version: 20 - corepack: true + cache: pnpm - name: Install dependencies run: pnpm install --frozen-lockfile From e412996f7f8c08a45111aadebcb70a960eec1a0d Mon Sep 17 00:00:00 2001 From: Karol Broda Date: Fri, 26 Dec 2025 02:51:26 +0100 Subject: [PATCH 4/6] fix: define headers variable in getBody function --- packages/better-fetch/src/utils.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/better-fetch/src/utils.ts b/packages/better-fetch/src/utils.ts index fb05686..826eb17 100644 --- a/packages/better-fetch/src/utils.ts +++ b/packages/better-fetch/src/utils.ts @@ -209,23 +209,23 @@ export function detectContentType(body: any) { } export function getBody(options?: BetterFetchOption) { - if (!options?.body) { + if (options === null || options === undefined || options.body === null || options.body === undefined) { return null; } - - let hasContentType = false; - if (options?.headers) { + + let headers: Headers | null = null; + if (options.headers !== null && options.headers !== undefined) { if (options.headers instanceof Headers) { - hasContentType = options.headers.has("content-type"); + headers = options.headers; } else if (typeof options.headers === "object") { - hasContentType = "content-type" in options.headers && - options.headers["content-type"] !== null && - options.headers["content-type"] !== undefined; + headers = new Headers(options.headers as Record); } } - + + const hasContentType = headers !== null && headers.has("content-type"); + if (isJSONSerializable(options.body) && !hasContentType) { - for (const [key, value] of Object.entries(options?.body)) { + for (const [key, value] of Object.entries(options.body)) { if (value instanceof Date) { options.body[key] = value.toISOString(); } @@ -234,6 +234,7 @@ export function getBody(options?: BetterFetchOption) { } if ( + headers !== null && headers.has("content-type") && headers.get("content-type") === "application/x-www-form-urlencoded" ) { From e011c575e808e8773e013760e08183850cc112ed Mon Sep 17 00:00:00 2001 From: Karol Broda Date: Fri, 26 Dec 2025 02:53:32 +0100 Subject: [PATCH 5/6] fix: simplify headers fix to match existing code style --- packages/better-fetch/src/utils.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/better-fetch/src/utils.ts b/packages/better-fetch/src/utils.ts index 826eb17..1ac31a4 100644 --- a/packages/better-fetch/src/utils.ts +++ b/packages/better-fetch/src/utils.ts @@ -209,12 +209,12 @@ export function detectContentType(body: any) { } export function getBody(options?: BetterFetchOption) { - if (options === null || options === undefined || options.body === null || options.body === undefined) { + if (!options?.body) { return null; } let headers: Headers | null = null; - if (options.headers !== null && options.headers !== undefined) { + if (options?.headers) { if (options.headers instanceof Headers) { headers = options.headers; } else if (typeof options.headers === "object") { @@ -222,10 +222,10 @@ export function getBody(options?: BetterFetchOption) { } } - const hasContentType = headers !== null && headers.has("content-type"); + const hasContentType = headers?.has("content-type") ?? false; if (isJSONSerializable(options.body) && !hasContentType) { - for (const [key, value] of Object.entries(options.body)) { + for (const [key, value] of Object.entries(options?.body)) { if (value instanceof Date) { options.body[key] = value.toISOString(); } @@ -233,11 +233,7 @@ export function getBody(options?: BetterFetchOption) { return JSON.stringify(options.body); } - if ( - headers !== null && - headers.has("content-type") && - headers.get("content-type") === "application/x-www-form-urlencoded" - ) { + if (headers?.get("content-type") === "application/x-www-form-urlencoded") { if (isJSONSerializable(options.body)) { return new URLSearchParams(options.body).toString(); } From 2baed86f90a3ee3f312b94b0f43ee69eb3c1b5ee Mon Sep 17 00:00:00 2001 From: Karol Broda Date: Fri, 26 Dec 2025 03:31:20 +0100 Subject: [PATCH 6/6] fix: handle array-style headers in getHeaders --- packages/better-fetch/src/utils.ts | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/packages/better-fetch/src/utils.ts b/packages/better-fetch/src/utils.ts index 1ac31a4..6b7e1f4 100644 --- a/packages/better-fetch/src/utils.ts +++ b/packages/better-fetch/src/utils.ts @@ -105,17 +105,12 @@ export async function getHeaders(opts?: BetterFetchOption) { const headers = new Headers(); if (opts?.headers) { - if (opts.headers instanceof Headers) { - opts.headers.forEach((value, key) => { - headers.set(key, value); - }); - } else { - for (const [key, value] of Object.entries(opts.headers)) { - if (value !== null && value !== undefined) { - headers.set(key, value); - } - } - } + const source = opts.headers instanceof Headers + ? opts.headers + : new Headers(opts.headers as HeadersInit); + source.forEach((value, key) => { + headers.set(key, value); + }); } const authHeader = await getAuthHeader(opts); @@ -213,14 +208,9 @@ export function getBody(options?: BetterFetchOption) { return null; } - let headers: Headers | null = null; - if (options?.headers) { - if (options.headers instanceof Headers) { - headers = options.headers; - } else if (typeof options.headers === "object") { - headers = new Headers(options.headers as Record); - } - } + const headers = options?.headers + ? new Headers(options.headers as HeadersInit) + : null; const hasContentType = headers?.has("content-type") ?? false;