Skip to content

Commit 1cedb32

Browse files
fengmk2claude
andauthored
chore(build): migrate to tsdown workspace mode (#5738)
Replace per-package tsdown config spreading with native workspace mode: - Add root tsdown.config.ts with workspace configuration - Remove 60 standard tsdown.config.ts files that only spread base config - Keep 7 configs with custom options (copy, unbundle, unused.ignore) - Simplify root build script to just run tsdown once - Delete tsdown.config.json (old JSON base config) 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Build Process Improvements** * Introduces a workspace-wide tsdown build/configuration flow; adds workspace scripts (including a tsdown alias and clean-dist) and centralizes defaults so most packages no longer need individual build configs. * **Breaking Changes** * Many package-level build scripts and per-package tsdown configs were removed; publishing or custom build workflows may require updating. * **Documentation** * Guidance updated: per-package config is optional — create one only for custom behavior; example simplified. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 6de1d54 commit 1cedb32

File tree

251 files changed

+357
-2025
lines changed

Some content is hidden

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

251 files changed

+357
-2025
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,8 @@ jobs:
163163

164164
- name: Run example tests
165165
if: ${{ matrix.node != '20' && matrix.os != 'windows-latest' }}
166-
run: pnpm run example:test:all
166+
run: |
167+
pnpm run example:test:all
167168
168169
- name: Code Coverage
169170
# skip on windows, it will hangup on codecov
@@ -176,9 +177,8 @@ jobs:
176177
strategy:
177178
fail-fast: false
178179
matrix:
179-
# os: ['ubuntu-latest', 'macos-latest', 'windows-latest']
180180
os: ['ubuntu-latest', 'windows-latest']
181-
node: ['22']
181+
node: ['24']
182182
# 0-based index
183183
shardIndex: [0, 1, 2]
184184
shardTotal: [3]
@@ -207,7 +207,9 @@ jobs:
207207
run: pnpm install --frozen-lockfile
208208

209209
- name: Run tests
210-
run: pnpm run --filter=./tools/egg-bin ci
210+
run: |
211+
pnpm build --workspace ./tools/egg-bin
212+
pnpm run --filter ./tools/egg-bin ci
211213
env:
212214
# https://github.com/jamiebuilds/ci-parallel-vars
213215
CI_NODE_INDEX: ${{ matrix.shardIndex }}
@@ -251,7 +253,9 @@ jobs:
251253
run: pnpm install --frozen-lockfile
252254

253255
- name: Run tests
254-
run: pnpm run --filter=./tools/scripts ci
256+
run: |
257+
pnpm build
258+
pnpm run --filter=./tools/scripts ci
255259
256260
- name: Code Coverage
257261
if: ${{ matrix.os != 'windows-latest' }}

.github/workflows/release.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,12 @@ jobs:
7272
cache: 'pnpm'
7373
registry-url: 'https://registry.npmjs.org'
7474

75-
- name: Re-install npm
76-
# TODO: OIDC requires npm >=11.5.1.
77-
# Until Node.js v24 is LTS (with npm 11 as the default), we need to bump.
78-
run: npm install -g npm@11
79-
8075
- name: Install dependencies
8176
run: pnpm install --frozen-lockfile
8277

78+
- name: Run build
79+
run: pnpm build
80+
8381
- name: Configure Git
8482
run: |
8583
git config --local user.email "action@github.com"

CLAUDE.md

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ The framework follows a specific loading order:
222222
- **`pnpm-workspace.yaml`** - pnpm workspace configuration with catalog dependencies
223223
- **`package.json`** - Root monorepo configuration with pnpm scripts
224224
- **`tsconfig.json`** - Root TypeScript configuration for all packages (extends @eggjs/tsconfig)
225-
- **`tsconfig.build.json`** - Root build configuration (extends tsconfig.json)
226225
- **`packages/egg/package.json`** - Main egg package with hybrid CommonJS/ESM exports
227226
- **`packages/egg/tsconfig.json`** - Extends workspace root tsconfig.json
228227
- **`packages/egg/tsdown.config.ts`** - tsdown build configuration for unbundled ESM output
@@ -288,7 +287,6 @@ The framework extends Koa's context with Egg-specific features:
288287
2. Add package.json with workspace dependencies using `workspace:*`
289288
3. Create minimal TypeScript config files:
290289
- `tsconfig.json``{"extends": "../../tsconfig.json"}`
291-
- `tsconfig.build.json``{"extends": "../../tsconfig.build.json"}`
292290
4. Add package reference to root tsconfig.json `references` array
293291
5. Update root pnpm-workspace.yaml if needed (plugins/\* is already included)
294292
6. Use `pnpm --filter=<package>` for package-specific commands
@@ -305,35 +303,38 @@ All Egg framework plugins should be placed in the `plugins/` directory:
305303
- `src/` - TypeScript source code
306304
- `test/` - Test suite (use Vitest for new plugins)
307305
- `package.json` with `eggPlugin` configuration
308-
- `tsdown.config.ts` - Build configuration (see standard template below)
306+
- `tsdown.config.ts` - Only needed if custom build options required (see below)
309307

310-
#### Standard Plugin tsdown Configuration
308+
#### tsdown Workspace Configuration
311309

312-
**IMPORTANT: All future plugins MUST use this tsdown configuration template** (based on `plugins/development/tsdown.config.ts`):
310+
**This monorepo uses tsdown workspace mode** for build configuration. The root `/tsdown.config.ts` defines shared defaults for all packages:
311+
312+
- `entry: 'src/**/*.ts'` - Processes all TypeScript files in src directory
313+
- `unbundle: true` - Creates unbundled output (preserves file structure)
314+
- `dts: true` - Generates TypeScript declaration files
315+
- `exports.devExports: true` - Enables development-friendly exports
316+
- `unused.level: 'error'` - Error on unused dependencies
317+
- `publint` - Package linting enabled
318+
319+
**Most plugins do NOT need a `tsdown.config.ts` file** - they inherit all settings from the root workspace config.
320+
321+
**Only create a `tsdown.config.ts` if you need custom options** (e.g., copy assets, custom entry points, ignore unused deps):
313322

314323
```typescript
324+
// plugins/[plugin-name]/tsdown.config.ts - ONLY if custom options needed
315325
import { defineConfig } from 'tsdown';
316326

317327
export default defineConfig({
318-
entry: 'src/**/*.ts',
319-
unbundle: true,
320-
unused: {
321-
level: 'error',
322-
},
323-
dts: true,
324-
exports: {
325-
devExports: true,
326-
},
328+
// Only specify options that differ from workspace defaults
329+
copy: [
330+
{
331+
from: 'src/assets/template.html',
332+
to: 'dist/assets/template.html',
333+
},
334+
],
327335
});
328336
```
329337

330-
This configuration ensures:
331-
332-
- **`entry: 'src/**/\*.ts'`\*\* - Processes all TypeScript files in src directory
333-
- **`unbundle: true`** - Creates unbundled output (preserves file structure)
334-
- **`dts: true`** - Generates TypeScript declaration files
335-
- **`exports.devExports: true`** - Enables development-friendly exports
336-
337338
#### Standard Plugin TypeScript Types
338339

339340
**IMPORTANT: All plugins MUST define a `src/types.ts` file** that extends the Egg module declarations:
@@ -427,11 +428,8 @@ Plugins should configure their package.json following this pattern:
427428
},
428429
"files": ["dist"],
429430
"scripts": {
430-
"build": "tsdown && rimraf dist *.tsbuildinfo && tsc -p tsconfig.build.json",
431-
"typecheck": "tsgo --noEmit && tsc --noEmit",
432-
"lint": "oxlint --type-aware",
433-
"test": "vitest run",
434-
"prepublishOnly": "pnpm run build"
431+
"typecheck": "tsgo --noEmit",
432+
"test": "vitest run"
435433
}
436434
}
437435
```
@@ -471,7 +469,7 @@ Tool packages (like egg-bin) should be placed in the `tools/` directory:
471469
- Use `oxlint --type-aware` for enhanced TypeScript checking
472470
- oxlint automatically respects `.gitignore` patterns for file exclusion
473471
- Package-specific scripts:
474-
- `"typecheck": "tsgo --noEmit && tsc --noEmit"` - Pure TypeScript type checking
472+
- `"typecheck": "tsgo --noEmit"` - Pure TypeScript type checking
475473
- `"lint": "oxlint --type-aware"` - Linting with type awareness
476474
- Remove any `.eslintrc` or `.eslintrc.js` files when migrating packages
477475

@@ -509,10 +507,6 @@ Tool packages (like egg-bin) should be placed in the `tools/` directory:
509507
- Uses `${configDir}` variable for dynamic path resolution
510508
- Includes project `references` array listing all sub-packages
511509
- Sets `composite: true` and `incremental: true` for project references
512-
- `tsconfig.build.json` - Build-specific configuration
513-
- Extends from root `tsconfig.json`
514-
- Defines `rootDir` as `${configDir}/src` and `outDir` as `${configDir}/dist`
515-
- Excludes test files, dist directories, and config files
516510

517511
**Sub-Project Configuration Pattern:**
518512

@@ -525,13 +519,6 @@ All packages, plugins, and tools MUST follow this minimal pattern:
525519
}
526520
```
527521

528-
```json
529-
// packages/*/tsconfig.build.json, plugins/*/tsconfig.build.json
530-
{
531-
"extends": "../../tsconfig.build.json"
532-
}
533-
```
534-
535522
**Key Requirements:**
536523

537524
- **Keep it minimal** - Sub-project configs should ONLY contain the `extends` field
@@ -852,7 +839,7 @@ NODE_OPTIONS='--inspect-brk' pnpm --filter=egg run test
852839
- Add `"oxlint": "catalog:"` to devDependencies
853840
2. Delete `.eslintrc`, `.eslintrc.js`, or `.eslintrc.json` files
854841
3. Update scripts in package.json:
855-
- Add `"typecheck": "tsgo --noEmit && tsc --noEmit"` for TypeScript type checking
842+
- Add `"typecheck": "tsgo --noEmit"` for TypeScript type checking
856843
- Change `"lint": "eslint ..."` to `"lint": "oxlint --type-aware"`
857844
- Add `"lint:fix": "npm run lint -- --fix"`
858845
4. Ensure both type checking and linting are run:

examples/helloworld-commonjs/package.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
"scripts": {
88
"dev": "egg-bin dev",
99
"debug": "egg-bin debug",
10-
"test": "egg-bin test",
11-
"cov": "egg-bin cov",
12-
"lint": "oxlint",
1310
"ci": "pnpm run lint && pnpm run cov",
1411
"start": "egg-scripts start --daemon",
1512
"stop": "egg-scripts stop"
@@ -18,8 +15,7 @@
1815
"egg": "workspace:*"
1916
},
2017
"devDependencies": {
21-
"@eggjs/bin": "workspace:*",
22-
"oxlint": "catalog:"
18+
"@eggjs/bin": "workspace:*"
2319
},
2420
"engines": {
2521
"node": ">=22.18.0"

examples/helloworld-tegg/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"prepublishOnly": "pnpm run build",
4545
"start": "egg-scripts start --daemon",
4646
"stop": "egg-scripts stop",
47-
"typecheck": "tsgo --noEmit && tsc --noEmit",
47+
"typecheck": "tsgo --noEmit",
4848
"build": "tsdown"
4949
},
5050
"dependencies": {

examples/helloworld-typescript/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"prepublishOnly": "pnpm run build",
3333
"start": "egg-scripts start --daemon",
3434
"stop": "egg-scripts stop",
35-
"typecheck": "tsgo --noEmit && tsc --noEmit",
35+
"typecheck": "tsgo --noEmit",
3636
"build": "tsdown"
3737
},
3838
"dependencies": {

package.json

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
},
1111
"type": "module",
1212
"scripts": {
13-
"clean": "pnpm -r --parallel run clean && rimraf packages/*/dist plugins/*/dist tools/*/dist examples/*/dist tegg/**/dist **/*/*.tsbuildinfo",
14-
"build": "pnpm clean && pnpm -r run build",
15-
"build:parallel": "pnpm clean && pnpm -r --parallel run build",
13+
"clean-dist": "pnpm -r --parallel exec rimraf dist",
14+
"clean": "pnpm -r --parallel run clean && pnpm clean-dist",
15+
"build": "tsdown",
16+
"prelint": "pnpm clean-dist",
1617
"lint": "oxlint --type-aware --type-check --quiet",
1718
"fmt": "oxfmt",
1819
"typecheck": "pnpm clean && pnpm -r run typecheck",
19-
"typecheck:parallel": "pnpm clean && pnpm -r --parallel run typecheck",
2020
"fmtcheck": "oxfmt --check .",
2121
"pretest": "pnpm run clean && pnpm -r run pretest",
22-
"test": "vitest run --bail 1 --retry 2",
22+
"test": "vitest run --bail 1 --retry 2 --testTimeout 20000 --hookTimeout 20000",
2323
"test:cov": "pnpm run test --coverage",
2424
"preci": "pnpm -r --parallel run pretest",
25-
"ci": "vitest run --bail 1 --retry 2 --coverage --testTimeout 20000 --hookTimeout 20000",
25+
"ci": "pnpm run test --coverage",
2626
"site:dev": "pnpm --filter=site run dev",
2727
"site:build": "pnpm --filter=site run build",
2828
"puml": "puml . --dest ./site",
@@ -60,14 +60,15 @@
6060
"publint": "catalog:",
6161
"rimraf": "catalog:",
6262
"semver": "catalog:",
63+
"tsdown": "catalog:",
6364
"tsx": "catalog:",
6465
"typescript": "catalog:",
6566
"urllib": "catalog:",
6667
"vitest": "catalog:"
6768
},
6869
"lint-staged": {
6970
"*": [
70-
"oxfmt",
71+
"oxfmt --no-error-on-unmatched-pattern",
7172
"oxlint --type-aware --fix"
7273
]
7374
},

packages/cluster/package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@
4141
}
4242
},
4343
"scripts": {
44-
"build": "tsdown && rimraf dist *.tsbuildinfo && tsc -p tsconfig.build.json",
4544
"lint": "oxlint",
46-
"typecheck": "tsgo --noEmit && tsc --noEmit",
47-
"test": "vitest run",
48-
"prepublishOnly": "pnpm run build"
45+
"typecheck": "tsgo --noEmit",
46+
"test": "vitest run"
4947
},
5048
"dependencies": {
5149
"@eggjs/utils": "workspace:*",

packages/cluster/tsconfig.build.json

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

packages/cluster/tsdown.config.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
import { defineConfig, type UserConfig } from 'tsdown';
1+
import { defineConfig } from 'tsdown';
22

3-
import baseConfig from '../../tsdown.config.json' with { type: 'json' };
4-
5-
const config: UserConfig = defineConfig({
6-
...(baseConfig as UserConfig),
3+
export default defineConfig({
74
entry: {
85
index: 'src/index.ts',
96
agent_worker: 'src/agent_worker.ts',
107
app_worker: 'src/app_worker.ts',
118
},
129
});
13-
14-
export default config;

0 commit comments

Comments
 (0)