MCPcopy Create free account
hub / github.com/delinoio/oss / validateBundle

Function validateBundle

apps/async-commit-hook/scripts/embed.mjs:11–54  ·  view source on GitHub ↗
(root = source)

Source from the content-addressed store, hash-verified

9 import.meta.url,
10);
11export async function validateBundle(root = source) {
12 const files = (
13 await readdir(root, { recursive: true, withFileTypes: true })
14 ).filter((entry) => !entry.isDirectory());
15 for (const entry of files)
16 assert.ok(entry.isFile(), "UI assets must be regular files");
17 const names = files
18 .map((entry) =>
19 relative(
20 fileURLToPath(root),
21 resolve(entry.parentPath, entry.name),
22 ).replaceAll("\\", "/"),
23 )
24 .sort();
25 assert.ok(names.includes("index.html"), "UI index is missing");
26 assert.ok(
27 names.some((name) => name.endsWith(".js")),
28 "UI JavaScript is missing",
29 );
30 assert.ok(
31 names.some((name) => name.endsWith(".css")),
32 "UI styles are missing",
33 );
34 for (const name of names)
35 assert.match(
36 name,
37 /^(index\.html|assets\/[A-Za-z0-9_.-]+\.[0-9a-f]{8}\.(js|css)(\.LICENSE\.txt)?)$/,
38 "unexpected UI asset",
39 );
40 const html = await readFile(new URL("index.html", root), "utf8");
41 assert.match(html, /<html lang="en">/);
42 assert.doesNotMatch(
43 html,
44 /<script(?![^>]*\bsrc=)|<style\b|\sstyle=|https?:\/\//i,
45 );
46 const references = [
47 ...html.matchAll(/(?:src|href)="\/?(assets\/[^"?]+)"/g),
48 ].map((match) => match[1]);
49 assert.ok(references.some((name) => name.endsWith(".js")));
50 assert.ok(references.some((name) => name.endsWith(".css")));
51 for (const name of references)
52 assert.ok(names.includes(name), "referenced UI asset is missing");
53 return names;
54}
55
56if (process.argv[1] === fileURLToPath(import.meta.url)) {
57 // Remove the previous embed first so any build/validation failure cannot leave

Callers 2

build.test.mjsFile · 0.90
embed.mjsFile · 0.85

Calls 3

includesMethod · 0.80
resolveFunction · 0.50
mapMethod · 0.45

Tested by

no test coverage detected