From 630ba66d91a2cb38903c09f88ad5e407e35ada16 Mon Sep 17 00:00:00 2001 From: Ayan Khan Date: Fri, 1 Dec 2023 13:15:10 -0500 Subject: [PATCH] make changes --- hook.js | 9 +++++++-- ...ic-import-assert.mjs => v18-static-import-assert.mjs} | 0 2 files changed, 7 insertions(+), 2 deletions(-) rename test/hook/{v16-static-import-assert.mjs => v18-static-import-assert.mjs} (100%) diff --git a/hook.js b/hook.js index 0ec34a4..4c887bf 100644 --- a/hook.js +++ b/hook.js @@ -11,6 +11,7 @@ const isWin = process.platform === "win32" // FIXME: Typescript extensions are added temporarily until we find a better // way of supporting arbitrary extensions const EXTENSION_RE = /\.(js|mjs|cjs|ts|mts|cts)$/ +const EXTENSION_MJS_RE = /\.mjs$/; const NODE_VERSION = process.versions.node.split('.') const NODE_MAJOR = Number(NODE_VERSION[0]) const NODE_MINOR = Number(NODE_VERSION[1]) @@ -110,10 +111,14 @@ function createHook (meta) { ) { return url } - + + // on Node 16.12.0, url.format is undefined for .mjs files, so explicitly set it to 'module' + if (url.format === undefined && EXTENSION_MJS_RE.test(url.url)) { + url.format = 'module' + } specifiers.set(url.url, specifier) - + return { url: url.format !== 'module' || NODE_MAJOR < 16 ? addIitm(url.url) : url.url, shortCircuit: true, diff --git a/test/hook/v16-static-import-assert.mjs b/test/hook/v18-static-import-assert.mjs similarity index 100% rename from test/hook/v16-static-import-assert.mjs rename to test/hook/v18-static-import-assert.mjs