Skip to content

Commit

Permalink
Defer creation of cache directory (#13420)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchhentgesspotify authored Nov 8, 2022
1 parent ba20c15 commit 1c3565f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
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

0 comments on commit 1c3565f

Please sign in to comment.