Honor XDG base directories for data and settings #4419
Closedcolonelpanic8(GitHub profile, opens in a new tab)wants to merge 3 commits into
main fromrefs/pull/4419/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -23,0 +24,21 @@24+export function resolveDefaultT3BaseDir(input: {25+ readonly platform: string;26+ readonly homeDirectory: string;27+ readonly xdgDataHome: string | undefined;28+ readonly path: {29+ readonly isAbsolute: (value: string) => boolean;30+ readonly join: (...paths: Array<string>) => string;31+ };32+}): string {33+ const xdgDataHome = input.xdgDataHome?.trim();34+ if (35+ input.platform !== "win32" &&36+ xdgDataHome !== undefined &&37+ xdgDataHome.length > 0 &&38+ input.path.isAbsolute(xdgDataHome)39+ ) {40+ return input.path.join(xdgDataHome, "t3code");41+ }42+43+ return input.path.join(input.homeDirectory, ".t3");44+}
colonelpanic8(GitHub profile, opens in a new tab) changed the title
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/cli/config.ts line 294OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -272,6 +276,19 @@272- );276+ const selectedBaseDir = resolveOptionPrecedence(277+ explicitBaseDir,278+ Option.fromUndefinedOr(bootstrap?.t3Home),279+ ).pipe(Option.filter((value) => value.trim().length > 0));280+ const baseDir = yield* resolveBaseDir(Option.getOrUndefined(selectedBaseDir), env.xdgDataHome);273281 const rawCwd = Option.getOrElse(normalizedFlags.cwd, () => process.cwd());274282 const cwd = path.resolve(yield* expandHomePath(rawCwd.trim()));275283 yield* fs.makeDirectory(cwd, { recursive: true });284+ const xdgConfigBaseDir = Option.isNone(selectedBaseDir)285+ ? yield* resolveXdgBaseDir(env.xdgConfigHome)286+ : undefined;287+ const configDir =288+ xdgConfigBaseDir === undefined289+ ? undefined290+ : devUrl === undefined291+ ? xdgConfigBaseDir292+ : path.join(xdgConfigBaseDir, "dev");276293 const derivedPaths = yield* ServerConfig.deriveServerPaths(baseDir, devUrl, {277- baseDirIsExplicit: Option.isSome(explicitBaseDir),294+ baseDirIsExplicit: Option.isSome(selectedBaseDir),
- apps/server/src/cli/config.ts lines 295 to 297Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -265,8 +276,16 @@265276 normalizedFlags.baseDir,266277 Option.fromUndefinedOr(env.t3Home),267278 ).pipe(Option.filter((value) => value.trim().length > 0));279+ const selectedBaseDir = resolveOptionPrecedence(280+ explicitBaseDir,281+ Option.fromUndefinedOr(bootstrap?.t3Home),282+ ).pipe(Option.filter((value) => value.trim().length > 0));283+ const homeDirectory = options?.homeDirectory ?? NodeOS.homedir();268284 const baseDir = yield* resolveBaseDir(269- Option.getOrUndefined(270- resolveOptionPrecedence(explicitBaseDir, Option.fromUndefinedOr(bootstrap?.t3Home)),271- ),285+ Option.getOrUndefined(selectedBaseDir),286+ env.xdgDataHome,287+ homeDirectory,272288 );289+ const bootstrapBaseDirIsExplicit =290+ bootstrap?.t3Home === undefined ? false : (bootstrap.t3HomeIsExplicit ?? true);291+ const baseDirIsExplicit = Option.isSome(explicitBaseDir) || bootstrapBaseDirIsExplicit;packages/shared/src/path.ts line 58Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -23,0 +38,21 @@38+ ) {39+ return input.path.join(xdgHome, "t3code");40+ }41+42+ return undefined;43+}44+45+export function resolveDefaultT3BaseDir(46+ input: Parameters<typeof resolveT3XdgBaseDir>[0] & {47+ readonly homeDirectory: string;48+ },49+): string {50+ return resolveT3XdgBaseDir(input) ?? input.path.join(input.homeDirectory, ".t3");51+}52+53+/**54+ * Preserve an existing legacy installation until the matching XDG directory55+ * has been initialized. This keeps upgrades non-destructive while still56+ * making XDG the default for new installations.57+ */58+export function selectT3XdgDirectory(input: {
- @@ -275,0 +308,21 @@308+ ? xdgConfigBaseDir309+ : path.join(xdgConfigBaseDir, "dev");310+ const legacyConfigDir = path.join(311+ homeDirectory,312+ ".t3",313+ devUrl === undefined || baseDirIsExplicit ? "userdata" : "dev",314+ );315+ const configDir = baseDirIsExplicit316+ ? undefined317+ : bootstrapConfigDir !== undefined318+ ? path.resolve(yield* expandHomePath(bootstrapConfigDir))319+ : selectT3XdgDirectory({320+ xdgDirectory: preferredConfigDir,321+ legacyDirectory: legacyConfigDir,322+ xdgDirectoryExists:323+ preferredConfigDir !== undefined &&324+ (yield* fs.exists(preferredConfigDir).pipe(Effect.orElseSucceed(() => false))),325+ legacyDirectoryExists: yield* fs326+ .exists(legacyConfigDir)327+ .pipe(Effect.orElseSucceed(() => false)),328+ });
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
aa299b02-4b49-44fa-9315-75ab3631545aYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share