Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid to duplicate register ts-node in dev #5015

Merged
merged 2 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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