Skip to content

Commit

Permalink
fix: always get extension from Module._extensions (#211)
Browse files Browse the repository at this point in the history
ts-node/register may require after tegg loader

<!--
Thank you for your pull request. Please review below requirements.
Bug fixes and new features should include tests and possibly benchmarks.
Contributors guide:
https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md

感谢您贡献代码。请确认下列 checklist 的完成情况。
Bug 修复和新功能必须包含测试,必要时请附上性能测试。
Contributors guide:
https://github.com/eggjs/egg/blob/master/CONTRIBUTING.md
-->

##### Checklist
<!-- Remove items that do not apply. For completed items, change [ ] to
[x]. -->

- [ ] `npm test` passes
- [ ] tests and/or benchmarks are included
- [ ] documentation is changed or added
- [ ] commit message follows commit guidelines

##### Affected core subsystem(s)
<!-- Provide affected core subsystem(s). -->


##### Description of change
<!-- Provide a description of the change below this comment. -->

<!--
- any feature?
- close https://github.com/eggjs/egg/ISSUE_URL
-->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Refactor**
- Improved how file extensions are determined in the loading process to
enhance flexibility and reliability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
killagu committed Apr 17, 2024
1 parent 334e13d commit 62e9c06
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/loader/src/LoaderUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
Expand All @@ -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);
Expand Down

0 comments on commit 62e9c06

Please sign in to comment.