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.
- package/dist/components/ui/native-select/NativeSelectOptGroup.vue.d.ts +48 -48
- package/dist/components/ui/native-select/NativeSelectOption.vue.d.ts +50 -50
- package/dist/dev-tools/blob-explorer/blobExplorerTypes.d.ts +11 -2
- package/dist/dev-tools/document-explorer/composables/useOptimisticList.d.ts +3 -3
- package/dist/dev-tools/document-explorer/documentLists.d.ts +72 -0
- package/dist/dev-tools/document-explorer/utils.d.ts +1 -0
- package/dist/dev-tools/vite-plugin/generated-env-resolver-core.d.ts +131 -12
- package/dist/dev-tools/vite-plugin/index.cjs +3 -3
- package/dist/dev-tools/vite-plugin/index.js +173 -105
- package/dist/dev-tools/vite-plugin/primitive-env.d.ts +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.js +3418 -3402
- package/dist/lib/portal-target.d.ts +14 -0
- package/dist/lib-CZJJRJq3.cjs +1 -0
- package/dist/{lib-B7ZH2Pdd.js → lib-SnRn0TGH.js} +101 -29
- package/dist/primitive-app.css +1 -1
- package/dist/services/JsBaoClientService.d.ts +4 -2
- package/dist/testing/index.cjs +1 -1
- package/dist/testing/index.js +4 -4
- package/package.json +3 -2
- package/src/style.css +185 -2
- package/dist/lib-CFnieS8T.cjs +0 -1
|
@@ -63,14 +63,21 @@ export const keyboardShortcut = ${JSON.stringify(s)};
|
|
|
63
63
|
}
|
|
64
64
|
};
|
|
65
65
|
}
|
|
66
|
-
var h = "
|
|
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
|
|
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
|
|
86
|
-
return `Environment "${e}" in ${t ? `${
|
|
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
|
|
95
|
+
function E(e) {
|
|
89
96
|
if (typeof e == "string") return e.trim() || void 0;
|
|
90
97
|
}
|
|
91
|
-
function
|
|
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
|
|
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,
|
|
110
|
+
let t = s(r, h, _);
|
|
103
111
|
if (e(t)) return t;
|
|
104
|
-
let n =
|
|
105
|
-
if (n
|
|
106
|
-
|
|
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
|
|
119
|
+
function k(e) {
|
|
110
120
|
let t = o(e);
|
|
111
|
-
return a(t) === "
|
|
121
|
+
return a(t) === "primitive" ? o(t) : t;
|
|
112
122
|
}
|
|
113
|
-
function
|
|
114
|
-
return s(
|
|
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
|
|
117
|
-
if (!e(n)) throw new
|
|
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
|
|
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
|
|
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
|
|
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
|
|
133
|
-
if (a.version !== 1) throw new
|
|
134
|
-
if (!a.environments || typeof a.environments != "object" || Array.isArray(a.environments)) throw new
|
|
135
|
-
let
|
|
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
|
|
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
|
|
140
|
-
let i =
|
|
141
|
-
if (!i) throw new
|
|
142
|
-
|
|
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:
|
|
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:
|
|
166
|
+
environments: s
|
|
154
167
|
};
|
|
155
168
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
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
|
-
|
|
180
|
+
o = JSON.parse(t(i, "utf-8"));
|
|
164
181
|
} catch (e) {
|
|
165
|
-
return
|
|
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
|
-
|
|
168
|
-
|
|
169
|
-
|
|
190
|
+
return {
|
|
191
|
+
selectedEnvironment: c,
|
|
192
|
+
environments: F(s.environments, i, r)
|
|
193
|
+
};
|
|
170
194
|
}
|
|
171
|
-
function
|
|
172
|
-
let
|
|
173
|
-
|
|
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:
|
|
226
|
+
source: o
|
|
177
227
|
};
|
|
178
228
|
};
|
|
179
|
-
if (t.explicitEnvName) return
|
|
180
|
-
if (t.envVarName) return
|
|
181
|
-
if (t.localSelection) return
|
|
182
|
-
if (e.defaultEnvironment) return
|
|
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
|
|
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
|
|
190
|
-
let t = e.env ?? process.env, n = e.configPath ??
|
|
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
|
|
195
|
-
let 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:
|
|
248
|
+
localSelection: a.selectedEnvironment,
|
|
249
|
+
localEnvironments: a.environments,
|
|
199
250
|
configPath: n
|
|
200
|
-
}),
|
|
201
|
-
|
|
202
|
-
|
|
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:
|
|
212
|
-
projectRoot:
|
|
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
|
|
284
|
+
var z = [
|
|
218
285
|
"VITE_APP_ID",
|
|
219
286
|
"VITE_API_URL",
|
|
220
287
|
"VITE_WS_URL",
|
|
221
288
|
"VITE_APP_NAME"
|
|
222
|
-
],
|
|
223
|
-
function
|
|
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 !== "" &&
|
|
292
|
+
n !== void 0 && n !== "" && V.get(e) !== n || (process.env[e] = t, V.set(e, t));
|
|
226
293
|
}
|
|
227
|
-
function
|
|
228
|
-
return
|
|
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
|
|
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
|
|
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
|
|
250
|
-
let n = process.env[
|
|
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 =
|
|
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
|
|
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
|
|
273
|
-
`[primitive-env] expected: ${t.value} (${
|
|
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 ${
|
|
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
|
|
283
|
-
let r =
|
|
284
|
-
if (r && r.value !== "" && r.value !== n.name) throw Error(
|
|
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
|
|
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 =
|
|
294
|
-
for (let e of
|
|
295
|
-
let t = process.env[e], n = t !== void 0 &&
|
|
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 =
|
|
368
|
+
p = R({
|
|
301
369
|
cwd: l,
|
|
302
370
|
explicitEnvName: e.primitiveEnv ?? null
|
|
303
371
|
});
|
|
304
372
|
} catch (e) {
|
|
305
|
-
if (e instanceof
|
|
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 =
|
|
310
|
-
|
|
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
|
|
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),
|
|
397
|
+
t !== void 0 && (h[`import.meta.env.${e}`] = JSON.stringify(t), H(e, t));
|
|
330
398
|
}
|
|
331
|
-
return
|
|
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(
|
|
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 =
|
|
341
|
-
n === o.dir && r === o.mode || (
|
|
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
|
|
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,
|
|
439
|
+
for (let e of n) Object.assign(r, Z(s(t, e)));
|
|
372
440
|
return r;
|
|
373
441
|
}
|
|
374
|
-
function
|
|
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 {
|
|
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
|
-
*
|
|
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:
|