Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: revert #13073, use consistent virtual module ID in module graph #13734

Merged
merged 1 commit into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/vite/src/node/plugins/importAnalysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
// normalize and rewrite accepted urls
const normalizedAcceptedUrls = new Set<string>()
for (const { url, start, end } of acceptedUrls) {
const isRelative = url[0] === '.'
const [normalized] = await moduleGraph.resolveUrl(
isRelative ? toAbsoluteUrl(url) : url,
toAbsoluteUrl(url),
ssr,
)
normalizedAcceptedUrls.add(normalized)
Expand Down
7 changes: 6 additions & 1 deletion packages/vite/src/node/plugins/importMetaGlob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export async function transformGlobImport(
): Promise<TransformGlobImportResult | null> {
id = slash(id)
root = slash(root)
const isVirtual = !isAbsolute(id)
const isVirtual = isVirtualModule(id)
const dir = isVirtual ? undefined : dirname(id)
const matches = await parseImportGlob(
code,
Expand Down Expand Up @@ -645,3 +645,8 @@ export function getCommonBase(globsResolved: string[]): null | string {

return commonAncestor
}

export function isVirtualModule(id: string): boolean {
// https://vitejs.dev/guide/api-plugin.html#virtual-modules-convention
return id.startsWith('virtual:') || id[0] === '\0' || !id.includes('/')
}
9 changes: 0 additions & 9 deletions playground/hmr/__tests__/hmr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
removeFile,
untilBrowserLogAfter,
untilUpdated,
viteServer,
viteTestUrl,
} from '~utils'

Expand Down Expand Up @@ -677,14 +676,6 @@ if (!isBuild) {
expect(await btn.textContent()).toBe('Compteur 0')
})

test('virtual module in module graph', async () => {
const moduleGraph = viteServer.moduleGraph
const virtualId = Array.from(moduleGraph.idToModuleMap.keys()).filter(
(id: string) => id.includes('virtual'),
)
expect(virtualId).toEqual(['\x00virtual:file', '/@id/__x00__virtual:file'])
})

test('handle virtual module updates', async () => {
await page.goto(viteTestUrl)
const el = await page.$('.virtual')
Expand Down
7 changes: 0 additions & 7 deletions playground/hmr/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ if (import.meta.hot) {
handleDep('multi deps', foo, nestedFoo)
})

import.meta.hot.accept(
['virtual:file', '/@id/__x00__virtual:file'],
([rawVirtualPath, acceptedVirtualPath]) => {
text('.virtual', acceptedVirtualPath.virtual)
},
)

import.meta.hot.dispose(() => {
console.log(`foo was:`, foo)
})
Expand Down