vidra-cli 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +7 -1
  2. package/dist/cli.js +908 -235
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // src/commands/build.ts
2
- import path17 from "path";
3
- import fs15 from "fs-extra";
4
- import { execSync as execSync4 } from "child_process";
2
+ import path18 from "path";
3
+ import fs16 from "fs-extra";
4
+ import { execFileSync as execFileSync9, execSync as execSync4 } from "child_process";
5
5
 
6
6
  // ../shared/src/utils.ts
7
7
  var parseArgs = (argv) => {
@@ -589,7 +589,7 @@ var writeIfChanged = (output, contents) => {
589
589
  };
590
590
 
591
591
  // src/cli-version.ts
592
- var CLI_VERSION = "0.5.0";
592
+ var CLI_VERSION = "0.6.0";
593
593
 
594
594
  // src/help.ts
595
595
  var UNIVERSAL = [
@@ -703,7 +703,7 @@ var DEV = {
703
703
  summary: "start vite + the native host (UI and C# reload on save)",
704
704
  usage: "dev [--target <os>] [--no-hot-reload]",
705
705
  flags: [
706
- { name: "--target", arg: "os", describe: "macos or windows (default: this machine)" },
706
+ { name: "--target", arg: "os", describe: "macos, windows, or android (default: this machine)" },
707
707
  { name: "--no-hot-reload", describe: "skip dotnet watch, build and launch once" },
708
708
  { name: "--port", arg: "n", describe: "vite port (default: 5173, or the next free one)" },
709
709
  { name: "--verbose", describe: "stream the full build output" }
@@ -718,7 +718,7 @@ var RUN = {
718
718
  summary: "launch the native host only",
719
719
  usage: "run [--target <os>]",
720
720
  flags: [
721
- { name: "--target", arg: "os", describe: "macos or windows (default: this machine)" },
721
+ { name: "--target", arg: "os", describe: "macos, windows, or android (default: this machine)" },
722
722
  { name: "--verbose", describe: "stream the full build output" }
723
723
  ]
724
724
  };
@@ -730,7 +730,7 @@ var BUILD = {
730
730
  { name: "--app", describe: "the installable app and its release, no web bundle" },
731
731
  { name: "--web", describe: "the web bundle only, no compile and no platform" },
732
732
  { name: "--channel", arg: "name", describe: "publish to a ring (env: VIDRA_CHANNEL)" },
733
- { name: "--target", arg: "os", describe: "macos or windows (default: this machine)" },
733
+ { name: "--target", arg: "os", describe: "macos, windows, or android (default: this machine)" },
734
734
  { name: "--sign", arg: "key.pem", describe: "sign the web feed (env: VIDRA_UPDATE_SIGNING_KEY)" },
735
735
  { name: "--plan", describe: "print every step and artifact, run nothing" },
736
736
  { name: "--dry-run", describe: "alias for --plan" },
@@ -777,7 +777,10 @@ var VERIFY = {
777
777
  var DOCTOR = {
778
778
  name: "doctor",
779
779
  summary: "check your environment, and this project's update wiring",
780
- usage: "doctor"
780
+ usage: "doctor [--target <os>]",
781
+ flags: [
782
+ { name: "--target", arg: "os", describe: "macos, windows, or android (default: this machine)" }
783
+ ]
781
784
  };
782
785
  var ALL = [DEV, RUN, BUILD, UPDATES, KEYGEN, VERIFY, DOCTOR];
783
786
 
@@ -1986,9 +1989,9 @@ var detectPlatform = () => {
1986
1989
  case "win32":
1987
1990
  return "windows";
1988
1991
  case "linux":
1989
- return "linux";
1992
+ return "android";
1990
1993
  default:
1991
- return "macos";
1994
+ return process.platform;
1992
1995
  }
1993
1996
  };
1994
1997
  var detectProject = (cwd) => {
@@ -2059,7 +2062,7 @@ import os3 from "os";
2059
2062
  var macosTarget = {
2060
2063
  name: "macos",
2061
2064
  framework: "net10.0-maccatalyst",
2062
- extraPublishArgs: "-p:CreatePackage=false",
2065
+ extraPublishArgs: ["-p:CreatePackage=false"],
2063
2066
  findBundle(publishDir, _projectName) {
2064
2067
  if (!fs12.existsSync(publishDir)) return null;
2065
2068
  for (const entry of fs12.readdirSync(publishDir, { withFileTypes: true })) {
@@ -2087,7 +2090,7 @@ var macosTarget = {
2087
2090
  } finally {
2088
2091
  fs12.removeSync(staging);
2089
2092
  }
2090
- return dmgPath;
2093
+ return [dmgPath];
2091
2094
  }
2092
2095
  };
2093
2096
 
@@ -2210,7 +2213,12 @@ var windowsTarget = {
2210
2213
  // `RuntimeIdentifierOverride` (rather than `-r`/`RuntimeIdentifier`) is the
2211
2214
  // MAUI-recommended way to set the Windows RID — it sidesteps WindowsAppSDK
2212
2215
  // issue #3337, which otherwise pulls in the wrong packaging assets.
2213
- extraPublishArgs: "-p:WindowsPackageType=None -p:SelfContained=true -p:WindowsAppSDKSelfContained=true -p:RuntimeIdentifierOverride=win-x64",
2216
+ extraPublishArgs: [
2217
+ "-p:WindowsPackageType=None",
2218
+ "-p:SelfContained=true",
2219
+ "-p:WindowsAppSDKSelfContained=true",
2220
+ "-p:RuntimeIdentifierOverride=win-x64"
2221
+ ],
2214
2222
  findBundle(publishDir, _projectName) {
2215
2223
  const preferred = path15.join(publishDir, "win-x64", "publish");
2216
2224
  if (dirContainsExe(preferred)) return preferred;
@@ -2237,7 +2245,7 @@ var windowsTarget = {
2237
2245
  } finally {
2238
2246
  fs13.removeSync(staging);
2239
2247
  }
2240
- return outPath;
2248
+ return [outPath];
2241
2249
  }
2242
2250
  };
2243
2251
  var dirContainsExe = (dir) => fs13.existsSync(dir) && fs13.readdirSync(dir, { withFileTypes: true }).some((e) => e.isFile() && e.name.toLowerCase().endsWith(".exe"));
@@ -2260,6 +2268,153 @@ var findDirWithExe = (root) => {
2260
2268
  return walk(root) ?? fallback;
2261
2269
  };
2262
2270
 
2271
+ // src/targets/android.ts
2272
+ import path16 from "path";
2273
+ import fs14 from "fs-extra";
2274
+ import { spawnSync as spawnSync2 } from "child_process";
2275
+ var resolveAndroidSigningConfig = (env = process.env) => {
2276
+ const keyStore = env.VIDRA_ANDROID_KEYSTORE?.trim();
2277
+ const keyAlias = env.VIDRA_ANDROID_KEY_ALIAS?.trim();
2278
+ const keyPassword = env.VIDRA_ANDROID_KEY_PASSWORD;
2279
+ const storePassword = env.VIDRA_ANDROID_STORE_PASSWORD;
2280
+ if (!keyStore && !keyAlias && !keyPassword && !storePassword) return null;
2281
+ if (!keyStore || !keyAlias || !keyPassword || !storePassword) {
2282
+ throw new Error(
2283
+ "Android signing is incomplete \u2014 set VIDRA_ANDROID_KEYSTORE, VIDRA_ANDROID_KEY_ALIAS, VIDRA_ANDROID_KEY_PASSWORD, and VIDRA_ANDROID_STORE_PASSWORD"
2284
+ );
2285
+ }
2286
+ if (!fs14.existsSync(keyStore)) {
2287
+ throw new Error(`Android keystore not found: ${keyStore}`);
2288
+ }
2289
+ return { keyStore: path16.resolve(keyStore), keyAlias };
2290
+ };
2291
+ var androidPublishArgs = (signing, env = process.env) => [
2292
+ "-p:AndroidPackageFormats=apk%3Baab",
2293
+ "-p:AndroidKeyStore=true",
2294
+ `-p:AndroidSigningKeyStore=${escapeMsBuildProperty(signing.keyStore)}`,
2295
+ `-p:AndroidSigningKeyAlias=${escapeMsBuildProperty(signing.keyAlias)}`,
2296
+ "-p:AndroidSigningKeyPass=env:VIDRA_ANDROID_KEY_PASSWORD",
2297
+ "-p:AndroidSigningStorePass=env:VIDRA_ANDROID_STORE_PASSWORD",
2298
+ ...env.VIDRA_ANDROID_DEBUGGABLE === "1" ? ["-p:VidraAndroidTestRuntime=true"] : []
2299
+ ];
2300
+ var escapeMsBuildProperty = (value3) => value3.replace(
2301
+ /[%$@';?*()]/g,
2302
+ (character) => `%${character.charCodeAt(0).toString(16).toUpperCase()}`
2303
+ );
2304
+ var verifyAndroidPackage = (artifact) => {
2305
+ const apk = artifact.endsWith(".apk");
2306
+ const signerJar = apk ? resolveApkSignerJar() : null;
2307
+ if (apk && !signerJar) {
2308
+ return {
2309
+ ok: false,
2310
+ tool: "apksigner",
2311
+ output: "apksigner was not found in Android SDK build-tools"
2312
+ };
2313
+ }
2314
+ const tool = apk ? "apksigner" : "jarsigner";
2315
+ const executable = apk ? "java" : "jarsigner";
2316
+ const args = apk ? ["-jar", signerJar, "verify", "--verbose", artifact] : ["-verify", artifact];
2317
+ const result = spawnSync2(executable, args, {
2318
+ encoding: "utf8",
2319
+ stdio: ["ignore", "pipe", "pipe"]
2320
+ });
2321
+ const output = [result.stdout, result.stderr, result.error?.message].filter(Boolean).join("\n");
2322
+ const affirmativelySigned = apk || /\bjar verified\b/i.test(output);
2323
+ return {
2324
+ ok: result.status === 0 && affirmativelySigned,
2325
+ tool,
2326
+ output
2327
+ };
2328
+ };
2329
+ var androidTarget = {
2330
+ name: "android",
2331
+ framework: "net10.0-android",
2332
+ findBundle(publishDir) {
2333
+ const files = findAndroidPackages(publishDir);
2334
+ return files.some((file) => file.endsWith(".apk")) && files.some((file) => file.endsWith(".aab")) ? publishDir : null;
2335
+ },
2336
+ async package(publishDir, outputDir, meta) {
2337
+ const packages = findAndroidPackages(publishDir);
2338
+ const apk = preferredPackage(packages, ".apk");
2339
+ const aab = preferredPackage(packages, ".aab");
2340
+ if (!apk || !aab) {
2341
+ throw new Error(`Android publish did not produce both an APK and AAB under ${publishDir}`);
2342
+ }
2343
+ fs14.ensureDirSync(outputDir);
2344
+ const apkOut = path16.join(
2345
+ outputDir,
2346
+ `${meta.projectName}-${meta.displayVersion}-android.apk`
2347
+ );
2348
+ const aabOut = path16.join(
2349
+ outputDir,
2350
+ `${meta.projectName}-${meta.displayVersion}-android.aab`
2351
+ );
2352
+ const versionCodeFile = `${aabOut}.version-code`;
2353
+ const previous = highestPackagedVersionCode(path16.join(meta.projectRoot, "dist"));
2354
+ if (previous !== null && meta.buildNumber < previous) {
2355
+ throw new Error(
2356
+ `Android versionCode ${meta.buildNumber} cannot be lower than the previously packaged ${previous}; set VIDRA_BUILD_NUMBER to a larger value`
2357
+ );
2358
+ }
2359
+ if (previous !== null && meta.buildNumber === previous && !fs14.existsSync(versionCodeFile)) {
2360
+ throw new Error(
2361
+ `Android versionCode ${meta.buildNumber} is already assigned to another local artifact; set VIDRA_BUILD_NUMBER to a larger value`
2362
+ );
2363
+ }
2364
+ fs14.copySync(apk, apkOut, { overwrite: true });
2365
+ fs14.copySync(aab, aabOut, { overwrite: true });
2366
+ fs14.writeFileSync(versionCodeFile, `${meta.buildNumber}
2367
+ `);
2368
+ return [apkOut, aabOut];
2369
+ }
2370
+ };
2371
+ var preferredPackage = (files, extension) => {
2372
+ const matching = files.filter((file) => file.toLowerCase().endsWith(extension));
2373
+ return matching.find((file) => /-signed\.(?:apk|aab)$/i.test(file)) ?? matching[0] ?? null;
2374
+ };
2375
+ var findAndroidPackages = (root) => {
2376
+ if (!fs14.existsSync(root)) return [];
2377
+ const found = [];
2378
+ const visit = (directory) => {
2379
+ for (const entry of fs14.readdirSync(directory, { withFileTypes: true })) {
2380
+ const fullPath = path16.join(directory, entry.name);
2381
+ if (entry.isDirectory()) visit(fullPath);
2382
+ else if (/\.(?:apk|aab)$/i.test(entry.name)) found.push(fullPath);
2383
+ }
2384
+ };
2385
+ visit(root);
2386
+ return found;
2387
+ };
2388
+ var highestPackagedVersionCode = (outputDir) => {
2389
+ if (!fs14.existsSync(outputDir)) return null;
2390
+ const values = [];
2391
+ const visit = (directory) => {
2392
+ for (const entry of fs14.readdirSync(directory, { withFileTypes: true })) {
2393
+ const fullPath = path16.join(directory, entry.name);
2394
+ if (entry.isDirectory()) {
2395
+ visit(fullPath);
2396
+ } else if (entry.name.endsWith(".aab.version-code")) {
2397
+ const value3 = Number(fs14.readFileSync(fullPath, "utf8").trim());
2398
+ if (Number.isSafeInteger(value3)) values.push(value3);
2399
+ }
2400
+ }
2401
+ };
2402
+ visit(outputDir);
2403
+ return values.length > 0 ? Math.max(...values) : null;
2404
+ };
2405
+ var resolveApkSignerJar = () => {
2406
+ const sdk = process.env.ANDROID_SDK_ROOT ?? process.env.ANDROID_HOME;
2407
+ if (!sdk) return null;
2408
+ const buildTools = path16.join(sdk, "build-tools");
2409
+ if (!fs14.existsSync(buildTools)) return null;
2410
+ const versions = fs14.readdirSync(buildTools, { withFileTypes: true }).filter((entry) => entry.isDirectory()).map((entry) => entry.name).sort((a, b) => b.localeCompare(a, void 0, { numeric: true }));
2411
+ for (const version of versions) {
2412
+ const candidate = path16.join(buildTools, version, "lib", "apksigner.jar");
2413
+ if (fs14.existsSync(candidate)) return candidate;
2414
+ }
2415
+ return null;
2416
+ };
2417
+
2263
2418
  // ../shared/src/dotnet-toolchain.ts
2264
2419
  import { execFileSync as execFileSync8 } from "child_process";
2265
2420
  import prompts from "prompts";
@@ -2273,6 +2428,14 @@ var newestNet10Sdk = (listSdksOutput) => splitLines(listSdksOutput).map((line) =
2273
2428
  (a, b) => a.localeCompare(b, void 0, { numeric: true, sensitivity: "base" })
2274
2429
  ).pop();
2275
2430
  var outputMentionsMaui = (workloadListOutput) => MAUI_WORKLOAD.test(workloadListOutput);
2431
+ var outputMentionsMauiTarget = (workloadListOutput, target) => {
2432
+ if (!target) return outputMentionsMaui(workloadListOutput);
2433
+ const targetWorkload = target === "macos" ? "maui-maccatalyst" : target === "windows" ? "maui-windows" : "maui-android";
2434
+ return new RegExp(
2435
+ `(?:\\[(?:maui|${targetWorkload})\\]|^\\s*(?:maui|${targetWorkload})\\s)`,
2436
+ "m"
2437
+ ).test(workloadListOutput);
2438
+ };
2276
2439
  var checkDotnetSdk = () => {
2277
2440
  const name = ".NET SDK";
2278
2441
  const res = run(DOTNET, ["--list-sdks"]);
@@ -2298,9 +2461,13 @@ var checkDotnetSdk = () => {
2298
2461
  fix: INSTALL_NET_10_FIX
2299
2462
  };
2300
2463
  };
2301
- var isMauiWorkloadInstalled = () => outputMentionsMaui(run(DOTNET, ["workload", "list"]).stdout);
2302
- var installWorkload = (csprojPath) => {
2303
- const args = csprojPath ? ["workload", "restore", csprojPath] : ["workload", "install", "maui"];
2464
+ var isMauiWorkloadInstalled = (target) => outputMentionsMauiTarget(
2465
+ run(DOTNET, ["workload", "list"]).stdout,
2466
+ target
2467
+ );
2468
+ var mauiWorkloadFor = (target) => target === "android" ? "maui-android" : target === "windows" ? "maui-windows" : target === "macos" ? "maui-maccatalyst" : "maui";
2469
+ var installWorkload = (csprojPath, target) => {
2470
+ const args = target ? ["workload", "install", mauiWorkloadFor(target)] : csprojPath ? ["workload", "restore", csprojPath] : ["workload", "install", "maui"];
2304
2471
  console.log();
2305
2472
  console.log(
2306
2473
  row({
@@ -2327,7 +2494,9 @@ var installWorkload = (csprojPath) => {
2327
2494
  )
2328
2495
  )
2329
2496
  );
2330
- console.error(fixLine("sudo dotnet workload install maui"));
2497
+ console.error(
2498
+ fixLine(`sudo dotnet workload install ${mauiWorkloadFor(target)}`)
2499
+ );
2331
2500
  console.error();
2332
2501
  return false;
2333
2502
  }
@@ -2349,7 +2518,7 @@ var ensureMauiWorkload = async (opts = {}) => {
2349
2518
  return false;
2350
2519
  }
2351
2520
  if (dotnet.status === "unknown") return true;
2352
- if (isMauiWorkloadInstalled()) return true;
2521
+ if (isMauiWorkloadInstalled(opts.target)) return true;
2353
2522
  console.log();
2354
2523
  console.log(
2355
2524
  row({
@@ -2373,7 +2542,7 @@ var ensureMauiWorkload = async (opts = {}) => {
2373
2542
  install = false;
2374
2543
  }
2375
2544
  if (install) {
2376
- if (installWorkload(opts.csprojPath) && isMauiWorkloadInstalled()) {
2545
+ if (installWorkload(opts.csprojPath, opts.target) && isMauiWorkloadInstalled(opts.target)) {
2377
2546
  console.log(
2378
2547
  row({
2379
2548
  glyph: "done",
@@ -2386,14 +2555,16 @@ var ensureMauiWorkload = async (opts = {}) => {
2386
2555
  return false;
2387
2556
  }
2388
2557
  }
2389
- console.log(fixLine("dotnet workload install maui", "run:"));
2558
+ console.log(
2559
+ fixLine(`dotnet workload install ${mauiWorkloadFor(opts.target)}`, "run:")
2560
+ );
2390
2561
  console.log(fixLine(MAUI_DOCS, "docs:"));
2391
2562
  return false;
2392
2563
  };
2393
2564
 
2394
2565
  // src/doctor.ts
2395
- import fs14 from "fs";
2396
- import path16 from "path";
2566
+ import fs15 from "fs";
2567
+ import path17 from "path";
2397
2568
  var matchesAny = (text, patterns) => patterns.some((pattern) => pattern.test(text));
2398
2569
  var COMMAND_LINE_TOOLS_PATH = /CommandLineTools/i;
2399
2570
  var MISSING_WORKLOAD_SIGNATURES = [
@@ -2401,6 +2572,7 @@ var MISSING_WORKLOAD_SIGNATURES = [
2401
2572
  /workloads?\s+must\s+be\s+installed/i,
2402
2573
  /maui-maccatalyst/i,
2403
2574
  /maui-windows/i,
2575
+ /maui-android/i,
2404
2576
  /to\s+install\s+the\s+.*workload/i
2405
2577
  ];
2406
2578
  var MISSING_XCODE_SIGNATURES = [
@@ -2415,7 +2587,7 @@ var OUTDATED_XCODE_SIGNATURES = [
2415
2587
  var looksLikeMissingWorkload = (output) => matchesAny(output, MISSING_WORKLOAD_SIGNATURES);
2416
2588
  var looksLikeMissingXcode = (output) => matchesAny(output, MISSING_XCODE_SIGNATURES);
2417
2589
  var looksLikeXcodeTooOld = (output) => matchesAny(output, OUTDATED_XCODE_SIGNATURES);
2418
- var checkMauiWorkload = (workloadList) => {
2590
+ var checkMauiWorkload = (workloadList, target) => {
2419
2591
  const name = ".NET MAUI workload";
2420
2592
  if (!workloadList) {
2421
2593
  return { name, status: "unknown", detail: "requires the .NET SDK first" };
@@ -2423,14 +2595,18 @@ var checkMauiWorkload = (workloadList) => {
2423
2595
  if (!workloadList.found) {
2424
2596
  return { name, status: "unknown", detail: "could not query workloads" };
2425
2597
  }
2426
- if (outputMentionsMaui(workloadList.stdout)) {
2598
+ const hasRequiredWorkload = outputMentionsMauiTarget(
2599
+ workloadList.stdout,
2600
+ target
2601
+ );
2602
+ if (hasRequiredWorkload) {
2427
2603
  return { name, status: "ok", detail: "installed" };
2428
2604
  }
2429
2605
  return {
2430
2606
  name,
2431
2607
  status: "missing",
2432
2608
  detail: "not installed",
2433
- fix: "dotnet workload install maui"
2609
+ fix: target === "android" ? "dotnet workload install maui-android" : "dotnet workload install maui"
2434
2610
  };
2435
2611
  };
2436
2612
  var FIRST_FIXED_MACCATALYST_PACK = [26, 2, 10233];
@@ -2463,20 +2639,20 @@ var macCatalystPackIsStale = (version) => {
2463
2639
  };
2464
2640
  var dotnetPacksDir = () => {
2465
2641
  if (process.env.DOTNET_ROOT) {
2466
- return path16.join(process.env.DOTNET_ROOT, "packs");
2642
+ return path17.join(process.env.DOTNET_ROOT, "packs");
2467
2643
  }
2468
2644
  const res = run(DOTNET, ["--list-sdks"]);
2469
2645
  if (!res.found) return void 0;
2470
2646
  const sdkDir = res.stdout.trim().split("\n").pop()?.match(/\[(.+)\]\s*$/)?.[1];
2471
- return sdkDir ? path16.join(path16.dirname(sdkDir), "packs") : void 0;
2647
+ return sdkDir ? path17.join(path17.dirname(sdkDir), "packs") : void 0;
2472
2648
  };
2473
2649
  var installedMacCatalystPackVersion = () => {
2474
2650
  const packs = dotnetPacksDir();
2475
2651
  if (!packs) return void 0;
2476
2652
  try {
2477
- const versions = fs14.readdirSync(packs, { withFileTypes: true }).filter((e) => e.isDirectory() && MACCATALYST_PACK_DIR.test(e.name)).flatMap((e) => {
2653
+ const versions = fs15.readdirSync(packs, { withFileTypes: true }).filter((e) => e.isDirectory() && MACCATALYST_PACK_DIR.test(e.name)).flatMap((e) => {
2478
2654
  try {
2479
- return fs14.readdirSync(path16.join(packs, e.name), { withFileTypes: true }).filter((v) => v.isDirectory()).map((v) => v.name);
2655
+ return fs15.readdirSync(path17.join(packs, e.name), { withFileTypes: true }).filter((v) => v.isDirectory()).map((v) => v.name);
2480
2656
  } catch {
2481
2657
  return [];
2482
2658
  }
@@ -2486,11 +2662,18 @@ var installedMacCatalystPackVersion = () => {
2486
2662
  return void 0;
2487
2663
  }
2488
2664
  };
2489
- var checkCSharpDevLoop = (workloadList) => {
2665
+ var checkCSharpDevLoop = (workloadList, target) => {
2490
2666
  const name = "C# dev loop";
2491
2667
  if (!workloadList) {
2492
2668
  return { name, status: "unknown", detail: "requires the .NET SDK first" };
2493
2669
  }
2670
+ if (target === "android") {
2671
+ return {
2672
+ name,
2673
+ status: "ok",
2674
+ detail: "C# edits rebuild, reinstall, and relaunch the Android app"
2675
+ };
2676
+ }
2494
2677
  if (process.platform !== "darwin") {
2495
2678
  return {
2496
2679
  name,
@@ -2640,6 +2823,61 @@ var checkVelopack = (required) => {
2640
2823
  fix: "dotnet tool install -g vpk"
2641
2824
  };
2642
2825
  };
2826
+ var checkAndroidSdk = () => {
2827
+ const sdk = process.env.ANDROID_SDK_ROOT ?? process.env.ANDROID_HOME;
2828
+ return sdk && fs15.existsSync(sdk) ? { name: "Android SDK", status: "ok", detail: sdk } : {
2829
+ name: "Android SDK",
2830
+ status: "missing",
2831
+ detail: "ANDROID_SDK_ROOT/ANDROID_HOME does not point to an installed SDK",
2832
+ fix: "install Android Studio command-line tools and set ANDROID_SDK_ROOT"
2833
+ };
2834
+ };
2835
+ var checkJdk17 = () => {
2836
+ const result = run("java", ["-version"]);
2837
+ const output = `${result.stdout}
2838
+ ${result.stderr}`;
2839
+ const major = Number(output.match(/version \"(?:1\\.)?(\\d+)/)?.[1]);
2840
+ return result.found && major >= 17 ? { name: "JDK", status: "ok", detail: `Java ${major}` } : {
2841
+ name: "JDK",
2842
+ status: "missing",
2843
+ detail: result.found ? "Java 17 or newer is required" : "java not found",
2844
+ fix: "install JDK 17 and set JAVA_HOME"
2845
+ };
2846
+ };
2847
+ var checkAdb = () => {
2848
+ const result = run("adb", ["devices"]);
2849
+ if (!result.found) {
2850
+ return {
2851
+ name: "adb",
2852
+ status: "missing",
2853
+ detail: "not found on PATH",
2854
+ fix: "add Android SDK platform-tools to PATH"
2855
+ };
2856
+ }
2857
+ const connected = result.stdout.split(/\r?\n/).slice(1).filter((line) => /\sdevice\s*$/.test(line)).length;
2858
+ return {
2859
+ name: "adb",
2860
+ status: connected > 0 ? "ok" : "unknown",
2861
+ detail: connected > 0 ? `${connected} device${connected === 1 ? "" : "s"} connected` : "installed; no emulator or device connected"
2862
+ };
2863
+ };
2864
+ var checkAndroidSigning = () => {
2865
+ try {
2866
+ const config = resolveAndroidSigningConfig();
2867
+ return config ? { name: "Android signing", status: "ok", detail: `${config.keyAlias} \xB7 ${config.keyStore}` } : {
2868
+ name: "Android signing",
2869
+ status: "unknown",
2870
+ detail: "not configured; required only for `vidra build --target android`",
2871
+ fix: "set VIDRA_ANDROID_KEYSTORE, VIDRA_ANDROID_KEY_ALIAS, VIDRA_ANDROID_KEY_PASSWORD, and VIDRA_ANDROID_STORE_PASSWORD"
2872
+ };
2873
+ } catch (error) {
2874
+ return {
2875
+ name: "Android signing",
2876
+ status: "missing",
2877
+ detail: error instanceof Error ? error.message : String(error)
2878
+ };
2879
+ }
2880
+ };
2643
2881
  var diagnoseUpdateConfiguration = (input) => {
2644
2882
  const { config } = input;
2645
2883
  if (!config) return [];
@@ -2677,31 +2915,40 @@ var diagnoseUpdateConfiguration = (input) => {
2677
2915
  });
2678
2916
  }
2679
2917
  if (feeds.app) {
2680
- if (mauiProgram !== null && !mauiProgram.includes(".UseVidraNativeUpdates(")) {
2681
- found.push({
2682
- name: "Native updates wired up",
2683
- status: "missing",
2684
- detail: "a feed is configured, but MauiProgram never calls .UseVidraNativeUpdates()",
2685
- fix: "add .UseVidraNativeUpdates() after .UseVidra() in MauiProgram.cs"
2686
- });
2687
- }
2688
- if (input.csproj !== null && !input.csproj.includes("Vidra.Updates.Native")) {
2918
+ if (input.target === "android") {
2689
2919
  found.push({
2690
- name: "Velopack package",
2920
+ name: "Android app updates",
2691
2921
  status: "missing",
2692
- detail: "the host project does not reference Vidra.Updates.Native, so there is no updater to run",
2693
- fix: '<PackageReference Include="Vidra.Updates.Native" Version="..." /> in the host .csproj'
2922
+ detail: "whole-app feeds are unsupported on Android; Google Play owns app updates",
2923
+ fix: "configure updates.feed.web only for Android builds"
2694
2924
  });
2695
- }
2696
- for (const [platform, source] of Object.entries(input.entryPoints)) {
2697
- if (!stripComments(source).includes("VelopackApp.Build(")) {
2925
+ } else {
2926
+ if (mauiProgram !== null && !mauiProgram.includes(".UseVidraNativeUpdates(")) {
2698
2927
  found.push({
2699
- name: `Velopack entry point (${platform})`,
2928
+ name: "Native updates wired up",
2700
2929
  status: "missing",
2701
- detail: `Platforms/${platform}/Program.cs never calls VelopackApp.Build()...Run(), so install and update hooks are ignored`,
2702
- fix: "VelopackApp.Build().UseVidraLocator().Run(); as the first line of Main"
2930
+ detail: "a feed is configured, but MauiProgram never calls .UseVidraNativeUpdates()",
2931
+ fix: "add .UseVidraNativeUpdates() after .UseVidra() in MauiProgram.cs"
2703
2932
  });
2704
2933
  }
2934
+ if (input.csproj !== null && !input.csproj.includes("Vidra.Updates.Native")) {
2935
+ found.push({
2936
+ name: "Velopack package",
2937
+ status: "missing",
2938
+ detail: "the host project does not reference Vidra.Updates.Native, so there is no updater to run",
2939
+ fix: '<PackageReference Include="Vidra.Updates.Native" Version="..." /> in the host .csproj'
2940
+ });
2941
+ }
2942
+ for (const [platform, source] of Object.entries(input.entryPoints)) {
2943
+ if (!stripComments(source).includes("VelopackApp.Build(")) {
2944
+ found.push({
2945
+ name: `Velopack entry point (${platform})`,
2946
+ status: "missing",
2947
+ detail: `Platforms/${platform}/Program.cs never calls VelopackApp.Build()...Run(), so install and update hooks are ignored`,
2948
+ fix: "VelopackApp.Build().UseVidraLocator().Run(); as the first line of Main"
2949
+ });
2950
+ }
2951
+ }
2705
2952
  }
2706
2953
  }
2707
2954
  if (input.publishedUnsigned && (config?.publicKeys?.length ?? 0) > 0) {
@@ -2718,29 +2965,29 @@ var stripComments = (source) => source.replace(/\/\*[\s\S]*?\*\//g, "").replace(
2718
2965
  var publishedFeeds = (projectRoot) => {
2719
2966
  const found = [];
2720
2967
  const walk = (dir, depth) => {
2721
- if (depth > 2 || !fs14.existsSync(dir)) return;
2722
- for (const entry of fs14.readdirSync(dir, { withFileTypes: true })) {
2723
- const full = path16.join(dir, entry.name);
2968
+ if (depth > 2 || !fs15.existsSync(dir)) return;
2969
+ for (const entry of fs15.readdirSync(dir, { withFileTypes: true })) {
2970
+ const full = path17.join(dir, entry.name);
2724
2971
  if (entry.isDirectory()) walk(full, depth + 1);
2725
2972
  else if (entry.name === "bundles.json") found.push(full);
2726
2973
  }
2727
2974
  };
2728
- walk(path16.join(projectRoot, "dist"), 0);
2975
+ walk(path17.join(projectRoot, "dist"), 0);
2729
2976
  return found;
2730
2977
  };
2731
- var inspectUpdateConfiguration = (config) => {
2978
+ var inspectUpdateConfiguration = (config, target) => {
2732
2979
  const project = tryDetectProject(process.cwd());
2733
2980
  if (!project) return [];
2734
2981
  if (!config) return [];
2735
2982
  const entryPoints = {};
2736
2983
  for (const platform of ["MacCatalyst", "Windows"]) {
2737
2984
  const source = readIfPresent(
2738
- path16.join(project.hostDir, "Platforms", platform, "Program.cs")
2985
+ path17.join(project.hostDir, "Platforms", platform, "Program.cs")
2739
2986
  );
2740
2987
  if (source !== null) entryPoints[platform] = source;
2741
2988
  }
2742
2989
  const publishedUnsigned = publishedFeeds(project.root).some(
2743
- (index) => !fs14.existsSync(`${index}.sig`)
2990
+ (index) => !fs15.existsSync(`${index}.sig`)
2744
2991
  );
2745
2992
  let nativeWanted = false;
2746
2993
  try {
@@ -2748,10 +2995,11 @@ var inspectUpdateConfiguration = (config) => {
2748
2995
  } catch {
2749
2996
  }
2750
2997
  return [
2751
- ...nativeWanted || resolveVpk() ? [checkVelopack(nativeWanted)] : [],
2998
+ ...target !== "android" && (nativeWanted || resolveVpk()) ? [checkVelopack(nativeWanted)] : [],
2752
2999
  ...diagnoseUpdateConfiguration({
2753
3000
  config,
2754
- mauiProgram: readIfPresent(path16.join(project.hostDir, "MauiProgram.cs")),
3001
+ target,
3002
+ mauiProgram: readIfPresent(path17.join(project.hostDir, "MauiProgram.cs")),
2755
3003
  csproj: readIfPresent(project.csprojPath),
2756
3004
  entryPoints,
2757
3005
  publishedUnsigned
@@ -2760,29 +3008,36 @@ var inspectUpdateConfiguration = (config) => {
2760
3008
  };
2761
3009
  var readIfPresent = (file) => {
2762
3010
  try {
2763
- return fs14.readFileSync(file, "utf-8");
3011
+ return fs15.readFileSync(file, "utf-8");
2764
3012
  } catch {
2765
3013
  return null;
2766
3014
  }
2767
3015
  };
2768
3016
  var collectRequirements = (opts = {}) => {
3017
+ const platformTarget = opts.target ?? (process.platform === "darwin" ? "macos" : process.platform === "win32" ? "windows" : "android");
2769
3018
  const dotnet = checkDotnetSdk();
2770
3019
  const workloadList = dotnet.status === "ok" ? run(DOTNET, ["workload", "list"]) : null;
2771
3020
  const reqs = [
2772
3021
  dotnet,
2773
- checkMauiWorkload(workloadList),
2774
- checkCSharpDevLoop(workloadList)
3022
+ checkMauiWorkload(workloadList, platformTarget),
3023
+ checkCSharpDevLoop(workloadList, platformTarget)
2775
3024
  ];
2776
- if (opts.includeXcode ?? process.platform === "darwin") {
3025
+ if (opts.includeXcode ?? platformTarget === "macos") {
2777
3026
  reqs.push(checkXcode());
2778
3027
  }
2779
- if (process.platform === "darwin") {
3028
+ if (platformTarget === "macos") {
2780
3029
  reqs.push(checkMacSigningIdentity(), checkNotarization());
2781
3030
  }
2782
- if (process.platform === "win32") {
3031
+ if (platformTarget === "windows") {
2783
3032
  reqs.push(checkWindowsSigning(), checkWebView2Runtime());
2784
3033
  }
2785
- const updateIssues = inspectUpdateConfiguration(opts.updateConfig ?? null);
3034
+ if (platformTarget === "android") {
3035
+ reqs.push(checkAndroidSdk(), checkJdk17(), checkAdb(), checkAndroidSigning());
3036
+ }
3037
+ const updateIssues = inspectUpdateConfiguration(
3038
+ opts.updateConfig ?? null,
3039
+ platformTarget
3040
+ );
2786
3041
  if (updateIssues.length > 0) {
2787
3042
  reqs.push(...updateIssues);
2788
3043
  }
@@ -2809,7 +3064,15 @@ var printRequirements = (reqs) => {
2809
3064
  }
2810
3065
  }
2811
3066
  };
2812
- var runDoctor = async () => {
3067
+ var runDoctor = async (argv = []) => {
3068
+ const args = parseArgs(["_", "_", ...argv]);
3069
+ if (rejectUnknownFlags(DOCTOR, args)) return 1;
3070
+ const defaultTarget = process.platform === "darwin" ? "macos" : process.platform === "win32" ? "windows" : "android";
3071
+ const target = args.target ?? defaultTarget;
3072
+ if (!["macos", "windows", "android"].includes(target)) {
3073
+ console.error(row({ glyph: "error", detail: dim(`unsupported target: ${target}`) }));
3074
+ return 1;
3075
+ }
2813
3076
  console.log();
2814
3077
  console.log(` ${lime("vidra")} ${value("doctor")}`);
2815
3078
  console.log();
@@ -2819,9 +3082,9 @@ var runDoctor = async () => {
2819
3082
  const updateConfig = project ? (await loadVidraConfig(project.root, {
2820
3083
  command: "doctor",
2821
3084
  mode: "development",
2822
- target: process.platform === "darwin" ? "macos" : process.platform === "win32" ? "windows" : null
3085
+ target
2823
3086
  })).updates : null;
2824
- const reqs = collectRequirements({ updateConfig });
3087
+ const reqs = collectRequirements({ updateConfig, target });
2825
3088
  printRequirements(reqs);
2826
3089
  console.log();
2827
3090
  const missing = reqs.filter((r) => r.status === "missing");
@@ -2895,10 +3158,11 @@ var printXcodeHint = () => {
2895
3158
  // src/commands/build.ts
2896
3159
  var TARGETS = {
2897
3160
  macos: macosTarget,
2898
- windows: windowsTarget
3161
+ windows: windowsTarget,
3162
+ android: androidTarget
2899
3163
  };
2900
- var packageLabel = (target) => target.name === "macos" ? "package DMG" : "package ZIP";
2901
- var artifactName = (project, target) => `${project.projectName}-${project.displayVersion}-${target.name}.${target.name === "macos" ? "dmg" : "zip"}`;
3164
+ var packageLabel = (target) => target.name === "macos" ? "package DMG" : target.name === "windows" ? "package ZIP" : "package APK/AAB";
3165
+ var artifactName = (project, target) => `${project.projectName}-${project.displayVersion}-${target.name}.${target.name === "macos" ? "dmg" : target.name === "windows" ? "zip" : "aab"}`;
2902
3166
  var parseBuildMode = (args) => args.app ? "app" : args.web ? "web" : "all";
2903
3167
  var resolveChannel = (flag, env = process.env) => {
2904
3168
  const raw = typeof flag === "string" ? flag : env.VIDRA_CHANNEL;
@@ -2992,7 +3256,7 @@ var buildCommand = async (argv) => {
2992
3256
  typeof args["sign"] === "string" ? args["sign"] : void 0
2993
3257
  );
2994
3258
  console.log();
2995
- console.log(footer(`${dim("done \u2014")} ${value(path17.relative(project.root, layout.web))}`));
3259
+ console.log(footer(`${dim("done \u2014")} ${value(path18.relative(project.root, layout.web))}`));
2996
3260
  console.log();
2997
3261
  return;
2998
3262
  }
@@ -3007,7 +3271,41 @@ var buildCommand = async (argv) => {
3007
3271
  console.log(kv("project", project.projectName));
3008
3272
  console.log(kv("target", appTarget.framework));
3009
3273
  console.log();
3010
- const nativeSettings = feeds.app && layout.app ? resolveNativeUpdateSettings({
3274
+ let androidSigning = null;
3275
+ if (appTarget.name === "android") {
3276
+ try {
3277
+ androidSigning = resolveAndroidSigningConfig();
3278
+ if (!androidSigning && !plan) {
3279
+ throw new Error(
3280
+ "Android release builds require a signing keystore \u2014 set VIDRA_ANDROID_KEYSTORE, VIDRA_ANDROID_KEY_ALIAS, VIDRA_ANDROID_KEY_PASSWORD, and VIDRA_ANDROID_STORE_PASSWORD"
3281
+ );
3282
+ }
3283
+ } catch (error) {
3284
+ console.error(
3285
+ row({
3286
+ glyph: "error",
3287
+ label: "android signing",
3288
+ labelWidth: STEP_LABEL_WIDTH,
3289
+ detail: dim(error instanceof Error ? error.message : String(error))
3290
+ })
3291
+ );
3292
+ process.exit(1);
3293
+ }
3294
+ }
3295
+ if (appTarget.name === "android" && feeds.app) {
3296
+ console.error(
3297
+ row({
3298
+ glyph: "error",
3299
+ label: "app updates",
3300
+ labelWidth: STEP_LABEL_WIDTH,
3301
+ detail: dim(
3302
+ "whole-app feeds are not supported on Android \u2014 publish the AAB through Google Play and configure a web-only feed"
3303
+ )
3304
+ })
3305
+ );
3306
+ process.exit(1);
3307
+ }
3308
+ const nativeSettings = appTarget.name !== "android" && feeds.app && layout.app ? resolveNativeUpdateSettings({
3011
3309
  feed: feeds.app,
3012
3310
  releaseDir: layout.app,
3013
3311
  csprojPath: project.csprojPath,
@@ -3044,13 +3342,21 @@ var buildCommand = async (argv) => {
3044
3342
  console.log();
3045
3343
  return;
3046
3344
  }
3047
- if (!await ensureMauiWorkload({ csprojPath: project.csprojPath })) {
3345
+ if (!await ensureMauiWorkload({
3346
+ csprojPath: project.csprojPath,
3347
+ target: appTarget.name
3348
+ })) {
3048
3349
  process.exit(1);
3049
3350
  }
3050
3351
  stepBuildUi2(project, verbose);
3051
3352
  stepCopyAssets(project);
3052
3353
  stepStampUpdateConfig(project, updateConfig, feeds, layout);
3053
- const publishDir = stepDotnetPublish(project, appTarget, verbose);
3354
+ const publishDir = stepDotnetPublish(
3355
+ project,
3356
+ appTarget,
3357
+ verbose,
3358
+ androidSigning ? androidPublishArgs(androidSigning) : void 0
3359
+ );
3054
3360
  const bundlePath = appTarget.findBundle(publishDir, project.projectName);
3055
3361
  if (!bundlePath) {
3056
3362
  console.error(
@@ -3088,12 +3394,32 @@ var buildCommand = async (argv) => {
3088
3394
  }
3089
3395
  const packed = nativeSettings ? stepNativeUpdate(project, appTarget, bundlePath, entitlements, nativeSettings, io) : null;
3090
3396
  const released = packed?.status === "packed" ? packed : null;
3091
- const outputPath = released && appTarget.name === "windows" ? stepPublishVelopackWindowsArtifacts(project, layout, appTarget, released) : await stepPackage(
3397
+ const outputPaths = released && appTarget.name === "windows" ? [stepPublishVelopackWindowsArtifacts(project, layout, appTarget, released)] : await stepPackage(
3092
3398
  project,
3093
3399
  layout,
3094
3400
  appTarget,
3095
3401
  released ? extractPackedApp(released.outputs.portableZip) : bundlePath
3096
3402
  );
3403
+ const outputPath = outputPaths[0];
3404
+ if (appTarget.name === "android") {
3405
+ for (const artifact of outputPaths) {
3406
+ const verification = verifyAndroidPackage(artifact);
3407
+ console.log(
3408
+ row({
3409
+ glyph: verification.ok ? "done" : "error",
3410
+ label: "verify sig",
3411
+ labelWidth: STEP_LABEL_WIDTH,
3412
+ detail: dim(
3413
+ verification.ok ? `${verification.tool} accepted ${path18.basename(artifact)}` : `${verification.tool} rejected ${path18.basename(artifact)}`
3414
+ )
3415
+ })
3416
+ );
3417
+ if (!verification.ok) {
3418
+ if (verification.output) console.error(dim(verification.output.trim()));
3419
+ process.exit(1);
3420
+ }
3421
+ }
3422
+ }
3097
3423
  if (appTarget.name === "macos") {
3098
3424
  signMacDmgIfPossible(outputPath, io);
3099
3425
  const notarized = notarizeAndStaple(outputPath, io);
@@ -3124,7 +3450,7 @@ var buildCommand = async (argv) => {
3124
3450
  console.log();
3125
3451
  console.log(
3126
3452
  footer(
3127
- `${dim("done \u2014")} ${value(path17.relative(project.root, outputPath))}`
3453
+ `${dim("done \u2014")} ${outputPaths.map((artifact) => value(path18.relative(project.root, artifact))).join(dim(" \xB7 "))}`
3128
3454
  )
3129
3455
  );
3130
3456
  console.log();
@@ -3137,7 +3463,7 @@ var stepWebBundle = async (project, outDir, feeds, config, sign) => {
3137
3463
  accessFingerprint: config.accessFingerprint,
3138
3464
  publicKeys: config.updates?.publicKeys,
3139
3465
  // In `all` mode the app half already ran Vite into the same `ui/dist`.
3140
- skipBuild: fs15.existsSync(path17.join(project.uiDir, "dist", "index.html"))
3466
+ skipBuild: fs16.existsSync(path18.join(project.uiDir, "dist", "index.html"))
3141
3467
  });
3142
3468
  };
3143
3469
  var printWebPlan = (project, outDir, feeds) => {
@@ -3162,13 +3488,13 @@ var printWebPlan = (project, outDir, feeds) => {
3162
3488
  glyph: "active",
3163
3489
  label: "pack bundle",
3164
3490
  labelWidth: STEP_LABEL_WIDTH,
3165
- detail: `${dim("\u2192")} ${value(path17.relative(project.root, outDir))}`
3491
+ detail: `${dim("\u2192")} ${value(path18.relative(project.root, outDir))}`
3166
3492
  })
3167
3493
  );
3168
3494
  };
3169
3495
  var entitlementsPath = (project) => {
3170
- const candidate = path17.join(project.hostDir, "Entitlements.plist");
3171
- return fs15.existsSync(candidate) ? candidate : null;
3496
+ const candidate = path18.join(project.hostDir, "Entitlements.plist");
3497
+ return fs16.existsSync(candidate) ? candidate : null;
3172
3498
  };
3173
3499
  var reportMacVerification = (bundlePath, entitlements) => {
3174
3500
  const verified = verifyMacSignature(bundlePath);
@@ -3265,7 +3591,7 @@ var printBuildPlan = (project, target, layout, feeds, nativeSettings, mode) => {
3265
3591
  label: "vpk pack",
3266
3592
  labelWidth: STEP_LABEL_WIDTH,
3267
3593
  detail: vpk ? `${value(`${nativeSettings.packId} ${nativeSettings.packVersion}`)} ${dim(
3268
- `\u2192 ${path17.relative(project.root, nativeSettings.releaseDir)}`
3594
+ `\u2192 ${path18.relative(project.root, nativeSettings.releaseDir)}`
3269
3595
  )}` : dim("vpk is not installed \u2014 dotnet tool install -g vpk")
3270
3596
  })
3271
3597
  );
@@ -3325,7 +3651,7 @@ var printBuildPlan = (project, target, layout, feeds, nativeSettings, mode) => {
3325
3651
  detail: dim("spctl --assess")
3326
3652
  })
3327
3653
  );
3328
- } else {
3654
+ } else if (target.name === "windows") {
3329
3655
  const winCert = resolveWindowsSigningConfig();
3330
3656
  console.log(
3331
3657
  row({
@@ -3355,6 +3681,26 @@ var printBuildPlan = (project, target, layout, feeds, nativeSettings, mode) => {
3355
3681
  })
3356
3682
  );
3357
3683
  }
3684
+ } else {
3685
+ const signing = resolveAndroidSigningConfig();
3686
+ console.log(
3687
+ row({
3688
+ glyph: signing ? "done" : "error",
3689
+ label: "android signing",
3690
+ labelWidth: STEP_LABEL_WIDTH,
3691
+ detail: dim(
3692
+ signing ? `${signing.keyAlias} \xB7 ${signing.keyStore}` : "keystore credentials are required for release"
3693
+ )
3694
+ })
3695
+ );
3696
+ console.log(
3697
+ row({
3698
+ glyph: "active",
3699
+ label: "package APK/AAB",
3700
+ labelWidth: STEP_LABEL_WIDTH,
3701
+ detail: `${dim("signed release \u2192")} ${value(artifactName(project, target))}`
3702
+ })
3703
+ );
3358
3704
  }
3359
3705
  };
3360
3706
  var stepBuildUi2 = (project, verbose) => {
@@ -3387,8 +3733,8 @@ var stepBuildUi2 = (project, verbose) => {
3387
3733
  );
3388
3734
  };
3389
3735
  var stepCopyAssets = (project) => {
3390
- const viteDist = path17.join(project.uiDir, "dist");
3391
- if (!fs15.existsSync(viteDist)) {
3736
+ const viteDist = path18.join(project.uiDir, "dist");
3737
+ if (!fs16.existsSync(viteDist)) {
3392
3738
  console.error(
3393
3739
  row({
3394
3740
  glyph: "error",
@@ -3399,9 +3745,9 @@ var stepCopyAssets = (project) => {
3399
3745
  );
3400
3746
  process.exit(1);
3401
3747
  }
3402
- const wwwroot = path17.join(project.hostDir, "Resources", "Raw", "wwwroot");
3403
- fs15.removeSync(wwwroot);
3404
- fs15.copySync(viteDist, wwwroot);
3748
+ const wwwroot = path18.join(project.hostDir, "Resources", "Raw", "wwwroot");
3749
+ fs16.removeSync(wwwroot);
3750
+ fs16.copySync(viteDist, wwwroot);
3405
3751
  const fileCount = countFiles(wwwroot);
3406
3752
  console.log(
3407
3753
  row({
@@ -3436,33 +3782,43 @@ var stepStampUpdateConfig = (project, config, feeds, layout) => {
3436
3782
  glyph: "plan",
3437
3783
  label: `${name} feed`,
3438
3784
  labelWidth: STEP_LABEL_WIDTH,
3439
- detail: `${value(path17.relative(project.root, dir))} ${dim("\u2192")} ${value(feed.base)}`
3785
+ detail: `${value(path18.relative(project.root, dir))} ${dim("\u2192")} ${value(feed.base)}`
3440
3786
  })
3441
3787
  );
3442
3788
  }
3443
3789
  };
3444
3790
  var countFiles = (dir) => {
3445
3791
  let count = 0;
3446
- for (const entry of fs15.readdirSync(dir, { withFileTypes: true })) {
3792
+ for (const entry of fs16.readdirSync(dir, { withFileTypes: true })) {
3447
3793
  if (entry.isDirectory()) {
3448
- count += countFiles(path17.join(dir, entry.name));
3794
+ count += countFiles(path18.join(dir, entry.name));
3449
3795
  } else {
3450
3796
  count++;
3451
3797
  }
3452
3798
  }
3453
3799
  return count;
3454
3800
  };
3455
- var stepDotnetPublish = (project, target, verbose) => {
3801
+ var stepDotnetPublish = (project, target, verbose, publishArgsOverride) => {
3456
3802
  const start = Date.now();
3457
- const extraArgs = target.extraPublishArgs ?? "-p:CreatePackage=false";
3803
+ const extraArgs = publishArgsOverride ?? target.extraPublishArgs ?? ["-p:CreatePackage=false"];
3458
3804
  const version = resolveAppVersion(project.root, project.csprojPath);
3459
- const versionArgs = versionPublishArgs(version).join(" ");
3460
3805
  try {
3461
- execSync4(
3462
- `dotnet publish "${project.csprojPath}" -c Release -f ${target.framework} ${extraArgs} ${versionArgs}`,
3806
+ execFileSync9(
3807
+ "dotnet",
3808
+ [
3809
+ "publish",
3810
+ project.csprojPath,
3811
+ "-c",
3812
+ "Release",
3813
+ "-f",
3814
+ target.framework,
3815
+ ...extraArgs,
3816
+ ...versionPublishArgs(version)
3817
+ ],
3463
3818
  {
3464
3819
  cwd: project.root,
3465
- stdio: verbose ? "inherit" : "pipe"
3820
+ stdio: verbose ? "inherit" : "pipe",
3821
+ maxBuffer: 64 * 1024 * 1024
3466
3822
  }
3467
3823
  );
3468
3824
  } catch (e) {
@@ -3492,7 +3848,7 @@ var stepDotnetPublish = (project, target, verbose) => {
3492
3848
  detail: `${dim("Release \xB7")} ${value(target.framework)} ${dim(`(${elapsed}s)`)}`
3493
3849
  })
3494
3850
  );
3495
- return path17.join(project.hostDir, "bin", "Release", target.framework);
3851
+ return path18.join(project.hostDir, "bin", "Release", target.framework);
3496
3852
  };
3497
3853
  var stepNativeUpdate = (project, target, packDir, entitlements, settings, io) => {
3498
3854
  const start = Date.now();
@@ -3534,7 +3890,7 @@ var stepNativeUpdate = (project, target, packDir, entitlements, settings, io) =>
3534
3890
  glyph: "done",
3535
3891
  label: "merge feed",
3536
3892
  labelWidth: STEP_LABEL_WIDTH,
3537
- detail: `${dim("vpk download \u2192")} ${value(path17.relative(project.root, settings.releaseDir))}`
3893
+ detail: `${dim("vpk download \u2192")} ${value(path18.relative(project.root, settings.releaseDir))}`
3538
3894
  })
3539
3895
  );
3540
3896
  }
@@ -3561,7 +3917,7 @@ var stepNativeUpdate = (project, target, packDir, entitlements, settings, io) =>
3561
3917
  label: "vpk pack",
3562
3918
  labelWidth: STEP_LABEL_WIDTH,
3563
3919
  detail: `${value(`${settings.packId} ${settings.packVersion}`)} ${dim(
3564
- `\u2192 ${path17.relative(project.root, settings.releaseDir)} (${elapsed}s)`
3920
+ `\u2192 ${path18.relative(project.root, settings.releaseDir)} (${elapsed}s)`
3565
3921
  )}`
3566
3922
  })
3567
3923
  );
@@ -3580,23 +3936,23 @@ var stepNativeUpdate = (project, target, packDir, entitlements, settings, io) =>
3580
3936
  };
3581
3937
  var stepPublishVelopackWindowsArtifacts = (project, layout, target, packed) => {
3582
3938
  const outputDir = layout.root;
3583
- fs15.ensureDirSync(outputDir);
3584
- const zipPath = path17.join(outputDir, artifactName(project, target));
3585
- fs15.copySync(packed.outputs.portableZip, zipPath, { overwrite: true });
3939
+ fs16.ensureDirSync(outputDir);
3940
+ const zipPath = path18.join(outputDir, artifactName(project, target));
3941
+ fs16.copySync(packed.outputs.portableZip, zipPath, { overwrite: true });
3586
3942
  console.log(
3587
3943
  row({
3588
3944
  glyph: "done",
3589
3945
  label: packageLabel(target),
3590
3946
  labelWidth: STEP_LABEL_WIDTH,
3591
- detail: `${value(path17.basename(zipPath))} ${dim(
3592
- `(${(fs15.statSync(zipPath).size / (1024 * 1024)).toFixed(1)} MB, from vpk)`
3947
+ detail: `${value(path18.basename(zipPath))} ${dim(
3948
+ `(${(fs16.statSync(zipPath).size / (1024 * 1024)).toFixed(1)} MB, from vpk)`
3593
3949
  )}`
3594
3950
  })
3595
3951
  );
3596
3952
  if (packed.outputs.setupExe) {
3597
3953
  const setupName = `${project.projectName}-${project.displayVersion}-Setup.exe`;
3598
- const setupPath = path17.join(outputDir, setupName);
3599
- fs15.copySync(packed.outputs.setupExe, setupPath, { overwrite: true });
3954
+ const setupPath = path18.join(outputDir, setupName);
3955
+ fs16.copySync(packed.outputs.setupExe, setupPath, { overwrite: true });
3600
3956
  console.log(
3601
3957
  row({
3602
3958
  glyph: "done",
@@ -3610,13 +3966,16 @@ var stepPublishVelopackWindowsArtifacts = (project, layout, target, packed) => {
3610
3966
  };
3611
3967
  var stepPackage = async (project, layout, target, bundlePath) => {
3612
3968
  const outputDir = layout.root;
3613
- fs15.ensureDirSync(outputDir);
3969
+ fs16.ensureDirSync(outputDir);
3614
3970
  const start = Date.now();
3615
- let outputPath;
3971
+ let outputPaths;
3616
3972
  try {
3617
- outputPath = await target.package(bundlePath, outputDir, {
3973
+ const version = resolveAppVersion(project.root, project.csprojPath);
3974
+ outputPaths = await target.package(bundlePath, outputDir, {
3618
3975
  projectName: project.projectName,
3619
- displayVersion: project.displayVersion
3976
+ displayVersion: project.displayVersion,
3977
+ buildNumber: version.build,
3978
+ projectRoot: project.root
3620
3979
  });
3621
3980
  } catch (e) {
3622
3981
  console.error(
@@ -3631,38 +3990,40 @@ var stepPackage = async (project, layout, target, bundlePath) => {
3631
3990
  process.exit(1);
3632
3991
  }
3633
3992
  const pkgTime = ((Date.now() - start) / 1e3).toFixed(1);
3634
- const sizeMB = (fs15.statSync(outputPath).size / (1024 * 1024)).toFixed(1);
3635
- console.log(
3636
- row({
3637
- glyph: "done",
3638
- label: packageLabel(target),
3639
- labelWidth: STEP_LABEL_WIDTH,
3640
- detail: `${value(path17.basename(outputPath))} ${dim(`(${sizeMB} MB, ${pkgTime}s)`)}`
3641
- })
3642
- );
3643
- return outputPath;
3993
+ for (const [index, outputPath] of outputPaths.entries()) {
3994
+ const sizeMB = (fs16.statSync(outputPath).size / (1024 * 1024)).toFixed(1);
3995
+ console.log(
3996
+ row({
3997
+ glyph: "done",
3998
+ label: index === 0 ? packageLabel(target) : "",
3999
+ labelWidth: STEP_LABEL_WIDTH,
4000
+ detail: `${value(path18.basename(outputPath))} ${dim(`(${sizeMB} MB, ${pkgTime}s)`)}`
4001
+ })
4002
+ );
4003
+ }
4004
+ return outputPaths;
3644
4005
  };
3645
4006
 
3646
4007
  // src/commands/keygen.ts
3647
- import fs16 from "fs";
3648
- import path18 from "path";
4008
+ import fs17 from "fs";
4009
+ import path19 from "path";
3649
4010
  var writeSigningKeyPair = (out, force) => {
3650
- if (fs16.existsSync(out) && !force) return null;
4011
+ if (fs17.existsSync(out) && !force) return null;
3651
4012
  const { privateKeyPem, publicKey, keyId } = generateKeyPair();
3652
- fs16.writeFileSync(out, privateKeyPem, { mode: 384 });
4013
+ fs17.writeFileSync(out, privateKeyPem, { mode: 384 });
3653
4014
  try {
3654
- fs16.chmodSync(out, 384);
4015
+ fs17.chmodSync(out, 384);
3655
4016
  } catch {
3656
4017
  }
3657
4018
  const publicKeyPath = `${out}.pub`;
3658
- fs16.writeFileSync(publicKeyPath, `${publicKey}
4019
+ fs17.writeFileSync(publicKeyPath, `${publicKey}
3659
4020
  `);
3660
4021
  return { publicKey, keyId, privateKeyPath: out, publicKeyPath };
3661
4022
  };
3662
4023
  var keygenCommand = async (argv) => {
3663
4024
  const args = parseArgs(["_", "_", ...argv]);
3664
4025
  if (rejectUnknownFlags(KEYGEN, args)) return process.exit(1);
3665
- const out = path18.resolve(
4026
+ const out = path19.resolve(
3666
4027
  typeof args.out === "string" ? args.out : "vidra-signing-key.pem"
3667
4028
  );
3668
4029
  const force = !!args.force;
@@ -3675,7 +4036,7 @@ var keygenCommand = async (argv) => {
3675
4036
  label: "write key",
3676
4037
  labelWidth: STEP_LABEL_WIDTH,
3677
4038
  detail: dim(
3678
- `${path18.basename(out)} already exists \u2014 apps trusting it could not install updates signed by a new key. Pass --force only if you mean to replace it.`
4039
+ `${path19.basename(out)} already exists \u2014 apps trusting it could not install updates signed by a new key. Pass --force only if you mean to replace it.`
3679
4040
  )
3680
4041
  })
3681
4042
  );
@@ -3687,7 +4048,7 @@ var keygenCommand = async (argv) => {
3687
4048
  glyph: "done",
3688
4049
  label: "private key",
3689
4050
  labelWidth: STEP_LABEL_WIDTH,
3690
- detail: `${value(path18.relative(process.cwd(), out) || out)} ${dim(`(key ${keyId})`)}`
4051
+ detail: `${value(path19.relative(process.cwd(), out) || out)} ${dim(`(key ${keyId})`)}`
3691
4052
  })
3692
4053
  );
3693
4054
  console.log(
@@ -3695,7 +4056,7 @@ var keygenCommand = async (argv) => {
3695
4056
  glyph: "done",
3696
4057
  label: "public key",
3697
4058
  labelWidth: STEP_LABEL_WIDTH,
3698
- detail: `${value(path18.relative(process.cwd(), publicKeyPath) || publicKeyPath)} ${dim("\u2014 add it to vidra.config.ts:")}`
4059
+ detail: `${value(path19.relative(process.cwd(), publicKeyPath) || publicKeyPath)} ${dim("\u2014 add it to vidra.config.ts:")}`
3699
4060
  })
3700
4061
  );
3701
4062
  console.log();
@@ -3727,7 +4088,7 @@ var keygenCommand = async (argv) => {
3727
4088
  };
3728
4089
 
3729
4090
  // src/commands/updates.ts
3730
- import path19 from "path";
4091
+ import path20 from "path";
3731
4092
  var updatesCommand = async (argv) => {
3732
4093
  const args = parseArgs(["_", "_", ...argv]);
3733
4094
  if (rejectUnknownFlags(UPDATES, args)) return process.exit(1);
@@ -3844,7 +4205,7 @@ var initUpdates = async (args) => {
3844
4205
  console.log();
3845
4206
  };
3846
4207
  var signWithNewKey = (projectRoot, force) => {
3847
- const out = path19.join(projectRoot, "vidra-signing-key.pem");
4208
+ const out = path20.join(projectRoot, "vidra-signing-key.pem");
3848
4209
  const key = writeSigningKeyPair(out, force);
3849
4210
  if (!key) {
3850
4211
  console.log(
@@ -3922,7 +4283,7 @@ var printStatus = async () => {
3922
4283
  var configContext = () => ({
3923
4284
  command: "updates",
3924
4285
  mode: "production",
3925
- target: process.platform === "darwin" ? "macos" : process.platform === "win32" ? "windows" : null
4286
+ target: process.platform === "darwin" ? "macos" : process.platform === "win32" ? "windows" : "android"
3926
4287
  });
3927
4288
  var feedRow = (label, base, off) => {
3928
4289
  console.log(
@@ -3936,46 +4297,46 @@ var feedRow = (label, base, off) => {
3936
4297
  };
3937
4298
 
3938
4299
  // src/commands/verify.ts
3939
- import path21 from "path";
3940
- import fs18 from "fs-extra";
4300
+ import path22 from "path";
4301
+ import fs19 from "fs-extra";
3941
4302
 
3942
4303
  // src/artifacts.ts
3943
- import path20 from "path";
4304
+ import path21 from "path";
3944
4305
  import os5 from "os";
3945
- import fs17 from "fs-extra";
3946
- import { execFileSync as execFileSync9 } from "child_process";
4306
+ import fs18 from "fs-extra";
4307
+ import { execFileSync as execFileSync10 } from "child_process";
3947
4308
  var findAppBundle2 = (dir) => {
3948
- if (!fs17.existsSync(dir)) return null;
3949
- for (const entry of fs17.readdirSync(dir, { withFileTypes: true })) {
4309
+ if (!fs18.existsSync(dir)) return null;
4310
+ for (const entry of fs18.readdirSync(dir, { withFileTypes: true })) {
3950
4311
  if (entry.name.endsWith(".app") && entry.isDirectory()) {
3951
- return path20.join(dir, entry.name);
4312
+ return path21.join(dir, entry.name);
3952
4313
  }
3953
4314
  }
3954
4315
  return null;
3955
4316
  };
3956
4317
  var findWindowsExecutable = (dir, projectName) => {
3957
- if (!fs17.existsSync(dir)) return null;
3958
- const exes = fs17.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isFile() && e.name.toLowerCase().endsWith(".exe")).map((e) => e.name);
4318
+ if (!fs18.existsSync(dir)) return null;
4319
+ const exes = fs18.readdirSync(dir, { withFileTypes: true }).filter((e) => e.isFile() && e.name.toLowerCase().endsWith(".exe")).map((e) => e.name);
3959
4320
  const wanted = projectName?.toLowerCase();
3960
4321
  const preferred = wanted && exes.find((n) => n.toLowerCase() === `${wanted}.host.exe`) || wanted && exes.find((n) => n.toLowerCase().startsWith(wanted)) || exes.find((n) => n.toLowerCase().endsWith(".host.exe")) || exes.find((n) => n.toLowerCase() !== "createdump.exe");
3961
- return preferred ? path20.join(dir, preferred) : null;
4322
+ return preferred ? path21.join(dir, preferred) : null;
3962
4323
  };
3963
4324
  var findWindowsExecutableRecursive = (root, projectName) => {
3964
4325
  const direct = findWindowsExecutable(root, projectName);
3965
4326
  if (direct) return direct;
3966
- if (!fs17.existsSync(root)) return null;
3967
- for (const entry of fs17.readdirSync(root, { withFileTypes: true })) {
4327
+ if (!fs18.existsSync(root)) return null;
4328
+ for (const entry of fs18.readdirSync(root, { withFileTypes: true })) {
3968
4329
  if (!entry.isDirectory()) continue;
3969
- const found = findWindowsExecutableRecursive(path20.join(root, entry.name), projectName);
4330
+ const found = findWindowsExecutableRecursive(path21.join(root, entry.name), projectName);
3970
4331
  if (found) return found;
3971
4332
  }
3972
4333
  return null;
3973
4334
  };
3974
4335
  var extractArchive = (zipPath) => {
3975
- const dir = fs17.mkdtempSync(path20.join(os5.tmpdir(), "vidra-zip-"));
4336
+ const dir = fs18.mkdtempSync(path21.join(os5.tmpdir(), "vidra-zip-"));
3976
4337
  try {
3977
4338
  if (process.platform === "win32") {
3978
- execFileSync9(
4339
+ execFileSync10(
3979
4340
  "powershell",
3980
4341
  [
3981
4342
  "-NoProfile",
@@ -3985,17 +4346,17 @@ var extractArchive = (zipPath) => {
3985
4346
  { stdio: "pipe" }
3986
4347
  );
3987
4348
  } else {
3988
- execFileSync9("unzip", ["-q", "-o", zipPath, "-d", dir], { stdio: "pipe" });
4349
+ execFileSync10("unzip", ["-q", "-o", zipPath, "-d", dir], { stdio: "pipe" });
3989
4350
  }
3990
4351
  } catch (error) {
3991
- fs17.removeSync(dir);
4352
+ fs18.removeSync(dir);
3992
4353
  throw error;
3993
4354
  }
3994
- return { dir, release: () => fs17.removeSync(dir) };
4355
+ return { dir, release: () => fs18.removeSync(dir) };
3995
4356
  };
3996
4357
  var mountDiskImage = (dmgPath) => {
3997
- const mountPoint = fs17.mkdtempSync(path20.join(os5.tmpdir(), "vidra-dmg-mount-"));
3998
- execFileSync9(
4358
+ const mountPoint = fs18.mkdtempSync(path21.join(os5.tmpdir(), "vidra-dmg-mount-"));
4359
+ execFileSync10(
3999
4360
  "hdiutil",
4000
4361
  ["attach", dmgPath, "-mountpoint", mountPoint, "-nobrowse", "-quiet"],
4001
4362
  { stdio: "pipe" }
@@ -4004,10 +4365,10 @@ var mountDiskImage = (dmgPath) => {
4004
4365
  mountPoint,
4005
4366
  release: () => {
4006
4367
  try {
4007
- execFileSync9("hdiutil", ["detach", mountPoint, "-quiet"], { stdio: "pipe" });
4368
+ execFileSync10("hdiutil", ["detach", mountPoint, "-quiet"], { stdio: "pipe" });
4008
4369
  } catch {
4009
4370
  }
4010
- fs17.removeSync(mountPoint);
4371
+ fs18.removeSync(mountPoint);
4011
4372
  }
4012
4373
  };
4013
4374
  };
@@ -4027,16 +4388,17 @@ var verifyCommand = async (argv) => {
4027
4388
  );
4028
4389
  process.exit(1);
4029
4390
  }
4030
- if (!fs18.existsSync(artifact)) {
4391
+ if (!fs19.existsSync(artifact)) {
4031
4392
  console.error();
4032
4393
  console.error(row({ glyph: "error", detail: dim(`not found: ${artifact}`) }));
4033
4394
  process.exit(1);
4034
4395
  }
4035
4396
  console.log();
4036
- console.log(header("verify", path21.basename(artifact)));
4397
+ console.log(header("verify", path22.basename(artifact)));
4037
4398
  console.log(kv("artifact", artifact));
4038
4399
  console.log();
4039
- const failures = artifactKind(artifact) === "macos" ? verifyMacArtifact(artifact) : verifyWindowsArtifact(artifact);
4400
+ const kind = artifactKind(artifact);
4401
+ const failures = kind === "macos" ? verifyMacArtifact(artifact) : kind === "android" ? verifyAndroidArtifact(artifact) : verifyWindowsArtifact(artifact);
4040
4402
  console.log();
4041
4403
  if (failures.length > 0) {
4042
4404
  console.log(
@@ -4050,8 +4412,19 @@ var verifyCommand = async (argv) => {
4050
4412
  };
4051
4413
  var artifactKind = (artifact) => {
4052
4414
  if (artifact.endsWith(".dmg") || artifact.endsWith(".app")) return "macos";
4415
+ if (artifact.endsWith(".apk") || artifact.endsWith(".aab")) return "android";
4053
4416
  return "windows";
4054
4417
  };
4418
+ var verifyAndroidArtifact = (artifact) => {
4419
+ const result = verifyAndroidPackage(artifact);
4420
+ report(
4421
+ result.ok,
4422
+ "android signature",
4423
+ result.ok ? `${result.tool} verification passed` : `${result.tool} verification failed`,
4424
+ result.output
4425
+ );
4426
+ return result.ok ? [] : ["android signature"];
4427
+ };
4055
4428
  var verifyMacArtifact = (artifact) => {
4056
4429
  const failures = [];
4057
4430
  let appBundle = artifact;
@@ -4114,7 +4487,7 @@ var verifyWindowsArtifact = (artifact) => {
4114
4487
  extracted = archive;
4115
4488
  searchRoot = archive.dir;
4116
4489
  } catch (error) {
4117
- report(false, "archive", `could not open ${path21.basename(artifact)}`, String(error));
4490
+ report(false, "archive", `could not open ${path22.basename(artifact)}`, String(error));
4118
4491
  return ["archive"];
4119
4492
  }
4120
4493
  }
@@ -4124,7 +4497,7 @@ var verifyWindowsArtifact = (artifact) => {
4124
4497
  report(false, "executable", `no .exe found under ${artifact}`);
4125
4498
  return ["executable"];
4126
4499
  }
4127
- console.log(kv("executable", path21.basename(exe)));
4500
+ console.log(kv("executable", path22.basename(exe)));
4128
4501
  const sig = verifyWindowsSignature(exe);
4129
4502
  report(
4130
4503
  sig.ok,
@@ -4151,17 +4524,19 @@ var report = (ok, label, detail, output) => {
4151
4524
  };
4152
4525
  var discoverArtifact = () => {
4153
4526
  const project = detectProject(process.cwd());
4154
- const dist = path21.join(project.root, "dist");
4155
- if (!fs18.existsSync(dist)) return null;
4156
- const wanted = detectPlatform() === "windows" ? ".zip" : ".dmg";
4157
- const candidates = fs18.readdirSync(dist).filter((f) => f.endsWith(wanted)).map((f) => path21.join(dist, f)).sort((a, b) => fs18.statSync(b).mtimeMs - fs18.statSync(a).mtimeMs);
4527
+ const dist = path22.join(project.root, "dist");
4528
+ if (!fs19.existsSync(dist)) return null;
4529
+ const platform = detectPlatform();
4530
+ const wanted = platform === "windows" ? [".zip"] : platform === "android" ? [".aab", ".apk"] : [".dmg"];
4531
+ const candidates = fs19.readdirSync(dist).filter((file) => wanted.some((extension) => file.endsWith(extension))).map((f) => path22.join(dist, f)).sort((a, b) => fs19.statSync(b).mtimeMs - fs19.statSync(a).mtimeMs);
4158
4532
  return candidates[0] ?? null;
4159
4533
  };
4160
4534
 
4161
4535
  // src/commands/dev.ts
4162
- import path22 from "path";
4163
- import fs19 from "fs-extra";
4164
- import { execFileSync as execFileSync10, spawn as spawn2 } from "child_process";
4536
+ import path23 from "path";
4537
+ import os6 from "os";
4538
+ import fs20 from "fs-extra";
4539
+ import { execFileSync as execFileSync11, spawn as spawn2 } from "child_process";
4165
4540
  import { request } from "http";
4166
4541
 
4167
4542
  // src/dev-port.ts
@@ -4254,6 +4629,10 @@ var TARGETS2 = {
4254
4629
  windows: {
4255
4630
  name: "windows",
4256
4631
  framework: "net10.0-windows10.0.19041.0"
4632
+ },
4633
+ android: {
4634
+ name: "android",
4635
+ framework: "net10.0-android"
4257
4636
  }
4258
4637
  };
4259
4638
  var devCommand = (argv) => startSession(argv, { vite: true, hotReloadDefault: true });
@@ -4284,7 +4663,10 @@ var startSession = async (argv, opts) => {
4284
4663
  });
4285
4664
  writeBridgePolicy(project.hostDir, loadedConfig);
4286
4665
  writeFrontendAccessFingerprint(project.uiDir, loadedConfig.accessFingerprint);
4287
- if (!await ensureMauiWorkload({ csprojPath: project.csprojPath })) {
4666
+ if (!await ensureMauiWorkload({
4667
+ csprojPath: project.csprojPath,
4668
+ target: target.name
4669
+ })) {
4288
4670
  process.exit(1);
4289
4671
  }
4290
4672
  if (opts.vite) {
@@ -4295,8 +4677,8 @@ var startSession = async (argv, opts) => {
4295
4677
  hotReload
4296
4678
  });
4297
4679
  let reloadTimer;
4298
- const configWatcher = fs19.watch(project.root, (_event, filename) => {
4299
- if (filename && path22.basename(filename.toString()) !== VIDRA_CONFIG_FILE) {
4680
+ const configWatcher = fs20.watch(project.root, (_event, filename) => {
4681
+ if (filename && path23.basename(filename.toString()) !== VIDRA_CONFIG_FILE) {
4300
4682
  return;
4301
4683
  }
4302
4684
  clearTimeout(reloadTimer);
@@ -4313,12 +4695,7 @@ var startSession = async (argv, opts) => {
4313
4695
  next.accessFingerprint
4314
4696
  );
4315
4697
  if (policyWrite.changed) {
4316
- console.log(row({
4317
- glyph: "done",
4318
- detail: dim(
4319
- "vidra.config.ts updated \u2014 dotnet watch is rebuilding and relaunching the host"
4320
- )
4321
- }));
4698
+ await session.restartHostForBridgePolicyChange();
4322
4699
  } else if (frontendWrite.changed) {
4323
4700
  console.log(row({
4324
4701
  glyph: "done",
@@ -4340,7 +4717,7 @@ var startSession = async (argv, opts) => {
4340
4717
  configWatcher.close();
4341
4718
  }
4342
4719
  };
4343
- var watchStrategyFor = (_targetName) => "delta";
4720
+ var watchStrategyFor = (targetName) => targetName === "android" ? "rebuild" : "delta";
4344
4721
  var DELTA_CHANNEL_DEAD_WARNING = "further changes won't be applied to this process";
4345
4722
  var buildDotnetWatchArgs = (opts) => [
4346
4723
  "watch",
@@ -4368,13 +4745,14 @@ var dotnetWatchEnv = (devUrl) => ({
4368
4745
  // SDK silently breaks the dev loop for everyone whose machine isn't English.
4369
4746
  DOTNET_CLI_UI_LANGUAGE: "en"
4370
4747
  });
4371
- var buildViteArgs = (devUrl) => [
4748
+ var buildViteArgs = (devUrl, exposeNetwork = false) => [
4372
4749
  "run",
4373
4750
  "dev",
4374
4751
  "--",
4375
4752
  "--port",
4376
4753
  new URL(devUrl).port,
4377
- "--strictPort"
4754
+ "--strictPort",
4755
+ ...exposeNetwork ? ["--host", "0.0.0.0"] : []
4378
4756
  ];
4379
4757
  var HOST_READY_SENTINEL = "[vidra] host ready";
4380
4758
  var classifyWatchLine = (line) => {
@@ -4427,6 +4805,7 @@ var DevSession = class {
4427
4805
  viteUrl;
4428
4806
  verbose;
4429
4807
  children = [];
4808
+ watchChildren = /* @__PURE__ */ new Set();
4430
4809
  buildConfig = process.env.VIDRA_BUILD_CONFIG || "Debug";
4431
4810
  vite;
4432
4811
  hotReload;
@@ -4447,7 +4826,10 @@ var DevSession = class {
4447
4826
  hostChild;
4448
4827
  relaunching = false;
4449
4828
  relaunchPending = false;
4829
+ restartingWatch = false;
4830
+ watchRestartPending = false;
4450
4831
  fellBackToClassic = false;
4832
+ androidSerial;
4451
4833
  endSession = () => {
4452
4834
  };
4453
4835
  sessionDone = new Promise((resolve) => {
@@ -4496,7 +4878,7 @@ var DevSession = class {
4496
4878
  );
4497
4879
  }
4498
4880
  this.launchHost();
4499
- const hostDirLabel = `src/${path22.basename(this.project.hostDir)}`;
4881
+ const hostDirLabel = `src/${path23.basename(this.project.hostDir)}`;
4500
4882
  if (this.vite) {
4501
4883
  console.log(
4502
4884
  taggedRow(
@@ -4535,18 +4917,24 @@ var DevSession = class {
4535
4917
  }
4536
4918
  startVite() {
4537
4919
  console.log(taggedRow("active", "ui", dim("starting dev server\u2026")));
4538
- const vite = spawn2(NPM_COMMAND, buildViteArgs(this.viteUrl), {
4539
- cwd: this.project.uiDir,
4540
- stdio: ["ignore", "pipe", "pipe"],
4541
- shell: process.platform === "win32"
4542
- });
4920
+ const vite = spawn2(
4921
+ NPM_COMMAND,
4922
+ buildViteArgs(this.viteUrl, this.target.name === "android"),
4923
+ {
4924
+ cwd: this.project.uiDir,
4925
+ stdio: ["ignore", "pipe", "pipe"],
4926
+ shell: process.platform === "win32"
4927
+ }
4928
+ );
4543
4929
  return this.registerChild(vite, "ui", "Vite dev server");
4544
4930
  }
4545
4931
  launchHost() {
4546
4932
  if (this.hotReload) {
4547
4933
  return this.launchHostWithWatch();
4548
4934
  }
4549
- return this.target.name === "macos" ? this.launchMacosHost() : this.launchWindowsHost();
4935
+ if (this.target.name === "macos") return this.launchMacosHost();
4936
+ if (this.target.name === "windows") return this.launchWindowsHost();
4937
+ return this.launchAndroidHost();
4550
4938
  }
4551
4939
  // --- dotnet watch launch (C# hot reload) -----------------------------------
4552
4940
  launchHostWithWatch() {
@@ -4578,15 +4966,19 @@ var DevSession = class {
4578
4966
  );
4579
4967
  this.watchChild = watch;
4580
4968
  this.children.push(watch);
4969
+ this.watchChildren.add(watch);
4581
4970
  const notSentinel = (line) => !line.includes(HOST_READY_SENTINEL);
4582
4971
  prefixStream(watch.stdout, "host", notSentinel);
4583
4972
  prefixStream(watch.stderr, "host", notSentinel);
4584
4973
  scanStream(watch.stdout, (line) => this.onWatchLine(line));
4585
4974
  scanStream(watch.stderr, (line) => this.onWatchLine(line));
4586
4975
  watch.on("exit", (code, signal) => {
4976
+ this.forgetChild(watch);
4977
+ this.watchChildren.delete(watch);
4587
4978
  if (this.shuttingDown) return;
4588
4979
  if (this.watchChild !== watch) return;
4589
4980
  if (this.watchReady) {
4981
+ killChild(watch, { processGroup: true, signal: "SIGKILL" });
4590
4982
  const failed = code !== null && code !== 0 || signal !== null;
4591
4983
  if (failed) {
4592
4984
  console.error(
@@ -4615,6 +5007,56 @@ var DevSession = class {
4615
5007
  });
4616
5008
  return watch;
4617
5009
  }
5010
+ /**
5011
+ * A bridge policy is a bundled native resource, not managed code, so
5012
+ * `dotnet watch` notices the file but cannot apply it as a metadata delta.
5013
+ * Replace the watcher it owns: the new watch session performs a real build,
5014
+ * embeds the policy, launches the host, and retains the current delta or
5015
+ * rebuild strategy for later C# edits.
5016
+ */
5017
+ async restartHostForBridgePolicyChange() {
5018
+ if (this.shuttingDown) return;
5019
+ if (!this.hotReload || this.fellBackToClassic) {
5020
+ console.log(
5021
+ taggedRow(
5022
+ "manual",
5023
+ "host",
5024
+ dim("vidra.config.ts updated \u2014 restart the host to apply bridge access")
5025
+ )
5026
+ );
5027
+ return;
5028
+ }
5029
+ if (!this.watchChild) return;
5030
+ if (this.restartingWatch) {
5031
+ this.watchRestartPending = true;
5032
+ return;
5033
+ }
5034
+ this.restartingWatch = true;
5035
+ try {
5036
+ do {
5037
+ this.watchRestartPending = false;
5038
+ console.log(
5039
+ taggedRow(
5040
+ "active",
5041
+ "host",
5042
+ dim("vidra.config.ts updated \u2014 rebuilding and relaunching the host\u2026")
5043
+ )
5044
+ );
5045
+ const previous = this.watchChild;
5046
+ this.watchChild = void 0;
5047
+ this.watchReady = false;
5048
+ this.buildOutcome = null;
5049
+ this.everBuilt = false;
5050
+ if (previous) {
5051
+ await terminateChild(previous, { processGroup: true });
5052
+ }
5053
+ if (this.shuttingDown) return;
5054
+ this.launchHostWithWatch();
5055
+ } while (this.watchRestartPending && !this.shuttingDown);
5056
+ } finally {
5057
+ this.restartingWatch = false;
5058
+ }
5059
+ }
4618
5060
  onWatchLine(line) {
4619
5061
  this.watchOutputTail = (this.watchOutputTail + line + "\n").slice(
4620
5062
  -WATCH_OUTPUT_TAIL_CHARS
@@ -4739,11 +5181,10 @@ var DevSession = class {
4739
5181
  if (previous) {
4740
5182
  this.hostChild = void 0;
4741
5183
  console.log(taggedRow("active", "host", dim("relaunching\u2026")));
4742
- killChild(previous);
4743
- await waitForExit(previous, HOST_TERMINATION_TIMEOUT_MS);
5184
+ await terminateChild(previous);
4744
5185
  }
4745
5186
  if (this.shuttingDown) return;
4746
- this.hostChild = this.spawnMacosHost({ fatal: false }) ?? void 0;
5187
+ this.hostChild = this.target.name === "macos" ? this.spawnMacosHost({ fatal: false }) ?? void 0 : this.target.name === "windows" ? this.launchWindowsHost() : this.launchAndroidHost();
4747
5188
  if (this.hostChild) this.watchReady = true;
4748
5189
  } while (this.relaunchPending && !this.shuttingDown);
4749
5190
  } finally {
@@ -4792,8 +5233,7 @@ var DevSession = class {
4792
5233
  const previous = this.watchChild;
4793
5234
  this.watchChild = void 0;
4794
5235
  if (previous) {
4795
- killChild(previous, { processGroup: true });
4796
- await waitForExit(previous, HOST_TERMINATION_TIMEOUT_MS);
5236
+ await terminateChild(previous, { processGroup: true });
4797
5237
  }
4798
5238
  if (this.shuttingDown) return;
4799
5239
  this.buildOutcome = null;
@@ -4843,11 +5283,9 @@ var DevSession = class {
4843
5283
  )
4844
5284
  );
4845
5285
  console.log();
4846
- if (this.target.name === "macos") {
4847
- this.launchMacosHost();
4848
- } else {
4849
- this.launchWindowsHost();
4850
- }
5286
+ if (this.target.name === "macos") this.launchMacosHost();
5287
+ else if (this.target.name === "windows") this.launchWindowsHost();
5288
+ else this.launchAndroidHost();
4851
5289
  }
4852
5290
  // --- classic launch (one build + direct spawn) ------------------------------
4853
5291
  // Builds the MAUI host as a discrete step (a plain `dotnet build`, never
@@ -4863,7 +5301,7 @@ var DevSession = class {
4863
5301
  )
4864
5302
  );
4865
5303
  try {
4866
- execFileSync10(
5304
+ execFileSync11(
4867
5305
  DOTNET_COMMAND,
4868
5306
  [
4869
5307
  "build",
@@ -4906,7 +5344,7 @@ var DevSession = class {
4906
5344
  * than exiting the process.
4907
5345
  */
4908
5346
  spawnMacosHost(opts) {
4909
- const outputDir = path22.join(
5347
+ const outputDir = path23.join(
4910
5348
  this.project.hostDir,
4911
5349
  "bin",
4912
5350
  this.buildConfig,
@@ -4933,14 +5371,14 @@ var DevSession = class {
4933
5371
  return fail2(`could not find the app executable in ${appBundle}`);
4934
5372
  }
4935
5373
  console.log(
4936
- taggedRow("active", "host", `${dim("launching")} ${value(path22.basename(appBundle))}${dim("\u2026")}`)
5374
+ taggedRow("active", "host", `${dim("launching")} ${value(path23.basename(appBundle))}${dim("\u2026")}`)
4937
5375
  );
4938
5376
  const host = spawn2(binary, [], {
4939
5377
  cwd: this.project.root,
4940
5378
  stdio: ["ignore", "pipe", "pipe"],
4941
5379
  env: { ...process.env, VIDRA_DEV_URL: this.viteUrl }
4942
5380
  });
4943
- return this.registerChild(host, "host", path22.basename(binary));
5381
+ return this.registerChild(host, "host", path23.basename(binary));
4944
5382
  }
4945
5383
  // Build first, then spawn the produced .exe directly. A single
4946
5384
  // `dotnet build -t:Run` on an unpackaged MAUI Windows app
@@ -4963,21 +5401,146 @@ var DevSession = class {
4963
5401
  row({
4964
5402
  glyph: "error",
4965
5403
  detail: dim(
4966
- `could not find the host .exe under ${path22.join(this.project.hostDir, "bin", this.buildConfig, this.target.framework)}`
5404
+ `could not find the host .exe under ${path23.join(this.project.hostDir, "bin", this.buildConfig, this.target.framework)}`
4967
5405
  )
4968
5406
  })
4969
5407
  );
4970
5408
  process.exit(1);
4971
5409
  }
4972
5410
  console.log(
4973
- taggedRow("active", "host", `${dim("launching")} ${value(path22.basename(exe))}${dim("\u2026")}`)
5411
+ taggedRow("active", "host", `${dim("launching")} ${value(path23.basename(exe))}${dim("\u2026")}`)
4974
5412
  );
4975
5413
  const host = spawn2(exe, [], {
4976
- cwd: path22.dirname(exe),
5414
+ cwd: path23.dirname(exe),
4977
5415
  stdio: ["ignore", "pipe", "pipe"],
4978
5416
  env: { ...process.env, VIDRA_DEV_URL: this.viteUrl }
4979
5417
  });
4980
- return this.registerChild(host, "host", path22.basename(exe));
5418
+ return this.registerChild(host, "host", path23.basename(exe));
5419
+ }
5420
+ launchAndroidHost() {
5421
+ const serial = this.androidSerial ??= resolveAndroidDevice();
5422
+ const applicationId = readAndroidApplicationId(this.project.csprojPath);
5423
+ console.log(
5424
+ taggedRow(
5425
+ "active",
5426
+ "host",
5427
+ `${dim("building and installing")} ${value(this.target.framework)} ${dim(`on ${serial}\u2026`)}`
5428
+ )
5429
+ );
5430
+ try {
5431
+ execFileSync11(
5432
+ DOTNET_COMMAND,
5433
+ [
5434
+ "build",
5435
+ "-c",
5436
+ this.buildConfig,
5437
+ "-f",
5438
+ this.target.framework,
5439
+ "-t:Install",
5440
+ `-p:AndroidDeviceSerial=${serial}`,
5441
+ this.project.csprojPath
5442
+ ],
5443
+ {
5444
+ cwd: this.project.root,
5445
+ stdio: this.verbose ? "inherit" : "pipe"
5446
+ }
5447
+ );
5448
+ } catch (error) {
5449
+ console.error(taggedRow("error", "host", dim("Android build/install failed")));
5450
+ console.error(dim(formatBuildError(error)));
5451
+ process.exit(1);
5452
+ }
5453
+ const adb = (...args) => execFileSync11("adb", ["-s", serial, ...args], {
5454
+ encoding: "utf8",
5455
+ stdio: ["ignore", "pipe", "pipe"]
5456
+ }).trim();
5457
+ const tryAdb = (...args) => {
5458
+ try {
5459
+ return adb(...args);
5460
+ } catch {
5461
+ return "";
5462
+ }
5463
+ };
5464
+ const port = new URL(this.viteUrl).port;
5465
+ let reversed = true;
5466
+ if (port) {
5467
+ try {
5468
+ adb("reverse", `tcp:${port}`, `tcp:${port}`);
5469
+ } catch {
5470
+ reversed = false;
5471
+ }
5472
+ }
5473
+ const deviceDevUrl = selectAndroidDevUrl(
5474
+ serial,
5475
+ port,
5476
+ reversed,
5477
+ resolveAndroidFallbackHost(
5478
+ this.viteUrl,
5479
+ process.env.VIDRA_ANDROID_HOST,
5480
+ localNetworkAddress()
5481
+ )
5482
+ );
5483
+ if (!reversed) {
5484
+ console.log(
5485
+ taggedRow(
5486
+ "manual",
5487
+ "host",
5488
+ `${dim("adb reverse unavailable \u2014 using")} ${value(deviceDevUrl)}`
5489
+ )
5490
+ );
5491
+ }
5492
+ adb("logcat", "-c");
5493
+ adb("shell", "am", "force-stop", applicationId);
5494
+ adb(
5495
+ "shell",
5496
+ "am",
5497
+ "start",
5498
+ "-W",
5499
+ "-a",
5500
+ "android.intent.action.MAIN",
5501
+ "-c",
5502
+ "android.intent.category.LAUNCHER",
5503
+ "-p",
5504
+ applicationId,
5505
+ "--es",
5506
+ "VIDRA_DEV_URL",
5507
+ deviceDevUrl
5508
+ );
5509
+ const pid = tryAdb("shell", "pidof", "-s", applicationId) || parseAndroidPid(adb("shell", "ps"), applicationId);
5510
+ if (!pid) {
5511
+ console.error(
5512
+ row({ glyph: "error", detail: dim(`Android app ${applicationId} did not start`) })
5513
+ );
5514
+ process.exit(1);
5515
+ }
5516
+ console.log(
5517
+ taggedRow(
5518
+ "active",
5519
+ "host",
5520
+ `${dim("launched")} ${value(applicationId)} ${dim(`\xB7 logcat pid ${pid}`)}`
5521
+ )
5522
+ );
5523
+ const androidApi = Number(tryAdb("shell", "getprop", "ro.build.version.sdk"));
5524
+ const logcatArgs = [
5525
+ "-s",
5526
+ serial,
5527
+ "logcat",
5528
+ ...androidApi >= 24 ? ["--pid", pid] : []
5529
+ ];
5530
+ if (androidApi < 24) {
5531
+ console.log(
5532
+ taggedRow(
5533
+ "manual",
5534
+ "host",
5535
+ dim("API 21\u201323: logcat cannot filter by process; showing device-wide logs")
5536
+ )
5537
+ );
5538
+ }
5539
+ const logcat = spawn2("adb", logcatArgs, {
5540
+ cwd: this.project.root,
5541
+ stdio: ["ignore", "pipe", "pipe"]
5542
+ });
5543
+ return this.registerChild(logcat, "host", applicationId);
4981
5544
  }
4982
5545
  registerChild(child, tag2, label) {
4983
5546
  this.children.push(child);
@@ -5058,12 +5621,112 @@ var DevSession = class {
5058
5621
  shutdown(exitCode) {
5059
5622
  if (this.shuttingDown) return;
5060
5623
  this.shuttingDown = true;
5061
- for (const child of [...this.children]) {
5062
- killChild(child, { processGroup: child === this.watchChild });
5624
+ if (this.target.name === "android" && this.androidSerial) {
5625
+ try {
5626
+ execFileSync11(
5627
+ "adb",
5628
+ [
5629
+ "-s",
5630
+ this.androidSerial,
5631
+ "shell",
5632
+ "am",
5633
+ "force-stop",
5634
+ readAndroidApplicationId(this.project.csprojPath)
5635
+ ],
5636
+ { stdio: "ignore" }
5637
+ );
5638
+ } catch {
5639
+ }
5640
+ }
5641
+ const watchChildren = new Set(this.watchChildren);
5642
+ const children = [...this.children];
5643
+ void Promise.all(
5644
+ children.map(
5645
+ (child) => terminateChild(child, { processGroup: watchChildren.has(child) })
5646
+ )
5647
+ ).finally(() => {
5648
+ this.endSession();
5649
+ process.exit(exitCode);
5650
+ });
5651
+ }
5652
+ };
5653
+ var parseAdbDevices = (output) => output.split(/\r?\n/).slice(1).map((line) => line.trim().split(/\s+/)).filter((parts) => parts.length >= 2 && parts[1] === "device").map((parts) => parts[0]);
5654
+ var selectAndroidDevUrl = (serial, port, reverseSucceeded, lanAddress) => {
5655
+ if (reverseSucceeded) return `http://127.0.0.1:${port}`;
5656
+ if (serial.startsWith("emulator-")) return `http://10.0.2.2:${port}`;
5657
+ if (lanAddress) return `http://${lanAddress}:${port}`;
5658
+ throw new Error(
5659
+ "adb reverse failed and no LAN address is available; connect the device by USB or set up host networking"
5660
+ );
5661
+ };
5662
+ var resolveAndroidFallbackHost = (devUrl, override, detectedLanAddress) => {
5663
+ const explicit = override?.trim();
5664
+ if (explicit) return explicit;
5665
+ const configured = new URL(devUrl).hostname;
5666
+ if (!["localhost", "127.0.0.1", "0.0.0.0", "::1"].includes(configured)) {
5667
+ return configured;
5668
+ }
5669
+ return detectedLanAddress;
5670
+ };
5671
+ var parseAndroidPid = (output, applicationId) => {
5672
+ const lines = output.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
5673
+ if (lines.length < 2) return "";
5674
+ const header2 = lines[0].split(/\s+/);
5675
+ const pidIndex = header2.indexOf("PID");
5676
+ for (const line of lines.slice(1)) {
5677
+ const columns = line.split(/\s+/);
5678
+ if (columns.at(-1) === applicationId) {
5679
+ return columns[pidIndex >= 0 ? pidIndex : 1] ?? "";
5680
+ }
5681
+ }
5682
+ return "";
5683
+ };
5684
+ var localNetworkAddress = () => {
5685
+ for (const addresses of Object.values(os6.networkInterfaces())) {
5686
+ for (const address of addresses ?? []) {
5687
+ if (address.family === "IPv4" && !address.internal) return address.address;
5063
5688
  }
5064
- this.endSession();
5065
- process.exit(exitCode);
5066
5689
  }
5690
+ return void 0;
5691
+ };
5692
+ var resolveAndroidDevice = () => {
5693
+ const requested = process.env.ANDROID_SERIAL?.trim();
5694
+ let devices;
5695
+ try {
5696
+ devices = parseAdbDevices(
5697
+ execFileSync11("adb", ["devices"], { encoding: "utf8" })
5698
+ );
5699
+ } catch {
5700
+ console.error(row({ glyph: "error", detail: dim("adb is not installed or not on PATH") }));
5701
+ process.exit(1);
5702
+ }
5703
+ if (requested) {
5704
+ if (devices.includes(requested)) return requested;
5705
+ console.error(
5706
+ row({ glyph: "error", detail: dim(`ANDROID_SERIAL device is not connected: ${requested}`) })
5707
+ );
5708
+ process.exit(1);
5709
+ }
5710
+ if (devices.length === 1) return devices[0];
5711
+ if (devices.length === 0) {
5712
+ console.error(row({ glyph: "error", detail: dim("no Android emulator or device is connected") }));
5713
+ } else {
5714
+ console.error(
5715
+ row({
5716
+ glyph: "error",
5717
+ detail: dim(`multiple Android devices are connected \u2014 set ANDROID_SERIAL (${devices.join(", ")})`)
5718
+ })
5719
+ );
5720
+ }
5721
+ process.exit(1);
5722
+ };
5723
+ var readAndroidApplicationId = (csprojPath) => {
5724
+ const project = fs20.readFileSync(csprojPath, "utf8");
5725
+ const applicationId = project.match(/<ApplicationId>([^<]+)<\/ApplicationId>/)?.[1]?.trim();
5726
+ if (!applicationId) {
5727
+ throw new Error(`no <ApplicationId> found in ${csprojPath}`);
5728
+ }
5729
+ return applicationId;
5067
5730
  };
5068
5731
  var ensureTargetMatchesHostOs = (targetName) => {
5069
5732
  if (targetName === "macos" && process.platform !== "darwin") {
@@ -5137,13 +5800,13 @@ var waitForServer = (url, timeoutMs) => {
5137
5800
  });
5138
5801
  };
5139
5802
  var findMacAppBundle = (hostDir, framework, buildConfig) => {
5140
- const outputDir = path22.join(hostDir, "bin", buildConfig, framework);
5803
+ const outputDir = path23.join(hostDir, "bin", buildConfig, framework);
5141
5804
  return findAppBundleRecursive(outputDir);
5142
5805
  };
5143
5806
  var findAppBundleRecursive = (dir) => {
5144
- if (!fs19.existsSync(dir)) return null;
5145
- for (const entry of fs19.readdirSync(dir, { withFileTypes: true })) {
5146
- const fullPath = path22.join(dir, entry.name);
5807
+ if (!fs20.existsSync(dir)) return null;
5808
+ for (const entry of fs20.readdirSync(dir, { withFileTypes: true })) {
5809
+ const fullPath = path23.join(dir, entry.name);
5147
5810
  if (entry.isDirectory() && entry.name.endsWith(".app")) {
5148
5811
  return fullPath;
5149
5812
  }
@@ -5155,35 +5818,35 @@ var findAppBundleRecursive = (dir) => {
5155
5818
  return null;
5156
5819
  };
5157
5820
  var findMacExecutable = (appBundle) => {
5158
- const macOsDir = path22.join(appBundle, "Contents", "MacOS");
5159
- if (!fs19.existsSync(macOsDir)) return null;
5160
- for (const entry of fs19.readdirSync(macOsDir, { withFileTypes: true })) {
5821
+ const macOsDir = path23.join(appBundle, "Contents", "MacOS");
5822
+ if (!fs20.existsSync(macOsDir)) return null;
5823
+ for (const entry of fs20.readdirSync(macOsDir, { withFileTypes: true })) {
5161
5824
  if (entry.isFile()) {
5162
- return path22.join(macOsDir, entry.name);
5825
+ return path23.join(macOsDir, entry.name);
5163
5826
  }
5164
5827
  }
5165
5828
  return null;
5166
5829
  };
5167
5830
  var findWindowsExecutable2 = (hostDir, csprojPath, framework, buildConfig) => {
5168
- const outputDir = path22.join(hostDir, "bin", buildConfig, framework);
5169
- if (!fs19.existsSync(outputDir)) return null;
5170
- const exeName = `${path22.basename(csprojPath, ".csproj")}.exe`.toLowerCase();
5831
+ const outputDir = path23.join(hostDir, "bin", buildConfig, framework);
5832
+ if (!fs20.existsSync(outputDir)) return null;
5833
+ const exeName = `${path23.basename(csprojPath, ".csproj")}.exe`.toLowerCase();
5171
5834
  return findFileRecursive(outputDir, (name) => name.toLowerCase() === exeName) ?? findFileRecursive(
5172
5835
  outputDir,
5173
5836
  (name) => name.toLowerCase().endsWith(".host.exe")
5174
5837
  ) ?? findFileRecursive(outputDir, (name) => name.toLowerCase().endsWith(".exe"));
5175
5838
  };
5176
5839
  var findFileRecursive = (dir, match) => {
5177
- if (!fs19.existsSync(dir)) return null;
5178
- const entries = fs19.readdirSync(dir, { withFileTypes: true });
5840
+ if (!fs20.existsSync(dir)) return null;
5841
+ const entries = fs20.readdirSync(dir, { withFileTypes: true });
5179
5842
  for (const entry of entries) {
5180
5843
  if (entry.isFile() && match(entry.name)) {
5181
- return path22.join(dir, entry.name);
5844
+ return path23.join(dir, entry.name);
5182
5845
  }
5183
5846
  }
5184
5847
  for (const entry of entries) {
5185
5848
  if (entry.isDirectory()) {
5186
- const found = findFileRecursive(path22.join(dir, entry.name), match);
5849
+ const found = findFileRecursive(path23.join(dir, entry.name), match);
5187
5850
  if (found) return found;
5188
5851
  }
5189
5852
  }
@@ -5191,23 +5854,23 @@ var findFileRecursive = (dir, match) => {
5191
5854
  };
5192
5855
  var waitForExit = (child, timeoutMs) => new Promise((resolve) => {
5193
5856
  if (child.exitCode !== null || child.signalCode !== null) {
5194
- resolve();
5857
+ resolve(true);
5195
5858
  return;
5196
5859
  }
5197
5860
  const timer = setTimeout(() => {
5198
- child.kill("SIGKILL");
5199
- resolve();
5861
+ resolve(false);
5200
5862
  }, timeoutMs);
5201
5863
  child.once("exit", () => {
5202
5864
  clearTimeout(timer);
5203
- resolve();
5865
+ resolve(true);
5204
5866
  });
5205
5867
  });
5206
5868
  var killChild = (child, opts = {}) => {
5207
- if (!child.pid || child.exitCode !== null) return;
5869
+ if (!child.pid) return;
5208
5870
  if (process.platform === "win32") {
5871
+ if (child.exitCode !== null) return;
5209
5872
  try {
5210
- execFileSync10("taskkill", ["/PID", String(child.pid), "/T", "/F"], {
5873
+ execFileSync11("taskkill", ["/PID", String(child.pid), "/T", "/F"], {
5211
5874
  stdio: "ignore"
5212
5875
  });
5213
5876
  } catch {
@@ -5217,12 +5880,22 @@ var killChild = (child, opts = {}) => {
5217
5880
  }
5218
5881
  if (opts.processGroup) {
5219
5882
  try {
5220
- process.kill(-child.pid, "SIGTERM");
5883
+ process.kill(-child.pid, opts.signal ?? "SIGTERM");
5221
5884
  return;
5222
5885
  } catch {
5223
5886
  }
5224
5887
  }
5225
- child.kill("SIGTERM");
5888
+ if (child.exitCode === null) child.kill(opts.signal ?? "SIGTERM");
5889
+ };
5890
+ var terminateChild = async (child, opts = {}) => {
5891
+ killChild(child, opts);
5892
+ const exited = await waitForExit(child, HOST_TERMINATION_TIMEOUT_MS);
5893
+ if (!exited || opts.processGroup) {
5894
+ killChild(child, { ...opts, signal: "SIGKILL" });
5895
+ }
5896
+ if (!exited) {
5897
+ await waitForExit(child, 1e3);
5898
+ }
5226
5899
  };
5227
5900
  var printMacLaunchHint = () => {
5228
5901
  console.error();
@@ -5258,8 +5931,8 @@ var COMMANDS = {
5258
5931
  verify: { spec: VERIFY, run: verifyCommand },
5259
5932
  doctor: {
5260
5933
  spec: DOCTOR,
5261
- run: async () => {
5262
- process.exit(await runDoctor());
5934
+ run: async (argv) => {
5935
+ process.exit(await runDoctor(argv));
5263
5936
  }
5264
5937
  }
5265
5938
  };