@moku-labs/native 0.3.10 → 0.3.12
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 +16 -4
- package/dist/index.cjs +1445 -479
- package/dist/index.d.cts +63 -26
- package/dist/index.d.mts +63 -26
- package/dist/index.mjs +1445 -479
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -820,8 +820,8 @@ function generateCapabilities(input) {
|
|
|
820
820
|
//#endregion
|
|
821
821
|
//#region src/plugins/project/generators/cargo.ts
|
|
822
822
|
/**
|
|
823
|
-
* @file project plugin generator — Cargo.toml with registry-pinned crate dependencies
|
|
824
|
-
*
|
|
823
|
+
* @file project plugin generator — Cargo.toml with registry-pinned crate dependencies, the
|
|
824
|
+
* path dependency of every generated local crate, and the size profile of a release build.
|
|
825
825
|
*/
|
|
826
826
|
/**
|
|
827
827
|
* The `tauri` crate floor. The `back` capability calls `exit()` and grants
|
|
@@ -836,6 +836,19 @@ const TAURI_VERSION_FLOOR = "2.12";
|
|
|
836
836
|
*/
|
|
837
837
|
const IOS_ONLY_DEPENDENCIES = [`[target.'cfg(target_os = "ios")'.dependencies]`, "objc2 = \"0.6\""];
|
|
838
838
|
/**
|
|
839
|
+
* The release profile, for every target and both build profiles: the debug build is a
|
|
840
|
+
* release build too, so what a phone measures is what the store ships. It trades compile
|
|
841
|
+
* time for a smaller library, and `panic = "abort"` drops the unwinding tables.
|
|
842
|
+
*/
|
|
843
|
+
const RELEASE_PROFILE = [
|
|
844
|
+
"[profile.release]",
|
|
845
|
+
"codegen-units = 1",
|
|
846
|
+
"lto = true",
|
|
847
|
+
"opt-level = \"s\"",
|
|
848
|
+
"panic = \"abort\"",
|
|
849
|
+
"strip = true"
|
|
850
|
+
];
|
|
851
|
+
/**
|
|
839
852
|
* Derives a valid Cargo package name from the app's display name — lowercased,
|
|
840
853
|
* non-alphanumeric runs collapsed to a single hyphen, and guaranteed to start with a
|
|
841
854
|
* letter (Cargo package names must match `[a-z][a-z0-9_-]*`).
|
|
@@ -893,7 +906,8 @@ function dependencyLine(capability) {
|
|
|
893
906
|
* the tray API is not compiled in at all), plus one dependency line per resolved
|
|
894
907
|
* capability that ships a crate: pinned for a published one, by path for the generated
|
|
895
908
|
* shell crate. Feature-only and permission-only rows contribute no dependency line. The
|
|
896
|
-
* iOS-only `objc2` table closes the file on
|
|
909
|
+
* `[profile.release]` table follows, and the iOS-only `objc2` table closes the file on
|
|
910
|
+
* every target.
|
|
897
911
|
*
|
|
898
912
|
* @param input - Frozen global config + capabilities resolved for the target.
|
|
899
913
|
* @returns A single-artifact array for `src-tauri/Cargo.toml`.
|
|
@@ -923,6 +937,8 @@ function generateCargo(input) {
|
|
|
923
937
|
"serde_json = \"1\"",
|
|
924
938
|
...pinnedDeps,
|
|
925
939
|
"",
|
|
940
|
+
...RELEASE_PROFILE,
|
|
941
|
+
"",
|
|
926
942
|
...IOS_ONLY_DEPENDENCIES,
|
|
927
943
|
""
|
|
928
944
|
].join("\n")
|
|
@@ -1042,7 +1058,7 @@ function generateEntitlements(input) {
|
|
|
1042
1058
|
//#region src/plugins/project/generators/rust.ts
|
|
1043
1059
|
/**
|
|
1044
1060
|
* @file project plugin generator — main.rs/lib.rs with mobile entry point, plugin init
|
|
1045
|
-
* lines and the iOS safe
|
|
1061
|
+
* lines and the iOS setup hook (the safe area, and the idle timer with `app.keepScreenOn`).
|
|
1046
1062
|
*/
|
|
1047
1063
|
/**
|
|
1048
1064
|
* `Manager` brings `get_webview_window` into scope. Only the iOS arm of the setup hook
|
|
@@ -1050,11 +1066,12 @@ function generateEntitlements(input) {
|
|
|
1050
1066
|
*/
|
|
1051
1067
|
const IOS_MANAGER_IMPORT = ["#[cfg(target_os = \"ios\")]", "use tauri::Manager;"];
|
|
1052
1068
|
/**
|
|
1053
|
-
* The safe-area setup hook, as verified on the iOS 26.3
|
|
1054
|
-
* WKWebView page by the safe area while its scroll view stays on
|
|
1055
|
-
* gives the page the whole screen, and CSS `env(safe-area-inset-*)`
|
|
1056
|
-
* notch. The `cfg` makes it a no-op off iOS, so `lib.rs` does not differ
|
|
1057
|
-
* window is tauri's default `main` label: the generated `app.windows` entry
|
|
1069
|
+
* The safe-area setup hook up to the end of the iOS closure, as verified on the iOS 26.3
|
|
1070
|
+
* simulator. UIKit shrinks a WKWebView page by the safe area while its scroll view stays on
|
|
1071
|
+
* `.automatic`; `.never` gives the page the whole screen, and CSS `env(safe-area-inset-*)`
|
|
1072
|
+
* still reports the notch. The `cfg` makes it a no-op off iOS, so `lib.rs` does not differ
|
|
1073
|
+
* per target. The window is tauri's default `main` label: the generated `app.windows` entry
|
|
1074
|
+
* carries none.
|
|
1058
1075
|
*/
|
|
1059
1076
|
const SAFE_AREA_SETUP = [
|
|
1060
1077
|
" .setup(|_app| {",
|
|
@@ -1067,7 +1084,19 @@ const SAFE_AREA_SETUP = [
|
|
|
1067
1084
|
" let wk = &*(webview.inner() as *mut AnyObject);",
|
|
1068
1085
|
" let scroll: *mut AnyObject = msg_send![wk, scrollView];",
|
|
1069
1086
|
" // UIScrollViewContentInsetAdjustmentNever = 2",
|
|
1070
|
-
" let _: () = msg_send![&*scroll, setContentInsetAdjustmentBehavior: 2isize];"
|
|
1087
|
+
" let _: () = msg_send![&*scroll, setContentInsetAdjustmentBehavior: 2isize];"
|
|
1088
|
+
];
|
|
1089
|
+
/**
|
|
1090
|
+
* The `app.keepScreenOn` calls, the tail of the iOS closure: `with_webview` runs on the main
|
|
1091
|
+
* thread, the one UIKit wants them on, and the page cannot do this for itself on iOS.
|
|
1092
|
+
*/
|
|
1093
|
+
const IDLE_TIMER_CALLS = [
|
|
1094
|
+
" // iOS refuses navigator.wakeLock until the first tap, so the app does it at launch.",
|
|
1095
|
+
" let application: *mut AnyObject = msg_send![objc2::class!(UIApplication), sharedApplication];",
|
|
1096
|
+
" let _: () = msg_send![&*application, setIdleTimerDisabled: true];"
|
|
1097
|
+
];
|
|
1098
|
+
/** Closes the iOS closure and the setup hook. */
|
|
1099
|
+
const SETUP_END = [
|
|
1071
1100
|
" })?;",
|
|
1072
1101
|
" }",
|
|
1073
1102
|
" Ok(())",
|
|
@@ -1078,13 +1107,15 @@ const SAFE_AREA_SETUP = [
|
|
|
1078
1107
|
* `#[cfg_attr(mobile, tauri::mobile_entry_point)]`-annotated `run()` with one
|
|
1079
1108
|
* `.plugin(...)` init line per resolved capability that has a real Rust init (rows
|
|
1080
1109
|
* without one, e.g. tray's cargo-feature row, contribute no line), then the iOS
|
|
1081
|
-
* safe-area `.setup` hook
|
|
1110
|
+
* safe-area `.setup` hook, which turns the idle timer off too with `app.keepScreenOn`;
|
|
1111
|
+
* `main.rs` is a thin entry point that calls into the lib crate.
|
|
1082
1112
|
*
|
|
1083
1113
|
* @param input - Frozen global config + capabilities resolved for the target.
|
|
1084
1114
|
* @returns Artifacts for `src-tauri/src/lib.rs` and `src-tauri/src/main.rs`.
|
|
1085
1115
|
* @example
|
|
1086
1116
|
* ```ts
|
|
1087
|
-
* generateRust({ global, target: "android", capabilities: [] });
|
|
1117
|
+
* generateRust({ global, target: "android", capabilities: [], profile: "store" }).map(file => file.path);
|
|
1118
|
+
* // ["src-tauri/src/lib.rs", "src-tauri/src/main.rs"]
|
|
1088
1119
|
* ```
|
|
1089
1120
|
*/
|
|
1090
1121
|
function generateRust(input) {
|
|
@@ -1098,6 +1129,8 @@ function generateRust(input) {
|
|
|
1098
1129
|
" tauri::Builder::default()",
|
|
1099
1130
|
...pluginLines,
|
|
1100
1131
|
...SAFE_AREA_SETUP,
|
|
1132
|
+
...input.global.app.keepScreenOn ? IDLE_TIMER_CALLS : [],
|
|
1133
|
+
...SETUP_END,
|
|
1101
1134
|
" .run(tauri::generate_context!())",
|
|
1102
1135
|
" .expect(\"error while running tauri application\");",
|
|
1103
1136
|
"}",
|
|
@@ -1958,7 +1991,7 @@ function shellPageScript(input, profile) {
|
|
|
1958
1991
|
* @returns The crate's artifacts, paths relative to `projectDir`; empty without the shell.
|
|
1959
1992
|
* @example
|
|
1960
1993
|
* ```ts
|
|
1961
|
-
* generateShell({ global, target: "android", capabilities: [resolve("shell")] }, "debug")[0]?.path;
|
|
1994
|
+
* generateShell({ global, target: "android", capabilities: [resolve("shell")], profile: "debug" }, "debug")[0]?.path;
|
|
1962
1995
|
* // "plugins/moku-shell/Cargo.toml"
|
|
1963
1996
|
* ```
|
|
1964
1997
|
*/
|
|
@@ -2097,32 +2130,72 @@ function escapeXml(text) {
|
|
|
2097
2130
|
/**
|
|
2098
2131
|
* @file project plugin generator — Info.ios.plist sidecar (src-tauri root, outside gen/).
|
|
2099
2132
|
*/
|
|
2133
|
+
/** One indentation step of the generated plist. */
|
|
2134
|
+
const PLIST_INDENT = " ";
|
|
2135
|
+
/**
|
|
2136
|
+
* Tells a plist `<array>` from a `<dict>`: `Array.isArray` alone does not narrow a readonly
|
|
2137
|
+
* array.
|
|
2138
|
+
*
|
|
2139
|
+
* @param value - An array or a dictionary value.
|
|
2140
|
+
* @returns True, narrowing `value`, when it is an array.
|
|
2141
|
+
* @example
|
|
2142
|
+
* ```ts
|
|
2143
|
+
* isPlistArray(["a"]); // true
|
|
2144
|
+
* ```
|
|
2145
|
+
*/
|
|
2146
|
+
function isPlistArray(value) {
|
|
2147
|
+
return Array.isArray(value);
|
|
2148
|
+
}
|
|
2149
|
+
/**
|
|
2150
|
+
* Renders one dictionary's entries as `<key>` lines, each followed by its value. Every key is
|
|
2151
|
+
* XML-escaped.
|
|
2152
|
+
*
|
|
2153
|
+
* @param entries - The key/value pairs, in order.
|
|
2154
|
+
* @param indent - The indentation of the `<key>` lines.
|
|
2155
|
+
* @returns The entries' lines.
|
|
2156
|
+
* @example
|
|
2157
|
+
* ```ts
|
|
2158
|
+
* renderPlistEntries([["A&B", true]], " "); // [" <key>A&B</key>", " <true/>"]
|
|
2159
|
+
* ```
|
|
2160
|
+
*/
|
|
2161
|
+
function renderPlistEntries(entries, indent) {
|
|
2162
|
+
return [...entries].flatMap(([key, value]) => [`${indent}<key>${escapeXml(key)}</key>`, ...renderPlistValue(value, indent)]);
|
|
2163
|
+
}
|
|
2100
2164
|
/**
|
|
2101
2165
|
* Renders one plist value as the lines that follow its `<key>`: a `<string>`, a
|
|
2102
|
-
* `<true/>`/`<false/>`, or an `<array>` of
|
|
2166
|
+
* `<true/>`/`<false/>`, or an `<array>` or `<dict>` holding more of them, as deep as the
|
|
2167
|
+
* value goes. Every text is XML-escaped.
|
|
2103
2168
|
*
|
|
2104
2169
|
* @param value - The entry value.
|
|
2105
|
-
* @
|
|
2170
|
+
* @param indent - The indentation of the value's first line.
|
|
2171
|
+
* @returns The value's lines.
|
|
2106
2172
|
* @example
|
|
2107
2173
|
* ```ts
|
|
2108
|
-
* renderPlistValue(["UIInterfaceOrientationPortrait"]);
|
|
2174
|
+
* renderPlistValue(["UIInterfaceOrientationPortrait"], " ");
|
|
2109
2175
|
* // [" <array>", " <string>UIInterfaceOrientationPortrait</string>", " </array>"]
|
|
2110
2176
|
* ```
|
|
2111
2177
|
*/
|
|
2112
|
-
function renderPlistValue(value) {
|
|
2113
|
-
if (typeof value === "boolean") return [value ? "
|
|
2114
|
-
if (typeof value === "string") return [
|
|
2178
|
+
function renderPlistValue(value, indent) {
|
|
2179
|
+
if (typeof value === "boolean") return [`${indent}${value ? "<true/>" : "<false/>"}`];
|
|
2180
|
+
if (typeof value === "string") return [`${indent}<string>${escapeXml(value)}</string>`];
|
|
2181
|
+
const nested = `${indent}${PLIST_INDENT}`;
|
|
2182
|
+
if (isPlistArray(value)) return [
|
|
2183
|
+
`${indent}<array>`,
|
|
2184
|
+
...value.flatMap((item) => renderPlistValue(item, nested)),
|
|
2185
|
+
`${indent}</array>`
|
|
2186
|
+
];
|
|
2115
2187
|
return [
|
|
2116
|
-
|
|
2117
|
-
...
|
|
2118
|
-
|
|
2188
|
+
`${indent}<dict>`,
|
|
2189
|
+
...renderPlistEntries(Object.entries(value), nested),
|
|
2190
|
+
`${indent}</dict>`
|
|
2119
2191
|
];
|
|
2120
2192
|
}
|
|
2121
2193
|
/**
|
|
2122
2194
|
* Generates the `Info.ios.plist` SIDECAR at the src-tauri root, which Tauri merges into the
|
|
2123
2195
|
* app's Info.plist on every iOS build. Its entries are every resolved capability's
|
|
2124
|
-
* `sidecarPlist`, then the orientation lock (`app.orientation`); on a
|
|
2125
|
-
* later entry wins, so
|
|
2196
|
+
* `sidecarPlist`, then `ios.infoPlist`, then the orientation lock (`app.orientation`); on a
|
|
2197
|
+
* duplicate key the later entry wins, so the app's keys beat a capability and orientation
|
|
2198
|
+
* beats both.
|
|
2126
2199
|
*
|
|
2127
2200
|
* On iOS the file is ALWAYS written, as an empty `<dict>` when nothing contributes a key:
|
|
2128
2201
|
* the writer never deletes a file, and a portrait lock left in a stale sidecar would keep
|
|
@@ -2134,15 +2207,22 @@ function renderPlistValue(value) {
|
|
|
2134
2207
|
* ```ts
|
|
2135
2208
|
* // `config` is any full native Config
|
|
2136
2209
|
* const global = { ...config, app: { name: "Demo", identifier: "com.acme.demo", orientation: "portrait" } };
|
|
2137
|
-
* generateSidecar({ global, target: "ios", capabilities: [] })[0]?.path; // "src-tauri/Info.ios.plist"
|
|
2210
|
+
* generateSidecar({ global, target: "ios", capabilities: [], profile: "store" })[0]?.path; // "src-tauri/Info.ios.plist"
|
|
2138
2211
|
* // its <dict>: UISupportedInterfaceOrientations, UISupportedInterfaceOrientations~ipad, UIRequiresFullScreen
|
|
2139
|
-
* generateSidecar({ global, target: "macos", capabilities: [] }); // []
|
|
2212
|
+
* generateSidecar({ global, target: "macos", capabilities: [], profile: "store" }); // []
|
|
2140
2213
|
* ```
|
|
2141
2214
|
*/
|
|
2142
2215
|
function generateSidecar(input) {
|
|
2143
2216
|
if (input.target !== "ios") return [];
|
|
2144
2217
|
const entries = /* @__PURE__ */ new Map();
|
|
2145
|
-
const contributed = [
|
|
2218
|
+
const contributed = [
|
|
2219
|
+
...input.capabilities.flatMap((capability) => capability.sidecarPlist),
|
|
2220
|
+
...Object.entries(input.global.ios?.infoPlist ?? {}).map(([key, value]) => ({
|
|
2221
|
+
key,
|
|
2222
|
+
value
|
|
2223
|
+
})),
|
|
2224
|
+
...orientationPlist(input.global.app.orientation)
|
|
2225
|
+
];
|
|
2146
2226
|
for (const entry of contributed) entries.set(entry.key, entry.value);
|
|
2147
2227
|
return [{
|
|
2148
2228
|
path: "src-tauri/Info.ios.plist",
|
|
@@ -2151,7 +2231,7 @@ function generateSidecar(input) {
|
|
|
2151
2231
|
"<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">",
|
|
2152
2232
|
"<plist version=\"1.0\">",
|
|
2153
2233
|
"<dict>",
|
|
2154
|
-
...
|
|
2234
|
+
...renderPlistEntries(entries, PLIST_INDENT),
|
|
2155
2235
|
"</dict>",
|
|
2156
2236
|
"</plist>",
|
|
2157
2237
|
""
|
|
@@ -2162,7 +2242,7 @@ function generateSidecar(input) {
|
|
|
2162
2242
|
//#region src/plugins/project/generators/tauri-conf.ts
|
|
2163
2243
|
/**
|
|
2164
2244
|
* @file project plugin generator — tauri.conf.json (identity, build wiring, bundle
|
|
2165
|
-
* metadata, Apple signing, plugin blocks).
|
|
2245
|
+
* metadata, Apple signing, the Android versionCode, plugin blocks).
|
|
2166
2246
|
*/
|
|
2167
2247
|
/**
|
|
2168
2248
|
* The icon set `tauri icon` writes into `src-tauri/icons`. Tauri reads `bundle.icon` at
|
|
@@ -2175,13 +2255,10 @@ const BUNDLE_ICONS = [
|
|
|
2175
2255
|
"icons/icon.icns",
|
|
2176
2256
|
"icons/icon.ico"
|
|
2177
2257
|
];
|
|
2178
|
-
/**
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
* on a current Xcode failed until the person found and set this value themselves.
|
|
2183
|
-
*/
|
|
2184
|
-
const DEFAULT_IOS_MINIMUM_SYSTEM_VERSION = "15.0";
|
|
2258
|
+
/** A whole number without leading zeros: the only shape Gradle's `versionCode` takes. */
|
|
2259
|
+
const VERSION_CODE_PATTERN = /^[1-9]\d*$/;
|
|
2260
|
+
/** The highest `versionCode` Google Play accepts. */
|
|
2261
|
+
const MAX_VERSION_CODE = 21e8;
|
|
2185
2262
|
/**
|
|
2186
2263
|
* Drops the entries whose value is unset, so an unconfigured store/signing field is
|
|
2187
2264
|
* ABSENT from the JSON rather than present-and-null (Tauri rejects null there).
|
|
@@ -2199,16 +2276,51 @@ function compact(entries) {
|
|
|
2199
2276
|
return result;
|
|
2200
2277
|
}
|
|
2201
2278
|
/**
|
|
2279
|
+
* Reads the Android `versionCode` from `app.buildNumber`, as the JSON number Tauri asks for.
|
|
2280
|
+
* Checked here and not at composition: `"1.0.3"` stays a legal macOS/iOS bundle version, and
|
|
2281
|
+
* `build.run({ targets })` may name a target outside `config.targets`.
|
|
2282
|
+
*
|
|
2283
|
+
* @param input - Frozen global config + the target being generated for.
|
|
2284
|
+
* @returns The `versionCode` on android with a build number set, undefined otherwise.
|
|
2285
|
+
* @throws {Error} `[native]` on android when the build number is not a whole number from 1
|
|
2286
|
+
* to 2100000000.
|
|
2287
|
+
* @example
|
|
2288
|
+
* ```ts
|
|
2289
|
+
* androidVersionCode({ global: { app: { buildNumber: "42" } }, target: "android" }); // 42
|
|
2290
|
+
* ```
|
|
2291
|
+
*/
|
|
2292
|
+
function androidVersionCode(input) {
|
|
2293
|
+
const { buildNumber } = input.global.app;
|
|
2294
|
+
if (input.target !== "android" || buildNumber === void 0) return void 0;
|
|
2295
|
+
const versionCode = Number(buildNumber);
|
|
2296
|
+
if (VERSION_CODE_PATTERN.test(buildNumber) && versionCode <= MAX_VERSION_CODE) return versionCode;
|
|
2297
|
+
throw new Error(`[native] app.buildNumber "${buildNumber}" is not a valid Android versionCode.\n Use a whole number from 1 to ${MAX_VERSION_CODE}, such as "42".`);
|
|
2298
|
+
}
|
|
2299
|
+
/**
|
|
2300
|
+
* Whether a platform block carries anything worth writing.
|
|
2301
|
+
*
|
|
2302
|
+
* @param block - A compacted block.
|
|
2303
|
+
* @returns True when the block has at least one key.
|
|
2304
|
+
* @example
|
|
2305
|
+
* ```ts
|
|
2306
|
+
* hasEntries({}); // false
|
|
2307
|
+
* ```
|
|
2308
|
+
*/
|
|
2309
|
+
function hasEntries(block) {
|
|
2310
|
+
return Object.keys(block).length > 0;
|
|
2311
|
+
}
|
|
2312
|
+
/**
|
|
2202
2313
|
* Builds the `bundle` block — icon set, optional store metadata, and the signing
|
|
2203
|
-
* identifiers. `iOS` and `android` always exist (Tauri expects the keys),
|
|
2204
|
-
* carries a deployment target Xcode accepts
|
|
2205
|
-
*
|
|
2314
|
+
* identifiers. `iOS` and `android` always exist (Tauri expects the keys), `iOS` always
|
|
2315
|
+
* carries a deployment target Xcode accepts, and `android` carries a `versionCode` on an
|
|
2316
|
+
* android build with a build number; `macOS` and `windows` appear only when something is
|
|
2317
|
+
* actually configured for them.
|
|
2206
2318
|
*
|
|
2207
2319
|
* @param input - Frozen global config + capabilities resolved for the target.
|
|
2208
2320
|
* @returns The `bundle` object for tauri.conf.json.
|
|
2209
2321
|
* @example
|
|
2210
2322
|
* ```ts
|
|
2211
|
-
* buildBundle({ global: { app: { name: "App" }, signing: {} }, target: "ios", capabilities: [] }).iOS;
|
|
2323
|
+
* buildBundle({ global: { app: { name: "App" }, signing: {} }, target: "ios", capabilities: [], profile: "store" }).iOS;
|
|
2212
2324
|
* // { minimumSystemVersion: "15.0" }
|
|
2213
2325
|
* ```
|
|
2214
2326
|
*/
|
|
@@ -2216,6 +2328,7 @@ function buildBundle(input) {
|
|
|
2216
2328
|
const { app, signing } = input.global;
|
|
2217
2329
|
const apple = signing.apple ?? {};
|
|
2218
2330
|
const windows = compact([["certificateThumbprint", signing.windows?.certificateThumbprint]]);
|
|
2331
|
+
const versionCode = androidVersionCode(input);
|
|
2219
2332
|
const macOS = compact([
|
|
2220
2333
|
["signingIdentity", apple.signingIdentity],
|
|
2221
2334
|
["providerShortName", apple.providerShortName],
|
|
@@ -2230,12 +2343,12 @@ function buildBundle(input) {
|
|
|
2230
2343
|
...compact([["category", app.category]]),
|
|
2231
2344
|
iOS: compact([
|
|
2232
2345
|
["developmentTeam", apple.teamId],
|
|
2233
|
-
["minimumSystemVersion", apple.iosMinimumSystemVersion ??
|
|
2346
|
+
["minimumSystemVersion", apple.iosMinimumSystemVersion ?? "15.0"],
|
|
2234
2347
|
["bundleVersion", app.buildNumber]
|
|
2235
2348
|
]),
|
|
2236
|
-
...
|
|
2237
|
-
...
|
|
2238
|
-
android: {}
|
|
2349
|
+
...hasEntries(macOS) ? { macOS } : {},
|
|
2350
|
+
...hasEntries(windows) ? { windows } : {},
|
|
2351
|
+
android: versionCode === void 0 ? {} : { versionCode }
|
|
2239
2352
|
};
|
|
2240
2353
|
}
|
|
2241
2354
|
/**
|
|
@@ -2263,9 +2376,10 @@ function buildPlugins(capabilities) {
|
|
|
2263
2376
|
return plugins;
|
|
2264
2377
|
}
|
|
2265
2378
|
/**
|
|
2266
|
-
* Generates `src-tauri/tauri.conf.json` — app identity, the web build/dev wiring,
|
|
2267
|
-
*
|
|
2268
|
-
*
|
|
2379
|
+
* Generates `src-tauri/tauri.conf.json` — app identity, the web build/dev wiring, with
|
|
2380
|
+
* `removeUnusedCommands` in the store profile only (a debug page may call what a store
|
|
2381
|
+
* page does not), the main window (its title, plus `app.backgroundColor` when set), the
|
|
2382
|
+
* bundle/signing metadata, and a `plugins.<name>` block per CONFIGURED capability (see
|
|
2269
2383
|
* {@link buildPlugins}; this is where deep-link's scheme rides — per D-011/D-012 the whole
|
|
2270
2384
|
* v1 mobile-permission story is conf-only). Both path-shaped fields are rebased onto
|
|
2271
2385
|
* `src-tauri`, which is where Tauri resolves them from, and the before-commands carry an
|
|
@@ -2273,9 +2387,11 @@ function buildPlugins(capabilities) {
|
|
|
2273
2387
|
*
|
|
2274
2388
|
* @param input - Frozen global config + capabilities resolved for the target.
|
|
2275
2389
|
* @returns A single-artifact array for `src-tauri/tauri.conf.json`.
|
|
2390
|
+
* @throws {Error} `[native]` on android when `app.buildNumber` is not a valid `versionCode`.
|
|
2276
2391
|
* @example
|
|
2277
2392
|
* ```ts
|
|
2278
|
-
* generateTauriConf({ global, target: "ios", capabilities: [] });
|
|
2393
|
+
* generateTauriConf({ global, target: "ios", capabilities: [], profile: "store" })[0]?.path;
|
|
2394
|
+
* // "src-tauri/tauri.conf.json"
|
|
2279
2395
|
* ```
|
|
2280
2396
|
*/
|
|
2281
2397
|
function generateTauriConf(input) {
|
|
@@ -2295,7 +2411,8 @@ function generateTauriConf(input) {
|
|
|
2295
2411
|
cwd: webRoot
|
|
2296
2412
|
},
|
|
2297
2413
|
devUrl: global.web.devUrl,
|
|
2298
|
-
frontendDist: relativeToTauriRoot(global.projectDir, node_path.default.resolve(webRoot, global.web.dist))
|
|
2414
|
+
frontendDist: relativeToTauriRoot(global.projectDir, node_path.default.resolve(webRoot, global.web.dist)),
|
|
2415
|
+
...input.profile === "store" ? { removeUnusedCommands: true } : {}
|
|
2299
2416
|
},
|
|
2300
2417
|
app: { windows: [{
|
|
2301
2418
|
title: global.app.name,
|
|
@@ -2604,12 +2721,13 @@ async function writeIfChanged(filePath, content, projectDirectory) {
|
|
|
2604
2721
|
//#region src/plugins/project/mobile/files.ts
|
|
2605
2722
|
/**
|
|
2606
2723
|
* @file project plugin — the ONE owner of "which generated files a mobile patch pass may
|
|
2607
|
-
* touch".
|
|
2608
|
-
*
|
|
2609
|
-
* about — and
|
|
2610
|
-
* belong to the toolchain. The
|
|
2611
|
-
*
|
|
2612
|
-
*
|
|
2724
|
+
* touch". Every iOS patch (the runner-command rewrite, the Xcode build-settings patch and
|
|
2725
|
+
* the iOS project patches) reads the same list from here, so none can drift into a file the
|
|
2726
|
+
* others do not know about — and none ever descends into `gen/apple/build` or
|
|
2727
|
+
* `gen/android/build`, which belong to the toolchain. The privacy manifest's place in the
|
|
2728
|
+
* tree is here too. The Android status bar patch finds its MainActivity.kt here, the profile
|
|
2729
|
+
* patches their `strings.xml` and network security config, and the icon inset its adaptive
|
|
2730
|
+
* icon directory.
|
|
2613
2731
|
*/
|
|
2614
2732
|
/** Source extensions that can carry the Android runner command. */
|
|
2615
2733
|
const ANDROID_SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
@@ -2639,6 +2757,8 @@ const SKIPPED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
|
2639
2757
|
".gradle",
|
|
2640
2758
|
".idea"
|
|
2641
2759
|
]);
|
|
2760
|
+
/** The file name Apple reads a privacy manifest from, at the top of the app bundle. */
|
|
2761
|
+
const IOS_PRIVACY_MANIFEST_FILE = "PrivacyInfo.xcprivacy";
|
|
2642
2762
|
/**
|
|
2643
2763
|
* Lists the generated iOS files a patch pass may rewrite: `project.yml` plus the
|
|
2644
2764
|
* `project.pbxproj` of every generated Xcode project. `gen/apple/build` is never listed —
|
|
@@ -2663,6 +2783,21 @@ async function iosPatchFiles(genDirectory) {
|
|
|
2663
2783
|
return files;
|
|
2664
2784
|
}
|
|
2665
2785
|
/**
|
|
2786
|
+
* Returns where the iOS patch pass keeps the privacy manifest: the top of `gen/apple`, the
|
|
2787
|
+
* directory `project.yml` and the pbxproj's root group resolve a relative path from.
|
|
2788
|
+
*
|
|
2789
|
+
* @param genDirectory - The `src-tauri/gen/apple` directory.
|
|
2790
|
+
* @returns The `PrivacyInfo.xcprivacy` path of that tree.
|
|
2791
|
+
* @example
|
|
2792
|
+
* ```ts
|
|
2793
|
+
* iosPrivacyManifestPath("/repo/.moku/tauri/src-tauri/gen/apple");
|
|
2794
|
+
* // "/repo/.moku/tauri/src-tauri/gen/apple/PrivacyInfo.xcprivacy"
|
|
2795
|
+
* ```
|
|
2796
|
+
*/
|
|
2797
|
+
function iosPrivacyManifestPath(genDirectory) {
|
|
2798
|
+
return node_path.default.join(genDirectory, IOS_PRIVACY_MANIFEST_FILE);
|
|
2799
|
+
}
|
|
2800
|
+
/**
|
|
2666
2801
|
* Walks a directory tree collecting accepted files, skipping derived build output.
|
|
2667
2802
|
*
|
|
2668
2803
|
* @param directory - The directory to walk (a missing directory yields nothing).
|
|
@@ -2731,6 +2866,21 @@ async function androidMainActivityFiles(genDirectory) {
|
|
|
2731
2866
|
return (await collectFiles(androidJavaDirectory(genDirectory), (name) => name === MAIN_ACTIVITY_FILE)).toSorted();
|
|
2732
2867
|
}
|
|
2733
2868
|
/**
|
|
2869
|
+
* Returns the directory `tauri android init` writes the app's resources into, where the
|
|
2870
|
+
* window background patch finds every `values*\/themes.xml`.
|
|
2871
|
+
*
|
|
2872
|
+
* @param genDirectory - The `src-tauri/gen/android` directory.
|
|
2873
|
+
* @returns The `app/src/main/res` directory of that tree.
|
|
2874
|
+
* @example
|
|
2875
|
+
* ```ts
|
|
2876
|
+
* androidResourceDirectory("/repo/.moku/tauri/src-tauri/gen/android");
|
|
2877
|
+
* // "/repo/.moku/tauri/src-tauri/gen/android/app/src/main/res"
|
|
2878
|
+
* ```
|
|
2879
|
+
*/
|
|
2880
|
+
function androidResourceDirectory(genDirectory) {
|
|
2881
|
+
return node_path.default.join(genDirectory, ...ANDROID_RESOURCE_SEGMENTS);
|
|
2882
|
+
}
|
|
2883
|
+
/**
|
|
2734
2884
|
* Returns the app's string resources, where the debug profile renames the app.
|
|
2735
2885
|
*
|
|
2736
2886
|
* @param genDirectory - The `src-tauri/gen/android` directory.
|
|
@@ -2836,154 +2986,936 @@ async function patchAndroidIcon(options) {
|
|
|
2836
2986
|
};
|
|
2837
2987
|
}
|
|
2838
2988
|
//#endregion
|
|
2839
|
-
//#region src/plugins/project/mobile/
|
|
2989
|
+
//#region src/plugins/project/mobile/xcode-settings.ts
|
|
2840
2990
|
/**
|
|
2841
|
-
* @file project plugin — the
|
|
2842
|
-
* main activity carries (`android:screenOrientation` among them), so the mobile patch pass
|
|
2843
|
-
* sets those attributes on the `<activity>` of the generated
|
|
2844
|
-
* `gen/android/app/src/main/AndroidManifest.xml` itself. The same rules set attributes on
|
|
2845
|
-
* the `<application>` start tag (the debug profile's network security config).
|
|
2991
|
+
* @file project plugin — the Xcode build-settings patch that makes an iOS REBUILD work.
|
|
2846
2992
|
*
|
|
2847
|
-
*
|
|
2848
|
-
*
|
|
2993
|
+
* A capability plugin's build script rewrites the generated `<app>_iOS.entitlements` file
|
|
2994
|
+
* while Xcode is compiling, and Xcode fails the second build on that:
|
|
2995
|
+
* `Entitlements file "<app>_iOS.entitlements" was modified during the build, which is not
|
|
2996
|
+
* supported`. Xcode names the way out itself — `CODE_SIGN_ALLOW_ENTITLEMENTS_MODIFICATION`
|
|
2997
|
+
* — so every `buildSettings` block of the generated `project.pbxproj` carries it, and the
|
|
2998
|
+
* `project.yml` target carries it too, so a later xcodegen regeneration keeps it.
|
|
2999
|
+
*
|
|
3000
|
+
* Both transforms are pure text functions over the real generated shapes: line endings,
|
|
3001
|
+
* indentation and every neighbouring line survive byte for byte, and a second pass is a
|
|
3002
|
+
* no-op.
|
|
2849
3003
|
*/
|
|
2850
|
-
/**
|
|
2851
|
-
const
|
|
2852
|
-
|
|
2853
|
-
|
|
2854
|
-
"main",
|
|
2855
|
-
"AndroidManifest.xml"
|
|
2856
|
-
];
|
|
2857
|
-
/** The tag name the application start tag opens with. */
|
|
2858
|
-
const APPLICATION_OPEN = "<application";
|
|
2859
|
-
/** Where an `<application` start tag opens. */
|
|
2860
|
-
const APPLICATION_OPEN_PATTERN = /<application(?=[\s/>])/;
|
|
2861
|
-
/** The tag name an activity start tag opens with. */
|
|
2862
|
-
const ACTIVITY_OPEN = "<activity";
|
|
2863
|
-
/** The end tag that closes an activity's body. */
|
|
2864
|
-
const ACTIVITY_CLOSE = "</activity>";
|
|
2865
|
-
/** The intent action that marks the launcher activity. */
|
|
2866
|
-
const MAIN_ACTION = "android.intent.action.MAIN";
|
|
2867
|
-
/** Where an `<activity` start tag opens — `<activity-alias` is a different element. */
|
|
2868
|
-
const ACTIVITY_OPEN_PATTERN = /<activity(?=[\s/>])/g;
|
|
3004
|
+
/** The Xcode build setting that permits a build script to rewrite the entitlements file. */
|
|
3005
|
+
const ENTITLEMENTS_MODIFICATION_KEY = "CODE_SIGN_ALLOW_ENTITLEMENTS_MODIFICATION";
|
|
3006
|
+
/** The pbxproj value form — Xcode writes booleans as `YES`/`NO`. */
|
|
3007
|
+
const PBXPROJ_ENABLED_VALUE = "YES";
|
|
2869
3008
|
/**
|
|
2870
|
-
*
|
|
2871
|
-
*
|
|
3009
|
+
* The project.yml value form. xcodegen renders a YAML boolean as `YES` in the pbxproj it
|
|
3010
|
+
* generates, which is why the target's sibling settings read `true`/`false` there.
|
|
2872
3011
|
*/
|
|
2873
|
-
const
|
|
2874
|
-
/**
|
|
2875
|
-
const
|
|
3012
|
+
const YML_ENABLED_VALUE = "true";
|
|
3013
|
+
/** Opens one settings block inside a `XCBuildConfiguration` section. */
|
|
3014
|
+
const BUILD_SETTINGS_OPEN_PATTERN = /^([ \t]*)buildSettings = \{[ \t]*$/;
|
|
3015
|
+
/** The setting, already present as a pbxproj assignment (whatever its value). */
|
|
3016
|
+
const PBXPROJ_SETTING_PATTERN = new RegExp(`^[ \t]*${ENTITLEMENTS_MODIFICATION_KEY}[ \t]*=`);
|
|
3017
|
+
/** The setting, already present as a YAML key (whatever its value). */
|
|
3018
|
+
const YML_SETTING_PATTERN = new RegExp(`^[ \t]*${ENTITLEMENTS_MODIFICATION_KEY}[ \t]*:`);
|
|
3019
|
+
/** Opens a target's `settings:` mapping in `project.yml`. */
|
|
3020
|
+
const YML_SETTINGS_PATTERN = /^([ \t]*)settings:[ \t]*$/;
|
|
3021
|
+
/** Opens the `base:` mapping a `settings:` block carries its own build settings in. */
|
|
3022
|
+
const YML_BASE_PATTERN = /^([ \t]*)base:[ \t]*$/;
|
|
3023
|
+
/** The leading whitespace of a line — never matches a line break. */
|
|
3024
|
+
const INDENT_PATTERN$1 = /^[ \t]*/;
|
|
3025
|
+
/** Splits text into lines, keeping each line's own terminator attached to it. */
|
|
3026
|
+
const LINE_SPLIT_PATTERN = /(?<=\n)/;
|
|
3027
|
+
/** A line's terminator (LF or CRLF), stripped to compare the line's text alone. */
|
|
3028
|
+
const LINE_ENDING_PATTERN = /\r?\n$/;
|
|
3029
|
+
/** One indentation step inside a pbxproj — the generated file is tab-indented. */
|
|
3030
|
+
const PBXPROJ_NESTED_INDENT = " ";
|
|
3031
|
+
/** One indentation step inside a project.yml — YAML mappings never indent with tabs. */
|
|
3032
|
+
const YML_NESTED_INDENT = " ";
|
|
2876
3033
|
/**
|
|
2877
|
-
*
|
|
3034
|
+
* Splits text into lines that each remember their own terminator, so a file mixing (or
|
|
3035
|
+
* using) CRLF comes back out exactly as it went in.
|
|
2878
3036
|
*
|
|
2879
|
-
* @param
|
|
2880
|
-
* @returns
|
|
3037
|
+
* @param text - The file content.
|
|
3038
|
+
* @returns One entry per line, in order.
|
|
2881
3039
|
* @example
|
|
2882
3040
|
* ```ts
|
|
2883
|
-
*
|
|
3041
|
+
* splitLines("a\r\nb"); // [{ body: "a", ending: "\r\n" }, { body: "b", ending: "" }]
|
|
2884
3042
|
* ```
|
|
2885
3043
|
*/
|
|
2886
|
-
function
|
|
2887
|
-
return
|
|
3044
|
+
function splitLines$1(text) {
|
|
3045
|
+
return text.split(LINE_SPLIT_PATTERN).map((chunk) => {
|
|
3046
|
+
const body = chunk.replace(LINE_ENDING_PATTERN, "");
|
|
3047
|
+
return {
|
|
3048
|
+
body,
|
|
3049
|
+
ending: chunk.slice(body.length)
|
|
3050
|
+
};
|
|
3051
|
+
});
|
|
2888
3052
|
}
|
|
2889
3053
|
/**
|
|
2890
|
-
*
|
|
3054
|
+
* Joins lines back into file content.
|
|
2891
3055
|
*
|
|
2892
|
-
* @param
|
|
2893
|
-
* @returns
|
|
3056
|
+
* @param lines - The lines to join.
|
|
3057
|
+
* @returns The file content.
|
|
2894
3058
|
* @example
|
|
2895
3059
|
* ```ts
|
|
2896
|
-
*
|
|
3060
|
+
* joinLines([{ body: "a", ending: "\n" }]); // "a\n"
|
|
2897
3061
|
* ```
|
|
2898
3062
|
*/
|
|
2899
|
-
function
|
|
2900
|
-
return
|
|
3063
|
+
function joinLines(lines) {
|
|
3064
|
+
return lines.map((line) => line.body + line.ending).join("");
|
|
2901
3065
|
}
|
|
2902
3066
|
/**
|
|
2903
|
-
*
|
|
2904
|
-
* one never ends the tag.
|
|
3067
|
+
* Reads a line's leading whitespace — the indentation a new sibling line has to match.
|
|
2905
3068
|
*
|
|
2906
|
-
* @param
|
|
2907
|
-
* @
|
|
2908
|
-
* @returns The offset just past the closing `>`, or undefined for a tag that never closes.
|
|
3069
|
+
* @param body - The line's text.
|
|
3070
|
+
* @returns The leading spaces/tabs, possibly empty.
|
|
2909
3071
|
* @example
|
|
2910
3072
|
* ```ts
|
|
2911
|
-
*
|
|
3073
|
+
* indentOf("\t\t\tisa = XCBuildConfiguration;"); // "\t\t\t"
|
|
2912
3074
|
* ```
|
|
2913
3075
|
*/
|
|
2914
|
-
function
|
|
2915
|
-
|
|
2916
|
-
for (let index = from; index < text.length; index += 1) {
|
|
2917
|
-
const character = text[index];
|
|
2918
|
-
if (quote !== void 0) {
|
|
2919
|
-
if (character === quote) quote = void 0;
|
|
2920
|
-
continue;
|
|
2921
|
-
}
|
|
2922
|
-
if (character === "\"" || character === "'") {
|
|
2923
|
-
quote = character;
|
|
2924
|
-
continue;
|
|
2925
|
-
}
|
|
2926
|
-
if (character === ">") return index + 1;
|
|
2927
|
-
}
|
|
3076
|
+
function indentOf(body) {
|
|
3077
|
+
return INDENT_PATTERN$1.exec(body)?.[0] ?? "";
|
|
2928
3078
|
}
|
|
2929
3079
|
/**
|
|
2930
|
-
*
|
|
2931
|
-
*
|
|
2932
|
-
*
|
|
2933
|
-
* that never closes is not counted at all.
|
|
3080
|
+
* Returns a block that carries the setting exactly once: an assignment already there is
|
|
3081
|
+
* rewritten in place (a block that turned the setting OFF would still break the rebuild),
|
|
3082
|
+
* and an absent one is inserted as the block's first entry, at its siblings' indentation.
|
|
2934
3083
|
*
|
|
2935
|
-
* @param
|
|
2936
|
-
* @
|
|
3084
|
+
* @param block - The lines inside the block, without its opening and closing line.
|
|
3085
|
+
* @param options - How to place the setting.
|
|
3086
|
+
* @param options.present - Matches an assignment of the setting already in the block.
|
|
3087
|
+
* @param options.render - Renders the setting line at a given indentation.
|
|
3088
|
+
* @param options.fallbackIndent - Indentation used when the block carries no line to match.
|
|
3089
|
+
* @param options.fallbackEnding - Terminator used when the block carries no line to match.
|
|
3090
|
+
* @returns The block's lines, with the setting present exactly once.
|
|
2937
3091
|
* @example
|
|
2938
3092
|
* ```ts
|
|
2939
|
-
*
|
|
2940
|
-
* // [{ start: 0, end: 30, isMain: false }, { start: 30, end: 58, isMain: true }]
|
|
3093
|
+
* placeSetting(block, { present: PBXPROJ_SETTING_PATTERN, render, fallbackIndent, fallbackEnding });
|
|
2941
3094
|
* ```
|
|
2942
3095
|
*/
|
|
2943
|
-
function
|
|
2944
|
-
const
|
|
2945
|
-
const
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
|
|
2954
|
-
|
|
2955
|
-
});
|
|
2956
|
-
}
|
|
2957
|
-
return activities;
|
|
3096
|
+
function placeSetting(block, options) {
|
|
3097
|
+
const { present, render, fallbackIndent, fallbackEnding } = options;
|
|
3098
|
+
const existingIndex = block.findIndex((line) => present.test(line.body));
|
|
3099
|
+
if (existingIndex !== -1) return block.map((line, index) => index === existingIndex ? {
|
|
3100
|
+
body: render(indentOf(line.body)),
|
|
3101
|
+
ending: line.ending
|
|
3102
|
+
} : line);
|
|
3103
|
+
const sibling = block.find((line) => line.body.trim().length > 0);
|
|
3104
|
+
return [{
|
|
3105
|
+
body: render(sibling ? indentOf(sibling.body) : fallbackIndent),
|
|
3106
|
+
ending: sibling?.ending ?? fallbackEnding
|
|
3107
|
+
}, ...block];
|
|
2958
3108
|
}
|
|
2959
3109
|
/**
|
|
2960
|
-
*
|
|
2961
|
-
*
|
|
3110
|
+
* Collects the lines of one block, starting at `start` and stopping at the first line the
|
|
3111
|
+
* block does not own.
|
|
2962
3112
|
*
|
|
2963
|
-
* @param
|
|
2964
|
-
* @
|
|
3113
|
+
* @param lines - Every line of the file.
|
|
3114
|
+
* @param start - Index of the block's first line.
|
|
3115
|
+
* @param isMember - Whether a line still belongs to the block.
|
|
3116
|
+
* @returns The block's lines, and the index of the first line after it.
|
|
2965
3117
|
* @example
|
|
2966
3118
|
* ```ts
|
|
2967
|
-
*
|
|
2968
|
-
* // { start: 30, end: 58, isMain: true }
|
|
2969
|
-
* mainActivity([{ start: 0, end: 30, isMain: false }, { start: 30, end: 58, isMain: false }]); // undefined
|
|
3119
|
+
* const { block, next } = collectBlock(lines, index, line => line.body !== "\t\t\t};");
|
|
2970
3120
|
* ```
|
|
2971
3121
|
*/
|
|
2972
|
-
function
|
|
2973
|
-
const
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2981
|
-
|
|
2982
|
-
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
3122
|
+
function collectBlock(lines, start, isMember) {
|
|
3123
|
+
const block = [];
|
|
3124
|
+
let index = start;
|
|
3125
|
+
while (index < lines.length) {
|
|
3126
|
+
const line = lines[index];
|
|
3127
|
+
if (!line || !isMember(line)) break;
|
|
3128
|
+
block.push(line);
|
|
3129
|
+
index += 1;
|
|
3130
|
+
}
|
|
3131
|
+
return {
|
|
3132
|
+
block,
|
|
3133
|
+
next: index
|
|
3134
|
+
};
|
|
3135
|
+
}
|
|
3136
|
+
/**
|
|
3137
|
+
* Renders the setting as a pbxproj assignment.
|
|
3138
|
+
*
|
|
3139
|
+
* @param indent - The indentation its sibling settings use.
|
|
3140
|
+
* @returns The assignment line.
|
|
3141
|
+
* @example
|
|
3142
|
+
* ```ts
|
|
3143
|
+
* renderPbxprojSetting("\t\t\t\t"); // "\t\t\t\tCODE_SIGN_ALLOW_ENTITLEMENTS_MODIFICATION = YES;"
|
|
3144
|
+
* ```
|
|
3145
|
+
*/
|
|
3146
|
+
function renderPbxprojSetting(indent) {
|
|
3147
|
+
return `${indent}${ENTITLEMENTS_MODIFICATION_KEY} = ${PBXPROJ_ENABLED_VALUE};`;
|
|
3148
|
+
}
|
|
3149
|
+
/**
|
|
3150
|
+
* Renders the setting as a YAML mapping entry.
|
|
3151
|
+
*
|
|
3152
|
+
* @param indent - The indentation its sibling entries use.
|
|
3153
|
+
* @returns The entry line.
|
|
3154
|
+
* @example
|
|
3155
|
+
* ```ts
|
|
3156
|
+
* renderYmlSetting(" "); // " CODE_SIGN_ALLOW_ENTITLEMENTS_MODIFICATION: true"
|
|
3157
|
+
* ```
|
|
3158
|
+
*/
|
|
3159
|
+
function renderYmlSetting(indent) {
|
|
3160
|
+
return `${indent}${ENTITLEMENTS_MODIFICATION_KEY}: ${YML_ENABLED_VALUE}`;
|
|
3161
|
+
}
|
|
3162
|
+
/**
|
|
3163
|
+
* Reads the `base:` mapping a target's `settings:` line opens — the one block in
|
|
3164
|
+
* `project.yml` that holds build settings.
|
|
3165
|
+
*
|
|
3166
|
+
* The block is walked, not peeked at: `base:` is a direct child of `settings:`, but not
|
|
3167
|
+
* necessarily the FIRST one — xcodegen is equally happy with `settings:` followed by
|
|
3168
|
+
* `groups: [app]` and `base:` below it. So every line indented deeper than `settings:` is
|
|
3169
|
+
* scanned until the block dedents, and the first `base:` sitting at the direct-child level
|
|
3170
|
+
* wins; a nested `base:` deeper inside somebody else's sub-mapping does not. A `settings:`
|
|
3171
|
+
* block carrying no `base:` at all owns no such block and is left alone.
|
|
3172
|
+
*
|
|
3173
|
+
* @param lines - Every line of the file.
|
|
3174
|
+
* @param settingsIndex - Index of the candidate `settings:` line.
|
|
3175
|
+
* @returns The `base:` line, its index and its indentation, or undefined when there is none.
|
|
3176
|
+
* @example
|
|
3177
|
+
* ```ts
|
|
3178
|
+
* baseMappingAt(splitLines(" settings:\n groups: [app]\n base:\n"), 0);
|
|
3179
|
+
* ```
|
|
3180
|
+
*/
|
|
3181
|
+
function baseMappingAt(lines, settingsIndex) {
|
|
3182
|
+
const settingsLine = lines[settingsIndex];
|
|
3183
|
+
const settings = settingsLine && YML_SETTINGS_PATTERN.exec(settingsLine.body);
|
|
3184
|
+
if (!settings) return void 0;
|
|
3185
|
+
const settingsIndent = (settings[1] ?? "").length;
|
|
3186
|
+
let childIndent;
|
|
3187
|
+
for (let index = settingsIndex + 1; index < lines.length; index += 1) {
|
|
3188
|
+
const line = lines[index];
|
|
3189
|
+
if (!line) break;
|
|
3190
|
+
if (line.body.trim().length === 0) continue;
|
|
3191
|
+
const indent = indentOf(line.body);
|
|
3192
|
+
if (indent.length <= settingsIndent) break;
|
|
3193
|
+
childIndent ??= indent.length;
|
|
3194
|
+
if (indent.length !== childIndent) continue;
|
|
3195
|
+
if (YML_BASE_PATTERN.test(line.body)) return {
|
|
3196
|
+
line,
|
|
3197
|
+
index,
|
|
3198
|
+
indent
|
|
3199
|
+
};
|
|
3200
|
+
}
|
|
3201
|
+
}
|
|
3202
|
+
/**
|
|
3203
|
+
* Adds `CODE_SIGN_ALLOW_ENTITLEMENTS_MODIFICATION = YES;` to every `buildSettings` block of
|
|
3204
|
+
* a generated `project.pbxproj`, exactly once per block and at the indentation its sibling
|
|
3205
|
+
* settings use. Content outside those blocks — the shell-script build phase included — is
|
|
3206
|
+
* returned byte for byte, and a file that already carries the setting comes back unchanged.
|
|
3207
|
+
*
|
|
3208
|
+
* @param existing - The current `project.pbxproj` content.
|
|
3209
|
+
* @returns The content with the setting in every settings block.
|
|
3210
|
+
* @example
|
|
3211
|
+
* ```ts
|
|
3212
|
+
* applyPbxprojEntitlementsSetting(await readFile(pbxprojPath, "utf8"));
|
|
3213
|
+
* ```
|
|
3214
|
+
*/
|
|
3215
|
+
function applyPbxprojEntitlementsSetting(existing) {
|
|
3216
|
+
const lines = splitLines$1(existing);
|
|
3217
|
+
const patched = [];
|
|
3218
|
+
let index = 0;
|
|
3219
|
+
while (index < lines.length) {
|
|
3220
|
+
const line = lines[index];
|
|
3221
|
+
if (!line) break;
|
|
3222
|
+
patched.push(line);
|
|
3223
|
+
index += 1;
|
|
3224
|
+
const opening = BUILD_SETTINGS_OPEN_PATTERN.exec(line.body);
|
|
3225
|
+
if (!opening) continue;
|
|
3226
|
+
const blockIndent = opening[1] ?? "";
|
|
3227
|
+
const closing = `${blockIndent}};`;
|
|
3228
|
+
const { block, next } = collectBlock(lines, index, (inner) => inner.body !== closing);
|
|
3229
|
+
index = next;
|
|
3230
|
+
patched.push(...placeSetting(block, {
|
|
3231
|
+
present: PBXPROJ_SETTING_PATTERN,
|
|
3232
|
+
render: renderPbxprojSetting,
|
|
3233
|
+
fallbackIndent: `${blockIndent}${PBXPROJ_NESTED_INDENT}`,
|
|
3234
|
+
fallbackEnding: line.ending
|
|
3235
|
+
}));
|
|
3236
|
+
}
|
|
3237
|
+
return joinLines(patched);
|
|
3238
|
+
}
|
|
3239
|
+
/**
|
|
3240
|
+
* Adds the setting to every target's `settings.base` block in a generated `project.yml`, so
|
|
3241
|
+
* an xcodegen regeneration writes it back into the pbxproj. Only a `base:` mapping that is a
|
|
3242
|
+
* direct child of a `settings:` mapping is touched — a `settingGroups:` block is somebody
|
|
3243
|
+
* else's. A blank line inside the block does not end it: YAML mappings end at a dedent, so
|
|
3244
|
+
* an entry printed below an empty line is still seen and never duplicated.
|
|
3245
|
+
*
|
|
3246
|
+
* @param existing - The current `project.yml` content.
|
|
3247
|
+
* @returns The content with the setting under each target's `settings.base`.
|
|
3248
|
+
* @example
|
|
3249
|
+
* ```ts
|
|
3250
|
+
* applyProjectYmlEntitlementsSetting(await readFile(projectYmlPath, "utf8"));
|
|
3251
|
+
* ```
|
|
3252
|
+
*/
|
|
3253
|
+
function applyProjectYmlEntitlementsSetting(existing) {
|
|
3254
|
+
const lines = splitLines$1(existing);
|
|
3255
|
+
const patched = [];
|
|
3256
|
+
let index = 0;
|
|
3257
|
+
while (index < lines.length) {
|
|
3258
|
+
const line = lines[index];
|
|
3259
|
+
if (!line) break;
|
|
3260
|
+
const base = baseMappingAt(lines, index);
|
|
3261
|
+
patched.push(line);
|
|
3262
|
+
index += 1;
|
|
3263
|
+
if (!base) continue;
|
|
3264
|
+
patched.push(...lines.slice(index, base.index + 1));
|
|
3265
|
+
index = base.index + 1;
|
|
3266
|
+
const { block, next } = collectBlock(lines, index, (entry) => entry.body.trim().length === 0 || indentOf(entry.body).length > base.indent.length);
|
|
3267
|
+
index = next;
|
|
3268
|
+
patched.push(...placeSetting(block, {
|
|
3269
|
+
present: YML_SETTING_PATTERN,
|
|
3270
|
+
render: renderYmlSetting,
|
|
3271
|
+
fallbackIndent: `${base.indent}${YML_NESTED_INDENT}`,
|
|
3272
|
+
fallbackEnding: base.line.ending
|
|
3273
|
+
}));
|
|
3274
|
+
}
|
|
3275
|
+
return joinLines(patched);
|
|
3276
|
+
}
|
|
3277
|
+
/**
|
|
3278
|
+
* Applies the entitlements-modification setting to every generated iOS project file —
|
|
3279
|
+
* `project.yml` and each `*.xcodeproj/project.pbxproj`. Idempotent: a second pass reports
|
|
3280
|
+
* every file unchanged. Nothing under `gen/apple/build` is ever read or written.
|
|
3281
|
+
*
|
|
3282
|
+
* @param projectDirectory - The Tauri project root.
|
|
3283
|
+
* @param genDirectory - The `src-tauri/gen/apple` directory.
|
|
3284
|
+
* @returns The paths patched vs. left unchanged.
|
|
3285
|
+
* @example
|
|
3286
|
+
* ```ts
|
|
3287
|
+
* await patchXcodeSettings(projectDir, path.join(projectDir, "src-tauri/gen/apple"));
|
|
3288
|
+
* ```
|
|
3289
|
+
*/
|
|
3290
|
+
async function patchXcodeSettings(projectDirectory, genDirectory) {
|
|
3291
|
+
const patched = [];
|
|
3292
|
+
const unchanged = [];
|
|
3293
|
+
for (const file of await iosPatchFiles(genDirectory)) {
|
|
3294
|
+
const existing = await (0, node_fs_promises.readFile)(file, "utf8");
|
|
3295
|
+
(await writeIfChanged(file, file.endsWith(".yml") ? applyProjectYmlEntitlementsSetting(existing) : applyPbxprojEntitlementsSetting(existing), projectDirectory) === "written" ? patched : unchanged).push(file);
|
|
3296
|
+
}
|
|
3297
|
+
return {
|
|
3298
|
+
patched,
|
|
3299
|
+
unchanged
|
|
3300
|
+
};
|
|
3301
|
+
}
|
|
3302
|
+
//#endregion
|
|
3303
|
+
//#region src/plugins/project/mobile/ios-project.ts
|
|
3304
|
+
/**
|
|
3305
|
+
* @file project plugin — the iOS project patches: the deployment target and the privacy
|
|
3306
|
+
* manifest.
|
|
3307
|
+
*
|
|
3308
|
+
* `tauri ios build` never runs xcodegen on a kept tree, and init runs before this pass, so a
|
|
3309
|
+
* change to `project.yml` alone reaches no build. Every change here lands in `project.yml`
|
|
3310
|
+
* (a later xcodegen keeps it) AND in each `project.pbxproj` (the file Xcode reads today).
|
|
3311
|
+
*
|
|
3312
|
+
* The transforms are pure text functions over the real generated shapes: line endings and
|
|
3313
|
+
* every neighbouring line survive byte for byte, and a second pass is a no-op. A file
|
|
3314
|
+
* without the line a transform needs is a `[native]` error, never a silent skip: the app
|
|
3315
|
+
* would ship the old minimum, or no manifest, with nothing in the log.
|
|
3316
|
+
*/
|
|
3317
|
+
/** The name a pbxproj error reports. */
|
|
3318
|
+
const PBXPROJ_FILE = "project.pbxproj";
|
|
3319
|
+
/** The name a project.yml error reports. */
|
|
3320
|
+
const PROJECT_YML_FILE = "project.yml";
|
|
3321
|
+
/** Every deployment target of a pbxproj. Group 1 is the line up to the value. */
|
|
3322
|
+
const PBXPROJ_DEPLOYMENT_PATTERN = /^([ \t]*IPHONEOS_DEPLOYMENT_TARGET = )[^;\r\n]*;/gm;
|
|
3323
|
+
/** Opens the `deploymentTarget:` mapping of `project.yml`. */
|
|
3324
|
+
const YML_DEPLOYMENT_PATTERN = /^[ \t]*deploymentTarget:[ \t]*$/;
|
|
3325
|
+
/** The iOS entry of that mapping. Group 1 is the line up to the value. */
|
|
3326
|
+
const YML_IOS_ENTRY_PATTERN = /^([ \t]+iOS:[ \t]*)\S.*$/;
|
|
3327
|
+
/** The object id `mainGroup` names, with or without a name comment after it. */
|
|
3328
|
+
const MAIN_GROUP_PATTERN = /^[ \t]*mainGroup = (\w+)/;
|
|
3329
|
+
/** Opens the `children` list of a group. */
|
|
3330
|
+
const CHILDREN_LINE = "children = (";
|
|
3331
|
+
/** Opens the `files` list of a build phase. */
|
|
3332
|
+
const FILES_LINE = "files = (";
|
|
3333
|
+
/** The `PBXBuildFile` id of the manifest: `MOKU` in ASCII, then a counter. Never xcodegen's. */
|
|
3334
|
+
const PRIVACY_BUILD_FILE_ID = "4D4F4B5500000000000000A1";
|
|
3335
|
+
/** The `PBXFileReference` id of the manifest. */
|
|
3336
|
+
const PRIVACY_FILE_REFERENCE_ID = "4D4F4B5500000000000000A2";
|
|
3337
|
+
/** The manifest's `PBXBuildFile` line. */
|
|
3338
|
+
const BUILD_FILE_LINE = `\t\t${PRIVACY_BUILD_FILE_ID} /* ${IOS_PRIVACY_MANIFEST_FILE} in Resources */ = {isa = PBXBuildFile; fileRef = ${PRIVACY_FILE_REFERENCE_ID} /* ${IOS_PRIVACY_MANIFEST_FILE} */; };`;
|
|
3339
|
+
/** The manifest's `PBXFileReference` line; the root group resolves it from `gen/apple`. */
|
|
3340
|
+
const FILE_REFERENCE_LINE = `\t\t${PRIVACY_FILE_REFERENCE_ID} /* ${IOS_PRIVACY_MANIFEST_FILE} */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = ${IOS_PRIVACY_MANIFEST_FILE}; sourceTree = "<group>"; };`;
|
|
3341
|
+
/** The manifest's entry in the root group's `children`. */
|
|
3342
|
+
const GROUP_CHILD_LINE = `\t\t\t\t${PRIVACY_FILE_REFERENCE_ID} /* ${IOS_PRIVACY_MANIFEST_FILE} */,`;
|
|
3343
|
+
/** The manifest's entry in the Resources phase's `files`. */
|
|
3344
|
+
const RESOURCES_FILE_LINE = `\t\t\t\t${PRIVACY_BUILD_FILE_ID} /* ${IOS_PRIVACY_MANIFEST_FILE} in Resources */,`;
|
|
3345
|
+
/** The `project.yml` key of the targets, top level. */
|
|
3346
|
+
const YML_TARGETS_LINE = "targets:";
|
|
3347
|
+
/** Opens a `sources:` list in `project.yml`. */
|
|
3348
|
+
const YML_SOURCES_PATTERN = /^[ \t]+sources:[ \t]*$/;
|
|
3349
|
+
/** The first line of a YAML list entry. */
|
|
3350
|
+
const YML_LIST_ITEM_PATTERN = /^[ \t]*- /;
|
|
3351
|
+
/** The manifest's entry in the sources list. */
|
|
3352
|
+
const YML_PRIVACY_PATH_LINE = `- path: ${IOS_PRIVACY_MANIFEST_FILE}`;
|
|
3353
|
+
/** The second line of that entry. The `assets` entry carries the same one: it stays. */
|
|
3354
|
+
const YML_RESOURCES_PHASE_LINE = "buildPhase: resources";
|
|
3355
|
+
/** How deep a list entry's second line sits below its `- `. */
|
|
3356
|
+
const YML_ENTRY_INDENT = " ";
|
|
3357
|
+
/**
|
|
3358
|
+
* Builds the `[native]` refusal for a generated file that lacks what a patch needs.
|
|
3359
|
+
*
|
|
3360
|
+
* @param anchor - What is missing.
|
|
3361
|
+
* @param file - The file's name.
|
|
3362
|
+
* @returns A formatted `[native] ...` error.
|
|
3363
|
+
* @example
|
|
3364
|
+
* ```ts
|
|
3365
|
+
* missingAnchorError("mainGroup", "project.pbxproj").message;
|
|
3366
|
+
* // "[native] Could not find mainGroup in project.pbxproj.\n Run clean for ios and build again, or report the project.pbxproj Tauri generated."
|
|
3367
|
+
* ```
|
|
3368
|
+
*/
|
|
3369
|
+
function missingAnchorError(anchor, file) {
|
|
3370
|
+
return /* @__PURE__ */ new Error(`[native] Could not find ${anchor} in ${file}.\n Run clean for ios and build again, or report the ${file} Tauri generated.`);
|
|
3371
|
+
}
|
|
3372
|
+
/**
|
|
3373
|
+
* Finds a line by its text inside a range of lines.
|
|
3374
|
+
*
|
|
3375
|
+
* @param lines - Every line of the file.
|
|
3376
|
+
* @param matches - Whether a line's text is the one looked for.
|
|
3377
|
+
* @param from - Index of the first line to look at.
|
|
3378
|
+
* @param to - Index after the last line to look at.
|
|
3379
|
+
* @returns The line's index in `lines`, or -1.
|
|
3380
|
+
* @example
|
|
3381
|
+
* ```ts
|
|
3382
|
+
* findLine(splitLines("a\nb\nb\n"), body => body === "b", 2, 3); // 2
|
|
3383
|
+
* ```
|
|
3384
|
+
*/
|
|
3385
|
+
function findLine(lines, matches, from, to) {
|
|
3386
|
+
const index = lines.slice(from, to).findIndex((line) => matches(line.body));
|
|
3387
|
+
return index === -1 ? -1 : from + index;
|
|
3388
|
+
}
|
|
3389
|
+
/**
|
|
3390
|
+
* Finds the `Begin` and `End` comments of a pbxproj section.
|
|
3391
|
+
*
|
|
3392
|
+
* @param lines - Every line of the file.
|
|
3393
|
+
* @param section - The section's name, an `isa` value.
|
|
3394
|
+
* @returns The indices of both comments.
|
|
3395
|
+
* @throws {Error} `[native]` when the section is not there.
|
|
3396
|
+
* @example
|
|
3397
|
+
* ```ts
|
|
3398
|
+
* sectionBounds(splitLines("/* Begin A section *\/\n/* End A section *\/\n"), "A"); // { begin: 0, end: 1 }
|
|
3399
|
+
* ```
|
|
3400
|
+
*/
|
|
3401
|
+
function sectionBounds(lines, section) {
|
|
3402
|
+
const begin = lines.findIndex((line) => line.body === `/* Begin ${section} section */`);
|
|
3403
|
+
const end = lines.findIndex((line) => line.body === `/* End ${section} section */`);
|
|
3404
|
+
if (begin === -1 || end === -1) throw missingAnchorError(`the ${section} section`, PBXPROJ_FILE);
|
|
3405
|
+
return {
|
|
3406
|
+
begin,
|
|
3407
|
+
end
|
|
3408
|
+
};
|
|
3409
|
+
}
|
|
3410
|
+
/**
|
|
3411
|
+
* Whether a line opens the object of one group id.
|
|
3412
|
+
*
|
|
3413
|
+
* @param body - The line's text.
|
|
3414
|
+
* @param id - The group's object id.
|
|
3415
|
+
* @returns True for the group's opening line.
|
|
3416
|
+
* @example
|
|
3417
|
+
* ```ts
|
|
3418
|
+
* opensGroup("\t\tAA = {", "AA"); // true
|
|
3419
|
+
* ```
|
|
3420
|
+
*/
|
|
3421
|
+
function opensGroup(body, id) {
|
|
3422
|
+
return body.trimStart().startsWith(`${id} `) && body.trimEnd().endsWith("= {");
|
|
3423
|
+
}
|
|
3424
|
+
/**
|
|
3425
|
+
* Finds the `children = (` line of the root group: the group the `PBXProject` object's
|
|
3426
|
+
* `mainGroup` names, which has no name of its own to look for.
|
|
3427
|
+
*
|
|
3428
|
+
* @param lines - Every line of the file.
|
|
3429
|
+
* @returns The line's index.
|
|
3430
|
+
* @throws {Error} `[native]` when the `mainGroup` line, the group or its list is not there.
|
|
3431
|
+
* @example
|
|
3432
|
+
* ```ts
|
|
3433
|
+
* const text = [
|
|
3434
|
+
* "/* Begin PBXGroup section *\/",
|
|
3435
|
+
* "\t\tAA = {",
|
|
3436
|
+
* "\t\t\tisa = PBXGroup;",
|
|
3437
|
+
* "\t\t\tchildren = (",
|
|
3438
|
+
* "\t\t\t);",
|
|
3439
|
+
* "\t\t};",
|
|
3440
|
+
* "/* End PBXGroup section *\/",
|
|
3441
|
+
* "/* Begin PBXProject section *\/",
|
|
3442
|
+
* "\t\t\tmainGroup = AA;",
|
|
3443
|
+
* "/* End PBXProject section *\/"
|
|
3444
|
+
* ].join("\n");
|
|
3445
|
+
* rootGroupChildren(splitLines(text)); // 3
|
|
3446
|
+
* ```
|
|
3447
|
+
*/
|
|
3448
|
+
function rootGroupChildren(lines) {
|
|
3449
|
+
const project = sectionBounds(lines, "PBXProject");
|
|
3450
|
+
const mainGroup = lines.slice(project.begin, project.end).map((line) => MAIN_GROUP_PATTERN.exec(line.body)?.[1]).find((id) => id !== void 0);
|
|
3451
|
+
if (mainGroup === void 0) throw missingAnchorError("mainGroup", PBXPROJ_FILE);
|
|
3452
|
+
const groups = sectionBounds(lines, "PBXGroup");
|
|
3453
|
+
const open = findLine(lines, (body) => opensGroup(body, mainGroup), groups.begin, groups.end);
|
|
3454
|
+
const opening = lines[open];
|
|
3455
|
+
if (!opening) throw missingAnchorError(`the main group ${mainGroup}`, PBXPROJ_FILE);
|
|
3456
|
+
const closing = `${indentOf(opening.body)}};`;
|
|
3457
|
+
const { block } = collectBlock(lines, open, (line) => line.body !== closing);
|
|
3458
|
+
const children = block.findIndex((line) => line.body.trim() === CHILDREN_LINE);
|
|
3459
|
+
if (children === -1) throw missingAnchorError(`the children of the main group ${mainGroup}`, PBXPROJ_FILE);
|
|
3460
|
+
return open + children;
|
|
3461
|
+
}
|
|
3462
|
+
/**
|
|
3463
|
+
* Finds the `files = (` line of the Resources phase. A generated project has one target,
|
|
3464
|
+
* so one such phase.
|
|
3465
|
+
*
|
|
3466
|
+
* @param lines - Every line of the file.
|
|
3467
|
+
* @returns The line's index.
|
|
3468
|
+
* @throws {Error} `[native]` when the section or its list is not there.
|
|
3469
|
+
* @example
|
|
3470
|
+
* ```ts
|
|
3471
|
+
* const text = [
|
|
3472
|
+
* "/* Begin PBXResourcesBuildPhase section *\/",
|
|
3473
|
+
* "\t\t\tisa = PBXResourcesBuildPhase;",
|
|
3474
|
+
* "\t\t\tfiles = (",
|
|
3475
|
+
* "/* End PBXResourcesBuildPhase section *\/"
|
|
3476
|
+
* ].join("\n");
|
|
3477
|
+
* resourcesFiles(splitLines(text)); // 2
|
|
3478
|
+
* ```
|
|
3479
|
+
*/
|
|
3480
|
+
function resourcesFiles(lines) {
|
|
3481
|
+
const phases = sectionBounds(lines, "PBXResourcesBuildPhase");
|
|
3482
|
+
const files = findLine(lines, (body) => body.trim() === FILES_LINE, phases.begin, phases.end);
|
|
3483
|
+
if (files === -1) throw missingAnchorError("the PBXResourcesBuildPhase files", PBXPROJ_FILE);
|
|
3484
|
+
return files;
|
|
3485
|
+
}
|
|
3486
|
+
/**
|
|
3487
|
+
* Finds the `iOS:` entry of the `deploymentTarget:` mapping. The mapping is walked to its
|
|
3488
|
+
* dedent, so an entry below a sibling or a blank line counts, and an `iOS:` key outside it
|
|
3489
|
+
* does not.
|
|
3490
|
+
*
|
|
3491
|
+
* @param lines - Every line of the file.
|
|
3492
|
+
* @returns The entry's index, or -1.
|
|
3493
|
+
* @example
|
|
3494
|
+
* ```ts
|
|
3495
|
+
* ymlDeploymentEntry(splitLines(" deploymentTarget:\n iOS: 16.0\n")); // 1
|
|
3496
|
+
* ```
|
|
3497
|
+
*/
|
|
3498
|
+
function ymlDeploymentEntry(lines) {
|
|
3499
|
+
const open = lines.findIndex((line) => YML_DEPLOYMENT_PATTERN.test(line.body));
|
|
3500
|
+
const opening = lines[open];
|
|
3501
|
+
if (!opening) return -1;
|
|
3502
|
+
const depth = indentOf(opening.body).length;
|
|
3503
|
+
const { block } = collectBlock(lines, open + 1, (line) => line.body.trim().length === 0 || indentOf(line.body).length > depth);
|
|
3504
|
+
const entry = block.findIndex((line) => YML_IOS_ENTRY_PATTERN.test(line.body));
|
|
3505
|
+
return entry === -1 ? -1 : open + 1 + entry;
|
|
3506
|
+
}
|
|
3507
|
+
/**
|
|
3508
|
+
* Rewrites every `IPHONEOS_DEPLOYMENT_TARGET` of a generated `project.pbxproj`, the setting
|
|
3509
|
+
* `MinimumOSVersion` comes from.
|
|
3510
|
+
*
|
|
3511
|
+
* @param existing - The current `project.pbxproj` content.
|
|
3512
|
+
* @param version - The deployment target to write.
|
|
3513
|
+
* @returns The content with every setting on `version`.
|
|
3514
|
+
* @throws {Error} `[native]` when the file has no such line.
|
|
3515
|
+
* @example
|
|
3516
|
+
* ```ts
|
|
3517
|
+
* applyPbxprojDeploymentTarget("\tIPHONEOS_DEPLOYMENT_TARGET = 16.0;\n", "26.0");
|
|
3518
|
+
* // "\tIPHONEOS_DEPLOYMENT_TARGET = 26.0;\n"
|
|
3519
|
+
* ```
|
|
3520
|
+
*/
|
|
3521
|
+
function applyPbxprojDeploymentTarget(existing, version) {
|
|
3522
|
+
if (existing.search(PBXPROJ_DEPLOYMENT_PATTERN) === -1) throw missingAnchorError("IPHONEOS_DEPLOYMENT_TARGET", PBXPROJ_FILE);
|
|
3523
|
+
return existing.replaceAll(PBXPROJ_DEPLOYMENT_PATTERN, (_match, assignment) => `${assignment}${version};`);
|
|
3524
|
+
}
|
|
3525
|
+
/**
|
|
3526
|
+
* Rewrites `deploymentTarget.iOS` in a generated `project.yml`.
|
|
3527
|
+
*
|
|
3528
|
+
* @param existing - The current `project.yml` content.
|
|
3529
|
+
* @param version - The deployment target to write.
|
|
3530
|
+
* @returns The content with the entry on `version`.
|
|
3531
|
+
* @throws {Error} `[native]` when the file has no such entry.
|
|
3532
|
+
* @example
|
|
3533
|
+
* ```ts
|
|
3534
|
+
* applyProjectYmlDeploymentTarget(" deploymentTarget:\n iOS: 16.0\n", "26.0");
|
|
3535
|
+
* // " deploymentTarget:\n iOS: 26.0\n"
|
|
3536
|
+
* ```
|
|
3537
|
+
*/
|
|
3538
|
+
function applyProjectYmlDeploymentTarget(existing, version) {
|
|
3539
|
+
const lines = splitLines$1(existing);
|
|
3540
|
+
const index = ymlDeploymentEntry(lines);
|
|
3541
|
+
const entry = lines[index];
|
|
3542
|
+
if (!entry) throw missingAnchorError("deploymentTarget.iOS", PROJECT_YML_FILE);
|
|
3543
|
+
const body = entry.body.replace(YML_IOS_ENTRY_PATTERN, (_match, key) => `${key}${version}`);
|
|
3544
|
+
return joinLines(lines.with(index, {
|
|
3545
|
+
body,
|
|
3546
|
+
ending: entry.ending
|
|
3547
|
+
}));
|
|
3548
|
+
}
|
|
3549
|
+
/**
|
|
3550
|
+
* Keeps the privacy manifest in a generated `project.pbxproj`: a `PBXBuildFile`, a
|
|
3551
|
+
* `PBXFileReference`, a child of the root group and an entry in the Resources phase. Every
|
|
3552
|
+
* line carrying one of the two fixed ids is dropped first, so a second pass is a no-op and
|
|
3553
|
+
* `enabled: false` gives back the file as it was, needing no anchor.
|
|
3554
|
+
*
|
|
3555
|
+
* @param existing - The current `project.pbxproj` content.
|
|
3556
|
+
* @param enabled - Whether the app carries a manifest.
|
|
3557
|
+
* @returns The content with the four lines, or without them.
|
|
3558
|
+
* @throws {Error} `[native]` when `enabled` and the file lacks an anchor.
|
|
3559
|
+
* @example
|
|
3560
|
+
* ```ts
|
|
3561
|
+
* applyPbxprojPrivacyManifest("// !$*UTF8*$!\n", false); // "// !$*UTF8*$!\n"
|
|
3562
|
+
* ```
|
|
3563
|
+
*/
|
|
3564
|
+
function applyPbxprojPrivacyManifest(existing, enabled) {
|
|
3565
|
+
const lines = splitLines$1(existing).filter((line) => !line.body.includes(PRIVACY_BUILD_FILE_ID) && !line.body.includes(PRIVACY_FILE_REFERENCE_ID));
|
|
3566
|
+
if (!enabled) return joinLines(lines);
|
|
3567
|
+
const inserted = /* @__PURE__ */ new Map([
|
|
3568
|
+
[sectionBounds(lines, "PBXBuildFile").end, BUILD_FILE_LINE],
|
|
3569
|
+
[sectionBounds(lines, "PBXFileReference").end, FILE_REFERENCE_LINE],
|
|
3570
|
+
[rootGroupChildren(lines) + 1, GROUP_CHILD_LINE],
|
|
3571
|
+
[resourcesFiles(lines) + 1, RESOURCES_FILE_LINE]
|
|
3572
|
+
]);
|
|
3573
|
+
return joinLines(lines.flatMap((line, index) => {
|
|
3574
|
+
const body = inserted.get(index);
|
|
3575
|
+
return body === void 0 ? [line] : [{
|
|
3576
|
+
body,
|
|
3577
|
+
ending: line.ending
|
|
3578
|
+
}, line];
|
|
3579
|
+
}));
|
|
3580
|
+
}
|
|
3581
|
+
/**
|
|
3582
|
+
* Tests whether a `project.yml` line is the first line of the manifest's list entry.
|
|
3583
|
+
*
|
|
3584
|
+
* @param line - The line, or undefined past either end of the file.
|
|
3585
|
+
* @returns Whether it is that line.
|
|
3586
|
+
* @example
|
|
3587
|
+
* ```ts
|
|
3588
|
+
* isYmlPrivacyPath({ body: " - path: PrivacyInfo.xcprivacy", ending: "\n" }); // true
|
|
3589
|
+
* ```
|
|
3590
|
+
*/
|
|
3591
|
+
function isYmlPrivacyPath(line) {
|
|
3592
|
+
return line?.body.trim() === YML_PRIVACY_PATH_LINE;
|
|
3593
|
+
}
|
|
3594
|
+
/**
|
|
3595
|
+
* Drops the manifest's list entry from `project.yml`: the path line, and the `buildPhase`
|
|
3596
|
+
* line right after it, never the same line of another entry.
|
|
3597
|
+
*
|
|
3598
|
+
* @param lines - Every line of the file.
|
|
3599
|
+
* @returns The lines without the entry.
|
|
3600
|
+
* @example
|
|
3601
|
+
* ```ts
|
|
3602
|
+
* dropYmlPrivacyEntry(splitLines("- path: PrivacyInfo.xcprivacy\n buildPhase: resources\n")); // []
|
|
3603
|
+
* ```
|
|
3604
|
+
*/
|
|
3605
|
+
function dropYmlPrivacyEntry(lines) {
|
|
3606
|
+
return lines.filter((line, index) => {
|
|
3607
|
+
if (isYmlPrivacyPath(line)) return false;
|
|
3608
|
+
return !(isYmlPrivacyPath(lines[index - 1]) && line.body.trim() === YML_RESOURCES_PHASE_LINE);
|
|
3609
|
+
});
|
|
3610
|
+
}
|
|
3611
|
+
/**
|
|
3612
|
+
* Finds the first entry of the app target's `sources:` list: the first `sources:` after the
|
|
3613
|
+
* top-level `targets:` line. A `targetTemplates` block carries its own one above that line.
|
|
3614
|
+
*
|
|
3615
|
+
* @param lines - Every line of the file.
|
|
3616
|
+
* @returns The first entry's index and line.
|
|
3617
|
+
* @throws {Error} `[native]` when there is no such list.
|
|
3618
|
+
* @example
|
|
3619
|
+
* ```ts
|
|
3620
|
+
* firstTargetSource(splitLines("targets:\n app:\n sources:\n - path: Sources\n")).index; // 3
|
|
3621
|
+
* ```
|
|
3622
|
+
*/
|
|
3623
|
+
function firstTargetSource(lines) {
|
|
3624
|
+
const targets = lines.findIndex((line) => line.body.trimEnd() === YML_TARGETS_LINE);
|
|
3625
|
+
const sources = findLine(lines, (body) => YML_SOURCES_PATTERN.test(body), targets + 1, lines.length);
|
|
3626
|
+
const index = sources + 1;
|
|
3627
|
+
const line = lines[index];
|
|
3628
|
+
const hasSourcesList = targets !== -1 && sources !== -1 && YML_LIST_ITEM_PATTERN.test(line?.body ?? "");
|
|
3629
|
+
if (!line || !hasSourcesList) throw missingAnchorError("the target's sources list", PROJECT_YML_FILE);
|
|
3630
|
+
return {
|
|
3631
|
+
index,
|
|
3632
|
+
line
|
|
3633
|
+
};
|
|
3634
|
+
}
|
|
3635
|
+
/**
|
|
3636
|
+
* Keeps the privacy manifest in a generated `project.yml`, as the first entry of the app
|
|
3637
|
+
* target's sources, so a later xcodegen writes it back into the pbxproj. The entry is
|
|
3638
|
+
* dropped first, so a second pass is a no-op and `enabled: false` gives back the file as it
|
|
3639
|
+
* was, needing no anchor.
|
|
3640
|
+
*
|
|
3641
|
+
* @param existing - The current `project.yml` content.
|
|
3642
|
+
* @param enabled - Whether the app carries a manifest.
|
|
3643
|
+
* @returns The content with the entry, or without it.
|
|
3644
|
+
* @throws {Error} `[native]` when `enabled` and the file has no target sources list.
|
|
3645
|
+
* @example
|
|
3646
|
+
* ```ts
|
|
3647
|
+
* applyProjectYmlPrivacyManifest("name: app\n", false); // "name: app\n"
|
|
3648
|
+
* ```
|
|
3649
|
+
*/
|
|
3650
|
+
function applyProjectYmlPrivacyManifest(existing, enabled) {
|
|
3651
|
+
const lines = dropYmlPrivacyEntry(splitLines$1(existing));
|
|
3652
|
+
if (!enabled) return joinLines(lines);
|
|
3653
|
+
const { index, line } = firstTargetSource(lines);
|
|
3654
|
+
const indent = indentOf(line.body);
|
|
3655
|
+
return joinLines(lines.toSpliced(index, 0, {
|
|
3656
|
+
body: `${indent}${YML_PRIVACY_PATH_LINE}`,
|
|
3657
|
+
ending: line.ending
|
|
3658
|
+
}, {
|
|
3659
|
+
body: `${indent}${YML_ENTRY_INDENT}${YML_RESOURCES_PHASE_LINE}`,
|
|
3660
|
+
ending: line.ending
|
|
3661
|
+
}));
|
|
3662
|
+
}
|
|
3663
|
+
/**
|
|
3664
|
+
* Reads the privacy manifest `ios.privacyManifest` names, as bytes: a binary plist is legal.
|
|
3665
|
+
* The patch pass calls it first, so a missing source is refused before anything is written.
|
|
3666
|
+
*
|
|
3667
|
+
* @param source - `ios.privacyManifest`, or undefined when unset.
|
|
3668
|
+
* @returns The manifest's bytes, or undefined when the option is unset.
|
|
3669
|
+
* @throws {Error} `[native] ios.privacyManifest "<path>" was not found.`
|
|
3670
|
+
* @example
|
|
3671
|
+
* ```ts
|
|
3672
|
+
* await readPrivacyManifest(undefined); // undefined
|
|
3673
|
+
* ```
|
|
3674
|
+
*/
|
|
3675
|
+
async function readPrivacyManifest(source) {
|
|
3676
|
+
if (source === void 0) return void 0;
|
|
3677
|
+
if (!(0, node_fs.existsSync)(source)) throw new Error(`[native] ios.privacyManifest "${source}" was not found.\n Point config.ios.privacyManifest at the manifest file, or unset it.`);
|
|
3678
|
+
return (0, node_fs_promises.readFile)(source);
|
|
3679
|
+
}
|
|
3680
|
+
/**
|
|
3681
|
+
* Rewrites every generated iOS project file. All of them are transformed before the first
|
|
3682
|
+
* write, so a file that refuses leaves the tree as it was.
|
|
3683
|
+
*
|
|
3684
|
+
* @param projectDirectory - The Tauri project root.
|
|
3685
|
+
* @param genDirectory - The `src-tauri/gen/apple` directory.
|
|
3686
|
+
* @param transform - Rewrites one file's content; its second argument says whether the file
|
|
3687
|
+
* is `project.yml`.
|
|
3688
|
+
* @returns The paths patched vs. left unchanged.
|
|
3689
|
+
* @throws {Error} What the transform throws.
|
|
3690
|
+
*/
|
|
3691
|
+
async function rewriteProjectFiles(projectDirectory, genDirectory, transform) {
|
|
3692
|
+
const rewrites = [];
|
|
3693
|
+
for (const file of await iosPatchFiles(genDirectory)) {
|
|
3694
|
+
const existing = await (0, node_fs_promises.readFile)(file, "utf8");
|
|
3695
|
+
rewrites.push({
|
|
3696
|
+
file,
|
|
3697
|
+
content: transform(existing, file.endsWith(".yml"))
|
|
3698
|
+
});
|
|
3699
|
+
}
|
|
3700
|
+
const patched = [];
|
|
3701
|
+
const unchanged = [];
|
|
3702
|
+
for (const { file, content } of rewrites) (await writeIfChanged(file, content, projectDirectory) === "written" ? patched : unchanged).push(file);
|
|
3703
|
+
return {
|
|
3704
|
+
patched,
|
|
3705
|
+
unchanged
|
|
3706
|
+
};
|
|
3707
|
+
}
|
|
3708
|
+
/**
|
|
3709
|
+
* Moves a kept iOS tree to the configured deployment target, in `project.yml` and each
|
|
3710
|
+
* `project.pbxproj`. Idempotent: a second pass reports every file unchanged.
|
|
3711
|
+
*
|
|
3712
|
+
* @param projectDirectory - The Tauri project root.
|
|
3713
|
+
* @param genDirectory - The `src-tauri/gen/apple` directory.
|
|
3714
|
+
* @param version - The deployment target to write.
|
|
3715
|
+
* @returns The paths patched vs. left unchanged.
|
|
3716
|
+
* @throws {Error} `[native]` when a file has no deployment target line.
|
|
3717
|
+
* @example
|
|
3718
|
+
* ```ts
|
|
3719
|
+
* await patchDeploymentTarget(projectDir, path.join(projectDir, "src-tauri/gen/apple"), "26.0");
|
|
3720
|
+
* // { patched: [".../gen/apple/project.yml", ".../gen/apple/app.xcodeproj/project.pbxproj"], unchanged: [] }
|
|
3721
|
+
* ```
|
|
3722
|
+
*/
|
|
3723
|
+
async function patchDeploymentTarget(projectDirectory, genDirectory, version) {
|
|
3724
|
+
return rewriteProjectFiles(projectDirectory, genDirectory, (text, isProjectYml) => isProjectYml ? applyProjectYmlDeploymentTarget(text, version) : applyPbxprojDeploymentTarget(text, version));
|
|
3725
|
+
}
|
|
3726
|
+
/**
|
|
3727
|
+
* Keeps the privacy manifest of a kept iOS tree: with bytes, `gen/apple/PrivacyInfo.xcprivacy`
|
|
3728
|
+
* holds them and `project.yml` and each `project.pbxproj` name it; without, the entries go
|
|
3729
|
+
* and so does the file, so the option can be dropped. A tree with no project file gets
|
|
3730
|
+
* nothing: no file would name the manifest. Idempotent: a second pass changes nothing.
|
|
3731
|
+
*
|
|
3732
|
+
* @param projectDirectory - The Tauri project root.
|
|
3733
|
+
* @param genDirectory - The `src-tauri/gen/apple` directory.
|
|
3734
|
+
* @param manifest - The bytes from {@link readPrivacyManifest}, undefined when unset.
|
|
3735
|
+
* @returns The paths patched vs. left unchanged; a removed manifest counts as patched.
|
|
3736
|
+
* @throws {Error} `[native]` when a manifest meets a project file that lacks an anchor.
|
|
3737
|
+
* @example
|
|
3738
|
+
* ```ts
|
|
3739
|
+
* await patchPrivacyManifest(projectDir, genDir, await readPrivacyManifest("/repo/PrivacyInfo.xcprivacy"));
|
|
3740
|
+
* ```
|
|
3741
|
+
*/
|
|
3742
|
+
async function patchPrivacyManifest(projectDirectory, genDirectory, manifest) {
|
|
3743
|
+
const enabled = manifest !== void 0;
|
|
3744
|
+
const { patched, unchanged } = await rewriteProjectFiles(projectDirectory, genDirectory, (text, isProjectYml) => isProjectYml ? applyProjectYmlPrivacyManifest(text, enabled) : applyPbxprojPrivacyManifest(text, enabled));
|
|
3745
|
+
if (patched.length + unchanged.length === 0) return {
|
|
3746
|
+
patched,
|
|
3747
|
+
unchanged
|
|
3748
|
+
};
|
|
3749
|
+
const manifestPath = iosPrivacyManifestPath(genDirectory);
|
|
3750
|
+
if (manifest !== void 0) {
|
|
3751
|
+
if (await writeIfChanged(manifestPath, manifest, projectDirectory) === "written") return {
|
|
3752
|
+
patched: [...patched, manifestPath],
|
|
3753
|
+
unchanged
|
|
3754
|
+
};
|
|
3755
|
+
return {
|
|
3756
|
+
patched,
|
|
3757
|
+
unchanged: [...unchanged, manifestPath]
|
|
3758
|
+
};
|
|
3759
|
+
}
|
|
3760
|
+
if (!(0, node_fs.existsSync)(manifestPath)) return {
|
|
3761
|
+
patched,
|
|
3762
|
+
unchanged
|
|
3763
|
+
};
|
|
3764
|
+
await (0, node_fs_promises.rm)(manifestPath, { force: true });
|
|
3765
|
+
return {
|
|
3766
|
+
patched: [...patched, manifestPath],
|
|
3767
|
+
unchanged
|
|
3768
|
+
};
|
|
3769
|
+
}
|
|
3770
|
+
//#endregion
|
|
3771
|
+
//#region src/plugins/project/mobile/manifest.ts
|
|
3772
|
+
/**
|
|
3773
|
+
* @file project plugin — the Android manifest patch. Tauri has no config key for what the
|
|
3774
|
+
* main activity carries (`android:screenOrientation` among them), so the mobile patch pass
|
|
3775
|
+
* sets those attributes on the `<activity>` of the generated
|
|
3776
|
+
* `gen/android/app/src/main/AndroidManifest.xml` itself. The same rules set attributes on
|
|
3777
|
+
* the `<application>` start tag (the debug profile's network security config).
|
|
3778
|
+
*
|
|
3779
|
+
* The transform is a pure text function: only the touched attribute changes, every other
|
|
3780
|
+
* byte (line endings and indentation included) survives, and a second pass is a no-op.
|
|
3781
|
+
*/
|
|
3782
|
+
/** Where `tauri android init` writes the app manifest, below `gen/android`. */
|
|
3783
|
+
const MANIFEST_PATH_SEGMENTS = [
|
|
3784
|
+
"app",
|
|
3785
|
+
"src",
|
|
3786
|
+
"main",
|
|
3787
|
+
"AndroidManifest.xml"
|
|
3788
|
+
];
|
|
3789
|
+
/** The tag name the application start tag opens with. */
|
|
3790
|
+
const APPLICATION_OPEN = "<application";
|
|
3791
|
+
/** Where an `<application` start tag opens. */
|
|
3792
|
+
const APPLICATION_OPEN_PATTERN = /<application(?=[\s/>])/;
|
|
3793
|
+
/** The tag name an activity start tag opens with. */
|
|
3794
|
+
const ACTIVITY_OPEN = "<activity";
|
|
3795
|
+
/** The end tag that closes an activity's body. */
|
|
3796
|
+
const ACTIVITY_CLOSE = "</activity>";
|
|
3797
|
+
/** The intent action that marks the launcher activity. */
|
|
3798
|
+
const MAIN_ACTION = "android.intent.action.MAIN";
|
|
3799
|
+
/** Where an `<activity` start tag opens — `<activity-alias` is a different element. */
|
|
3800
|
+
const ACTIVITY_OPEN_PATTERN = /<activity(?=[\s/>])/g;
|
|
3801
|
+
/**
|
|
3802
|
+
* One attribute inside a start tag, from the whitespace character before it:
|
|
3803
|
+
* ` (name)="value"`. XML allows spaces around `=`, but no generated manifest writes them.
|
|
3804
|
+
*/
|
|
3805
|
+
const ATTRIBUTE_PATTERN = /\s([\w:.-]+)=(?:"[^"]*"|'[^']*')/g;
|
|
3806
|
+
/** An XML comment — blanked before the scan, so a commented-out activity never counts. */
|
|
3807
|
+
const COMMENT_PATTERN = /<!--[\s\S]*?-->/g;
|
|
3808
|
+
/**
|
|
3809
|
+
* Builds the `[native]` error for a manifest whose main activity cannot be told apart.
|
|
3810
|
+
*
|
|
3811
|
+
* @param manifestPath - The manifest that was searched.
|
|
3812
|
+
* @returns A formatted `[native] ...` error.
|
|
3813
|
+
* @example
|
|
3814
|
+
* ```ts
|
|
3815
|
+
* throw mainActivityError("/repo/.moku/tauri/src-tauri/gen/android/app/src/main/AndroidManifest.xml");
|
|
3816
|
+
* ```
|
|
3817
|
+
*/
|
|
3818
|
+
function mainActivityError(manifestPath) {
|
|
3819
|
+
return /* @__PURE__ */ new Error(`[native] Could not find the main <activity> in ${manifestPath}.\n Re-run the mobile init pass (tauri android init) or report the manifest Tauri generated.`);
|
|
3820
|
+
}
|
|
3821
|
+
/**
|
|
3822
|
+
* Builds the `[native]` error for a manifest without an `<application>` element.
|
|
3823
|
+
*
|
|
3824
|
+
* @param manifestPath - The manifest that was searched.
|
|
3825
|
+
* @returns A formatted `[native] ...` error.
|
|
3826
|
+
* @example
|
|
3827
|
+
* ```ts
|
|
3828
|
+
* throw applicationError("/repo/.moku/tauri/src-tauri/gen/android/app/src/main/AndroidManifest.xml");
|
|
3829
|
+
* ```
|
|
3830
|
+
*/
|
|
3831
|
+
function applicationError(manifestPath) {
|
|
3832
|
+
return /* @__PURE__ */ new Error(`[native] Could not find the <application> element in ${manifestPath}.\n Re-run the mobile init pass (tauri android init) or report the manifest Tauri generated.`);
|
|
3833
|
+
}
|
|
3834
|
+
/**
|
|
3835
|
+
* Finds where a start tag ends. A quoted attribute value is skipped whole, so a `>` inside
|
|
3836
|
+
* one never ends the tag.
|
|
3837
|
+
*
|
|
3838
|
+
* @param text - The manifest content.
|
|
3839
|
+
* @param from - Offset just past the tag name.
|
|
3840
|
+
* @returns The offset just past the closing `>`, or undefined for a tag that never closes.
|
|
3841
|
+
* @example
|
|
3842
|
+
* ```ts
|
|
3843
|
+
* startTagEnd('<activity android:label="a > b">', 9); // 32
|
|
3844
|
+
* ```
|
|
3845
|
+
*/
|
|
3846
|
+
function startTagEnd(text, from) {
|
|
3847
|
+
let quote;
|
|
3848
|
+
for (let index = from; index < text.length; index += 1) {
|
|
3849
|
+
const character = text[index];
|
|
3850
|
+
if (quote !== void 0) {
|
|
3851
|
+
if (character === quote) quote = void 0;
|
|
3852
|
+
continue;
|
|
3853
|
+
}
|
|
3854
|
+
if (character === "\"" || character === "'") {
|
|
3855
|
+
quote = character;
|
|
3856
|
+
continue;
|
|
3857
|
+
}
|
|
3858
|
+
if (character === ">") return index + 1;
|
|
3859
|
+
}
|
|
3860
|
+
}
|
|
3861
|
+
/**
|
|
3862
|
+
* Locates every `<activity>` start tag and records whether its body declares MAIN.
|
|
3863
|
+
* Comments are blanked out first (same length, so every offset still points into the real
|
|
3864
|
+
* text), which keeps a commented-out activity from being counted or patched. A start tag
|
|
3865
|
+
* that never closes is not counted at all.
|
|
3866
|
+
*
|
|
3867
|
+
* @param text - The manifest content.
|
|
3868
|
+
* @returns One entry per activity, in file order.
|
|
3869
|
+
* @example
|
|
3870
|
+
* ```ts
|
|
3871
|
+
* locateActivities('<activity android:name=".A" /><activity android:name=".B"><action android:name="android.intent.action.MAIN" /></activity>');
|
|
3872
|
+
* // [{ start: 0, end: 30, isMain: false }, { start: 30, end: 58, isMain: true }]
|
|
3873
|
+
* ```
|
|
3874
|
+
*/
|
|
3875
|
+
function locateActivities(text) {
|
|
3876
|
+
const masked = text.replaceAll(COMMENT_PATTERN, (comment) => " ".repeat(comment.length));
|
|
3877
|
+
const activities = [];
|
|
3878
|
+
for (const match of masked.matchAll(ACTIVITY_OPEN_PATTERN)) {
|
|
3879
|
+
const start = match.index;
|
|
3880
|
+
const end = startTagEnd(masked, start + 9);
|
|
3881
|
+
if (end === void 0) continue;
|
|
3882
|
+
const body = masked.slice(start, end).endsWith("/>") ? "" : masked.slice(end, masked.indexOf(ACTIVITY_CLOSE, end));
|
|
3883
|
+
activities.push({
|
|
3884
|
+
start,
|
|
3885
|
+
end,
|
|
3886
|
+
isMain: body.includes(MAIN_ACTION)
|
|
3887
|
+
});
|
|
3888
|
+
}
|
|
3889
|
+
return activities;
|
|
3890
|
+
}
|
|
3891
|
+
/**
|
|
3892
|
+
* Picks the main activity: the one whose body declares MAIN. A manifest with a single
|
|
3893
|
+
* activity and no MAIN still has an obvious one; anything else is ambiguous.
|
|
3894
|
+
*
|
|
3895
|
+
* @param activities - Every activity in the manifest.
|
|
3896
|
+
* @returns The main activity, or undefined when none or several qualify.
|
|
3897
|
+
* @example
|
|
3898
|
+
* ```ts
|
|
3899
|
+
* mainActivity([{ start: 0, end: 30, isMain: false }, { start: 30, end: 58, isMain: true }]);
|
|
3900
|
+
* // { start: 30, end: 58, isMain: true }
|
|
3901
|
+
* mainActivity([{ start: 0, end: 30, isMain: false }, { start: 30, end: 58, isMain: false }]); // undefined
|
|
3902
|
+
* ```
|
|
3903
|
+
*/
|
|
3904
|
+
function mainActivity(activities) {
|
|
3905
|
+
const mains = activities.filter((activity) => activity.isMain);
|
|
3906
|
+
if (mains.length === 1) return mains[0];
|
|
3907
|
+
if (mains.length === 0 && activities.length === 1) return activities[0];
|
|
3908
|
+
}
|
|
3909
|
+
/**
|
|
3910
|
+
* Locates the first `<application>` start tag outside a comment.
|
|
3911
|
+
*
|
|
3912
|
+
* @param text - The manifest content.
|
|
3913
|
+
* @returns The tag's offsets, or undefined when there is none.
|
|
3914
|
+
* @example
|
|
3915
|
+
* ```ts
|
|
3916
|
+
* locateApplication('<manifest><application android:label="a"></application></manifest>');
|
|
3917
|
+
* // { start: 10, end: 40 }
|
|
3918
|
+
* ```
|
|
2987
3919
|
*/
|
|
2988
3920
|
function locateApplication(text) {
|
|
2989
3921
|
const masked = text.replaceAll(COMMENT_PATTERN, (comment) => " ".repeat(comment.length));
|
|
@@ -4482,322 +5414,206 @@ async function patchAndroidSystemBars(projectDirectory, genDirectory, background
|
|
|
4482
5414
|
unchanged: []
|
|
4483
5415
|
} : {
|
|
4484
5416
|
patched: [],
|
|
4485
|
-
unchanged: [activity.path]
|
|
4486
|
-
};
|
|
4487
|
-
}
|
|
4488
|
-
//#endregion
|
|
4489
|
-
//#region src/plugins/project/mobile/xcode-settings.ts
|
|
4490
|
-
/**
|
|
4491
|
-
* @file project plugin — the Xcode build-settings patch that makes an iOS REBUILD work.
|
|
4492
|
-
*
|
|
4493
|
-
* A capability plugin's build script rewrites the generated `<app>_iOS.entitlements` file
|
|
4494
|
-
* while Xcode is compiling, and Xcode fails the second build on that:
|
|
4495
|
-
* `Entitlements file "<app>_iOS.entitlements" was modified during the build, which is not
|
|
4496
|
-
* supported`. Xcode names the way out itself — `CODE_SIGN_ALLOW_ENTITLEMENTS_MODIFICATION`
|
|
4497
|
-
* — so every `buildSettings` block of the generated `project.pbxproj` carries it, and the
|
|
4498
|
-
* `project.yml` target carries it too, so a later xcodegen regeneration keeps it.
|
|
4499
|
-
*
|
|
4500
|
-
* Both transforms are pure text functions over the real generated shapes: line endings,
|
|
4501
|
-
* indentation and every neighbouring line survive byte for byte, and a second pass is a
|
|
4502
|
-
* no-op.
|
|
4503
|
-
*/
|
|
4504
|
-
/** The Xcode build setting that permits a build script to rewrite the entitlements file. */
|
|
4505
|
-
const ENTITLEMENTS_MODIFICATION_KEY = "CODE_SIGN_ALLOW_ENTITLEMENTS_MODIFICATION";
|
|
4506
|
-
/** The pbxproj value form — Xcode writes booleans as `YES`/`NO`. */
|
|
4507
|
-
const PBXPROJ_ENABLED_VALUE = "YES";
|
|
4508
|
-
/**
|
|
4509
|
-
* The project.yml value form. xcodegen renders a YAML boolean as `YES` in the pbxproj it
|
|
4510
|
-
* generates, which is why the target's sibling settings read `true`/`false` there.
|
|
4511
|
-
*/
|
|
4512
|
-
const YML_ENABLED_VALUE = "true";
|
|
4513
|
-
/** Opens one settings block inside a `XCBuildConfiguration` section. */
|
|
4514
|
-
const BUILD_SETTINGS_OPEN_PATTERN = /^([ \t]*)buildSettings = \{[ \t]*$/;
|
|
4515
|
-
/** The setting, already present as a pbxproj assignment (whatever its value). */
|
|
4516
|
-
const PBXPROJ_SETTING_PATTERN = new RegExp(`^[ \t]*${ENTITLEMENTS_MODIFICATION_KEY}[ \t]*=`);
|
|
4517
|
-
/** The setting, already present as a YAML key (whatever its value). */
|
|
4518
|
-
const YML_SETTING_PATTERN = new RegExp(`^[ \t]*${ENTITLEMENTS_MODIFICATION_KEY}[ \t]*:`);
|
|
4519
|
-
/** Opens a target's `settings:` mapping in `project.yml`. */
|
|
4520
|
-
const YML_SETTINGS_PATTERN = /^([ \t]*)settings:[ \t]*$/;
|
|
4521
|
-
/** Opens the `base:` mapping a `settings:` block carries its own build settings in. */
|
|
4522
|
-
const YML_BASE_PATTERN = /^([ \t]*)base:[ \t]*$/;
|
|
4523
|
-
/** The leading whitespace of a line — never matches a line break. */
|
|
4524
|
-
const INDENT_PATTERN = /^[ \t]*/;
|
|
4525
|
-
/** Splits text into lines, keeping each line's own terminator attached to it. */
|
|
4526
|
-
const LINE_SPLIT_PATTERN = /(?<=\n)/;
|
|
4527
|
-
/** A line's terminator (LF or CRLF), stripped to compare the line's text alone. */
|
|
4528
|
-
const LINE_ENDING_PATTERN = /\r?\n$/;
|
|
4529
|
-
/** One indentation step inside a pbxproj — the generated file is tab-indented. */
|
|
4530
|
-
const PBXPROJ_NESTED_INDENT = " ";
|
|
4531
|
-
/** One indentation step inside a project.yml — YAML mappings never indent with tabs. */
|
|
4532
|
-
const YML_NESTED_INDENT = " ";
|
|
4533
|
-
/**
|
|
4534
|
-
* Splits text into lines that each remember their own terminator, so a file mixing (or
|
|
4535
|
-
* using) CRLF comes back out exactly as it went in.
|
|
4536
|
-
*
|
|
4537
|
-
* @param text - The file content.
|
|
4538
|
-
* @returns One entry per line, in order.
|
|
4539
|
-
* @example
|
|
4540
|
-
* ```ts
|
|
4541
|
-
* splitLines("a\r\nb"); // [{ body: "a", ending: "\r\n" }, { body: "b", ending: "" }]
|
|
4542
|
-
* ```
|
|
4543
|
-
*/
|
|
4544
|
-
function splitLines$1(text) {
|
|
4545
|
-
return text.split(LINE_SPLIT_PATTERN).map((chunk) => {
|
|
4546
|
-
const body = chunk.replace(LINE_ENDING_PATTERN, "");
|
|
4547
|
-
return {
|
|
4548
|
-
body,
|
|
4549
|
-
ending: chunk.slice(body.length)
|
|
4550
|
-
};
|
|
4551
|
-
});
|
|
4552
|
-
}
|
|
4553
|
-
/**
|
|
4554
|
-
* Joins lines back into file content.
|
|
4555
|
-
*
|
|
4556
|
-
* @param lines - The lines to join.
|
|
4557
|
-
* @returns The file content.
|
|
4558
|
-
* @example
|
|
4559
|
-
* ```ts
|
|
4560
|
-
* joinLines([{ body: "a", ending: "\n" }]); // "a\n"
|
|
4561
|
-
* ```
|
|
4562
|
-
*/
|
|
4563
|
-
function joinLines(lines) {
|
|
4564
|
-
return lines.map((line) => line.body + line.ending).join("");
|
|
4565
|
-
}
|
|
4566
|
-
/**
|
|
4567
|
-
* Reads a line's leading whitespace — the indentation a new sibling line has to match.
|
|
4568
|
-
*
|
|
4569
|
-
* @param body - The line's text.
|
|
4570
|
-
* @returns The leading spaces/tabs, possibly empty.
|
|
4571
|
-
* @example
|
|
4572
|
-
* ```ts
|
|
4573
|
-
* indentOf("\t\t\tisa = XCBuildConfiguration;"); // "\t\t\t"
|
|
4574
|
-
* ```
|
|
4575
|
-
*/
|
|
4576
|
-
function indentOf(body) {
|
|
4577
|
-
return INDENT_PATTERN.exec(body)?.[0] ?? "";
|
|
5417
|
+
unchanged: [activity.path]
|
|
5418
|
+
};
|
|
4578
5419
|
}
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
*
|
|
4583
|
-
*
|
|
4584
|
-
*
|
|
4585
|
-
*
|
|
4586
|
-
*
|
|
4587
|
-
*
|
|
4588
|
-
*
|
|
4589
|
-
*
|
|
4590
|
-
*
|
|
5420
|
+
//#endregion
|
|
5421
|
+
//#region src/plugins/project/mobile/window-background.ts
|
|
5422
|
+
/**
|
|
5423
|
+
* @file project plugin — the Android window background patch. The generated app theme
|
|
5424
|
+
* (`Theme.Material3.DayNight.NoActionBar`) sets no window background, so between the
|
|
5425
|
+
* system's icon splash and the WebView's first paint the activity window shows the theme's
|
|
5426
|
+
* default, dark in night mode: a dark flash at every launch. When `app.backgroundColor` is
|
|
5427
|
+
* set, this patch writes that colour as a moku-owned colour resource and points the app
|
|
5428
|
+
* theme's `android:windowBackground` and `android:windowSplashScreenBackground` (the
|
|
5429
|
+
* Android 12+ icon splash) at it, in every `res/values*\/themes.xml` that holds the theme.
|
|
5430
|
+
*
|
|
5431
|
+
* Every line and file this patch writes carries {@link MARKER}, so a pass first strips its
|
|
5432
|
+
* own lines and then writes them again: a second pass is a no-op, other bytes (line endings
|
|
5433
|
+
* included) survive, and unsetting the colour restores the generated files.
|
|
5434
|
+
*/
|
|
5435
|
+
/** Marks every line and file this patch owns. */
|
|
5436
|
+
const MARKER = "<!-- moku:native window background -->";
|
|
5437
|
+
/** The colour resource the theme items point at. */
|
|
5438
|
+
const COLOUR_NAME = "moku_window_background";
|
|
5439
|
+
/** The unqualified resource directory: the day theme and the colour resource live there. */
|
|
5440
|
+
const VALUES_DIRECTORY = "values";
|
|
5441
|
+
/** The theme file `tauri android init` writes per resource qualifier. */
|
|
5442
|
+
const THEMES_FILE = "themes.xml";
|
|
5443
|
+
/** `#rrggbb` or `#rrggbbaa`: the colour and the optional alpha, captured apart. */
|
|
5444
|
+
const HEX_COLOUR_PATTERN$1 = /^#([\da-f]{6})([\da-f]{2})?$/i;
|
|
5445
|
+
/** The prefix `android:theme` names the app theme with. */
|
|
5446
|
+
const STYLE_REFERENCE_PREFIX = "@style/";
|
|
5447
|
+
/** The theme items, in the order they are written: window first, then the icon splash. */
|
|
5448
|
+
const THEME_ITEMS = [`<item name="android:windowBackground">@color/${COLOUR_NAME}</item>`, `<item name="android:windowSplashScreenBackground" tools:targetApi="31">@color/${COLOUR_NAME}</item>`];
|
|
5449
|
+
/** One level of indentation, for a style with no child line to copy it from. */
|
|
5450
|
+
const INDENT_STEP = " ";
|
|
5451
|
+
/** The leading spaces and tabs of a line. */
|
|
5452
|
+
const INDENT_PATTERN = /^[\t ]*/;
|
|
5453
|
+
/**
|
|
5454
|
+
* Builds the `[native]` error for a generated file this patch needs and cannot use.
|
|
5455
|
+
*
|
|
5456
|
+
* @param problem - What is wrong, starting with the file path.
|
|
5457
|
+
* @returns A formatted `[native] ...` error.
|
|
4591
5458
|
* @example
|
|
4592
5459
|
* ```ts
|
|
4593
|
-
*
|
|
5460
|
+
* throw initError("/repo/.moku/tauri/src-tauri/gen/android/app/src/main/res/values/themes.xml not found");
|
|
4594
5461
|
* ```
|
|
4595
5462
|
*/
|
|
4596
|
-
function
|
|
4597
|
-
|
|
4598
|
-
const existingIndex = block.findIndex((line) => present.test(line.body));
|
|
4599
|
-
if (existingIndex !== -1) return block.map((line, index) => index === existingIndex ? {
|
|
4600
|
-
body: render(indentOf(line.body)),
|
|
4601
|
-
ending: line.ending
|
|
4602
|
-
} : line);
|
|
4603
|
-
const sibling = block.find((line) => line.body.trim().length > 0);
|
|
4604
|
-
return [{
|
|
4605
|
-
body: render(sibling ? indentOf(sibling.body) : fallbackIndent),
|
|
4606
|
-
ending: sibling?.ending ?? fallbackEnding
|
|
4607
|
-
}, ...block];
|
|
5463
|
+
function initError(problem) {
|
|
5464
|
+
return /* @__PURE__ */ new Error(`[native] ${problem}.\n Re-run the mobile init pass (tauri android init), or unset app.backgroundColor.`);
|
|
4608
5465
|
}
|
|
4609
5466
|
/**
|
|
4610
|
-
*
|
|
4611
|
-
* block does not own.
|
|
5467
|
+
* Converts `app.backgroundColor` to Android's colour notation, which puts the alpha first.
|
|
4612
5468
|
*
|
|
4613
|
-
* @param
|
|
4614
|
-
* @
|
|
4615
|
-
* @
|
|
4616
|
-
* @returns The block's lines, and the index of the first line after it.
|
|
5469
|
+
* @param colour - `#rrggbb` or `#rrggbbaa`.
|
|
5470
|
+
* @returns `#rrggbb` unchanged, or `#aarrggbb`.
|
|
5471
|
+
* @throws {Error} `[native]` when the value is not a hex colour.
|
|
4617
5472
|
* @example
|
|
4618
5473
|
* ```ts
|
|
4619
|
-
*
|
|
5474
|
+
* androidColour("#10161d"); // "#10161d"
|
|
5475
|
+
* androidColour("#10161d80"); // "#8010161d"
|
|
4620
5476
|
* ```
|
|
4621
5477
|
*/
|
|
4622
|
-
function
|
|
4623
|
-
const
|
|
4624
|
-
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
if (!line || !isMember(line)) break;
|
|
4628
|
-
block.push(line);
|
|
4629
|
-
index += 1;
|
|
4630
|
-
}
|
|
4631
|
-
return {
|
|
4632
|
-
block,
|
|
4633
|
-
next: index
|
|
4634
|
-
};
|
|
5478
|
+
function androidColour(colour) {
|
|
5479
|
+
const match = HEX_COLOUR_PATTERN$1.exec(colour);
|
|
5480
|
+
if (!match) throw new Error(`[native] app.backgroundColor "${colour}" is not a valid colour.\n Use a hex colour such as "#10161d".`);
|
|
5481
|
+
const [, rgb = "", alpha = ""] = match;
|
|
5482
|
+
return `#${alpha}${rgb}`;
|
|
4635
5483
|
}
|
|
4636
5484
|
/**
|
|
4637
|
-
*
|
|
5485
|
+
* Sets or clears the window background items of one `themes.xml`. The patch's own lines are
|
|
5486
|
+
* removed first; when enabled, the items go right after the start tag of the named style,
|
|
5487
|
+
* at the indentation of the line that follows it.
|
|
4638
5488
|
*
|
|
4639
|
-
* @param
|
|
4640
|
-
* @
|
|
5489
|
+
* @param source - The `themes.xml` content.
|
|
5490
|
+
* @param styleName - The app theme, as `android:theme` names it without `@style/`.
|
|
5491
|
+
* @param enabled - Whether `app.backgroundColor` is set.
|
|
5492
|
+
* @param filePath - The `themes.xml` path, named in the error.
|
|
5493
|
+
* @returns The content with the items applied.
|
|
5494
|
+
* @throws {Error} `[native]` when enabled and the file holds no such style.
|
|
4641
5495
|
* @example
|
|
4642
5496
|
* ```ts
|
|
4643
|
-
*
|
|
5497
|
+
* applyWindowBackground('<resources>\n <style name="Theme.app" parent="P">\n </style>\n</resources>\n', "Theme.app", true, "themes.xml");
|
|
5498
|
+
* // the same file with the window and splash items as the style's first two lines
|
|
4644
5499
|
* ```
|
|
4645
5500
|
*/
|
|
4646
|
-
function
|
|
4647
|
-
|
|
5501
|
+
function applyWindowBackground(source, styleName, enabled, filePath) {
|
|
5502
|
+
const lines = source.split("\n").filter((line) => !line.includes(MARKER));
|
|
5503
|
+
if (!enabled) return lines.join("\n");
|
|
5504
|
+
const index = lines.findIndex((line) => line.includes(`<style name="${styleName}"`));
|
|
5505
|
+
if (index === -1) throw initError(`${filePath} has no <style name="${styleName}"> to set the window background in`);
|
|
5506
|
+
const styleIndent = INDENT_PATTERN.exec(lines[index] ?? "")?.[0] ?? "";
|
|
5507
|
+
const nextIndent = INDENT_PATTERN.exec(lines[index + 1] ?? "")?.[0] ?? "";
|
|
5508
|
+
const indent = nextIndent.length > styleIndent.length ? nextIndent : styleIndent + INDENT_STEP;
|
|
5509
|
+
const carriageReturn = source.includes("\r\n") ? "\r" : "";
|
|
5510
|
+
const items = THEME_ITEMS.map((item) => `${indent}${item} ${MARKER}${carriageReturn}`);
|
|
5511
|
+
return [
|
|
5512
|
+
...lines.slice(0, index + 1),
|
|
5513
|
+
...items,
|
|
5514
|
+
...lines.slice(index + 1)
|
|
5515
|
+
].join("\n");
|
|
4648
5516
|
}
|
|
4649
5517
|
/**
|
|
4650
|
-
*
|
|
5518
|
+
* Builds the moku-owned colour resource file.
|
|
4651
5519
|
*
|
|
4652
|
-
* @param
|
|
4653
|
-
* @returns The
|
|
5520
|
+
* @param colour - The colour in Android notation.
|
|
5521
|
+
* @returns The `moku_window_background.xml` content.
|
|
4654
5522
|
* @example
|
|
4655
5523
|
* ```ts
|
|
4656
|
-
*
|
|
5524
|
+
* colourResource("#10161d"); // a <resources> file with <color name="moku_window_background">#10161d</color>
|
|
4657
5525
|
* ```
|
|
4658
5526
|
*/
|
|
4659
|
-
function
|
|
4660
|
-
return
|
|
5527
|
+
function colourResource(colour) {
|
|
5528
|
+
return [
|
|
5529
|
+
"<?xml version=\"1.0\" encoding=\"utf-8\"?>",
|
|
5530
|
+
MARKER,
|
|
5531
|
+
"<resources>",
|
|
5532
|
+
` <color name="${COLOUR_NAME}">${colour}</color>`,
|
|
5533
|
+
"</resources>",
|
|
5534
|
+
""
|
|
5535
|
+
].join("\n");
|
|
4661
5536
|
}
|
|
4662
5537
|
/**
|
|
4663
|
-
*
|
|
4664
|
-
* `project.yml` that holds build settings.
|
|
4665
|
-
*
|
|
4666
|
-
* The block is walked, not peeked at: `base:` is a direct child of `settings:`, but not
|
|
4667
|
-
* necessarily the FIRST one — xcodegen is equally happy with `settings:` followed by
|
|
4668
|
-
* `groups: [app]` and `base:` below it. So every line indented deeper than `settings:` is
|
|
4669
|
-
* scanned until the block dedents, and the first `base:` sitting at the direct-child level
|
|
4670
|
-
* wins; a nested `base:` deeper inside somebody else's sub-mapping does not. A `settings:`
|
|
4671
|
-
* block carrying no `base:` at all owns no such block and is left alone.
|
|
5538
|
+
* Lists every `res/values*\/themes.xml` of the tree, sorted, so `values` comes first.
|
|
4672
5539
|
*
|
|
4673
|
-
* @param
|
|
4674
|
-
* @
|
|
4675
|
-
* @returns The `base:` line, its index and its indentation, or undefined when there is none.
|
|
4676
|
-
* @example
|
|
4677
|
-
* ```ts
|
|
4678
|
-
* baseMappingAt(splitLines(" settings:\n groups: [app]\n base:\n"), 0);
|
|
4679
|
-
* ```
|
|
5540
|
+
* @param resourceDirectory - The `app/src/main/res` directory.
|
|
5541
|
+
* @returns The theme files found, possibly none.
|
|
4680
5542
|
*/
|
|
4681
|
-
function
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
if (!settings) return void 0;
|
|
4685
|
-
const settingsIndent = (settings[1] ?? "").length;
|
|
4686
|
-
let childIndent;
|
|
4687
|
-
for (let index = settingsIndex + 1; index < lines.length; index += 1) {
|
|
4688
|
-
const line = lines[index];
|
|
4689
|
-
if (!line) break;
|
|
4690
|
-
if (line.body.trim().length === 0) continue;
|
|
4691
|
-
const indent = indentOf(line.body);
|
|
4692
|
-
if (indent.length <= settingsIndent) break;
|
|
4693
|
-
childIndent ??= indent.length;
|
|
4694
|
-
if (indent.length !== childIndent) continue;
|
|
4695
|
-
if (YML_BASE_PATTERN.test(line.body)) return {
|
|
4696
|
-
line,
|
|
4697
|
-
index,
|
|
4698
|
-
indent
|
|
4699
|
-
};
|
|
4700
|
-
}
|
|
5543
|
+
async function themeFiles(resourceDirectory) {
|
|
5544
|
+
if (!(0, node_fs.existsSync)(resourceDirectory)) return [];
|
|
5545
|
+
return (await (0, node_fs_promises.readdir)(resourceDirectory, { withFileTypes: true })).filter((entry) => entry.isDirectory() && entry.name.startsWith(VALUES_DIRECTORY)).map((entry) => entry.name).toSorted().map((name) => node_path.default.join(resourceDirectory, name, THEMES_FILE)).filter((file) => (0, node_fs.existsSync)(file));
|
|
4701
5546
|
}
|
|
4702
5547
|
/**
|
|
4703
|
-
*
|
|
4704
|
-
* a generated `project.pbxproj`, exactly once per block and at the indentation its sibling
|
|
4705
|
-
* settings use. Content outside those blocks — the shell-script build phase included — is
|
|
4706
|
-
* returned byte for byte, and a file that already carries the setting comes back unchanged.
|
|
5548
|
+
* Reads the app theme's style name from the manifest's `<application android:theme>`.
|
|
4707
5549
|
*
|
|
4708
|
-
* @param
|
|
4709
|
-
* @returns The
|
|
4710
|
-
* @
|
|
4711
|
-
* ```ts
|
|
4712
|
-
* applyPbxprojEntitlementsSetting(await readFile(pbxprojPath, "utf8"));
|
|
4713
|
-
* ```
|
|
5550
|
+
* @param genDirectory - The `src-tauri/gen/android` directory.
|
|
5551
|
+
* @returns The style name without `@style/`.
|
|
5552
|
+
* @throws {Error} `[native]` when the manifest is missing or names no style.
|
|
4714
5553
|
*/
|
|
4715
|
-
function
|
|
4716
|
-
const
|
|
4717
|
-
|
|
4718
|
-
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
if (!line) break;
|
|
4722
|
-
patched.push(line);
|
|
4723
|
-
index += 1;
|
|
4724
|
-
const opening = BUILD_SETTINGS_OPEN_PATTERN.exec(line.body);
|
|
4725
|
-
if (!opening) continue;
|
|
4726
|
-
const blockIndent = opening[1] ?? "";
|
|
4727
|
-
const closing = `${blockIndent}};`;
|
|
4728
|
-
const { block, next } = collectBlock(lines, index, (inner) => inner.body !== closing);
|
|
4729
|
-
index = next;
|
|
4730
|
-
patched.push(...placeSetting(block, {
|
|
4731
|
-
present: PBXPROJ_SETTING_PATTERN,
|
|
4732
|
-
render: renderPbxprojSetting,
|
|
4733
|
-
fallbackIndent: `${blockIndent}${PBXPROJ_NESTED_INDENT}`,
|
|
4734
|
-
fallbackEnding: line.ending
|
|
4735
|
-
}));
|
|
4736
|
-
}
|
|
4737
|
-
return joinLines(patched);
|
|
5554
|
+
async function appThemeName(genDirectory) {
|
|
5555
|
+
const manifestPath = androidManifestPath(genDirectory);
|
|
5556
|
+
if (!(0, node_fs.existsSync)(manifestPath)) throw initError(`${manifestPath} not found`);
|
|
5557
|
+
const theme = applicationAttribute(await (0, node_fs_promises.readFile)(manifestPath, "utf8"), "android:theme");
|
|
5558
|
+
if (!theme?.startsWith(STYLE_REFERENCE_PREFIX)) throw initError(`${manifestPath} names no android:theme on <application> to set the window background in`);
|
|
5559
|
+
return theme.slice(7);
|
|
4738
5560
|
}
|
|
4739
5561
|
/**
|
|
4740
|
-
*
|
|
4741
|
-
*
|
|
4742
|
-
* direct child of a `settings:` mapping is touched — a `settingGroups:` block is somebody
|
|
4743
|
-
* else's. A blank line inside the block does not end it: YAML mappings end at a dedent, so
|
|
4744
|
-
* an entry printed below an empty line is still seen and never duplicated.
|
|
5562
|
+
* Writes or removes the moku-owned colour resource. A file without the marker is someone
|
|
5563
|
+
* else's and is never touched.
|
|
4745
5564
|
*
|
|
4746
|
-
* @param
|
|
4747
|
-
* @
|
|
4748
|
-
* @
|
|
4749
|
-
*
|
|
4750
|
-
*
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
let index = 0;
|
|
4757
|
-
while (index < lines.length) {
|
|
4758
|
-
const line = lines[index];
|
|
4759
|
-
if (!line) break;
|
|
4760
|
-
const base = baseMappingAt(lines, index);
|
|
4761
|
-
patched.push(line);
|
|
4762
|
-
index += 1;
|
|
4763
|
-
if (!base) continue;
|
|
4764
|
-
patched.push(...lines.slice(index, base.index + 1));
|
|
4765
|
-
index = base.index + 1;
|
|
4766
|
-
const { block, next } = collectBlock(lines, index, (entry) => entry.body.trim().length === 0 || indentOf(entry.body).length > base.indent.length);
|
|
4767
|
-
index = next;
|
|
4768
|
-
patched.push(...placeSetting(block, {
|
|
4769
|
-
present: YML_SETTING_PATTERN,
|
|
4770
|
-
render: renderYmlSetting,
|
|
4771
|
-
fallbackIndent: `${base.indent}${YML_NESTED_INDENT}`,
|
|
4772
|
-
fallbackEnding: base.line.ending
|
|
4773
|
-
}));
|
|
5565
|
+
* @param projectDirectory - The Tauri project root.
|
|
5566
|
+
* @param colourPath - The `res/values/moku_window_background.xml` path.
|
|
5567
|
+
* @param colour - The colour in Android notation, or undefined to remove the file.
|
|
5568
|
+
* @param result - The lists the path is recorded in.
|
|
5569
|
+
* @returns Resolves once the file is in place or gone.
|
|
5570
|
+
*/
|
|
5571
|
+
async function syncColourFile(projectDirectory, colourPath, colour, result) {
|
|
5572
|
+
if (colour !== void 0) {
|
|
5573
|
+
(await writeIfChanged(colourPath, colourResource(colour), projectDirectory) === "written" ? result.patched : result.unchanged).push(colourPath);
|
|
5574
|
+
return;
|
|
4774
5575
|
}
|
|
4775
|
-
|
|
5576
|
+
if (!(0, node_fs.existsSync)(colourPath)) return;
|
|
5577
|
+
if (!(await (0, node_fs_promises.readFile)(colourPath, "utf8")).includes(MARKER)) return;
|
|
5578
|
+
await (0, node_fs_promises.rm)(colourPath, { force: true });
|
|
5579
|
+
result.patched.push(colourPath);
|
|
4776
5580
|
}
|
|
4777
5581
|
/**
|
|
4778
|
-
*
|
|
4779
|
-
*
|
|
4780
|
-
*
|
|
5582
|
+
* Sets the Android window and icon-splash background from `app.backgroundColor`, through
|
|
5583
|
+
* the write-if-changed writer: the colour resource, then every `themes.xml` in sorted order.
|
|
5584
|
+
* Without a colour the patch's own lines and file are removed, and a tree it never touched
|
|
5585
|
+
* is left as it is.
|
|
4781
5586
|
*
|
|
4782
5587
|
* @param projectDirectory - The Tauri project root.
|
|
4783
|
-
* @param genDirectory - The `src-tauri/gen/
|
|
4784
|
-
* @
|
|
5588
|
+
* @param genDirectory - The `src-tauri/gen/android` directory.
|
|
5589
|
+
* @param backgroundColor - `app.backgroundColor`, or undefined when unset.
|
|
5590
|
+
* @returns The colour file and theme files, patched or unchanged.
|
|
5591
|
+
* @throws {Error} `[native]` when a colour is set and the manifest names no app theme, the
|
|
5592
|
+
* `res/values/themes.xml` is missing, or it lacks the app theme.
|
|
4785
5593
|
* @example
|
|
4786
5594
|
* ```ts
|
|
4787
|
-
*
|
|
5595
|
+
* // First pass on the generated tree; a second pass lists every file under `unchanged`.
|
|
5596
|
+
* await patchAndroidWindowBackground(".moku/tauri", ".moku/tauri/src-tauri/gen/android", "#10161d");
|
|
5597
|
+
* // { patched: [".../values/moku_window_background.xml", ".../values/themes.xml", ".../values-night/themes.xml"], unchanged: [] }
|
|
4788
5598
|
* ```
|
|
4789
5599
|
*/
|
|
4790
|
-
async function
|
|
4791
|
-
const
|
|
4792
|
-
const
|
|
4793
|
-
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
|
|
4797
|
-
|
|
4798
|
-
|
|
4799
|
-
unchanged
|
|
5600
|
+
async function patchAndroidWindowBackground(projectDirectory, genDirectory, backgroundColor) {
|
|
5601
|
+
const colour = backgroundColor === void 0 ? void 0 : androidColour(backgroundColor);
|
|
5602
|
+
const resourceDirectory = androidResourceDirectory(genDirectory);
|
|
5603
|
+
const dayThemes = node_path.default.join(resourceDirectory, VALUES_DIRECTORY, THEMES_FILE);
|
|
5604
|
+
const styleName = colour === void 0 ? "" : await appThemeName(genDirectory);
|
|
5605
|
+
if (colour !== void 0 && !(0, node_fs.existsSync)(dayThemes)) throw initError(`${dayThemes} not found`);
|
|
5606
|
+
const result = {
|
|
5607
|
+
patched: [],
|
|
5608
|
+
unchanged: []
|
|
4800
5609
|
};
|
|
5610
|
+
await syncColourFile(projectDirectory, node_path.default.join(resourceDirectory, VALUES_DIRECTORY, `${COLOUR_NAME}.xml`), colour, result);
|
|
5611
|
+
for (const file of await themeFiles(resourceDirectory)) {
|
|
5612
|
+
const source = await (0, node_fs_promises.readFile)(file, "utf8");
|
|
5613
|
+
const holdsTheme = file === dayThemes || source.includes(`<style name="${styleName}"`);
|
|
5614
|
+
(await writeIfChanged(file, applyWindowBackground(source, styleName, colour !== void 0 && holdsTheme, file), projectDirectory) === "written" ? result.patched : result.unchanged).push(file);
|
|
5615
|
+
}
|
|
5616
|
+
return result;
|
|
4801
5617
|
}
|
|
4802
5618
|
//#endregion
|
|
4803
5619
|
//#region src/plugins/project/mobile/patch.ts
|
|
@@ -4807,8 +5623,10 @@ async function patchXcodeSettings(projectDirectory, genDirectory) {
|
|
|
4807
5623
|
* `profile.ts` (the Android build-profile patches), `signing.ts` (the Android
|
|
4808
5624
|
* release-signing block), `manifest.ts` (the Android main activity's attributes, such as
|
|
4809
5625
|
* the orientation lock), `system-bars.ts` (the Android status bar icon style from
|
|
4810
|
-
* `app.backgroundColor`), `
|
|
4811
|
-
* `
|
|
5626
|
+
* `app.backgroundColor`), `window-background.ts` (the Android window and icon-splash
|
|
5627
|
+
* background from the same colour), `runner.ts` (the Xcode / Android-Studio runner command),
|
|
5628
|
+
* `xcode-settings.ts` (the iOS entitlements-modification setting that makes a REBUILD work)
|
|
5629
|
+
* and `ios-project.ts` (the iOS deployment target and privacy manifest).
|
|
4812
5630
|
*/
|
|
4813
5631
|
/** The profile of a pass whose caller names none: the store profile, warnings dropped. */
|
|
4814
5632
|
const STORE_PROFILE = { profile: "store" };
|
|
@@ -4832,31 +5650,44 @@ function mergePatchResults(...results) {
|
|
|
4832
5650
|
};
|
|
4833
5651
|
}
|
|
4834
5652
|
/**
|
|
4835
|
-
* The iOS half of {@link patchMobile}: the Xcode entitlements-modification setting,
|
|
4836
|
-
*
|
|
4837
|
-
* left alone and reports nothing.
|
|
5653
|
+
* The iOS half of {@link patchMobile}: the Xcode entitlements-modification setting, the
|
|
5654
|
+
* deployment target, the privacy manifest, then the runner command when the caller supplies
|
|
5655
|
+
* a runner. A tree that was never initialised is left alone and reports nothing.
|
|
4838
5656
|
*
|
|
4839
|
-
* @param
|
|
4840
|
-
* @param
|
|
4841
|
-
* @param
|
|
4842
|
-
* @
|
|
5657
|
+
* @param options - What to patch.
|
|
5658
|
+
* @param options.projectDirectory - The Tauri project root.
|
|
5659
|
+
* @param options.genDirectory - The `src-tauri/gen/apple` directory.
|
|
5660
|
+
* @param options.runner - The absolute Node/tauri.js runner pair, or undefined to keep it.
|
|
5661
|
+
* @param options.minimumVersion - The iOS deployment target to write.
|
|
5662
|
+
* @param options.privacyManifest - `ios.privacyManifest`; unset removes one a previous pass
|
|
5663
|
+
* added.
|
|
5664
|
+
* @returns The paths patched vs. left unchanged, merged over every patch.
|
|
5665
|
+
* @throws {Error} When the privacy manifest source is missing (before anything is written),
|
|
5666
|
+
* or a project file lacks a line a patch needs.
|
|
4843
5667
|
*/
|
|
4844
|
-
async function patchIos(
|
|
5668
|
+
async function patchIos(options) {
|
|
5669
|
+
const { projectDirectory, genDirectory, runner } = options;
|
|
4845
5670
|
if (!(0, node_fs.existsSync)(genDirectory)) return {
|
|
4846
5671
|
patched: [],
|
|
4847
5672
|
unchanged: []
|
|
4848
5673
|
};
|
|
4849
|
-
const
|
|
4850
|
-
|
|
4851
|
-
|
|
5674
|
+
const manifest = await readPrivacyManifest(options.privacyManifest);
|
|
5675
|
+
const iosResults = [
|
|
5676
|
+
await patchXcodeSettings(projectDirectory, genDirectory),
|
|
5677
|
+
await patchDeploymentTarget(projectDirectory, genDirectory, options.minimumVersion),
|
|
5678
|
+
await patchPrivacyManifest(projectDirectory, genDirectory, manifest)
|
|
5679
|
+
];
|
|
5680
|
+
if (!runner) return mergePatchResults(...iosResults);
|
|
5681
|
+
const runnerResult = await patchRunner(projectDirectory, genDirectory, {
|
|
4852
5682
|
target: "ios",
|
|
4853
5683
|
runner
|
|
4854
|
-
})
|
|
5684
|
+
});
|
|
5685
|
+
return mergePatchResults(...iosResults, runnerResult);
|
|
4855
5686
|
}
|
|
4856
5687
|
/**
|
|
4857
5688
|
* The Android half of {@link patchMobile}: the build-profile patches, the release signing
|
|
4858
|
-
* block, the main activity's manifest attributes, the status bar style,
|
|
4859
|
-
* command when the caller supplies a runner.
|
|
5689
|
+
* block, the main activity's manifest attributes, the status bar style, the window
|
|
5690
|
+
* background, then the runner command when the caller supplies a runner.
|
|
4860
5691
|
*
|
|
4861
5692
|
* @param options - What to patch.
|
|
4862
5693
|
* @param options.projectDirectory - The Tauri project root.
|
|
@@ -4864,7 +5695,8 @@ async function patchIos(projectDirectory, genDirectory, runner) {
|
|
|
4864
5695
|
* @param options.runner - The absolute Node/tauri.js runner pair, or undefined to keep it.
|
|
4865
5696
|
* @param options.signing - The full signing config (only `.android` is consulted).
|
|
4866
5697
|
* @param options.manifest - Android manifest entries for the main activity.
|
|
4867
|
-
* @param options.backgroundColor - `app.backgroundColor`, which the status bar icons
|
|
5698
|
+
* @param options.backgroundColor - `app.backgroundColor`, which the status bar icons and the
|
|
5699
|
+
* window background follow.
|
|
4868
5700
|
* @param options.profile - The Android build profile.
|
|
4869
5701
|
* @returns The paths patched vs. left unchanged, merged over every patch.
|
|
4870
5702
|
* @throws {Error} When the `gen/android` tree (or its `app/build.gradle.kts`) is missing, the
|
|
@@ -4884,7 +5716,8 @@ async function patchAndroid(options) {
|
|
|
4884
5716
|
}),
|
|
4885
5717
|
await patchAndroidSigning(projectDirectory, genDirectory, options.signing.android ?? {}, debugKeystore),
|
|
4886
5718
|
await patchAndroidManifest(projectDirectory, genDirectory, options.manifest),
|
|
4887
|
-
await patchAndroidSystemBars(projectDirectory, genDirectory, options.backgroundColor)
|
|
5719
|
+
await patchAndroidSystemBars(projectDirectory, genDirectory, options.backgroundColor),
|
|
5720
|
+
await patchAndroidWindowBackground(projectDirectory, genDirectory, options.backgroundColor)
|
|
4888
5721
|
];
|
|
4889
5722
|
if (!runner) return mergePatchResults(...androidResults);
|
|
4890
5723
|
const runnerResult = await patchRunner(projectDirectory, genDirectory, {
|
|
@@ -4896,31 +5729,46 @@ async function patchAndroid(options) {
|
|
|
4896
5729
|
/**
|
|
4897
5730
|
* Deterministic, idempotent post-init patch pass over an existing complete gen/ tree.
|
|
4898
5731
|
* Android gets, in this order, its build-profile patches, its release signing block, the
|
|
4899
|
-
* main activity's manifest attributes, the system bar style in MainActivity.kt,
|
|
4900
|
-
*
|
|
4901
|
-
*
|
|
5732
|
+
* main activity's manifest attributes, the system bar style in MainActivity.kt, the window
|
|
5733
|
+
* and icon-splash background in the app theme, then the runner command. The profile
|
|
5734
|
+
* patches run before signing so that the store profile cuts its Gradle block out byte for
|
|
5735
|
+
* byte, wherever the signing block sits. iOS gets the Xcode
|
|
4902
5736
|
* entitlements-modification setting (without it the SECOND build of the same tree fails),
|
|
4903
|
-
*
|
|
4904
|
-
*
|
|
4905
|
-
*
|
|
4906
|
-
*
|
|
5737
|
+
* the deployment target and the privacy manifest (a kept tree never runs xcodegen again, so
|
|
5738
|
+
* both land in `project.yml` AND `project.pbxproj`), then the runner command. The runner
|
|
5739
|
+
* rewrite runs only when the caller supplies a `runner`. iOS takes no manifest entries, no
|
|
5740
|
+
* background colour and no profile: its orientation lock and signing travel through the
|
|
5741
|
+
* generated `Info.ios.plist` sidecar and tauri.conf.json, and its status bar adapts to the
|
|
5742
|
+
* page on its own.
|
|
4907
5743
|
*
|
|
4908
5744
|
* @param projectDirectory - The Tauri project root.
|
|
4909
5745
|
* @param opts - The mobile platform, and optionally the absolute Node/tauri.js runner pair.
|
|
4910
|
-
* @param signing - The full signing config (
|
|
5746
|
+
* @param signing - The full signing config (`.android` on Android, the iOS minimum in
|
|
5747
|
+
* `.apple` on iOS).
|
|
4911
5748
|
* @param manifest - Android manifest entries for the main activity (ignored on iOS).
|
|
4912
|
-
* @param backgroundColor - `app.backgroundColor`; the Android status bar icons
|
|
4913
|
-
* (ignored on iOS).
|
|
5749
|
+
* @param backgroundColor - `app.backgroundColor`; the Android status bar icons, window
|
|
5750
|
+
* background and icon-splash background follow it (ignored on iOS).
|
|
4914
5751
|
* @param profile - The Android build profile; the store profile when omitted.
|
|
5752
|
+
* @param privacyManifest - `ios.privacyManifest`, an absolute path; unset removes one a
|
|
5753
|
+
* previous pass added (ignored on Android).
|
|
4915
5754
|
* @returns The paths patched vs. left unchanged, one merged report over every patch.
|
|
4916
5755
|
* @throws {Error} When the Android `gen/android` tree (or its `app/build.gradle.kts`) is
|
|
4917
5756
|
* missing, the debug keystore is missing in the debug profile (before anything is
|
|
4918
|
-
* written), manifest entries meet a missing manifest or an unclear main activity,
|
|
4919
|
-
* background colour meets a tree without exactly one MainActivity.kt to style
|
|
5757
|
+
* written), manifest entries meet a missing manifest or an unclear main activity, a
|
|
5758
|
+
* background colour meets a tree without exactly one MainActivity.kt to style or without
|
|
5759
|
+
* the app theme to set the window background in; or when the iOS privacy manifest source
|
|
5760
|
+
* is missing (before anything is written), or `project.yml` or `project.pbxproj` lacks a
|
|
5761
|
+
* line a patch needs.
|
|
4920
5762
|
*/
|
|
4921
|
-
async function patchMobile(projectDirectory, opts, signing, manifest = [], backgroundColor, profile = STORE_PROFILE) {
|
|
5763
|
+
async function patchMobile(projectDirectory, opts, signing, manifest = [], backgroundColor, profile = STORE_PROFILE, privacyManifest) {
|
|
4922
5764
|
const genDirectory = genDirectoryPath(projectDirectory, opts.target);
|
|
4923
|
-
if (opts.target === "ios") return patchIos(
|
|
5765
|
+
if (opts.target === "ios") return patchIos({
|
|
5766
|
+
projectDirectory,
|
|
5767
|
+
genDirectory,
|
|
5768
|
+
runner: opts.runner,
|
|
5769
|
+
minimumVersion: signing.apple?.iosMinimumSystemVersion ?? "15.0",
|
|
5770
|
+
privacyManifest
|
|
5771
|
+
});
|
|
4924
5772
|
return patchAndroid({
|
|
4925
5773
|
projectDirectory,
|
|
4926
5774
|
genDirectory,
|
|
@@ -5469,7 +6317,8 @@ function createProjectApi(ctx) {
|
|
|
5469
6317
|
const input = {
|
|
5470
6318
|
global: ctx.global,
|
|
5471
6319
|
target: opts.target,
|
|
5472
|
-
capabilities
|
|
6320
|
+
capabilities,
|
|
6321
|
+
profile
|
|
5473
6322
|
};
|
|
5474
6323
|
const artifacts = [
|
|
5475
6324
|
...generateTauriConf(input),
|
|
@@ -5533,7 +6382,8 @@ function createProjectApi(ctx) {
|
|
|
5533
6382
|
};
|
|
5534
6383
|
/**
|
|
5535
6384
|
* Implements {@link Api.patchMobile}: hands Android its build profile, its manifest
|
|
5536
|
-
* entries and `app.backgroundColor` (the status bar icons
|
|
6385
|
+
* entries and `app.backgroundColor` (the status bar icons and the window background
|
|
6386
|
+
* follow it), hands iOS `ios.privacyManifest`, then logs.
|
|
5537
6387
|
*
|
|
5538
6388
|
* @param opts - See {@link Api.patchMobile}.
|
|
5539
6389
|
* @returns See {@link Api.patchMobile}.
|
|
@@ -5541,7 +6391,7 @@ function createProjectApi(ctx) {
|
|
|
5541
6391
|
const runPatchMobile = async (opts) => {
|
|
5542
6392
|
const manifest = opts.target === "android" ? androidManifestEntries(ctx.global) : [];
|
|
5543
6393
|
const profile = androidProfile(opts);
|
|
5544
|
-
const result = await patchMobile(ctx.global.projectDir, opts, ctx.global.signing, manifest, ctx.global.app.backgroundColor, profile);
|
|
6394
|
+
const result = await patchMobile(ctx.global.projectDir, opts, ctx.global.signing, manifest, ctx.global.app.backgroundColor, profile, ctx.global.ios?.privacyManifest);
|
|
5545
6395
|
ctx.log.info("project:patchMobile", {
|
|
5546
6396
|
target: opts.target,
|
|
5547
6397
|
profile: profile.profile,
|
|
@@ -5673,6 +6523,12 @@ function createProjectApi(ctx) {
|
|
|
5673
6523
|
}
|
|
5674
6524
|
//#endregion
|
|
5675
6525
|
//#region src/plugins/project/validate.ts
|
|
6526
|
+
/**
|
|
6527
|
+
* @file project plugin — composition-time validation of the global config. Runs in the
|
|
6528
|
+
* plugin's `onInit`, so a misconfigured app fails at `createApp` with a `[native]` fix-it
|
|
6529
|
+
* instead of deep inside `tauri build`.
|
|
6530
|
+
*/
|
|
6531
|
+
/** Reverse-DNS app identifier: at least two dot-separated labels. */
|
|
5676
6532
|
const IDENTIFIER_PATTERN = /^[a-z][a-z0-9-]*(\.[a-z][a-z0-9-]*)+$/i;
|
|
5677
6533
|
/** `MAJOR.MINOR.PATCH` with an optional pre-release/build suffix — lands raw in Cargo TOML. */
|
|
5678
6534
|
const VERSION_PATTERN = /^\d+\.\d+\.\d+(?:[-+][\w.]+)?$/;
|
|
@@ -5686,6 +6542,8 @@ const ENV_VAR_NAME_PATTERN = /^[a-z_][a-z\d_]*$/i;
|
|
|
5686
6542
|
const HEX_COLOUR_PATTERN = /^#[0-9a-f]{6}([0-9a-f]{2})?$/i;
|
|
5687
6543
|
/** The three `Orientation` values — plain-JS config can carry anything else. */
|
|
5688
6544
|
const ORIENTATION_PATTERN = /^(?:portrait|landscape|any)$/;
|
|
6545
|
+
/** `MAJOR.MINOR[.PATCH]` — lands raw in `project.yml` and `project.pbxproj`. */
|
|
6546
|
+
const IOS_VERSION_PATTERN = /^\d+\.\d+(?:\.\d+)?$/;
|
|
5689
6547
|
/**
|
|
5690
6548
|
* Validates one free-text config value that is interpolated verbatim into a generated
|
|
5691
6549
|
* file. Every generated format (TOML, Kotlin, plist, XML) has its own escape rules, so a
|
|
@@ -5764,6 +6622,56 @@ function assertIconInset(inset) {
|
|
|
5764
6622
|
throw new Error(`[native] app.adaptiveIconInset must be a number above 0 and at most ${MAX_ICON_INSET}, got ${String(inset)}.\n Use the percent per side the art needs, such as 19.44, or unset it to leave the icon untouched.`);
|
|
5765
6623
|
}
|
|
5766
6624
|
/**
|
|
6625
|
+
* Tells a plain object from everything else `typeof` calls an object: `null`, a `Date`, a
|
|
6626
|
+
* class instance. Only a plain object renders as a `<dict>` with its entries in it.
|
|
6627
|
+
*
|
|
6628
|
+
* @param value - The configured value.
|
|
6629
|
+
* @returns True, narrowing `value`, when it is a plain object.
|
|
6630
|
+
* @example
|
|
6631
|
+
* ```ts
|
|
6632
|
+
* isPlainObject({ a: 1 }); // true
|
|
6633
|
+
* isPlainObject(new Date(0)); // false
|
|
6634
|
+
* ```
|
|
6635
|
+
*/
|
|
6636
|
+
function isPlainObject(value) {
|
|
6637
|
+
return value instanceof Object && Object.getPrototypeOf(value) === Object.prototype;
|
|
6638
|
+
}
|
|
6639
|
+
/**
|
|
6640
|
+
* Validates one `ios.infoPlist` value and everything below it. Config arrives as plain JS
|
|
6641
|
+
* too, and anything but a string, a boolean, an array or a plain object would render as an
|
|
6642
|
+
* empty `<dict>`, so the `PlistValue` type is not trusted.
|
|
6643
|
+
*
|
|
6644
|
+
* @param field - The dotted config path of the value, used verbatim in the error.
|
|
6645
|
+
* @param value - The configured value.
|
|
6646
|
+
* @throws {Error} When the value, or one nested in it, is not a plist value.
|
|
6647
|
+
* @example
|
|
6648
|
+
* ```ts
|
|
6649
|
+
* assertPlistValue("ios.infoPlist.Build", 7); // throws: [native] ios.infoPlist.Build is not a plist value.
|
|
6650
|
+
* ```
|
|
6651
|
+
*/
|
|
6652
|
+
function assertPlistValue(field, value) {
|
|
6653
|
+
if (typeof value === "string" || typeof value === "boolean") return;
|
|
6654
|
+
if (!Array.isArray(value) && !isPlainObject(value)) throw new Error(`[native] ${field} is not a plist value.\n Use a string, a boolean, an array or a plain object.`);
|
|
6655
|
+
for (const [key, child] of Object.entries(value)) assertPlistValue(`${field}.${key}`, child);
|
|
6656
|
+
}
|
|
6657
|
+
/**
|
|
6658
|
+
* Validates `ios`: the privacy manifest must be an absolute path, because the patch pass
|
|
6659
|
+
* runs from whichever cwd started the build, and every `infoPlist` value must be a plist
|
|
6660
|
+
* value.
|
|
6661
|
+
*
|
|
6662
|
+
* @param ios - The configured `ios` block, or undefined when unset.
|
|
6663
|
+
* @throws {Error} When the manifest path is relative or a plist value is invalid.
|
|
6664
|
+
* @example
|
|
6665
|
+
* ```ts
|
|
6666
|
+
* assertIosConfig({ privacyManifest: "PrivacyInfo.xcprivacy" }); // throws: [native] ios.privacyManifest "PrivacyInfo.xcprivacy" must be an absolute path.
|
|
6667
|
+
* ```
|
|
6668
|
+
*/
|
|
6669
|
+
function assertIosConfig(ios) {
|
|
6670
|
+
const privacyManifest = ios?.privacyManifest;
|
|
6671
|
+
if (privacyManifest !== void 0 && !node_path.default.isAbsolute(privacyManifest)) throw new Error(`[native] ios.privacyManifest "${privacyManifest}" must be an absolute path.\n Resolve it first, such as with path.resolve("PrivacyInfo.xcprivacy").`);
|
|
6672
|
+
for (const [key, value] of Object.entries(ios?.infoPlist ?? {})) assertPlistValue(`ios.infoPlist.${key}`, value);
|
|
6673
|
+
}
|
|
6674
|
+
/**
|
|
5767
6675
|
* Validates the app identity and web wiring: `app.name`, a reverse-DNS `app.identifier`,
|
|
5768
6676
|
* and every `web.*` field. Each lands verbatim in tauri.conf.json, where a missing value
|
|
5769
6677
|
* fails deep inside `tauri build` instead of at `createApp`.
|
|
@@ -5797,13 +6705,13 @@ function assertDeepLinkScheme(global) {
|
|
|
5797
6705
|
* Validates the global config at composition time — throws `[native]`-formatted errors
|
|
5798
6706
|
* for missing app identity, missing web wiring, values that would break out of the
|
|
5799
6707
|
* generated file they are written into, a window colour, orientation or adaptive icon
|
|
5800
|
-
* inset outside its allowed shape,
|
|
5801
|
-
*
|
|
5802
|
-
* scheme.
|
|
6708
|
+
* inset outside its allowed shape, an `ios` block a build could not use, a `projectDir`
|
|
6709
|
+
* outside the project, an `outDir` this app must not deliver into, unknown `config.system`
|
|
6710
|
+
* names, or a `deep-link` composition missing its scheme.
|
|
5803
6711
|
*
|
|
5804
6712
|
* @param global - Frozen global framework config.
|
|
5805
|
-
* @throws {Error} When identity, web wiring, interpolated values, presentation fields,
|
|
5806
|
-
* derived directories, system names, or deep-link config are invalid.
|
|
6713
|
+
* @throws {Error} When identity, web wiring, interpolated values, presentation fields, the
|
|
6714
|
+
* `ios` block, derived directories, system names, or deep-link config are invalid.
|
|
5807
6715
|
*/
|
|
5808
6716
|
function validateProjectConfig(global) {
|
|
5809
6717
|
assertIdentity(global);
|
|
@@ -5814,6 +6722,8 @@ function validateProjectConfig(global) {
|
|
|
5814
6722
|
assertIconInset(global.app.adaptiveIconInset);
|
|
5815
6723
|
assertShape("signing.android.keystorePasswordEnv", global.signing.android?.keystorePasswordEnv, ENV_VAR_NAME_PATTERN, "environment variable name", "Reference the password by variable NAME, such as \"ANDROID_KEYSTORE_PASSWORD\" — never the password itself.");
|
|
5816
6724
|
assertShape("signing.android.keyPasswordEnv", global.signing.android?.keyPasswordEnv, ENV_VAR_NAME_PATTERN, "environment variable name", "Reference the password by variable NAME, such as \"ANDROID_KEY_PASSWORD\" — never the password itself.");
|
|
6725
|
+
assertShape("signing.apple.iosMinimumSystemVersion", global.signing.apple?.iosMinimumSystemVersion, IOS_VERSION_PATTERN, "iOS version", "Use a version such as \"16.0\".");
|
|
6726
|
+
assertIosConfig(global.ios);
|
|
5817
6727
|
assertDerivedDirectory(global.projectDir);
|
|
5818
6728
|
assertDeliveryDirectory(global.outDir);
|
|
5819
6729
|
assertKnownCapabilities(global.system);
|
|
@@ -5825,8 +6735,9 @@ function validateProjectConfig(global) {
|
|
|
5825
6735
|
* Complex tier — capability registry + generators/ (the `tauri-plugin-moku-shell` crate
|
|
5826
6736
|
* among them) + write-if-changed writer + the mobile/ sub-domain (completeness gate, build
|
|
5827
6737
|
* profile patches, Android signing block, Android manifest attributes, adaptive icon inset,
|
|
5828
|
-
* shell link check, Xcode settings,
|
|
5829
|
-
* lock + the page agent scan + the
|
|
6738
|
+
* shell link check, Xcode settings, iOS deployment target and privacy manifest,
|
|
6739
|
+
* runner-command rewrite) + the build-time orientation lock + the page agent scan + the
|
|
6740
|
+
* guarded clean.
|
|
5830
6741
|
*
|
|
5831
6742
|
* @see README.md
|
|
5832
6743
|
* @example
|
|
@@ -8834,6 +9745,12 @@ const rustupCheck = {
|
|
|
8834
9745
|
//#endregion
|
|
8835
9746
|
//#region src/plugins/doctor/checks/signing.ts
|
|
8836
9747
|
/**
|
|
9748
|
+
* @file doctor plugin check — signing readiness for ios/macos/android: env-var PRESENCE only
|
|
9749
|
+
* (never values) plus, for Apple, a count-only keychain identity probe and, for Android,
|
|
9750
|
+
* whether the keystore file exists. Warn-only posture: unsigned and simulator builds are
|
|
9751
|
+
* legal, so this check never fails.
|
|
9752
|
+
*/
|
|
9753
|
+
/**
|
|
8837
9754
|
* The two Apple credential sets Tauri accepts — either one, complete, is enough.
|
|
8838
9755
|
* Presence only: a value is never read, so nothing here can reach a message.
|
|
8839
9756
|
*/
|
|
@@ -8852,9 +9769,21 @@ const APPLE_CREDENTIAL_SETS = [{
|
|
|
8852
9769
|
"APPLE_API_KEY_PATH"
|
|
8853
9770
|
]
|
|
8854
9771
|
}];
|
|
9772
|
+
/** The scopes that carry a signing identifier or env ref. */
|
|
9773
|
+
const SIGNING_TARGETS = /* @__PURE__ */ new Set([
|
|
9774
|
+
"ios",
|
|
9775
|
+
"macos",
|
|
9776
|
+
"android",
|
|
9777
|
+
"windows"
|
|
9778
|
+
]);
|
|
8855
9779
|
/** Every signing message repeats this — doctor never fails a build over signing. */
|
|
8856
9780
|
const LEGAL_NOTE = "unsigned and simulator builds are legal";
|
|
8857
9781
|
/**
|
|
9782
|
+
* The Gradle module that holds the signing config, relative to `projectDir`. Gradle's
|
|
9783
|
+
* `file()` in `app/build.gradle.kts` resolves a relative `storeFile` from this directory.
|
|
9784
|
+
*/
|
|
9785
|
+
const GRADLE_APP_DIRECTORY = "src-tauri/gen/android/app";
|
|
9786
|
+
/**
|
|
8858
9787
|
* Whether the local keychain is worth probing: only when a concrete `signingIdentity` is
|
|
8859
9788
|
* configured (not the ad-hoc `"-"`) and CI has not brought its own certificate.
|
|
8860
9789
|
*
|
|
@@ -8934,12 +9863,27 @@ async function checkAppleSigning(input) {
|
|
|
8934
9863
|
};
|
|
8935
9864
|
}
|
|
8936
9865
|
/**
|
|
8937
|
-
*
|
|
9866
|
+
* Looks up the configured `signing.android.keystorePath` where Gradle will read it: an
|
|
9867
|
+
* absolute path as it stands, a relative one under {@link GRADLE_APP_DIRECTORY}.
|
|
9868
|
+
*
|
|
9869
|
+
* @param input - The check input (looks through its fs facade).
|
|
9870
|
+
* @returns The path that is missing, or `undefined` when none is configured or the file exists.
|
|
9871
|
+
*/
|
|
9872
|
+
async function missingKeystore(input) {
|
|
9873
|
+
const configured = input.global.signing.android?.keystorePath;
|
|
9874
|
+
if (!configured) return void 0;
|
|
9875
|
+
const keystore = node_path.default.isAbsolute(configured) ? configured : node_path.default.join(input.global.projectDir, GRADLE_APP_DIRECTORY, configured);
|
|
9876
|
+
return await input.fs.exists(keystore) ? void 0 : keystore;
|
|
9877
|
+
}
|
|
9878
|
+
/**
|
|
9879
|
+
* Checks android signing: the `signing.android.keystorePasswordEnv` var, then the
|
|
9880
|
+
* `signing.android.keyPasswordEnv` var when one is configured (presence only), then the
|
|
9881
|
+
* `signing.android.keystorePath` file when one is configured. The first gap is the result.
|
|
8938
9882
|
*
|
|
8939
9883
|
* @param input - The check input, scoped to "android".
|
|
8940
9884
|
* @returns The check result — "pass" or "warn", never "fail".
|
|
8941
9885
|
*/
|
|
8942
|
-
function checkAndroidSigning(input) {
|
|
9886
|
+
async function checkAndroidSigning(input) {
|
|
8943
9887
|
const envName = input.global.signing.android?.keystorePasswordEnv;
|
|
8944
9888
|
if (!envName) return {
|
|
8945
9889
|
id: "signing-android",
|
|
@@ -8955,6 +9899,22 @@ function checkAndroidSigning(input) {
|
|
|
8955
9899
|
message: `[native] android signing env var "${envName}" is not set.`,
|
|
8956
9900
|
fixIt: `export ${envName} before building a signed android release`
|
|
8957
9901
|
};
|
|
9902
|
+
const keyPasswordVariable = input.global.signing.android?.keyPasswordEnv;
|
|
9903
|
+
if (keyPasswordVariable && !input.env.has(keyPasswordVariable)) return {
|
|
9904
|
+
id: "signing-android",
|
|
9905
|
+
target: "android",
|
|
9906
|
+
status: "warn",
|
|
9907
|
+
message: `[native] android key password env var "${keyPasswordVariable}" is not set.`,
|
|
9908
|
+
fixIt: `export ${keyPasswordVariable} before building a signed android release`
|
|
9909
|
+
};
|
|
9910
|
+
const keystore = await missingKeystore(input);
|
|
9911
|
+
if (keystore !== void 0) return {
|
|
9912
|
+
id: "signing-android",
|
|
9913
|
+
target: "android",
|
|
9914
|
+
status: "warn",
|
|
9915
|
+
message: `[native] android keystore not found at ${keystore}.`,
|
|
9916
|
+
fixIt: `put the keystore at ${keystore}, or correct signing.android.keystorePath (a relative path resolves from ${GRADLE_APP_DIRECTORY})`
|
|
9917
|
+
};
|
|
8958
9918
|
return {
|
|
8959
9919
|
id: "signing-android",
|
|
8960
9920
|
target: "android",
|
|
@@ -9024,7 +9984,7 @@ const signingCheck = {
|
|
|
9024
9984
|
* signingCheck.appliesTo("android", global); // true
|
|
9025
9985
|
* ```
|
|
9026
9986
|
*/
|
|
9027
|
-
appliesTo: (target) => target
|
|
9987
|
+
appliesTo: (target) => SIGNING_TARGETS.has(target),
|
|
9028
9988
|
run: run$4
|
|
9029
9989
|
};
|
|
9030
9990
|
//#endregion
|
|
@@ -10253,7 +11213,7 @@ const cliPlugin = createPlugin$1("cli", {
|
|
|
10253
11213
|
*
|
|
10254
11214
|
* | Field | Type | Default |
|
|
10255
11215
|
* |---|---|---|
|
|
10256
|
-
* | `app` | `{ name; identifier; version?; icon?; category?; buildNumber?; orientation?; backgroundColor?; adaptiveIconInset? }` | `{ name: "", identifier: "" }` — both validated non-empty at composition; `orientation` (`"portrait" \| "landscape" \| "any"`) is a build-time mobile lock, `backgroundColor` a hex window colour, `adaptiveIconInset` the Android adaptive icon inset (percent per side, `0 < n ≤ 30`) |
|
|
11216
|
+
* | `app` | `{ name; identifier; version?; icon?; category?; buildNumber?; orientation?; backgroundColor?; adaptiveIconInset?; keepScreenOn? }` | `{ name: "", identifier: "" }` — both validated non-empty at composition; `buildNumber` is also the Android `versionCode` (a whole number from 1 to 2100000000, checked at generate, android only); `orientation` (`"portrait" \| "landscape" \| "any"`) is a build-time mobile lock, `backgroundColor` a hex window colour, `adaptiveIconInset` the Android adaptive icon inset (percent per side, `0 < n ≤ 30`), `keepScreenOn` turns the iOS idle timer off |
|
|
10257
11217
|
* | `web` | `{ build; devCommand; devUrl; dist; cwd? }` | `"bun run build"`, `"bun run dev"`, `"http://localhost:5173"`, `"dist"` |
|
|
10258
11218
|
* | `system` | `ReadonlyArray<{ name: string }>` | `[]` — the composed `@moku-labs/system` plugins |
|
|
10259
11219
|
* | `capabilities` | `Partial<CapabilityConfigMap>` | `{}` — keys: `store`, `notification`, `clipboard-manager`, `tray`, `deep-link`, `back`, `haptics`, `shell` |
|
|
@@ -10261,6 +11221,12 @@ const cliPlugin = createPlugin$1("cli", {
|
|
|
10261
11221
|
* | `projectDir` | `string` | `".moku/tauri"` — generated Tauri project (gitignored build output) |
|
|
10262
11222
|
* | `outDir` | `string` | `"dist-native"` — installer delivery root |
|
|
10263
11223
|
* | `signing` | `SigningConfig` | `{}` — identifiers and env-var NAMES only, never secrets; the generated iOS minimum falls back to `"15.0"` |
|
|
11224
|
+
* | `ios` | `{ infoPlist?; privacyManifest? }` | unset — `infoPlist` merges into `Info.plist` (`app.orientation` wins a shared key); `privacyManifest` is the absolute path of the bundle's `PrivacyInfo.xcprivacy`, and unset removes one an earlier build left |
|
|
11225
|
+
*
|
|
11226
|
+
* Every generated `Cargo.toml` carries a size `[profile.release]`, and a store build sets
|
|
11227
|
+
* `build.removeUnusedCommands` in `tauri.conf.json`. Each iOS patch pass keeps the deployment
|
|
11228
|
+
* target and the privacy manifest in both `project.yml` and `project.pbxproj`, because a kept
|
|
11229
|
+
* tree never runs xcodegen again.
|
|
10264
11230
|
*
|
|
10265
11231
|
* Per-plugin config (`pluginConfigs`) — each plugin's own defaults, all seams `undefined`
|
|
10266
11232
|
* so the real implementation runs unless a test injects one:
|