chrome/vendor-webawesome.sh
Michał Kopeć f6c8fe3d36 chrome: the shared shell, extracted from four copies
One page frame, one palette, one set of components, one implementation of
config readers, proxy auth, /healthz, i18n and cache-busted asset URLs.

The design tokens had been copied into homepage, marketplace, agent-bridge
and scribe and had started to drift; so had theme.js and the asset() helper,
which existed in two incompatible versions. board.css carried the instruction
"Copy the values from homepage's style.css when they change there", which is
the problem stated as a procedure.

Components come from Web Awesome 3.14.0 (MIT), vendored under static/wa by
vendor-webawesome.sh - curl and tar against the npm registry, so there is no
node_modules, no lockfile and nothing for CI or a Containerfile to run. The
script prunes type definitions and IDE metadata, 13M down to 3.4M, and keeps
only the en and pl translations. Components style themselves inside a shadow
root, so a page rule cannot reach into one: "this input is the wrong width"
stops being a thing that can happen rather than a thing to be careful about.

Two decisions worth recording here:

- Asset versioning is a content digest over the whole static tree, not each
  file's mtime. mtime is wrong in a container, where every COPY'd file
  carries the build timestamp, so every asset appeared to change on every
  build. A single tree-wide token also means a cached page can never pair
  itself with a newer script.
- Pages keep the data-theme="light|dark|system" attribute the services have
  always used. Web Awesome drives light/dark from a wa-light/wa-dark class
  instead; base.html and theme.js own that mapping so nothing else learns it.

The compatibility aliases in tokens.css (--bg, --surface, --accent, ...) are
deliberate: they let a service move page by page instead of all at once.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-10-04 12:34:13 +02:00

46 lines
2 KiB
Bash
Executable file

#!/usr/bin/env bash
# Re-vendor Web Awesome into chrome/static/wa/.
#
# Deliberately a curl + tar of the npm registry tarball, not `npm install`:
# no node_modules, no lockfile, no package.json anywhere in this repo, and
# nothing for a Containerfile or a CI job to run. The only tool needed is
# curl. A vendoring step that requires a toolchain is a vendoring step that
# gets skipped, and skipping it is how four copies of a stylesheet drift.
#
# ./vendor-webawesome.sh # the pinned version below
# ./vendor-webawesome.sh 3.15.0 # upgrade; commit the diff
set -euo pipefail
VERSION="${1:-3.14.0}"
HERE="$(cd "$(dirname "$0")" && pwd)"
DEST="$HERE/chrome/static/wa"
TMP="$(mktemp -d)"
trap 'rm -rf "$TMP"' EXIT
echo "fetching @awesome.me/webawesome@$VERSION"
curl -sfL --max-time 300 \
"https://registry.npmjs.org/@awesome.me/webawesome/-/webawesome-$VERSION.tgz" \
-o "$TMP/wa.tgz"
tar xzf "$TMP/wa.tgz" -C "$TMP"
# dist-cdn, not dist: its modules are self-contained and resolve each other
# by relative path, so a browser can load them straight from /static/wa with
# no import map and no bundler. `dist` uses bare specifiers and cannot.
rm -rf "$DEST"
mkdir -p "$DEST"
cp -r "$TMP/package/dist-cdn/." "$DEST/"
cp "$TMP/package/LICENSE.md" "$DEST/LICENSE.md"
# Prune what only a build toolchain or an IDE would read. ~13M -> ~4M, which
# is the difference between a reasonable git history and an unreasonable one.
find "$DEST" -name '*.d.ts' -delete
rm -rf "$DEST/types" "$DEST/react" "$DEST/ssr" "$DEST/skills"
rm -f "$DEST/custom-elements.json" "$DEST/web-types.json" \
"$DEST/vscode.html-custom-data.json" "$DEST/custom-elements-jsx.d.ts" \
"$DEST/webawesome.ssr-loader.js" "$DEST/llms.txt"
# Only the locales chrome's i18n actually offers (see chrome/i18n.py).
find "$DEST/translations" -name '*.js' ! -name 'en.js' ! -name 'pl.js' -delete
echo "$VERSION" > "$DEST/VERSION"
echo "vendored Web Awesome $VERSION -> $DEST ($(du -sh "$DEST" | cut -f1))"