vidra-cli 0.5.0 → 0.5.1

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 (2) hide show
  1. package/dist/cli.js +88 -23
  2. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -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.5.1";
593
593
 
594
594
  // src/help.ts
595
595
  var UNIVERSAL = [
@@ -4313,12 +4313,7 @@ var startSession = async (argv, opts) => {
4313
4313
  next.accessFingerprint
4314
4314
  );
4315
4315
  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
- }));
4316
+ await session.restartHostForBridgePolicyChange();
4322
4317
  } else if (frontendWrite.changed) {
4323
4318
  console.log(row({
4324
4319
  glyph: "done",
@@ -4427,6 +4422,7 @@ var DevSession = class {
4427
4422
  viteUrl;
4428
4423
  verbose;
4429
4424
  children = [];
4425
+ watchChildren = /* @__PURE__ */ new Set();
4430
4426
  buildConfig = process.env.VIDRA_BUILD_CONFIG || "Debug";
4431
4427
  vite;
4432
4428
  hotReload;
@@ -4447,6 +4443,8 @@ var DevSession = class {
4447
4443
  hostChild;
4448
4444
  relaunching = false;
4449
4445
  relaunchPending = false;
4446
+ restartingWatch = false;
4447
+ watchRestartPending = false;
4450
4448
  fellBackToClassic = false;
4451
4449
  endSession = () => {
4452
4450
  };
@@ -4578,15 +4576,19 @@ var DevSession = class {
4578
4576
  );
4579
4577
  this.watchChild = watch;
4580
4578
  this.children.push(watch);
4579
+ this.watchChildren.add(watch);
4581
4580
  const notSentinel = (line) => !line.includes(HOST_READY_SENTINEL);
4582
4581
  prefixStream(watch.stdout, "host", notSentinel);
4583
4582
  prefixStream(watch.stderr, "host", notSentinel);
4584
4583
  scanStream(watch.stdout, (line) => this.onWatchLine(line));
4585
4584
  scanStream(watch.stderr, (line) => this.onWatchLine(line));
4586
4585
  watch.on("exit", (code, signal) => {
4586
+ this.forgetChild(watch);
4587
+ this.watchChildren.delete(watch);
4587
4588
  if (this.shuttingDown) return;
4588
4589
  if (this.watchChild !== watch) return;
4589
4590
  if (this.watchReady) {
4591
+ killChild(watch, { processGroup: true, signal: "SIGKILL" });
4590
4592
  const failed = code !== null && code !== 0 || signal !== null;
4591
4593
  if (failed) {
4592
4594
  console.error(
@@ -4615,6 +4617,56 @@ var DevSession = class {
4615
4617
  });
4616
4618
  return watch;
4617
4619
  }
4620
+ /**
4621
+ * A bridge policy is a bundled native resource, not managed code, so
4622
+ * `dotnet watch` notices the file but cannot apply it as a metadata delta.
4623
+ * Replace the watcher it owns: the new watch session performs a real build,
4624
+ * embeds the policy, launches the host, and retains the current delta or
4625
+ * rebuild strategy for later C# edits.
4626
+ */
4627
+ async restartHostForBridgePolicyChange() {
4628
+ if (this.shuttingDown) return;
4629
+ if (!this.hotReload || this.fellBackToClassic) {
4630
+ console.log(
4631
+ taggedRow(
4632
+ "manual",
4633
+ "host",
4634
+ dim("vidra.config.ts updated \u2014 restart the host to apply bridge access")
4635
+ )
4636
+ );
4637
+ return;
4638
+ }
4639
+ if (!this.watchChild) return;
4640
+ if (this.restartingWatch) {
4641
+ this.watchRestartPending = true;
4642
+ return;
4643
+ }
4644
+ this.restartingWatch = true;
4645
+ try {
4646
+ do {
4647
+ this.watchRestartPending = false;
4648
+ console.log(
4649
+ taggedRow(
4650
+ "active",
4651
+ "host",
4652
+ dim("vidra.config.ts updated \u2014 rebuilding and relaunching the host\u2026")
4653
+ )
4654
+ );
4655
+ const previous = this.watchChild;
4656
+ this.watchChild = void 0;
4657
+ this.watchReady = false;
4658
+ this.buildOutcome = null;
4659
+ this.everBuilt = false;
4660
+ if (previous) {
4661
+ await terminateChild(previous, { processGroup: true });
4662
+ }
4663
+ if (this.shuttingDown) return;
4664
+ this.launchHostWithWatch();
4665
+ } while (this.watchRestartPending && !this.shuttingDown);
4666
+ } finally {
4667
+ this.restartingWatch = false;
4668
+ }
4669
+ }
4618
4670
  onWatchLine(line) {
4619
4671
  this.watchOutputTail = (this.watchOutputTail + line + "\n").slice(
4620
4672
  -WATCH_OUTPUT_TAIL_CHARS
@@ -4739,8 +4791,7 @@ var DevSession = class {
4739
4791
  if (previous) {
4740
4792
  this.hostChild = void 0;
4741
4793
  console.log(taggedRow("active", "host", dim("relaunching\u2026")));
4742
- killChild(previous);
4743
- await waitForExit(previous, HOST_TERMINATION_TIMEOUT_MS);
4794
+ await terminateChild(previous);
4744
4795
  }
4745
4796
  if (this.shuttingDown) return;
4746
4797
  this.hostChild = this.spawnMacosHost({ fatal: false }) ?? void 0;
@@ -4792,8 +4843,7 @@ var DevSession = class {
4792
4843
  const previous = this.watchChild;
4793
4844
  this.watchChild = void 0;
4794
4845
  if (previous) {
4795
- killChild(previous, { processGroup: true });
4796
- await waitForExit(previous, HOST_TERMINATION_TIMEOUT_MS);
4846
+ await terminateChild(previous, { processGroup: true });
4797
4847
  }
4798
4848
  if (this.shuttingDown) return;
4799
4849
  this.buildOutcome = null;
@@ -5058,11 +5108,16 @@ var DevSession = class {
5058
5108
  shutdown(exitCode) {
5059
5109
  if (this.shuttingDown) return;
5060
5110
  this.shuttingDown = true;
5061
- for (const child of [...this.children]) {
5062
- killChild(child, { processGroup: child === this.watchChild });
5063
- }
5064
- this.endSession();
5065
- process.exit(exitCode);
5111
+ const watchChildren = new Set(this.watchChildren);
5112
+ const children = [...this.children];
5113
+ void Promise.all(
5114
+ children.map(
5115
+ (child) => terminateChild(child, { processGroup: watchChildren.has(child) })
5116
+ )
5117
+ ).finally(() => {
5118
+ this.endSession();
5119
+ process.exit(exitCode);
5120
+ });
5066
5121
  }
5067
5122
  };
5068
5123
  var ensureTargetMatchesHostOs = (targetName) => {
@@ -5191,21 +5246,21 @@ var findFileRecursive = (dir, match) => {
5191
5246
  };
5192
5247
  var waitForExit = (child, timeoutMs) => new Promise((resolve) => {
5193
5248
  if (child.exitCode !== null || child.signalCode !== null) {
5194
- resolve();
5249
+ resolve(true);
5195
5250
  return;
5196
5251
  }
5197
5252
  const timer = setTimeout(() => {
5198
- child.kill("SIGKILL");
5199
- resolve();
5253
+ resolve(false);
5200
5254
  }, timeoutMs);
5201
5255
  child.once("exit", () => {
5202
5256
  clearTimeout(timer);
5203
- resolve();
5257
+ resolve(true);
5204
5258
  });
5205
5259
  });
5206
5260
  var killChild = (child, opts = {}) => {
5207
- if (!child.pid || child.exitCode !== null) return;
5261
+ if (!child.pid) return;
5208
5262
  if (process.platform === "win32") {
5263
+ if (child.exitCode !== null) return;
5209
5264
  try {
5210
5265
  execFileSync10("taskkill", ["/PID", String(child.pid), "/T", "/F"], {
5211
5266
  stdio: "ignore"
@@ -5217,12 +5272,22 @@ var killChild = (child, opts = {}) => {
5217
5272
  }
5218
5273
  if (opts.processGroup) {
5219
5274
  try {
5220
- process.kill(-child.pid, "SIGTERM");
5275
+ process.kill(-child.pid, opts.signal ?? "SIGTERM");
5221
5276
  return;
5222
5277
  } catch {
5223
5278
  }
5224
5279
  }
5225
- child.kill("SIGTERM");
5280
+ if (child.exitCode === null) child.kill(opts.signal ?? "SIGTERM");
5281
+ };
5282
+ var terminateChild = async (child, opts = {}) => {
5283
+ killChild(child, opts);
5284
+ const exited = await waitForExit(child, HOST_TERMINATION_TIMEOUT_MS);
5285
+ if (!exited || opts.processGroup) {
5286
+ killChild(child, { ...opts, signal: "SIGKILL" });
5287
+ }
5288
+ if (!exited) {
5289
+ await waitForExit(child, 1e3);
5290
+ }
5226
5291
  };
5227
5292
  var printMacLaunchHint = () => {
5228
5293
  console.error();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vidra-cli",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "The vidra command: dev, build, updates and doctor for Vidra apps (React + .NET MAUI)",
5
5
  "type": "module",
6
6
  "bin": {