Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/azure-pipelines/common/computeNodeModulesCacheKey.ts
3520 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import fs from 'fs';
7
import path from 'path';
8
import crypto from 'crypto';
9
const { dirs } = require('../../npm/dirs');
10
11
const ROOT = path.join(__dirname, '../../../');
12
13
const shasum = crypto.createHash('sha256');
14
15
shasum.update(fs.readFileSync(path.join(ROOT, 'build/.cachesalt')));
16
shasum.update(fs.readFileSync(path.join(ROOT, '.npmrc')));
17
shasum.update(fs.readFileSync(path.join(ROOT, 'build', '.npmrc')));
18
shasum.update(fs.readFileSync(path.join(ROOT, 'remote', '.npmrc')));
19
20
// Add `package.json` and `package-lock.json` files
21
for (const dir of dirs) {
22
const packageJsonPath = path.join(ROOT, dir, 'package.json');
23
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());
24
const relevantPackageJsonSections = {
25
dependencies: packageJson.dependencies,
26
devDependencies: packageJson.devDependencies,
27
optionalDependencies: packageJson.optionalDependencies,
28
resolutions: packageJson.resolutions,
29
distro: packageJson.distro
30
};
31
shasum.update(JSON.stringify(relevantPackageJsonSections));
32
33
const packageLockPath = path.join(ROOT, dir, 'package-lock.json');
34
shasum.update(fs.readFileSync(packageLockPath));
35
}
36
37
// Add any other command line arguments
38
for (let i = 2; i < process.argv.length; i++) {
39
shasum.update(process.argv[i]);
40
}
41
42
process.stdout.write(shasum.digest('hex'));
43
44