import-in-the-middle 1.14.1 → 1.14.3

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.
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "1.14.1"
2
+ ".": "1.14.3"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.14.3](https://github.com/nodejs/import-in-the-middle/compare/import-in-the-middle-v1.14.2...import-in-the-middle-v1.14.3) (2025-09-24)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * use `createRequire` to load `hook.js` ([#205](https://github.com/nodejs/import-in-the-middle/issues/205)) ([81a2ae0](https://github.com/nodejs/import-in-the-middle/commit/81a2ae0ea094df27c9baaf6e267276e0acb21af1))
9
+
10
+ ## [1.14.2](https://github.com/nodejs/import-in-the-middle/compare/import-in-the-middle-v1.14.1...import-in-the-middle-v1.14.2) (2025-06-13)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * do not replace dollar sign in shim variable name ([#200](https://github.com/nodejs/import-in-the-middle/issues/200)) ([20bf0e5](https://github.com/nodejs/import-in-the-middle/commit/20bf0e5c5f6f44f42a8618ad45d08622a63d4d45))
16
+
3
17
  ## [1.14.1](https://github.com/nodejs/import-in-the-middle/compare/import-in-the-middle-v1.14.0...import-in-the-middle-v1.14.1) (2025-06-12)
4
18
 
5
19
 
package/hook.js CHANGED
@@ -254,7 +254,7 @@ async function processModule ({ srcUrl, context, parentGetSource, parentResolve,
254
254
  addSetter(name, setter, true)
255
255
  }
256
256
  } else {
257
- const variableName = `$${n.replace(/[^a-zA-Z0-9_]/g, '_')}`
257
+ const variableName = `$${n.replace(/[^a-zA-Z0-9_$]/g, '_')}`
258
258
  const objectKey = JSON.stringify(n)
259
259
  const reExportedName = n === 'default' || NODE_MAJOR < 16 ? n : objectKey
260
260
 
package/hook.mjs CHANGED
@@ -2,7 +2,9 @@
2
2
  //
3
3
  // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021 Datadog, Inc.
4
4
 
5
- import { createHook } from './hook.js'
5
+ import { createRequire } from 'node:module'
6
+ const require = createRequire(import.meta.url)
7
+ const { createHook } = require('./hook.js')
6
8
 
7
9
  const { initialize, load, resolve, getFormat, getSource } = createHook(import.meta)
8
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "import-in-the-middle",
3
- "version": "1.14.1",
3
+ "version": "1.14.3",
4
4
  "description": "Intercept imports in Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,9 @@
1
+ import { readFile } from 'fs/promises'
2
+
3
+ export async function load (url, context, nextLoad) {
4
+ const result = await nextLoad(url, context)
5
+ if (!result.source && url.startsWith('file:')) {
6
+ result.source = await readFile(new URL(url))
7
+ }
8
+ return result
9
+ }
@@ -3,3 +3,6 @@ exports['one.two'] = () => console.log('b')
3
3
 
4
4
  // See: https://github.com/nodejs/import-in-the-middle/issues/94
5
5
  exports['unsigned short'] = 'something'
6
+
7
+ exports._ = 'foo'
8
+ exports.$ = 'bar'
@@ -0,0 +1,15 @@
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 { execSync } from 'child_process'
6
+ import { doesNotThrow } from 'assert'
7
+
8
+ const env = {
9
+ ...process.env,
10
+ NODE_OPTIONS: '--no-warnings --experimental-loader ./test/fixtures/double-loader.mjs --experimental-loader ./hook.mjs'
11
+ }
12
+
13
+ doesNotThrow(() => {
14
+ execSync('node -p 0', { env })
15
+ })