Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 27 additions & 16 deletions apps/server/src/cli/theme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () =>
Expand Down
5 changes: 3 additions & 2 deletions apps/server/src/cli/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>()(
"ThemeSettingsUnreadableError",
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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("~");
Expand Down
Loading