Skip to content

Commit

Permalink
fix: avoid to duplicate register ts-node in dev (#5015)
Browse files Browse the repository at this point in the history
  • Loading branch information
yimingjfe authored Nov 29, 2023
1 parent 8793e64 commit a3f2269
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/clever-weeks-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@modern-js/bff-core': patch
---

fix: avoid to duplicate register ts-node in dev
fix: 避免在开发环境重复注册 ts-node
7 changes: 2 additions & 5 deletions packages/server/bff-core/src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -313,6 +309,7 @@ export class ApiRouter {
}

private getModuleInfo(filename: string) {
this.enableRegister();
try {
const module = requireHandlerModule(filename);
return {
Expand Down

0 comments on commit a3f2269

Please sign in to comment.