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

fix: lower length of key to improve usage in win32 #13827

Merged
merged 33 commits into from
Feb 23, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
30d1230
fix: lower length of key to improve usage in win32
trajano Jan 26, 2023
4555dfa
lint fix
trajano Jan 27, 2023
d79fe07
Removed default on getGlobalCacheKey and placed in the exported function
trajano Jan 27, 2023
2aca02e
Update CHANGELOG.md
trajano Jan 27, 2023
643fd29
Update CHANGELOG.md
trajano Jan 27, 2023
64d3a61
Update index.ts
trajano Jan 27, 2023
6341ece
Update CHANGELOG.md
trajano Jan 27, 2023
522d7b8
Update index.ts
trajano Jan 27, 2023
fa8bee7
Update index.ts
trajano Jan 28, 2023
a8a7911
Update packages/jest-create-cache-key-function/src/index.ts
trajano Jan 30, 2023
6fb185b
Update index.ts
trajano Jan 30, 2023
9f3b767
Update index.ts
trajano Jan 30, 2023
7b60763
Update README.md
trajano Jan 30, 2023
1e2a2db
Update index.ts
trajano Jan 30, 2023
77551f8
Update packages/jest-create-cache-key-function/src/index.ts
trajano Jan 30, 2023
77e7ab3
Update packages/jest-create-cache-key-function/src/index.ts
trajano Jan 30, 2023
99ef72d
Update index.ts
trajano Jan 30, 2023
edfea07
Update packages/jest-create-cache-key-function/README.md
trajano Jan 30, 2023
530f949
Update packages/jest-create-cache-key-function/README.md
trajano Jan 30, 2023
0a36e2b
Update packages/jest-create-cache-key-function/src/index.ts
trajano Jan 30, 2023
0889626
Merge branch 'main' into patch-1
SimenB Feb 2, 2023
f849b2c
Update index.test.ts
trajano Feb 2, 2023
6b8361f
Update index.ts
trajano Feb 2, 2023
b1fcfb9
Update index.ts
trajano Feb 15, 2023
714a93d
Update index.test.ts
trajano Feb 15, 2023
da16001
Merge branch 'main' into patch-1
trajano Feb 15, 2023
77cc75d
Update index.test.ts
trajano Feb 15, 2023
b4d7955
Merge branch 'main' into patch-1
SimenB Feb 23, 2023
2f075e2
move changelog entry
SimenB Feb 23, 2023
e75fa73
pass length to both substrings
SimenB Feb 23, 2023
9536286
move changelog entry again
SimenB Feb 23, 2023
e0d2f39
default to linux platform in tests
SimenB Feb 23, 2023
e59df8d
Merge branch 'main' into patch-1
SimenB Feb 23, 2023
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 @@ -4,6 +4,8 @@

### Fixes

- getCacheKey reduces size of global cache key portion to 16 characters. ([#13826](https://github.com/facebook/jest/pull/13827))
trajano marked this conversation as resolved.
Show resolved Hide resolved

### Chore & Maintenance

### Performance
Expand Down
27 changes: 24 additions & 3 deletions packages/jest-create-cache-key-function/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ type NewGetCacheKeyFunction = (

type GetCacheKeyFunction = OldGetCacheKeyFunction | NewGetCacheKeyFunction;

function getGlobalCacheKey(files: Array<string>, values: Array<string>) {
/**
* Computes the global cache key given a collection of files and values. This limits
* the output with a provided length.
* @param files list of files to read
* @param values list of values to add to the computation
* @param length length of the resulting key
* @returns {string} the global cache key
*/
trajano marked this conversation as resolved.
Show resolved Hide resolved
function getGlobalCacheKey(
files: Array<string>,
values: Array<string>,
length: number,
) {
return [
process.env.NODE_ENV,
process.env.BABEL_ENV,
Expand All @@ -52,7 +64,7 @@ function getGlobalCacheKey(files: Array<string>, values: Array<string>) {
createHash('sha1'),
)
.digest('hex')
.substring(0, 32);
.substring(0, length);
}

function getCacheKeyFunction(globalCacheKey: string): GetCacheKeyFunction {
Expand All @@ -75,9 +87,18 @@ function getCacheKeyFunction(globalCacheKey: string): GetCacheKeyFunction {
};
}

/**
* Computes the cache key given a collection of files and values. This limits
* the output with a provided length.
trajano marked this conversation as resolved.
Show resolved Hide resolved
* @param files list of files to read
* @param values list of values to add to the computation
* @param length length of the resulting key defaults to 16
* @returns {string} the global cache key
trajano marked this conversation as resolved.
Show resolved Hide resolved
*/
export default function createCacheKey(
files: Array<string> = [],
values: Array<string> = [],
length = 16,
): GetCacheKeyFunction {
return getCacheKeyFunction(getGlobalCacheKey(files, values));
return getCacheKeyFunction(getGlobalCacheKey(files, values, length));
}