Skip to content

Commit 8417576

Browse files
sherwinskiclaude
andcommitted
chore(examples): make setup.sh work with bun fallback and ts resolution
The demo setup script assumed a vite-plus build that ships `vp pm pack`, `vp add`, and `vp remove`, but older globally-installed vite-plus only ships `vp install`, so `vp run android/ios` failed with "Command 'pm' not found". The SDK build also failed because vite-plus's global tsc helper couldn't resolve the SDK's typescript. - Add a package-manager shim that prefers `vp` and falls back to `bun` (the repo's pinned package manager) for pack/add/remove. - Export NODE_PATH=$SDK_ROOT/node_modules for `vp run build` so the bundler resolves the project's typescript. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent a986bb1 commit 8417576

1 file changed

Lines changed: 35 additions & 14 deletions

File tree

‎examples/setup.sh‎

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,36 +67,57 @@ if [ "${FORCE_SETUP:-0}" != "1" ] \
6767
exit 0
6868
fi
6969

70+
# --- Package-manager shim --------------------------------------------------
71+
# `vp` (vite-plus) is the intended toolchain and wraps bun under the hood, but
72+
# some installed vite-plus versions only ship `vp install` and lack the
73+
# `vp pm pack`, `vp add`, and `vp remove` subcommands this script needs. Probe
74+
# once and fall back to bun directly when they're unavailable. The repo pins
75+
# bun via package.json's "packageManager" field, so bun is a faithful
76+
# substitute and keeps bun.lock's integrity hashes in sync just as `vp` would.
77+
if vp pm pack --help >/dev/null 2>&1; then
78+
pm_pack() { vp pm pack; }
79+
pm_add() { vp add "$@"; }
80+
pm_remove() { vp remove "$@"; }
81+
else
82+
echo "vite-plus is missing 'vp pm'/'vp add'/'vp remove'; falling back to bun."
83+
pm_pack() { bun pm pack; }
84+
pm_add() { bun add "$@"; }
85+
pm_remove() { bun remove "$@"; }
86+
fi
87+
7088
cd "$SDK_ROOT"
71-
vp run build
89+
# NODE_PATH points the build at the SDK's own typescript. When vite-plus is
90+
# installed globally, its internal tsc helper resolves `require('typescript')`
91+
# from vite-plus's own node_modules and otherwise fails to find the compiler.
92+
NODE_PATH="$SDK_ROOT/node_modules" vp run build
7293

73-
# `vp pm pack` (wraps bun pm pack) honors package.json's "files" field
94+
# `pm_pack` (vp pm pack / bun pm pack) honors package.json's "files" field
7495
# (so the tarball matches what would actually be published). The version
7596
# suffix in the filename is unstable, so we normalize to
7697
# react-native-onesignal.tgz for a deterministic path that package.json +
7798
# the extract step can reference.
7899
rm -f react-native-onesignal*.tgz
79-
vp pm pack
100+
pm_pack
80101
mv react-native-onesignal-*.tgz react-native-onesignal.tgz
81102

82103
cd "$ORIGINAL_DIR"
83104

84-
# Always go through `vp add` (wraps bun) so bun.lock's integrity hash for
85-
# the tarball stays in sync with the freshly-built tarball on disk. A
105+
# Always go through the package manager (vp/bun) so bun.lock's integrity hash
106+
# for the tarball stays in sync with the freshly-built tarball on disk. A
86107
# previous version of this script had a "hot path" that just untarred
87108
# over node_modules directly, which was faster but left a stale sha512
88-
# in bun.lock — any subsequent `vp install` that re-resolved this entry
109+
# in bun.lock — any subsequent install that re-resolved this entry
89110
# (e.g. when the lockfile was touched by another dep) would fail with
90111
# IntegrityCheckFailed.
91112
#
92-
# `vp remove` first because bun verifies the existing integrity hash
93-
# before replacing the entry; without removing, a stale hash from a prior
94-
# build causes `vp add` itself to fail. The relative `file:../../...`
95-
# path is intentional — an absolute path would leak this machine's
96-
# layout into the lockfile.
97-
echo "Registering tarball with vp (refreshes bun.lock integrity hash)..."
98-
vp remove react-native-onesignal 2>/dev/null || true
99-
vp add file:../../react-native-onesignal.tgz
113+
# Remove first because bun verifies the existing integrity hash before
114+
# replacing the entry; without removing, a stale hash from a prior build
115+
# causes the add itself to fail. The relative `file:../../...` path is
116+
# intentional — an absolute path would leak this machine's layout into the
117+
# lockfile.
118+
echo "Registering tarball with the package manager (refreshes bun.lock integrity hash)..."
119+
pm_remove react-native-onesignal 2>/dev/null || true
120+
pm_add file:../../react-native-onesignal.tgz
100121

101122
# Record the hash only after a successful build/install so that an
102123
# interrupted run forces a full retry next time.

0 commit comments

Comments
 (0)