Skip to content

Commit

Permalink
fix: Use correct format when resolving exports from sub-modules (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
timfish authored Jul 15, 2024
1 parent df0bf4f commit 1db08ef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
23 changes: 9 additions & 14 deletions hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, `
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions test/hook/vue-server-renderer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// https://github.com/nodejs/import-in-the-middle/issues/139
import { strictEqual } from 'assert'
import * as lib from 'vue/server-renderer'

strictEqual(typeof lib.renderToString, 'function')

0 comments on commit 1db08ef

Please sign in to comment.