@tangle-network/agent-app 0.50.11 → 0.50.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/peer-floors/cli.js
CHANGED
|
@@ -5,11 +5,32 @@ import {
|
|
|
5
5
|
import {
|
|
6
6
|
checkAllPeerFloors,
|
|
7
7
|
checkDependencySources,
|
|
8
|
+
checkPeerFloors,
|
|
8
9
|
formatDependencySourceReport,
|
|
9
10
|
formatPeerFloorReport
|
|
10
11
|
} from "../chunk-BOQ4HVVH.js";
|
|
11
12
|
|
|
12
13
|
// src/peer-floors/cli.ts
|
|
14
|
+
import { readFileSync } from "fs";
|
|
15
|
+
import { join } from "path";
|
|
16
|
+
function checkDeclaredPins(appDir) {
|
|
17
|
+
const manifest = JSON.parse(readFileSync(join(appDir, "package.json"), "utf8"));
|
|
18
|
+
const pins = Object.fromEntries(
|
|
19
|
+
Object.entries({ ...manifest.devDependencies, ...manifest.dependencies }).filter(([name, version]) => name.startsWith("@tangle-network/") && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$/.test(version))
|
|
20
|
+
);
|
|
21
|
+
const report = checkPeerFloors({ appDir, shellManifest: { peerDependencies: pins } });
|
|
22
|
+
const installed = report.rows.filter((row) => row.installed !== null);
|
|
23
|
+
const mismatches = installed.filter((row) => row.installed !== row.range);
|
|
24
|
+
for (const row of mismatches) {
|
|
25
|
+
process.stderr.write(`DECLARED PIN VIOLATED: ${row.name} declares ${row.range}, but ${row.installed} is installed. Reinstall from the current frozen lockfile.
|
|
26
|
+
`);
|
|
27
|
+
}
|
|
28
|
+
if (mismatches.length === 0) {
|
|
29
|
+
process.stdout.write(`declared pins: ${installed.length} installed exact Tangle versions matched
|
|
30
|
+
`);
|
|
31
|
+
}
|
|
32
|
+
return mismatches.length === 0;
|
|
33
|
+
}
|
|
13
34
|
function parsePeerCheckArgs(argv) {
|
|
14
35
|
const exclude = [];
|
|
15
36
|
let appDir;
|
|
@@ -48,6 +69,13 @@ function main() {
|
|
|
48
69
|
if (reports.some((report) => !report.ok)) failed = true;
|
|
49
70
|
} catch (err) {
|
|
50
71
|
process.stderr.write(`agent-app-peer-check (peer floors) failed: ${err instanceof Error ? err.message : String(err)}
|
|
72
|
+
`);
|
|
73
|
+
failed = true;
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
if (!checkDeclaredPins(appDir)) failed = true;
|
|
77
|
+
} catch (err) {
|
|
78
|
+
process.stderr.write(`agent-app-peer-check (declared pins) failed: ${err instanceof Error ? err.message : String(err)}
|
|
51
79
|
`);
|
|
52
80
|
failed = true;
|
|
53
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/peer-floors/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * `agent-app-peer-check` — fail a consumer's CI when its dependencies are wrong\n *
|
|
1
|
+
{"version":3,"sources":["../../src/peer-floors/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * `agent-app-peer-check` — fail a consumer's CI when its dependencies are wrong\n * through installed compatibility, source, and declared-version checks.\n *\n * Runs in the CONSUMER's repo, over the consumer's own tree, because both\n * installed checks only mean anything against a real install. Add it next to\n * typecheck:\n *\n * \"scripts\": { \"peer-check\": \"agent-app-peer-check\" }\n *\n * Three gates, one report, one exit code:\n *\n * PEER FLOORS — is the installed version inside the range the shell\n * declares. `pnpm` only WARNS on an unmet peer that is\n * also a direct dependency and says nothing at all for an\n * unmet optional one.\n * DEPENDENCY SOURCE — is the installed package the one the registry\n * publishes at all. A `file:` tarball, a `link:` out of\n * the repo, or a hand-patched `node_modules` all report\n * the same version as the real release and ship different\n * bytes.\n * DECLARED PINS — do installed exact Tangle versions match the consumer's\n * dependency and development dependency declarations.\n *\n * The source gate runs FIRST and independently: it needs no installed shell, so\n * a repo whose install is broken still gets the answer that explains why.\n *\n * Usage: agent-app-peer-check [repoDir] [--exclude <path>]...\n * `--exclude` takes a repo-relative path prefix the source-tree walk skips —\n * the escape hatch for a repo that genuinely carries a tarball as test data.\n * Exits 1 on any violation, 0 otherwise.\n */\nimport { readFileSync } from 'node:fs'\nimport { join } from 'node:path'\nimport { checkAllPeerFloors, checkPeerFloors, formatPeerFloorReport } from './check'\nimport { checkDependencySources, formatDependencySourceReport } from './dependency-source'\nimport { invokedAsScript } from '../signoff/invoked-as-script'\n\ninterface CliArgs {\n readonly appDir: string\n readonly exclude: readonly string[]\n}\n\n/** Exact consumer pins choose an artifact; engine peer ranges choose compatibility. */\nfunction checkDeclaredPins(appDir: string): boolean {\n const manifest = JSON.parse(readFileSync(join(appDir, 'package.json'), 'utf8')) as {\n dependencies?: Record<string, string>\n devDependencies?: Record<string, string>\n }\n const pins = Object.fromEntries(\n Object.entries({ ...manifest.devDependencies, ...manifest.dependencies })\n .filter(([name, version]) => name.startsWith('@tangle-network/')\n && /^\\d+\\.\\d+\\.\\d+(?:-[0-9A-Za-z.-]+)?(?:\\+[0-9A-Za-z.-]+)?$/.test(version)),\n )\n const report = checkPeerFloors({ appDir, shellManifest: { peerDependencies: pins } })\n const installed = report.rows.filter((row) => row.installed !== null)\n const mismatches = installed.filter((row) => row.installed !== row.range)\n for (const row of mismatches) {\n process.stderr.write(`DECLARED PIN VIOLATED: ${row.name} declares ${row.range}, but ${row.installed} is installed. Reinstall from the current frozen lockfile.\\n`)\n }\n if (mismatches.length === 0) {\n process.stdout.write(`declared pins: ${installed.length} installed exact Tangle versions matched\\n`)\n }\n return mismatches.length === 0\n}\n\nexport function parsePeerCheckArgs(argv: readonly string[]): CliArgs {\n const exclude: string[] = []\n let appDir: string | undefined\n for (let i = 0; i < argv.length; i += 1) {\n const arg = argv[i] as string\n if (arg === '--exclude') {\n const value = argv[i + 1]\n if (value) exclude.push(value)\n i += 1\n } else if (arg.startsWith('--exclude=')) {\n exclude.push(arg.slice('--exclude='.length))\n } else if (!arg.startsWith('-') && appDir === undefined) {\n appDir = arg\n }\n }\n return { appDir: appDir ?? process.cwd(), exclude }\n}\n\nfunction main(): void {\n const { appDir, exclude } = parsePeerCheckArgs(process.argv.slice(2))\n let failed = false\n\n try {\n const sources = checkDependencySources({ repoDir: appDir, exclude })\n process.stdout.write(`${formatDependencySourceReport(sources)}\\n\\n`)\n if (!sources.ok) failed = true\n } catch (err) {\n process.stderr.write(`agent-app-peer-check (dependency sources) failed: ${err instanceof Error ? err.message : String(err)}\\n`)\n failed = true\n }\n\n try {\n const reports = checkAllPeerFloors({ appDir })\n process.stdout.write(`${reports.map((report) => formatPeerFloorReport(report)).join('\\n\\n')}\\n`)\n if (reports.some((report) => !report.ok)) failed = true\n } catch (err) {\n process.stderr.write(`agent-app-peer-check (peer floors) failed: ${err instanceof Error ? err.message : String(err)}\\n`)\n failed = true\n }\n\n try {\n if (!checkDeclaredPins(appDir)) failed = true\n } catch (err) {\n process.stderr.write(`agent-app-peer-check (declared pins) failed: ${err instanceof Error ? err.message : String(err)}\\n`)\n failed = true\n }\n\n process.exit(failed ? 1 : 0)\n}\n\n/* c8 ignore start — process wiring, exercised by the bin itself */\nif (invokedAsScript(import.meta.url, process.argv[1])) main()\n/* c8 ignore stop */\n"],"mappings":";;;;;;;;;;;;;AAiCA,SAAS,oBAAoB;AAC7B,SAAS,YAAY;AAWrB,SAAS,kBAAkB,QAAyB;AAClD,QAAM,WAAW,KAAK,MAAM,aAAa,KAAK,QAAQ,cAAc,GAAG,MAAM,CAAC;AAI9E,QAAM,OAAO,OAAO;AAAA,IAClB,OAAO,QAAQ,EAAE,GAAG,SAAS,iBAAiB,GAAG,SAAS,aAAa,CAAC,EACrE,OAAO,CAAC,CAAC,MAAM,OAAO,MAAM,KAAK,WAAW,kBAAkB,KAC1D,2DAA2D,KAAK,OAAO,CAAC;AAAA,EACjF;AACA,QAAM,SAAS,gBAAgB,EAAE,QAAQ,eAAe,EAAE,kBAAkB,KAAK,EAAE,CAAC;AACpF,QAAM,YAAY,OAAO,KAAK,OAAO,CAAC,QAAQ,IAAI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