vomebook commited on
Commit ·
2b6b673
1
Parent(s): 6e49c9e
Compile the static asset inventory with one pinned CLI session
Browse files- Dockerfile +2 -4
- scripts/build/compile_static_assets.mjs +21 -0
- tests/gates/test_static_contract.py +12 -4
Dockerfile
CHANGED
|
@@ -138,16 +138,14 @@ COPY scripts/build/build_static_assets.mjs /build/build_static_assets.mjs
|
|
| 138 |
COPY scripts/build/copy_reader_vendor.mjs /build/copy_reader_vendor.mjs
|
| 139 |
COPY scripts/build/check_reader_release.mjs /build/check_reader_release.mjs
|
| 140 |
COPY scripts/build/compose_app.mjs /build/compose_app.mjs
|
|
|
|
| 141 |
|
| 142 |
RUN mkdir -p /out \
|
| 143 |
&& cp -a static/. /out/ \
|
| 144 |
&& node /build/copy_reader_vendor.mjs /out/vendor \
|
| 145 |
&& node /build/compose_app.mjs > /build/app-composed.js \
|
| 146 |
&& esbuild /build/app-composed.js --minify --target=es2020 --charset=utf8 --legal-comments=none --outfile=/out/app.js \
|
| 147 |
-
&&
|
| 148 |
-
flags=$(node -e 'console.log(require("./static/reader-resources.js").bundleArguments(process.argv[1]).join(" "))' "$file"); \
|
| 149 |
-
esbuild "static/$file" $flags --minify --target=es2020 --charset=utf8 --legal-comments=none --outfile="/out/$file" || exit 1; \
|
| 150 |
-
done \
|
| 151 |
&& node /build/build_static_assets.mjs \
|
| 152 |
&& esbuild /out/sw.js --minify --target=es2019 --charset=utf8 --legal-comments=none --outfile=/out/sw.min.js \
|
| 153 |
&& mv /out/sw.min.js /out/sw.js
|
|
|
|
| 138 |
COPY scripts/build/copy_reader_vendor.mjs /build/copy_reader_vendor.mjs
|
| 139 |
COPY scripts/build/check_reader_release.mjs /build/check_reader_release.mjs
|
| 140 |
COPY scripts/build/compose_app.mjs /build/compose_app.mjs
|
| 141 |
+
COPY scripts/build/compile_static_assets.mjs /build/compile_static_assets.mjs
|
| 142 |
|
| 143 |
RUN mkdir -p /out \
|
| 144 |
&& cp -a static/. /out/ \
|
| 145 |
&& node /build/copy_reader_vendor.mjs /out/vendor \
|
| 146 |
&& node /build/compose_app.mjs > /build/app-composed.js \
|
| 147 |
&& esbuild /build/app-composed.js --minify --target=es2020 --charset=utf8 --legal-comments=none --outfile=/out/app.js \
|
| 148 |
+
&& node /build/compile_static_assets.mjs hf /build /out esbuild \
|
|
|
|
|
|
|
|
|
|
| 149 |
&& node /build/build_static_assets.mjs \
|
| 150 |
&& esbuild /out/sw.js --minify --target=es2019 --charset=utf8 --legal-comments=none --outfile=/out/sw.min.js \
|
| 151 |
&& mv /out/sw.min.js /out/sw.js
|
scripts/build/compile_static_assets.mjs
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import { spawnSync } from "node:child_process";
|
| 2 |
+
import { createRequire } from "node:module";
|
| 3 |
+
import { resolve } from "node:path";
|
| 4 |
+
|
| 5 |
+
const [project, cwd, outdir, esbuild] = process.argv.slice(2);
|
| 6 |
+
if (!["github", "hf"].includes(project) || !cwd || !outdir || !esbuild) {
|
| 7 |
+
throw new Error("Usage: compile_static_assets.mjs <github|hf> <cwd> <outdir> <esbuild>");
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
// Resolve against the source checkout, not the location of this driver.
|
| 11 |
+
const resources = createRequire(import.meta.url)(resolve(cwd, "static/reader-resources.js"));
|
| 12 |
+
for (const file of resources.buildFiles(project)) {
|
| 13 |
+
if (file === "app.js") continue; // The caller builds the composed app separately.
|
| 14 |
+
const result = spawnSync(esbuild, [
|
| 15 |
+
`static/${file}`, ...resources.bundleArguments(file),
|
| 16 |
+
"--minify", "--target=es2020", "--charset=utf8", "--legal-comments=none",
|
| 17 |
+
`--outfile=${outdir}/${file}`,
|
| 18 |
+
], { cwd, stdio: "inherit" });
|
| 19 |
+
if (result.error) throw result.error;
|
| 20 |
+
if (result.status !== 0) process.exit(result.status ?? 1);
|
| 21 |
+
}
|
tests/gates/test_static_contract.py
CHANGED
|
@@ -763,10 +763,18 @@ console.log('Chapter adapter contract passed; 5 negative controls rejected');
|
|
| 763 |
self.assertIn("ARG ESBUILD_VERSION=0.28.2", dockerfile)
|
| 764 |
self.assertIn("node /build/compose_app.mjs > /build/app-composed.js", dockerfile)
|
| 765 |
self.assertIn("esbuild /build/app-composed.js --minify --target=es2020 --charset=utf8 --legal-comments=none", dockerfile)
|
| 766 |
-
|
| 767 |
-
self.assertIn(
|
| 768 |
-
self.assertIn('.
|
| 769 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 770 |
self.assertIn("node /build/copy_reader_vendor.mjs /out/vendor", dockerfile)
|
| 771 |
self.assertIn("esbuild /out/sw.js --minify --target=es2019 --charset=utf8 --legal-comments=none", dockerfile)
|
| 772 |
self.assertIn("COPY --from=static-assets /out/ static/", dockerfile)
|
|
|
|
| 763 |
self.assertIn("ARG ESBUILD_VERSION=0.28.2", dockerfile)
|
| 764 |
self.assertIn("node /build/compose_app.mjs > /build/app-composed.js", dockerfile)
|
| 765 |
self.assertIn("esbuild /build/app-composed.js --minify --target=es2020 --charset=utf8 --legal-comments=none", dockerfile)
|
| 766 |
+
assets = dockerfile.split(" AS static-assets\n", 1)[1].split("\nFROM ", 1)[0]
|
| 767 |
+
self.assertIn("COPY scripts/build/compile_static_assets.mjs /build/compile_static_assets.mjs\n", assets)
|
| 768 |
+
self.assertIn('\n'.join((
|
| 769 |
+
" && esbuild /build/app-composed.js --minify --target=es2020 --charset=utf8 --legal-comments=none --outfile=/out/app.js \\",
|
| 770 |
+
" && node /build/compile_static_assets.mjs hf /build /out esbuild \\",
|
| 771 |
+
" && node /build/build_static_assets.mjs \\",
|
| 772 |
+
)), assets)
|
| 773 |
+
self.assertNotIn("for file in", assets)
|
| 774 |
+
compiler = (ROOT / "scripts/build/compile_static_assets.mjs").read_text(encoding="utf-8")
|
| 775 |
+
self.assertIn('resolve(cwd, "static/reader-resources.js")', compiler)
|
| 776 |
+
self.assertIn("resources.buildFiles(project)", compiler)
|
| 777 |
+
self.assertIn("...resources.bundleArguments(file)", compiler)
|
| 778 |
self.assertIn("node /build/copy_reader_vendor.mjs /out/vendor", dockerfile)
|
| 779 |
self.assertIn("esbuild /out/sw.js --minify --target=es2019 --charset=utf8 --legal-comments=none", dockerfile)
|
| 780 |
self.assertIn("COPY --from=static-assets /out/ static/", dockerfile)
|