import-in-the-middle 1.2.0 → 1.2.1

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 (3) hide show
  1. package/hook.mjs +8 -8
  2. package/package.json +1 -1
  3. package/fuck.mjs +0 -12
package/hook.mjs CHANGED
@@ -11,8 +11,8 @@ let entrypoint
11
11
  export async function resolve (specifier, context, parentResolve) {
12
12
  const { parentURL = '' } = context
13
13
 
14
- if (specifier.startsWith('iitm:')) {
15
- specifier = specifier.replace('iitm:', '')
14
+ if (specifier.startsWith('file:iitm:')) {
15
+ specifier = specifier.replace('file:iitm:', '')
16
16
  }
17
17
  const url = await parentResolve(specifier, context, parentResolve)
18
18
 
@@ -21,19 +21,19 @@ export async function resolve (specifier, context, parentResolve) {
21
21
  return { url: url.url, format: 'commonjs' }
22
22
  }
23
23
 
24
- if (parentURL === import.meta.url || parentURL.startsWith('iitm:')) {
24
+ if (parentURL === import.meta.url || parentURL.startsWith('file:iitm:')) {
25
25
  return url
26
26
  }
27
27
 
28
28
  specifiers.set(url.url, specifier)
29
29
 
30
30
  return {
31
- url: `iitm:${url.url}`
31
+ url: `file:iitm:${url.url}`
32
32
  }
33
33
  }
34
34
 
35
35
  export function getFormat (url, context, parentGetFormat) {
36
- if (url.startsWith('iitm:')) {
36
+ if (url.startsWith('file:iitm:')) {
37
37
  return {
38
38
  format: 'module'
39
39
  }
@@ -49,8 +49,8 @@ export function getFormat (url, context, parentGetFormat) {
49
49
 
50
50
  const iitmURL = new URL('lib/register.js', import.meta.url).toString()
51
51
  export async function getSource (url, context, parentGetSource) {
52
- if (url.startsWith('iitm:')) {
53
- const realUrl = url.replace('iitm:', '')
52
+ if (url.startsWith('file:iitm:')) {
53
+ const realUrl = url.replace('file:iitm:', '')
54
54
  const realModule = await import(realUrl)
55
55
  const exportNames = Object.keys(realModule)
56
56
  return {
@@ -76,7 +76,7 @@ register('${realUrl}', namespace, set, '${specifiers.get(realUrl)}')
76
76
 
77
77
  // For Node.js 16.12.0 and higher.
78
78
  export async function load (url, context, parentLoad) {
79
- if (url.startsWith('iitm:')) {
79
+ if (url.startsWith('file:iitm:')) {
80
80
  const { source } = await getSource(url, context)
81
81
  return {
82
82
  source,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "import-in-the-middle",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "description": "Intercept imports in Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/fuck.mjs DELETED
@@ -1,12 +0,0 @@
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))