Skip to content

Commit 1a8af6c

Browse files
committed
feat(cli): Add Rust CLI for schema generation with watch mode
Major rewrite of the schema generation system from TypeScript to Rust, providing significant performance improvements and a standalone CLI tool. Key changes: - Add Rust CLI with generate and watch subcommands - Migrate to tRPC v11 APIs - Add comprehensive test suite (unit, integration, E2E, snapshots) - Add benchmark infrastructure with Criterion - Improve error handling with miette diagnostics - Add dry-run mode with diff preview - Update documentation and migration guides - Fix CI workflow for Rust toolchain and test runner
1 parent 8e921eb commit 1a8af6c

File tree

197 files changed

+25616
-20995
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

197 files changed

+25616
-20995
lines changed

.github/workflows/verify.yml

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
branches:
66
- main
77
pull_request:
8-
types: [opened, reopened]
8+
types: [opened, reopened, synchronize]
99

1010
jobs:
1111
verify:
@@ -17,13 +17,91 @@ jobs:
1717
with:
1818
token: ${{ secrets.GITHUB_TOKEN }}
1919
submodules: false
20-
- name: Enable Corepack
21-
run: corepack enable
20+
- name: Setup Bun
21+
uses: oven-sh/setup-bun@v2
2222
- name: Install dependencies
23-
run: yarn install --frozen-lockfile
23+
run: bun install --frozen-lockfile
2424
- name: Lint
25-
run: yarn lint --no-fix
25+
run: bun run lint --no-fix
2626
- name: Test
27-
run: yarn test
27+
run: bun run test
2828
- name: Build
29-
run: yarn build
29+
run: bun run build
30+
31+
verify-rust-cli:
32+
runs-on: ubuntu-latest
33+
name: verify-rust-cli
34+
defaults:
35+
run:
36+
working-directory: packages/nestjs-trpc/cli
37+
steps:
38+
- name: Checkout the repo
39+
uses: actions/checkout@v4
40+
with:
41+
token: ${{ secrets.GITHUB_TOKEN }}
42+
submodules: false
43+
- name: Setup Rust
44+
uses: actions-rust-lang/setup-rust-toolchain@v1
45+
with:
46+
toolchain: stable
47+
components: rustfmt, clippy
48+
cache-workspaces: packages/nestjs-trpc/cli -> target
49+
- name: Check formatting
50+
run: cargo fmt --check
51+
- name: Run clippy
52+
run: cargo clippy --all-targets --all-features -- -D warnings
53+
- name: Run tests
54+
run: cargo test
55+
- name: Build
56+
run: cargo build --release
57+
- name: Check file sizes
58+
run: ./scripts/check-line-count.sh
59+
60+
e2e-tests:
61+
runs-on: ubuntu-latest
62+
name: e2e-tests
63+
needs: [verify, verify-rust-cli]
64+
steps:
65+
- name: Checkout the repo
66+
uses: actions/checkout@v4
67+
with:
68+
token: ${{ secrets.GITHUB_TOKEN }}
69+
submodules: false
70+
- name: Setup Bun
71+
uses: oven-sh/setup-bun@v2
72+
- name: Setup Rust
73+
uses: actions-rust-lang/setup-rust-toolchain@v1
74+
with:
75+
toolchain: stable
76+
cache-workspaces: packages/nestjs-trpc/cli -> target
77+
- name: Install dependencies
78+
run: bun install --frozen-lockfile
79+
- name: Build library
80+
run: bun run build
81+
- name: Build Rust CLI
82+
working-directory: packages/nestjs-trpc/cli
83+
run: cargo build --release
84+
- name: Generate types for Express example
85+
working-directory: examples/nestjs-express
86+
run: |
87+
mkdir -p src/@generated
88+
../../packages/nestjs-trpc/cli/target/release/nestjs-trpc generate \
89+
--entrypoint ./src/user.router.ts \
90+
--output ./src/@generated/server.ts
91+
- name: Verify Express generated file exists
92+
run: test -s examples/nestjs-express/src/@generated/server.ts
93+
- name: Generate types for Fastify example
94+
working-directory: examples/nestjs-fastify
95+
run: |
96+
mkdir -p src/@generated
97+
../../packages/nestjs-trpc/cli/target/release/nestjs-trpc generate \
98+
--entrypoint ./src/user.router.ts \
99+
--output ./src/@generated/server.ts
100+
- name: Verify Fastify generated file exists
101+
run: test -s examples/nestjs-fastify/src/@generated/server.ts
102+
- name: Run E2E tests (Express)
103+
working-directory: examples/nestjs-express
104+
run: bun run test:e2e
105+
- name: Run E2E tests (Fastify)
106+
working-directory: examples/nestjs-fastify
107+
run: bun run test:e2e

.gitignore

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,27 @@ test/**/dist
3333
!.yarn/plugins
3434
!.yarn/releases
3535
!.yarn/sdks
36-
!.yarn/versions
36+
!.yarn/versions
37+
38+
# Rust CLI (packages/nestjs-trpc/cli)
39+
**/target/
40+
**/*.rs.bk
41+
42+
# Development tools
43+
.auto-claude/
44+
.worktrees/
45+
.claude/
46+
.planning/
47+
48+
# Native binaries
49+
packages/nestjs-trpc/native/
50+
51+
# Generated/build artifacts
52+
packages/nestjs-trpc/cli/@generated/
53+
**/*.rlib
54+
55+
# Compiled test files
56+
examples/**/test/**/*.js
57+
examples/**/test/**/*.js.map
58+
examples/**/test/**/*.d.ts
59+
examples/**/test/**/*.d.ts.map

.husky/commit-msg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
yarn commitlint -c --config .commitlintrc.json -E --edit
1+
bun run commitlint -c --config .commitlintrc.json -E --edit

.husky/pre-commit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
yarn lint-staged
1+
bun run lint-staged

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ docs/
44
public/
55
*.md
66
*.mdx
7-
packages/**/__tests__/*.ts
7+
packages/**/__tests__/*.ts
8+
packages/nestjs-trpc/cli/tests/fixtures/

.yarnrc.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,36 @@
11
# Changelog
22

3+
## [2.0.0] - UNRELEASED
4+
5+
### BREAKING CHANGES
6+
7+
#### tRPC v11 Required
8+
- **Minimum tRPC version**: `@trpc/server@^11.0.0` is now required
9+
- If using data transformers, move them to link configuration (see [migration guide](/docs/migration/v10-to-v11))
10+
11+
#### TypeScript Generator Removed
12+
- **Code generation**: Now handled exclusively by Rust CLI
13+
- **Removed**: `TRPCGenerator` class and `autoSchemaFile` option
14+
- **Removed**: `ts-morph` dependency
15+
- **Migration**: Use `npx nestjs-trpc generate` instead (see [migration guide](/docs/migration/typescript-to-rust-cli))
16+
17+
#### ImportsScanner Removed
18+
- **Internal change**: `ImportsScanner` class removed (was internal, should not affect users)
19+
20+
### Added
21+
22+
- **Watch mode**: `npx nestjs-trpc watch` for automatic regeneration on file changes
23+
- **Better error messages**: Rich diagnostics with file paths and line numbers
24+
- **Faster generation**: Rust-based CLI is 10-50x faster than TypeScript generator
25+
26+
### Changed
27+
28+
- **Internal**: Router construction uses plain objects instead of explicit `router()` calls (tRPC v11 shorthand)
29+
30+
### Fixed
31+
32+
- Various parser edge cases for complex Zod schemas
33+
334
## <small>1.6.1 (2024-10-30)</small>
435

536
## 1.6.0 (2024-10-30)

0 commit comments

Comments
 (0)