From a3f2269d114c9c749b4e66a5d6cc76f234b03925 Mon Sep 17 00:00:00 2001 From: Ming Date: Wed, 29 Nov 2023 17:34:42 +0800 Subject: [PATCH] fix: avoid to duplicate register ts-node in dev (#5015) --- .changeset/clever-weeks-wink.md | 6 ++++++ packages/server/bff-core/src/router/index.ts | 7 ++----- 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 .changeset/clever-weeks-wink.md diff --git a/.changeset/clever-weeks-wink.md b/.changeset/clever-weeks-wink.md new file mode 100644 index 000000000000..e4b4049f4d22 --- /dev/null +++ b/.changeset/clever-weeks-wink.md @@ -0,0 +1,6 @@ +--- +'@modern-js/bff-core': patch +--- + +fix: avoid to duplicate register ts-node in dev +fix: 避免在开发环境重复注册 ts-node diff --git a/packages/server/bff-core/src/router/index.ts b/packages/server/bff-core/src/router/index.ts index cf8fd91c3858..5e3475cdd4c8 100644 --- a/packages/server/bff-core/src/router/index.ts +++ b/packages/server/bff-core/src/router/index.ts @@ -68,16 +68,12 @@ export class ApiRouter { this.lambdaDir = this.getExactLambdaDir(this.apiDir, lambdaDir); this.existLambdaDir = fs.existsSync(this.lambdaDir); debug(`apiDir:`, this.apiDir, `lambdaDir:`, this.lambdaDir); - this.enableRegister(); } private enableRegister() { // eslint-disable-next-line node/no-deprecated-api const existTsLoader = Boolean(require.extensions['.ts']); - if ( - !existTsLoader && - (process.env.NODE_ENV !== 'production' || this.isBuild) - ) { + if (!existTsLoader) { try { const projectSearchDir = this.appDir || this.apiDir; const tsNode: typeof import('ts-node') = require('ts-node'); @@ -313,6 +309,7 @@ export class ApiRouter { } private getModuleInfo(filename: string) { + this.enableRegister(); try { const module = requireHandlerModule(filename); return {