Skip to content

Commit

Permalink
Support Node.js v21
Browse files Browse the repository at this point in the history
* Renaming a context property
* Importing extensionless now works
  • Loading branch information
bengl committed Nov 30, 2023
1 parent 5845e21 commit f935c89
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

strategy:
matrix:
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]
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, 21.x]
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
Expand Down
6 changes: 5 additions & 1 deletion hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ function createHook (meta) {
return url
}

if (context.importAssertions && context.importAssertions.type === 'json') {
// Node.js v21 renames importAssertions to importAttributes
if (
(context.importAssertions && context.importAssertions.type === 'json') ||
(context.importAttributes && context.importAttributes.type === 'json')
) {
return url
}

Expand Down
5 changes: 5 additions & 0 deletions test/other/import-executable.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@

import { rejects } from 'assert'
(async () => {
const [processMajor] = process.versions.node.split('.').map(Number)
if (processMajor >= 21) {
// Files without extension are supported in Node.js 21+
return
}
await rejects(() => import('./executable'), {
name: 'TypeError',
code: 'ERR_UNKNOWN_FILE_EXTENSION'
Expand Down

0 comments on commit f935c89

Please sign in to comment.