/ scripts / check-git-hashes.js
check-git-hashes.js
 1  #! /usr/bin/env node
 2  
 3  /* global console */
 4  
 5  import concat from 'iter-tools-es/methods/concat';
 6  import { readFile, readdir } from 'fs/promises';
 7  import { local } from './utils/path.js';
 8  
 9  const repos = {};
10  
11  for (const repo of await readdir(local`repos`)) {
12    let headHash, pkg, dependencies;
13  
14    try {
15      headHash = (await readFile(local`repos/${repo}/.git/refs/heads/trunk`, 'utf-8')).slice(0, -1);
16    } catch (e) {}
17  
18    try {
19      pkg = JSON.parse(await readFile(local`repos/${repo}/package.json`, 'utf-8'));
20  
21      dependencies = {};
22  
23      for (const [name, version] of concat(
24        Object.entries(pkg.dependencies),
25        Object.entries(pkg.devDependencies),
26      )) {
27        if (/^@?bablr/.test(name)) {
28          const result = /github:bablr-lang\/[^#]+#([a-f0-9]+)/.exec(version);
29          dependencies[name] = result[1];
30        }
31      }
32    } catch (e) {}
33  
34    if (headHash && pkg.name) {
35      repos[pkg.name] = {
36        headHash,
37        dependencies,
38      };
39    }
40  }
41  
42  for (const [name, repo] of Object.entries(repos)) {
43    for (const [depName, depHash] of Object.entries(repo.dependencies)) {
44      const { headHash } = repos[depName];
45      if (headHash !== depHash) {
46        console.log(
47          `Outdated dependency in ${name}: ${depName}\n  headHash:${headHash}\n  depHash:${depHash}`,
48        );
49      }
50    }
51  }