From 883287bc4307d93fcfd180521fd9e353a6db8bc6 Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Thu, 16 Oct 2025 11:00:44 +0300 Subject: [PATCH 1/7] fix(repo): remove npx nx from package.jsons --- packages/core/auth-js/package.json | 2 +- packages/core/storage-js/package.json | 2 +- packages/core/supabase-js/package.json | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/core/auth-js/package.json b/packages/core/auth-js/package.json index f7cad7d88..7ebf21c3e 100644 --- a/packages/core/auth-js/package.json +++ b/packages/core/auth-js/package.json @@ -29,7 +29,7 @@ "clean": "rimraf dist docs", "coverage": "echo \"run npm test\"", "build:node18": "npm run clean && npm run build:main && npm run build:module", - "build": "npm run clean && npx nx build:main auth-js && npx nx build:module auth-js", + "build": "npm run clean && npm run build:main && npm run build:module", "build:main": "tsc -p tsconfig.json", "build:module": "tsc -p tsconfig.module.json", "test:auth": "npm run test:clean && npm run test:infra && npm run test:suite && npm run test:clean", diff --git a/packages/core/storage-js/package.json b/packages/core/storage-js/package.json index 789519e13..40c3c3073 100644 --- a/packages/core/storage-js/package.json +++ b/packages/core/storage-js/package.json @@ -26,7 +26,7 @@ }, "scripts": { "clean": "rimraf dist docs/v2", - "build": "npx nx clean storage-js && npx nx build:main storage-js && npx nx build:module storage-js && npx nx build:umd storage-js", + "build": "npm run clean && npm run build:main && npm run build:module && npm run build:umd", "build:main": "tsc -p tsconfig.json", "build:module": "tsc -p tsconfig.module.json", "build:umd": "webpack", diff --git a/packages/core/supabase-js/package.json b/packages/core/supabase-js/package.json index e2c584be7..55b767779 100644 --- a/packages/core/supabase-js/package.json +++ b/packages/core/supabase-js/package.json @@ -26,12 +26,12 @@ }, "scripts": { "clean": "rimraf dist docs/v2", - "build": "npm run clean && npx nx build:main supabase-js && npx nx build:module supabase-js && npx nx build:umd supabase-js", + "build": "npm run clean && npm run build:main && npm run build:module && npm run build:umd", "build:main": "tsc -p tsconfig.json", "build:module": "tsc -p tsconfig.module.json", "build:umd": "webpack --env mode=production", - "test": "npx nx test:types supabase-js && npx nx test:run supabase-js", - "test:all": "npx nx test:types supabase-js && npx nx test:run supabase-js && npx nx test:integration supabase-js && npx nx test:integration:browser supabase-js", + "test": "npm run test:types && npm run test:run", + "test:all": "npm run test:types && npm run test:run && npm run test:integration && npm run test:integration:browser", "test:run": "jest --runInBand --detectOpenHandles", "test:unit": "jest --runInBand --detectOpenHandles test/unit", "test:coverage": "jest --runInBand --coverage --testPathIgnorePatterns=\"test/integration|test/deno\"", @@ -41,7 +41,7 @@ "test:watch": "jest --watch --verbose false --silent false", "test:node:playwright": "cd test/integration/node-browser && npm install && cp ../../../dist/umd/supabase.js . && npm run test", "test:bun": "cd test/integration/bun && bun install && bun test", - "test:types": "npx nx build:module supabase-js && tsd --files test/types/*.test-d.ts && jsr publish --dry-run --allow-dirty", + "test:types": "npm run build:module && tsd --files test/types/*.test-d.ts && jsr publish --dry-run --allow-dirty", "docs": "typedoc --entryPoints src/index.ts --out docs/v2", "docs:json": "typedoc --entryPoints src/index.ts --json docs/v2/spec.json --excludeExternals", "serve:coverage": "npx nx test:coverage supabase-js && serve test/coverage", From 6f19c9740963f1712c02fd93274c409e6a0865f1 Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Thu, 16 Oct 2025 11:17:11 +0300 Subject: [PATCH 2/7] fix(repo): codegen checks --- .github/workflows/ci-core.yml | 3 + .husky/pre-commit | 15 +++ package.json | 2 + packages/core/postgrest-js/package.json | 1 - .../src/lib/rest/types/common/common.ts | 11 ++ .../src/lib/rest/types/common/rpc.ts | 10 ++ scripts/sync-common-types.js | 110 ++++++++++++++++++ 7 files changed, 151 insertions(+), 1 deletion(-) create mode 100755 .husky/pre-commit create mode 100755 scripts/sync-common-types.js diff --git a/.github/workflows/ci-core.yml b/.github/workflows/ci-core.yml index 276c54015..0c995cc22 100644 --- a/.github/workflows/ci-core.yml +++ b/.github/workflows/ci-core.yml @@ -44,6 +44,9 @@ jobs: # Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud # - run: npx nx-cloud record -- echo Hello World # When you enable task distribution, run the e2e-ci task instead of e2e + - name: Check generated types are in sync + run: npm run codegen:check + - name: Build affected packages run: npx nx affected --target=build diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 000000000..5107c906e --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,15 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +# Check if postgrest-js common types were modified +if git diff --cached --name-only | grep -q "packages/core/postgrest-js/src/types/common/"; then + echo "šŸ“ Detected changes in postgrest-js common types..." + echo "šŸ”„ Running codegen to sync types..." + + npm run codegen + + # Add the generated files to the commit + git add packages/core/supabase-js/src/lib/rest/types/common/ + + echo "āœ… Generated types have been updated and staged" +fi diff --git a/package.json b/package.json index dd3b3ede9..9e4d9bbab 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,8 @@ "scripts": { "commit": "cz", "prepare": "husky", + "codegen": "node scripts/sync-common-types.js", + "codegen:check": "node scripts/sync-common-types.js && git diff --exit-code packages/core/supabase-js/src/lib/rest/types/common || (echo '\nāŒ Generated types are out of sync.\n Run: npm run codegen\n Then commit the changes.\n' && exit 1)", "release-canary": "npx tsx scripts/release-canary.ts", "release-stable": "npx tsx scripts/release-stable.ts" }, diff --git a/packages/core/postgrest-js/package.json b/packages/core/postgrest-js/package.json index d71ad18bd..c10192cf2 100644 --- a/packages/core/postgrest-js/package.json +++ b/packages/core/postgrest-js/package.json @@ -37,7 +37,6 @@ "format": "node scripts/format.js", "format:check": "node scripts/format.js check", "build": "npm run clean && npm run build:cjs && npm run build:esm", - "postbuild": "cp -rf ./src/types/common ../supabase-js/src/lib/rest/types/common", "build:cjs": "tsc -p tsconfig.json", "build:esm": "cpy wrapper.mjs dist/esm/", "docs": "typedoc src/index.ts --out docs/v2", diff --git a/packages/core/supabase-js/src/lib/rest/types/common/common.ts b/packages/core/supabase-js/src/lib/rest/types/common/common.ts index 9ad962ef5..cfdc04755 100644 --- a/packages/core/supabase-js/src/lib/rest/types/common/common.ts +++ b/packages/core/supabase-js/src/lib/rest/types/common/common.ts @@ -1,3 +1,13 @@ +/** + * AUTO-GENERATED FILE - DO NOT EDIT + * + * This file is automatically synchronized from @supabase/postgrest-js + * Source: packages/core/postgrest-js/src/types/common/ + * + * To update this file, modify the source in postgrest-js and run: + * npm run codegen + */ + // Types that are shared between supabase-js and postgrest-js export type Fetch = typeof fetch @@ -54,3 +64,4 @@ export type GenericSchema = { export type ClientServerOptions = { PostgrestVersion?: string } + diff --git a/packages/core/supabase-js/src/lib/rest/types/common/rpc.ts b/packages/core/supabase-js/src/lib/rest/types/common/rpc.ts index 52e57419a..fe457bded 100644 --- a/packages/core/supabase-js/src/lib/rest/types/common/rpc.ts +++ b/packages/core/supabase-js/src/lib/rest/types/common/rpc.ts @@ -1,3 +1,13 @@ +/** + * AUTO-GENERATED FILE - DO NOT EDIT + * + * This file is automatically synchronized from @supabase/postgrest-js + * Source: packages/core/postgrest-js/src/types/common/ + * + * To update this file, modify the source in postgrest-js and run: + * npm run codegen + */ + import type { GenericFunction, GenericSchema, GenericSetofOption } from './common' // Functions matching utils diff --git a/scripts/sync-common-types.js b/scripts/sync-common-types.js new file mode 100755 index 000000000..b31c66016 --- /dev/null +++ b/scripts/sync-common-types.js @@ -0,0 +1,110 @@ +#!/usr/bin/env node + +/** + * Sync common type definitions from postgrest-js to supabase-js + * + * This script copies shared type definitions from @supabase/postgrest-js + * to @supabase/supabase-js to ensure type compatibility across complex + * generic types and conditional types. + * + * Source of truth: packages/core/postgrest-js/src/types/common/ + * Destination: packages/core/supabase-js/src/lib/rest/types/common/ + */ + +const fs = require('fs') +const path = require('path') +const crypto = require('crypto') + +const SOURCE_DIR = path.join(__dirname, '../packages/core/postgrest-js/src/types/common') +const DEST_DIR = path.join(__dirname, '../packages/core/supabase-js/src/lib/rest/types/common') + +const HEADER_COMMENT = `/** + * AUTO-GENERATED FILE - DO NOT EDIT + * + * This file is automatically synchronized from @supabase/postgrest-js + * Source: packages/core/postgrest-js/src/types/common/ + * + * To update this file, modify the source in postgrest-js and run: + * npm run codegen + */ + +` + +function getFileHash(filePath) { + if (!fs.existsSync(filePath)) return null + const content = fs.readFileSync(filePath, 'utf8') + return crypto.createHash('md5').update(content).digest('hex') +} + +function stripGeneratedHeader(content) { + // Remove existing AUTO-GENERATED header if present + const headerRegex = /^\/\*\*\s*\n\s*\*\s*AUTO-GENERATED FILE[\s\S]*?\*\/\s*\n\s*\n/ + return content.replace(headerRegex, '') +} + +function syncFile(fileName) { + const sourcePath = path.join(SOURCE_DIR, fileName) + const destPath = path.join(DEST_DIR, fileName) + + if (!fs.existsSync(sourcePath)) { + console.error(`āŒ Source file not found: ${sourcePath}`) + process.exit(1) + } + + const sourceContent = fs.readFileSync(sourcePath, 'utf8') + const sourceHash = crypto.createHash('md5').update(sourceContent).digest('hex') + + // Check if destination exists and compare content (excluding header) + let needsUpdate = true + if (fs.existsSync(destPath)) { + const destContent = fs.readFileSync(destPath, 'utf8') + const destContentStripped = stripGeneratedHeader(destContent) + const destHash = crypto.createHash('md5').update(destContentStripped).digest('hex') + + if (sourceHash === destHash) { + needsUpdate = false + } + } + + if (needsUpdate) { + const contentWithHeader = HEADER_COMMENT + sourceContent + fs.writeFileSync(destPath, contentWithHeader, 'utf8') + console.log(`āœ… Synced: ${fileName}`) + return true + } else { + console.log(`ā­ļø Unchanged: ${fileName}`) + return false + } +} + +function main() { + console.log('šŸ”„ Syncing common types from postgrest-js to supabase-js...\n') + + // Ensure destination directory exists + if (!fs.existsSync(DEST_DIR)) { + fs.mkdirSync(DEST_DIR, { recursive: true }) + console.log(`šŸ“ Created directory: ${DEST_DIR}\n`) + } + + // Get all .ts files from source directory + const sourceFiles = fs.readdirSync(SOURCE_DIR).filter(file => file.endsWith('.ts')) + + if (sourceFiles.length === 0) { + console.error(`āŒ No TypeScript files found in ${SOURCE_DIR}`) + process.exit(1) + } + + let changedCount = 0 + for (const file of sourceFiles) { + const changed = syncFile(file) + if (changed) changedCount++ + } + + console.log(`\n✨ Sync complete: ${changedCount} file(s) updated, ${sourceFiles.length - changedCount} unchanged`) + + if (changedCount > 0) { + console.log('\nāš ļø Generated files were updated. Please commit these changes.') + } +} + +main() From ec36461bcfcdb0d25769d666c75b352ce41ebfa7 Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Thu, 16 Oct 2025 11:18:47 +0300 Subject: [PATCH 3/7] fix(repo): husky syntax --- .husky/pre-commit | 3 --- 1 file changed, 3 deletions(-) diff --git a/.husky/pre-commit b/.husky/pre-commit index 5107c906e..508cc4dce 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,6 +1,3 @@ -#!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" - # Check if postgrest-js common types were modified if git diff --cached --name-only | grep -q "packages/core/postgrest-js/src/types/common/"; then echo "šŸ“ Detected changes in postgrest-js common types..." From 6a4b145e4c03c5fa639289915329ee1ac4e152c9 Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Thu, 16 Oct 2025 11:26:52 +0300 Subject: [PATCH 4/7] chore(repo): update common types --- packages/core/supabase-js/src/lib/rest/types/common/common.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/supabase-js/src/lib/rest/types/common/common.ts b/packages/core/supabase-js/src/lib/rest/types/common/common.ts index cfdc04755..8e38dd231 100644 --- a/packages/core/supabase-js/src/lib/rest/types/common/common.ts +++ b/packages/core/supabase-js/src/lib/rest/types/common/common.ts @@ -64,4 +64,3 @@ export type GenericSchema = { export type ClientServerOptions = { PostgrestVersion?: string } - From 43232f1609042a49bc95a3953931b30e075a7a69 Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Thu, 16 Oct 2025 11:30:48 +0300 Subject: [PATCH 5/7] chore(repo): fix codegen script --- scripts/sync-common-types.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/scripts/sync-common-types.js b/scripts/sync-common-types.js index b31c66016..31ca48d3f 100755 --- a/scripts/sync-common-types.js +++ b/scripts/sync-common-types.js @@ -52,23 +52,21 @@ function syncFile(fileName) { } const sourceContent = fs.readFileSync(sourcePath, 'utf8') - const sourceHash = crypto.createHash('md5').update(sourceContent).digest('hex') + const expectedContent = HEADER_COMMENT + sourceContent - // Check if destination exists and compare content (excluding header) + // Check if destination exists and compare with what we would generate let needsUpdate = true if (fs.existsSync(destPath)) { const destContent = fs.readFileSync(destPath, 'utf8') - const destContentStripped = stripGeneratedHeader(destContent) - const destHash = crypto.createHash('md5').update(destContentStripped).digest('hex') - if (sourceHash === destHash) { + // Compare the full expected output with the current file + if (destContent === expectedContent) { needsUpdate = false } } if (needsUpdate) { - const contentWithHeader = HEADER_COMMENT + sourceContent - fs.writeFileSync(destPath, contentWithHeader, 'utf8') + fs.writeFileSync(destPath, expectedContent, 'utf8') console.log(`āœ… Synced: ${fileName}`) return true } else { From 17fd379bfa0f0dc51a0990f9ebb35b9c6b6a688c Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Thu, 16 Oct 2025 11:32:40 +0300 Subject: [PATCH 6/7] chore(repo): error message and success message --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9e4d9bbab..a56b49e71 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "commit": "cz", "prepare": "husky", "codegen": "node scripts/sync-common-types.js", - "codegen:check": "node scripts/sync-common-types.js && git diff --exit-code packages/core/supabase-js/src/lib/rest/types/common || (echo '\nāŒ Generated types are out of sync.\n Run: npm run codegen\n Then commit the changes.\n' && exit 1)", + "codegen:check": "node scripts/sync-common-types.js && git diff --exit-code packages/core/supabase-js/src/lib/rest/types/common && echo '\nāœ… Generated types are in sync!' || (echo '\nāŒ Generated types are out of sync.\n Run: npm run codegen\n Then commit the changes.\n' && exit 1)", "release-canary": "npx tsx scripts/release-canary.ts", "release-stable": "npx tsx scripts/release-stable.ts" }, From 56abf4c97f6eca65d39c3fa9c82a52d341b8d049 Mon Sep 17 00:00:00 2001 From: Katerina Skroumpelou Date: Thu, 16 Oct 2025 11:38:46 +0300 Subject: [PATCH 7/7] chore(repo): remove unused methods --- scripts/sync-common-types.js | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/scripts/sync-common-types.js b/scripts/sync-common-types.js index 31ca48d3f..467f8d2c6 100755 --- a/scripts/sync-common-types.js +++ b/scripts/sync-common-types.js @@ -13,7 +13,6 @@ const fs = require('fs') const path = require('path') -const crypto = require('crypto') const SOURCE_DIR = path.join(__dirname, '../packages/core/postgrest-js/src/types/common') const DEST_DIR = path.join(__dirname, '../packages/core/supabase-js/src/lib/rest/types/common') @@ -30,18 +29,6 @@ const HEADER_COMMENT = `/** ` -function getFileHash(filePath) { - if (!fs.existsSync(filePath)) return null - const content = fs.readFileSync(filePath, 'utf8') - return crypto.createHash('md5').update(content).digest('hex') -} - -function stripGeneratedHeader(content) { - // Remove existing AUTO-GENERATED header if present - const headerRegex = /^\/\*\*\s*\n\s*\*\s*AUTO-GENERATED FILE[\s\S]*?\*\/\s*\n\s*\n/ - return content.replace(headerRegex, '') -} - function syncFile(fileName) { const sourcePath = path.join(SOURCE_DIR, fileName) const destPath = path.join(DEST_DIR, fileName) @@ -85,7 +72,7 @@ function main() { } // Get all .ts files from source directory - const sourceFiles = fs.readdirSync(SOURCE_DIR).filter(file => file.endsWith('.ts')) + const sourceFiles = fs.readdirSync(SOURCE_DIR).filter((file) => file.endsWith('.ts')) if (sourceFiles.length === 0) { console.error(`āŒ No TypeScript files found in ${SOURCE_DIR}`) @@ -98,7 +85,9 @@ function main() { if (changed) changedCount++ } - console.log(`\n✨ Sync complete: ${changedCount} file(s) updated, ${sourceFiles.length - changedCount} unchanged`) + console.log( + `\n✨ Sync complete: ${changedCount} file(s) updated, ${sourceFiles.length - changedCount} unchanged` + ) if (changedCount > 0) { console.log('\nāš ļø Generated files were updated. Please commit these changes.')