Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/azure-pipelines/common/computeNodeModulesCacheKey.ts
5239 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
import fs from 'fs';
6
import path from 'path';
7
import crypto from 'crypto';
8
import { dirs } from '../../npm/dirs.ts';
9
10
const ROOT = path.join(import.meta.dirname, '../../../');
11
12
const shasum = crypto.createHash('sha256');
13
14
shasum.update(fs.readFileSync(path.join(ROOT, 'build/.cachesalt')));
15
shasum.update(fs.readFileSync(path.join(ROOT, '.npmrc')));
16
shasum.update(fs.readFileSync(path.join(ROOT, 'build', '.npmrc')));
17
shasum.update(fs.readFileSync(path.join(ROOT, 'remote', '.npmrc')));
18
19
// Add `package.json` and `package-lock.json` files
20
for (const dir of dirs) {
21
const packageJsonPath = path.join(ROOT, dir, 'package.json');
22
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());
23
const relevantPackageJsonSections = {
24
dependencies: packageJson.dependencies,
25
devDependencies: packageJson.devDependencies,
26
optionalDependencies: packageJson.optionalDependencies,
27
resolutions: packageJson.resolutions,
28
distro: packageJson.distro
29
};
30
shasum.update(JSON.stringify(relevantPackageJsonSections));
31
32
const packageLockPath = path.join(ROOT, dir, 'package-lock.json');
33
shasum.update(fs.readFileSync(packageLockPath));
34
}
35
36
// Add any other command line arguments
37
for (let i = 2; i < process.argv.length; i++) {
38
shasum.update(process.argv[i]);
39
}
40
41
process.stdout.write(shasum.digest('hex'));
42
43