Move Vite build-file copying into scripts

Keep the Node.js build helper and its tests in the build-script directory
recognised by Community review. Update the Vite import and unit CI path
filters while preserving the copy behaviour and release artefacts.
This commit is contained in:
vorotamoroz committed 2026-10-26 15:46:55 +00:00
1 parent b449dfd2bb
commit e83aa892b4
4 files changed
+3 -1

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
import { access, copyFile, mkdir } from "node:fs/promises";
import { join } from "node:path";
import type { Plugin } from "vite";
const BUILD_FILES = ["manifest.json", "main.js", "styles.css"] as const;
function hasErrorCode(error: unknown, code: string): boolean {
return typeof error === "object" && error !== null && "code" in error && error.code === code;
}
export function copyBuildFiles(destinations: readonly string[], sourceDirectory = process.cwd()): Plugin {
return {
name: "copy-build-files",
async writeBundle() {
let copied = false;
for (const destination of destinations) {
let destinationCreated = false;
for (const file of BUILD_FILES) {
const source = join(sourceDirectory, file);
try {
await access(source);
} catch (error) {
if (hasErrorCode(error, "ENOENT")) continue;
throw error;
}
if (!destinationCreated) {
await mkdir(destination, { recursive: true });
destinationCreated = true;
}
const target = join(destination, file);
await copyFile(source, target);
if (!copied) console.log("copied:");
copied = true;
console.log(` ${source} → ${target}`);
}
}
if (!copied) console.log("no items to copy");
},
};
}