Skip to content

Commit 9a32d71

Browse files
killaclaude
authored andcommitted
perf(test): transpile runtime .ts imports with oxc-node instead of tsx
The vitest run loads many .ts files at runtime via Node's native `import()` (the egg loader resolving fixtures/plugins/app code, plus workspace `src` exports under node_modules). That path is driven by the `--import` hook in `test.env.NODE_OPTIONS`, previously `tsx/esm`. Switch it to `@oxc-node/core/register` (oxc-based, Rust): it is noticeably faster than tsx and transpiles workspace `src` + decorators correctly. `@oxc-node/core` >= 0.1.0 fixes the earlier "Cannot read properties of undefined (reading 'mode')" crash that blocked this swap (the old FIXME). Full Node-22 suite (isolate:false, --retry 2): same pass/fail result as tsx (only the env-dependent orm/ssrf failures), with the runtime-transpile portion ~6-13% faster depending on how transpile-heavy the workload is. tsx is kept as a dependency — it is still used by worker_threads tests and a few other spots. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent d8c6128 commit 9a32d71

3 files changed

Lines changed: 8 additions & 5 deletions

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"devDependencies": {
5353
"@eggjs/bin": "workspace:*",
5454
"@eggjs/tsconfig": "workspace:*",
55+
"@oxc-node/core": "catalog:",
5556
"@types/content-type": "catalog:",
5657
"@types/js-yaml": "catalog:",
5758
"@types/koa-compose": "catalog:",

pnpm-workspace.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ catalog:
1818
'@eggjs/scripts': ^4.0.0
1919
'@fengmk2/ps-tree': ^2.0.1
2020
'@oclif/core': ^4.2.0
21-
'@oxc-node/core': ^0.0.35
21+
'@oxc-node/core': ^0.1.0
2222
'@swc-node/register': ^1.11.1
2323
'@swc/core': ^1.15.1
2424
'@types/accepts': ^1.3.7

vitest.config.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,12 @@ const config: UserWorkspaceConfig = defineConfig({
3636
env: {
3737
// disable tegg plugins by default on unittest, make test speed up
3838
DISABLE_TEGG_PLUGINS: 'true',
39-
// TODO: aop plugin required this flag, otherwise there will be a SyntaxError: Invalid or unexpected token
40-
NODE_OPTIONS: '--import=tsx/esm',
41-
// FIXME: TypeError: Cannot read properties of undefined (reading 'mode')
42-
// NODE_OPTIONS: '--import=@oxc-node/core/register',
39+
// Transpile runtime `import()` of .ts files (egg loader resolving
40+
// fixtures/plugins/app code, and the workspace `src` exports under
41+
// node_modules) with oxc-node — noticeably faster than tsx and it handles
42+
// decorators correctly. Requires @oxc-node/core >= 0.1.0, which fixes the
43+
// earlier "Cannot read properties of undefined (reading 'mode')" crash.
44+
NODE_OPTIONS: '--import=@oxc-node/core/register',
4345
},
4446
// poolOptions: {
4547
// forks: {

0 commit comments

Comments
 (0)