fix(fsModuleCache): don't store importers in cache (#9422) · vitest-dev/vitest@751364e
@@ -125,19 +125,18 @@ class ModuleFetcher {
125125})
126126}
127127128-const cachedModule = await this.getCachedModule(cachePath, environment, moduleGraphModule)
128+const cachedModule = await this.getCachedModule(cachePath, environment, moduleGraphModule, importer)
129129if (cachedModule) {
130130this.recordResult(trace, cachedModule)
131131return cachedModule
132132}
133133134134const result = await this.fetchAndProcess(environment, url, importer, moduleGraphModule, options)
135-const importers = this.getSerializedDependencies(moduleGraphModule)
136135const importedUrls = this.getSerializedImports(moduleGraphModule)
137136const map = moduleGraphModule.transformResult?.map
138137const mappings = map && !('version' in map) && map.mappings === ''
139138140-return this.cacheResult(result, cachePath, importers, importedUrls, !!mappings)
139+return this.cacheResult(result, cachePath, importedUrls, !!mappings)
141140}
142141143142// we need this for UI to be able to show a module graph
@@ -149,17 +148,6 @@ class ModuleFetcher {
149148return imports
150149}
151150152-// we need this for the watcher to be able to find the related test file
153-private getSerializedDependencies(node: EnvironmentModuleNode): string[] {
154-const dependencies: string[] = []
155-node.importers.forEach((importer) => {
156-if (importer.id) {
157-dependencies.push(importer.id)
158-}
159-})
160-return dependencies
161-}
162-163151private recordResult(trace: Span, result: FetchResult | FetchCachedFileSystemResult): void {
164152if ('externalize' in result) {
165153trace.setAttributes({
@@ -235,6 +223,7 @@ class ModuleFetcher {
235223cachePath: string,
236224environment: DevEnvironment,
237225moduleGraphModule: EnvironmentModuleNode,
226+importer: string | undefined,
238227): Promise<FetchResult | FetchCachedFileSystemResult | undefined> {
239228if (moduleGraphModule.transformResult?.__vitestTmp) {
240229return {
@@ -270,12 +259,12 @@ class ModuleFetcher {
270259}
271260272261// we populate the module graph to make the watch mode work because it relies on importers
273-cachedModule.importers.forEach((importer) => {
262+if (importer) {
274263const environmentNode = environment.moduleGraph.getModuleById(importer)
275264if (environmentNode) {
276265moduleGraphModule.importers.add(environmentNode)
277266}
278-})
267+}
279268280269await Promise.all(cachedModule.importedUrls.map(async (url) => {
281270const moduleNode = await environment.moduleGraph.ensureEntryFromUrl(url).catch(() => null)
@@ -317,7 +306,6 @@ class ModuleFetcher {
317306private async cacheResult(
318307result: FetchResult,
319308cachePath: string,
320-importers: string[] = [],
321309importedUrls: string[] = [],
322310mappings = false,
323311): Promise<FetchResult | FetchCachedFileSystemResult> {
@@ -331,7 +319,7 @@ class ModuleFetcher {
331319}
332320333321const savePromise = this.fsCache
334-.saveCachedModule(cachePath, result, importers, importedUrls, mappings)
322+.saveCachedModule(cachePath, result, importedUrls, mappings)
335323.then(() => result)
336324.finally(() => {
337325saveCachePromises.delete(cachePath)