Skip to content

Commit 12af5f9

Browse files
authored
feat: detect typescript enable on env.VITEST === 'true' (#42)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Improved the logic for detecting TypeScript compatibility by incorporating an additional environment condition. - Introduced a new utility to streamline the retrieval of module extension information for better consistency. - **Tests** - Updated the verification suite to include the newly exposed utility in the module's public interface. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent a439076 commit 12af5f9

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/import.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,17 @@ function getRequire() {
3232
return _customRequire;
3333
}
3434

35+
export function getExtensions() {
36+
return getRequire().extensions;
37+
}
38+
3539
let _supportTypeScript: boolean | undefined;
3640
export function isSupportTypeScript() {
3741
if (_supportTypeScript === undefined) {
38-
const extensions = getRequire().extensions;
39-
_supportTypeScript = extensions['.ts'] !== undefined;
40-
debug('[isSupportTypeScript] %o, extensions: %j', _supportTypeScript, Object.keys(extensions));
42+
const extensions = getExtensions();
43+
_supportTypeScript = extensions['.ts'] !== undefined || process.env.VITEST === 'true';
44+
debug('[isSupportTypeScript] %o, extensions: %j, process.env.VITEST: %j',
45+
_supportTypeScript, Object.keys(extensions), process.env.VITEST);
4146
}
4247
return _supportTypeScript;
4348
}

test/index.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ describe('test/index.test.ts', () => {
3838
'default',
3939
'detectType',
4040
'getConfig',
41+
'getExtensions',
4142
'getFrameworkOrEggPath',
4243
'getFrameworkPath',
4344
'getLoadUnits',

0 commit comments

Comments
 (0)