|
| 1 | +# Cursor Rules for Supabase JS Libraries Monorepo |
| 2 | + |
| 3 | +You are working in a unified Nx monorepo that consolidates all Supabase JavaScript client libraries. This migration from 6 separate repositories addresses maintenance overhead, dependency duplication, and release coordination challenges. |
| 4 | + |
| 5 | +## Repository Context |
| 6 | + |
| 7 | +This monorepo contains 6 JavaScript/TypeScript libraries previously maintained as separate repositories: |
| 8 | +- `packages/core/supabase-js` - Main isomorphic client combining all libraries (@supabase/supabase-js) |
| 9 | +- `packages/core/auth-js` - Authentication client (@supabase/auth-js) |
| 10 | +- `packages/core/functions-js` - Edge Functions client (@supabase/functions-js) |
| 11 | +- `packages/core/postgrest-js` - PostgREST database client (@supabase/postgrest-js) |
| 12 | +- `packages/core/realtime-js` - Real-time subscriptions client (@supabase/realtime-js) |
| 13 | +- `packages/core/storage-js` - File storage client (@supabase/storage-js) |
| 14 | + |
| 15 | +## Key Principles |
| 16 | + |
| 17 | +1. **Zero Breaking Changes**: All migrations and changes must maintain full backward compatibility for consumers |
| 18 | +2. **Fixed Version Mode**: All packages share the same version number and are released together |
| 19 | +3. **Workspace Dependencies**: Internal dependencies use `*` which Nx replaces with actual versions during release |
| 20 | +4. **Affected Testing**: Always use `nx affected` commands to test only what changed |
| 21 | +5. **Conventional Commits**: Use conventional commit format for automated versioning and changelogs |
| 22 | + |
| 23 | +## Common Commands |
| 24 | + |
| 25 | +### Building |
| 26 | +- Build all: `nx run-many --target=build --all` |
| 27 | +- Build specific: `nx build auth-js` |
| 28 | +- Build affected: `nx affected --target=build` |
| 29 | +- Watch mode: `nx build auth-js --watch` |
| 30 | + |
| 31 | +### Testing |
| 32 | +- Test all: `nx run-many --target=test --all` |
| 33 | +- Test specific: `nx test auth-js` |
| 34 | +- Test affected: `nx affected --target=test` |
| 35 | +- Integration tests: `nx run-many --target=test:integration --all` |
| 36 | + |
| 37 | +### Code Quality |
| 38 | +- Lint all: `nx run-many --target=lint --all` |
| 39 | +- Format: `nx format` |
| 40 | +- Check format: `nx format:check` |
| 41 | + |
| 42 | +### Analysis |
| 43 | +- Dependency graph: `nx graph` |
| 44 | +- Show projects: `nx show projects` |
| 45 | +- Affected graph: `nx affected --graph` |
| 46 | + |
| 47 | +## Development Patterns |
| 48 | + |
| 49 | +### Cross-Library Changes |
| 50 | +When making changes that affect multiple libraries: |
| 51 | +1. Make all changes in a single PR |
| 52 | +2. Update tests in both source library and integration tests in supabase-js |
| 53 | +3. Use `nx affected --target=test` to verify all impacts |
| 54 | +4. Commit with clear scope: `fix(realtime-js): resolve connection issue` |
| 55 | + |
| 56 | +### Adding New Features |
| 57 | +1. Implement in the specific library under `packages/core/[library-name]` |
| 58 | +2. Add comprehensive unit tests in the library's `test/` directory |
| 59 | +3. If it affects supabase-js, add integration tests there |
| 60 | +4. Run `nx affected --target=test` before committing |
| 61 | + |
| 62 | +### Quick Fixes |
| 63 | +Even for single-library fixes: |
| 64 | +1. Use conventional commit: `fix(storage-js): correct upload timeout` |
| 65 | +2. All packages will be versioned together (fixed mode) |
| 66 | +3. Run `nx affected --target=test` |
| 67 | +4. Changes ship together in next release |
| 68 | + |
| 69 | +## TypeScript Configuration |
| 70 | + |
| 71 | +The workspace uses strict TypeScript settings: |
| 72 | +- Target: ES2022 |
| 73 | +- Module: NodeNext |
| 74 | +- Strict mode enabled |
| 75 | +- Isolated modules for performance |
| 76 | +- Composite projects for incremental builds |
| 77 | + |
| 78 | +## Testing Infrastructure |
| 79 | + |
| 80 | +### Unit Tests |
| 81 | +- Located in each library's `test/` directory |
| 82 | +- Use Jest as test runner |
| 83 | +- Mock external dependencies |
| 84 | + |
| 85 | +### Integration Tests |
| 86 | +- Libraries with external services (auth-js, storage-js) use Docker |
| 87 | +- Docker Compose configs in `infra/` directories |
| 88 | +- Run with: `npm run test:infra` from library directory |
| 89 | + |
| 90 | +### Cross-Platform Tests |
| 91 | +The main supabase-js tests against: |
| 92 | +- Node.js |
| 93 | +- Next.js |
| 94 | +- Expo (React Native) |
| 95 | +- Bun runtime |
| 96 | +- Deno runtime |
| 97 | +- Browser environment |
| 98 | + |
| 99 | +## File Structure Conventions |
| 100 | + |
| 101 | +``` |
| 102 | +packages/core/[library-name]/ |
| 103 | +├── src/ # Source code |
| 104 | +├── test/ # Test files |
| 105 | +├── dist/ # Build output (gitignored) |
| 106 | +├── package.json # Package configuration |
| 107 | +└── tsconfig.json # TypeScript config |
| 108 | +``` |
| 109 | + |
| 110 | +## Important Notes |
| 111 | + |
| 112 | +- **Different Default Branches**: Original repos used either `master` or `main` - be aware when referencing history |
| 113 | +- **Package Names**: All packages maintain original npm names (@supabase/[package-name]) |
| 114 | +- **Shared Code**: Extract common patterns (HTTP client, error handling) to shared packages when identified |
| 115 | +- **Docker Required**: Integration tests for auth-js and storage-js require Docker to be running |
| 116 | + |
| 117 | +## Release Process |
| 118 | + |
| 119 | +### Fixed Version Release |
| 120 | +All packages released with same version: |
| 121 | +```bash |
| 122 | +nx release # Interactive release |
| 123 | +nx release --dry-run # Preview changes |
| 124 | +nx release --yes # CI automation |
| 125 | +``` |
| 126 | + |
| 127 | +### Internal Dependencies |
| 128 | +```json |
| 129 | +// packages/core/supabase-js/package.json |
| 130 | +"dependencies": { |
| 131 | + "@supabase/auth-js": "*", |
| 132 | + "@supabase/realtime-js": "*", |
| 133 | + "@supabase/functions-js": "*", |
| 134 | + "@supabase/storage-js": "*", |
| 135 | + "@supabase/postgrest-js": "*" |
| 136 | +} |
| 137 | +``` |
| 138 | +The `*` is replaced with actual version during release. |
| 139 | + |
| 140 | +## Code Style |
| 141 | + |
| 142 | +- Use Prettier for formatting (config in .prettierrc) |
| 143 | +- Follow existing patterns in each library |
| 144 | +- Maintain consistency across the monorepo |
| 145 | +- Document public APIs with JSDoc comments |
| 146 | + |
| 147 | +## Common Pitfalls to Avoid |
| 148 | + |
| 149 | +1. Don't hardcode version numbers for internal dependencies |
| 150 | +2. Don't make breaking changes to public APIs |
| 151 | +3. Don't forget to run affected tests before committing |
| 152 | +4. Don't mix unrelated changes in a single commit |
| 153 | +5. Don't bypass the Nx build system by running npm scripts directly for cross-library work |
| 154 | + |
| 155 | +## When Making Suggestions |
| 156 | + |
| 157 | +1. Always consider the monorepo structure - changes might affect multiple packages |
| 158 | +2. Use Nx commands rather than npm/yarn directly for workspace operations |
| 159 | +3. Suggest running affected tests, not all tests, for better performance |
| 160 | +4. Remember that all packages version together in fixed mode |
| 161 | +5. Consider Docker requirements for integration tests |
| 162 | +6. Maintain backward compatibility at all costs |
0 commit comments