Skip to content

Commit 1143f6f

Browse files
authored
feature: update cache key (#73)
1 parent 5b53956 commit 1143f6f

File tree

1 file changed

+1
-57
lines changed

1 file changed

+1
-57
lines changed

scripts/computeNodeModulesCacheKey.js

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1 @@
1-
import { createHash } from 'node:crypto'
2-
import { readFile } from 'node:fs/promises'
3-
import { dirname, join } from 'node:path'
4-
import { fileURLToPath } from 'node:url'
5-
6-
const __dirname = dirname(fileURLToPath(import.meta.url))
7-
8-
const root = join(__dirname, '..')
9-
10-
const locations = [
11-
'lerna.json',
12-
'package-lock.json',
13-
'packages/e2e/package-lock.json',
14-
'packages/build/package-lock.json',
15-
'packages/extension/package-lock.json',
16-
'packages/integration/package-lock.json',
17-
'packages/schemas/package-lock.json',
18-
'packages/json-worker/package-lock.json',
19-
'.github/workflows/pr.yml',
20-
'.github/workflows/ci.yml',
21-
'.github/workflows/release.yml',
22-
'scripts/computeNodeModulesCacheKey.js',
23-
]
24-
25-
const getAbsolutePath = (relativePath) => {
26-
return join(root, relativePath)
27-
}
28-
29-
const getContent = (absolutePath) => {
30-
return readFile(absolutePath, 'utf8')
31-
}
32-
33-
export const computeHash = (contents) => {
34-
const hash = createHash('sha1')
35-
if (Array.isArray(contents)) {
36-
for (const content of contents) {
37-
hash.update(content)
38-
}
39-
} else if (typeof contents === 'string') {
40-
hash.update(contents)
41-
}
42-
return hash.digest('hex')
43-
}
44-
45-
const computeCacheKey = async (locations) => {
46-
const absolutePaths = locations.map(getAbsolutePath)
47-
const contents = await Promise.all(absolutePaths.map(getContent))
48-
const hash = computeHash(contents)
49-
return hash
50-
}
51-
52-
const main = async () => {
53-
const hash = await computeCacheKey(locations)
54-
process.stdout.write(hash)
55-
}
56-
57-
main()
1+
import '../packages/build/src/computeNodeModulesCacheKey.js'

0 commit comments

Comments
 (0)