@oxy.so/app-preset 4.1.0 → 5.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 +52 -18
- 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 +3 -3
- package/plugin/requireFromProject.js +14 -6
- package/plugin/withOxyAndroidRelease.js +15 -122
- package/plugin/withOxyAppPreset.js +18 -3
- package/plugin/withOxyR8Optimize.js +40 -0
package/README.md
CHANGED
|
@@ -14,8 +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` |
|
|
18
|
-
| Android release build | `@oxy.so/app-preset/plugin/withOxyAndroidRelease` | R8 `-optimize` ProGuard file + shared-keystore release signing (opt-in, see below) |
|
|
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 |
|
|
19
18
|
| Android WebP resources | `@oxy.so/app-preset/plugin/withOxyAndroidWebp` | re-encoding generated mipmaps/splash bitmaps to real lossless WebP (opt-in, needs `sharp`) |
|
|
20
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) |
|
|
21
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 |
|
|
@@ -120,17 +119,61 @@ react-native's `Image` renders nothing for it, with no error. The keys exist fro
|
|
|
120
119
|
`expo-build-properties` 58 (Expo SDK 58); older versions ignore them silently.
|
|
121
120
|
|
|
122
121
|
The `sharedUserId` and `sharedIdentityReader` options were removed in 3.0.0 and
|
|
123
|
-
throw if passed. `@oxy.so/services`
|
|
122
|
+
throw if passed. `@oxy.so/services` 13.4.0+ is a required peer (the preset refuses an older one: it would declare the permissions without release signing).
|
|
124
123
|
|
|
125
124
|
`webgpu: true` (opt-in, 3.2.0+) also applies `react-native-webgpu`'s config
|
|
126
125
|
plugin, for an app that draws with WebGPU on native. Install
|
|
127
126
|
`react-native-webgpu` in the app first; the option throws without it.
|
|
128
127
|
|
|
129
|
-
#### Android release
|
|
128
|
+
#### Android release signing (always on, fails closed)
|
|
129
|
+
|
|
130
|
+
Every Oxy Android release is signed with the ONE ecosystem key (certificate
|
|
131
|
+
SHA-256 `b8ab3746466ce4569d7a6a0ffa1eed91bc375174d503613987ca09cb33d6a58d`,
|
|
132
|
+
alias `oxy`). It is not a preset plugin: `@oxy.so/services/plugins/withOxySharedPermissions`
|
|
133
|
+
applies `withOxyReleaseSigning` (services 13.4.0+), because the signature
|
|
134
|
+
permissions it declares are what make the certificate load-bearing. A release
|
|
135
|
+
signed with anything else takes ownership of `so.oxy.permission.IDENTITY` /
|
|
136
|
+
`DEVICE_SESSION`, after which every correctly signed Oxy app fails to install
|
|
137
|
+
(`INSTALL_FAILED_DUPLICATE_PERMISSION`), and Commons refuses it. So every app
|
|
138
|
+
that declares the permissions, through the preset or directly, gets the rule;
|
|
139
|
+
**list no signing plugin**.
|
|
140
|
+
|
|
141
|
+
The keystore comes from Gradle properties (`~/.gradle/gradle.properties`, `-P`,
|
|
142
|
+
or `ORG_GRADLE_PROJECT_<name>` environment variables), never from the repo:
|
|
143
|
+
|
|
144
|
+
```properties
|
|
145
|
+
OXY_UPLOAD_STORE_FILE=~/.config/oxy/oxy-ecosystem-release.keystore
|
|
146
|
+
OXY_UPLOAD_STORE_PASSWORD_FILE=~/.config/oxy/oxy-ecosystem-release-keystore.pass
|
|
147
|
+
OXY_UPLOAD_KEY_ALIAS=oxy
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
`OXY_UPLOAD_STORE_PASSWORD` takes the password itself instead of a file;
|
|
151
|
+
`OXY_UPLOAD_KEY_PASSWORD` (or `_FILE`) is needed only when the key's password
|
|
152
|
+
differs from the store's. `~/` is expanded, a password file is trimmed.
|
|
153
|
+
|
|
154
|
+
Release always uses `signingConfigs.release`; nothing falls back to the debug
|
|
155
|
+
key. A task, `oxyVerifyReleaseSigning`, runs before every release variant
|
|
156
|
+
(`pre…ReleaseBuild`, `validateSigning…Release`, so `assembleRelease`,
|
|
157
|
+
`bundleRelease`, `expo run:android --variant release` and EAS's release
|
|
158
|
+
builds) and fails the build, saying how to provide the key, unless the release
|
|
159
|
+
buildType's EFFECTIVE signing config opens and its certificate is the ecosystem
|
|
160
|
+
one. It checks the outcome, not the properties, so it also refuses EAS-managed
|
|
161
|
+
or per-app keys and a wrong alias. Debug builds never run it. There is no
|
|
162
|
+
opt-out for release.
|
|
163
|
+
|
|
164
|
+
Debug builds keep Expo's debug key unless `OXY_UPLOAD_SIGN_DEBUG=true` is set:
|
|
165
|
+
then debug is signed with the same key and checked by the same task, so a dev
|
|
166
|
+
client can be installed next to real Oxy apps and be granted the permissions
|
|
167
|
+
(this replaces Willo's `withOxyDebugSigning`, which prebuild now refuses). An app
|
|
168
|
+
that declares no Oxy permission (Authenticator) lists
|
|
169
|
+
`@oxy.so/services/plugins/withOxyReleaseSigning` directly for the same release
|
|
170
|
+
signing.
|
|
130
171
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
172
|
+
`withOxyAndroidRelease` was removed in 5.0.0; listing it throws and says to delete it.
|
|
173
|
+
|
|
174
|
+
#### Android WebP resources (opt-in)
|
|
175
|
+
|
|
176
|
+
`withOxyAndroidWebp` needs `sharp` installed, so it is registered explicitly:
|
|
134
177
|
|
|
135
178
|
```js
|
|
136
179
|
plugins: [
|
|
@@ -138,17 +181,9 @@ plugins: [
|
|
|
138
181
|
// order, and this has to run after every image generator (splash included).
|
|
139
182
|
'@oxy.so/app-preset/plugin/withOxyAndroidWebp',
|
|
140
183
|
// …app-specific plugins…
|
|
141
|
-
'@oxy.so/app-preset/plugin/withOxyAndroidRelease',
|
|
142
184
|
]
|
|
143
185
|
```
|
|
144
186
|
|
|
145
|
-
`withOxyAndroidRelease` reads the release keystore from four Gradle properties
|
|
146
|
-
(`OXY_UPLOAD_STORE_FILE`, `OXY_UPLOAD_STORE_PASSWORD`, `OXY_UPLOAD_KEY_ALIAS`,
|
|
147
|
-
`OXY_UPLOAD_KEY_PASSWORD`) in `~/.gradle/gradle.properties` or CI secrets — never
|
|
148
|
-
from the repo. When they are absent the release buildType falls back to the debug
|
|
149
|
-
keystore, so **always verify the artefact's certificate** (`keytool -printcert
|
|
150
|
-
-jarfile <aab>`, `apksigner verify --print-certs <apk>`) instead of assuming.
|
|
151
|
-
|
|
152
187
|
`withOxyAndroidWebp` requires `sharp` as a devDependency of the app.
|
|
153
188
|
|
|
154
189
|
#### Oxy Updates (OTA) (opt-in)
|
|
@@ -336,6 +371,5 @@ Requires **Expo SDK 56+**; validated against **Expo SDK 58 / React Native 0.88**
|
|
|
336
371
|
(the current Oxy ecosystem target) with a clean `expo prebuild` of `test-app-expo`,
|
|
337
372
|
`accounts` and `commons` (Android and iOS). SDK 58's Android template already
|
|
338
373
|
uses `proguard-android-optimize.txt` and turns R8 on through `gradle.properties`
|
|
339
|
-
(`android.enableMinifyInReleaseBuilds`), so
|
|
340
|
-
only
|
|
341
|
-
`-optimize` ProGuard file.
|
|
374
|
+
(`android.enableMinifyInReleaseBuilds`), so the preset's `-optimize` ProGuard
|
|
375
|
+
swap only changes anything on SDK 56/57.
|
|
@@ -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": "
|
|
3
|
+
"version": "5.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": {
|
|
@@ -62,10 +62,10 @@
|
|
|
62
62
|
"scripts": {
|
|
63
63
|
"test": "node --test __tests__/*.test.js"
|
|
64
64
|
},
|
|
65
|
-
"//peerDependencies": "THE TWO @oxy.so PEERS ARE DELIBERATE. This package couples to them by FILE PATH, not by API: `css/base.css` imports `@oxy.so/bloom/design-tokens/theme.css`, and `plugin/withOxyAppPreset.js` requires `@oxy.so/services/plugins/withOxySharedPermissions` (services
|
|
65
|
+
"//peerDependencies": "THE TWO @oxy.so PEERS ARE DELIBERATE. This package couples to them by FILE PATH, not by API: `css/base.css` imports `@oxy.so/bloom/design-tokens/theme.css`, and `plugin/withOxyAppPreset.js` requires `@oxy.so/services/plugins/withOxySharedPermissions` together with the `withOxyReleaseSigning` it applies (services 13.4.0+, the first release whose permissions plugin signs and checks the release; the floor is that release). Both peers retain a measured floor and are deliberately OPEN-ENDED above it: Oxy apps always run the latest Bloom and Services, so a new release of either must never need a preset release first. A release that breaks this package's file-path coupling is caught by its own tests and the apps' CI, not by a cap. Never replace either constraint with `*`.",
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"@oxy.so/bloom": "^2.0.0 || ^3.0.0 || ^4.2.0 || ^5.1.0 || >=6.0.0",
|
|
68
|
-
"@oxy.so/services": ">=
|
|
68
|
+
"@oxy.so/services": ">=13.4.0",
|
|
69
69
|
"babel-preset-expo": "*",
|
|
70
70
|
"eslint": ">=9.0.0",
|
|
71
71
|
"eslint-config-expo": "*",
|
|
@@ -12,16 +12,24 @@
|
|
|
12
12
|
* @param {string | undefined} projectRoot The app's directory.
|
|
13
13
|
*/
|
|
14
14
|
function requireFromProject(specifier, projectRoot) {
|
|
15
|
+
return require(resolveFromProject(specifier, projectRoot));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* The file `requireFromProject` would load, resolved the same way.
|
|
20
|
+
*
|
|
21
|
+
* @param {string} specifier
|
|
22
|
+
* @param {string | undefined} projectRoot
|
|
23
|
+
*/
|
|
24
|
+
function resolveFromProject(specifier, projectRoot) {
|
|
15
25
|
if (projectRoot) {
|
|
16
|
-
let resolved;
|
|
17
26
|
try {
|
|
18
|
-
|
|
27
|
+
return require.resolve(specifier, { paths: [projectRoot] });
|
|
19
28
|
} catch {
|
|
20
|
-
|
|
29
|
+
// Fall through to the preset's own resolution.
|
|
21
30
|
}
|
|
22
|
-
if (resolved) return require(resolved);
|
|
23
31
|
}
|
|
24
|
-
return require(specifier);
|
|
32
|
+
return require.resolve(specifier);
|
|
25
33
|
}
|
|
26
34
|
|
|
27
35
|
/**
|
|
@@ -34,4 +42,4 @@ function projectRootOf(config) {
|
|
|
34
42
|
return config?._internal?.projectRoot ?? process.cwd();
|
|
35
43
|
}
|
|
36
44
|
|
|
37
|
-
module.exports = { requireFromProject, projectRootOf };
|
|
45
|
+
module.exports = { requireFromProject, resolveFromProject, projectRootOf };
|
|
@@ -1,127 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Removed in `@oxy.so/app-preset` 5.0.0. It stays only to fail with the fix
|
|
3
|
+
* instead of an unresolvable module path; it does nothing else.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* `
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* `android/` is gitignored and regenerated by `expo prebuild`, so these edits
|
|
11
|
-
* have to live in a plugin or they are lost on the next prebuild.
|
|
12
|
-
*
|
|
13
|
-
* 1. R8 optimization passes
|
|
14
|
-
* Expo generates `getDefaultProguardFile("proguard-android.txt")`, whose
|
|
15
|
-
* only meaningful line is `-dontoptimize`. Swapping to the `-optimize`
|
|
16
|
-
* variant drops that and adds `-allowaccessmodification`, which is what lets
|
|
17
|
-
* R8 inline and merge classes. Worth a few MB of dex on a typical Oxy app.
|
|
18
|
-
* Expo SDK 58's template already generates the `-optimize` file, so on SDK
|
|
19
|
-
* 58 this step is a no-op and only the signing config below changes.
|
|
20
|
-
*
|
|
21
|
-
* 2. Release signing
|
|
22
|
-
* Expo generates `signingConfig signingConfigs.debug` for release, and Play
|
|
23
|
-
* rejects a debug-signed AAB. The real credentials are read from Gradle
|
|
24
|
-
* properties (set in the developer's `~/.gradle/gradle.properties` or CI
|
|
25
|
-
* secrets) so nothing secret ever lands in the repo. When those properties
|
|
26
|
-
* are absent the build falls back to the debug keystore, so a contributor
|
|
27
|
-
* without the keystore can still build — which is exactly why the shipped
|
|
28
|
-
* artefact's certificate must ALWAYS be verified (`keytool -printcert
|
|
29
|
-
* -jarfile <aab>` / `apksigner verify --print-certs <apk>`) rather than
|
|
30
|
-
* assumed.
|
|
31
|
-
*
|
|
32
|
-
* The certificate MUST be the shared Oxy ecosystem one: Oxy apps share the
|
|
33
|
-
* identity and the device session through `signature`-level permissions
|
|
34
|
-
* (`withOxySharedPermissions`) and providers that check the caller's
|
|
35
|
-
* certificate. An app-specific key is refused by Commons, and its duplicate
|
|
36
|
-
* permission declaration makes Android refuse to install it next to its
|
|
37
|
-
* siblings (INSTALL_FAILED_DUPLICATE_PERMISSION).
|
|
38
|
-
*
|
|
39
|
-
* @param {import('expo/config').ExpoConfig} config
|
|
5
|
+
* Release signing moved to `@oxy.so/services/plugins/withOxySharedPermissions`
|
|
6
|
+
* (services 13.4.0), which every Oxy Android app already applies (directly or
|
|
7
|
+
* through `['@oxy.so/app-preset', {}]`): an app cannot declare the Oxy signature
|
|
8
|
+
* permissions without its release being signed with, and checked against, the
|
|
9
|
+
* ecosystem certificate. The R8 `-optimize` swap moved into
|
|
10
|
+
* `['@oxy.so/app-preset', {}]`.
|
|
40
11
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const KEY_PASSWORD = 'OXY_UPLOAD_KEY_PASSWORD';
|
|
49
|
-
|
|
50
|
-
const DEFAULT_PROGUARD = 'getDefaultProguardFile("proguard-android.txt")';
|
|
51
|
-
const OPTIMIZED_PROGUARD = 'getDefaultProguardFile("proguard-android-optimize.txt")';
|
|
52
|
-
|
|
53
|
-
const DEBUG_SIGNING_CONFIG = 'signingConfig signingConfigs.debug';
|
|
54
|
-
const CONDITIONAL_SIGNING_CONFIG = `signingConfig project.hasProperty('${STORE_FILE}') ? signingConfigs.release : signingConfigs.debug`;
|
|
55
|
-
|
|
56
|
-
const RELEASE_SIGNING_CONFIG = ` release {
|
|
57
|
-
// Populated only when the Oxy release keystore properties are
|
|
58
|
-
// available; otherwise this config stays empty and the release
|
|
59
|
-
// buildType falls back to signingConfigs.debug below.
|
|
60
|
-
if (project.hasProperty('${STORE_FILE}')) {
|
|
61
|
-
storeFile file(project.property('${STORE_FILE}'))
|
|
62
|
-
storePassword project.property('${STORE_PASSWORD}')
|
|
63
|
-
keyAlias project.property('${KEY_ALIAS}')
|
|
64
|
-
keyPassword project.property('${KEY_PASSWORD}')
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
`;
|
|
68
|
-
|
|
69
|
-
function useOptimizedProguardFile(contents) {
|
|
70
|
-
if (contents.includes(OPTIMIZED_PROGUARD)) return contents;
|
|
71
|
-
if (!contents.includes(DEFAULT_PROGUARD)) {
|
|
72
|
-
throw new Error(
|
|
73
|
-
`[withOxyAndroidRelease] Could not find ${DEFAULT_PROGUARD} in app/build.gradle. ` +
|
|
74
|
-
'The Expo template changed — update this plugin instead of editing android/ by hand.',
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
|
-
return contents.replace(DEFAULT_PROGUARD, OPTIMIZED_PROGUARD);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function addReleaseSigningConfig(contents) {
|
|
81
|
-
if (contents.includes(CONDITIONAL_SIGNING_CONFIG)) return contents;
|
|
82
|
-
|
|
83
|
-
// Declare signingConfigs.release immediately after the generated debug entry.
|
|
84
|
-
const debugSigningBlock = /(signingConfigs\s*\{\s*\n\s*debug\s*\{[\s\S]*?\n\s{8}\}\n)/;
|
|
85
|
-
if (!debugSigningBlock.test(contents)) {
|
|
86
|
-
throw new Error(
|
|
87
|
-
'[withOxyAndroidRelease] Could not find the generated signingConfigs.debug block in ' +
|
|
88
|
-
'app/build.gradle. The Expo template changed — update this plugin.',
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
const next = contents.replace(debugSigningBlock, `$1${RELEASE_SIGNING_CONFIG}`);
|
|
92
|
-
|
|
93
|
-
// Point the release buildType at it. The debug buildType also contains
|
|
94
|
-
// `signingConfig signingConfigs.debug`, so only replace the occurrence that
|
|
95
|
-
// follows the `release {` marker.
|
|
96
|
-
const releaseBuildType = next.indexOf('release {', next.indexOf('buildTypes'));
|
|
97
|
-
if (releaseBuildType === -1) {
|
|
98
|
-
throw new Error(
|
|
99
|
-
'[withOxyAndroidRelease] Could not find the release buildType in app/build.gradle.',
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
const target = next.indexOf(DEBUG_SIGNING_CONFIG, releaseBuildType);
|
|
103
|
-
if (target === -1) {
|
|
104
|
-
throw new Error(
|
|
105
|
-
'[withOxyAndroidRelease] Could not find the release buildType signingConfig line.',
|
|
106
|
-
);
|
|
107
|
-
}
|
|
108
|
-
return (
|
|
109
|
-
next.slice(0, target) +
|
|
110
|
-
CONDITIONAL_SIGNING_CONFIG +
|
|
111
|
-
next.slice(target + DEBUG_SIGNING_CONFIG.length)
|
|
12
|
+
module.exports = function withOxyAndroidRelease() {
|
|
13
|
+
throw new Error(
|
|
14
|
+
'[@oxy.so/app-preset] plugin/withOxyAndroidRelease was removed in 5.0.0. Delete it from the ' +
|
|
15
|
+
'app config: release signing is applied by @oxy.so/services/plugins/withOxySharedPermissions ' +
|
|
16
|
+
"(@oxy.so/services 13.4.0 or later, also applied by ['@oxy.so/app-preset', {}]), and it now " +
|
|
17
|
+
'FAILS a release build that is not signed with the Oxy ecosystem key. The R8 -optimize ' +
|
|
18
|
+
"ProGuard swap is applied by ['@oxy.so/app-preset', {}].",
|
|
112
19
|
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
module.exports = function withOxyAndroidRelease(config) {
|
|
116
|
-
return withAppBuildGradle(config, (config) => {
|
|
117
|
-
if (config.modResults.language !== 'groovy') {
|
|
118
|
-
throw new Error(
|
|
119
|
-
`[withOxyAndroidRelease] Expected a Groovy app/build.gradle, got ${config.modResults.language}.`,
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
config.modResults.contents = addReleaseSigningConfig(
|
|
123
|
-
useOptimizedProguardFile(config.modResults.contents),
|
|
124
|
-
);
|
|
125
|
-
return config;
|
|
126
|
-
});
|
|
127
20
|
};
|
|
@@ -30,6 +30,12 @@
|
|
|
30
30
|
* options throw, so an app config that still passes them fails loudly instead
|
|
31
31
|
* of silently doing something else.
|
|
32
32
|
*
|
|
33
|
+
* `withOxySharedPermissions` also signs every release build with the ONE Oxy
|
|
34
|
+
* ecosystem key (the `OXY_UPLOAD_*` Gradle properties) and fails a release that
|
|
35
|
+
* does not carry its certificate; an app lists no signing plugin of its own.
|
|
36
|
+
* `withOxyR8Optimize` (always applied) swaps in R8's `-optimize` ProGuard file on
|
|
37
|
+
* Expo SDK 56/57 and is a no-op on 58.
|
|
38
|
+
*
|
|
33
39
|
* @param {import('expo/config').ExpoConfig} config
|
|
34
40
|
* @param {object} [options]
|
|
35
41
|
* @param {string|false} [options.keychainGroup='group.so.oxy.shared']
|
|
@@ -48,7 +54,9 @@
|
|
|
48
54
|
*/
|
|
49
55
|
const withOxyKeychain = require('./withOxyKeychain');
|
|
50
56
|
const withOxyBuildProperties = require('./withOxyBuildProperties');
|
|
51
|
-
const
|
|
57
|
+
const withOxyR8Optimize = require('./withOxyR8Optimize');
|
|
58
|
+
const { dirname, join } = require('node:path');
|
|
59
|
+
const { projectRootOf, requireFromProject, resolveFromProject } = require('./requireFromProject');
|
|
52
60
|
|
|
53
61
|
const REMOVED_OPTIONS = {
|
|
54
62
|
sharedUserId:
|
|
@@ -94,15 +102,22 @@ module.exports = function withOxyAppPreset(config, options = {}) {
|
|
|
94
102
|
next = withOxyBuildProperties(next, { ios, android });
|
|
95
103
|
}
|
|
96
104
|
|
|
105
|
+
next = withOxyR8Optimize(next);
|
|
106
|
+
|
|
97
107
|
let withOxySharedPermissions;
|
|
98
108
|
try {
|
|
99
|
-
|
|
109
|
+
const permissionsPlugin = resolveFromProject(
|
|
100
110
|
'@oxy.so/services/plugins/withOxySharedPermissions',
|
|
101
111
|
projectRootOf(config),
|
|
102
112
|
);
|
|
113
|
+
// A Services older than 13.4.0 declares the permissions WITHOUT release
|
|
114
|
+
// signing, and Expo's template then signs release with the debug key: refuse
|
|
115
|
+
// it. Its sibling, because withOxySharedPermissions loads that very file.
|
|
116
|
+
require.resolve(join(dirname(permissionsPlugin), 'withOxyReleaseSigning'));
|
|
117
|
+
withOxySharedPermissions = require(permissionsPlugin);
|
|
103
118
|
} catch (error) {
|
|
104
119
|
throw new Error(
|
|
105
|
-
"[@oxy.so/app-preset] needs '@oxy.so/services'
|
|
120
|
+
"[@oxy.so/app-preset] needs '@oxy.so/services' 13.4.0 or later (for plugins/withOxySharedPermissions and withOxyReleaseSigning). " +
|
|
106
121
|
`Install it in the app. (${error instanceof Error ? error.message : String(error)})`,
|
|
107
122
|
);
|
|
108
123
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expo Config Plugin: withOxyR8Optimize (applied by `['@oxy.so/app-preset', {}]`).
|
|
3
|
+
*
|
|
4
|
+
* Expo SDK 56/57 generate `getDefaultProguardFile("proguard-android.txt")` for
|
|
5
|
+
* the release buildType, whose only meaningful line is `-dontoptimize`. The
|
|
6
|
+
* `-optimize` variant drops it and adds `-allowaccessmodification`, which is what
|
|
7
|
+
* lets R8 inline and merge classes (measured on Mention: dex 22,814,960 →
|
|
8
|
+
* 15,290,636 bytes uncompressed, -33%, 4 dex files → 2). SDK 58's template
|
|
9
|
+
* already generates the `-optimize` file, so there this is a no-op.
|
|
10
|
+
*
|
|
11
|
+
* Release signing is not here: `@oxy.so/services/plugins/withOxySharedPermissions`
|
|
12
|
+
* (which the preset applies) owns it, because the signature permissions it
|
|
13
|
+
* declares are what make the certificate load-bearing.
|
|
14
|
+
*/
|
|
15
|
+
const { withAppBuildGradle } = require('expo/config-plugins');
|
|
16
|
+
|
|
17
|
+
const DEFAULT_PROGUARD = 'getDefaultProguardFile("proguard-android.txt")';
|
|
18
|
+
const OPTIMIZED_PROGUARD = 'getDefaultProguardFile("proguard-android-optimize.txt")';
|
|
19
|
+
|
|
20
|
+
/** @param {string} contents */
|
|
21
|
+
function optimizeProguardFile(contents) {
|
|
22
|
+
if (contents.includes(OPTIMIZED_PROGUARD)) return contents;
|
|
23
|
+
if (!contents.includes(DEFAULT_PROGUARD)) {
|
|
24
|
+
throw new Error(
|
|
25
|
+
`[@oxy.so/app-preset withOxyR8Optimize] Could not find ${DEFAULT_PROGUARD} in app/build.gradle. ` +
|
|
26
|
+
'The Expo template changed: update this plugin instead of editing android/ by hand.',
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
return contents.replace(DEFAULT_PROGUARD, OPTIMIZED_PROGUARD);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = function withOxyR8Optimize(config) {
|
|
33
|
+
return withAppBuildGradle(config, (modConfig) => {
|
|
34
|
+
if (modConfig.modResults.language === 'groovy') {
|
|
35
|
+
modConfig.modResults.contents = optimizeProguardFile(modConfig.modResults.contents);
|
|
36
|
+
}
|
|
37
|
+
return modConfig;
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
module.exports.optimizeProguardFile = optimizeProguardFile;
|