Skip to content

Commit

Permalink
chore: update test app to use tarball plugin dependency (#187)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 authored Dec 20, 2024
1 parent 4872085 commit 82b7601
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: npm publish --dry-run

test-plugin:
name: Test unit tests for plguin
name: Test unit tests for plugin
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
.nvm
npm-debug.log
yarn-error.log
*.tgz

# OS X
.DS_Store
Expand Down
10 changes: 10 additions & 0 deletions local-development-readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ npx expo run:android
npx expo run:ios
```

### Plugin Dependency Installation

> Note: For Node.js 18 or newer, this typically runs automatically with `npm install`.
We use tarball dependency to ensure our expo plugin is installed as if it was published, avoiding path issues and ensuring dependencies are resolved consistently. If you face errors, run following command before running `npm install`:

```bash
npm run preinstall
```

## Convenience scripts

Sometimes when you are making changes to the plugin, it's helpful to clear out dependencies or rebuild the plugin. There are a couple of convenience scripts that you can use.
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ print_blue "\nInstalling root dependencies for plugin and tests...\n"
npm install

print_blue "\nInstalling test-app dependencies...\n"
(cd test-app && npm install)
(cd test-app && npm run preinstall && npm install)

print_blue "\nGenerating Android and iOS native projects...\n"
(cd test-app && npx npx expo prebuild)
Expand Down
45 changes: 45 additions & 0 deletions scripts/install-plugin-tarball.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash

# Script that generates a tarball for the npm package.
#
# Designed to be run before installing dependencies in the app.
#
# Use script: npm run install (in test-app)
# Ensures the tarball name is consistent to avoid unnecessary git diffs.

# Includes utils.sh script located in the same directory as this script
source "$(dirname "$0")/utils.sh"
set -e

# Define constants
PLUGIN_NAME="customerio-expo-plugin"
PLUGIN_PATH_RELATIVE=${1:-..} # Default plugin path to `..` if no argument is provided
TARBALL_NAME=$PLUGIN_NAME-latest.tgz
TARBALL_PATTERN=$PLUGIN_NAME-*.tgz
START_DIR=$(pwd) # Save the current directory (starting directory)

print_heading "Running install-plugin-tarball.sh script..."

print_blue "Starting in directory: '$START_DIR' with relative plugin path: '$PLUGIN_PATH_RELATIVE'"
print_blue "Generating tarball for expo plugin...\n"

# Navigate to root plugin directory
cd $PLUGIN_PATH_RELATIVE
# Remove any existing matching tarball to avoid conflicts
rm $TARBALL_PATTERN || true
# Generate the tarball using npm pack
# This creates a tarball named based on the `name` and `version` fields in the package.json
npm pack --silent
# Rename the tarball to a consistent name
mv $TARBALL_PATTERN $TARBALL_NAME
print_blue "\nTarball created successfully: '$TARBALL_NAME' at '$(pwd)'"

# Return to the starting directory
cd $START_DIR
print_blue "Returned to directory: '$(pwd)'"

print_blue "Uninstalling existing expo plugin and installing tarball dependency to ensure it is up-to-date..."
npm uninstall $PLUGIN_NAME --no-save
npm install "$PLUGIN_PATH_RELATIVE/$TARBALL_NAME" --silent

print_success "$TARBALL_NAME dependency installed successfully!"
1 change: 1 addition & 0 deletions scripts/setup-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ echo "Setting up the test project..."
cd test-app

echo "Installing dependencies..."
npm run preinstall
npm install

echo "Running expo prebuild..."
Expand Down
89 changes: 55 additions & 34 deletions test-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "1.0.0",
"main": "index.js",
"scripts": {
"install-plugin": "bash ../scripts/install-plugin-tarball.sh ..",
"preinstall": "npm run install-plugin",
"start": "expo start",
"android": "expo run:android",
"ios": "expo run:ios",
Expand All @@ -12,7 +14,7 @@
"@react-native-community/masked-view": "^0.1.11",
"@react-navigation/native": "^7.0.14",
"@react-navigation/stack": "^7.1.0",
"customerio-expo-plugin": "file:..",
"customerio-expo-plugin": "file:../customerio-expo-plugin-latest.tgz",
"customerio-reactnative": "^4.1.1",
"expo": "~52.0.11",
"expo-status-bar": "~2.0.0",
Expand Down

0 comments on commit 82b7601

Please sign in to comment.