import-in-the-middle 1.1.1 → 1.1.2
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/fuck.mjs +12 -0
- package/hook.mjs +14 -0
- package/package.json +2 -2
package/fuck.mjs
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import vm from 'vm'
|
|
2
|
+
|
|
3
|
+
const context = vm.createContext()
|
|
4
|
+
console.log(vm)
|
|
5
|
+
const mod = new vm.SourceTextModule(`
|
|
6
|
+
export const bar = 5
|
|
7
|
+
`, { context })
|
|
8
|
+
await mod.link(async () => {
|
|
9
|
+
return new vm.SyntheticModule([], function () {
|
|
10
|
+
}, { context })
|
|
11
|
+
})
|
|
12
|
+
console.log(Reflect.ownKeys(mod.namespace))
|
package/hook.mjs
CHANGED
|
@@ -59,3 +59,17 @@ register('${realUrl}', namespace, set, '${specifiers.get(realUrl)}')
|
|
|
59
59
|
|
|
60
60
|
return parentGetSource(url, context, parentGetSource)
|
|
61
61
|
}
|
|
62
|
+
|
|
63
|
+
// For Node.js 16.12.0 and higher.
|
|
64
|
+
export async function load (url, context, parentLoad) {
|
|
65
|
+
if (url.startsWith('iitm:')) {
|
|
66
|
+
const { source } = await getSource(url, context)
|
|
67
|
+
return {
|
|
68
|
+
source,
|
|
69
|
+
format: 'module'
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return parentLoad(url, context, parentLoad)
|
|
74
|
+
}
|
|
75
|
+
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "import-in-the-middle",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Intercept imports in Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "c8 --check-coverage --lines
|
|
7
|
+
"test": "c8 --check-coverage --lines 90 imhotap --runner test/runtest --files test/{hook,low-level}/*.*js",
|
|
8
8
|
"coverage": "c8 --reporter html imhotap --runner test/runtest --files test/{hook,low-level}/*.*js && echo '\nNow open coverage/index.html\n'"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|