@makoojs/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.
package/dist/index.js CHANGED
@@ -5,7 +5,7 @@ import { MakooError as o } from "@makoojs/core";
5
5
  //#region packages/cli/src/config/defaults.ts
6
6
  var s = {
7
7
  open: a.platform === "win32" || a.platform === "darwin",
8
- prefix: "server:",
8
+ prefix: (e) => `server:${e}`,
9
9
  mountGmApi: !1
10
10
  }, c = {
11
11
  metaFileName: !1,
@@ -2275,28 +2275,28 @@ var Y = /*@__PURE__*/ d("ZodType", (e, t) => (F.init(e, t), Object.assign(e["~st
2275
2275
  return e.add(this, t), this;
2276
2276
  },
2277
2277
  refine(e, t) {
2278
- return this.check(ua(e, t));
2278
+ return this.check(da(e, t));
2279
2279
  },
2280
2280
  superRefine(e, t) {
2281
- return this.check(da(e, t));
2281
+ return this.check(fa(e, t));
2282
2282
  },
2283
2283
  overwrite(e) {
2284
2284
  return this.check(/* @__PURE__ */ U(e));
2285
2285
  },
2286
2286
  optional() {
2287
- return Ki(this);
2287
+ return qi(this);
2288
2288
  },
2289
2289
  exactOptional() {
2290
- return Ji(this);
2290
+ return Yi(this);
2291
2291
  },
2292
2292
  nullable() {
2293
- return Xi(this);
2293
+ return Zi(this);
2294
2294
  },
2295
2295
  nullish() {
2296
- return Ki(Xi(this));
2296
+ return qi(Zi(this));
2297
2297
  },
2298
2298
  nonoptional(e) {
2299
- return na(this, e);
2299
+ return ra(this, e);
2300
2300
  },
2301
2301
  array() {
2302
2302
  return Pi(this);
@@ -2308,22 +2308,22 @@ var Y = /*@__PURE__*/ d("ZodType", (e, t) => (F.init(e, t), Object.assign(e["~st
2308
2308
  return Vi(this, e);
2309
2309
  },
2310
2310
  transform(e) {
2311
- return oa(this, Wi(e));
2311
+ return sa(this, Gi(e));
2312
2312
  },
2313
2313
  default(e) {
2314
- return Qi(this, e);
2314
+ return $i(this, e);
2315
2315
  },
2316
2316
  prefault(e) {
2317
- return ea(this, e);
2317
+ return ta(this, e);
2318
2318
  },
2319
2319
  catch(e) {
2320
- return ia(this, e);
2320
+ return aa(this, e);
2321
2321
  },
2322
2322
  pipe(e) {
2323
- return oa(this, e);
2323
+ return sa(this, e);
2324
2324
  },
2325
2325
  readonly() {
2326
- return ca(this);
2326
+ return la(this);
2327
2327
  },
2328
2328
  describe(e) {
2329
2329
  let t = this.clone();
@@ -2481,7 +2481,7 @@ function Pi(e, t) {
2481
2481
  var Fi = /*@__PURE__*/ d("ZodObject", (e, t) => {
2482
2482
  nn.init(e, t), Y.init(e, t), e._zod.processJSONSchema = (t, n, r) => jr(e, t, n, r), v(e, "shape", () => t.shape), J(e, "ZodObject", {
2483
2483
  keyof() {
2484
- return Hi(Object.keys(this._zod.def.shape));
2484
+ return Ui(Object.keys(this._zod.def.shape));
2485
2485
  },
2486
2486
  catchall(e) {
2487
2487
  return this.clone({
@@ -2529,10 +2529,10 @@ var Fi = /*@__PURE__*/ d("ZodObject", (e, t) => {
2529
2529
  return fe(this, e);
2530
2530
  },
2531
2531
  partial(...e) {
2532
- return ge(Gi, this, e[0]);
2532
+ return ge(Ki, this, e[0]);
2533
2533
  },
2534
2534
  required(...e) {
2535
- return _e(ta, this, e[0]);
2535
+ return _e(na, this, e[0]);
2536
2536
  }
2537
2537
  });
2538
2538
  });
@@ -2571,14 +2571,14 @@ function Vi(e, t) {
2571
2571
  right: t
2572
2572
  });
2573
2573
  }
2574
- var $ = /*@__PURE__*/ d("ZodEnum", (e, t) => {
2574
+ var Hi = /*@__PURE__*/ d("ZodEnum", (e, t) => {
2575
2575
  cn.init(e, t), Y.init(e, t), e._zod.processJSONSchema = (t, n, r) => Dr(e, t, n, r), e.enum = t.entries, e.options = Object.values(t.entries);
2576
2576
  let n = new Set(Object.keys(t.entries));
2577
2577
  e.extract = (e, r) => {
2578
2578
  let i = {};
2579
2579
  for (let r of e) if (n.has(r)) i[r] = t.entries[r];
2580
2580
  else throw Error(`Key ${r} not found in enum`);
2581
- return new $({
2581
+ return new Hi({
2582
2582
  ...t,
2583
2583
  checks: [],
2584
2584
  ...T(r),
@@ -2588,7 +2588,7 @@ var $ = /*@__PURE__*/ d("ZodEnum", (e, t) => {
2588
2588
  let i = { ...t.entries };
2589
2589
  for (let t of e) if (n.has(t)) delete i[t];
2590
2590
  else throw Error(`Key ${t} not found in enum`);
2591
- return new $({
2591
+ return new Hi({
2592
2592
  ...t,
2593
2593
  checks: [],
2594
2594
  ...T(r),
@@ -2596,14 +2596,14 @@ var $ = /*@__PURE__*/ d("ZodEnum", (e, t) => {
2596
2596
  });
2597
2597
  };
2598
2598
  });
2599
- function Hi(e, t) {
2600
- return new $({
2599
+ function Ui(e, t) {
2600
+ return new Hi({
2601
2601
  type: "enum",
2602
2602
  entries: Array.isArray(e) ? Object.fromEntries(e.map((e) => [e, e])) : e,
2603
2603
  ...T(t)
2604
2604
  });
2605
2605
  }
2606
- var Ui = /*@__PURE__*/ d("ZodTransform", (e, t) => {
2606
+ var Wi = /*@__PURE__*/ d("ZodTransform", (e, t) => {
2607
2607
  ln.init(e, t), Y.init(e, t), e._zod.processJSONSchema = (t, n, r) => kr(e, t, n, r), e._zod.parse = (n, r) => {
2608
2608
  if (r.direction === "backward") throw new p(e.constructor.name);
2609
2609
  n.addIssue = (r) => {
@@ -2617,44 +2617,44 @@ var Ui = /*@__PURE__*/ d("ZodTransform", (e, t) => {
2617
2617
  return i instanceof Promise ? i.then((e) => (n.value = e, n.fallback = !0, n)) : (n.value = i, n.fallback = !0, n);
2618
2618
  };
2619
2619
  });
2620
- function Wi(e) {
2621
- return new Ui({
2620
+ function Gi(e) {
2621
+ return new Wi({
2622
2622
  type: "transform",
2623
2623
  transform: e
2624
2624
  });
2625
2625
  }
2626
- var Gi = /*@__PURE__*/ d("ZodOptional", (e, t) => {
2626
+ var Ki = /*@__PURE__*/ d("ZodOptional", (e, t) => {
2627
2627
  dn.init(e, t), Y.init(e, t), e._zod.processJSONSchema = (t, n, r) => Vr(e, t, n, r), e.unwrap = () => e._zod.def.innerType;
2628
2628
  });
2629
- function Ki(e) {
2630
- return new Gi({
2629
+ function qi(e) {
2630
+ return new Ki({
2631
2631
  type: "optional",
2632
2632
  innerType: e
2633
2633
  });
2634
2634
  }
2635
- var qi = /*@__PURE__*/ d("ZodExactOptional", (e, t) => {
2635
+ var Ji = /*@__PURE__*/ d("ZodExactOptional", (e, t) => {
2636
2636
  fn.init(e, t), Y.init(e, t), e._zod.processJSONSchema = (t, n, r) => Vr(e, t, n, r), e.unwrap = () => e._zod.def.innerType;
2637
2637
  });
2638
- function Ji(e) {
2639
- return new qi({
2638
+ function Yi(e) {
2639
+ return new Ji({
2640
2640
  type: "optional",
2641
2641
  innerType: e
2642
2642
  });
2643
2643
  }
2644
- var Yi = /*@__PURE__*/ d("ZodNullable", (e, t) => {
2644
+ var Xi = /*@__PURE__*/ d("ZodNullable", (e, t) => {
2645
2645
  pn.init(e, t), Y.init(e, t), e._zod.processJSONSchema = (t, n, r) => Pr(e, t, n, r), e.unwrap = () => e._zod.def.innerType;
2646
2646
  });
2647
- function Xi(e) {
2648
- return new Yi({
2647
+ function Zi(e) {
2648
+ return new Xi({
2649
2649
  type: "nullable",
2650
2650
  innerType: e
2651
2651
  });
2652
2652
  }
2653
- var Zi = /*@__PURE__*/ d("ZodDefault", (e, t) => {
2653
+ var Qi = /*@__PURE__*/ d("ZodDefault", (e, t) => {
2654
2654
  mn.init(e, t), Y.init(e, t), e._zod.processJSONSchema = (t, n, r) => Ir(e, t, n, r), e.unwrap = () => e._zod.def.innerType, e.removeDefault = e.unwrap;
2655
2655
  });
2656
- function Qi(e, t) {
2657
- return new Zi({
2656
+ function $i(e, t) {
2657
+ return new Qi({
2658
2658
  type: "default",
2659
2659
  innerType: e,
2660
2660
  get defaultValue() {
@@ -2662,11 +2662,11 @@ function Qi(e, t) {
2662
2662
  }
2663
2663
  });
2664
2664
  }
2665
- var $i = /*@__PURE__*/ d("ZodPrefault", (e, t) => {
2665
+ var ea = /*@__PURE__*/ d("ZodPrefault", (e, t) => {
2666
2666
  gn.init(e, t), Y.init(e, t), e._zod.processJSONSchema = (t, n, r) => Lr(e, t, n, r), e.unwrap = () => e._zod.def.innerType;
2667
2667
  });
2668
- function ea(e, t) {
2669
- return new $i({
2668
+ function ta(e, t) {
2669
+ return new ea({
2670
2670
  type: "prefault",
2671
2671
  innerType: e,
2672
2672
  get defaultValue() {
@@ -2674,114 +2674,102 @@ function ea(e, t) {
2674
2674
  }
2675
2675
  });
2676
2676
  }
2677
- var ta = /*@__PURE__*/ d("ZodNonOptional", (e, t) => {
2677
+ var na = /*@__PURE__*/ d("ZodNonOptional", (e, t) => {
2678
2678
  _n.init(e, t), Y.init(e, t), e._zod.processJSONSchema = (t, n, r) => Fr(e, t, n, r), e.unwrap = () => e._zod.def.innerType;
2679
2679
  });
2680
- function na(e, t) {
2681
- return new ta({
2680
+ function ra(e, t) {
2681
+ return new na({
2682
2682
  type: "nonoptional",
2683
2683
  innerType: e,
2684
2684
  ...T(t)
2685
2685
  });
2686
2686
  }
2687
- var ra = /*@__PURE__*/ d("ZodCatch", (e, t) => {
2687
+ var ia = /*@__PURE__*/ d("ZodCatch", (e, t) => {
2688
2688
  yn.init(e, t), Y.init(e, t), e._zod.processJSONSchema = (t, n, r) => Rr(e, t, n, r), e.unwrap = () => e._zod.def.innerType, e.removeCatch = e.unwrap;
2689
2689
  });
2690
- function ia(e, t) {
2691
- return new ra({
2690
+ function aa(e, t) {
2691
+ return new ia({
2692
2692
  type: "catch",
2693
2693
  innerType: e,
2694
2694
  catchValue: typeof t == "function" ? t : () => t
2695
2695
  });
2696
2696
  }
2697
- var aa = /*@__PURE__*/ d("ZodPipe", (e, t) => {
2697
+ var oa = /*@__PURE__*/ d("ZodPipe", (e, t) => {
2698
2698
  bn.init(e, t), Y.init(e, t), e._zod.processJSONSchema = (t, n, r) => zr(e, t, n, r), e.in = t.in, e.out = t.out;
2699
2699
  });
2700
- function oa(e, t) {
2701
- return new aa({
2700
+ function sa(e, t) {
2701
+ return new oa({
2702
2702
  type: "pipe",
2703
2703
  in: e,
2704
2704
  out: t
2705
2705
  });
2706
2706
  }
2707
- var sa = /*@__PURE__*/ d("ZodReadonly", (e, t) => {
2707
+ var ca = /*@__PURE__*/ d("ZodReadonly", (e, t) => {
2708
2708
  xn.init(e, t), Y.init(e, t), e._zod.processJSONSchema = (t, n, r) => Br(e, t, n, r), e.unwrap = () => e._zod.def.innerType;
2709
2709
  });
2710
- function ca(e) {
2711
- return new sa({
2710
+ function la(e) {
2711
+ return new ca({
2712
2712
  type: "readonly",
2713
2713
  innerType: e
2714
2714
  });
2715
2715
  }
2716
- var la = /*@__PURE__*/ d("ZodCustom", (e, t) => {
2716
+ var ua = /*@__PURE__*/ d("ZodCustom", (e, t) => {
2717
2717
  Cn.init(e, t), Y.init(e, t), e._zod.processJSONSchema = (t, n, r) => Or(e, t, n, r);
2718
2718
  });
2719
- function ua(e, t = {}) {
2720
- return /* @__PURE__ */ _r(la, e, t);
2719
+ function da(e, t = {}) {
2720
+ return /* @__PURE__ */ _r(ua, e, t);
2721
2721
  }
2722
- function da(e, t) {
2722
+ function fa(e, t) {
2723
2723
  return /* @__PURE__ */ vr(e, t);
2724
2724
  }
2725
2725
  //#endregion
2726
2726
  //#region packages/cli/src/config/errors.ts
2727
- var fa = { CLI_CONFIG_INVALID: "MAKOO_CLI_CONFIG_INVALID" }, pa = class extends o {
2728
- constructor(e, t = fa.CLI_CONFIG_INVALID, n) {
2729
- super("Invalid CliConfig", e, t, n), this.name = "ConfigValidationError";
2730
- }
2731
- };
2732
- function ma(e) {
2733
- return e.length === 0 ? "(root)" : e.filter((e) => typeof e != "symbol").map((e) => typeof e == "number" ? `[${e}]` : e).join(".");
2734
- }
2735
- function ha(e) {
2736
- return e.code === "invalid_type" && e.message.endsWith("received undefined") ? "is required" : e.message;
2737
- }
2738
- function ga(e) {
2739
- return {
2740
- path: ma(e.path),
2741
- message: ha(e)
2742
- };
2743
- }
2744
- //#endregion
2745
- //#region packages/cli/src/config/validation.ts
2746
- var _a = Li({
2727
+ var pa = { CLI_CONFIG_INVALID: "MAKOO_CLI_CONFIG_INVALID" }, ma = Li({
2747
2728
  name: X().min(1, "app.name is required"),
2748
2729
  version: X().min(1, "app.version is required"),
2749
2730
  description: X().optional()
2750
- }), va = Ii({}).loose(), ya = Li({
2731
+ }), ha = Ii({}).loose(), ga = Li({
2751
2732
  entry: X().min(1, "entry is required"),
2752
- app: _a,
2753
- monkey: va
2733
+ app: ma,
2734
+ monkey: ha
2754
2735
  });
2755
- function ba(e) {
2756
- let t = ya.safeParse(e);
2757
- if (!t.success) throw new pa(t.error.issues.map(ga));
2736
+ function _a(e) {
2737
+ let t = ga.safeParse(e);
2738
+ if (!t.success) throw va(t.error);
2739
+ }
2740
+ function va(e) {
2741
+ let t = e.issues.map((e) => `${e.path.map(String).join(".") || "(root)"}: ${e.message}`);
2742
+ return new o(t.join("\n"), {
2743
+ code: pa.CLI_CONFIG_INVALID,
2744
+ cause: e
2745
+ });
2758
2746
  }
2759
2747
  //#endregion
2760
2748
  //#region packages/cli/src/config/resolve.ts
2761
- var xa = (e, t) => n(t) ? r(t) : r(i(e, t)), Sa = (e) => r(e ? i(e) : a.cwd()), Ca = (e) => typeof e == "string" ? { "": e } : e, wa = (e) => ({
2749
+ var ya = (e, t) => n(t) ? r(t) : r(i(e, t)), ba = (e) => r(e ? i(e) : a.cwd()), xa = (e) => typeof e == "string" ? { "": e } : e, Sa = (e) => ({
2762
2750
  ...e,
2763
- name: Ca(e.name),
2764
- description: Ca(e.description)
2765
- }), Ta = (e, t) => t === !1 || t === void 0 ? !1 : t === !0 ? e.replace(/\.user\.js$/, ".meta.js") : typeof t == "function" ? t(e) : t, Ea = (e) => ({
2751
+ name: xa(e.name),
2752
+ description: xa(e.description)
2753
+ }), Ca = (e, t) => t === !1 || t === void 0 ? !1 : t === !0 ? e.replace(/\.user\.js$/, ".meta.js") : typeof t == "function" ? t(e) : t, wa = (e) => ({
2766
2754
  name: e.name,
2767
2755
  version: e.version,
2768
2756
  description: e.description
2769
- }), Da = (e) => ({
2757
+ }), Ta = (e) => ({
2770
2758
  open: e.server?.open ?? s.open,
2771
2759
  prefix: e.server?.prefix ?? s.prefix,
2772
2760
  mountGmApi: s.mountGmApi
2773
- }), Oa = (e, t) => {
2761
+ }), Ea = (e, t) => {
2774
2762
  let n = t.build?.fileName ?? `${e.name}.user.js`;
2775
2763
  return {
2776
2764
  fileName: n,
2777
- metaFileName: Ta(n, t.build?.metaFileName ?? c.metaFileName),
2765
+ metaFileName: Ca(n, t.build?.metaFileName ?? c.metaFileName),
2778
2766
  externalGlobals: t.build?.externalGlobals,
2779
2767
  autoGrant: t.build?.autoGrant ?? c.autoGrant,
2780
2768
  externalResource: t.build?.externalResource,
2781
2769
  systemjs: t.build?.systemjs,
2782
2770
  cssSideEffects: t.build?.cssSideEffects
2783
2771
  };
2784
- }, ka = (e, t) => {
2772
+ }, Da = (e, t) => {
2785
2773
  let { userscript: n, align: r, styleImport: i, server: a, build: o, ...s } = t;
2786
2774
  return {
2787
2775
  ...s,
@@ -2793,34 +2781,34 @@ var xa = (e, t) => n(t) ? r(t) : r(i(e, t)), Sa = (e) => r(e ? i(e) : a.cwd()),
2793
2781
  },
2794
2782
  align: r ?? l.align,
2795
2783
  styleImport: i ?? l.styleImport,
2796
- server: Da(t),
2797
- build: Oa(e, t)
2784
+ server: Ta(t),
2785
+ build: Ea(e, t)
2798
2786
  };
2799
- }, Aa = (e, t) => {
2800
- ba(e);
2801
- let n = Sa(t), r = Ea(e.app);
2787
+ }, Oa = (e, t) => {
2788
+ _a(e);
2789
+ let n = ba(t), r = wa(e.app);
2802
2790
  return {
2803
2791
  root: n,
2804
- entry: xa(n, e.entry),
2792
+ entry: ya(n, e.entry),
2805
2793
  app: r,
2806
- monkey: ka(r, e.monkey)
2794
+ monkey: Da(r, e.monkey)
2807
2795
  };
2808
- }, ja = (e) => ({
2796
+ }, ka = (e) => ({
2809
2797
  ...e.monkey,
2810
2798
  entry: e.entry,
2811
- userscript: wa(e.monkey.userscript),
2799
+ userscript: Sa(e.monkey.userscript),
2812
2800
  server: { ...e.monkey.server },
2813
2801
  build: { ...e.monkey.build }
2814
2802
  });
2815
2803
  //#endregion
2816
2804
  //#region packages/cli/src/vite/makoo.ts
2817
- function Ma(t) {
2818
- let { root: n, ...r } = t, i = ja(Aa(r, n));
2805
+ function Aa(t) {
2806
+ let { root: n, ...r } = t, i = ka(Oa(r, n));
2819
2807
  return e(i);
2820
2808
  }
2821
2809
  //#endregion
2822
2810
  //#region packages/cli/src/session/DevSession.ts
2823
- var Na = class {
2811
+ var ja = 5, Ma = class {
2824
2812
  clients = /* @__PURE__ */ new Map();
2825
2813
  nextClientId = 1;
2826
2814
  onChange = null;
@@ -2834,33 +2822,27 @@ var Na = class {
2834
2822
  n || (n = {
2835
2823
  clientId: this.nextClientId,
2836
2824
  runtimes: /* @__PURE__ */ new Map()
2837
- }, this.nextClientId += 1, this.clients.set(e, n)), n.runtimes.set(t.runtimeId, { tasks: /* @__PURE__ */ new Map() }), this.onChange?.();
2825
+ }, this.nextClientId += 1, this.clients.set(e, n)), n.runtimes.set(t.runtimeId, {
2826
+ injections: /* @__PURE__ */ new Map(),
2827
+ diagnostics: []
2828
+ }), this.onChange?.();
2838
2829
  }
2839
- record(e, t) {
2840
- let n = this.clients.get(e);
2841
- if (!n) return;
2842
- let r = n.runtimes.get(t.runtimeId);
2843
- if (!r) return;
2844
- let { event: i } = t;
2845
- switch (i.name) {
2846
- case "task:afterDestroy":
2847
- i.taskId && r.tasks.delete(i.taskId);
2848
- break;
2849
- case "register:success":
2850
- i.taskId && i.kind && i.status && i.injectAt && r.tasks.set(i.taskId, {
2851
- taskId: i.taskId,
2852
- kind: i.kind,
2853
- status: i.status,
2854
- injectAt: i.injectAt
2855
- });
2830
+ updateInjection(e, t) {
2831
+ let n = this.clients.get(e)?.runtimes.get(t.runtimeId);
2832
+ n && (n.injections.set(t.injection.name, t.injection), this.onChange?.());
2833
+ }
2834
+ applyNotice(e, t) {
2835
+ let n = this.clients.get(e)?.runtimes, r = n?.get(t.runtimeId);
2836
+ if (!n || !r) return;
2837
+ let { notice: i } = t;
2838
+ switch (i.type) {
2839
+ case "injection-removed":
2840
+ r.injections.delete(i.name);
2856
2841
  break;
2857
- default: {
2858
- if (!i.taskId) break;
2859
- let e = r.tasks.get(i.taskId);
2860
- if (!e) break;
2861
- i.status && (e.status = i.status), i.injectAt && (e.injectAt = i.injectAt);
2842
+ case "diagnostic":
2843
+ r.diagnostics.push(i), r.diagnostics.length > ja && r.diagnostics.shift();
2862
2844
  break;
2863
- }
2845
+ case "instance-disposed": n.delete(t.runtimeId);
2864
2846
  }
2865
2847
  this.onChange?.();
2866
2848
  }
@@ -2870,164 +2852,142 @@ var Na = class {
2870
2852
  isEmpty() {
2871
2853
  return this.clients.size === 0;
2872
2854
  }
2873
- getTasks() {
2855
+ getRuntimeSnapshots() {
2874
2856
  return [...this.clients.values()].flatMap((e) => [...e.runtimes.entries()].map(([t, n]) => ({
2875
2857
  clientId: e.clientId,
2876
2858
  runtimeId: t,
2877
- tasks: [...n.tasks.values()]
2859
+ injections: [...n.injections.values()],
2860
+ diagnostics: [...n.diagnostics]
2878
2861
  })));
2879
2862
  }
2880
- }, Pa = "\0virtual:makoo-dev", Fa = "@makoojs/core", Ia = Symbol("makooDev.bindSession");
2881
- function La(e) {
2863
+ }, Na = "\0virtual:makoo-dev", Pa = "@makoojs/core", $ = {
2864
+ open: "makoo:runtime:open",
2865
+ injection: "makoo:runtime:injection",
2866
+ notice: "makoo:runtime:notice"
2867
+ }, Fa = Symbol("makooDev.bindSession");
2868
+ function Ia(e) {
2882
2869
  let t = JSON.stringify(e);
2883
2870
  return `
2884
2871
  export * from ${t};
2885
- import {
2886
- createMakoo as __makooCreateMakoo,
2887
- createObserverHub as __makooCreateObserverHub,
2888
- MakooError as __MakooError
2889
- } from ${t};
2890
-
2891
- function __makooSerializeObserveEvent(event) {
2892
- const { error, ...rest } = event;
2872
+ import { createMakoo as __makooCreateMakoo } from ${t};
2893
2873
 
2894
- if (error === undefined) {
2895
- return rest;
2874
+ function __makooSend(event, payload) {
2875
+ try {
2876
+ import.meta.hot?.send(event, payload);
2877
+ } catch {
2878
+ // Session transport failures must not affect the user runtime.
2896
2879
  }
2880
+ }
2897
2881
 
2898
- if (error instanceof __MakooError) {
2899
- return {
2900
- ...rest,
2901
- error: {
2902
- name: error.name,
2903
- message: error.message,
2904
- stack: error.stack,
2905
- code: error.code,
2906
- summary: error.summary,
2907
- issues: error.issues,
2908
- context: error.context
2909
- }
2910
- };
2882
+ function __makooSerializeError(error) {
2883
+ const serialized = { code: error.code, message: error.message };
2884
+ if (error.cause !== undefined) {
2885
+ serialized.cause = error.cause instanceof Error ? error.cause.message : String(error.cause);
2911
2886
  }
2887
+ return serialized;
2888
+ }
2912
2889
 
2913
- if (error instanceof Error) {
2914
- return {
2915
- ...rest,
2916
- error: {
2917
- name: error.name,
2918
- message: error.message,
2919
- stack: error.stack
2920
- }
2921
- };
2890
+ function __makooSnapshotInjection(declaration, statusHandle) {
2891
+ const isComponent = declaration.kind === 'component';
2892
+ const snapshot = {
2893
+ name: declaration.name,
2894
+ kind: isComponent ? 'component' : 'standalone-listener',
2895
+ status: statusHandle.getSnapshot()
2896
+ };
2897
+ if (statusHandle.lastError) snapshot.lastError = __makooSerializeError(statusHandle.lastError);
2898
+ if (isComponent) {
2899
+ snapshot.attachedListeners = statusHandle.attachedListenerNames.map((listenerName) => ({
2900
+ name: listenerName,
2901
+ status: statusHandle.attachedListener(listenerName).getSnapshot()
2902
+ }));
2922
2903
  }
2904
+ return snapshot;
2905
+ }
2923
2906
 
2924
- return {
2925
- ...rest,
2926
- error: {
2927
- message: String(error)
2928
- }
2929
- };
2907
+ function __makooSerializeNotice(notice) {
2908
+ if (notice.type !== 'diagnostic') return notice;
2909
+ return { ...notice, error: __makooSerializeError(notice.error) };
2930
2910
  }
2931
2911
 
2932
- function __makooSend(event, payload) {
2912
+ function __makooWatchInjection(runtime, runtimeId, declaration) {
2913
+ let statusHandle;
2933
2914
  try {
2934
- import.meta.hot?.send(event, payload);
2915
+ statusHandle = runtime.statusHandle(declaration.name);
2935
2916
  } catch {
2936
- // Session transport failures must not affect the user runtime.
2917
+ // An earlier mount in the same batch already removed this injection.
2918
+ return;
2937
2919
  }
2938
- }
2939
-
2940
- function __makooCreateSessionObserver(observer, runtimeId) {
2941
- const sendEvent = (event) => {
2942
- __makooSend('makoo:runtime:event', {
2920
+ const push = () => {
2921
+ __makooSend('${$.injection}', {
2943
2922
  runtimeId,
2944
- event: __makooSerializeObserveEvent(event)
2923
+ injection: __makooSnapshotInjection(declaration, statusHandle)
2945
2924
  });
2946
2925
  };
2947
-
2948
- return {
2949
- on(event, hook) {
2950
- return observer.on(event, hook);
2951
- },
2952
- onTask(taskId, event, hook) {
2953
- return observer.onTask(taskId, event, hook);
2954
- },
2955
- onAny(hook) {
2956
- return observer.onAny(hook);
2957
- },
2958
- off(event, hook) {
2959
- observer.off(event, hook);
2960
- },
2961
- offTask(taskId, event, hook) {
2962
- observer.offTask(taskId, event, hook);
2963
- },
2964
- offAny(hook) {
2965
- observer.offAny(hook);
2966
- },
2967
- clear() {
2968
- observer.clear();
2969
- },
2970
- hasHooks(event) {
2971
- return observer.hasHooks(event);
2972
- },
2973
- emit(event) {
2974
- sendEvent(event);
2975
- observer.emit(event);
2976
- },
2977
- emitOnTask(taskId, event) {
2978
- let normalized = event;
2979
- if (event.taskId !== taskId) normalized = { ...event, taskId };
2980
- sendEvent(normalized);
2981
- observer.emitOnTask(taskId, event);
2926
+ push();
2927
+ statusHandle.subscribe(push);
2928
+ if (declaration.kind === 'component') {
2929
+ for (const listenerName of statusHandle.attachedListenerNames) {
2930
+ statusHandle.attachedListener(listenerName).subscribe(push);
2982
2931
  }
2983
- };
2932
+ }
2984
2933
  }
2985
2934
 
2986
2935
  let __makooNextRuntimeId = 1;
2987
2936
 
2988
- export function createMakoo(options = {}) {
2937
+ export function createMakoo() {
2938
+ const runtime = __makooCreateMakoo();
2989
2939
  const runtimeId = __makooNextRuntimeId++;
2990
- const baseObserver = options.observer ?? __makooCreateObserverHub(options.logger);
2991
- const observer = __makooCreateSessionObserver(baseObserver, runtimeId);
2992
- const makoo = __makooCreateMakoo({
2993
- ...options,
2994
- observer
2940
+ __makooSend('${$.open}', { runtimeId });
2941
+ runtime.observe((notice) => {
2942
+ __makooSend('${$.notice}', { runtimeId, notice: __makooSerializeNotice(notice) });
2995
2943
  });
2996
-
2997
- __makooSend('makoo:runtime:open', { runtimeId });
2998
- return makoo;
2944
+ return {
2945
+ ...runtime,
2946
+ apply(declarations) {
2947
+ runtime.apply(declarations);
2948
+ for (const declaration of declarations) {
2949
+ __makooWatchInjection(runtime, runtimeId, declaration);
2950
+ }
2951
+ }
2952
+ };
2999
2953
  }
3000
2954
  `;
3001
2955
  }
3002
- function Ra() {
3003
- let e = null, t = new Na();
2956
+ function La() {
2957
+ let e = null, t = new Ma();
3004
2958
  return {
3005
2959
  name: "makoo:dev",
3006
2960
  apply: "serve",
3007
2961
  enforce: "pre",
3008
2962
  api: { session: t },
3009
2963
  async resolveId(t, n, r) {
3010
- if (t !== Fa) return null;
3011
- let i = await this.resolve(Fa, n, {
2964
+ if (t !== Pa) return null;
2965
+ let i = await this.resolve(Pa, n, {
3012
2966
  ...r,
3013
2967
  skipSelf: !0
3014
2968
  });
3015
- return i ? (e = i.id, Pa) : null;
2969
+ return i ? (e = i.id, Na) : null;
3016
2970
  },
3017
2971
  load(t) {
3018
- return t !== Pa || !e ? null : La(e);
2972
+ return t !== Na || !e ? null : Ia(e);
3019
2973
  },
3020
2974
  configureServer(e) {
3021
- let n = e.config.inlineConfig[Ia];
3022
- n?.(t), e.hot.on("makoo:runtime:open", (e, n) => {
3023
- t.open(n, e);
3024
- }), e.hot.on("makoo:runtime:event", (e, n) => {
3025
- t.record(n, e);
3026
- }), e.hot.on("vite:client:disconnect", (e, n) => {
3027
- t.disconnect(n);
3028
- });
2975
+ let n = e.config.inlineConfig[Fa];
2976
+ n?.(t);
2977
+ for (let n of Object.values(e.environments)) {
2978
+ let { hot: e } = n;
2979
+ e.on($.open, (e, n) => {
2980
+ t.open(n, e);
2981
+ }), e.on($.injection, (e, n) => {
2982
+ t.updateInjection(n, e);
2983
+ }), e.on($.notice, (e, n) => {
2984
+ t.applyNotice(n, e);
2985
+ }), e.on("vite:client:disconnect", (e, n) => {
2986
+ t.disconnect(n);
2987
+ });
2988
+ }
3029
2989
  }
3030
2990
  };
3031
2991
  }
3032
2992
  //#endregion
3033
- export { t as cdn, Ma as makoo, Ra as makooDev };
2993
+ export { t as cdn, Aa as makoo, La as makooDev };