Skip to content

Commit 3fa79a5

Browse files
only21milclaude
andauthored
fix(scripts): copy web brand icons to an absolute target directory (#23491)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 4524eee commit 3fa79a5

2 files changed

Lines changed: 65 additions & 5 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import * as NodeServices from "@effect/platform-node/NodeServices";
2+
import { assert, it } from "@effect/vitest";
3+
import * as Effect from "effect/Effect";
4+
import * as FileSystem from "effect/FileSystem";
5+
import * as Path from "effect/Path";
6+
7+
import { applyWebBrandAssets } from "./apply-web-brand-assets.ts";
8+
9+
const WEB_ICON_FILENAMES = [
10+
"apple-touch-icon.png",
11+
"favicon-16x16.png",
12+
"favicon-32x32.png",
13+
"favicon.ico",
14+
];
15+
16+
it.layer(NodeServices.layer)("apply-web-brand-assets", (it) => {
17+
it.effect("copies the icons into an absolute target directory as given", () =>
18+
Effect.gen(function* () {
19+
const fs = yield* FileSystem.FileSystem;
20+
const targetDirectory = yield* fs.makeTempDirectoryScoped({
21+
prefix: "apply-web-brand-assets-",
22+
});
23+
24+
yield* applyWebBrandAssets("production", targetDirectory);
25+
26+
assert.deepStrictEqual(
27+
(yield* fs.readDirectory(targetDirectory)).toSorted(),
28+
WEB_ICON_FILENAMES,
29+
);
30+
}),
31+
);
32+
33+
it.effect("resolves an empty target directory to the repo root", () =>
34+
Effect.gen(function* () {
35+
const fs = yield* FileSystem.FileSystem;
36+
const path = yield* Path.Path;
37+
const repoRoot = yield* path.fromFileUrl(new URL("..", import.meta.url));
38+
const destinations = WEB_ICON_FILENAMES.map((filename) => path.join(repoRoot, filename));
39+
// readDirectory does not follow symlinks, so a dangling link counts as an existing entry.
40+
// Names are lowercased so a case-insensitive filesystem cannot hide a differently cased file.
41+
const existingEntries = new Set(
42+
(yield* fs.readDirectory(repoRoot)).map((entry) => entry.toLowerCase()),
43+
);
44+
for (const destination of destinations) {
45+
assert.isFalse(
46+
existingEntries.has(path.basename(destination)),
47+
`${destination} already exists`,
48+
);
49+
}
50+
yield* Effect.addFinalizer(() =>
51+
Effect.forEach(destinations, (destination) => fs.remove(destination, { force: true })).pipe(
52+
Effect.orDie,
53+
),
54+
);
55+
56+
yield* applyWebBrandAssets("production", "");
57+
58+
for (const destination of destinations) {
59+
assert.isTrue(yield* fs.exists(destination));
60+
}
61+
}),
62+
);
63+
});

‎scripts/apply-web-brand-assets.ts‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,9 @@ export const applyWebBrandAssets = Effect.fn("applyWebBrandAssets")(function* (
2929
const repoRoot = yield* path.fromFileUrl(new URL("..", import.meta.url));
3030

3131
yield* Effect.forEach(
32-
resolveWebIconOverrides(brand, targetDirectory),
32+
resolveWebIconOverrides(brand, path.resolve(repoRoot, targetDirectory)),
3333
(override) =>
34-
fs.copyFile(
35-
path.join(repoRoot, override.sourceRelativePath),
36-
path.join(repoRoot, override.targetRelativePath),
37-
),
34+
fs.copyFile(path.join(repoRoot, override.sourceRelativePath), override.targetRelativePath),
3835
{ concurrency: "unbounded" },
3936
);
4037
});

0 commit comments

Comments
 (0)