@oxy.so/app-preset 5.0.0 → 5.2.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 +8 -5
- package/certs/README.md +60 -29
- package/certs/oxy-updates-code-signing.pem +18 -0
- package/metro/fresh-workspace-builds.js +160 -0
- package/metro/index.js +14 -0
- package/metro/linked-native-packages.js +213 -0
- package/metro/source-stamp.js +98 -0
- package/package.json +1 -1
- package/plugin/withOxyUpdates.js +40 -15
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ and JSON.
|
|
|
16
16
|
| --- | --- | --- |
|
|
17
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 |
|
|
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
|
-
| Oxy Updates (OTA) | `@oxy.so/app-preset/plugin/withOxyUpdates` | the `expo-updates` manifest URL, release channel, `runtimeVersion` policy and the shared code-signing certificate (opt-in, see below) |
|
|
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 |
|
|
21
21
|
| Babel | `@oxy.so/app-preset/babel` | `babel-preset-expo` alone in development, so Expo's oxc transformer (Noxcturnal) runs; the build-id inliner in production |
|
|
22
22
|
| ESLint | `@oxy.so/app-preset/eslint` | `eslint-config-expo/flat` + `dist/*` ignore |
|
|
@@ -226,10 +226,13 @@ receive JS assuming native modules they do not have.
|
|
|
226
226
|
|
|
227
227
|
**Code signing is one certificate for the whole ecosystem**, shipped in this
|
|
228
228
|
package at `certs/oxy-updates-code-signing.pem` rather than copied into each app
|
|
229
|
-
repo, so a rotation is one preset bump. See `certs/README.md` for how it
|
|
230
|
-
generated and
|
|
231
|
-
|
|
232
|
-
|
|
229
|
+
repo, so a rotation is one preset bump. See `certs/README.md` for how it was
|
|
230
|
+
generated, where its private key lives, and how to rotate it. `withOxyUpdates`
|
|
231
|
+
fails the build (5.2.0+; before that the code defaulted to a warning) when the
|
|
232
|
+
certificate is missing or is not a PEM certificate, rather than producing a
|
|
233
|
+
binary that accepts unsigned manifests for its whole lifetime. The server side
|
|
234
|
+
matches: oxy-api signs every manifest and directive and serves nothing, and
|
|
235
|
+
accepts no publish, without its key. Development builds may explicitly pass
|
|
233
236
|
`{ codeSigning: 'auto' }` to receive platform warnings, or
|
|
234
237
|
`{ codeSigning: false }` to opt out of verification.
|
|
235
238
|
|
package/certs/README.md
CHANGED
|
@@ -1,55 +1,86 @@
|
|
|
1
1
|
# Oxy Updates code-signing certificate
|
|
2
2
|
|
|
3
|
-
`withOxyUpdates`
|
|
3
|
+
`withOxyUpdates` reads exactly one file in this directory:
|
|
4
4
|
|
|
5
5
|
```
|
|
6
6
|
oxy-updates-code-signing.pem
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
-
It is the **public** half of the Oxy Updates code-signing keypair
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
It is the **public** half of the Oxy Updates code-signing keypair (RSA 2048,
|
|
10
|
+
self-signed, `CN=Oxy Updates Code Signing`, extended key usage Code Signing,
|
|
11
|
+
valid 2026-10-24 to 2036-10-24, SHA-256 fingerprint
|
|
12
|
+
`E9:1D:40:E6:BA:F7:05:C8:C1:94:FF:89:F8:FD:65:E6:6B:89:DA:AB:26:95:B9:E4:7A:7E:54:28:F5:39:DA:81`).
|
|
13
|
+
It is safe to commit, and it lives here rather than in each app repo so that a
|
|
14
|
+
key rotation is one `@oxy.so/app-preset` bump instead of one edit per app.
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
`
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
`withOxyUpdates` fails the build when this file is missing or is not a PEM
|
|
17
|
+
certificate (`codeSigning: 'require'`, the default), because the certificate is
|
|
18
|
+
baked into the native binary: a binary built without it accepts unsigned
|
|
19
|
+
manifests for its whole lifetime. `codeSigning: 'auto'` / `false` are for local
|
|
20
|
+
development builds only.
|
|
17
21
|
|
|
18
|
-
##
|
|
22
|
+
## Where the private key lives
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
- **SSM SecureString `/oxy/oxy-api/UPDATES_CODE_SIGNING_PRIVATE_KEY`** (us-west-2,
|
|
25
|
+
KMS `alias/aws/ssm`), the base64-encoded PKCS#8 PEM. It is the only copy the
|
|
26
|
+
server reads: `deploy-aws.yml` binds it into the oxy-api task definition
|
|
27
|
+
(`TASK_SECRET_OVERRIDES_JSON`) and `services/updates/signing.service.ts` decodes
|
|
28
|
+
it. Runtime secrets are SSM-only (oxy-infra `docs/runbooks/46-app-secrets-in-ssm.md`);
|
|
29
|
+
it is NOT a GitHub Actions secret.
|
|
30
|
+
- **Offline backup**: `~/.config/oxy/oxy-updates-code-signing-private-key.b64`
|
|
31
|
+
(mode 0600) on the platform owner's machine, next to the Android release
|
|
32
|
+
keystore, and into the same USB vault.
|
|
33
|
+
|
|
34
|
+
Without the key, oxy-api answers every manifest request with 503 and refuses
|
|
35
|
+
every publish; it never serves an unsigned manifest.
|
|
36
|
+
|
|
37
|
+
## Provisioning (done 2026-10-25; for the record and for a rotation)
|
|
38
|
+
|
|
39
|
+
From `packages/api`:
|
|
21
40
|
|
|
22
41
|
```bash
|
|
23
42
|
bun scripts/generate-updates-code-signing.ts \
|
|
24
|
-
../app-preset/certs/oxy-updates-code-signing.pem
|
|
43
|
+
../app-preset/certs/oxy-updates-code-signing.pem \
|
|
44
|
+
~/.config/oxy/oxy-updates-code-signing-private-key.b64
|
|
25
45
|
```
|
|
26
46
|
|
|
27
|
-
|
|
28
|
-
|
|
47
|
+
The script writes the certificate here and the private key to the second path
|
|
48
|
+
with mode 0600. It refuses a key path inside a git work tree or one that already
|
|
49
|
+
exists, and it never prints the key. Then:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
aws ssm put-parameter --profile oxy --region us-west-2 --type SecureString \
|
|
53
|
+
--name /oxy/oxy-api/UPDATES_CODE_SIGNING_PRIVATE_KEY \
|
|
54
|
+
--value file://$HOME/.config/oxy/oxy-updates-code-signing-private-key.b64
|
|
55
|
+
```
|
|
29
56
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
workflow syncs it to SSM `/oxy/oxy-api/UPDATES_CODE_SIGNING_PRIVATE_KEY`, and
|
|
33
|
-
oxy-api reads it in `services/updates/signing.service.ts`.
|
|
34
|
-
2. Commit **only** the certificate. The private key is never written to disk by
|
|
35
|
-
the script and must never enter the repo.
|
|
36
|
-
3. Clear the terminal scrollback.
|
|
57
|
+
`--value file://` keeps the key out of the shell history and the terminal.
|
|
58
|
+
Commit **only** the certificate.
|
|
37
59
|
|
|
38
|
-
Verify the server
|
|
39
|
-
stop returning HTTP 500.
|
|
60
|
+
Verify the server, after a deploy, with the key bound:
|
|
40
61
|
|
|
41
62
|
```bash
|
|
42
|
-
curl -s -o /dev/null
|
|
43
|
-
-H 'expo-protocol-version: 1' -H 'expo-platform:
|
|
44
|
-
-H 'expo-runtime-version: 1.
|
|
45
|
-
-H 'expo-expect-signature: sig, keyid="main", alg="rsa-v1_5-sha256"' \
|
|
63
|
+
curl -s -D - -o /dev/null \
|
|
64
|
+
-H 'expo-protocol-version: 1' -H 'expo-platform: android' \
|
|
65
|
+
-H 'expo-runtime-version: 1.3.0' -H 'expo-channel-name: production' \
|
|
46
66
|
https://api.oxy.so/updates/v1/apps/<clientId>/manifest
|
|
47
67
|
```
|
|
48
68
|
|
|
69
|
+
It must answer 200 (a 503 means the key is not bound), and the multipart part
|
|
70
|
+
must carry `expo-signature: sig="…", keyid="main"` that verifies against this
|
|
71
|
+
certificate. The deploy's post-deploy smoke checks exactly that.
|
|
72
|
+
|
|
49
73
|
## Rotation
|
|
50
74
|
|
|
51
75
|
The certificate is baked into a native binary at build time, so a rotation only
|
|
52
76
|
reaches devices that install a NEW binary carrying the new certificate. Rotate by
|
|
53
|
-
generating a new pair, shipping the new certificate in a store
|
|
54
|
-
|
|
55
|
-
|
|
77
|
+
generating a new pair to a NEW key path, shipping the new certificate in a store
|
|
78
|
+
release of every OTA app first (the plugin's `certificatePath` covers an overlap
|
|
79
|
+
where one binary must trust the incoming certificate early), and only switching
|
|
80
|
+
the SSM parameter once that release has taken over. Devices still on the old
|
|
81
|
+
binary reject manifests signed by the new key, and stop receiving updates.
|
|
82
|
+
|
|
83
|
+
Binaries built before this certificate was committed verify nothing (every
|
|
84
|
+
Commons build up to and including the 1.3.0 test builds; Accounts likewise).
|
|
85
|
+
Commons' first signed runtime is 1.4.0. Never publish an update for a runtime
|
|
86
|
+
version that only such binaries run: they would run it unverified.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
|
2
|
+
MIIC8zCCAdugAwIBAgIJNavjOrAeD36HMA0GCSqGSIb3DQEBCwUAMCMxITAfBgNV
|
|
3
|
+
BAMMGE94eSBVcGRhdGVzIENvZGUgU2lnbmluZzAeFw0yNjEwMjQyMzEzMzdaFw0z
|
|
4
|
+
NjEwMjQyMzEzMzdaMCMxITAfBgNVBAMMGE94eSBVcGRhdGVzIENvZGUgU2lnbmlu
|
|
5
|
+
ZzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALmY5biytPgR37i0MKhy
|
|
6
|
+
+3F7cr6tEQ0QpHV9XOZdXlMKWWZXM9tI8lv+apFL1jUdgRkLL/1WP+1IW6c8vz4W
|
|
7
|
+
GSVJSurKfe4uO8Chp7SLiDIM/aUDMfi++7iGV5GbJB8351XOSK6pw77keszjdjjW
|
|
8
|
+
U1lzwnWzl58Ok6XgwOT7Y9316FbCaNc4Zm6Zo/YA0elYCi1Bzg8xmPwEuE/pS6sD
|
|
9
|
+
+eyXc6i6ulaAPwTPdMkq95e/oKBkWsyHJPEVqaIZYnANB5ysJVYrHwm/6UiFOrlc
|
|
10
|
+
jGtQZ6Nd4b2tOvwLB2MXVo5V8ruOx1k9uR+SbzHV8CuBGjDT6tI3dHzP3WWFzznn
|
|
11
|
+
AN8CAwEAAaMqMCgwDgYDVR0PAQH/BAQDAgeAMBYGA1UdJQEB/wQMMAoGCCsGAQUF
|
|
12
|
+
BwMDMA0GCSqGSIb3DQEBCwUAA4IBAQA+n7UgCUqsZehbhnxQuo5rKTb2YVtjcJQ5
|
|
13
|
+
ju9G0N2MwCtCLW4Ra3zGqwSHm6vzRiGCTdU4vj05wSj0/4xWauQoV83Y72fWWixq
|
|
14
|
+
CqxM3rpscYBvOdpd98qU7Rfv32ROIcT7dU7GEcgRlasujOn9EPK3jdx/UjYxwZQB
|
|
15
|
+
k0AHchz8uNeEd0B2iGgQS9igcb57RI4C+D2gZlpb+BMPM5cNqefn2Dk1B0V3J2bv
|
|
16
|
+
A73yiP/9QoL3J1kIpToKafVwNI3yxkWPhz6VPN9dinkvseJHNF4AV+wRciRq1FlW
|
|
17
|
+
zrIo1oeMMhO5FEFMyo3FsPmtUvQVvw6y7TVpiiGzp5EcCv/C+q5r
|
|
18
|
+
-----END CERTIFICATE-----
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Refuse to put a workspace package's build output into a RELEASE bundle when
|
|
3
|
+
* it was not built from the sources the checkout holds.
|
|
4
|
+
*
|
|
5
|
+
* An app in this monorepo consumes `@oxy.so/core`, `@oxy.so/contracts`,
|
|
6
|
+
* `@oxy.so/protocol`, `@oxy.so/telemetry` and `@oxy.so/expo-splash` through
|
|
7
|
+
* their BUILT entry points (`dist/`), which nothing rebuilds when the checkout
|
|
8
|
+
* moves. Measured on Commons 1.3.0 (2026-10-25): the checkout was at the
|
|
9
|
+
* release commit but its `packages/contracts/dist` dated from five days
|
|
10
|
+
* earlier, written for Zod 3. `app/+native-intent.ts` imported
|
|
11
|
+
* `@oxy.so/contracts`, expo-router loads that file while it builds the linking
|
|
12
|
+
* config, and the stale `oauth.js` called `catalogToolSchema.innerType()` at
|
|
13
|
+
* module scope against Zod 4: `TypeError: undefined is not a function` on every
|
|
14
|
+
* launch. The bundle also carried a core from before the commit's own
|
|
15
|
+
* KeyManager changes. Nothing failed at build time; a phone found it.
|
|
16
|
+
*
|
|
17
|
+
* A package that opts in (`"oxySourceStamp": "dist"`, see `source-stamp.js`)
|
|
18
|
+
* writes a digest of its `src/` into its output at the end of every build. A
|
|
19
|
+
* release bundle (Metro `dev: false`, or NODE_ENV=production) that reaches that
|
|
20
|
+
* output fails when the stamp is missing or does not match the sources, naming
|
|
21
|
+
* the command that rebuilds it; a development bundle warns once. A package that
|
|
22
|
+
* does not opt in is only compared by mtime, and only ever warned about: an
|
|
23
|
+
* mtime cannot tell a checkout round trip from an edit.
|
|
24
|
+
*/
|
|
25
|
+
const fs = require('node:fs');
|
|
26
|
+
const path = require('node:path');
|
|
27
|
+
const { readStamp, sourceDigest, stampedOutputDir } = require('./source-stamp');
|
|
28
|
+
|
|
29
|
+
const OUTPUT_DIRS = new Set(['dist', 'lib', 'build']);
|
|
30
|
+
const IGNORED =
|
|
31
|
+
/(?:^|[/\\])(?:__tests__|__mocks__)(?:[/\\]|$)|\.(?:test|spec)\.[cm]?[jt]sx?$|\.md$/;
|
|
32
|
+
|
|
33
|
+
function newestMtime(dir, ignore) {
|
|
34
|
+
let newest = 0;
|
|
35
|
+
let newestFile = null;
|
|
36
|
+
const stack = [dir];
|
|
37
|
+
while (stack.length > 0) {
|
|
38
|
+
const current = stack.pop();
|
|
39
|
+
let entries;
|
|
40
|
+
try {
|
|
41
|
+
entries = fs.readdirSync(current, { withFileTypes: true });
|
|
42
|
+
} catch {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
for (const entry of entries) {
|
|
46
|
+
const full = path.join(current, entry.name);
|
|
47
|
+
if (ignore?.test(full)) continue;
|
|
48
|
+
if (entry.isDirectory()) {
|
|
49
|
+
if (entry.name !== 'node_modules') stack.push(full);
|
|
50
|
+
} else if (entry.isFile()) {
|
|
51
|
+
const { mtimeMs } = fs.statSync(full);
|
|
52
|
+
if (mtimeMs > newest) {
|
|
53
|
+
newest = mtimeMs;
|
|
54
|
+
newestFile = full;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return { newest, newestFile };
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Whether `packageDir/outputDir` was built from `packageDir/src` as it is now.
|
|
64
|
+
* `null` when it was (or there is nothing to compare); otherwise
|
|
65
|
+
* `{ stamped, reason }`, where `stamped` says the verdict is exact (a source
|
|
66
|
+
* stamp) rather than an mtime guess.
|
|
67
|
+
*/
|
|
68
|
+
function staleBuild(packageDir, outputDir) {
|
|
69
|
+
const srcDir = path.join(packageDir, 'src');
|
|
70
|
+
const outDir = path.join(packageDir, outputDir);
|
|
71
|
+
if (!fs.existsSync(srcDir) || !fs.existsSync(outDir)) return null;
|
|
72
|
+
|
|
73
|
+
if (stampedOutputDir(packageDir) === outputDir) {
|
|
74
|
+
const stamp = readStamp(packageDir, outputDir);
|
|
75
|
+
if (stamp === null) {
|
|
76
|
+
return {
|
|
77
|
+
stamped: true,
|
|
78
|
+
reason: `${outputDir}/ carries no source stamp (built before stamping)`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
if (stamp !== sourceDigest(packageDir)) {
|
|
82
|
+
return { stamped: true, reason: `src/ changed since ${outputDir}/ was built` };
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const source = newestMtime(srcDir, IGNORED);
|
|
88
|
+
const output = newestMtime(outDir, null);
|
|
89
|
+
if (source.newest > output.newest) {
|
|
90
|
+
return {
|
|
91
|
+
stamped: false,
|
|
92
|
+
reason: `${path.relative(packageDir, source.newestFile)} is newer than ${outputDir}/`,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @param {import('metro-config').MetroConfig} config
|
|
100
|
+
* @param {string} monorepoRoot
|
|
101
|
+
* @param {{ production?: boolean, warn?: (message: string) => void }} [deps] Test seams.
|
|
102
|
+
* @returns {import('metro-config').MetroConfig}
|
|
103
|
+
*/
|
|
104
|
+
function withFreshWorkspaceBuilds(config, monorepoRoot, deps = {}) {
|
|
105
|
+
// A release bundle: Metro's own `dev: false` (what `expo export:embed` in the
|
|
106
|
+
// Gradle/Xcode release task passes), or NODE_ENV=production.
|
|
107
|
+
const isProduction = (context) =>
|
|
108
|
+
deps.production ?? (context.dev === false || process.env.NODE_ENV === 'production');
|
|
109
|
+
const warn = deps.warn ?? ((message) => console.warn(message));
|
|
110
|
+
const packagesDir = `${path.resolve(monorepoRoot, 'packages')}${path.sep}`;
|
|
111
|
+
const parentResolveRequest = config.resolver.resolveRequest;
|
|
112
|
+
const verdicts = new Map();
|
|
113
|
+
const warned = new Set();
|
|
114
|
+
|
|
115
|
+
config.resolver.resolveRequest = (context, moduleName, platform) => {
|
|
116
|
+
const resolution = (parentResolveRequest ?? context.resolveRequest)(
|
|
117
|
+
context,
|
|
118
|
+
moduleName,
|
|
119
|
+
platform,
|
|
120
|
+
);
|
|
121
|
+
if (resolution?.type !== 'sourceFile') return resolution;
|
|
122
|
+
let filePath = resolution.filePath;
|
|
123
|
+
try {
|
|
124
|
+
filePath = fs.realpathSync(filePath);
|
|
125
|
+
} catch {
|
|
126
|
+
return resolution;
|
|
127
|
+
}
|
|
128
|
+
if (!filePath.startsWith(packagesDir)) return resolution;
|
|
129
|
+
const [packageName, outputDir] = filePath.slice(packagesDir.length).split(path.sep);
|
|
130
|
+
if (!packageName || !OUTPUT_DIRS.has(outputDir)) return resolution;
|
|
131
|
+
|
|
132
|
+
const key = `${packageName}/${outputDir}`;
|
|
133
|
+
if (!verdicts.has(key)) {
|
|
134
|
+
verdicts.set(key, staleBuild(path.join(packagesDir, packageName), outputDir));
|
|
135
|
+
}
|
|
136
|
+
const stale = verdicts.get(key);
|
|
137
|
+
if (!stale) return resolution;
|
|
138
|
+
|
|
139
|
+
const rebuild = `bunx turbo run build --filter=./packages/${packageName}`;
|
|
140
|
+
if (stale.stamped && isProduction(context)) {
|
|
141
|
+
throw new Error(
|
|
142
|
+
`[@oxy.so/app-preset/metro] refusing to bundle packages/${key}: ${stale.reason}. ` +
|
|
143
|
+
'A release would ship code this checkout does not contain. Run ' +
|
|
144
|
+
`\`${rebuild}\` (or \`bun run build:all\`) at the repository root, then build again.`,
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
if (!warned.has(key)) {
|
|
148
|
+
warned.add(key);
|
|
149
|
+
warn(
|
|
150
|
+
`[@oxy.so/app-preset/metro] packages/${key} may be out of date: ${stale.reason}; ` +
|
|
151
|
+
`run \`${rebuild}\`.`,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
return resolution;
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
return config;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
module.exports = { withFreshWorkspaceBuilds, staleBuild };
|
package/metro/index.js
CHANGED
|
@@ -49,6 +49,8 @@ const path = require('node:path');
|
|
|
49
49
|
const { resolveOxyBuildId } = require('../build-id');
|
|
50
50
|
const { requireFromProject } = require('../plugin/requireFromProject');
|
|
51
51
|
const { withStaticHydrationBoundary } = require('./static-hydration/resolver');
|
|
52
|
+
const { withLinkedNativePackagesOnly } = require('./linked-native-packages');
|
|
53
|
+
const { withFreshWorkspaceBuilds } = require('./fresh-workspace-builds');
|
|
52
54
|
|
|
53
55
|
function escapeRegExp(value) {
|
|
54
56
|
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
@@ -391,6 +393,16 @@ function createOxyMetroConfigWithBloom(projectRoot, options = {}) {
|
|
|
391
393
|
let config = withBloomSingleInstance(nativeWindConfig, projectRoot);
|
|
392
394
|
if (staticHydrationBoundary) config = withStaticHydrationBoundary(config, projectRoot);
|
|
393
395
|
if (workletsBundleMode) config = withWorkletsBundleMode(config, projectRoot);
|
|
396
|
+
// Sees every resolution but the complete-react-native module's own two
|
|
397
|
+
// imports: an optional probe for a native package autolinking does not link
|
|
398
|
+
// is answered "not found" (see the module header for the launch crash).
|
|
399
|
+
config = withLinkedNativePackagesOnly(config, projectRoot);
|
|
400
|
+
// A production bundle never ships a workspace package's build output that is
|
|
401
|
+
// older than its sources (the same launch crash, second cause).
|
|
402
|
+
config = withFreshWorkspaceBuilds(
|
|
403
|
+
config,
|
|
404
|
+
options.workspaceRoot ? path.resolve(options.workspaceRoot) : findWorkspaceRoot(projectRoot),
|
|
405
|
+
);
|
|
394
406
|
// Outermost, so it sees the final resolution and its own module's imports
|
|
395
407
|
// reach no redirect beneath it.
|
|
396
408
|
return withCompleteReactNative(config, projectRoot);
|
|
@@ -401,4 +413,6 @@ module.exports = {
|
|
|
401
413
|
findWorkspaceRoot,
|
|
402
414
|
withBloomSingleInstance,
|
|
403
415
|
withCompleteReactNative,
|
|
416
|
+
withLinkedNativePackagesOnly,
|
|
417
|
+
withFreshWorkspaceBuilds,
|
|
404
418
|
};
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keep native packages the build does not link out of the bundle's OPTIONAL
|
|
3
|
+
* requires.
|
|
4
|
+
*
|
|
5
|
+
* An optional require (`try { require('x') } catch {}`, an `import()` in a
|
|
6
|
+
* `try`) is how libraries probe for an optional peer: expo-router probes for
|
|
7
|
+
* `@expo/ui`, @oxy.so/protocol for `expo-crypto`, @oxy.so/services for
|
|
8
|
+
* `expo-clipboard`. Metro resolves the probe against whatever is on disk. Expo
|
|
9
|
+
* autolinking decides what native code the binary carries by a different rule:
|
|
10
|
+
* the app's dependencies and devDependencies, then, recursively, each
|
|
11
|
+
* package's dependencies and NON-optional peers. When the two disagree, the JS
|
|
12
|
+
* of a package whose native half is not in the binary is bundled, the probe
|
|
13
|
+
* succeeds, and that JS runs against native code that is not there.
|
|
14
|
+
*
|
|
15
|
+
* Measured on Commons 1.3.0 (2026-10-25): a checkout's bun store kept a stale
|
|
16
|
+
* `node_modules/.bun/node_modules/@expo/ui` (@expo/ui 57.0.17, from an old
|
|
17
|
+
* install, absent from bun.lock). Node's resolution walks up into that hoisted
|
|
18
|
+
* fallback, so expo-router's `@expo/ui/jetpack-compose` probe found it, the
|
|
19
|
+
* SDK 57 JS ran its side effects against an SDK 58 binary that never linked
|
|
20
|
+
* it, and the release crashed on launch (`Exception in HostFunction:
|
|
21
|
+
* ... getClass() on a null object reference`, then `TypeError: undefined is not
|
|
22
|
+
* a function`). A clean install has no such file and the same commit ran.
|
|
23
|
+
*
|
|
24
|
+
* So an optional request that resolves into a native package autolinking will
|
|
25
|
+
* not link is answered "not found", which is what the probe sees on a clean
|
|
26
|
+
* install: the library takes its documented fallback. Non-optional requests
|
|
27
|
+
* are left alone (a static import of an unlinked native package is reported
|
|
28
|
+
* once as a warning, not turned into a build failure), so this never changes
|
|
29
|
+
* what an app that builds today bundles, except for those probes.
|
|
30
|
+
*/
|
|
31
|
+
const fs = require('node:fs');
|
|
32
|
+
const path = require('node:path');
|
|
33
|
+
const Module = require('node:module');
|
|
34
|
+
|
|
35
|
+
/** Expo autolinking's own recursion limit (`resolution.js` MAX_DEPTH). */
|
|
36
|
+
const MAX_DEPTH = 9;
|
|
37
|
+
|
|
38
|
+
function readJson(file) {
|
|
39
|
+
try {
|
|
40
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function realpathOrNull(target) {
|
|
47
|
+
try {
|
|
48
|
+
return fs.realpathSync(target);
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function isOptionalPeer(manifest, name) {
|
|
55
|
+
const meta = manifest.peerDependenciesMeta;
|
|
56
|
+
return Boolean(meta?.[name]?.optional);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The names Expo autolinking links for the app at `projectRoot`, computed by
|
|
61
|
+
* the rules of expo-modules-autolinking 58 (`dependencies/resolution.js`): the
|
|
62
|
+
* app's dependencies + devDependencies, then each package's dependencies and
|
|
63
|
+
* non-optional peers, resolved through the node_modules chain of the package
|
|
64
|
+
* that declares them, to depth {@link MAX_DEPTH}.
|
|
65
|
+
*
|
|
66
|
+
* @param {string} projectRoot
|
|
67
|
+
* @returns {Set<string>}
|
|
68
|
+
*/
|
|
69
|
+
function computeLinkedPackageNames(projectRoot) {
|
|
70
|
+
const linked = new Set();
|
|
71
|
+
const shallowestDepth = new Map();
|
|
72
|
+
|
|
73
|
+
const visit = (packageDir, depth) => {
|
|
74
|
+
const seen = shallowestDepth.get(packageDir);
|
|
75
|
+
if (seen !== undefined && seen <= depth) return;
|
|
76
|
+
shallowestDepth.set(packageDir, depth);
|
|
77
|
+
const manifest = readJson(path.join(packageDir, 'package.json'));
|
|
78
|
+
if (!manifest || depth >= MAX_DEPTH) return;
|
|
79
|
+
|
|
80
|
+
const names = new Set(Object.keys(manifest.dependencies || {}));
|
|
81
|
+
if (depth === 0) {
|
|
82
|
+
for (const name of Object.keys(manifest.devDependencies || {})) names.add(name);
|
|
83
|
+
}
|
|
84
|
+
for (const name of Object.keys(manifest.peerDependencies || {})) {
|
|
85
|
+
if (!isOptionalPeer(manifest, name)) names.add(name);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const lookupDirs = Module._nodeModulePaths(packageDir);
|
|
89
|
+
for (const name of names) {
|
|
90
|
+
for (const dir of lookupDirs) {
|
|
91
|
+
const resolved = realpathOrNull(path.join(dir, name));
|
|
92
|
+
if (resolved) {
|
|
93
|
+
linked.add(name);
|
|
94
|
+
visit(resolved, depth + 1);
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const root = realpathOrNull(projectRoot);
|
|
102
|
+
if (root) visit(root, 0);
|
|
103
|
+
return linked;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The package a file belongs to: the nearest ancestor `package.json` that has
|
|
108
|
+
* a `name` (a nested `{"type":"module"}` manifest has none and is skipped).
|
|
109
|
+
*/
|
|
110
|
+
function createPackageLookup() {
|
|
111
|
+
const cache = new Map();
|
|
112
|
+
return function packageOf(filePath) {
|
|
113
|
+
let dir = path.dirname(filePath);
|
|
114
|
+
const visited = [];
|
|
115
|
+
let found = null;
|
|
116
|
+
for (;;) {
|
|
117
|
+
if (cache.has(dir)) {
|
|
118
|
+
found = cache.get(dir);
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
visited.push(dir);
|
|
122
|
+
const manifest = readJson(path.join(dir, 'package.json'));
|
|
123
|
+
if (manifest && typeof manifest.name === 'string') {
|
|
124
|
+
found = { name: manifest.name, version: manifest.version, dir };
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
const parent = path.dirname(dir);
|
|
128
|
+
if (parent === dir) break;
|
|
129
|
+
dir = parent;
|
|
130
|
+
}
|
|
131
|
+
for (const entry of visited) cache.set(entry, found);
|
|
132
|
+
return found;
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** True when a package carries native code autolinking would have to link. */
|
|
137
|
+
function createNativeCheck() {
|
|
138
|
+
const cache = new Map();
|
|
139
|
+
return function isNativePackage(pkg) {
|
|
140
|
+
if (!cache.has(pkg.dir)) {
|
|
141
|
+
cache.set(
|
|
142
|
+
pkg.dir,
|
|
143
|
+
fs.existsSync(path.join(pkg.dir, 'expo-module.config.json')) ||
|
|
144
|
+
fs.existsSync(path.join(pkg.dir, 'android', 'build.gradle')) ||
|
|
145
|
+
fs.existsSync(path.join(pkg.dir, 'android', 'build.gradle.kts')),
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return cache.get(pkg.dir);
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Wrap `config.resolver.resolveRequest` so an OPTIONAL request on a native
|
|
154
|
+
* platform that resolves into a native package autolinking does not link
|
|
155
|
+
* throws, which Metro records as a missing optional dependency.
|
|
156
|
+
*
|
|
157
|
+
* @param {import('metro-config').MetroConfig} config
|
|
158
|
+
* @param {string} projectRoot
|
|
159
|
+
* @param {{ computeLinked?: (projectRoot: string) => Set<string>, warn?: (message: string) => void }} [deps]
|
|
160
|
+
* Test seams.
|
|
161
|
+
* @returns {import('metro-config').MetroConfig}
|
|
162
|
+
*/
|
|
163
|
+
function withLinkedNativePackagesOnly(config, projectRoot, deps = {}) {
|
|
164
|
+
const computeLinked = deps.computeLinked ?? computeLinkedPackageNames;
|
|
165
|
+
const warn = deps.warn ?? ((message) => console.warn(message));
|
|
166
|
+
const parentResolveRequest = config.resolver.resolveRequest;
|
|
167
|
+
const packageOf = createPackageLookup();
|
|
168
|
+
const isNativePackage = createNativeCheck();
|
|
169
|
+
const reported = new Set();
|
|
170
|
+
let linked = null;
|
|
171
|
+
|
|
172
|
+
config.resolver.resolveRequest = (context, moduleName, platform) => {
|
|
173
|
+
const resolution = (parentResolveRequest ?? context.resolveRequest)(
|
|
174
|
+
context,
|
|
175
|
+
moduleName,
|
|
176
|
+
platform,
|
|
177
|
+
);
|
|
178
|
+
if (platform === 'web' || resolution?.type !== 'sourceFile') return resolution;
|
|
179
|
+
const pkg = packageOf(resolution.filePath);
|
|
180
|
+
if (!pkg || !isNativePackage(pkg)) return resolution;
|
|
181
|
+
linked ??= computeLinked(projectRoot);
|
|
182
|
+
if (linked.has(pkg.name)) return resolution;
|
|
183
|
+
|
|
184
|
+
const optional = context.dependency?.data?.isOptional === true;
|
|
185
|
+
const key = `${pkg.name}@${pkg.version}`;
|
|
186
|
+
if (optional) {
|
|
187
|
+
if (!reported.has(`optional:${key}`)) {
|
|
188
|
+
reported.add(`optional:${key}`);
|
|
189
|
+
warn(
|
|
190
|
+
`[@oxy.so/app-preset/metro] left ${key} out of an optional require ` +
|
|
191
|
+
`('${moduleName}'): it has native code this build does not autolink ` +
|
|
192
|
+
'(not a dependency of the app, nor a non-optional dependency of one). ' +
|
|
193
|
+
`Found at ${pkg.dir}.`,
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
throw new Error(
|
|
197
|
+
`${moduleName} resolves to ${key}, a native package this build does not link`,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
if (!reported.has(`static:${key}`)) {
|
|
201
|
+
reported.add(`static:${key}`);
|
|
202
|
+
warn(
|
|
203
|
+
`[@oxy.so/app-preset/metro] ${key} is bundled ('${moduleName}') but has native code ` +
|
|
204
|
+
'this build does not autolink; declare it as a dependency of the app.',
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
return resolution;
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
return config;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
module.exports = { withLinkedNativePackagesOnly, computeLinkedPackageNames };
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* The source stamp: a digest of a workspace package's `src/`, written into its
|
|
4
|
+
* build output by its build, and checked by the Metro guard
|
|
5
|
+
* (`fresh-workspace-builds.js`) before a release bundle uses that output.
|
|
6
|
+
*
|
|
7
|
+
* Content, not mtimes: a `git checkout` there and back gives the sources new
|
|
8
|
+
* mtimes without changing them, and turbo then (correctly) replays its cache
|
|
9
|
+
* without rewriting the output, so an mtime comparison would refuse a build
|
|
10
|
+
* that is fine and name a command (`build:all`) that cannot fix it.
|
|
11
|
+
*
|
|
12
|
+
* A package opts in with `"oxySourceStamp": "<output dir>"` in its
|
|
13
|
+
* package.json and, last in its `build` (cwd = the package), calls
|
|
14
|
+
* `writeStamp(process.cwd())` from this file when the file is there:
|
|
15
|
+
*
|
|
16
|
+
* node -e "const p='../app-preset/metro/source-stamp.js';require('node:fs').existsSync(p)&&require(p).writeStamp(process.cwd())"
|
|
17
|
+
*
|
|
18
|
+
* The guard is for builds that never reach Metro: the API and node Docker
|
|
19
|
+
* images copy only the packages they build, not app-preset, and a missing
|
|
20
|
+
* stamp only matters to a Metro release bundle, which then refuses it. The
|
|
21
|
+
* stamp is `<output dir>/.oxy-source-digest`.
|
|
22
|
+
*/
|
|
23
|
+
const crypto = require('node:crypto');
|
|
24
|
+
const fs = require('node:fs');
|
|
25
|
+
const path = require('node:path');
|
|
26
|
+
|
|
27
|
+
const STAMP_FILE = '.oxy-source-digest';
|
|
28
|
+
|
|
29
|
+
/** Not part of what a build compiles: tests, mocks, docs. */
|
|
30
|
+
const IGNORED =
|
|
31
|
+
/(?:^|[/\\])(?:__tests__|__mocks__)(?:[/\\]|$)|\.(?:test|spec)\.[cm]?[jt]sx?$|\.md$/;
|
|
32
|
+
|
|
33
|
+
function listFiles(dir) {
|
|
34
|
+
const out = [];
|
|
35
|
+
const stack = [dir];
|
|
36
|
+
while (stack.length > 0) {
|
|
37
|
+
const current = stack.pop();
|
|
38
|
+
for (const entry of fs.readdirSync(current, { withFileTypes: true })) {
|
|
39
|
+
const full = path.join(current, entry.name);
|
|
40
|
+
if (IGNORED.test(full)) continue;
|
|
41
|
+
if (entry.isDirectory()) {
|
|
42
|
+
if (entry.name !== 'node_modules') stack.push(full);
|
|
43
|
+
} else if (entry.isFile()) {
|
|
44
|
+
out.push(full);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** sha256 over every source file's relative path and bytes, in a stable order. */
|
|
52
|
+
function sourceDigest(packageDir) {
|
|
53
|
+
const srcDir = path.join(packageDir, 'src');
|
|
54
|
+
const files = listFiles(srcDir)
|
|
55
|
+
.map((file) => path.relative(srcDir, file).split(path.sep).join('/'))
|
|
56
|
+
.sort();
|
|
57
|
+
const hash = crypto.createHash('sha256');
|
|
58
|
+
for (const relative of files) {
|
|
59
|
+
hash.update(relative);
|
|
60
|
+
hash.update('\0');
|
|
61
|
+
hash.update(fs.readFileSync(path.join(srcDir, relative)));
|
|
62
|
+
hash.update('\0');
|
|
63
|
+
}
|
|
64
|
+
return hash.digest('hex');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The output directory a package stamps, or `null` when it does not opt in. */
|
|
68
|
+
function stampedOutputDir(packageDir) {
|
|
69
|
+
try {
|
|
70
|
+
const manifest = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8'));
|
|
71
|
+
return typeof manifest.oxySourceStamp === 'string' ? manifest.oxySourceStamp : null;
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function readStamp(packageDir, outputDir) {
|
|
78
|
+
try {
|
|
79
|
+
return fs.readFileSync(path.join(packageDir, outputDir, STAMP_FILE), 'utf8').trim();
|
|
80
|
+
} catch {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function writeStamp(packageDir) {
|
|
86
|
+
const outputDir = stampedOutputDir(packageDir);
|
|
87
|
+
if (!outputDir) {
|
|
88
|
+
throw new Error(`${packageDir}/package.json declares no "oxySourceStamp" output directory`);
|
|
89
|
+
}
|
|
90
|
+
fs.mkdirSync(path.join(packageDir, outputDir), { recursive: true });
|
|
91
|
+
fs.writeFileSync(path.join(packageDir, outputDir, STAMP_FILE), `${sourceDigest(packageDir)}\n`);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (require.main === module) {
|
|
95
|
+
writeStamp(process.cwd());
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports = { STAMP_FILE, sourceDigest, stampedOutputDir, readStamp, writeStamp };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxy.so/app-preset",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.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": {
|
package/plugin/withOxyUpdates.js
CHANGED
|
@@ -39,12 +39,14 @@
|
|
|
39
39
|
* (`certs/oxy-updates-code-signing.pem`) rather than copied into every app repo,
|
|
40
40
|
* so a key rotation is one preset bump instead of thirteen.
|
|
41
41
|
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* certificate is baked into the native build
|
|
46
|
-
*
|
|
47
|
-
*
|
|
42
|
+
* **It fails closed.** The default is `codeSigning: 'require'`: a build whose
|
|
43
|
+
* certificate is missing or is not a PEM certificate throws, because a binary
|
|
44
|
+
* built without it can never verify a manifest signature for its whole lifetime
|
|
45
|
+
* (the certificate is baked into the native build) and would run whatever an
|
|
46
|
+
* attacker between it and the server sent. The server side matches: oxy-api
|
|
47
|
+
* signs every manifest and directive and serves nothing without its key.
|
|
48
|
+
* `'auto'` (warn when absent) and `false` (no verification) exist for local
|
|
49
|
+
* development only and must be asked for explicitly.
|
|
48
50
|
*
|
|
49
51
|
* @param {import('expo/config').ExpoConfig} config
|
|
50
52
|
* @param {object} options
|
|
@@ -52,9 +54,10 @@
|
|
|
52
54
|
* (`oxy_dk_...`) identifying this app to the update server. Required.
|
|
53
55
|
* @param {string} [options.apiOrigin='https://api.oxy.so'] Origin serving `/updates/v1`.
|
|
54
56
|
* @param {string} [options.channel='production'] Release channel this binary tracks.
|
|
55
|
-
* @param {'
|
|
56
|
-
*
|
|
57
|
-
*
|
|
57
|
+
* @param {'require'|'auto'|false} [options.codeSigning='require'] `require`
|
|
58
|
+
* throws unless a valid certificate is present; `auto` (development only)
|
|
59
|
+
* wires signing when present and warns when not; `false` (development only)
|
|
60
|
+
* skips verification entirely.
|
|
58
61
|
* @param {string} [options.certificatePath] Absolute path to a different
|
|
59
62
|
* certificate than the bundled one. Normally unset; it exists for the overlap
|
|
60
63
|
* window of a key rotation, where one binary has to trust an incoming
|
|
@@ -92,7 +95,7 @@ module.exports = function withOxyUpdates(config, options = {}) {
|
|
|
92
95
|
clientId,
|
|
93
96
|
apiOrigin = DEFAULT_API_ORIGIN,
|
|
94
97
|
channel = DEFAULT_CHANNEL,
|
|
95
|
-
codeSigning = '
|
|
98
|
+
codeSigning = 'require',
|
|
96
99
|
certificatePath = CERTIFICATE_PATH,
|
|
97
100
|
runtimeVersionPolicy = 'appVersion',
|
|
98
101
|
} = options;
|
|
@@ -117,8 +120,29 @@ module.exports = function withOxyUpdates(config, options = {}) {
|
|
|
117
120
|
updates.url = `${origin}/updates/v1/apps/${clientId}/manifest`;
|
|
118
121
|
updates.requestHeaders = { ...updates.requestHeaders, 'expo-channel-name': channel };
|
|
119
122
|
|
|
123
|
+
if (codeSigning !== false && codeSigning !== 'auto' && codeSigning !== 'require') {
|
|
124
|
+
throw new Error(
|
|
125
|
+
`[${PLUGIN_NAME}] \`codeSigning\` must be 'require' (the default), 'auto' or false; got ` +
|
|
126
|
+
`${JSON.stringify(codeSigning)}.`,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
120
130
|
if (codeSigning !== false) {
|
|
121
|
-
|
|
131
|
+
const certificate = fs.existsSync(certificatePath)
|
|
132
|
+
? fs.readFileSync(certificatePath, 'utf8')
|
|
133
|
+
: null;
|
|
134
|
+
if (
|
|
135
|
+
certificate !== null &&
|
|
136
|
+
!/-----BEGIN CERTIFICATE-----[\s\S]+-----END CERTIFICATE-----/.test(certificate)
|
|
137
|
+
) {
|
|
138
|
+
// Never wire a file expo-updates cannot parse: the binary would fail every
|
|
139
|
+
// update check, or worse, a later native change could treat it as absent.
|
|
140
|
+
throw new Error(
|
|
141
|
+
`[${PLUGIN_NAME}] ${certificatePath} is not a PEM certificate. It must be the PUBLIC ` +
|
|
142
|
+
'certificate written by oxy-api `scripts/generate-updates-code-signing.ts`.',
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
if (certificate !== null) {
|
|
122
146
|
const projectRoot = config._internal?.projectRoot;
|
|
123
147
|
if (typeof projectRoot !== 'string') {
|
|
124
148
|
throw new Error(
|
|
@@ -133,10 +157,11 @@ module.exports = function withOxyUpdates(config, options = {}) {
|
|
|
133
157
|
updates.codeSigningMetadata = { keyid: CODE_SIGNING_KEY_ID, alg: CODE_SIGNING_ALG };
|
|
134
158
|
} else if (codeSigning === 'require') {
|
|
135
159
|
throw new Error(
|
|
136
|
-
`[${PLUGIN_NAME}]
|
|
137
|
-
`${certificatePath}
|
|
138
|
-
'
|
|
139
|
-
'
|
|
160
|
+
`[${PLUGIN_NAME}] the Oxy Updates code-signing certificate is missing at ` +
|
|
161
|
+
`${certificatePath}, and an OTA-enabled build without it would accept unsigned ` +
|
|
162
|
+
'updates for its whole lifetime. Use an @oxy.so/app-preset that ships ' +
|
|
163
|
+
'`certs/oxy-updates-code-signing.pem` (see certs/README.md). For a local development ' +
|
|
164
|
+
"build only, pass `{ codeSigning: 'auto' }` or `{ codeSigning: false }`.",
|
|
140
165
|
);
|
|
141
166
|
} else {
|
|
142
167
|
const warning =
|