mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-10-30 18:34:19 +00:00
# Conflicts: # .github/workflows/check-insights-major-version.yml # .github/workflows/check-posthog-major-version.yml # .github/workflows/ci-security.yaml # .github/workflows/validate-versioning.yml # AGENTS.md # AGENTS.md~upstream_main # packages/ai/src/otel/capture.ts # packages/ai/src/otel/mappers/aiSdk.ts # packages/ai/src/otel/mappers/index.ts # packages/ai/src/otel/types.ts # packages/core/src/__tests__/posthog.init.spec.ts # packages/react-native/src/PostHogProvider.tsx # packages/react/src/context/PostHogContext.ts # packages/react/src/context/PostHogProvider.tsx # tooling/eslint-plugin-insights/no-unsafe-web-global.js
148 lines
5.4 KiB
Bash
Executable File
148 lines
5.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# adapted from https://github.com/getsentry/sentry-react-native/blob/e76d0d388228437e82f235546de00f4e748fcbda/packages/core/scripts/sentry-xcode.sh
|
|
# Bundle React Native code and images
|
|
# PWD=ios
|
|
|
|
# print commands before executing them and stop on first error
|
|
set -x -e
|
|
|
|
# Ensure common tool paths are available so posthog-cli can auto-detect git
|
|
# (Xcode runs build phases with a minimal PATH)
|
|
export PATH="/usr/bin:/usr/local/bin:/opt/homebrew/bin:$HOME/.cargo/bin:$HOME/.local/bin:$HOME/.posthog:$PATH"
|
|
|
|
# WITH_ENVIRONMENT is executed by React Native
|
|
|
|
REACT_NATIVE_XCODE_DEFAULT="../node_modules/react-native/scripts/react-native-xcode.sh"
|
|
# Accept $1 only when it actually points at a shell script; guard against the
|
|
# Expo plugin previously passing "/bin/sh" as $1 (issue #3682).
|
|
if [[ "${1:-}" == *.sh ]]; then
|
|
REACT_NATIVE_XCODE="$1"
|
|
else
|
|
REACT_NATIVE_XCODE="$REACT_NATIVE_XCODE_DEFAULT"
|
|
fi
|
|
|
|
# Check if DERIVED_FILE_DIR exists, defined by Xcode
|
|
if [ ! -d "$DERIVED_FILE_DIR" ]; then
|
|
echo "error: DERIVED_FILE_DIR does not exist: $DERIVED_FILE_DIR"
|
|
exit 1
|
|
fi
|
|
|
|
# RN/users can define a BUNDLE_NAME, or fallback to main
|
|
SOURCEMAP_NAME="${BUNDLE_NAME:-main}.jsbundle.map"
|
|
|
|
[ -z "$SOURCEMAP_FILE" ] && export SOURCEMAP_FILE="$DERIVED_FILE_DIR/$SOURCEMAP_NAME"
|
|
|
|
# Check if CONFIGURATION_BUILD_DIR exists, defined by Xcode
|
|
if [ ! -d "$CONFIGURATION_BUILD_DIR" ]; then
|
|
echo "error: CONFIGURATION_BUILD_DIR does not exist: $CONFIGURATION_BUILD_DIR"
|
|
exit 1
|
|
fi
|
|
|
|
# Check for insights-cli using installer environment variables
|
|
# TODO: provide a config that users can force the location
|
|
# Xcode starts with a very limited $PATH so using whereis does not work
|
|
if [ -f "$HOME/.insights/insights-cli" ]; then
|
|
PH_CLI_PATH="$HOME/.insights/insights-cli"
|
|
else
|
|
# Check if installed via npm -g @hanzo/cli
|
|
NPM_GLOBAL_PREFIX=$(npm prefix -g 2>/dev/null)
|
|
if [ -n "$NPM_GLOBAL_PREFIX" ] && [ -f "$NPM_GLOBAL_PREFIX/bin/insights-cli" ]; then
|
|
PH_CLI_PATH="$NPM_GLOBAL_PREFIX/bin/insights-cli"
|
|
else
|
|
# Check if installed as local dependency
|
|
NPM_LOCAL_ROOT=$(npm root 2>/dev/null)
|
|
if [ -n "$NPM_LOCAL_ROOT" ] && [ -f "$NPM_LOCAL_ROOT/.bin/insights-cli" ]; then
|
|
PH_CLI_PATH="$NPM_LOCAL_ROOT/.bin/insights-cli"
|
|
else
|
|
# Fallback to searching common locations
|
|
export PATH="/usr/local/bin:/opt/homebrew/bin:$HOME/.cargo/bin:$HOME/.local/bin:$HOME/.insights:$PATH"
|
|
PH_CLI_PATH=$(command -v insights-cli 2>/dev/null)
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
if [ -z "$PH_CLI_PATH" ] || [ ! -x "$PH_CLI_PATH" ]; then
|
|
echo "error: insights-cli not found"
|
|
exit 1
|
|
fi
|
|
|
|
MIN_POSTHOG_CLI_VERSION="0.7.8"
|
|
PH_CLI_VERSION=$("$PH_CLI_PATH" --version 2>/dev/null | awk '{print $NF}' | tr -d 'v')
|
|
if [ -n "$PH_CLI_VERSION" ]; then
|
|
LOWEST=$(printf '%s\n%s\n' "$MIN_POSTHOG_CLI_VERSION" "$PH_CLI_VERSION" | sort -t. -k1,1n -k2,2n -k3,3n | head -n1)
|
|
if [ "$LOWEST" != "$MIN_POSTHOG_CLI_VERSION" ]; then
|
|
echo "error: posthog-cli >= ${MIN_POSTHOG_CLI_VERSION} required (found ${PH_CLI_VERSION}). Upgrade: npm install -g @posthog/cli@latest"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# mimics how the file is defined in node_modules/react-native/scripts/react-native-xcode.sh (PACKAGER_SOURCEMAP_FILE)
|
|
SOURCEMAP_PACKAGER_FILE="$CONFIGURATION_BUILD_DIR/$SOURCEMAP_NAME"
|
|
|
|
# Pass release info from Xcode build settings when available
|
|
CLI_RELEASE_ARGS=""
|
|
if [ -n "${PRODUCT_BUNDLE_IDENTIFIER}" ]; then
|
|
CLI_RELEASE_ARGS="$CLI_RELEASE_ARGS --release-name $PRODUCT_BUNDLE_IDENTIFIER"
|
|
fi
|
|
if [ -n "${MARKETING_VERSION}" ]; then
|
|
CLI_RELEASE_ARGS="$CLI_RELEASE_ARGS --release-version $MARKETING_VERSION"
|
|
fi
|
|
if [ -n "${CURRENT_PROJECT_VERSION}" ]; then
|
|
CLI_RELEASE_ARGS="$CLI_RELEASE_ARGS --build $CURRENT_PROJECT_VERSION"
|
|
fi
|
|
|
|
# RN deletes the PACKAGER_SOURCEMAP_FILE file after execution but we need it
|
|
# lets patch the script to comment out this part if not yet
|
|
if grep -q '^[[:space:]]*rm.*PACKAGER_SOURCEMAP_FILE' "$REACT_NATIVE_XCODE"; then
|
|
echo "Patching React Native script to preserve sourcemap file..."
|
|
sed -i '' 's/^[[:space:]]*rm.*PACKAGER_SOURCEMAP_FILE/#&/' "$REACT_NATIVE_XCODE"
|
|
echo "Patched: commented out rm PACKAGER_SOURCEMAP_FILE line"
|
|
fi
|
|
|
|
# Execute React Native Xcode script and check exit code
|
|
set +x +e # disable printing commands and allow continuing on error
|
|
RN_XCODE_OUTPUT=$(/bin/sh -c "$REACT_NATIVE_XCODE" 2>&1)
|
|
RN_XCODE_EXIT_CODE=$?
|
|
if [ $RN_XCODE_EXIT_CODE -eq 0 ]; then
|
|
echo "$RN_XCODE_OUTPUT" | awk '{print "output: react-native-xcode - " $0}'
|
|
else
|
|
echo "error: react-native-xcode - $RN_XCODE_OUTPUT"
|
|
exit $RN_XCODE_EXIT_CODE
|
|
fi
|
|
set -x -e # re-enable
|
|
|
|
# files wont exist if skip bundling
|
|
set +x +e
|
|
if [[ "$SKIP_BUNDLING" ]]; then
|
|
echo "SKIP_BUNDLING enabled; skipping insights-cli upload calls."
|
|
exit 0;
|
|
fi
|
|
set -x -e
|
|
|
|
# Execute insights cli clone
|
|
set +x +e
|
|
CLI_CLONE_OUTPUT=$(/bin/sh -c "$PH_CLI_PATH hermes clone --minified-map-path $SOURCEMAP_PACKAGER_FILE --composed-map-path $SOURCEMAP_FILE $CLI_RELEASE_ARGS" 2>&1)
|
|
CLONE_EXIT_CODE=$?
|
|
if [ $CLONE_EXIT_CODE -eq 0 ]; then
|
|
echo "$CLI_CLONE_OUTPUT" | awk '{print "output: insights-cli - " $0}'
|
|
else
|
|
echo "error: insights-cli - $CLI_CLONE_OUTPUT"
|
|
exit $CLONE_EXIT_CODE
|
|
fi
|
|
set -x -e
|
|
|
|
# Execute insights cli upload
|
|
set +x +e
|
|
CLI_UPLOAD_OUTPUT=$(/bin/sh -c "$PH_CLI_PATH hermes upload --directory $DERIVED_FILE_DIR $CLI_RELEASE_ARGS" 2>&1)
|
|
UPLOAD_EXIT_CODE=$?
|
|
if [ $UPLOAD_EXIT_CODE -eq 0 ]; then
|
|
echo "$CLI_UPLOAD_OUTPUT" | awk '{print "output: insights-cli - " $0}'
|
|
else
|
|
echo "error: insights-cli - $CLI_UPLOAD_OUTPUT"
|
|
exit $UPLOAD_EXIT_CODE
|
|
fi
|
|
set -x -e
|
|
|
|
|
|
exit 0
|