-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfix_hashes.js
More file actions
44 lines (36 loc) · 1.74 KB
/
fix_hashes.js
File metadata and controls
44 lines (36 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const fs = require('node:fs');
const path = require('node:path');
const { hashElement } = require('folder-hash');
const crypto = require('node:crypto');
const packagesDir = path.join(__dirname, 'packages');
const registryFile = path.join(__dirname, '.version_hashes.json');
const registry = JSON.parse(fs.readFileSync(registryFile, 'utf8'));
const hashOptions = {
folders: { exclude: ['.*', 'node_modules', 'dist', 'lib'] },
files: { include: ['*.js', '*.ts', '*.json', '*.md'], exclude: ['package.json', 'tsconfig.tsbuildinfo'] }
};
async function run() {
const packages = fs.readdirSync(packagesDir);
for(const pkg of packages) {
const pkgDir = path.join(packagesDir, pkg);
if (!fs.statSync(pkgDir).isDirectory()) continue;
const pkgJsonPath = path.join(pkgDir, 'package.json');
if (!fs.existsSync(pkgJsonPath)) continue;
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));
const { hash: rawHash } = await hashElement(pkgDir, hashOptions);
const depsHash = crypto.createHash('sha256').update(JSON.stringify({
dependencies: pkgJson.dependencies || {},
devDependencies: pkgJson.devDependencies || {},
peerDependencies: pkgJson.peerDependencies || {},
scripts: pkgJson.scripts || {},
bin: pkgJson.bin || {}
})).digest('hex');
const finalHash = `${rawHash}-${depsHash}`;
if (registry[pkgJson.name]) {
registry[pkgJson.name].hash = finalHash;
}
}
fs.writeFileSync(registryFile, JSON.stringify(registry, null, 2), 'utf8');
console.log("Les hashes sont maintenant parfaitement synchronisés avec le nouvel algorithme !");
}
run().catch(console.error);