char/avril

(wip) why'd you have to go and make things so complicaaaaated?

git clone https://git.t4t.associates/char/avril

Charlotte Somrearrange libs into lib and extensions into extsf4a0f5b

main
1.9 KiB61 linesraw
1import { execFileSync } from "node:child_process";
2import { mkdtemp, readFile, rm } from "node:fs/promises";
3import { createRequire } from "node:module";
4import { tmpdir } from "node:os";
5import path from "node:path";
6import { pathToFileURL } from "node:url";
7
8const vendor = import.meta.dirname;
9const source = await mkdtemp(path.join(tmpdir(), "avril-webstreams-build-"));
10const commit = "12b4fedec6c01503a137d837204ca0b85992461e";
11const run = (command, args) =>
12  execFileSync(command, args, { cwd: source, stdio: "inherit" });
13const previousDirectory = process.cwd();
14
15try {
16  run("git", ["init", "-q"]);
17  run("git", [
18    "fetch",
19    "--depth=1",
20    "https://github.com/MattiasBuelens/web-streams-polyfill.git",
21    commit,
22  ]);
23  run("git", ["checkout", "--detach", "-q", "FETCH_HEAD"]);
24  run("git", ["apply", path.join(vendor, "avril.patch")]);
25  run("npm", [
26    "ci",
27    "--include=dev",
28    "--ignore-scripts",
29    "--no-audit",
30    "--no-fund",
31  ]);
32
33  process.chdir(source);
34  const { default: configs } = await import(
35    pathToFileURL(path.join(source, "rollup.config.mjs"))
36  );
37  const config = configs.find((config) =>
38    config.input === "src/polyfill.ts" &&
39    config.output[0].file === "dist/polyfill.js"
40  );
41  if (!config) throw new Error("Upstream polyfill build configuration changed");
42  const original = await readFile(path.join(vendor, "polyfill.js"), "utf8");
43  const banner = original.match(/^\/\*\*[\s\S]*?\*\//)?.[0];
44  if (!banner) throw new Error("Missing upstream license banner");
45
46  const { rollup } = createRequire(path.join(source, "package.json"))("rollup");
47  const { output, ...input } = config;
48  const bundle = await rollup(input);
49  try {
50    await bundle.write({
51      ...output[0],
52      banner,
53      file: path.join(vendor, "polyfill.avril.js"),
54    });
55  } finally {
56    await bundle.close();
57  }
58} finally {
59  process.chdir(previousDirectory);
60  await rm(source, { recursive: true, force: true });
61}