Skip to content

refactor(server): enforce server-only module boundaries with .server.ts convention#7

Merged
carlosvin merged 1 commit into
mainfrom
refactor/server-only-imports
May 27, 2026
Merged

refactor(server): enforce server-only module boundaries with .server.ts convention#7
carlosvin merged 1 commit into
mainfrom
refactor/server-only-imports

Conversation

@carlosvin
Copy link
Copy Markdown
Owner

Summary

  • Rename four server-only modules to the .server.ts convention (jwt, mongoClient, getRepository, mongoRepository) so the file name itself signals that the module must never run in the browser
  • Enable TanStack Start's importProtection in vite.config.ts to statically enforce the boundary: any client-side import of mongodb or the renamed files now throws a build error (test files are excluded)
  • Update all call-sites (auth.ts, serverFns.ts, jwt.test.ts) to the new paths
  • Add pnpm-workspace.yaml with allowBuilds entries for native packages (@parcel/watcher, @sentry/cli, @swc/core, esbuild, protobufjs, sharp)
  • Sync the TanStack Promptable Fullstack App Template skill and derived artifacts to document the .server.ts naming convention

Why

Without an enforced boundary, a developer can accidentally import mongoClient or a JWT utility from a React component and ship Node.js-only code to the browser bundle. Splitting by name convention + build-time gating makes the mistake immediately visible rather than failing silently at runtime.

Test plan

  • pnpm lint passes (types + Biome)
  • pnpm test passes
  • pnpm build completes without import-protection errors
  • Verify that adding a client-side import of mongoClient.server.ts triggers a build error

…ts convention

Rename server-side modules to the .server.ts convention so TanStack
Start's importProtection can statically prevent them from leaking into
the client bundle.

- Rename jwt.ts → jwt.server.ts, mongoClient.ts → mongoClient.server.ts,
  getRepository.ts → getRepository.server.ts, and
  mongoRepository.ts → mongoRepository.server.ts
- Enable importProtection in vite.config.ts targeting mongodb and the
  renamed server files; errors on client imports, skips test files
- Update all import paths in auth.ts, serverFns.ts, and tests
- Add pnpm-workspace.yaml with allowBuilds entries for native packages
- Sync skill docs to document the .server.ts naming convention

Co-authored-by: Cursor <cursoragent@cursor.com>
@carlosvin carlosvin merged commit 58b8e2e into main May 27, 2026
1 check passed
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.

1 participant