From 5642dd7552f036e61d13a732d9de703d7562f178 Mon Sep 17 00:00:00 2001 From: stygian-desolator Date: Wed, 8 Jun 2022 22:08:02 +0800 Subject: [PATCH 1/3] fix: encode id in different way --- packages/vite/src/node/utils.ts | 5 ++++- .../optimize-deps/__tests__/optimize-deps.spec.ts | 5 +++++ playground/optimize-deps/index.html | 12 ++++++++++++ playground/optimize-deps/package.json | 4 +++- 4 files changed, 24 insertions(+), 2 deletions(-) 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 @@

Alias with colon

Reused variable names

This should show reused:
+

Flatten Id

+
+
+ + + diff --git a/playground/optimize-deps/package.json b/playground/optimize-deps/package.json index 3a274ff63b5fdf..ee07d10897133e 100644 --- a/playground/optimize-deps/package.json +++ b/playground/optimize-deps/package.json @@ -30,7 +30,9 @@ "resolve-linked": "workspace:0.0.0", "url": "^0.11.0", "vue": "^3.2.37", - "vuex": "^4.0.2" + "vuex": "^4.0.2", + "lodash": "^4.17.21", + "lodash.clonedeep": "^4.5.0" }, "devDependencies": { "@vitejs/plugin-vue": "workspace:*" From 6753c116ea863719fef29d58936ccea87b167494 Mon Sep 17 00:00:00 2001 From: stygian-desolator Date: Thu, 9 Jun 2022 09:10:33 +0800 Subject: [PATCH 2/3] chore: udpate lock file --- pnpm-lock.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 438930772bdd48..5076a0b94debe2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -585,7 +585,9 @@ importers: dep-with-builtin-module-cjs: file:./dep-with-builtin-module-cjs dep-with-builtin-module-esm: file:./dep-with-builtin-module-esm dep-with-dynamic-import: file:./dep-with-dynamic-import + lodash: ^4.17.21 lodash-es: ^4.17.21 + lodash.clonedeep: ^4.5.0 nested-exclude: file:./nested-exclude phoenix: ^1.6.10 react: ^17.0.2 @@ -608,7 +610,9 @@ importers: dep-with-builtin-module-cjs: file:playground/optimize-deps/dep-with-builtin-module-cjs dep-with-builtin-module-esm: file:playground/optimize-deps/dep-with-builtin-module-esm dep-with-dynamic-import: file:playground/optimize-deps/dep-with-dynamic-import + lodash: 4.17.21 lodash-es: 4.17.21 + lodash.clonedeep: 4.5.0 nested-exclude: file:playground/optimize-deps/nested-exclude phoenix: 1.6.10 react: 17.0.2 @@ -5842,6 +5846,10 @@ packages: resolution: {integrity: sha1-soqmKIorn8ZRA1x3EfZathkDMaY=} dev: true + /lodash.clonedeep/4.5.0: + resolution: {integrity: sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==} + dev: false + /lodash.defaults/4.2.0: resolution: {integrity: sha1-0JF4cW/+pN3p5ft7N/bwgCJ0WAw=} dev: true From 86460ecb936d61fcf9239801deb6909e201a08dc Mon Sep 17 00:00:00 2001 From: patak Date: Thu, 9 Jun 2022 17:01:03 +0200 Subject: [PATCH 3/3] chore: improve encoding map Co-authored-by: Bjorn Lu --- packages/vite/src/node/utils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/utils.ts b/packages/vite/src/node/utils.ts index 253d61bd562614..c743ef7caa76e5 100644 --- a/packages/vite/src/node/utils.ts +++ b/packages/vite/src/node/utils.ts @@ -38,9 +38,9 @@ export function unwrapId(id: string): string { export const flattenId = (id: string): string => id - .replace(/(\s*>\s*)/g, '__') .replace(/[\/:]/g, '_') - .replace(/[\.]/g, '___') + .replace(/[\.]/g, '__') + .replace(/(\s*>\s*)/g, '___') export const normalizeId = (id: string): string => id.replace(/(\s*>\s*)/g, ' > ')