import-in-the-middle 3.3.1 → 3.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/create-hook.mjs +26 -2
- package/lib/get-esm-exports.mjs +6 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [3.3.2](https://github.com/nodejs/import-in-the-middle/compare/import-in-the-middle-v3.3.1...import-in-the-middle-v3.3.2) (2026-07-20)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* delegate tagged modules to their owning loader ([#276](https://github.com/nodejs/import-in-the-middle/issues/276)) ([e0c57bd](https://github.com/nodejs/import-in-the-middle/commit/e0c57bd810d89d74e6a22a14c243d650cbda8a3c))
|
|
9
|
+
* escape loader URL in generated wrappers ([#275](https://github.com/nodejs/import-in-the-middle/issues/275)) ([86ca0e5](https://github.com/nodejs/import-in-the-middle/commit/86ca0e579cb8b592b0ae49cef9bc834b3971592d))
|
|
10
|
+
* skip code generation on broken maglev ([#271](https://github.com/nodejs/import-in-the-middle/issues/271)) ([ae914ac](https://github.com/nodejs/import-in-the-middle/commit/ae914ac41a4cc9215cbaf4fa5ec48fbe3fa8e7b3))
|
|
11
|
+
|
|
3
12
|
## [3.3.1](https://github.com/nodejs/import-in-the-middle/compare/import-in-the-middle-v3.3.0...import-in-the-middle-v3.3.1) (2026-07-07)
|
|
4
13
|
|
|
5
14
|
|
package/create-hook.mjs
CHANGED
|
@@ -17,7 +17,6 @@ import { supportsSyncHooks } from './supports-sync-hooks.mjs'
|
|
|
17
17
|
// this file's acorn / cjs-module-lexer dependency graph.
|
|
18
18
|
export { supportsSyncHooks }
|
|
19
19
|
|
|
20
|
-
const specifiers = new Map()
|
|
21
20
|
const isWin = process.platform === 'win32'
|
|
22
21
|
|
|
23
22
|
// Depth at which `processModule` starts tracking visited URLs to break an
|
|
@@ -37,6 +36,9 @@ const HANDLED_FORMATS = new Set([
|
|
|
37
36
|
])
|
|
38
37
|
const TRACE_WARNINGS = process.execArgv.includes('--trace-warnings')
|
|
39
38
|
|
|
39
|
+
/** @typedef {import('node:module').LoadHookContext} LoadContext */
|
|
40
|
+
/** @typedef {import('node:module').LoadFnOutput} LoadResult */
|
|
41
|
+
|
|
40
42
|
function hasIitm (url) {
|
|
41
43
|
// Fast path: avoid URL parsing on the hot path when there's clearly no iitm.
|
|
42
44
|
if (typeof url !== 'string' || url.indexOf('iitm') === -1) {
|
|
@@ -404,7 +406,11 @@ function addIitm (url) {
|
|
|
404
406
|
return urlObj.href
|
|
405
407
|
}
|
|
406
408
|
|
|
409
|
+
/**
|
|
410
|
+
* @param {{ url: string }} meta
|
|
411
|
+
*/
|
|
407
412
|
export function createHook (meta) {
|
|
413
|
+
const specifiers = new Map()
|
|
408
414
|
let cachedResolve
|
|
409
415
|
const iitmURL = new URL('lib/register.js', meta.url).toString()
|
|
410
416
|
let includeModules, excludeModules
|
|
@@ -651,7 +657,7 @@ export function createHook (meta) {
|
|
|
651
657
|
}
|
|
652
658
|
|
|
653
659
|
return `
|
|
654
|
-
import { register, ModuleBinder } from
|
|
660
|
+
import { register, ModuleBinder } from ${JSON.stringify(iitmURL)}
|
|
655
661
|
import * as namespace from ${JSON.stringify(realUrl)}
|
|
656
662
|
${originImports}
|
|
657
663
|
const __binder = new ModuleBinder()
|
|
@@ -689,10 +695,19 @@ register(${JSON.stringify(realUrl)}, __binder.namespace, __binder.set, __binder.
|
|
|
689
695
|
emitWarning(err)
|
|
690
696
|
}
|
|
691
697
|
|
|
698
|
+
/**
|
|
699
|
+
* @param {string} url
|
|
700
|
+
* @param {LoadContext} context
|
|
701
|
+
* @param {(url: string, context?: Partial<LoadContext>) => LoadResult | Promise<LoadResult>} parentGetSource
|
|
702
|
+
*/
|
|
692
703
|
async function getSource (url, context, parentGetSource) {
|
|
693
704
|
if (hasIitm(url)) {
|
|
694
705
|
const realUrl = deleteIitm(url)
|
|
695
706
|
const originalSpecifier = specifiers.get(realUrl)
|
|
707
|
+
if (originalSpecifier === undefined) {
|
|
708
|
+
specifiers.delete(url)
|
|
709
|
+
return parentGetSource(url, context)
|
|
710
|
+
}
|
|
696
711
|
|
|
697
712
|
try {
|
|
698
713
|
const { setters, originNamespaces } = await driveAsync(
|
|
@@ -713,10 +728,19 @@ register(${JSON.stringify(realUrl)}, __binder.namespace, __binder.set, __binder.
|
|
|
713
728
|
// Synchronous counterpart to `getSource`, for `module.registerHooks`. Drives
|
|
714
729
|
// `processModule` straight through; all bookkeeping and source generation is
|
|
715
730
|
// shared with `getSource`.
|
|
731
|
+
/**
|
|
732
|
+
* @param {string} url
|
|
733
|
+
* @param {LoadContext} context
|
|
734
|
+
* @param {(url: string, context?: Partial<LoadContext>) => LoadResult} nextLoad
|
|
735
|
+
*/
|
|
716
736
|
function getSourceSync (url, context, nextLoad) {
|
|
717
737
|
if (hasIitm(url)) {
|
|
718
738
|
const realUrl = deleteIitm(url)
|
|
719
739
|
const originalSpecifier = specifiers.get(realUrl)
|
|
740
|
+
if (originalSpecifier === undefined) {
|
|
741
|
+
specifiers.delete(url)
|
|
742
|
+
return nextLoad(url, context)
|
|
743
|
+
}
|
|
720
744
|
|
|
721
745
|
try {
|
|
722
746
|
const { setters, originNamespaces } = driveSync(
|
package/lib/get-esm-exports.mjs
CHANGED
|
@@ -15,8 +15,13 @@ const require = createRequire(import.meta.url)
|
|
|
15
15
|
// generation from strings is disallowed. Resolve the parser once at load time
|
|
16
16
|
// so the per-module path stays a bare `parse(source)` call.
|
|
17
17
|
const flag = '--disallow-code-generation-from-strings'
|
|
18
|
+
// Node.js versions with broken maglev compiler
|
|
19
|
+
const hasBrokenMaglev = process.version.startsWith('v20.') &&
|
|
20
|
+
process.version[5] === '.' &&
|
|
21
|
+
Number(process.version[4]) < 9
|
|
18
22
|
const disallowCodegen = process.execArgv.includes(flag) ||
|
|
19
|
-
(process.env.NODE_OPTIONS?.includes(flag) ?? false)
|
|
23
|
+
(process.env.NODE_OPTIONS?.includes(flag) ?? false) ||
|
|
24
|
+
hasBrokenMaglev
|
|
20
25
|
|
|
21
26
|
// initSync compiles the Wasm module up front so `parse` can run inside
|
|
22
27
|
// synchronous loader hooks (`module.registerHooks`) as well as the off-thread
|