/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import fs from 'fs'; import path from 'path'; import crypto from 'crypto'; const { dirs } = require('../../npm/dirs'); const ROOT = path.join(__dirname, '../../../'); const shasum = crypto.createHash('sha256'); // Add build configuration files shasum.update(fs.readFileSync(path.join(ROOT, 'build/.cachesalt'))); shasum.update(fs.readFileSync(path.join(ROOT, '.npmrc'))); shasum.update(fs.readFileSync(path.join(ROOT, 'build', '.npmrc'))); shasum.update(fs.readFileSync(path.join(ROOT, 'remote', '.npmrc'))); // Add build scripts that could affect the build const buildScripts = [ 'gulpfile.js', 'build/gulpfile.js', 'build/gulpfile.vscode.js', 'build/lib/util.js' ]; for (const script of buildScripts) { try { const scriptPath = path.join(ROOT, script); if (fs.existsSync(scriptPath)) { shasum.update(fs.readFileSync(scriptPath)); } } catch (err) { console.warn(`Warning: Could not read build script ${script}`); } } // Add package.json and package-lock.json files for (const dir of dirs) { const packageJsonPath = path.join(ROOT, dir, 'package.json'); const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString()); const relevantPackageJsonSections = { dependencies: packageJson.dependencies, devDependencies: packageJson.devDependencies, optionalDependencies: packageJson.optionalDependencies, resolutions: packageJson.resolutions, distro: packageJson.distro, scripts: packageJson.scripts // Include build scripts }; shasum.update(JSON.stringify(relevantPackageJsonSections)); const packageLockPath = path.join(ROOT, dir, 'package-lock.json'); shasum.update(fs.readFileSync(packageLockPath)); } // Add environment variables that could affect the build const relevantEnvVars = [ 'VSCODE_QUALITY', 'VSCODE_BUILD_STAGE', 'VSCODE_BUILD_ARCH', 'ENABLE_EXTENSIONS' ]; for (const envVar of relevantEnvVars) { if (process.env[envVar]) { shasum.update(envVar + '=' + process.env[envVar]); } } // Add any other command line arguments for (let i = 2; i < process.argv.length; i++) { shasum.update(process.argv[i]); } process.stdout.write(shasum.digest('hex'));