|
| 1 | +#!/usr/bin/env node |
| 2 | + |
| 3 | +/** |
| 4 | + * This script verifies that every package in the @agoric/sdk project has an |
| 5 | + * Agoric-controlled name and its name matches its `private` flag. |
| 6 | + * |
| 7 | + * This helps make more clear when viewing a package name whether it will be published. |
| 8 | + * It's also a backstop against accidentally flipping the `private` flag because |
| 9 | + * our NPM account doesn't have permission to publish to non-Agoric names. |
| 10 | + */ |
| 11 | + |
| 12 | +import { execFileSync } from 'node:child_process'; |
| 13 | +import fs from 'node:fs'; |
| 14 | +import path from 'node:path'; |
| 15 | +// eslint-disable-next-line import/no-relative-packages -- one-off script |
| 16 | +import { listWorkspaces } from '../packages/agoric-cli/src/lib/packageManager.js'; |
| 17 | + |
| 18 | +let hasErrors = false; |
| 19 | +const err = msg => { |
| 20 | + console.error(msg); |
| 21 | + hasErrors = true; |
| 22 | +}; |
| 23 | + |
| 24 | +// Get all workspaces in the project |
| 25 | +const workspaces = listWorkspaces({ execFileSync }); |
| 26 | + |
| 27 | +// Check each package.json |
| 28 | +for (const { name, location } of workspaces) { |
| 29 | + const packageJsonPath = path.join(location, 'package.json'); |
| 30 | + |
| 31 | + try { |
| 32 | + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); |
| 33 | + const { private: isPrivate } = packageJson; |
| 34 | + |
| 35 | + // These orgs and name are owned in NPM by OpCo |
| 36 | + const owned = |
| 37 | + name.startsWith('@agoric/') || |
| 38 | + name.startsWith('@aglocal/') || |
| 39 | + name === 'agoric'; |
| 40 | + |
| 41 | + if (!owned) { |
| 42 | + err(`Uncontrolled package name ${name}`); |
| 43 | + } |
| 44 | + |
| 45 | + const isLocal = name.startsWith('@aglocal/'); |
| 46 | + |
| 47 | + if (isLocal && !isPrivate) { |
| 48 | + err(`Package ${name} is a local name but is not marked private`); |
| 49 | + } else if (isPrivate && !isLocal) { |
| 50 | + err(`Package ${name} is a public name but marked private`); |
| 51 | + } |
| 52 | + } catch (error) { |
| 53 | + err(`Error processing ${packageJsonPath}: ${error.message}`); |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +// Exit with error code if any issues were found |
| 58 | +process.exit(hasErrors ? 1 : 0); |
0 commit comments