@moku-labs/native 0.3.13 → 0.3.15
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 +135 -1
- package/dist/index.d.cts +41 -2
- package/dist/index.d.mts +41 -2
- package/dist/index.mjs +136 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3048,6 +3048,120 @@ 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 mobile `gen/<platform>` tree was initialised for, and
|
|
3054
|
+
* setting a tree aside when that id is not the configured one. `tauri android init` bakes the
|
|
3055
|
+
* id into the namespace, the `applicationId` and the Kotlin package path; `tauri ios init`
|
|
3056
|
+
* bakes it into `project.yml` and the Xcode project. A kept tree never runs init again, so a
|
|
3057
|
+
* changed `app.identifier` would otherwise build against the old package or bundle id.
|
|
3058
|
+
*/
|
|
3059
|
+
/** The key of the `applicationId = "<id>"` line; the debug suffix is a separate line. */
|
|
3060
|
+
const APPLICATION_ID_KEY = "applicationId";
|
|
3061
|
+
/** The key of the `PRODUCT_BUNDLE_IDENTIFIER: <id>` line of `project.yml`. */
|
|
3062
|
+
const BUNDLE_IDENTIFIER_KEY = "PRODUCT_BUNDLE_IDENTIFIER";
|
|
3063
|
+
/**
|
|
3064
|
+
* Reads the `applicationId` a `gen/android` tree was initialised for. Only a quoted literal
|
|
3065
|
+
* is recognised, the form `tauri android init` writes; an expression reads as no id.
|
|
3066
|
+
*
|
|
3067
|
+
* @param genDirectory - The absolute `src-tauri/gen/android` directory.
|
|
3068
|
+
* @returns The id, or undefined when `app/build.gradle.kts` is absent or names no literal id.
|
|
3069
|
+
* @example
|
|
3070
|
+
* ```ts
|
|
3071
|
+
* readAndroidApplicationId("/repo/.moku/tauri/src-tauri/gen/android"); // "com.acme.demo"
|
|
3072
|
+
* ```
|
|
3073
|
+
*/
|
|
3074
|
+
function readAndroidApplicationId(genDirectory) {
|
|
3075
|
+
const gradlePath = node_path.default.join(genDirectory, "app", "build.gradle.kts");
|
|
3076
|
+
if (!(0, node_fs.existsSync)(gradlePath)) return void 0;
|
|
3077
|
+
for (const line of (0, node_fs.readFileSync)(gradlePath, "utf8").split("\n")) {
|
|
3078
|
+
const [key, value] = line.split("=", 2).map((part) => part.trim());
|
|
3079
|
+
if (key === APPLICATION_ID_KEY && value?.startsWith("\"")) return value.split("\"")[1];
|
|
3080
|
+
}
|
|
3081
|
+
}
|
|
3082
|
+
/**
|
|
3083
|
+
* Reads the bundle id a `gen/apple` tree was initialised for, from the
|
|
3084
|
+
* `PRODUCT_BUNDLE_IDENTIFIER` of its `project.yml` — the file the Xcode project is generated
|
|
3085
|
+
* from, so both carry the same id. A quoted value is read without its quotes.
|
|
3086
|
+
*
|
|
3087
|
+
* @param genDirectory - The absolute `src-tauri/gen/apple` directory.
|
|
3088
|
+
* @returns The id, or undefined when `project.yml` is absent or names no bundle id.
|
|
3089
|
+
* @example
|
|
3090
|
+
* ```ts
|
|
3091
|
+
* readAppleBundleIdentifier("/repo/.moku/tauri/src-tauri/gen/apple"); // "com.acme.demo"
|
|
3092
|
+
* ```
|
|
3093
|
+
*/
|
|
3094
|
+
function readAppleBundleIdentifier(genDirectory) {
|
|
3095
|
+
const projectPath = node_path.default.join(genDirectory, "project.yml");
|
|
3096
|
+
if (!(0, node_fs.existsSync)(projectPath)) return void 0;
|
|
3097
|
+
for (const line of (0, node_fs.readFileSync)(projectPath, "utf8").split("\n")) {
|
|
3098
|
+
const [key, value] = line.split(":", 2).map((part) => part.trim());
|
|
3099
|
+
if (key === BUNDLE_IDENTIFIER_KEY && value) return value.replaceAll(/["']/g, "");
|
|
3100
|
+
}
|
|
3101
|
+
}
|
|
3102
|
+
/**
|
|
3103
|
+
* Compares two app ids the way Tauri writes them: a `-` may come out as `_` on Android and
|
|
3104
|
+
* a `_` as `-` on Apple.
|
|
3105
|
+
*
|
|
3106
|
+
* @param left - One id.
|
|
3107
|
+
* @param right - The other id.
|
|
3108
|
+
* @returns Whether both name the same app.
|
|
3109
|
+
*/
|
|
3110
|
+
function sameAppId(left, right) {
|
|
3111
|
+
return left.replaceAll("-", "_") === right.replaceAll("-", "_");
|
|
3112
|
+
}
|
|
3113
|
+
/**
|
|
3114
|
+
* Picks the first free `<genDirectory>.old-<id>` path, then `-2`, `-3`, … so an earlier
|
|
3115
|
+
* set-aside tree is never overwritten.
|
|
3116
|
+
*
|
|
3117
|
+
* @param genDirectory - The tree being set aside.
|
|
3118
|
+
* @param found - The id it was initialised for.
|
|
3119
|
+
* @returns A path that does not exist yet.
|
|
3120
|
+
*/
|
|
3121
|
+
function freeAsidePath(genDirectory, found) {
|
|
3122
|
+
const base = `${genDirectory}.old-${found}`;
|
|
3123
|
+
let candidate = base;
|
|
3124
|
+
let n = 1;
|
|
3125
|
+
while ((0, node_fs.existsSync)(candidate)) {
|
|
3126
|
+
n += 1;
|
|
3127
|
+
candidate = `${base}-${n}`;
|
|
3128
|
+
}
|
|
3129
|
+
return candidate;
|
|
3130
|
+
}
|
|
3131
|
+
/**
|
|
3132
|
+
* Moves a `gen/android` or `gen/apple` tree aside when it was initialised for another app id,
|
|
3133
|
+
* so the next `tauri android|ios init` writes a fresh one. The tree is renamed, never deleted:
|
|
3134
|
+
* it may hold a keystore or hand edits. A tree whose id cannot be read is left to the
|
|
3135
|
+
* completeness gate.
|
|
3136
|
+
*
|
|
3137
|
+
* @param options - The check options.
|
|
3138
|
+
* @param options.target - The mobile platform the tree belongs to.
|
|
3139
|
+
* @param options.genDirectory - The absolute `src-tauri/gen/<platform>` directory.
|
|
3140
|
+
* @param options.identifier - The configured `app.identifier`.
|
|
3141
|
+
* @returns What was found and where it went, or undefined when the tree was kept.
|
|
3142
|
+
* @example
|
|
3143
|
+
* ```ts
|
|
3144
|
+
* await setAsideStaleMobileTree({
|
|
3145
|
+
* target: "android",
|
|
3146
|
+
* genDirectory,
|
|
3147
|
+
* identifier: "studio.kitto.memorymissing"
|
|
3148
|
+
* });
|
|
3149
|
+
* // { found: "com.mokulabs.memorymissing", expected: "studio.kitto.memorymissing",
|
|
3150
|
+
* // movedTo: ".../gen/android.old-com.mokulabs.memorymissing" }
|
|
3151
|
+
* ```
|
|
3152
|
+
*/
|
|
3153
|
+
async function setAsideStaleMobileTree(options) {
|
|
3154
|
+
const found = options.target === "android" ? readAndroidApplicationId(options.genDirectory) : readAppleBundleIdentifier(options.genDirectory);
|
|
3155
|
+
if (found === void 0 || sameAppId(found, options.identifier)) return void 0;
|
|
3156
|
+
const movedTo = freeAsidePath(options.genDirectory, found);
|
|
3157
|
+
await (0, node_fs_promises.rename)(options.genDirectory, movedTo);
|
|
3158
|
+
return {
|
|
3159
|
+
found,
|
|
3160
|
+
expected: options.identifier,
|
|
3161
|
+
movedTo
|
|
3162
|
+
};
|
|
3163
|
+
}
|
|
3164
|
+
//#endregion
|
|
3051
3165
|
//#region src/plugins/project/mobile/xcode-settings.ts
|
|
3052
3166
|
/**
|
|
3053
3167
|
* @file project plugin — the Xcode build-settings patch that makes an iOS REBUILD work.
|
|
@@ -6543,6 +6657,23 @@ function createProjectApi(ctx) {
|
|
|
6543
6657
|
*/
|
|
6544
6658
|
const checkCompleteness = (opts) => completeness(ctx.global.projectDir, opts.target);
|
|
6545
6659
|
/**
|
|
6660
|
+
* Implements {@link Api.setAsideStaleTree}: one plain warn line when a tree was moved.
|
|
6661
|
+
*
|
|
6662
|
+
* @param opts - See {@link Api.setAsideStaleTree}.
|
|
6663
|
+
* @param opts.target - The mobile platform whose tree to check.
|
|
6664
|
+
* @returns See {@link Api.setAsideStaleTree}.
|
|
6665
|
+
*/
|
|
6666
|
+
const runSetAsideStaleTree = async (opts) => {
|
|
6667
|
+
const genDirectory = genDirectoryPath(ctx.global.projectDir, opts.target);
|
|
6668
|
+
const aside = await setAsideStaleMobileTree({
|
|
6669
|
+
target: opts.target,
|
|
6670
|
+
genDirectory,
|
|
6671
|
+
identifier: ctx.global.app.identifier
|
|
6672
|
+
});
|
|
6673
|
+
if (aside !== void 0) ctx.log.warn(`gen/${node_path.default.basename(genDirectory)} was made for ${aside.found}, not ${aside.expected}: moved it to ${node_path.default.basename(aside.movedTo)} and generating it again`);
|
|
6674
|
+
return aside;
|
|
6675
|
+
};
|
|
6676
|
+
/**
|
|
6546
6677
|
* Builds the Android profile one patch pass applies. The debug profile resolves the debug
|
|
6547
6678
|
* keystore from `ctx.env` here (`HOME` ?? `USERPROFILE`), so the patch itself never reads
|
|
6548
6679
|
* the environment. Every other case applies as store: the `dev` profile, and iOS, which reads
|
|
@@ -6689,6 +6820,7 @@ function createProjectApi(ctx) {
|
|
|
6689
6820
|
generate: generateArtifacts,
|
|
6690
6821
|
getBundleLayout,
|
|
6691
6822
|
getCompleteness: checkCompleteness,
|
|
6823
|
+
setAsideStaleTree: runSetAsideStaleTree,
|
|
6692
6824
|
patchMobile: runPatchMobile,
|
|
6693
6825
|
patchMobileIcons: runPatchMobileIcons,
|
|
6694
6826
|
detectPageAgent: runDetectPageAgent,
|
|
@@ -9047,7 +9179,8 @@ async function runScaffold(ctx) {
|
|
|
9047
9179
|
}
|
|
9048
9180
|
/**
|
|
9049
9181
|
* Runs the `codegen` phase — `project.generate()` first (mobile init needs the generated
|
|
9050
|
-
* `tauri.conf.json`), then for a mobile target:
|
|
9182
|
+
* `tauri.conf.json`), then for a mobile target: a tree initialised for another app id is
|
|
9183
|
+
* set aside (`project.setAsideStaleTree()`), `tauri.mobileInit()` when the `gen/` tree
|
|
9051
9184
|
* is absent, the completeness gate (a partial tree fails fast, never silently
|
|
9052
9185
|
* re-initialized), and the idempotent `project.patchMobile()` pass carrying
|
|
9053
9186
|
* `tauri.getRunner()` — Tauri's own generated build phase calls a `node tauri` command
|
|
@@ -9066,6 +9199,7 @@ async function runCodegen(ctx, deps, target, profile = "store") {
|
|
|
9066
9199
|
profile
|
|
9067
9200
|
});
|
|
9068
9201
|
if (!isMobileTarget(target)) return { mobileInitRan: false };
|
|
9202
|
+
await deps.project.setAsideStaleTree({ target });
|
|
9069
9203
|
let status = deps.project.getCompleteness({ target });
|
|
9070
9204
|
let mobileInitRan = false;
|
|
9071
9205
|
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,28 @@ type Api$4 = {
|
|
|
556
573
|
getCompleteness(opts: {
|
|
557
574
|
target: Target;
|
|
558
575
|
}): CompletenessResult;
|
|
576
|
+
/**
|
|
577
|
+
* Sets a `gen/android` or `gen/apple` tree aside when it was initialised for another app id
|
|
578
|
+
* than `app.identifier` (Android: `applicationId` in `app/build.gradle.kts`; iOS:
|
|
579
|
+
* `PRODUCT_BUNDLE_IDENTIFIER` in `project.yml`): renames it to `gen/<platform>.old-<old id>`
|
|
580
|
+
* (never deletes it, it may hold a keystore or hand edits) and logs one line, so the build's
|
|
581
|
+
* mobile init writes a fresh tree. The build plugin calls it before the completeness read.
|
|
582
|
+
* A missing tree and a 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>;
|
|
559
598
|
/**
|
|
560
599
|
* Runs the idempotent mobile post-init patch pass. Android gets its build-profile
|
|
561
600
|
* patches (debug: the `.debug` id suffix, the `"<name> (debug)"` label, a cleartext
|
|
@@ -1145,7 +1184,7 @@ type PathResolver = (target: string) => string;
|
|
|
1145
1184
|
* cross-plugin surface build depends on (D-007) is readable in one place.
|
|
1146
1185
|
*/
|
|
1147
1186
|
type BuildDeps = {
|
|
1148
|
-
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">;
|
|
1149
1188
|
readonly tauri: Pick<Api$3, "build" | "mobileInit" | "icon" | "getRunner">;
|
|
1150
1189
|
};
|
|
1151
1190
|
/** 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,28 @@ type Api$4 = {
|
|
|
557
574
|
getCompleteness(opts: {
|
|
558
575
|
target: Target;
|
|
559
576
|
}): CompletenessResult;
|
|
577
|
+
/**
|
|
578
|
+
* Sets a `gen/android` or `gen/apple` tree aside when it was initialised for another app id
|
|
579
|
+
* than `app.identifier` (Android: `applicationId` in `app/build.gradle.kts`; iOS:
|
|
580
|
+
* `PRODUCT_BUNDLE_IDENTIFIER` in `project.yml`): renames it to `gen/<platform>.old-<old id>`
|
|
581
|
+
* (never deletes it, it may hold a keystore or hand edits) and logs one line, so the build's
|
|
582
|
+
* mobile init writes a fresh tree. The build plugin calls it before the completeness read.
|
|
583
|
+
* A missing tree and a tree whose id cannot be read get undefined.
|
|
584
|
+
*
|
|
585
|
+
* @param opts - The check options.
|
|
586
|
+
* @param opts.target - The mobile platform whose tree to check.
|
|
587
|
+
* @returns What was set aside, or undefined when the tree was kept.
|
|
588
|
+
* @example
|
|
589
|
+
* ```ts
|
|
590
|
+
* // app.identifier changed from com.mokulabs.memorymissing to studio.kitto.memorymissing.
|
|
591
|
+
* await app.project.setAsideStaleTree({ target: "android" });
|
|
592
|
+
* // { found: "com.mokulabs.memorymissing", expected: "studio.kitto.memorymissing",
|
|
593
|
+
* // movedTo: "/repo/.moku/tauri/src-tauri/gen/android.old-com.mokulabs.memorymissing" }
|
|
594
|
+
* ```
|
|
595
|
+
*/
|
|
596
|
+
setAsideStaleTree(opts: {
|
|
597
|
+
target: MobileTarget;
|
|
598
|
+
}): Promise<StaleTree | undefined>;
|
|
560
599
|
/**
|
|
561
600
|
* Runs the idempotent mobile post-init patch pass. Android gets its build-profile
|
|
562
601
|
* patches (debug: the `.debug` id suffix, the `"<name> (debug)"` label, a cleartext
|
|
@@ -1146,7 +1185,7 @@ type PathResolver = (target: string) => string;
|
|
|
1146
1185
|
* cross-plugin surface build depends on (D-007) is readable in one place.
|
|
1147
1186
|
*/
|
|
1148
1187
|
type BuildDeps = {
|
|
1149
|
-
readonly project: Pick<Api$4, "generate" | "getBundleLayout" | "getCompleteness" | "patchMobile" | "clearMobileBuildOutput" | "ensureIconSource" | "resolveDerivedPath" | "patchMobileIcons" | "detectPageAgent" | "checkShellLinked">;
|
|
1188
|
+
readonly project: Pick<Api$4, "generate" | "getBundleLayout" | "getCompleteness" | "setAsideStaleTree" | "patchMobile" | "clearMobileBuildOutput" | "ensureIconSource" | "resolveDerivedPath" | "patchMobileIcons" | "detectPageAgent" | "checkShellLinked">;
|
|
1150
1189
|
readonly tauri: Pick<Api$3, "build" | "mobileInit" | "icon" | "getRunner">;
|
|
1151
1190
|
};
|
|
1152
1191
|
/** 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,120 @@ 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 mobile `gen/<platform>` tree was initialised for, and
|
|
3027
|
+
* setting a tree aside when that id is not the configured one. `tauri android init` bakes the
|
|
3028
|
+
* id into the namespace, the `applicationId` and the Kotlin package path; `tauri ios init`
|
|
3029
|
+
* bakes it into `project.yml` and the Xcode project. A kept tree never runs init again, so a
|
|
3030
|
+
* changed `app.identifier` would otherwise build against the old package or bundle id.
|
|
3031
|
+
*/
|
|
3032
|
+
/** The key of the `applicationId = "<id>"` line; the debug suffix is a separate line. */
|
|
3033
|
+
const APPLICATION_ID_KEY = "applicationId";
|
|
3034
|
+
/** The key of the `PRODUCT_BUNDLE_IDENTIFIER: <id>` line of `project.yml`. */
|
|
3035
|
+
const BUNDLE_IDENTIFIER_KEY = "PRODUCT_BUNDLE_IDENTIFIER";
|
|
3036
|
+
/**
|
|
3037
|
+
* Reads the `applicationId` a `gen/android` tree was initialised for. Only a quoted literal
|
|
3038
|
+
* is recognised, the form `tauri android init` writes; an expression reads as no id.
|
|
3039
|
+
*
|
|
3040
|
+
* @param genDirectory - The absolute `src-tauri/gen/android` directory.
|
|
3041
|
+
* @returns The id, or undefined when `app/build.gradle.kts` is absent or names no literal id.
|
|
3042
|
+
* @example
|
|
3043
|
+
* ```ts
|
|
3044
|
+
* readAndroidApplicationId("/repo/.moku/tauri/src-tauri/gen/android"); // "com.acme.demo"
|
|
3045
|
+
* ```
|
|
3046
|
+
*/
|
|
3047
|
+
function readAndroidApplicationId(genDirectory) {
|
|
3048
|
+
const gradlePath = path.join(genDirectory, "app", "build.gradle.kts");
|
|
3049
|
+
if (!existsSync(gradlePath)) return void 0;
|
|
3050
|
+
for (const line of readFileSync(gradlePath, "utf8").split("\n")) {
|
|
3051
|
+
const [key, value] = line.split("=", 2).map((part) => part.trim());
|
|
3052
|
+
if (key === APPLICATION_ID_KEY && value?.startsWith("\"")) return value.split("\"")[1];
|
|
3053
|
+
}
|
|
3054
|
+
}
|
|
3055
|
+
/**
|
|
3056
|
+
* Reads the bundle id a `gen/apple` tree was initialised for, from the
|
|
3057
|
+
* `PRODUCT_BUNDLE_IDENTIFIER` of its `project.yml` — the file the Xcode project is generated
|
|
3058
|
+
* from, so both carry the same id. A quoted value is read without its quotes.
|
|
3059
|
+
*
|
|
3060
|
+
* @param genDirectory - The absolute `src-tauri/gen/apple` directory.
|
|
3061
|
+
* @returns The id, or undefined when `project.yml` is absent or names no bundle id.
|
|
3062
|
+
* @example
|
|
3063
|
+
* ```ts
|
|
3064
|
+
* readAppleBundleIdentifier("/repo/.moku/tauri/src-tauri/gen/apple"); // "com.acme.demo"
|
|
3065
|
+
* ```
|
|
3066
|
+
*/
|
|
3067
|
+
function readAppleBundleIdentifier(genDirectory) {
|
|
3068
|
+
const projectPath = path.join(genDirectory, "project.yml");
|
|
3069
|
+
if (!existsSync(projectPath)) return void 0;
|
|
3070
|
+
for (const line of readFileSync(projectPath, "utf8").split("\n")) {
|
|
3071
|
+
const [key, value] = line.split(":", 2).map((part) => part.trim());
|
|
3072
|
+
if (key === BUNDLE_IDENTIFIER_KEY && value) return value.replaceAll(/["']/g, "");
|
|
3073
|
+
}
|
|
3074
|
+
}
|
|
3075
|
+
/**
|
|
3076
|
+
* Compares two app ids the way Tauri writes them: a `-` may come out as `_` on Android and
|
|
3077
|
+
* a `_` as `-` on Apple.
|
|
3078
|
+
*
|
|
3079
|
+
* @param left - One id.
|
|
3080
|
+
* @param right - The other id.
|
|
3081
|
+
* @returns Whether both name the same app.
|
|
3082
|
+
*/
|
|
3083
|
+
function sameAppId(left, right) {
|
|
3084
|
+
return left.replaceAll("-", "_") === right.replaceAll("-", "_");
|
|
3085
|
+
}
|
|
3086
|
+
/**
|
|
3087
|
+
* Picks the first free `<genDirectory>.old-<id>` path, then `-2`, `-3`, … so an earlier
|
|
3088
|
+
* set-aside tree is never overwritten.
|
|
3089
|
+
*
|
|
3090
|
+
* @param genDirectory - The tree being set aside.
|
|
3091
|
+
* @param found - The id it was initialised for.
|
|
3092
|
+
* @returns A path that does not exist yet.
|
|
3093
|
+
*/
|
|
3094
|
+
function freeAsidePath(genDirectory, found) {
|
|
3095
|
+
const base = `${genDirectory}.old-${found}`;
|
|
3096
|
+
let candidate = base;
|
|
3097
|
+
let n = 1;
|
|
3098
|
+
while (existsSync(candidate)) {
|
|
3099
|
+
n += 1;
|
|
3100
|
+
candidate = `${base}-${n}`;
|
|
3101
|
+
}
|
|
3102
|
+
return candidate;
|
|
3103
|
+
}
|
|
3104
|
+
/**
|
|
3105
|
+
* Moves a `gen/android` or `gen/apple` tree aside when it was initialised for another app id,
|
|
3106
|
+
* so the next `tauri android|ios init` writes a fresh one. The tree is renamed, never deleted:
|
|
3107
|
+
* it may hold a keystore or hand edits. A tree whose id cannot be read is left to the
|
|
3108
|
+
* completeness gate.
|
|
3109
|
+
*
|
|
3110
|
+
* @param options - The check options.
|
|
3111
|
+
* @param options.target - The mobile platform the tree belongs to.
|
|
3112
|
+
* @param options.genDirectory - The absolute `src-tauri/gen/<platform>` directory.
|
|
3113
|
+
* @param options.identifier - The configured `app.identifier`.
|
|
3114
|
+
* @returns What was found and where it went, or undefined when the tree was kept.
|
|
3115
|
+
* @example
|
|
3116
|
+
* ```ts
|
|
3117
|
+
* await setAsideStaleMobileTree({
|
|
3118
|
+
* target: "android",
|
|
3119
|
+
* genDirectory,
|
|
3120
|
+
* identifier: "studio.kitto.memorymissing"
|
|
3121
|
+
* });
|
|
3122
|
+
* // { found: "com.mokulabs.memorymissing", expected: "studio.kitto.memorymissing",
|
|
3123
|
+
* // movedTo: ".../gen/android.old-com.mokulabs.memorymissing" }
|
|
3124
|
+
* ```
|
|
3125
|
+
*/
|
|
3126
|
+
async function setAsideStaleMobileTree(options) {
|
|
3127
|
+
const found = options.target === "android" ? readAndroidApplicationId(options.genDirectory) : readAppleBundleIdentifier(options.genDirectory);
|
|
3128
|
+
if (found === void 0 || sameAppId(found, options.identifier)) return void 0;
|
|
3129
|
+
const movedTo = freeAsidePath(options.genDirectory, found);
|
|
3130
|
+
await rename(options.genDirectory, movedTo);
|
|
3131
|
+
return {
|
|
3132
|
+
found,
|
|
3133
|
+
expected: options.identifier,
|
|
3134
|
+
movedTo
|
|
3135
|
+
};
|
|
3136
|
+
}
|
|
3137
|
+
//#endregion
|
|
3024
3138
|
//#region src/plugins/project/mobile/xcode-settings.ts
|
|
3025
3139
|
/**
|
|
3026
3140
|
* @file project plugin — the Xcode build-settings patch that makes an iOS REBUILD work.
|
|
@@ -6516,6 +6630,23 @@ function createProjectApi(ctx) {
|
|
|
6516
6630
|
*/
|
|
6517
6631
|
const checkCompleteness = (opts) => completeness(ctx.global.projectDir, opts.target);
|
|
6518
6632
|
/**
|
|
6633
|
+
* Implements {@link Api.setAsideStaleTree}: one plain warn line when a tree was moved.
|
|
6634
|
+
*
|
|
6635
|
+
* @param opts - See {@link Api.setAsideStaleTree}.
|
|
6636
|
+
* @param opts.target - The mobile platform whose tree to check.
|
|
6637
|
+
* @returns See {@link Api.setAsideStaleTree}.
|
|
6638
|
+
*/
|
|
6639
|
+
const runSetAsideStaleTree = async (opts) => {
|
|
6640
|
+
const genDirectory = genDirectoryPath(ctx.global.projectDir, opts.target);
|
|
6641
|
+
const aside = await setAsideStaleMobileTree({
|
|
6642
|
+
target: opts.target,
|
|
6643
|
+
genDirectory,
|
|
6644
|
+
identifier: ctx.global.app.identifier
|
|
6645
|
+
});
|
|
6646
|
+
if (aside !== void 0) ctx.log.warn(`gen/${path.basename(genDirectory)} was made for ${aside.found}, not ${aside.expected}: moved it to ${path.basename(aside.movedTo)} and generating it again`);
|
|
6647
|
+
return aside;
|
|
6648
|
+
};
|
|
6649
|
+
/**
|
|
6519
6650
|
* Builds the Android profile one patch pass applies. The debug profile resolves the debug
|
|
6520
6651
|
* keystore from `ctx.env` here (`HOME` ?? `USERPROFILE`), so the patch itself never reads
|
|
6521
6652
|
* the environment. Every other case applies as store: the `dev` profile, and iOS, which reads
|
|
@@ -6662,6 +6793,7 @@ function createProjectApi(ctx) {
|
|
|
6662
6793
|
generate: generateArtifacts,
|
|
6663
6794
|
getBundleLayout,
|
|
6664
6795
|
getCompleteness: checkCompleteness,
|
|
6796
|
+
setAsideStaleTree: runSetAsideStaleTree,
|
|
6665
6797
|
patchMobile: runPatchMobile,
|
|
6666
6798
|
patchMobileIcons: runPatchMobileIcons,
|
|
6667
6799
|
detectPageAgent: runDetectPageAgent,
|
|
@@ -9020,7 +9152,8 @@ async function runScaffold(ctx) {
|
|
|
9020
9152
|
}
|
|
9021
9153
|
/**
|
|
9022
9154
|
* Runs the `codegen` phase — `project.generate()` first (mobile init needs the generated
|
|
9023
|
-
* `tauri.conf.json`), then for a mobile target:
|
|
9155
|
+
* `tauri.conf.json`), then for a mobile target: a tree initialised for another app id is
|
|
9156
|
+
* set aside (`project.setAsideStaleTree()`), `tauri.mobileInit()` when the `gen/` tree
|
|
9024
9157
|
* is absent, the completeness gate (a partial tree fails fast, never silently
|
|
9025
9158
|
* re-initialized), and the idempotent `project.patchMobile()` pass carrying
|
|
9026
9159
|
* `tauri.getRunner()` — Tauri's own generated build phase calls a `node tauri` command
|
|
@@ -9039,6 +9172,7 @@ async function runCodegen(ctx, deps, target, profile = "store") {
|
|
|
9039
9172
|
profile
|
|
9040
9173
|
});
|
|
9041
9174
|
if (!isMobileTarget(target)) return { mobileInitRan: false };
|
|
9175
|
+
await deps.project.setAsideStaleTree({ target });
|
|
9042
9176
|
let status = deps.project.getCompleteness({ target });
|
|
9043
9177
|
let mobileInitRan = false;
|
|
9044
9178
|
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.15",
|
|
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",
|