Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/integration-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ jobs:
fail-fast: false
matrix:
# We run the ubuntu tests on multiple Node versions with 2 shards since they're the fastest.
node: [18, 19, 20, 21, 22]
node: [18, 19, 20, 21, 22, 23]
platform: [[ubuntu, 20.04]]
shard: ['1/2', '2/2']
include:
Expand Down
77 changes: 70 additions & 7 deletions packages/acceptance-tests/pkg-tests-specs/sources/pnp-esm.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Filename, npath, ppath, xfs} from '@yarnpkg/fslib';
import {ALLOWS_EXTENSIONLESS_FILES, HAS_LOADERS_AFFECTING_LOADERS, SUPPORTS_IMPORT_ATTRIBUTES, SUPPORTS_IMPORT_ATTRIBUTES_ONLY} from '@yarnpkg/pnp/sources/esm-loader/loaderFlags';
import {pathToFileURL} from 'url';
import {Filename, npath, ppath, xfs} from '@yarnpkg/fslib';
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';
import {pathToFileURL} from 'url';

describe(`Plug'n'Play - ESM`, () => {
test(
Expand Down Expand Up @@ -361,7 +361,7 @@
test(
`it should load extensionless commonjs files as an entrypoint`,
makeTemporaryEnv(
{ },
{},
{
pnpEnableEsmLoader: true,
},
Expand All @@ -381,7 +381,7 @@
test(
`it should load symlinked extensionless commonjs files as an entrypoint`,
makeTemporaryEnv(
{ },
{},
{
pnpEnableEsmLoader: true,
},
Expand All @@ -403,7 +403,7 @@
(ALLOWS_EXTENSIONLESS_FILES ? it.skip : it)(
`it should not allow extensionless commonjs imports`,
makeTemporaryEnv(
{ },
{},
{
pnpEnableEsmLoader: true,
},
Expand All @@ -424,7 +424,7 @@
(ALLOWS_EXTENSIONLESS_FILES ? it : it.skip)(
`it should allow extensionless commonjs imports`,
makeTemporaryEnv(
{ },
{},
{
pnpEnableEsmLoader: true,
},
Expand Down Expand Up @@ -1160,4 +1160,67 @@
},
),
);
(SUPPORTS_TYPE_STRIPPING ? describe : describe.skip)(`Node builtin type stripping`, () => {
for (const type of [`module`, `commonjs`, undefined]) {
test(
`${type}: it should import mts typescript`,
makeTemporaryEnv(
{
type,
dependencies: {
"no-deps": `1.0.0`,
},
},
{
pnpEnableEsmLoader: true,
},
async ({path, run}) => {
await xfs.writeFilePromise(ppath.join(path, `mod.mts`), `export const foo = 42 as any;`);

await xfs.writeFilePromise(ppath.join(path, `index.mts`), `
import * as fs from 'node:fs';
import * as asd from 'no-deps/index.js';
import {foo} from './mod.mts';
console.log(foo as any);`,
);
await run(`install`);
await expect(run(`node`, `index.mts`)).resolves.toMatchObject({
code: 0,
stdout: `42\n`,
});
},
),
);
test(
`${type}: it should import cts typescript`,
makeTemporaryEnv(
{
type,
dependencies: {
"no-deps": `1.0.0`,
},
},
{
pnpEnableEsmLoader: true,
},
async ({path, run}) => {
await xfs.writeFilePromise(ppath.join(path, `mod.cts`), `module.exports.foo = 42 as any;`);

Check failure on line 1208 in packages/acceptance-tests/pkg-tests-specs/sources/pnp-esm.test.ts

View workflow job for this annotation

GitHub Actions / Testing chores

Trailing spaces not allowed
await xfs.writeFilePromise(ppath.join(path, `index.cts`), `
const fs = require('node:fs');
const asd = require('no-deps/index.js');
const {foo} = require('./mod.cts');
console.log(foo as any);`

Check failure on line 1213 in packages/acceptance-tests/pkg-tests-specs/sources/pnp-esm.test.ts

View workflow job for this annotation

GitHub Actions / Testing chores

Missing trailing comma
);

await run(`install`);
await expect(run(`node`, `index.cts`)).resolves.toMatchObject({
code: 0,
stdout: `42\n`,
});
},
),
);
}
});
});
3 changes: 3 additions & 0 deletions packages/yarnpkg-pnp/sources/esm-loader/loaderFlags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ export const SUPPORTS_IMPORT_ATTRIBUTES = major >= 21 || (major === 20 && minor

// https://github.com/nodejs/node/pull/52104
export const SUPPORTS_IMPORT_ATTRIBUTES_ONLY = major >= 22;

// https://github.com/nodejs/node/pull/53725
export const SUPPORTS_TYPE_STRIPPING = major > 23 || (major === 23 && minor > 6);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading