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' ;
4
4
5
5
describe ( `Plug'n'Play - ESM` , ( ) => {
6
6
test (
@@ -361,7 +361,7 @@ describe(`Plug'n'Play - ESM`, () => {
361
361
test (
362
362
`it should load extensionless commonjs files as an entrypoint` ,
363
363
makeTemporaryEnv (
364
- { } ,
364
+ { } ,
365
365
{
366
366
pnpEnableEsmLoader : true ,
367
367
} ,
@@ -381,7 +381,7 @@ describe(`Plug'n'Play - ESM`, () => {
381
381
test (
382
382
`it should load symlinked extensionless commonjs files as an entrypoint` ,
383
383
makeTemporaryEnv (
384
- { } ,
384
+ { } ,
385
385
{
386
386
pnpEnableEsmLoader : true ,
387
387
} ,
@@ -403,7 +403,7 @@ describe(`Plug'n'Play - ESM`, () => {
403
403
( ALLOWS_EXTENSIONLESS_FILES ? it . skip : it ) (
404
404
`it should not allow extensionless commonjs imports` ,
405
405
makeTemporaryEnv (
406
- { } ,
406
+ { } ,
407
407
{
408
408
pnpEnableEsmLoader : true ,
409
409
} ,
@@ -424,7 +424,7 @@ describe(`Plug'n'Play - ESM`, () => {
424
424
( ALLOWS_EXTENSIONLESS_FILES ? it : it . skip ) (
425
425
`it should allow extensionless commonjs imports` ,
426
426
makeTemporaryEnv (
427
- { } ,
427
+ { } ,
428
428
{
429
429
pnpEnableEsmLoader : true ,
430
430
} ,
@@ -1160,4 +1160,67 @@ describe(`Plug'n'Play - ESM`, () => {
1160
1160
} ,
1161
1161
) ,
1162
1162
) ;
1163
+ ( SUPPORTS_TYPE_STRIPPING ? describe : describe . skip ) ( `Node builtin type stripping` , ( ) => {
1164
+ for ( const type of [ `module` , `commonjs` , undefined ] ) {
1165
+ test (
1166
+ `${ type } : it should import mts typescript` ,
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 } : it should import cts typescript` ,
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
+ } ) ;
1163
1226
} ) ;
0 commit comments