@korajs/cli 1.0.0-beta.7 → 1.0.0-beta.9

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 (46) hide show
  1. package/dist/bin.cjs +74 -31
  2. package/dist/bin.cjs.map +1 -1
  3. package/dist/bin.js +67 -29
  4. package/dist/bin.js.map +1 -1
  5. package/dist/{chunk-ZTVVAYHJ.js → chunk-Z7GCXMGW.js} +8 -4
  6. package/dist/chunk-Z7GCXMGW.js.map +1 -0
  7. package/dist/create.cjs +7 -3
  8. package/dist/create.cjs.map +1 -1
  9. package/dist/create.js +1 -1
  10. package/package.json +8 -8
  11. package/templates/react-basic/src/main.tsx +1 -1
  12. package/templates/react-basic/src/vite-env.d.ts +1 -0
  13. package/templates/react-sync/server.ts +4 -1
  14. package/templates/react-sync/src/main.tsx +1 -1
  15. package/templates/react-sync/src/vite-env.d.ts +1 -0
  16. package/templates/react-sync/vite.config.ts +1 -1
  17. package/templates/react-tailwind/src/main.tsx +1 -1
  18. package/templates/react-tailwind/src/vite-env.d.ts +1 -0
  19. package/templates/react-tailwind-sync/server.ts +4 -1
  20. package/templates/react-tailwind-sync/src/main.tsx +1 -1
  21. package/templates/react-tailwind-sync/src/vite-env.d.ts +1 -0
  22. package/templates/react-tailwind-sync/vite.config.ts +1 -1
  23. package/templates/svelte-basic/src/main.ts +1 -1
  24. package/templates/svelte-sync/server.ts +4 -1
  25. package/templates/svelte-sync/src/main.ts +1 -1
  26. package/templates/svelte-sync/src/vite-env.d.ts +1 -0
  27. package/templates/svelte-sync/vite.config.ts +1 -1
  28. package/templates/svelte-tailwind/src/main.ts +1 -1
  29. package/templates/svelte-tailwind-sync/server.ts +4 -1
  30. package/templates/svelte-tailwind-sync/src/main.ts +1 -1
  31. package/templates/svelte-tailwind-sync/src/vite-env.d.ts +1 -0
  32. package/templates/svelte-tailwind-sync/vite.config.ts +1 -1
  33. package/templates/tauri-react/server.ts +4 -1
  34. package/templates/tauri-react/src/AppShell.tsx +1 -1
  35. package/templates/tauri-react/src/vite-env.d.ts +1 -0
  36. package/templates/vue-basic/src/main.ts +1 -1
  37. package/templates/vue-sync/server.ts +4 -1
  38. package/templates/vue-sync/src/main.ts +1 -1
  39. package/templates/vue-sync/src/vite-env.d.ts +1 -0
  40. package/templates/vue-sync/vite.config.ts +1 -1
  41. package/templates/vue-tailwind/src/main.ts +1 -1
  42. package/templates/vue-tailwind-sync/server.ts +4 -1
  43. package/templates/vue-tailwind-sync/src/main.ts +1 -1
  44. package/templates/vue-tailwind-sync/src/vite-env.d.ts +1 -0
  45. package/templates/vue-tailwind-sync/vite.config.ts +1 -1
  46. package/dist/chunk-ZTVVAYHJ.js.map +0 -1
package/dist/bin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  createCommand
4
- } from "./chunk-ZTVVAYHJ.js";
4
+ } from "./chunk-Z7GCXMGW.js";
5
5
  import {
6
6
  agentsCommand,
7
7
  deployCommand,
@@ -373,6 +373,7 @@ import { spawn as spawnChild } from "child_process";
373
373
  var ProcessManager = class {
374
374
  processes = /* @__PURE__ */ new Map();
375
375
  spawn(config) {
376
+ this.processes.get(config.label)?.child.kill("SIGTERM");
376
377
  const options = {
377
378
  cwd: config.cwd,
378
379
  env: { ...process.env, ...config.env },
@@ -416,6 +417,20 @@ var ProcessManager = class {
416
417
  hasRunning() {
417
418
  return this.processes.size > 0;
418
419
  }
420
+ async restart(config) {
421
+ await this.stop(config.label);
422
+ this.spawn(config);
423
+ }
424
+ async stop(label) {
425
+ const running = this.processes.get(label);
426
+ if (!running) return;
427
+ running.child.kill("SIGTERM");
428
+ await Promise.race([running.exitPromise, delay(5e3)]);
429
+ const remaining = this.processes.get(label);
430
+ if (!remaining) return;
431
+ remaining.child.kill("SIGKILL");
432
+ await remaining.exitPromise;
433
+ }
419
434
  async shutdownAll() {
420
435
  const running = Array.from(this.processes.values());
421
436
  if (running.length === 0) return;
@@ -468,6 +483,7 @@ var SchemaWatcher = class {
468
483
  debounceMs;
469
484
  watcher = null;
470
485
  debounceTimer = null;
486
+ schemaVersion = null;
471
487
  start() {
472
488
  if (this.watcher) return;
473
489
  this.watcher = watch(this.config.schemaPath, () => {
@@ -476,6 +492,9 @@ var SchemaWatcher = class {
476
492
  this.watcher.on("error", (error) => {
477
493
  this.config.onError?.(toError(error));
478
494
  });
495
+ void this.refreshSchemaVersion().catch((error) => {
496
+ this.config.onError?.(toError(error));
497
+ });
479
498
  }
480
499
  stop() {
481
500
  if (this.debounceTimer) {
@@ -499,6 +518,15 @@ var SchemaWatcher = class {
499
518
  const args = hasTsx ? ["--import", "tsx", koraBinJs, "generate", "types", "--schema", this.config.schemaPath] : [koraBinJs, "generate", "types", "--schema", this.config.schemaPath];
500
519
  await spawnCommand(command, args, this.config.projectRoot);
501
520
  this.config.onRegenerate?.();
521
+ await this.refreshSchemaVersion();
522
+ }
523
+ async refreshSchemaVersion() {
524
+ const schema = await loadSchemaDefinition(this.config.schemaPath, this.config.projectRoot);
525
+ const previous = this.schemaVersion;
526
+ this.schemaVersion = schema.version;
527
+ if (previous !== null && previous !== schema.version) {
528
+ this.config.onSchemaVersionChange?.({ previous, next: schema.version });
529
+ }
502
530
  }
503
531
  scheduleRegeneration() {
504
532
  if (this.debounceTimer) {
@@ -685,7 +713,9 @@ var devCommand = defineCommand3({
685
713
  logger.step(" Schema watcher disabled (schema.ts not found)");
686
714
  }
687
715
  logger.blank();
688
- logger.step(" Kora DevTools overlay: Ctrl+Shift+K (Cmd+Shift+K on macOS) when devtools: true");
716
+ logger.step(
717
+ " Kora DevTools overlay: Ctrl+Shift+K (Cmd+Shift+K on macOS) when devtools is enabled"
718
+ );
689
719
  processManager.spawn({
690
720
  label: "vite",
691
721
  command: process.execPath,
@@ -696,33 +726,31 @@ var devCommand = defineCommand3({
696
726
  },
697
727
  onExit: onManagedProcessExit
698
728
  });
699
- if (shouldStartSync && hasTsx && syncServerFile) {
700
- processManager.spawn({
701
- label: "sync",
702
- command: process.execPath,
703
- args: ["--import", "tsx", syncServerFile],
704
- cwd: projectRoot,
705
- env: {
706
- PORT: String(syncPort),
707
- KORA_SYNC_PORT: String(syncPort)
708
- },
709
- onExit: onManagedProcessExit
710
- });
711
- }
712
- if (shouldStartSync && syncServerFile === null && managedSyncStore !== null) {
713
- processManager.spawn({
714
- label: "sync",
715
- command: process.execPath,
716
- args: ["--input-type=module", "--eval", MANAGED_SYNC_BOOTSTRAP_SCRIPT],
717
- cwd: projectRoot,
718
- env: {
719
- KORA_DEV_SYNC_CONFIG: JSON.stringify({
720
- port: Number(syncPort),
721
- store: managedSyncStore
722
- })
723
- },
724
- onExit: onManagedProcessExit
725
- });
729
+ const syncProcessConfig = shouldStartSync && hasTsx && syncServerFile ? {
730
+ label: "sync",
731
+ command: process.execPath,
732
+ args: ["--import", "tsx", syncServerFile],
733
+ cwd: projectRoot,
734
+ env: {
735
+ PORT: String(syncPort),
736
+ KORA_SYNC_PORT: String(syncPort)
737
+ },
738
+ onExit: onManagedProcessExit
739
+ } : shouldStartSync && syncServerFile === null && managedSyncStore !== null ? {
740
+ label: "sync",
741
+ command: process.execPath,
742
+ args: ["--input-type=module", "--eval", MANAGED_SYNC_BOOTSTRAP_SCRIPT],
743
+ cwd: projectRoot,
744
+ env: {
745
+ KORA_DEV_SYNC_CONFIG: JSON.stringify({
746
+ port: Number(syncPort),
747
+ store: managedSyncStore
748
+ })
749
+ },
750
+ onExit: onManagedProcessExit
751
+ } : null;
752
+ if (syncProcessConfig) {
753
+ processManager.spawn(syncProcessConfig);
726
754
  }
727
755
  if (watchEnabled && schemaPath) {
728
756
  schemaWatcher = new SchemaWatcher({
@@ -732,6 +760,16 @@ var devCommand = defineCommand3({
732
760
  onRegenerate: () => {
733
761
  logger.success("Regenerated types from schema changes");
734
762
  },
763
+ onSchemaVersionChange: ({ previous, next }) => {
764
+ if (!syncProcessConfig) {
765
+ logger.warn(
766
+ `Schema version changed from ${previous} to ${next}; restart your sync server before clients can sync.`
767
+ );
768
+ return;
769
+ }
770
+ logger.warn(`Schema version changed from ${previous} to ${next}; restarting sync server.`);
771
+ void processManager.restart(syncProcessConfig);
772
+ },
735
773
  onError: (error) => {
736
774
  logger.error(`Schema watcher error: ${error.message}`);
737
775
  }