TypeScript
fix(scripts): copy web brand icons to an absolute target directory (#23491)
Victor Vogel3fa79a5c8381
diff --git a/scripts/apply-web-brand-assets.test.ts b/scripts/apply-web-brand-assets.test.tsnew file mode 100644index 00000000000..c3073879b20--- /dev/null+++ b/scripts/apply-web-brand-assets.test.ts@@ -0,0 +1,63 @@+import * as NodeServices from "@effect/platform-node/NodeServices";+import { assert, it } from "@effect/vitest";+import * as Effect from "effect/Effect";+import * as FileSystem from "effect/FileSystem";+import * as Path from "effect/Path";++import { applyWebBrandAssets } from "./apply-web-brand-assets.ts";++const WEB_ICON_FILENAMES = [+ "apple-touch-icon.png",+ "favicon-16x16.png",+ "favicon-32x32.png",+ "favicon.ico",+];++it.layer(NodeServices.layer)("apply-web-brand-assets", (it) => {+ it.effect("copies the icons into an absolute target directory as given", () =>+ Effect.gen(function* () {+ const fs = yield* FileSystem.FileSystem;+ const targetDirectory = yield* fs.makeTempDirectoryScoped({+ prefix: "apply-web-brand-assets-",+ });++ yield* applyWebBrandAssets("production", targetDirectory);++ assert.deepStrictEqual(+ (yield* fs.readDirectory(targetDirectory)).toSorted(),+ WEB_ICON_FILENAMES,+ );+ }),+ );++ it.effect("resolves an empty target directory to the repo root", () =>+ Effect.gen(function* () {+ const fs = yield* FileSystem.FileSystem;+ const path = yield* Path.Path;+ const repoRoot = yield* path.fromFileUrl(new URL("..", import.meta.url));+ const destinations = WEB_ICON_FILENAMES.map((filename) => path.join(repoRoot, filename));+ // readDirectory does not follow symlinks, so a dangling link counts as an existing entry.+ // Names are lowercased so a case-insensitive filesystem cannot hide a differently cased file.+ const existingEntries = new Set(+ (yield* fs.readDirectory(repoRoot)).map((entry) => entry.toLowerCase()),+ );+ for (const destination of destinations) {+ assert.isFalse(+ existingEntries.has(path.basename(destination)),+ `${destination} already exists`,+ );+ }+ yield* Effect.addFinalizer(() =>+ Effect.forEach(destinations, (destination) => fs.remove(destination, { force: true })).pipe(+ Effect.orDie,+ ),+ );++ yield* applyWebBrandAssets("production", "");++ for (const destination of destinations) {+ assert.isTrue(yield* fs.exists(destination));+ }+ }),+ );+});diff --git a/scripts/apply-web-brand-assets.ts b/scripts/apply-web-brand-assets.tsindex 90b4e39c104..a6941de8b43 100644--- a/scripts/apply-web-brand-assets.ts+++ b/scripts/apply-web-brand-assets.ts@@ -29,12 +29,9 @@ export const applyWebBrandAssets = Effect.fn("applyWebBrandAssets")(function* (const repoRoot = yield* path.fromFileUrl(new URL("..", import.meta.url));yield* Effect.forEach(- resolveWebIconOverrides(brand, targetDirectory),+ resolveWebIconOverrides(brand, path.resolve(repoRoot, targetDirectory)),(override) =>- fs.copyFile(- path.join(repoRoot, override.sourceRelativePath),- path.join(repoRoot, override.targetRelativePath),- ),+ fs.copyFile(path.join(repoRoot, override.sourceRelativePath), override.targetRelativePath),{ concurrency: "unbounded" },);});