* 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 f
()
| 10 | * the yarn.lock file. |
| 11 | */ |
| 12 | function outputDependencyCacheKey() { |
| 13 | const lockfileContent = fs.readFileSync(path.join(process.cwd(), 'yarn.lock'), 'utf8'); |
| 14 | |
| 15 | const hashParts = [lockfileContent]; |
| 16 | |
| 17 | const packageJson = require(path.join(process.cwd(), 'package.json')); |
| 18 | |
| 19 | const workspacePackages = packageJson.workspaces || []; |
| 20 | |
| 21 | // Get the package name (e.g. @sentry/browser) of all workspace packages |
| 22 | // we want to ignore their version numbers later |
| 23 | const workspacePackageNames = getWorkspacePackageNames(workspacePackages); |
| 24 | |
| 25 | // Add the dependencies of the workspace itself |
| 26 | hashParts.push(getNormalizedDependencies(packageJson, workspacePackageNames)); |
| 27 | |
| 28 | // Now for each workspace package, add the dependencies |
| 29 | workspacePackages.forEach(workspace => { |
| 30 | const packageJsonPath = path.join(process.cwd(), workspace, 'package.json'); |
| 31 | const packageJson = require(packageJsonPath); |
| 32 | hashParts.push(getNormalizedDependencies(packageJson, workspacePackageNames)); |
| 33 | }); |
| 34 | |
| 35 | const hash = crypto.createHash('md5').update(hashParts.join('\n')).digest('hex'); |
| 36 | // We log the output in a way that the GitHub Actions can append it to the output |
| 37 | // We prefix it with `dependencies-` so it is easier to identify in the logs |
| 38 | // eslint-disable-next-line no-console |
| 39 | console.log(`hash=dependencies-${hash}`); |
| 40 | } |
| 41 | |
| 42 | function getNormalizedDependencies(packageJson, workspacePackageNames) { |
| 43 | const { dependencies, devDependencies } = packageJson; |
no test coverage detected