Skip to content

Commit a990869

Browse files
committed
should fail
1 parent 1908ee7 commit a990869

File tree

3 files changed

+74
-8
lines changed

3 files changed

+74
-8
lines changed

.github/workflows/integration-workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ jobs:
214214
fail-fast: false
215215
matrix:
216216
# We run the ubuntu tests on multiple Node versions with 2 shards since they're the fastest.
217-
node: [18, 19, 20, 21, 22]
217+
node: [18, 19, 20, 21, 22, 23]
218218
platform: [[ubuntu, 20.04]]
219219
shard: ['1/2', '2/2']
220220
include:

packages/acceptance-tests/pkg-tests-specs/sources/pnp-esm.test.ts

Lines changed: 70 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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

55
describe(`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}: 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+
});
11631226
});

packages/yarnpkg-pnp/sources/esm-loader/loaderFlags.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ export const SUPPORTS_IMPORT_ATTRIBUTES = major >= 21 || (major === 20 && minor
2020

2121
// https://github.com/nodejs/node/pull/52104
2222
export const SUPPORTS_IMPORT_ATTRIBUTES_ONLY = major >= 22;
23+
24+
// https://github.com/nodejs/node/pull/53725
25+
export const SUPPORTS_TYPE_STRIPPING = major > 23 || (major === 23 && minor > 6);

0 commit comments

Comments
 (0)