Skip to content

Commit ebf9a0d

Browse files
authored
fix(pnp): esm - support import attributes (#6268)
**What's the problem this PR addresses?** In Node.js v22 import assertions were replaced with import attributes so we need to add support for those as well. Fixes #6267 **How did you fix it?** Added support for the `importAttributes` property. **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.
1 parent 578d896 commit ebf9a0d

File tree

7 files changed

+88
-28
lines changed

7 files changed

+88
-28
lines changed

.github/workflows/integration-workflow.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ jobs:
206206
fail-fast: false
207207
matrix:
208208
# We run the ubuntu tests on multiple Node versions with 2 shards since they're the fastest.
209-
node: [18, 19, 20, 21]
209+
node: [18, 19, 20, 21, 22]
210210
platform: [[ubuntu, 20.04]]
211211
shard: ['1/2', '2/2']
212212
include:
@@ -221,13 +221,13 @@ jobs:
221221
- {node: 18, platform: [macos, latest], shard: 3/3}
222222
# We also run them on the maximum Node version we support, to catch potential regressions in Node.js.
223223
# Windows tests
224-
- {node: 21, platform: [windows, latest], shard: 1/3}
225-
- {node: 21, platform: [windows, latest], shard: 2/3}
226-
- {node: 21, platform: [windows, latest], shard: 3/3}
224+
- {node: 22, platform: [windows, latest], shard: 1/3}
225+
- {node: 22, platform: [windows, latest], shard: 2/3}
226+
- {node: 22, platform: [windows, latest], shard: 3/3}
227227
# macOS tests
228-
- {node: 21, platform: [macos, latest], shard: 1/3}
229-
- {node: 21, platform: [macos, latest], shard: 2/3}
230-
- {node: 21, platform: [macos, latest], shard: 3/3}
228+
- {node: 22, platform: [macos, latest], shard: 1/3}
229+
- {node: 22, platform: [macos, latest], shard: 2/3}
230+
- {node: 22, platform: [macos, latest], shard: 3/3}
231231

232232
name: '${{matrix.platform[0]}}-latest w/ Node.js ${{matrix.node}}.x (${{matrix.shard}})'
233233
runs-on: ${{matrix.platform[0]}}-${{matrix.platform[1]}}

.pnp.loader.mjs

Lines changed: 17 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.yarn/versions/a5b83769.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
releases:
2+
"@yarnpkg/cli": patch
3+
"@yarnpkg/plugin-pnp": patch
4+
"@yarnpkg/pnp": patch
5+
6+
declined:
7+
- "@yarnpkg/plugin-compat"
8+
- "@yarnpkg/plugin-constraints"
9+
- "@yarnpkg/plugin-dlx"
10+
- "@yarnpkg/plugin-essentials"
11+
- "@yarnpkg/plugin-init"
12+
- "@yarnpkg/plugin-interactive-tools"
13+
- "@yarnpkg/plugin-nm"
14+
- "@yarnpkg/plugin-npm-cli"
15+
- "@yarnpkg/plugin-pack"
16+
- "@yarnpkg/plugin-patch"
17+
- "@yarnpkg/plugin-pnpm"
18+
- "@yarnpkg/plugin-stage"
19+
- "@yarnpkg/plugin-typescript"
20+
- "@yarnpkg/plugin-version"
21+
- "@yarnpkg/plugin-workspace-tools"
22+
- "@yarnpkg/builder"
23+
- "@yarnpkg/core"
24+
- "@yarnpkg/doctor"
25+
- "@yarnpkg/nm"
26+
- "@yarnpkg/pnpify"
27+
- "@yarnpkg/sdks"

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

Lines changed: 7 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} 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} from '@yarnpkg/pnp/sources/esm-loader/loaderFlags';
3+
import {pathToFileURL} from 'url';
44

55
describe(`Plug'n'Play - ESM`, () => {
66
test(
@@ -220,7 +220,7 @@ describe(`Plug'n'Play - ESM`, () => {
220220
);
221221

222222
test(
223-
`it should not resolve JSON modules without an import assertion`,
223+
`it should not resolve JSON modules without an import assertion/attribute`,
224224
makeTemporaryEnv(
225225
{
226226
type: `module`,
@@ -236,14 +236,14 @@ describe(`Plug'n'Play - ESM`, () => {
236236

237237
await expect(run(`node`, `./index.js`)).rejects.toMatchObject({
238238
code: 1,
239-
stderr: expect.stringContaining(`ERR_IMPORT_ASSERTION_TYPE_MISSING`),
239+
stderr: expect.stringContaining(SUPPORTS_IMPORT_ATTRIBUTES_ONLY ? `ERR_IMPORT_ATTRIBUTE_MISSING` : `ERR_IMPORT_ASSERTION_TYPE_MISSING`),
240240
});
241241
},
242242
),
243243
);
244244

245245
test(
246-
`it should resolve JSON modules with an import assertion`,
246+
`it should resolve JSON modules with an import assertion/attribute`,
247247
makeTemporaryEnv(
248248
{
249249
type: `module`,
@@ -254,7 +254,7 @@ describe(`Plug'n'Play - ESM`, () => {
254254
await xfs.writeFilePromise(
255255
ppath.join(path, `index.js`),
256256
`
257-
import foo from './foo.json' assert { type: 'json' };
257+
import foo from './foo.json' ${SUPPORTS_IMPORT_ATTRIBUTES ? `with` : `assert`} { type: 'json' };
258258
console.log(foo.name);
259259
`,
260260
);

0 commit comments

Comments
 (0)