fix(setup): honor config roots and display terminal dry-run plans
Normalize empty XDG config homes once for configuration writers and registration readers. Render the resolved plan for terminal dry runs while preserving structured output. Cover registration placement and a real PTY dry run, including absence of configuration writes.
This commit is contained in:
@@ -75,6 +75,10 @@ interface ClientDefinition {
|
||||
) => NonNullable<SetupClient["geminiSettings"]>;
|
||||
}
|
||||
|
||||
/** XDG treats an empty config-home value as unset. */
|
||||
const xdgConfigHome = ({ home, env }: ClientPathContext): string =>
|
||||
env.XDG_CONFIG_HOME || join(home, ".config");
|
||||
|
||||
const vscodeUserDirectory = ({
|
||||
home,
|
||||
platform,
|
||||
@@ -88,7 +92,7 @@ const vscodeUserDirectory = ({
|
||||
);
|
||||
if (platform === "darwin")
|
||||
return join(home, "Library", "Application Support", "Code", "User");
|
||||
return join(env.XDG_CONFIG_HOME ?? join(home, ".config"), "Code", "User");
|
||||
return join(xdgConfigHome({ home, platform, env }), "Code", "User");
|
||||
};
|
||||
|
||||
const traeUserDirectory = ({
|
||||
@@ -104,7 +108,7 @@ const traeUserDirectory = ({
|
||||
);
|
||||
if (platform === "darwin")
|
||||
return join(home, "Library", "Application Support", "Trae", "User");
|
||||
return join(env.XDG_CONFIG_HOME ?? join(home, ".config"), "Trae", "User");
|
||||
return join(xdgConfigHome({ home, platform, env }), "Trae", "User");
|
||||
};
|
||||
|
||||
const claudeDesktopDirectory = ({
|
||||
@@ -115,7 +119,7 @@ const claudeDesktopDirectory = ({
|
||||
if (platform === "win32")
|
||||
return join(env.APPDATA ?? join(home, "AppData", "Roaming"), "Claude");
|
||||
if (platform === "linux")
|
||||
return join(env.XDG_CONFIG_HOME ?? join(home, ".config"), "Claude");
|
||||
return join(xdgConfigHome({ home, platform, env }), "Claude");
|
||||
return join(home, "Library", "Application Support", "Claude");
|
||||
};
|
||||
|
||||
@@ -268,19 +272,13 @@ const openCodeOverrideDirectory = (
|
||||
|
||||
const opencodeDirectory = (context: ClientPathContext): string =>
|
||||
openCodeOverrideDirectory(context.env) ??
|
||||
join(
|
||||
context.env.XDG_CONFIG_HOME ?? join(context.home, ".config"),
|
||||
"opencode",
|
||||
);
|
||||
join(xdgConfigHome(context), "opencode");
|
||||
|
||||
/** OpenCode loads global JSON before JSONC, then explicit file and directory overrides. */
|
||||
const openCodeConfigurationPaths = (
|
||||
context: ClientPathContext,
|
||||
): readonly string[] => {
|
||||
const directory = join(
|
||||
context.env.XDG_CONFIG_HOME ?? join(context.home, ".config"),
|
||||
"opencode",
|
||||
);
|
||||
const directory = join(xdgConfigHome(context), "opencode");
|
||||
const overrideDirectory = openCodeOverrideDirectory(context.env);
|
||||
const paths = [
|
||||
join(directory, "config.json"),
|
||||
|
||||
@@ -82,6 +82,13 @@ export const renderSetupProgress = (event: SetupProgressEvent): void => {
|
||||
writeLine(`${symbol} ${event.label}${suffix}`);
|
||||
};
|
||||
|
||||
/** Show the resolved dry-run plan to a human at an interactive terminal. */
|
||||
export const renderSetupDryRun = (actions: readonly SetupAction[]): void => {
|
||||
intro("REA setup plan", promptStreams);
|
||||
renderPreflight(actions);
|
||||
outro("Dry run complete. No changes were made.", promptStreams);
|
||||
};
|
||||
|
||||
/** Finish an interactive setup journey without exposing the full doctor catalog. */
|
||||
export const renderInteractiveSetupResult = (
|
||||
result: SetupResult,
|
||||
|
||||
@@ -11,6 +11,7 @@ import { homeDirectoryFromEnvironment } from "../config/homeDirectory.js";
|
||||
import { isUpdateFailure } from "../application/UpdateFailure.js";
|
||||
import {
|
||||
confirmInteractiveSetup,
|
||||
renderSetupDryRun,
|
||||
renderInteractiveSetupResult,
|
||||
renderSetupProgress,
|
||||
} from "./interactiveSetup.js";
|
||||
@@ -225,6 +226,8 @@ const runSetupCommand = async (
|
||||
: undefined,
|
||||
);
|
||||
if (interactive) renderInteractiveSetupResult(result, environment);
|
||||
else if (options.dryRun && !input.formatExplicit && hasInteractiveTerminal())
|
||||
renderSetupDryRun(result.plannedActions);
|
||||
return result;
|
||||
};
|
||||
|
||||
@@ -282,6 +285,9 @@ const setupIsInteractive = (
|
||||
!options.yes &&
|
||||
!options.dryRun &&
|
||||
!formatExplicit &&
|
||||
hasInteractiveTerminal();
|
||||
|
||||
const hasInteractiveTerminal = (): boolean =>
|
||||
process.stdin.isTTY === true &&
|
||||
process.stdout.isTTY === true &&
|
||||
process.stderr.isTTY === true;
|
||||
|
||||
Reference in New Issue
Block a user