|
| 1 | +import fs from 'node:fs' |
| 2 | + |
| 3 | +const dependencyName = '@whiskeysockets/baileys' |
| 4 | +const repoPrefix = 'github:ViperTecCorporation/Baileys#' |
| 5 | + |
| 6 | +const packageJson = JSON.parse(fs.readFileSync('package.json', 'utf8')) |
| 7 | +const wantedRefs = [ |
| 8 | + packageJson.dependencies?.[dependencyName], |
| 9 | + packageJson.resolutions?.[dependencyName], |
| 10 | +].filter(Boolean) |
| 11 | + |
| 12 | +const wantedHashes = [...new Set(wantedRefs.map((ref) => `${ref}`.split('#')[1]).filter(Boolean))] |
| 13 | +if (!wantedHashes.length) { |
| 14 | + console.error(`[check-baileys-lock] ${dependencyName} must be pinned with ${repoPrefix}<commit>`) |
| 15 | + process.exit(1) |
| 16 | +} |
| 17 | + |
| 18 | +if (wantedHashes.length > 1) { |
| 19 | + console.error(`[check-baileys-lock] package.json has conflicting Baileys pins: ${wantedHashes.join(', ')}`) |
| 20 | + process.exit(1) |
| 21 | +} |
| 22 | + |
| 23 | +const wantedHash = wantedHashes[0] |
| 24 | +const lockLines = fs.readFileSync('yarn.lock', 'utf8').split(/\r?\n/) |
| 25 | +const entryStart = lockLines.findIndex((line) => line.includes(`"${dependencyName}@${repoPrefix}`)) |
| 26 | +let lockEntry = '' |
| 27 | +if (entryStart >= 0) { |
| 28 | + const entryLines = [lockLines[entryStart]] |
| 29 | + for (let index = entryStart + 1; index < lockLines.length; index += 1) { |
| 30 | + const line = lockLines[index] |
| 31 | + if (line && !line.startsWith(' ')) break |
| 32 | + entryLines.push(line) |
| 33 | + } |
| 34 | + lockEntry = entryLines.join('\n') |
| 35 | +} |
| 36 | +const lockedHash = lockEntry.match(/Baileys#([0-9a-f]{7,40})/)?.[1] || lockEntry.match(/tar\.gz\/([0-9a-f]{7,40})/)?.[1] || '' |
| 37 | + |
| 38 | +if (!lockEntry || !lockedHash) { |
| 39 | + console.error('[check-baileys-lock] Baileys entry was not found in yarn.lock') |
| 40 | + process.exit(1) |
| 41 | +} |
| 42 | + |
| 43 | +if (lockedHash !== wantedHash) { |
| 44 | + console.error(`[check-baileys-lock] Baileys lock mismatch: package.json=${wantedHash} yarn.lock=${lockedHash}`) |
| 45 | + console.error('[check-baileys-lock] Run yarn install and commit yarn.lock with package.json.') |
| 46 | + process.exit(1) |
| 47 | +} |
| 48 | + |
| 49 | +console.log(`[check-baileys-lock] Baileys lock is in sync: ${wantedHash}`) |
0 commit comments