@leadconnector/vite-tanstack-config 0.3.2-beta.0 → 0.3.3-beta.0
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/index.cjs +774 -1012
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +23 -22
- package/dist/index.d.mts +25 -0
- package/dist/index.mjs +890 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +25 -11
- package/dist/index.d.ts +0 -24
- package/dist/index.js +0 -1097
- package/dist/index.js.map +0 -1
package/dist/index.js
DELETED
|
@@ -1,1097 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
import { componentTagger } from "@leadconnector/vibe-tagger";
|
|
3
|
-
import { resolve as resolve2 } from "path";
|
|
4
|
-
import {
|
|
5
|
-
loadEnv,
|
|
6
|
-
mergeConfig as mergeConfig2
|
|
7
|
-
} from "vite";
|
|
8
|
-
|
|
9
|
-
// src/bundledDev.ts
|
|
10
|
-
import { createRequire } from "module";
|
|
11
|
-
import { readFile, writeFile } from "fs/promises";
|
|
12
|
-
import { isAbsolute, join, resolve } from "path";
|
|
13
|
-
var BUNDLED_DEV_ENV_VAR = "VIBE_FEATURE_BUNDLED_DEV";
|
|
14
|
-
var CSS_URL_VIRTUAL_PREFIX = "\0vibe-bundled-dev-css-url:";
|
|
15
|
-
var CSS_URL_VIRTUAL_SUFFIX = ".shim.js";
|
|
16
|
-
var NODEJS_COMPAT_DEFAULT_ON_DATE = "2026-08-04";
|
|
17
|
-
var DEFAULT_SANDBOX_SERVER_DIR = "dist/server";
|
|
18
|
-
function bundledDevRequested() {
|
|
19
|
-
return process.env[BUNDLED_DEV_ENV_VAR] === "true";
|
|
20
|
-
}
|
|
21
|
-
function viteVersionSupportsBundledDev(version) {
|
|
22
|
-
if (!version || version.includes("-"))
|
|
23
|
-
return false;
|
|
24
|
-
const match = /^(\d+)\.(\d+)\.(\d+)$/.exec(version);
|
|
25
|
-
if (!match)
|
|
26
|
-
return false;
|
|
27
|
-
const major = Number(match[1]);
|
|
28
|
-
const minor = Number(match[2]);
|
|
29
|
-
return major > 8 || major === 8 && minor >= 1;
|
|
30
|
-
}
|
|
31
|
-
function resolveInstalledViteVersion(cwd = process.cwd()) {
|
|
32
|
-
try {
|
|
33
|
-
const manifest = createRequire(`${cwd}/package.json`)(
|
|
34
|
-
"vite/package.json"
|
|
35
|
-
);
|
|
36
|
-
return typeof manifest.version === "string" ? manifest.version : void 0;
|
|
37
|
-
} catch {
|
|
38
|
-
return void 0;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
function bundledDevCssUrlShim() {
|
|
42
|
-
return {
|
|
43
|
-
name: "vibe-bundled-dev-css-url-shim",
|
|
44
|
-
apply: "serve",
|
|
45
|
-
enforce: "pre",
|
|
46
|
-
async resolveId(id, importer) {
|
|
47
|
-
if (!id.endsWith(".css?url"))
|
|
48
|
-
return null;
|
|
49
|
-
const resolved = await this.resolve(id.slice(0, -4), importer, {
|
|
50
|
-
skipSelf: true
|
|
51
|
-
});
|
|
52
|
-
return resolved ? `${CSS_URL_VIRTUAL_PREFIX}${resolved.id}${CSS_URL_VIRTUAL_SUFFIX}` : null;
|
|
53
|
-
},
|
|
54
|
-
load(id) {
|
|
55
|
-
if (!id.startsWith(CSS_URL_VIRTUAL_PREFIX) || !id.endsWith(CSS_URL_VIRTUAL_SUFFIX)) {
|
|
56
|
-
return null;
|
|
57
|
-
}
|
|
58
|
-
const cssId = id.slice(
|
|
59
|
-
CSS_URL_VIRTUAL_PREFIX.length,
|
|
60
|
-
-CSS_URL_VIRTUAL_SUFFIX.length
|
|
61
|
-
);
|
|
62
|
-
const inlineSpecifier = cssId.includes("?") ? `${cssId}&inline` : `${cssId}?inline`;
|
|
63
|
-
return [
|
|
64
|
-
`import css from ${JSON.stringify(inlineSpecifier)};`,
|
|
65
|
-
'const b64 = typeof Buffer !== "undefined" ? Buffer.from(css, "utf8").toString("base64") : btoa(unescape(encodeURIComponent(css)));',
|
|
66
|
-
'export default "data:text/css;base64," + b64;'
|
|
67
|
-
].join("\n");
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
function isCanonicalCompatibilityDate(value) {
|
|
72
|
-
return /^\d{4}-\d{2}-\d{2}$/.test(value);
|
|
73
|
-
}
|
|
74
|
-
function stripRedundantNodejsCompatFlag(serverDir = DEFAULT_SANDBOX_SERVER_DIR) {
|
|
75
|
-
let root = process.cwd();
|
|
76
|
-
let warn = (message) => console.warn(message);
|
|
77
|
-
return {
|
|
78
|
-
name: "vibe-strip-redundant-nodejs-compat",
|
|
79
|
-
apply: "build",
|
|
80
|
-
configResolved(config) {
|
|
81
|
-
root = config.root;
|
|
82
|
-
if (typeof config.logger?.warn === "function") {
|
|
83
|
-
warn = config.logger.warn.bind(config.logger);
|
|
84
|
-
}
|
|
85
|
-
},
|
|
86
|
-
buildApp: {
|
|
87
|
-
order: "post",
|
|
88
|
-
async handler() {
|
|
89
|
-
const configPath = join(
|
|
90
|
-
isAbsolute(serverDir) ? serverDir : resolve(root, serverDir),
|
|
91
|
-
"wrangler.json"
|
|
92
|
-
);
|
|
93
|
-
let parsed;
|
|
94
|
-
try {
|
|
95
|
-
parsed = JSON.parse(await readFile(configPath, "utf8"));
|
|
96
|
-
} catch {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
const config = parsed;
|
|
103
|
-
if (typeof config.compatibility_date !== "string" || !isCanonicalCompatibilityDate(config.compatibility_date) || config.compatibility_date < NODEJS_COMPAT_DEFAULT_ON_DATE || !Array.isArray(config.compatibility_flags)) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const flags = config.compatibility_flags.filter(
|
|
107
|
-
(flag) => flag !== "nodejs_compat"
|
|
108
|
-
);
|
|
109
|
-
if (flags.length === config.compatibility_flags.length)
|
|
110
|
-
return;
|
|
111
|
-
try {
|
|
112
|
-
await writeFile(
|
|
113
|
-
configPath,
|
|
114
|
-
`${JSON.stringify({ ...config, compatibility_flags: flags }, null, 2)}
|
|
115
|
-
`
|
|
116
|
-
);
|
|
117
|
-
} catch {
|
|
118
|
-
warn(
|
|
119
|
-
`[@leadconnector/vite-tanstack-config] Unable to remove redundant nodejs_compat from ${configPath}; continuing with the generated configuration.`
|
|
120
|
-
);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// src/diagnostics.ts
|
|
128
|
-
var SSR_CAPTURE_KEY = "__VIBE_TANSTACK_CAPTURE_SSR_ERROR__";
|
|
129
|
-
var HANDLER_RAN_KEY = "__VIBE_TANSTACK_HANDLER_RAN__";
|
|
130
|
-
var SERVER_FN_SEND_KEY = "__VIBE_TANSTACK_SERVER_FN_HMR_SEND__";
|
|
131
|
-
var MAX_JSON_LENGTH = 6e3;
|
|
132
|
-
var MAX_STRING_LENGTH = 2e3;
|
|
133
|
-
var MAX_ITEMS = 20;
|
|
134
|
-
var MAX_DEPTH = 4;
|
|
135
|
-
var ERROR_FIELDS = [
|
|
136
|
-
"name",
|
|
137
|
-
"message",
|
|
138
|
-
"plugin",
|
|
139
|
-
"pluginCode",
|
|
140
|
-
"id",
|
|
141
|
-
"moduleId",
|
|
142
|
-
"hook",
|
|
143
|
-
"code",
|
|
144
|
-
"loc",
|
|
145
|
-
"frame",
|
|
146
|
-
"stack",
|
|
147
|
-
"cause"
|
|
148
|
-
];
|
|
149
|
-
function truncate(value, max = MAX_STRING_LENGTH) {
|
|
150
|
-
return value.length > max ? `${value.slice(0, max)}...[truncated]` : value;
|
|
151
|
-
}
|
|
152
|
-
function readProperty(value, key) {
|
|
153
|
-
try {
|
|
154
|
-
return value[key];
|
|
155
|
-
} catch (error) {
|
|
156
|
-
return `[unreadable: ${error instanceof Error ? error.message : String(error)}]`;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
function describePrimitive(value) {
|
|
160
|
-
if (typeof value === "symbol") {
|
|
161
|
-
return value.description ? `Symbol(${value.description})` : "Symbol()";
|
|
162
|
-
}
|
|
163
|
-
if (typeof value === "function") {
|
|
164
|
-
return `[function ${value.name || "anonymous"}]`;
|
|
165
|
-
}
|
|
166
|
-
return String(value);
|
|
167
|
-
}
|
|
168
|
-
function serializeDiagnosticValue(value, depth = 0, seen = /* @__PURE__ */ new WeakSet()) {
|
|
169
|
-
if (value == null)
|
|
170
|
-
return value;
|
|
171
|
-
if (typeof value === "string")
|
|
172
|
-
return truncate(value);
|
|
173
|
-
if (typeof value === "number" || typeof value === "boolean")
|
|
174
|
-
return value;
|
|
175
|
-
if (typeof value !== "object")
|
|
176
|
-
return describePrimitive(value);
|
|
177
|
-
if (seen.has(value))
|
|
178
|
-
return "[circular]";
|
|
179
|
-
if (depth >= MAX_DEPTH)
|
|
180
|
-
return "[max depth]";
|
|
181
|
-
seen.add(value);
|
|
182
|
-
try {
|
|
183
|
-
if (Array.isArray(value)) {
|
|
184
|
-
const entries = value.slice(0, MAX_ITEMS).map((entry) => serializeDiagnosticValue(entry, depth + 1, seen));
|
|
185
|
-
if (value.length > MAX_ITEMS) {
|
|
186
|
-
entries.push(`[${value.length - MAX_ITEMS} items truncated]`);
|
|
187
|
-
}
|
|
188
|
-
return entries;
|
|
189
|
-
}
|
|
190
|
-
const output = {};
|
|
191
|
-
for (const field of ERROR_FIELDS) {
|
|
192
|
-
if (!(field in value))
|
|
193
|
-
continue;
|
|
194
|
-
const nested = readProperty(value, field);
|
|
195
|
-
if (nested == null || nested === "")
|
|
196
|
-
continue;
|
|
197
|
-
output[field] = serializeDiagnosticValue(nested, depth + 1, seen);
|
|
198
|
-
}
|
|
199
|
-
const nestedErrors = readProperty(value, "errors");
|
|
200
|
-
if (nestedErrors != null && nestedErrors !== "") {
|
|
201
|
-
output.errors = serializeDiagnosticValue(
|
|
202
|
-
Array.isArray(nestedErrors) ? nestedErrors.slice(0, MAX_ITEMS) : nestedErrors,
|
|
203
|
-
depth + 1,
|
|
204
|
-
seen
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
if (Object.keys(output).length > 0)
|
|
208
|
-
return output;
|
|
209
|
-
const keys = Object.keys(value);
|
|
210
|
-
for (const key of keys.slice(0, MAX_ITEMS)) {
|
|
211
|
-
const nested = readProperty(value, key);
|
|
212
|
-
if (nested == null || nested === "")
|
|
213
|
-
continue;
|
|
214
|
-
output[truncate(key, 200)] = serializeDiagnosticValue(
|
|
215
|
-
nested,
|
|
216
|
-
depth + 1,
|
|
217
|
-
seen
|
|
218
|
-
);
|
|
219
|
-
}
|
|
220
|
-
if (keys.length > MAX_ITEMS) {
|
|
221
|
-
output.properties_truncated = keys.length - MAX_ITEMS;
|
|
222
|
-
}
|
|
223
|
-
return Object.keys(output).length > 0 ? output : Object.prototype.toString.call(value);
|
|
224
|
-
} catch (error) {
|
|
225
|
-
return `[unreadable object: ${error instanceof Error ? error.message : String(error)}]`;
|
|
226
|
-
} finally {
|
|
227
|
-
seen.delete(value);
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
function stringifyDiagnosticPayload(value) {
|
|
231
|
-
const serialized = serializeDiagnosticValue(value);
|
|
232
|
-
const full = JSON.stringify(serialized);
|
|
233
|
-
if (full.length <= MAX_JSON_LENGTH)
|
|
234
|
-
return full;
|
|
235
|
-
const compact = serializeDiagnosticValue(value, 2);
|
|
236
|
-
const compactPayload = compact && typeof compact === "object" && !Array.isArray(compact) ? { ...compact, diagnostics_truncated: true } : { diagnostics_truncated: true, value: compact };
|
|
237
|
-
const compactJson = JSON.stringify(compactPayload);
|
|
238
|
-
if (compactJson.length <= MAX_JSON_LENGTH)
|
|
239
|
-
return compactJson;
|
|
240
|
-
return JSON.stringify({
|
|
241
|
-
diagnostics_truncated: true,
|
|
242
|
-
message: "Diagnostic payload exceeded output budget."
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
function boundedData(value) {
|
|
246
|
-
try {
|
|
247
|
-
const parsed = JSON.parse(stringifyDiagnosticPayload(value));
|
|
248
|
-
return parsed && typeof parsed === "object" && !Array.isArray(parsed) ? parsed : { value: parsed };
|
|
249
|
-
} catch {
|
|
250
|
-
return { message: "Diagnostic payload could not be serialized." };
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
function createBuildErrorDiagnostics() {
|
|
254
|
-
let emitted = false;
|
|
255
|
-
const emit = (error) => {
|
|
256
|
-
if (!error || emitted)
|
|
257
|
-
return;
|
|
258
|
-
emitted = true;
|
|
259
|
-
try {
|
|
260
|
-
const output = `
|
|
261
|
-
[vibe-build-error-diagnostics]
|
|
262
|
-
${stringifyDiagnosticPayload(
|
|
263
|
-
error
|
|
264
|
-
)}
|
|
265
|
-
[/vibe-build-error-diagnostics]
|
|
266
|
-
`;
|
|
267
|
-
let written = false;
|
|
268
|
-
const write = () => {
|
|
269
|
-
if (written)
|
|
270
|
-
return;
|
|
271
|
-
written = true;
|
|
272
|
-
try {
|
|
273
|
-
process.stderr.write(output);
|
|
274
|
-
} catch {
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
setImmediate(write);
|
|
278
|
-
process.once("exit", write);
|
|
279
|
-
} catch {
|
|
280
|
-
}
|
|
281
|
-
};
|
|
282
|
-
return {
|
|
283
|
-
name: "vibe-build-error-diagnostics",
|
|
284
|
-
apply: "build",
|
|
285
|
-
buildEnd: emit,
|
|
286
|
-
renderError: emit
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
function isEsbuildMessageArray(errors) {
|
|
290
|
-
return Array.isArray(errors) && errors.length > 0 && errors.every(
|
|
291
|
-
(entry) => entry != null && typeof entry === "object" && "text" in entry && "location" in entry
|
|
292
|
-
);
|
|
293
|
-
}
|
|
294
|
-
function isBuildError(error) {
|
|
295
|
-
const messagePattern = /transform failed with \d+ error|failed to parse source/i;
|
|
296
|
-
if (typeof error === "string")
|
|
297
|
-
return messagePattern.test(error);
|
|
298
|
-
if (!error || typeof error !== "object")
|
|
299
|
-
return false;
|
|
300
|
-
const record = error;
|
|
301
|
-
if (typeof record.plugin === "string" && (record.plugin.startsWith("vite:") || record.plugin.startsWith("esbuild:"))) {
|
|
302
|
-
return true;
|
|
303
|
-
}
|
|
304
|
-
if (record.frame != null && record.loc != null)
|
|
305
|
-
return true;
|
|
306
|
-
if (isEsbuildMessageArray(record.errors))
|
|
307
|
-
return true;
|
|
308
|
-
return typeof record.message === "string" && messagePattern.test(record.message);
|
|
309
|
-
}
|
|
310
|
-
function isRequestResponseModule(id) {
|
|
311
|
-
const normalized = id.replaceAll("\\", "/").split("?")[0];
|
|
312
|
-
return normalized.includes(
|
|
313
|
-
"/@tanstack/start-server-core/src/request-response.ts"
|
|
314
|
-
) || normalized.includes(
|
|
315
|
-
"/@tanstack/start-server-core/dist/esm/request-response.js"
|
|
316
|
-
);
|
|
317
|
-
}
|
|
318
|
-
function isServerFunctionsHandlerModule(id) {
|
|
319
|
-
const normalized = id.replaceAll("\\", "/").split("?")[0];
|
|
320
|
-
return normalized.includes(
|
|
321
|
-
"/@tanstack/start-server-core/src/server-functions-handler.ts"
|
|
322
|
-
) || normalized.includes(
|
|
323
|
-
"/@tanstack/start-server-core/dist/esm/server-functions-handler.js"
|
|
324
|
-
);
|
|
325
|
-
}
|
|
326
|
-
var runtimeGlobal = globalThis;
|
|
327
|
-
var ssrGlobalRegistrations = [];
|
|
328
|
-
var serverFnGlobalRegistrations = [];
|
|
329
|
-
var originalSsrCapture;
|
|
330
|
-
var originalSsrMark;
|
|
331
|
-
var originalServerFnSend;
|
|
332
|
-
function snapshotGlobal(key) {
|
|
333
|
-
return {
|
|
334
|
-
existed: Object.prototype.hasOwnProperty.call(runtimeGlobal, key),
|
|
335
|
-
value: runtimeGlobal[key]
|
|
336
|
-
};
|
|
337
|
-
}
|
|
338
|
-
function restoreGlobal(key, snapshot) {
|
|
339
|
-
if (snapshot.existed)
|
|
340
|
-
runtimeGlobal[key] = snapshot.value;
|
|
341
|
-
else
|
|
342
|
-
delete runtimeGlobal[key];
|
|
343
|
-
}
|
|
344
|
-
function registerSsrGlobals(registration) {
|
|
345
|
-
if (ssrGlobalRegistrations.length === 0) {
|
|
346
|
-
originalSsrCapture = snapshotGlobal(SSR_CAPTURE_KEY);
|
|
347
|
-
originalSsrMark = snapshotGlobal(HANDLER_RAN_KEY);
|
|
348
|
-
}
|
|
349
|
-
ssrGlobalRegistrations.push(registration);
|
|
350
|
-
runtimeGlobal[SSR_CAPTURE_KEY] = registration.capture;
|
|
351
|
-
runtimeGlobal[HANDLER_RAN_KEY] = registration.mark;
|
|
352
|
-
}
|
|
353
|
-
function unregisterSsrGlobals(registration) {
|
|
354
|
-
const index = ssrGlobalRegistrations.indexOf(registration);
|
|
355
|
-
if (index === -1)
|
|
356
|
-
return;
|
|
357
|
-
ssrGlobalRegistrations.splice(index, 1);
|
|
358
|
-
const active = ssrGlobalRegistrations.at(-1);
|
|
359
|
-
if (active) {
|
|
360
|
-
runtimeGlobal[SSR_CAPTURE_KEY] = active.capture;
|
|
361
|
-
runtimeGlobal[HANDLER_RAN_KEY] = active.mark;
|
|
362
|
-
return;
|
|
363
|
-
}
|
|
364
|
-
restoreGlobal(SSR_CAPTURE_KEY, originalSsrCapture);
|
|
365
|
-
restoreGlobal(HANDLER_RAN_KEY, originalSsrMark);
|
|
366
|
-
originalSsrCapture = void 0;
|
|
367
|
-
originalSsrMark = void 0;
|
|
368
|
-
}
|
|
369
|
-
function registerServerFnGlobal(registration) {
|
|
370
|
-
if (serverFnGlobalRegistrations.length === 0) {
|
|
371
|
-
originalServerFnSend = snapshotGlobal(SERVER_FN_SEND_KEY);
|
|
372
|
-
}
|
|
373
|
-
serverFnGlobalRegistrations.push(registration);
|
|
374
|
-
runtimeGlobal[SERVER_FN_SEND_KEY] = registration.dispatch;
|
|
375
|
-
}
|
|
376
|
-
function unregisterServerFnGlobal(registration) {
|
|
377
|
-
const index = serverFnGlobalRegistrations.indexOf(registration);
|
|
378
|
-
if (index === -1)
|
|
379
|
-
return;
|
|
380
|
-
serverFnGlobalRegistrations.splice(index, 1);
|
|
381
|
-
const active = serverFnGlobalRegistrations.at(-1);
|
|
382
|
-
if (active) {
|
|
383
|
-
runtimeGlobal[SERVER_FN_SEND_KEY] = active.dispatch;
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
restoreGlobal(SERVER_FN_SEND_KEY, originalServerFnSend);
|
|
387
|
-
originalServerFnSend = void 0;
|
|
388
|
-
}
|
|
389
|
-
function createSsrErrorLogger() {
|
|
390
|
-
const handlerRan = Symbol("vibeHandlerRan");
|
|
391
|
-
const capturedError = Symbol("vibeCapturedSsrError");
|
|
392
|
-
const generations = [];
|
|
393
|
-
let globalsInstalled = false;
|
|
394
|
-
const responseFromEvent = (event) => {
|
|
395
|
-
const response = event?.node?.res;
|
|
396
|
-
return response && typeof response === "object" ? response : void 0;
|
|
397
|
-
};
|
|
398
|
-
const capture = (error, event) => {
|
|
399
|
-
const response = responseFromEvent(event);
|
|
400
|
-
if (!response)
|
|
401
|
-
return;
|
|
402
|
-
response[handlerRan] = true;
|
|
403
|
-
response[capturedError] = error;
|
|
404
|
-
};
|
|
405
|
-
const consumeCapture = (response) => {
|
|
406
|
-
const error = response[capturedError];
|
|
407
|
-
delete response[capturedError];
|
|
408
|
-
return error;
|
|
409
|
-
};
|
|
410
|
-
const markHandlerRan = (event) => {
|
|
411
|
-
const response = responseFromEvent(event);
|
|
412
|
-
if (response)
|
|
413
|
-
response[handlerRan] = true;
|
|
414
|
-
};
|
|
415
|
-
const registration = { capture, mark: markHandlerRan };
|
|
416
|
-
const installGlobals = () => {
|
|
417
|
-
if (globalsInstalled)
|
|
418
|
-
return;
|
|
419
|
-
registerSsrGlobals(registration);
|
|
420
|
-
globalsInstalled = true;
|
|
421
|
-
};
|
|
422
|
-
const restoreGlobals = () => {
|
|
423
|
-
if (!globalsInstalled || generations.length > 0)
|
|
424
|
-
return;
|
|
425
|
-
globalsInstalled = false;
|
|
426
|
-
unregisterSsrGlobals(registration);
|
|
427
|
-
};
|
|
428
|
-
const retireOldestDetached = () => {
|
|
429
|
-
generations.find((generation) => !generation.httpServer)?.close();
|
|
430
|
-
};
|
|
431
|
-
return {
|
|
432
|
-
name: "vibe-ssr-error-logger",
|
|
433
|
-
apply: "serve",
|
|
434
|
-
configureServer(server) {
|
|
435
|
-
installGlobals();
|
|
436
|
-
const httpServer = server.httpServer;
|
|
437
|
-
let closed = false;
|
|
438
|
-
const generation = {};
|
|
439
|
-
const cleanup = () => {
|
|
440
|
-
if (closed)
|
|
441
|
-
return;
|
|
442
|
-
closed = true;
|
|
443
|
-
httpServer?.off("close", cleanup);
|
|
444
|
-
const index = generations.indexOf(generation);
|
|
445
|
-
if (index !== -1)
|
|
446
|
-
generations.splice(index, 1);
|
|
447
|
-
restoreGlobals();
|
|
448
|
-
};
|
|
449
|
-
generation.close = cleanup;
|
|
450
|
-
generation.httpServer = httpServer ?? void 0;
|
|
451
|
-
generations.push(generation);
|
|
452
|
-
httpServer?.once("close", cleanup);
|
|
453
|
-
server.middlewares.use((request, response, next) => {
|
|
454
|
-
let handled = false;
|
|
455
|
-
const handleErrorResponse = () => {
|
|
456
|
-
if (handled || response.statusCode < 500)
|
|
457
|
-
return;
|
|
458
|
-
handled = true;
|
|
459
|
-
const responseRecord = response;
|
|
460
|
-
const captured = consumeCapture(responseRecord);
|
|
461
|
-
const ranHandler = Boolean(responseRecord[handlerRan]);
|
|
462
|
-
const source = !ranHandler ? "vite" : isBuildError(captured) ? "build" : "app";
|
|
463
|
-
if (!response.headersSent) {
|
|
464
|
-
try {
|
|
465
|
-
response.setHeader("x-vibe-error-source", source);
|
|
466
|
-
} catch {
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
const where = [request.method, request.url].filter(Boolean).join(" ") || "the request";
|
|
470
|
-
const data = captured !== void 0 ? boundedData(captured) : {
|
|
471
|
-
message: ranHandler ? `The app returned ${response.statusCode} while handling ${where}, but no stack was captured.` : `The dev server returned ${response.statusCode} for ${where} before the app handler ran.`
|
|
472
|
-
};
|
|
473
|
-
try {
|
|
474
|
-
server.ws.send({
|
|
475
|
-
type: "custom",
|
|
476
|
-
event: "vibe:server-ssr-error",
|
|
477
|
-
data
|
|
478
|
-
});
|
|
479
|
-
} catch {
|
|
480
|
-
}
|
|
481
|
-
};
|
|
482
|
-
const writeHead = response.writeHead.bind(response);
|
|
483
|
-
response.writeHead = (...args) => {
|
|
484
|
-
if (typeof args[0] === "number")
|
|
485
|
-
response.statusCode = args[0];
|
|
486
|
-
handleErrorResponse();
|
|
487
|
-
return writeHead(...args);
|
|
488
|
-
};
|
|
489
|
-
const end = response.end.bind(response);
|
|
490
|
-
response.end = (...args) => {
|
|
491
|
-
handleErrorResponse();
|
|
492
|
-
return end(...args);
|
|
493
|
-
};
|
|
494
|
-
next();
|
|
495
|
-
});
|
|
496
|
-
},
|
|
497
|
-
transform(code, id) {
|
|
498
|
-
if (!isRequestResponseModule(id))
|
|
499
|
-
return null;
|
|
500
|
-
if (code.includes(SSR_CAPTURE_KEY))
|
|
501
|
-
return null;
|
|
502
|
-
const needle = "handler(request, requestOpts)";
|
|
503
|
-
if (!code.includes(needle)) {
|
|
504
|
-
throw new Error(
|
|
505
|
-
`[@leadconnector/vite-tanstack-config] unsupported @tanstack/start-server-core request-response transform: expected ${JSON.stringify(needle)} in ${id}.`
|
|
506
|
-
);
|
|
507
|
-
}
|
|
508
|
-
return code.replace(
|
|
509
|
-
needle,
|
|
510
|
-
`(() => {
|
|
511
|
-
const __vibeSsrEvent = typeof h3Event === "undefined" ? undefined : h3Event
|
|
512
|
-
globalThis.${HANDLER_RAN_KEY}?.(__vibeSsrEvent)
|
|
513
|
-
try {
|
|
514
|
-
return Promise.resolve(${needle}).catch((err) => {
|
|
515
|
-
globalThis.${SSR_CAPTURE_KEY}?.(err, __vibeSsrEvent)
|
|
516
|
-
throw err
|
|
517
|
-
})
|
|
518
|
-
} catch (err) {
|
|
519
|
-
globalThis.${SSR_CAPTURE_KEY}?.(err, __vibeSsrEvent)
|
|
520
|
-
throw err
|
|
521
|
-
}
|
|
522
|
-
})()`
|
|
523
|
-
);
|
|
524
|
-
},
|
|
525
|
-
closeWatcher() {
|
|
526
|
-
},
|
|
527
|
-
closeBundle() {
|
|
528
|
-
retireOldestDetached();
|
|
529
|
-
}
|
|
530
|
-
};
|
|
531
|
-
}
|
|
532
|
-
function createServerFnErrorLogger() {
|
|
533
|
-
const generations = [];
|
|
534
|
-
let globalInstalled = false;
|
|
535
|
-
const dispatch = (data) => {
|
|
536
|
-
generations.at(-1)?.send(data);
|
|
537
|
-
};
|
|
538
|
-
const registration = { dispatch };
|
|
539
|
-
const installGlobal = () => {
|
|
540
|
-
if (globalInstalled)
|
|
541
|
-
return;
|
|
542
|
-
registerServerFnGlobal(registration);
|
|
543
|
-
globalInstalled = true;
|
|
544
|
-
};
|
|
545
|
-
const restoreGlobal2 = () => {
|
|
546
|
-
if (!globalInstalled || generations.length > 0)
|
|
547
|
-
return;
|
|
548
|
-
globalInstalled = false;
|
|
549
|
-
unregisterServerFnGlobal(registration);
|
|
550
|
-
};
|
|
551
|
-
const retireOldestDetached = () => {
|
|
552
|
-
generations.find((generation) => !generation.httpServer)?.close();
|
|
553
|
-
};
|
|
554
|
-
return {
|
|
555
|
-
name: "vibe-server-fn-error-logger",
|
|
556
|
-
apply: "serve",
|
|
557
|
-
enforce: "pre",
|
|
558
|
-
configureServer(server) {
|
|
559
|
-
installGlobal();
|
|
560
|
-
const send = (data) => {
|
|
561
|
-
try {
|
|
562
|
-
server.ws.send({
|
|
563
|
-
type: "custom",
|
|
564
|
-
event: "vibe:server-fn-error",
|
|
565
|
-
data: boundedData(data)
|
|
566
|
-
});
|
|
567
|
-
} catch {
|
|
568
|
-
}
|
|
569
|
-
};
|
|
570
|
-
const httpServer = server.httpServer;
|
|
571
|
-
let closed = false;
|
|
572
|
-
const generation = {};
|
|
573
|
-
const cleanup = () => {
|
|
574
|
-
if (closed)
|
|
575
|
-
return;
|
|
576
|
-
closed = true;
|
|
577
|
-
httpServer?.off("close", cleanup);
|
|
578
|
-
const index = generations.indexOf(generation);
|
|
579
|
-
if (index !== -1)
|
|
580
|
-
generations.splice(index, 1);
|
|
581
|
-
restoreGlobal2();
|
|
582
|
-
};
|
|
583
|
-
generation.close = cleanup;
|
|
584
|
-
generation.httpServer = httpServer ?? void 0;
|
|
585
|
-
generation.send = send;
|
|
586
|
-
generations.push(generation);
|
|
587
|
-
httpServer?.once("close", cleanup);
|
|
588
|
-
},
|
|
589
|
-
transform(code, id) {
|
|
590
|
-
if (!isServerFunctionsHandlerModule(id))
|
|
591
|
-
return null;
|
|
592
|
-
if (code.includes(SERVER_FN_SEND_KEY))
|
|
593
|
-
return null;
|
|
594
|
-
const needle = "const unwrapped = res.result || res.error";
|
|
595
|
-
if (!code.includes(needle)) {
|
|
596
|
-
throw new Error(
|
|
597
|
-
`[@leadconnector/vite-tanstack-config] unsupported @tanstack/start-server-core server-functions-handler transform: expected ${JSON.stringify(needle)} in ${id}.`
|
|
598
|
-
);
|
|
599
|
-
}
|
|
600
|
-
return code.replace(
|
|
601
|
-
needle,
|
|
602
|
-
`${needle}
|
|
603
|
-
|
|
604
|
-
if (res?.error) {
|
|
605
|
-
const err = res.error
|
|
606
|
-
const clipVibeDiagnostic = (value, max = 2000) => {
|
|
607
|
-
let text
|
|
608
|
-
try { text = String(value ?? "") } catch { text = "[unreadable]" }
|
|
609
|
-
return text.length > max ? text.slice(0, max) + "...[truncated]" : text
|
|
610
|
-
}
|
|
611
|
-
globalThis.${SERVER_FN_SEND_KEY}?.({
|
|
612
|
-
source: "tanstack",
|
|
613
|
-
type: "vibe:server-fn-error",
|
|
614
|
-
method: clipVibeDiagnostic(request.method, 32),
|
|
615
|
-
url: clipVibeDiagnostic(request.url, 1000),
|
|
616
|
-
name: clipVibeDiagnostic(err?.name ?? "Error", 200),
|
|
617
|
-
message: clipVibeDiagnostic(err?.message ?? err),
|
|
618
|
-
stack: typeof err?.stack === "string" ? clipVibeDiagnostic(err.stack) : undefined,
|
|
619
|
-
})
|
|
620
|
-
}`
|
|
621
|
-
);
|
|
622
|
-
},
|
|
623
|
-
closeWatcher() {
|
|
624
|
-
},
|
|
625
|
-
closeBundle() {
|
|
626
|
-
retireOldestDetached();
|
|
627
|
-
}
|
|
628
|
-
};
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
// src/env.ts
|
|
632
|
-
var VIBE_SANDBOX_ENV_VAR = "VIBE_SANDBOX";
|
|
633
|
-
function isSandboxEnvironment() {
|
|
634
|
-
return process.env[VIBE_SANDBOX_ENV_VAR] === "1";
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
// src/nitro.ts
|
|
638
|
-
function shouldRunNitro(command, nitroOpt, isSandbox) {
|
|
639
|
-
const explicit = nitroOpt === true || typeof nitroOpt === "object" && nitroOpt !== null;
|
|
640
|
-
return nitroOpt !== false && command === "build" && (explicit || isSandbox);
|
|
641
|
-
}
|
|
642
|
-
function buildNitroOptions(nitroOpt, isSandbox) {
|
|
643
|
-
const user = typeof nitroOpt === "object" && nitroOpt ? nitroOpt : {};
|
|
644
|
-
const opts = { defaultPreset: "cloudflare-module", ...user };
|
|
645
|
-
if (isSandbox) {
|
|
646
|
-
delete opts.defaultPreset;
|
|
647
|
-
opts.preset = "cloudflare-module";
|
|
648
|
-
opts.output = { dir: "dist", serverDir: "dist/server", publicDir: "dist/client" };
|
|
649
|
-
opts.cloudflare = { nodeCompat: true, deployConfig: true, ...user.cloudflare };
|
|
650
|
-
}
|
|
651
|
-
return opts;
|
|
652
|
-
}
|
|
653
|
-
async function loadNitroPlugin(importer, requiredReason) {
|
|
654
|
-
let nitroModule;
|
|
655
|
-
try {
|
|
656
|
-
nitroModule = await importer();
|
|
657
|
-
} catch (error) {
|
|
658
|
-
throw new Error(
|
|
659
|
-
`[@leadconnector/vite-tanstack-config] ${requiredReason}, but the \`nitro\` package could not be loaded. Install \`nitro\` in devDependencies (peerDependency >=3.0.260603-beta). Original import error: ${error instanceof Error ? error.message : String(error)}`,
|
|
660
|
-
{ cause: error }
|
|
661
|
-
);
|
|
662
|
-
}
|
|
663
|
-
const nitro = nitroModule.nitro;
|
|
664
|
-
if (typeof nitro !== "function") {
|
|
665
|
-
throw new Error(
|
|
666
|
-
`[@leadconnector/vite-tanstack-config] could not resolve the Nitro plugin (expected a named \`nitro\` export from \`nitro/vite\`). Installed exports: ${Object.keys(nitroModule).join(", ") || "(none)"}.`
|
|
667
|
-
);
|
|
668
|
-
}
|
|
669
|
-
return nitro;
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
// src/server.ts
|
|
673
|
-
import { mergeConfig } from "vite";
|
|
674
|
-
var TOOL_MANAGED_WATCH_IGNORES = [
|
|
675
|
-
"**/.workspace/**",
|
|
676
|
-
"**/.agents/**",
|
|
677
|
-
"**/.claude/**",
|
|
678
|
-
"**/.lovable/**",
|
|
679
|
-
"**/.tanstack/tmp/**"
|
|
680
|
-
];
|
|
681
|
-
var MAX_WARNING_ITEMS = 8;
|
|
682
|
-
var MAX_WARNING_LENGTH = 800;
|
|
683
|
-
function logWarning(message) {
|
|
684
|
-
const bounded = message.length > MAX_WARNING_LENGTH ? `${message.slice(0, MAX_WARNING_LENGTH)}...[truncated]` : message;
|
|
685
|
-
console.warn(`[@leadconnector/vite-tanstack-config] ${bounded}`);
|
|
686
|
-
}
|
|
687
|
-
function boundedList(values) {
|
|
688
|
-
const shown = values.slice(0, MAX_WARNING_ITEMS);
|
|
689
|
-
const omitted = values.length - shown.length;
|
|
690
|
-
return `${shown.join(", ")}${omitted > 0 ? ` (+${omitted} more)` : ""}`;
|
|
691
|
-
}
|
|
692
|
-
function normalizeIgnored(value) {
|
|
693
|
-
if (typeof value === "string" || typeof value === "function" || value instanceof RegExp) {
|
|
694
|
-
return [value];
|
|
695
|
-
}
|
|
696
|
-
if (!Array.isArray(value))
|
|
697
|
-
return [];
|
|
698
|
-
return value.filter(
|
|
699
|
-
(entry) => typeof entry === "string" || typeof entry === "function" || entry instanceof RegExp
|
|
700
|
-
);
|
|
701
|
-
}
|
|
702
|
-
function previewAllowedHosts() {
|
|
703
|
-
const hosts = /* @__PURE__ */ new Set([".modal.host"]);
|
|
704
|
-
const addHost = (value) => {
|
|
705
|
-
const trimmed = value.trim();
|
|
706
|
-
if (!trimmed)
|
|
707
|
-
return;
|
|
708
|
-
try {
|
|
709
|
-
const parsed = new URL(
|
|
710
|
-
trimmed.includes("://") ? trimmed : `https://${trimmed}`
|
|
711
|
-
);
|
|
712
|
-
if (!["http:", "https:"].includes(parsed.protocol))
|
|
713
|
-
throw new Error();
|
|
714
|
-
if (parsed.username || parsed.password)
|
|
715
|
-
throw new Error();
|
|
716
|
-
const hostname = parsed.hostname.toLowerCase();
|
|
717
|
-
const hostnameBody = hostname.startsWith(".") ? hostname.slice(1) : hostname;
|
|
718
|
-
const validHostname = hostnameBody === "localhost" || /^\[[0-9a-f:]+\]$/i.test(hostnameBody) || hostnameBody.split(".").every(
|
|
719
|
-
(label) => label.length > 0 && label.length <= 63 && /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i.test(label)
|
|
720
|
-
);
|
|
721
|
-
if (!validHostname || hostname === "*")
|
|
722
|
-
throw new Error();
|
|
723
|
-
hosts.add(hostname);
|
|
724
|
-
} catch {
|
|
725
|
-
logWarning(`Ignoring invalid preview host ${JSON.stringify(trimmed)}.`);
|
|
726
|
-
}
|
|
727
|
-
};
|
|
728
|
-
if (process.env.VIBE_PREVIEW_HOST)
|
|
729
|
-
addHost(process.env.VIBE_PREVIEW_HOST);
|
|
730
|
-
for (const host of (process.env.VIBE_PREVIEW_HOSTS ?? "").split(",")) {
|
|
731
|
-
addHost(host);
|
|
732
|
-
}
|
|
733
|
-
return [...hosts];
|
|
734
|
-
}
|
|
735
|
-
var DEPRECATED_HMR_WEBSOCKET_KEYS = [
|
|
736
|
-
"protocol",
|
|
737
|
-
"host",
|
|
738
|
-
"port",
|
|
739
|
-
"path",
|
|
740
|
-
"clientPort",
|
|
741
|
-
"timeout",
|
|
742
|
-
"server"
|
|
743
|
-
];
|
|
744
|
-
function withoutDeprecatedHmrWebsocketOptions(config) {
|
|
745
|
-
const hmr = config.server?.hmr;
|
|
746
|
-
if (hmr === false || hmr == null || typeof hmr !== "object") {
|
|
747
|
-
return config;
|
|
748
|
-
}
|
|
749
|
-
const nextHmr = { ...hmr };
|
|
750
|
-
let stripped = false;
|
|
751
|
-
for (const key of DEPRECATED_HMR_WEBSOCKET_KEYS) {
|
|
752
|
-
if (key in nextHmr) {
|
|
753
|
-
delete nextHmr[key];
|
|
754
|
-
stripped = true;
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
if (!stripped)
|
|
758
|
-
return config;
|
|
759
|
-
return {
|
|
760
|
-
...config,
|
|
761
|
-
server: {
|
|
762
|
-
...config.server,
|
|
763
|
-
hmr: nextHmr
|
|
764
|
-
}
|
|
765
|
-
};
|
|
766
|
-
}
|
|
767
|
-
function warnAndStripUnsupportedServerFields(config) {
|
|
768
|
-
const server = config.server;
|
|
769
|
-
if (!server)
|
|
770
|
-
return config;
|
|
771
|
-
if (server.headers) {
|
|
772
|
-
logWarning(
|
|
773
|
-
`Sandbox mode removed unsupported server.headers: ${boundedList(
|
|
774
|
-
Object.keys(server.headers)
|
|
775
|
-
)}.`
|
|
776
|
-
);
|
|
777
|
-
}
|
|
778
|
-
if (server.cors !== void 0) {
|
|
779
|
-
logWarning("Sandbox mode removed unsupported custom server.cors.");
|
|
780
|
-
}
|
|
781
|
-
if (server.proxy) {
|
|
782
|
-
logWarning(
|
|
783
|
-
`Sandbox mode removed unsupported server.proxy routes: ${boundedList(
|
|
784
|
-
Object.keys(server.proxy)
|
|
785
|
-
)}.`
|
|
786
|
-
);
|
|
787
|
-
}
|
|
788
|
-
if (server.headers === void 0 && server.cors === void 0 && server.proxy === void 0) {
|
|
789
|
-
return config;
|
|
790
|
-
}
|
|
791
|
-
const {
|
|
792
|
-
headers: _headers,
|
|
793
|
-
cors: _cors,
|
|
794
|
-
proxy: _proxy,
|
|
795
|
-
...supportedServer
|
|
796
|
-
} = server;
|
|
797
|
-
return { ...config, server: supportedServer };
|
|
798
|
-
}
|
|
799
|
-
function applyNonSandboxWatchDefaults(config) {
|
|
800
|
-
if (config.server?.watch === null)
|
|
801
|
-
return config;
|
|
802
|
-
return mergeConfig({
|
|
803
|
-
server: {
|
|
804
|
-
watch: {
|
|
805
|
-
awaitWriteFinish: {
|
|
806
|
-
stabilityThreshold: 1e3,
|
|
807
|
-
pollInterval: 100
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
|
-
}, config);
|
|
812
|
-
}
|
|
813
|
-
function applySandboxServerInvariants(config) {
|
|
814
|
-
const userWatch = config.server?.watch ?? {};
|
|
815
|
-
const ignored = [
|
|
816
|
-
...normalizeIgnored(userWatch.ignored),
|
|
817
|
-
...TOOL_MANAGED_WATCH_IGNORES
|
|
818
|
-
];
|
|
819
|
-
const dedupedIgnored = [...new Set(ignored)];
|
|
820
|
-
const allowedHosts = previewAllowedHosts();
|
|
821
|
-
const sanitized = withoutDeprecatedHmrWebsocketOptions(config);
|
|
822
|
-
const userHmr = sanitized.server?.hmr;
|
|
823
|
-
const sandboxHmr = userHmr === false ? false : { overlay: false };
|
|
824
|
-
const merged = mergeConfig(sanitized, {
|
|
825
|
-
server: {
|
|
826
|
-
host: "::",
|
|
827
|
-
port: 8080,
|
|
828
|
-
strictPort: true,
|
|
829
|
-
allowedHosts,
|
|
830
|
-
watch: { ...userWatch, ignored: dedupedIgnored },
|
|
831
|
-
hmr: sandboxHmr
|
|
832
|
-
}
|
|
833
|
-
});
|
|
834
|
-
const mergedServer = merged.server ?? {};
|
|
835
|
-
const invariantConfig = {
|
|
836
|
-
...merged,
|
|
837
|
-
server: {
|
|
838
|
-
...mergedServer,
|
|
839
|
-
host: "::",
|
|
840
|
-
port: 8080,
|
|
841
|
-
strictPort: true,
|
|
842
|
-
allowedHosts,
|
|
843
|
-
watch: {
|
|
844
|
-
...mergedServer.watch,
|
|
845
|
-
ignored: dedupedIgnored
|
|
846
|
-
},
|
|
847
|
-
hmr: sandboxHmr
|
|
848
|
-
}
|
|
849
|
-
};
|
|
850
|
-
return warnAndStripUnsupportedServerFields(invariantConfig);
|
|
851
|
-
}
|
|
852
|
-
|
|
853
|
-
// src/index.ts
|
|
854
|
-
var OPTION_KEYS = /* @__PURE__ */ new Set([
|
|
855
|
-
"vite",
|
|
856
|
-
"nitro",
|
|
857
|
-
"tanstackStart",
|
|
858
|
-
"react",
|
|
859
|
-
"envDefine",
|
|
860
|
-
"hmrGate",
|
|
861
|
-
"devServerBridge",
|
|
862
|
-
"ssrErrorLogger",
|
|
863
|
-
"serverFnErrorLogger"
|
|
864
|
-
]);
|
|
865
|
-
var DEFAULT_IMPORT_PROTECTION = {
|
|
866
|
-
behavior: "error",
|
|
867
|
-
client: {
|
|
868
|
-
files: ["**/server/**"],
|
|
869
|
-
specifiers: ["server-only"]
|
|
870
|
-
}
|
|
871
|
-
};
|
|
872
|
-
var DEFAULT_DEDUPE = [
|
|
873
|
-
"react",
|
|
874
|
-
"react-dom",
|
|
875
|
-
"react/jsx-runtime",
|
|
876
|
-
"react/jsx-dev-runtime",
|
|
877
|
-
"@tanstack/react-query",
|
|
878
|
-
"@tanstack/query-core"
|
|
879
|
-
];
|
|
880
|
-
var DEFAULT_OPTIMIZE_DEPS = [
|
|
881
|
-
"react",
|
|
882
|
-
"react-dom",
|
|
883
|
-
"react-dom/client",
|
|
884
|
-
"react/jsx-runtime",
|
|
885
|
-
"react/jsx-dev-runtime"
|
|
886
|
-
];
|
|
887
|
-
function logWarning2(message) {
|
|
888
|
-
console.warn(`[@leadconnector/vite-tanstack-config] ${message}`);
|
|
889
|
-
}
|
|
890
|
-
function isPromiseLike(value) {
|
|
891
|
-
return !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
|
|
892
|
-
}
|
|
893
|
-
function isExplicitOptions(value) {
|
|
894
|
-
return Object.keys(value).some((key) => OPTION_KEYS.has(key));
|
|
895
|
-
}
|
|
896
|
-
async function normalizeOptions(input, env) {
|
|
897
|
-
if (typeof input === "function") {
|
|
898
|
-
return { vite: await Promise.resolve(input(env)) };
|
|
899
|
-
}
|
|
900
|
-
if (isPromiseLike(input))
|
|
901
|
-
return { vite: await input };
|
|
902
|
-
const object = input && typeof input === "object" ? input : {};
|
|
903
|
-
return isExplicitOptions(object) ? object : { vite: object };
|
|
904
|
-
}
|
|
905
|
-
function pluginEnabled(option, isSandbox) {
|
|
906
|
-
return isSandbox ? option !== false : option === true || !!option;
|
|
907
|
-
}
|
|
908
|
-
function pluginOptions(option) {
|
|
909
|
-
return option && typeof option === "object" ? option : {};
|
|
910
|
-
}
|
|
911
|
-
function platformDevServerBridgeOptions(option, isSandbox) {
|
|
912
|
-
const configured = pluginOptions(option);
|
|
913
|
-
if (!isSandbox || !configured.errorCollector || typeof configured.errorCollector !== "object") {
|
|
914
|
-
return configured;
|
|
915
|
-
}
|
|
916
|
-
return {
|
|
917
|
-
...configured,
|
|
918
|
-
errorCollector: {
|
|
919
|
-
...configured.errorCollector,
|
|
920
|
-
endpoint: "/__vibe/error-collector"
|
|
921
|
-
}
|
|
922
|
-
};
|
|
923
|
-
}
|
|
924
|
-
function withUserAliasPrecedence(config, userConfig) {
|
|
925
|
-
const userAlias = userConfig.resolve?.alias;
|
|
926
|
-
if (!userAlias)
|
|
927
|
-
return config;
|
|
928
|
-
if (Array.isArray(userAlias)) {
|
|
929
|
-
const userAtAliases = userAlias.filter((entry) => entry.find === "@");
|
|
930
|
-
if (userAtAliases.length === 0)
|
|
931
|
-
return config;
|
|
932
|
-
const merged = Array.isArray(config.resolve?.alias) ? config.resolve.alias : Object.entries(config.resolve?.alias ?? {}).map(
|
|
933
|
-
([find, replacement]) => ({ find, replacement })
|
|
934
|
-
);
|
|
935
|
-
return {
|
|
936
|
-
...config,
|
|
937
|
-
resolve: {
|
|
938
|
-
...config.resolve,
|
|
939
|
-
alias: [
|
|
940
|
-
...userAtAliases,
|
|
941
|
-
...merged.filter((entry) => entry.find !== "@")
|
|
942
|
-
]
|
|
943
|
-
}
|
|
944
|
-
};
|
|
945
|
-
}
|
|
946
|
-
const userAliasRecord = userAlias;
|
|
947
|
-
if (!Object.prototype.hasOwnProperty.call(userAliasRecord, "@"))
|
|
948
|
-
return config;
|
|
949
|
-
const mergedAlias = Array.isArray(config.resolve?.alias) ? config.resolve.alias.filter((entry) => entry.find !== "@") : config.resolve?.alias;
|
|
950
|
-
return {
|
|
951
|
-
...config,
|
|
952
|
-
resolve: {
|
|
953
|
-
...config.resolve,
|
|
954
|
-
alias: Array.isArray(mergedAlias) ? [{ find: "@", replacement: userAliasRecord["@"] }, ...mergedAlias] : { ...mergedAlias, "@": userAliasRecord["@"] }
|
|
955
|
-
}
|
|
956
|
-
};
|
|
957
|
-
}
|
|
958
|
-
function defineConfig(configOrOptions = {}) {
|
|
959
|
-
return async (env) => {
|
|
960
|
-
const { command, mode } = env;
|
|
961
|
-
const isSandbox = isSandboxEnvironment();
|
|
962
|
-
const options = await normalizeOptions(configOrOptions, env);
|
|
963
|
-
const internalPlugins = [];
|
|
964
|
-
if (mode === "development") {
|
|
965
|
-
const { devtools } = await import("@tanstack/devtools-vite");
|
|
966
|
-
internalPlugins.push(
|
|
967
|
-
devtools({
|
|
968
|
-
logging: false,
|
|
969
|
-
eventBusConfig: { enabled: false },
|
|
970
|
-
enhancedLogs: { enabled: false },
|
|
971
|
-
consolePiping: { enabled: false },
|
|
972
|
-
removeDevtoolsOnBuild: false,
|
|
973
|
-
injectSource: { enabled: true }
|
|
974
|
-
})
|
|
975
|
-
);
|
|
976
|
-
}
|
|
977
|
-
if (command === "serve" && mode === "development") {
|
|
978
|
-
internalPlugins.push(
|
|
979
|
-
componentTagger({ jsxSource: true, tailwindConfig: true })
|
|
980
|
-
);
|
|
981
|
-
}
|
|
982
|
-
const tailwindcss = (await import("@tailwindcss/vite")).default;
|
|
983
|
-
const tsConfigPaths = (await import("vite-tsconfig-paths")).default;
|
|
984
|
-
internalPlugins.push(tailwindcss());
|
|
985
|
-
internalPlugins.push(tsConfigPaths({ projects: ["./tsconfig.json"] }));
|
|
986
|
-
if (options.serverFnErrorLogger !== false) {
|
|
987
|
-
internalPlugins.push(createServerFnErrorLogger());
|
|
988
|
-
}
|
|
989
|
-
if (options.ssrErrorLogger !== false) {
|
|
990
|
-
internalPlugins.push(createSsrErrorLogger());
|
|
991
|
-
}
|
|
992
|
-
if (command === "build" && isSandbox) {
|
|
993
|
-
internalPlugins.push(createBuildErrorDiagnostics());
|
|
994
|
-
}
|
|
995
|
-
const { tanstackStart } = await import("@tanstack/react-start/plugin/vite");
|
|
996
|
-
const tanstackStartOptions = mergeConfig2(
|
|
997
|
-
{ importProtection: DEFAULT_IMPORT_PROTECTION },
|
|
998
|
-
options.tanstackStart ?? {}
|
|
999
|
-
);
|
|
1000
|
-
internalPlugins.push(tanstackStart(tanstackStartOptions));
|
|
1001
|
-
if (shouldRunNitro(command, options.nitro, isSandbox)) {
|
|
1002
|
-
const requiredReason = options.nitro === true || typeof options.nitro === "object" && options.nitro !== null ? "an explicit `nitro` option was set" : "running inside a Vibe sandbox";
|
|
1003
|
-
const nitroFn = await loadNitroPlugin(
|
|
1004
|
-
// nitro is an optional peer dependency, so keep the import dynamic.
|
|
1005
|
-
// @ts-expect-error -- optional peer types are intentionally unavailable.
|
|
1006
|
-
() => import("nitro/vite"),
|
|
1007
|
-
requiredReason
|
|
1008
|
-
);
|
|
1009
|
-
const nitroOptions = buildNitroOptions(options.nitro, isSandbox);
|
|
1010
|
-
internalPlugins.push(nitroFn(nitroOptions));
|
|
1011
|
-
if (isSandbox) {
|
|
1012
|
-
const output = nitroOptions.output;
|
|
1013
|
-
internalPlugins.push(
|
|
1014
|
-
stripRedundantNodejsCompatFlag(
|
|
1015
|
-
typeof output?.serverDir === "string" ? output.serverDir : "dist/server"
|
|
1016
|
-
)
|
|
1017
|
-
);
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
const viteReact = (await import("@vitejs/plugin-react")).default;
|
|
1021
|
-
internalPlugins.push(viteReact(options.react ?? {}));
|
|
1022
|
-
if (command === "serve" && pluginEnabled(options.hmrGate, isSandbox)) {
|
|
1023
|
-
const { hmrGatePlugin } = await import("@leadconnector/vite-plugin-hmr-gate");
|
|
1024
|
-
internalPlugins.push(
|
|
1025
|
-
hmrGatePlugin(pluginOptions(options.hmrGate))
|
|
1026
|
-
);
|
|
1027
|
-
}
|
|
1028
|
-
if (command === "serve" && pluginEnabled(options.devServerBridge, isSandbox)) {
|
|
1029
|
-
const { devServerBridgePlugin } = await import("@leadconnector/vite-plugin-dev-server-bridge");
|
|
1030
|
-
internalPlugins.push(
|
|
1031
|
-
devServerBridgePlugin(
|
|
1032
|
-
platformDevServerBridgeOptions(options.devServerBridge, isSandbox)
|
|
1033
|
-
)
|
|
1034
|
-
);
|
|
1035
|
-
}
|
|
1036
|
-
const userConfig = options.vite ?? {};
|
|
1037
|
-
const projectRoot = resolve2(process.cwd(), userConfig.root ?? ".");
|
|
1038
|
-
const envDirectory = userConfig.envDir === false ? void 0 : resolve2(projectRoot, userConfig.envDir ?? ".");
|
|
1039
|
-
const envDefine = {};
|
|
1040
|
-
if (options.envDefine !== false && envDirectory) {
|
|
1041
|
-
const loadedEnv = loadEnv(mode, envDirectory, "VITE_");
|
|
1042
|
-
for (const [key, value] of Object.entries(loadedEnv)) {
|
|
1043
|
-
envDefine[`import.meta.env.${key}`] = JSON.stringify(value);
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
|
-
const isDevBuild = command === "build" && mode === "development";
|
|
1047
|
-
const baseConfig = {
|
|
1048
|
-
define: {
|
|
1049
|
-
...envDefine,
|
|
1050
|
-
...isDevBuild ? {
|
|
1051
|
-
"process.env.NODE_ENV": JSON.stringify("development")
|
|
1052
|
-
} : {}
|
|
1053
|
-
},
|
|
1054
|
-
...isDevBuild ? {
|
|
1055
|
-
environments: {
|
|
1056
|
-
client: {
|
|
1057
|
-
define: {
|
|
1058
|
-
"process.env.NODE_ENV": JSON.stringify("development")
|
|
1059
|
-
}
|
|
1060
|
-
}
|
|
1061
|
-
},
|
|
1062
|
-
esbuild: { keepNames: true }
|
|
1063
|
-
} : {},
|
|
1064
|
-
css: { transformer: "lightningcss" },
|
|
1065
|
-
resolve: {
|
|
1066
|
-
alias: { "@": resolve2(projectRoot, "src") },
|
|
1067
|
-
dedupe: DEFAULT_DEDUPE
|
|
1068
|
-
},
|
|
1069
|
-
optimizeDeps: {
|
|
1070
|
-
include: DEFAULT_OPTIMIZE_DEPS,
|
|
1071
|
-
ignoreOutdatedRequests: true
|
|
1072
|
-
},
|
|
1073
|
-
plugins: [...internalPlugins, ...options.plugins ?? []],
|
|
1074
|
-
server: { host: "::", port: 8080 }
|
|
1075
|
-
};
|
|
1076
|
-
let config = mergeConfig2(baseConfig, userConfig);
|
|
1077
|
-
config = withUserAliasPrecedence(config, userConfig);
|
|
1078
|
-
if (command === "serve" && isSandbox && bundledDevRequested()) {
|
|
1079
|
-
const viteVersion = resolveInstalledViteVersion(projectRoot);
|
|
1080
|
-
if (viteVersionSupportsBundledDev(viteVersion)) {
|
|
1081
|
-
config = mergeConfig2(config, {
|
|
1082
|
-
experimental: { bundledDev: true },
|
|
1083
|
-
plugins: [bundledDevCssUrlShim()]
|
|
1084
|
-
});
|
|
1085
|
-
} else {
|
|
1086
|
-
logWarning2(
|
|
1087
|
-
`Bundled dev requested (${BUNDLED_DEV_ENV_VAR}=true), but installed Vite ${viteVersion ?? "unresolved"} is missing, prerelease, or below 8.1. Starting classic dev.`
|
|
1088
|
-
);
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
return isSandbox ? applySandboxServerInvariants(config) : applyNonSandboxWatchDefaults(config);
|
|
1092
|
-
};
|
|
1093
|
-
}
|
|
1094
|
-
export {
|
|
1095
|
-
defineConfig
|
|
1096
|
-
};
|
|
1097
|
-
//# sourceMappingURL=index.js.map
|