Skip to content

Commit afed1d4

Browse files
committed
fix(demo): split SDK build and install stamps
1 parent ff45c06 commit afed1d4

4 files changed

Lines changed: 31 additions & 17 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ node_modules
55
dist/
66
coverage/
77
.capacitor-sdk-source.stamp
8+
.capacitor-sdk-installed.stamp
89
.cap-sync.stamp
910

1011
# macOS

examples/demo_pods/package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,16 @@
88
"build": "vp build",
99
"clean:android": "rm -rf android/app/build android/app/.cxx android/build",
1010
"clean:ios": "rm -rf ios/App/Pods ios/App/build",
11+
"dev": "vp dev --host --port 5173",
12+
"dev:android": "bash ../dev-android.sh",
13+
"dev:ios": "bash ../dev-ios.sh",
1114
"ios": "bash ../run-ios.sh",
12-
"preandroid": "bun run setup",
13-
"preios": "bun run setup",
14-
"setup": "../setup.sh"
15+
"preandroid": "vp run setup",
16+
"predev:android": "vp run setup",
17+
"predev:ios": "vp run setup",
18+
"preios": "vp run setup",
19+
"setup": "../setup.sh",
20+
"update:pods": "(cd ios/App && pod update OneSignalXCFramework --no-repo-update)"
1521
},
1622
"dependencies": {
1723
"@capacitor/android": "^8.3.0",
@@ -36,13 +42,7 @@
3642
"@types/react-router": "^5.1.20",
3743
"@types/react-router-dom": "^5.3.3",
3844
"@vitejs/plugin-react": "^6.0.1",
39-
"typescript": "^6.0.2",
40-
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
41-
"vite-plus": "0.1.17"
45+
"typescript": "^6.0.3"
4246
},
43-
"overrides": {
44-
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
45-
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
46-
},
47-
"packageManager": "bun@1.3.11"
47+
"packageManager": "bun@1.3.13"
4848
}

examples/demo_pods/src/hooks/useOneSignal.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ export function useOneSignal(): UseOneSignalReturn {
278278
setIsLoading(false);
279279
});
280280

281+
console.log('Loaded OneSignal');
281282
return () => {
283+
console.log('Cleaning up OneSignal listeners');
282284
OneSignal.InAppMessages.removeEventListener('willDisplay', handleIamWillDisplay);
283285
OneSignal.InAppMessages.removeEventListener('didDisplay', handleIamDidDisplay);
284286
OneSignal.InAppMessages.removeEventListener('willDismiss', handleIamWillDismiss);

examples/setup.sh

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,16 @@ SDK_ROOT=$(cd "$ORIGINAL_DIR/../.." && pwd)
88
info() { echo -e "\033[0;32m[setup]\033[0m $*"; }
99

1010
# ── Plugin tarball cache ─────────────────────────────────────────────────────
11-
# Skip rebuild/repack/`vp add` when plugin sources haven't changed.
12-
SDK_STAMP="$SDK_ROOT/.capacitor-sdk-source.stamp"
11+
# Two stamps: the SDK build is shared across demos (one tarball serves all),
12+
# but the `vp add` install is per-demo. Without the split, running setup in
13+
# `demo` first would leave the shared stamp at the new hash, and a follow-up
14+
# `demo_pods` setup would short-circuit the install and keep stale sources in
15+
# `demo_pods/node_modules/@onesignal/capacitor-plugin/` — which is what
16+
# CocoaPods path-references, so the native pod stays pre-fix.
17+
SDK_BUILD_STAMP="$SDK_ROOT/.capacitor-sdk-source.stamp"
18+
INSTALLED_STAMP="$ORIGINAL_DIR/.capacitor-sdk-installed.stamp"
1319
INSTALLED_DIR="$ORIGINAL_DIR/node_modules/@onesignal/capacitor-plugin"
20+
TARBALL="$SDK_ROOT/onesignal-capacitor-plugin.tgz"
1421

1522
SDK_SRC_HASH=$(find "$SDK_ROOT/src" "$SDK_ROOT/android" "$SDK_ROOT/ios" \
1623
"$SDK_ROOT/package.json" \
@@ -23,21 +30,25 @@ SDK_SRC_HASH=$(find "$SDK_ROOT/src" "$SDK_ROOT/android" "$SDK_ROOT/ios" \
2330
| shasum \
2431
| awk '{print $1}')
2532

26-
if [[ -d "$INSTALLED_DIR" ]] && [[ -f "$SDK_STAMP" ]] && [[ "$(cat "$SDK_STAMP")" == "$SDK_SRC_HASH" ]]; then
27-
info "Capacitor SDK source unchanged, skipping rebuild + repack"
33+
if [[ -f "$TARBALL" ]] && [[ -f "$SDK_BUILD_STAMP" ]] && [[ "$(cat "$SDK_BUILD_STAMP")" == "$SDK_SRC_HASH" ]]; then
34+
info "Capacitor SDK tarball is up-to-date, skipping rebuild + repack"
2835
else
2936
info "Building Capacitor plugin & packing tarball..."
3037
(cd "$SDK_ROOT" && vp run build)
3138
(cd "$SDK_ROOT" && rm -f onesignal-capacitor-plugin*.tgz && vp pm pack && mv onesignal-capacitor-plugin-*.tgz onesignal-capacitor-plugin.tgz)
39+
echo "$SDK_SRC_HASH" > "$SDK_BUILD_STAMP"
40+
fi
3241

42+
if [[ -d "$INSTALLED_DIR" ]] && [[ -f "$INSTALLED_STAMP" ]] && [[ "$(cat "$INSTALLED_STAMP")" == "$SDK_SRC_HASH" ]]; then
43+
info "Plugin already installed at current SDK hash, skipping vp add"
44+
else
3345
# Remove before add so bun.lock's integrity hash refreshes against the new
3446
# tarball; otherwise `vp add` hits a dependency-loop error under bun 1.3+.
3547
# Keep the relative `file:../../...` path to match package.json's spec.
3648
info "Registering tarball with vp (refreshes bun.lock integrity hash)..."
3749
vp remove @onesignal/capacitor-plugin 2>/dev/null || true
3850
vp add file:../../onesignal-capacitor-plugin.tgz
39-
40-
echo "$SDK_SRC_HASH" > "$SDK_STAMP"
51+
echo "$SDK_SRC_HASH" > "$INSTALLED_STAMP"
4152
fi
4253

4354
# ── Vite prebundle staleness check ───────────────────────────────────────────

0 commit comments

Comments
 (0)