Skip to content

Latest commit

 

History

History
307 lines (220 loc) · 13.5 KB

File metadata and controls

307 lines (220 loc) · 13.5 KB

Contributing

Contributions are always welcome, no matter how large or small!

We want this community to be friendly and respectful to each other. Please follow it in all your interactions with the project. Before contributing, please read the code of conduct.

Development workflow

This project is a monorepo managed using Yarn workspaces. It contains the following packages:

  • The library package in the root directory.
  • An example app in the example/ directory.
  • A separate React Native macOS example workspace in examples/macos/.
  • A separate React Native Windows example workspace in examples/windows/.

To get started with the project, make sure you have the correct version of Node.js installed. See the .nvmrc file for the version used in this project.

Run yarn in the root directory to install the required dependencies for each package:

yarn

Since the project relies on Yarn workspaces, you cannot use npm for development without manually migrating.

Submodules and Zig prebuilts

This repository vendors xxHash, BLAKE3, and zig-files-hash via git submodules. After cloning, run:

git submodule update --init --recursive

If you are changing Zig engine integration and need to refresh Zig prebuilts:

./scripts/build-zig-android.sh
./scripts/build-zig-ios.sh
./scripts/build-zig-macos.sh
./scripts/build-zig-windows.sh

Prebuilt output locations:

  • third_party/zig-files-hash-prebuilt/android/<ABI>/libzig_files_hash.a
  • third_party/zig-files-hash-prebuilt/ios/ZigFilesHash.xcframework
  • third_party/zig-files-hash-prebuilt/macos/ZigFilesHash.xcframework
  • third_party/zig-files-hash-prebuilt/windows/<Platform>/zig_files_hash.lib

The bundled Zig core is zig-files-hash v0.0.6 with C ABI v3 (ZFH_API_VERSION = 3). Custom source/prebuilt builds must use a compatible Zig C ABI.

Release builds on physical devices (native vs zig)

Use these commands for manual smoke/performance verification in Release mode. Replace "<IOS_DEVICE_NAME>" with your actual iPhone device name.

# 1) Android / native / Release / physical device
(cd example/android && ./gradlew :app:installRelease --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a -Preact_native_file_hash_engine=native)

# 2) Android / zig / Release / physical device
./scripts/build-zig-android.sh && (cd example/android && ./gradlew :app:installRelease --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a -Preact_native_file_hash_engine=zig)

# 3) iOS / native / Release / physical device
(cd example && ZFH_ENGINE=native bundle exec pod install --project-directory=ios && ZFH_ENGINE=native npx react-native run-ios --mode Release --device "<IOS_DEVICE_NAME>")

# 4) iOS / zig / Release / physical device
./scripts/build-zig-ios.sh && (cd example && ZFH_ENGINE=zig bundle exec pod install --project-directory=ios && ZFH_ENGINE=zig npx react-native run-ios --mode Release --device "<IOS_DEVICE_NAME>")

# 5) macOS / zig / Debug
./scripts/build-zig-macos.sh && yarn install && (cd examples/macos && yarn pods && yarn macos)

# 6) Windows / zig / Debug
./scripts/build-zig-windows.sh && yarn install && (cd examples/windows && yarn windows)

The desktop examples are Yarn workspaces, so the same commands can also be run from the repository root:

yarn workspace @preeternal/react-native-file-hash-macos-example pods
yarn workspace @preeternal/react-native-file-hash-macos-example start --reset-cache
yarn workspace @preeternal/react-native-file-hash-macos-example macos

yarn workspace @preeternal/react-native-file-hash-windows-example start --reset-cache
yarn workspace @preeternal/react-native-file-hash-windows-example windows

React Native Windows CLI currently requires PowerShell 7 (pwsh.exe) on PATH. Without it, RNW commands can fail with a misleading unknown command error instead of the real cause; see microsoft/react-native-windows#16274.

If the Windows example shell needs to be created or refreshed from the official React Native Windows template, run this from examples/windows:

npx react-native init-windows --overwrite

The command can overwrite RNW-generated files such as windows/ and metro.config.js, so re-apply the monorepo Metro config and local app changes after regenerating.

If RNW points you to node_modules/react-native-windows/scripts/rnw-dependencies.ps1, it is asking for the Windows development prerequisites. Run the dependency setup from an elevated PowerShell window:

Set-ExecutionPolicy Unrestricted -Scope Process -Force
iex (New-Object System.Net.WebClient).DownloadString('https://aka.ms/rnw-vs2022-deps.ps1')

Local development and rebuilds

If you need a full clean rebuild, run ./gradlew clean (Android) or clean the Xcode build folder before repeating the commands in the sections below.

The example app demonstrates usage of the library. You need to run it to test any changes you make.

It is configured to use the local version of the library, so any changes you make to the library's source code will be reflected in the example app. Changes to the library's JavaScript code will be reflected in the example app without a rebuild, but native code changes will require a rebuild of the example app.

If you want to use Android Studio or Xcode to edit the native code, you can open the example/android or example/ios directories respectively in those editors. To edit the Objective-C or Swift files, open example/ios/FileHashExample.xcworkspace in Xcode and find the source files at Pods > Development Pods > @preeternal/react-native-file-hash.

To edit the Java or Kotlin files, open example/android in Android studio and find the source files at preeternal-react-native-file-hash under Android.

You can use various commands from the root directory to work with the project.

To start the packager:

yarn example start

To run the example app on Android:

yarn example android

To run the example app on iOS:

yarn example ios

To confirm that the app is running with the new architecture, you can check the Metro logs for a message like this:

Running "FileHashExample" with {"fabric":true,"initialProps":{"concurrentRoot":true},"rootTag":1}

Note the "fabric":true and "concurrentRoot":true properties.

Make sure your code passes TypeScript:

yarn typecheck

To check for linting errors, run the following:

yarn lint

To fix formatting errors, run the following:

yarn lint --fix

Remember to add tests for your change if possible. Run the unit tests by:

yarn test

Local Maestro smoke runs (Android/iOS, native/zig)

Use these commands to run the same Maestro smoke checks locally that CI uses.

Notes:

  • If maestro is not installed yet, install it once: curl -Ls "https://get.maestro.mobile.dev" | bash Then make sure $HOME/.maestro/bin is in your PATH for the current shell.
  • For Android, set -PreactNativeArchitectures to match your local emulator ABI. Apple Silicon emulators are usually arm64-v8a; GitHub Actions Linux uses x86_64.
  • The Android commands below auto-pick the first connected device from adb devices. If you have more than one device/emulator attached, set ANDROID_SERIAL manually before running them.
  • For iOS, always pass --device "$SIMULATOR_ID" to Maestro. If Android and iOS devices are both running, Maestro can otherwise pick the wrong device.
# 1) Android / native / local emulator
ANDROID_SERIAL="${ANDROID_SERIAL:-$(adb devices | awk '$2 == "device" { print $1; exit }')}"
[[ -n "$ANDROID_SERIAL" ]] || { echo "No Android device/emulator found" >&2; exit 1; }
adb -s "$ANDROID_SERIAL" uninstall preeternal.reactnativefilehash.example || true
./example/android/gradlew -p example/android :app:installRelease --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a -Preact_native_file_hash_engine=native
ANDROID_SERIAL="$ANDROID_SERIAL" MAESTRO_CLI_NO_ANALYTICS=1 MAESTRO_DRIVER_STARTUP_TIMEOUT=300000 bash ./scripts/maestro-runtime-smoke.sh native

# 2) Android / zig / local emulator
ANDROID_SERIAL="${ANDROID_SERIAL:-$(adb devices | awk '$2 == "device" { print $1; exit }')}"
[[ -n "$ANDROID_SERIAL" ]] || { echo "No Android device/emulator found" >&2; exit 1; }
adb -s "$ANDROID_SERIAL" uninstall preeternal.reactnativefilehash.example || true
./scripts/build-zig-android.sh
./example/android/gradlew -p example/android :app:installRelease --no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a -Preact_native_file_hash_engine=zig
ANDROID_SERIAL="$ANDROID_SERIAL" MAESTRO_CLI_NO_ANALYTICS=1 MAESTRO_DRIVER_STARTUP_TIMEOUT=300000 bash ./scripts/maestro-runtime-smoke.sh zig

# 3) iOS / native / local simulator
SIMULATOR_ID=$(xcrun simctl list devices available | awk -F '[()]' '/iPhone/ {print $2; exit}')
DERIVED_DATA="$TMPDIR/maestro-ios-native"
rm -rf "$DERIVED_DATA"
xcrun simctl boot "$SIMULATOR_ID" || true
xcrun simctl bootstatus "$SIMULATOR_ID" -b
(cd example && env -u ZFH_ENGINE bundle exec pod install --project-directory=ios)
xcodebuild -workspace example/ios/FileHashExample.xcworkspace -scheme FileHashExample -configuration Release -sdk iphonesimulator -destination "id=$SIMULATOR_ID" -derivedDataPath "$DERIVED_DATA" CODE_SIGNING_ALLOWED=NO build
APP_PATH=$(find "$DERIVED_DATA/Build/Products/Release-iphonesimulator" -maxdepth 1 -name "*.app" | head -n1)
APP_ID=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "$APP_PATH/Info.plist")
xcrun simctl uninstall "$SIMULATOR_ID" "$APP_ID" || true
xcrun simctl install "$SIMULATOR_ID" "$APP_PATH"
MAESTRO_CLI_NO_ANALYTICS=1 maestro --device "$SIMULATOR_ID" test -e APP_ID="$APP_ID" .maestro/runtime-native-smoke-ios.yaml

# 4) iOS / zig / local simulator
SIMULATOR_ID=$(xcrun simctl list devices available | awk -F '[()]' '/iPhone/ {print $2; exit}')
DERIVED_DATA="$TMPDIR/maestro-ios-zig"
rm -rf "$DERIVED_DATA"
xcrun simctl boot "$SIMULATOR_ID" || true
xcrun simctl bootstatus "$SIMULATOR_ID" -b
./scripts/build-zig-ios.sh
(cd example && ZFH_ENGINE=zig bundle exec pod install --project-directory=ios)
xcodebuild -workspace example/ios/FileHashExample.xcworkspace -scheme FileHashExample -configuration Release -sdk iphonesimulator -destination "id=$SIMULATOR_ID" -derivedDataPath "$DERIVED_DATA" CODE_SIGNING_ALLOWED=NO build
APP_PATH=$(find "$DERIVED_DATA/Build/Products/Release-iphonesimulator" -maxdepth 1 -name "*.app" | head -n1)
APP_ID=$(/usr/libexec/PlistBuddy -c "Print :CFBundleIdentifier" "$APP_PATH/Info.plist")
xcrun simctl uninstall "$SIMULATOR_ID" "$APP_ID" || true
xcrun simctl install "$SIMULATOR_ID" "$APP_PATH"
MAESTRO_CLI_NO_ANALYTICS=1 maestro --device "$SIMULATOR_ID" test -e APP_ID="$APP_ID" .maestro/runtime-zig-smoke-ios.yaml

Package validation

Before publishing a release, run yarn check:packaged-artifacts from the repository root. This verifies that the npm tarball contains all required packaged third-party artifacts for both native and zig builds.

Release checklist

Before publishing a release, run the packaging check and all four local Maestro smoke commands:

  • yarn check:packaged-artifacts
  • Android / native
  • Android / zig
  • iOS / native
  • iOS / zig

Maestro smoke is intentionally not part of GitHub Actions CI for this repository. Hosted emulator/simulator runs were too slow and too flaky, so these checks are kept local before release. The packaged-artifacts check does run in CI, because it is deterministic and must fail before any broken npm publish.

Commit message convention

We follow the conventional commits specification for our commit messages:

  • fix: bug fixes, e.g. fix crash due to deprecated method.
  • feat: new features, e.g. add new method to the module.
  • refactor: code refactor, e.g. migrate from class components to hooks.
  • docs: changes into documentation, e.g. add usage example for the module.
  • test: adding or updating tests, e.g. add integration tests using detox.
  • chore: tooling changes, e.g. change CI config.

Our pre-commit hooks verify that your commit message matches this format when committing.

Publishing to npm

We use release-it to make it easier to publish new versions. It handles common tasks like bumping version based on semver, creating tags and releases etc.

To publish new versions, run the following:

yarn release

Scripts

The package.json file contains various scripts for common tasks:

  • yarn: setup project by installing dependencies.
  • yarn typecheck: type-check files with TypeScript.
  • yarn lint: lint files with ESLint.
  • yarn test: run unit tests with Jest.
  • yarn example start: start the Metro server for the example app.
  • yarn example android: run the example app on Android.
  • yarn example ios: run the example app on iOS.

Sending a pull request

Working on your first pull request? You can learn how from this free series: How to Contribute to an Open Source Project on GitHub.

When you're sending a pull request:

  • Prefer small pull requests focused on one change.
  • Verify that linters and tests are passing.
  • Review the documentation to make sure it looks good.
  • Follow the pull request template when opening a pull request.
  • For pull requests that change the API or implementation, discuss with maintainers first by opening an issue.