Setting the file. One moment.
Setup Viem 8130 · Vibenet · base/skills · Skills Docs
ContentsBack to the top of the page Raw file
scripts/ setup-viem-8130.sh
Shell · 93 lines · 4 KB
15 # viem/eip8168) and APIs are unchanged, so nothing else in your code moves.
16 #
17 # Usage:
18 # scripts/setup-viem-8130.sh [APP_DIR] [BUILD_DIR]
19 #
20 # APP_DIR project to install viem into (default: current directory)
21 # BUILD_DIR where to clone+build the fork (default: <APP_DIR>/.viem-8130-src;
22 # ~500 MB with node_modules — the script gitignores it in APP_DIR;
23 # share one BUILD_DIR outside the app when you have several apps)
24 #
25 # Env overrides:
26 # VIEM_FORK_REPO (default: https://github.com/chunter-cb/viem)
27 # VIEM_FORK_BRANCH (default: feat/eip-8130-production)
28 #
29 # Idempotent: re-running pulls the latest branch commit and rebuilds.
30
31 set -euo pipefail
32
33 APP_DIR = " ${1 :- $PWD } "
34 APP_DIR = "$( cd " $APP_DIR " && pwd )" # absolute
35 BUILD_DIR = " ${2 :- $APP_DIR / . viem-8130-src } "
36 REPO = "${ VIEM_FORK_REPO :- https :// github . com / chunter-cb / viem }"
37 BRANCH = "${ VIEM_FORK_BRANCH :- feat / eip-8130-production }"
38
39 echo "==> viem 8130 setup"
40 echo " app: $APP_DIR "
41 echo " build: $BUILD_DIR "
42 echo " source: $REPO @ $BRANCH "
43
44 command -v git > /dev/null || { echo "error: git not found" >&2 ; exit 1 ; }
45 command -v npx > /dev/null || { echo "error: npx (Node.js) not found" >&2 ; exit 1 ; }
46
47 # 1) Clone or update the fork branch.
48 if [ -d " $BUILD_DIR /.git" ]; then
49 echo "==> updating existing checkout"
50 git -C " $BUILD_DIR " fetch origin " $BRANCH " --depth 1
51 git -C " $BUILD_DIR " checkout " $BRANCH "
52 git -C " $BUILD_DIR " reset --hard "origin/ $BRANCH "
53 else
54 echo "==> cloning $BRANCH "
55 git clone -b " $BRANCH " --depth 1 " $REPO " " $BUILD_DIR "
56 fi
57
58 # 2) Build. --ignore-scripts skips the monorepo's postinstall hooks (which
59 # aren't needed to produce the package and can fail in a bare checkout).
60 # The build populates the package that lives in the repo's src/.
61 echo "==> installing build deps (pnpm, via npx — no global install)"
62 ( cd " $BUILD_DIR " && npx --yes pnpm install --ignore-scripts )
63 echo "==> building viem"
64 ( cd " $BUILD_DIR " && npx --yes pnpm run build )
65
66 # 2b) Git hygiene: the build dir is a ~500 MB monorepo checkout. If it lives
67 # inside the app, make sure the app's .gitignore excludes it (idempotent).
68 case " $BUILD_DIR " in
69 " $APP_DIR "/ * )
70 REL = "${ BUILD_DIR # " $APP_DIR " / }/"
71 if ! grep -qxF " $REL " " $APP_DIR /.gitignore" 2> /dev/null ; then
72 echo "==> adding $REL to $APP_DIR /.gitignore"
73 printf '\n# viem 8130 fork build (scripts/setup-viem-8130.sh)\n%s\n' " $REL " >> " $APP_DIR /.gitignore"
74 fi
75 ;;
76 esac
77
78 # 3) Link into the app. --install-links is REQUIRED: without it npm symlinks
79 # node_modules/viem to a path outside the project root, and bundlers
80 # (Turbopack/Next.js) then fail with "Can't resolve 'viem'" even though tsc
81 # resolves it fine — a confusing, wrong-looking bundler error.
82 echo "==> installing viem into the app (--install-links)"
83 ( cd " $APP_DIR " && npm install --install-links "viem@file: $BUILD_DIR /src" )
84
85 cat << EOF
86
87 ==> done.
88 Import 8130 helpers from 'viem/eip8130' and payer helpers from 'viem/eip8168'.
89 Core helpers (createPublicClient, parseEther, ...) come from plain 'viem'.
90
91 Set "target": "ES2020" (or later) in tsconfig.json — BigInt literals
92 (0n) fail with TS2737 on any lower target.
93 EOF