Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions packages/vitest/src/node/cache/fsModuleCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class FileSystemModuleCache {
private rootCache: string
private metadataFilePath: string

private version = '1.0.0-beta.3'
private version = '1.0.0-beta.4'
private fsCacheRoots = new WeakMap<ResolvedConfig, string>()
private fsEnvironmentHashMap = new WeakMap<DevEnvironment, string>()
private fsCacheKeyGenerators = new Set<CacheKeyIdGenerator>()
Expand Down Expand Up @@ -108,7 +108,6 @@ export class FileSystemModuleCache {
url: meta.url,
file: meta.file,
code,
importers: meta.importers,
importedUrls: meta.importedUrls,
mappings: meta.mappings,
}
Expand All @@ -117,7 +116,6 @@ export class FileSystemModuleCache {
async saveCachedModule<T extends FetchResult>(
cachedFilePath: string,
fetchResult: T,
importers: string[] = [],
importedUrls: string[] = [],
mappings: boolean = false,
): Promise<void> {
Expand All @@ -126,7 +124,6 @@ export class FileSystemModuleCache {
file: fetchResult.file,
id: fetchResult.id,
url: fetchResult.url,
importers,
importedUrls,
mappings,
} satisfies Omit<CachedInlineModuleMeta, 'code'>
Expand Down Expand Up @@ -367,7 +364,6 @@ export interface CachedInlineModuleMeta {
id: string
file: string | null
code: string
importers: string[]
mappings: boolean
importedUrls: string[]
}
Expand Down
24 changes: 6 additions & 18 deletions packages/vitest/src/node/environments/fetchModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,19 +125,18 @@ class ModuleFetcher {
})
}

const cachedModule = await this.getCachedModule(cachePath, environment, moduleGraphModule)
const cachedModule = await this.getCachedModule(cachePath, environment, moduleGraphModule, importer)
if (cachedModule) {
this.recordResult(trace, cachedModule)
return cachedModule
}

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

return this.cacheResult(result, cachePath, importers, importedUrls, !!mappings)
return this.cacheResult(result, cachePath, importedUrls, !!mappings)
}

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

// we need this for the watcher to be able to find the related test file
private getSerializedDependencies(node: EnvironmentModuleNode): string[] {
const dependencies: string[] = []
node.importers.forEach((importer) => {
if (importer.id) {
dependencies.push(importer.id)
}
})
return dependencies
}

private recordResult(trace: Span, result: FetchResult | FetchCachedFileSystemResult): void {
if ('externalize' in result) {
trace.setAttributes({
Expand Down Expand Up @@ -235,6 +223,7 @@ class ModuleFetcher {
cachePath: string,
environment: DevEnvironment,
moduleGraphModule: EnvironmentModuleNode,
importer: string | undefined,
): Promise<FetchResult | FetchCachedFileSystemResult | undefined> {
if (moduleGraphModule.transformResult?.__vitestTmp) {
return {
Expand Down Expand Up @@ -270,12 +259,12 @@ class ModuleFetcher {
}

// we populate the module graph to make the watch mode work because it relies on importers
cachedModule.importers.forEach((importer) => {
if (importer) {
const environmentNode = environment.moduleGraph.getModuleById(importer)
if (environmentNode) {
moduleGraphModule.importers.add(environmentNode)
}
})
}

await Promise.all(cachedModule.importedUrls.map(async (url) => {
const moduleNode = await environment.moduleGraph.ensureEntryFromUrl(url).catch(() => null)
Expand Down Expand Up @@ -317,7 +306,6 @@ class ModuleFetcher {
private async cacheResult(
result: FetchResult,
cachePath: string,
importers: string[] = [],
importedUrls: string[] = [],
mappings = false,
): Promise<FetchResult | FetchCachedFileSystemResult> {
Expand All @@ -331,7 +319,7 @@ class ModuleFetcher {
}

const savePromise = this.fsCache
.saveCachedModule(cachePath, result, importers, importedUrls, mappings)
.saveCachedModule(cachePath, result, importedUrls, mappings)
.then(() => result)
.finally(() => {
saveCachePromises.delete(cachePath)
Expand Down
Loading