Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ node_modules
android/src/main/java/com/hotcodepush/reactnative/SdkVersion.kt
ios/SdkVersion.swift

# The core's XCFramework, downloaded by every build
# The cores, downloaded by every build: the Maven repository of the Android core and the XCFramework
android/libs
ios/Frameworks

# iOS
Expand Down
21 changes: 11 additions & 10 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ ios/ the Turbo Module (Objective-C
android/src/main/java/com/hotcodepush/reactnative the Turbo Module, the runtime, the first-render listener, the bundle loader, the reader of the embedded bundle and the React host over com.hotcodepush:core-android
android/src/test/java/com/hotcodepush/reactnative the Robolectric tests of the Android runtime and the Turbo Module, which verify:android runs
android/settings.gradle the library's own build, which takes React Native's Gradle plugin and react-android's version from node_modules
android/hotcodepush.gradle the task that runs binary create for every variant, and core-android's maven branch among `:app`'s repositories; applied by the app's build.gradle
android/hotcodepush.gradle the task that runs binary create for every variant, and the package's local Maven repository among `:app`'s repositories; applied by the app's build.gradle
scripts/binary-create-xcode.sh binary create as the app's Xcode phase runs it
scripts/download-core-android.mjs the core's Maven-layout zip into the ignored android/libs/m2, which both Gradle scripts read
scripts/download-core-ios.mjs the core's XCFramework into the ignored ios/Frameworks, which the pod vendors
benchmarks/ the size and cold-start baseline, measured on the demo
```

The native cores live in `core-ios` and `core-android`. `core-ios` is the XCFramework of a release: `package.json` pins its URL and checksum under `hotcodepush.coreIos`, and `scripts/download-core-ios.mjs` unpacks it into the ignored `ios/Frameworks` for the pod's `vendored_frameworks`, so the app's Podfile names no core. The Android library comes from core-android's `maven` branch by full sha in `android/build.gradle`; a core change lands there first and arrives here as a bump of both pins.
The native cores live in `core-ios` and `core-android`. `core-ios` is the XCFramework of a release: `package.json` pins its URL and checksum under `hotcodepush.coreIos`, and `scripts/download-core-ios.mjs` unpacks it into the ignored `ios/Frameworks` for the pod's `vendored_frameworks`, so the app's Podfile names no core. The Android module is the Maven-layout zip of a release, `core-android-<version>-maven.zip`: `package.json` pins its version and the zip's SHA-256 under `hotcodepush.coreAndroid`, and `scripts/download-core-android.mjs` unpacks it into the ignored `android/libs/m2`, the local Maven repository that `android/build.gradle` and the app's `android/hotcodepush.gradle` read. A bump of the core is a new version in `package.json` and in `android/build.gradle`, which the script checks against each other, and the checksum from the summary of core-android's release job. core-android's `maven` branch, pinned by full sha, is the development pin only, for trying a core change before its release; a published build never names it.
This package keeps what is React Native's: which bundle the host loads, the reload, the readiness signal and the bridge. Nothing of the protocol lives here.

## How the SDK meets React Native
Expand All @@ -37,14 +38,14 @@ This package keeps what is React Native's: which bundle the host loads, the relo

## Commands

| Command | Does |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `npm run lint` | ESLint, Prettier and SwiftLint |
| `npm run typecheck` | TypeScript |
| `npm test` | Vitest over the JavaScript |
| `npm run build` | the TypeScript into `dist/`; writes the SDK version from `package.json` into `SdkVersion.swift` and `SdkVersion.kt` and downloads the core's XCFramework, all ignored, so a fresh checkout runs it before opening the native projects |
| `npm run verify` | lint, typecheck, the Vitest tests and the build |
| `npm run verify:android` | Gradle builds, lints and unit-tests the Android library on its own, Robolectric; needs a JDK and the Android SDK |
| Command | Does |
| ------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `npm run lint` | ESLint, Prettier and SwiftLint |
| `npm run typecheck` | TypeScript |
| `npm test` | Vitest over the JavaScript |
| `npm run build` | the TypeScript into `dist/`; writes the SDK version from `package.json` into `SdkVersion.swift` and `SdkVersion.kt` and downloads the cores, the XCFramework and the Android Maven repository, all ignored, so a fresh checkout runs it before opening the native projects |
| `npm run verify` | lint, typecheck, the Vitest tests and the build |
| `npm run verify:android` | Gradle builds, lints and unit-tests the Android library on its own, Robolectric; needs a JDK and the Android SDK |

Run `npm run fmt` before every commit.
The iOS code compiles only inside an app: `ci.yml` builds the demo with the package from the commit, packed after `npm run build` so the pod carries the core; `benchmarks/prepare-demo.mjs` drops a core pod line the demo's Podfile still pins. The Android library also builds on its own: `android/settings.gradle` resolves React Native from the devDependency, so Codegen runs on the host, and `verify:android` runs its Robolectric tests in their own `ci.yml` job.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ See [hotcodepush.com/docs/sdks/react-native](https://hotcodepush.com/docs/sdks/r
```sh
nvm use
npm ci
npm run build # the TypeScript into dist/ and the iOS core into ios/Frameworks; run it before opening the native projects
npm run build # the TypeScript into dist/ and the cores into ios/Frameworks and android/libs; run it before opening the native projects
npm test
npm run lint && npm run typecheck
npm run verify:android # the Android library's build and Robolectric tests
Expand Down
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ kotlin {
}
}

// The core comes from core-android's maven branch at a pinned commit until the library is on Maven Central.
// The core comes from its release asset, which scripts/download-core-android.mjs unpacks into libs/m2.
repositories {
google()
mavenCentral()
maven {
url 'https://raw.githubusercontent.com/hotcodepush-team/core-android/maven/'
url = file('libs/m2')
content { includeGroup 'com.hotcodepush' }
}
}

dependencies {
implementation 'com.facebook.react:react-android'
implementation 'com.hotcodepush:core-android:a5bfc4aeede98739302f49510766a6f5decb9299'
implementation 'com.hotcodepush:core-android:0.1.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.2'
testImplementation 'junit:junit:4.13.2'
testImplementation 'org.mockito:mockito-core:5.20.0'
Expand Down
4 changes: 2 additions & 2 deletions android/hotcodepush.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import javax.inject.Inject
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.tasks.Optional

// The app resolves the core from core-android's maven branch until the library is on Maven Central.
// The app resolves the core from the package's local Maven repository beside this file.
repositories {
maven {
url 'https://raw.githubusercontent.com/hotcodepush-team/core-android/maven/'
url = new File(buildscript.sourceFile.parentFile, 'libs/m2')
content { includeGroup 'com.hotcodepush' }
}
}
Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
"files": [
"android/build.gradle",
"android/hotcodepush.gradle",
"android/libs/m2/",
"android/src/main/",
"dist/",
"ios/",
"!ios/Frameworks/HotCodePushCore.checksum",
"scripts/",
"!scripts/*.test.ts",
"!scripts/download-core-android.mjs",
"!scripts/download-core-ios.mjs",
"!scripts/write-sdk-version.mjs",
"src/",
Expand All @@ -42,14 +44,14 @@
"HotcodepushReactNativeCodePush.podspec"
],
"scripts": {
"build": "npm run clean && node scripts/write-sdk-version.mjs && node scripts/download-core-ios.mjs && tsc --project tsconfig.build.json",
"build": "npm run clean && node scripts/write-sdk-version.mjs && node scripts/download-core-android.mjs && node scripts/download-core-ios.mjs && tsc --project tsconfig.build.json",
"clean": "rimraf ./dist",
"fmt": "eslint . --fix && prettier --write . && swiftlint --fix --quiet ios",
"lint": "eslint . && prettier --check . && swiftlint lint --quiet --strict ios",
"test": "vitest run",
"typecheck": "tsc --noEmit",
"verify": "npm run lint && npm run typecheck && npm test && npm run build",
"verify:android": "node scripts/write-sdk-version.mjs && cd android && ./gradlew build --console=plain"
"verify:android": "node scripts/write-sdk-version.mjs && node scripts/download-core-android.mjs && cd android && ./gradlew build --console=plain"
},
"codegenConfig": {
"name": "HotCodePushSpec",
Expand All @@ -65,6 +67,10 @@
}
},
"hotcodepush": {
"coreAndroid": {
"version": "0.1.0",
"checksum": "7c9b91381c5c99bf9e2592fd14e912972f0bb8f3df1b0a3c340a75ca5ef3a65b"
},
"coreIos": {
"url": "https://github.com/hotcodepush-team/core-ios/releases/download/0.3.0/HotCodePushCore.xcframework.zip",
"checksum": "6d12e0613ce25748963f0ff492a6e33687a25bf291d94e2950d5b1867bbc3685"
Expand Down
67 changes: 67 additions & 0 deletions scripts/download-core-android.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { execFileSync } from 'node:child_process';
import { createHash } from 'node:crypto';
import {
existsSync,
mkdirSync,
readFileSync,
rmSync,
writeFileSync,
} from 'node:fs';
import { tmpdir } from 'node:os';
import { dirname, join } from 'node:path';
import { fileURLToPath } from 'node:url';

// Gradle cannot check a release asset's checksum before it resolves the core from it.
// So every build fetches the release asset that package.json pins under hotcodepush.coreAndroid, checks its checksum and unpacks it into the ignored local Maven repository that android/build.gradle and android/hotcodepush.gradle name.

const packageDirectory = join(dirname(fileURLToPath(import.meta.url)), '..');
const libsDirectory = join(packageDirectory, 'android/libs');
const mavenDirectory = join(libsDirectory, 'm2');
const checksumFile = join(libsDirectory, 'core-android.checksum');

const { version, checksum } =
JSON.parse(readFileSync(join(packageDirectory, 'package.json'), 'utf8'))
.hotcodepush?.coreAndroid ?? {};
if (!version || !/^[0-9a-f]{64}$/.test(checksum ?? '')) {
throw new Error(
'package.json names no hotcodepush.coreAndroid with a version and a checksum',
);
}

const [, gradleVersion] =
readFileSync(join(packageDirectory, 'android/build.gradle'), 'utf8').match(
/'com\.hotcodepush:core-android:([^']+)'/,
) ?? [];
if (gradleVersion !== version) {
throw new Error(
`android/build.gradle names core-android ${gradleVersion}, package.json pins ${version}`,
);
Comment on lines +35 to +38
}

if (
existsSync(checksumFile) &&
readFileSync(checksumFile, 'utf8') === checksum
) {
process.exit(0);
}

const url = `https://github.com/hotcodepush-team/core-android/releases/download/${version}/core-android-${version}-maven.zip`;
const response = await fetch(url);
if (!response.ok) {
throw new Error(`${url} answered ${response.status}`);
}
const archive = Buffer.from(await response.arrayBuffer());
const actualChecksum = createHash('sha256').update(archive).digest('hex');
if (actualChecksum !== checksum) {
throw new Error(
`${url} has the checksum ${actualChecksum}, package.json pins ${checksum}`,
Comment on lines +53 to +57
);
}

const archiveFile = join(tmpdir(), `core-android-${checksum}.zip`);
writeFileSync(archiveFile, archive);
rmSync(libsDirectory, { recursive: true, force: true });
mkdirSync(mavenDirectory, { recursive: true });
execFileSync('unzip', ['-q', archiveFile, '-d', mavenDirectory]);
rmSync(archiveFile);
writeFileSync(checksumFile, checksum);
Loading