From 7826ef81087f4458d1e14c8e2d8d51726fec7f18 Mon Sep 17 00:00:00 2001 From: Ida Liu <119438987+ida613@users.noreply.github.com> Date: Mon, 18 Mar 2024 19:40:55 -0400 Subject: [PATCH 1/3] added module property symbols --- hook.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hook.js b/hook.js index aa22356..3d46ba4 100644 --- a/hook.js +++ b/hook.js @@ -310,6 +310,9 @@ const primary = namespaces.shift() for (const [k, v] of Object.entries(primary)) { _[k] = v } +for (const k of Object.getOwnPropertySymbols(primary)) { + _[k] = primary[k] +} for (const ns of namespaces) { for (const [k, v] of Object.entries(ns)) { if (k === 'default') continue From 878fadb5b00866235fbf7a54d273b1bfcd1c88af Mon Sep 17 00:00:00 2001 From: Ida Liu <119438987+ida613@users.noreply.github.com> Date: Mon, 25 Mar 2024 17:24:00 -0400 Subject: [PATCH 2/3] added optional argument to specify a list of modules to patch to createHook --- hook.js | 80 ++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/hook.js b/hook.js index 3d46ba4..468d136 100644 --- a/hook.js +++ b/hook.js @@ -228,38 +228,66 @@ function addIitm (url) { return needsToAddFileProtocol(urlObj) ? 'file:' + urlObj.href : urlObj.href } -function createHook (meta) { - async function resolve (specifier, context, parentResolve) { - const { parentURL = '' } = context - const newSpecifier = deleteIitm(specifier) - if (isWin && parentURL.indexOf('file:node') === 0) { - context.parentURL = '' - } - const url = await parentResolve(newSpecifier, context, parentResolve) - if (parentURL === '' && !EXTENSION_RE.test(url.url)) { - entrypoint = url.url - return { url: url.url, format: 'commonjs' } +// moduleList is an optional Map specifiying which modules need IITM patching +// format: { moduleName : ['/file1.js', '/file2.js'] } +function createHook (meta, moduleList={}) { + async function resolve (specifier, context, parentResolve, moduleList) { + let patch = true + if (moduleList.size) { + patch = false // do not patch unless specifier is in moduleList + if (moduleList.has(specifier)) { // if specifier is a module name present in moduleList + patch = true + } else { + for (let mod of moduleList.key) { + if (specifier.includes(mod)) { + for (let path of moduleList[mod]) { + if (specifier.endsWith(mod + path) || specifier.endsWith(mod + path + '/')) { + patch = true + continue + } + } + } + } + } } - if (isIitm(parentURL, meta) || hasIitm(parentURL)) { - return url - } + if (patch) { + const { parentURL = '' } = context + const newSpecifier = deleteIitm(specifier) + if (isWin && parentURL.indexOf('file:node') === 0) { + context.parentURL = '' + } + const url = await parentResolve(newSpecifier, context, parentResolve) + if (parentURL === '' && !EXTENSION_RE.test(url.url)) { + entrypoint = url.url + return { url: url.url, format: 'commonjs' } // early return, find out format + } - // Node.js v21 renames importAssertions to importAttributes - if ( - (context.importAssertions && context.importAssertions.type === 'json') || - (context.importAttributes && context.importAttributes.type === 'json') - ) { - return url - } + if (isIitm(parentURL, meta) || hasIitm(parentURL)) { + return url + } - specifiers.set(url.url, specifier) + // Node.js v21 renames importAssertions to importAttributes + if ( + (context.importAssertions && context.importAssertions.type === 'json') || + (context.importAttributes && context.importAttributes.type === 'json') + ) { + return url + } - return { - url: addIitm(url.url), - shortCircuit: true, - format: url.format + specifiers.set(url.url, specifier) + return { + url: addIitm(url.url), + shortCircuit: true, + format: url.format + } } + const newSpecifier = deleteIitm(specifier) + if (isWin && parentURL.indexOf('file:node') === 0) { + context.parentURL = '' + } + const url = await parentResolve(newSpecifier, context, parentResolve) + return { url: url.url, format: url.format } } const iitmURL = new URL('lib/register.js', meta.url).toString() From b0109bc9fe5a2c86f0daf914a66a14d722528420 Mon Sep 17 00:00:00 2001 From: Ida Liu <119438987+ida613@users.noreply.github.com> Date: Mon, 25 Mar 2024 17:28:13 -0400 Subject: [PATCH 3/3] Revert "added optional argument to specify a list of modules to patch to createHook" This reverts commit 878fadb5b00866235fbf7a54d273b1bfcd1c88af. --- hook.js | 80 +++++++++++++++++++-------------------------------------- 1 file changed, 26 insertions(+), 54 deletions(-) diff --git a/hook.js b/hook.js index 468d136..3d46ba4 100644 --- a/hook.js +++ b/hook.js @@ -228,66 +228,38 @@ function addIitm (url) { return needsToAddFileProtocol(urlObj) ? 'file:' + urlObj.href : urlObj.href } -// moduleList is an optional Map specifiying which modules need IITM patching -// format: { moduleName : ['/file1.js', '/file2.js'] } -function createHook (meta, moduleList={}) { - async function resolve (specifier, context, parentResolve, moduleList) { - let patch = true - if (moduleList.size) { - patch = false // do not patch unless specifier is in moduleList - if (moduleList.has(specifier)) { // if specifier is a module name present in moduleList - patch = true - } else { - for (let mod of moduleList.key) { - if (specifier.includes(mod)) { - for (let path of moduleList[mod]) { - if (specifier.endsWith(mod + path) || specifier.endsWith(mod + path + '/')) { - patch = true - continue - } - } - } - } - } +function createHook (meta) { + async function resolve (specifier, context, parentResolve) { + const { parentURL = '' } = context + const newSpecifier = deleteIitm(specifier) + if (isWin && parentURL.indexOf('file:node') === 0) { + context.parentURL = '' + } + const url = await parentResolve(newSpecifier, context, parentResolve) + if (parentURL === '' && !EXTENSION_RE.test(url.url)) { + entrypoint = url.url + return { url: url.url, format: 'commonjs' } } - if (patch) { - const { parentURL = '' } = context - const newSpecifier = deleteIitm(specifier) - if (isWin && parentURL.indexOf('file:node') === 0) { - context.parentURL = '' - } - const url = await parentResolve(newSpecifier, context, parentResolve) - if (parentURL === '' && !EXTENSION_RE.test(url.url)) { - entrypoint = url.url - return { url: url.url, format: 'commonjs' } // early return, find out format - } + if (isIitm(parentURL, meta) || hasIitm(parentURL)) { + return url + } - if (isIitm(parentURL, meta) || hasIitm(parentURL)) { - return url - } + // Node.js v21 renames importAssertions to importAttributes + if ( + (context.importAssertions && context.importAssertions.type === 'json') || + (context.importAttributes && context.importAttributes.type === 'json') + ) { + return url + } - // Node.js v21 renames importAssertions to importAttributes - if ( - (context.importAssertions && context.importAssertions.type === 'json') || - (context.importAttributes && context.importAttributes.type === 'json') - ) { - return url - } + specifiers.set(url.url, specifier) - specifiers.set(url.url, specifier) - return { - url: addIitm(url.url), - shortCircuit: true, - format: url.format - } - } - const newSpecifier = deleteIitm(specifier) - if (isWin && parentURL.indexOf('file:node') === 0) { - context.parentURL = '' + return { + url: addIitm(url.url), + shortCircuit: true, + format: url.format } - const url = await parentResolve(newSpecifier, context, parentResolve) - return { url: url.url, format: url.format } } const iitmURL = new URL('lib/register.js', meta.url).toString()