veryfront 0.0.72 → 0.0.74
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/README.md +3 -0
- package/dist/ai/components.js +593 -52
- package/dist/ai/components.js.map +3 -3
- package/dist/ai/dev.js +121 -18
- package/dist/ai/dev.js.map +2 -2
- package/dist/ai/index.js +732 -236
- package/dist/ai/index.js.map +4 -4
- package/dist/ai/production.js +121 -18
- package/dist/ai/production.js.map +2 -2
- package/dist/ai/react.js +57 -37
- package/dist/ai/react.js.map +2 -2
- package/dist/ai/workflow.js +435 -63
- package/dist/ai/workflow.js.map +4 -4
- package/dist/components.js +3353 -206
- package/dist/components.js.map +4 -4
- package/dist/config.js +377 -40
- package/dist/config.js.map +3 -3
- package/dist/context.d.ts +44 -0
- package/dist/context.js +52 -0
- package/dist/context.js.map +7 -0
- package/dist/data.js +156 -37
- package/dist/data.js.map +3 -3
- package/dist/fonts.d.ts +24 -0
- package/dist/fonts.js +45 -0
- package/dist/fonts.js.map +7 -0
- package/dist/head.d.ts +21 -0
- package/dist/head.js +34 -0
- package/dist/head.js.map +7 -0
- package/dist/index.js +3463 -282
- package/dist/index.js.map +4 -4
- package/dist/oauth/handlers.js +1 -1
- package/dist/oauth/handlers.js.map +2 -2
- package/dist/oauth/index.js +1 -1
- package/dist/oauth/index.js.map +2 -2
- package/dist/oauth/providers.js +1 -1
- package/dist/oauth/providers.js.map +2 -2
- package/dist/router.d.ts +69 -0
- package/dist/router.js +61 -0
- package/dist/router.js.map +7 -0
- package/dist/templates/ai/app/api/chat/route.ts +106 -3
- package/package.json +19 -2
- package/dist/cli.js +0 -108105
package/dist/components.js
CHANGED
|
@@ -122,6 +122,47 @@ function resolveLogLevel(force = false) {
|
|
|
122
122
|
}
|
|
123
123
|
return cachedLogLevel;
|
|
124
124
|
}
|
|
125
|
+
function resolveLogFormat(force = false) {
|
|
126
|
+
if (force || cachedLogFormat === void 0) {
|
|
127
|
+
cachedLogFormat = getDefaultFormat();
|
|
128
|
+
}
|
|
129
|
+
return cachedLogFormat;
|
|
130
|
+
}
|
|
131
|
+
function getDefaultFormat() {
|
|
132
|
+
const envFormat = getEnvironmentVariable("LOG_FORMAT");
|
|
133
|
+
if (envFormat === "json" || envFormat === "text") {
|
|
134
|
+
return envFormat;
|
|
135
|
+
}
|
|
136
|
+
return isProductionEnvironment() ? "json" : "text";
|
|
137
|
+
}
|
|
138
|
+
function serializeError(err) {
|
|
139
|
+
if (err instanceof Error) {
|
|
140
|
+
return {
|
|
141
|
+
name: err.name,
|
|
142
|
+
message: err.message,
|
|
143
|
+
stack: err.stack
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
if (err !== void 0 && err !== null) {
|
|
147
|
+
return {
|
|
148
|
+
name: "UnknownError",
|
|
149
|
+
message: String(err)
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return void 0;
|
|
153
|
+
}
|
|
154
|
+
function extractContext(args) {
|
|
155
|
+
let context;
|
|
156
|
+
let error;
|
|
157
|
+
for (const arg of args) {
|
|
158
|
+
if (arg instanceof Error) {
|
|
159
|
+
error = serializeError(arg);
|
|
160
|
+
} else if (typeof arg === "object" && arg !== null && !Array.isArray(arg)) {
|
|
161
|
+
context = { ...context, ...arg };
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return { context, error };
|
|
165
|
+
}
|
|
125
166
|
function parseLogLevel(levelString) {
|
|
126
167
|
if (!levelString)
|
|
127
168
|
return void 0;
|
|
@@ -146,8 +187,10 @@ function createLogger(prefix) {
|
|
|
146
187
|
}
|
|
147
188
|
function __loggerResetForTests(options = {}) {
|
|
148
189
|
const updatedLevel = resolveLogLevel(true);
|
|
190
|
+
const updatedFormat = resolveLogFormat(true);
|
|
149
191
|
for (const instance of trackedLoggers) {
|
|
150
192
|
instance.setLevel(updatedLevel);
|
|
193
|
+
instance.setFormat(updatedFormat);
|
|
151
194
|
}
|
|
152
195
|
if (options.restoreConsole) {
|
|
153
196
|
console.debug = originalConsole.debug;
|
|
@@ -156,7 +199,10 @@ function __loggerResetForTests(options = {}) {
|
|
|
156
199
|
console.error = originalConsole.error;
|
|
157
200
|
}
|
|
158
201
|
}
|
|
159
|
-
|
|
202
|
+
function createRequestLogger(baseLogger, requestContext) {
|
|
203
|
+
return baseLogger.child(requestContext);
|
|
204
|
+
}
|
|
205
|
+
var LogLevel, originalConsole, cachedLogLevel, cachedLogFormat, ConsoleLogger, getDefaultLevel, trackedLoggers, cliLogger, serverLogger, rendererLogger, bundlerLogger, agentLogger, proxyLogger, logger;
|
|
160
206
|
var init_logger = __esm({
|
|
161
207
|
"src/core/utils/logger/logger.ts"() {
|
|
162
208
|
"use strict";
|
|
@@ -175,10 +221,15 @@ var init_logger = __esm({
|
|
|
175
221
|
warn: console.warn,
|
|
176
222
|
error: console.error
|
|
177
223
|
};
|
|
178
|
-
ConsoleLogger = class {
|
|
179
|
-
constructor(prefix, level = resolveLogLevel()) {
|
|
224
|
+
ConsoleLogger = class _ConsoleLogger {
|
|
225
|
+
constructor(prefix, level = resolveLogLevel(), format = resolveLogFormat(), boundContext) {
|
|
180
226
|
this.prefix = prefix;
|
|
181
227
|
this.level = level;
|
|
228
|
+
this.format = format;
|
|
229
|
+
this.boundContext = {};
|
|
230
|
+
if (boundContext) {
|
|
231
|
+
this.boundContext = boundContext;
|
|
232
|
+
}
|
|
182
233
|
}
|
|
183
234
|
setLevel(level) {
|
|
184
235
|
this.level = level;
|
|
@@ -186,36 +237,88 @@ var init_logger = __esm({
|
|
|
186
237
|
getLevel() {
|
|
187
238
|
return this.level;
|
|
188
239
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
240
|
+
setFormat(format) {
|
|
241
|
+
this.format = format;
|
|
242
|
+
}
|
|
243
|
+
getFormat() {
|
|
244
|
+
return this.format;
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Create a child logger with additional bound context.
|
|
248
|
+
*/
|
|
249
|
+
child(context) {
|
|
250
|
+
return new _ConsoleLogger(this.prefix, this.level, this.format, {
|
|
251
|
+
...this.boundContext,
|
|
252
|
+
...context
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
formatJson(level, message, args) {
|
|
256
|
+
const { context, error } = extractContext(args);
|
|
257
|
+
const entry = {
|
|
258
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString(),
|
|
259
|
+
level,
|
|
260
|
+
service: this.prefix.toLowerCase(),
|
|
261
|
+
message
|
|
262
|
+
};
|
|
263
|
+
const mergedContext = { ...this.boundContext, ...context };
|
|
264
|
+
if (Object.keys(mergedContext).length > 0) {
|
|
265
|
+
if ("requestId" in mergedContext) {
|
|
266
|
+
entry.requestId = String(mergedContext.requestId);
|
|
267
|
+
delete mergedContext.requestId;
|
|
268
|
+
}
|
|
269
|
+
if ("traceId" in mergedContext) {
|
|
270
|
+
entry.traceId = String(mergedContext.traceId);
|
|
271
|
+
delete mergedContext.traceId;
|
|
272
|
+
}
|
|
273
|
+
if ("projectSlug" in mergedContext) {
|
|
274
|
+
entry.projectSlug = String(mergedContext.projectSlug);
|
|
275
|
+
delete mergedContext.projectSlug;
|
|
276
|
+
}
|
|
277
|
+
if ("durationMs" in mergedContext) {
|
|
278
|
+
entry.durationMs = Number(mergedContext.durationMs);
|
|
279
|
+
delete mergedContext.durationMs;
|
|
280
|
+
}
|
|
281
|
+
if (Object.keys(mergedContext).length > 0) {
|
|
282
|
+
entry.context = mergedContext;
|
|
283
|
+
}
|
|
192
284
|
}
|
|
285
|
+
if (error) {
|
|
286
|
+
entry.error = error;
|
|
287
|
+
}
|
|
288
|
+
return JSON.stringify(entry);
|
|
193
289
|
}
|
|
194
|
-
|
|
195
|
-
if (this.level
|
|
196
|
-
|
|
290
|
+
log(level, logLevel, consoleFn, message, args) {
|
|
291
|
+
if (this.level > logLevel)
|
|
292
|
+
return;
|
|
293
|
+
if (this.format === "json") {
|
|
294
|
+
consoleFn(this.formatJson(level, message, args));
|
|
295
|
+
} else {
|
|
296
|
+
const prefix = level === "info" ? "" : ` ${level.toUpperCase()}:`;
|
|
297
|
+
consoleFn(`[${this.prefix}]${prefix} ${message}`, ...args);
|
|
197
298
|
}
|
|
198
299
|
}
|
|
300
|
+
debug(message, ...args) {
|
|
301
|
+
this.log("debug", 0 /* DEBUG */, console.debug, message, args);
|
|
302
|
+
}
|
|
303
|
+
info(message, ...args) {
|
|
304
|
+
this.log("info", 1 /* INFO */, console.log, message, args);
|
|
305
|
+
}
|
|
199
306
|
warn(message, ...args) {
|
|
200
|
-
|
|
201
|
-
console.warn(`[${this.prefix}] WARN: ${message}`, ...args);
|
|
202
|
-
}
|
|
307
|
+
this.log("warn", 2 /* WARN */, console.warn, message, args);
|
|
203
308
|
}
|
|
204
309
|
error(message, ...args) {
|
|
205
|
-
|
|
206
|
-
console.error(`[${this.prefix}] ERROR: ${message}`, ...args);
|
|
207
|
-
}
|
|
310
|
+
this.log("error", 3 /* ERROR */, console.error, message, args);
|
|
208
311
|
}
|
|
209
312
|
async time(label, fn) {
|
|
210
313
|
const start = performance.now();
|
|
211
314
|
try {
|
|
212
315
|
const result = await fn();
|
|
213
|
-
const
|
|
214
|
-
this.debug(`${label} completed
|
|
316
|
+
const durationMs = performance.now() - start;
|
|
317
|
+
this.debug(`${label} completed`, { durationMs: Math.round(durationMs) });
|
|
215
318
|
return result;
|
|
216
319
|
} catch (error) {
|
|
217
|
-
const
|
|
218
|
-
this.error(`${label} failed
|
|
320
|
+
const durationMs = performance.now() - start;
|
|
321
|
+
this.error(`${label} failed`, { durationMs: Math.round(durationMs) }, error);
|
|
219
322
|
throw error;
|
|
220
323
|
}
|
|
221
324
|
}
|
|
@@ -236,6 +339,7 @@ var init_logger = __esm({
|
|
|
236
339
|
rendererLogger = createLogger("RENDERER");
|
|
237
340
|
bundlerLogger = createLogger("BUNDLER");
|
|
238
341
|
agentLogger = createLogger("AGENT");
|
|
342
|
+
proxyLogger = createLogger("PROXY");
|
|
239
343
|
logger = createLogger("VERYFRONT");
|
|
240
344
|
}
|
|
241
345
|
});
|
|
@@ -311,7 +415,7 @@ var init_deno = __esm({
|
|
|
311
415
|
"deno.json"() {
|
|
312
416
|
deno_default = {
|
|
313
417
|
name: "veryfront",
|
|
314
|
-
version: "0.0.
|
|
418
|
+
version: "0.0.74",
|
|
315
419
|
nodeModulesDir: "auto",
|
|
316
420
|
exclude: [
|
|
317
421
|
"npm/",
|
|
@@ -396,12 +500,12 @@ var init_deno = __esm({
|
|
|
396
500
|
csstype: "https://esm.sh/csstype@3.2.3",
|
|
397
501
|
"@types/react": "https://esm.sh/@types/react@18.3.27?deps=csstype@3.2.3",
|
|
398
502
|
"@types/react-dom": "https://esm.sh/@types/react-dom@18.3.7?deps=csstype@3.2.3",
|
|
399
|
-
react: "
|
|
400
|
-
"react-dom": "
|
|
401
|
-
"react-dom/server": "
|
|
402
|
-
"react-dom/client": "
|
|
403
|
-
"react/jsx-runtime": "
|
|
404
|
-
"react/jsx-dev-runtime": "
|
|
503
|
+
react: "npm:react@18.3.1",
|
|
504
|
+
"react-dom": "npm:react-dom@18.3.1",
|
|
505
|
+
"react-dom/server": "npm:react-dom@18.3.1/server.node",
|
|
506
|
+
"react-dom/client": "npm:react-dom@18.3.1/client",
|
|
507
|
+
"react/jsx-runtime": "npm:react@18.3.1/jsx-runtime",
|
|
508
|
+
"react/jsx-dev-runtime": "npm:react@18.3.1/jsx-dev-runtime",
|
|
405
509
|
"@mdx-js/mdx": "npm:@mdx-js/mdx@3.0.0",
|
|
406
510
|
"@mdx-js/react": "npm:@mdx-js/react@3.0.0",
|
|
407
511
|
"unist-util-visit": "npm:unist-util-visit@5.0.0",
|
|
@@ -411,27 +515,36 @@ var init_deno = __esm({
|
|
|
411
515
|
"remark-frontmatter": "npm:remark-frontmatter@5.0.0",
|
|
412
516
|
"rehype-highlight": "npm:rehype-highlight@7.0.2",
|
|
413
517
|
"rehype-slug": "npm:rehype-slug@6.0.0",
|
|
414
|
-
esbuild: "
|
|
415
|
-
"esbuild/mod.js": "
|
|
518
|
+
esbuild: "npm:esbuild@0.20.2",
|
|
519
|
+
"esbuild/mod.js": "npm:esbuild@0.20.2",
|
|
416
520
|
"es-module-lexer": "npm:es-module-lexer@1.5.0",
|
|
417
|
-
zod: "npm:zod@3.
|
|
521
|
+
zod: "npm:zod@3.25.76",
|
|
418
522
|
"mime-types": "npm:mime-types@2.1.35",
|
|
419
523
|
mdast: "npm:@types/mdast@4.0.3",
|
|
420
524
|
hast: "npm:@types/hast@3.0.3",
|
|
421
525
|
unist: "npm:@types/unist@3.0.2",
|
|
422
526
|
unified: "npm:unified@11.0.5",
|
|
423
|
-
ai: "
|
|
424
|
-
"ai/react": "
|
|
425
|
-
"@ai-sdk/react": "
|
|
527
|
+
ai: "npm:ai@5.0.76",
|
|
528
|
+
"ai/react": "npm:@ai-sdk/react@2.0.1",
|
|
529
|
+
"@ai-sdk/react": "npm:@ai-sdk/react@2.0.1",
|
|
426
530
|
"@ai-sdk/openai": "https://esm.sh/@ai-sdk/openai@2.0.1",
|
|
427
531
|
"@ai-sdk/anthropic": "https://esm.sh/@ai-sdk/anthropic@2.0.1",
|
|
428
532
|
unocss: "https://esm.sh/unocss@0.59.0",
|
|
429
533
|
"@unocss/core": "https://esm.sh/@unocss/core@0.59.0",
|
|
430
534
|
"@unocss/preset-wind": "https://esm.sh/@unocss/preset-wind@0.59.0",
|
|
535
|
+
"next-themes": "npm:next-themes@0.3.0",
|
|
431
536
|
redis: "npm:redis",
|
|
432
537
|
pg: "npm:pg",
|
|
433
538
|
"@opentelemetry/api": "npm:@opentelemetry/api@1",
|
|
434
|
-
"@opentelemetry/core": "npm:@opentelemetry/core@1"
|
|
539
|
+
"@opentelemetry/core": "npm:@opentelemetry/core@1",
|
|
540
|
+
"@opentelemetry/sdk-trace-base": "npm:@opentelemetry/sdk-trace-base@1",
|
|
541
|
+
"@opentelemetry/exporter-trace-otlp-http": "npm:@opentelemetry/exporter-trace-otlp-http@0.57",
|
|
542
|
+
"@opentelemetry/resources": "npm:@opentelemetry/resources@1",
|
|
543
|
+
"@opentelemetry/semantic-conventions": "npm:@opentelemetry/semantic-conventions@1",
|
|
544
|
+
"@babel/parser": "npm:@babel/parser@7.26.3",
|
|
545
|
+
"@babel/traverse": "npm:@babel/traverse@7.26.3",
|
|
546
|
+
"@babel/generator": "npm:@babel/generator@7.26.3",
|
|
547
|
+
"@babel/types": "npm:@babel/types@7.26.3"
|
|
435
548
|
},
|
|
436
549
|
compilerOptions: {
|
|
437
550
|
jsx: "react-jsx",
|
|
@@ -439,7 +552,7 @@ var init_deno = __esm({
|
|
|
439
552
|
strict: true,
|
|
440
553
|
noImplicitAny: true,
|
|
441
554
|
noUncheckedIndexedAccess: true,
|
|
442
|
-
types: [],
|
|
555
|
+
types: ["npm:@types/react@18"],
|
|
443
556
|
lib: [
|
|
444
557
|
"deno.window",
|
|
445
558
|
"dom",
|
|
@@ -454,9 +567,9 @@ var init_deno = __esm({
|
|
|
454
567
|
build: "deno compile --allow-all --output ../../bin/veryfront src/cli/main.ts",
|
|
455
568
|
"build:npm": "deno run -A scripts/build-npm.ts",
|
|
456
569
|
release: "deno run -A scripts/release.ts",
|
|
457
|
-
test: "DENO_JOBS=1 deno test --parallel --fail-fast --allow-all --unstable-worker-options --unstable-net",
|
|
458
|
-
"test:unit": "DENO_JOBS=1 deno test --parallel --allow-all --v8-flags=--max-old-space-size=8192 --ignore=tests --unstable-worker-options --unstable-net",
|
|
459
|
-
"test:integration": "DENO_JOBS=1 deno test --parallel --fail-fast --allow-all tests --unstable-worker-options --unstable-net",
|
|
570
|
+
test: "VF_DISABLE_LRU_INTERVAL=1 DENO_JOBS=1 deno test --parallel --fail-fast --allow-all --unstable-worker-options --unstable-net",
|
|
571
|
+
"test:unit": "VF_DISABLE_LRU_INTERVAL=1 DENO_JOBS=1 deno test --parallel --allow-all --v8-flags=--max-old-space-size=8192 --ignore=tests,src/ai/workflow/__tests__ --unstable-worker-options --unstable-net",
|
|
572
|
+
"test:integration": "VF_DISABLE_LRU_INTERVAL=1 DENO_JOBS=1 deno test --parallel --fail-fast --allow-all tests --unstable-worker-options --unstable-net",
|
|
460
573
|
"test:coverage": "rm -rf coverage && DENO_JOBS=1 deno test --parallel --fail-fast --allow-all --coverage=coverage --unstable-worker-options --unstable-net || exit 1",
|
|
461
574
|
"test:coverage:unit": "rm -rf coverage && DENO_JOBS=1 deno test --parallel --fail-fast --allow-all --coverage=coverage --ignore=tests --unstable-worker-options --unstable-net || exit 1",
|
|
462
575
|
"test:coverage:integration": "rm -rf coverage && DENO_JOBS=1 deno test --parallel --fail-fast --allow-all --coverage=coverage tests --unstable-worker-options --unstable-net || exit 1",
|
|
@@ -519,12 +632,17 @@ var init_deno = __esm({
|
|
|
519
632
|
});
|
|
520
633
|
|
|
521
634
|
// src/platform/compat/runtime.ts
|
|
635
|
+
function isNodeRuntime() {
|
|
636
|
+
const _global = globalThis;
|
|
637
|
+
const isRealDeno = typeof Deno !== "undefined" && typeof Deno.version === "object";
|
|
638
|
+
return !isRealDeno && typeof _global.process !== "undefined" && !!_global.process?.versions?.node;
|
|
639
|
+
}
|
|
522
640
|
var isDeno, isNode, isBun, isCloudflare;
|
|
523
641
|
var init_runtime = __esm({
|
|
524
642
|
"src/platform/compat/runtime.ts"() {
|
|
525
643
|
"use strict";
|
|
526
644
|
init_deno_env();
|
|
527
|
-
isDeno = typeof Deno !== "undefined";
|
|
645
|
+
isDeno = typeof Deno !== "undefined" && typeof Deno.version === "object";
|
|
528
646
|
isNode = typeof globalThis.process !== "undefined" && globalThis.process?.versions?.node !== void 0;
|
|
529
647
|
isBun = typeof globalThis.Bun !== "undefined";
|
|
530
648
|
isCloudflare = typeof globalThis !== "undefined" && "caches" in globalThis && "WebSocketPair" in globalThis;
|
|
@@ -571,7 +689,7 @@ var init_process = __esm({
|
|
|
571
689
|
});
|
|
572
690
|
|
|
573
691
|
// src/core/utils/version.ts
|
|
574
|
-
var VERSION;
|
|
692
|
+
var VERSION, SERVER_START_TIME;
|
|
575
693
|
var init_version = __esm({
|
|
576
694
|
"src/core/utils/version.ts"() {
|
|
577
695
|
"use strict";
|
|
@@ -579,6 +697,7 @@ var init_version = __esm({
|
|
|
579
697
|
init_deno();
|
|
580
698
|
init_process();
|
|
581
699
|
VERSION = getEnv("VERYFRONT_VERSION") || (typeof deno_default.version === "string" ? deno_default.version : "0.0.0");
|
|
700
|
+
SERVER_START_TIME = Date.now();
|
|
582
701
|
}
|
|
583
702
|
});
|
|
584
703
|
|
|
@@ -617,7 +736,7 @@ function getDenoStdNodeBase() {
|
|
|
617
736
|
function getUnoCSSTailwindResetUrl() {
|
|
618
737
|
return `${ESM_CDN_BASE}/@unocss/reset@${UNOCSS_VERSION}/tailwind.css`;
|
|
619
738
|
}
|
|
620
|
-
var ESM_CDN_BASE, JSDELIVR_CDN_BASE, DENO_STD_BASE, REACT_VERSION_17, REACT_VERSION_18_2, REACT_VERSION_18_3, REACT_VERSION_19_RC, REACT_VERSION_19, REACT_DEFAULT_VERSION, DEFAULT_ALLOWED_CDN_HOSTS, DENO_STD_VERSION, UNOCSS_VERSION;
|
|
739
|
+
var ESM_CDN_BASE, JSDELIVR_CDN_BASE, DENO_STD_BASE, REACT_VERSION_17, REACT_VERSION_18_2, REACT_VERSION_18_3, REACT_VERSION_19_RC, REACT_VERSION_19, REACT_DEFAULT_VERSION, DEFAULT_ALLOWED_CDN_HOSTS, DENO_STD_VERSION, TAILWIND_VERSION, UNOCSS_VERSION;
|
|
621
740
|
var init_cdn = __esm({
|
|
622
741
|
"src/core/utils/constants/cdn.ts"() {
|
|
623
742
|
"use strict";
|
|
@@ -634,6 +753,7 @@ var init_cdn = __esm({
|
|
|
634
753
|
REACT_DEFAULT_VERSION = REACT_VERSION_18_3;
|
|
635
754
|
DEFAULT_ALLOWED_CDN_HOSTS = [ESM_CDN_BASE, DENO_STD_BASE];
|
|
636
755
|
DENO_STD_VERSION = "0.220.0";
|
|
756
|
+
TAILWIND_VERSION = "4.1.8";
|
|
637
757
|
UNOCSS_VERSION = "0.59.0";
|
|
638
758
|
}
|
|
639
759
|
});
|
|
@@ -1371,8 +1491,8 @@ var init_bundle_manifest = __esm({
|
|
|
1371
1491
|
// src/core/utils/bundle-manifest-init.ts
|
|
1372
1492
|
async function initializeBundleManifest(config, mode, adapter) {
|
|
1373
1493
|
const manifestConfig = config.cache?.bundleManifest;
|
|
1374
|
-
const
|
|
1375
|
-
if (!
|
|
1494
|
+
const enabled2 = manifestConfig?.enabled ?? mode === "production";
|
|
1495
|
+
if (!enabled2) {
|
|
1376
1496
|
serverLogger.info("[bundle-manifest] Bundle manifest disabled");
|
|
1377
1497
|
setBundleManifestStore(new InMemoryBundleManifestStore());
|
|
1378
1498
|
return;
|
|
@@ -1514,6 +1634,380 @@ var init_platform = __esm({
|
|
|
1514
1634
|
}
|
|
1515
1635
|
});
|
|
1516
1636
|
|
|
1637
|
+
// src/core/utils/import-lockfile.ts
|
|
1638
|
+
function createEmptyLockfile() {
|
|
1639
|
+
return {
|
|
1640
|
+
version: LOCKFILE_VERSION,
|
|
1641
|
+
imports: {}
|
|
1642
|
+
};
|
|
1643
|
+
}
|
|
1644
|
+
async function computeIntegrity(content) {
|
|
1645
|
+
const hash = await computeHash(content);
|
|
1646
|
+
return `sha256-${hash}`;
|
|
1647
|
+
}
|
|
1648
|
+
function verifyIntegrity(content, integrity) {
|
|
1649
|
+
return computeIntegrity(content).then((computed) => computed === integrity);
|
|
1650
|
+
}
|
|
1651
|
+
function createNodeFSAdapter() {
|
|
1652
|
+
const fs = globalThis.Deno ? null : __require2("fs/promises");
|
|
1653
|
+
return {
|
|
1654
|
+
readFile(path) {
|
|
1655
|
+
if (globalThis.Deno) {
|
|
1656
|
+
return Deno.readTextFile(path);
|
|
1657
|
+
}
|
|
1658
|
+
return fs.readFile(path, "utf-8");
|
|
1659
|
+
},
|
|
1660
|
+
async writeFile(path, content) {
|
|
1661
|
+
if (globalThis.Deno) {
|
|
1662
|
+
await Deno.writeTextFile(path, content);
|
|
1663
|
+
return;
|
|
1664
|
+
}
|
|
1665
|
+
await fs.writeFile(path, content, "utf-8");
|
|
1666
|
+
},
|
|
1667
|
+
async exists(path) {
|
|
1668
|
+
try {
|
|
1669
|
+
if (globalThis.Deno) {
|
|
1670
|
+
await Deno.stat(path);
|
|
1671
|
+
return true;
|
|
1672
|
+
}
|
|
1673
|
+
await fs.access(path);
|
|
1674
|
+
return true;
|
|
1675
|
+
} catch {
|
|
1676
|
+
return false;
|
|
1677
|
+
}
|
|
1678
|
+
},
|
|
1679
|
+
async remove(path) {
|
|
1680
|
+
if (globalThis.Deno) {
|
|
1681
|
+
await Deno.remove(path);
|
|
1682
|
+
return;
|
|
1683
|
+
}
|
|
1684
|
+
await fs.unlink(path);
|
|
1685
|
+
}
|
|
1686
|
+
};
|
|
1687
|
+
}
|
|
1688
|
+
function createLockfileManager(projectDir, fsAdapter) {
|
|
1689
|
+
const fs = fsAdapter || createNodeFSAdapter();
|
|
1690
|
+
const lockfilePath = `${projectDir}/${LOCKFILE_NAME}`;
|
|
1691
|
+
let cache = null;
|
|
1692
|
+
let dirty = false;
|
|
1693
|
+
const read = async () => {
|
|
1694
|
+
if (cache)
|
|
1695
|
+
return cache;
|
|
1696
|
+
try {
|
|
1697
|
+
if (await fs.exists(lockfilePath)) {
|
|
1698
|
+
const content = await fs.readFile(lockfilePath);
|
|
1699
|
+
cache = JSON.parse(content);
|
|
1700
|
+
if (cache.version !== LOCKFILE_VERSION) {
|
|
1701
|
+
serverLogger.warn(
|
|
1702
|
+
`[lockfile] Version mismatch, expected ${LOCKFILE_VERSION}, got ${cache.version}`
|
|
1703
|
+
);
|
|
1704
|
+
cache = createEmptyLockfile();
|
|
1705
|
+
}
|
|
1706
|
+
return cache;
|
|
1707
|
+
}
|
|
1708
|
+
} catch (e) {
|
|
1709
|
+
serverLogger.debug(`[lockfile] Could not read lockfile: ${e}`);
|
|
1710
|
+
}
|
|
1711
|
+
return null;
|
|
1712
|
+
};
|
|
1713
|
+
const write = async (data) => {
|
|
1714
|
+
cache = data;
|
|
1715
|
+
const sorted = {
|
|
1716
|
+
version: data.version,
|
|
1717
|
+
imports: Object.fromEntries(
|
|
1718
|
+
Object.entries(data.imports).sort(([a], [b]) => a.localeCompare(b))
|
|
1719
|
+
)
|
|
1720
|
+
};
|
|
1721
|
+
await fs.writeFile(lockfilePath, JSON.stringify(sorted, null, 2) + "\n");
|
|
1722
|
+
dirty = false;
|
|
1723
|
+
serverLogger.debug(`[lockfile] Written ${Object.keys(data.imports).length} entries`);
|
|
1724
|
+
};
|
|
1725
|
+
const get = async (url) => {
|
|
1726
|
+
const data = await read();
|
|
1727
|
+
return data?.imports[url] ?? null;
|
|
1728
|
+
};
|
|
1729
|
+
const set = async (url, entry) => {
|
|
1730
|
+
let data = await read();
|
|
1731
|
+
if (!data) {
|
|
1732
|
+
data = createEmptyLockfile();
|
|
1733
|
+
}
|
|
1734
|
+
data.imports[url] = entry;
|
|
1735
|
+
cache = data;
|
|
1736
|
+
dirty = true;
|
|
1737
|
+
};
|
|
1738
|
+
const has = async (url) => {
|
|
1739
|
+
const data = await read();
|
|
1740
|
+
return url in (data?.imports ?? {});
|
|
1741
|
+
};
|
|
1742
|
+
const clear = async () => {
|
|
1743
|
+
cache = createEmptyLockfile();
|
|
1744
|
+
if (fs.remove && await fs.exists(lockfilePath)) {
|
|
1745
|
+
await fs.remove(lockfilePath);
|
|
1746
|
+
}
|
|
1747
|
+
};
|
|
1748
|
+
const flush = async () => {
|
|
1749
|
+
if (dirty && cache) {
|
|
1750
|
+
await write(cache);
|
|
1751
|
+
}
|
|
1752
|
+
};
|
|
1753
|
+
return {
|
|
1754
|
+
read,
|
|
1755
|
+
write,
|
|
1756
|
+
get,
|
|
1757
|
+
set,
|
|
1758
|
+
has,
|
|
1759
|
+
clear,
|
|
1760
|
+
flush
|
|
1761
|
+
};
|
|
1762
|
+
}
|
|
1763
|
+
async function fetchWithLock(options) {
|
|
1764
|
+
const { lockfile, url, fetchFn = fetch, strict = false } = options;
|
|
1765
|
+
const entry = await lockfile.get(url);
|
|
1766
|
+
if (entry) {
|
|
1767
|
+
serverLogger.debug(`[lockfile] Cache hit for ${url}`);
|
|
1768
|
+
const res2 = await fetchFn(entry.resolved, {
|
|
1769
|
+
headers: { "user-agent": "Mozilla/5.0 Veryfront/1.0" }
|
|
1770
|
+
});
|
|
1771
|
+
if (!res2.ok) {
|
|
1772
|
+
if (strict) {
|
|
1773
|
+
throw new Error(
|
|
1774
|
+
`Lockfile entry stale: ${url} resolved to ${entry.resolved} returned ${res2.status}`
|
|
1775
|
+
);
|
|
1776
|
+
}
|
|
1777
|
+
serverLogger.warn(`[lockfile] Cached URL ${entry.resolved} returned ${res2.status}, refetching`);
|
|
1778
|
+
} else {
|
|
1779
|
+
const content2 = await res2.text();
|
|
1780
|
+
const currentIntegrity = await computeIntegrity(content2);
|
|
1781
|
+
if (currentIntegrity !== entry.integrity) {
|
|
1782
|
+
if (strict) {
|
|
1783
|
+
throw new Error(
|
|
1784
|
+
`Integrity mismatch for ${url}: expected ${entry.integrity}, got ${currentIntegrity}`
|
|
1785
|
+
);
|
|
1786
|
+
}
|
|
1787
|
+
serverLogger.warn(`[lockfile] Integrity mismatch for ${url}, updating lockfile`);
|
|
1788
|
+
} else {
|
|
1789
|
+
return {
|
|
1790
|
+
content: content2,
|
|
1791
|
+
resolvedUrl: entry.resolved,
|
|
1792
|
+
fromCache: true,
|
|
1793
|
+
integrity: entry.integrity
|
|
1794
|
+
};
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
serverLogger.debug(`[lockfile] Fetching fresh: ${url}`);
|
|
1799
|
+
const res = await fetchFn(url, {
|
|
1800
|
+
headers: { "user-agent": "Mozilla/5.0 Veryfront/1.0" },
|
|
1801
|
+
redirect: "follow"
|
|
1802
|
+
});
|
|
1803
|
+
if (!res.ok) {
|
|
1804
|
+
throw new Error(`Failed to fetch ${url}: ${res.status}`);
|
|
1805
|
+
}
|
|
1806
|
+
const content = await res.text();
|
|
1807
|
+
const resolvedUrl = res.url || url;
|
|
1808
|
+
const integrity = await computeIntegrity(content);
|
|
1809
|
+
await lockfile.set(url, {
|
|
1810
|
+
resolved: resolvedUrl,
|
|
1811
|
+
integrity,
|
|
1812
|
+
fetchedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
1813
|
+
});
|
|
1814
|
+
await lockfile.flush();
|
|
1815
|
+
return {
|
|
1816
|
+
content,
|
|
1817
|
+
resolvedUrl,
|
|
1818
|
+
fromCache: false,
|
|
1819
|
+
integrity
|
|
1820
|
+
};
|
|
1821
|
+
}
|
|
1822
|
+
function extractImports(content) {
|
|
1823
|
+
const imports = [];
|
|
1824
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1825
|
+
for (const match of content.matchAll(IMPORT_REGEX)) {
|
|
1826
|
+
const specifier = match[1];
|
|
1827
|
+
if (specifier && !seen.has(specifier)) {
|
|
1828
|
+
seen.add(specifier);
|
|
1829
|
+
imports.push({ specifier, type: "static" });
|
|
1830
|
+
}
|
|
1831
|
+
}
|
|
1832
|
+
for (const match of content.matchAll(EXPORT_FROM_REGEX)) {
|
|
1833
|
+
const specifier = match[1];
|
|
1834
|
+
if (specifier && !seen.has(specifier)) {
|
|
1835
|
+
seen.add(specifier);
|
|
1836
|
+
imports.push({ specifier, type: "static" });
|
|
1837
|
+
}
|
|
1838
|
+
}
|
|
1839
|
+
for (const match of content.matchAll(DYNAMIC_IMPORT_REGEX)) {
|
|
1840
|
+
const specifier = match[1];
|
|
1841
|
+
if (specifier && !seen.has(specifier)) {
|
|
1842
|
+
seen.add(specifier);
|
|
1843
|
+
imports.push({ specifier, type: "dynamic" });
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
return imports;
|
|
1847
|
+
}
|
|
1848
|
+
function resolveImportUrl(specifier, baseUrl) {
|
|
1849
|
+
if (specifier.startsWith("http://") || specifier.startsWith("https://")) {
|
|
1850
|
+
return specifier;
|
|
1851
|
+
}
|
|
1852
|
+
if (specifier.startsWith("./") || specifier.startsWith("../")) {
|
|
1853
|
+
try {
|
|
1854
|
+
return new URL(specifier, baseUrl).toString();
|
|
1855
|
+
} catch {
|
|
1856
|
+
return null;
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
return null;
|
|
1860
|
+
}
|
|
1861
|
+
var LOCKFILE_NAME, LOCKFILE_VERSION, IMPORT_REGEX, DYNAMIC_IMPORT_REGEX, EXPORT_FROM_REGEX;
|
|
1862
|
+
var init_import_lockfile = __esm({
|
|
1863
|
+
"src/core/utils/import-lockfile.ts"() {
|
|
1864
|
+
"use strict";
|
|
1865
|
+
init_deno_env();
|
|
1866
|
+
init_hash_utils();
|
|
1867
|
+
init_logger2();
|
|
1868
|
+
LOCKFILE_NAME = "veryfront.lock";
|
|
1869
|
+
LOCKFILE_VERSION = 1;
|
|
1870
|
+
IMPORT_REGEX = /import\s+(?:(?:[\w*\s{},]*)\s+from\s+)?['"]([^'"]+)['"]/g;
|
|
1871
|
+
DYNAMIC_IMPORT_REGEX = /import\s*\(\s*['"]([^'"]+)['"]\s*\)/g;
|
|
1872
|
+
EXPORT_FROM_REGEX = /export\s+(?:[\w*\s{},]*)\s+from\s+['"]([^'"]+)['"]/g;
|
|
1873
|
+
}
|
|
1874
|
+
});
|
|
1875
|
+
|
|
1876
|
+
// src/core/utils/perf-timer.ts
|
|
1877
|
+
function startRequest(requestId) {
|
|
1878
|
+
if (!enabled)
|
|
1879
|
+
return;
|
|
1880
|
+
currentRequestId = requestId;
|
|
1881
|
+
timings.set(requestId, []);
|
|
1882
|
+
}
|
|
1883
|
+
function startTimer(label, parent) {
|
|
1884
|
+
if (!enabled || !currentRequestId)
|
|
1885
|
+
return () => {
|
|
1886
|
+
};
|
|
1887
|
+
const entry = {
|
|
1888
|
+
label,
|
|
1889
|
+
startMs: performance.now(),
|
|
1890
|
+
parent
|
|
1891
|
+
};
|
|
1892
|
+
const entries = timings.get(currentRequestId);
|
|
1893
|
+
if (entries) {
|
|
1894
|
+
entries.push(entry);
|
|
1895
|
+
}
|
|
1896
|
+
return () => {
|
|
1897
|
+
entry.endMs = performance.now();
|
|
1898
|
+
entry.durationMs = entry.endMs - entry.startMs;
|
|
1899
|
+
};
|
|
1900
|
+
}
|
|
1901
|
+
async function timeAsync(label, fn, parent) {
|
|
1902
|
+
if (!enabled)
|
|
1903
|
+
return fn();
|
|
1904
|
+
const stop = startTimer(label, parent);
|
|
1905
|
+
try {
|
|
1906
|
+
return await fn();
|
|
1907
|
+
} finally {
|
|
1908
|
+
stop();
|
|
1909
|
+
}
|
|
1910
|
+
}
|
|
1911
|
+
function endRequest(requestId) {
|
|
1912
|
+
if (!enabled)
|
|
1913
|
+
return;
|
|
1914
|
+
const entries = timings.get(requestId);
|
|
1915
|
+
if (!entries || entries.length === 0) {
|
|
1916
|
+
currentRequestId = null;
|
|
1917
|
+
return;
|
|
1918
|
+
}
|
|
1919
|
+
const sorted = entries.filter((e) => e.durationMs !== void 0).sort((a, b) => (b.durationMs || 0) - (a.durationMs || 0));
|
|
1920
|
+
const total = entries.find((e) => e.label === "total")?.durationMs || sorted.reduce((sum, e) => sum + (e.durationMs || 0), 0);
|
|
1921
|
+
console.log(`
|
|
1922
|
+
[PERF] Request ${requestId} - Total: ${total.toFixed(1)}ms`);
|
|
1923
|
+
console.log("\u2500".repeat(60));
|
|
1924
|
+
const roots = sorted.filter((e) => !e.parent);
|
|
1925
|
+
const children = /* @__PURE__ */ new Map();
|
|
1926
|
+
for (const entry of sorted) {
|
|
1927
|
+
if (entry.parent) {
|
|
1928
|
+
const list = children.get(entry.parent) || [];
|
|
1929
|
+
list.push(entry);
|
|
1930
|
+
children.set(entry.parent, list);
|
|
1931
|
+
}
|
|
1932
|
+
}
|
|
1933
|
+
for (const entry of roots) {
|
|
1934
|
+
const pct = ((entry.durationMs || 0) / total * 100).toFixed(1);
|
|
1935
|
+
console.log(` ${entry.label}: ${entry.durationMs?.toFixed(1)}ms (${pct}%)`);
|
|
1936
|
+
const childList = children.get(entry.label);
|
|
1937
|
+
if (childList) {
|
|
1938
|
+
for (const child of childList.slice(0, 5)) {
|
|
1939
|
+
const childPct = ((child.durationMs || 0) / total * 100).toFixed(1);
|
|
1940
|
+
console.log(` \u2514\u2500 ${child.label}: ${child.durationMs?.toFixed(1)}ms (${childPct}%)`);
|
|
1941
|
+
}
|
|
1942
|
+
if (childList.length > 5) {
|
|
1943
|
+
console.log(` \u2514\u2500 ... and ${childList.length - 5} more`);
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
console.log("\u2500".repeat(60));
|
|
1948
|
+
timings.delete(requestId);
|
|
1949
|
+
currentRequestId = null;
|
|
1950
|
+
}
|
|
1951
|
+
function isEnabled() {
|
|
1952
|
+
return enabled;
|
|
1953
|
+
}
|
|
1954
|
+
var enabled, timings, currentRequestId;
|
|
1955
|
+
var init_perf_timer = __esm({
|
|
1956
|
+
"src/core/utils/perf-timer.ts"() {
|
|
1957
|
+
"use strict";
|
|
1958
|
+
init_deno_env();
|
|
1959
|
+
enabled = typeof process !== "undefined" ? process.env?.VERYFRONT_PERF === "1" : typeof Deno !== "undefined" ? Deno.env.get("VERYFRONT_PERF") === "1" : false;
|
|
1960
|
+
timings = /* @__PURE__ */ new Map();
|
|
1961
|
+
currentRequestId = null;
|
|
1962
|
+
}
|
|
1963
|
+
});
|
|
1964
|
+
|
|
1965
|
+
// src/core/utils/cookie-utils.ts
|
|
1966
|
+
function parseCookies(cookieHeader) {
|
|
1967
|
+
const cookies = {};
|
|
1968
|
+
if (!cookieHeader)
|
|
1969
|
+
return cookies;
|
|
1970
|
+
cookieHeader.split(";").forEach((cookie) => {
|
|
1971
|
+
const trimmed = cookie.trim();
|
|
1972
|
+
if (!trimmed)
|
|
1973
|
+
return;
|
|
1974
|
+
const separatorIndex = trimmed.indexOf("=");
|
|
1975
|
+
if (separatorIndex <= 0)
|
|
1976
|
+
return;
|
|
1977
|
+
const name = trimmed.slice(0, separatorIndex).trim();
|
|
1978
|
+
const value = trimmed.slice(separatorIndex + 1);
|
|
1979
|
+
if (!name)
|
|
1980
|
+
return;
|
|
1981
|
+
cookies[name] = decodeURIComponent(value);
|
|
1982
|
+
});
|
|
1983
|
+
return cookies;
|
|
1984
|
+
}
|
|
1985
|
+
function parseCookiesFromHeaders(headers) {
|
|
1986
|
+
return parseCookies(headers.get("cookie") || "");
|
|
1987
|
+
}
|
|
1988
|
+
var init_cookie_utils = __esm({
|
|
1989
|
+
"src/core/utils/cookie-utils.ts"() {
|
|
1990
|
+
"use strict";
|
|
1991
|
+
init_deno_env();
|
|
1992
|
+
}
|
|
1993
|
+
});
|
|
1994
|
+
|
|
1995
|
+
// src/core/utils/base64url.ts
|
|
1996
|
+
function base64urlEncode(input) {
|
|
1997
|
+
const b64 = btoa(input);
|
|
1998
|
+
return b64.replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
|
|
1999
|
+
}
|
|
2000
|
+
function base64urlEncodeBytes(bytes) {
|
|
2001
|
+
const b64 = btoa(String.fromCharCode(...bytes));
|
|
2002
|
+
return b64.replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
|
|
2003
|
+
}
|
|
2004
|
+
var init_base64url = __esm({
|
|
2005
|
+
"src/core/utils/base64url.ts"() {
|
|
2006
|
+
"use strict";
|
|
2007
|
+
init_deno_env();
|
|
2008
|
+
}
|
|
2009
|
+
});
|
|
2010
|
+
|
|
1517
2011
|
// src/core/utils/index.ts
|
|
1518
2012
|
var utils_exports = {};
|
|
1519
2013
|
__export(utils_exports, {
|
|
@@ -1661,6 +2155,7 @@ __export(utils_exports, {
|
|
|
1661
2155
|
SECONDS_PER_MINUTE: () => SECONDS_PER_MINUTE,
|
|
1662
2156
|
SERVER_ACTION_DEFAULT_TTL_SEC: () => SERVER_ACTION_DEFAULT_TTL_SEC,
|
|
1663
2157
|
SERVER_FUNCTION_DEFAULT_TIMEOUT_MS: () => SERVER_FUNCTION_DEFAULT_TIMEOUT_MS,
|
|
2158
|
+
TAILWIND_VERSION: () => TAILWIND_VERSION,
|
|
1664
2159
|
TSX_LAYOUT_MAX_ENTRIES: () => TSX_LAYOUT_MAX_ENTRIES,
|
|
1665
2160
|
TSX_LAYOUT_TTL_MS: () => TSX_LAYOUT_TTL_MS,
|
|
1666
2161
|
UNOCSS_VERSION: () => UNOCSS_VERSION,
|
|
@@ -1671,13 +2166,22 @@ __export(utils_exports, {
|
|
|
1671
2166
|
Z_INDEX_ERROR_OVERLAY: () => Z_INDEX_ERROR_OVERLAY,
|
|
1672
2167
|
__loggerResetForTests: () => __loggerResetForTests,
|
|
1673
2168
|
agentLogger: () => agentLogger,
|
|
2169
|
+
base64urlEncode: () => base64urlEncode,
|
|
2170
|
+
base64urlEncodeBytes: () => base64urlEncodeBytes,
|
|
1674
2171
|
bundlerLogger: () => bundlerLogger,
|
|
1675
2172
|
cliLogger: () => cliLogger,
|
|
1676
2173
|
computeCodeHash: () => computeCodeHash,
|
|
1677
2174
|
computeContentHash: () => computeContentHash,
|
|
1678
2175
|
computeHash: () => computeHash,
|
|
2176
|
+
computeIntegrity: () => computeIntegrity,
|
|
2177
|
+
createEmptyLockfile: () => createEmptyLockfile,
|
|
2178
|
+
createLockfileManager: () => createLockfileManager,
|
|
2179
|
+
createRequestLogger: () => createRequestLogger,
|
|
2180
|
+
endRequest: () => endRequest,
|
|
1679
2181
|
estimateSize: () => estimateSize,
|
|
1680
2182
|
estimateSizeWithCircularHandling: () => estimateSizeWithCircularHandling,
|
|
2183
|
+
extractImports: () => extractImports,
|
|
2184
|
+
fetchWithLock: () => fetchWithLock,
|
|
1681
2185
|
formatBytes: () => formatBytes,
|
|
1682
2186
|
formatDuration: () => formatDuration,
|
|
1683
2187
|
formatNumber: () => formatNumber,
|
|
@@ -1708,6 +2212,7 @@ __export(utils_exports, {
|
|
|
1708
2212
|
isDebugEnabled: () => isDebugEnabled,
|
|
1709
2213
|
isDeepInspectEnabled: () => isDeepInspectEnabled,
|
|
1710
2214
|
isDevelopmentEnvironment: () => isDevelopmentEnvironment,
|
|
2215
|
+
isEnabled: () => isEnabled,
|
|
1711
2216
|
isInternalEndpoint: () => isInternalEndpoint,
|
|
1712
2217
|
isProductionEnvironment: () => isProductionEnvironment,
|
|
1713
2218
|
isRSCEnabled: () => isRSCEnabled,
|
|
@@ -1724,13 +2229,21 @@ __export(utils_exports, {
|
|
|
1724
2229
|
normalizeChunkPath: () => normalizeChunkPath,
|
|
1725
2230
|
normalizePath: () => normalizePath,
|
|
1726
2231
|
numericHash: () => simpleHash,
|
|
2232
|
+
parseCookies: () => parseCookies,
|
|
2233
|
+
parseCookiesFromHeaders: () => parseCookiesFromHeaders,
|
|
2234
|
+
proxyLogger: () => proxyLogger,
|
|
1727
2235
|
rendererLogger: () => rendererLogger,
|
|
2236
|
+
resolveImportUrl: () => resolveImportUrl,
|
|
1728
2237
|
serverLogger: () => serverLogger,
|
|
1729
2238
|
setBundleManifestStore: () => setBundleManifestStore,
|
|
1730
2239
|
shortHash: () => shortHash,
|
|
1731
2240
|
simpleHash: () => simpleHash,
|
|
2241
|
+
startRequest: () => startRequest,
|
|
2242
|
+
startTimer: () => startTimer,
|
|
2243
|
+
timeAsync: () => timeAsync,
|
|
1732
2244
|
toBase64Url: () => toBase64Url,
|
|
1733
2245
|
truncateString: () => truncateString,
|
|
2246
|
+
verifyIntegrity: () => verifyIntegrity,
|
|
1734
2247
|
warmupBundleManifest: () => warmupBundleManifest
|
|
1735
2248
|
});
|
|
1736
2249
|
var init_utils = __esm({
|
|
@@ -1749,6 +2262,10 @@ var init_utils = __esm({
|
|
|
1749
2262
|
init_bundle_manifest_init();
|
|
1750
2263
|
init_feature_flags();
|
|
1751
2264
|
init_platform();
|
|
2265
|
+
init_import_lockfile();
|
|
2266
|
+
init_perf_timer();
|
|
2267
|
+
init_cookie_utils();
|
|
2268
|
+
init_base64url();
|
|
1752
2269
|
}
|
|
1753
2270
|
});
|
|
1754
2271
|
|
|
@@ -1775,6 +2292,56 @@ var init_veryfront_error = __esm({
|
|
|
1775
2292
|
|
|
1776
2293
|
// src/core/config/schema.ts
|
|
1777
2294
|
import { z } from "zod";
|
|
2295
|
+
function validateVeryfrontConfig(input) {
|
|
2296
|
+
const parsed = veryfrontConfigSchema.safeParse(input);
|
|
2297
|
+
if (!parsed.success) {
|
|
2298
|
+
const first = parsed.error.issues[0];
|
|
2299
|
+
const path = first?.path?.length ? first.path.join(".") : "<root>";
|
|
2300
|
+
const expected = first?.message || String(first);
|
|
2301
|
+
let hint = "";
|
|
2302
|
+
if (String(path).includes("security.cors")) {
|
|
2303
|
+
hint = " Expected boolean or { origin?: string }.";
|
|
2304
|
+
}
|
|
2305
|
+
const context = {
|
|
2306
|
+
field: path,
|
|
2307
|
+
expected: expected + hint,
|
|
2308
|
+
value: input
|
|
2309
|
+
};
|
|
2310
|
+
throw toError(
|
|
2311
|
+
createError({
|
|
2312
|
+
type: "config",
|
|
2313
|
+
message: `Invalid veryfront.config at ${path}: ${expected}.${hint}`,
|
|
2314
|
+
context
|
|
2315
|
+
})
|
|
2316
|
+
);
|
|
2317
|
+
}
|
|
2318
|
+
return parsed.data;
|
|
2319
|
+
}
|
|
2320
|
+
function findUnknownTopLevelKeys(input) {
|
|
2321
|
+
const known = /* @__PURE__ */ new Set([
|
|
2322
|
+
"title",
|
|
2323
|
+
"description",
|
|
2324
|
+
"experimental",
|
|
2325
|
+
"router",
|
|
2326
|
+
"defaultLayout",
|
|
2327
|
+
"layout",
|
|
2328
|
+
"provider",
|
|
2329
|
+
"app",
|
|
2330
|
+
"theme",
|
|
2331
|
+
"build",
|
|
2332
|
+
"cache",
|
|
2333
|
+
"dev",
|
|
2334
|
+
"resolve",
|
|
2335
|
+
"security",
|
|
2336
|
+
"middleware",
|
|
2337
|
+
"theming",
|
|
2338
|
+
"assetPipeline",
|
|
2339
|
+
"observability",
|
|
2340
|
+
"fs",
|
|
2341
|
+
"client"
|
|
2342
|
+
]);
|
|
2343
|
+
return Object.keys(input).filter((k) => !known.has(k));
|
|
2344
|
+
}
|
|
1778
2345
|
var corsSchema, veryfrontConfigSchema;
|
|
1779
2346
|
var init_schema = __esm({
|
|
1780
2347
|
"src/core/config/schema.ts"() {
|
|
@@ -1791,6 +2358,9 @@ var init_schema = __esm({
|
|
|
1791
2358
|
}).partial().optional(),
|
|
1792
2359
|
router: z.enum(["app", "pages"]).optional(),
|
|
1793
2360
|
defaultLayout: z.string().optional(),
|
|
2361
|
+
layout: z.string().optional(),
|
|
2362
|
+
provider: z.string().optional(),
|
|
2363
|
+
app: z.string().optional(),
|
|
1794
2364
|
theme: z.object({ colors: z.record(z.string()).optional() }).partial().optional(),
|
|
1795
2365
|
build: z.object({
|
|
1796
2366
|
outDir: z.string().optional(),
|
|
@@ -1886,6 +2456,8 @@ var init_schema = __esm({
|
|
|
1886
2456
|
apiBaseUrl: z.string().url(),
|
|
1887
2457
|
apiToken: z.string(),
|
|
1888
2458
|
projectSlug: z.string(),
|
|
2459
|
+
proxyMode: z.boolean().optional(),
|
|
2460
|
+
productionMode: z.boolean().optional(),
|
|
1889
2461
|
cache: z.object({
|
|
1890
2462
|
enabled: z.boolean().optional(),
|
|
1891
2463
|
ttl: z.number().int().positive().optional(),
|
|
@@ -1918,71 +2490,437 @@ var init_schema = __esm({
|
|
|
1918
2490
|
}
|
|
1919
2491
|
});
|
|
1920
2492
|
|
|
1921
|
-
// src/
|
|
1922
|
-
|
|
1923
|
-
|
|
1924
|
-
|
|
2493
|
+
// src/platform/compat/fs.ts
|
|
2494
|
+
function createFileSystem() {
|
|
2495
|
+
if (isDeno) {
|
|
2496
|
+
return new DenoFileSystem();
|
|
2497
|
+
} else {
|
|
2498
|
+
return new NodeFileSystem();
|
|
2499
|
+
}
|
|
1925
2500
|
}
|
|
1926
|
-
var
|
|
1927
|
-
var
|
|
1928
|
-
"src/
|
|
2501
|
+
var NodeFileSystem, DenoFileSystem;
|
|
2502
|
+
var init_fs = __esm({
|
|
2503
|
+
"src/platform/compat/fs.ts"() {
|
|
1929
2504
|
"use strict";
|
|
1930
2505
|
init_deno_env();
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
1936
|
-
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
build: {
|
|
1950
|
-
outDir: "dist",
|
|
1951
|
-
trailingSlash: false,
|
|
1952
|
-
esbuild: {
|
|
1953
|
-
wasmURL: "https://deno.land/x/esbuild@v0.20.1/esbuild.wasm",
|
|
1954
|
-
worker: false
|
|
1955
|
-
}
|
|
1956
|
-
},
|
|
1957
|
-
cache: {
|
|
1958
|
-
dir: DEFAULT_CACHE_DIR,
|
|
1959
|
-
render: {
|
|
1960
|
-
type: "memory",
|
|
1961
|
-
ttl: void 0,
|
|
1962
|
-
maxEntries: 500,
|
|
1963
|
-
kvPath: void 0,
|
|
1964
|
-
redisUrl: void 0,
|
|
1965
|
-
redisKeyPrefix: void 0
|
|
2506
|
+
init_veryfront_error();
|
|
2507
|
+
init_runtime();
|
|
2508
|
+
NodeFileSystem = class {
|
|
2509
|
+
constructor() {
|
|
2510
|
+
this.fs = null;
|
|
2511
|
+
this.os = null;
|
|
2512
|
+
this.path = null;
|
|
2513
|
+
this.initialized = false;
|
|
2514
|
+
}
|
|
2515
|
+
async ensureInitialized() {
|
|
2516
|
+
if (this.initialized)
|
|
2517
|
+
return;
|
|
2518
|
+
if (!isNode) {
|
|
2519
|
+
throw toError(createError({
|
|
2520
|
+
type: "not_supported",
|
|
2521
|
+
message: "Node.js fs modules not available",
|
|
2522
|
+
feature: "Node.js"
|
|
2523
|
+
}));
|
|
1966
2524
|
}
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
2525
|
+
const [fsModule, osModule, pathModule] = await Promise.all([
|
|
2526
|
+
import("node:fs/promises"),
|
|
2527
|
+
import("node:os"),
|
|
2528
|
+
import("node:path")
|
|
2529
|
+
]);
|
|
2530
|
+
this.fs = fsModule;
|
|
2531
|
+
this.os = osModule;
|
|
2532
|
+
this.path = pathModule;
|
|
2533
|
+
this.initialized = true;
|
|
2534
|
+
}
|
|
2535
|
+
async readTextFile(path) {
|
|
2536
|
+
await this.ensureInitialized();
|
|
2537
|
+
return await this.fs.readFile(path, { encoding: "utf8" });
|
|
2538
|
+
}
|
|
2539
|
+
async readFile(path) {
|
|
2540
|
+
await this.ensureInitialized();
|
|
2541
|
+
return await this.fs.readFile(path);
|
|
2542
|
+
}
|
|
2543
|
+
async writeTextFile(path, data) {
|
|
2544
|
+
await this.ensureInitialized();
|
|
2545
|
+
await this.fs.writeFile(path, data, { encoding: "utf8" });
|
|
2546
|
+
}
|
|
2547
|
+
async writeFile(path, data) {
|
|
2548
|
+
await this.ensureInitialized();
|
|
2549
|
+
await this.fs.writeFile(path, data);
|
|
2550
|
+
}
|
|
2551
|
+
async exists(path) {
|
|
2552
|
+
await this.ensureInitialized();
|
|
2553
|
+
try {
|
|
2554
|
+
await this.fs.access(path);
|
|
2555
|
+
return true;
|
|
2556
|
+
} catch (error) {
|
|
2557
|
+
if (error.code === "ENOENT") {
|
|
2558
|
+
return false;
|
|
2559
|
+
}
|
|
2560
|
+
throw error;
|
|
1981
2561
|
}
|
|
1982
2562
|
}
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
2563
|
+
async stat(path) {
|
|
2564
|
+
await this.ensureInitialized();
|
|
2565
|
+
const stat = await this.fs.stat(path);
|
|
2566
|
+
return {
|
|
2567
|
+
isFile: stat.isFile(),
|
|
2568
|
+
isDirectory: stat.isDirectory(),
|
|
2569
|
+
isSymlink: stat.isSymbolicLink(),
|
|
2570
|
+
size: stat.size,
|
|
2571
|
+
mtime: stat.mtime
|
|
2572
|
+
};
|
|
2573
|
+
}
|
|
2574
|
+
async mkdir(path, options) {
|
|
2575
|
+
await this.ensureInitialized();
|
|
2576
|
+
await this.fs.mkdir(path, { recursive: options?.recursive ?? false });
|
|
2577
|
+
}
|
|
2578
|
+
async *readDir(path) {
|
|
2579
|
+
await this.ensureInitialized();
|
|
2580
|
+
const entries = await this.fs.readdir(path, { withFileTypes: true });
|
|
2581
|
+
for (const entry of entries) {
|
|
2582
|
+
yield {
|
|
2583
|
+
name: entry.name,
|
|
2584
|
+
isFile: entry.isFile(),
|
|
2585
|
+
isDirectory: entry.isDirectory()
|
|
2586
|
+
};
|
|
2587
|
+
}
|
|
2588
|
+
}
|
|
2589
|
+
async remove(path, options) {
|
|
2590
|
+
await this.ensureInitialized();
|
|
2591
|
+
await this.fs.rm(path, {
|
|
2592
|
+
recursive: options?.recursive ?? false,
|
|
2593
|
+
force: options?.recursive ?? false
|
|
2594
|
+
});
|
|
2595
|
+
}
|
|
2596
|
+
async makeTempDir(options) {
|
|
2597
|
+
await this.ensureInitialized();
|
|
2598
|
+
const tempDir = this.path.join(
|
|
2599
|
+
this.os.tmpdir(),
|
|
2600
|
+
`${options?.prefix ?? "tmp-"}${Math.random().toString(36).substring(2, 8)}`
|
|
2601
|
+
);
|
|
2602
|
+
await this.fs.mkdir(tempDir, { recursive: true });
|
|
2603
|
+
return tempDir;
|
|
2604
|
+
}
|
|
2605
|
+
};
|
|
2606
|
+
DenoFileSystem = class {
|
|
2607
|
+
async readTextFile(path) {
|
|
2608
|
+
return await Deno.readTextFile(path);
|
|
2609
|
+
}
|
|
2610
|
+
async readFile(path) {
|
|
2611
|
+
return await Deno.readFile(path);
|
|
2612
|
+
}
|
|
2613
|
+
async writeTextFile(path, data) {
|
|
2614
|
+
await Deno.writeTextFile(path, data);
|
|
2615
|
+
}
|
|
2616
|
+
async writeFile(path, data) {
|
|
2617
|
+
await Deno.writeFile(path, data);
|
|
2618
|
+
}
|
|
2619
|
+
async exists(path) {
|
|
2620
|
+
try {
|
|
2621
|
+
await Deno.stat(path);
|
|
2622
|
+
return true;
|
|
2623
|
+
} catch (error) {
|
|
2624
|
+
if (error instanceof Deno.errors.NotFound) {
|
|
2625
|
+
return false;
|
|
2626
|
+
}
|
|
2627
|
+
throw error;
|
|
2628
|
+
}
|
|
2629
|
+
}
|
|
2630
|
+
async stat(path) {
|
|
2631
|
+
const stat = await Deno.stat(path);
|
|
2632
|
+
return {
|
|
2633
|
+
isFile: stat.isFile,
|
|
2634
|
+
isDirectory: stat.isDirectory,
|
|
2635
|
+
isSymlink: stat.isSymlink,
|
|
2636
|
+
size: stat.size,
|
|
2637
|
+
mtime: stat.mtime
|
|
2638
|
+
};
|
|
2639
|
+
}
|
|
2640
|
+
async mkdir(path, options) {
|
|
2641
|
+
await Deno.mkdir(path, { recursive: options?.recursive ?? false });
|
|
2642
|
+
}
|
|
2643
|
+
async *readDir(path) {
|
|
2644
|
+
for await (const entry of Deno.readDir(path)) {
|
|
2645
|
+
yield {
|
|
2646
|
+
name: entry.name,
|
|
2647
|
+
isFile: entry.isFile,
|
|
2648
|
+
isDirectory: entry.isDirectory
|
|
2649
|
+
};
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
async remove(path, options) {
|
|
2653
|
+
await Deno.remove(path, { recursive: options?.recursive ?? false });
|
|
2654
|
+
}
|
|
2655
|
+
async makeTempDir(options) {
|
|
2656
|
+
return await Deno.makeTempDir({ prefix: options?.prefix });
|
|
2657
|
+
}
|
|
2658
|
+
};
|
|
2659
|
+
}
|
|
2660
|
+
});
|
|
2661
|
+
|
|
2662
|
+
// src/core/config/loader.ts
|
|
2663
|
+
import { dirname, join } from "node:path";
|
|
2664
|
+
function getDefaultImportMapForConfig() {
|
|
2665
|
+
return { imports: getReactImportMap(REACT_DEFAULT_VERSION) };
|
|
2666
|
+
}
|
|
2667
|
+
function validateCorsConfig(userConfig) {
|
|
2668
|
+
if (!userConfig || typeof userConfig !== "object") {
|
|
2669
|
+
return;
|
|
2670
|
+
}
|
|
2671
|
+
const config = userConfig;
|
|
2672
|
+
const security = config.security;
|
|
2673
|
+
const cors = security?.cors;
|
|
2674
|
+
if (!cors || typeof cors !== "object" || Array.isArray(cors)) {
|
|
2675
|
+
return;
|
|
2676
|
+
}
|
|
2677
|
+
const corsObj = cors;
|
|
2678
|
+
const origin = corsObj.origin;
|
|
2679
|
+
if (origin !== void 0 && typeof origin !== "string") {
|
|
2680
|
+
throw new ConfigValidationError(
|
|
2681
|
+
"security.cors.origin must be a string. Expected boolean or { origin?: string }"
|
|
2682
|
+
);
|
|
2683
|
+
}
|
|
2684
|
+
}
|
|
2685
|
+
function validateConfigShape(userConfig) {
|
|
2686
|
+
validateVeryfrontConfig(userConfig);
|
|
2687
|
+
const unknown = typeof userConfig === "object" && userConfig ? findUnknownTopLevelKeys(userConfig) : [];
|
|
2688
|
+
if (unknown.length > 0) {
|
|
2689
|
+
serverLogger.warn(`Unknown config keys: ${unknown.join(", ")}. These will be ignored.`);
|
|
2690
|
+
}
|
|
2691
|
+
}
|
|
2692
|
+
function mergeConfigs(userConfig) {
|
|
2693
|
+
const merged = {
|
|
2694
|
+
...DEFAULT_CONFIG,
|
|
2695
|
+
...userConfig,
|
|
2696
|
+
dev: {
|
|
2697
|
+
...DEFAULT_CONFIG.dev,
|
|
2698
|
+
...userConfig.dev
|
|
2699
|
+
},
|
|
2700
|
+
theme: {
|
|
2701
|
+
...DEFAULT_CONFIG.theme,
|
|
2702
|
+
...userConfig.theme
|
|
2703
|
+
},
|
|
2704
|
+
build: {
|
|
2705
|
+
...DEFAULT_CONFIG.build,
|
|
2706
|
+
...userConfig.build
|
|
2707
|
+
},
|
|
2708
|
+
cache: {
|
|
2709
|
+
...DEFAULT_CONFIG.cache,
|
|
2710
|
+
...userConfig.cache
|
|
2711
|
+
},
|
|
2712
|
+
resolve: {
|
|
2713
|
+
...DEFAULT_CONFIG.resolve,
|
|
2714
|
+
...userConfig.resolve
|
|
2715
|
+
},
|
|
2716
|
+
client: {
|
|
2717
|
+
...DEFAULT_CONFIG.client,
|
|
2718
|
+
...userConfig.client,
|
|
2719
|
+
cdn: {
|
|
2720
|
+
...DEFAULT_CONFIG.client?.cdn,
|
|
2721
|
+
...userConfig.client?.cdn
|
|
2722
|
+
}
|
|
2723
|
+
}
|
|
2724
|
+
};
|
|
2725
|
+
if (merged.resolve) {
|
|
2726
|
+
const defaultMap = DEFAULT_CONFIG.resolve?.importMap;
|
|
2727
|
+
const userMap = userConfig.resolve?.importMap;
|
|
2728
|
+
if (defaultMap || userMap) {
|
|
2729
|
+
merged.resolve.importMap = {
|
|
2730
|
+
imports: {
|
|
2731
|
+
...defaultMap?.imports ?? {},
|
|
2732
|
+
...userMap?.imports ?? {}
|
|
2733
|
+
},
|
|
2734
|
+
scopes: {
|
|
2735
|
+
...defaultMap?.scopes ?? {},
|
|
2736
|
+
...userMap?.scopes ?? {}
|
|
2737
|
+
}
|
|
2738
|
+
};
|
|
2739
|
+
}
|
|
2740
|
+
}
|
|
2741
|
+
return merged;
|
|
2742
|
+
}
|
|
2743
|
+
function isVirtualFilesystem(adapter) {
|
|
2744
|
+
const wrappedAdapter = adapter?.fs?.fsAdapter;
|
|
2745
|
+
const adapterName = wrappedAdapter?.constructor?.name;
|
|
2746
|
+
return adapterName === "VeryfrontFSAdapter";
|
|
2747
|
+
}
|
|
2748
|
+
async function loadConfigFromVirtualFS(configPath, projectDir, adapter) {
|
|
2749
|
+
const fs = createFileSystem();
|
|
2750
|
+
const content = await adapter.fs.readFile(configPath);
|
|
2751
|
+
const source = typeof content === "string" ? content : new TextDecoder().decode(content);
|
|
2752
|
+
serverLogger.debug(`[CONFIG] Loading config from virtual FS: ${configPath}`);
|
|
2753
|
+
const isTsx = configPath.endsWith(".tsx");
|
|
2754
|
+
const loader = isTsx ? "tsx" : configPath.endsWith(".ts") ? "ts" : "js";
|
|
2755
|
+
const { build } = await import("esbuild");
|
|
2756
|
+
const result = await build({
|
|
2757
|
+
bundle: false,
|
|
2758
|
+
// Config files shouldn't need bundling
|
|
2759
|
+
write: false,
|
|
2760
|
+
format: "esm",
|
|
2761
|
+
platform: "neutral",
|
|
2762
|
+
target: "es2022",
|
|
2763
|
+
stdin: {
|
|
2764
|
+
contents: source,
|
|
2765
|
+
loader,
|
|
2766
|
+
resolveDir: dirname(configPath),
|
|
2767
|
+
sourcefile: configPath
|
|
2768
|
+
}
|
|
2769
|
+
});
|
|
2770
|
+
if (result.errors && result.errors.length > 0) {
|
|
2771
|
+
const first = result.errors[0]?.text || "unknown error";
|
|
2772
|
+
throw new ConfigValidationError(`Failed to transpile config: ${first}`);
|
|
2773
|
+
}
|
|
2774
|
+
const js = result.outputFiles?.[0]?.text ?? "export default {}";
|
|
2775
|
+
const tempDir = await fs.makeTempDir({ prefix: "vf-config-" });
|
|
2776
|
+
const tempFile = join(tempDir, "config.mjs");
|
|
2777
|
+
try {
|
|
2778
|
+
await fs.writeTextFile(tempFile, js);
|
|
2779
|
+
const configModule = await import(`file://${tempFile}?v=${Date.now()}`);
|
|
2780
|
+
const userConfig = configModule.default || configModule;
|
|
2781
|
+
if (userConfig === null || typeof userConfig !== "object" || Array.isArray(userConfig)) {
|
|
2782
|
+
throw new ConfigValidationError(
|
|
2783
|
+
`Expected object, received ${userConfig === null ? "null" : typeof userConfig}`
|
|
2784
|
+
);
|
|
2785
|
+
}
|
|
2786
|
+
validateCorsConfig(userConfig);
|
|
2787
|
+
validateConfigShape(userConfig);
|
|
2788
|
+
const merged = mergeConfigs(userConfig);
|
|
2789
|
+
configCacheByProject.set(projectDir, { revision: cacheRevision, config: merged });
|
|
2790
|
+
return merged;
|
|
2791
|
+
} finally {
|
|
2792
|
+
await fs.remove(tempDir, { recursive: true });
|
|
2793
|
+
}
|
|
2794
|
+
}
|
|
2795
|
+
async function loadAndMergeConfig(configPath, projectDir, adapter) {
|
|
2796
|
+
if (isVirtualFilesystem(adapter)) {
|
|
2797
|
+
return loadConfigFromVirtualFS(configPath, projectDir, adapter);
|
|
2798
|
+
}
|
|
2799
|
+
try {
|
|
2800
|
+
const configUrl = `file://${configPath}?t=${Date.now()}-${crypto.randomUUID()}`;
|
|
2801
|
+
const configModule = await import(configUrl);
|
|
2802
|
+
const userConfig = configModule.default || configModule;
|
|
2803
|
+
if (userConfig === null || typeof userConfig !== "object" || Array.isArray(userConfig)) {
|
|
2804
|
+
throw new ConfigValidationError(
|
|
2805
|
+
`Expected object, received ${userConfig === null ? "null" : typeof userConfig}`
|
|
2806
|
+
);
|
|
2807
|
+
}
|
|
2808
|
+
validateCorsConfig(userConfig);
|
|
2809
|
+
validateConfigShape(userConfig);
|
|
2810
|
+
const merged = mergeConfigs(userConfig);
|
|
2811
|
+
configCacheByProject.set(projectDir, { revision: cacheRevision, config: merged });
|
|
2812
|
+
return merged;
|
|
2813
|
+
} catch (error) {
|
|
2814
|
+
if (error instanceof ConfigValidationError) {
|
|
2815
|
+
throw error;
|
|
2816
|
+
}
|
|
2817
|
+
if (error instanceof Error && error.message.startsWith("Invalid veryfront.config")) {
|
|
2818
|
+
throw error;
|
|
2819
|
+
}
|
|
2820
|
+
throw error;
|
|
2821
|
+
}
|
|
2822
|
+
}
|
|
2823
|
+
async function getConfig(projectDir, adapter) {
|
|
2824
|
+
const cached = configCacheByProject.get(projectDir);
|
|
2825
|
+
if (cached && cached.revision === cacheRevision)
|
|
2826
|
+
return cached.config;
|
|
2827
|
+
const configFiles = ["veryfront.config.js", "veryfront.config.ts", "veryfront.config.mjs"];
|
|
2828
|
+
for (const configFile of configFiles) {
|
|
2829
|
+
const configPath = join(projectDir, configFile);
|
|
2830
|
+
const exists = await adapter.fs.exists(configPath);
|
|
2831
|
+
if (!exists)
|
|
2832
|
+
continue;
|
|
2833
|
+
try {
|
|
2834
|
+
const merged = await loadAndMergeConfig(configPath, projectDir, adapter);
|
|
2835
|
+
if (merged)
|
|
2836
|
+
return merged;
|
|
2837
|
+
} catch (error) {
|
|
2838
|
+
if (error instanceof ConfigValidationError) {
|
|
2839
|
+
throw error;
|
|
2840
|
+
}
|
|
2841
|
+
if (error instanceof Error && error.message.startsWith("Invalid veryfront.config")) {
|
|
2842
|
+
throw error;
|
|
2843
|
+
}
|
|
2844
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
2845
|
+
serverLogger.debug(`[CONFIG] Failed to load ${configFile}, trying next config file:`, {
|
|
2846
|
+
error: errorMessage
|
|
2847
|
+
});
|
|
2848
|
+
continue;
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
const defaultConfig2 = DEFAULT_CONFIG;
|
|
2852
|
+
configCacheByProject.set(projectDir, { revision: cacheRevision, config: defaultConfig2 });
|
|
2853
|
+
return defaultConfig2;
|
|
2854
|
+
}
|
|
2855
|
+
var DEFAULT_CONFIG, configCacheByProject, cacheRevision, ConfigValidationError;
|
|
2856
|
+
var init_loader = __esm({
|
|
2857
|
+
"src/core/config/loader.ts"() {
|
|
2858
|
+
"use strict";
|
|
2859
|
+
init_deno_env();
|
|
2860
|
+
init_schema();
|
|
2861
|
+
init_logger();
|
|
2862
|
+
init_cdn();
|
|
2863
|
+
init_server();
|
|
2864
|
+
init_defaults();
|
|
2865
|
+
init_fs();
|
|
2866
|
+
DEFAULT_CONFIG = {
|
|
2867
|
+
title: "Veryfront App",
|
|
2868
|
+
description: "Built with Veryfront",
|
|
2869
|
+
experimental: {
|
|
2870
|
+
esmLayouts: true
|
|
2871
|
+
},
|
|
2872
|
+
router: void 0,
|
|
2873
|
+
defaultLayout: void 0,
|
|
2874
|
+
theme: {
|
|
2875
|
+
colors: {
|
|
2876
|
+
primary: "#3B82F6"
|
|
2877
|
+
}
|
|
2878
|
+
},
|
|
2879
|
+
build: {
|
|
2880
|
+
outDir: "dist",
|
|
2881
|
+
trailingSlash: false,
|
|
2882
|
+
esbuild: {
|
|
2883
|
+
wasmURL: "https://deno.land/x/esbuild@v0.20.1/esbuild.wasm",
|
|
2884
|
+
worker: false
|
|
2885
|
+
}
|
|
2886
|
+
},
|
|
2887
|
+
cache: {
|
|
2888
|
+
dir: DEFAULT_CACHE_DIR,
|
|
2889
|
+
render: {
|
|
2890
|
+
type: "memory",
|
|
2891
|
+
ttl: void 0,
|
|
2892
|
+
maxEntries: 500,
|
|
2893
|
+
kvPath: void 0,
|
|
2894
|
+
redisUrl: void 0,
|
|
2895
|
+
redisKeyPrefix: void 0
|
|
2896
|
+
}
|
|
2897
|
+
},
|
|
2898
|
+
dev: {
|
|
2899
|
+
port: DEFAULT_PORT,
|
|
2900
|
+
host: "localhost",
|
|
2901
|
+
open: false
|
|
2902
|
+
},
|
|
2903
|
+
resolve: {
|
|
2904
|
+
importMap: getDefaultImportMapForConfig()
|
|
2905
|
+
},
|
|
2906
|
+
client: {
|
|
2907
|
+
moduleResolution: "cdn",
|
|
2908
|
+
cdn: {
|
|
2909
|
+
provider: "esm.sh",
|
|
2910
|
+
versions: "auto"
|
|
2911
|
+
}
|
|
2912
|
+
}
|
|
2913
|
+
};
|
|
2914
|
+
configCacheByProject = /* @__PURE__ */ new Map();
|
|
2915
|
+
cacheRevision = 0;
|
|
2916
|
+
ConfigValidationError = class extends Error {
|
|
2917
|
+
constructor(message) {
|
|
2918
|
+
super(message);
|
|
2919
|
+
this.name = "ConfigValidationError";
|
|
2920
|
+
}
|
|
2921
|
+
};
|
|
2922
|
+
}
|
|
2923
|
+
});
|
|
1986
2924
|
|
|
1987
2925
|
// src/core/config/define-config.ts
|
|
1988
2926
|
var init_define_config = __esm({
|
|
@@ -2274,7 +3212,7 @@ var init_deno2 = __esm({
|
|
|
2274
3212
|
});
|
|
2275
3213
|
|
|
2276
3214
|
// src/platform/adapters/shared-watcher.ts
|
|
2277
|
-
import { join as
|
|
3215
|
+
import { join as join5 } from "node:path";
|
|
2278
3216
|
async function setupNodeFsWatcher(path, options) {
|
|
2279
3217
|
try {
|
|
2280
3218
|
const fs = await import("node:fs");
|
|
@@ -2286,7 +3224,7 @@ async function setupNodeFsWatcher(path, options) {
|
|
|
2286
3224
|
if (options.closed() || options.signal?.aborted)
|
|
2287
3225
|
return;
|
|
2288
3226
|
const kind = eventType === "change" ? "modify" : "any";
|
|
2289
|
-
const fullPath = filename ?
|
|
3227
|
+
const fullPath = filename ? join5(path, filename) : path;
|
|
2290
3228
|
enqueueWatchEvent(
|
|
2291
3229
|
{ kind, paths: [fullPath] },
|
|
2292
3230
|
options.eventQueue,
|
|
@@ -2416,9 +3354,9 @@ var init_filesystem_adapter = __esm({
|
|
|
2416
3354
|
}
|
|
2417
3355
|
async makeTempDir(prefix) {
|
|
2418
3356
|
const { mkdtemp } = await import("node:fs/promises");
|
|
2419
|
-
const { join:
|
|
3357
|
+
const { join: join7 } = await import("node:path");
|
|
2420
3358
|
const { tmpdir } = await import("node:os");
|
|
2421
|
-
return await mkdtemp(
|
|
3359
|
+
return await mkdtemp(join7(tmpdir(), prefix));
|
|
2422
3360
|
}
|
|
2423
3361
|
watch(paths, options) {
|
|
2424
3362
|
const pathArray = Array.isArray(paths) ? paths : [paths];
|
|
@@ -2499,9 +3437,9 @@ var init_environment_adapter = __esm({
|
|
|
2499
3437
|
}
|
|
2500
3438
|
});
|
|
2501
3439
|
|
|
2502
|
-
//
|
|
3440
|
+
// ../../node_modules/ws/lib/constants.js
|
|
2503
3441
|
var require_constants = __commonJS({
|
|
2504
|
-
"
|
|
3442
|
+
"../../node_modules/ws/lib/constants.js"(exports, module) {
|
|
2505
3443
|
"use strict";
|
|
2506
3444
|
init_deno_env();
|
|
2507
3445
|
var BINARY_TYPES = ["nodebuffer", "arraybuffer", "fragments"];
|
|
@@ -2523,9 +3461,9 @@ var require_constants = __commonJS({
|
|
|
2523
3461
|
}
|
|
2524
3462
|
});
|
|
2525
3463
|
|
|
2526
|
-
//
|
|
3464
|
+
// ../../node_modules/ws/lib/buffer-util.js
|
|
2527
3465
|
var require_buffer_util = __commonJS({
|
|
2528
|
-
"
|
|
3466
|
+
"../../node_modules/ws/lib/buffer-util.js"(exports, module) {
|
|
2529
3467
|
"use strict";
|
|
2530
3468
|
init_deno_env();
|
|
2531
3469
|
var { EMPTY_BUFFER } = require_constants();
|
|
@@ -2606,9 +3544,9 @@ var require_buffer_util = __commonJS({
|
|
|
2606
3544
|
}
|
|
2607
3545
|
});
|
|
2608
3546
|
|
|
2609
|
-
//
|
|
3547
|
+
// ../../node_modules/ws/lib/limiter.js
|
|
2610
3548
|
var require_limiter = __commonJS({
|
|
2611
|
-
"
|
|
3549
|
+
"../../node_modules/ws/lib/limiter.js"(exports, module) {
|
|
2612
3550
|
"use strict";
|
|
2613
3551
|
init_deno_env();
|
|
2614
3552
|
var kDone = Symbol("kDone");
|
|
@@ -2658,9 +3596,9 @@ var require_limiter = __commonJS({
|
|
|
2658
3596
|
}
|
|
2659
3597
|
});
|
|
2660
3598
|
|
|
2661
|
-
//
|
|
3599
|
+
// ../../node_modules/ws/lib/permessage-deflate.js
|
|
2662
3600
|
var require_permessage_deflate = __commonJS({
|
|
2663
|
-
"
|
|
3601
|
+
"../../node_modules/ws/lib/permessage-deflate.js"(exports, module) {
|
|
2664
3602
|
"use strict";
|
|
2665
3603
|
init_deno_env();
|
|
2666
3604
|
var zlib = __require2("zlib");
|
|
@@ -3043,9 +3981,9 @@ var require_permessage_deflate = __commonJS({
|
|
|
3043
3981
|
}
|
|
3044
3982
|
});
|
|
3045
3983
|
|
|
3046
|
-
//
|
|
3984
|
+
// ../../node_modules/ws/lib/validation.js
|
|
3047
3985
|
var require_validation = __commonJS({
|
|
3048
|
-
"
|
|
3986
|
+
"../../node_modules/ws/lib/validation.js"(exports, module) {
|
|
3049
3987
|
"use strict";
|
|
3050
3988
|
init_deno_env();
|
|
3051
3989
|
var { isUtf8 } = __require2("buffer");
|
|
@@ -3245,9 +4183,9 @@ var require_validation = __commonJS({
|
|
|
3245
4183
|
}
|
|
3246
4184
|
});
|
|
3247
4185
|
|
|
3248
|
-
//
|
|
4186
|
+
// ../../node_modules/ws/lib/receiver.js
|
|
3249
4187
|
var require_receiver = __commonJS({
|
|
3250
|
-
"
|
|
4188
|
+
"../../node_modules/ws/lib/receiver.js"(exports, module) {
|
|
3251
4189
|
"use strict";
|
|
3252
4190
|
init_deno_env();
|
|
3253
4191
|
var { Writable } = __require2("stream");
|
|
@@ -3849,9 +4787,9 @@ var require_receiver = __commonJS({
|
|
|
3849
4787
|
}
|
|
3850
4788
|
});
|
|
3851
4789
|
|
|
3852
|
-
//
|
|
4790
|
+
// ../../node_modules/ws/lib/sender.js
|
|
3853
4791
|
var require_sender = __commonJS({
|
|
3854
|
-
"
|
|
4792
|
+
"../../node_modules/ws/lib/sender.js"(exports, module) {
|
|
3855
4793
|
"use strict";
|
|
3856
4794
|
init_deno_env();
|
|
3857
4795
|
var { Duplex } = __require2("stream");
|
|
@@ -4344,9 +5282,9 @@ var require_sender = __commonJS({
|
|
|
4344
5282
|
}
|
|
4345
5283
|
});
|
|
4346
5284
|
|
|
4347
|
-
//
|
|
5285
|
+
// ../../node_modules/ws/lib/event-target.js
|
|
4348
5286
|
var require_event_target = __commonJS({
|
|
4349
|
-
"
|
|
5287
|
+
"../../node_modules/ws/lib/event-target.js"(exports, module) {
|
|
4350
5288
|
"use strict";
|
|
4351
5289
|
init_deno_env();
|
|
4352
5290
|
var { kForOnEventAttribute, kListener } = require_constants();
|
|
@@ -4574,9 +5512,9 @@ var require_event_target = __commonJS({
|
|
|
4574
5512
|
}
|
|
4575
5513
|
});
|
|
4576
5514
|
|
|
4577
|
-
//
|
|
5515
|
+
// ../../node_modules/ws/lib/extension.js
|
|
4578
5516
|
var require_extension = __commonJS({
|
|
4579
|
-
"
|
|
5517
|
+
"../../node_modules/ws/lib/extension.js"(exports, module) {
|
|
4580
5518
|
"use strict";
|
|
4581
5519
|
init_deno_env();
|
|
4582
5520
|
var { tokenChars } = require_validation();
|
|
@@ -4586,7 +5524,7 @@ var require_extension = __commonJS({
|
|
|
4586
5524
|
else
|
|
4587
5525
|
dest[name].push(elem);
|
|
4588
5526
|
}
|
|
4589
|
-
function
|
|
5527
|
+
function parse2(header) {
|
|
4590
5528
|
const offers = /* @__PURE__ */ Object.create(null);
|
|
4591
5529
|
let params = /* @__PURE__ */ Object.create(null);
|
|
4592
5530
|
let mustUnescape = false;
|
|
@@ -4741,13 +5679,13 @@ var require_extension = __commonJS({
|
|
|
4741
5679
|
}).join(", ");
|
|
4742
5680
|
}).join(", ");
|
|
4743
5681
|
}
|
|
4744
|
-
module.exports = { format, parse };
|
|
5682
|
+
module.exports = { format, parse: parse2 };
|
|
4745
5683
|
}
|
|
4746
5684
|
});
|
|
4747
5685
|
|
|
4748
|
-
//
|
|
5686
|
+
// ../../node_modules/ws/lib/websocket.js
|
|
4749
5687
|
var require_websocket = __commonJS({
|
|
4750
|
-
"
|
|
5688
|
+
"../../node_modules/ws/lib/websocket.js"(exports, module) {
|
|
4751
5689
|
"use strict";
|
|
4752
5690
|
init_deno_env();
|
|
4753
5691
|
var EventEmitter = __require2("events");
|
|
@@ -4775,7 +5713,7 @@ var require_websocket = __commonJS({
|
|
|
4775
5713
|
var {
|
|
4776
5714
|
EventTarget: { addEventListener, removeEventListener }
|
|
4777
5715
|
} = require_event_target();
|
|
4778
|
-
var { format, parse } = require_extension();
|
|
5716
|
+
var { format, parse: parse2 } = require_extension();
|
|
4779
5717
|
var { toBuffer } = require_buffer_util();
|
|
4780
5718
|
var closeTimeout = 30 * 1e3;
|
|
4781
5719
|
var kAborted = Symbol("kAborted");
|
|
@@ -5463,7 +6401,7 @@ var require_websocket = __commonJS({
|
|
|
5463
6401
|
}
|
|
5464
6402
|
let extensions;
|
|
5465
6403
|
try {
|
|
5466
|
-
extensions =
|
|
6404
|
+
extensions = parse2(secWebSocketExtensions);
|
|
5467
6405
|
} catch (err) {
|
|
5468
6406
|
const message = "Invalid Sec-WebSocket-Extensions header";
|
|
5469
6407
|
abortHandshake(websocket, socket, message);
|
|
@@ -5658,9 +6596,9 @@ var require_websocket = __commonJS({
|
|
|
5658
6596
|
}
|
|
5659
6597
|
});
|
|
5660
6598
|
|
|
5661
|
-
//
|
|
6599
|
+
// ../../node_modules/ws/lib/stream.js
|
|
5662
6600
|
var require_stream = __commonJS({
|
|
5663
|
-
"
|
|
6601
|
+
"../../node_modules/ws/lib/stream.js"(exports, module) {
|
|
5664
6602
|
"use strict";
|
|
5665
6603
|
init_deno_env();
|
|
5666
6604
|
var WebSocket2 = require_websocket();
|
|
@@ -5765,13 +6703,13 @@ var require_stream = __commonJS({
|
|
|
5765
6703
|
}
|
|
5766
6704
|
});
|
|
5767
6705
|
|
|
5768
|
-
//
|
|
6706
|
+
// ../../node_modules/ws/lib/subprotocol.js
|
|
5769
6707
|
var require_subprotocol = __commonJS({
|
|
5770
|
-
"
|
|
6708
|
+
"../../node_modules/ws/lib/subprotocol.js"(exports, module) {
|
|
5771
6709
|
"use strict";
|
|
5772
6710
|
init_deno_env();
|
|
5773
6711
|
var { tokenChars } = require_validation();
|
|
5774
|
-
function
|
|
6712
|
+
function parse2(header) {
|
|
5775
6713
|
const protocols = /* @__PURE__ */ new Set();
|
|
5776
6714
|
let start = -1;
|
|
5777
6715
|
let end = -1;
|
|
@@ -5810,13 +6748,13 @@ var require_subprotocol = __commonJS({
|
|
|
5810
6748
|
protocols.add(protocol);
|
|
5811
6749
|
return protocols;
|
|
5812
6750
|
}
|
|
5813
|
-
module.exports = { parse };
|
|
6751
|
+
module.exports = { parse: parse2 };
|
|
5814
6752
|
}
|
|
5815
6753
|
});
|
|
5816
6754
|
|
|
5817
|
-
//
|
|
6755
|
+
// ../../node_modules/ws/lib/websocket-server.js
|
|
5818
6756
|
var require_websocket_server = __commonJS({
|
|
5819
|
-
"
|
|
6757
|
+
"../../node_modules/ws/lib/websocket-server.js"(exports, module) {
|
|
5820
6758
|
"use strict";
|
|
5821
6759
|
init_deno_env();
|
|
5822
6760
|
var EventEmitter = __require2("events");
|
|
@@ -6213,7 +7151,7 @@ var require_websocket_server = __commonJS({
|
|
|
6213
7151
|
}
|
|
6214
7152
|
});
|
|
6215
7153
|
|
|
6216
|
-
//
|
|
7154
|
+
// ../../node_modules/ws/wrapper.mjs
|
|
6217
7155
|
var wrapper_exports = {};
|
|
6218
7156
|
__export(wrapper_exports, {
|
|
6219
7157
|
Receiver: () => import_receiver.default,
|
|
@@ -6225,7 +7163,7 @@ __export(wrapper_exports, {
|
|
|
6225
7163
|
});
|
|
6226
7164
|
var import_stream, import_receiver, import_sender, import_websocket, import_websocket_server, wrapper_default;
|
|
6227
7165
|
var init_wrapper = __esm({
|
|
6228
|
-
"
|
|
7166
|
+
"../../node_modules/ws/wrapper.mjs"() {
|
|
6229
7167
|
init_deno_env();
|
|
6230
7168
|
import_stream = __toESM(require_stream(), 1);
|
|
6231
7169
|
import_receiver = __toESM(require_receiver(), 1);
|
|
@@ -6679,6 +7617,15 @@ var init_error_handlers = __esm({
|
|
|
6679
7617
|
}
|
|
6680
7618
|
});
|
|
6681
7619
|
|
|
7620
|
+
// src/core/errors/error-context.ts
|
|
7621
|
+
var init_error_context = __esm({
|
|
7622
|
+
"src/core/errors/error-context.ts"() {
|
|
7623
|
+
"use strict";
|
|
7624
|
+
init_deno_env();
|
|
7625
|
+
init_logger();
|
|
7626
|
+
}
|
|
7627
|
+
});
|
|
7628
|
+
|
|
6682
7629
|
// src/core/errors/error-codes.ts
|
|
6683
7630
|
function getErrorDocsUrl(code) {
|
|
6684
7631
|
return `https://veryfront.com/docs/errors/${code}`;
|
|
@@ -7841,6 +8788,7 @@ var init_errors = __esm({
|
|
|
7841
8788
|
init_runtime_errors();
|
|
7842
8789
|
init_system_errors();
|
|
7843
8790
|
init_error_handlers();
|
|
8791
|
+
init_error_context();
|
|
7844
8792
|
init_catalog();
|
|
7845
8793
|
init_user_friendly();
|
|
7846
8794
|
}
|
|
@@ -7911,9 +8859,9 @@ var init_filesystem_adapter2 = __esm({
|
|
|
7911
8859
|
}
|
|
7912
8860
|
async makeTempDir(prefix) {
|
|
7913
8861
|
const { mkdtemp } = await import("node:fs/promises");
|
|
7914
|
-
const { join:
|
|
8862
|
+
const { join: join7 } = await import("node:path");
|
|
7915
8863
|
const { tmpdir } = await import("node:os");
|
|
7916
|
-
return await mkdtemp(
|
|
8864
|
+
return await mkdtemp(join7(tmpdir(), prefix));
|
|
7917
8865
|
}
|
|
7918
8866
|
watch(paths, options) {
|
|
7919
8867
|
const pathArray = Array.isArray(paths) ? paths : [paths];
|
|
@@ -8504,7 +9452,7 @@ __export(detect_exports, {
|
|
|
8504
9452
|
runtime: () => runtime
|
|
8505
9453
|
});
|
|
8506
9454
|
function isDeno2(global) {
|
|
8507
|
-
return "Deno" in global && typeof global.Deno === "object";
|
|
9455
|
+
return "Deno" in global && typeof global.Deno === "object" && typeof global.Deno.version === "object";
|
|
8508
9456
|
}
|
|
8509
9457
|
function isBun2(global) {
|
|
8510
9458
|
return "Bun" in global && typeof global.Bun === "object";
|
|
@@ -9001,6 +9949,9 @@ var LRUCache = class {
|
|
|
9001
9949
|
this.adapter.cleanupExpired();
|
|
9002
9950
|
}, this.cleanupIntervalMs);
|
|
9003
9951
|
this.cleanupTimer = timer;
|
|
9952
|
+
if (typeof Deno !== "undefined" && "unrefTimer" in Deno) {
|
|
9953
|
+
Deno.unrefTimer(timer);
|
|
9954
|
+
}
|
|
9004
9955
|
}
|
|
9005
9956
|
toStringKey(key) {
|
|
9006
9957
|
if (typeof key === "string") {
|
|
@@ -9078,13 +10029,29 @@ init_deno_env();
|
|
|
9078
10029
|
init_deno_env();
|
|
9079
10030
|
init_utils();
|
|
9080
10031
|
init_config();
|
|
9081
|
-
import { dirname, join as join2 } from "node:path";
|
|
10032
|
+
import { dirname as dirname2, join as join2 } from "node:path";
|
|
9082
10033
|
|
|
9083
10034
|
// src/module-system/import-map/default-import-map.ts
|
|
9084
10035
|
init_deno_env();
|
|
9085
10036
|
init_utils();
|
|
10037
|
+
init_runtime();
|
|
10038
|
+
var IS_TRUE_NODE = isNode && !isDeno;
|
|
10039
|
+
function getNpmReactImportMap(version) {
|
|
10040
|
+
return {
|
|
10041
|
+
react: `npm:react@${version}`,
|
|
10042
|
+
"react-dom": `npm:react-dom@${version}`,
|
|
10043
|
+
"react-dom/client": `npm:react-dom@${version}/client`,
|
|
10044
|
+
"react-dom/server": `npm:react-dom@${version}/server`,
|
|
10045
|
+
"react/jsx-runtime": `npm:react@${version}/jsx-runtime`,
|
|
10046
|
+
"react/jsx-dev-runtime": `npm:react@${version}/jsx-dev-runtime`,
|
|
10047
|
+
"react/": `npm:react@${version}/`
|
|
10048
|
+
};
|
|
10049
|
+
}
|
|
9086
10050
|
function getDefaultImportMap() {
|
|
9087
10051
|
const reactVersion = REACT_DEFAULT_VERSION;
|
|
10052
|
+
if (!IS_TRUE_NODE) {
|
|
10053
|
+
return { imports: getNpmReactImportMap(reactVersion) };
|
|
10054
|
+
}
|
|
9088
10055
|
const importMap = getReactImportMap(reactVersion);
|
|
9089
10056
|
importMap["react/"] = `https://esm.sh/react@${reactVersion}/`;
|
|
9090
10057
|
return { imports: importMap };
|
|
@@ -9157,46 +10124,1725 @@ init_deno_env();
|
|
|
9157
10124
|
// src/build/transforms/mdx/esm-module-loader.ts
|
|
9158
10125
|
init_runtime();
|
|
9159
10126
|
init_process();
|
|
9160
|
-
import { join as
|
|
9161
|
-
|
|
9162
|
-
|
|
9163
|
-
|
|
9164
|
-
|
|
9165
|
-
|
|
9166
|
-
|
|
9167
|
-
|
|
9168
|
-
|
|
9169
|
-
|
|
9170
|
-
|
|
9171
|
-
|
|
9172
|
-
|
|
9173
|
-
|
|
9174
|
-
|
|
9175
|
-
|
|
10127
|
+
import { join as join6, posix } from "node:path";
|
|
10128
|
+
|
|
10129
|
+
// src/build/transforms/esm-transform.ts
|
|
10130
|
+
init_deno_env();
|
|
10131
|
+
|
|
10132
|
+
// src/build/transforms/esm/index.ts
|
|
10133
|
+
init_deno_env();
|
|
10134
|
+
|
|
10135
|
+
// src/build/transforms/esm/transform-core.ts
|
|
10136
|
+
init_deno_env();
|
|
10137
|
+
import * as esbuild from "esbuild/mod.js";
|
|
10138
|
+
|
|
10139
|
+
// src/build/transforms/esm/transform-cache.ts
|
|
10140
|
+
init_deno_env();
|
|
10141
|
+
|
|
10142
|
+
// src/core/memory/index.ts
|
|
10143
|
+
init_deno_env();
|
|
10144
|
+
|
|
10145
|
+
// src/core/memory/profiler.ts
|
|
10146
|
+
init_deno_env();
|
|
10147
|
+
init_utils();
|
|
10148
|
+
var cacheRegistry = /* @__PURE__ */ new Map();
|
|
10149
|
+
function registerCache(name, getStats) {
|
|
10150
|
+
cacheRegistry.set(name, getStats);
|
|
10151
|
+
rendererLogger.debug(`[MemoryProfiler] Registered cache: ${name}`);
|
|
10152
|
+
}
|
|
10153
|
+
|
|
10154
|
+
// src/build/transforms/esm/transform-cache.ts
|
|
10155
|
+
init_logger();
|
|
10156
|
+
|
|
10157
|
+
// src/core/utils/redis-client.ts
|
|
10158
|
+
init_deno_env();
|
|
10159
|
+
init_logger();
|
|
10160
|
+
|
|
10161
|
+
// src/build/transforms/esm/transform-cache.ts
|
|
10162
|
+
var DEFAULT_TTL_MS = 5 * 60 * 1e3;
|
|
10163
|
+
var DEFAULT_TTL_SECONDS = 300;
|
|
10164
|
+
var MAX_ENTRIES = 2e3;
|
|
10165
|
+
var CLEANUP_INTERVAL_MS = 6e4;
|
|
10166
|
+
var REDIS_KEY_PREFIX = "veryfront:transform:";
|
|
10167
|
+
var memoryCache = /* @__PURE__ */ new Map();
|
|
10168
|
+
var redisEnabled = false;
|
|
10169
|
+
var redisClient = null;
|
|
10170
|
+
registerCache("transform-cache", () => ({
|
|
10171
|
+
name: "transform-cache",
|
|
10172
|
+
entries: memoryCache.size,
|
|
10173
|
+
maxEntries: MAX_ENTRIES,
|
|
10174
|
+
redisEnabled
|
|
10175
|
+
}));
|
|
10176
|
+
var cleanupInterval;
|
|
10177
|
+
function shouldDisableInterval2() {
|
|
10178
|
+
if (globalThis.__vfDisableLruInterval === true) {
|
|
10179
|
+
return true;
|
|
10180
|
+
}
|
|
9176
10181
|
try {
|
|
9177
|
-
|
|
9178
|
-
|
|
9179
|
-
|
|
9180
|
-
_resolvedPaths[packageSpec] = resolved;
|
|
9181
|
-
return resolved;
|
|
10182
|
+
if (typeof Deno !== "undefined" && Deno.env) {
|
|
10183
|
+
return Deno.env.get("VF_DISABLE_LRU_INTERVAL") === "1";
|
|
10184
|
+
}
|
|
9182
10185
|
} catch {
|
|
9183
|
-
_resolvedPaths[packageSpec] = null;
|
|
9184
|
-
return null;
|
|
9185
10186
|
}
|
|
10187
|
+
return false;
|
|
9186
10188
|
}
|
|
9187
|
-
|
|
9188
|
-
if (
|
|
9189
|
-
return
|
|
9190
|
-
|
|
9191
|
-
|
|
9192
|
-
|
|
9193
|
-
|
|
9194
|
-
|
|
9195
|
-
|
|
9196
|
-
|
|
9197
|
-
|
|
9198
|
-
|
|
9199
|
-
|
|
10189
|
+
function startPeriodicCleanup() {
|
|
10190
|
+
if (shouldDisableInterval2()) {
|
|
10191
|
+
return;
|
|
10192
|
+
}
|
|
10193
|
+
if (cleanupInterval)
|
|
10194
|
+
return;
|
|
10195
|
+
cleanupInterval = setInterval(() => {
|
|
10196
|
+
const now = Date.now();
|
|
10197
|
+
for (const [key, entry] of memoryCache) {
|
|
10198
|
+
if (entry.expiresAt <= now) {
|
|
10199
|
+
memoryCache.delete(key);
|
|
10200
|
+
}
|
|
10201
|
+
}
|
|
10202
|
+
}, CLEANUP_INTERVAL_MS);
|
|
10203
|
+
if (typeof Deno !== "undefined" && "unrefTimer" in Deno) {
|
|
10204
|
+
Deno.unrefTimer(cleanupInterval);
|
|
10205
|
+
}
|
|
10206
|
+
}
|
|
10207
|
+
startPeriodicCleanup();
|
|
10208
|
+
function generateCacheKey(projectId, filePath, contentHash, ssr = false) {
|
|
10209
|
+
const projectKey = projectId?.trim() || "default";
|
|
10210
|
+
const ssrKey = ssr ? "ssr" : "browser";
|
|
10211
|
+
return `${projectKey}:${filePath}:${contentHash}:${ssrKey}`;
|
|
10212
|
+
}
|
|
10213
|
+
function redisKey(key) {
|
|
10214
|
+
return `${REDIS_KEY_PREFIX}${key}`;
|
|
10215
|
+
}
|
|
10216
|
+
function getCachedTransform(key) {
|
|
10217
|
+
const entry = memoryCache.get(key);
|
|
10218
|
+
if (!entry) {
|
|
10219
|
+
return void 0;
|
|
10220
|
+
}
|
|
10221
|
+
if (entry.expiresAt <= Date.now()) {
|
|
10222
|
+
memoryCache.delete(key);
|
|
10223
|
+
return void 0;
|
|
10224
|
+
}
|
|
10225
|
+
return entry;
|
|
10226
|
+
}
|
|
10227
|
+
function setCachedTransform(key, code, hash, ttl = DEFAULT_TTL_MS) {
|
|
10228
|
+
const now = Date.now();
|
|
10229
|
+
memoryCache.set(key, {
|
|
10230
|
+
code,
|
|
10231
|
+
hash,
|
|
10232
|
+
timestamp: now,
|
|
10233
|
+
expiresAt: now + Math.max(1, ttl)
|
|
10234
|
+
});
|
|
10235
|
+
if (memoryCache.size > MAX_ENTRIES) {
|
|
10236
|
+
pruneMemoryCache();
|
|
10237
|
+
}
|
|
10238
|
+
if (redisEnabled && redisClient) {
|
|
10239
|
+
const entry = {
|
|
10240
|
+
code,
|
|
10241
|
+
hash,
|
|
10242
|
+
timestamp: now,
|
|
10243
|
+
expiresAt: now + Math.max(1, ttl)
|
|
10244
|
+
};
|
|
10245
|
+
const ttlSeconds = Math.ceil(ttl / 1e3);
|
|
10246
|
+
redisClient.set(redisKey(key), JSON.stringify(entry), {
|
|
10247
|
+
EX: ttlSeconds > 0 ? ttlSeconds : DEFAULT_TTL_SECONDS
|
|
10248
|
+
}).catch((error) => {
|
|
10249
|
+
logger.debug("[TransformCache] Redis set failed", { key, error });
|
|
10250
|
+
});
|
|
10251
|
+
}
|
|
10252
|
+
}
|
|
10253
|
+
function pruneMemoryCache() {
|
|
10254
|
+
const entries = Array.from(memoryCache.entries()).sort(
|
|
10255
|
+
([, a], [, b]) => a.timestamp - b.timestamp
|
|
10256
|
+
);
|
|
10257
|
+
const excess = memoryCache.size - MAX_ENTRIES;
|
|
10258
|
+
for (let i = 0; i < excess; i++) {
|
|
10259
|
+
const [key] = entries[i];
|
|
10260
|
+
memoryCache.delete(key);
|
|
10261
|
+
}
|
|
10262
|
+
}
|
|
10263
|
+
|
|
10264
|
+
// src/build/transforms/esm/transform-utils.ts
|
|
10265
|
+
init_deno_env();
|
|
10266
|
+
init_hash_utils();
|
|
10267
|
+
function computeContentHash2(content) {
|
|
10268
|
+
return shortHash(content);
|
|
10269
|
+
}
|
|
10270
|
+
function getLoaderFromPath(filePath) {
|
|
10271
|
+
if (filePath.endsWith(".tsx"))
|
|
10272
|
+
return "tsx";
|
|
10273
|
+
if (filePath.endsWith(".ts"))
|
|
10274
|
+
return "ts";
|
|
10275
|
+
if (filePath.endsWith(".jsx"))
|
|
10276
|
+
return "jsx";
|
|
10277
|
+
if (filePath.endsWith(".js"))
|
|
10278
|
+
return "js";
|
|
10279
|
+
if (filePath.endsWith(".mdx"))
|
|
10280
|
+
return "jsx";
|
|
10281
|
+
return "tsx";
|
|
10282
|
+
}
|
|
10283
|
+
|
|
10284
|
+
// src/build/transforms/esm/react-imports.ts
|
|
10285
|
+
init_deno_env();
|
|
10286
|
+
|
|
10287
|
+
// src/build/transforms/esm/lexer.ts
|
|
10288
|
+
init_deno_env();
|
|
10289
|
+
|
|
10290
|
+
// node_modules/.deno/es-module-lexer@1.5.0/node_modules/es-module-lexer/dist/lexer.js
|
|
10291
|
+
init_deno_env();
|
|
10292
|
+
var ImportType;
|
|
10293
|
+
!function(A2) {
|
|
10294
|
+
A2[A2.Static = 1] = "Static", A2[A2.Dynamic = 2] = "Dynamic", A2[A2.ImportMeta = 3] = "ImportMeta", A2[A2.StaticSourcePhase = 4] = "StaticSourcePhase", A2[A2.DynamicSourcePhase = 5] = "DynamicSourcePhase";
|
|
10295
|
+
}(ImportType || (ImportType = {}));
|
|
10296
|
+
var A = 1 === new Uint8Array(new Uint16Array([1]).buffer)[0];
|
|
10297
|
+
function parse(E2, g = "@") {
|
|
10298
|
+
if (!C)
|
|
10299
|
+
return init.then(() => parse(E2));
|
|
10300
|
+
const I = E2.length + 1, w = (C.__heap_base.value || C.__heap_base) + 4 * I - C.memory.buffer.byteLength;
|
|
10301
|
+
w > 0 && C.memory.grow(Math.ceil(w / 65536));
|
|
10302
|
+
const D = C.sa(I - 1);
|
|
10303
|
+
if ((A ? B : Q)(E2, new Uint16Array(C.memory.buffer, D, I)), !C.parse())
|
|
10304
|
+
throw Object.assign(new Error(`Parse error ${g}:${E2.slice(0, C.e()).split("\n").length}:${C.e() - E2.lastIndexOf("\n", C.e() - 1)}`), { idx: C.e() });
|
|
10305
|
+
const o = [], K = [];
|
|
10306
|
+
for (; C.ri(); ) {
|
|
10307
|
+
const A2 = C.is(), Q2 = C.ie(), B2 = C.it(), g2 = C.ai(), I2 = C.id(), w2 = C.ss(), D2 = C.se();
|
|
10308
|
+
let K2;
|
|
10309
|
+
C.ip() && (K2 = k(E2.slice(-1 === I2 ? A2 - 1 : A2, -1 === I2 ? Q2 + 1 : Q2))), o.push({ n: K2, t: B2, s: A2, e: Q2, ss: w2, se: D2, d: I2, a: g2 });
|
|
10310
|
+
}
|
|
10311
|
+
for (; C.re(); ) {
|
|
10312
|
+
const A2 = C.es(), Q2 = C.ee(), B2 = C.els(), g2 = C.ele(), I2 = E2.slice(A2, Q2), w2 = I2[0], D2 = B2 < 0 ? void 0 : E2.slice(B2, g2), o2 = D2 ? D2[0] : "";
|
|
10313
|
+
K.push({ s: A2, e: Q2, ls: B2, le: g2, n: '"' === w2 || "'" === w2 ? k(I2) : I2, ln: '"' === o2 || "'" === o2 ? k(D2) : D2 });
|
|
10314
|
+
}
|
|
10315
|
+
function k(A2) {
|
|
10316
|
+
try {
|
|
10317
|
+
return (0, eval)(A2);
|
|
10318
|
+
} catch (A3) {
|
|
10319
|
+
}
|
|
10320
|
+
}
|
|
10321
|
+
return [o, K, !!C.f(), !!C.ms()];
|
|
10322
|
+
}
|
|
10323
|
+
function Q(A2, Q2) {
|
|
10324
|
+
const B2 = A2.length;
|
|
10325
|
+
let C2 = 0;
|
|
10326
|
+
for (; C2 < B2; ) {
|
|
10327
|
+
const B3 = A2.charCodeAt(C2);
|
|
10328
|
+
Q2[C2++] = (255 & B3) << 8 | B3 >>> 8;
|
|
10329
|
+
}
|
|
10330
|
+
}
|
|
10331
|
+
function B(A2, Q2) {
|
|
10332
|
+
const B2 = A2.length;
|
|
10333
|
+
let C2 = 0;
|
|
10334
|
+
for (; C2 < B2; )
|
|
10335
|
+
Q2[C2] = A2.charCodeAt(C2++);
|
|
10336
|
+
}
|
|
10337
|
+
var C;
|
|
10338
|
+
var init = WebAssembly.compile((E = "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", "undefined" != typeof Buffer ? Buffer.from(E, "base64") : Uint8Array.from(atob(E), (A2) => A2.charCodeAt(0)))).then(WebAssembly.instantiate).then(({ exports: A2 }) => {
|
|
10339
|
+
C = A2;
|
|
10340
|
+
});
|
|
10341
|
+
var E;
|
|
10342
|
+
|
|
10343
|
+
// src/build/transforms/esm/lexer.ts
|
|
10344
|
+
var initPromise = null;
|
|
10345
|
+
async function initLexer() {
|
|
10346
|
+
if (!initPromise) {
|
|
10347
|
+
const anyInit = init;
|
|
10348
|
+
initPromise = typeof anyInit === "function" ? anyInit() : anyInit;
|
|
10349
|
+
}
|
|
10350
|
+
await initPromise;
|
|
10351
|
+
}
|
|
10352
|
+
async function parseImports(code) {
|
|
10353
|
+
await initLexer();
|
|
10354
|
+
return parse(code)[0];
|
|
10355
|
+
}
|
|
10356
|
+
async function replaceSpecifiers(code, replacer) {
|
|
10357
|
+
const imports = await parseImports(code);
|
|
10358
|
+
let result = code;
|
|
10359
|
+
for (let i = imports.length - 1; i >= 0; i--) {
|
|
10360
|
+
const imp = imports[i];
|
|
10361
|
+
if (!imp)
|
|
10362
|
+
continue;
|
|
10363
|
+
if (imp.n === void 0)
|
|
10364
|
+
continue;
|
|
10365
|
+
const replacement = replacer(imp.n, imp.d > -1);
|
|
10366
|
+
if (replacement && replacement !== imp.n) {
|
|
10367
|
+
const before = result.substring(0, imp.s);
|
|
10368
|
+
const after = result.substring(imp.e);
|
|
10369
|
+
result = before + replacement + after;
|
|
10370
|
+
}
|
|
10371
|
+
}
|
|
10372
|
+
return result;
|
|
10373
|
+
}
|
|
10374
|
+
async function rewriteImports(code, rewriter) {
|
|
10375
|
+
const imports = await parseImports(code);
|
|
10376
|
+
let result = code;
|
|
10377
|
+
for (let i = imports.length - 1; i >= 0; i--) {
|
|
10378
|
+
const imp = imports[i];
|
|
10379
|
+
if (!imp)
|
|
10380
|
+
continue;
|
|
10381
|
+
const statement = code.substring(imp.ss, imp.se);
|
|
10382
|
+
const replacement = rewriter(imp, statement);
|
|
10383
|
+
if (replacement !== null) {
|
|
10384
|
+
const before = result.substring(0, imp.ss);
|
|
10385
|
+
const after = result.substring(imp.se);
|
|
10386
|
+
result = before + replacement + after;
|
|
10387
|
+
}
|
|
10388
|
+
}
|
|
10389
|
+
return result;
|
|
10390
|
+
}
|
|
10391
|
+
|
|
10392
|
+
// src/build/transforms/esm/react-imports.ts
|
|
10393
|
+
init_cdn();
|
|
10394
|
+
init_runtime();
|
|
10395
|
+
init_process();
|
|
10396
|
+
function getVeryfrontAIReactPath(subpath = "") {
|
|
10397
|
+
const currentDir = new URL(".", import.meta.url).pathname;
|
|
10398
|
+
const srcDir = currentDir.replace(/\/build\/transforms\/esm\/?$/, "");
|
|
10399
|
+
const modulePath = subpath || "index.ts";
|
|
10400
|
+
return `file://${srcDir}/ai/react/${modulePath}`;
|
|
10401
|
+
}
|
|
10402
|
+
var projectHasReactDom = null;
|
|
10403
|
+
async function checkProjectHasReactDom() {
|
|
10404
|
+
if (projectHasReactDom !== null) {
|
|
10405
|
+
return projectHasReactDom;
|
|
10406
|
+
}
|
|
10407
|
+
if (!isNodeRuntime()) {
|
|
10408
|
+
projectHasReactDom = false;
|
|
10409
|
+
return false;
|
|
10410
|
+
}
|
|
10411
|
+
try {
|
|
10412
|
+
const { createRequire } = await import("node:module");
|
|
10413
|
+
const { pathToFileURL } = await import("node:url");
|
|
10414
|
+
const projectRequire = createRequire(pathToFileURL(cwd() + "/").href);
|
|
10415
|
+
projectRequire.resolve("react");
|
|
10416
|
+
projectRequire.resolve("react-dom/server");
|
|
10417
|
+
projectHasReactDom = true;
|
|
10418
|
+
return true;
|
|
10419
|
+
} catch {
|
|
10420
|
+
projectHasReactDom = false;
|
|
10421
|
+
return false;
|
|
10422
|
+
}
|
|
10423
|
+
}
|
|
10424
|
+
async function getBundledReactPath(subpath = "") {
|
|
10425
|
+
if (!isNodeRuntime()) {
|
|
10426
|
+
return null;
|
|
10427
|
+
}
|
|
10428
|
+
try {
|
|
10429
|
+
const { createRequire } = await import("node:module");
|
|
10430
|
+
const cliRequire = createRequire(import.meta.url);
|
|
10431
|
+
const moduleName = subpath ? `react${subpath}` : "react";
|
|
10432
|
+
return cliRequire.resolve(moduleName);
|
|
10433
|
+
} catch {
|
|
10434
|
+
return null;
|
|
10435
|
+
}
|
|
10436
|
+
}
|
|
10437
|
+
async function resolveReactImports(code, forSSR = false) {
|
|
10438
|
+
const isNode2 = isNodeRuntime();
|
|
10439
|
+
if (isNode2 && forSSR) {
|
|
10440
|
+
const hasReactDom = await checkProjectHasReactDom();
|
|
10441
|
+
const { pathToFileURL } = await import("node:url");
|
|
10442
|
+
if (hasReactDom) {
|
|
10443
|
+
try {
|
|
10444
|
+
const { createRequire } = await import("node:module");
|
|
10445
|
+
const projectRequire = createRequire(pathToFileURL(cwd() + "/").href);
|
|
10446
|
+
const projectImports = {
|
|
10447
|
+
"react/jsx-runtime": pathToFileURL(projectRequire.resolve("react/jsx-runtime")).href,
|
|
10448
|
+
"react/jsx-dev-runtime": pathToFileURL(projectRequire.resolve("react/jsx-dev-runtime")).href,
|
|
10449
|
+
"react": pathToFileURL(projectRequire.resolve("react")).href
|
|
10450
|
+
};
|
|
10451
|
+
return replaceSpecifiers(code, (specifier) => {
|
|
10452
|
+
return projectImports[specifier] || null;
|
|
10453
|
+
});
|
|
10454
|
+
} catch {
|
|
10455
|
+
}
|
|
10456
|
+
}
|
|
10457
|
+
const bundledReact = await getBundledReactPath();
|
|
10458
|
+
const bundledJsxRuntime = await getBundledReactPath("/jsx-runtime");
|
|
10459
|
+
const bundledJsxDevRuntime = await getBundledReactPath("/jsx-dev-runtime");
|
|
10460
|
+
if (bundledReact && bundledJsxRuntime && bundledJsxDevRuntime) {
|
|
10461
|
+
const bundledImports = {
|
|
10462
|
+
"react/jsx-runtime": pathToFileURL(bundledJsxRuntime).href,
|
|
10463
|
+
"react/jsx-dev-runtime": pathToFileURL(bundledJsxDevRuntime).href,
|
|
10464
|
+
"react": pathToFileURL(bundledReact).href
|
|
10465
|
+
};
|
|
10466
|
+
return replaceSpecifiers(code, (specifier) => {
|
|
10467
|
+
return bundledImports[specifier] || null;
|
|
10468
|
+
});
|
|
10469
|
+
}
|
|
10470
|
+
return code;
|
|
10471
|
+
}
|
|
10472
|
+
if (isNode2) {
|
|
10473
|
+
return code;
|
|
10474
|
+
}
|
|
10475
|
+
if (forSSR) {
|
|
10476
|
+
const denoSSRImports = {
|
|
10477
|
+
"veryfront/ai/react": getVeryfrontAIReactPath(),
|
|
10478
|
+
"veryfront/ai/components": getVeryfrontAIReactPath("components/index.ts"),
|
|
10479
|
+
"veryfront/ai/primitives": getVeryfrontAIReactPath("primitives/index.ts")
|
|
10480
|
+
};
|
|
10481
|
+
return replaceSpecifiers(code, (specifier) => {
|
|
10482
|
+
return denoSSRImports[specifier] || null;
|
|
10483
|
+
});
|
|
10484
|
+
}
|
|
10485
|
+
const reactImports = {
|
|
10486
|
+
"react/jsx-runtime": `https://esm.sh/react@${REACT_DEFAULT_VERSION}/jsx-runtime`,
|
|
10487
|
+
"react/jsx-dev-runtime": `https://esm.sh/react@${REACT_DEFAULT_VERSION}/jsx-dev-runtime`,
|
|
10488
|
+
"react-dom/server": `https://esm.sh/react-dom@${REACT_DEFAULT_VERSION}/server`,
|
|
10489
|
+
"react-dom/client": `https://esm.sh/react-dom@${REACT_DEFAULT_VERSION}/client`,
|
|
10490
|
+
"react-dom": `https://esm.sh/react-dom@${REACT_DEFAULT_VERSION}`,
|
|
10491
|
+
"react": `https://esm.sh/react@${REACT_DEFAULT_VERSION}`
|
|
10492
|
+
};
|
|
10493
|
+
return replaceSpecifiers(code, (specifier) => {
|
|
10494
|
+
return reactImports[specifier] || null;
|
|
10495
|
+
});
|
|
10496
|
+
}
|
|
10497
|
+
function addDepsToEsmShUrls(code, forSSR = false) {
|
|
10498
|
+
if (isNodeRuntime()) {
|
|
10499
|
+
return Promise.resolve(code);
|
|
10500
|
+
}
|
|
10501
|
+
return Promise.resolve(replaceSpecifiers(code, (specifier) => {
|
|
10502
|
+
if (specifier.startsWith("https://esm.sh/") && !specifier.includes(`react@${REACT_DEFAULT_VERSION}`)) {
|
|
10503
|
+
const hasQuery = specifier.includes("?");
|
|
10504
|
+
const hasExternal = specifier.includes("external=");
|
|
10505
|
+
if (forSSR) {
|
|
10506
|
+
if (hasExternal) {
|
|
10507
|
+
return null;
|
|
10508
|
+
}
|
|
10509
|
+
const separator = hasQuery ? "&" : "?";
|
|
10510
|
+
return `${specifier}${separator}external=react,react-dom`;
|
|
10511
|
+
} else {
|
|
10512
|
+
if (hasQuery) {
|
|
10513
|
+
return null;
|
|
10514
|
+
}
|
|
10515
|
+
return `${specifier}?deps=react@${REACT_DEFAULT_VERSION},react-dom@${REACT_DEFAULT_VERSION}`;
|
|
10516
|
+
}
|
|
10517
|
+
}
|
|
10518
|
+
return null;
|
|
10519
|
+
}));
|
|
10520
|
+
}
|
|
10521
|
+
|
|
10522
|
+
// src/build/transforms/esm/path-resolver.ts
|
|
10523
|
+
init_deno_env();
|
|
10524
|
+
init_cdn();
|
|
10525
|
+
init_utils();
|
|
10526
|
+
import { join as join3 } from "node:path";
|
|
10527
|
+
import { ensureDir } from "node:fs";
|
|
10528
|
+
var SSR_STUBS_DIR = join3(
|
|
10529
|
+
Deno.env.get("HOME") || "/tmp",
|
|
10530
|
+
".cache",
|
|
10531
|
+
"veryfront-ssr-stubs"
|
|
10532
|
+
);
|
|
10533
|
+
var stubFileCache = /* @__PURE__ */ new Map();
|
|
10534
|
+
function extractNamedImports(statement) {
|
|
10535
|
+
const namedImports = [];
|
|
10536
|
+
const braceMatch = statement.match(/\{([^}]+)\}/);
|
|
10537
|
+
if (braceMatch) {
|
|
10538
|
+
const inside = braceMatch[1];
|
|
10539
|
+
const parts = inside.split(",");
|
|
10540
|
+
for (const part of parts) {
|
|
10541
|
+
const trimmed = part.trim();
|
|
10542
|
+
if (!trimmed)
|
|
10543
|
+
continue;
|
|
10544
|
+
const asMatch = trimmed.match(/^(\w+)\s+as\s+\w+$/);
|
|
10545
|
+
if (asMatch) {
|
|
10546
|
+
namedImports.push(asMatch[1]);
|
|
10547
|
+
} else {
|
|
10548
|
+
namedImports.push(trimmed);
|
|
10549
|
+
}
|
|
10550
|
+
}
|
|
10551
|
+
}
|
|
10552
|
+
return namedImports;
|
|
10553
|
+
}
|
|
10554
|
+
var CROSS_PROJECT_VERSIONED_PATTERN = /^([a-z0-9-]+)@([\d^~x][\d.x^~-]*)\/@\/(.+)$/;
|
|
10555
|
+
var CROSS_PROJECT_LATEST_PATTERN = /^([a-z0-9-]+)\/@\/(.+)$/;
|
|
10556
|
+
function parseCrossProjectImport(specifier) {
|
|
10557
|
+
const versionedMatch = specifier.match(CROSS_PROJECT_VERSIONED_PATTERN);
|
|
10558
|
+
if (versionedMatch) {
|
|
10559
|
+
return {
|
|
10560
|
+
projectSlug: versionedMatch[1],
|
|
10561
|
+
version: versionedMatch[2],
|
|
10562
|
+
path: versionedMatch[3]
|
|
10563
|
+
};
|
|
10564
|
+
}
|
|
10565
|
+
const latestMatch = specifier.match(CROSS_PROJECT_LATEST_PATTERN);
|
|
10566
|
+
if (latestMatch) {
|
|
10567
|
+
return {
|
|
10568
|
+
projectSlug: latestMatch[1],
|
|
10569
|
+
version: "latest",
|
|
10570
|
+
path: latestMatch[2]
|
|
10571
|
+
};
|
|
10572
|
+
}
|
|
10573
|
+
return null;
|
|
10574
|
+
}
|
|
10575
|
+
function resolveCrossProjectImports(code, options) {
|
|
10576
|
+
const { ssr = false } = options;
|
|
10577
|
+
if (ssr) {
|
|
10578
|
+
return Promise.resolve(code);
|
|
10579
|
+
}
|
|
10580
|
+
return Promise.resolve(
|
|
10581
|
+
replaceSpecifiers(code, (specifier) => {
|
|
10582
|
+
const parsed = parseCrossProjectImport(specifier);
|
|
10583
|
+
if (!parsed)
|
|
10584
|
+
return null;
|
|
10585
|
+
const { projectSlug, version, path } = parsed;
|
|
10586
|
+
let modulePath = path;
|
|
10587
|
+
if (!/\.(js|mjs|jsx|ts|tsx|mdx)$/.test(modulePath)) {
|
|
10588
|
+
modulePath = `${modulePath}.tsx`;
|
|
10589
|
+
}
|
|
10590
|
+
const projectRef = version === "latest" ? projectSlug : `${projectSlug}@${version}`;
|
|
10591
|
+
const moduleServerUrl = `/_vf_modules/_cross/${projectRef}/@/${modulePath}`;
|
|
10592
|
+
rendererLogger.debug("[CrossProjectImport] Rewriting", { from: specifier, to: moduleServerUrl });
|
|
10593
|
+
return moduleServerUrl;
|
|
10594
|
+
})
|
|
10595
|
+
);
|
|
10596
|
+
}
|
|
10597
|
+
async function hashUrl(url) {
|
|
10598
|
+
const encoder = new TextEncoder();
|
|
10599
|
+
const data = encoder.encode(url);
|
|
10600
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", data);
|
|
10601
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
10602
|
+
return hashArray.slice(0, 8).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
10603
|
+
}
|
|
10604
|
+
async function getOrCreateStubFile(specifier, namedExports = []) {
|
|
10605
|
+
const sortedExports = [...namedExports].sort();
|
|
10606
|
+
const cacheKey = `${specifier}::${sortedExports.join(",")}`;
|
|
10607
|
+
const cached = stubFileCache.get(cacheKey);
|
|
10608
|
+
if (cached) {
|
|
10609
|
+
return cached;
|
|
10610
|
+
}
|
|
10611
|
+
const namedExportDeclarations = namedExports.map((name) => {
|
|
10612
|
+
if (/^[A-Z]/.test(name) || name.endsWith("Provider") || name.endsWith("Consumer")) {
|
|
10613
|
+
return `export const ${name} = noopComponent;`;
|
|
10614
|
+
}
|
|
10615
|
+
if (name.startsWith("use")) {
|
|
10616
|
+
return `export const ${name} = () => ({});`;
|
|
10617
|
+
}
|
|
10618
|
+
if (["clsx", "cn", "twMerge", "twJoin", "cx", "classNames", "classnames"].includes(name)) {
|
|
10619
|
+
return `export const ${name} = (...args) => args.filter(Boolean).join(" ");`;
|
|
10620
|
+
}
|
|
10621
|
+
if (name === "cva") {
|
|
10622
|
+
return `export const ${name} = (base, _config) => (_props) => base || "";`;
|
|
10623
|
+
}
|
|
10624
|
+
if (name === "motion" || name === "m") {
|
|
10625
|
+
return `export const ${name} = motionProxy;`;
|
|
10626
|
+
}
|
|
10627
|
+
if (name === "AnimatePresence") {
|
|
10628
|
+
return `export const ${name} = noopComponent;`;
|
|
10629
|
+
}
|
|
10630
|
+
return `export const ${name} = noop;`;
|
|
10631
|
+
}).join("\n");
|
|
10632
|
+
const stubModule = `// SSR stub for ${specifier}
|
|
10633
|
+
// Named exports: ${namedExports.join(", ") || "(none)"}
|
|
10634
|
+
const noop = () => {};
|
|
10635
|
+
const noopComponent = (props) => props?.children || null;
|
|
10636
|
+
|
|
10637
|
+
// Proxy for motion-like APIs (motion.div, motion.span, etc.)
|
|
10638
|
+
const motionProxy = new Proxy(noopComponent, {
|
|
10639
|
+
get(_, prop) {
|
|
10640
|
+
if (prop === 'default' || prop === '__esModule') return motionProxy;
|
|
10641
|
+
// motion.div, motion.span, etc. should return a component
|
|
10642
|
+
return noopComponent;
|
|
10643
|
+
}
|
|
10644
|
+
});
|
|
10645
|
+
|
|
10646
|
+
const noopProxy = new Proxy(function(){}, {
|
|
10647
|
+
get(_, prop) {
|
|
10648
|
+
if (prop === 'default' || prop === '__esModule') return noopProxy;
|
|
10649
|
+
if (prop === 'Provider' || prop === 'Consumer') return noopComponent;
|
|
10650
|
+
if (typeof prop === 'string' && prop.startsWith('use')) return () => ({});
|
|
10651
|
+
return noop;
|
|
10652
|
+
},
|
|
10653
|
+
apply() { return null; }
|
|
10654
|
+
});
|
|
10655
|
+
|
|
10656
|
+
// Named exports
|
|
10657
|
+
${namedExportDeclarations}
|
|
10658
|
+
|
|
10659
|
+
// Default export and metadata
|
|
10660
|
+
export default noopProxy;
|
|
10661
|
+
export const __ssr_stub__ = true;
|
|
10662
|
+
export const __original_url__ = ${JSON.stringify(specifier)};
|
|
10663
|
+
`;
|
|
10664
|
+
const hash = await hashUrl(cacheKey);
|
|
10665
|
+
const stubPath = join3(SSR_STUBS_DIR, `stub-${hash}.js`);
|
|
10666
|
+
await ensureDir(SSR_STUBS_DIR);
|
|
10667
|
+
await Deno.writeTextFile(stubPath, stubModule);
|
|
10668
|
+
try {
|
|
10669
|
+
await import(`file://${stubPath}`);
|
|
10670
|
+
} catch {
|
|
10671
|
+
}
|
|
10672
|
+
stubFileCache.set(cacheKey, stubPath);
|
|
10673
|
+
return stubPath;
|
|
10674
|
+
}
|
|
10675
|
+
async function blockExternalUrlImports(code, _filePath) {
|
|
10676
|
+
const blockedUrls = [];
|
|
10677
|
+
const imports = await parseImports(code);
|
|
10678
|
+
const urlToNamedExports = /* @__PURE__ */ new Map();
|
|
10679
|
+
for (const imp of imports) {
|
|
10680
|
+
if (imp.n && (imp.n.startsWith("https://") || imp.n.startsWith("http://"))) {
|
|
10681
|
+
blockedUrls.push(imp.n);
|
|
10682
|
+
const statement = code.substring(imp.ss, imp.se);
|
|
10683
|
+
const namedExports = extractNamedImports(statement);
|
|
10684
|
+
const existing = urlToNamedExports.get(imp.n) || [];
|
|
10685
|
+
urlToNamedExports.set(imp.n, [.../* @__PURE__ */ new Set([...existing, ...namedExports])]);
|
|
10686
|
+
}
|
|
10687
|
+
}
|
|
10688
|
+
if (blockedUrls.length === 0) {
|
|
10689
|
+
return { code, blockedUrls };
|
|
10690
|
+
}
|
|
10691
|
+
const stubPaths = /* @__PURE__ */ new Map();
|
|
10692
|
+
for (const [url, namedExports] of urlToNamedExports) {
|
|
10693
|
+
const stubPath = await getOrCreateStubFile(url, namedExports);
|
|
10694
|
+
stubPaths.set(url, stubPath);
|
|
10695
|
+
}
|
|
10696
|
+
const transformedCode = await replaceSpecifiers(code, (specifier) => {
|
|
10697
|
+
if (specifier.startsWith("https://") || specifier.startsWith("http://")) {
|
|
10698
|
+
const stubPath = stubPaths.get(specifier);
|
|
10699
|
+
if (stubPath) {
|
|
10700
|
+
return `file://${stubPath}`;
|
|
10701
|
+
}
|
|
10702
|
+
}
|
|
10703
|
+
return null;
|
|
10704
|
+
});
|
|
10705
|
+
return { code: transformedCode, blockedUrls };
|
|
10706
|
+
}
|
|
10707
|
+
function resolveVeryfrontImports(code) {
|
|
10708
|
+
return Promise.resolve(replaceSpecifiers(code, (specifier) => {
|
|
10709
|
+
if (specifier.startsWith("@veryfront/")) {
|
|
10710
|
+
return specifier.replace("@veryfront/", "veryfront/");
|
|
10711
|
+
}
|
|
10712
|
+
if (specifier === "@veryfront") {
|
|
10713
|
+
return "veryfront";
|
|
10714
|
+
}
|
|
10715
|
+
return null;
|
|
10716
|
+
}));
|
|
10717
|
+
}
|
|
10718
|
+
function resolvePathAliases(code, filePath, projectDir, ssr = false) {
|
|
10719
|
+
const _normalizedProjectDir = projectDir.replace(/\\/g, "/").replace(/\/$/, "");
|
|
10720
|
+
let relativeFilePath = filePath;
|
|
10721
|
+
if (filePath.startsWith(_normalizedProjectDir)) {
|
|
10722
|
+
relativeFilePath = filePath.substring(_normalizedProjectDir.length + 1);
|
|
10723
|
+
} else if (filePath.startsWith("/")) {
|
|
10724
|
+
const pathParts = filePath.split("/");
|
|
10725
|
+
const projectParts = _normalizedProjectDir.split("/");
|
|
10726
|
+
const lastProjectPart = projectParts[projectParts.length - 1];
|
|
10727
|
+
const projectIndex = pathParts.indexOf(lastProjectPart);
|
|
10728
|
+
if (projectIndex >= 0) {
|
|
10729
|
+
relativeFilePath = pathParts.slice(projectIndex + 1).join("/");
|
|
10730
|
+
}
|
|
10731
|
+
}
|
|
10732
|
+
const fileDir = relativeFilePath.substring(0, relativeFilePath.lastIndexOf("/"));
|
|
10733
|
+
const depth = fileDir.split("/").filter(Boolean).length;
|
|
10734
|
+
const relativeToRoot = depth === 0 ? "." : "../".repeat(depth).slice(0, -1);
|
|
10735
|
+
return Promise.resolve(replaceSpecifiers(code, (specifier) => {
|
|
10736
|
+
if (specifier.startsWith("@/")) {
|
|
10737
|
+
const path = specifier.substring(2);
|
|
10738
|
+
const relativePath = depth === 0 ? `./${path}` : `${relativeToRoot}/${path}`;
|
|
10739
|
+
if (!/\.(tsx?|jsx?|mjs|cjs|mdx)$/.test(relativePath)) {
|
|
10740
|
+
return relativePath + ".js";
|
|
10741
|
+
}
|
|
10742
|
+
if (ssr) {
|
|
10743
|
+
return relativePath.replace(/\.(tsx?|jsx|mdx)$/, ".js");
|
|
10744
|
+
}
|
|
10745
|
+
return relativePath;
|
|
10746
|
+
}
|
|
10747
|
+
return null;
|
|
10748
|
+
}));
|
|
10749
|
+
}
|
|
10750
|
+
function resolveRelativeImports(code, filePath, projectDir, moduleServerUrl) {
|
|
10751
|
+
const _normalizedProjectDir = projectDir.replace(/\\/g, "/").replace(/\/$/, "");
|
|
10752
|
+
let relativeFilePath = filePath;
|
|
10753
|
+
if (filePath.startsWith(_normalizedProjectDir)) {
|
|
10754
|
+
relativeFilePath = filePath.substring(_normalizedProjectDir.length + 1);
|
|
10755
|
+
} else if (filePath.startsWith("/")) {
|
|
10756
|
+
const pathParts = filePath.split("/");
|
|
10757
|
+
const projectParts = _normalizedProjectDir.split("/");
|
|
10758
|
+
const lastProjectPart = projectParts[projectParts.length - 1];
|
|
10759
|
+
const projectIndex = pathParts.indexOf(lastProjectPart);
|
|
10760
|
+
if (projectIndex >= 0) {
|
|
10761
|
+
relativeFilePath = pathParts.slice(projectIndex + 1).join("/");
|
|
10762
|
+
}
|
|
10763
|
+
}
|
|
10764
|
+
const fileDir = relativeFilePath.substring(0, relativeFilePath.lastIndexOf("/"));
|
|
10765
|
+
return Promise.resolve(replaceSpecifiers(code, (specifier) => {
|
|
10766
|
+
if (specifier.startsWith("./") || specifier.startsWith("../")) {
|
|
10767
|
+
let rewrittenSpecifier = specifier;
|
|
10768
|
+
if (/\.(tsx?|jsx)$/.test(specifier)) {
|
|
10769
|
+
rewrittenSpecifier = specifier.replace(/\.(tsx?|jsx)$/, ".js");
|
|
10770
|
+
}
|
|
10771
|
+
if (moduleServerUrl) {
|
|
10772
|
+
const resolvedPath = resolveRelativePath(fileDir, rewrittenSpecifier);
|
|
10773
|
+
return `${moduleServerUrl}/${resolvedPath}`;
|
|
10774
|
+
}
|
|
10775
|
+
return rewrittenSpecifier;
|
|
10776
|
+
}
|
|
10777
|
+
return null;
|
|
10778
|
+
}));
|
|
10779
|
+
}
|
|
10780
|
+
function resolveRelativePath(currentDir, importPath) {
|
|
10781
|
+
const currentParts = currentDir.split("/").filter(Boolean);
|
|
10782
|
+
const importParts = importPath.split("/").filter(Boolean);
|
|
10783
|
+
const resolvedParts = [...currentParts];
|
|
10784
|
+
for (const part of importParts) {
|
|
10785
|
+
if (part === "..") {
|
|
10786
|
+
resolvedParts.pop();
|
|
10787
|
+
} else if (part !== ".") {
|
|
10788
|
+
resolvedParts.push(part);
|
|
10789
|
+
}
|
|
10790
|
+
}
|
|
10791
|
+
return resolvedParts.join("/");
|
|
10792
|
+
}
|
|
10793
|
+
function resolveRelativeImportsForSSR(code) {
|
|
10794
|
+
return Promise.resolve(replaceSpecifiers(code, (specifier) => {
|
|
10795
|
+
if (specifier.startsWith("./") || specifier.startsWith("../")) {
|
|
10796
|
+
if (/\.(js|mjs|cjs)$/.test(specifier)) {
|
|
10797
|
+
return null;
|
|
10798
|
+
}
|
|
10799
|
+
const withoutExt = specifier.replace(/\.(tsx?|jsx|mdx)$/, "");
|
|
10800
|
+
return withoutExt + ".js";
|
|
10801
|
+
}
|
|
10802
|
+
return null;
|
|
10803
|
+
}));
|
|
10804
|
+
}
|
|
10805
|
+
|
|
10806
|
+
// src/build/transforms/esm/import-rewriter.ts
|
|
10807
|
+
init_deno_env();
|
|
10808
|
+
init_cdn();
|
|
10809
|
+
init_utils();
|
|
10810
|
+
var unversionedImportsWarned = /* @__PURE__ */ new Set();
|
|
10811
|
+
function hasVersionSpecifier(specifier) {
|
|
10812
|
+
return /@[\d^~x][\d.x^~-]*(?=\/|$)/.test(specifier);
|
|
10813
|
+
}
|
|
10814
|
+
function warnUnversionedImport(specifier) {
|
|
10815
|
+
if (unversionedImportsWarned.has(specifier)) {
|
|
10816
|
+
return;
|
|
10817
|
+
}
|
|
10818
|
+
unversionedImportsWarned.add(specifier);
|
|
10819
|
+
const suggestedVersion = "x.y.z";
|
|
10820
|
+
const packageName = specifier.split("/")[0];
|
|
10821
|
+
const isScoped = specifier.startsWith("@");
|
|
10822
|
+
const scopedPackage = isScoped ? specifier.split("/").slice(0, 2).join("/") : packageName;
|
|
10823
|
+
const subpath = isScoped ? specifier.split("/").slice(2).join("/") : specifier.split("/").slice(1).join("/");
|
|
10824
|
+
const versionedSpecifier = subpath ? `${scopedPackage}@${suggestedVersion}/${subpath}` : `${scopedPackage}@${suggestedVersion}`;
|
|
10825
|
+
rendererLogger.warn("[ESM] Unversioned import may cause reproducibility issues", {
|
|
10826
|
+
import: specifier,
|
|
10827
|
+
suggestion: `Pin version: import '${versionedSpecifier}'`,
|
|
10828
|
+
help: "Run 'npm info " + (isScoped ? scopedPackage : packageName) + " version' to find current version"
|
|
10829
|
+
});
|
|
10830
|
+
}
|
|
10831
|
+
function normalizeVersionedSpecifier(specifier) {
|
|
10832
|
+
return specifier.replace(/@[\d^~x][\d.x^~-]*(?=\/|$)/, "");
|
|
10833
|
+
}
|
|
10834
|
+
function rewriteBareImports(code, _moduleServerUrl) {
|
|
10835
|
+
const importMap = {
|
|
10836
|
+
"react": `https://esm.sh/react@${REACT_DEFAULT_VERSION}`,
|
|
10837
|
+
"react-dom": `https://esm.sh/react-dom@${REACT_DEFAULT_VERSION}`,
|
|
10838
|
+
"react-dom/client": `https://esm.sh/react-dom@${REACT_DEFAULT_VERSION}/client`,
|
|
10839
|
+
"react-dom/server": `https://esm.sh/react-dom@${REACT_DEFAULT_VERSION}/server`,
|
|
10840
|
+
"react/jsx-runtime": `https://esm.sh/react@${REACT_DEFAULT_VERSION}/jsx-runtime`,
|
|
10841
|
+
"react/jsx-dev-runtime": `https://esm.sh/react@${REACT_DEFAULT_VERSION}/jsx-dev-runtime`,
|
|
10842
|
+
// React Query must use same URL as HTML import map to avoid multiple module instances
|
|
10843
|
+
"@tanstack/react-query": `https://esm.sh/@tanstack/react-query@5?external=react`
|
|
10844
|
+
// NOTE: veryfront/ai/react is NOT rewritten here - it's handled by the HTML import map
|
|
10845
|
+
// which points to /_veryfront/lib/ai/react.js served from the local package
|
|
10846
|
+
};
|
|
10847
|
+
return Promise.resolve(replaceSpecifiers(code, (specifier) => {
|
|
10848
|
+
if (importMap[specifier]) {
|
|
10849
|
+
return importMap[specifier];
|
|
10850
|
+
}
|
|
10851
|
+
if (specifier.startsWith("http://") || specifier.startsWith("https://") || specifier.startsWith("./") || specifier.startsWith("../") || specifier.startsWith("/") || specifier.startsWith("@/") || // Project alias
|
|
10852
|
+
specifier.startsWith("veryfront")) {
|
|
10853
|
+
return null;
|
|
10854
|
+
}
|
|
10855
|
+
const normalized = normalizeVersionedSpecifier(specifier);
|
|
10856
|
+
let finalSpecifier = normalized;
|
|
10857
|
+
if (normalized === "tailwindcss" || normalized.startsWith("tailwindcss/")) {
|
|
10858
|
+
finalSpecifier = normalized.replace(/^tailwindcss/, `tailwindcss@${TAILWIND_VERSION}`);
|
|
10859
|
+
} else if (!hasVersionSpecifier(specifier)) {
|
|
10860
|
+
warnUnversionedImport(specifier);
|
|
10861
|
+
}
|
|
10862
|
+
return `https://esm.sh/${finalSpecifier}?deps=react@${REACT_DEFAULT_VERSION},react-dom@${REACT_DEFAULT_VERSION}`;
|
|
10863
|
+
}));
|
|
10864
|
+
}
|
|
10865
|
+
async function rewriteVendorImports(code, moduleServerUrl, vendorBundleHash) {
|
|
10866
|
+
const vendorUrl = `${moduleServerUrl}/_vendor.js?v=${vendorBundleHash}`;
|
|
10867
|
+
const reactPackages = /* @__PURE__ */ new Set([
|
|
10868
|
+
"react",
|
|
10869
|
+
"react-dom",
|
|
10870
|
+
"react-dom/client",
|
|
10871
|
+
"react-dom/server",
|
|
10872
|
+
"react/jsx-runtime",
|
|
10873
|
+
"react/jsx-dev-runtime"
|
|
10874
|
+
]);
|
|
10875
|
+
let result = await rewriteImports(code, (imp, statement) => {
|
|
10876
|
+
if (!imp.n || !reactPackages.has(imp.n))
|
|
10877
|
+
return null;
|
|
10878
|
+
const trimmed = statement.trimStart();
|
|
10879
|
+
if (!trimmed.startsWith("export"))
|
|
10880
|
+
return null;
|
|
10881
|
+
const specStart = imp.s - imp.ss;
|
|
10882
|
+
const specEnd = imp.e - imp.ss;
|
|
10883
|
+
const before = statement.slice(0, specStart);
|
|
10884
|
+
const after = statement.slice(specEnd);
|
|
10885
|
+
return `${before}${vendorUrl}${after}`;
|
|
10886
|
+
});
|
|
10887
|
+
const baseSource = result;
|
|
10888
|
+
const imports = await parseImports(baseSource);
|
|
10889
|
+
for (let i = imports.length - 1; i >= 0; i--) {
|
|
10890
|
+
const imp = imports[i];
|
|
10891
|
+
if (!imp)
|
|
10892
|
+
continue;
|
|
10893
|
+
if (!imp.n || !reactPackages.has(imp.n))
|
|
10894
|
+
continue;
|
|
10895
|
+
const exportName = sanitizeVendorExportName(imp.n);
|
|
10896
|
+
if (imp.d > -1) {
|
|
10897
|
+
const afterSpecifier = baseSource.substring(imp.e);
|
|
10898
|
+
const match = afterSpecifier.match(/^['"]\s*\)/);
|
|
10899
|
+
if (!match)
|
|
10900
|
+
continue;
|
|
10901
|
+
const endOfCall = imp.e + match[0].length;
|
|
10902
|
+
const before = result.substring(0, imp.d);
|
|
10903
|
+
const after = result.substring(endOfCall);
|
|
10904
|
+
const replacement = `import('${vendorUrl}').then(m => m.${exportName})`;
|
|
10905
|
+
result = before + replacement + after;
|
|
10906
|
+
} else {
|
|
10907
|
+
const beforeSpecifier = baseSource.substring(imp.ss, imp.s);
|
|
10908
|
+
const fromIndex = beforeSpecifier.lastIndexOf("from");
|
|
10909
|
+
if (fromIndex === -1) {
|
|
10910
|
+
const before2 = result.substring(0, imp.ss);
|
|
10911
|
+
const after2 = result.substring(imp.se);
|
|
10912
|
+
result = before2 + `import '${vendorUrl}'` + after2;
|
|
10913
|
+
continue;
|
|
10914
|
+
}
|
|
10915
|
+
const clause = beforeSpecifier.substring(6, fromIndex).trim();
|
|
10916
|
+
let replacement = "";
|
|
10917
|
+
if (clause.startsWith("*")) {
|
|
10918
|
+
replacement = `import ${clause} from '${vendorUrl}'`;
|
|
10919
|
+
} else if (clause.startsWith("{")) {
|
|
10920
|
+
replacement = `import { ${exportName} } from '${vendorUrl}'; const ${clause} = ${exportName}`;
|
|
10921
|
+
} else {
|
|
10922
|
+
replacement = `import { ${exportName} as ${clause} } from '${vendorUrl}'`;
|
|
10923
|
+
}
|
|
10924
|
+
const before = result.substring(0, imp.ss);
|
|
10925
|
+
const after = result.substring(imp.se);
|
|
10926
|
+
result = before + replacement + after;
|
|
10927
|
+
}
|
|
10928
|
+
}
|
|
10929
|
+
return result;
|
|
10930
|
+
}
|
|
10931
|
+
function sanitizeVendorExportName(pkg) {
|
|
10932
|
+
return pkg.replace(/^@/, "").replace(/[\/\-]/g, "_").replace(/_([a-z])/g, (_, letter) => letter.toUpperCase()).replace(/^_/, "");
|
|
10933
|
+
}
|
|
10934
|
+
|
|
10935
|
+
// src/build/transforms/mdx/compiler/mdx-compiler.ts
|
|
10936
|
+
init_deno_env();
|
|
10937
|
+
init_utils();
|
|
10938
|
+
|
|
10939
|
+
// src/build/transforms/plugins/plugin-loader.ts
|
|
10940
|
+
init_deno_env();
|
|
10941
|
+
init_config();
|
|
10942
|
+
init_utils();
|
|
10943
|
+
|
|
10944
|
+
// src/build/transforms/plugins/rehype-utils.ts
|
|
10945
|
+
init_deno_env();
|
|
10946
|
+
import { visit } from "unist-util-visit";
|
|
10947
|
+
function rehypePreserveNodeIds() {
|
|
10948
|
+
return (tree) => {
|
|
10949
|
+
visit(tree, "element", (node) => {
|
|
10950
|
+
if (!node.properties) {
|
|
10951
|
+
node.properties = {};
|
|
10952
|
+
}
|
|
10953
|
+
if (node.data && node.data.hProperties) {
|
|
10954
|
+
Object.entries(
|
|
10955
|
+
node.data.hProperties
|
|
10956
|
+
).forEach(([key, value]) => {
|
|
10957
|
+
if (key.startsWith("data-node-")) {
|
|
10958
|
+
node.properties[key] = value;
|
|
10959
|
+
}
|
|
10960
|
+
});
|
|
10961
|
+
}
|
|
10962
|
+
});
|
|
10963
|
+
};
|
|
10964
|
+
}
|
|
10965
|
+
function rehypeAddClasses() {
|
|
10966
|
+
return (tree) => {
|
|
10967
|
+
visit(tree, "element", (node) => {
|
|
10968
|
+
if (!node.properties) {
|
|
10969
|
+
node.properties = {};
|
|
10970
|
+
}
|
|
10971
|
+
switch (node.tagName) {
|
|
10972
|
+
case "p":
|
|
10973
|
+
addClassName(node, "mb-4");
|
|
10974
|
+
break;
|
|
10975
|
+
case "h1":
|
|
10976
|
+
addClassName(node, "text-4xl font-bold mb-8 mt-12");
|
|
10977
|
+
break;
|
|
10978
|
+
case "h2":
|
|
10979
|
+
addClassName(node, "text-3xl font-bold mb-6 mt-10");
|
|
10980
|
+
break;
|
|
10981
|
+
case "h3":
|
|
10982
|
+
addClassName(node, "text-2xl font-bold mb-4 mt-8");
|
|
10983
|
+
break;
|
|
10984
|
+
case "a":
|
|
10985
|
+
addClassName(node, "text-blue-600 hover:text-blue-800 underline");
|
|
10986
|
+
break;
|
|
10987
|
+
case "code":
|
|
10988
|
+
if (Array.isArray(node.properties.className) && node.properties.className.some((cls) => String(cls).includes("language-"))) {
|
|
10989
|
+
addClassName(node, "block p-4 bg-gray-900 text-gray-100 rounded-lg overflow-x-auto");
|
|
10990
|
+
} else {
|
|
10991
|
+
addClassName(node, "px-1 py-0.5 bg-gray-100 text-gray-900 rounded text-sm");
|
|
10992
|
+
}
|
|
10993
|
+
break;
|
|
10994
|
+
case "blockquote":
|
|
10995
|
+
addClassName(node, "border-l-4 border-gray-300 pl-4 italic");
|
|
10996
|
+
break;
|
|
10997
|
+
case "ul":
|
|
10998
|
+
addClassName(node, "list-disc list-inside mb-4");
|
|
10999
|
+
break;
|
|
11000
|
+
case "ol":
|
|
11001
|
+
addClassName(node, "list-decimal list-inside mb-4");
|
|
11002
|
+
break;
|
|
11003
|
+
case "li":
|
|
11004
|
+
addClassName(node, "mb-2");
|
|
11005
|
+
break;
|
|
11006
|
+
}
|
|
11007
|
+
});
|
|
11008
|
+
};
|
|
11009
|
+
}
|
|
11010
|
+
function rehypeMdxComponents() {
|
|
11011
|
+
return (tree) => {
|
|
11012
|
+
visit(tree, "mdxJsxFlowElement", (node) => {
|
|
11013
|
+
if (!node.data) {
|
|
11014
|
+
node.data = {};
|
|
11015
|
+
}
|
|
11016
|
+
if (!node.data.hProperties) {
|
|
11017
|
+
node.data.hProperties = {};
|
|
11018
|
+
}
|
|
11019
|
+
node.data.hProperties["data-mdx-component"] = node.name;
|
|
11020
|
+
});
|
|
11021
|
+
};
|
|
11022
|
+
}
|
|
11023
|
+
function addClassName(node, className) {
|
|
11024
|
+
if (!node.properties) {
|
|
11025
|
+
node.properties = {};
|
|
11026
|
+
}
|
|
11027
|
+
if (!node.properties.className) {
|
|
11028
|
+
node.properties.className = [];
|
|
11029
|
+
} else if (typeof node.properties.className === "string") {
|
|
11030
|
+
node.properties.className = node.properties.className.split(" ");
|
|
11031
|
+
}
|
|
11032
|
+
node.properties.className.push(className);
|
|
11033
|
+
}
|
|
11034
|
+
|
|
11035
|
+
// src/build/transforms/plugins/remark-headings.ts
|
|
11036
|
+
init_deno_env();
|
|
11037
|
+
import GithubSlugger from "github-slugger";
|
|
11038
|
+
import { toString } from "mdast-util-to-string";
|
|
11039
|
+
import { visit as visit2 } from "unist-util-visit";
|
|
11040
|
+
function remarkMdxHeadings() {
|
|
11041
|
+
const slugger = new GithubSlugger();
|
|
11042
|
+
return (tree, file) => {
|
|
11043
|
+
const headings = [];
|
|
11044
|
+
slugger.reset();
|
|
11045
|
+
visit2(tree, "heading", (node) => {
|
|
11046
|
+
const text = toString(node);
|
|
11047
|
+
const id = slugger.slug(text);
|
|
11048
|
+
if (!node.data) {
|
|
11049
|
+
node.data = {};
|
|
11050
|
+
}
|
|
11051
|
+
if (!node.data.hProperties) {
|
|
11052
|
+
node.data.hProperties = {};
|
|
11053
|
+
}
|
|
11054
|
+
node.data.hProperties.id = id;
|
|
11055
|
+
headings.push({
|
|
11056
|
+
text,
|
|
11057
|
+
id,
|
|
11058
|
+
level: node.depth
|
|
11059
|
+
});
|
|
11060
|
+
});
|
|
11061
|
+
if (!file.data) {
|
|
11062
|
+
file.data = {};
|
|
11063
|
+
}
|
|
11064
|
+
file.data.headings = headings;
|
|
11065
|
+
const headingsExport = {
|
|
11066
|
+
type: "mdxjsEsm",
|
|
11067
|
+
value: "",
|
|
11068
|
+
data: {
|
|
11069
|
+
estree: {
|
|
11070
|
+
type: "Program",
|
|
11071
|
+
sourceType: "module",
|
|
11072
|
+
body: [
|
|
11073
|
+
{
|
|
11074
|
+
type: "ExportNamedDeclaration",
|
|
11075
|
+
specifiers: [],
|
|
11076
|
+
source: null,
|
|
11077
|
+
declaration: {
|
|
11078
|
+
type: "VariableDeclaration",
|
|
11079
|
+
kind: "const",
|
|
11080
|
+
declarations: [
|
|
11081
|
+
{
|
|
11082
|
+
type: "VariableDeclarator",
|
|
11083
|
+
id: { type: "Identifier", name: "headings" },
|
|
11084
|
+
init: {
|
|
11085
|
+
type: "ArrayExpression",
|
|
11086
|
+
elements: headings.map((h) => ({
|
|
11087
|
+
type: "ObjectExpression",
|
|
11088
|
+
properties: [
|
|
11089
|
+
{
|
|
11090
|
+
type: "Property",
|
|
11091
|
+
key: { type: "Identifier", name: "text" },
|
|
11092
|
+
value: { type: "Literal", value: h.text },
|
|
11093
|
+
kind: "init",
|
|
11094
|
+
method: false,
|
|
11095
|
+
shorthand: false,
|
|
11096
|
+
computed: false
|
|
11097
|
+
},
|
|
11098
|
+
{
|
|
11099
|
+
type: "Property",
|
|
11100
|
+
key: { type: "Identifier", name: "id" },
|
|
11101
|
+
value: { type: "Literal", value: h.id },
|
|
11102
|
+
kind: "init",
|
|
11103
|
+
method: false,
|
|
11104
|
+
shorthand: false,
|
|
11105
|
+
computed: false
|
|
11106
|
+
},
|
|
11107
|
+
{
|
|
11108
|
+
type: "Property",
|
|
11109
|
+
key: { type: "Identifier", name: "level" },
|
|
11110
|
+
value: { type: "Literal", value: h.level },
|
|
11111
|
+
kind: "init",
|
|
11112
|
+
method: false,
|
|
11113
|
+
shorthand: false,
|
|
11114
|
+
computed: false
|
|
11115
|
+
}
|
|
11116
|
+
]
|
|
11117
|
+
}))
|
|
11118
|
+
}
|
|
11119
|
+
}
|
|
11120
|
+
]
|
|
11121
|
+
}
|
|
11122
|
+
}
|
|
11123
|
+
]
|
|
11124
|
+
}
|
|
11125
|
+
}
|
|
11126
|
+
};
|
|
11127
|
+
tree.children.unshift(headingsExport);
|
|
11128
|
+
};
|
|
11129
|
+
}
|
|
11130
|
+
|
|
11131
|
+
// src/build/transforms/plugins/plugin-loader.ts
|
|
11132
|
+
init_veryfront_error();
|
|
11133
|
+
|
|
11134
|
+
// src/build/transforms/plugins/remark-mdx-utils.ts
|
|
11135
|
+
init_deno_env();
|
|
11136
|
+
import { visit as visit3 } from "unist-util-visit";
|
|
11137
|
+
function remarkMdxRemoveParagraphs() {
|
|
11138
|
+
return (tree) => {
|
|
11139
|
+
visit3(
|
|
11140
|
+
tree,
|
|
11141
|
+
"paragraph",
|
|
11142
|
+
(node, index, parent) => {
|
|
11143
|
+
const children = Array.isArray(node?.children) ? node.children : [];
|
|
11144
|
+
if (children.length === 1 && (children[0]?.type === "mdxJsxTextElement" || children[0]?.type === "mdxJsxFlowElement")) {
|
|
11145
|
+
if (parent && Array.isArray(parent.children) && typeof index === "number") {
|
|
11146
|
+
parent.children.splice(index, 1, children[0]);
|
|
11147
|
+
}
|
|
11148
|
+
}
|
|
11149
|
+
}
|
|
11150
|
+
);
|
|
11151
|
+
};
|
|
11152
|
+
}
|
|
11153
|
+
function remarkCodeBlocks() {
|
|
11154
|
+
return (tree) => {
|
|
11155
|
+
visit3(tree, "code", (node) => {
|
|
11156
|
+
if (!node.data) {
|
|
11157
|
+
node.data = {};
|
|
11158
|
+
}
|
|
11159
|
+
if (!node.data.hProperties) {
|
|
11160
|
+
node.data.hProperties = {};
|
|
11161
|
+
}
|
|
11162
|
+
if (node.lang) {
|
|
11163
|
+
node.data.hProperties.className = [`language-${node.lang}`];
|
|
11164
|
+
}
|
|
11165
|
+
if (node.meta) {
|
|
11166
|
+
const highlightMatch = node.meta.match(/\{([\d,-]+)\}/);
|
|
11167
|
+
if (highlightMatch) {
|
|
11168
|
+
node.data.hProperties["data-line-numbers"] = highlightMatch[1];
|
|
11169
|
+
}
|
|
11170
|
+
}
|
|
11171
|
+
});
|
|
11172
|
+
};
|
|
11173
|
+
}
|
|
11174
|
+
function remarkMdxImports() {
|
|
11175
|
+
return (tree, file) => {
|
|
11176
|
+
const imports = [];
|
|
11177
|
+
visit3(tree, "mdxjsEsm", (node) => {
|
|
11178
|
+
if (node.value?.includes("import")) {
|
|
11179
|
+
const importMatches = node.value.matchAll(
|
|
11180
|
+
/import\s+(?:(?:\{[^}]*\}|\*\s+as\s+\w+|\w+)\s+from\s+)?['"]([^'"]+)['"]/g
|
|
11181
|
+
);
|
|
11182
|
+
for (const match of importMatches) {
|
|
11183
|
+
const path = match[1];
|
|
11184
|
+
if (typeof path === "string")
|
|
11185
|
+
imports.push(path);
|
|
11186
|
+
}
|
|
11187
|
+
}
|
|
11188
|
+
});
|
|
11189
|
+
if (!file.data) {
|
|
11190
|
+
file.data = {};
|
|
11191
|
+
}
|
|
11192
|
+
file.data.imports = imports;
|
|
11193
|
+
};
|
|
11194
|
+
}
|
|
11195
|
+
|
|
11196
|
+
// src/build/transforms/plugins/remark-node-id.ts
|
|
11197
|
+
init_deno_env();
|
|
11198
|
+
import { visit as visit4 } from "unist-util-visit";
|
|
11199
|
+
function remarkAddNodeId(options = {}) {
|
|
11200
|
+
const { prefix = "node", includePosition = true } = options;
|
|
11201
|
+
return (tree, file) => {
|
|
11202
|
+
let nodeId = 0;
|
|
11203
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
11204
|
+
visit4(tree, (node) => {
|
|
11205
|
+
if (["yaml", "toml", "mdxjsEsm", "mdxjsFlow"].includes(String(node.type))) {
|
|
11206
|
+
return;
|
|
11207
|
+
}
|
|
11208
|
+
if (!node.data) {
|
|
11209
|
+
node.data = {};
|
|
11210
|
+
}
|
|
11211
|
+
if (!node.data.hProperties) {
|
|
11212
|
+
node.data.hProperties = {};
|
|
11213
|
+
}
|
|
11214
|
+
const id = `${prefix}-${nodeId}`;
|
|
11215
|
+
node.data.hProperties["data-node-id"] = id;
|
|
11216
|
+
if (includePosition && node.position) {
|
|
11217
|
+
const pos = node.position;
|
|
11218
|
+
node.data.hProperties["data-node-start"] = pos.start.offset;
|
|
11219
|
+
node.data.hProperties["data-node-end"] = pos.end.offset;
|
|
11220
|
+
node.data.hProperties["data-node-line"] = pos.start.line;
|
|
11221
|
+
node.data.hProperties["data-node-column"] = pos.start.column;
|
|
11222
|
+
node.data.hProperties["data-node-end-line"] = pos.end.line;
|
|
11223
|
+
node.data.hProperties["data-node-end-column"] = pos.end.column;
|
|
11224
|
+
}
|
|
11225
|
+
nodeMap.set(nodeId, {
|
|
11226
|
+
id,
|
|
11227
|
+
type: node.type,
|
|
11228
|
+
position: node.position,
|
|
11229
|
+
value: node.value
|
|
11230
|
+
});
|
|
11231
|
+
nodeId++;
|
|
11232
|
+
});
|
|
11233
|
+
if (!file.data) {
|
|
11234
|
+
file.data = {};
|
|
11235
|
+
}
|
|
11236
|
+
file.data.nodeMap = nodeMap;
|
|
11237
|
+
file.data.nodeCount = nodeId;
|
|
11238
|
+
};
|
|
11239
|
+
}
|
|
11240
|
+
|
|
11241
|
+
// src/build/transforms/plugins/rehype-mermaid.ts
|
|
11242
|
+
init_deno_env();
|
|
11243
|
+
import { visit as visit5 } from "unist-util-visit";
|
|
11244
|
+
function rehypeMermaid() {
|
|
11245
|
+
return (tree) => {
|
|
11246
|
+
visit5(tree, "element", (node, index, parent) => {
|
|
11247
|
+
const firstChild = node.children[0];
|
|
11248
|
+
if (node.tagName === "pre" && node.children.length === 1 && firstChild && firstChild.type === "element" && firstChild.tagName === "code") {
|
|
11249
|
+
const codeNode = node.children[0];
|
|
11250
|
+
const className = codeNode.properties?.className;
|
|
11251
|
+
const isMermaid = Array.isArray(className) ? className.some(
|
|
11252
|
+
(c) => String(c).includes("mermaid") || String(c).includes("language-mermaid")
|
|
11253
|
+
) : String(className || "").includes("mermaid");
|
|
11254
|
+
if (isMermaid && parent && typeof index === "number") {
|
|
11255
|
+
const textContent = extractText(codeNode);
|
|
11256
|
+
const mermaidDiv = {
|
|
11257
|
+
type: "element",
|
|
11258
|
+
tagName: "div",
|
|
11259
|
+
properties: {
|
|
11260
|
+
className: ["mermaid"]
|
|
11261
|
+
},
|
|
11262
|
+
children: [{ type: "text", value: textContent }]
|
|
11263
|
+
};
|
|
11264
|
+
parent.children[index] = mermaidDiv;
|
|
11265
|
+
}
|
|
11266
|
+
}
|
|
11267
|
+
});
|
|
11268
|
+
};
|
|
11269
|
+
}
|
|
11270
|
+
function extractText(node) {
|
|
11271
|
+
let text = "";
|
|
11272
|
+
for (const child of node.children) {
|
|
11273
|
+
if (child.type === "text") {
|
|
11274
|
+
text += child.value;
|
|
11275
|
+
} else if (child.type === "element") {
|
|
11276
|
+
text += extractText(child);
|
|
11277
|
+
}
|
|
11278
|
+
}
|
|
11279
|
+
return text.trim();
|
|
11280
|
+
}
|
|
11281
|
+
|
|
11282
|
+
// src/build/transforms/plugins/plugin-loader.ts
|
|
11283
|
+
import remarkGfm from "remark-gfm";
|
|
11284
|
+
import remarkFrontmatter from "remark-frontmatter";
|
|
11285
|
+
import rehypeHighlight from "rehype-highlight";
|
|
11286
|
+
import rehypeSlug from "rehype-slug";
|
|
11287
|
+
async function loadUserPlugins(projectDir, adapter, pluginType) {
|
|
11288
|
+
try {
|
|
11289
|
+
const _config = await getConfig(projectDir, adapter);
|
|
11290
|
+
return [];
|
|
11291
|
+
} catch (error) {
|
|
11292
|
+
serverLogger.warn(
|
|
11293
|
+
`Failed to load ${pluginType} plugins from config`,
|
|
11294
|
+
{ error: error instanceof Error ? error.message : String(error) }
|
|
11295
|
+
);
|
|
11296
|
+
return [];
|
|
11297
|
+
}
|
|
11298
|
+
}
|
|
11299
|
+
async function getRemarkPlugins(projectDir, adapter) {
|
|
11300
|
+
const defaultPlugins = [
|
|
11301
|
+
remarkGfm,
|
|
11302
|
+
remarkFrontmatter,
|
|
11303
|
+
remarkAddNodeId,
|
|
11304
|
+
remarkMdxHeadings,
|
|
11305
|
+
remarkMdxRemoveParagraphs,
|
|
11306
|
+
remarkCodeBlocks,
|
|
11307
|
+
remarkMdxImports
|
|
11308
|
+
];
|
|
11309
|
+
if (adapter) {
|
|
11310
|
+
try {
|
|
11311
|
+
const userPlugins = await loadUserPlugins(projectDir, adapter, "remark");
|
|
11312
|
+
return [...defaultPlugins, ...userPlugins];
|
|
11313
|
+
} catch (error) {
|
|
11314
|
+
serverLogger.error(
|
|
11315
|
+
"Error loading user remark plugins",
|
|
11316
|
+
{ error: error instanceof Error ? error.message : String(error) }
|
|
11317
|
+
);
|
|
11318
|
+
}
|
|
11319
|
+
}
|
|
11320
|
+
return defaultPlugins;
|
|
11321
|
+
}
|
|
11322
|
+
async function getRehypePlugins(projectDir, adapter) {
|
|
11323
|
+
const defaultPlugins = [
|
|
11324
|
+
rehypeMermaid,
|
|
11325
|
+
// Must run before rehypeHighlight
|
|
11326
|
+
rehypeHighlight,
|
|
11327
|
+
rehypeSlug,
|
|
11328
|
+
rehypePreserveNodeIds,
|
|
11329
|
+
rehypeAddClasses,
|
|
11330
|
+
rehypeMdxComponents
|
|
11331
|
+
];
|
|
11332
|
+
if (adapter) {
|
|
11333
|
+
try {
|
|
11334
|
+
const userPlugins = await loadUserPlugins(projectDir, adapter, "rehype");
|
|
11335
|
+
return [...defaultPlugins, ...userPlugins];
|
|
11336
|
+
} catch (error) {
|
|
11337
|
+
serverLogger.error(
|
|
11338
|
+
"Error loading user rehype plugins",
|
|
11339
|
+
{ error: error instanceof Error ? error.message : String(error) }
|
|
11340
|
+
);
|
|
11341
|
+
}
|
|
11342
|
+
}
|
|
11343
|
+
return defaultPlugins;
|
|
11344
|
+
}
|
|
11345
|
+
|
|
11346
|
+
// src/build/transforms/mdx/compiler/frontmatter-extractor.ts
|
|
11347
|
+
init_deno_env();
|
|
11348
|
+
init_utils();
|
|
11349
|
+
async function extractYamlFrontmatter(content) {
|
|
11350
|
+
if (!content.trim().startsWith("---")) {
|
|
11351
|
+
return { body: content, frontmatter: {} };
|
|
11352
|
+
}
|
|
11353
|
+
const { extract } = await import("gray-matter");
|
|
11354
|
+
const extracted = extract(content);
|
|
11355
|
+
return {
|
|
11356
|
+
body: extracted.body,
|
|
11357
|
+
frontmatter: extracted.attrs
|
|
11358
|
+
};
|
|
11359
|
+
}
|
|
11360
|
+
function extractExportConstants(body) {
|
|
11361
|
+
const exportRegex = /^export\s+const\s+(\w+)\s*=\s*(['"`][^'"`\n]*['"`]|\d+(?:\.\d+)?|true|false|null)\s*;?\s*$/gm;
|
|
11362
|
+
const exports = {};
|
|
11363
|
+
const linesToRemove = [];
|
|
11364
|
+
let match;
|
|
11365
|
+
while ((match = exportRegex.exec(body)) !== null) {
|
|
11366
|
+
const key = match[1];
|
|
11367
|
+
const rawValue = match[2];
|
|
11368
|
+
if (key && key.length > 0 && rawValue) {
|
|
11369
|
+
linesToRemove.push(match[0]);
|
|
11370
|
+
if (rawValue === "true") {
|
|
11371
|
+
exports[key] = true;
|
|
11372
|
+
} else if (rawValue === "false") {
|
|
11373
|
+
exports[key] = false;
|
|
11374
|
+
} else if (rawValue === "null") {
|
|
11375
|
+
exports[key] = null;
|
|
11376
|
+
} else if (/^\d+(?:\.\d+)?$/.test(rawValue)) {
|
|
11377
|
+
exports[key] = parseFloat(rawValue);
|
|
11378
|
+
} else {
|
|
11379
|
+
exports[key] = rawValue.replace(/^['"`]|['"`]$/g, "");
|
|
11380
|
+
}
|
|
11381
|
+
}
|
|
11382
|
+
}
|
|
11383
|
+
let cleanedBody = body;
|
|
11384
|
+
for (const line of linesToRemove) {
|
|
11385
|
+
cleanedBody = cleanedBody.replace(line, "");
|
|
11386
|
+
}
|
|
11387
|
+
return { body: cleanedBody, exports };
|
|
11388
|
+
}
|
|
11389
|
+
async function extractFrontmatter(content, providedFrontmatter) {
|
|
11390
|
+
let body = content;
|
|
11391
|
+
let frontmatter = {};
|
|
11392
|
+
if (content.trim().startsWith("---")) {
|
|
11393
|
+
const yamlResult = await extractYamlFrontmatter(content);
|
|
11394
|
+
body = yamlResult.body;
|
|
11395
|
+
frontmatter = yamlResult.frontmatter;
|
|
11396
|
+
}
|
|
11397
|
+
if (providedFrontmatter) {
|
|
11398
|
+
frontmatter = { ...frontmatter, ...providedFrontmatter };
|
|
11399
|
+
}
|
|
11400
|
+
const exportResult = extractExportConstants(body);
|
|
11401
|
+
body = exportResult.body;
|
|
11402
|
+
frontmatter = { ...frontmatter, ...exportResult.exports };
|
|
11403
|
+
rendererLogger.info("Extracted frontmatter:", frontmatter);
|
|
11404
|
+
return { body, frontmatter };
|
|
11405
|
+
}
|
|
11406
|
+
|
|
11407
|
+
// src/build/transforms/mdx/compiler/import-rewriter.ts
|
|
11408
|
+
init_deno_env();
|
|
11409
|
+
import { dirname as dirname3, join as join4, resolve as pathResolve } from "node:path";
|
|
11410
|
+
function toAbsPath(spec, basedir) {
|
|
11411
|
+
try {
|
|
11412
|
+
if (spec.startsWith("file://"))
|
|
11413
|
+
return new URL(spec).pathname;
|
|
11414
|
+
if (spec.startsWith("/"))
|
|
11415
|
+
return pathResolve(spec);
|
|
11416
|
+
if (spec.startsWith("http://") || spec.startsWith("https://"))
|
|
11417
|
+
return spec;
|
|
11418
|
+
if (!spec.startsWith(".") && !spec.startsWith("/")) {
|
|
11419
|
+
return spec;
|
|
11420
|
+
}
|
|
11421
|
+
return pathResolve(join4(basedir, spec));
|
|
11422
|
+
} catch {
|
|
11423
|
+
return spec;
|
|
11424
|
+
}
|
|
11425
|
+
}
|
|
11426
|
+
function toBrowserFs(abs, baseUrl) {
|
|
11427
|
+
if (abs.startsWith("http://") || abs.startsWith("https://"))
|
|
11428
|
+
return abs;
|
|
11429
|
+
const b64 = btoa(abs).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
|
|
11430
|
+
const path = `/_veryfront/fs/${b64}.js`;
|
|
11431
|
+
return baseUrl ? `${baseUrl}${path}` : path;
|
|
11432
|
+
}
|
|
11433
|
+
function mapSpec(spec, basedir, target, baseUrl, _projectDir) {
|
|
11434
|
+
if (spec.startsWith("@/")) {
|
|
11435
|
+
const relativePath = spec.slice(2);
|
|
11436
|
+
if (target === "browser") {
|
|
11437
|
+
const path = `/_vf_modules/${relativePath}.js`;
|
|
11438
|
+
return baseUrl ? `${baseUrl}${path}` : path;
|
|
11439
|
+
} else {
|
|
11440
|
+
return spec;
|
|
11441
|
+
}
|
|
11442
|
+
}
|
|
11443
|
+
const abs = toAbsPath(spec, basedir);
|
|
11444
|
+
if (typeof abs !== "string")
|
|
11445
|
+
return spec;
|
|
11446
|
+
if (abs === spec && !spec.startsWith(".") && !spec.startsWith("/") && !spec.startsWith("file://") && !spec.startsWith("http")) {
|
|
11447
|
+
return spec;
|
|
11448
|
+
}
|
|
11449
|
+
if (target === "browser")
|
|
11450
|
+
return toBrowserFs(abs, baseUrl);
|
|
11451
|
+
return abs.startsWith("http") ? abs : `file://${abs}`;
|
|
11452
|
+
}
|
|
11453
|
+
function rewriteLine(line, basedir, target, baseUrl, projectDir) {
|
|
11454
|
+
const mapper = (spec) => mapSpec(spec, basedir, target, baseUrl, projectDir);
|
|
11455
|
+
line = line.replace(
|
|
11456
|
+
/^(\s*import\s+[^'";]+?from\s+)(["'])([^"']+)(\2)/,
|
|
11457
|
+
(_m, p1, q, s, q2) => `${p1}${q}${mapper(s)}${q2}`
|
|
11458
|
+
);
|
|
11459
|
+
line = line.replace(
|
|
11460
|
+
/^(\s*import\s+)(["'])([^"']+)(\2)/,
|
|
11461
|
+
(_m, p1, q, s, q2) => `${p1}${q}${mapper(s)}${q2}`
|
|
11462
|
+
);
|
|
11463
|
+
line = line.replace(
|
|
11464
|
+
/^(\s*export\s+[^'";]+?from\s+)(["'])([^"']+)(\2)/,
|
|
11465
|
+
(_m, p1, q, s, q2) => `${p1}${q}${mapper(s)}${q2}`
|
|
11466
|
+
);
|
|
11467
|
+
return line;
|
|
11468
|
+
}
|
|
11469
|
+
function rewriteBodyImports(body, config) {
|
|
11470
|
+
const basedir = dirname3(config.filePath);
|
|
11471
|
+
return body.split(/\r?\n/).map((ln) => {
|
|
11472
|
+
const trimmed = ln.trimStart();
|
|
11473
|
+
if (trimmed.startsWith("import") || trimmed.startsWith("export")) {
|
|
11474
|
+
return rewriteLine(ln, basedir, config.target, config.baseUrl, config.projectDir);
|
|
11475
|
+
}
|
|
11476
|
+
return ln;
|
|
11477
|
+
}).join("\n");
|
|
11478
|
+
}
|
|
11479
|
+
function rewriteCompiledImports(compiledCode, config) {
|
|
11480
|
+
const basedir = dirname3(config.filePath);
|
|
11481
|
+
const mapper = (spec) => mapSpec(spec, basedir, config.target, config.baseUrl, config.projectDir);
|
|
11482
|
+
let code = compiledCode;
|
|
11483
|
+
code = code.replace(
|
|
11484
|
+
/(from\s+["'])(@\/[^"']+)(["'])/g,
|
|
11485
|
+
(_m, p1, p2, p3) => `${p1}${mapper(p2)}${p3}`
|
|
11486
|
+
);
|
|
11487
|
+
code = code.replace(
|
|
11488
|
+
/(import\(\s*["'])(@\/[^"']+)(["']\s*\))/g,
|
|
11489
|
+
(_m, p1, p2, p3) => `${p1}${mapper(p2)}${p3}`
|
|
11490
|
+
);
|
|
11491
|
+
code = code.replace(
|
|
11492
|
+
/(from\s+["'])(\.{1,2}\/[^"']+)(["'])/g,
|
|
11493
|
+
(_m, p1, p2, p3) => `${p1}${mapper(p2)}${p3}`
|
|
11494
|
+
);
|
|
11495
|
+
code = code.replace(
|
|
11496
|
+
/(from\s+["'])(file:\/\/[^"']+)(["'])/g,
|
|
11497
|
+
(_m, p1, p2, p3) => `${p1}${mapper(p2)}${p3}`
|
|
11498
|
+
);
|
|
11499
|
+
code = code.replace(
|
|
11500
|
+
/(import\(\s*["'])(\.{1,2}\/[^"']+)(["']\s*\))/g,
|
|
11501
|
+
(_m, p1, p2, p3) => `${p1}${mapper(p2)}${p3}`
|
|
11502
|
+
);
|
|
11503
|
+
code = code.replace(
|
|
11504
|
+
/(import\(\s*["'])(file:\/\/[^"']+)(["']\s*\))/g,
|
|
11505
|
+
(_m, p1, p2, p3) => `${p1}${mapper(p2)}${p3}`
|
|
11506
|
+
);
|
|
11507
|
+
code = code.replace(/file:\/\/[A-Za-z0-9_\-./%]+/g, (match) => mapper(match));
|
|
11508
|
+
return code;
|
|
11509
|
+
}
|
|
11510
|
+
|
|
11511
|
+
// src/build/transforms/mdx/compiler/mdx-compiler.ts
|
|
11512
|
+
init_veryfront_error();
|
|
11513
|
+
|
|
11514
|
+
// src/build/transforms/plugins/rehype-node-positions.ts
|
|
11515
|
+
init_deno_env();
|
|
11516
|
+
import { visit as visit6 } from "unist-util-visit";
|
|
11517
|
+
function rehypeNodePositions(options = {}) {
|
|
11518
|
+
console.log("[rehypeNodePositions] Plugin called with options:", options);
|
|
11519
|
+
return (tree) => {
|
|
11520
|
+
console.log(
|
|
11521
|
+
"[rehypeNodePositions] Processing tree, root type:",
|
|
11522
|
+
tree.type,
|
|
11523
|
+
"children:",
|
|
11524
|
+
tree.children?.length
|
|
11525
|
+
);
|
|
11526
|
+
tree.children?.slice(0, 5).forEach((child, i) => {
|
|
11527
|
+
console.log(
|
|
11528
|
+
`[rehypeNodePositions] Child ${i}: type=${child.type}, name=${child.name || child.tagName || "N/A"}`
|
|
11529
|
+
);
|
|
11530
|
+
});
|
|
11531
|
+
let elementCount = 0;
|
|
11532
|
+
let positionCount = 0;
|
|
11533
|
+
visit6(tree, (node) => {
|
|
11534
|
+
if (node.type === "element") {
|
|
11535
|
+
elementCount++;
|
|
11536
|
+
if (node.position) {
|
|
11537
|
+
positionCount++;
|
|
11538
|
+
addPositionAttributes(node, node.properties || (node.properties = {}), options.filePath);
|
|
11539
|
+
}
|
|
11540
|
+
return;
|
|
11541
|
+
}
|
|
11542
|
+
if (node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") {
|
|
11543
|
+
elementCount++;
|
|
11544
|
+
console.log(
|
|
11545
|
+
"[rehypeNodePositions] Found MDX JSX element:",
|
|
11546
|
+
node.name,
|
|
11547
|
+
"position:",
|
|
11548
|
+
node.position ? "yes" : "no"
|
|
11549
|
+
);
|
|
11550
|
+
if (node.position) {
|
|
11551
|
+
positionCount++;
|
|
11552
|
+
if (!node.attributes) {
|
|
11553
|
+
node.attributes = [];
|
|
11554
|
+
}
|
|
11555
|
+
const { start, end } = node.position;
|
|
11556
|
+
if (start) {
|
|
11557
|
+
node.attributes.push(
|
|
11558
|
+
{ type: "mdxJsxAttribute", name: "data-node-line", value: String(start.line) },
|
|
11559
|
+
{
|
|
11560
|
+
type: "mdxJsxAttribute",
|
|
11561
|
+
name: "data-node-column",
|
|
11562
|
+
value: String(start.column - 1)
|
|
11563
|
+
}
|
|
11564
|
+
);
|
|
11565
|
+
}
|
|
11566
|
+
if (end) {
|
|
11567
|
+
node.attributes.push(
|
|
11568
|
+
{ type: "mdxJsxAttribute", name: "data-node-end-line", value: String(end.line) },
|
|
11569
|
+
{
|
|
11570
|
+
type: "mdxJsxAttribute",
|
|
11571
|
+
name: "data-node-end-column",
|
|
11572
|
+
value: String(end.column - 1)
|
|
11573
|
+
}
|
|
11574
|
+
);
|
|
11575
|
+
}
|
|
11576
|
+
if (options.filePath) {
|
|
11577
|
+
node.attributes.push(
|
|
11578
|
+
{ type: "mdxJsxAttribute", name: "data-node-file", value: options.filePath }
|
|
11579
|
+
);
|
|
11580
|
+
}
|
|
11581
|
+
}
|
|
11582
|
+
}
|
|
11583
|
+
});
|
|
11584
|
+
console.log("[rehypeNodePositions] Processed", { elementCount, positionCount });
|
|
11585
|
+
};
|
|
11586
|
+
}
|
|
11587
|
+
function addPositionAttributes(node, properties, filePath) {
|
|
11588
|
+
if (!node.position)
|
|
11589
|
+
return;
|
|
11590
|
+
const { start, end } = node.position;
|
|
11591
|
+
if (start) {
|
|
11592
|
+
properties["data-node-line"] = start.line;
|
|
11593
|
+
properties["data-node-column"] = start.column - 1;
|
|
11594
|
+
}
|
|
11595
|
+
if (end) {
|
|
11596
|
+
properties["data-node-end-line"] = end.line;
|
|
11597
|
+
properties["data-node-end-column"] = end.column - 1;
|
|
11598
|
+
}
|
|
11599
|
+
if (filePath) {
|
|
11600
|
+
properties["data-node-file"] = filePath;
|
|
11601
|
+
}
|
|
11602
|
+
}
|
|
11603
|
+
|
|
11604
|
+
// src/build/transforms/mdx/compiler/mdx-compiler.ts
|
|
11605
|
+
async function compileMDXRuntime(mode, projectDir, content, frontmatter, filePath, target = "server", baseUrl) {
|
|
11606
|
+
try {
|
|
11607
|
+
const { compile } = await import("@mdx-js/mdx");
|
|
11608
|
+
const remarkPlugins = await getRemarkPlugins(projectDir);
|
|
11609
|
+
const rehypePlugins = await getRehypePlugins(projectDir);
|
|
11610
|
+
const extracted = await extractFrontmatter(content, frontmatter);
|
|
11611
|
+
let { body } = extracted;
|
|
11612
|
+
const { frontmatter: extractedFrontmatter } = extracted;
|
|
11613
|
+
if (filePath && (target === "browser" || target === "server")) {
|
|
11614
|
+
body = rewriteBodyImports(body, { filePath, target, baseUrl, projectDir });
|
|
11615
|
+
}
|
|
11616
|
+
const allRehypePlugins = [
|
|
11617
|
+
...rehypePlugins,
|
|
11618
|
+
[rehypeNodePositions, { filePath }]
|
|
11619
|
+
];
|
|
11620
|
+
const compiled = await compile(body, {
|
|
11621
|
+
outputFormat: "program",
|
|
11622
|
+
development: mode === "development",
|
|
11623
|
+
remarkPlugins,
|
|
11624
|
+
rehypePlugins: allRehypePlugins,
|
|
11625
|
+
providerImportSource: void 0,
|
|
11626
|
+
jsxImportSource: "react"
|
|
11627
|
+
});
|
|
11628
|
+
rendererLogger.info("MDX compiled output preview:", String(compiled).substring(0, 200));
|
|
11629
|
+
rendererLogger.info("Extracted frontmatter:", extractedFrontmatter);
|
|
11630
|
+
let compiledCode = String(compiled);
|
|
11631
|
+
if (filePath && (target === "browser" || target === "server")) {
|
|
11632
|
+
compiledCode = rewriteCompiledImports(compiledCode, {
|
|
11633
|
+
filePath,
|
|
11634
|
+
target,
|
|
11635
|
+
baseUrl,
|
|
11636
|
+
projectDir
|
|
11637
|
+
});
|
|
11638
|
+
}
|
|
11639
|
+
return {
|
|
11640
|
+
compiledCode,
|
|
11641
|
+
frontmatter: extractedFrontmatter,
|
|
11642
|
+
globals: {},
|
|
11643
|
+
headings: [],
|
|
11644
|
+
nodeMap: /* @__PURE__ */ new Map()
|
|
11645
|
+
};
|
|
11646
|
+
} catch (error) {
|
|
11647
|
+
rendererLogger.error("[MDX Compiler] Compilation failed:", {
|
|
11648
|
+
filePath,
|
|
11649
|
+
error: error instanceof Error ? error.message : String(error),
|
|
11650
|
+
stack: error instanceof Error ? error.stack : void 0
|
|
11651
|
+
});
|
|
11652
|
+
throw toError(createError({
|
|
11653
|
+
type: "build",
|
|
11654
|
+
message: `MDX compilation error: ${error instanceof Error ? error.message : String(error)} | file: ${filePath || "<memory>"}`
|
|
11655
|
+
}));
|
|
11656
|
+
}
|
|
11657
|
+
}
|
|
11658
|
+
|
|
11659
|
+
// src/build/transforms/esm/transform-core.ts
|
|
11660
|
+
init_utils();
|
|
11661
|
+
async function transformToESM(source, filePath, projectDir, _adapter, options) {
|
|
11662
|
+
const transformStart = performance.now();
|
|
11663
|
+
const timings2 = {};
|
|
11664
|
+
const {
|
|
11665
|
+
dev = true,
|
|
11666
|
+
projectId,
|
|
11667
|
+
jsxImportSource = "react",
|
|
11668
|
+
moduleServerUrl,
|
|
11669
|
+
vendorBundleHash,
|
|
11670
|
+
ssr = false
|
|
11671
|
+
} = options;
|
|
11672
|
+
const hashStart = performance.now();
|
|
11673
|
+
const contentHash = await computeContentHash2(source);
|
|
11674
|
+
timings2.hash = performance.now() - hashStart;
|
|
11675
|
+
const cacheKey = generateCacheKey(projectId, filePath, contentHash, ssr);
|
|
11676
|
+
const cached = getCachedTransform(cacheKey);
|
|
11677
|
+
if (cached) {
|
|
11678
|
+
return cached.code;
|
|
11679
|
+
}
|
|
11680
|
+
let transformSource = source;
|
|
11681
|
+
if (filePath.endsWith(".mdx")) {
|
|
11682
|
+
const mdxStart = performance.now();
|
|
11683
|
+
const mdxTarget = ssr ? "server" : "browser";
|
|
11684
|
+
const mdxBaseUrl = ssr ? void 0 : moduleServerUrl;
|
|
11685
|
+
const mdxResult = await compileMDXRuntime(
|
|
11686
|
+
dev ? "development" : "production",
|
|
11687
|
+
projectDir,
|
|
11688
|
+
source,
|
|
11689
|
+
void 0,
|
|
11690
|
+
filePath,
|
|
11691
|
+
mdxTarget,
|
|
11692
|
+
mdxBaseUrl
|
|
11693
|
+
);
|
|
11694
|
+
transformSource = mdxResult.compiledCode;
|
|
11695
|
+
timings2.mdx = performance.now() - mdxStart;
|
|
11696
|
+
}
|
|
11697
|
+
const esbuildStart = performance.now();
|
|
11698
|
+
const loader = getLoaderFromPath(filePath);
|
|
11699
|
+
let result;
|
|
11700
|
+
try {
|
|
11701
|
+
result = await esbuild.transform(transformSource, {
|
|
11702
|
+
loader,
|
|
11703
|
+
format: "esm",
|
|
11704
|
+
target: "es2020",
|
|
11705
|
+
jsx: "automatic",
|
|
11706
|
+
jsxImportSource,
|
|
11707
|
+
minify: !dev,
|
|
11708
|
+
sourcemap: dev ? "inline" : false,
|
|
11709
|
+
treeShaking: !dev,
|
|
11710
|
+
// Disable in dev mode to preserve import errors
|
|
11711
|
+
keepNames: true
|
|
11712
|
+
});
|
|
11713
|
+
} catch (transformError) {
|
|
11714
|
+
const sourcePreview = transformSource.split("\n").slice(0, 10).map(
|
|
11715
|
+
(line, i) => `${String(i + 1).padStart(3, " ")}| ${line}`
|
|
11716
|
+
).join("\n");
|
|
11717
|
+
rendererLogger.error("[ESM-TRANSFORM] Transform failed", {
|
|
11718
|
+
filePath,
|
|
11719
|
+
loader,
|
|
11720
|
+
sourceLength: transformSource.length,
|
|
11721
|
+
isMdx: filePath.endsWith(".mdx"),
|
|
11722
|
+
error: transformError instanceof Error ? transformError.message : String(transformError)
|
|
11723
|
+
});
|
|
11724
|
+
rendererLogger.error("[ESM-TRANSFORM] Source preview (first 10 lines):\n" + sourcePreview);
|
|
11725
|
+
const errorMsg = transformError instanceof Error ? transformError.message : String(transformError);
|
|
11726
|
+
throw new Error(`ESM transform failed for ${filePath} (loader: ${loader}): ${errorMsg}`);
|
|
11727
|
+
}
|
|
11728
|
+
timings2.esbuild = performance.now() - esbuildStart;
|
|
11729
|
+
const rewriteStart = performance.now();
|
|
11730
|
+
let code = result.code;
|
|
11731
|
+
code = await resolveReactImports(code, ssr);
|
|
11732
|
+
code = await addDepsToEsmShUrls(code, ssr);
|
|
11733
|
+
code = await resolvePathAliases(code, filePath, projectDir, ssr);
|
|
11734
|
+
const apiBaseUrl = options.apiBaseUrl || Deno.env.get("VERYFRONT_API_BASE_URL") || Deno.env.get("VERYFRONT_API_URL")?.replace("/graphql", "/api") || "http://api.lvh.me:4000/api";
|
|
11735
|
+
code = await resolveCrossProjectImports(code, {
|
|
11736
|
+
apiBaseUrl,
|
|
11737
|
+
ssr
|
|
11738
|
+
});
|
|
11739
|
+
if (ssr) {
|
|
11740
|
+
const urlBlockResult = await blockExternalUrlImports(code, filePath);
|
|
11741
|
+
code = urlBlockResult.code;
|
|
11742
|
+
if (urlBlockResult.blockedUrls.length > 0) {
|
|
11743
|
+
rendererLogger.warn("[ESM-TRANSFORM] Blocked external URL imports in SSR mode", {
|
|
11744
|
+
file: filePath.slice(-60),
|
|
11745
|
+
blockedUrls: urlBlockResult.blockedUrls
|
|
11746
|
+
});
|
|
11747
|
+
}
|
|
11748
|
+
code = await resolveRelativeImportsForSSR(code);
|
|
11749
|
+
code = await resolveVeryfrontImports(code);
|
|
11750
|
+
} else {
|
|
11751
|
+
code = await resolveRelativeImports(code, filePath, projectDir, moduleServerUrl);
|
|
11752
|
+
if (moduleServerUrl && vendorBundleHash) {
|
|
11753
|
+
code = await rewriteVendorImports(code, moduleServerUrl, vendorBundleHash);
|
|
11754
|
+
} else {
|
|
11755
|
+
code = await rewriteBareImports(code, moduleServerUrl);
|
|
11756
|
+
}
|
|
11757
|
+
}
|
|
11758
|
+
timings2.rewrite = performance.now() - rewriteStart;
|
|
11759
|
+
setCachedTransform(cacheKey, code, contentHash);
|
|
11760
|
+
const totalMs = performance.now() - transformStart;
|
|
11761
|
+
rendererLogger.debug("[ESM-TRANSFORM] Timing breakdown", {
|
|
11762
|
+
file: filePath.slice(-40),
|
|
11763
|
+
totalMs: totalMs.toFixed(1),
|
|
11764
|
+
hashMs: timings2.hash?.toFixed(1),
|
|
11765
|
+
mdxMs: timings2.mdx?.toFixed(1),
|
|
11766
|
+
esbuildMs: timings2.esbuild?.toFixed(1),
|
|
11767
|
+
rewriteMs: timings2.rewrite?.toFixed(1)
|
|
11768
|
+
});
|
|
11769
|
+
return code;
|
|
11770
|
+
}
|
|
11771
|
+
|
|
11772
|
+
// src/build/transforms/mdx/esm-module-loader.ts
|
|
11773
|
+
var IS_TRUE_NODE2 = isNode && !isDeno;
|
|
11774
|
+
var LOG_PREFIX_MDX_LOADER = "[mdx-loader]";
|
|
11775
|
+
var LOG_PREFIX_MDX_RENDERER = "[mdx-renderer]";
|
|
11776
|
+
var JSX_IMPORT_PATTERN = /import\s+([^'"]+)\s+from\s+['"]file:\/\/([^'"]+\.(jsx|tsx))['"];?/g;
|
|
11777
|
+
var REACT_IMPORT_PATTERN = /import\s+.*React.*\s+from\s+['"]react['"]/;
|
|
11778
|
+
var HTTP_IMPORT_PATTERN = /['"]https?:\/\/[^'"]+['"]/;
|
|
11779
|
+
var ESBUILD_JSX_FACTORY = "React.createElement";
|
|
11780
|
+
var ESBUILD_JSX_FRAGMENT = "React.Fragment";
|
|
11781
|
+
var HTTP_MODULE_FETCH_TIMEOUT_MS2 = 3e4;
|
|
11782
|
+
var _resolvedPaths = {};
|
|
11783
|
+
var _modulePathCache = null;
|
|
11784
|
+
var _modulePathCacheLoaded = false;
|
|
11785
|
+
async function getModulePathCache(cacheDir) {
|
|
11786
|
+
if (_modulePathCache && _modulePathCacheLoaded) {
|
|
11787
|
+
return _modulePathCache;
|
|
11788
|
+
}
|
|
11789
|
+
_modulePathCache = /* @__PURE__ */ new Map();
|
|
11790
|
+
const indexPath = join6(cacheDir, "_index.json");
|
|
11791
|
+
try {
|
|
11792
|
+
const content = await Deno.readTextFile(indexPath);
|
|
11793
|
+
const index = JSON.parse(content);
|
|
11794
|
+
for (const [path, cachePath] of Object.entries(index)) {
|
|
11795
|
+
_modulePathCache.set(path, cachePath);
|
|
11796
|
+
}
|
|
11797
|
+
rendererLogger.debug(`${LOG_PREFIX_MDX_LOADER} Loaded module index: ${_modulePathCache.size} entries`);
|
|
11798
|
+
} catch {
|
|
11799
|
+
}
|
|
11800
|
+
_modulePathCacheLoaded = true;
|
|
11801
|
+
return _modulePathCache;
|
|
11802
|
+
}
|
|
11803
|
+
async function saveModulePathCache(cacheDir) {
|
|
11804
|
+
if (!_modulePathCache)
|
|
11805
|
+
return;
|
|
11806
|
+
const indexPath = join6(cacheDir, "_index.json");
|
|
11807
|
+
const index = {};
|
|
11808
|
+
for (const [path, cachePath] of _modulePathCache.entries()) {
|
|
11809
|
+
index[path] = cachePath;
|
|
11810
|
+
}
|
|
11811
|
+
try {
|
|
11812
|
+
await Deno.writeTextFile(indexPath, JSON.stringify(index));
|
|
11813
|
+
} catch (error) {
|
|
11814
|
+
rendererLogger.warn(`${LOG_PREFIX_MDX_LOADER} Failed to save module index`, error);
|
|
11815
|
+
}
|
|
11816
|
+
}
|
|
11817
|
+
async function resolveNodePackage(packageSpec) {
|
|
11818
|
+
if (!IS_TRUE_NODE2)
|
|
11819
|
+
return null;
|
|
11820
|
+
if (packageSpec in _resolvedPaths)
|
|
11821
|
+
return _resolvedPaths[packageSpec];
|
|
11822
|
+
try {
|
|
11823
|
+
const { createRequire } = await import("node:module");
|
|
11824
|
+
const require2 = createRequire(import.meta.url);
|
|
11825
|
+
const resolved = require2.resolve(packageSpec);
|
|
11826
|
+
_resolvedPaths[packageSpec] = resolved;
|
|
11827
|
+
return resolved;
|
|
11828
|
+
} catch {
|
|
11829
|
+
_resolvedPaths[packageSpec] = null;
|
|
11830
|
+
return null;
|
|
11831
|
+
}
|
|
11832
|
+
}
|
|
11833
|
+
async function transformReactImportsToAbsolute(code) {
|
|
11834
|
+
if (!IS_TRUE_NODE2)
|
|
11835
|
+
return code;
|
|
11836
|
+
const reactPath = await resolveNodePackage("react");
|
|
11837
|
+
const reactJsxPath = await resolveNodePackage("react/jsx-runtime");
|
|
11838
|
+
const reactJsxDevPath = await resolveNodePackage("react/jsx-dev-runtime");
|
|
11839
|
+
const reactDomPath = await resolveNodePackage("react-dom");
|
|
11840
|
+
let result = code;
|
|
11841
|
+
if (reactJsxPath) {
|
|
11842
|
+
result = result.replace(
|
|
11843
|
+
/from\s+['"]react\/jsx-runtime['"]/g,
|
|
11844
|
+
`from "file://${reactJsxPath}"`
|
|
11845
|
+
);
|
|
9200
11846
|
}
|
|
9201
11847
|
if (reactJsxDevPath) {
|
|
9202
11848
|
result = result.replace(
|
|
@@ -9218,6 +11864,94 @@ async function transformReactImportsToAbsolute(code) {
|
|
|
9218
11864
|
}
|
|
9219
11865
|
return result;
|
|
9220
11866
|
}
|
|
11867
|
+
function addExternalToEsmShUrls(code) {
|
|
11868
|
+
if (IS_TRUE_NODE2)
|
|
11869
|
+
return code;
|
|
11870
|
+
return code.replace(
|
|
11871
|
+
/from\s+["'](https:\/\/esm\.sh\/[^"']+)["']/g,
|
|
11872
|
+
(match, url) => {
|
|
11873
|
+
if (url.includes("external=")) {
|
|
11874
|
+
return match;
|
|
11875
|
+
}
|
|
11876
|
+
if (url.includes("/react@") || url.includes("/react-dom@")) {
|
|
11877
|
+
return match;
|
|
11878
|
+
}
|
|
11879
|
+
const separator = url.includes("?") ? "&" : "?";
|
|
11880
|
+
return `from "${url}${separator}external=react,react-dom"`;
|
|
11881
|
+
}
|
|
11882
|
+
);
|
|
11883
|
+
}
|
|
11884
|
+
function normalizeReactToNpm(code) {
|
|
11885
|
+
if (IS_TRUE_NODE2)
|
|
11886
|
+
return code;
|
|
11887
|
+
const REACT_VERSION = "18.3.1";
|
|
11888
|
+
let result = code;
|
|
11889
|
+
result = result.replace(
|
|
11890
|
+
/import\s*\{([^}]*)\bjsxDEV\s+as\s+(\w+)([^}]*)\}\s*from\s*["']([^"']*\/?)jsx-dev-runtime["']/g,
|
|
11891
|
+
(_match, before, alias, after, prefix) => {
|
|
11892
|
+
return `import {${before}jsx as ${alias}${after}} from "${prefix}jsx-runtime"`;
|
|
11893
|
+
}
|
|
11894
|
+
);
|
|
11895
|
+
result = result.replace(
|
|
11896
|
+
/import\s*\{([^}]*)\bjsxDEV\b([^}]*)\}\s*from\s*["']([^"']*\/?)jsx-dev-runtime["']/g,
|
|
11897
|
+
(_match, before, after, prefix) => {
|
|
11898
|
+
return `import {${before}jsx${after}} from "${prefix}jsx-runtime"`;
|
|
11899
|
+
}
|
|
11900
|
+
);
|
|
11901
|
+
result = result.replace(
|
|
11902
|
+
/from\s+['"]https:\/\/esm\.sh\/react@[^'"\/]+\/jsx-dev-runtime[^'"]*['"]/g,
|
|
11903
|
+
`from "npm:react@${REACT_VERSION}/jsx-runtime"`
|
|
11904
|
+
);
|
|
11905
|
+
result = result.replace(
|
|
11906
|
+
/from\s+['"]https:\/\/esm\.sh\/react@[^'"\/]+\/jsx-runtime[^'"]*['"]/g,
|
|
11907
|
+
`from "npm:react@${REACT_VERSION}/jsx-runtime"`
|
|
11908
|
+
);
|
|
11909
|
+
result = result.replace(
|
|
11910
|
+
/from\s+['"]https:\/\/esm\.sh\/react-dom@[^'"\/]+\/server[^'"]*['"]/g,
|
|
11911
|
+
`from "npm:react-dom@${REACT_VERSION}/server"`
|
|
11912
|
+
);
|
|
11913
|
+
result = result.replace(
|
|
11914
|
+
/from\s+['"]npm:react\/jsx-dev-runtime['"]/g,
|
|
11915
|
+
`from "npm:react@${REACT_VERSION}/jsx-runtime"`
|
|
11916
|
+
);
|
|
11917
|
+
result = result.replace(
|
|
11918
|
+
/from\s+['"]npm:react\/jsx-runtime['"]/g,
|
|
11919
|
+
`from "npm:react@${REACT_VERSION}/jsx-runtime"`
|
|
11920
|
+
);
|
|
11921
|
+
result = result.replace(
|
|
11922
|
+
/from\s+['"]npm:react-dom\/server['"]/g,
|
|
11923
|
+
`from "npm:react-dom@${REACT_VERSION}/server"`
|
|
11924
|
+
);
|
|
11925
|
+
result = result.replace(
|
|
11926
|
+
/from\s+['"]react\/jsx-dev-runtime['"]/g,
|
|
11927
|
+
`from "npm:react@${REACT_VERSION}/jsx-runtime"`
|
|
11928
|
+
);
|
|
11929
|
+
result = result.replace(
|
|
11930
|
+
/from\s+['"]react\/jsx-runtime['"]/g,
|
|
11931
|
+
`from "npm:react@${REACT_VERSION}/jsx-runtime"`
|
|
11932
|
+
);
|
|
11933
|
+
result = result.replace(
|
|
11934
|
+
/from\s+['"]https:\/\/esm\.sh\/react@[^'"\/]+['"]/g,
|
|
11935
|
+
`from "npm:react@${REACT_VERSION}"`
|
|
11936
|
+
);
|
|
11937
|
+
result = result.replace(
|
|
11938
|
+
/from\s+['"]https:\/\/esm\.sh\/react-dom@[^'"\/]+['"]/g,
|
|
11939
|
+
`from "npm:react-dom@${REACT_VERSION}"`
|
|
11940
|
+
);
|
|
11941
|
+
result = result.replace(
|
|
11942
|
+
/from\s+['"]npm:react['"]/g,
|
|
11943
|
+
`from "npm:react@${REACT_VERSION}"`
|
|
11944
|
+
);
|
|
11945
|
+
result = result.replace(
|
|
11946
|
+
/from\s+['"]npm:react-dom['"]/g,
|
|
11947
|
+
`from "npm:react-dom@${REACT_VERSION}"`
|
|
11948
|
+
);
|
|
11949
|
+
result = result.replace(
|
|
11950
|
+
/from\s+['"]npm:@tanstack\/react-query(?:@[^'"\/]+)?['"]/g,
|
|
11951
|
+
`from "https://esm.sh/@tanstack/react-query?external=react,react-dom"`
|
|
11952
|
+
);
|
|
11953
|
+
return result;
|
|
11954
|
+
}
|
|
9221
11955
|
function hashString(input) {
|
|
9222
11956
|
const HASH_SEED_FNV1A2 = 2166136261;
|
|
9223
11957
|
let hash = HASH_SEED_FNV1A2 >>> 0;
|
|
@@ -9288,37 +12022,436 @@ function createHTTPPluginForMDX() {
|
|
|
9288
12022
|
};
|
|
9289
12023
|
}
|
|
9290
12024
|
async function loadModuleESM(compiledProgramCode, context) {
|
|
12025
|
+
const loadStart = performance.now();
|
|
9291
12026
|
try {
|
|
9292
12027
|
const { getAdapter: getAdapter2 } = await Promise.resolve().then(() => (init_detect(), detect_exports));
|
|
9293
12028
|
const adapter = await getAdapter2();
|
|
9294
12029
|
if (!context.esmCacheDir) {
|
|
9295
|
-
|
|
9296
|
-
|
|
9297
|
-
|
|
9298
|
-
|
|
9299
|
-
|
|
9300
|
-
|
|
9301
|
-
)
|
|
9302
|
-
|
|
9303
|
-
|
|
9304
|
-
|
|
9305
|
-
|
|
12030
|
+
const persistentCacheDir = join6(cwd(), ".cache", "veryfront-mdx-esm");
|
|
12031
|
+
try {
|
|
12032
|
+
await Deno.mkdir(persistentCacheDir, { recursive: true });
|
|
12033
|
+
context.esmCacheDir = persistentCacheDir;
|
|
12034
|
+
rendererLogger.info(`${LOG_PREFIX_MDX_LOADER} Using persistent cache dir: ${persistentCacheDir}`);
|
|
12035
|
+
} catch {
|
|
12036
|
+
if (IS_TRUE_NODE2) {
|
|
12037
|
+
const projectCacheDir = join6(cwd(), "node_modules", ".cache", "veryfront-mdx");
|
|
12038
|
+
await adapter.fs.mkdir(projectCacheDir, { recursive: true });
|
|
12039
|
+
context.esmCacheDir = projectCacheDir;
|
|
12040
|
+
} else {
|
|
12041
|
+
context.esmCacheDir = await adapter.fs.makeTempDir("veryfront-mdx-esm-");
|
|
12042
|
+
}
|
|
9306
12043
|
}
|
|
9307
12044
|
}
|
|
9308
|
-
let rewritten
|
|
9309
|
-
|
|
9310
|
-
|
|
12045
|
+
let rewritten = compiledProgramCode.replace(
|
|
12046
|
+
/from\s+["']@\/([^"']+)["']/g,
|
|
12047
|
+
(_match, path) => {
|
|
12048
|
+
const jsPath = path.endsWith(".js") ? path : `${path}.js`;
|
|
12049
|
+
return `from "/_vf_modules/${jsPath}"`;
|
|
12050
|
+
}
|
|
12051
|
+
);
|
|
12052
|
+
if (IS_TRUE_NODE2) {
|
|
12053
|
+
rewritten = await transformReactImportsToAbsolute(rewritten);
|
|
9311
12054
|
} else {
|
|
9312
12055
|
rewritten = transformImportsWithMap(
|
|
9313
|
-
|
|
12056
|
+
rewritten,
|
|
9314
12057
|
getDefaultImportMap(),
|
|
9315
12058
|
void 0,
|
|
9316
12059
|
{ resolveBare: true }
|
|
9317
12060
|
);
|
|
9318
12061
|
}
|
|
12062
|
+
const vfModulePattern = /from\s+["'](\/?)(_vf_modules\/[^"']+)["']/g;
|
|
12063
|
+
const vfModuleImports = [];
|
|
12064
|
+
let vfMatch;
|
|
12065
|
+
while ((vfMatch = vfModulePattern.exec(rewritten)) !== null) {
|
|
12066
|
+
const [original, , path] = vfMatch;
|
|
12067
|
+
if (path) {
|
|
12068
|
+
vfModuleImports.push({ original, path });
|
|
12069
|
+
}
|
|
12070
|
+
}
|
|
12071
|
+
const projectDir = cwd();
|
|
12072
|
+
const projectId = "default";
|
|
12073
|
+
const inFlight = /* @__PURE__ */ new Map();
|
|
12074
|
+
async function fetchAndCacheModule(modulePath, parentModulePath) {
|
|
12075
|
+
let normalizedPath = modulePath.replace(/^\//, "");
|
|
12076
|
+
if (parentModulePath && (modulePath.startsWith("./") || modulePath.startsWith("../"))) {
|
|
12077
|
+
const parentDir = parentModulePath.replace(/\/[^/]+$/, "");
|
|
12078
|
+
const joinedPath = posix.join(parentDir, modulePath);
|
|
12079
|
+
normalizedPath = posix.normalize(joinedPath);
|
|
12080
|
+
if (!normalizedPath.startsWith("_vf_modules/")) {
|
|
12081
|
+
normalizedPath = `_vf_modules/${normalizedPath}`;
|
|
12082
|
+
}
|
|
12083
|
+
}
|
|
12084
|
+
const existingFetch = inFlight.get(normalizedPath);
|
|
12085
|
+
if (existingFetch) {
|
|
12086
|
+
rendererLogger.debug(`${LOG_PREFIX_MDX_LOADER} Waiting for in-flight fetch: ${normalizedPath}`);
|
|
12087
|
+
return existingFetch;
|
|
12088
|
+
}
|
|
12089
|
+
let resolveDeferred;
|
|
12090
|
+
const fetchPromise = new Promise((resolve) => {
|
|
12091
|
+
resolveDeferred = resolve;
|
|
12092
|
+
});
|
|
12093
|
+
inFlight.set(normalizedPath, fetchPromise);
|
|
12094
|
+
const result2 = await (async () => {
|
|
12095
|
+
const pathCache = await getModulePathCache(context.esmCacheDir);
|
|
12096
|
+
const cachedPath = pathCache.get(normalizedPath);
|
|
12097
|
+
if (cachedPath) {
|
|
12098
|
+
try {
|
|
12099
|
+
const stat = await adapter.fs.stat(cachedPath);
|
|
12100
|
+
if (stat?.isFile) {
|
|
12101
|
+
return cachedPath;
|
|
12102
|
+
}
|
|
12103
|
+
} catch {
|
|
12104
|
+
pathCache.delete(normalizedPath);
|
|
12105
|
+
}
|
|
12106
|
+
}
|
|
12107
|
+
try {
|
|
12108
|
+
const filePathWithoutJs = normalizedPath.replace(/^_vf_modules\//, "").replace(/\.js$/, "");
|
|
12109
|
+
const extensions = [".tsx", ".ts", ".jsx", ".js", ".mdx"];
|
|
12110
|
+
const prefixes = ["", "src/"];
|
|
12111
|
+
const prefixesToStrip = ["components/", "pages/", "lib/", "app/"];
|
|
12112
|
+
let sourceCode = null;
|
|
12113
|
+
let actualFilePath = null;
|
|
12114
|
+
const hasKnownExt = extensions.some((ext) => filePathWithoutJs.endsWith(ext));
|
|
12115
|
+
if (hasKnownExt) {
|
|
12116
|
+
for (const prefix of prefixes) {
|
|
12117
|
+
const tryPath = prefix + filePathWithoutJs;
|
|
12118
|
+
try {
|
|
12119
|
+
const content = await adapter.fs.readFile(tryPath);
|
|
12120
|
+
sourceCode = typeof content === "string" ? content : new TextDecoder().decode(content);
|
|
12121
|
+
actualFilePath = tryPath;
|
|
12122
|
+
break;
|
|
12123
|
+
} catch {
|
|
12124
|
+
}
|
|
12125
|
+
}
|
|
12126
|
+
}
|
|
12127
|
+
if (!sourceCode) {
|
|
12128
|
+
const filePathWithoutExt = hasKnownExt ? filePathWithoutJs.replace(/\.(tsx|ts|jsx|js|mdx)$/, "") : filePathWithoutJs;
|
|
12129
|
+
const triedPaths = [];
|
|
12130
|
+
outer:
|
|
12131
|
+
for (const prefix of prefixes) {
|
|
12132
|
+
for (const ext of extensions) {
|
|
12133
|
+
const tryPath = prefix + filePathWithoutExt + ext;
|
|
12134
|
+
triedPaths.push(tryPath);
|
|
12135
|
+
try {
|
|
12136
|
+
const content = await adapter.fs.readFile(tryPath);
|
|
12137
|
+
sourceCode = typeof content === "string" ? content : new TextDecoder().decode(content);
|
|
12138
|
+
actualFilePath = tryPath;
|
|
12139
|
+
rendererLogger.debug(`${LOG_PREFIX_MDX_LOADER} Found file with extension`, {
|
|
12140
|
+
normalizedPath,
|
|
12141
|
+
tryPath
|
|
12142
|
+
});
|
|
12143
|
+
break outer;
|
|
12144
|
+
} catch {
|
|
12145
|
+
}
|
|
12146
|
+
}
|
|
12147
|
+
}
|
|
12148
|
+
if (!sourceCode) {
|
|
12149
|
+
rendererLogger.debug(`${LOG_PREFIX_MDX_LOADER} Extension resolution failed`, {
|
|
12150
|
+
normalizedPath,
|
|
12151
|
+
filePathWithoutExt,
|
|
12152
|
+
triedPaths
|
|
12153
|
+
});
|
|
12154
|
+
}
|
|
12155
|
+
}
|
|
12156
|
+
if (!sourceCode) {
|
|
12157
|
+
const filePathWithoutExt = hasKnownExt ? filePathWithoutJs.replace(/\.(tsx|ts|jsx|js|mdx)$/, "") : filePathWithoutJs;
|
|
12158
|
+
stripLoop:
|
|
12159
|
+
for (const stripPrefix of prefixesToStrip) {
|
|
12160
|
+
if (filePathWithoutExt.startsWith(stripPrefix)) {
|
|
12161
|
+
const strippedPath = filePathWithoutExt.slice(stripPrefix.length);
|
|
12162
|
+
for (const ext of extensions) {
|
|
12163
|
+
const tryPath = strippedPath + ext;
|
|
12164
|
+
try {
|
|
12165
|
+
const content = await adapter.fs.readFile(tryPath);
|
|
12166
|
+
sourceCode = typeof content === "string" ? content : new TextDecoder().decode(content);
|
|
12167
|
+
actualFilePath = tryPath;
|
|
12168
|
+
rendererLogger.debug(`${LOG_PREFIX_MDX_LOADER} Found file after stripping prefix`, {
|
|
12169
|
+
originalPath: filePathWithoutJs,
|
|
12170
|
+
strippedPath: tryPath
|
|
12171
|
+
});
|
|
12172
|
+
break stripLoop;
|
|
12173
|
+
} catch {
|
|
12174
|
+
}
|
|
12175
|
+
}
|
|
12176
|
+
}
|
|
12177
|
+
}
|
|
12178
|
+
}
|
|
12179
|
+
if (!sourceCode) {
|
|
12180
|
+
const basePath = hasKnownExt ? filePathWithoutJs.replace(/\.(tsx|ts|jsx|js|mdx)$/, "") : filePathWithoutJs;
|
|
12181
|
+
outer:
|
|
12182
|
+
for (const prefix of prefixes) {
|
|
12183
|
+
for (const ext of extensions) {
|
|
12184
|
+
const tryPath = `${prefix}${basePath}/index${ext}`;
|
|
12185
|
+
try {
|
|
12186
|
+
const content = await adapter.fs.readFile(tryPath);
|
|
12187
|
+
sourceCode = typeof content === "string" ? content : new TextDecoder().decode(content);
|
|
12188
|
+
actualFilePath = tryPath;
|
|
12189
|
+
break outer;
|
|
12190
|
+
} catch {
|
|
12191
|
+
}
|
|
12192
|
+
}
|
|
12193
|
+
}
|
|
12194
|
+
}
|
|
12195
|
+
if (!sourceCode || !actualFilePath) {
|
|
12196
|
+
rendererLogger.debug(
|
|
12197
|
+
`${LOG_PREFIX_MDX_LOADER} Direct read failed, falling back to HTTP: ${filePathWithoutJs}`
|
|
12198
|
+
);
|
|
12199
|
+
const envGet = (key) => globalThis.Deno?.env?.get(key);
|
|
12200
|
+
const port = envGet("VERYFRONT_DEV_PORT") || envGet("PORT") || "3001";
|
|
12201
|
+
const moduleUrl = `http://localhost:${port}/${normalizedPath}?ssr=true`;
|
|
12202
|
+
const response = await fetch(moduleUrl);
|
|
12203
|
+
if (!response.ok) {
|
|
12204
|
+
rendererLogger.warn(
|
|
12205
|
+
`${LOG_PREFIX_MDX_LOADER} HTTP fetch also failed: ${moduleUrl} (${response.status})`
|
|
12206
|
+
);
|
|
12207
|
+
return null;
|
|
12208
|
+
}
|
|
12209
|
+
let moduleCode2 = await response.text();
|
|
12210
|
+
moduleCode2 = addExternalToEsmShUrls(moduleCode2);
|
|
12211
|
+
moduleCode2 = normalizeReactToNpm(moduleCode2);
|
|
12212
|
+
const vfModuleImportPattern2 = /from\s+["'](\/?_vf_modules\/[^"'?]+)(?:\?[^"']*)?["']/g;
|
|
12213
|
+
const nestedImports2 = [];
|
|
12214
|
+
let match2;
|
|
12215
|
+
while ((match2 = vfModuleImportPattern2.exec(moduleCode2)) !== null) {
|
|
12216
|
+
if (match2[1]) {
|
|
12217
|
+
nestedImports2.push({ original: match2[0], path: match2[1].replace(/^\//, "") });
|
|
12218
|
+
}
|
|
12219
|
+
}
|
|
12220
|
+
const relativeImportPattern2 = /from\s+["'](\.\.?\/[^"'?]+)(?:\?[^"']*)?["']/g;
|
|
12221
|
+
const relativeImports2 = [];
|
|
12222
|
+
let relMatch2;
|
|
12223
|
+
while ((relMatch2 = relativeImportPattern2.exec(moduleCode2)) !== null) {
|
|
12224
|
+
if (relMatch2[1]) {
|
|
12225
|
+
relativeImports2.push({ original: relMatch2[0], path: relMatch2[1] });
|
|
12226
|
+
}
|
|
12227
|
+
}
|
|
12228
|
+
const nestedResults2 = await Promise.all(
|
|
12229
|
+
nestedImports2.map(async ({ original, path: nestedPath }) => {
|
|
12230
|
+
const nestedFilePath = await fetchAndCacheModule(nestedPath, normalizedPath);
|
|
12231
|
+
return { original, nestedFilePath };
|
|
12232
|
+
})
|
|
12233
|
+
);
|
|
12234
|
+
for (const { original, nestedFilePath } of nestedResults2) {
|
|
12235
|
+
if (nestedFilePath) {
|
|
12236
|
+
moduleCode2 = moduleCode2.replace(original, `from "file://${nestedFilePath}"`);
|
|
12237
|
+
}
|
|
12238
|
+
}
|
|
12239
|
+
const relativeResults2 = await Promise.all(
|
|
12240
|
+
relativeImports2.map(async ({ original, path: relativePath }) => {
|
|
12241
|
+
const nestedFilePath = await fetchAndCacheModule(relativePath, normalizedPath);
|
|
12242
|
+
return { original, nestedFilePath };
|
|
12243
|
+
})
|
|
12244
|
+
);
|
|
12245
|
+
for (const { original, nestedFilePath } of relativeResults2) {
|
|
12246
|
+
if (nestedFilePath) {
|
|
12247
|
+
moduleCode2 = moduleCode2.replace(original, `from "file://${nestedFilePath}"`);
|
|
12248
|
+
}
|
|
12249
|
+
}
|
|
12250
|
+
const unresolvedPattern3 = /from\s+["'](\/?_vf_modules\/[^"']+)["']/g;
|
|
12251
|
+
const unresolvedMatches3 = [...moduleCode2.matchAll(unresolvedPattern3)];
|
|
12252
|
+
if (unresolvedMatches3.length > 0) {
|
|
12253
|
+
const unresolvedPaths = unresolvedMatches3.map((m) => m[1]).slice(0, 3);
|
|
12254
|
+
rendererLogger.warn(
|
|
12255
|
+
`${LOG_PREFIX_MDX_LOADER} Module has ${unresolvedMatches3.length} unresolved imports, skipping cache`,
|
|
12256
|
+
{ path: normalizedPath, unresolved: unresolvedPaths }
|
|
12257
|
+
);
|
|
12258
|
+
return null;
|
|
12259
|
+
}
|
|
12260
|
+
const contentHash2 = hashString(normalizedPath + moduleCode2);
|
|
12261
|
+
const cachePath2 = join6(context.esmCacheDir, `vfmod-${contentHash2}.mjs`);
|
|
12262
|
+
try {
|
|
12263
|
+
const stat = await adapter.fs.stat(cachePath2);
|
|
12264
|
+
if (stat?.isFile) {
|
|
12265
|
+
pathCache.set(normalizedPath, cachePath2);
|
|
12266
|
+
rendererLogger.debug(`${LOG_PREFIX_MDX_LOADER} Content cache hit: ${normalizedPath}`);
|
|
12267
|
+
return cachePath2;
|
|
12268
|
+
}
|
|
12269
|
+
} catch {
|
|
12270
|
+
}
|
|
12271
|
+
await Deno.mkdir(context.esmCacheDir, { recursive: true });
|
|
12272
|
+
await adapter.fs.writeFile(cachePath2, moduleCode2);
|
|
12273
|
+
pathCache.set(normalizedPath, cachePath2);
|
|
12274
|
+
await saveModulePathCache(context.esmCacheDir);
|
|
12275
|
+
rendererLogger.debug(`${LOG_PREFIX_MDX_LOADER} Cached: ${normalizedPath} -> ${cachePath2}`);
|
|
12276
|
+
return cachePath2;
|
|
12277
|
+
}
|
|
12278
|
+
let moduleCode;
|
|
12279
|
+
try {
|
|
12280
|
+
moduleCode = await transformToESM(
|
|
12281
|
+
sourceCode,
|
|
12282
|
+
actualFilePath,
|
|
12283
|
+
projectDir,
|
|
12284
|
+
adapter,
|
|
12285
|
+
{ projectId, dev: true, ssr: true }
|
|
12286
|
+
);
|
|
12287
|
+
} catch (transformError) {
|
|
12288
|
+
rendererLogger.error(`${LOG_PREFIX_MDX_LOADER} Transform failed for module`, {
|
|
12289
|
+
normalizedPath,
|
|
12290
|
+
actualFilePath,
|
|
12291
|
+
sourceLength: sourceCode.length,
|
|
12292
|
+
sourcePreview: sourceCode.slice(0, 200),
|
|
12293
|
+
error: transformError instanceof Error ? transformError.message : String(transformError)
|
|
12294
|
+
});
|
|
12295
|
+
throw transformError;
|
|
12296
|
+
}
|
|
12297
|
+
moduleCode = addExternalToEsmShUrls(moduleCode);
|
|
12298
|
+
moduleCode = normalizeReactToNpm(moduleCode);
|
|
12299
|
+
const vfModuleImportPattern = /from\s+["'](\/?_vf_modules\/[^"'?]+)(?:\?[^"']*)?["']/g;
|
|
12300
|
+
const nestedImports = [];
|
|
12301
|
+
let match;
|
|
12302
|
+
while ((match = vfModuleImportPattern.exec(moduleCode)) !== null) {
|
|
12303
|
+
if (match[1]) {
|
|
12304
|
+
nestedImports.push({ original: match[0], path: match[1].replace(/^\//, "") });
|
|
12305
|
+
}
|
|
12306
|
+
}
|
|
12307
|
+
const relativeImportPattern = /from\s+["'](\.\.?\/[^"'?]+)(?:\?[^"']*)?["']/g;
|
|
12308
|
+
const relativeImports = [];
|
|
12309
|
+
let relMatch;
|
|
12310
|
+
while ((relMatch = relativeImportPattern.exec(moduleCode)) !== null) {
|
|
12311
|
+
if (relMatch[1]) {
|
|
12312
|
+
relativeImports.push({ original: relMatch[0], path: relMatch[1] });
|
|
12313
|
+
}
|
|
12314
|
+
}
|
|
12315
|
+
const nestedResults = await Promise.all(
|
|
12316
|
+
nestedImports.map(async ({ original, path: nestedPath }) => {
|
|
12317
|
+
const nestedFilePath = await fetchAndCacheModule(nestedPath, normalizedPath);
|
|
12318
|
+
return { original, nestedFilePath, nestedPath };
|
|
12319
|
+
})
|
|
12320
|
+
);
|
|
12321
|
+
for (const { original, nestedFilePath, nestedPath } of nestedResults) {
|
|
12322
|
+
if (nestedFilePath) {
|
|
12323
|
+
moduleCode = moduleCode.replace(original, `from "file://${nestedFilePath}"`);
|
|
12324
|
+
} else {
|
|
12325
|
+
const stubCode = `
|
|
12326
|
+
// Stub module for missing file: ${nestedPath}
|
|
12327
|
+
// This file was not found in the project's published release.
|
|
12328
|
+
const handler = {
|
|
12329
|
+
get(_, prop) {
|
|
12330
|
+
if (prop === 'default' || prop === '__esModule' || typeof prop === 'symbol') {
|
|
12331
|
+
return new Proxy({}, handler);
|
|
12332
|
+
}
|
|
12333
|
+
console.warn('[Veryfront] Missing module: ${nestedPath}. Component "' + prop + '" was not found.');
|
|
12334
|
+
return () => null;
|
|
12335
|
+
},
|
|
12336
|
+
apply() { return null; }
|
|
12337
|
+
};
|
|
12338
|
+
export default new Proxy(function(){}, handler);
|
|
12339
|
+
`;
|
|
12340
|
+
const stubHash = hashString(`stub:${nestedPath}`);
|
|
12341
|
+
const stubPath = join6(context.esmCacheDir, `stub-${stubHash}.mjs`);
|
|
12342
|
+
try {
|
|
12343
|
+
await adapter.fs.writeFile(stubPath, stubCode);
|
|
12344
|
+
moduleCode = moduleCode.replace(original, `from "file://${stubPath}"`);
|
|
12345
|
+
rendererLogger.warn(
|
|
12346
|
+
`${LOG_PREFIX_MDX_LOADER} Created stub for missing module: ${nestedPath}`
|
|
12347
|
+
);
|
|
12348
|
+
} catch (e) {
|
|
12349
|
+
rendererLogger.error(
|
|
12350
|
+
`${LOG_PREFIX_MDX_LOADER} Failed to create stub for: ${nestedPath}`,
|
|
12351
|
+
e
|
|
12352
|
+
);
|
|
12353
|
+
}
|
|
12354
|
+
}
|
|
12355
|
+
}
|
|
12356
|
+
const relativeResults = await Promise.all(
|
|
12357
|
+
relativeImports.map(async ({ original, path: relativePath }) => {
|
|
12358
|
+
const nestedFilePath = await fetchAndCacheModule(relativePath, normalizedPath);
|
|
12359
|
+
return { original, nestedFilePath, relativePath };
|
|
12360
|
+
})
|
|
12361
|
+
);
|
|
12362
|
+
for (const { original, nestedFilePath, relativePath } of relativeResults) {
|
|
12363
|
+
if (nestedFilePath) {
|
|
12364
|
+
moduleCode = moduleCode.replace(original, `from "file://${nestedFilePath}"`);
|
|
12365
|
+
} else {
|
|
12366
|
+
const stubCode = `
|
|
12367
|
+
// Stub module for missing file: ${relativePath}
|
|
12368
|
+
// This file was not found in the project's published release.
|
|
12369
|
+
const handler = {
|
|
12370
|
+
get(_, prop) {
|
|
12371
|
+
if (prop === 'default' || prop === '__esModule' || typeof prop === 'symbol') {
|
|
12372
|
+
return new Proxy({}, handler);
|
|
12373
|
+
}
|
|
12374
|
+
console.warn('[Veryfront] Missing module: ${relativePath}. Component "' + prop + '" was not found.');
|
|
12375
|
+
return () => null;
|
|
12376
|
+
},
|
|
12377
|
+
apply() { return null; }
|
|
12378
|
+
};
|
|
12379
|
+
export default new Proxy(function(){}, handler);
|
|
12380
|
+
`;
|
|
12381
|
+
const stubHash = hashString(`stub:${relativePath}`);
|
|
12382
|
+
const stubPath = join6(context.esmCacheDir, `stub-${stubHash}.mjs`);
|
|
12383
|
+
try {
|
|
12384
|
+
await adapter.fs.writeFile(stubPath, stubCode);
|
|
12385
|
+
moduleCode = moduleCode.replace(original, `from "file://${stubPath}"`);
|
|
12386
|
+
rendererLogger.warn(
|
|
12387
|
+
`${LOG_PREFIX_MDX_LOADER} Created stub for missing module: ${relativePath}`
|
|
12388
|
+
);
|
|
12389
|
+
} catch (e) {
|
|
12390
|
+
rendererLogger.error(
|
|
12391
|
+
`${LOG_PREFIX_MDX_LOADER} Failed to create stub for: ${relativePath}`,
|
|
12392
|
+
e
|
|
12393
|
+
);
|
|
12394
|
+
}
|
|
12395
|
+
}
|
|
12396
|
+
}
|
|
12397
|
+
const unresolvedPattern2 = /from\s+["'](\/?_vf_modules\/[^"']+)["']/g;
|
|
12398
|
+
const unresolvedMatches2 = [...moduleCode.matchAll(unresolvedPattern2)];
|
|
12399
|
+
if (unresolvedMatches2.length > 0) {
|
|
12400
|
+
const unresolvedPaths = unresolvedMatches2.map((m) => m[1]).slice(0, 3);
|
|
12401
|
+
rendererLogger.warn(
|
|
12402
|
+
`${LOG_PREFIX_MDX_LOADER} Module has ${unresolvedMatches2.length} unresolved imports, skipping cache`,
|
|
12403
|
+
{ path: normalizedPath, unresolved: unresolvedPaths }
|
|
12404
|
+
);
|
|
12405
|
+
return null;
|
|
12406
|
+
}
|
|
12407
|
+
const contentHash = hashString(normalizedPath + moduleCode);
|
|
12408
|
+
const cachePath = join6(context.esmCacheDir, `vfmod-${contentHash}.mjs`);
|
|
12409
|
+
try {
|
|
12410
|
+
const stat = await adapter.fs.stat(cachePath);
|
|
12411
|
+
if (stat?.isFile) {
|
|
12412
|
+
pathCache.set(normalizedPath, cachePath);
|
|
12413
|
+
rendererLogger.debug(`${LOG_PREFIX_MDX_LOADER} Content cache hit: ${normalizedPath}`);
|
|
12414
|
+
return cachePath;
|
|
12415
|
+
}
|
|
12416
|
+
} catch {
|
|
12417
|
+
}
|
|
12418
|
+
await Deno.mkdir(context.esmCacheDir, { recursive: true });
|
|
12419
|
+
await adapter.fs.writeFile(cachePath, moduleCode);
|
|
12420
|
+
pathCache.set(normalizedPath, cachePath);
|
|
12421
|
+
await saveModulePathCache(context.esmCacheDir);
|
|
12422
|
+
rendererLogger.debug(
|
|
12423
|
+
`${LOG_PREFIX_MDX_LOADER} Cached vf_module: ${normalizedPath} -> ${cachePath}`
|
|
12424
|
+
);
|
|
12425
|
+
return cachePath;
|
|
12426
|
+
} catch (error) {
|
|
12427
|
+
rendererLogger.warn(`${LOG_PREFIX_MDX_LOADER} Failed to process ${normalizedPath}`, error);
|
|
12428
|
+
return null;
|
|
12429
|
+
}
|
|
12430
|
+
})();
|
|
12431
|
+
resolveDeferred(result2);
|
|
12432
|
+
inFlight.delete(normalizedPath);
|
|
12433
|
+
return result2;
|
|
12434
|
+
}
|
|
12435
|
+
const fetchStart = performance.now();
|
|
12436
|
+
const vfModuleResults = await Promise.all(
|
|
12437
|
+
vfModuleImports.map(async ({ original, path }) => {
|
|
12438
|
+
const filePath2 = await fetchAndCacheModule(path);
|
|
12439
|
+
return { original, filePath: filePath2 };
|
|
12440
|
+
})
|
|
12441
|
+
);
|
|
12442
|
+
const fetchEnd = performance.now();
|
|
12443
|
+
rendererLogger.info(`${LOG_PREFIX_MDX_LOADER} Module fetch phase completed`, {
|
|
12444
|
+
moduleCount: vfModuleImports.length,
|
|
12445
|
+
durationMs: (fetchEnd - fetchStart).toFixed(1)
|
|
12446
|
+
});
|
|
12447
|
+
for (const { original, filePath: filePath2 } of vfModuleResults) {
|
|
12448
|
+
if (filePath2) {
|
|
12449
|
+
rewritten = rewritten.replace(original, `from "file://${filePath2}"`);
|
|
12450
|
+
}
|
|
12451
|
+
}
|
|
9319
12452
|
let jsxMatch;
|
|
9320
12453
|
const jsxTransforms = [];
|
|
9321
|
-
const { transform } = await import("esbuild/mod.js");
|
|
12454
|
+
const { transform: transform2 } = await import("esbuild/mod.js");
|
|
9322
12455
|
while ((jsxMatch = JSX_IMPORT_PATTERN.exec(rewritten)) !== null) {
|
|
9323
12456
|
const [fullMatch, importClause, filePath2, ext] = jsxMatch;
|
|
9324
12457
|
if (!filePath2) {
|
|
@@ -9329,7 +12462,7 @@ async function loadModuleESM(compiledProgramCode, context) {
|
|
|
9329
12462
|
}
|
|
9330
12463
|
try {
|
|
9331
12464
|
const jsxCode = await adapter.fs.readFile(filePath2);
|
|
9332
|
-
const result2 = await
|
|
12465
|
+
const result2 = await transform2(jsxCode, {
|
|
9333
12466
|
loader: ext === "tsx" ? "tsx" : "jsx",
|
|
9334
12467
|
jsx: "transform",
|
|
9335
12468
|
jsxFactory: ESBUILD_JSX_FACTORY,
|
|
@@ -9342,7 +12475,7 @@ async function loadModuleESM(compiledProgramCode, context) {
|
|
|
9342
12475
|
${transformed}`;
|
|
9343
12476
|
}
|
|
9344
12477
|
const transformedFileName = `jsx-${hashString(filePath2)}.mjs`;
|
|
9345
|
-
const transformedPath =
|
|
12478
|
+
const transformedPath = join6(context.esmCacheDir, transformedFileName);
|
|
9346
12479
|
await adapter.fs.writeFile(transformedPath, transformed);
|
|
9347
12480
|
jsxTransforms.push({
|
|
9348
12481
|
original: fullMatch,
|
|
@@ -9361,10 +12494,10 @@ ${transformed}`;
|
|
|
9361
12494
|
if (/\bconst\s+MDXLayout\b/.test(rewritten) && !/export\s+\{[^}]*MDXLayout/.test(rewritten)) {
|
|
9362
12495
|
rewritten += "\nexport { MDXLayout as __vfLayout };\n";
|
|
9363
12496
|
}
|
|
9364
|
-
if (
|
|
9365
|
-
rendererLogger.info(`${LOG_PREFIX_MDX_LOADER} Bundling HTTP imports via esbuild
|
|
12497
|
+
if (HTTP_IMPORT_PATTERN.test(rewritten)) {
|
|
12498
|
+
rendererLogger.info(`${LOG_PREFIX_MDX_LOADER} Bundling HTTP imports via esbuild`);
|
|
9366
12499
|
const { build } = await import("esbuild/mod.js");
|
|
9367
|
-
const tempSourcePath =
|
|
12500
|
+
const tempSourcePath = join6(context.esmCacheDir, `temp-${hashString(rewritten)}.mjs`);
|
|
9368
12501
|
await adapter.fs.writeFile(tempSourcePath, rewritten);
|
|
9369
12502
|
try {
|
|
9370
12503
|
const result2 = await build({
|
|
@@ -9384,8 +12517,8 @@ ${transformed}`;
|
|
|
9384
12517
|
rendererLogger.info(`${LOG_PREFIX_MDX_LOADER} Successfully bundled HTTP imports`);
|
|
9385
12518
|
}
|
|
9386
12519
|
} catch (bundleError) {
|
|
9387
|
-
rendererLogger.
|
|
9388
|
-
`${LOG_PREFIX_MDX_LOADER} Failed to bundle HTTP imports
|
|
12520
|
+
rendererLogger.error(
|
|
12521
|
+
`${LOG_PREFIX_MDX_LOADER} Failed to bundle HTTP imports`,
|
|
9389
12522
|
bundleError
|
|
9390
12523
|
);
|
|
9391
12524
|
} finally {
|
|
@@ -9400,13 +12533,23 @@ ${transformed}`;
|
|
|
9400
12533
|
}
|
|
9401
12534
|
}
|
|
9402
12535
|
}
|
|
12536
|
+
rewritten = addExternalToEsmShUrls(rewritten);
|
|
12537
|
+
rewritten = normalizeReactToNpm(rewritten);
|
|
9403
12538
|
const codeHash = hashString(rewritten);
|
|
9404
12539
|
const namespace = getCacheNamespace() || "default";
|
|
9405
12540
|
const compositeKey = `${namespace}:${codeHash}`;
|
|
9406
12541
|
const cached = context.moduleCache.get(compositeKey);
|
|
9407
12542
|
if (cached)
|
|
9408
12543
|
return cached;
|
|
9409
|
-
const
|
|
12544
|
+
const unresolvedPattern = /from\s+["'](\/?_vf_modules\/[^"']+)["']/g;
|
|
12545
|
+
const unresolvedMatches = [...rewritten.matchAll(unresolvedPattern)];
|
|
12546
|
+
if (unresolvedMatches.length > 0) {
|
|
12547
|
+
const unresolvedPaths = unresolvedMatches.map((m) => m[1]).slice(0, 5);
|
|
12548
|
+
const errorMsg = `MDX has ${unresolvedMatches.length} unresolved module imports: ${unresolvedPaths.join(", ")}`;
|
|
12549
|
+
rendererLogger.error(`${LOG_PREFIX_MDX_RENDERER} ${errorMsg}`);
|
|
12550
|
+
throw new Error(errorMsg);
|
|
12551
|
+
}
|
|
12552
|
+
const nsDir = join6(context.esmCacheDir, namespace);
|
|
9410
12553
|
try {
|
|
9411
12554
|
await adapter.fs.mkdir(nsDir, { recursive: true });
|
|
9412
12555
|
} catch (e) {
|
|
@@ -9415,7 +12558,7 @@ ${transformed}`;
|
|
|
9415
12558
|
e instanceof Error ? e : String(e)
|
|
9416
12559
|
);
|
|
9417
12560
|
}
|
|
9418
|
-
const filePath =
|
|
12561
|
+
const filePath = join6(nsDir, `${codeHash}.mjs`);
|
|
9419
12562
|
try {
|
|
9420
12563
|
const stat = await adapter.fs.stat(filePath);
|
|
9421
12564
|
if (!stat?.isFile) {
|
|
@@ -9443,6 +12586,10 @@ ${transformed}`;
|
|
|
9443
12586
|
MainLayout: mod?.MainLayout
|
|
9444
12587
|
};
|
|
9445
12588
|
context.moduleCache.set(compositeKey, result);
|
|
12589
|
+
const loadEnd = performance.now();
|
|
12590
|
+
rendererLogger.info(`${LOG_PREFIX_MDX_LOADER} loadModuleESM completed`, {
|
|
12591
|
+
durationMs: (loadEnd - loadStart).toFixed(1)
|
|
12592
|
+
});
|
|
9446
12593
|
return result;
|
|
9447
12594
|
} catch (error) {
|
|
9448
12595
|
rendererLogger.error(`${LOG_PREFIX_MDX_RENDERER} MDX ESM load failed:`, error);
|
|
@@ -9501,7 +12648,7 @@ function parseJsonish(value) {
|
|
|
9501
12648
|
}
|
|
9502
12649
|
|
|
9503
12650
|
// src/build/transforms/mdx/module-loader/metadata-extractor.ts
|
|
9504
|
-
function
|
|
12651
|
+
function extractFrontmatter2(moduleCode) {
|
|
9505
12652
|
try {
|
|
9506
12653
|
const fmIndex = moduleCode.search(/(?:export\s+)?const\s+frontmatter\s*=\s*/);
|
|
9507
12654
|
if (fmIndex < 0)
|
|
@@ -9600,7 +12747,7 @@ function parseMDXCode(compiledCode) {
|
|
|
9600
12747
|
rendererLogger.debug("Code snippet:", cleanedCode.substring(0, 200));
|
|
9601
12748
|
}
|
|
9602
12749
|
const exports = {};
|
|
9603
|
-
const frontmatter =
|
|
12750
|
+
const frontmatter = extractFrontmatter2(cleanedCode);
|
|
9604
12751
|
if (frontmatter) {
|
|
9605
12752
|
exports.frontmatter = frontmatter;
|
|
9606
12753
|
}
|