import-in-the-middle 1.4.1 → 1.5.0

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/hook.js CHANGED
@@ -100,7 +100,11 @@ function createHook (meta) {
100
100
  return url
101
101
  }
102
102
 
103
- if (context.importAssertions && context.importAssertions.type === 'json') {
103
+ // Node.js v21 renames importAssertions to importAttributes
104
+ if (
105
+ (context.importAssertions && context.importAssertions.type === 'json') ||
106
+ (context.importAttributes && context.importAttributes.type === 'json')
107
+ ) {
104
108
  return url
105
109
  }
106
110
 
@@ -122,7 +126,7 @@ function createHook (meta) {
122
126
  return {
123
127
  source: `
124
128
  import { register } from '${iitmURL}'
125
- import * as namespace from '${url}'
129
+ import * as namespace from ${JSON.stringify(url)}
126
130
  const set = {}
127
131
  ${exportNames.map((n) => `
128
132
  let $${n} = namespace.${n}
@@ -132,7 +136,7 @@ set.${n} = (v) => {
132
136
  return true
133
137
  }
134
138
  `).join('\n')}
135
- register('${realUrl}', namespace, set, '${specifiers.get(realUrl)}')
139
+ register(${JSON.stringify(realUrl)}, namespace, set, ${JSON.stringify(specifiers.get(realUrl))})
136
140
  `
137
141
  }
138
142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "import-in-the-middle",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "description": "Intercept imports in Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,11 @@
1
+ // Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
2
+ //
3
+ // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
4
+
5
+ import { addHook } from '../../index.js'
6
+
7
+ addHook(() => {})
8
+
9
+ ;(async () => {
10
+ await import("../fixtures/something.mjs#*/'/*';eval('process.exit\x281\x29\x0A')")
11
+ })()
@@ -4,6 +4,13 @@
4
4
 
5
5
  import { rejects } from 'assert'
6
6
  (async () => {
7
+ const [processMajor, processMinor] = process.versions.node.split('.').map(Number)
8
+ const extensionlessSupported = processMajor >= 21 ||
9
+ (processMajor === 20 && processMinor >= 10)
10
+ if (extensionlessSupported) {
11
+ // Files without extension are supported in Node.js >= 20.10.0
12
+ return
13
+ }
7
14
  await rejects(() => import('./executable'), {
8
15
  name: 'TypeError',
9
16
  code: 'ERR_UNKNOWN_FILE_EXTENSION'