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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Performance

- `[jest-transform]` Defer creation of cache directory [#13420](https://github.com/facebook/jest/pull/13420)

## 29.3.0

### Features
Expand Down
18 changes: 6 additions & 12 deletions packages/jest-transform/src/ScriptTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,7 @@ class ScriptTransformer {
);
}

private _createFolderFromCacheKey(
filename: string,
cacheKey: string,
): string {
private _createCachedFilename(filename: string, cacheKey: string): string {
const HasteMapClass = HasteMap.getStatic(this._config);
const baseCacheDir = HasteMapClass.getCacheFilePath(
this._config.cacheDirectory,
Expand All @@ -223,12 +220,7 @@ class ScriptTransformer {
const cacheFilenamePrefix = path
.basename(filename, path.extname(filename))
.replace(/\W/g, '');
const cachePath = slash(
path.join(cacheDir, `${cacheFilenamePrefix}_${cacheKey}`),
);
createDirectory(cacheDir);

return cachePath;
return slash(path.join(cacheDir, `${cacheFilenamePrefix}_${cacheKey}`));
}

private _getFileCachePath(
Expand All @@ -238,7 +230,7 @@ class ScriptTransformer {
): string {
const cacheKey = this._getCacheKey(content, filename, options);

return this._createFolderFromCacheKey(filename, cacheKey);
return this._createCachedFilename(filename, cacheKey);
}

private async _getFileCachePathAsync(
Expand All @@ -248,7 +240,7 @@ class ScriptTransformer {
): Promise<string> {
const cacheKey = await this._getCacheKeyAsync(content, filename, options);

return this._createFolderFromCacheKey(filename, cacheKey);
return this._createCachedFilename(filename, cacheKey);
}

private _getTransformPath(filename: string) {
Expand Down Expand Up @@ -504,6 +496,7 @@ class ScriptTransformer {
});
}

createDirectory(path.dirname(cacheFilePath));
return this._buildTransformResult(
filename,
cacheFilePath,
Expand Down Expand Up @@ -568,6 +561,7 @@ class ScriptTransformer {
});
}

createDirectory(path.dirname(cacheFilePath));
return this._buildTransformResult(
filename,
cacheFilePath,
Expand Down