Skip to content

Commit 34dba94

Browse files
HexaFieldclaude
andcommitted
chore(scripts): port build-with-ad4m-link.sh from Flux
The companion Flux PR already uses scripts/build-with-ad4m-link.sh for the cross-repo build workflow — CI / reviewers set BRANCH (or rely on auto-detected CI env vars) and the script clones the matching ad4m branch, builds core + connect, rewrites pnpm.overrides to file:./ad4m/*, and rebuilds the consumer. This is the exact same script, adapted for WE: - GitHub PR resolution URL points at coasys/we (was coasys/flux). - Drops the ad4m-hooks helpers / react / vue build + override steps — WE only consumes @coasys/ad4m and @coasys/ad4m-connect. - find -name 'dist' walks apps/ and packages/ instead of views/ and packages/ (matches WE's layout). - Vite cache clear is scoped to the WE tree (excludes ./ad4m/* so we don't nuke the linked ad4m checkout's own cache). - Heap bump to --max-old-space-size=8192 (WE's build hits OOM at 4096 on this workspace; see daily memory note). Usage (mirrors Flux): BRANCH=feat/query-abort scripts/build-with-ad4m-link.sh Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent c6ce71d commit 34dba94

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

scripts/build-with-ad4m-link.sh

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Detect branch (Netlify sets BRANCH / HEAD; GitHub Actions uses GITHUB_HEAD_REF / GITHUB_REF)
5+
BRANCH="${BRANCH:-${HEAD:-${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}}}"
6+
7+
# For Netlify deploy previews, branch is set to "pull/N/head" instead of the actual branch name
8+
# Resolve the real branch name via the GitHub API
9+
if echo "$BRANCH" | grep -qE '^pull/[0-9]+/head$'; then
10+
PR_NUM=$(echo "$BRANCH" | sed 's|pull/\([0-9]*\)/head|\1|')
11+
echo "==> PR deploy preview detected (PR #$PR_NUM), resolving branch name..."
12+
REAL_BRANCH=$(curl -sf "https://api.github.com/repos/coasys/we/pulls/$PR_NUM" | python3 -c "import sys,json; print(json.load(sys.stdin)['head']['ref'])" 2>/dev/null || true)
13+
if [ -n "$REAL_BRANCH" ]; then
14+
BRANCH="$REAL_BRANCH"
15+
fi
16+
fi
17+
18+
echo "==> Detected branch: $BRANCH"
19+
20+
# Resolve which AD4M branch to clone: matching branch if available, otherwise dev.
21+
# Published @coasys/ad4m-* packages have broken workspace: refs and dev's package.json
22+
# pins @coasys/ad4m to link:../ad4m/core, so a local ad4m clone is always required.
23+
if git ls-remote --exit-code --heads \
24+
https://github.com/coasys/ad4m.git "$BRANCH" >/dev/null 2>&1; then
25+
AD4M_BRANCH="$BRANCH"
26+
echo "==> Found matching AD4M branch '$BRANCH'"
27+
else
28+
AD4M_BRANCH="dev"
29+
echo "==> No matching AD4M branch — falling back to 'dev'"
30+
fi
31+
32+
echo "==> Cloning AD4M branch '$AD4M_BRANCH'"
33+
rm -rf ad4m
34+
git clone --depth 1 --single-branch --branch "$AD4M_BRANCH" \
35+
https://github.com/coasys/ad4m.git ad4m
36+
37+
# Pin pnpm to v9 for AD4M build (ad4m uses object-format workspace overrides which pnpm v10 rejects)
38+
npm i -g pnpm@9.15.0 2>/dev/null || true
39+
40+
cd ad4m
41+
pnpm install --no-frozen-lockfile
42+
43+
echo "==> Building @coasys/ad4m (core)"
44+
cd core && pnpm exec tsc && pnpm run bundle && cd ..
45+
46+
echo "==> Building @coasys/ad4m-connect"
47+
cd connect && pnpm run build && cd ..
48+
49+
cd ..
50+
echo "==> AD4M packages built"
51+
52+
echo "==> Overriding @coasys packages with local builds"
53+
node -e "
54+
const pkg = require('./package.json');
55+
pkg.pnpm = pkg.pnpm || {};
56+
pkg.pnpm.overrides = pkg.pnpm.overrides || {};
57+
pkg.pnpm.overrides['@coasys/ad4m'] = 'file:./ad4m/core';
58+
pkg.pnpm.overrides['@coasys/ad4m-connect'] = 'file:./ad4m/connect';
59+
require('fs').writeFileSync('./package.json', JSON.stringify(pkg, null, 2) + '\n');
60+
"
61+
62+
pnpm install --no-frozen-lockfile
63+
64+
# Clear ALL build caches AND pre-built dist bundles so everything rebuilds with the linked SDK
65+
rm -rf .turbo node_modules/.cache
66+
find . -name '.turbo' -type d -not -path './ad4m/*' -not -path './node_modules/*' -exec rm -rf {} + 2>/dev/null || true
67+
find . -name '.vite' -type d -path '*/node_modules/.vite' -not -path './ad4m/*' -exec rm -rf {} + 2>/dev/null || true
68+
find packages -name 'dist' -type d -exec rm -rf {} + 2>/dev/null || true
69+
find apps -name 'dist' -type d -exec rm -rf {} + 2>/dev/null || true
70+
echo "==> All caches + dist directories cleared"
71+
72+
NODE_OPTIONS='--max-old-space-size=8192' pnpm build

0 commit comments

Comments
 (0)