Skip to content

Conversation

mandarini
Copy link
Contributor

@mandarini mandarini commented Oct 16, 2025

Description

This PR fixes build script issues and converts the postbuild type sync mechanism to an explicit codegen workflow with automated checks.

What changed?

  1. Fixed nested Nx invocations causing build failures:
  • Changed package build scripts in supabase-js, auth-js, and storage-js to use npm run instead of npx nx
  • Previously, build scripts calling npx nx build:main package-name caused nested Nx processes that conflicted over the project graph
  • This was causing [readCachedProjectGraph] ERROR: No cached ProjectGraph is available errors
  1. Fixed nested common/common/ directory creation
  • The postbuild script in postgrest-js was using cp -rf ./src/types/common ../supabase-js/src/lib/rest/types/common
  • When the destination already existed, it would copy the directory INTO it instead of replacing contents
  • This created nested common/common/common.ts and common/common/rpc.ts files
  1. Converted postbuild to explicit codegen workflow
  • Removed automatic postbuild script from postgrest-js/package.json
  • Created scripts/sync-common-types.js for explicit type synchronization
  • Added npm run codegen and npm run codegen:check commands
  • Generated files now include AUTO-GENERATED header comments with clear instructions
  • Added pre-commit hook that automatically runs codegen when source types change
  • Added CI check (codegen:check) in ci-core.yml to ensure types stay in sync

Why was this change needed?

Postbuild Issues:
The automatic postbuild approach had several issues:

  1. Builds modifying source files - Anti-pattern that creates non-deterministic builds
  2. Git workflow confusion - Running builds could create uncommitted changes
  3. Nested directory bug - cp -rf behavior created invalid directory structures
  4. Hidden behavior - Developers weren't aware files were being auto-generated

Why Explicit Codegen is needed:

  • Builds are pure (same input = same output)
  • Clear when files are generated (explicit npm run codegen)
  • Pre-commit hook ensures types stay in sync automatically
  • CI catches any missed syncs with clear error messages
  • AUTO-GENERATED headers warn developers not to edit manually
  • Transparent and predictable workflow

Context from PR #1632:
These common types need to be copied (not imported across package boundaries) because TypeScript's structural typing requires exact type definitions for complex generics and conditional types to work correctly across postgrest-js and supabase-js. The codegen approach maintains this requirement while making the process explicit and safe.

Related Issues

@mandarini mandarini changed the title Fix/build scripts fix(repo): convert postbuild to explicit codegen Oct 16, 2025
@coveralls
Copy link

coveralls commented Oct 16, 2025

Coverage Status

coverage: 82.089% (-0.6%) from 82.663%
when pulling 56abf4c on fix/build-scripts
into c4554ff on master.

@mandarini mandarini marked this pull request as ready for review October 16, 2025 08:34
@mandarini mandarini requested review from a team as code owners October 16, 2025 08:34
@mandarini mandarini self-assigned this Oct 16, 2025
@mandarini mandarini requested a review from avallete October 16, 2025 08:40
@mandarini
Copy link
Contributor Author

@avallete let me know if this is ok for what you intended!

@avallete
Copy link
Member

Totally ! Great work on this, thank's for catching it 👍

@mandarini mandarini enabled auto-merge (squash) October 16, 2025 08:50
@mandarini mandarini merged commit 698c306 into master Oct 16, 2025
27 checks passed
@mandarini mandarini deleted the fix/build-scripts branch October 16, 2025 08:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants