diff --git a/apps/server/src/cli/theme.test.ts b/apps/server/src/cli/theme.test.ts index d2e72dd7e1cc..7a503498efde 100644 --- a/apps/server/src/cli/theme.test.ts +++ b/apps/server/src/cli/theme.test.ts @@ -129,22 +129,33 @@ describe("t3 theme", () => { }), ); - it.effect("publishes a theme file under its filename and sets it", () => - Effect.gen(function* () { - const baseDir = makeBaseDir(); - const themeFile = NodePath.join(baseDir, "nightfall.json"); - NodeFS.writeFileSync(themeFile, NIGHTFALL_THEME_JSON); - - yield* runCli(["theme", "set", themeFile, "--base-dir", baseDir]); - - const published = NodePath.join(baseDir, "userdata", "themes", "nightfall.json"); - assert.equal(NodeFS.existsSync(published), true); - assert.equal(readSettings(baseDir).defaultTheme, "nightfall"); - const residue = NodeFS.readdirSync(NodePath.dirname(published)).filter( - (entry) => !entry.endsWith(".json"), - ); - assert.deepEqual(residue, []); - }), + it.effect.each([ + { extension: "json", relativePath: null }, + { extension: "JSON", relativePath: "nightfall.JSON" }, + ])( + "publishes a .$extension theme file under its filename and sets it", + ({ extension, relativePath }) => + Effect.gen(function* () { + const baseDir = makeBaseDir(); + const themeFile = NodePath.join(baseDir, `nightfall.${extension}`); + NodeFS.writeFileSync(themeFile, NIGHTFALL_THEME_JSON); + + yield* runCliIn(baseDir, [ + "theme", + "set", + relativePath ?? themeFile, + "--base-dir", + baseDir, + ]); + + const published = NodePath.join(baseDir, "userdata", "themes", "nightfall.json"); + assert.equal(NodeFS.readFileSync(published, "utf8"), NIGHTFALL_THEME_JSON); + assert.equal(readSettings(baseDir).defaultTheme, "nightfall"); + const residue = NodeFS.readdirSync(NodePath.dirname(published)).filter( + (entry) => !entry.endsWith(".json"), + ); + assert.deepEqual(residue, []); + }), ); it.effect("publishes the file named with a leading space, not its trimmed sibling", () => diff --git a/apps/server/src/cli/theme.ts b/apps/server/src/cli/theme.ts index ba9e89c17a2b..c6f0f97f8e17 100644 --- a/apps/server/src/cli/theme.ts +++ b/apps/server/src/cli/theme.ts @@ -40,6 +40,7 @@ const decodeThemeFileJsonExit = Schema.decodeUnknownExit( Schema.fromJsonString(EnvironmentThemeFile), ); const isEnvironmentThemeId = Schema.is(EnvironmentThemeId); +const THEME_JSON_SUFFIX = /\.json$/i; export class ThemeSettingsUnreadableError extends Schema.TaggedError()( "ThemeSettingsUnreadableError", @@ -311,7 +312,7 @@ const publishThemeFile = Effect.fn(function* (input: { return yield* new ThemeFileColorlessError({ filePath: input.filePath }); } - const fileBasename = path.basename(input.filePath, ".json"); + const fileBasename = path.basename(input.filePath).replace(THEME_JSON_SUFFIX, ""); const themeId = Option.getOrElse(input.explicitId, () => fileBasename); // Match watcher validation so published files will not be skipped. if (!isEnvironmentThemeId(themeId) || UNPUBLISHABLE_THEME_IDS.has(themeId)) { @@ -464,7 +465,7 @@ const themeSetCommand = Command.make("set", { // A bare theme id must not publish a same-named file that happens to exist in cwd. const looksLikePath = - target.endsWith(".json") || + THEME_JSON_SUFFIX.test(target) || target.includes("/") || target.includes("\\") || target.startsWith("~");