@moku-labs/native 0.3.13 → 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/dist/index.cjs +105 -1
- package/dist/index.d.cts +40 -2
- package/dist/index.d.mts +40 -2
- package/dist/index.mjs +106 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3048,6 +3048,90 @@ async function patchAndroidIcon(options) {
|
|
|
3048
3048
|
};
|
|
3049
3049
|
}
|
|
3050
3050
|
//#endregion
|
|
3051
|
+
//#region src/plugins/project/mobile/identity.ts
|
|
3052
|
+
/**
|
|
3053
|
+
* @file project plugin — the app id a `gen/android` tree was initialised for, and setting a
|
|
3054
|
+
* tree aside when that id is not the configured one. `tauri android init` bakes the id into
|
|
3055
|
+
* the namespace, the `applicationId` and the Kotlin package path; a kept tree never runs
|
|
3056
|
+
* init again, so a changed `app.identifier` would otherwise build against the old package.
|
|
3057
|
+
*/
|
|
3058
|
+
/** The key of the `applicationId = "<id>"` line; the debug suffix is a separate line. */
|
|
3059
|
+
const APPLICATION_ID_KEY = "applicationId";
|
|
3060
|
+
/**
|
|
3061
|
+
* Reads the `applicationId` a `gen/android` tree was initialised for. Only a quoted literal
|
|
3062
|
+
* is recognised, the form `tauri android init` writes; an expression reads as no id.
|
|
3063
|
+
*
|
|
3064
|
+
* @param genDirectory - The absolute `src-tauri/gen/android` directory.
|
|
3065
|
+
* @returns The id, or undefined when `app/build.gradle.kts` is absent or names no literal id.
|
|
3066
|
+
* @example
|
|
3067
|
+
* ```ts
|
|
3068
|
+
* readAndroidApplicationId("/repo/.moku/tauri/src-tauri/gen/android"); // "com.acme.demo"
|
|
3069
|
+
* ```
|
|
3070
|
+
*/
|
|
3071
|
+
function readAndroidApplicationId(genDirectory) {
|
|
3072
|
+
const gradlePath = node_path.default.join(genDirectory, "app", "build.gradle.kts");
|
|
3073
|
+
if (!(0, node_fs.existsSync)(gradlePath)) return void 0;
|
|
3074
|
+
for (const line of (0, node_fs.readFileSync)(gradlePath, "utf8").split("\n")) {
|
|
3075
|
+
const [key, value] = line.split("=", 2).map((part) => part.trim());
|
|
3076
|
+
if (key === APPLICATION_ID_KEY && value?.startsWith("\"")) return value.split("\"")[1];
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3079
|
+
/**
|
|
3080
|
+
* Compares two Android ids the way Tauri writes them: a `-` may come out as `_`.
|
|
3081
|
+
*
|
|
3082
|
+
* @param left - One id.
|
|
3083
|
+
* @param right - The other id.
|
|
3084
|
+
* @returns Whether both name the same app.
|
|
3085
|
+
*/
|
|
3086
|
+
function sameAndroidId(left, right) {
|
|
3087
|
+
return left.replaceAll("-", "_") === right.replaceAll("-", "_");
|
|
3088
|
+
}
|
|
3089
|
+
/**
|
|
3090
|
+
* Picks the first free `<genDirectory>.old-<id>` path, then `-2`, `-3`, … so an earlier
|
|
3091
|
+
* set-aside tree is never overwritten.
|
|
3092
|
+
*
|
|
3093
|
+
* @param genDirectory - The tree being set aside.
|
|
3094
|
+
* @param found - The id it was initialised for.
|
|
3095
|
+
* @returns A path that does not exist yet.
|
|
3096
|
+
*/
|
|
3097
|
+
function freeAsidePath(genDirectory, found) {
|
|
3098
|
+
const base = `${genDirectory}.old-${found}`;
|
|
3099
|
+
let candidate = base;
|
|
3100
|
+
let n = 1;
|
|
3101
|
+
while ((0, node_fs.existsSync)(candidate)) {
|
|
3102
|
+
n += 1;
|
|
3103
|
+
candidate = `${base}-${n}`;
|
|
3104
|
+
}
|
|
3105
|
+
return candidate;
|
|
3106
|
+
}
|
|
3107
|
+
/**
|
|
3108
|
+
* Moves a `gen/android` tree aside when it was initialised for another app id, so the next
|
|
3109
|
+
* `tauri android init` writes a fresh one. The tree is renamed, never deleted: it may hold a
|
|
3110
|
+
* keystore or hand edits. A tree whose id cannot be read is left to the completeness gate.
|
|
3111
|
+
*
|
|
3112
|
+
* @param options - The check options.
|
|
3113
|
+
* @param options.genDirectory - The absolute `src-tauri/gen/android` directory.
|
|
3114
|
+
* @param options.identifier - The configured `app.identifier`.
|
|
3115
|
+
* @returns What was found and where it went, or undefined when the tree was kept.
|
|
3116
|
+
* @example
|
|
3117
|
+
* ```ts
|
|
3118
|
+
* await setAsideStaleAndroidTree({ genDirectory, identifier: "studio.kitto.memorymissing" });
|
|
3119
|
+
* // { found: "com.mokulabs.memorymissing", expected: "studio.kitto.memorymissing",
|
|
3120
|
+
* // movedTo: ".../gen/android.old-com.mokulabs.memorymissing" }
|
|
3121
|
+
* ```
|
|
3122
|
+
*/
|
|
3123
|
+
async function setAsideStaleAndroidTree(options) {
|
|
3124
|
+
const found = readAndroidApplicationId(options.genDirectory);
|
|
3125
|
+
if (found === void 0 || sameAndroidId(found, options.identifier)) return void 0;
|
|
3126
|
+
const movedTo = freeAsidePath(options.genDirectory, found);
|
|
3127
|
+
await (0, node_fs_promises.rename)(options.genDirectory, movedTo);
|
|
3128
|
+
return {
|
|
3129
|
+
found,
|
|
3130
|
+
expected: options.identifier,
|
|
3131
|
+
movedTo
|
|
3132
|
+
};
|
|
3133
|
+
}
|
|
3134
|
+
//#endregion
|
|
3051
3135
|
//#region src/plugins/project/mobile/xcode-settings.ts
|
|
3052
3136
|
/**
|
|
3053
3137
|
* @file project plugin — the Xcode build-settings patch that makes an iOS REBUILD work.
|
|
@@ -6543,6 +6627,23 @@ function createProjectApi(ctx) {
|
|
|
6543
6627
|
*/
|
|
6544
6628
|
const checkCompleteness = (opts) => completeness(ctx.global.projectDir, opts.target);
|
|
6545
6629
|
/**
|
|
6630
|
+
* Implements {@link Api.setAsideStaleTree}: Android only, one plain warn line when a tree
|
|
6631
|
+
* was moved.
|
|
6632
|
+
*
|
|
6633
|
+
* @param opts - See {@link Api.setAsideStaleTree}.
|
|
6634
|
+
* @param opts.target - The mobile platform whose tree to check.
|
|
6635
|
+
* @returns See {@link Api.setAsideStaleTree}.
|
|
6636
|
+
*/
|
|
6637
|
+
const runSetAsideStaleTree = async (opts) => {
|
|
6638
|
+
if (opts.target !== "android") return void 0;
|
|
6639
|
+
const aside = await setAsideStaleAndroidTree({
|
|
6640
|
+
genDirectory: genDirectoryPath(ctx.global.projectDir, opts.target),
|
|
6641
|
+
identifier: ctx.global.app.identifier
|
|
6642
|
+
});
|
|
6643
|
+
if (aside !== void 0) ctx.log.warn(`gen/android was made for ${aside.found}, not ${aside.expected}: moved it to ${node_path.default.basename(aside.movedTo)} and generating it again`);
|
|
6644
|
+
return aside;
|
|
6645
|
+
};
|
|
6646
|
+
/**
|
|
6546
6647
|
* Builds the Android profile one patch pass applies. The debug profile resolves the debug
|
|
6547
6648
|
* keystore from `ctx.env` here (`HOME` ?? `USERPROFILE`), so the patch itself never reads
|
|
6548
6649
|
* the environment. Every other case applies as store: the `dev` profile, and iOS, which reads
|
|
@@ -6689,6 +6790,7 @@ function createProjectApi(ctx) {
|
|
|
6689
6790
|
generate: generateArtifacts,
|
|
6690
6791
|
getBundleLayout,
|
|
6691
6792
|
getCompleteness: checkCompleteness,
|
|
6793
|
+
setAsideStaleTree: runSetAsideStaleTree,
|
|
6692
6794
|
patchMobile: runPatchMobile,
|
|
6693
6795
|
patchMobileIcons: runPatchMobileIcons,
|
|
6694
6796
|
detectPageAgent: runDetectPageAgent,
|
|
@@ -9047,7 +9149,8 @@ async function runScaffold(ctx) {
|
|
|
9047
9149
|
}
|
|
9048
9150
|
/**
|
|
9049
9151
|
* Runs the `codegen` phase — `project.generate()` first (mobile init needs the generated
|
|
9050
|
-
* `tauri.conf.json`), then for a mobile target:
|
|
9152
|
+
* `tauri.conf.json`), then for a mobile target: a tree initialised for another app id is
|
|
9153
|
+
* set aside (`project.setAsideStaleTree()`), `tauri.mobileInit()` when the `gen/` tree
|
|
9051
9154
|
* is absent, the completeness gate (a partial tree fails fast, never silently
|
|
9052
9155
|
* re-initialized), and the idempotent `project.patchMobile()` pass carrying
|
|
9053
9156
|
* `tauri.getRunner()` — Tauri's own generated build phase calls a `node tauri` command
|
|
@@ -9066,6 +9169,7 @@ async function runCodegen(ctx, deps, target, profile = "store") {
|
|
|
9066
9169
|
profile
|
|
9067
9170
|
});
|
|
9068
9171
|
if (!isMobileTarget(target)) return { mobileInitRan: false };
|
|
9172
|
+
await deps.project.setAsideStaleTree({ target });
|
|
9069
9173
|
let status = deps.project.getCompleteness({ target });
|
|
9070
9174
|
let mobileInitRan = false;
|
|
9071
9175
|
if (status.status === "not-initialized") {
|
package/dist/index.d.cts
CHANGED
|
@@ -297,7 +297,7 @@ type BundleLayout = {
|
|
|
297
297
|
readonly genDirectory: string | undefined;
|
|
298
298
|
};
|
|
299
299
|
declare namespace types_d_exports$3 {
|
|
300
|
-
export { AndroidProfile, Api$4 as Api, CleanResult, CompletenessResult, DebugKeystore, DeepLinkConf, GenerateResult, ManifestEntry, PageAgentResult, PatchMobileOptions, PatchResult, PlistEntry, PlistValue, ProjectContext, RegistryRow, ResolvedCapability, TauriConfFragment };
|
|
300
|
+
export { AndroidProfile, Api$4 as Api, CleanResult, CompletenessResult, DebugKeystore, DeepLinkConf, GenerateResult, ManifestEntry, PageAgentResult, PatchMobileOptions, PatchResult, PlistEntry, PlistValue, ProjectContext, RegistryRow, ResolvedCapability, StaleTree, TauriConfFragment };
|
|
301
301
|
}
|
|
302
302
|
/**
|
|
303
303
|
* What one `generate` pass did to each artifact, as paths under `projectDir`: written
|
|
@@ -380,6 +380,23 @@ type PageAgentResult = {
|
|
|
380
380
|
type CleanResult = {
|
|
381
381
|
removed: readonly string[];
|
|
382
382
|
};
|
|
383
|
+
/**
|
|
384
|
+
* A mobile `gen/` tree set aside because it was initialised for another app id.
|
|
385
|
+
*
|
|
386
|
+
* @example
|
|
387
|
+
* ```ts
|
|
388
|
+
* const aside: StaleTree = {
|
|
389
|
+
* found: "com.mokulabs.memorymissing",
|
|
390
|
+
* expected: "studio.kitto.memorymissing",
|
|
391
|
+
* movedTo: "/repo/.moku/tauri/src-tauri/gen/android.old-com.mokulabs.memorymissing"
|
|
392
|
+
* };
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
type StaleTree = {
|
|
396
|
+
/** The id the tree was initialised for. */readonly found: string; /** The configured `app.identifier`. */
|
|
397
|
+
readonly expected: string; /** The absolute path the tree was renamed to. */
|
|
398
|
+
readonly movedTo: string;
|
|
399
|
+
};
|
|
383
400
|
/**
|
|
384
401
|
* The Android SDK debug keystore the debug profile signs with, and the shell command that
|
|
385
402
|
* creates it. `path` is undefined when the environment names no home directory.
|
|
@@ -556,6 +573,27 @@ type Api$4 = {
|
|
|
556
573
|
getCompleteness(opts: {
|
|
557
574
|
target: Target;
|
|
558
575
|
}): CompletenessResult;
|
|
576
|
+
/**
|
|
577
|
+
* Sets a `gen/android` tree aside when it was initialised for another app id than
|
|
578
|
+
* `app.identifier`: renames it to `gen/android.old-<old id>` (never deletes it, it may hold
|
|
579
|
+
* a keystore or hand edits) and logs one line, so the build's mobile init writes a fresh
|
|
580
|
+
* tree. The build plugin calls it before the completeness read. iOS, a missing tree and a
|
|
581
|
+
* tree whose id cannot be read get undefined.
|
|
582
|
+
*
|
|
583
|
+
* @param opts - The check options.
|
|
584
|
+
* @param opts.target - The mobile platform whose tree to check.
|
|
585
|
+
* @returns What was set aside, or undefined when the tree was kept.
|
|
586
|
+
* @example
|
|
587
|
+
* ```ts
|
|
588
|
+
* // app.identifier changed from com.mokulabs.memorymissing to studio.kitto.memorymissing.
|
|
589
|
+
* await app.project.setAsideStaleTree({ target: "android" });
|
|
590
|
+
* // { found: "com.mokulabs.memorymissing", expected: "studio.kitto.memorymissing",
|
|
591
|
+
* // movedTo: "/repo/.moku/tauri/src-tauri/gen/android.old-com.mokulabs.memorymissing" }
|
|
592
|
+
* ```
|
|
593
|
+
*/
|
|
594
|
+
setAsideStaleTree(opts: {
|
|
595
|
+
target: MobileTarget;
|
|
596
|
+
}): Promise<StaleTree | undefined>;
|
|
559
597
|
/**
|
|
560
598
|
* Runs the idempotent mobile post-init patch pass. Android gets its build-profile
|
|
561
599
|
* patches (debug: the `.debug` id suffix, the `"<name> (debug)"` label, a cleartext
|
|
@@ -1145,7 +1183,7 @@ type PathResolver = (target: string) => string;
|
|
|
1145
1183
|
* cross-plugin surface build depends on (D-007) is readable in one place.
|
|
1146
1184
|
*/
|
|
1147
1185
|
type BuildDeps = {
|
|
1148
|
-
readonly project: Pick<Api$4, "generate" | "getBundleLayout" | "getCompleteness" | "patchMobile" | "clearMobileBuildOutput" | "ensureIconSource" | "resolveDerivedPath" | "patchMobileIcons" | "detectPageAgent" | "checkShellLinked">;
|
|
1186
|
+
readonly project: Pick<Api$4, "generate" | "getBundleLayout" | "getCompleteness" | "setAsideStaleTree" | "patchMobile" | "clearMobileBuildOutput" | "ensureIconSource" | "resolveDerivedPath" | "patchMobileIcons" | "detectPageAgent" | "checkShellLinked">;
|
|
1149
1187
|
readonly tauri: Pick<Api$3, "build" | "mobileInit" | "icon" | "getRunner">;
|
|
1150
1188
|
};
|
|
1151
1189
|
/** Public API of the build plugin — the per-target pipeline orchestrator. */
|
package/dist/index.d.mts
CHANGED
|
@@ -298,7 +298,7 @@ type BundleLayout = {
|
|
|
298
298
|
readonly genDirectory: string | undefined;
|
|
299
299
|
};
|
|
300
300
|
declare namespace types_d_exports$3 {
|
|
301
|
-
export { AndroidProfile, Api$4 as Api, CleanResult, CompletenessResult, DebugKeystore, DeepLinkConf, GenerateResult, ManifestEntry, PageAgentResult, PatchMobileOptions, PatchResult, PlistEntry, PlistValue, ProjectContext, RegistryRow, ResolvedCapability, TauriConfFragment };
|
|
301
|
+
export { AndroidProfile, Api$4 as Api, CleanResult, CompletenessResult, DebugKeystore, DeepLinkConf, GenerateResult, ManifestEntry, PageAgentResult, PatchMobileOptions, PatchResult, PlistEntry, PlistValue, ProjectContext, RegistryRow, ResolvedCapability, StaleTree, TauriConfFragment };
|
|
302
302
|
}
|
|
303
303
|
/**
|
|
304
304
|
* What one `generate` pass did to each artifact, as paths under `projectDir`: written
|
|
@@ -381,6 +381,23 @@ type PageAgentResult = {
|
|
|
381
381
|
type CleanResult = {
|
|
382
382
|
removed: readonly string[];
|
|
383
383
|
};
|
|
384
|
+
/**
|
|
385
|
+
* A mobile `gen/` tree set aside because it was initialised for another app id.
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```ts
|
|
389
|
+
* const aside: StaleTree = {
|
|
390
|
+
* found: "com.mokulabs.memorymissing",
|
|
391
|
+
* expected: "studio.kitto.memorymissing",
|
|
392
|
+
* movedTo: "/repo/.moku/tauri/src-tauri/gen/android.old-com.mokulabs.memorymissing"
|
|
393
|
+
* };
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
type StaleTree = {
|
|
397
|
+
/** The id the tree was initialised for. */readonly found: string; /** The configured `app.identifier`. */
|
|
398
|
+
readonly expected: string; /** The absolute path the tree was renamed to. */
|
|
399
|
+
readonly movedTo: string;
|
|
400
|
+
};
|
|
384
401
|
/**
|
|
385
402
|
* The Android SDK debug keystore the debug profile signs with, and the shell command that
|
|
386
403
|
* creates it. `path` is undefined when the environment names no home directory.
|
|
@@ -557,6 +574,27 @@ type Api$4 = {
|
|
|
557
574
|
getCompleteness(opts: {
|
|
558
575
|
target: Target;
|
|
559
576
|
}): CompletenessResult;
|
|
577
|
+
/**
|
|
578
|
+
* Sets a `gen/android` tree aside when it was initialised for another app id than
|
|
579
|
+
* `app.identifier`: renames it to `gen/android.old-<old id>` (never deletes it, it may hold
|
|
580
|
+
* a keystore or hand edits) and logs one line, so the build's mobile init writes a fresh
|
|
581
|
+
* tree. The build plugin calls it before the completeness read. iOS, a missing tree and a
|
|
582
|
+
* tree whose id cannot be read get undefined.
|
|
583
|
+
*
|
|
584
|
+
* @param opts - The check options.
|
|
585
|
+
* @param opts.target - The mobile platform whose tree to check.
|
|
586
|
+
* @returns What was set aside, or undefined when the tree was kept.
|
|
587
|
+
* @example
|
|
588
|
+
* ```ts
|
|
589
|
+
* // app.identifier changed from com.mokulabs.memorymissing to studio.kitto.memorymissing.
|
|
590
|
+
* await app.project.setAsideStaleTree({ target: "android" });
|
|
591
|
+
* // { found: "com.mokulabs.memorymissing", expected: "studio.kitto.memorymissing",
|
|
592
|
+
* // movedTo: "/repo/.moku/tauri/src-tauri/gen/android.old-com.mokulabs.memorymissing" }
|
|
593
|
+
* ```
|
|
594
|
+
*/
|
|
595
|
+
setAsideStaleTree(opts: {
|
|
596
|
+
target: MobileTarget;
|
|
597
|
+
}): Promise<StaleTree | undefined>;
|
|
560
598
|
/**
|
|
561
599
|
* Runs the idempotent mobile post-init patch pass. Android gets its build-profile
|
|
562
600
|
* patches (debug: the `.debug` id suffix, the `"<name> (debug)"` label, a cleartext
|
|
@@ -1146,7 +1184,7 @@ type PathResolver = (target: string) => string;
|
|
|
1146
1184
|
* cross-plugin surface build depends on (D-007) is readable in one place.
|
|
1147
1185
|
*/
|
|
1148
1186
|
type BuildDeps = {
|
|
1149
|
-
readonly project: Pick<Api$4, "generate" | "getBundleLayout" | "getCompleteness" | "patchMobile" | "clearMobileBuildOutput" | "ensureIconSource" | "resolveDerivedPath" | "patchMobileIcons" | "detectPageAgent" | "checkShellLinked">;
|
|
1187
|
+
readonly project: Pick<Api$4, "generate" | "getBundleLayout" | "getCompleteness" | "setAsideStaleTree" | "patchMobile" | "clearMobileBuildOutput" | "ensureIconSource" | "resolveDerivedPath" | "patchMobileIcons" | "detectPageAgent" | "checkShellLinked">;
|
|
1150
1188
|
readonly tauri: Pick<Api$3, "build" | "mobileInit" | "icon" | "getRunner">;
|
|
1151
1189
|
};
|
|
1152
1190
|
/** Public API of the build plugin — the per-target pipeline orchestrator. */
|
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";
|
|
@@ -3021,6 +3021,90 @@ async function patchAndroidIcon(options) {
|
|
|
3021
3021
|
};
|
|
3022
3022
|
}
|
|
3023
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
|
|
3024
3108
|
//#region src/plugins/project/mobile/xcode-settings.ts
|
|
3025
3109
|
/**
|
|
3026
3110
|
* @file project plugin — the Xcode build-settings patch that makes an iOS REBUILD work.
|
|
@@ -6516,6 +6600,23 @@ function createProjectApi(ctx) {
|
|
|
6516
6600
|
*/
|
|
6517
6601
|
const checkCompleteness = (opts) => completeness(ctx.global.projectDir, opts.target);
|
|
6518
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
|
+
/**
|
|
6519
6620
|
* Builds the Android profile one patch pass applies. The debug profile resolves the debug
|
|
6520
6621
|
* keystore from `ctx.env` here (`HOME` ?? `USERPROFILE`), so the patch itself never reads
|
|
6521
6622
|
* the environment. Every other case applies as store: the `dev` profile, and iOS, which reads
|
|
@@ -6662,6 +6763,7 @@ function createProjectApi(ctx) {
|
|
|
6662
6763
|
generate: generateArtifacts,
|
|
6663
6764
|
getBundleLayout,
|
|
6664
6765
|
getCompleteness: checkCompleteness,
|
|
6766
|
+
setAsideStaleTree: runSetAsideStaleTree,
|
|
6665
6767
|
patchMobile: runPatchMobile,
|
|
6666
6768
|
patchMobileIcons: runPatchMobileIcons,
|
|
6667
6769
|
detectPageAgent: runDetectPageAgent,
|
|
@@ -9020,7 +9122,8 @@ async function runScaffold(ctx) {
|
|
|
9020
9122
|
}
|
|
9021
9123
|
/**
|
|
9022
9124
|
* Runs the `codegen` phase — `project.generate()` first (mobile init needs the generated
|
|
9023
|
-
* `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
|
|
9024
9127
|
* is absent, the completeness gate (a partial tree fails fast, never silently
|
|
9025
9128
|
* re-initialized), and the idempotent `project.patchMobile()` pass carrying
|
|
9026
9129
|
* `tauri.getRunner()` — Tauri's own generated build phase calls a `node tauri` command
|
|
@@ -9039,6 +9142,7 @@ async function runCodegen(ctx, deps, target, profile = "store") {
|
|
|
9039
9142
|
profile
|
|
9040
9143
|
});
|
|
9041
9144
|
if (!isMobileTarget(target)) return { mobileInitRan: false };
|
|
9145
|
+
await deps.project.setAsideStaleTree({ target });
|
|
9042
9146
|
let status = deps.project.getCompleteness({ target });
|
|
9043
9147
|
let mobileInitRan = false;
|
|
9044
9148
|
if (status.status === "not-initialized") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moku-labs/native",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.14",
|
|
4
4
|
"description": "Node-only native packager framework for Moku — generates a gitignored Tauri project, codegens capabilities/Info.plist/AndroidManifest from composed system plugins, and runs tauri build.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|