Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklx committed Nov 29, 2024
1 parent d8fb835 commit 184dd38
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
15 changes: 13 additions & 2 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
const importedBindings = enablePartialAccept
? new Map<string, Set<string>>()
: null
const toAbsoluteUrl = (url: string) =>
path.posix.resolve(path.posix.dirname(importerModule.url), url)

const normalizeUrl = async (
url: string,
Expand Down Expand Up @@ -751,8 +753,17 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
// normalize and rewrite accepted urls
const normalizedAcceptedUrls = new Set<string>()
for (const { url, start, end } of acceptedUrls) {
const resolved = await this.resolve(url, importerModule.id || undefined)
const normalized = resolved?.id || url
let normalized
if (url.startsWith('.')) {
const [resolved] = await moduleGraph.resolveUrl(toAbsoluteUrl(url))
normalized = resolved
} else {
const resolved = await this.resolve(
url,
importerModule.id || undefined,
)
normalized = resolved?.id || url
}
normalizedAcceptedUrls.add(normalized)
const hmrAccept = normalizeHmrUrl(normalized)
str().overwrite(start, end, JSON.stringify(hmrAccept), {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@





interface Foo {
bar: string
}

export function throwError(foo?: Foo): void {
throw new Error('method error')
}

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('module runner initialization', async () => {
mod.throwError()
})
expect(serializeStack(runner, methodError)).toBe(
' at Module.throwError (<root>/fixtures/throws-error-method.ts:11:9)',
' at Module.throwError (<root>/fixtures/throws-error-method.ts:6:9)',
)

// simulate HMR
Expand All @@ -61,7 +61,7 @@ describe('module runner initialization', async () => {
})

expect(serializeStack(runner, methodErrorNew)).toBe(
' at Module.throwError (<root>/fixtures/throws-error-method.ts:16:9)',
' at Module.throwError (<root>/fixtures/throws-error-method.ts:11:9)',
)
})

Expand Down

0 comments on commit 184dd38

Please sign in to comment.