From 6196ec5f74faa0b783a1b3d75eadcd6cad5f651e Mon Sep 17 00:00:00 2001 From: memdmp Date: Mon, 24 Feb 2025 04:42:53 +0100 Subject: fix: split bundles, reproducible builds (hopefully) --- Makefile | 6 +++++- contrib/compress-worker.mjs | 13 ++++++++++++ contrib/ensure-reproducible-builds.sh | 29 ++++++++++++++++++++++++++ contrib/strip-srcmap.sh | 6 ++++++ manifest.json | 2 +- package.json | 4 +++- pnpm-lock.yaml | 9 ++++++++ src/routes/Monaco.svelte | 39 +++++++++++++++++++++-------------- src/routes/ts-worker.ts | 11 ++++++++++ svelte.config.js | 13 +++++++++--- vite.config.ts | 1 + 11 files changed, 112 insertions(+), 21 deletions(-) create mode 100755 contrib/compress-worker.mjs create mode 100755 contrib/ensure-reproducible-builds.sh create mode 100755 contrib/strip-srcmap.sh create mode 100644 src/routes/ts-worker.ts diff --git a/Makefile b/Makefile index acdb95e..f28fd57 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,8 @@ mozaddons: $(MAKE) deepclean $(MAKE) bootstrap pnpm i - $(MAKE) build + $(MAKE) build-reproducible + contrib/strip-srcmap.sh $(MAKE) pack clean: @@ -21,5 +22,8 @@ bootstrap: build: pnpm build +build-reproducible: + pnpm build-reproducible + pack: contrib/pack diff --git a/contrib/compress-worker.mjs b/contrib/compress-worker.mjs new file mode 100755 index 0000000..5c26694 --- /dev/null +++ b/contrib/compress-worker.mjs @@ -0,0 +1,13 @@ +#!/usr/bin/env node +import { readFileSync, writeFileSync } from 'node:fs'; +import { brotliCompressSync } from 'zlib'; + +writeFileSync( + 'static/generated/ts-worker.js.br', + brotliCompressSync( + readFileSync( + 'node_modules/monaco-editor/esm/vs/language/typescript/ts.worker.js' + ), + {} + ) +); diff --git a/contrib/ensure-reproducible-builds.sh b/contrib/ensure-reproducible-builds.sh new file mode 100755 index 0000000..f9b880a --- /dev/null +++ b/contrib/ensure-reproducible-builds.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env zsh +set -e +echo "First Build" +make mozaddons +# Zips are unstable with hashes +cd artifacts +ZIPNAME="$(jq -r '.name + "-" + .version + "-unsigned.zip"' ../manifest.json)" +unzip "$ZIPNAME" +rm "$ZIPNAME" +HASH1="$( (find . -type f -print0 | sort -z | xargs -0 sha512sum; + find . \( -type f -o -type d \) -print0 | sort -z | \ + xargs -0 stat -c '%n %a') \ + | sha512sum)" +cd .. +echo "Got Hash $HASH1" +sleep 1; +echo "Second Build" +make mozaddons +# Zips are unstable with hashes +cd artifacts +unzip "$ZIPNAME" +rm "$ZIPNAME" +HASH2="$( (find . -type f -print0 | sort -z | xargs -0 sha512sum; + find . \( -type f -o -type d \) -print0 | sort -z | \ + xargs -0 stat -c '%n %a') \ + | sha512sum)" +cd .. +echo "Got Hash $HASH2" +if [[ "$HASH1" != "$HASH2" ]]; then echo -e "\x1b[0;31mNot reproducible!\x1b[0m"; fi; \ No newline at end of file diff --git a/contrib/strip-srcmap.sh b/contrib/strip-srcmap.sh new file mode 100755 index 0000000..a87ab03 --- /dev/null +++ b/contrib/strip-srcmap.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env zsh +set -eax +# some source maps are >20MB, we can't keep that going. +for f in $(find build/uwu -name '*.js' -or -name '*.mjs'); do + grep -v sourceMappingURL= "$f" > /tmp/a && mv /tmp/a "$f" +done diff --git a/manifest.json b/manifest.json index 1c749a6..9a95478 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,5 @@ { - "description": "A minimal extension for manipulation of HTTP Requests and Responses; a fancy wrapper around browser.webRequest", + "description": "A minimal extension for manipulation of HTTP Requests and Responses; a fancy wrapper around browser.webRequest. Should be treated as a more restricted single-script userscript manager.", "manifest_version": 2, "name": "httptool", "version": "1.0", diff --git a/package.json b/package.json index 9a49872..d05594e 100644 --- a/package.json +++ b/package.json @@ -6,11 +6,12 @@ "scripts": { "dev": "concurrently -k --restart-tries -1 --restart-after 1000 \"vite build --mode development --watch\" \"vite build --mode development --watch --config vite.config.background.ts\" \"./do-webext-dev\"", "build": "concurrently --kill-others-on-fail \"vite build\" \"vite build --config vite.config.background.ts\"", + "build-reproducible": "REPRODUCIBLE=1 pnpm build", "preview": "web-ext run -p ff-ext --reload -f ./browser-launcher -s ./build", "prepare": "svelte-kit sync || echo ''", "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", - "install": "mkdir -p static/generated && cp node_modules/esbuild-wasm/esbuild.wasm static/generated/esbuild.wasm" + "install": "mkdir -p static/generated && cp node_modules/esbuild-wasm/esbuild.wasm static/generated/esbuild.wasm && contrib/compress-worker.mjs" }, "devDependencies": { "@sveltejs/adapter-static": "^3.0.8", @@ -39,6 +40,7 @@ ] }, "dependencies": { + "brotli-wasm": "3.0.1", "esbuild-wasm": "^0.25.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 5af7044..924d7b2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: dependencies: + brotli-wasm: + specifier: 3.0.1 + version: 3.0.1 esbuild-wasm: specifier: ^0.25.0 version: 0.25.0 @@ -851,6 +854,10 @@ packages: brace-expansion@1.1.11: resolution: {integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==} + brotli-wasm@3.0.1: + resolution: {integrity: sha512-U3K72/JAi3jITpdhZBqzSUq+DUY697tLxOuFXB+FpAE/Ug+5C3VZrv4uA674EUZHxNAuQ9wETXNqQkxZD6oL4A==} + engines: {node: '>=v18.0.0'} + browserslist@4.24.4: resolution: {integrity: sha512-KDi1Ny1gSePi1vm0q4oxSF8b4DR44GF4BbmS2YdhPLOEqd8pDviZOGH/GsmRwoWJ2+5Lr085X7naowMwKHDG1A==} engines: {node: ^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7} @@ -2981,6 +2988,8 @@ snapshots: balanced-match: 1.0.2 concat-map: 0.0.1 + brotli-wasm@3.0.1: {} + browserslist@4.24.4: dependencies: caniuse-lite: 1.0.30001700 diff --git a/src/routes/Monaco.svelte b/src/routes/Monaco.svelte index 409ab39..cfe9767 100644 --- a/src/routes/Monaco.svelte +++ b/src/routes/Monaco.svelte @@ -1,11 +1,11 @@