import-in-the-middle 2.0.3 → 2.0.4

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 CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.0.4](https://github.com/nodejs/import-in-the-middle/compare/import-in-the-middle-v2.0.3...import-in-the-middle-v2.0.4) (2026-01-14)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * do not instrument the top level module ([#225](https://github.com/nodejs/import-in-the-middle/issues/225)) ([b563b35](https://github.com/nodejs/import-in-the-middle/commit/b563b35c74b96554b5112905391ec3842162b7ee))
9
+
3
10
  ## [2.0.3](https://github.com/nodejs/import-in-the-middle/compare/import-in-the-middle-v2.0.2...import-in-the-middle-v2.0.3) (2026-01-13)
4
11
 
5
12
 
package/create-hook.mjs CHANGED
@@ -375,10 +375,20 @@ export function createHook (meta) {
375
375
  if (isWin && parentURL.indexOf('file:node') === 0) {
376
376
  context.parentURL = ''
377
377
  }
378
- const result = await parentResolve(newSpecifier, context, parentResolve)
379
- if (parentURL === '' && !EXTENSION_RE.test(result.url)) {
380
- entrypoint = result.url
381
- return { url: result.url, format: 'commonjs' }
378
+ const result = await parentResolve(newSpecifier, context)
379
+
380
+ // Do not wrap the entrypoint module. Many CLIs check whether they are the
381
+ // "main" module (e.g. require.main === module). Wrapping changes how they
382
+ // are evaluated, and can make them exit without doing anything.
383
+ if (parentURL === '') {
384
+ if (!EXTENSION_RE.test(result.url)) {
385
+ entrypoint = result.url
386
+ return { url: result.url, format: 'commonjs' }
387
+ }
388
+ if (NODE_MAJOR > 16 || (NODE_MAJOR === 16 && NODE_MINOR >= 16)) {
389
+ entrypoint = result.url
390
+ return result
391
+ }
382
392
  }
383
393
 
384
394
  // For included/excluded modules, we check the specifier to match libraries
@@ -502,7 +512,7 @@ register(${JSON.stringify(realUrl)}, _, set, get, ${JSON.stringify(originalSpeci
502
512
  }
503
513
  }
504
514
 
505
- return parentGetSource(url, context, parentGetSource)
515
+ return parentGetSource(url, context)
506
516
  }
507
517
 
508
518
  // For Node.js 16.12.0 and higher.
@@ -516,7 +526,7 @@ register(${JSON.stringify(realUrl)}, _, set, get, ${JSON.stringify(originalSpeci
516
526
  }
517
527
  }
518
528
 
519
- return parentLoad(url, context, parentLoad)
529
+ return parentLoad(url, context)
520
530
  }
521
531
 
522
532
  if (NODE_MAJOR >= 17 || (NODE_MAJOR === 16 && NODE_MINOR >= 12)) {
@@ -539,7 +549,7 @@ register(${JSON.stringify(realUrl)}, _, set, get, ${JSON.stringify(originalSpeci
539
549
  }
540
550
  }
541
551
 
542
- return parentGetFormat(url, context, parentGetFormat)
552
+ return parentGetFormat(url, context)
543
553
  }
544
554
  }
545
555
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "import-in-the-middle",
3
- "version": "2.0.3",
3
+ "version": "2.0.4",
4
4
  "description": "Intercept imports in Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {