Skip to content

Commit dc65e6b

Browse files
committed
chore(repo): configure TypeScript project references
1 parent 698c306 commit dc65e6b

31 files changed

+1448
-740
lines changed

.cursor/mcp.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
11
{
2-
"mcpServers": {
3-
"nx-mcp": {
4-
"command": "npx",
5-
"args": ["-y", "nx-mcp@latest"]
6-
}
7-
}
2+
"mcpServers": {}
83
}

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

.eslintrc.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"root": true,
3+
"ignorePatterns": ["**/*"],
4+
"plugins": ["@nx"],
5+
"overrides": [
6+
{
7+
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
8+
"rules": {
9+
"@nx/enforce-module-boundaries": [
10+
"error",
11+
{
12+
"enforceBuildableLibDependency": true,
13+
"allow": [],
14+
"depConstraints": [
15+
{
16+
"sourceTag": "*",
17+
"onlyDependOnLibsWithTags": ["*"]
18+
}
19+
]
20+
}
21+
]
22+
}
23+
},
24+
{
25+
"files": ["*.ts", "*.tsx"],
26+
"extends": ["plugin:@nx/typescript"],
27+
"rules": {}
28+
},
29+
{
30+
"files": ["*.js", "*.jsx"],
31+
"extends": ["plugin:@nx/javascript"],
32+
"rules": {}
33+
},
34+
{
35+
"files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"],
36+
"env": {
37+
"jest": true
38+
},
39+
"rules": {}
40+
}
41+
]
42+
}

.github/workflows/ci-core.yml

Lines changed: 74 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444
# Prepend any command with "nx-cloud record --" to record its logs to Nx Cloud
4545
# - run: npx nx-cloud record -- echo Hello World
4646
# When you enable task distribution, run the e2e-ci task instead of e2e
47-
- name: Check generated types are in sync
47+
- name: Check common types are in sync
4848
run: npm run codegen:check
4949

5050
- name: Build affected packages
@@ -55,6 +55,7 @@ jobs:
5555

5656
- name: Run test:ci for affected packages
5757
run: npx nx affected --target=test:ci
58+
timeout-minutes: 15
5859

5960
- name: Upload coverage for functions-js (if affected)
6061
uses: coverallsapp/github-action@v2
@@ -75,15 +76,6 @@ jobs:
7576
flag-name: realtime-js
7677
fail-on-error: false
7778
continue-on-error: true
78-
- name: Upload coverage for postgrest-js (if affected)
79-
uses: coverallsapp/github-action@v2
80-
with:
81-
github-token: ${{ secrets.GITHUB_TOKEN }}
82-
path-to-lcov: ./packages/core/postgrest-js/coverage/lcov.info
83-
parallel: true
84-
flag-name: postgrest-js
85-
fail-on-error: false
86-
continue-on-error: true
8779
- name: Run auth-js tests (if affected)
8880
run: npx nx affected --target=test:auth
8981

@@ -108,19 +100,89 @@ jobs:
108100
flag-name: storage-js
109101
fail-on-error: false
110102
continue-on-error: true
103+
# Separate job for postgrest-js tests (Docker-based, retriable)
104+
test-postgrest-js:
105+
name: Test postgrest-js
106+
runs-on: ubuntu-latest
107+
steps:
108+
- uses: actions/checkout@v4
109+
with:
110+
filter: tree:0
111+
fetch-depth: 0
112+
- uses: actions/setup-node@v4
113+
with:
114+
node-version: 20
115+
cache: 'npm'
116+
- name: Install dependencies
117+
run: npm ci --legacy-peer-deps
118+
- uses: nrwl/nx-set-shas@v4
119+
120+
- name: Run postgrest-js integration tests (if affected)
121+
run: npx nx affected --target=test:ci:postgrest
122+
timeout-minutes: 10
123+
124+
- name: Run postgrest-js type tests (if affected)
125+
run: npx nx affected --target=test:types:ci
126+
timeout-minutes: 15
127+
128+
- name: Upload coverage for postgrest-js (if affected)
129+
uses: coverallsapp/github-action@v2
130+
with:
131+
github-token: ${{ secrets.GITHUB_TOKEN }}
132+
path-to-lcov: ./packages/core/postgrest-js/coverage/lcov.info
133+
parallel: true
134+
flag-name: postgrest-js
135+
fail-on-error: false
136+
continue-on-error: true
137+
138+
# Separate job for slow type generation check (runs in parallel)
139+
check-postgrest-generated-types:
140+
name: Check Postgrest Generated Types
141+
runs-on: ubuntu-latest
142+
steps:
143+
- uses: actions/checkout@v4
144+
with:
145+
filter: tree:0
146+
fetch-depth: 0
147+
- uses: actions/setup-node@v4
148+
with:
149+
node-version: 20
150+
cache: 'npm'
151+
- name: Install dependencies
152+
run: npm ci --legacy-peer-deps
153+
154+
- name: Check if database schema changed
155+
id: check_changes
156+
run: |
157+
git fetch origin ${{ github.base_ref }}
158+
if git diff --name-only origin/${{ github.base_ref }}...HEAD | grep -q "packages/core/postgrest-js/test/db/"; then
159+
echo "changed=true" >> $GITHUB_OUTPUT
160+
else
161+
echo "changed=false" >> $GITHUB_OUTPUT
162+
fi
163+
164+
- name: Verify generated types are in sync
165+
if: steps.check_changes.outputs.changed == 'true'
166+
run: npm run codegen:check:postgrest
167+
timeout-minutes: 5
168+
169+
- name: Skip check
170+
if: steps.check_changes.outputs.changed != 'true'
171+
run: echo "⏭️ Skipping - no database schema changes detected"
172+
111173
# SUMMARY JOB
112174
all-core-tests-pass:
113175
name: All Core Package Tests Pass
114176
runs-on: ubuntu-latest
115-
needs: setup-build-test-node-20
177+
needs: [setup-build-test-node-20, test-postgrest-js, check-postgrest-generated-types]
116178
steps:
117179
- name: Summary
118180
run: echo "✅ All core package tests passed successfully!"
119181

120182
coveralls-finish:
121183
name: Coveralls Finished
122184
runs-on: ubuntu-latest
123-
needs: setup-build-test-node-20
185+
needs: [setup-build-test-node-20, test-postgrest-js]
124186
steps:
125187
- name: Coveralls Finished
126188
uses: coverallsapp/github-action@v2

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ Thumbs.db
4949
.github/instructions/nx.instructions.md
5050

5151
vite.config.*.timestamp*
52-
vitest.config.*.timestamp*
52+
vitest.config.*.timestamp*
53+
test-output

.husky/pre-push

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Check if postgrest-js test database schema was modified
2+
if git diff --name-only origin/master...HEAD 2>/dev/null | grep -q "packages/core/postgrest-js/test/db/"; then
3+
echo "📝 Detected changes in postgrest-js test database schema..."
4+
echo "🔍 Checking if generated types are in sync..."
5+
6+
npm run codegen:check:postgrest
7+
8+
if [ $? -ne 0 ]; then
9+
echo ""
10+
echo "❌ Push blocked: Postgrest generated types are out of sync"
11+
echo ""
12+
echo "To fix this:"
13+
echo " 1. Run: npm run codegen:postgrest"
14+
echo " 2. Commit the updated test/types.generated.ts"
15+
echo " 3. Push again"
16+
echo ""
17+
exit 1
18+
fi
19+
20+
echo "✅ Postgrest generated types are in sync"
21+
fi

CLAUDE.md

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,14 @@ nx test supabase-js --coverage # Test with coverage
138138

139139
**Docker Requirements:**
140140

141-
| Package | Docker Required | Infrastructure | Special Commands |
142-
| ------------ | --------------- | ------------------------------- | ---------------- |
143-
| auth-js | ✅ Yes | Auth Server + Postgres | May use `nx test:auth auth-js` |
144-
| functions-js | ✅ Yes | Deno relay (testcontainers) | Standard `nx test functions-js` |
145-
| postgrest-js | ✅ Yes | PostgREST + PostgreSQL | Standard `nx test postgrest-js` |
141+
| Package | Docker Required | Infrastructure | Special Commands |
142+
| ------------ | --------------- | ------------------------------- | ------------------------------------ |
143+
| auth-js | ✅ Yes | Auth Server + Postgres | May use `nx test:auth auth-js` |
144+
| functions-js | ✅ Yes | Deno relay (testcontainers) | Standard `nx test functions-js` |
145+
| postgrest-js | ✅ Yes | PostgREST + PostgreSQL | Standard `nx test postgrest-js` |
146146
| storage-js | ✅ Yes | Storage API + PostgreSQL + Kong | May use `nx test:storage storage-js` |
147-
| realtime-js | ❌ No | Mock WebSockets | Standard `nx test realtime-js` |
148-
| supabase-js | ❌ No | Unit tests only | Standard `nx test supabase-js` |
147+
| realtime-js | ❌ No | Mock WebSockets | Standard `nx test realtime-js` |
148+
| supabase-js | ❌ No | Unit tests only | Standard `nx test supabase-js` |
149149

150150
> **📖 See [TESTING.md](docs/TESTING.md) for complete testing guide and troubleshooting**
151151
@@ -216,6 +216,68 @@ nx release --tag=latest --yes # Promotes to stable with same version for ALL pa
216216

217217
Each library has its own `tsconfig.json` extending the base configuration, allowing for library-specific adjustments while maintaining consistency.
218218

219+
### TypeScript Project References Setup
220+
221+
This repository uses TypeScript project references for incremental builds and better type checking across packages.
222+
223+
**What's Configured:**
224+
225+
1. **tsconfig.base.json** - Base configuration inherited by all projects:
226+
- `composite: true` - Enables project references
227+
- `declaration: true` - Required by composite
228+
- `moduleResolution: "bundler"` - Works with workspaces
229+
- `isolatedModules: true` - Inherited but overridden in core packages
230+
- `noImplicitOverride: true` - Inherited but overridden in core packages
231+
- **No `customConditions`** - Removed to avoid conflicts with CommonJS packages
232+
233+
2. **Root tsconfig.json** - References all projects in the monorepo:
234+
235+
```json
236+
{
237+
"extends": "./tsconfig.base.json",
238+
"files": [],
239+
"references": [
240+
{ "path": "./packages/core/auth-js" },
241+
{ "path": "./packages/core/realtime-js" }
242+
// ... all other packages
243+
]
244+
}
245+
```
246+
247+
3. **Core packages** (auth-js, realtime-js, postgrest-js, functions-js, storage-js):
248+
- Keep `module: "CommonJS"` for backward compatibility
249+
- Override `moduleResolution: "Node"` (required for CommonJS)
250+
- Override `isolatedModules: false` (existing code doesn't use `export type`)
251+
- Override `noImplicitOverride: false` (existing code doesn't use `override` keyword)
252+
- Add `references` array pointing to dependencies (managed by `nx sync`)
253+
254+
4. **Utils packages** (utils-fetch):
255+
- Inherit `moduleResolution: "bundler"` from base
256+
- Can optionally add `customConditions: ["@supabase-js/source"]` for source preference
257+
258+
**Key Principles:**
259+
260+
-**No Breaking Changes**: Build output is identical - only type-checking is affected
261+
-**Incremental Builds**: TypeScript only recompiles changed projects
262+
-**Better Performance**: Reduced memory usage during builds
263+
-**Automatic References**: Nx sync automatically maintains project references
264+
- ⚠️ **No `customConditions` in base**: Would conflict with `moduleResolution: "Node"`
265+
266+
**When Adding New Packages:**
267+
268+
1. Ensure `composite: true` and `declaration: true` are set
269+
2. Add `references` array pointing to dependencies
270+
3. If using CommonJS, override `moduleResolution: "Node"` and disable strict options
271+
4. Run `nx sync` to update root tsconfig.json automatically
272+
273+
**Important Notes:**
274+
275+
- TypeScript project references work WITHOUT `customConditions` - it's optional
276+
- `customConditions` only optimizes source file resolution during development
277+
- Core packages use `moduleResolution: "Node"` which is incompatible with `customConditions`
278+
- The `isolatedModules: false` override avoids requiring `export type` for type re-exports
279+
- All build outputs remain identical to pre-project-references setup
280+
219281
## Testing Infrastructure
220282

221283
### Unit Tests (Jest)
@@ -314,10 +376,12 @@ Tests run against multiple environments:
314376
### Branch Information
315377

316378
**Current Repository:**
379+
317380
- **Default branch**: `master` (confirmed current default)
318381
- **Repository URL**: `github.com/supabase/supabase-js`
319382

320383
**Original Repository Branches** (for historical reference):
384+
321385
- **master**: auth-js, postgrest-js, realtime-js, supabase-js
322386
- **main**: functions-js, storage-js
323387

0 commit comments

Comments
 (0)