Skip to content

Commit 751364e

Browse files
authored
fix(fsModuleCache): don't store importers in cache (#9422)
1 parent d390eb5 commit 751364e

File tree

2 files changed

+7
-23
lines changed

2 files changed

+7
-23
lines changed

packages/vitest/src/node/cache/fsModuleCache.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class FileSystemModuleCache {
3333
private rootCache: string
3434
private metadataFilePath: string
3535

36-
private version = '1.0.0-beta.3'
36+
private version = '1.0.0-beta.4'
3737
private fsCacheRoots = new WeakMap<ResolvedConfig, string>()
3838
private fsEnvironmentHashMap = new WeakMap<DevEnvironment, string>()
3939
private fsCacheKeyGenerators = new Set<CacheKeyIdGenerator>()
@@ -108,7 +108,6 @@ export class FileSystemModuleCache {
108108
url: meta.url,
109109
file: meta.file,
110110
code,
111-
importers: meta.importers,
112111
importedUrls: meta.importedUrls,
113112
mappings: meta.mappings,
114113
}
@@ -117,7 +116,6 @@ export class FileSystemModuleCache {
117116
async saveCachedModule<T extends FetchResult>(
118117
cachedFilePath: string,
119118
fetchResult: T,
120-
importers: string[] = [],
121119
importedUrls: string[] = [],
122120
mappings: boolean = false,
123121
): Promise<void> {
@@ -126,7 +124,6 @@ export class FileSystemModuleCache {
126124
file: fetchResult.file,
127125
id: fetchResult.id,
128126
url: fetchResult.url,
129-
importers,
130127
importedUrls,
131128
mappings,
132129
} satisfies Omit<CachedInlineModuleMeta, 'code'>
@@ -367,7 +364,6 @@ export interface CachedInlineModuleMeta {
367364
id: string
368365
file: string | null
369366
code: string
370-
importers: string[]
371367
mappings: boolean
372368
importedUrls: string[]
373369
}

packages/vitest/src/node/environments/fetchModule.ts

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,18 @@ class ModuleFetcher {
125125
})
126126
}
127127

128-
const cachedModule = await this.getCachedModule(cachePath, environment, moduleGraphModule)
128+
const cachedModule = await this.getCachedModule(cachePath, environment, moduleGraphModule, importer)
129129
if (cachedModule) {
130130
this.recordResult(trace, cachedModule)
131131
return cachedModule
132132
}
133133

134134
const result = await this.fetchAndProcess(environment, url, importer, moduleGraphModule, options)
135-
const importers = this.getSerializedDependencies(moduleGraphModule)
136135
const importedUrls = this.getSerializedImports(moduleGraphModule)
137136
const map = moduleGraphModule.transformResult?.map
138137
const mappings = map && !('version' in map) && map.mappings === ''
139138

140-
return this.cacheResult(result, cachePath, importers, importedUrls, !!mappings)
139+
return this.cacheResult(result, cachePath, importedUrls, !!mappings)
141140
}
142141

143142
// we need this for UI to be able to show a module graph
@@ -149,17 +148,6 @@ class ModuleFetcher {
149148
return imports
150149
}
151150

152-
// 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-
163151
private recordResult(trace: Span, result: FetchResult | FetchCachedFileSystemResult): void {
164152
if ('externalize' in result) {
165153
trace.setAttributes({
@@ -235,6 +223,7 @@ class ModuleFetcher {
235223
cachePath: string,
236224
environment: DevEnvironment,
237225
moduleGraphModule: EnvironmentModuleNode,
226+
importer: string | undefined,
238227
): Promise<FetchResult | FetchCachedFileSystemResult | undefined> {
239228
if (moduleGraphModule.transformResult?.__vitestTmp) {
240229
return {
@@ -270,12 +259,12 @@ class ModuleFetcher {
270259
}
271260

272261
// we populate the module graph to make the watch mode work because it relies on importers
273-
cachedModule.importers.forEach((importer) => {
262+
if (importer) {
274263
const environmentNode = environment.moduleGraph.getModuleById(importer)
275264
if (environmentNode) {
276265
moduleGraphModule.importers.add(environmentNode)
277266
}
278-
})
267+
}
279268

280269
await Promise.all(cachedModule.importedUrls.map(async (url) => {
281270
const moduleNode = await environment.moduleGraph.ensureEntryFromUrl(url).catch(() => null)
@@ -317,7 +306,6 @@ class ModuleFetcher {
317306
private async cacheResult(
318307
result: FetchResult,
319308
cachePath: string,
320-
importers: string[] = [],
321309
importedUrls: string[] = [],
322310
mappings = false,
323311
): Promise<FetchResult | FetchCachedFileSystemResult> {
@@ -331,7 +319,7 @@ class ModuleFetcher {
331319
}
332320

333321
const savePromise = this.fsCache
334-
.saveCachedModule(cachePath, result, importers, importedUrls, mappings)
322+
.saveCachedModule(cachePath, result, importedUrls, mappings)
335323
.then(() => result)
336324
.finally(() => {
337325
saveCachePromises.delete(cachePath)

0 commit comments

Comments
 (0)