import-in-the-middle 1.14.0 → 1.14.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.
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "1.14.0"
2
+ ".": "1.14.2"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [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)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * 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))
9
+
10
+ ## [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)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * Account for invalid identifiers ([#198](https://github.com/nodejs/import-in-the-middle/issues/198)) ([2cc8207](https://github.com/nodejs/import-in-the-middle/commit/2cc82070a5ca947463b70f28647b03496a9526f0))
16
+
3
17
  ## [1.14.0](https://github.com/nodejs/import-in-the-middle/compare/import-in-the-middle-v1.13.2...import-in-the-middle-v1.14.0) (2025-05-24)
4
18
 
5
19
 
package/hook.js CHANGED
@@ -254,19 +254,23 @@ 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, '_')}`
258
+ const objectKey = JSON.stringify(n)
259
+ const reExportedName = n === 'default' || NODE_MAJOR < 16 ? n : objectKey
260
+
257
261
  addSetter(n, `
258
- let $${n}
262
+ let ${variableName}
259
263
  try {
260
- $${n} = _.${n} = namespace.${n}
264
+ ${variableName} = _[${objectKey}] = namespace[${objectKey}]
261
265
  } catch (err) {
262
266
  if (!(err instanceof ReferenceError)) throw err
263
267
  }
264
- export { $${n} as ${n} }
265
- set.${n} = (v) => {
266
- $${n} = v
268
+ export { ${variableName} as ${reExportedName} }
269
+ set[${objectKey}] = (v) => {
270
+ ${variableName} = v
267
271
  return true
268
272
  }
269
- get.${n} = () => $${n}
273
+ get[${objectKey}] = () => ${variableName}
270
274
  `)
271
275
  }
272
276
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "import-in-the-middle",
3
- "version": "1.14.0",
3
+ "version": "1.14.2",
4
4
  "description": "Intercept imports in Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,8 @@
1
+ // These export identifiers are only supported in Node 16+
2
+ exports['one.two'] = () => console.log('b')
3
+
4
+ // See: https://github.com/nodejs/import-in-the-middle/issues/94
5
+ exports['unsigned short'] = 'something'
6
+
7
+ exports._ = 'foo'
8
+ exports.$ = 'bar'
@@ -0,0 +1,7 @@
1
+ // Regression test for https://github.com/nodejs/import-in-the-middle/issues/196
2
+
3
+ export default function foo () {
4
+ // do nothing
5
+ }
6
+
7
+ export { foo as 'module.exports' }
@@ -0,0 +1,4 @@
1
+ import ui from '../fixtures/module-exports-cjs-shim.mjs'
2
+ import { notStrictEqual } from 'assert'
3
+
4
+ notStrictEqual(ui, undefined)
@@ -0,0 +1,5 @@
1
+ import * as lib from '../fixtures/invalid-identifier.js'
2
+ import { strictEqual } from 'assert'
3
+
4
+ strictEqual(typeof lib['one.two'], 'function')
5
+ strictEqual(typeof lib['unsigned short'], 'string')