From f935c89b3142fde05d7cd2cb300ef6fcb633fb0d Mon Sep 17 00:00:00 2001 From: Bryan English Date: Thu, 30 Nov 2023 13:39:41 -0500 Subject: [PATCH] Support Node.js v21 * Renaming a context property * Importing extensionless now works --- .github/workflows/ci.yml | 2 +- hook.js | 6 +++++- test/other/import-executable.mjs | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 71d3bfc..e6e9cba 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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: diff --git a/hook.js b/hook.js index 3639fbf..97a9c51 100644 --- a/hook.js +++ b/hook.js @@ -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 } diff --git a/test/other/import-executable.mjs b/test/other/import-executable.mjs index 5979db4..f99ae59 100644 --- a/test/other/import-executable.mjs +++ b/test/other/import-executable.mjs @@ -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'