Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
73 lines (58 loc) · 2.64 KB

File metadata and controls

73 lines (58 loc) · 2.64 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const crypto = require('crypto');
const fs = require('fs');
const path = require('path');
/**
* Build a cache key for the dependencies of the monorepo.
* In addition to the content of the yarn.lock file, we also include
* dependencies of all workspace packages in the cache key.
* This ensures that we get a consistent cache key even if a dependency change does not affect
* the yarn.lock file.
*/
function outputDependencyCacheKey() {
const lockfileContent = fs.readFileSync(path.join(process.cwd(), 'yarn.lock'), 'utf8');
const hashParts = [lockfileContent];
const packageJson = require(path.join(process.cwd(), 'package.json'));
const workspacePackages = packageJson.workspaces || [];
// Get the package name (e.g. @sentry/browser) of all workspace packages
// we want to ignore their version numbers later
const workspacePackageNames = getWorkspacePackageNames(workspacePackages);
// Add the dependencies of the workspace itself
hashParts.push(getNormalizedDependencies(packageJson, workspacePackageNames));
// Now for each workspace package, add the dependencies
workspacePackages.forEach(workspace => {
const packageJsonPath = path.join(process.cwd(), workspace, 'package.json');
const packageJson = require(packageJsonPath);
hashParts.push(getNormalizedDependencies(packageJson, workspacePackageNames));
});
const hash = crypto.createHash('md5').update(hashParts.join('\n')).digest('hex');
// We log the output in a way that the GitHub Actions can append it to the output
// We prefix it with `dependencies-` so it is easier to identify in the logs
// eslint-disable-next-line no-console
console.log(`hash=dependencies-${hash}`);
}
function getNormalizedDependencies(packageJson, workspacePackageNames) {
const { dependencies, devDependencies } = packageJson;
const mergedDependencies = {
...devDependencies,
...dependencies,
};
const normalizedDependencies = {};
// Sort the keys to ensure a consistent order
Object.keys(mergedDependencies)
.sort()
.forEach(key => {
// If the dependency is a workspace package, ignore the version
// No need to invalidate a cache after every release
const version = workspacePackageNames.includes(key) ? '**workspace**' : mergedDependencies[key];
normalizedDependencies[key] = version;
});
return JSON.stringify(normalizedDependencies);
}
function getWorkspacePackageNames(workspacePackages) {
return workspacePackages.map(workspace => {
const packageJsonPath = path.join(process.cwd(), workspace, 'package.json');
const packageJson = require(packageJsonPath);
return packageJson.name;
});
}
outputDependencyCacheKey();
Morty Proxy This is a proxified and sanitized view of the page, visit original site.