Path: blob/main/build/azure-pipelines/common/computeNodeModulesCacheKey.ts
5240 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/4import fs from 'fs';5import path from 'path';6import crypto from 'crypto';7import { dirs } from '../../npm/dirs.ts';89const ROOT = path.join(import.meta.dirname, '../../../');1011const shasum = crypto.createHash('sha256');1213shasum.update(fs.readFileSync(path.join(ROOT, 'build/.cachesalt')));14shasum.update(fs.readFileSync(path.join(ROOT, '.npmrc')));15shasum.update(fs.readFileSync(path.join(ROOT, 'build', '.npmrc')));16shasum.update(fs.readFileSync(path.join(ROOT, 'remote', '.npmrc')));1718// Add `package.json` and `package-lock.json` files19for (const dir of dirs) {20const packageJsonPath = path.join(ROOT, dir, 'package.json');21const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());22const relevantPackageJsonSections = {23dependencies: packageJson.dependencies,24devDependencies: packageJson.devDependencies,25optionalDependencies: packageJson.optionalDependencies,26resolutions: packageJson.resolutions,27distro: packageJson.distro28};29shasum.update(JSON.stringify(relevantPackageJsonSections));3031const packageLockPath = path.join(ROOT, dir, 'package-lock.json');32shasum.update(fs.readFileSync(packageLockPath));33}3435// Add any other command line arguments36for (let i = 2; i < process.argv.length; i++) {37shasum.update(process.argv[i]);38}3940process.stdout.write(shasum.digest('hex'));414243