From f5daf24918bd2c5b624ec8e9530ecaf642a92a01 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Sat, 13 Jul 2024 14:53:46 +0200 Subject: [PATCH 1/2] fix: Use correct `format` when resolving exports from sub-modules --- hook.js | 23 +++++++++-------------- package.json | 3 ++- test/hook/vue-server-renderer.mjs | 4 ++++ 3 files changed, 15 insertions(+), 15 deletions(-) create mode 100644 test/hook/vue-server-renderer.mjs diff --git a/hook.js b/hook.js index 1752bcf..40359db 100644 --- a/hook.js +++ b/hook.js @@ -206,24 +206,19 @@ async function processModule ({ srcUrl, context, parentGetSource, parentResolve, if (isStarExportLine(n) === true) { const [, modFile] = n.split('* from ') - let modUrl + async function processSubModule (url, ctx) { + const setters = await processModule({ srcUrl: url, context: ctx, parentGetSource, parentResolve, excludeDefault: true }) + for (const [name, setter] of setters.entries()) { + addSetter(name, setter, true) + } + } + if (isBareSpecifier(modFile)) { // Bare specifiers need to be resolved relative to the parent module. const result = await parentResolve(modFile, { parentURL: srcUrl }) - modUrl = result.url + await processSubModule(result.url, { ...context, format: result.format }) } else { - modUrl = new URL(modFile, srcUrl).href - } - - const setters = await processModule({ - srcUrl: modUrl, - context, - parentGetSource, - parentResolve, - excludeDefault: true - }) - for (const [name, setter] of setters.entries()) { - addSetter(name, setter, true) + await processSubModule(new URL(modFile, srcUrl).href, context) } } else { addSetter(n, ` diff --git a/package.json b/package.json index 45d4a06..5625605 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,8 @@ "imhotap": "^2.1.0", "openai": "^4.47.2", "ts-node": "^10.9.1", - "typescript": "^4.7.4" + "typescript": "^4.7.4", + "vue": "^3.4.31" }, "dependencies": { "acorn": "^8.8.2", diff --git a/test/hook/vue-server-renderer.mjs b/test/hook/vue-server-renderer.mjs new file mode 100644 index 0000000..7b9e343 --- /dev/null +++ b/test/hook/vue-server-renderer.mjs @@ -0,0 +1,4 @@ +import { strictEqual } from 'assert' +import * as lib from 'vue/server-renderer' + +strictEqual(typeof lib.renderToString, 'function') From f947ee72c349bc83f79e18f8b2f983a955fa3ae5 Mon Sep 17 00:00:00 2001 From: Tim Fish Date: Mon, 15 Jul 2024 15:41:52 +0200 Subject: [PATCH 2/2] Add link to issue --- test/hook/vue-server-renderer.mjs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/hook/vue-server-renderer.mjs b/test/hook/vue-server-renderer.mjs index 7b9e343..2e0b3b2 100644 --- a/test/hook/vue-server-renderer.mjs +++ b/test/hook/vue-server-renderer.mjs @@ -1,3 +1,4 @@ +// https://github.com/nodejs/import-in-the-middle/issues/139 import { strictEqual } from 'assert' import * as lib from 'vue/server-renderer'