#!/usr/bin/env bash # The npm package, built and checked as an installer would meet it: # # bash wai/wai-quantum-js/ci/check.sh OUT_DIR # # 1. build.sh builds and packs it into OUT_DIR; # 2. the tarball, unpacked, holds the package's allow-list and nothing else; # 3. test/smoke.mjs runs against the unpacked package; # 4. the tarball is installed into an empty app (npm install , nothing else to # fetch), and test/install.mjs, the README's Node example, runs there by name. # Leaves the tarball in OUT_DIR, with OUT_DIR/.sha256. set -euo pipefail here=$(cd "$(dirname "$0")/.." && pwd) mkdir -p "$1" out=$(cd "$1" && pwd) bash "$here/build.sh" "$out" tgz=$(ls "$out"/*.tgz) work=$(mktemp -d) trap 'rm -rf "$work"' EXIT mkdir "$work/unpacked" tar -xzf "$tgz" -C "$work/unpacked" have=$(cd "$work/unpacked/package" && find . -type f | sed 's|^\./||' | sort) want=$(printf '%s\n' LICENSE README.md package.json wai_quantum.d.ts wai_quantum.js wai_quantum_bg.wasm wai_quantum_bg.wasm.d.ts | sort) if [ "$have" != "$want" ]; then echo "check.sh: the tarball holds other files than the package's allow-list:" >&2 diff <(echo "$want") <(echo "$have") >&2 || true exit 1 fi echo "the tarball: $(echo "$have" | wc -l | tr -d ' ') files, the allow-list exactly" node "$here/test/smoke.mjs" "$work/unpacked/package" mkdir "$work/app" printf '{ "name": "app", "private": true, "type": "module" }\n' > "$work/app/package.json" (cd "$work/app" && npm install "$tgz" --no-audit --no-fund --silent) cp "$here/test/install.mjs" "$work/app/" (cd "$work/app" && node install.mjs) (cd "$out" && n=$(basename "$tgz") && { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$n"; else shasum -a 256 "$n"; fi; } > "$n.sha256" && cat "$n.sha256")