Skip to content

Commit 2e24987

Browse files
turadgmergify[bot]
authored andcommitted
ci: lint package naming
1 parent 181bf86 commit 2e24987

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

.github/workflows/test-all-packages.yml

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ jobs:
9393

9494
- name: lint repo format
9595
run: yarn lint:format
96+
- run: yarn lint:package-names
9697
# eslint and tsc
9798
- run: yarn lint:packages
9899

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"lint-fix": "yarn lerna run --no-bail lint-fix",
6464
"lint": "run-s --continue-on-error lint:*",
6565
"lint:packages": "yarn lerna run --no-bail lint",
66+
"lint:package-names": "./scripts/verify-package-names.js",
6667
"test": "yarn lerna run --no-bail test",
6768
"test:xs": "yarn workspaces run test:xs",
6869
"build": "yarn workspaces run build && scripts/agd-builder.sh stamp yarn-built",

scripts/verify-package-names.js

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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

Comments
 (0)