@incajs/cli 0.0.7 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,87 +1,102 @@
1
- import { i as e, n as t, o as n, r, t as i } from "./chunks/defaults-DNvHueCI.js";
1
+ import { i as e, n as t, o as n, r, t as i } from "./chunks/defaults-Bl2pge8b.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,31 @@ 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: [
440
- "pipe",
441
- "pipe",
442
- "pipe"
443
- ] });
463
+ let e = this.#e.hostBin ?? U();
464
+ W(e);
465
+ let t = ee(e, ["--dev", this.#e.entryFile], {
466
+ stdio: [
467
+ "pipe",
468
+ "pipe",
469
+ "pipe"
470
+ ],
471
+ env: this.#e.env
472
+ });
444
473
  this.#t = t;
445
- let n = this.#e.onStderr ?? De;
474
+ let n = this.#e.onStderr ?? je;
446
475
  t.stderr.setEncoding("utf8"), t.stderr.on("data", (e) => n(e)), t.stdin.on("error", (e) => {
447
476
  e.code !== "EPIPE" && n(`inca-host stdin: ${e.message}\n`);
448
- }), ee.createInterface({ input: t.stdout }).on("line", (e) => {
477
+ }), te.createInterface({ input: t.stdout }).on("line", (e) => {
449
478
  this.#a(e, n);
450
479
  }), t.on("exit", (e, t) => {
451
480
  let n = /* @__PURE__ */ Error(`inca-host exited (code=${String(e)}, signal=${String(t)}) before answering`);
452
481
  for (let { reject: e } of this.#r.values()) e(n);
453
482
  this.#r.clear(), this.#i || this.#e.onExit?.(e, t);
454
- }), await w(t, "spawn");
483
+ });
484
+ let r = !1;
485
+ t.on("error", (e) => {
486
+ r && n(`inca-host: ${e.message}\n`);
487
+ }), await E(t, "spawn"), r = !0;
455
488
  }
456
489
  #a(e, t) {
457
490
  let n;
@@ -461,7 +494,7 @@ var De = (e) => {
461
494
  t(`[stray stdout] ${e}`);
462
495
  return;
463
496
  }
464
- if (!Ee(n)) {
497
+ if (!Ae(n)) {
465
498
  t(`[stray stdout] ${e}`);
466
499
  return;
467
500
  }
@@ -472,14 +505,14 @@ var De = (e) => {
472
505
  if (n.id === null) {
473
506
  if (!("error" in n)) return;
474
507
  let { code: e, message: r, data: i } = n.error;
475
- e === Oe ? this.#e.onAppError?.({
508
+ e === Me ? this.#e.onAppError?.({
476
509
  message: r,
477
510
  stack: i?.stack ?? null
478
- }) : t(`[host error ${String(e)}] ${r}`);
511
+ }) : t(`[host error ${String(e)}] ${r}\n`);
479
512
  return;
480
513
  }
481
514
  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));
515
+ 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
516
  }
484
517
  #o(e, t, n) {
485
518
  switch (e) {
@@ -502,7 +535,7 @@ var De = (e) => {
502
535
  }
503
536
  }
504
537
  async #s(e) {
505
- let t = w(e, "exit");
538
+ let t = E(e, "exit");
506
539
  e.kill(), await t;
507
540
  }
508
541
  async call(e, t, n) {
@@ -543,35 +576,35 @@ var De = (e) => {
543
576
  let t = this.#t;
544
577
  if (!t || t.exitCode !== null || t.signalCode !== null) return;
545
578
  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);
579
+ let n = E(t, "exit");
580
+ this.call("shutdown").catch(() => {}), await Promise.race([n.then(() => "exited"), ne(e, void 0, { ref: !1 }).then(() => "timeout")]) === "timeout" && (t.kill(), await n);
548
581
  }
549
- }, Ae = "[inca]", je = new Intl.DateTimeFormat(void 0, {
582
+ }, Pe = "[inca]", Fe = new Intl.DateTimeFormat(void 0, {
550
583
  hour: "numeric",
551
584
  minute: "numeric",
552
585
  second: "numeric"
553
586
  });
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;
587
+ function K(e, t, n) {
588
+ let r = v(["bold", n], Pe, { stream: e });
589
+ return t.timestamp ? `${v("dim", Fe.format(/* @__PURE__ */ new Date()), { stream: e })} ${r}` : r;
557
590
  }
558
- function W(e, t, n = {}) {
559
- e.write(`${U(e, n, "cyan")} ${t}\n`);
591
+ function q(e, t, n = {}) {
592
+ e.write(`${K(e, n, "cyan")} ${t}\n`);
560
593
  }
561
- function G(e) {
594
+ function J(e) {
562
595
  let t = e.code;
563
596
  return typeof t == "string" ? t : null;
564
597
  }
565
- function Me(e) {
598
+ function Ie(e) {
566
599
  return /\bERR_INCA_[A-Z0-9_]+/.exec(e)?.[0] ?? null;
567
600
  }
568
- function Ne(e) {
601
+ function Le(e) {
569
602
  let t = e.stack;
570
603
  if (!t) return null;
571
604
  for (let n of [`${e.name}: ${e.message}`, e.message]) if (t.startsWith(n)) return t.slice(n.length).replace(/^\r?\n/, "") || null;
572
605
  return t;
573
606
  }
574
- function Pe(e) {
607
+ function Re(e) {
575
608
  let t = /^(?:\w*Error: )?(ERR_INCA_[A-Z0-9_]+): /.exec(e);
576
609
  return t ? {
577
610
  message: e.slice(t[0].length),
@@ -583,40 +616,40 @@ function Pe(e) {
583
616
  code: null
584
617
  };
585
618
  }
586
- function K(e) {
587
- return e instanceof H ? {
619
+ function Y(e) {
620
+ return e instanceof G ? {
588
621
  message: e.message,
589
622
  stack: e.hostStack,
590
- code: G(e)
623
+ code: J(e)
591
624
  } : e instanceof Error ? {
592
625
  message: e.message,
593
- stack: Ne(e),
594
- code: G(e) ?? Me(e.message)
626
+ stack: Le(e),
627
+ code: J(e) ?? Ie(e.message)
595
628
  } : {
596
629
  message: String(e),
597
630
  stack: null,
598
631
  code: null
599
632
  };
600
633
  }
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");
634
+ function ze(e, t) {
635
+ return e.split("\n").map((e) => /^\s*at\b/.test(e) ? v("dim", e, { stream: t }) : e).join("\n");
603
636
  }
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`);
637
+ function X(e, t, n, r = {}) {
638
+ n.stack && e.write(`${ze(n.stack, e)}\n`);
639
+ let i = n.code ? ` (${v("bold", n.code, { stream: e })})` : "";
640
+ e.write(`${K(e, r, "red")} ${t}${i}: ${n.message}\n`);
608
641
  }
609
642
  //#endregion
610
643
  //#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({
644
+ async function Be({ onBuild: e, onError: t, stdout: n = process.stdout, stderr: r = process.stderr, quiet: i = !1, ...a }) {
645
+ let { outDir: o } = a, s, c = await x(z({
613
646
  ...a,
614
647
  watch: !0,
615
648
  stdout: n,
616
649
  stderr: r,
617
650
  quiet: i,
618
651
  onOutput: (t) => {
619
- e(M(o, t, s)), s = void 0;
652
+ e(de(o, t, s)), s = void 0;
620
653
  }
621
654
  }));
622
655
  return c.on("change", (e) => {
@@ -628,90 +661,119 @@ async function Ie({ onBuild: e, onError: t, stdout: n = process.stdout, stderr:
628
661
  if (e.code !== "ERROR") return;
629
662
  s = void 0;
630
663
  let { errors: n } = e.error;
631
- t(Pe(n?.[0]?.message ?? e.error.message));
664
+ t(Re(n?.[0]?.message ?? e.error.message));
632
665
  }), { close: () => c.close() };
633
666
  }
634
667
  //#endregion
635
668
  //#region src/defaultBundler.mts
636
- var J = {
637
- watch: Ie,
638
- build: he,
639
- hmr: we
669
+ var Ve = {
670
+ watch: Be,
671
+ build: ye,
672
+ hmr: Oe
640
673
  };
641
674
  //#endregion
642
675
  //#region src/entry.mts
643
- async function Y(e) {
676
+ async function He(e) {
644
677
  let t = a.join(e, "src/main.mts");
645
678
  if (o(t)) return t;
646
679
  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}`);
680
+ if (o(n)) return Ue(n, e);
681
+ throw new O("ERR_INCA_ENTRY_NOT_FOUND", `no app entry found — expected ${t} or ${n}`);
649
682
  }
650
- async function Le(e, t) {
683
+ async function Ue(e, t) {
651
684
  let n = a.join(t, "node_modules/.inca");
652
- await u(n, { recursive: !0 });
685
+ await p(n, { recursive: !0 });
653
686
  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;
687
+ return await _(r, `import { createIncaApp } from "incajs/vue";\nimport App from ${i};\ncreateIncaApp(App).mount();\n`), r;
655
688
  }
656
689
  //#endregion
657
690
  //#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);
691
+ async function We(e = {}) {
692
+ 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);
693
+ j(t, r, o);
694
+ let s = e.runtimeConfig ?? await ue(t);
660
695
  return i.build({
661
- entry: a,
696
+ entry: o,
662
697
  outDir: r,
663
- runtimeConfig: o,
698
+ runtimeConfig: s,
664
699
  stdout: e.stdout,
665
700
  stderr: e.stderr
666
701
  });
667
702
  }
668
703
  //#endregion
669
704
  //#region src/dev-lock.mts
670
- function Re(e) {
705
+ function Ge(e) {
671
706
  return a.join(e, "node_modules/.inca/dev.pid");
672
707
  }
673
- function ze(e) {
708
+ function Ke(e) {
674
709
  try {
675
710
  return process.kill(e, 0), !0;
676
711
  } catch (e) {
677
712
  return e.code === "EPERM";
678
713
  }
679
714
  }
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 });
715
+ var qe = D();
716
+ function Z(e) {
717
+ return new O("ERR_INCA_DEV_RUNNING", `inca dev is already running for this app (pid ${String(e)})`);
718
+ }
719
+ async function Je(e) {
720
+ let t = Ge(e), n = `${String(process.pid)}:${qe}`, r = `${t}.${D()}`;
721
+ await p(a.dirname(t), { recursive: !0 }), await _(r, n);
722
+ let i = process.pid;
723
+ try {
724
+ for (let e = 0; e < 5; e++) {
725
+ try {
726
+ return await f(r, t), Ye(t, n);
727
+ } catch (e) {
728
+ if (e.code !== "EEXIST") throw e;
729
+ }
730
+ let e = await m(t, "utf8").catch(() => ""), a = Number.parseInt(e, 10);
731
+ if (a === process.pid) {
732
+ if (e === n) throw Z(a);
733
+ } else if (Number.isSafeInteger(a) && a > 0 && Ke(a)) throw Z(a);
734
+ i = Number.isSafeInteger(a) && a > 0 ? a : i, await g(t, { force: !0 });
735
+ }
736
+ throw Z(i);
737
+ } finally {
738
+ await g(r, { force: !0 });
739
+ }
740
+ }
741
+ function Ye(e, t) {
742
+ let n = !1;
743
+ return async () => {
744
+ n || (n = !0, await m(e, "utf8").catch(() => "") === t && await g(e, { force: !0 }));
745
+ };
684
746
  }
685
747
  //#endregion
686
748
  //#region src/plist.mts
687
- function Z(e) {
749
+ function Xe(e) {
688
750
  return e.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;");
689
751
  }
690
- function Ve(e) {
691
- return typeof e == "boolean" ? e ? "<true/>" : "<false/>" : `<string>${Z(e)}</string>`;
752
+ function Ze(e) {
753
+ return typeof e == "boolean" ? e ? "<true/>" : "<false/>" : `<string>${Xe(e)}</string>`;
692
754
  }
693
- function He(e) {
755
+ function Qe(e) {
694
756
  return `<?xml version="1.0" encoding="UTF-8"?>
695
757
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
696
758
  <plist version="1.0">
697
759
  <dict>
698
- ${Object.entries(e).map(([e, t]) => `\t<key>${Z(e)}</key>\n\t${Ve(t)}`).join("\n")}\n</dict>
760
+ ${Object.entries(e).map(([e, t]) => `\t<key>${Xe(e)}</key>\n\t${Ze(t)}`).join("\n")}\n</dict>
699
761
  </plist>
700
762
  `;
701
763
  }
702
764
  //#endregion
703
765
  //#region src/macos-app.mts
704
- async function Q(e) {
766
+ async function $e(e) {
705
767
  let { appPath: t, metadata: n, hostBin: r } = e;
706
- await p(t, {
768
+ await g(t, {
707
769
  recursive: !0,
708
770
  force: !0
709
771
  });
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 = {
772
+ let i = a.join(t, "Contents"), o = a.join(i, "MacOS"), s = a.join(i, "Resources");
773
+ await p(o, { recursive: !0 }), await p(s, { recursive: !0 });
774
+ let c = a.join(o, n.productName);
775
+ e.link ? await f(r, c).catch(() => d(r, c)) : await d(r, c), await u(c, 493);
776
+ let l = {
715
777
  CFBundleName: n.productName,
716
778
  CFBundleDisplayName: n.productName,
717
779
  CFBundleExecutable: n.productName,
@@ -724,233 +786,252 @@ async function Q(e) {
724
786
  };
725
787
  if (n.icon) {
726
788
  let e = a.basename(n.icon);
727
- await c(n.icon, a.join(d, e)), h.CFBundleIconFile = e;
789
+ await d(n.icon, a.join(s, e)), l.CFBundleIconFile = e;
728
790
  }
729
- return await m(a.join(i, "Info.plist"), He(h)), await m(a.join(i, "PkgInfo"), "APPL????"), {
791
+ return await _(a.join(i, "Info.plist"), Qe(l)), await _(a.join(i, "PkgInfo"), "APPL????"), {
730
792
  appPath: t,
731
- executablePath: f,
732
- resourcesDir: d
793
+ executablePath: c,
794
+ resourcesDir: s
733
795
  };
734
796
  }
735
797
  //#endregion
736
798
  //#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) {
799
+ var Q = { timestamp: !0 }, et = 1e4, tt = ["ERR_INCA_PACKAGE_JSON_NOT_FOUND", "ERR_INCA_PRODUCT_NAME_MISSING"];
800
+ async function nt(e, t) {
739
801
  try {
740
- return await A(e);
802
+ return await ce(e);
741
803
  } catch (e) {
742
- if (!(e instanceof T) || !We.includes(e.code)) throw e;
743
- W(t, `running unnamed — ${e.message}`, $);
804
+ if (!(e instanceof O) || !tt.includes(e.code)) throw e;
805
+ q(t, `running unnamed — ${e.message}`, Q);
744
806
  return;
745
807
  }
746
808
  }
747
- async function Ke(e, t, n, r) {
809
+ async function rt(e, t, n, r) {
748
810
  if (process.platform === "darwin" && t) try {
749
- return (await Q({
811
+ return (await $e({
750
812
  appPath: a.join(e, "node_modules/.inca", `${t.productName}.app`),
751
813
  metadata: t,
752
- hostBin: n ?? V(),
814
+ hostBin: n,
753
815
  link: !0
754
816
  })).executablePath;
755
817
  } catch (e) {
756
- W(r, `running unbundled — ${K(e).message}`, $);
818
+ q(r, `running unbundled — ${Y(e).message}`, Q);
757
819
  return;
758
820
  }
759
821
  }
760
- function qe(e) {
761
- let t = y(e, [], !1), n = [e.stack, t].filter((e) => e).join("\n");
822
+ function it(e) {
823
+ let t = S(e, [], !1), n = [e.stack, t].filter((e) => e).join("\n");
762
824
  return {
763
825
  message: e.message,
764
826
  stack: n || null,
765
827
  code: null
766
828
  };
767
829
  }
768
- async function Je(e, t) {
830
+ async function at(e, t) {
769
831
  let n = new Set(t), r;
770
832
  try {
771
- r = await f(e, {
833
+ r = await h(e, {
772
834
  recursive: !0,
773
835
  withFileTypes: !0
774
836
  });
775
837
  } catch {
776
838
  return;
777
839
  }
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 })));
840
+ 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
841
  }
780
- async function Ye(e) {
781
- let t = e.cwd ?? process.cwd(), n = await k(t), r = await Be(t);
842
+ function ot(e) {
843
+ let { NO_COLOR: t, FORCE_COLOR: n } = process.env;
844
+ if (!(!e.isTTY || t || n)) return {
845
+ ...process.env,
846
+ FORCE_COLOR: "1"
847
+ };
848
+ }
849
+ async function st(e) {
850
+ let t = e.cwd ?? process.cwd(), n = await P(t), r = await Je(t);
782
851
  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;
852
+ let r = e.hostBin ?? U();
853
+ W(r);
854
+ 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);
855
+ j(t, i, l);
856
+ 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) => {
857
+ b = e;
785
858
  });
786
- async function b() {
859
+ async function S() {
787
860
  try {
788
- return await f?.call("reload", void 0, Ue), !0;
861
+ return await p?.call("reload", void 0, et), !0;
789
862
  } catch (e) {
790
- return q(s, "reload failed", K(e), $), !1;
863
+ return X(c, "reload failed", Y(e), Q), !1;
791
864
  }
792
865
  }
793
- async function x(e, t) {
794
- let n = new ke({
866
+ async function C(e, t) {
867
+ let n = new Ne({
795
868
  entryFile: e,
796
- hostBin: d,
797
- onStderr: (e) => s.write(e),
869
+ hostBin: f,
870
+ env: ot(c),
871
+ onStderr: (e) => c.write(e),
798
872
  onReady: () => {
799
- p = !0, W(o, "ready", $), m && (m = !1, b());
873
+ m = !0, q(s, "ready", Q), h && (h = !1, S());
800
874
  },
801
- onAppError: (e) => q(s, "app error", e, $),
802
- onExit: () => {
803
- g = !p, W(o, "host exited — stopping", $), v();
875
+ onAppError: (e) => X(c, "app error", e, Q),
876
+ onExit: (e, t) => {
877
+ g = !m, _ = {
878
+ code: e,
879
+ signal: t
880
+ }, q(s, "host exited — stopping", Q), b();
804
881
  },
805
882
  integrations: t
806
883
  });
807
884
  try {
808
885
  await n.start();
809
886
  } catch (e) {
810
- q(s, "failed to start inca-host", K(e), $);
887
+ X(c, "failed to start inca-host", Y(e), Q);
811
888
  return;
812
889
  }
813
- f = n;
890
+ p = n;
814
891
  }
815
- async function S(e) {
816
- if (await Je(e.outDir, e.files), !f) {
817
- await x(e.entryFile);
892
+ async function w(e) {
893
+ if (await at(e.outDir, e.files), !p) {
894
+ await C(e.entryFile);
818
895
  return;
819
896
  }
820
- if (!p) {
821
- m = !0;
897
+ if (!m) {
898
+ h = !0;
822
899
  return;
823
900
  }
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)`, $);
901
+ if (await S() && e.changed) {
902
+ let n = v("dim", a.relative(t, e.changed.file), { stream: s }), r = Date.now() - e.changed.at;
903
+ q(s, `${v("green", "reload")} ${n} (${r}ms)`, Q);
827
904
  }
828
905
  }
829
- let C;
906
+ let T;
830
907
  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,
908
+ if (!o.hmr) throw new O("ERR_INCA_HMR_UNSUPPORTED", "--experimental-hmr was set, but the configured bundler has no HMR support");
909
+ let e = await o.hmr({
910
+ entry: l,
834
911
  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), $),
912
+ runtimeConfig: d,
913
+ stdout: s,
914
+ stderr: c,
915
+ notify: (e) => p?.notify("vite", e),
916
+ reload: () => void S(),
917
+ onError: (e) => X(c, "build failed", it(e), Q),
841
918
  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)`, $);
919
+ let r = v("dim", a.relative(t, e), { stream: s });
920
+ q(s, `${v("green", "update")} ${r} (${n}ms)`, Q);
844
921
  }
845
922
  });
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,
923
+ await C(e.entryFile, { vite: (t) => e.dispatch(t) }), T = e, p || b();
924
+ } else T = await o.watch({
925
+ entry: l,
926
+ outDir: i,
927
+ runtimeConfig: d,
851
928
  mode: "development",
852
- stdout: o,
853
- stderr: s,
929
+ stdout: s,
930
+ stderr: c,
854
931
  onBuild: (e) => {
855
- _ = _.then(() => S(e));
932
+ y = y.then(() => w(e));
856
933
  },
857
934
  onError: (e) => {
858
- q(s, "build failed", e, $);
935
+ X(c, "build failed", e, Q);
859
936
  }
860
937
  });
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");
938
+ 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");
939
+ if (_ && _.code !== 0 && _.signal !== "SIGINT" && _.signal !== "SIGTERM") {
940
+ let { code: e, signal: t } = _;
941
+ throw new O("ERR_INCA_HOST_CRASHED", `the host exited with ${t ? `signal ${t}` : `code ${e}`}`);
942
+ }
862
943
  } finally {
863
944
  await r();
864
945
  }
865
946
  }
866
947
  //#endregion
867
948
  //#region src/package.mts
868
- function Xe() {
949
+ function ct() {
869
950
  if (process.platform === "darwin") return "macos";
870
951
  if (process.platform === "linux") return "linux";
871
- throw new T("ERR_INCA_PLATFORM_UNSUPPORTED", `inca package doesn't support ${process.platform} yet`);
952
+ throw new O("ERR_INCA_PLATFORM_UNSUPPORTED", `inca package doesn't support ${process.platform} yet`);
872
953
  }
873
- async function Ze(e, t) {
954
+ async function lt(e, t) {
874
955
  await Promise.all(e.files.map(async (n) => {
875
956
  let r = a.join(t, n);
876
- await u(a.dirname(r), { recursive: !0 }), await c(a.join(e.outDir, n), r);
957
+ await p(a.dirname(r), { recursive: !0 }), await d(a.join(e.outDir, n), r);
877
958
  }));
878
959
  }
879
- function Qe(e, t) {
960
+ function ut(e, t) {
880
961
  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`);
962
+ 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
963
  }
883
- async function $e({ metadata: e, output: t, hostBin: n }) {
884
- let { appPath: r, resourcesDir: i } = await Q({
964
+ async function dt({ metadata: e, output: t, hostBin: n }) {
965
+ let { appPath: r, resourcesDir: i } = await $e({
885
966
  appPath: a.join(t.outDir, `${e.productName}.app`),
886
967
  metadata: e,
887
968
  hostBin: n
888
969
  });
889
- return await Ze(t, i), r;
970
+ return await lt(t, i), r;
890
971
  }
891
- async function et({ metadata: t, output: n, hostBin: r }) {
972
+ async function ft({ metadata: t, output: n, hostBin: r }) {
892
973
  let i = e(t.productName);
893
- Qe(n, i);
974
+ ut(n, i);
894
975
  let o = a.join(n.outDir, i);
895
- await p(o, {
976
+ await g(o, {
896
977
  recursive: !0,
897
978
  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({
979
+ }), await p(o, { recursive: !0 });
980
+ let s = a.join(o, i);
981
+ return await d(r, s), await u(s, 493), await lt(n, o), o;
982
+ }
983
+ async function pt(e = {}) {
984
+ let t = e.cwd ?? process.cwd(), n = e.stdout ?? process.stdout, r = e.target ?? ct(), i = await ce(t);
985
+ 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}`);
986
+ let a = await We({
906
987
  cwd: t,
907
988
  entry: e.entry,
908
989
  config: i,
909
- runtimeConfig: j(i),
990
+ runtimeConfig: le(i),
910
991
  bundler: e.bundler,
911
992
  stdout: n,
912
993
  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 = {
994
+ }), o = e.hostBin ?? U();
995
+ W(o);
996
+ let s = {
916
997
  metadata: i,
917
998
  output: a,
918
- hostBin: s
999
+ hostBin: o
919
1000
  };
920
- return { appPath: r === "macos" ? await $e(c) : await et(c) };
1001
+ return { appPath: r === "macos" ? await dt(s) : await ft(s) };
921
1002
  }
922
1003
  //#endregion
923
1004
  //#region src/cli.mts
924
- var nt = "Usage: inca <dev|build|package>";
925
- function rt(e) {
1005
+ var mt = "Usage: inca <dev|build|package>";
1006
+ function $(e) {
926
1007
  return a.relative(process.cwd(), e);
927
1008
  }
928
- async function it(e = process.argv) {
1009
+ async function ht(e = process.argv) {
929
1010
  let t = e[2];
930
1011
  if (t === "build") {
931
1012
  try {
932
- let e = await X();
933
- W(process.stdout, `built ${rt(e.entryFile)}`);
1013
+ let e = await We();
1014
+ q(process.stdout, `built ${$(e.entryFile)}`);
934
1015
  } catch (e) {
935
- q(process.stderr, "build failed", K(e)), process.exitCode = 1;
1016
+ X(process.stderr, "build failed", Y(e)), process.exitCode = 1;
936
1017
  }
937
1018
  return;
938
1019
  }
939
1020
  if (t === "package") {
940
1021
  try {
941
- let { appPath: e } = await tt();
942
- W(process.stdout, `packaged ${rt(e)}`);
1022
+ let { appPath: e } = await pt();
1023
+ q(process.stdout, `packaged ${$(e)}`);
943
1024
  } catch (e) {
944
- q(process.stderr, "package failed", K(e)), process.exitCode = 1;
1025
+ X(process.stderr, "package failed", Y(e)), process.exitCode = 1;
945
1026
  }
946
1027
  return;
947
1028
  }
948
1029
  if (t !== "dev") {
949
- process.stderr.write(`${nt}\n`), process.exitCode = 1;
1030
+ process.stderr.write(`${mt}\n`), process.exitCode = 1;
950
1031
  return;
951
1032
  }
952
1033
  let n = new AbortController(), r = () => {
953
- n.signal.aborted || (W(process.stderr, "shutting down", { timestamp: !0 }), n.abort());
1034
+ n.signal.aborted || (q(process.stderr, "shutting down", { timestamp: !0 }), n.abort());
954
1035
  };
955
1036
  process.on("SIGINT", r), process.on("SIGTERM", r);
956
1037
  let i = e.includes("--experimental-hmr") || ![
@@ -958,15 +1039,15 @@ async function it(e = process.argv) {
958
1039
  "0",
959
1040
  "false"
960
1041
  ].includes(process.env.INCA_EXPERIMENTAL_HMR ?? "");
961
- i && W(process.stdout, "experimental HMR active", { timestamp: !0 });
1042
+ i && q(process.stdout, "experimental HMR active", { timestamp: !0 });
962
1043
  try {
963
- await Ye({
1044
+ await st({
964
1045
  signal: n.signal,
965
1046
  experimentalHmr: i
966
1047
  });
967
1048
  } catch (e) {
968
- q(process.stderr, "dev failed", K(e), { timestamp: !0 }), process.exitCode = 1;
1049
+ X(process.stderr, "dev failed", Y(e), { timestamp: !0 }), process.exitCode = 1;
969
1050
  }
970
1051
  }
971
1052
  //#endregion
972
- export { it as run };
1053
+ export { ht as run };