primitive-app 3.2.0-alpha.2 → 3.2.0-alpha.20

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.
@@ -63,14 +63,21 @@ export const keyboardShortcut = ${JSON.stringify(s)};
63
63
  }
64
64
  };
65
65
  }
66
- var h = ".primitive", g = "config.json", _ = "local.json", v = ".primitive/config.json", y = ".primitive/local.json", b = class extends Error {
66
+ var h = "primitive", g = ".primitive", _ = "config.json", v = "local.json", y = "primitive/config.json", b = ".primitive/local.json";
67
+ function x(e, t) {
68
+ return `Found ${e} but no ${t}: this project still uses the retired layout under ${g}/, which is never read.`;
69
+ }
70
+ function S(e) {
71
+ return `No ${y} found in ${e} or any parent directory. Primitive commands run inside a Primitive project: it is where the CLI reads the environment, the app that environment names, and the configuration tree from. Run 'primitive init' to create one.`;
72
+ }
73
+ var C = class extends Error {
67
74
  kind;
68
75
  path;
69
76
  constructor(e, t, n) {
70
77
  super(t), this.name = "PrimitiveEnvError", this.kind = e, this.path = n;
71
78
  }
72
79
  };
73
- function x(e) {
80
+ function w(e) {
74
81
  if (typeof e != "string") return;
75
82
  let t = e.trim();
76
83
  if (!t) return;
@@ -82,156 +89,216 @@ function x(e) {
82
89
  }
83
90
  if (!(n.protocol !== "https:" && n.protocol !== "http:") && !(n.protocol === "http:" && n.hostname !== "localhost" && n.hostname !== "127.0.0.1") && !(n.username || n.password) && !(n.pathname !== "/" && n.pathname !== "") && !(n.search || n.hash)) return n.origin;
84
91
  }
85
- function S(e, t) {
86
- return `Environment "${e}" in ${t ? `${v} (${t})` : v} has no "appId". Every environment names exactly one app — add "appId": "<app-id>" to that environment in ${v}. Find the app id in the Primitive admin UI, with 'primitive apps list' run from a directory outside this project, or as the residual "currentAppId" in .primitive/credentials.json if this environment was ever pointed at an app by the retired per-machine app selection.`;
92
+ function T(e, t) {
93
+ return `Environment "${e}" in ${t ? `${y} (${t})` : y} has no "appId". Every environment names exactly one app — add "appId": "<app-id>" to that environment in ${y}. Find the app id in the Primitive admin UI, with 'primitive apps list' run from another Primitive project, or as the residual "currentAppId" in .primitive/credentials.json if this environment was ever pointed at an app by the retired per-machine app selection.`;
87
94
  }
88
- function C(e) {
95
+ function E(e) {
89
96
  if (typeof e == "string") return e.trim() || void 0;
90
97
  }
91
- function w(e) {
98
+ function D(e) {
92
99
  return e.startsWith("https://") ? "wss://" + e.slice(8) : e.startsWith("http://") ? "ws://" + e.slice(7) : e;
93
100
  }
94
- function T(t = {}) {
101
+ function O(t = {}) {
95
102
  let n = (t.env ?? process.env).PRIMITIVE_PROJECT_CONFIG;
96
103
  if (n) {
97
104
  let t = c(n);
105
+ if (a(o(t)) === ".primitive") throw new C("stale-layout", x(t, s(o(o(t)), h, _)), t);
98
106
  return e(t) ? t : null;
99
107
  }
100
108
  let r = c(t.cwd ?? process.cwd());
101
109
  for (;;) {
102
- let t = s(r, h, g);
110
+ let t = s(r, h, _);
103
111
  if (e(t)) return t;
104
- let n = o(r);
105
- if (n === r) return null;
106
- r = n;
112
+ let n = s(r, g, _);
113
+ if (e(n)) throw new C("stale-layout", x(n, t), n);
114
+ let i = o(r);
115
+ if (i === r) return null;
116
+ r = i;
107
117
  }
108
118
  }
109
- function E(e) {
119
+ function k(e) {
110
120
  let t = o(e);
111
- return a(t) === ".primitive" ? o(t) : t;
121
+ return a(t) === "primitive" ? o(t) : t;
112
122
  }
113
- function D(e) {
114
- return s(o(e), _);
123
+ function A(e) {
124
+ return s(k(e), g, v);
125
+ }
126
+ function j(e) {
127
+ return e instanceof Error ? e.message : String(e);
115
128
  }
116
- function O(n) {
117
- if (!e(n)) throw new b("missing-config", `No ${v} found at ${n}. Run 'primitive init' to create one.`, n);
129
+ function M(n) {
130
+ if (!e(n)) throw new C("missing-config", S(o(n)), n);
118
131
  let r;
119
132
  try {
120
133
  r = t(n, "utf-8");
121
134
  } catch (e) {
122
- throw new b("malformed-config", `Failed to read ${v} (${n}): ${e.message}`, n);
135
+ throw new C("malformed-config", `Failed to read ${y} (${n}): ${j(e)}`, n);
123
136
  }
124
137
  let i;
125
138
  try {
126
139
  i = JSON.parse(r);
127
140
  } catch (e) {
128
- throw new b("malformed-config", `Failed to parse ${v} (${n}): ${e.message}`, n);
141
+ throw new C("malformed-config", `Failed to parse ${y} (${n}): ${j(e)}`, n);
129
142
  }
130
- if (!i || typeof i != "object" || Array.isArray(i)) throw new b("malformed-config", `${v} (${n}) must contain a JSON object at the top level.`, n);
143
+ if (!i || typeof i != "object" || Array.isArray(i)) throw new C("malformed-config", `${y} (${n}) must contain a JSON object at the top level.`, n);
131
144
  let a = i;
132
- if (typeof a.version != "number" || !Number.isInteger(a.version)) throw new b("malformed-config", `${v} (${n}) is missing required integer field "version".`, n);
133
- if (a.version !== 1) throw new b("unsupported-version", `${v} (${n}) has version ${a.version}, but this tool understands version 1.`, n);
134
- if (!a.environments || typeof a.environments != "object" || Array.isArray(a.environments)) throw new b("malformed-config", `${v} (${n}) is missing required "environments" object.`, n);
135
- let o = {};
145
+ if (typeof a.version != "number" || !Number.isInteger(a.version)) throw new C("malformed-config", `${y} (${n}) is missing required integer field "version".`, n);
146
+ if (a.version !== 1) throw new C("unsupported-version", `${y} (${n}) has version ${a.version}, but this tool understands version 1.`, n);
147
+ if (!a.environments || typeof a.environments != "object" || Array.isArray(a.environments)) throw new C("malformed-config", `${y} (${n}) is missing required "environments" object.`, n);
148
+ let s = {};
136
149
  for (let [e, t] of Object.entries(a.environments)) {
137
- if (!t || typeof t != "object" || Array.isArray(t)) throw new b("malformed-config", `Environment "${e}" must be an object in ${v} (${n}).`, n);
150
+ if (!t || typeof t != "object" || Array.isArray(t)) throw new C("malformed-config", `Environment "${e}" must be an object in ${y} (${n}).`, n);
138
151
  let r = t;
139
- if (typeof r.apiUrl != "string" || !r.apiUrl) throw new b("malformed-config", `Environment "${e}" must have a non-empty "apiUrl" string in ${v} (${n}).`, n);
140
- let i = C(r.appId);
141
- if (!i) throw new b("missing-app-id", S(e, n), n);
142
- o[e] = {
152
+ if (typeof r.apiUrl != "string" || !r.apiUrl) throw new C("malformed-config", `Environment "${e}" must have a non-empty "apiUrl" string in ${y} (${n}).`, n);
153
+ let i = E(r.appId);
154
+ if (!i) throw new C("missing-app-id", T(e, n), n);
155
+ s[e] = {
143
156
  apiUrl: r.apiUrl.replace(/\/$/, ""),
144
157
  appId: i,
145
158
  appName: typeof r.appName == "string" ? r.appName : void 0,
146
- webUrl: x(r.webUrl),
159
+ webUrl: w(r.webUrl),
147
160
  description: typeof r.description == "string" ? r.description : void 0
148
161
  };
149
162
  }
150
163
  return {
151
164
  version: a.version,
152
165
  defaultEnvironment: typeof a.defaultEnvironment == "string" && a.defaultEnvironment ? a.defaultEnvironment : void 0,
153
- environments: o
166
+ environments: s
154
167
  };
155
168
  }
156
- function k(n) {
157
- let r = D(n);
158
- if (!e(r)) return null;
159
- let i = (e) => {
160
- throw new b("corrupt-local-state", `${y} (${r}) is unreadable: ${e}. Delete the file or re-run 'primitive env use <name>'.`, r);
161
- }, a;
169
+ var N = /^[a-zA-Z0-9][a-zA-Z0-9_-]*$/;
170
+ function P(n, r) {
171
+ let i = A(n);
172
+ if (!e(i)) return {
173
+ selectedEnvironment: null,
174
+ environments: {}
175
+ };
176
+ let a = (e) => {
177
+ throw new C("corrupt-local-state", `${b} (${i}) is unreadable: ${e}. Delete the file or re-run 'primitive env use <name>'.`, i);
178
+ }, o;
162
179
  try {
163
- a = JSON.parse(t(r, "utf-8"));
180
+ o = JSON.parse(t(i, "utf-8"));
164
181
  } catch (e) {
165
- return i(e.message);
182
+ return a(j(e));
183
+ }
184
+ if (!o || typeof o != "object" || Array.isArray(o)) return a("expected a JSON object");
185
+ let s = o, c = null, l = s.selectedEnvironment;
186
+ if (l != null && l !== "") {
187
+ if (typeof l != "string") return a("\"selectedEnvironment\" must be a string");
188
+ c = l;
166
189
  }
167
- if (!a || typeof a != "object" || Array.isArray(a)) return i("expected a JSON object");
168
- let o = a.selectedEnvironment;
169
- return o == null || o === "" ? null : typeof o == "string" ? o : i("\"selectedEnvironment\" must be a string");
190
+ return {
191
+ selectedEnvironment: c,
192
+ environments: F(s.environments, i, r)
193
+ };
170
194
  }
171
- function A(e, t) {
172
- let n = Object.keys(e.environments), r = n.join(", ") || "(none)", i = t.configPath ? `${v} (${t.configPath})` : v, a = (n, a, o) => {
173
- if (!e.environments[n]) throw new b("unknown-environment", `Environment "${n}" is not defined in ${i} (selected ${o}). Available: ${r}`, t.configPath);
195
+ function F(e, t, n) {
196
+ let r = {};
197
+ if (e === void 0) return r;
198
+ if (!e || typeof e != "object" || Array.isArray(e)) throw new C("corrupt-local-state", `${b} (${t}) is unreadable: "environments" must be an object keyed by environment name. Fix or remove "environments" in ${b}.`, t);
199
+ let i = (e, n) => {
200
+ throw new C("corrupt-local-state", `${b} (${t}): machine-local environment "${e}" ${n}. Fix or remove the "${e}" entry under "environments" in ${b}.`, t);
201
+ }, a = n ? Object.keys(n.environments) : null;
202
+ for (let [t, n] of Object.entries(e)) {
203
+ N.test(t) || i(t, "is not a valid environment name (letters, digits, dashes and underscores, starting with a letter or digit)"), (!n || typeof n != "object" || Array.isArray(n)) && i(t, "must be an object");
204
+ let e = n;
205
+ (typeof e.apiUrl != "string" || !e.apiUrl.trim()) && i(t, "has no \"apiUrl\" string");
206
+ let o = E(e.appId);
207
+ o || i(t, "has no \"appId\" naming the app it selects"), (typeof e.tree != "string" || !e.tree.trim()) && i(t, "has no \"tree\" naming the committed environment whose configuration tree it uses");
208
+ let s = e.tree.trim();
209
+ a && (a.includes(t) && i(t, `has the name of a committed environment in ${y}; a machine-local environment needs a name of its own`), a.includes(s) || i(t, `has "tree": "${s}", which is not an environment in ${y} (available: ${a.join(", ") || "(none)"})`)), r[t] = {
210
+ apiUrl: e.apiUrl.trim().replace(/\/$/, ""),
211
+ appId: o,
212
+ appName: typeof e.appName == "string" ? e.appName : void 0,
213
+ tree: s
214
+ };
215
+ }
216
+ return r;
217
+ }
218
+ function I(e, t) {
219
+ return Object.prototype.hasOwnProperty.call(e.environments, t);
220
+ }
221
+ function L(e, t) {
222
+ let n = Object.keys(e.environments), r = Object.keys(t.localEnvironments ?? {}), i = [...n, ...r.map((e) => `${e} (local)`)].join(", ") || "(none)", a = t.configPath ? `${y} (${t.configPath})` : y, o = (n, o, s, c = !1) => {
223
+ if (!I(e, n) && (c || !r.includes(n))) throw new C("unknown-environment", `Environment "${n}" is not defined in ${a} (selected ${s}). Available: ${i}`, t.configPath);
174
224
  return {
175
225
  name: n,
176
- source: a
226
+ source: o
177
227
  };
178
228
  };
179
- if (t.explicitEnvName) return a(t.explicitEnvName, "explicit", "explicitly");
180
- if (t.envVarName) return a(t.envVarName, "env-var", "via PRIMITIVE_ENV");
181
- if (t.localSelection) return a(t.localSelection, "local", `in ${y}`);
182
- if (e.defaultEnvironment) return a(e.defaultEnvironment, "default", "as \"defaultEnvironment\"");
229
+ if (t.explicitEnvName) return o(t.explicitEnvName, "explicit", "explicitly");
230
+ if (t.envVarName) return o(t.envVarName, "env-var", "via PRIMITIVE_ENV");
231
+ if (t.localSelection) return o(t.localSelection, "local", `in ${b}`);
232
+ if (e.defaultEnvironment) return o(e.defaultEnvironment, "default", "as \"defaultEnvironment\"", !0);
183
233
  if (n.length === 1) return {
184
234
  name: n[0],
185
235
  source: "sole"
186
236
  };
187
- throw n.length === 0 ? new b("no-selection", `${i} has no environments defined. Run 'primitive env add <name>' or 'primitive init'.`, t.configPath) : new b("no-selection", `No environment selected. Run 'primitive env use <name>', set "defaultEnvironment" in ${i}, or export PRIMITIVE_ENV. Available: ${r}`, t.configPath);
237
+ throw n.length === 0 ? new C("no-selection", `${a} has no environments defined. Run 'primitive env add <name>' or 'primitive init'.`, t.configPath) : new C("no-selection", `No environment selected. Run 'primitive env use <name>', set "defaultEnvironment" in ${a}, or export PRIMITIVE_ENV. Available: ${i}`, t.configPath);
188
238
  }
189
- function j(e = {}) {
190
- let t = e.env ?? process.env, n = e.configPath ?? T({
239
+ function R(e = {}) {
240
+ let t = e.env ?? process.env, n = e.configPath ?? O({
191
241
  cwd: e.cwd,
192
242
  env: t
193
243
  });
194
- if (!n) throw new b("missing-config", `No ${v} found in ${e.cwd ?? process.cwd()} or any parent directory. Run 'primitive init' to create one, or 'primitive env add <name>' to add an environment.`);
195
- let r = O(n), { name: i, source: a } = A(r, {
244
+ if (!n) throw new C("missing-config", S(e.cwd ?? process.cwd()));
245
+ let r = k(n), i = M(n), a = P(n, i), { name: o, source: s } = L(i, {
196
246
  explicitEnvName: e.explicitEnvName || null,
197
247
  envVarName: t.PRIMITIVE_ENV || null,
198
- localSelection: k(n),
248
+ localSelection: a.selectedEnvironment,
249
+ localEnvironments: a.environments,
199
250
  configPath: n
200
- }), o = r.environments[i];
201
- return {
202
- name: i,
203
- apiUrl: o.apiUrl,
204
- wsUrl: w(o.apiUrl),
205
- appId: o.appId,
206
- appName: o.appName,
207
- webUrl: o.webUrl,
208
- description: o.description,
209
- source: a,
251
+ }), c = {
252
+ name: o,
253
+ source: s,
210
254
  configPath: n,
211
- localStatePath: D(n),
212
- projectRoot: E(n)
255
+ localStatePath: A(n),
256
+ projectRoot: r
257
+ }, l = I(i, o) ? void 0 : a.environments[o];
258
+ if (l) return {
259
+ ...c,
260
+ apiUrl: l.apiUrl,
261
+ wsUrl: D(l.apiUrl),
262
+ appId: l.appId,
263
+ appName: l.appName,
264
+ webUrl: void 0,
265
+ description: void 0,
266
+ tree: l.tree,
267
+ local: !0
268
+ };
269
+ let u = i.environments[o];
270
+ return {
271
+ ...c,
272
+ apiUrl: u.apiUrl,
273
+ wsUrl: D(u.apiUrl),
274
+ appId: u.appId,
275
+ appName: u.appName,
276
+ webUrl: u.webUrl,
277
+ description: u.description,
278
+ tree: o,
279
+ local: !1
213
280
  };
214
281
  }
215
282
  //#endregion
216
283
  //#region src/dev-tools/vite-plugin/primitive-env.ts
217
- var M = [
284
+ var z = [
218
285
  "VITE_APP_ID",
219
286
  "VITE_API_URL",
220
287
  "VITE_WS_URL",
221
288
  "VITE_APP_NAME"
222
- ], N = "VITE_EXPECTED_PRIMITIVE_ENV", P = /* @__PURE__ */ new Map();
223
- function F(e, t) {
289
+ ], B = "VITE_EXPECTED_PRIMITIVE_ENV", V = /* @__PURE__ */ new Map();
290
+ function H(e, t) {
224
291
  let n = process.env[e];
225
- n !== void 0 && n !== "" && P.get(e) !== n || (process.env[e] = t, P.set(e, t));
292
+ n !== void 0 && n !== "" && V.get(e) !== n || (process.env[e] = t, V.set(e, t));
226
293
  }
227
- function I(e = {}) {
228
- return j({
294
+ function U(e = {}) {
295
+ return R({
229
296
  cwd: e.root,
230
297
  env: e.env,
231
298
  explicitEnvName: e.primitiveEnv ?? null
232
299
  });
233
300
  }
234
- function L(e, t, n) {
301
+ function W(e, t, n) {
235
302
  let r = (e) => n.includes(e) ? " (overridden)" : "", i = [
236
303
  `[primitive-env] Primitive environment: ${e.name} (selected: ${e.source})`,
237
304
  `[primitive-env] apiUrl: ${t.apiUrl}${r("VITE_API_URL")}`,
@@ -242,12 +309,12 @@ function L(e, t, n) {
242
309
  ];
243
310
  return n.length > 0 && i.push(`[primitive-env] overridden by the environment: ${n.join(", ")}`), i.join("\n");
244
311
  }
245
- function R(e, t) {
312
+ function G(e, t) {
246
313
  let n = e?.envDir;
247
314
  return n === !1 ? null : typeof n == "string" && n !== "" ? c(t, n) : t;
248
315
  }
249
- function z(e, t) {
250
- let n = process.env[N];
316
+ function K(e, t) {
317
+ let n = process.env[B];
251
318
  if (n !== void 0 && n !== "") return {
252
319
  value: n,
253
320
  where: "the process environment"
@@ -259,7 +326,7 @@ function z(e, t) {
259
326
  ".env.local",
260
327
  ".env"
261
328
  ]) {
262
- let e = W(s(t, n))[N];
329
+ let e = Z(s(t, n))[B];
263
330
  if (e !== void 0) return {
264
331
  value: e,
265
332
  where: n
@@ -267,47 +334,48 @@ function z(e, t) {
267
334
  }
268
335
  return null;
269
336
  }
270
- function B(e, t, n) {
337
+ function q(e, t, n) {
338
+ let r = n.local ? `"${n.name}" (machine-local, tree "${n.tree}")` : `"${n.name}"`;
271
339
  return [
272
- `[primitive-env] Wrong pair: vite mode "${e}" is declared to run against Primitive environment "${t.value}", but "${n.name}" resolved.`,
273
- `[primitive-env] expected: ${t.value} (${N} in ${t.where})`,
274
- `[primitive-env] resolved: ${n.name} (selected: ${n.source})`,
340
+ `[primitive-env] Wrong pair: vite mode "${e}" is declared to run against Primitive environment "${t.value}", but ${r} resolved.`,
341
+ `[primitive-env] expected: ${t.value} (${B} in ${t.where}; a machine-local environment whose tree is ${t.value} also pairs)`,
342
+ `[primitive-env] resolved: ${n.name} (selected: ${n.source}${n.local ? `; machine-local, tree ${n.tree}` : ""})`,
275
343
  `[primitive-env] config: ${n.configPath}`,
276
344
  "",
277
- `Run the pair you meant — PRIMITIVE_ENV=${t.value} <command> --mode ${e}, or 'primitive env use ${t.value}' — or change/remove ${N} in ${t.where}.`,
345
+ `Run the pair you meant — PRIMITIVE_ENV=${t.value} <command> --mode ${e}, or 'primitive env use ${t.value}' — or change/remove ${B} in ${t.where}.`,
278
346
  "",
279
347
  `A mode declares this when its .env.${e} carries values coupled to one backend, so continuing would run this environment's identity with another's configuration.`
280
348
  ].join("\n");
281
349
  }
282
- function V(e, t, n) {
283
- let r = z(e, t);
284
- if (r && r.value !== "" && r.value !== n.name) throw Error(B(e, r, n));
350
+ function J(e, t, n) {
351
+ let r = K(e, t);
352
+ if (r && r.value !== "" && r.value !== n.name && !(n.local && r.value === n.tree)) throw Error(q(e, r, n));
285
353
  }
286
- function H(e = {}) {
354
+ function Y(e = {}) {
287
355
  let t = null, n = null, r, i = [], a = !1, o = null;
288
356
  return {
289
357
  name: "primitive-env",
290
358
  enforce: "pre",
291
359
  config(s, c) {
292
360
  a = c?.command === "serve", o = null;
293
- let l = s?.root ?? process.cwd(), u = c?.mode ?? "development", d = U(u, l), f = {};
294
- for (let e of M) {
295
- let t = process.env[e], n = t !== void 0 && P.get(e) !== t ? t : d[e];
361
+ let l = s?.root ?? process.cwd(), u = c?.mode ?? "development", d = X(u, l), f = {};
362
+ for (let e of z) {
363
+ let t = process.env[e], n = t !== void 0 && V.get(e) !== t ? t : d[e];
296
364
  n !== void 0 && n !== "" && (f[e] = n);
297
365
  }
298
366
  let p;
299
367
  try {
300
- p = j({
368
+ p = R({
301
369
  cwd: l,
302
370
  explicitEnvName: e.primitiveEnv ?? null
303
371
  });
304
372
  } catch (e) {
305
- if (e instanceof b && e.kind === "missing-config" && f.VITE_APP_ID && f.VITE_API_URL) return console.warn("[primitive-env] No .primitive/config.json found; using VITE_APP_ID / VITE_API_URL from the environment. Run 'primitive init' to make the project the source of truth."), r = f.VITE_APP_NAME, {};
373
+ if (e instanceof C && e.kind === "missing-config" && f.VITE_APP_ID && f.VITE_API_URL) return console.warn("[primitive-env] No primitive/config.json found; using VITE_APP_ID / VITE_API_URL from the environment. Run 'primitive init' to make the project the source of truth."), r = f.VITE_APP_NAME, {};
306
374
  throw e;
307
375
  }
308
376
  if (!(f.VITE_APP_ID && f.VITE_API_URL)) {
309
- let e = R(s, l);
310
- V(u, e, p), o = {
377
+ let e = G(s, l);
378
+ J(u, e, p), o = {
311
379
  root: l,
312
380
  mode: u,
313
381
  dir: e
@@ -320,25 +388,25 @@ function H(e = {}) {
320
388
  VITE_WS_URL: p.wsUrl,
321
389
  VITE_APP_NAME: p.appName
322
390
  }, h = { "import.meta.env.VITE_PRIMITIVE_ENV": JSON.stringify(p.name) }, g = [];
323
- for (let e of M) {
391
+ for (let e of z) {
324
392
  if (f[e] !== void 0) {
325
393
  g.push(e);
326
394
  continue;
327
395
  }
328
396
  let t = m[e];
329
- t !== void 0 && (h[`import.meta.env.${e}`] = JSON.stringify(t), F(e, t));
397
+ t !== void 0 && (h[`import.meta.env.${e}`] = JSON.stringify(t), H(e, t));
330
398
  }
331
- return F("VITE_PRIMITIVE_ENV", p.name), i = g, n = {
399
+ return H("VITE_PRIMITIVE_ENV", p.name), i = g, n = {
332
400
  apiUrl: f.VITE_API_URL ?? p.apiUrl,
333
401
  wsUrl: f.VITE_WS_URL ?? p.wsUrl,
334
402
  appId: f.VITE_APP_ID ?? p.appId,
335
403
  appName: r
336
- }, e.logResolved !== !1 && console.log(L(p, n, g)), g.length > 0 && console.warn(`[primitive-env] Overridden by an explicit value in .env or the shell: ${g.join(", ")}. Remove it to use .primitive/config.json (deploys reject these outright).`), { define: h };
404
+ }, e.logResolved !== !1 && console.log(W(p, n, g)), g.length > 0 && console.warn(`[primitive-env] Overridden by an explicit value in .env or the shell: ${g.join(", ")}. Remove it to use primitive/config.json (deploys reject these outright).`), { define: h };
337
405
  },
338
406
  configResolved(e) {
339
407
  if (!o || !t) return;
340
- let n = R(e, o.root), r = e?.mode ?? o.mode;
341
- n === o.dir && r === o.mode || (V(r, n, t), o = {
408
+ let n = G(e, o.root), r = e?.mode ?? o.mode;
409
+ n === o.dir && r === o.mode || (J(r, n, t), o = {
342
410
  root: o.root,
343
411
  mode: r,
344
412
  dir: n
@@ -361,17 +429,17 @@ function H(e = {}) {
361
429
  }
362
430
  };
363
431
  }
364
- function U(e, t) {
432
+ function X(e, t) {
365
433
  let n = [
366
434
  ".env",
367
435
  ".env.local",
368
436
  `.env.${e}`,
369
437
  `.env.${e}.local`
370
438
  ], r = {};
371
- for (let e of n) Object.assign(r, W(s(t, e)));
439
+ for (let e of n) Object.assign(r, Z(s(t, e)));
372
440
  return r;
373
441
  }
374
- function W(n) {
442
+ function Z(n) {
375
443
  if (!e(n)) return {};
376
444
  let r = {};
377
445
  for (let e of t(n, "utf-8").split(/\r?\n/)) {
@@ -385,4 +453,4 @@ function W(n) {
385
453
  return r;
386
454
  }
387
455
  //#endregion
388
- export { b as PrimitiveEnvError, m as primitiveDevTools, H as primitiveEnv, I as resolvePrimitiveEnv };
456
+ export { C as PrimitiveEnvError, m as primitiveDevTools, Y as primitiveEnv, U as resolvePrimitiveEnv };
@@ -2,7 +2,7 @@
2
2
  * `primitiveEnv()` — Primitive environment configuration for a Vite app (#2873).
3
3
  *
4
4
  * A scaffolded app used to type its backend URL and app ID twice: once in
5
- * `.primitive/config.json` (which every `primitive` command reads) and again in
5
+ * `primitive/config.json` (which every `primitive` command reads) and again in
6
6
  * `.env` / `.env.production`. This plugin removes the second copy. It resolves
7
7
  * the selected Primitive environment at config time and `define`s the keys the
8
8
  * app already reads: