@oxy.so/app-preset 5.3.1 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -14,7 +14,7 @@ and JSON.
14
14
 
15
15
  | Piece | Import | Replaces |
16
16
  | --- | --- | --- |
17
- | Config plugin | `['@oxy.so/app-preset', {}]` | iOS keychain entitlement + `expo-build-properties` + `@oxy.so/services/plugins/withOxySharedPermissions` (which signs every release with the ecosystem key, see below) + the R8 `-optimize` ProGuard file |
17
+ | Config plugin | `['@oxy.so/app-preset', {}]` | iOS keychain entitlement + `expo-build-properties` + `@oxy.so/services/plugins/withOxySharedPermissions` (which signs every release with the ecosystem key, see below) + the R8 `-optimize` ProGuard file + one APK per ABI |
18
18
  | Android WebP resources | `@oxy.so/app-preset/plugin/withOxyAndroidWebp` | re-encoding generated mipmaps/splash bitmaps to real lossless WebP (opt-in, needs `sharp`) |
19
19
  | Oxy Updates (OTA) | `@oxy.so/app-preset/plugin/withOxyUpdates` | the `expo-updates` manifest URL, release channel, `runtimeVersion` policy and the shared code-signing certificate, required (opt-in, see below) |
20
20
  | Metro | `@oxy.so/app-preset/metro` | monorepo watch folders, block list, symlink + package-exports resolution, web-font/wasm asset exts, release minifier, NativeWind wrapper |
@@ -172,6 +172,50 @@ signing.
172
172
 
173
173
  `withOxyAndroidRelease` was removed in 5.0.0; listing it throws and says to delete it.
174
174
 
175
+ #### Store build number (always on, 6.0.0+)
176
+
177
+ The preset derives Android `versionCode` and iOS `buildNumber` from the app's
178
+ `version`: `major * 1_000_000 + minor * 1_000 + patch` (1.2.3 → 1002003; minor
179
+ and patch ≤ 999). Every later version gets a strictly higher number, which is
180
+ what Google Play and the App Store require, and nobody keeps it by hand. An app
181
+ config that still sets `android.versionCode` or `ios.buildNumber` fails to
182
+ load: delete them. `version` must be `MAJOR.MINOR.PATCH`.
183
+
184
+ `version` is also the OTA boundary (`withOxyUpdates`, `appVersion` policy):
185
+ bump it for a native change and the next push to main releases a new binary
186
+ (oxy's `android-release.yml`, docs/engineering/build-and-deploy.md#native-android-releases);
187
+ a JS-only change keeps the version and ships as an OTA update.
188
+
189
+ #### One APK per ABI (always on, 6.1.0+)
190
+
191
+ `withOxyAbiSplits`, applied by the preset and by `withOxyUpdates`, adds Gradle
192
+ ABI splits to `android/app/build.gradle`, so `assembleRelease` writes one APK per
193
+ ABI and no universal APK:
194
+
195
+ | APK | For |
196
+ | --- | --- |
197
+ | `app-arm64-v8a-release.apk` | almost every phone and tablet, anything from about 2017 on |
198
+ | `app-armeabi-v7a-release.apk` | older phones, and Android TVs and TV boxes |
199
+
200
+ A universal APK carries every ABI's native libraries and a phone loads one
201
+ (Mention: 126 MB, of which 55 MB arm64-v8a and 37 MB armeabi-v7a libraries).
202
+ `bundleRelease` is unaffected: the AAB keeps every ABI and Google Play serves
203
+ each device its slice.
204
+
205
+ A build that compiles none of those ABIs splits to the ones it compiles, so
206
+ `expo run:android` on an x86_64 emulator (it passes
207
+ `-PreactNativeArchitectures=x86_64`) still gets `app-x86_64-debug.apk`, which the
208
+ Expo CLI installs by the device's ABI. An ABI that is not compiled never gets
209
+ an APK of its own, since it would carry no native libraries.
210
+
211
+ Both release APKs have the app's one `versionCode`. They are the same version of
212
+ the same app, so Android installs either over the other; Google Play's rule of a
213
+ distinct versionCode per APK applies only to APKs uploaded to Play, and Play
214
+ gets the AAB. A `build.gradle` that already has a `splits {}` block (an app's own
215
+ plugin) fails prebuild: remove it. The release workflow
216
+ (docs/engineering/build-and-deploy.md#native-android-releases) publishes the two
217
+ APKs and fails a build without them.
218
+
175
219
  #### Android WebP resources (opt-in)
176
220
 
177
221
  `withOxyAndroidWebp` needs `sharp` installed, so it is registered explicitly:
@@ -237,8 +281,23 @@ accepts no publish, without its key. Development builds may explicitly pass
237
281
  `{ codeSigning: 'auto' }` to receive platform warnings, or
238
282
  `{ codeSigning: false }` to opt out of verification.
239
283
 
240
- Publishing is `oxy-ship` (`@oxy.so/ship`); see that package's README and its
241
- `templates/publish-update.yml` CI workflow.
284
+ Publishing is `oxy-ship` (`@oxy.so/ship`) from GitHub Actions, with **no stored
285
+ secret** (oxy ADR 0057, GitHub trusted publishing). Per app repository:
286
+
287
+ 1. Declare the repository as the app's trusted publisher: an Oxy app adds
288
+ `trustedPublishers: [otaPublisher('OxyHQ/<Repo>', '<numeric id>')]` to its
289
+ entry in oxy's `seedOxyApplicationsSpecs.ts` and runs the seed; a
290
+ third-party app registers it with
291
+ `POST https://api.oxy.so/applications/<appId>/trusted-publishers`.
292
+ 2. Add `@oxy.so/ship` as a devDependency.
293
+ 3. Copy `@oxy.so/ship/templates/publish-update.yml` to
294
+ `.github/workflows/publish-update.yml` and set `OXY_CLIENT_ID` in it to the
295
+ same public client id passed to `withOxyUpdates` above.
296
+
297
+ Every push to `main` then publishes to `production`; the job's GitHub OIDC
298
+ token (`permissions: id-token: write`) is exchanged for a five-minute
299
+ `updates:publish` token of that app only. Pull requests never publish. See the
300
+ `@oxy.so/ship` README for the exchange and the registration fields.
242
301
 
243
302
  ### 2. Metro (`metro.config.js`)
244
303
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxy.so/app-preset",
3
- "version": "5.3.1",
3
+ "version": "6.1.0",
4
4
  "description": "The Oxy distro of Expo — centralized Expo config plugin, Metro/Babel/ESLint factories, Tailwind base CSS and TypeScript bases shared by every Oxy app (Mention, Homiio, Allo, accounts, …). A zero-build package: apps replace copy-pasted config with a single dependency bump.",
5
5
  "main": "./app.plugin.js",
6
6
  "publishConfig": {
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Expo Config Plugin: withOxyAbiSplits (always applied by the preset)
3
+ *
4
+ * Builds one APK per ABI instead of one universal APK. A universal Oxy APK
5
+ * carries the native libraries of every ABI, of which a phone loads one
6
+ * (Mention 126 MB: 55 MB of arm64-v8a libraries, 37 MB of armeabi-v7a), so a
7
+ * release ships
8
+ *
9
+ * app-arm64-v8a-release.apk every phone from about 2017 on
10
+ * app-armeabi-v7a-release.apk older phones and many Android TVs
11
+ *
12
+ * and no universal APK. Gradle's ABI splits only affect APKs: `bundleRelease`
13
+ * still builds one AAB with every ABI, and Google Play serves each device its
14
+ * own slice of it.
15
+ *
16
+ * A build for ONE device keeps working: `expo run:android` passes
17
+ * `-PreactNativeArchitectures=<the device's ABI>` for a debug build, so the
18
+ * split follows the ABIs Gradle compiles whenever none of the release ABIs is
19
+ * among them (an x86_64 emulator gets `app-x86_64-debug.apk`, which the Expo
20
+ * CLI finds by the device's ABI). A release ABI that is not compiled is never
21
+ * split out, because its APK would carry no native libraries.
22
+ *
23
+ * Every split APK has the app's one `versionCode` (`withOxyReleaseVersion`).
24
+ * That is what sideloading needs: they are the same version of the same app,
25
+ * and Android installs either over the other. Unique versionCodes per APK are
26
+ * a Google Play rule for publishing several APKs to Play; Play gets the AAB.
27
+ *
28
+ * Applied by the preset and by `withOxyUpdates`, the entry every app on the
29
+ * release pipeline lists, so it is idempotent: the second run finds its marker
30
+ * and changes nothing. A build.gradle that already has a `splits {}` block
31
+ * (another plugin's, or a hand edit) fails: two sources for the APK layout is
32
+ * how a release ends up shipping the wrong files.
33
+ */
34
+ const { withAppBuildGradle } = require('expo/config-plugins');
35
+
36
+ const PLUGIN = '[@oxy.so/app-preset withOxyAbiSplits]';
37
+ const MARKER = '@generated oxy-abi-splits';
38
+
39
+ /** The ABIs every Oxy release ships an APK for, in the order people should pick them. */
40
+ const RELEASE_ABIS = ['arm64-v8a', 'armeabi-v7a'];
41
+
42
+ /** Inserted before `android {`: which APKs this build splits out. */
43
+ const RESOLVE_ABIS = `// ${MARKER}: one APK per ABI, no universal APK (@oxy.so/app-preset
44
+ // withOxyAbiSplits). Edit the plugin, never this file. A release ships ${RELEASE_ABIS.join(' and ')};
45
+ // a build that compiles none of them (-PreactNativeArchitectures=x86_64, as \`expo run:android\`
46
+ // passes for an emulator) splits to the ABIs it compiles, so that device still gets an APK.
47
+ def oxyBuiltAbis = (findProperty('reactNativeArchitectures') ?: 'armeabi-v7a,arm64-v8a,x86,x86_64').toString().split(',').collect { it.trim() }.findAll { it }
48
+ def oxyReleaseAbis = [${RELEASE_ABIS.map((abi) => `'${abi}'`).join(', ')}].findAll { oxyBuiltAbis.contains(it) }
49
+ def oxyApkAbis = oxyReleaseAbis ?: oxyBuiltAbis
50
+
51
+ `;
52
+
53
+ /** Inserted as the first entry of `android {`. */
54
+ const SPLITS = `
55
+ // ${MARKER}: the APKs are oxyApkAbis, one each; the AAB is unaffected.
56
+ splits {
57
+ abi {
58
+ reset()
59
+ enable true
60
+ universalApk false
61
+ include(*oxyApkAbis)
62
+ }
63
+ }
64
+ `;
65
+
66
+ function fail(message) {
67
+ throw new Error(`${PLUGIN} ${message}`);
68
+ }
69
+
70
+ /**
71
+ * Apply the split to the text of a Groovy `android/app/build.gradle`. Idempotent.
72
+ *
73
+ * @param {string} contents
74
+ * @returns {string}
75
+ */
76
+ function applyAbiSplits(contents) {
77
+ if (contents.includes(MARKER)) return contents;
78
+
79
+ if (/^\s*splits\s*\{/m.test(contents)) {
80
+ fail(
81
+ 'app/build.gradle already has a `splits {}` block written by another plugin or by hand. ' +
82
+ 'Remove it: the preset splits every Oxy APK by ABI.',
83
+ );
84
+ }
85
+
86
+ const androidBlock = /^android \{$/m;
87
+ if (!androidBlock.test(contents)) {
88
+ fail(
89
+ 'Could not find the top-level `android {` block in app/build.gradle. The Expo template changed: update this plugin instead of editing android/ by hand.',
90
+ );
91
+ }
92
+ return contents.replace(androidBlock, `${RESOLVE_ABIS}android {${SPLITS}`);
93
+ }
94
+
95
+ /** @param {import('expo/config').ExpoConfig} config */
96
+ module.exports = function withOxyAbiSplits(config) {
97
+ return withAppBuildGradle(config, (modConfig) => {
98
+ if (modConfig.modResults.language !== 'groovy') {
99
+ fail(
100
+ `app/build.gradle is ${modConfig.modResults.language}, not Groovy. Oxy releases ship one APK per ABI; ` +
101
+ 'add the split to this plugin for that language instead of shipping a universal APK.',
102
+ );
103
+ }
104
+ modConfig.modResults.contents = applyAbiSplits(modConfig.modResults.contents);
105
+ return modConfig;
106
+ });
107
+ };
108
+ module.exports.applyAbiSplits = applyAbiSplits;
109
+ module.exports.RELEASE_ABIS = RELEASE_ABIS;
@@ -33,6 +33,10 @@
33
33
  * `withOxySharedPermissions` also signs every release build with the ONE Oxy
34
34
  * ecosystem key (the `OXY_UPLOAD_*` Gradle properties) and fails a release that
35
35
  * does not carry its certificate; an app lists no signing plugin of its own.
36
+ * `withOxyReleaseVersion` (always applied) derives Android `versionCode` and iOS
37
+ * `buildNumber` from `version` (1.2.3 → 1002003); an app sets neither.
38
+ * `withOxyAbiSplits` (always applied) builds one APK per ABI (arm64-v8a,
39
+ * armeabi-v7a) instead of a universal APK; the AAB is unaffected.
36
40
  * `withOxyR8Optimize` (always applied) swaps in R8's `-optimize` ProGuard file on
37
41
  * Expo SDK 56/57 and is a no-op on 58.
38
42
  *
@@ -55,6 +59,8 @@
55
59
  const withOxyKeychain = require('./withOxyKeychain');
56
60
  const withOxyBuildProperties = require('./withOxyBuildProperties');
57
61
  const withOxyR8Optimize = require('./withOxyR8Optimize');
62
+ const withOxyReleaseVersion = require('./withOxyReleaseVersion');
63
+ const withOxyAbiSplits = require('./withOxyAbiSplits');
58
64
  const { dirname, join } = require('node:path');
59
65
  const { projectRootOf, requireFromProject, resolveFromProject } = require('./requireFromProject');
60
66
 
@@ -103,6 +109,8 @@ module.exports = function withOxyAppPreset(config, options = {}) {
103
109
  }
104
110
 
105
111
  next = withOxyR8Optimize(next);
112
+ next = withOxyReleaseVersion(next);
113
+ next = withOxyAbiSplits(next);
106
114
 
107
115
  let withOxySharedPermissions;
108
116
  try {
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Expo Config Plugin: withOxyReleaseVersion (always applied by the preset)
3
+ *
4
+ * Derives the store build number from the app's `version`, so it is never kept
5
+ * by hand and never drifts: Android `versionCode` and iOS `buildNumber` are
6
+ *
7
+ * major * 1_000_000 + minor * 1_000 + patch (1.2.3 → 1002003)
8
+ *
9
+ * The app `version` is already the OTA compatibility boundary (`withOxyUpdates`
10
+ * uses the `appVersion` runtime policy): a new native binary is exactly a new
11
+ * version, and every new version gets a strictly higher build number, which is
12
+ * what Google Play and the App Store require. JS-only changes ship as OTA
13
+ * updates under the same version and never need a build number.
14
+ *
15
+ * Applied by the preset and by `withOxyUpdates` (the OTA boundary it rests on),
16
+ * so it is idempotent: a number equal to the derived one passes. An app that
17
+ * keeps any OTHER `android.versionCode` or `ios.buildNumber` fails: two sources
18
+ * for one number is how a release ends up rejected for reusing one.
19
+ */
20
+ const VERSION_PATTERN = /^(\d+)\.(\d+)\.(\d+)$/;
21
+ const MAX_MAJOR = 2099; // Play's versionCode ceiling is 2_100_000_000.
22
+
23
+ /**
24
+ * @param {string} version
25
+ * @returns {number}
26
+ */
27
+ function releaseBuildNumber(version) {
28
+ const match = VERSION_PATTERN.exec(String(version));
29
+ if (!match) {
30
+ throw new Error(
31
+ `[@oxy.so/app-preset] The app \`version\` must be MAJOR.MINOR.PATCH (got ${JSON.stringify(version)}): ` +
32
+ 'the store build number is derived from it.',
33
+ );
34
+ }
35
+ const [major, minor, patch] = match.slice(1).map(Number);
36
+ if (major > MAX_MAJOR || minor > 999 || patch > 999) {
37
+ throw new Error(
38
+ `[@oxy.so/app-preset] The app \`version\` ${version} is out of range: major ≤ ${MAX_MAJOR}, minor and patch ≤ 999.`,
39
+ );
40
+ }
41
+ return major * 1_000_000 + minor * 1_000 + patch;
42
+ }
43
+
44
+ /**
45
+ * @param {import('expo/config').ExpoConfig} config
46
+ */
47
+ function withOxyReleaseVersion(config) {
48
+ if (config.version === undefined) {
49
+ throw new Error('[@oxy.so/app-preset] The app config needs a `version` (MAJOR.MINOR.PATCH).');
50
+ }
51
+ const buildNumber = releaseBuildNumber(config.version);
52
+ const versionCode = config.android?.versionCode;
53
+ if (versionCode !== undefined && versionCode !== buildNumber) {
54
+ throw new Error(
55
+ `[@oxy.so/app-preset] Remove \`android.versionCode\` (${versionCode}): the preset derives it from \`version\` (${buildNumber}).`,
56
+ );
57
+ }
58
+ const iosBuildNumber = config.ios?.buildNumber;
59
+ if (iosBuildNumber !== undefined && iosBuildNumber !== String(buildNumber)) {
60
+ throw new Error(
61
+ `[@oxy.so/app-preset] Remove \`ios.buildNumber\` (${iosBuildNumber}): the preset derives it from \`version\` (${buildNumber}).`,
62
+ );
63
+ }
64
+ return {
65
+ ...config,
66
+ android: { ...config.android, versionCode: buildNumber },
67
+ ios: { ...config.ios, buildNumber: String(buildNumber) },
68
+ };
69
+ }
70
+
71
+ module.exports = withOxyReleaseVersion;
72
+ module.exports.releaseBuildNumber = releaseBuildNumber;
@@ -68,6 +68,8 @@
68
68
  const fs = require('fs');
69
69
  const path = require('path');
70
70
  const { WarningAggregator } = require('expo/config-plugins');
71
+ const withOxyReleaseVersion = require('./withOxyReleaseVersion');
72
+ const withOxyAbiSplits = require('./withOxyAbiSplits');
71
73
 
72
74
  /** Origin of the Oxy Updates server. `updates.oxy.so` does not exist; oxy-api serves it. */
73
75
  const DEFAULT_API_ORIGIN = 'https://api.oxy.so';
@@ -180,5 +182,8 @@ module.exports = function withOxyUpdates(config, options = {}) {
180
182
  next.runtimeVersion = { policy: runtimeVersionPolicy };
181
183
  }
182
184
 
183
- return next;
185
+ // `version` is the OTA boundary, so it also numbers the store build: an
186
+ // OTA-enabled app that skips the preset's main plugin gets the same rule,
187
+ // and the same per-ABI APKs (every app on the release pipeline lists this).
188
+ return withOxyAbiSplits(withOxyReleaseVersion(next));
184
189
  };