Skip to content

Commit

Permalink
add mts and cts awareness to internal/external classifier; add .d.cts…
Browse files Browse the repository at this point in the history
…/.d.mts extensions to tests
  • Loading branch information
cspotcode committed May 18, 2022
1 parent 5b1dcdc commit 00755d0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/resolver-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,17 @@ export function createResolverFunctions(kwargs: {
) => {
const { resolvedFileName } = resolvedModule;
if (resolvedFileName === undefined) return;
// .ts is always switched to internal
// [MUST_UPDATE_FOR_NEW_FILE_EXTENSIONS]
// .ts,.mts,.cts is always switched to internal
// .js is switched on-demand
if (
resolvedModule.isExternalLibraryImport &&
((resolvedFileName.endsWith('.ts') &&
!resolvedFileName.endsWith('.d.ts')) ||
(resolvedFileName.endsWith('.cts') &&
!resolvedFileName.endsWith('.d.cts')) ||
(resolvedFileName.endsWith('.mts') &&
!resolvedFileName.endsWith('.d.mts')) ||
isFileKnownToBeInternal(resolvedFileName) ||
isFileInInternalBucket(resolvedFileName))
) {
Expand Down
6 changes: 5 additions & 1 deletion src/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1044,14 +1044,18 @@ test.suite('ts-node', (test) => {
'.d.ts',
'.mts',
'.cts',
'.d.mts',
'.d.cts',
'.mjs',
'.cjs',
'.tsx',
'.jsx',
'.xyz',
'',
];
const mtsCts = tsSupportsMtsCtsExtensions ? ['.mts', '.cts'] : [];
const mtsCts = tsSupportsMtsCtsExtensions
? ['.mts', '.cts', '.d.mts', '.d.cts']
: [];
const mjsCjs = tsSupportsMtsCtsExtensions ? ['.mjs', '.cjs'] : [];

test('correctly filters file extensions from the compiler when allowJs=false and jsx=false', (t) => {
Expand Down

0 comments on commit 00755d0

Please sign in to comment.