|
| 1 | +#!/usr/bin/env node |
| 2 | +/** |
| 3 | + * Validates that every public package in packages/* has: |
| 4 | + * 1. repository.url === EXPECTED_REPO_URL |
| 5 | + * 2. pack-release script + publishConfig.directory (required when workspace: deps are present) |
| 6 | + */ |
| 7 | +import fs from "fs"; |
| 8 | +import path from "path"; |
| 9 | +import { fileURLToPath } from "url"; |
| 10 | + |
| 11 | +const __dirname = path.dirname(fileURLToPath(import.meta.url)); |
| 12 | +const PACKAGES_DIR = path.resolve(__dirname, "../packages"); |
| 13 | +const EXPECTED_REPO_URL = "https://github.com/phantom/phantom-connect-sdk"; |
| 14 | + |
| 15 | +const errors = []; |
| 16 | + |
| 17 | +const packageDirs = fs |
| 18 | + .readdirSync(PACKAGES_DIR) |
| 19 | + .filter(name => fs.statSync(path.join(PACKAGES_DIR, name)).isDirectory()); |
| 20 | + |
| 21 | +for (const dir of packageDirs) { |
| 22 | + const pkgPath = path.join(PACKAGES_DIR, dir, "package.json"); |
| 23 | + if (!fs.existsSync(pkgPath)) continue; |
| 24 | + |
| 25 | + const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8")); |
| 26 | + if (pkg.private) continue; |
| 27 | + |
| 28 | + const prefix = `[${pkg.name}]`; |
| 29 | + |
| 30 | + // 1. repository.url check |
| 31 | + if (pkg.repository?.url !== EXPECTED_REPO_URL) { |
| 32 | + errors.push(`${prefix} repository.url is "${pkg.repository?.url ?? ""}", expected "${EXPECTED_REPO_URL}"`); |
| 33 | + } |
| 34 | + |
| 35 | + // 2. pack-release + publishConfig required when workspace: deps are present |
| 36 | + const allDeps = { |
| 37 | + ...pkg.dependencies, |
| 38 | + ...pkg.devDependencies, |
| 39 | + ...pkg.peerDependencies, |
| 40 | + ...pkg.optionalDependencies, |
| 41 | + }; |
| 42 | + const hasWorkspaceDeps = Object.values(allDeps).some(v => String(v).startsWith("workspace:")); |
| 43 | + |
| 44 | + if (hasWorkspaceDeps) { |
| 45 | + if (!pkg.scripts?.["pack-release"]) { |
| 46 | + errors.push(`${prefix} has workspace: deps but is missing the "pack-release" script`); |
| 47 | + } |
| 48 | + if (pkg.publishConfig?.directory !== "_release/package") { |
| 49 | + errors.push(`${prefix} has workspace: deps but publishConfig.directory is not "_release/package"`); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +if (errors.length > 0) { |
| 55 | + console.error("Package config check failed:\n"); |
| 56 | + errors.forEach(e => console.error(` ✗ ${e}`)); |
| 57 | + process.exit(1); |
| 58 | +} else { |
| 59 | + console.log(`Package config check passed (${packageDirs.length} packages checked).`); |
| 60 | +} |
0 commit comments