import-in-the-middle 1.9.0 → 1.9.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.
@@ -1,3 +1,3 @@
1
1
  {
2
- ".": "1.9.0"
2
+ ".": "1.9.1"
3
3
  }
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.9.1](https://github.com/nodejs/import-in-the-middle/compare/import-in-the-middle-v1.9.0...import-in-the-middle-v1.9.1) (2024-07-15)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * Don't wrap native modules ([#142](https://github.com/nodejs/import-in-the-middle/issues/142)) ([f3278a3](https://github.com/nodejs/import-in-the-middle/commit/f3278a3c76af78fe369b599d5b2bf1d87edf0a7a))
9
+ * Use correct `format` when resolving exports from sub-modules ([#140](https://github.com/nodejs/import-in-the-middle/issues/140)) ([1db08ef](https://github.com/nodejs/import-in-the-middle/commit/1db08ef5f51346c20b4b3c313bf993e9cf1ca7d5))
10
+
3
11
  ## [1.9.0](https://github.com/nodejs/import-in-the-middle/compare/import-in-the-middle-v1.8.1...import-in-the-middle-v1.9.0) (2024-07-08)
4
12
 
5
13
 
package/hook.js CHANGED
@@ -206,24 +206,19 @@ async function processModule ({ srcUrl, context, parentGetSource, parentResolve,
206
206
  if (isStarExportLine(n) === true) {
207
207
  const [, modFile] = n.split('* from ')
208
208
 
209
- let modUrl
209
+ async function processSubModule (url, ctx) {
210
+ const setters = await processModule({ srcUrl: url, context: ctx, parentGetSource, parentResolve, excludeDefault: true })
211
+ for (const [name, setter] of setters.entries()) {
212
+ addSetter(name, setter, true)
213
+ }
214
+ }
215
+
210
216
  if (isBareSpecifier(modFile)) {
211
217
  // Bare specifiers need to be resolved relative to the parent module.
212
218
  const result = await parentResolve(modFile, { parentURL: srcUrl })
213
- modUrl = result.url
219
+ await processSubModule(result.url, { ...context, format: result.format })
214
220
  } else {
215
- modUrl = new URL(modFile, srcUrl).href
216
- }
217
-
218
- const setters = await processModule({
219
- srcUrl: modUrl,
220
- context,
221
- parentGetSource,
222
- parentResolve,
223
- excludeDefault: true
224
- })
225
- for (const [name, setter] of setters.entries()) {
226
- addSetter(name, setter, true)
221
+ await processSubModule(new URL(modFile, srcUrl).href, context)
227
222
  }
228
223
  } else {
229
224
  addSetter(n, `
@@ -297,6 +292,11 @@ function createHook (meta) {
297
292
  return result
298
293
  }
299
294
 
295
+ // We don't want to attempt to wrap native modules
296
+ if (result.url.endsWith('.node')) {
297
+ return result
298
+ }
299
+
300
300
  // Node.js v21 renames importAssertions to importAttributes
301
301
  if (
302
302
  (context.importAssertions && context.importAssertions.type === 'json') ||
@@ -48,6 +48,11 @@ async function getCjsExports (url, context, parentLoad, source) {
48
48
  }
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
+
52
+ if (newUrl.endsWith('.node')) {
53
+ return
54
+ }
55
+
51
56
  for (const each of await getExports(newUrl, context, parentLoad)) {
52
57
  full.add(each)
53
58
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "import-in-the-middle",
3
- "version": "1.9.0",
3
+ "version": "1.9.1",
4
4
  "description": "Intercept imports in Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -37,6 +37,7 @@
37
37
  "@babel/core": "^7.23.7",
38
38
  "@babel/eslint-parser": "^7.23.3",
39
39
  "@babel/plugin-syntax-import-assertions": "^7.23.3",
40
+ "@node-rs/crc32": "^1.10.3",
40
41
  "@react-email/components": "^0.0.19",
41
42
  "@types/node": "^18.0.6",
42
43
  "c8": "^7.8.0",
@@ -51,7 +52,8 @@
51
52
  "imhotap": "^2.1.0",
52
53
  "openai": "^4.47.2",
53
54
  "ts-node": "^10.9.1",
54
- "typescript": "^4.7.4"
55
+ "typescript": "^4.7.4",
56
+ "vue": "^3.4.31"
55
57
  },
56
58
  "dependencies": {
57
59
  "acorn": "^8.8.2",
@@ -0,0 +1 @@
1
+ module.exports = require('@node-rs/crc32-darwin-arm64')
@@ -0,0 +1 @@
1
+ module.exports = require('@node-rs/crc32-darwin-x64')
@@ -0,0 +1 @@
1
+ module.exports = require('@node-rs/crc32-linux-arm64-gnu')
@@ -0,0 +1 @@
1
+ module.exports = require('@node-rs/crc32-linux-x64-gnu')
@@ -0,0 +1 @@
1
+ module.exports = require('@node-rs/crc32-win32-arm64-msvc')
@@ -0,0 +1 @@
1
+ module.exports = require('@node-rs/crc32-win32-x64-msvc')
@@ -0,0 +1,10 @@
1
+ import { strictEqual } from 'assert'
2
+
3
+ // We dynamically import a specific file that imports the
4
+ // native module for this platform and architecture.
5
+ //
6
+ // This way we know the file exists and the native module can
7
+ // be loaded.
8
+ const lib = await import(`../fixtures/native-modules/${process.platform}-${process.arch}.js`)
9
+
10
+ strictEqual(typeof lib.default.crc32, 'function')
@@ -0,0 +1,5 @@
1
+ // https://github.com/nodejs/import-in-the-middle/issues/139
2
+ import { strictEqual } from 'assert'
3
+ import * as lib from 'vue/server-renderer'
4
+
5
+ strictEqual(typeof lib.renderToString, 'function')