@vvedantb/config 0.4.0 → 0.5.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/CHANGELOG.md +11 -0
- package/README.md +106 -1
- package/dist/android-release-cli.d.ts +2 -0
- package/dist/android-release-cli.js +251 -0
- package/dist/android-release.d.ts +113 -0
- package/dist/android-release.js +277 -0
- package/dist/check-asar-cli.js +0 -0
- package/dist/clerk-allow-cli.js +0 -0
- package/dist/cli.js +0 -0
- package/dist/expo.d.ts +18 -0
- package/dist/expo.js +29 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +2 -0
- package/dist/release-signing.d.ts +66 -0
- package/dist/release-signing.js +101 -0
- package/oxlint/plugin.mjs +32 -0
- package/oxlint/rules/no-double-cast.mjs +21 -0
- package/oxlint/rules/no-json-parse.mjs +86 -0
- package/oxlint/rules/no-source-text-in-tests.mjs +78 -0
- package/oxlint/rules/no-value-block-in-try.mjs +165 -0
- package/oxlint/utils.mjs +11 -0
- package/package.json +18 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#225](https://github.com/vvedantb/packages/pull/225) [`4eada13`](https://github.com/vvedantb/packages/commit/4eada137e0ff7871dd1003c9b92e92fa29c1b892) Thanks [@vvedantb](https://github.com/vvedantb)! - Add four shared tooling items used across the apps:
|
|
8
|
+
|
|
9
|
+
- `withReleaseSigning`: an Expo config plugin that signs the Android `release` build type from a keystore (environment, else `keystore.properties`), failing a release when a value is missing. `expo/config-plugins` is an optional, lazily resolved peer. Marker is configurable and defaults to a value containing `plugins/withReleaseSigning.js` so build-script greps pass.
|
|
10
|
+
- `singletons` (and `nativeWindConfig`) on `defineExpoMetroConfig`: rewrites `originModulePath` to the app's `package.json` for the given module heads so a single copy resolves. Backward compatible for apps that omit it.
|
|
11
|
+
- `vvedantb-android-release`: a config-driven Android release build bin that merges the per-app build scripts into one and keeps the reusable-workflow `GITHUB_OUTPUT` interface (`apk`, `release_json`, `version_name`, `version_code`, `sha256`). Runs on Linux CI.
|
|
12
|
+
- A shared oxlint JS plugin at `@vvedantb/config/oxlint/plugin.mjs` with `no-value-block-in-try`, `no-source-text-in-tests`, `no-double-cast` and `no-json-parse`.
|
|
13
|
+
|
|
3
14
|
## 0.4.0
|
|
4
15
|
|
|
5
16
|
- New subpath `@vvedantb/config/extension` for Chrome extensions built with WXT. Like the Vite presets, it never imports WXT, Vite or a plugin; the app passes its plugin factories in. WXT is not a peer.
|
package/README.md
CHANGED
|
@@ -50,6 +50,33 @@ Generic rules only: plugins `typescript`, `import`, `unicorn`, `react`; `suspici
|
|
|
50
50
|
|
|
51
51
|
The severity of `no-console` and `no-unused-vars` is set to `error` here. It was not copied from the source app file, which was not in the extract. Check it against the app.
|
|
52
52
|
|
|
53
|
+
### Custom oxlint rules (JS plugin)
|
|
54
|
+
|
|
55
|
+
The package ships one oxlint JS plugin at `@vvedantb/config/oxlint/plugin.mjs`. It holds four rules, with no app prefix:
|
|
56
|
+
|
|
57
|
+
| Rule | Flags |
|
|
58
|
+
| --- | --- |
|
|
59
|
+
| `no-value-block-in-try` | A value block (`?:`, `&&`/`\|\|`/`??`, optional chaining), loop, `throw`, `finally`, or missing `catch` inside a `try` in a React-compiled function or hook. Any one drops memoization for the whole file silently. |
|
|
60
|
+
| `no-source-text-in-tests` | A source file name (`.ts`, `.tsx`, `.mts`, `.css`, `.html`) passed to a file read (`readFileSync`, `readSource`, …) in a `*.test.*` / `*.spec.*` file. Plain path strings used as data stay allowed. |
|
|
61
|
+
| `no-double-cast` | A double cast such as `x as A as B` or `x as unknown as T`. |
|
|
62
|
+
| `no-json-parse` | A bare `JSON.parse(...)` result that flows unchecked. `schema.parse(JSON.parse(x))` / `schema.safeParse(...)` are always allowed. With `{ "allowUnknownEscapeHatch": true }`, a `: unknown` annotation or `as unknown` cast is also allowed. |
|
|
63
|
+
|
|
64
|
+
Wire it into the app's `.oxlintrc.json` (or `oxlint.jsonc`):
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"jsPlugins": [{ "name": "vvedantb", "specifier": "@vvedantb/config/oxlint/plugin.mjs" }],
|
|
69
|
+
"rules": {
|
|
70
|
+
"vvedantb/no-value-block-in-try": "error",
|
|
71
|
+
"vvedantb/no-source-text-in-tests": "error",
|
|
72
|
+
"vvedantb/no-double-cast": "error",
|
|
73
|
+
"vvedantb/no-json-parse": "error"
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
oxlint reports each as `vvedantb(<rule>)`. For vmem's original `no-json-parse` behaviour, set `"vvedantb/no-json-parse": ["error", { "allowUnknownEscapeHatch": true }]`; the default (eva's) is strict, where `unknown` is not an escape.
|
|
79
|
+
|
|
53
80
|
## Vite and Vitest presets
|
|
54
81
|
|
|
55
82
|
The root never imports Vite or a plugin. The app imports its plugins and passes the factories in, so the versions stay the app's own. The functions return plain objects; spread them into Vite's `defineConfig` and add `server`, `base` or `root` there.
|
|
@@ -216,8 +243,86 @@ module.exports = defineExpoMetroConfig({
|
|
|
216
243
|
|
|
217
244
|
- `monorepoRoot` sets `watchFolders: [<root>]` and `resolver.nodeModulesPaths` to the app's and the root's `node_modules`.
|
|
218
245
|
- `packageExports: true` sets `resolver.unstable_enablePackageExports: true`.
|
|
246
|
+
- `singletons: ["react", "react-dom", …]` installs a `resolver.resolveRequest` wrapper that rewrites `originModulePath` to the app's `package.json` for those module heads, so a single copy resolves. It composes with nativewind's own resolver and is applied before `withNativeWind`.
|
|
247
|
+
- `nativeWindConfig: "./tailwind.config.ts"` resolves to an absolute path and is passed to `withNativeWind` as `configPath`.
|
|
248
|
+
|
|
249
|
+
`withNativeWind` copies the config and its resolver and reads neither monorepo setting, so the order matches setting them before it.
|
|
250
|
+
|
|
251
|
+
vmem and eva pass `singletons`; verve and vibot omit it and behave exactly as before. Example (vmem/eva):
|
|
252
|
+
|
|
253
|
+
```js
|
|
254
|
+
module.exports = defineExpoMetroConfig({
|
|
255
|
+
projectRoot: __dirname,
|
|
256
|
+
getDefaultConfig,
|
|
257
|
+
withNativeWind,
|
|
258
|
+
inlineRem: 16,
|
|
259
|
+
monorepoRoot: "../..",
|
|
260
|
+
singletons: ["react", "react-dom"],
|
|
261
|
+
});
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
## Release signing (Expo config plugin)
|
|
265
|
+
|
|
266
|
+
`withReleaseSigning` is an Expo config plugin that signs the Android `release` build type from a sideload keystore. Each value comes from the environment, else from a `keystore.properties` file; a release task fails when any is missing, so a release never falls back to the debug key. `expo/config-plugins` is an optional peer, resolved lazily from the app, so the module loads under plain Node without Expo installed.
|
|
267
|
+
|
|
268
|
+
Each app keeps a thin wrapper at `apps/mobile/plugins/withReleaseSigning.js` and references it from `app.config`:
|
|
269
|
+
|
|
270
|
+
```js
|
|
271
|
+
// apps/mobile/plugins/withReleaseSigning.js
|
|
272
|
+
const { withReleaseSigning } = require("@vvedantb/config");
|
|
273
|
+
|
|
274
|
+
module.exports = (config) =>
|
|
275
|
+
withReleaseSigning(config, {
|
|
276
|
+
// Marker the app's build script greps android/app/build.gradle for.
|
|
277
|
+
marker: "// Added by apps/mobile/plugins/withReleaseSigning.js",
|
|
278
|
+
});
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
Options and defaults:
|
|
282
|
+
|
|
283
|
+
| Option | Default | Notes |
|
|
284
|
+
| --- | --- | --- |
|
|
285
|
+
| `marker` | `"// @generated @vvedantb/config plugins/withReleaseSigning.js"` | The idempotency marker and the substring build scripts grep for. The default contains `plugins/withReleaseSigning.js`, so the default already satisfies that grep. |
|
|
286
|
+
| `keystorePropertiesFile` | `rootProject.file("../../../keystore.properties")` | Groovy expression for the properties file (repo root, three levels above `android/app`). |
|
|
287
|
+
| `propertyKeys` | `ANDROID_KEYSTORE_PATH`, `ANDROID_KEYSTORE_PASSWORD`, `ANDROID_KEY_ALIAS`, `ANDROID_KEY_PASSWORD` | `Partial` override of the env / properties key names. |
|
|
288
|
+
| `storeType` | _(omitted)_ | Emitted as a `storeType "…"` line only when set. |
|
|
289
|
+
| `skipOnEasBuild` | `false` | Skip the append when `EAS_BUILD` is set (EAS handles its own signing). |
|
|
290
|
+
| `releaseTaskCondition` | any task of this project whose name contains `"release"` | Groovy boolean deciding whether a build must sign `release`. |
|
|
291
|
+
|
|
292
|
+
Exact marker each app expects:
|
|
293
|
+
|
|
294
|
+
- **vmem** and **eva**: `// Added by apps/mobile/plugins/withReleaseSigning.js` (vmem's own test asserts this string exactly, and that no non-marker line contains the app name — the shared block is generic, so it passes).
|
|
295
|
+
- **vibot**: any marker containing `plugins/withReleaseSigning.js` (its build script only greps that substring). The default works.
|
|
296
|
+
- **verve**: no build-script grep; the default marker is fine.
|
|
297
|
+
|
|
298
|
+
All four build scripts grep `android/app/build.gradle` for `plugins/withReleaseSigning.js`, which every marker above (and the default) contains.
|
|
299
|
+
|
|
300
|
+
## Android release build (`vvedantb-android-release`)
|
|
301
|
+
|
|
302
|
+
`vvedantb-android-release` builds a signed Android release APK in CI. It merges the three app build scripts (vibot, vmem, eva) into one bin driven by a config file, and keeps the reusable-workflow interface: it writes `apk`, `release_json`, `version_name`, `version_code` and `sha256` to `GITHUB_OUTPUT`. It runs on Linux CI with the Android SDK; it is **not** runnable on Windows.
|
|
303
|
+
|
|
304
|
+
```sh
|
|
305
|
+
VERSION_NAME=1.0.1 VERSION_CODE=1000 \
|
|
306
|
+
vvedantb-android-release --config android-release.config.json [--root <repo root>]
|
|
307
|
+
```
|
|
219
308
|
|
|
220
|
-
|
|
309
|
+
The config (parsed by `parseAndroidReleaseConfig`) covers the differences between apps:
|
|
310
|
+
|
|
311
|
+
| Field | Default | Notes |
|
|
312
|
+
| --- | --- | --- |
|
|
313
|
+
| `packageId` | _(required)_ | e.g. `com.projectvdotuk.vmem`; checked against `aapt2` badging. |
|
|
314
|
+
| `apkPrefix` | _(required)_ | Output name `<prefix>-<version>-android.apk`. |
|
|
315
|
+
| `appDir` | `apps/mobile` | Expo app directory. |
|
|
316
|
+
| `publicEnv` | `[]` | `EXPO_PUBLIC_*` names resolved from env, then `publicEnvSources`. |
|
|
317
|
+
| `publicEnvSources` | `[]` | `{ kind: "eas-profile", profile? }` or `{ kind: "config-literal", file, operators? }` (`??`/`\|\|`). |
|
|
318
|
+
| `pnpmFilters` | `["{.}"]` | `pnpm install --filter` targets. |
|
|
319
|
+
| `prebuildNoInstall` | `true` | Adds `--no-install` to `expo prebuild --clean`. |
|
|
320
|
+
| `extraEnv` / `optionalEnv` | `{}` / — | Extra and pass-through env for the build. |
|
|
321
|
+
| `preChecks` / `preBuildSteps` | — | bash steps run in the repo root / app dir before the build. |
|
|
322
|
+
| `gradleWrapperPin` | — | `{ ifContains, distributionUrl }` to pin the Gradle wrapper. |
|
|
323
|
+
| `summary` | — | `{ label, envVar }` echoed at the end. |
|
|
324
|
+
|
|
325
|
+
Pure helpers (`validateVersionName`, `validateVersionCode`, `publicEnvDefault`, `gradlePropertiesEdits`, `parseBadging`, `releaseJson`, `formatReleaseJson`, `formatGithubOutput`, `apkFileName`, `parseAndroidReleaseConfig`) are exported from the root and unit-tested. The full Android build was not exercised on Windows.
|
|
221
326
|
|
|
222
327
|
## Versions
|
|
223
328
|
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// `vvedantb-android-release`: build a signed, sideloadable Android release APK
|
|
3
|
+
// (arm64-v8a + x86_64, embedded JS) with Gradle, then write release.json next to
|
|
4
|
+
// it. No EAS. One bin for every app; per-app differences come from a JSON config:
|
|
5
|
+
//
|
|
6
|
+
// VERSION_NAME=1.0.1 VERSION_CODE=1000 \
|
|
7
|
+
// vvedantb-android-release --config scripts/android-release.config.json
|
|
8
|
+
//
|
|
9
|
+
// The release workflow chooses VERSION_NAME and VERSION_CODE. Signing reads
|
|
10
|
+
// ANDROID_KEYSTORE_PATH, ANDROID_KEYSTORE_PASSWORD, ANDROID_KEY_ALIAS and
|
|
11
|
+
// ANDROID_KEY_PASSWORD from the environment, else from keystore.properties in the
|
|
12
|
+
// repo root (see withReleaseSigning). The build stops if any is missing. Linux or
|
|
13
|
+
// WSL2 (GNU sed is not needed; edits run in Node). This orchestration needs a
|
|
14
|
+
// Linux host with the Android SDK, so it is exercised only on CI, never on the
|
|
15
|
+
// package's own test run.
|
|
16
|
+
import { spawnSync } from "node:child_process";
|
|
17
|
+
import { createHash } from "node:crypto";
|
|
18
|
+
import { appendFileSync, chmodSync, copyFileSync, existsSync, readdirSync, readFileSync, rmSync, writeFileSync, } from "node:fs";
|
|
19
|
+
import { dirname, join, resolve } from "node:path";
|
|
20
|
+
import { apkFileName, formatGithubOutput, formatReleaseJson, gradlePropertiesEdits, parseAndroidReleaseConfig, parseBadging, publicEnvDefault, releaseJson, validateVersionCode, validateVersionName, } from "./android-release.js";
|
|
21
|
+
function fail(message) {
|
|
22
|
+
console.error(message);
|
|
23
|
+
process.exit(1);
|
|
24
|
+
}
|
|
25
|
+
function flag(args, name) {
|
|
26
|
+
const index = args.indexOf(name);
|
|
27
|
+
if (index >= 0 && index + 1 < args.length)
|
|
28
|
+
return args[index + 1];
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
function run(command, commandArgs, options) {
|
|
32
|
+
const result = spawnSync(command, commandArgs, {
|
|
33
|
+
cwd: options.cwd,
|
|
34
|
+
env: options.env,
|
|
35
|
+
stdio: "inherit",
|
|
36
|
+
shell: false,
|
|
37
|
+
});
|
|
38
|
+
if (result.status !== 0) {
|
|
39
|
+
fail(`${command} ${commandArgs.join(" ")} failed with code ${result.status ?? "null"}.`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function capture(command, commandArgs, cwd) {
|
|
43
|
+
const result = spawnSync(command, commandArgs, { cwd, encoding: "utf8", shell: false });
|
|
44
|
+
if (result.status !== 0) {
|
|
45
|
+
fail(`${command} ${commandArgs.join(" ")} failed with code ${result.status ?? "null"}.`);
|
|
46
|
+
}
|
|
47
|
+
return result.stdout;
|
|
48
|
+
}
|
|
49
|
+
/** Highest versioned subdirectory under `base` whose `bin/sdkmanager` is a file. */
|
|
50
|
+
function findSdkManager(sdkRoot) {
|
|
51
|
+
const latest = join(sdkRoot, "cmdline-tools", "latest", "bin", "sdkmanager");
|
|
52
|
+
if (existsSync(latest))
|
|
53
|
+
return latest;
|
|
54
|
+
const toolsRoot = join(sdkRoot, "cmdline-tools");
|
|
55
|
+
if (!existsSync(toolsRoot))
|
|
56
|
+
return undefined;
|
|
57
|
+
const versioned = readdirSync(toolsRoot)
|
|
58
|
+
.filter((name) => /^[0-9]+(\.[0-9]+)*$/.test(name))
|
|
59
|
+
.sort(compareVersions);
|
|
60
|
+
for (const name of versioned) {
|
|
61
|
+
const candidate = join(toolsRoot, name, "bin", "sdkmanager");
|
|
62
|
+
if (existsSync(candidate))
|
|
63
|
+
return candidate;
|
|
64
|
+
}
|
|
65
|
+
return undefined;
|
|
66
|
+
}
|
|
67
|
+
/** Newest build-tools directory that has both aapt2 and apksigner. */
|
|
68
|
+
function findBuildTools(sdkRoot) {
|
|
69
|
+
const base = join(sdkRoot, "build-tools");
|
|
70
|
+
if (!existsSync(base))
|
|
71
|
+
return undefined;
|
|
72
|
+
const versions = readdirSync(base).sort(compareVersions);
|
|
73
|
+
let found;
|
|
74
|
+
for (const name of versions) {
|
|
75
|
+
const dir = join(base, name);
|
|
76
|
+
if (existsSync(join(dir, "aapt2")) && existsSync(join(dir, "apksigner"))) {
|
|
77
|
+
found = dir;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return found;
|
|
81
|
+
}
|
|
82
|
+
function compareVersions(a, b) {
|
|
83
|
+
const pa = a.split(".").map((n) => Number(n));
|
|
84
|
+
const pb = b.split(".").map((n) => Number(n));
|
|
85
|
+
for (let i = 0; i < Math.max(pa.length, pb.length); i++) {
|
|
86
|
+
const diff = (pa[i] ?? 0) - (pb[i] ?? 0);
|
|
87
|
+
if (diff !== 0)
|
|
88
|
+
return diff;
|
|
89
|
+
}
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
function sha256File(path) {
|
|
93
|
+
return createHash("sha256").update(readFileSync(path)).digest("hex");
|
|
94
|
+
}
|
|
95
|
+
const args = process.argv.slice(2);
|
|
96
|
+
const configPath = flag(args, "--config");
|
|
97
|
+
if (configPath === undefined) {
|
|
98
|
+
fail("Pass --config <path to android-release.config.json>.");
|
|
99
|
+
}
|
|
100
|
+
const root = resolve(flag(args, "--root") ?? process.cwd());
|
|
101
|
+
const skipPrebuild = (process.env.SKIP_PREBUILD ?? "") === "1";
|
|
102
|
+
let config;
|
|
103
|
+
try {
|
|
104
|
+
config = parseAndroidReleaseConfig(JSON.parse(readFileSync(resolve(configPath), "utf8")));
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
fail(`Could not read config at ${configPath}: ${error.message}`);
|
|
108
|
+
}
|
|
109
|
+
const appDir = join(root, config.appDir);
|
|
110
|
+
const env = { ...process.env };
|
|
111
|
+
const versionName = validateVersionName(env.VERSION_NAME);
|
|
112
|
+
const versionCode = validateVersionCode(env.VERSION_CODE);
|
|
113
|
+
env.VERSION_NAME = versionName;
|
|
114
|
+
env.VERSION_CODE = String(versionCode);
|
|
115
|
+
// Bake the production runtime config into the APK. Each value comes from the
|
|
116
|
+
// environment, else a baked-in default named in the config. A release never
|
|
117
|
+
// ships without them.
|
|
118
|
+
const readAppFile = (relativePath) => {
|
|
119
|
+
const full = join(appDir, relativePath);
|
|
120
|
+
return existsSync(full) ? readFileSync(full, "utf8") : undefined;
|
|
121
|
+
};
|
|
122
|
+
for (const name of config.publicEnv) {
|
|
123
|
+
const value = publicEnvDefault(name, { env, readAppFile, sources: config.publicEnvSources });
|
|
124
|
+
if (value === "") {
|
|
125
|
+
fail(`${name} is not set in the environment or as a default in ${config.appDir}.`);
|
|
126
|
+
}
|
|
127
|
+
env[name] = value;
|
|
128
|
+
}
|
|
129
|
+
// optionalEnv names are passed through from the environment when present; the
|
|
130
|
+
// copied `env` already carries them, so nothing extra is needed here.
|
|
131
|
+
for (const [key, value] of Object.entries(config.extraEnv))
|
|
132
|
+
env[key] = value;
|
|
133
|
+
// Our own signing (EAS_BUILD would switch it off in Expo tooling).
|
|
134
|
+
delete env.EAS_BUILD;
|
|
135
|
+
env.CI = env.CI ?? "1";
|
|
136
|
+
const sdkRoot = env.ANDROID_SDK_ROOT ?? env.ANDROID_HOME ?? join(env.HOME ?? "", "Android/Sdk");
|
|
137
|
+
env.ANDROID_SDK_ROOT = sdkRoot;
|
|
138
|
+
env.ANDROID_HOME = sdkRoot;
|
|
139
|
+
const javaHome = env.JAVA_HOME ?? "/usr/lib/jvm/java-21-openjdk-amd64";
|
|
140
|
+
env.JAVA_HOME = javaHome;
|
|
141
|
+
env.PATH = [
|
|
142
|
+
join(javaHome, "bin"),
|
|
143
|
+
join(sdkRoot, "platform-tools"),
|
|
144
|
+
join(sdkRoot, "emulator"),
|
|
145
|
+
env.PATH ?? "",
|
|
146
|
+
].join(":");
|
|
147
|
+
const sdkManager = findSdkManager(sdkRoot);
|
|
148
|
+
if (sdkManager === undefined) {
|
|
149
|
+
fail(`Android SDK cmdline-tools not found at ${sdkRoot}/cmdline-tools (latest or a version folder).`);
|
|
150
|
+
}
|
|
151
|
+
env.PATH = `${dirname(sdkManager)}:${env.PATH}`;
|
|
152
|
+
// Repo-root checks the app runs before building (such as a Clerk API check).
|
|
153
|
+
for (const check of config.preChecks) {
|
|
154
|
+
run("bash", ["-lc", check], { cwd: root, env });
|
|
155
|
+
}
|
|
156
|
+
// Mobile and its workspace deps, plus the root, whose pnpm settings the install uses.
|
|
157
|
+
const installArgs = ["install", "--frozen-lockfile"];
|
|
158
|
+
for (const filter of config.pnpmFilters)
|
|
159
|
+
installArgs.push("--filter", filter);
|
|
160
|
+
run("pnpm", installArgs, { cwd: root, env });
|
|
161
|
+
// App-folder steps after install, before prebuild (such as a babel smoke test).
|
|
162
|
+
for (const step of config.preBuildSteps) {
|
|
163
|
+
run("bash", ["-lc", step], { cwd: appDir, env });
|
|
164
|
+
}
|
|
165
|
+
if (!skipPrebuild) {
|
|
166
|
+
const prebuildArgs = ["expo", "prebuild", "--platform", "android", "--clean"];
|
|
167
|
+
if (config.prebuildNoInstall)
|
|
168
|
+
prebuildArgs.push("--no-install");
|
|
169
|
+
run("npx", prebuildArgs, { cwd: appDir, env });
|
|
170
|
+
}
|
|
171
|
+
// app.config reads VERSION_CODE at prebuild time, so a SKIP_PREBUILD run keeps
|
|
172
|
+
// whatever android/ was generated with.
|
|
173
|
+
const appGradle = join(appDir, "android", "app", "build.gradle");
|
|
174
|
+
const appGradleText = existsSync(appGradle) ? readFileSync(appGradle, "utf8") : "";
|
|
175
|
+
const versionCodeOk = new RegExp(`^[\\t ]*versionCode ${versionCode}[\\t ]*$`, "m").test(appGradleText);
|
|
176
|
+
if (!versionCodeOk || !appGradleText.includes("withReleaseSigning")) {
|
|
177
|
+
fail("android/ is stale (versionCode or signing). Run again without SKIP_PREBUILD=1.");
|
|
178
|
+
}
|
|
179
|
+
// Optionally pin the Gradle wrapper (one app ships an incompatible default).
|
|
180
|
+
if (config.gradleWrapperPin !== undefined) {
|
|
181
|
+
const wrapperProps = join(appDir, "android", "gradle", "wrapper", "gradle-wrapper.properties");
|
|
182
|
+
if (existsSync(wrapperProps)) {
|
|
183
|
+
const text = readFileSync(wrapperProps, "utf8");
|
|
184
|
+
if (text.includes(config.gradleWrapperPin.ifContains)) {
|
|
185
|
+
const next = text.replace(/^distributionUrl=.*$/m, `distributionUrl=${config.gradleWrapperPin.distributionUrl.replaceAll(":", "\\:")}`);
|
|
186
|
+
writeFileSync(wrapperProps, next);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
const propsPath = join(appDir, "android", "gradle.properties");
|
|
191
|
+
const propsText = existsSync(propsPath) ? readFileSync(propsPath, "utf8") : "";
|
|
192
|
+
writeFileSync(propsPath, gradlePropertiesEdits(propsText));
|
|
193
|
+
writeFileSync(join(appDir, "android", "local.properties"), `sdk.dir=${sdkRoot}\n`);
|
|
194
|
+
const outDir = join(appDir, "android", "app", "build", "outputs", "apk", "release");
|
|
195
|
+
const apk = join(outDir, "app-release.apk");
|
|
196
|
+
// A failed run must not leave an older APK or release.json to publish.
|
|
197
|
+
for (const stale of [apk, join(outDir, "release.json")]) {
|
|
198
|
+
if (existsSync(stale))
|
|
199
|
+
rmSync(stale);
|
|
200
|
+
}
|
|
201
|
+
if (existsSync(outDir)) {
|
|
202
|
+
for (const name of readdirSync(outDir)) {
|
|
203
|
+
if (new RegExp(`^${config.apkPrefix}-.*-android\\.apk$`).test(name)) {
|
|
204
|
+
rmSync(join(outDir, name));
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const androidDir = join(appDir, "android");
|
|
209
|
+
const gradlew = join(androidDir, "gradlew");
|
|
210
|
+
if (existsSync(gradlew))
|
|
211
|
+
chmodSync(gradlew, 0o755);
|
|
212
|
+
// Vital lint is not needed for a sideload APK and can run out of Metaspace.
|
|
213
|
+
run("./gradlew", ["assembleRelease", "--no-daemon", "-x", "lint", "-x", "lintVitalAnalyzeRelease", "-x", "lintVitalRelease"], { cwd: androidDir, env });
|
|
214
|
+
// Check the APK itself before describing it: package, versionCode, versionName,
|
|
215
|
+
// and a release signature rather than the debug key.
|
|
216
|
+
const buildTools = findBuildTools(sdkRoot);
|
|
217
|
+
if (buildTools === undefined) {
|
|
218
|
+
fail(`No build-tools with aapt2 and apksigner in ${sdkRoot}/build-tools. Install build-tools;36.0.0 with sdkmanager.`);
|
|
219
|
+
}
|
|
220
|
+
const badging = parseBadging(capture(join(buildTools, "aapt2"), ["dump", "badging", apk], androidDir));
|
|
221
|
+
if (badging.name !== config.packageId ||
|
|
222
|
+
badging.versionCode !== String(versionCode) ||
|
|
223
|
+
badging.versionName !== versionName) {
|
|
224
|
+
fail(`Built ${badging.name} ${badging.versionCode} ${badging.versionName} (package, versionCode, versionName); ` +
|
|
225
|
+
`expected ${config.packageId} ${versionCode} ${versionName}.`);
|
|
226
|
+
}
|
|
227
|
+
const certs = capture(join(buildTools, "apksigner"), ["verify", "--print-certs", apk], androidDir);
|
|
228
|
+
if (certs.includes("CN=Android Debug")) {
|
|
229
|
+
fail("The APK is signed with the debug key. Not writing release.json.");
|
|
230
|
+
}
|
|
231
|
+
const named = join(outDir, apkFileName(config.apkPrefix, versionName));
|
|
232
|
+
copyFileSync(apk, named);
|
|
233
|
+
const sha256 = sha256File(named);
|
|
234
|
+
const manifest = join(outDir, "release.json");
|
|
235
|
+
writeFileSync(manifest, formatReleaseJson(releaseJson(versionName, versionCode, sha256)));
|
|
236
|
+
console.info(`Built ${named}`);
|
|
237
|
+
console.info(` versionName ${versionName}, versionCode ${versionCode}`);
|
|
238
|
+
console.info(` SHA-256 ${sha256}`);
|
|
239
|
+
if (config.summary !== undefined) {
|
|
240
|
+
console.info(` ${config.summary.label} ${env[config.summary.envVar] ?? ""}`);
|
|
241
|
+
}
|
|
242
|
+
console.info(`Wrote ${manifest}`);
|
|
243
|
+
if (env.GITHUB_OUTPUT !== undefined && env.GITHUB_OUTPUT !== "") {
|
|
244
|
+
appendFileSync(env.GITHUB_OUTPUT, formatGithubOutput({
|
|
245
|
+
apk: named,
|
|
246
|
+
release_json: manifest,
|
|
247
|
+
version_name: versionName,
|
|
248
|
+
version_code: String(versionCode),
|
|
249
|
+
sha256,
|
|
250
|
+
}));
|
|
251
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/** Returns `value` when it is a version like `1.0.1`, else throws. */
|
|
2
|
+
export declare function validateVersionName(value: string | undefined): string;
|
|
3
|
+
/** Returns the versionCode as a number when valid (1..2_100_000_000), else throws. */
|
|
4
|
+
export declare function validateVersionCode(value: string | undefined): number;
|
|
5
|
+
/** Where a baked-in default for an `EXPO_PUBLIC_*` value is read from. */
|
|
6
|
+
export type PublicEnvSource = {
|
|
7
|
+
/** The `build.<profile>.env[name]` value in `eas.json`. */
|
|
8
|
+
kind: "eas-profile";
|
|
9
|
+
/** Profile name. Default `"production"`. */
|
|
10
|
+
profile?: string;
|
|
11
|
+
} | {
|
|
12
|
+
/** A `process.env.NAME <op> "literal"` default in a config file. */
|
|
13
|
+
kind: "config-literal";
|
|
14
|
+
/** File relative to the app folder, such as `"app.config.ts"` or `"src/config.ts"`. */
|
|
15
|
+
file: string;
|
|
16
|
+
/** Operators that precede the literal. Default `["??", "||"]`. */
|
|
17
|
+
operators?: readonly ("??" | "||")[];
|
|
18
|
+
};
|
|
19
|
+
/** Reads a text file relative to the app folder, or `undefined` when absent. */
|
|
20
|
+
export type ReadAppFile = (relativePath: string) => string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* Resolves an `EXPO_PUBLIC_*` value: the environment first, then each source in
|
|
23
|
+
* turn (an `eas.json` profile, or a `process.env.NAME ?? "literal"` default in a
|
|
24
|
+
* config file). Returns `""` when nothing supplies it, so callers decide whether
|
|
25
|
+
* a missing value is an error.
|
|
26
|
+
*/
|
|
27
|
+
export declare function publicEnvDefault(name: string, options: {
|
|
28
|
+
env: NodeJS.ProcessEnv;
|
|
29
|
+
readAppFile: ReadAppFile;
|
|
30
|
+
sources?: readonly PublicEnvSource[];
|
|
31
|
+
}): string;
|
|
32
|
+
/** One edit to `gradle.properties`. */
|
|
33
|
+
export interface GradlePropertyEdit {
|
|
34
|
+
/** Property key, such as `"org.gradle.jvmargs"`. */
|
|
35
|
+
key: string;
|
|
36
|
+
/** Property value. */
|
|
37
|
+
value: string;
|
|
38
|
+
/** Replace an existing line (true) or only append when absent (false). */
|
|
39
|
+
replace: boolean;
|
|
40
|
+
}
|
|
41
|
+
/** The edits the release build makes to `gradle.properties`, in order. */
|
|
42
|
+
export declare const DEFAULT_GRADLE_PROPERTY_EDITS: readonly GradlePropertyEdit[];
|
|
43
|
+
/**
|
|
44
|
+
* Applies the release edits to `gradle.properties` contents and returns the new
|
|
45
|
+
* text. A `replace` edit overwrites an existing `key=` line or appends when
|
|
46
|
+
* absent; a non-replace edit only appends when the key is absent. Always ends
|
|
47
|
+
* with a trailing newline (an append onto a file without one joins two lines and
|
|
48
|
+
* Gradle fails to parse it).
|
|
49
|
+
*/
|
|
50
|
+
export declare function gradlePropertiesEdits(contents: string, edits?: readonly GradlePropertyEdit[]): string;
|
|
51
|
+
/** The package, versionCode and versionName from `aapt2 dump badging`. */
|
|
52
|
+
export interface BadgingFields {
|
|
53
|
+
name: string;
|
|
54
|
+
versionCode: string;
|
|
55
|
+
versionName: string;
|
|
56
|
+
}
|
|
57
|
+
/** Parses the `package:` line of `aapt2 dump badging` output. */
|
|
58
|
+
export declare function parseBadging(output: string): BadgingFields;
|
|
59
|
+
/** The release.json written next to the APK. */
|
|
60
|
+
export interface ReleaseJson {
|
|
61
|
+
versionName: string;
|
|
62
|
+
versionCode: number;
|
|
63
|
+
sha256: string;
|
|
64
|
+
}
|
|
65
|
+
/** Builds the release.json object from the version values and APK hash. */
|
|
66
|
+
export declare function releaseJson(versionName: string, versionCode: number, sha256: string): ReleaseJson;
|
|
67
|
+
/** Serialises release.json exactly as published (2-space indent, trailing newline). */
|
|
68
|
+
export declare function formatReleaseJson(release: ReleaseJson): string;
|
|
69
|
+
/** Formats the `key=value` lines appended to `$GITHUB_OUTPUT`. */
|
|
70
|
+
export declare function formatGithubOutput(outputs: Readonly<Record<string, string>>): string;
|
|
71
|
+
/** Per-app configuration for the Android release build. */
|
|
72
|
+
export interface AndroidReleaseConfig {
|
|
73
|
+
/** Android package id, such as `"com.projectvdotuk.vmem"`. */
|
|
74
|
+
packageId: string;
|
|
75
|
+
/** App folder relative to the repo root. Default `"apps/mobile"`. */
|
|
76
|
+
appDir: string;
|
|
77
|
+
/** Published APK name prefix, such as `"vmem"` (`vmem-1.0.1-android.apk`). */
|
|
78
|
+
apkPrefix: string;
|
|
79
|
+
/** `EXPO_PUBLIC_*` names that must be baked into the APK. */
|
|
80
|
+
publicEnv: readonly string[];
|
|
81
|
+
/** Where to read a default for a missing `EXPO_PUBLIC_*` value. */
|
|
82
|
+
publicEnvSources: readonly PublicEnvSource[];
|
|
83
|
+
/** `pnpm install --filter` values, such as `["@vmem/mobile...", "{.}"]`. */
|
|
84
|
+
pnpmFilters: readonly string[];
|
|
85
|
+
/** Pass `--no-install` to `expo prebuild` (vibot installs during prebuild). */
|
|
86
|
+
prebuildNoInstall: boolean;
|
|
87
|
+
/** Extra environment set for the whole build, such as `{ APP_VARIANT: "production" }`. */
|
|
88
|
+
extraEnv: Readonly<Record<string, string>>;
|
|
89
|
+
/** Optional `EXPO_PUBLIC_*` names (set from env when present, never required). */
|
|
90
|
+
optionalEnv: readonly string[];
|
|
91
|
+
/** Shell commands run in the repo root before the build, such as a Clerk check. */
|
|
92
|
+
preChecks: readonly string[];
|
|
93
|
+
/** Commands run in the app folder after install, before prebuild, such as `pnpm run test:babel`. */
|
|
94
|
+
preBuildSteps: readonly string[];
|
|
95
|
+
/** Pin the Gradle wrapper: replace `distributionUrl` when it contains `ifContains`. */
|
|
96
|
+
gradleWrapperPin?: {
|
|
97
|
+
ifContains: string;
|
|
98
|
+
distributionUrl: string;
|
|
99
|
+
};
|
|
100
|
+
/** Label and env var for the final summary line, such as `{ label: "Convex", envVar: "EXPO_PUBLIC_CONVEX_URL" }`. */
|
|
101
|
+
summary?: {
|
|
102
|
+
label: string;
|
|
103
|
+
envVar: string;
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Validates a parsed JSON config object into an {@link AndroidReleaseConfig},
|
|
108
|
+
* filling defaults. Throws a clear error on a bad shape. Kept hand-written so
|
|
109
|
+
* the package takes no schema dependency.
|
|
110
|
+
*/
|
|
111
|
+
export declare function parseAndroidReleaseConfig(input: unknown): AndroidReleaseConfig;
|
|
112
|
+
/** The published APK file name for a version, such as `vmem-1.0.1-android.apk`. */
|
|
113
|
+
export declare function apkFileName(apkPrefix: string, versionName: string): string;
|