1- import  { Filename ,  npath ,  ppath ,  xfs }                                                                                             from  '@yarnpkg/fslib' ; 
2- import  { ALLOWS_EXTENSIONLESS_FILES ,  HAS_LOADERS_AFFECTING_LOADERS ,  SUPPORTS_IMPORT_ATTRIBUTES ,  SUPPORTS_IMPORT_ATTRIBUTES_ONLY }  from  '@yarnpkg/pnp/sources/esm-loader/loaderFlags' ; 
3- import  { pathToFileURL }                                                                                                           from  'url' ; 
1+ import  { Filename ,  npath ,  ppath ,  xfs }                                                                                                                       from  '@yarnpkg/fslib' ; 
2+ import  { ALLOWS_EXTENSIONLESS_FILES ,  HAS_LOADERS_AFFECTING_LOADERS ,  SUPPORTS_IMPORT_ATTRIBUTES ,  SUPPORTS_IMPORT_ATTRIBUTES_ONLY ,   SUPPORTS_TYPE_STRIPPING }  from  '@yarnpkg/pnp/sources/esm-loader/loaderFlags' ; 
3+ import  { pathToFileURL }                                                                                                                                     from  'url' ; 
44
55describe ( `Plug'n'Play - ESM` ,  ( )  =>  { 
66  test ( 
@@ -361,7 +361,7 @@ describe(`Plug'n'Play - ESM`, () => {
361361  test ( 
362362    `it should load extensionless commonjs files as an entrypoint` , 
363363    makeTemporaryEnv ( 
364-       {   } , 
364+       { } , 
365365      { 
366366        pnpEnableEsmLoader : true , 
367367      } , 
@@ -381,7 +381,7 @@ describe(`Plug'n'Play - ESM`, () => {
381381  test ( 
382382    `it should load symlinked extensionless commonjs files as an entrypoint` , 
383383    makeTemporaryEnv ( 
384-       {   } , 
384+       { } , 
385385      { 
386386        pnpEnableEsmLoader : true , 
387387      } , 
@@ -403,7 +403,7 @@ describe(`Plug'n'Play - ESM`, () => {
403403  ( ALLOWS_EXTENSIONLESS_FILES  ? it . skip  : it ) ( 
404404    `it should not allow extensionless commonjs imports` , 
405405    makeTemporaryEnv ( 
406-       {   } , 
406+       { } , 
407407      { 
408408        pnpEnableEsmLoader : true , 
409409      } , 
@@ -424,7 +424,7 @@ describe(`Plug'n'Play - ESM`, () => {
424424  ( ALLOWS_EXTENSIONLESS_FILES  ? it  : it . skip ) ( 
425425    `it should allow extensionless commonjs imports` , 
426426    makeTemporaryEnv ( 
427-       {   } , 
427+       { } , 
428428      { 
429429        pnpEnableEsmLoader : true , 
430430      } , 
@@ -1160,4 +1160,67 @@ describe(`Plug'n'Play - ESM`, () => {
11601160      } , 
11611161    ) , 
11621162  ) ; 
1163+   ( SUPPORTS_TYPE_STRIPPING  ? describe  : describe . skip ) ( `Node builtin type stripping` ,  ( )  =>  { 
1164+     for  ( const  type  of  [ `module` ,  `commonjs` ,  undefined ] )  { 
1165+       test ( 
1166+         `${ type }  , 
1167+         makeTemporaryEnv ( 
1168+           { 
1169+             type, 
1170+             dependencies : { 
1171+               "no-deps" : `1.0.0` , 
1172+             } , 
1173+           } , 
1174+           { 
1175+             pnpEnableEsmLoader : true , 
1176+           } , 
1177+           async  ( { path,  run} )  =>  { 
1178+             await  xfs . writeFilePromise ( ppath . join ( path ,  `mod.mts` ) ,  `export const foo = 42 as any;` ) ; 
1179+ 
1180+             await  xfs . writeFilePromise ( ppath . join ( path ,  `index.mts` ) ,  ` 
1181+ import * as fs from 'node:fs'; 
1182+ import * as asd from 'no-deps/index.js'; 
1183+ import {foo} from './mod.mts'; 
1184+ console.log(foo as any);` , 
1185+             ) ; 
1186+             await  run ( `install` ) ; 
1187+             await  expect ( run ( `node` ,  `index.mts` ) ) . resolves . toMatchObject ( { 
1188+               code : 0 , 
1189+               stdout : `42\n` , 
1190+             } ) ; 
1191+           } , 
1192+         ) , 
1193+       ) ; 
1194+       test ( 
1195+         `${ type }  , 
1196+         makeTemporaryEnv ( 
1197+           { 
1198+             type, 
1199+             dependencies : { 
1200+               "no-deps" : `1.0.0` , 
1201+             } , 
1202+           } , 
1203+           { 
1204+             pnpEnableEsmLoader : true , 
1205+           } , 
1206+           async  ( { path,  run} )  =>  { 
1207+             await  xfs . writeFilePromise ( ppath . join ( path ,  `mod.cts` ) ,  `module.exports.foo = 42 as any;` ) ; 
1208+             
1209+             await  xfs . writeFilePromise ( ppath . join ( path ,  `index.cts` ) ,  ` 
1210+ const fs = require('node:fs'); 
1211+ const asd = require('no-deps/index.js'); 
1212+ const {foo} = require('./mod.cts'); 
1213+ console.log(foo as any);` 
1214+             ) ; 
1215+ 
1216+             await  run ( `install` ) ; 
1217+             await  expect ( run ( `node` ,  `index.cts` ) ) . resolves . toMatchObject ( { 
1218+               code : 0 , 
1219+               stdout : `42\n` , 
1220+             } ) ; 
1221+           } , 
1222+         ) , 
1223+       ) ; 
1224+     } 
1225+   } ) ; 
11631226} ) ; 
0 commit comments