#!/usr/bin/env bash # # Clone upstream, patch, and build the single-file binary -> dist/httptoolkit # Requires: node (>=22), npm, bun, tar, git. # set -euo pipefail ROOT="$(cd "$(dirname "$0")/.." && pwd)" cd "$ROOT" export PUPPETEER_SKIP_DOWNLOAD=true export PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true echo "==> Cloning upstream sources" rm -rf httptoolkit-ui httptoolkit-server git clone --depth 1 https://github.com/httptoolkit/httptoolkit-ui.git git clone --depth 1 https://github.com/httptoolkit/httptoolkit-server.git echo "==> Applying patches + overlay" bash scripts/patch.sh echo "==> Building UI" ( cd httptoolkit-ui && npm ci && npm run build ) echo "==> Preparing server + embedding UI" # overrides/ is the interception support tree (terminal shims, JVM agent, frida, # webextension). Upstream reads it off disk at APP_ROOT/overrides, so it has to be # embedded too - the binary extracts both archives on startup. -p keeps the +x bits # on the shims in overrides/path. ( cd httptoolkit-server \ && npm ci \ && npm install --no-save tar@^7 \ && tar -czf ui.tar.gz -C ../httptoolkit-ui/dist . \ && tar -czpf overrides.tar.gz -C overrides . \ && rm -rf ui && cp -r ../httptoolkit-ui/dist ui ) echo "==> Patching installed deps for bun" bash scripts/patch-node-modules.sh echo "==> Compiling single-file binary -> dist/httptoolkit" mkdir -p dist ( cd httptoolkit-server && bun build ./htk-entry.ts --compile --outfile "$ROOT/dist/httptoolkit" ) echo "==> Done: dist/httptoolkit" ls -lh dist/httptoolkit