Skip to content

Commit 1c3565f

Browse files
Defer creation of cache directory (#13420)
1 parent ba20c15 commit 1c3565f

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Performance
1010

11+
- `[jest-transform]` Defer creation of cache directory [#13420](https://github.com/facebook/jest/pull/13420)
12+
1113
## 29.3.0
1214

1315
### Features

packages/jest-transform/src/ScriptTransformer.ts

+6-12
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,7 @@ class ScriptTransformer {
207207
);
208208
}
209209

210-
private _createFolderFromCacheKey(
211-
filename: string,
212-
cacheKey: string,
213-
): string {
210+
private _createCachedFilename(filename: string, cacheKey: string): string {
214211
const HasteMapClass = HasteMap.getStatic(this._config);
215212
const baseCacheDir = HasteMapClass.getCacheFilePath(
216213
this._config.cacheDirectory,
@@ -223,12 +220,7 @@ class ScriptTransformer {
223220
const cacheFilenamePrefix = path
224221
.basename(filename, path.extname(filename))
225222
.replace(/\W/g, '');
226-
const cachePath = slash(
227-
path.join(cacheDir, `${cacheFilenamePrefix}_${cacheKey}`),
228-
);
229-
createDirectory(cacheDir);
230-
231-
return cachePath;
223+
return slash(path.join(cacheDir, `${cacheFilenamePrefix}_${cacheKey}`));
232224
}
233225

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

241-
return this._createFolderFromCacheKey(filename, cacheKey);
233+
return this._createCachedFilename(filename, cacheKey);
242234
}
243235

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

251-
return this._createFolderFromCacheKey(filename, cacheKey);
243+
return this._createCachedFilename(filename, cacheKey);
252244
}
253245

254246
private _getTransformPath(filename: string) {
@@ -504,6 +496,7 @@ class ScriptTransformer {
504496
});
505497
}
506498

499+
createDirectory(path.dirname(cacheFilePath));
507500
return this._buildTransformResult(
508501
filename,
509502
cacheFilePath,
@@ -568,6 +561,7 @@ class ScriptTransformer {
568561
});
569562
}
570563

564+
createDirectory(path.dirname(cacheFilePath));
571565
return this._buildTransformResult(
572566
filename,
573567
cacheFilePath,

0 commit comments

Comments
 (0)