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