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