4.4 KiB
4.4 KiB
Frontend Asset Vendoring Playbook
This is the repeatable process used in GIA to self-host third-party frontend assets, pin versions, record provenance, and keep template SRI hashes maintainable.
Goals
- Avoid runtime CDN dependencies for core UI assets.
- Pin exact upstream versions and package integrity in source control.
- Record provenance, license, and SRI for each third-party asset.
- Keep a simple manifest-driven workflow that can be copied into other projects.
Files
tools/frontend_assets/package.json- Exact npm dependency pins for vendored frontend libraries.
tools/frontend_assets/package-lock.json- npm lockfile integrity and tarball resolution source of truth.
tools/frontend_assets/asset-manifest.json- Maps upstream package files and URL bundles into local
core/static/targets.
- Maps upstream package files and URL bundles into local
scripts/vendor_frontend_assets.py- Copies npm assets, downloads non-npm bundles, computes local SHA-256 and SRI SHA-512, and emits inventory reports.
artifacts/frontend_libraries.md- Human-readable inventory with versions, licenses, official URLs, tarballs, upstream integrity, and local SHA/SRI.
artifacts/frontend_libraries.json- Machine-readable inventory for template updates and audits.
Standard Workflow
- Add or update exact versions in
tools/frontend_assets/package.json. - Confirm each package is the official distribution, not a typosquat or community fork.
- Update
tools/frontend_assets/asset-manifest.jsonwith the exact files to vendor. - Run
npm install --ignore-scriptsintools/frontend_assets/. - Run
./genv/bin/python scripts/vendor_frontend_assets.py. - Copy the emitted
sri_sha512values into template tags incore/templates/base.html. - Restart the stack so
collectstaticrepublishes the new files. - Verify in the browser that assets load from local static URLs with no CDN fallbacks.
Provenance Rules
- Prefer official project docs or official extension listings before trusting npm search results.
- For Bulma extensions, treat
https://bulma.io/extensions/as the discovery source and verify the linked package/repo matches the npm package name. - Confirm npm metadata matches the expected project:
- homepage
- repository
- maintainers
- license
- publish recency
- Keep exact versions in
package.json; do not use ranges. - Use
package-lock.jsonas the immutable record of tarball URLs and upstream integrity. - If a library is not safely available from npm, vendor it from the official upstream URL as a
url_bundle. - Do not silently substitute a “free” or differently-scoped package if the templates rely on another asset family.
GIA Decisions
- Font Awesome:
- GIA templates use icon classes that are not safely replaceable with
@fortawesome/fontawesome-free. - The existing Font Awesome Pro
site-assetsv6.1.1 bundle is self-hosted undercore/static/vendor/fontawesome/instead.
- GIA templates use icon classes that are not safely replaceable with
- jQuery:
- Latest npm is 4.x, but GIA stays on
3.7.1to avoid breaking older plugins.
- Latest npm is 4.x, but GIA stays on
- Bulma extensions:
bulma-calendar,bulma-tagsinput,bulma-switch,bulma-slider, andbulma-tooltipwere matched against Bulma's official extensions page before pinning.bulma-calendarandbulma-tooltipare deprecated on npm, but Bulma still points to the Wikiki ecosystem for these extensions, so they were kept and documented instead of replaced ad hoc.
Theme Strategy
core/static/css/gia-theme.cssis now the project override layer instead of an inline<style>block inbase.html.- This is the low-friction step that works with the current stack immediately.
- If we want a true Bulma theme build later, add
sasstotools/frontend_assets, create agia-bulma.scssentrypoint that sets Bulma theme variables before importing Bulma, and vendor the compiled output through the same manifest process.
Commands
cd /code/xf/GIA/tools/frontend_assets
npm install --ignore-scripts
cd /code/xf/GIA
./genv/bin/python scripts/vendor_frontend_assets.py
bash ./scripts/quadlet/manage.sh restart
./genv/bin/python manage.py check
Verification Checklist
core/templates/base.htmlonly references local static URLs for vendored libraries.- Each included stylesheet/script in
base.htmlhas anintegrity="sha512-..."attribute. - Browser network panel shows local asset hits and no unexpected CDN requests.
artifacts/frontend_libraries.mdreflects the exact deployed asset set.