Skip to content

Commit

Permalink
test: update Node.js range for extensionless files (#6035)
Browse files Browse the repository at this point in the history
**What's the problem this PR addresses?**

Node.js v18.19 has been released and contains
nodejs/node#49869 so we need to update tests.

**How did you fix it?**

Updated the version range.

**Checklist**
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).
- [x] I have set the packages that need to be released for my changes to
be effective.
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.

(cherry picked from commit 6ca73db)
  • Loading branch information
merceyz committed Jan 30, 2024
1 parent db3cd21 commit a8857df
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions .yarn/versions/0fefb43f.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declined:
- "@yarnpkg/pnp"
45 changes: 43 additions & 2 deletions packages/acceptance-tests/pkg-tests-specs/sources/pnp-esm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
{ },
Expand All @@ -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(
{
Expand All @@ -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(
Expand Down
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 @@ -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);

0 comments on commit a8857df

Please sign in to comment.