Skip to content

Commit 155491e

Browse files
authored
Support Node.js v21 (#40)
* Renaming a context property * Importing extensionless now works
1 parent 5845e21 commit 155491e

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010

1111
strategy:
1212
matrix:
13-
node-version: [12.x, 14.x, 16.10.0, 16.16.0, 16.17.0, 16.x, 17.x, 18.5.0, 18.x, 20.x]
13+
node-version: [12.x, 14.x, 16.10.0, 16.16.0, 16.17.0, 16.x, 17.x, 18.5.0, 18.x, 20.9.0, 20.x, 21.x]
1414
os: [ubuntu-latest, macos-latest, windows-latest]
1515

1616
steps:

hook.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,11 @@ function createHook (meta) {
100100
return url
101101
}
102102

103-
if (context.importAssertions && context.importAssertions.type === 'json') {
103+
// Node.js v21 renames importAssertions to importAttributes
104+
if (
105+
(context.importAssertions && context.importAssertions.type === 'json') ||
106+
(context.importAttributes && context.importAttributes.type === 'json')
107+
) {
104108
return url
105109
}
106110

test/other/import-executable.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
import { rejects } from 'assert'
66
(async () => {
7+
const [processMajor, processMinor] = process.versions.node.split('.').map(Number)
8+
const extensionlessSupported = processMajor >= 21 ||
9+
(processMajor === 20 && processMinor >= 10)
10+
if (extensionlessSupported) {
11+
// Files without extension are supported in Node.js >= 20.10.0
12+
return
13+
}
714
await rejects(() => import('./executable'), {
815
name: 'TypeError',
916
code: 'ERR_UNKNOWN_FILE_EXTENSION'

0 commit comments

Comments
 (0)