This repository was archived by the owner on Oct 18, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +18
-4
lines changed
Expand file tree Collapse file tree 3 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -52,15 +52,15 @@ export const resolve: resolve = async function (
5252 }
5353
5454 /**
55- * Typescript 4.6.0 behavior seems to be that if `.mjs` is specified,
56- * it converts it to mts without testing if it exists, and without
57- * consideration for whether a file with .mjs exists
55+ * Typescript gives .mts or .cts priority over actual .mjs or .cjs extensions
5856 */
5957 if (
6058 / \. [ c m ] j s $ / . test ( specifier )
6159 && tsExtensionsPattern . test ( context . parentURL ! )
6260 ) {
63- specifier = `${ specifier . slice ( 0 , - 2 ) } ts` ;
61+ try {
62+ return await resolve ( `${ specifier . slice ( 0 , - 2 ) } ts` , context , defaultResolve ) ;
63+ } catch { }
6464 }
6565
6666 if ( tsExtensionsPattern . test ( specifier ) ) {
Original file line number Diff line number Diff line change @@ -30,6 +30,15 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
3030 expect ( nodeProcess . stderr ) . toMatch ( 'Cannot find module \'node:' ) ;
3131 }
3232 } ) ;
33+
34+ test ( 'TypeScript Import' , async ( ) => {
35+ const nodeProcess = await node . import ( importPath , { typescript : true } ) ;
36+ if ( semver . satisfies ( node . version , nodeSupportsNodePrefixRequire ) ) {
37+ expect ( nodeProcess . stdout ) . toBe ( `${ output } \n{"default":1234}` ) ;
38+ } else {
39+ expect ( nodeProcess . stderr ) . toMatch ( 'Cannot find module \'node:' ) ;
40+ }
41+ } ) ;
3342 } ) ;
3443
3544 describe ( 'extensionless - should not work' , ( { test } ) => {
Original file line number Diff line number Diff line change @@ -19,6 +19,11 @@ export default testSuite(async ({ describe }, node: NodeApis) => {
1919 const nodeProcess = await node . import ( importPath ) ;
2020 expect ( nodeProcess . stdout ) . toBe ( `${ output } \n{"default":1234}` ) ;
2121 } ) ;
22+
23+ test ( 'TypeScript Import' , async ( ) => {
24+ const nodeProcess = await node . import ( importPath , { typescript : true } ) ;
25+ expect ( nodeProcess . stdout ) . toBe ( `${ output } \n{"default":1234}` ) ;
26+ } ) ;
2227 } ) ;
2328
2429 describe ( 'extensionless - should not work' , ( { test } ) => {
You can’t perform that action at this time.
0 commit comments