@oxy.so/app-preset 5.3.1 → 6.0.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
@@ -172,6 +172,20 @@ 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
+
175
189
  #### Android WebP resources (opt-in)
176
190
 
177
191
  `withOxyAndroidWebp` needs `sharp` installed, so it is registered explicitly:
@@ -237,8 +251,23 @@ accepts no publish, without its key. Development builds may explicitly pass
237
251
  `{ codeSigning: 'auto' }` to receive platform warnings, or
238
252
  `{ codeSigning: false }` to opt out of verification.
239
253
 
240
- Publishing is `oxy-ship` (`@oxy.so/ship`); see that package's README and its
241
- `templates/publish-update.yml` CI workflow.
254
+ Publishing is `oxy-ship` (`@oxy.so/ship`) from GitHub Actions, with **no stored
255
+ secret** (oxy ADR 0057, GitHub trusted publishing). Per app repository:
256
+
257
+ 1. Declare the repository as the app's trusted publisher: an Oxy app adds
258
+ `trustedPublishers: [otaPublisher('OxyHQ/<Repo>', '<numeric id>')]` to its
259
+ entry in oxy's `seedOxyApplicationsSpecs.ts` and runs the seed; a
260
+ third-party app registers it with
261
+ `POST https://api.oxy.so/applications/<appId>/trusted-publishers`.
262
+ 2. Add `@oxy.so/ship` as a devDependency.
263
+ 3. Copy `@oxy.so/ship/templates/publish-update.yml` to
264
+ `.github/workflows/publish-update.yml` and set `OXY_CLIENT_ID` in it to the
265
+ same public client id passed to `withOxyUpdates` above.
266
+
267
+ Every push to `main` then publishes to `production`; the job's GitHub OIDC
268
+ token (`permissions: id-token: write`) is exchanged for a five-minute
269
+ `updates:publish` token of that app only. Pull requests never publish. See the
270
+ `@oxy.so/ship` README for the exchange and the registration fields.
242
271
 
243
272
  ### 2. Metro (`metro.config.js`)
244
273
 
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.0.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": {
@@ -33,6 +33,8 @@
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.
36
38
  * `withOxyR8Optimize` (always applied) swaps in R8's `-optimize` ProGuard file on
37
39
  * Expo SDK 56/57 and is a no-op on 58.
38
40
  *
@@ -55,6 +57,7 @@
55
57
  const withOxyKeychain = require('./withOxyKeychain');
56
58
  const withOxyBuildProperties = require('./withOxyBuildProperties');
57
59
  const withOxyR8Optimize = require('./withOxyR8Optimize');
60
+ const withOxyReleaseVersion = require('./withOxyReleaseVersion');
58
61
  const { dirname, join } = require('node:path');
59
62
  const { projectRootOf, requireFromProject, resolveFromProject } = require('./requireFromProject');
60
63
 
@@ -103,6 +106,7 @@ module.exports = function withOxyAppPreset(config, options = {}) {
103
106
  }
104
107
 
105
108
  next = withOxyR8Optimize(next);
109
+ next = withOxyReleaseVersion(next);
106
110
 
107
111
  let withOxySharedPermissions;
108
112
  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,7 @@
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');
71
72
 
72
73
  /** Origin of the Oxy Updates server. `updates.oxy.so` does not exist; oxy-api serves it. */
73
74
  const DEFAULT_API_ORIGIN = 'https://api.oxy.so';
@@ -180,5 +181,7 @@ module.exports = function withOxyUpdates(config, options = {}) {
180
181
  next.runtimeVersion = { policy: runtimeVersionPolicy };
181
182
  }
182
183
 
183
- return next;
184
+ // `version` is the OTA boundary, so it also numbers the store build: an
185
+ // OTA-enabled app that skips the preset's main plugin gets the same rule.
186
+ return withOxyReleaseVersion(next);
184
187
  };