Skip to content

Commit 2b3169e

Browse files
authored
Update check-hash-collision.js
1 parent 9d2e245 commit 2b3169e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,40 @@
1+
// Community/scripts/check-hash-collision.js
2+
const fs = require('fs');
3+
const path = require('path');
14

5+
const registryPath = path.join(__dirname, '../plugins-registry.json');
6+
const registry = JSON.parse(fs.readFileSync(registryPath, 'utf8'));
7+
8+
function getStableId(pluginId) {
9+
let hash = 23;
10+
for (let i = 0; i < pluginId.length; i++) {
11+
hash = (hash * 31 + pluginId.charCodeAt(i)) | 0;
12+
}
13+
return Math.abs(hash) + 1000;
14+
}
15+
16+
const seenIds = new Set();
17+
let hasError = false;
18+
19+
console.log("🔍 Starting to check for plugin ID conflicts...");
20+
21+
registry.forEach(item => {
22+
const stableId = getStableId(item.id);
23+
24+
console.log(`Checking [${item.id}] -> Hash: ${stableId}`);
25+
26+
if (seenIds.has(stableId)) {
27+
console.error(`⛔ Fatel error! Conflict detected!`);
28+
console.error(`The hash value (${stableId}) calculated from the plugin ID [${item.id}] is duplicated with an existing plugin.`);
29+
hasError = true;
30+
}
31+
seenIds.add(stableId);
32+
});
33+
34+
if (hasError) {
35+
console.log("⛔ Check failed, please change the plugin ID.");
36+
process.exit(1);
37+
} else {
38+
console.log("✅ The check passed; no conflicts were found.");
39+
process.exit(0);
40+
}

0 commit comments

Comments
 (0)