From b3b448caf1342617f75694c0a8b44393851f320b Mon Sep 17 00:00:00 2001 From: Wojtek Majewski Date: Sat, 15 Nov 2025 19:08:00 +0100 Subject: [PATCH] refactor: use realpath and consistent cwd in supabase-start-locked.sh - Replace cd && pwd with realpath for cleaner code - Standardize all project.json to use cwd: {projectRoot} - Remove unnecessary cd {projectRoot} commands - Use consistent ../../scripts/supabase-start-locked.sh . pattern --- pkgs/cli/project.json | 2 +- pkgs/client/project.json | 18 +++-- pkgs/client/tsconfig.typecheck.json | 3 +- pkgs/client/vitest.typecheck.config.ts | 1 + pkgs/core/project.json | 70 +++++++++---------- pkgs/core/tsconfig.typecheck.json | 3 +- pkgs/core/vite.config.ts | 2 +- pkgs/core/vitest.typecheck.config.ts | 22 ++++++ .../__tests__/types/array-method.test-d.ts | 33 ++------- pkgs/dsl/project.json | 6 +- pkgs/dsl/tsconfig.typecheck.json | 4 +- pkgs/dsl/vite.config.ts | 2 +- pkgs/dsl/vitest.typecheck.config.ts | 22 ++++++ pkgs/edge-worker/project.json | 36 +++++----- pkgs/website/project.json | 6 +- scripts/supabase-start-locked.sh | 2 +- 16 files changed, 126 insertions(+), 106 deletions(-) create mode 100644 pkgs/core/vitest.typecheck.config.ts create mode 100644 pkgs/dsl/vitest.typecheck.config.ts diff --git a/pkgs/cli/project.json b/pkgs/cli/project.json index e4299e71f..e387a77d8 100644 --- a/pkgs/cli/project.json +++ b/pkgs/cli/project.json @@ -77,7 +77,7 @@ "options": { "commands": [ "rm -rf supabase/", - "npx -y supabase@latest init --with-vscode-settings --with-intellij-settings", + "npx -y supabase@latest init --force --with-vscode-settings --with-intellij-settings", "node dist/index.js compile examples/analyze_website.ts --deno-json examples/deno.json --supabase-path supabase", "./scripts/assert-flow-compiled" ], diff --git a/pkgs/client/project.json b/pkgs/client/project.json index e1b7eb196..6254edd44 100644 --- a/pkgs/client/project.json +++ b/pkgs/client/project.json @@ -63,9 +63,9 @@ "local": true, "cache": false, "options": { - "cwd": "{workspaceRoot}", + "cwd": "{projectRoot}", "commands": [ - "scripts/supabase-start-locked.sh {projectRoot}" + "../../scripts/supabase-start-locked.sh ." ], "parallel": false } @@ -75,8 +75,8 @@ "local": true, "cache": false, "options": { - "cwd": "{workspaceRoot}", - "commands": ["scripts/supabase-start-locked.sh {projectRoot}"], + "cwd": "{projectRoot}", + "commands": ["../../scripts/supabase-start-locked.sh ."], "parallel": false } }, @@ -129,10 +129,10 @@ "cache": false, "dependsOn": ["supabase:prepare"], "options": { - "cwd": "{workspaceRoot}", + "cwd": "{projectRoot}", "commands": [ - "scripts/supabase-start-locked.sh {projectRoot}", - "cd {projectRoot} && supabase db reset" + "../../scripts/supabase-start-locked.sh .", + "supabase db reset" ], "parallel": false } @@ -202,9 +202,7 @@ }, "test:types:vitest": { "executor": "nx:run-commands", - "cache": true, - "dependsOn": ["build"], - "inputs": ["default", "^production"], + "dependsOn": ["^build"], "options": { "cwd": "{projectRoot}", "command": "pnpm vitest --typecheck.only --run --config vitest.typecheck.config.ts" diff --git a/pkgs/client/tsconfig.typecheck.json b/pkgs/client/tsconfig.typecheck.json index 165d7dba7..a369c6d01 100644 --- a/pkgs/client/tsconfig.typecheck.json +++ b/pkgs/client/tsconfig.typecheck.json @@ -17,5 +17,6 @@ "include": [ "__tests__/**/*.test-d.ts", "__tests__/**/*.spec-d.ts" - ] + ], + "exclude": ["dist", "node_modules"] } diff --git a/pkgs/client/vitest.typecheck.config.ts b/pkgs/client/vitest.typecheck.config.ts index 5546db0b4..a6b1782cd 100644 --- a/pkgs/client/vitest.typecheck.config.ts +++ b/pkgs/client/vitest.typecheck.config.ts @@ -15,6 +15,7 @@ export default defineConfig({ // NO setupFiles or globalSetup - type tests don't need runtime setup typecheck: { enabled: true, + tsconfig: './tsconfig.typecheck.json', }, reporters: ['default'], }, diff --git a/pkgs/core/project.json b/pkgs/core/project.json index 20f26a929..fe50593fe 100644 --- a/pkgs/core/project.json +++ b/pkgs/core/project.json @@ -29,10 +29,10 @@ ], "outputs": ["{projectRoot}/atlas/.supabase-baseline-schema.sql"], "options": { - "cwd": "{workspaceRoot}", + "cwd": "{projectRoot}", "commands": [ - "scripts/supabase-start-locked.sh {projectRoot}", - "cd {projectRoot} && scripts/atlas-dump-realtime-schema" + "../../scripts/supabase-start-locked.sh .", + "scripts/atlas-dump-realtime-schema" ], "parallel": false }, @@ -63,11 +63,11 @@ "inputs": ["migrations"], "outputs": ["{projectRoot}/.nx-inputs/verify-migrations.txt"], "options": { - "cwd": "{workspaceRoot}", + "cwd": "{projectRoot}", "commands": [ - "scripts/supabase-start-locked.sh {projectRoot}", - "cd {projectRoot} && mkdir -p .nx-inputs", - "cd {projectRoot} && supabase db reset > .nx-inputs/verify-migrations.txt 2>&1 || (cat .nx-inputs/verify-migrations.txt && exit 1)" + "../../scripts/supabase-start-locked.sh .", + "mkdir -p .nx-inputs", + "supabase db reset > .nx-inputs/verify-migrations.txt 2>&1 || (cat .nx-inputs/verify-migrations.txt && exit 1)" ], "parallel": false }, @@ -141,9 +141,9 @@ "local": true, "cache": false, "options": { - "cwd": "{workspaceRoot}", + "cwd": "{projectRoot}", "commands": [ - "scripts/supabase-start-locked.sh {projectRoot}" + "../../scripts/supabase-start-locked.sh ." ], "parallel": false } @@ -153,8 +153,8 @@ "local": true, "cache": false, "options": { - "cwd": "{workspaceRoot}", - "commands": ["scripts/supabase-start-locked.sh {projectRoot}"], + "cwd": "{projectRoot}", + "commands": ["../../scripts/supabase-start-locked.sh ."], "parallel": false } }, @@ -193,10 +193,10 @@ "local": true, "cache": false, "options": { - "cwd": "{workspaceRoot}", + "cwd": "{projectRoot}", "commands": [ - "scripts/supabase-start-locked.sh {projectRoot}", - "cd {projectRoot} && supabase db reset" + "../../scripts/supabase-start-locked.sh .", + "supabase db reset" ], "parallel": false } @@ -213,10 +213,10 @@ "inputs": ["schemas", "migrations", "pgtapTests"], "cache": true, "options": { - "cwd": "{workspaceRoot}", + "cwd": "{projectRoot}", "commands": [ - "scripts/supabase-start-locked.sh {projectRoot}", - "cd {projectRoot} && scripts/run-test-with-colors" + "../../scripts/supabase-start-locked.sh .", + "scripts/run-test-with-colors" ], "parallel": false } @@ -237,15 +237,15 @@ "inputs": ["migrations"], "outputs": ["{projectRoot}/src/database-types.ts"], "options": { + "cwd": "{projectRoot}", "commands": [ - "scripts/supabase-start-locked.sh {projectRoot}", - "cd {projectRoot} && echo 'Generating database types...'", - "cd {projectRoot} && supabase gen types --local --schema pgflow --schema pgmq > src/database-types.ts", - "cd {projectRoot} && echo 'Verifying generated types...'", - "cd {projectRoot} && grep -q 'pgflow' src/database-types.ts || (echo 'ERROR: Generated types file does not contain pgflow schema!' && exit 1)", - "cd {projectRoot} && [ -s src/database-types.ts ] || (echo 'ERROR: Generated types file is empty!' && exit 1)" + "../../scripts/supabase-start-locked.sh .", + "echo 'Generating database types...'", + "supabase gen types --local --schema pgflow --schema pgmq > src/database-types.ts", + "echo 'Verifying generated types...'", + "grep -q 'pgflow' src/database-types.ts || (echo 'ERROR: Generated types file does not contain pgflow schema!' && exit 1)", + "[ -s src/database-types.ts ] || (echo 'ERROR: Generated types file is empty!' && exit 1)" ], - "cwd": "{workspaceRoot}", "parallel": false }, "cache": true @@ -256,15 +256,15 @@ "inputs": ["migrations", "databaseTypes"], "outputs": ["{projectRoot}/.nx-inputs/verify-gen-types.txt"], "options": { - "cwd": "{workspaceRoot}", + "cwd": "{projectRoot}", "commands": [ - "scripts/supabase-start-locked.sh {projectRoot}", - "cd {projectRoot} && mkdir -p .nx-inputs", - "cd {projectRoot} && echo 'Verifying database types are up-to-date...'", - "cd {projectRoot} && cp src/database-types.ts .nx-inputs/database-types.ts.backup", - "cd {projectRoot} && supabase gen types --local --schema pgflow --schema pgmq > .nx-inputs/database-types.ts.new", - "cd {projectRoot} && diff .nx-inputs/database-types.ts.backup .nx-inputs/database-types.ts.new > .nx-inputs/verify-gen-types.txt 2>&1 || (echo 'ERROR: Database types are out of date! Run \"nx gen-types core\" to update them.' && echo '=============================================' && echo 'Diff between current and generated types:' && echo '=============================================' && diff -u .nx-inputs/database-types.ts.backup .nx-inputs/database-types.ts.new || true && echo '=============================================' && exit 1)", - "cd {projectRoot} && echo 'Database types are up-to-date' > .nx-inputs/verify-gen-types.txt" + "../../scripts/supabase-start-locked.sh .", + "mkdir -p .nx-inputs", + "echo 'Verifying database types are up-to-date...'", + "cp src/database-types.ts .nx-inputs/database-types.ts.backup", + "supabase gen types --local --schema pgflow --schema pgmq > .nx-inputs/database-types.ts.new", + "diff .nx-inputs/database-types.ts.backup .nx-inputs/database-types.ts.new > .nx-inputs/verify-gen-types.txt 2>&1 || (echo 'ERROR: Database types are out of date! Run \"nx gen-types core\" to update them.' && echo '=============================================' && echo 'Diff between current and generated types:' && echo '=============================================' && diff -u .nx-inputs/database-types.ts.backup .nx-inputs/database-types.ts.new || true && echo '=============================================' && exit 1)", + "echo 'Database types are up-to-date' > .nx-inputs/verify-gen-types.txt" ], "parallel": false }, @@ -272,12 +272,10 @@ }, "test:types:vitest": { "executor": "nx:run-commands", - "cache": true, - "dependsOn": ["build"], - "inputs": ["default", "^production"], + "dependsOn": ["^build"], "options": { "cwd": "{projectRoot}", - "command": "pnpm vitest --typecheck.only --run" + "command": "pnpm vitest --typecheck.only --run --config vitest.typecheck.config.ts" } }, "test:types:strict": { diff --git a/pkgs/core/tsconfig.typecheck.json b/pkgs/core/tsconfig.typecheck.json index 165d7dba7..a369c6d01 100644 --- a/pkgs/core/tsconfig.typecheck.json +++ b/pkgs/core/tsconfig.typecheck.json @@ -17,5 +17,6 @@ "include": [ "__tests__/**/*.test-d.ts", "__tests__/**/*.spec-d.ts" - ] + ], + "exclude": ["dist", "node_modules"] } diff --git a/pkgs/core/vite.config.ts b/pkgs/core/vite.config.ts index 58a4cfc0b..0d5e3c942 100644 --- a/pkgs/core/vite.config.ts +++ b/pkgs/core/vite.config.ts @@ -14,7 +14,7 @@ export default defineConfig({ globals: true, environment: 'jsdom', include: [ - '__tests__/**/*.{test,spec,test-d,spec-d}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', + '__tests__/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', ], reporters: ['default'], coverage: { diff --git a/pkgs/core/vitest.typecheck.config.ts b/pkgs/core/vitest.typecheck.config.ts new file mode 100644 index 000000000..f9ebbd6d6 --- /dev/null +++ b/pkgs/core/vitest.typecheck.config.ts @@ -0,0 +1,22 @@ +/// +import { defineConfig } from 'vitest/config'; + +// Separate config for type tests - NO global setup needed +export default defineConfig({ + root: __dirname, + cacheDir: '../../node_modules/.vite/pkgs/core', + test: { + watch: false, + globals: true, + environment: 'node', + include: [ + '__tests__/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}' + ], + // NO setupFiles or globalSetup - type tests don't need runtime setup + typecheck: { + enabled: true, + tsconfig: './tsconfig.typecheck.json', + }, + reporters: ['default'], + }, +}); diff --git a/pkgs/dsl/__tests__/types/array-method.test-d.ts b/pkgs/dsl/__tests__/types/array-method.test-d.ts index 0d7fa7d74..65fa534e2 100644 --- a/pkgs/dsl/__tests__/types/array-method.test-d.ts +++ b/pkgs/dsl/__tests__/types/array-method.test-d.ts @@ -20,27 +20,6 @@ describe('.array() method type constraints', () => { }); it('should reject handlers that return non-arrays', () => { - const flow = new Flow>({ slug: 'test' }); - - // Test that these handlers are NOT assignable to array handler type - type ArrayHandler = (input: { run: Record }, context: any) => Array | Promise>; - - const invalidNumber = () => 42; - expectTypeOf(invalidNumber).not.toMatchTypeOf(); - - const invalidString = () => 'not an array'; - expectTypeOf(invalidString).not.toMatchTypeOf(); - - const invalidObject = () => ({ not: 'array' }); - expectTypeOf(invalidObject).not.toMatchTypeOf(); - - const invalidNull = () => null; - expectTypeOf(invalidNull).not.toMatchTypeOf(); - - const invalidUndefined = () => undefined; - expectTypeOf(invalidUndefined).not.toMatchTypeOf(); - - // Keep the runtime tests with @ts-expect-error for actual type enforcement new Flow>({ slug: 'test2' }) // @ts-expect-error - should reject number return .array({ slug: 'invalid_number' }, () => 42) @@ -117,14 +96,10 @@ describe('.array() method type constraints', () => { describe('dependency validation', () => { it('should enforce compile-time dependency validation', () => { - const testFlow = new Flow({ slug: 'test' }) - .array({ slug: 'items' }, () => [1, 2, 3]); - - // Type assertion to verify compile-time error - type TestType = Parameters[0]['dependsOn']; - // @ts-expect-error - should only allow 'items' as a valid dependency - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const invalidDeps: TestType = ['nonExistentStep']; + new Flow({ slug: 'test' }) + .array({ slug: 'items' }, () => [1, 2, 3]) + // @ts-expect-error - should reject non-existent dependency + .array({ slug: 'invalid', dependsOn: ['nonExistentStep'] }, () => []); }); it('should not allow access to non-dependencies', () => { diff --git a/pkgs/dsl/project.json b/pkgs/dsl/project.json index 5c27d8ea3..9d298ebb5 100644 --- a/pkgs/dsl/project.json +++ b/pkgs/dsl/project.json @@ -38,15 +38,15 @@ }, "test:types:vitest": { "executor": "nx:run-commands", - "dependsOn": ["build"], + "dependsOn": [], "options": { "cwd": "{projectRoot}", - "command": "pnpm vitest --typecheck.only --run" + "command": "pnpm vitest --typecheck.only --run --config vitest.typecheck.config.ts" } }, "test:types:strict": { "executor": "nx:run-commands", - "dependsOn": ["build"], + "dependsOn": [], "options": { "cwd": "{projectRoot}", "command": "bash ../../scripts/typecheck-ts2578.sh" diff --git a/pkgs/dsl/tsconfig.typecheck.json b/pkgs/dsl/tsconfig.typecheck.json index 7527c5595..3cacf0782 100644 --- a/pkgs/dsl/tsconfig.typecheck.json +++ b/pkgs/dsl/tsconfig.typecheck.json @@ -19,6 +19,8 @@ "__tests__/**/*.spec-d.ts" ], "exclude": [ - "__tests__/**/__health__.test-d.ts" + "__tests__/**/__health__.test-d.ts", + "dist", + "node_modules" ] } diff --git a/pkgs/dsl/vite.config.ts b/pkgs/dsl/vite.config.ts index f676b5b66..8e4f93fe8 100644 --- a/pkgs/dsl/vite.config.ts +++ b/pkgs/dsl/vite.config.ts @@ -14,7 +14,7 @@ export default defineConfig({ globals: true, environment: 'jsdom', include: [ - '__tests__/**/*.{test,spec,test-d,spec-d}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', + '__tests__/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}', ], reporters: ['default'], coverage: { diff --git a/pkgs/dsl/vitest.typecheck.config.ts b/pkgs/dsl/vitest.typecheck.config.ts new file mode 100644 index 000000000..7dcf42564 --- /dev/null +++ b/pkgs/dsl/vitest.typecheck.config.ts @@ -0,0 +1,22 @@ +/// +import { defineConfig } from 'vitest/config'; + +// Separate config for type tests - NO global setup needed +export default defineConfig({ + root: __dirname, + cacheDir: '../../node_modules/.vite/pkgs/dsl', + test: { + watch: false, + globals: true, + environment: 'node', + include: [ + '__tests__/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}' + ], + // NO setupFiles or globalSetup - type tests don't need runtime setup + typecheck: { + enabled: true, + tsconfig: './tsconfig.typecheck.json', + }, + reporters: ['default'], + }, +}); diff --git a/pkgs/edge-worker/project.json b/pkgs/edge-worker/project.json index d767b5936..c1f886472 100644 --- a/pkgs/edge-worker/project.json +++ b/pkgs/edge-worker/project.json @@ -58,9 +58,9 @@ "local": true, "cache": false, "options": { - "cwd": "{workspaceRoot}", + "cwd": "{projectRoot}", "commands": [ - "scripts/supabase-start-locked.sh {projectRoot}" + "../../scripts/supabase-start-locked.sh ." ], "parallel": false } @@ -70,8 +70,8 @@ "local": true, "cache": false, "options": { - "cwd": "{workspaceRoot}", - "commands": ["scripts/supabase-start-locked.sh {projectRoot}"], + "cwd": "{projectRoot}", + "commands": ["../../scripts/supabase-start-locked.sh ."], "parallel": false } }, @@ -111,13 +111,13 @@ "local": true, "cache": false, "options": { - "cwd": "{workspaceRoot}", + "cwd": "{projectRoot}", "commands": [ - "cd pkgs/edge-worker && mkdir -p supabase/migrations/", - "cd pkgs/edge-worker && rm -f supabase/migrations/*.sql", - "cd pkgs/edge-worker && cp ../core/supabase/migrations/*.sql supabase/migrations/", - "scripts/supabase-start-locked.sh pkgs/edge-worker", - "cd pkgs/edge-worker && supabase db reset" + "mkdir -p supabase/migrations/", + "rm -f supabase/migrations/*.sql", + "cp ../core/supabase/migrations/*.sql supabase/migrations/", + "../../scripts/supabase-start-locked.sh .", + "supabase db reset" ], "parallel": false } @@ -127,10 +127,10 @@ "local": true, "cache": false, "options": { - "cwd": "{workspaceRoot}", + "cwd": "{projectRoot}", "commands": [ - "scripts/supabase-start-locked.sh {projectRoot}", - "cd {projectRoot} && supabase functions serve --env-file supabase/functions/.env --no-verify-jwt" + "../../scripts/supabase-start-locked.sh .", + "supabase functions serve --env-file supabase/functions/.env --no-verify-jwt" ], "parallel": false } @@ -189,12 +189,12 @@ "local": true, "cache": false, "options": { - "cwd": "{workspaceRoot}", + "cwd": "{projectRoot}", "commands": [ - "mkdir -p pkgs/edge-worker/supabase/migrations/", - "rm -f pkgs/edge-worker/supabase/migrations/*.sql", - "cp pkgs/core/supabase/migrations/*.sql pkgs/edge-worker/supabase/migrations/", - "scripts/supabase-start-locked.sh pkgs/edge-worker" + "mkdir -p supabase/migrations/", + "rm -f supabase/migrations/*.sql", + "cp ../core/supabase/migrations/*.sql supabase/migrations/", + "../../scripts/supabase-start-locked.sh ." ], "parallel": false } diff --git a/pkgs/website/project.json b/pkgs/website/project.json index c4c5e6f78..6dd76b636 100644 --- a/pkgs/website/project.json +++ b/pkgs/website/project.json @@ -107,10 +107,10 @@ "local": true, "cache": false, "options": { - "cwd": "{workspaceRoot}", + "cwd": "{projectRoot}", "commands": [ - "scripts/supabase-start-locked.sh {projectRoot}", - "cd {projectRoot} && astro dev" + "../../scripts/supabase-start-locked.sh .", + "astro dev" ] } } diff --git a/scripts/supabase-start-locked.sh b/scripts/supabase-start-locked.sh index 9329af471..02ea7e3ea 100755 --- a/scripts/supabase-start-locked.sh +++ b/scripts/supabase-start-locked.sh @@ -60,7 +60,7 @@ fi # Normalize to absolute path to ensure consistent lock naming # This prevents "./pkgs/core" and "pkgs/core" from creating different locks -PROJECT_DIR_ABS=$(cd "$PROJECT_DIR" && pwd) +PROJECT_DIR_ABS=$(realpath "$PROJECT_DIR") # Create a unique lock file path based on the absolute project directory # Using md5sum hash to create a safe filename from the directory path