diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 121505f566f6e9..253d61bd562614 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -37,7 +37,10 @@ export function unwrapId(id: string): string { } export const flattenId = (id: string): string => - id.replace(/(\s*>\s*)/g, '__').replace(/[\/\.:]/g, '_') + id + .replace(/(\s*>\s*)/g, '__') + .replace(/[\/:]/g, '_') + .replace(/[\.]/g, '___') export const normalizeId = (id: string): string => id.replace(/(\s*>\s*)/g, ' > ') diff --git a/playground/optimize-deps/__tests__/optimize-deps.spec.ts b/playground/optimize-deps/__tests__/optimize-deps.spec.ts index bf4fee61e4e74c..cc712fbbdc4a09 100644 --- a/playground/optimize-deps/__tests__/optimize-deps.spec.ts +++ b/playground/optimize-deps/__tests__/optimize-deps.spec.ts @@ -121,6 +121,11 @@ test('variable names are reused in different scripts', async () => { expect(await page.textContent('.reused-variable-names')).toBe('reused') }) +test('flatten id should generate correctly', async () => { + expect(await page.textContent('.clonedeep-slash')).toBe('clonedeep-slash') + expect(await page.textContent('.clonedeep-dot')).toBe('clonedeep-dot') +}) + test.runIf(isServe)('error on builtin modules usage', () => { expect(browserLogs).toEqual( expect.arrayContaining([ diff --git a/playground/optimize-deps/index.html b/playground/optimize-deps/index.html index 39d76fd83d0609..b96620902c1eca 100644 --- a/playground/optimize-deps/index.html +++ b/playground/optimize-deps/index.html @@ -74,6 +74,10 @@