diff --git a/.vscode/settings.json b/.vscode/settings.json index 5c370d3990a0..3dcc2efd65d0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,7 +14,7 @@ ], "eslint.nodePath": ".yarn/sdks", "editor.codeActionsOnSave": { - "source.fixAll.eslint": true + "source.fixAll.eslint": "explicit" }, "pasteImage.path": "${projectRoot}/packages/gatsby/static", "pasteImage.basePath": "${projectRoot}/packages/gatsby/static", diff --git a/.yarn/versions/0fefb43f.yml b/.yarn/versions/0fefb43f.yml new file mode 100644 index 000000000000..9f2a58084c4d --- /dev/null +++ b/.yarn/versions/0fefb43f.yml @@ -0,0 +1,2 @@ +declined: + - "@yarnpkg/pnp" diff --git a/packages/acceptance-tests/pkg-tests-specs/sources/pnp-esm.test.ts b/packages/acceptance-tests/pkg-tests-specs/sources/pnp-esm.test.ts index 91e81c13588e..bddcbd09a233 100644 --- a/packages/acceptance-tests/pkg-tests-specs/sources/pnp-esm.test.ts +++ b/packages/acceptance-tests/pkg-tests-specs/sources/pnp-esm.test.ts @@ -423,7 +423,7 @@ describe(`Plug'n'Play - ESM`, () => { ), ); - test( + (loaderFlags.ALLOWS_EXTENSIONLESS_FILES ? it.skip : it)( `it should not allow extensionless commonjs imports`, makeTemporaryEnv( { }, @@ -444,7 +444,27 @@ describe(`Plug'n'Play - ESM`, () => { ), ); - test( + (loaderFlags.ALLOWS_EXTENSIONLESS_FILES ? it : it.skip)( + `it should allow extensionless commonjs imports`, + makeTemporaryEnv( + { }, + { + pnpEnableEsmLoader: true, + }, + async ({path, run, source}) => { + await xfs.writeFilePromise(ppath.join(path, `index.mjs` as Filename), `import bin from './cjs-bin';\nconsole.log(bin)`); + await xfs.writeFilePromise(ppath.join(path, `cjs-bin` as Filename), `module.exports = 42`); + + await expect(run(`install`)).resolves.toMatchObject({code: 0}); + + await expect(run(`node`, `./index.mjs`)).resolves.toMatchObject({ + stdout: `42\n`, + }); + }, + ), + ); + + (loaderFlags.ALLOWS_EXTENSIONLESS_FILES ? it.skip : it)( `it should not allow extensionless files with {"type": "module"}`, makeTemporaryEnv( { @@ -466,6 +486,27 @@ describe(`Plug'n'Play - ESM`, () => { ), ); + (loaderFlags.ALLOWS_EXTENSIONLESS_FILES ? it : it.skip)( + `it should allow extensionless files with {"type": "module"}`, + makeTemporaryEnv( + { + type: `module`, + }, + { + pnpEnableEsmLoader: true, + }, + async ({path, run, source}) => { + await xfs.writeFilePromise(ppath.join(path, `index` as Filename), `console.log(42)`); + + await expect(run(`install`)).resolves.toMatchObject({code: 0}); + + await expect(run(`node`, `./index`)).resolves.toMatchObject({ + stdout: `42\n`, + }); + }, + ), + ); + test( `it should support ESM binaries`, makeTemporaryEnv( diff --git a/packages/yarnpkg-pnp/sources/esm-loader/loaderFlags.ts b/packages/yarnpkg-pnp/sources/esm-loader/loaderFlags.ts index 2b83ddb60dc7..4d5ca763afff 100644 --- a/packages/yarnpkg-pnp/sources/esm-loader/loaderFlags.ts +++ b/packages/yarnpkg-pnp/sources/esm-loader/loaderFlags.ts @@ -23,3 +23,6 @@ export const HAS_LOADERS_AFFECTING_LOADERS = major > 19 || (major === 19 && mino // https://github.com/nodejs/node/pull/42881 export const ALLOWS_NON_FILE_PARENT = major > 18 || (major === 18 && minor >= 1) || (major === 16 && minor >= 17); + +// https://github.com/nodejs/node/pull/49869 +export const ALLOWS_EXTENSIONLESS_FILES = major >= 21 || (major === 20 && minor >= 10) || (major === 18 && minor >= 19);