@moku-labs/native 0.3.12 → 0.3.14
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 +50 -13
- package/dist/index.cjs +365 -66
- package/dist/index.d.cts +126 -37
- package/dist/index.d.mts +126 -37
- package/dist/index.mjs +366 -67
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { envPlugin, logPlugin, workerSafeProcessEnv } from "@moku-labs/common";
|
|
|
3
3
|
import { createCoreConfig } from "@moku-labs/core";
|
|
4
4
|
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
5
5
|
import path from "node:path";
|
|
6
|
-
import { access, cp, glob, lstat, mkdir, readFile, readdir, realpath, rm, stat, writeFile } from "node:fs/promises";
|
|
6
|
+
import { access, cp, glob, lstat, mkdir, readFile, readdir, realpath, rename, rm, stat, writeFile } from "node:fs/promises";
|
|
7
7
|
import os from "node:os";
|
|
8
8
|
import process$1 from "node:process";
|
|
9
9
|
import { Buffer } from "node:buffer";
|
|
@@ -794,7 +794,8 @@ function generateCapabilities(input) {
|
|
|
794
794
|
//#region src/plugins/project/generators/cargo.ts
|
|
795
795
|
/**
|
|
796
796
|
* @file project plugin generator — Cargo.toml with registry-pinned crate dependencies, the
|
|
797
|
-
* path dependency of every generated local crate,
|
|
797
|
+
* path dependency of every generated local crate, the iOS debug `devtools` feature, and the
|
|
798
|
+
* size profile of a release build.
|
|
798
799
|
*/
|
|
799
800
|
/**
|
|
800
801
|
* The `tauri` crate floor. The `back` capability calls `exit()` and grants
|
|
@@ -809,7 +810,7 @@ const TAURI_VERSION_FLOOR = "2.12";
|
|
|
809
810
|
*/
|
|
810
811
|
const IOS_ONLY_DEPENDENCIES = [`[target.'cfg(target_os = "ios")'.dependencies]`, "objc2 = \"0.6\""];
|
|
811
812
|
/**
|
|
812
|
-
* The release profile, for every target and
|
|
813
|
+
* The release profile, for every target and every build profile: the debug build is a
|
|
813
814
|
* release build too, so what a phone measures is what the store ships. It trades compile
|
|
814
815
|
* time for a smaller library, and `panic = "abort"` drops the unwinding tables.
|
|
815
816
|
*/
|
|
@@ -822,6 +823,12 @@ const RELEASE_PROFILE = [
|
|
|
822
823
|
"strip = true"
|
|
823
824
|
];
|
|
824
825
|
/**
|
|
826
|
+
* The `tauri` feature an iOS debug build adds. The debug build is a release build, and a
|
|
827
|
+
* release build compiles the inspector only with it: the window's `devtools` flag alone does
|
|
828
|
+
* nothing there.
|
|
829
|
+
*/
|
|
830
|
+
const IOS_DEBUG_FEATURE = "devtools";
|
|
831
|
+
/**
|
|
825
832
|
* Derives a valid Cargo package name from the app's display name — lowercased,
|
|
826
833
|
* non-alphanumeric runs collapsed to a single hyphen, and guaranteed to start with a
|
|
827
834
|
* letter (Cargo package names must match `[a-z][a-z0-9_-]*`).
|
|
@@ -878,9 +885,9 @@ function dependencyLine(capability) {
|
|
|
878
885
|
* every cargo feature the composed capabilities ask for (tray's `tray-icon`; without it
|
|
879
886
|
* the tray API is not compiled in at all), plus one dependency line per resolved
|
|
880
887
|
* capability that ships a crate: pinned for a published one, by path for the generated
|
|
881
|
-
* shell crate. Feature-only and permission-only rows contribute no dependency line.
|
|
882
|
-
* `[profile.release]` table follows, and
|
|
883
|
-
* every target.
|
|
888
|
+
* shell crate. Feature-only and permission-only rows contribute no dependency line. An iOS
|
|
889
|
+
* debug build adds `devtools` to those features. The `[profile.release]` table follows, and
|
|
890
|
+
* the iOS-only `objc2` table closes the file on every target.
|
|
884
891
|
*
|
|
885
892
|
* @param input - Frozen global config + capabilities resolved for the target.
|
|
886
893
|
* @returns A single-artifact array for `src-tauri/Cargo.toml`.
|
|
@@ -888,7 +895,9 @@ function dependencyLine(capability) {
|
|
|
888
895
|
function generateCargo(input) {
|
|
889
896
|
const packageName = sanitizePackageName(input.global.app.name);
|
|
890
897
|
const pinnedDeps = input.capabilities.map((capability) => dependencyLine(capability)).filter((line) => line !== void 0).toSorted();
|
|
891
|
-
const
|
|
898
|
+
const iosDebug = input.target === "ios" && input.profile === "debug";
|
|
899
|
+
const requested = input.capabilities.flatMap((capability) => capability.cargoFeatures);
|
|
900
|
+
const features = [.../* @__PURE__ */ new Set([...requested, ...iosDebug ? [IOS_DEBUG_FEATURE] : []])].toSorted().map((feature) => `"${feature}"`).join(", ");
|
|
892
901
|
return [{
|
|
893
902
|
path: "src-tauri/Cargo.toml",
|
|
894
903
|
content: [
|
|
@@ -1676,7 +1685,7 @@ class MokuShellPlugin(private val activity: Activity) : Plugin(activity) {
|
|
|
1676
1685
|
`;
|
|
1677
1686
|
/**
|
|
1678
1687
|
* Renders `MokuShellProfile.kt`: the one per-profile file of the module. The debug profile
|
|
1679
|
-
* turns on WebView debugging and `share`; the store
|
|
1688
|
+
* turns on WebView debugging and `share`; the store and dev profiles turn both off.
|
|
1680
1689
|
*
|
|
1681
1690
|
* @param profile - The build profile the crate is generated for.
|
|
1682
1691
|
* @returns The Kotlin source.
|
|
@@ -1919,8 +1928,8 @@ const CONTRACT_BODY = String.raw` var MAX_SHARE_BYTES = 32 * 1024 * 1024;
|
|
|
1919
1928
|
}, noop);`;
|
|
1920
1929
|
/**
|
|
1921
1930
|
* Builds the page contract script for one app and profile. The build profile and id are
|
|
1922
|
-
* baked in at generate time: the store
|
|
1923
|
-
* `"<app.version>+<app.buildNumber ?? 0>"`, with `"-debug"` in the debug profile. A second
|
|
1931
|
+
* baked in at generate time: the store and dev profiles read `"release"` on the page, and the
|
|
1932
|
+
* id is `"<app.version>+<app.buildNumber ?? 0>"`, with `"-debug"` in the debug profile. A second
|
|
1924
1933
|
* run of the script in the same frame is a no-op.
|
|
1925
1934
|
*
|
|
1926
1935
|
* @param input - The generator input (target, app version and build number).
|
|
@@ -2100,11 +2109,14 @@ function escapeXml(text) {
|
|
|
2100
2109
|
}
|
|
2101
2110
|
//#endregion
|
|
2102
2111
|
//#region src/plugins/project/generators/sidecar.ts
|
|
2103
|
-
/**
|
|
2104
|
-
* @file project plugin generator — Info.ios.plist sidecar (src-tauri root, outside gen/).
|
|
2105
|
-
*/
|
|
2106
2112
|
/** One indentation step of the generated plist. */
|
|
2107
2113
|
const PLIST_INDENT = " ";
|
|
2114
|
+
/** The key of the sentence iOS shows when it asks to reach the local network. */
|
|
2115
|
+
const LOCAL_NETWORK_USAGE_KEY = "NSLocalNetworkUsageDescription";
|
|
2116
|
+
/** The key of App Transport Security, which refuses `ws://` to the editor by default. */
|
|
2117
|
+
const APP_TRANSPORT_SECURITY_KEY = "NSAppTransportSecurity";
|
|
2118
|
+
/** The sentence iOS shows when an iOS debug build first reaches for the editor. */
|
|
2119
|
+
const LOCAL_NETWORK_USAGE = "This debug build talks to the editor on your local network.";
|
|
2108
2120
|
/**
|
|
2109
2121
|
* Tells a plist `<array>` from a `<dict>`: `Array.isArray` alone does not narrow a readonly
|
|
2110
2122
|
* array.
|
|
@@ -2164,11 +2176,35 @@ function renderPlistValue(value, indent) {
|
|
|
2164
2176
|
];
|
|
2165
2177
|
}
|
|
2166
2178
|
/**
|
|
2179
|
+
* Lists what the debug profile needs to reach the editor from an iPhone: the local-network
|
|
2180
|
+
* sentence, and App Transport Security opened for the local network alone. Every other
|
|
2181
|
+
* profile adds nothing, and the iOS patch pass takes both keys out of a kept tree again
|
|
2182
|
+
* (`mobile/ios-plist.ts`).
|
|
2183
|
+
*
|
|
2184
|
+
* @param profile - The build profile being generated for.
|
|
2185
|
+
* @returns The two entries in the debug profile, otherwise none.
|
|
2186
|
+
* @example
|
|
2187
|
+
* ```ts
|
|
2188
|
+
* debugPlist("store"); // []
|
|
2189
|
+
* ```
|
|
2190
|
+
*/
|
|
2191
|
+
function debugPlist(profile) {
|
|
2192
|
+
if (profile !== "debug") return [];
|
|
2193
|
+
return [{
|
|
2194
|
+
key: LOCAL_NETWORK_USAGE_KEY,
|
|
2195
|
+
value: LOCAL_NETWORK_USAGE
|
|
2196
|
+
}, {
|
|
2197
|
+
key: APP_TRANSPORT_SECURITY_KEY,
|
|
2198
|
+
value: { NSAllowsLocalNetworking: true }
|
|
2199
|
+
}];
|
|
2200
|
+
}
|
|
2201
|
+
/**
|
|
2167
2202
|
* Generates the `Info.ios.plist` SIDECAR at the src-tauri root, which Tauri merges into the
|
|
2168
2203
|
* app's Info.plist on every iOS build. Its entries are every resolved capability's
|
|
2169
|
-
* `sidecarPlist`, then `ios.infoPlist`, then the
|
|
2170
|
-
* duplicate key the later entry wins, so the app's keys beat a
|
|
2171
|
-
* beats
|
|
2204
|
+
* `sidecarPlist`, then `ios.infoPlist`, then the debug profile's two keys, then the orientation
|
|
2205
|
+
* lock (`app.orientation`); on a duplicate key the later entry wins, so the app's keys beat a
|
|
2206
|
+
* capability, the debug keys beat a game's own in that profile only, and orientation beats
|
|
2207
|
+
* them all.
|
|
2172
2208
|
*
|
|
2173
2209
|
* On iOS the file is ALWAYS written, as an empty `<dict>` when nothing contributes a key:
|
|
2174
2210
|
* the writer never deletes a file, and a portrait lock left in a stale sidecar would keep
|
|
@@ -2194,6 +2230,7 @@ function generateSidecar(input) {
|
|
|
2194
2230
|
key,
|
|
2195
2231
|
value
|
|
2196
2232
|
})),
|
|
2233
|
+
...debugPlist(input.profile),
|
|
2197
2234
|
...orientationPlist(input.global.app.orientation)
|
|
2198
2235
|
];
|
|
2199
2236
|
for (const entry of contributed) entries.set(entry.key, entry.value);
|
|
@@ -2214,8 +2251,9 @@ function generateSidecar(input) {
|
|
|
2214
2251
|
//#endregion
|
|
2215
2252
|
//#region src/plugins/project/generators/tauri-conf.ts
|
|
2216
2253
|
/**
|
|
2217
|
-
* @file project plugin generator — tauri.conf.json (identity, build wiring,
|
|
2218
|
-
* metadata, Apple signing, the Android
|
|
2254
|
+
* @file project plugin generator — tauri.conf.json (identity, build wiring, the main
|
|
2255
|
+
* window with its iOS debug inspector, bundle metadata, Apple signing, the Android
|
|
2256
|
+
* versionCode, plugin blocks).
|
|
2219
2257
|
*/
|
|
2220
2258
|
/**
|
|
2221
2259
|
* The icon set `tauri icon` writes into `src-tauri/icons`. Tauri reads `bundle.icon` at
|
|
@@ -2350,9 +2388,11 @@ function buildPlugins(capabilities) {
|
|
|
2350
2388
|
}
|
|
2351
2389
|
/**
|
|
2352
2390
|
* Generates `src-tauri/tauri.conf.json` — app identity, the web build/dev wiring, with
|
|
2353
|
-
* `removeUnusedCommands` in the store profile only (a debug page may call what a
|
|
2354
|
-
* page does not), the main window (its title, plus `app.backgroundColor` when set
|
|
2355
|
-
*
|
|
2391
|
+
* `removeUnusedCommands` in the store profile only (a debug or dev page may call what a
|
|
2392
|
+
* store page does not), the main window (its title, plus `app.backgroundColor` when set, and
|
|
2393
|
+
* `devtools` in an iOS debug build, so Safari Web Inspector can attach: the debug build is a
|
|
2394
|
+
* release build, where Tauri closes the inspector), the bundle/signing metadata, and a
|
|
2395
|
+
* `plugins.<name>` block per CONFIGURED capability (see
|
|
2356
2396
|
* {@link buildPlugins}; this is where deep-link's scheme rides — per D-011/D-012 the whole
|
|
2357
2397
|
* v1 mobile-permission story is conf-only). Both path-shaped fields are rebased onto
|
|
2358
2398
|
* `src-tauri`, which is where Tauri resolves them from, and the before-commands carry an
|
|
@@ -2370,6 +2410,7 @@ function buildPlugins(capabilities) {
|
|
|
2370
2410
|
function generateTauriConf(input) {
|
|
2371
2411
|
const { global, capabilities } = input;
|
|
2372
2412
|
const webRoot = path.resolve(global.web.cwd ?? ".");
|
|
2413
|
+
const inspectable = input.target === "ios" && input.profile === "debug";
|
|
2373
2414
|
const conf = {
|
|
2374
2415
|
productName: global.app.name,
|
|
2375
2416
|
identifier: global.app.identifier,
|
|
@@ -2389,7 +2430,8 @@ function generateTauriConf(input) {
|
|
|
2389
2430
|
},
|
|
2390
2431
|
app: { windows: [{
|
|
2391
2432
|
title: global.app.name,
|
|
2392
|
-
...compact([["backgroundColor", global.app.backgroundColor]])
|
|
2433
|
+
...compact([["backgroundColor", global.app.backgroundColor]]),
|
|
2434
|
+
...inspectable ? { devtools: true } : {}
|
|
2393
2435
|
}] },
|
|
2394
2436
|
bundle: buildBundle(input),
|
|
2395
2437
|
plugins: buildPlugins(capabilities)
|
|
@@ -2698,9 +2740,9 @@ async function writeIfChanged(filePath, content, projectDirectory) {
|
|
|
2698
2740
|
* the iOS project patches) reads the same list from here, so none can drift into a file the
|
|
2699
2741
|
* others do not know about — and none ever descends into `gen/apple/build` or
|
|
2700
2742
|
* `gen/android/build`, which belong to the toolchain. The privacy manifest's place in the
|
|
2701
|
-
* tree is here too. The Android status bar patch finds its
|
|
2702
|
-
* patches their `strings.xml` and network security config,
|
|
2703
|
-
* icon directory.
|
|
2743
|
+
* tree is here too, and so is the app's `Info.plist`. The Android status bar patch finds its
|
|
2744
|
+
* MainActivity.kt here, the profile patches their `strings.xml` and network security config,
|
|
2745
|
+
* and the icon inset its adaptive icon directory.
|
|
2704
2746
|
*/
|
|
2705
2747
|
/** Source extensions that can carry the Android runner command. */
|
|
2706
2748
|
const ANDROID_SOURCE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
@@ -2732,6 +2774,10 @@ const SKIPPED_DIRECTORIES = /* @__PURE__ */ new Set([
|
|
|
2732
2774
|
]);
|
|
2733
2775
|
/** The file name Apple reads a privacy manifest from, at the top of the app bundle. */
|
|
2734
2776
|
const IOS_PRIVACY_MANIFEST_FILE = "PrivacyInfo.xcprivacy";
|
|
2777
|
+
/** How the directory of the app's own files ends in `gen/apple`: `<slug>_iOS`. */
|
|
2778
|
+
const IOS_APP_DIRECTORY_SUFFIX = "_iOS";
|
|
2779
|
+
/** The file name of the app's property list, in that directory. */
|
|
2780
|
+
const IOS_INFO_PLIST_FILE = "Info.plist";
|
|
2735
2781
|
/**
|
|
2736
2782
|
* Lists the generated iOS files a patch pass may rewrite: `project.yml` plus the
|
|
2737
2783
|
* `project.pbxproj` of every generated Xcode project. `gen/apple/build` is never listed —
|
|
@@ -2756,6 +2802,22 @@ async function iosPatchFiles(genDirectory) {
|
|
|
2756
2802
|
return files;
|
|
2757
2803
|
}
|
|
2758
2804
|
/**
|
|
2805
|
+
* Lists the `Info.plist` of the generated iOS app, the file `tauri ios build` merges the
|
|
2806
|
+
* sidecar into: in the `gen/apple` directory that ends in `_iOS`. A tree where tauri has not
|
|
2807
|
+
* written it yet lists nothing.
|
|
2808
|
+
*
|
|
2809
|
+
* @param genDirectory - The `src-tauri/gen/apple` directory.
|
|
2810
|
+
* @returns The existing files, possibly none.
|
|
2811
|
+
* @example
|
|
2812
|
+
* ```ts
|
|
2813
|
+
* await iosInfoPlistFiles("/repo/.moku/tauri/src-tauri/gen/apple");
|
|
2814
|
+
* // ["/repo/.moku/tauri/src-tauri/gen/apple/my-game_iOS/Info.plist"]
|
|
2815
|
+
* ```
|
|
2816
|
+
*/
|
|
2817
|
+
async function iosInfoPlistFiles(genDirectory) {
|
|
2818
|
+
return (await readdir(genDirectory, { withFileTypes: true })).filter((entry) => entry.isDirectory() && entry.name.endsWith(IOS_APP_DIRECTORY_SUFFIX)).map((entry) => path.join(genDirectory, entry.name, IOS_INFO_PLIST_FILE)).filter((file) => existsSync(file));
|
|
2819
|
+
}
|
|
2820
|
+
/**
|
|
2759
2821
|
* Returns where the iOS patch pass keeps the privacy manifest: the top of `gen/apple`, the
|
|
2760
2822
|
* directory `project.yml` and the pbxproj's root group resolve a relative path from.
|
|
2761
2823
|
*
|
|
@@ -2959,6 +3021,90 @@ async function patchAndroidIcon(options) {
|
|
|
2959
3021
|
};
|
|
2960
3022
|
}
|
|
2961
3023
|
//#endregion
|
|
3024
|
+
//#region src/plugins/project/mobile/identity.ts
|
|
3025
|
+
/**
|
|
3026
|
+
* @file project plugin — the app id a `gen/android` tree was initialised for, and setting a
|
|
3027
|
+
* tree aside when that id is not the configured one. `tauri android init` bakes the id into
|
|
3028
|
+
* the namespace, the `applicationId` and the Kotlin package path; a kept tree never runs
|
|
3029
|
+
* init again, so a changed `app.identifier` would otherwise build against the old package.
|
|
3030
|
+
*/
|
|
3031
|
+
/** The key of the `applicationId = "<id>"` line; the debug suffix is a separate line. */
|
|
3032
|
+
const APPLICATION_ID_KEY = "applicationId";
|
|
3033
|
+
/**
|
|
3034
|
+
* Reads the `applicationId` a `gen/android` tree was initialised for. Only a quoted literal
|
|
3035
|
+
* is recognised, the form `tauri android init` writes; an expression reads as no id.
|
|
3036
|
+
*
|
|
3037
|
+
* @param genDirectory - The absolute `src-tauri/gen/android` directory.
|
|
3038
|
+
* @returns The id, or undefined when `app/build.gradle.kts` is absent or names no literal id.
|
|
3039
|
+
* @example
|
|
3040
|
+
* ```ts
|
|
3041
|
+
* readAndroidApplicationId("/repo/.moku/tauri/src-tauri/gen/android"); // "com.acme.demo"
|
|
3042
|
+
* ```
|
|
3043
|
+
*/
|
|
3044
|
+
function readAndroidApplicationId(genDirectory) {
|
|
3045
|
+
const gradlePath = path.join(genDirectory, "app", "build.gradle.kts");
|
|
3046
|
+
if (!existsSync(gradlePath)) return void 0;
|
|
3047
|
+
for (const line of readFileSync(gradlePath, "utf8").split("\n")) {
|
|
3048
|
+
const [key, value] = line.split("=", 2).map((part) => part.trim());
|
|
3049
|
+
if (key === APPLICATION_ID_KEY && value?.startsWith("\"")) return value.split("\"")[1];
|
|
3050
|
+
}
|
|
3051
|
+
}
|
|
3052
|
+
/**
|
|
3053
|
+
* Compares two Android ids the way Tauri writes them: a `-` may come out as `_`.
|
|
3054
|
+
*
|
|
3055
|
+
* @param left - One id.
|
|
3056
|
+
* @param right - The other id.
|
|
3057
|
+
* @returns Whether both name the same app.
|
|
3058
|
+
*/
|
|
3059
|
+
function sameAndroidId(left, right) {
|
|
3060
|
+
return left.replaceAll("-", "_") === right.replaceAll("-", "_");
|
|
3061
|
+
}
|
|
3062
|
+
/**
|
|
3063
|
+
* Picks the first free `<genDirectory>.old-<id>` path, then `-2`, `-3`, … so an earlier
|
|
3064
|
+
* set-aside tree is never overwritten.
|
|
3065
|
+
*
|
|
3066
|
+
* @param genDirectory - The tree being set aside.
|
|
3067
|
+
* @param found - The id it was initialised for.
|
|
3068
|
+
* @returns A path that does not exist yet.
|
|
3069
|
+
*/
|
|
3070
|
+
function freeAsidePath(genDirectory, found) {
|
|
3071
|
+
const base = `${genDirectory}.old-${found}`;
|
|
3072
|
+
let candidate = base;
|
|
3073
|
+
let n = 1;
|
|
3074
|
+
while (existsSync(candidate)) {
|
|
3075
|
+
n += 1;
|
|
3076
|
+
candidate = `${base}-${n}`;
|
|
3077
|
+
}
|
|
3078
|
+
return candidate;
|
|
3079
|
+
}
|
|
3080
|
+
/**
|
|
3081
|
+
* Moves a `gen/android` tree aside when it was initialised for another app id, so the next
|
|
3082
|
+
* `tauri android init` writes a fresh one. The tree is renamed, never deleted: it may hold a
|
|
3083
|
+
* keystore or hand edits. A tree whose id cannot be read is left to the completeness gate.
|
|
3084
|
+
*
|
|
3085
|
+
* @param options - The check options.
|
|
3086
|
+
* @param options.genDirectory - The absolute `src-tauri/gen/android` directory.
|
|
3087
|
+
* @param options.identifier - The configured `app.identifier`.
|
|
3088
|
+
* @returns What was found and where it went, or undefined when the tree was kept.
|
|
3089
|
+
* @example
|
|
3090
|
+
* ```ts
|
|
3091
|
+
* await setAsideStaleAndroidTree({ genDirectory, identifier: "studio.kitto.memorymissing" });
|
|
3092
|
+
* // { found: "com.mokulabs.memorymissing", expected: "studio.kitto.memorymissing",
|
|
3093
|
+
* // movedTo: ".../gen/android.old-com.mokulabs.memorymissing" }
|
|
3094
|
+
* ```
|
|
3095
|
+
*/
|
|
3096
|
+
async function setAsideStaleAndroidTree(options) {
|
|
3097
|
+
const found = readAndroidApplicationId(options.genDirectory);
|
|
3098
|
+
if (found === void 0 || sameAndroidId(found, options.identifier)) return void 0;
|
|
3099
|
+
const movedTo = freeAsidePath(options.genDirectory, found);
|
|
3100
|
+
await rename(options.genDirectory, movedTo);
|
|
3101
|
+
return {
|
|
3102
|
+
found,
|
|
3103
|
+
expected: options.identifier,
|
|
3104
|
+
movedTo
|
|
3105
|
+
};
|
|
3106
|
+
}
|
|
3107
|
+
//#endregion
|
|
2962
3108
|
//#region src/plugins/project/mobile/xcode-settings.ts
|
|
2963
3109
|
/**
|
|
2964
3110
|
* @file project plugin — the Xcode build-settings patch that makes an iOS REBUILD work.
|
|
@@ -3741,6 +3887,118 @@ async function patchPrivacyManifest(projectDirectory, genDirectory, manifest) {
|
|
|
3741
3887
|
};
|
|
3742
3888
|
}
|
|
3743
3889
|
//#endregion
|
|
3890
|
+
//#region src/plugins/project/mobile/ios-plist.ts
|
|
3891
|
+
/**
|
|
3892
|
+
* @file project plugin — the iOS `Info.plist` patch: takes the debug keys out of a kept tree.
|
|
3893
|
+
*
|
|
3894
|
+
* `tauri ios build` merges `Info.ios.plist` INTO `gen/apple/<slug>_iOS/Info.plist` for good
|
|
3895
|
+
* (measured with tauri-cli 2.11.4), so a key dropped from the sidecar stays in that file: a
|
|
3896
|
+
* store build of a tree that once built in debug would ship the loosened App Transport
|
|
3897
|
+
* Security. Outside the debug profile this pass removes both debug keys; the sidecar merge
|
|
3898
|
+
* after it restores whatever the game itself asked for.
|
|
3899
|
+
*
|
|
3900
|
+
* The transform is a pure text function over the shape the plist crate writes: line endings
|
|
3901
|
+
* and every neighbouring line survive byte for byte, and a file without the keys comes back
|
|
3902
|
+
* untouched. That crate escapes every value and writes no comment, so a `<` is always a tag.
|
|
3903
|
+
*/
|
|
3904
|
+
/** The keys only a debug build may carry, the ones `generators/sidecar.ts` adds there. */
|
|
3905
|
+
const DEBUG_KEYS = [LOCAL_NETWORK_USAGE_KEY, APP_TRANSPORT_SECURITY_KEY];
|
|
3906
|
+
/** Every element tag of a plist. Group 1 marks a closing tag, group 2 a self-closed one. */
|
|
3907
|
+
const TAG_PATTERN = /<(\/?)[a-z][^<>]*?(\/?)>/gi;
|
|
3908
|
+
/**
|
|
3909
|
+
* Finds where the plist value that starts after `from` ends, walking its depth: a `<dict>`
|
|
3910
|
+
* may hold more of them, and a `<dict/>` opens nothing.
|
|
3911
|
+
*
|
|
3912
|
+
* @param text - The file content.
|
|
3913
|
+
* @param from - The index right after the value's `<key>` element.
|
|
3914
|
+
* @returns The index after the value, or undefined when no value follows.
|
|
3915
|
+
* @example
|
|
3916
|
+
* ```ts
|
|
3917
|
+
* valueEnd("<key>K</key><dict><dict/></dict>", 12); // 32
|
|
3918
|
+
* ```
|
|
3919
|
+
*/
|
|
3920
|
+
function valueEnd(text, from) {
|
|
3921
|
+
let depth = 0;
|
|
3922
|
+
for (const match of text.slice(from).matchAll(TAG_PATTERN)) {
|
|
3923
|
+
const [tag, closing, selfClosed] = match;
|
|
3924
|
+
if (depth === 0 && tag === "<key>") return void 0;
|
|
3925
|
+
if (closing) depth -= 1;
|
|
3926
|
+
else if (!selfClosed) depth += 1;
|
|
3927
|
+
if (depth === 0) return from + match.index + tag.length;
|
|
3928
|
+
if (depth < 0) return void 0;
|
|
3929
|
+
}
|
|
3930
|
+
}
|
|
3931
|
+
/**
|
|
3932
|
+
* Cuts a range out of a text: the whole lines when the range is alone on them, so no blank
|
|
3933
|
+
* line stays behind and the file keeps its line endings, otherwise the range only.
|
|
3934
|
+
*
|
|
3935
|
+
* @param text - The file content.
|
|
3936
|
+
* @param start - The index of the range's first character.
|
|
3937
|
+
* @param end - The index after its last character.
|
|
3938
|
+
* @returns The text without the range.
|
|
3939
|
+
* @example
|
|
3940
|
+
* ```ts
|
|
3941
|
+
* cutRange("a\n\tb\nc\n", 3, 4); // "a\nc\n"
|
|
3942
|
+
* ```
|
|
3943
|
+
*/
|
|
3944
|
+
function cutRange(text, start, end) {
|
|
3945
|
+
const lineStart = text.lastIndexOf("\n", start) + 1;
|
|
3946
|
+
const lineBreak = text.indexOf("\n", end);
|
|
3947
|
+
const lineEnd = lineBreak === -1 ? text.length : lineBreak + 1;
|
|
3948
|
+
return text.slice(lineStart, start).trim() === "" && text.slice(end, lineEnd).trim() === "" ? text.slice(0, lineStart) + text.slice(lineEnd) : text.slice(0, start) + text.slice(end);
|
|
3949
|
+
}
|
|
3950
|
+
/**
|
|
3951
|
+
* Removes keys and their values from the text of an XML property list. A value is whatever
|
|
3952
|
+
* element follows the `<key>`, however deep it nests. Content without the keys comes back
|
|
3953
|
+
* byte-identical, so the writer leaves the file alone.
|
|
3954
|
+
*
|
|
3955
|
+
* @param existing - The current `Info.plist` content.
|
|
3956
|
+
* @param keys - The keys to remove.
|
|
3957
|
+
* @returns The content without those keys.
|
|
3958
|
+
* @throws {Error} `[native]` when a key has no value after it: the file is broken, and a store
|
|
3959
|
+
* build must not go on with the key still in it.
|
|
3960
|
+
* @example
|
|
3961
|
+
* ```ts
|
|
3962
|
+
* removePlistKeys("<dict>\n\t<key>A</key>\n\t<dict/>\n\t<key>B</key>\n\t<true/>\n</dict>\n", ["A"]);
|
|
3963
|
+
* // "<dict>\n\t<key>B</key>\n\t<true/>\n</dict>\n"
|
|
3964
|
+
* ```
|
|
3965
|
+
*/
|
|
3966
|
+
function removePlistKeys(existing, keys) {
|
|
3967
|
+
let text = existing;
|
|
3968
|
+
for (const key of keys) {
|
|
3969
|
+
const element = `<key>${key}</key>`;
|
|
3970
|
+
for (let start = text.indexOf(element); start !== -1; start = text.indexOf(element)) {
|
|
3971
|
+
const end = valueEnd(text, start + element.length);
|
|
3972
|
+
if (end === void 0) throw missingAnchorError(`the value of ${key}`, IOS_INFO_PLIST_FILE);
|
|
3973
|
+
text = cutRange(text, start, end);
|
|
3974
|
+
}
|
|
3975
|
+
}
|
|
3976
|
+
return text;
|
|
3977
|
+
}
|
|
3978
|
+
/**
|
|
3979
|
+
* Takes the debug keys out of the `Info.plist` of a kept iOS tree. Idempotent: a second pass
|
|
3980
|
+
* reports the file unchanged. A tree where tauri has not written the file reports nothing.
|
|
3981
|
+
*
|
|
3982
|
+
* @param projectDirectory - The Tauri project root.
|
|
3983
|
+
* @param genDirectory - The `src-tauri/gen/apple` directory.
|
|
3984
|
+
* @returns The paths patched vs. left unchanged.
|
|
3985
|
+
* @throws {Error} `[native]` when a debug key has no value after it.
|
|
3986
|
+
* @example
|
|
3987
|
+
* ```ts
|
|
3988
|
+
* await patchIosInfoPlist(projectDir, path.join(projectDir, "src-tauri/gen/apple"));
|
|
3989
|
+
* // { patched: [".../gen/apple/my-game_iOS/Info.plist"], unchanged: [] }
|
|
3990
|
+
* ```
|
|
3991
|
+
*/
|
|
3992
|
+
async function patchIosInfoPlist(projectDirectory, genDirectory) {
|
|
3993
|
+
const patched = [];
|
|
3994
|
+
const unchanged = [];
|
|
3995
|
+
for (const file of await iosInfoPlistFiles(genDirectory)) (await writeIfChanged(file, removePlistKeys(await readFile(file, "utf8"), DEBUG_KEYS), projectDirectory) === "written" ? patched : unchanged).push(file);
|
|
3996
|
+
return {
|
|
3997
|
+
patched,
|
|
3998
|
+
unchanged
|
|
3999
|
+
};
|
|
4000
|
+
}
|
|
4001
|
+
//#endregion
|
|
3744
4002
|
//#region src/plugins/project/mobile/manifest.ts
|
|
3745
4003
|
/**
|
|
3746
4004
|
* @file project plugin — the Android manifest patch. Tauri has no config key for what the
|
|
@@ -5598,8 +5856,9 @@ async function patchAndroidWindowBackground(projectDirectory, genDirectory, back
|
|
|
5598
5856
|
* the orientation lock), `system-bars.ts` (the Android status bar icon style from
|
|
5599
5857
|
* `app.backgroundColor`), `window-background.ts` (the Android window and icon-splash
|
|
5600
5858
|
* background from the same colour), `runner.ts` (the Xcode / Android-Studio runner command),
|
|
5601
|
-
* `xcode-settings.ts` (the iOS entitlements-modification setting that makes a REBUILD work)
|
|
5602
|
-
*
|
|
5859
|
+
* `xcode-settings.ts` (the iOS entitlements-modification setting that makes a REBUILD work),
|
|
5860
|
+
* `ios-project.ts` (the iOS deployment target and privacy manifest) and `ios-plist.ts` (the
|
|
5861
|
+
* debug keys a debug build left in the iOS `Info.plist`).
|
|
5603
5862
|
*/
|
|
5604
5863
|
/** The profile of a pass whose caller names none: the store profile, warnings dropped. */
|
|
5605
5864
|
const STORE_PROFILE = { profile: "store" };
|
|
@@ -5624,8 +5883,9 @@ function mergePatchResults(...results) {
|
|
|
5624
5883
|
}
|
|
5625
5884
|
/**
|
|
5626
5885
|
* The iOS half of {@link patchMobile}: the Xcode entitlements-modification setting, the
|
|
5627
|
-
* deployment target, the privacy manifest,
|
|
5628
|
-
*
|
|
5886
|
+
* deployment target, the privacy manifest, outside the debug profile the removal of the debug
|
|
5887
|
+
* `Info.plist` keys, then the runner command when the caller supplies a runner. A tree that
|
|
5888
|
+
* was never initialised is left alone and reports nothing.
|
|
5629
5889
|
*
|
|
5630
5890
|
* @param options - What to patch.
|
|
5631
5891
|
* @param options.projectDirectory - The Tauri project root.
|
|
@@ -5634,9 +5894,10 @@ function mergePatchResults(...results) {
|
|
|
5634
5894
|
* @param options.minimumVersion - The iOS deployment target to write.
|
|
5635
5895
|
* @param options.privacyManifest - `ios.privacyManifest`; unset removes one a previous pass
|
|
5636
5896
|
* added.
|
|
5897
|
+
* @param options.profile - The build profile of this pass.
|
|
5637
5898
|
* @returns The paths patched vs. left unchanged, merged over every patch.
|
|
5638
5899
|
* @throws {Error} When the privacy manifest source is missing (before anything is written),
|
|
5639
|
-
*
|
|
5900
|
+
* a project file lacks a line a patch needs, or a debug key in `Info.plist` has no value.
|
|
5640
5901
|
*/
|
|
5641
5902
|
async function patchIos(options) {
|
|
5642
5903
|
const { projectDirectory, genDirectory, runner } = options;
|
|
@@ -5650,6 +5911,7 @@ async function patchIos(options) {
|
|
|
5650
5911
|
await patchDeploymentTarget(projectDirectory, genDirectory, options.minimumVersion),
|
|
5651
5912
|
await patchPrivacyManifest(projectDirectory, genDirectory, manifest)
|
|
5652
5913
|
];
|
|
5914
|
+
if (options.profile !== "debug") iosResults.push(await patchIosInfoPlist(projectDirectory, genDirectory));
|
|
5653
5915
|
if (!runner) return mergePatchResults(...iosResults);
|
|
5654
5916
|
const runnerResult = await patchRunner(projectDirectory, genDirectory, {
|
|
5655
5917
|
target: "ios",
|
|
@@ -5708,20 +5970,23 @@ async function patchAndroid(options) {
|
|
|
5708
5970
|
* byte, wherever the signing block sits. iOS gets the Xcode
|
|
5709
5971
|
* entitlements-modification setting (without it the SECOND build of the same tree fails),
|
|
5710
5972
|
* the deployment target and the privacy manifest (a kept tree never runs xcodegen again, so
|
|
5711
|
-
* both land in `project.yml` AND `project.pbxproj`),
|
|
5712
|
-
*
|
|
5713
|
-
*
|
|
5714
|
-
*
|
|
5715
|
-
* page on its
|
|
5973
|
+
* both land in `project.yml` AND `project.pbxproj`), outside the debug profile the removal of
|
|
5974
|
+
* the debug keys a debug build merged into `Info.plist`, then the runner command. The runner
|
|
5975
|
+
* rewrite runs only when the caller supplies a `runner`. iOS takes no manifest entries and no
|
|
5976
|
+
* background colour: its orientation lock and signing travel through the generated
|
|
5977
|
+
* `Info.ios.plist` sidecar and tauri.conf.json, and its status bar adapts to the page on its
|
|
5978
|
+
* own. Its profile is `opts.profile`, because `profile` below reads store for iOS.
|
|
5716
5979
|
*
|
|
5717
5980
|
* @param projectDirectory - The Tauri project root.
|
|
5718
|
-
* @param opts - The mobile platform,
|
|
5981
|
+
* @param opts - The mobile platform, optionally the absolute Node/tauri.js runner pair, and
|
|
5982
|
+
* the build profile, which iOS reads here; the store profile when omitted.
|
|
5719
5983
|
* @param signing - The full signing config (`.android` on Android, the iOS minimum in
|
|
5720
5984
|
* `.apple` on iOS).
|
|
5721
5985
|
* @param manifest - Android manifest entries for the main activity (ignored on iOS).
|
|
5722
5986
|
* @param backgroundColor - `app.backgroundColor`; the Android status bar icons, window
|
|
5723
5987
|
* background and icon-splash background follow it (ignored on iOS).
|
|
5724
|
-
* @param profile - The Android build profile; the store profile
|
|
5988
|
+
* @param profile - The Android build profile, `dev` included as store; the store profile
|
|
5989
|
+
* when omitted (ignored on iOS).
|
|
5725
5990
|
* @param privacyManifest - `ios.privacyManifest`, an absolute path; unset removes one a
|
|
5726
5991
|
* previous pass added (ignored on Android).
|
|
5727
5992
|
* @returns The paths patched vs. left unchanged, one merged report over every patch.
|
|
@@ -5730,8 +5995,8 @@ async function patchAndroid(options) {
|
|
|
5730
5995
|
* written), manifest entries meet a missing manifest or an unclear main activity, a
|
|
5731
5996
|
* background colour meets a tree without exactly one MainActivity.kt to style or without
|
|
5732
5997
|
* the app theme to set the window background in; or when the iOS privacy manifest source
|
|
5733
|
-
* is missing (before anything is written),
|
|
5734
|
-
*
|
|
5998
|
+
* is missing (before anything is written), `project.yml` or `project.pbxproj` lacks a line
|
|
5999
|
+
* a patch needs, or a debug key in `Info.plist` has no value.
|
|
5735
6000
|
*/
|
|
5736
6001
|
async function patchMobile(projectDirectory, opts, signing, manifest = [], backgroundColor, profile = STORE_PROFILE, privacyManifest) {
|
|
5737
6002
|
const genDirectory = genDirectoryPath(projectDirectory, opts.target);
|
|
@@ -5740,7 +6005,8 @@ async function patchMobile(projectDirectory, opts, signing, manifest = [], backg
|
|
|
5740
6005
|
genDirectory,
|
|
5741
6006
|
runner: opts.runner,
|
|
5742
6007
|
minimumVersion: signing.apple?.iosMinimumSystemVersion ?? "15.0",
|
|
5743
|
-
privacyManifest
|
|
6008
|
+
privacyManifest,
|
|
6009
|
+
profile: opts.profile ?? "store"
|
|
5744
6010
|
});
|
|
5745
6011
|
return patchAndroid({
|
|
5746
6012
|
projectDirectory,
|
|
@@ -6334,9 +6600,27 @@ function createProjectApi(ctx) {
|
|
|
6334
6600
|
*/
|
|
6335
6601
|
const checkCompleteness = (opts) => completeness(ctx.global.projectDir, opts.target);
|
|
6336
6602
|
/**
|
|
6603
|
+
* Implements {@link Api.setAsideStaleTree}: Android only, one plain warn line when a tree
|
|
6604
|
+
* was moved.
|
|
6605
|
+
*
|
|
6606
|
+
* @param opts - See {@link Api.setAsideStaleTree}.
|
|
6607
|
+
* @param opts.target - The mobile platform whose tree to check.
|
|
6608
|
+
* @returns See {@link Api.setAsideStaleTree}.
|
|
6609
|
+
*/
|
|
6610
|
+
const runSetAsideStaleTree = async (opts) => {
|
|
6611
|
+
if (opts.target !== "android") return void 0;
|
|
6612
|
+
const aside = await setAsideStaleAndroidTree({
|
|
6613
|
+
genDirectory: genDirectoryPath(ctx.global.projectDir, opts.target),
|
|
6614
|
+
identifier: ctx.global.app.identifier
|
|
6615
|
+
});
|
|
6616
|
+
if (aside !== void 0) ctx.log.warn(`gen/android was made for ${aside.found}, not ${aside.expected}: moved it to ${path.basename(aside.movedTo)} and generating it again`);
|
|
6617
|
+
return aside;
|
|
6618
|
+
};
|
|
6619
|
+
/**
|
|
6337
6620
|
* Builds the Android profile one patch pass applies. The debug profile resolves the debug
|
|
6338
6621
|
* keystore from `ctx.env` here (`HOME` ?? `USERPROFILE`), so the patch itself never reads
|
|
6339
|
-
* the environment.
|
|
6622
|
+
* the environment. Every other case applies as store: the `dev` profile, and iOS, which reads
|
|
6623
|
+
* `opts.profile` itself.
|
|
6340
6624
|
*
|
|
6341
6625
|
* @param opts - See {@link Api.patchMobile}.
|
|
6342
6626
|
* @returns The Android profile with its app name, keystore and log.
|
|
@@ -6356,7 +6640,7 @@ function createProjectApi(ctx) {
|
|
|
6356
6640
|
/**
|
|
6357
6641
|
* Implements {@link Api.patchMobile}: hands Android its build profile, its manifest
|
|
6358
6642
|
* entries and `app.backgroundColor` (the status bar icons and the window background
|
|
6359
|
-
* follow it), hands iOS `ios.privacyManifest`, then logs.
|
|
6643
|
+
* follow it), hands iOS `ios.privacyManifest` and its profile through `opts`, then logs.
|
|
6360
6644
|
*
|
|
6361
6645
|
* @param opts - See {@link Api.patchMobile}.
|
|
6362
6646
|
* @returns See {@link Api.patchMobile}.
|
|
@@ -6367,7 +6651,7 @@ function createProjectApi(ctx) {
|
|
|
6367
6651
|
const result = await patchMobile(ctx.global.projectDir, opts, ctx.global.signing, manifest, ctx.global.app.backgroundColor, profile, ctx.global.ios?.privacyManifest);
|
|
6368
6652
|
ctx.log.info("project:patchMobile", {
|
|
6369
6653
|
target: opts.target,
|
|
6370
|
-
profile:
|
|
6654
|
+
profile: opts.profile ?? "store",
|
|
6371
6655
|
patched: result.patched.length
|
|
6372
6656
|
});
|
|
6373
6657
|
return result;
|
|
@@ -6479,6 +6763,7 @@ function createProjectApi(ctx) {
|
|
|
6479
6763
|
generate: generateArtifacts,
|
|
6480
6764
|
getBundleLayout,
|
|
6481
6765
|
getCompleteness: checkCompleteness,
|
|
6766
|
+
setAsideStaleTree: runSetAsideStaleTree,
|
|
6482
6767
|
patchMobile: runPatchMobile,
|
|
6483
6768
|
patchMobileIcons: runPatchMobileIcons,
|
|
6484
6769
|
detectPageAgent: runDetectPageAgent,
|
|
@@ -8155,18 +8440,22 @@ const tauriPlugin = createPlugin$1("tauri", {
|
|
|
8155
8440
|
//#endregion
|
|
8156
8441
|
//#region src/plugins/build/phase.ts
|
|
8157
8442
|
/**
|
|
8158
|
-
* Picks the profile a build flavour asks for: `debug` set means the debug profile,
|
|
8159
|
-
* anything else the store one.
|
|
8443
|
+
* Picks the profile a build flavour asks for: `debug` set means the debug profile, `dev` set
|
|
8444
|
+
* the dev one, anything else the store one. Both set name no profile and are refused here,
|
|
8445
|
+
* so every caller reads the refusal before its first phase.
|
|
8160
8446
|
*
|
|
8161
8447
|
* @param flavor - The build flavour of the run.
|
|
8162
|
-
* @returns `"debug"` or `"store"`.
|
|
8448
|
+
* @returns `"debug"`, `"dev"` or `"store"`.
|
|
8449
|
+
* @throws {TypeError} `[native] debug and dev cannot be combined.` when both are set.
|
|
8163
8450
|
* @example
|
|
8164
8451
|
* ```ts
|
|
8165
|
-
* profileOf({
|
|
8452
|
+
* profileOf({ dev: true }); // "dev"
|
|
8166
8453
|
* ```
|
|
8167
8454
|
*/
|
|
8168
8455
|
function profileOf(flavor) {
|
|
8169
|
-
|
|
8456
|
+
if (flavor.debug === true && flavor.dev === true) throw new TypeError("[native] debug and dev cannot be combined.\n Build one profile: debug for the local app, dev for the store-signed test app.");
|
|
8457
|
+
if (flavor.debug === true) return "debug";
|
|
8458
|
+
return flavor.dev === true ? "dev" : "store";
|
|
8170
8459
|
}
|
|
8171
8460
|
/**
|
|
8172
8461
|
* Emits one `native:phase` event, omitting `durationMs`/`detail` when absent rather than
|
|
@@ -8231,7 +8520,7 @@ function bundleRoot(projectDirectory, layout) {
|
|
|
8231
8520
|
return path.join(projectDirectory, layout.root);
|
|
8232
8521
|
}
|
|
8233
8522
|
/**
|
|
8234
|
-
* Names a build's delivery directory under `outDir`: the target for a store build,
|
|
8523
|
+
* Names a build's delivery directory under `outDir`: the target for a store or dev build,
|
|
8235
8524
|
* `<target>-debug` for a debug one — so a debug installer never overwrites the store one.
|
|
8236
8525
|
*
|
|
8237
8526
|
* @param target - The packaging target being collected.
|
|
@@ -8463,8 +8752,9 @@ function storeAgentRefusal(dist, file) {
|
|
|
8463
8752
|
/**
|
|
8464
8753
|
* The checks at the end of compile/bundle, before anything is collected: on android the
|
|
8465
8754
|
* shell link (the project plugin decides whether the profile composes the shell), then the
|
|
8466
|
-
* page — a store build whose page carries the editor agent is refused
|
|
8467
|
-
* full compile because tauri runs the web build inside
|
|
8755
|
+
* page — a store build whose page carries the editor agent is refused; a debug or dev build
|
|
8756
|
+
* may carry it. They run after the full compile because tauri runs the web build inside
|
|
8757
|
+
* `tauri build`.
|
|
8468
8758
|
*
|
|
8469
8759
|
* @param ctx - The build pipeline's domain context.
|
|
8470
8760
|
* @param deps - The resolved project/tauri APIs.
|
|
@@ -8800,23 +9090,24 @@ function incompleteMobileTreeError(target, missing) {
|
|
|
8800
9090
|
return /* @__PURE__ */ new Error(`[native] ${target} project tree is incomplete.\n Missing ${missing.join(", ")} — run \`native doctor\` to diagnose, or \`native clean --target ${target}\` to reset before rebuilding.`);
|
|
8801
9091
|
}
|
|
8802
9092
|
/**
|
|
8803
|
-
* Refuses the debug profile for every target but android (Decision D2
|
|
8804
|
-
* runs, and for ALL the targets of a run at once, so nothing
|
|
9093
|
+
* Refuses the debug profile for every target but android and ios (Decision D2, widened to
|
|
9094
|
+
* iOS by F133) — before any phase runs, and for ALL the targets of a run at once, so nothing
|
|
9095
|
+
* is half-built.
|
|
8805
9096
|
*
|
|
8806
9097
|
* @param targets - Every target the run will build.
|
|
8807
9098
|
* @param flavor - The build flavour of the run.
|
|
8808
|
-
* @throws {Error} `[native] --debug builds Android only for now (asked for <target>).`
|
|
8809
|
-
* the first target that is
|
|
9099
|
+
* @throws {Error} `[native] --debug builds Android and iOS only for now (asked for <target>).`
|
|
9100
|
+
* for the first target that is neither, when `debug` is set.
|
|
8810
9101
|
* @example
|
|
8811
9102
|
* ```ts
|
|
8812
|
-
* assertDebugTargets(["android", "
|
|
9103
|
+
* assertDebugTargets(["android", "macos"], { debug: true }); // throws: asked for macos
|
|
8813
9104
|
* ```
|
|
8814
9105
|
*/
|
|
8815
9106
|
function assertDebugTargets(targets, flavor) {
|
|
8816
9107
|
if (flavor.debug !== true) return;
|
|
8817
|
-
const refused = targets.find((target) => target
|
|
9108
|
+
const refused = targets.find((target) => !isMobileTarget(target));
|
|
8818
9109
|
if (refused === void 0) return;
|
|
8819
|
-
throw new Error(`[native] --debug builds Android only for now (asked for ${refused}).\n Build the debug profile for android, or drop debug to build ${refused}.`);
|
|
9110
|
+
throw new Error(`[native] --debug builds Android and iOS only for now (asked for ${refused}).\n Build the debug profile for android or ios, or drop debug to build ${refused}.`);
|
|
8820
9111
|
}
|
|
8821
9112
|
/**
|
|
8822
9113
|
* Runs the `scaffold` phase: ensures `projectDir` exists. Nothing else — the mobile
|
|
@@ -8831,7 +9122,8 @@ async function runScaffold(ctx) {
|
|
|
8831
9122
|
}
|
|
8832
9123
|
/**
|
|
8833
9124
|
* Runs the `codegen` phase — `project.generate()` first (mobile init needs the generated
|
|
8834
|
-
* `tauri.conf.json`), then for a mobile target:
|
|
9125
|
+
* `tauri.conf.json`), then for a mobile target: a tree initialised for another app id is
|
|
9126
|
+
* set aside (`project.setAsideStaleTree()`), `tauri.mobileInit()` when the `gen/` tree
|
|
8835
9127
|
* is absent, the completeness gate (a partial tree fails fast, never silently
|
|
8836
9128
|
* re-initialized), and the idempotent `project.patchMobile()` pass carrying
|
|
8837
9129
|
* `tauri.getRunner()` — Tauri's own generated build phase calls a `node tauri` command
|
|
@@ -8850,6 +9142,7 @@ async function runCodegen(ctx, deps, target, profile = "store") {
|
|
|
8850
9142
|
profile
|
|
8851
9143
|
});
|
|
8852
9144
|
if (!isMobileTarget(target)) return { mobileInitRan: false };
|
|
9145
|
+
await deps.project.setAsideStaleTree({ target });
|
|
8853
9146
|
let status = deps.project.getCompleteness({ target });
|
|
8854
9147
|
let mobileInitRan = false;
|
|
8855
9148
|
if (status.status === "not-initialized") {
|
|
@@ -8945,19 +9238,20 @@ async function runPrepare(ctx, deps, target, profile = "store") {
|
|
|
8945
9238
|
* Runs the full `scaffold → codegen → icons → compile → bundle → collect` pipeline for
|
|
8946
9239
|
* ONE target — sequential phases, each timed and reported via `native:phase`, stopping at
|
|
8947
9240
|
* the first failing phase. Emits `native:complete` on success, with the run's profile. A
|
|
8948
|
-
* debug run on any target but android
|
|
9241
|
+
* debug run on any target but android and ios, and a run asking for `debug` and `dev`
|
|
9242
|
+
* together, are refused before the first phase.
|
|
8949
9243
|
*
|
|
8950
9244
|
* @param ctx - The build pipeline's domain context.
|
|
8951
9245
|
* @param deps - The resolved project/tauri APIs.
|
|
8952
|
-
* @param opts - The target plus the platform build flags (`simulator`, `aab`, `debug`).
|
|
9246
|
+
* @param opts - The target plus the platform build flags (`simulator`, `aab`, `debug`, `dev`).
|
|
8953
9247
|
* @returns The completed pipeline's result, with all six phase timings and the profile.
|
|
8954
9248
|
* @throws {Error} Whatever the failing phase throws (already reported via native:phase), or
|
|
8955
|
-
* the debug-target refusal (before any phase event).
|
|
9249
|
+
* the debug-target or `debug` + `dev` refusal (before any phase event).
|
|
8956
9250
|
*/
|
|
8957
9251
|
async function runPipeline(ctx, deps, opts) {
|
|
8958
9252
|
const { target } = opts;
|
|
8959
|
-
assertDebugTargets([target], opts);
|
|
8960
9253
|
const profile = profileOf(opts);
|
|
9254
|
+
assertDebugTargets([target], opts);
|
|
8961
9255
|
const startedAt = performance.now();
|
|
8962
9256
|
const phases = [...await runPrepare(ctx, deps, target, profile)];
|
|
8963
9257
|
const { compileDurationMs, bundleDurationMs } = await runCompileAndBundle(ctx, deps, opts);
|
|
@@ -8972,6 +9266,7 @@ async function runPipeline(ctx, deps, opts) {
|
|
|
8972
9266
|
simulator: opts.simulator,
|
|
8973
9267
|
aab: opts.aab,
|
|
8974
9268
|
debug: opts.debug,
|
|
9269
|
+
dev: opts.dev,
|
|
8975
9270
|
resolvePath: deps.project.resolveDerivedPath
|
|
8976
9271
|
}));
|
|
8977
9272
|
phases.push({
|
|
@@ -9044,13 +9339,15 @@ function createBuildApi(ctx, deps) {
|
|
|
9044
9339
|
*/
|
|
9045
9340
|
async runAll(opts = {}) {
|
|
9046
9341
|
const targets = opts.targets ?? ctx.global.targets;
|
|
9342
|
+
profileOf(opts);
|
|
9047
9343
|
assertDebugTargets(targets, opts);
|
|
9048
9344
|
const results = [];
|
|
9049
9345
|
for (const target of targets) results.push(await runPipeline(ctx, deps, {
|
|
9050
9346
|
target,
|
|
9051
9347
|
simulator: opts.simulator,
|
|
9052
9348
|
aab: opts.aab,
|
|
9053
|
-
debug: opts.debug
|
|
9349
|
+
debug: opts.debug,
|
|
9350
|
+
dev: opts.dev
|
|
9054
9351
|
}));
|
|
9055
9352
|
return results;
|
|
9056
9353
|
}
|
|
@@ -10951,13 +11248,14 @@ function createCliApi(ctx, deps) {
|
|
|
10951
11248
|
* @returns See {@link Api.build}.
|
|
10952
11249
|
*/
|
|
10953
11250
|
async build(opts = {}) {
|
|
10954
|
-
const { simulator, aab, debug } = opts;
|
|
11251
|
+
const { simulator, aab, debug, dev } = opts;
|
|
10955
11252
|
try {
|
|
10956
11253
|
if (opts.all) {
|
|
10957
11254
|
await build.runAll({
|
|
10958
11255
|
simulator,
|
|
10959
11256
|
aab,
|
|
10960
|
-
debug
|
|
11257
|
+
debug,
|
|
11258
|
+
dev
|
|
10961
11259
|
});
|
|
10962
11260
|
return;
|
|
10963
11261
|
}
|
|
@@ -10965,7 +11263,8 @@ function createCliApi(ctx, deps) {
|
|
|
10965
11263
|
target: opts.target ?? hostTarget(),
|
|
10966
11264
|
simulator,
|
|
10967
11265
|
aab,
|
|
10968
|
-
debug
|
|
11266
|
+
debug,
|
|
11267
|
+
dev
|
|
10969
11268
|
});
|
|
10970
11269
|
} catch (error) {
|
|
10971
11270
|
renderBuildFailure(ui, error);
|