import-in-the-middle 1.2.2 → 1.2.3

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.
Files changed (2) hide show
  1. package/hook.mjs +12 -2
  2. package/package.json +1 -1
package/hook.mjs CHANGED
@@ -6,6 +6,8 @@ const specifiers = new Map()
6
6
 
7
7
  const EXTENSION_RE = /\.(js|mjs|cjs)$/
8
8
 
9
+ const NODE_MAJOR = Number(process.versions.node.split('.')[0])
10
+
9
11
  let entrypoint
10
12
 
11
13
  function hasIitm (url) {
@@ -22,8 +24,16 @@ function deleteIitm (url) {
22
24
  const urlObj = new URL(url)
23
25
  if (urlObj.searchParams.has('iitm')) {
24
26
  urlObj.searchParams.delete('iitm')
27
+ resultUrl = urlObj.href
28
+ if (resultUrl.startsWith('file:node:')) {
29
+ resultUrl = resultUrl.replace('file:', '')
30
+ }
31
+ if (resultUrl.startsWith('file:///node:')) {
32
+ resultUrl = resultUrl.replace('file:///', '')
33
+ }
34
+ } else {
35
+ resultUrl = urlObj.href
25
36
  }
26
- resultUrl = urlObj.href
27
37
  } catch {
28
38
  resultUrl = url
29
39
  }
@@ -33,7 +43,7 @@ function deleteIitm (url) {
33
43
  function addIitm (url) {
34
44
  const urlObj = new URL(url)
35
45
  urlObj.searchParams.set('iitm', 'true')
36
- return urlObj.href
46
+ return urlObj.protocol !== 'file:' && NODE_MAJOR < 18 ? 'file:' + urlObj.href : urlObj.href
37
47
  }
38
48
 
39
49
  export async function resolve (specifier, context, parentResolve) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "import-in-the-middle",
3
- "version": "1.2.2",
3
+ "version": "1.2.3",
4
4
  "description": "Intercept imports in Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {