import-in-the-middle 1.1.2 → 1.2.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.mjs +14 -0
- package/package.json +4 -4
- package/test/other/executable +6 -0
- package/test/other/import-executable.mjs +11 -0
package/hook.mjs
CHANGED
|
@@ -4,6 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
const specifiers = new Map()
|
|
6
6
|
|
|
7
|
+
const EXTENSION_RE = /\.(js|mjs|cjs)$/
|
|
8
|
+
|
|
9
|
+
let entrypoint
|
|
10
|
+
|
|
7
11
|
export async function resolve (specifier, context, parentResolve) {
|
|
8
12
|
const { parentURL = '' } = context
|
|
9
13
|
|
|
@@ -12,6 +16,11 @@ export async function resolve (specifier, context, parentResolve) {
|
|
|
12
16
|
}
|
|
13
17
|
const url = await parentResolve(specifier, context, parentResolve)
|
|
14
18
|
|
|
19
|
+
if (parentURL === '' && !EXTENSION_RE.test(url.url)) {
|
|
20
|
+
entrypoint = url.url
|
|
21
|
+
return { url: url.url, format: 'commonjs' }
|
|
22
|
+
}
|
|
23
|
+
|
|
15
24
|
if (parentURL === import.meta.url || parentURL.startsWith('iitm:')) {
|
|
16
25
|
return url
|
|
17
26
|
}
|
|
@@ -29,6 +38,11 @@ export function getFormat (url, context, parentGetFormat) {
|
|
|
29
38
|
format: 'module'
|
|
30
39
|
}
|
|
31
40
|
}
|
|
41
|
+
if (url === entrypoint) {
|
|
42
|
+
return {
|
|
43
|
+
format: 'commonjs'
|
|
44
|
+
}
|
|
45
|
+
}
|
|
32
46
|
|
|
33
47
|
return parentGetFormat(url, context, parentGetFormat)
|
|
34
48
|
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "import-in-the-middle",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Intercept imports in Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "c8 --check-coverage --lines 90 imhotap --runner test/runtest --files test/{hook,low-level}
|
|
8
|
-
"coverage": "c8 --reporter html imhotap --runner test/runtest --files test/{hook,low-level}
|
|
7
|
+
"test": "c8 --check-coverage --lines 90 imhotap --runner test/runtest --files test/{hook,low-level,other}/*",
|
|
8
|
+
"coverage": "c8 --reporter html imhotap --runner test/runtest --files test/{hook,low-level,other}/* && echo '\nNow open coverage/index.html\n'"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"homepage": "https://github.com/DataDog/import-in-the-middle#readme",
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"c8": "^7.8.0",
|
|
30
|
-
"imhotap": "^
|
|
30
|
+
"imhotap": "^2.0.0"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"module-details-from-path": "^1.0.3"
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2.0 License.
|
|
3
|
+
//
|
|
4
|
+
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
|
|
5
|
+
|
|
6
|
+
// This script doesn't actually have to do anything.
|
|
@@ -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 { rejects } from 'assert'
|
|
6
|
+
(async () => {
|
|
7
|
+
await rejects(() => import('./executable'), {
|
|
8
|
+
name: 'TypeError',
|
|
9
|
+
code: 'ERR_UNKNOWN_FILE_EXTENSION'
|
|
10
|
+
})
|
|
11
|
+
})()
|