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)

129129

if (cachedModule) {

130130

this.recordResult(trace, cachedModule)

131131

return cachedModule

132132

}

133133134134

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 === ''

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 {

149148

return 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-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

}

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) {

274263

const environmentNode = environment.moduleGraph.getModuleById(importer)

275264

if (environmentNode) {

276265

moduleGraphModule.importers.add(environmentNode)

277266

}

278-

})

267+

}

279268280269

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

}

332320333321

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)