import-in-the-middle 1.12.0 → 1.13.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.
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +16 -0
- package/hook.js +9 -9
- package/lib/get-esm-exports.js +2 -2
- package/lib/get-exports.js +1 -1
- package/package.json +2 -2
- package/test/fixtures/circular-a.mjs +5 -0
- package/test/fixtures/circular-b.mjs +3 -0
- package/test/fixtures/re-export-cjs-json.js +1 -0
- package/test/hook/re-export-cjs.mjs +8 -1
- package/test/hook/v20.10-static-import-attributes.mjs +7 -9
- package/test/register/v18.19-circular.mjs +17 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.13.1](https://github.com/nodejs/import-in-the-middle/compare/import-in-the-middle-v1.13.0...import-in-the-middle-v1.13.1) (2025-02-28)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* handling of circular dependencies ([#181](https://github.com/nodejs/import-in-the-middle/issues/181)) ([b58092e](https://github.com/nodejs/import-in-the-middle/commit/b58092ec9becf4a14f541da4cf5bfb190f2a9a9b))
|
|
9
|
+
* importing JSON files ([#182](https://github.com/nodejs/import-in-the-middle/issues/182)) ([8c52014](https://github.com/nodejs/import-in-the-middle/commit/8c52014658fcf698cc340d032b441d9e7a65be36))
|
|
10
|
+
* warning from use of context.importAssertions ([#179](https://github.com/nodejs/import-in-the-middle/issues/179)) ([8e56cf1](https://github.com/nodejs/import-in-the-middle/commit/8e56cf1e89752e6c8768d648c10c12fb3178e2ae))
|
|
11
|
+
|
|
12
|
+
## [1.13.0](https://github.com/nodejs/import-in-the-middle/compare/import-in-the-middle-v1.12.0...import-in-the-middle-v1.13.0) (2025-02-06)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* Support import attributes ([#176](https://github.com/nodejs/import-in-the-middle/issues/176)) ([916af26](https://github.com/nodejs/import-in-the-middle/commit/916af2627e0e8cb6d50a3b54c1a280dc16e20925))
|
|
18
|
+
|
|
3
19
|
## [1.12.0](https://github.com/nodejs/import-in-the-middle/compare/import-in-the-middle-v1.11.3...import-in-the-middle-v1.12.0) (2024-12-13)
|
|
4
20
|
|
|
5
21
|
|
package/hook.js
CHANGED
|
@@ -253,7 +253,12 @@ async function processModule ({ srcUrl, context, parentGetSource, parentResolve,
|
|
|
253
253
|
}
|
|
254
254
|
} else {
|
|
255
255
|
addSetter(n, `
|
|
256
|
-
let $${n}
|
|
256
|
+
let $${n}
|
|
257
|
+
try {
|
|
258
|
+
$${n} = _.${n} = namespace.${n}
|
|
259
|
+
} catch (err) {
|
|
260
|
+
if (!(err instanceof ReferenceError)) throw err
|
|
261
|
+
}
|
|
257
262
|
export { $${n} as ${n} }
|
|
258
263
|
set.${n} = (v) => {
|
|
259
264
|
$${n} = v
|
|
@@ -362,10 +367,8 @@ function createHook (meta) {
|
|
|
362
367
|
}
|
|
363
368
|
|
|
364
369
|
// Node.js v21 renames importAssertions to importAttributes
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
(context.importAttributes && context.importAttributes.type === 'json')
|
|
368
|
-
) {
|
|
370
|
+
const importAttributes = context.importAttributes || context.importAssertions
|
|
371
|
+
if (importAttributes && importAttributes.type === 'json') {
|
|
369
372
|
return result
|
|
370
373
|
}
|
|
371
374
|
|
|
@@ -404,10 +407,7 @@ import { register } from '${iitmURL}'
|
|
|
404
407
|
import * as namespace from ${JSON.stringify(realUrl)}
|
|
405
408
|
|
|
406
409
|
// Mimic a Module object (https://tc39.es/ecma262/#sec-module-namespace-objects).
|
|
407
|
-
const _ = Object.
|
|
408
|
-
Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } }),
|
|
409
|
-
namespace
|
|
410
|
-
)
|
|
410
|
+
const _ = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } })
|
|
411
411
|
const set = {}
|
|
412
412
|
const get = {}
|
|
413
413
|
|
package/lib/get-esm-exports.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { Parser } = require('acorn')
|
|
4
|
-
const {
|
|
4
|
+
const { importAttributesOrAssertions } = require('acorn-import-attributes')
|
|
5
5
|
|
|
6
6
|
const acornOpts = {
|
|
7
7
|
ecmaVersion: 'latest',
|
|
8
8
|
sourceType: 'module'
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
const parser = Parser.extend(
|
|
11
|
+
const parser = Parser.extend(importAttributesOrAssertions)
|
|
12
12
|
|
|
13
13
|
function warn (txt) {
|
|
14
14
|
process.emitWarning(txt, 'get-esm-exports')
|
package/lib/get-exports.js
CHANGED
|
@@ -49,7 +49,7 @@ async function getCjsExports (url, context, parentLoad, source) {
|
|
|
49
49
|
// Resolve the re-exported module relative to the current module.
|
|
50
50
|
const newUrl = pathToFileURL(require.resolve(re, { paths: [dirname(fileURLToPath(url))] })).href
|
|
51
51
|
|
|
52
|
-
if (newUrl.endsWith('.node')) {
|
|
52
|
+
if (newUrl.endsWith('.node') || newUrl.endsWith('.json')) {
|
|
53
53
|
return
|
|
54
54
|
}
|
|
55
55
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "import-in-the-middle",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.13.1",
|
|
4
4
|
"description": "Intercept imports in Node.js",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"vue": "^3.4.31"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"acorn": "^8.
|
|
59
|
+
"acorn": "^8.14.0",
|
|
60
60
|
"acorn-import-attributes": "^1.9.5",
|
|
61
61
|
"cjs-module-lexer": "^1.2.2",
|
|
62
62
|
"module-details-from-path": "^1.0.3"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./something.json')
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import Hook from '../../index.js'
|
|
2
2
|
import foo from '../fixtures/re-export-cjs-built-in.js'
|
|
3
3
|
import foo2 from '../fixtures/re-export-cjs.js'
|
|
4
|
-
import
|
|
4
|
+
import foo3 from '../fixtures/re-export-cjs-json.js'
|
|
5
|
+
import { deepStrictEqual, strictEqual } from 'assert'
|
|
5
6
|
|
|
6
7
|
Hook((exports, name) => {
|
|
7
8
|
if (name.endsWith('fixtures/re-export-cjs-built-in.js')) {
|
|
@@ -13,7 +14,13 @@ Hook((exports, name) => {
|
|
|
13
14
|
strictEqual(exports.default, 'bar')
|
|
14
15
|
exports.default = '2'
|
|
15
16
|
}
|
|
17
|
+
|
|
18
|
+
if (name.endsWith('fixtures/re-export-cjs-json.js')) {
|
|
19
|
+
deepStrictEqual(exports.default, { data: 'dog' })
|
|
20
|
+
exports.default = '3'
|
|
21
|
+
}
|
|
16
22
|
})
|
|
17
23
|
|
|
18
24
|
strictEqual(foo, '1')
|
|
19
25
|
strictEqual(foo2, '2')
|
|
26
|
+
strictEqual(foo3, '3')
|
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
//
|
|
3
3
|
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
|
|
4
4
|
|
|
5
|
+
import Hook from '../../index.js'
|
|
5
6
|
import jsonMjs from '../fixtures/json-attributes.mjs'
|
|
6
7
|
import { strictEqual } from 'assert'
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
// exports.default.data += '-dawg'
|
|
14
|
-
// }
|
|
15
|
-
// })
|
|
9
|
+
Hook((exports, name) => {
|
|
10
|
+
if (name.match(/json-attributes\.mjs/)) {
|
|
11
|
+
exports.default.data += '-dawg'
|
|
12
|
+
}
|
|
13
|
+
})
|
|
16
14
|
|
|
17
|
-
strictEqual(jsonMjs.data, 'dog')
|
|
15
|
+
strictEqual(jsonMjs.data, 'dog-dawg')
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { register } from 'module'
|
|
2
|
+
import Hook from '../../index.js'
|
|
3
|
+
import { strictEqual } from 'assert'
|
|
4
|
+
|
|
5
|
+
register('../../hook.mjs', import.meta.url)
|
|
6
|
+
|
|
7
|
+
let bar
|
|
8
|
+
|
|
9
|
+
Hook((exports, name) => {
|
|
10
|
+
if (name.match(/circular-b.mjs/)) {
|
|
11
|
+
bar = exports.bar
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
await import('../fixtures/circular-b.mjs')
|
|
16
|
+
|
|
17
|
+
strictEqual(bar, 2)
|