generate-deps-hash.js 1004 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. const crypto = require('crypto');
  2. const fs = require('fs');
  3. const path = require('path');
  4. // Fallback to blow away old cache keys
  5. const HASH_VERSION = 1;
  6. // Base files to hash
  7. const filesToHash = [
  8. path.resolve(__dirname, '../DEPS'),
  9. path.resolve(__dirname, '../yarn.lock')
  10. ];
  11. const addAllFiles = (dir) => {
  12. for (const child of fs.readdirSync(dir).sort()) {
  13. const childPath = path.resolve(dir, child);
  14. if (fs.statSync(childPath).isDirectory()) {
  15. addAllFiles(childPath);
  16. } else {
  17. filesToHash.push(childPath);
  18. }
  19. }
  20. };
  21. // Add all patch files to the hash
  22. addAllFiles(path.resolve(__dirname, '../patches'));
  23. // Create Hash
  24. const hasher = crypto.createHash('SHA256');
  25. for (const file of filesToHash) {
  26. hasher.update(fs.readFileSync(file));
  27. }
  28. // Add the GCLIENT_EXTRA_ARGS variable to the hash
  29. hasher.update(process.env.GCLIENT_EXTRA_ARGS || 'no_extra_args');
  30. // Write the hash to disk
  31. fs.writeFileSync(path.resolve(__dirname, '../.depshash'), hasher.digest('hex'));