From 62e9c06f3cbde28d17d0e43797d4080279d7b9fa Mon Sep 17 00:00:00 2001 From: killa Date: Wed, 17 Apr 2024 17:21:51 +0800 Subject: [PATCH] fix: always get extension from Module._extensions (#211) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ts-node/register may require after tegg loader ##### Checklist - [ ] `npm test` passes - [ ] tests and/or benchmarks are included - [ ] documentation is changed or added - [ ] commit message follows commit guidelines ##### Affected core subsystem(s) ##### Description of change ## Summary by CodeRabbit - **Refactor** - Improved how file extensions are determined in the loading process to enhance flexibility and reliability. --- core/loader/src/LoaderUtil.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/loader/src/LoaderUtil.ts b/core/loader/src/LoaderUtil.ts index 6f281a45..8cfcf0a6 100644 --- a/core/loader/src/LoaderUtil.ts +++ b/core/loader/src/LoaderUtil.ts @@ -9,8 +9,6 @@ const Module = module.constructor.length > 1 /* istanbul ignore next */ : BuiltinModule; -const EXTENSION = Object.keys((Module as any)._extensions).find(t => t === '.ts') ? '.ts' : '.js'; - interface LoaderUtilConfig { extraFilePattern?: string[]; } @@ -21,7 +19,9 @@ export class LoaderUtil { this.config = config; } - static extension = EXTENSION; + static get extension() { + return Object.keys((Module as any)._extensions).find(t => t === '.ts') ? '.ts' : '.js'; + } static filePattern(): string[] { const extensions = Object.keys((Module as any)._extensions);