From dafff4ae6eabf22b7f08a582f3663eb8a08bfc32 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Tue, 2 Jul 2024 17:47:29 +0800 Subject: [PATCH] fix: lazily evaluate __vite__mapDeps files (#17602) --- packages/vite/src/node/plugins/importAnalysisBuild.ts | 2 +- playground/js-sourcemap/__tests__/js-sourcemap.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/vite/src/node/plugins/importAnalysisBuild.ts b/packages/vite/src/node/plugins/importAnalysisBuild.ts index 3a99b310cd810a..fbadacaa9c4757 100644 --- a/packages/vite/src/node/plugins/importAnalysisBuild.ts +++ b/packages/vite/src/node/plugins/importAnalysisBuild.ts @@ -657,7 +657,7 @@ export function buildImportAnalysisPlugin(config: ResolvedConfig): Plugin { ) .join(',')}]` - const mapDepsCode = `const __vite__fileDeps=${fileDepsCode},__vite__mapDeps=i=>i.map(i=>__vite__fileDeps[i]);\n` + const mapDepsCode = `const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=${fileDepsCode})))=>i.map(i=>d[i]);\n` // inject extra code at the top or next line of hashbang if (code.startsWith('#!')) { diff --git a/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts b/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts index 15d82acd776283..c4f7af623fb724 100644 --- a/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts +++ b/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts @@ -164,7 +164,7 @@ describe.runIf(isBuild)('build tests', () => { const js = findAssetFile(/after-preload-dynamic-hashbang-[-\w]{8}\.js$/) expect(js.split('\n').slice(0, 2)).toEqual([ '#!/usr/bin/env node', - expect.stringContaining('const __vite__fileDeps=['), + expect.stringContaining('const __vite__mapDeps=(i'), ]) })