Merge PR #5467: fix(cli): flush config JSON output before exit (@roboomp)

This commit is contained in:
can1357
2026-07-14 22:58:46 +02:00
3 changed files with 41 additions and 3 deletions
+15 -3
View File
@@ -241,7 +241,7 @@ export async function runConfigCommand(cmd: ConfigCommandArgs): Promise<void> {
switch (cmd.action) {
case "list":
handleList(cmd.flags);
await handleList(cmd.flags);
break;
case "get":
handleGet(cmd.key, cmd.flags);
@@ -261,7 +261,19 @@ export async function runConfigCommand(cmd: ConfigCommandArgs): Promise<void> {
}
}
function handleList(flags: { json?: boolean }): void {
async function writeStdout(text: string): Promise<void> {
const pending = Promise.withResolvers<void>();
process.stdout.write(text, error => {
if (error) {
pending.reject(error);
return;
}
pending.resolve();
});
await pending.promise;
}
async function handleList(flags: { json?: boolean }): Promise<void> {
const defs = ALL_SETTING_PATHS.map(path => findSettingDef(path)).filter((def): def is CliSettingDef => !!def);
if (flags.json) {
@@ -273,7 +285,7 @@ function handleList(flags: { json?: boolean }): void {
description: def.description,
};
}
console.log(JSON.stringify(result, null, 2));
await writeStdout(`${JSON.stringify(result, null, 2)}\n`);
return;
}