@incajs/cli 0.0.6 → 0.0.8

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/cli.js CHANGED
@@ -1,18 +1,19 @@
1
1
  import { i as e, n as t, o as n, r, t as i } from "./chunks/defaults-DNvHueCI.js";
2
2
  import a from "node:path";
3
- import { existsSync as o } from "node:fs";
4
- import { chmod as s, cp as c, link as l, mkdir as u, readFile as d, readdir as f, rm as p, writeFile as m } from "node:fs/promises";
5
- import { styleText as h } from "node:util";
6
- import { fileURLToPath as g } from "node:url";
7
- import { DevEnvironment as _, build as v, buildErrorMessage as y, createServer as b } from "vite";
8
- import x from "@vitejs/plugin-vue";
9
- import { createRequire as S } from "node:module";
3
+ import { existsSync as o, lstatSync as s, realpathSync as c, statSync as l } from "node:fs";
4
+ import { chmod as u, cp as d, link as f, mkdir as p, readFile as m, readdir as h, rm as g, writeFile as _ } from "node:fs/promises";
5
+ import { styleText as v } from "node:util";
6
+ import { fileURLToPath as y } from "node:url";
7
+ import { DevEnvironment as b, build as x, buildErrorMessage as S, createServer as C } from "vite";
8
+ import w from "@vitejs/plugin-vue";
9
+ import { createRequire as T } from "node:module";
10
10
  import { spawn as ee } from "node:child_process";
11
- import { once as C } from "node:events";
11
+ import { once as E } from "node:events";
12
12
  import te from "node:readline";
13
13
  import { setTimeout as ne } from "node:timers/promises";
14
+ import { randomUUID as D } from "node:crypto";
14
15
  //#region src/error.mts
15
- var w = class extends Error {
16
+ var O = class extends Error {
16
17
  code;
17
18
  name = "IncaError";
18
19
  constructor(e, t) {
@@ -29,10 +30,39 @@ var w = class extends Error {
29
30
  function ae(e) {
30
31
  return e === e.trim() && e !== "" && e !== "." && e !== ".." && !ie.test(e);
31
32
  }
32
- function T(e) {
33
- if (!(typeof e == "string" && ae(e))) throw new w("ERR_INCA_PRODUCT_NAME_INVALID", `${JSON.stringify(e)} can't name a directory — set a "productName" in inca.config.ts with no leading or trailing space, and none of \`/\\:*?"<>|\``);
33
+ function k(e) {
34
+ if (!(typeof e == "string" && ae(e))) throw new O("ERR_INCA_PRODUCT_NAME_INVALID", `${JSON.stringify(e)} can't name a directory — set a "productName" in inca.config.ts with no leading or trailing space, and none of \`/\\:*?"<>|\``);
35
+ }
36
+ var oe = process.platform === "darwin" || process.platform === "win32";
37
+ function se(e, t) {
38
+ let n = (e) => oe ? e.toLowerCase() : e, r = a.relative(n(e), n(t));
39
+ return r === "" || r !== ".." && !r.startsWith(`..${a.sep}`) && !a.isAbsolute(r);
40
+ }
41
+ function A(e) {
42
+ let t = a.resolve(e), n = t;
43
+ for (let e; !s(n, { throwIfNoEntry: !1 }) && (e = a.dirname(n)) !== n;) n = e;
44
+ return a.join(c.native(n), a.relative(n, t));
34
45
  }
35
- async function E(e) {
46
+ function j(e, t, n) {
47
+ let r = a.resolve(e, t), i;
48
+ try {
49
+ let t = A(r);
50
+ i = [
51
+ e,
52
+ a.join(e, "src"),
53
+ a.join(e, "node_modules"),
54
+ ...n ? [n] : []
55
+ ].some((e) => se(t, A(e)));
56
+ } catch {
57
+ i = !0;
58
+ }
59
+ if (i) throw new O("ERR_INCA_OUT_DIR_INVALID", `"outDir" resolves to ${r}, which holds the app's own files. Set it to a directory the build can own, such as "dist"`);
60
+ }
61
+ function M(e, t, n) {
62
+ let r = a.resolve(e, t ?? i.outDir);
63
+ return j(e, r, n), r;
64
+ }
65
+ async function N(e) {
36
66
  let { config: t, layers: r } = await n({
37
67
  cwd: e,
38
68
  ...re
@@ -42,31 +72,31 @@ async function E(e) {
42
72
  usedPackageJsonKey: Object.keys(i?.config ?? {}).length > 0
43
73
  };
44
74
  }
45
- async function D(e) {
46
- let { config: t } = await E(e);
75
+ async function P(e) {
76
+ let { config: t } = await N(e), n = t.entry ? a.resolve(e, t.entry) : void 0;
47
77
  return {
48
- entry: t.entry ? a.resolve(e, t.entry) : void 0,
49
- outDir: a.resolve(e, t.outDir ?? i.outDir)
78
+ entry: n,
79
+ outDir: M(e, t.outDir, n)
50
80
  };
51
81
  }
52
- async function O(e) {
82
+ async function ce(e) {
53
83
  let n = a.join(e, "package.json"), s;
54
84
  try {
55
- s = await d(n, "utf8");
85
+ s = await m(n, "utf8");
56
86
  } catch {
57
- throw new w("ERR_INCA_PACKAGE_JSON_NOT_FOUND", `no package.json found at ${n}`);
87
+ throw new O("ERR_INCA_PACKAGE_JSON_NOT_FOUND", `no package.json found at ${n}`);
58
88
  }
59
- let c = JSON.parse(s), { config: l, usedPackageJsonKey: u } = await E(e), f = l.productName ?? r(c.name);
60
- if (!f) throw new w("ERR_INCA_PRODUCT_NAME_MISSING", `${n} needs a "name", or "productName" in inca.config.ts`);
61
- T(f);
62
- let p = l.version ?? c.version ?? i.version, m = l.identifier ?? t(f), h;
63
- if (l.icon && (h = a.resolve(e, l.icon), !o(h))) throw new w("ERR_INCA_ICON_NOT_FOUND", `"icon" points to ${h}, which doesn't exist`);
64
- let g = l.entry ? a.resolve(e, l.entry) : void 0, _ = a.resolve(e, l.outDir ?? i.outDir);
89
+ let c = JSON.parse(s), { config: l, usedPackageJsonKey: u } = await N(e), d = l.productName ?? r(c.name);
90
+ if (!d) throw new O("ERR_INCA_PRODUCT_NAME_MISSING", `${n} needs a "name", or "productName" in inca.config.ts`);
91
+ k(d);
92
+ let f = l.version ?? c.version ?? i.version, p = l.identifier ?? t(d), h;
93
+ if (l.icon && (h = a.resolve(e, l.icon), !o(h))) throw new O("ERR_INCA_ICON_NOT_FOUND", `"icon" points to ${h}, which doesn't exist`);
94
+ let g = l.entry ? a.resolve(e, l.entry) : void 0, _ = M(e, l.outDir, g);
65
95
  return {
66
- productName: f,
67
- identifier: m,
96
+ productName: d,
97
+ identifier: p,
68
98
  identifierIsDefault: l.identifier === void 0,
69
- version: p,
99
+ version: f,
70
100
  icon: h,
71
101
  window: l.window,
72
102
  entry: g,
@@ -74,20 +104,20 @@ async function O(e) {
74
104
  usedPackageJsonKey: u
75
105
  };
76
106
  }
77
- function k(e) {
107
+ function le(e) {
78
108
  return {
79
109
  name: e.productName,
80
110
  identifier: e.identifier,
81
111
  window: e.window
82
112
  };
83
113
  }
84
- async function A(e) {
85
- let { config: n } = await E(e), i = {};
114
+ async function ue(e) {
115
+ let { config: n } = await N(e), i = {};
86
116
  try {
87
- i = JSON.parse(await d(a.join(e, "package.json"), "utf8"));
117
+ i = JSON.parse(await m(a.join(e, "package.json"), "utf8"));
88
118
  } catch {}
89
119
  let o = n.productName ?? r(i.name);
90
- o && T(o);
120
+ o && k(o);
91
121
  let s = {
92
122
  name: o,
93
123
  identifier: n.identifier ?? (o ? t(o) : void 0),
@@ -97,7 +127,7 @@ async function A(e) {
97
127
  }
98
128
  //#endregion
99
129
  //#region src/adapter/vite/captureOutput.mts
100
- function j(e, t, n) {
130
+ function de(e, t, n) {
101
131
  return {
102
132
  outDir: e,
103
133
  entryFile: a.join(e, t.entryFile),
@@ -105,12 +135,12 @@ function j(e, t, n) {
105
135
  changed: n
106
136
  };
107
137
  }
108
- function oe(e) {
138
+ function fe(e) {
109
139
  return {
110
140
  name: "inca:capture-output",
111
141
  writeBundle(t, n) {
112
142
  let r = Object.keys(n), i = Object.values(n).find((e) => e.type === "chunk" && e.isEntry);
113
- if (!i) throw new w("ERR_INCA_BUILD_NO_ENTRY_CHUNK", "build produced no entry chunk");
143
+ if (!i) throw new O("ERR_INCA_BUILD_NO_ENTRY_CHUNK", "build produced no entry chunk");
114
144
  e({
115
145
  entryFile: i.fileName,
116
146
  files: r
@@ -120,19 +150,19 @@ function oe(e) {
120
150
  }
121
151
  //#endregion
122
152
  //#region src/adapter/vite/emitConfig.mts
123
- var M = "inca.json";
124
- function N(e) {
153
+ var F = "inca.json";
154
+ function I(e) {
125
155
  let t = JSON.stringify(e, void 0, 2);
126
156
  if (t !== void 0 && t !== "{}") return `${t}\n`;
127
157
  }
128
- function se(e) {
129
- let t = N(e);
158
+ function pe(e) {
159
+ let t = I(e);
130
160
  return {
131
161
  name: "inca:emit-config",
132
162
  generateBundle() {
133
163
  t && this.emitFile({
134
164
  type: "asset",
135
- fileName: M,
165
+ fileName: F,
136
166
  source: t
137
167
  });
138
168
  }
@@ -140,8 +170,8 @@ function se(e) {
140
170
  }
141
171
  //#endregion
142
172
  //#region src/adapter/vite/logger.mts
143
- var ce = "Build failed with ", le = "Pre-transform error";
144
- function P(e, t, n = !1) {
173
+ var me = "Build failed with ", he = "Pre-transform error";
174
+ function L(e, t, n = !1) {
145
175
  let r = /* @__PURE__ */ new WeakSet(), i = /* @__PURE__ */ new Set(), a = {
146
176
  hasWarned: !1,
147
177
  info(t) {
@@ -154,7 +184,7 @@ function P(e, t, n = !1) {
154
184
  i.has(e) || (i.add(e), a.warn(e));
155
185
  },
156
186
  error(e, n) {
157
- a.hasWarned = !0, n?.error && r.add(n.error), !e.includes(ce) && (e.includes(le) || t.write(`${e.replace(/\n\s+at .*/g, "")}\n`));
187
+ a.hasWarned = !0, n?.error && r.add(n.error), !e.includes(me) && (e.includes(he) || t.write(`${e.replace(/\n\s+at .*/g, "")}\n`));
158
188
  },
159
189
  clearScreen() {},
160
190
  hasErrorLogged(e) {
@@ -165,7 +195,7 @@ function P(e, t, n = !1) {
165
195
  }
166
196
  //#endregion
167
197
  //#region src/adapter/vite/unsupported.mts
168
- var ue = /\.(?:css|pcss|postcss|sass|scss|less|styl|stylus)(?:\?|$)/, de = [{
198
+ var ge = /\.(?:css|pcss|postcss|sass|scss|less|styl|stylus)(?:\?|$)/, _e = [{
169
199
  code: "ERR_INCA_UNSUPPORTED_STYLE",
170
200
  name: "a <style> block",
171
201
  matches: (e) => e.includes("vue&type=style"),
@@ -173,10 +203,10 @@ var ue = /\.(?:css|pcss|postcss|sass|scss|less|styl|stylus)(?:\?|$)/, de = [{
173
203
  }, {
174
204
  code: "ERR_INCA_UNSUPPORTED_STYLESHEET",
175
205
  name: "a stylesheet import",
176
- matches: (e) => ue.test(e),
206
+ matches: (e) => ge.test(e),
177
207
  hint: "the renderer applies no stylesheet — use a :style binding instead"
178
208
  }];
179
- function F(e = de) {
209
+ function R(e = _e) {
180
210
  return {
181
211
  name: "inca:reject-unsupported",
182
212
  enforce: "pre",
@@ -184,33 +214,36 @@ function F(e = de) {
184
214
  let r = e.find((e) => e.matches(n));
185
215
  if (!r) return null;
186
216
  let i = a.relative(process.cwd(), n.split("?")[0] ?? n);
187
- throw new w(r.code, `${r.code}: ${i} uses ${r.name}, unsupported for now: ${r.hint}`);
217
+ throw new O(r.code, `${r.code}: ${i} uses ${r.name}, unsupported for now: ${r.hint}`);
188
218
  }
189
219
  };
190
220
  }
191
221
  //#endregion
192
222
  //#region src/adapter/vite/config.mts
193
- var fe = "bundle.js";
194
- function I({ entry: e, outDir: t, mode: n, watch: r, onOutput: i, stdout: o, stderr: s, quiet: c, runtimeConfig: l }) {
223
+ var ve = "bundle.js";
224
+ function z({ entry: e, outDir: t, mode: n, watch: r, onOutput: i, stdout: o, stderr: s, quiet: c, runtimeConfig: l }) {
195
225
  return {
196
226
  configFile: !1,
197
227
  root: a.dirname(e),
198
228
  mode: n,
199
229
  clearScreen: !1,
200
230
  logLevel: c ? "silent" : "info",
201
- customLogger: P(o, s),
231
+ customLogger: L(o, s),
202
232
  define: { "process.env.NODE_ENV": JSON.stringify(n) },
203
233
  plugins: [
204
- x({ template: { compilerOptions: { runtimeModuleName: "@vue/runtime-core" } } }),
205
- F(),
206
- se(l),
207
- oe(i)
234
+ w({ template: { compilerOptions: {
235
+ runtimeModuleName: "@vue/runtime-core",
236
+ hoistStatic: !1
237
+ } } }),
238
+ R(),
239
+ pe(l),
240
+ fe(i)
208
241
  ],
209
242
  build: {
210
243
  lib: {
211
244
  entry: e,
212
245
  formats: ["es"],
213
- fileName: () => fe
246
+ fileName: () => ve
214
247
  },
215
248
  outDir: t,
216
249
  emptyOutDir: n === "production",
@@ -225,9 +258,9 @@ function I({ entry: e, outDir: t, mode: n, watch: r, onOutput: i, stdout: o, std
225
258
  }
226
259
  //#endregion
227
260
  //#region src/adapter/vite/build.mts
228
- async function pe({ entry: e, outDir: t, runtimeConfig: n, stdout: r = process.stdout, stderr: i = process.stderr, quiet: a = !1 }) {
261
+ async function ye({ entry: e, outDir: t, runtimeConfig: n, stdout: r = process.stdout, stderr: i = process.stderr, quiet: a = !1 }) {
229
262
  let o;
230
- if (await v(I({
263
+ if (await x(z({
231
264
  entry: e,
232
265
  outDir: t,
233
266
  runtimeConfig: n,
@@ -237,18 +270,18 @@ async function pe({ entry: e, outDir: t, runtimeConfig: n, stdout: r = process.s
237
270
  stderr: i,
238
271
  quiet: a,
239
272
  onOutput: (e) => {
240
- o = j(t, e);
273
+ o = de(t, e);
241
274
  }
242
- })), !o) throw new w("ERR_INCA_BUILD_NO_OUTPUT", "build produced no output");
275
+ })), !o) throw new O("ERR_INCA_BUILD_NO_OUTPUT", "build produced no output");
243
276
  return o;
244
277
  }
245
278
  //#endregion
246
279
  //#region src/adapter/vite/hmr.mts
247
- function L(e) {
280
+ function B(e) {
248
281
  return a.join(e, "node_modules/.inca/hmr");
249
282
  }
250
- function me() {
251
- let e = a.dirname(g(import.meta.url));
283
+ function be() {
284
+ let e = a.dirname(y(import.meta.url));
252
285
  for (; !o(a.join(e, "package.json"));) {
253
286
  let t = a.dirname(e);
254
287
  if (t === e) throw Error("could not locate @incajs/cli's own package.json");
@@ -256,34 +289,34 @@ function me() {
256
289
  }
257
290
  return a.join(e, "dist/hmr-runtime.js");
258
291
  }
259
- function he(e, t) {
292
+ function xe(e, t) {
260
293
  let n = a.relative(e, t).split(a.sep).join("/");
261
294
  return n.startsWith(".") ? n : `./${n}`;
262
295
  }
263
- async function ge(e, t, n) {
264
- let r = L(e);
265
- await u(r, { recursive: !0 });
266
- let i = a.join(r, "entry.js"), o = he(r, n ?? me()), s = t.split(a.sep).join("/");
267
- return await m(i, `import { start } from ${JSON.stringify(o)};\nstart(${JSON.stringify(s)}).catch((err) => console.error(err));\n`), i;
296
+ async function Se(e, t, n) {
297
+ let r = B(e);
298
+ await p(r, { recursive: !0 });
299
+ let i = a.join(r, "entry.js"), o = xe(r, n ?? be()), s = t.split(a.sep).join("/");
300
+ return await _(i, `import { start } from ${JSON.stringify(o)};\nstart(${JSON.stringify(s)}).catch((err) => console.error(err));\n`), i;
268
301
  }
269
- function _e(e) {
302
+ function Ce(e) {
270
303
  if (e.type === "error") return e.err;
271
304
  if (e.type === "custom" && e.event === "vite:invoke") return e.data?.data?.error;
272
305
  }
273
- function ve(e) {
306
+ function we(e) {
274
307
  if (e.type !== "custom" || e.event !== "vite:invoke") return !1;
275
308
  let t = e.data;
276
309
  return t.name === "fetchModule" && !t.data?.error;
277
310
  }
278
- function ye(e, t, n, r, i) {
311
+ function Te(e, t, n, r, i) {
279
312
  let a = /* @__PURE__ */ new Map(), o = { send: s };
280
313
  function s(a) {
281
314
  if (a.type === "full-reload") {
282
315
  t();
283
316
  return;
284
317
  }
285
- let o = _e(a);
286
- o ? (n(o), i.current = void 0) : ve(a) && i.current && (r({
318
+ let o = Ce(a);
319
+ o ? (n(o), i.current = void 0) : we(a) && i.current && (r({
287
320
  file: i.current.file,
288
321
  took: Date.now() - i.current.at
289
322
  }), i.current = void 0), e(a);
@@ -305,7 +338,7 @@ function ye(e, t, n, r, i) {
305
338
  }
306
339
  };
307
340
  }
308
- function be() {
341
+ function Ee() {
309
342
  let e = "\0inca:vite-client-shim";
310
343
  return {
311
344
  name: "inca:shim-vite-client",
@@ -318,7 +351,7 @@ function be() {
318
351
  }
319
352
  };
320
353
  }
321
- function xe(e) {
354
+ function De(e) {
322
355
  return {
323
356
  name: "inca:file-changed",
324
357
  hotUpdate(t) {
@@ -333,16 +366,16 @@ function xe(e) {
333
366
  }
334
367
  };
335
368
  }
336
- async function Se({ entry: e, cwd: t, runtimeConfig: n, runtimePath: r, stdout: i = process.stdout, stderr: o = process.stderr, quiet: s = !1, notify: c, reload: l, onError: u, onUpdate: d = () => {} }) {
337
- let f = await ge(t, e, r), p = N(n);
338
- p && await m(a.join(L(t), M), p);
339
- let h = { current: void 0 }, { channel: g, dispatch: v } = ye(c, l, u, d, h), y = await b({
369
+ async function Oe({ entry: e, cwd: t, runtimeConfig: n, runtimePath: r, stdout: i = process.stdout, stderr: o = process.stderr, quiet: s = !1, notify: c, reload: l, onError: u, onUpdate: d = () => {} }) {
370
+ let f = await Se(t, e, r), p = I(n);
371
+ p && await _(a.join(B(t), F), p);
372
+ let m = { current: void 0 }, { channel: h, dispatch: g } = Te(c, l, u, d, m), v = await C({
340
373
  configFile: !1,
341
374
  root: a.dirname(e),
342
375
  mode: "development",
343
376
  clearScreen: !1,
344
377
  logLevel: s ? "silent" : "info",
345
- customLogger: P(i, o, s),
378
+ customLogger: L(i, o, s),
346
379
  define: { "process.env.NODE_ENV": JSON.stringify("development") },
347
380
  server: {
348
381
  middlewareMode: !0,
@@ -353,65 +386,71 @@ async function Se({ entry: e, cwd: t, runtimeConfig: n, runtimePath: r, stdout:
353
386
  consumer: "client",
354
387
  dev: {
355
388
  moduleRunnerTransform: !0,
356
- createEnvironment: (e, t) => new _(e, t, {
389
+ createEnvironment: (e, t) => new b(e, t, {
357
390
  hot: !0,
358
- transport: g
391
+ transport: h
359
392
  })
360
393
  }
361
394
  } },
362
395
  plugins: [
363
- x({ template: { compilerOptions: { runtimeModuleName: "@vue/runtime-core" } } }),
364
- F(),
365
- be(),
366
- xe(h)
396
+ w({ template: { compilerOptions: {
397
+ runtimeModuleName: "@vue/runtime-core",
398
+ hoistStatic: !1
399
+ } } }),
400
+ R(),
401
+ Ee(),
402
+ De(m)
367
403
  ]
368
404
  });
369
405
  return {
370
406
  entryFile: f,
371
- dispatch: v,
372
- close: () => y.close()
407
+ dispatch: g,
408
+ close: () => v.close()
373
409
  };
374
410
  }
375
411
  //#endregion
376
412
  //#region src/dev-client/hostBin.mts
377
- var R = "INCA_HOST_BIN";
378
- function z() {
413
+ var V = "INCA_HOST_BIN";
414
+ function H() {
379
415
  let e = process.platform === "darwin" || process.platform === "linux" ? process.platform : void 0, t = process.arch === "arm64" || process.arch === "x64" ? process.arch : void 0;
380
416
  return e && t ? `@incajs/host-${e}-${t}` : void 0;
381
417
  }
382
- function Ce() {
383
- let e = z();
418
+ function ke() {
419
+ let e = H();
384
420
  if (e) try {
385
- return S(import.meta.url).resolve(`${e}/bin/inca-host`);
421
+ return T(import.meta.url).resolve(`${e}/bin/inca-host`);
386
422
  } catch {
387
423
  return;
388
424
  }
389
425
  }
390
- function B() {
391
- let e = process.env[R];
426
+ function U() {
427
+ let e = process.env[V];
392
428
  if (e) return e;
393
- let t = Ce();
429
+ let t = ke();
394
430
  if (t) return t;
395
- let n = z();
396
- throw new w("ERR_INCA_HOST_BIN_UNRESOLVED", `no inca-host binary found — ${n ? `no ${n} package is installed for it` : `this platform (${process.platform}/${process.arch}) has no published package`}, and ${R} isn't set to one`);
431
+ let n = H();
432
+ throw new O("ERR_INCA_HOST_BIN_UNRESOLVED", `no inca-host binary found — ${n ? `no ${n} package is installed for it` : `this platform (${process.platform}/${process.arch}) has no published package`}, and ${V} isn't set to one`);
433
+ }
434
+ function W(e) {
435
+ if (!l(e, { throwIfNoEntry: !1 })?.isFile()) throw new O("ERR_INCA_HOST_BIN_NOT_FOUND", `no host binary at ${e} — check that it was built and is executable`);
397
436
  }
398
437
  //#endregion
399
438
  //#region src/dev-client/hostError.mts
400
- var V = class extends Error {
439
+ var G = class extends Error {
401
440
  code;
402
441
  hostStack;
403
442
  constructor(e, t, n = null) {
404
443
  super(e), this.code = t, this.hostStack = n, this.name = "HostError";
405
444
  }
406
445
  };
407
- function we(e) {
446
+ function Ae(e) {
408
447
  return typeof e == "object" && !!e && e.jsonrpc === "2.0";
409
448
  }
410
449
  //#endregion
411
450
  //#region src/dev-client/hostClient.mts
412
- var Te = (e) => {
451
+ var je = (e) => {
413
452
  process.stderr.write(e.endsWith("\n") ? e : `${e}\n`);
414
- }, Ee = class {
453
+ }, Me = -32e3, Ne = class {
415
454
  #e;
416
455
  #t;
417
456
  #n = 1;
@@ -421,13 +460,15 @@ var Te = (e) => {
421
460
  this.#e = e;
422
461
  }
423
462
  async start() {
424
- let e = this.#e.hostBin ?? B(), t = ee(e, ["--dev", this.#e.entryFile], { stdio: [
463
+ let e = this.#e.hostBin ?? U();
464
+ W(e);
465
+ let t = ee(e, ["--dev", this.#e.entryFile], { stdio: [
425
466
  "pipe",
426
467
  "pipe",
427
468
  "pipe"
428
469
  ] });
429
470
  this.#t = t;
430
- let n = this.#e.onStderr ?? Te;
471
+ let n = this.#e.onStderr ?? je;
431
472
  t.stderr.setEncoding("utf8"), t.stderr.on("data", (e) => n(e)), t.stdin.on("error", (e) => {
432
473
  e.code !== "EPIPE" && n(`inca-host stdin: ${e.message}\n`);
433
474
  }), te.createInterface({ input: t.stdout }).on("line", (e) => {
@@ -436,7 +477,11 @@ var Te = (e) => {
436
477
  let n = /* @__PURE__ */ Error(`inca-host exited (code=${String(e)}, signal=${String(t)}) before answering`);
437
478
  for (let { reject: e } of this.#r.values()) e(n);
438
479
  this.#r.clear(), this.#i || this.#e.onExit?.(e, t);
439
- }), await C(t, "spawn");
480
+ });
481
+ let r = !1;
482
+ t.on("error", (e) => {
483
+ r && n(`inca-host: ${e.message}\n`);
484
+ }), await E(t, "spawn"), r = !0;
440
485
  }
441
486
  #a(e, t) {
442
487
  let n;
@@ -446,7 +491,7 @@ var Te = (e) => {
446
491
  t(`[stray stdout] ${e}`);
447
492
  return;
448
493
  }
449
- if (!we(n)) {
494
+ if (!Ae(n)) {
450
495
  t(`[stray stdout] ${e}`);
451
496
  return;
452
497
  }
@@ -454,8 +499,17 @@ var Te = (e) => {
454
499
  this.#o(n.method, n.params, t);
455
500
  return;
456
501
  }
502
+ if (n.id === null) {
503
+ if (!("error" in n)) return;
504
+ let { code: e, message: r, data: i } = n.error;
505
+ e === Me ? this.#e.onAppError?.({
506
+ message: r,
507
+ stack: i?.stack ?? null
508
+ }) : t(`[host error ${String(e)}] ${r}\n`);
509
+ return;
510
+ }
457
511
  let r = this.#r.get(n.id);
458
- r && (this.#r.delete(n.id), "error" in n ? r.reject(new V(n.error.message, n.error.code, n.error.data?.stack ?? null)) : r.resolve(n.result));
512
+ r && (this.#r.delete(n.id), "error" in n ? r.reject(new G(n.error.message, n.error.code, n.error.data?.stack ?? null)) : r.resolve(n.result));
459
513
  }
460
514
  #o(e, t, n) {
461
515
  switch (e) {
@@ -478,8 +532,7 @@ var Te = (e) => {
478
532
  }
479
533
  }
480
534
  async #s(e) {
481
- this.#i = !0;
482
- let t = C(e, "exit");
535
+ let t = E(e, "exit");
483
536
  e.kill(), await t;
484
537
  }
485
538
  async call(e, t, n) {
@@ -520,35 +573,35 @@ var Te = (e) => {
520
573
  let t = this.#t;
521
574
  if (!t || t.exitCode !== null || t.signalCode !== null) return;
522
575
  this.#i = !0;
523
- let n = C(t, "exit");
524
- this.call("shutdown").catch(() => {}), await Promise.race([n.then(() => "exited"), ne(e).then(() => "timeout")]) === "timeout" && (t.kill(), await n);
576
+ let n = E(t, "exit");
577
+ this.call("shutdown").catch(() => {}), await Promise.race([n.then(() => "exited"), ne(e, void 0, { ref: !1 }).then(() => "timeout")]) === "timeout" && (t.kill(), await n);
525
578
  }
526
- }, De = "[inca]", Oe = new Intl.DateTimeFormat(void 0, {
579
+ }, Pe = "[inca]", Fe = new Intl.DateTimeFormat(void 0, {
527
580
  hour: "numeric",
528
581
  minute: "numeric",
529
582
  second: "numeric"
530
583
  });
531
- function H(e, t, n) {
532
- let r = h(["bold", n], De, { stream: e });
533
- return t.timestamp ? `${h("dim", Oe.format(/* @__PURE__ */ new Date()), { stream: e })} ${r}` : r;
584
+ function K(e, t, n) {
585
+ let r = v(["bold", n], Pe, { stream: e });
586
+ return t.timestamp ? `${v("dim", Fe.format(/* @__PURE__ */ new Date()), { stream: e })} ${r}` : r;
534
587
  }
535
- function U(e, t, n = {}) {
536
- e.write(`${H(e, n, "cyan")} ${t}\n`);
588
+ function q(e, t, n = {}) {
589
+ e.write(`${K(e, n, "cyan")} ${t}\n`);
537
590
  }
538
- function W(e) {
591
+ function J(e) {
539
592
  let t = e.code;
540
593
  return typeof t == "string" ? t : null;
541
594
  }
542
- function ke(e) {
595
+ function Ie(e) {
543
596
  return /\bERR_INCA_[A-Z0-9_]+/.exec(e)?.[0] ?? null;
544
597
  }
545
- function Ae(e) {
598
+ function Le(e) {
546
599
  let t = e.stack;
547
600
  if (!t) return null;
548
601
  for (let n of [`${e.name}: ${e.message}`, e.message]) if (t.startsWith(n)) return t.slice(n.length).replace(/^\r?\n/, "") || null;
549
602
  return t;
550
603
  }
551
- function je(e) {
604
+ function Re(e) {
552
605
  let t = /^(?:\w*Error: )?(ERR_INCA_[A-Z0-9_]+): /.exec(e);
553
606
  return t ? {
554
607
  message: e.slice(t[0].length),
@@ -560,40 +613,40 @@ function je(e) {
560
613
  code: null
561
614
  };
562
615
  }
563
- function G(e) {
564
- return e instanceof V ? {
616
+ function Y(e) {
617
+ return e instanceof G ? {
565
618
  message: e.message,
566
619
  stack: e.hostStack,
567
- code: W(e)
620
+ code: J(e)
568
621
  } : e instanceof Error ? {
569
622
  message: e.message,
570
- stack: Ae(e),
571
- code: W(e) ?? ke(e.message)
623
+ stack: Le(e),
624
+ code: J(e) ?? Ie(e.message)
572
625
  } : {
573
626
  message: String(e),
574
627
  stack: null,
575
628
  code: null
576
629
  };
577
630
  }
578
- function Me(e, t) {
579
- return e.split("\n").map((e) => /^\s*at\b/.test(e) ? h("dim", e, { stream: t }) : e).join("\n");
631
+ function ze(e, t) {
632
+ return e.split("\n").map((e) => /^\s*at\b/.test(e) ? v("dim", e, { stream: t }) : e).join("\n");
580
633
  }
581
- function K(e, t, n, r = {}) {
582
- n.stack && e.write(`${Me(n.stack, e)}\n`);
583
- let i = n.code ? ` (${h("bold", n.code, { stream: e })})` : "";
584
- e.write(`${H(e, r, "red")} ${t}${i}: ${n.message}\n`);
634
+ function X(e, t, n, r = {}) {
635
+ n.stack && e.write(`${ze(n.stack, e)}\n`);
636
+ let i = n.code ? ` (${v("bold", n.code, { stream: e })})` : "";
637
+ e.write(`${K(e, r, "red")} ${t}${i}: ${n.message}\n`);
585
638
  }
586
639
  //#endregion
587
640
  //#region src/adapter/vite/watch.mts
588
- async function Ne({ onBuild: e, onError: t, stdout: n = process.stdout, stderr: r = process.stderr, quiet: i = !1, ...a }) {
589
- let { outDir: o } = a, s, c = await v(I({
641
+ async function Be({ onBuild: e, onError: t, stdout: n = process.stdout, stderr: r = process.stderr, quiet: i = !1, ...a }) {
642
+ let { outDir: o } = a, s, c = await x(z({
590
643
  ...a,
591
644
  watch: !0,
592
645
  stdout: n,
593
646
  stderr: r,
594
647
  quiet: i,
595
648
  onOutput: (t) => {
596
- e(j(o, t, s)), s = void 0;
649
+ e(de(o, t, s)), s = void 0;
597
650
  }
598
651
  }));
599
652
  return c.on("change", (e) => {
@@ -605,90 +658,119 @@ async function Ne({ onBuild: e, onError: t, stdout: n = process.stdout, stderr:
605
658
  if (e.code !== "ERROR") return;
606
659
  s = void 0;
607
660
  let { errors: n } = e.error;
608
- t(je(n?.[0]?.message ?? e.error.message));
661
+ t(Re(n?.[0]?.message ?? e.error.message));
609
662
  }), { close: () => c.close() };
610
663
  }
611
664
  //#endregion
612
665
  //#region src/defaultBundler.mts
613
- var q = {
614
- watch: Ne,
615
- build: pe,
616
- hmr: Se
666
+ var Ve = {
667
+ watch: Be,
668
+ build: ye,
669
+ hmr: Oe
617
670
  };
618
671
  //#endregion
619
672
  //#region src/entry.mts
620
- async function J(e) {
673
+ async function He(e) {
621
674
  let t = a.join(e, "src/main.mts");
622
675
  if (o(t)) return t;
623
676
  let n = a.join(e, "src/App.vue");
624
- if (o(n)) return Pe(n, e);
625
- throw new w("ERR_INCA_ENTRY_NOT_FOUND", `no app entry found — expected ${t} or ${n}`);
677
+ if (o(n)) return Ue(n, e);
678
+ throw new O("ERR_INCA_ENTRY_NOT_FOUND", `no app entry found — expected ${t} or ${n}`);
626
679
  }
627
- async function Pe(e, t) {
680
+ async function Ue(e, t) {
628
681
  let n = a.join(t, "node_modules/.inca");
629
- await u(n, { recursive: !0 });
682
+ await p(n, { recursive: !0 });
630
683
  let r = a.join(n, "entry.mts"), i = JSON.stringify(e.split(a.sep).join("/"));
631
- return await m(r, `import { createIncaApp } from "incajs/vue";\nimport App from ${i};\ncreateIncaApp(App).mount();\n`), r;
684
+ return await _(r, `import { createIncaApp } from "incajs/vue";\nimport App from ${i};\ncreateIncaApp(App).mount();\n`), r;
632
685
  }
633
686
  //#endregion
634
687
  //#region src/build.mts
635
- async function Y(e = {}) {
636
- let t = e.cwd ?? process.cwd(), n = e.config ?? await D(t), r = n.outDir, i = e.bundler ?? q, a = e.entry ?? n.entry ?? await J(t), o = e.runtimeConfig ?? await A(t);
688
+ async function We(e = {}) {
689
+ let t = e.cwd ?? process.cwd(), n = e.config ?? await P(t), r = a.resolve(t, n.outDir), i = e.bundler ?? Ve, o = e.entry ?? n.entry ?? await He(t);
690
+ j(t, r, o);
691
+ let s = e.runtimeConfig ?? await ue(t);
637
692
  return i.build({
638
- entry: a,
693
+ entry: o,
639
694
  outDir: r,
640
- runtimeConfig: o,
695
+ runtimeConfig: s,
641
696
  stdout: e.stdout,
642
697
  stderr: e.stderr
643
698
  });
644
699
  }
645
700
  //#endregion
646
701
  //#region src/dev-lock.mts
647
- function Fe(e) {
702
+ function Ge(e) {
648
703
  return a.join(e, "node_modules/.inca/dev.pid");
649
704
  }
650
- function Ie(e) {
705
+ function Ke(e) {
651
706
  try {
652
707
  return process.kill(e, 0), !0;
653
708
  } catch (e) {
654
709
  return e.code === "EPERM";
655
710
  }
656
711
  }
657
- async function Le(e) {
658
- let t = Fe(e), n = Number.parseInt(await d(t, "utf8").catch(() => ""), 10);
659
- if (Number.isInteger(n) && Ie(n)) throw new w("ERR_INCA_DEV_RUNNING", `inca dev is already running for this app (pid ${String(n)})`);
660
- return await u(a.dirname(t), { recursive: !0 }), await m(t, String(process.pid)), () => p(t, { force: !0 });
712
+ var qe = D();
713
+ function Z(e) {
714
+ return new O("ERR_INCA_DEV_RUNNING", `inca dev is already running for this app (pid ${String(e)})`);
715
+ }
716
+ async function Je(e) {
717
+ let t = Ge(e), n = `${String(process.pid)}:${qe}`, r = `${t}.${D()}`;
718
+ await p(a.dirname(t), { recursive: !0 }), await _(r, n);
719
+ let i = process.pid;
720
+ try {
721
+ for (let e = 0; e < 5; e++) {
722
+ try {
723
+ return await f(r, t), Ye(t, n);
724
+ } catch (e) {
725
+ if (e.code !== "EEXIST") throw e;
726
+ }
727
+ let e = await m(t, "utf8").catch(() => ""), a = Number.parseInt(e, 10);
728
+ if (a === process.pid) {
729
+ if (e === n) throw Z(a);
730
+ } else if (Number.isSafeInteger(a) && a > 0 && Ke(a)) throw Z(a);
731
+ i = Number.isSafeInteger(a) && a > 0 ? a : i, await g(t, { force: !0 });
732
+ }
733
+ throw Z(i);
734
+ } finally {
735
+ await g(r, { force: !0 });
736
+ }
737
+ }
738
+ function Ye(e, t) {
739
+ let n = !1;
740
+ return async () => {
741
+ n || (n = !0, await m(e, "utf8").catch(() => "") === t && await g(e, { force: !0 }));
742
+ };
661
743
  }
662
744
  //#endregion
663
745
  //#region src/plist.mts
664
- function X(e) {
746
+ function Xe(e) {
665
747
  return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
666
748
  }
667
- function Re(e) {
668
- return typeof e == "boolean" ? e ? "<true/>" : "<false/>" : `<string>${X(e)}</string>`;
749
+ function Ze(e) {
750
+ return typeof e == "boolean" ? e ? "<true/>" : "<false/>" : `<string>${Xe(e)}</string>`;
669
751
  }
670
- function ze(e) {
752
+ function Qe(e) {
671
753
  return `<?xml version="1.0" encoding="UTF-8"?>
672
754
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
673
755
  <plist version="1.0">
674
756
  <dict>
675
- ${Object.entries(e).map(([e, t]) => `\t<key>${X(e)}</key>\n\t${Re(t)}`).join("\n")}\n</dict>
757
+ ${Object.entries(e).map(([e, t]) => `\t<key>${Xe(e)}</key>\n\t${Ze(t)}`).join("\n")}\n</dict>
676
758
  </plist>
677
759
  `;
678
760
  }
679
761
  //#endregion
680
762
  //#region src/macos-app.mts
681
- async function Z(e) {
763
+ async function $e(e) {
682
764
  let { appPath: t, metadata: n, hostBin: r } = e;
683
- await p(t, {
765
+ await g(t, {
684
766
  recursive: !0,
685
767
  force: !0
686
768
  });
687
- let i = a.join(t, "Contents"), o = a.join(i, "MacOS"), d = a.join(i, "Resources");
688
- await u(o, { recursive: !0 }), await u(d, { recursive: !0 });
689
- let f = a.join(o, n.productName);
690
- e.link ? await l(r, f).catch(() => c(r, f)) : await c(r, f), await s(f, 493);
691
- let h = {
769
+ let i = a.join(t, "Contents"), o = a.join(i, "MacOS"), s = a.join(i, "Resources");
770
+ await p(o, { recursive: !0 }), await p(s, { recursive: !0 });
771
+ let c = a.join(o, n.productName);
772
+ e.link ? await f(r, c).catch(() => d(r, c)) : await d(r, c), await u(c, 493);
773
+ let l = {
692
774
  CFBundleName: n.productName,
693
775
  CFBundleDisplayName: n.productName,
694
776
  CFBundleExecutable: n.productName,
@@ -701,227 +783,244 @@ async function Z(e) {
701
783
  };
702
784
  if (n.icon) {
703
785
  let e = a.basename(n.icon);
704
- await c(n.icon, a.join(d, e)), h.CFBundleIconFile = e;
786
+ await d(n.icon, a.join(s, e)), l.CFBundleIconFile = e;
705
787
  }
706
- return await m(a.join(i, "Info.plist"), ze(h)), await m(a.join(i, "PkgInfo"), "APPL????"), {
788
+ return await _(a.join(i, "Info.plist"), Qe(l)), await _(a.join(i, "PkgInfo"), "APPL????"), {
707
789
  appPath: t,
708
- executablePath: f,
709
- resourcesDir: d
790
+ executablePath: c,
791
+ resourcesDir: s
710
792
  };
711
793
  }
712
794
  //#endregion
713
795
  //#region src/dev.mts
714
- var Q = { timestamp: !0 }, Be = 1e4, Ve = ["ERR_INCA_PACKAGE_JSON_NOT_FOUND", "ERR_INCA_PRODUCT_NAME_MISSING"];
715
- async function He(e, t) {
796
+ var Q = { timestamp: !0 }, et = 1e4, tt = ["ERR_INCA_PACKAGE_JSON_NOT_FOUND", "ERR_INCA_PRODUCT_NAME_MISSING"];
797
+ async function nt(e, t) {
716
798
  try {
717
- return await O(e);
799
+ return await ce(e);
718
800
  } catch (e) {
719
- if (!(e instanceof w) || !Ve.includes(e.code)) throw e;
720
- U(t, `running unnamed — ${e.message}`, Q);
801
+ if (!(e instanceof O) || !tt.includes(e.code)) throw e;
802
+ q(t, `running unnamed — ${e.message}`, Q);
721
803
  return;
722
804
  }
723
805
  }
724
- async function Ue(e, t, n, r) {
806
+ async function rt(e, t, n, r) {
725
807
  if (process.platform === "darwin" && t) try {
726
- return (await Z({
808
+ return (await $e({
727
809
  appPath: a.join(e, "node_modules/.inca", `${t.productName}.app`),
728
810
  metadata: t,
729
- hostBin: n ?? B(),
811
+ hostBin: n,
730
812
  link: !0
731
813
  })).executablePath;
732
814
  } catch (e) {
733
- U(r, `running unbundled — ${G(e).message}`, Q);
815
+ q(r, `running unbundled — ${Y(e).message}`, Q);
734
816
  return;
735
817
  }
736
818
  }
737
- function We(e) {
738
- let t = y(e, [], !1), n = [e.stack, t].filter((e) => e).join("\n");
819
+ function it(e) {
820
+ let t = S(e, [], !1), n = [e.stack, t].filter((e) => e).join("\n");
739
821
  return {
740
822
  message: e.message,
741
823
  stack: n || null,
742
824
  code: null
743
825
  };
744
826
  }
745
- async function Ge(e, t) {
827
+ async function at(e, t) {
746
828
  let n = new Set(t), r;
747
829
  try {
748
- r = await f(e, {
830
+ r = await h(e, {
749
831
  recursive: !0,
750
832
  withFileTypes: !0
751
833
  });
752
834
  } catch {
753
835
  return;
754
836
  }
755
- await Promise.all(r.filter((e) => e.isFile()).map((t) => a.relative(e, a.join(t.parentPath, t.name))).filter((e) => !n.has(e)).map((t) => p(a.join(e, t), { force: !0 })));
837
+ await Promise.all(r.filter((e) => e.isFile()).map((t) => a.relative(e, a.join(t.parentPath, t.name))).filter((e) => !n.has(e)).map((t) => g(a.join(e, t), { force: !0 })));
756
838
  }
757
- async function Ke(e) {
758
- let t = e.cwd ?? process.cwd(), n = await D(t), r = await Le(t);
839
+ async function ot(e) {
840
+ let t = e.cwd ?? process.cwd(), n = await P(t), r = await Je(t);
759
841
  try {
760
- let r = n.outDir, i = e.bundler ?? q, o = e.stdout ?? process.stdout, s = e.stderr ?? process.stderr, c = e.entry ?? n.entry ?? await J(t), l = await He(t, o), u = l ? k(l) : await A(t), d = await Ue(t, l, e.hostBin, o) ?? e.hostBin, f, p = !1, m = !1, g = Promise.resolve(), _ = () => {}, v = new Promise((e) => {
761
- _ = e;
842
+ let r = e.hostBin ?? U();
843
+ W(r);
844
+ let i = a.resolve(t, n.outDir), o = e.bundler ?? Ve, s = e.stdout ?? process.stdout, c = e.stderr ?? process.stderr, l = e.entry ?? n.entry ?? await He(t);
845
+ j(t, i, l);
846
+ let u = await nt(t, s), d = u ? le(u) : await ue(t), f = await rt(t, u, r, s) ?? r, p, m = !1, h = !1, g = !1, _, y = Promise.resolve(), b = () => {}, x = new Promise((e) => {
847
+ b = e;
762
848
  });
763
- async function y() {
849
+ async function S() {
764
850
  try {
765
- return await f?.call("reload", void 0, Be), !0;
851
+ return await p?.call("reload", void 0, et), !0;
766
852
  } catch (e) {
767
- return K(s, "reload failed", G(e), Q), !1;
853
+ return X(c, "reload failed", Y(e), Q), !1;
768
854
  }
769
855
  }
770
- async function b(e, t) {
771
- let n = new Ee({
856
+ async function C(e, t) {
857
+ let n = new Ne({
772
858
  entryFile: e,
773
- hostBin: d,
774
- onStderr: (e) => s.write(e),
859
+ hostBin: f,
860
+ onStderr: (e) => c.write(e),
775
861
  onReady: () => {
776
- p = !0, U(o, "ready", Q), m && (m = !1, y());
862
+ m = !0, q(s, "ready", Q), h && (h = !1, S());
777
863
  },
778
- onAppError: (e) => K(s, "app error", e, Q),
779
- onExit: () => {
780
- U(o, "host exited — stopping", Q), _();
864
+ onAppError: (e) => X(c, "app error", e, Q),
865
+ onExit: (e, t) => {
866
+ g = !m, _ = {
867
+ code: e,
868
+ signal: t
869
+ }, q(s, "host exited — stopping", Q), b();
781
870
  },
782
871
  integrations: t
783
872
  });
784
873
  try {
785
874
  await n.start();
786
875
  } catch (e) {
787
- K(s, "failed to start inca-host", G(e), Q);
876
+ X(c, "failed to start inca-host", Y(e), Q);
788
877
  return;
789
878
  }
790
- f = n;
879
+ p = n;
791
880
  }
792
- async function x(e) {
793
- if (await Ge(e.outDir, e.files), !f) {
794
- await b(e.entryFile);
881
+ async function w(e) {
882
+ if (await at(e.outDir, e.files), !p) {
883
+ await C(e.entryFile);
795
884
  return;
796
885
  }
797
- if (!p) {
798
- m = !0;
886
+ if (!m) {
887
+ h = !0;
799
888
  return;
800
889
  }
801
- if (await y() && e.changed) {
802
- let n = h("dim", a.relative(t, e.changed.file), { stream: o }), r = Date.now() - e.changed.at;
803
- U(o, `${h("green", "reload")} ${n} (${r}ms)`, Q);
890
+ if (await S() && e.changed) {
891
+ let n = v("dim", a.relative(t, e.changed.file), { stream: s }), r = Date.now() - e.changed.at;
892
+ q(s, `${v("green", "reload")} ${n} (${r}ms)`, Q);
804
893
  }
805
894
  }
806
- let S;
895
+ let T;
807
896
  if (e.experimentalHmr) {
808
- if (!i.hmr) throw new w("ERR_INCA_HMR_UNSUPPORTED", "--experimental-hmr was set, but the configured bundler has no HMR support");
809
- let e = await i.hmr({
810
- entry: c,
897
+ if (!o.hmr) throw new O("ERR_INCA_HMR_UNSUPPORTED", "--experimental-hmr was set, but the configured bundler has no HMR support");
898
+ let e = await o.hmr({
899
+ entry: l,
811
900
  cwd: t,
812
- runtimeConfig: u,
813
- stdout: o,
814
- stderr: s,
815
- notify: (e) => f?.notify("vite", e),
816
- reload: () => void y(),
817
- onError: (e) => K(s, "build failed", We(e), Q),
901
+ runtimeConfig: d,
902
+ stdout: s,
903
+ stderr: c,
904
+ notify: (e) => p?.notify("vite", e),
905
+ reload: () => void S(),
906
+ onError: (e) => X(c, "build failed", it(e), Q),
818
907
  onUpdate: ({ file: e, took: n }) => {
819
- let r = h("dim", a.relative(t, e), { stream: o });
820
- U(o, `${h("green", "update")} ${r} (${n}ms)`, Q);
908
+ let r = v("dim", a.relative(t, e), { stream: s });
909
+ q(s, `${v("green", "update")} ${r} (${n}ms)`, Q);
821
910
  }
822
911
  });
823
- await b(e.entryFile, { vite: (t) => e.dispatch(t) }), S = e, f || _();
824
- } else S = await i.watch({
825
- entry: c,
826
- outDir: r,
827
- runtimeConfig: u,
912
+ await C(e.entryFile, { vite: (t) => e.dispatch(t) }), T = e, p || b();
913
+ } else T = await o.watch({
914
+ entry: l,
915
+ outDir: i,
916
+ runtimeConfig: d,
828
917
  mode: "development",
829
- stdout: o,
830
- stderr: s,
918
+ stdout: s,
919
+ stderr: c,
831
920
  onBuild: (e) => {
832
- g = g.then(() => x(e));
921
+ y = y.then(() => w(e));
833
922
  },
834
923
  onError: (e) => {
835
- K(s, "build failed", e, Q);
924
+ X(c, "build failed", e, Q);
836
925
  }
837
926
  });
838
- e.signal.aborted ? _() : e.signal.addEventListener("abort", () => _(), { once: !0 }), await v, await g, await f?.stop(), await S.close();
927
+ if (e.signal.aborted ? b() : e.signal.addEventListener("abort", () => b(), { once: !0 }), await x, await y, await p?.stop(), await T.close(), g) throw new O("ERR_INCA_HOST_EXITED_EARLY", "the host exited before it was ready");
928
+ if (_ && _.code !== 0 && _.signal !== "SIGINT" && _.signal !== "SIGTERM") {
929
+ let { code: e, signal: t } = _;
930
+ throw new O("ERR_INCA_HOST_CRASHED", `the host exited with ${t ? `signal ${t}` : `code ${e}`}`);
931
+ }
839
932
  } finally {
840
933
  await r();
841
934
  }
842
935
  }
843
936
  //#endregion
844
937
  //#region src/package.mts
845
- function qe() {
938
+ function st() {
846
939
  if (process.platform === "darwin") return "macos";
847
940
  if (process.platform === "linux") return "linux";
848
- throw new w("ERR_INCA_PLATFORM_UNSUPPORTED", `inca package doesn't support ${process.platform} yet`);
941
+ throw new O("ERR_INCA_PLATFORM_UNSUPPORTED", `inca package doesn't support ${process.platform} yet`);
849
942
  }
850
- async function $(e, t) {
943
+ async function ct(e, t) {
851
944
  await Promise.all(e.files.map(async (n) => {
852
945
  let r = a.join(t, n);
853
- await u(a.dirname(r), { recursive: !0 }), await c(a.join(e.outDir, n), r);
946
+ await p(a.dirname(r), { recursive: !0 }), await d(a.join(e.outDir, n), r);
854
947
  }));
855
948
  }
856
- async function Je({ metadata: e, output: t, hostBin: n }) {
857
- let { appPath: r, resourcesDir: i } = await Z({
949
+ function lt(e, t) {
950
+ let n = e.files.map((e) => e.split("/")[0] ?? e).find((e) => e.toLowerCase() === t.toLowerCase());
951
+ if (n !== void 0) throw new O("ERR_INCA_PRODUCT_NAME_INVALID", `the packaged app's directory "${t}" collides with "${n}" in the build output. Set a different "productName" in inca.config.ts`);
952
+ }
953
+ async function ut({ metadata: e, output: t, hostBin: n }) {
954
+ let { appPath: r, resourcesDir: i } = await $e({
858
955
  appPath: a.join(t.outDir, `${e.productName}.app`),
859
956
  metadata: e,
860
957
  hostBin: n
861
958
  });
862
- return await $(t, i), r;
959
+ return await ct(t, i), r;
863
960
  }
864
- async function Ye({ metadata: t, output: n, hostBin: r }) {
865
- let i = e(t.productName), o = a.join(n.outDir, i);
866
- await p(o, {
961
+ async function dt({ metadata: t, output: n, hostBin: r }) {
962
+ let i = e(t.productName);
963
+ lt(n, i);
964
+ let o = a.join(n.outDir, i);
965
+ await g(o, {
867
966
  recursive: !0,
868
967
  force: !0
869
- }), await u(o, { recursive: !0 });
870
- let l = a.join(o, i);
871
- return await c(r, l), await s(l, 493), await $(n, o), o;
872
- }
873
- async function Xe(e = {}) {
874
- let t = e.cwd ?? process.cwd(), n = e.stdout ?? process.stdout, r = e.target ?? qe(), i = await O(t);
875
- i.usedPackageJsonKey && U(n, "the \"inca\" key in package.json is deprecated — move these settings to inca.config.ts"), i.identifierIsDefault && U(n, `no "identifier" set in inca.config.ts — using generated identifier ${i.identifier}`);
876
- let a = await Y({
968
+ }), await p(o, { recursive: !0 });
969
+ let s = a.join(o, i);
970
+ return await d(r, s), await u(s, 493), await ct(n, o), o;
971
+ }
972
+ async function ft(e = {}) {
973
+ let t = e.cwd ?? process.cwd(), n = e.stdout ?? process.stdout, r = e.target ?? st(), i = await ce(t);
974
+ i.usedPackageJsonKey && q(n, "the \"inca\" key in package.json is deprecated — move these settings to inca.config.ts"), i.identifierIsDefault && q(n, `no "identifier" set in inca.config.ts — using generated identifier ${i.identifier}`);
975
+ let a = await We({
877
976
  cwd: t,
878
977
  entry: e.entry,
879
978
  config: i,
880
- runtimeConfig: k(i),
979
+ runtimeConfig: le(i),
881
980
  bundler: e.bundler,
882
981
  stdout: n,
883
982
  stderr: e.stderr
884
- }), s = e.hostBin ?? B();
885
- if (!o(s)) throw new w("ERR_INCA_HOST_BIN_NOT_FOUND", `no host binary at ${s} — check that it was built and is executable`);
886
- let c = {
983
+ }), o = e.hostBin ?? U();
984
+ W(o);
985
+ let s = {
887
986
  metadata: i,
888
987
  output: a,
889
- hostBin: s
988
+ hostBin: o
890
989
  };
891
- return { appPath: r === "macos" ? await Je(c) : await Ye(c) };
990
+ return { appPath: r === "macos" ? await ut(s) : await dt(s) };
892
991
  }
893
992
  //#endregion
894
993
  //#region src/cli.mts
895
- var Ze = "Usage: inca <dev|build|package>";
896
- function Qe(e) {
994
+ var pt = "Usage: inca <dev|build|package>";
995
+ function $(e) {
897
996
  return a.relative(process.cwd(), e);
898
997
  }
899
- async function $e(e = process.argv) {
998
+ async function mt(e = process.argv) {
900
999
  let t = e[2];
901
1000
  if (t === "build") {
902
1001
  try {
903
- let e = await Y();
904
- U(process.stdout, `built ${Qe(e.entryFile)}`);
1002
+ let e = await We();
1003
+ q(process.stdout, `built ${$(e.entryFile)}`);
905
1004
  } catch (e) {
906
- K(process.stderr, "build failed", G(e)), process.exitCode = 1;
1005
+ X(process.stderr, "build failed", Y(e)), process.exitCode = 1;
907
1006
  }
908
1007
  return;
909
1008
  }
910
1009
  if (t === "package") {
911
1010
  try {
912
- let { appPath: e } = await Xe();
913
- U(process.stdout, `packaged ${Qe(e)}`);
1011
+ let { appPath: e } = await ft();
1012
+ q(process.stdout, `packaged ${$(e)}`);
914
1013
  } catch (e) {
915
- K(process.stderr, "package failed", G(e)), process.exitCode = 1;
1014
+ X(process.stderr, "package failed", Y(e)), process.exitCode = 1;
916
1015
  }
917
1016
  return;
918
1017
  }
919
1018
  if (t !== "dev") {
920
- process.stderr.write(`${Ze}\n`), process.exitCode = 1;
1019
+ process.stderr.write(`${pt}\n`), process.exitCode = 1;
921
1020
  return;
922
1021
  }
923
1022
  let n = new AbortController(), r = () => {
924
- n.signal.aborted || (U(process.stderr, "shutting down", { timestamp: !0 }), n.abort());
1023
+ n.signal.aborted || (q(process.stderr, "shutting down", { timestamp: !0 }), n.abort());
925
1024
  };
926
1025
  process.on("SIGINT", r), process.on("SIGTERM", r);
927
1026
  let i = e.includes("--experimental-hmr") || ![
@@ -929,15 +1028,15 @@ async function $e(e = process.argv) {
929
1028
  "0",
930
1029
  "false"
931
1030
  ].includes(process.env.INCA_EXPERIMENTAL_HMR ?? "");
932
- i && U(process.stdout, "experimental HMR active", { timestamp: !0 });
1031
+ i && q(process.stdout, "experimental HMR active", { timestamp: !0 });
933
1032
  try {
934
- await Ke({
1033
+ await ot({
935
1034
  signal: n.signal,
936
1035
  experimentalHmr: i
937
1036
  });
938
1037
  } catch (e) {
939
- K(process.stderr, "dev failed", G(e), { timestamp: !0 }), process.exitCode = 1;
1038
+ X(process.stderr, "dev failed", Y(e), { timestamp: !0 }), process.exitCode = 1;
940
1039
  }
941
1040
  }
942
1041
  //#endregion
943
- export { $e as run };
1042
+ export { mt as run };
@@ -30,6 +30,18 @@ export interface RuntimeConfig {
30
30
  identifier?: string;
31
31
  window?: WindowConfig;
32
32
  }
33
+ /**
34
+ * Refuses an `outDir` that would hold the app's own sources. `inca dev` and
35
+ * `inca build` delete whatever a build didn't write under `outDir`. Symlinks
36
+ * are followed on both sides of the comparison.
37
+ *
38
+ * @param cwd - the app's root directory
39
+ * @param outDir - the `outDir`, absolute or relative to `cwd`
40
+ * @param entry - the resolved entry, if any
41
+ * @throws if it is, or contains, the app's root, `src/`, `node_modules/`, or
42
+ * the entry, or if a symlink on the way can't be resolved
43
+ */
44
+ export declare function assertOutDir(cwd: string, outDir: string, entry?: string): void;
33
45
  /**
34
46
  * Loads just `entry`/`outDir` from `inca.config.ts`, with derived defaults.
35
47
  * Never touches `package.json`.
@@ -45,7 +57,8 @@ export declare function resolveBuildConfig(cwd: string): Promise<ResolvedBuildCo
45
57
  * @param cwd - the app's root directory
46
58
  * @returns the resolved config
47
59
  * @throws if `package.json` is missing, has neither a `name` nor a
48
- * `productName`, or an `icon` doesn't resolve to a real file
60
+ * `productName`, an `icon` doesn't resolve to a real file, or `outDir`
61
+ * would hold the app's own files
49
62
  */
50
63
  export declare function resolveAppConfig(cwd: string): Promise<ResolvedAppConfig>;
51
64
  /**
@@ -7,3 +7,9 @@
7
7
  * it failed to install.
8
8
  */
9
9
  export declare function resolveHostBin(): string;
10
+ /**
11
+ * Checks that a host binary is a file.
12
+ * @param bin - the path to check
13
+ * @throws if nothing is a file at `bin`
14
+ */
15
+ export declare function assertHostBin(bin: string): void;
@@ -15,10 +15,10 @@ export interface HostClientOptions {
15
15
  * speaks the protocol revision this package was built for.
16
16
  */
17
17
  onReady?: () => void;
18
- /** An app's own event listener threw; the host caught it and kept rendering. */
18
+ /** An app's event listener threw, or the app threw while the host loaded it. */
19
19
  onAppError?: (error: AppErrorParams) => void;
20
20
  /**
21
- * The host exited on its own — its window was closed, or it crashed.
21
+ * The host exited on its own, or was stopped over a protocol mismatch.
22
22
  * Not called for the exit `stop()` asks for.
23
23
  */
24
24
  onExit?: (code: number | null, signal: NodeJS.Signals | null) => void;
@@ -40,8 +40,9 @@ export declare class HostClient {
40
40
  constructor(options: HostClientOptions);
41
41
  /**
42
42
  * Starts the child and wires up its streams. Resolves once the process
43
- * has actually spawned; rejects if it never does (e.g. the resolved
44
- * binary doesn't exist).
43
+ * has spawned. Rejects with `ERR_INCA_HOST_BIN_NOT_FOUND` if no file
44
+ * exists at the host binary's path, or with the spawn error if the
45
+ * process can't start.
45
46
  */
46
47
  start(): Promise<void>;
47
48
  /**
@@ -1,4 +1,4 @@
1
- export { resolveHostBin } from './hostBin.mts';
1
+ export { assertHostBin, resolveHostBin } from './hostBin.mts';
2
2
  export { HostError } from './hostError.mts';
3
3
  export { HostClient } from './hostClient.mts';
4
4
  export type { HostClientOptions } from './hostClient.mts';
@@ -21,7 +21,8 @@ export interface RpcResult {
21
21
  }
22
22
  export interface RpcFailure {
23
23
  jsonrpc: typeof JSONRPC;
24
- id: number;
24
+ /** `null` when the host fails before any call could be answered. */
25
+ id: number | null;
25
26
  error: {
26
27
  code: number;
27
28
  message: string;
@@ -2,9 +2,10 @@
2
2
  * Claims `cwd` for this process. Two `inca dev`s on one app watch the same
3
3
  * files and interleave their output on one terminal, and an orphan left by
4
4
  * an earlier run stays invisible until this says so. A lock whose pid is
5
- * gone is taken over.
5
+ * gone, or that an earlier run of this process left behind, is taken over.
6
6
  *
7
- * @returns a function releasing the lock.
7
+ * @param cwd - the app directory to claim
8
+ * @returns a function releasing the lock, safe to call more than once.
8
9
  * @throws if another live `inca dev` holds `cwd`.
9
10
  */
10
11
  export declare function acquireDevLock(cwd: string): Promise<() => Promise<void>>;
package/dist/dev.d.mts CHANGED
@@ -31,6 +31,9 @@ export interface DevOptions {
31
31
  * reloads it on every rebuild — until `options.signal` aborts or the host
32
32
  * exits on its own.
33
33
  *
34
- * @throws if another `inca dev` is already running for this app.
34
+ * @throws if another `inca dev` is already running for this app, or if the
35
+ * host binary can't be resolved or isn't a file. Both stop it before any build.
36
+ * Also throws if the host exits before it is ready, or exits non-zero or by
37
+ * a signal other than SIGINT/SIGTERM afterwards.
35
38
  */
36
39
  export declare function dev(options: DevOptions): Promise<void>;
@@ -41,7 +41,8 @@ export interface PackageResult {
41
41
  * app's own `dist/`. The app launches with no arguments and no terminal,
42
42
  * since `inca-host` finds its own bundle beside its executable.
43
43
  *
44
- * @throws if the app's metadata can't be read, the build fails, or no
45
- * `inca-host` binary can be resolved for the target platform.
44
+ * @throws if the app's metadata can't be read, the build fails, no
45
+ * `inca-host` binary can be resolved for the target platform, or no file
46
+ * exists at the resolved path.
46
47
  */
47
48
  export declare function packageApp(options?: PackageAppOptions): Promise<PackageResult>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@incajs/cli",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "Dev server, bundler, and packager for Incarnative.js apps.",
5
5
  "keywords": [
6
6
  "bundler",
@@ -70,9 +70,9 @@
70
70
  }
71
71
  },
72
72
  "optionalDependencies": {
73
- "@incajs/host-darwin-arm64": "0.0.6",
74
- "@incajs/host-linux-arm64": "0.0.6",
75
- "@incajs/host-linux-x64": "0.0.6"
73
+ "@incajs/host-darwin-arm64": "0.0.8",
74
+ "@incajs/host-linux-arm64": "0.0.8",
75
+ "@incajs/host-linux-x64": "0.0.8"
76
76
  },
77
77
  "engines": {
78
78
  "node": ">=22.18"