import-in-the-middle 1.7.3 → 1.7.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/fix.patch +52 -0
- package/hook.js +2 -1
- package/lib/get-esm-exports.js +1 -1
- package/package.json +2 -2
- package/test/hook/module-toStringTag.mjs +25 -0
package/fix.patch
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
From 5a9ae09d53e43a30709c7162fb351f3a57626f79 Mon Sep 17 00:00:00 2001
|
|
2
|
+
From: Bryan English <bryan.english@datadoghq.com>
|
|
3
|
+
Date: Fri, 21 Jul 2023 11:50:34 -0400
|
|
4
|
+
Subject: [PATCH] sanitize URLs
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
hook.js | 4 ++--
|
|
8
|
+
test/low-level/sanitized-url.mjs | 11 +++++++++++
|
|
9
|
+
2 files changed, 13 insertions(+), 2 deletions(-)
|
|
10
|
+
create mode 100644 test/low-level/sanitized-url.mjs
|
|
11
|
+
|
|
12
|
+
diff --git a/hook.js b/hook.js
|
|
13
|
+
index 884ee3a..3639fbf 100644
|
|
14
|
+
--- a/hook.js
|
|
15
|
+
+++ b/hook.js
|
|
16
|
+
@@ -122,7 +122,7 @@ function createHook (meta) {
|
|
17
|
+
return {
|
|
18
|
+
source: `
|
|
19
|
+
import { register } from '${iitmURL}'
|
|
20
|
+
-import * as namespace from '${url}'
|
|
21
|
+
+import * as namespace from ${JSON.stringify(url)}
|
|
22
|
+
const set = {}
|
|
23
|
+
${exportNames.map((n) => `
|
|
24
|
+
let $${n} = namespace.${n}
|
|
25
|
+
@@ -132,7 +132,7 @@ set.${n} = (v) => {
|
|
26
|
+
return true
|
|
27
|
+
}
|
|
28
|
+
`).join('\n')}
|
|
29
|
+
-register('${realUrl}', namespace, set, '${specifiers.get(realUrl)}')
|
|
30
|
+
+register(${JSON.stringify(realUrl)}, namespace, set, ${JSON.stringify(specifiers.get(realUrl))})
|
|
31
|
+
`
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
diff --git a/test/low-level/sanitized-url.mjs b/test/low-level/sanitized-url.mjs
|
|
35
|
+
new file mode 100644
|
|
36
|
+
index 0000000..6fe5e81
|
|
37
|
+
--- /dev/null
|
|
38
|
+
+++ b/test/low-level/sanitized-url.mjs
|
|
39
|
+
@@ -0,0 +1,11 @@
|
|
40
|
+
+// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
|
|
41
|
+
+//
|
|
42
|
+
+// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
|
|
43
|
+
+
|
|
44
|
+
+import { addHook } from '../../index.js'
|
|
45
|
+
+
|
|
46
|
+
+addHook(() => {})
|
|
47
|
+
+
|
|
48
|
+
+;(async () => {
|
|
49
|
+
+ await import("../fixtures/something.mjs#*/'/*';eval('process.exit\x281\x29\x0A')")
|
|
50
|
+
+})()
|
|
51
|
+
--
|
|
52
|
+
2.39.0
|
package/hook.js
CHANGED
|
@@ -303,7 +303,8 @@ import { register } from '${iitmURL}'
|
|
|
303
303
|
${imports.join('\n')}
|
|
304
304
|
|
|
305
305
|
const namespaces = [${namespaces.join(', ')}]
|
|
306
|
-
|
|
306
|
+
// Mimic a Module object (https://tc39.es/ecma262/#sec-module-namespace-objects).
|
|
307
|
+
const _ = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } })
|
|
307
308
|
const set = {}
|
|
308
309
|
|
|
309
310
|
const primary = namespaces.shift()
|
package/lib/get-esm-exports.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "import-in-the-middle",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.4",
|
|
4
4
|
"description": "Intercept imports in Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"acorn": "^8.8.2",
|
|
53
|
-
"acorn-import-
|
|
53
|
+
"acorn-import-attributes": "^1.9.5",
|
|
54
54
|
"cjs-module-lexer": "^1.2.2",
|
|
55
55
|
"module-details-from-path": "^1.0.3"
|
|
56
56
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 Hook from '../../index.js'
|
|
6
|
+
import { foo as fooMjs } from '../fixtures/something.mjs'
|
|
7
|
+
import { foo as fooJs } from '../fixtures/something.js'
|
|
8
|
+
import { strictEqual, deepStrictEqual } from 'assert'
|
|
9
|
+
|
|
10
|
+
let hookedExports
|
|
11
|
+
|
|
12
|
+
Hook((exports, name) => {
|
|
13
|
+
hookedExports = exports
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
strictEqual(fooMjs, 42)
|
|
17
|
+
strictEqual(fooJs, 42)
|
|
18
|
+
|
|
19
|
+
strictEqual(hookedExports[Symbol.toStringTag], 'Module')
|
|
20
|
+
deepStrictEqual(Object.getOwnPropertyDescriptor(hookedExports, Symbol.toStringTag), {
|
|
21
|
+
value: 'Module',
|
|
22
|
+
enumerable: false,
|
|
23
|
+
writable: false,
|
|
24
|
+
configurable: false
|
|
25
|
+
})
|