Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer creation of cache directory #13420

Merged
merged 2 commits into from
Nov 8, 2022
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