Part 1 of 2 of the n/no-process-exit cleanup (umbrella #738): convert every process.exit() call in standalone scripts/** CLIs to the rule-compliant pattern. - New shared helper scripts/lib/cli-exit.cjs: ExitError(code,message) + runMain() which translates a thrown ExitError / returned number into process.exitCode (never process.exit()), flushing output and still firing process.on('exit'). - main()-based entrypoints: throw new ExitError(code) for errors, return <code> for verdicts; invoked via runMain(main). Child exit codes preserved via return. - top-level-only scripts: imperative body extracted into main() so mid-flow aborts (throw ExitError) actually halt; pure consts/helpers stay at module scope. - diff-touches-shipped-paths.cjs: stdin event handling restructured to an async read so the whole flow runs under runMain; uncaughtException/unhandledRejection nets replaced by an in-band catch that preserves EXIT_ERROR=2. Exit codes verified unchanged for every converted script (success/error/help and the 0/1/2 semantic codes in diff-touches). Rule stays warn here; flipped to error in part 2 (#738) once gsd-core/bin/** is also clean. Refs #739 Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -25,6 +25,7 @@
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const { runMain } = require('./lib/cli-exit.cjs');
|
||||
|
||||
const PROFILES_MODULE = path.join(__dirname, '..', 'gsd-core', 'bin', 'lib', 'install-profiles.cjs');
|
||||
const { PROFILES, loadSkillsManifest, resolveProfile } = require(PROFILES_MODULE);
|
||||
@@ -142,39 +143,43 @@ function checkProfileClosure(manifest) {
|
||||
// Main
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const manifest = loadSkillsManifest(commandsDir);
|
||||
const allStems = new Set(
|
||||
[...manifest.keys()].filter((k) => !k.startsWith('_calls_agents_'))
|
||||
);
|
||||
function main() {
|
||||
const manifest = loadSkillsManifest(commandsDir);
|
||||
const allStems = new Set(
|
||||
[...manifest.keys()].filter((k) => !k.startsWith('_calls_agents_'))
|
||||
);
|
||||
|
||||
const consistencyViolations = checkFrontmatterBodyConsistency(manifest, allStems);
|
||||
const closureViolations = checkProfileClosure(manifest);
|
||||
const consistencyViolations = checkFrontmatterBodyConsistency(manifest, allStems);
|
||||
const closureViolations = checkProfileClosure(manifest);
|
||||
|
||||
const totalViolations = consistencyViolations.length + closureViolations.length;
|
||||
const totalViolations = consistencyViolations.length + closureViolations.length;
|
||||
|
||||
if (totalViolations === 0) {
|
||||
const checked = manifest.size;
|
||||
process.stdout.write('ok lint-skill-deps: ' + checked + ' skill(s) checked, 0 violations\n');
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
process.stderr.write('\nERROR lint-skill-deps: ' + totalViolations + ' violation(s) found\n\n');
|
||||
|
||||
if (consistencyViolations.length > 0) {
|
||||
process.stderr.write('Frontmatter to body consistency violations (' + consistencyViolations.length + '):\n\n');
|
||||
for (const v of consistencyViolations) {
|
||||
process.stderr.write(' ' + v.filePath + '\n');
|
||||
process.stderr.write(' ' + v.message + '\n\n');
|
||||
if (totalViolations === 0) {
|
||||
const checked = manifest.size;
|
||||
process.stdout.write('ok lint-skill-deps: ' + checked + ' skill(s) checked, 0 violations\n');
|
||||
return 0;
|
||||
}
|
||||
process.stderr.write('Fix: add missing deps to requires: in the skill frontmatter.\n\n');
|
||||
}
|
||||
|
||||
if (closureViolations.length > 0) {
|
||||
process.stderr.write('Profile closure violations (' + closureViolations.length + '):\n\n');
|
||||
for (const v of closureViolations) {
|
||||
process.stderr.write(' ' + v.message + '\n');
|
||||
process.stderr.write('\nERROR lint-skill-deps: ' + totalViolations + ' violation(s) found\n\n');
|
||||
|
||||
if (consistencyViolations.length > 0) {
|
||||
process.stderr.write('Frontmatter to body consistency violations (' + consistencyViolations.length + '):\n\n');
|
||||
for (const v of consistencyViolations) {
|
||||
process.stderr.write(' ' + v.filePath + '\n');
|
||||
process.stderr.write(' ' + v.message + '\n\n');
|
||||
}
|
||||
process.stderr.write('Fix: add missing deps to requires: in the skill frontmatter.\n\n');
|
||||
}
|
||||
process.stderr.write('\nFix: add the missing skills to the profile base set in install-profiles.cjs.\n\n');
|
||||
|
||||
if (closureViolations.length > 0) {
|
||||
process.stderr.write('Profile closure violations (' + closureViolations.length + '):\n\n');
|
||||
for (const v of closureViolations) {
|
||||
process.stderr.write(' ' + v.message + '\n');
|
||||
}
|
||||
process.stderr.write('\nFix: add the missing skills to the profile base set in install-profiles.cjs.\n\n');
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
runMain(main);
|
||||
|
||||
Reference in New Issue
Block a user