File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments