import-in-the-middle 1.4.2 → 1.6.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
@@ -14,7 +14,8 @@ const NODE_MINOR = Number(NODE_VERSION[1])
14
14
 
15
15
  let entrypoint
16
16
 
17
- if (NODE_MAJOR >= 20) {
17
+ let getExports
18
+ if (NODE_MAJOR >= 20 || (NODE_MAJOR == 18 && NODE_MINOR >= 19)) {
18
19
  getExports = require('./lib/get-exports.js')
19
20
  } else {
20
21
  getExports = (url) => import(url).then(Object.keys)
@@ -100,7 +101,11 @@ function createHook (meta) {
100
101
  return url
101
102
  }
102
103
 
103
- if (context.importAssertions && context.importAssertions.type === 'json') {
104
+ // Node.js v21 renames importAssertions to importAttributes
105
+ if (
106
+ (context.importAssertions && context.importAssertions.type === 'json') ||
107
+ (context.importAttributes && context.importAttributes.type === 'json')
108
+ ) {
104
109
  return url
105
110
  }
106
111
 
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "import-in-the-middle",
3
- "version": "1.4.2",
3
+ "version": "1.6.0",
4
4
  "description": "Intercept imports in Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,3 @@
1
+ // v18.19.0 backported ESM hook execution to a separate thread,
2
+ // thus being equivalent to >=v20.
3
+ require('./v20-get-esm-exports')
@@ -4,6 +4,14 @@
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
+ (processMajor === 18 && processMinor >= 19)
11
+ if (extensionlessSupported) {
12
+ // Files without extension are supported in Node.js ^21, ^20.10.0, and ^18.19.0
13
+ return
14
+ }
7
15
  await rejects(() => import('./executable'), {
8
16
  name: 'TypeError',
9
17
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
package/test/runtest CHANGED
@@ -16,14 +16,19 @@ const args = [
16
16
  ...process.argv.slice(2)
17
17
  ]
18
18
 
19
- const [processMajor] = process.versions.node.split('.').map(Number)
19
+ const [processMajor, processMinor] = process.versions.node.split('.').map(Number)
20
20
 
21
- const match = filename.match(/v([0-9]+)/)
21
+ const match = filename.match(/v([0-9]+)(?:\.([0-9]+))?/)
22
22
 
23
- const versionRequirement = match ? match[1] : 0;
23
+ const majorRequirement = match ? match[1] : 0;
24
+ const minorRequirement = match && match[2];
24
25
 
25
- if (processMajor < versionRequirement) {
26
- console.log(`skipping ${filename} as this is Node.js v${processMajor} and test wants v${versionRequirement}`);
26
+ if (processMajor < majorRequirement && minorRequirement === undefined) {
27
+ console.log(`skipping ${filename} as this is Node.js v${processMajor} and test wants v${majorRequirement}`);
28
+ process.exit(0);
29
+ }
30
+ if (processMajor < majorRequirement && processMinor < minorRequirement) {
31
+ console.log(`skipping ${filename} as this is Node.js v${processMajor}.${processMinor} and test wants >=v${majorRequirement}.${minorRequirement}`);
27
32
  process.exit(0);
28
33
  }
29
34