veryfront 0.1.812 → 0.1.814
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/esm/deno.js +1 -1
- package/esm/src/agent/conversation/durable-append-errors.d.ts +17 -0
- package/esm/src/agent/conversation/durable-append-errors.d.ts.map +1 -0
- package/esm/src/agent/conversation/durable-append-errors.js +49 -0
- package/esm/src/agent/conversation/durable.d.ts +1 -16
- package/esm/src/agent/conversation/durable.d.ts.map +1 -1
- package/esm/src/agent/conversation/durable.js +3 -49
- package/esm/src/agent/runtime/agent-runtime-step.d.ts +44 -0
- package/esm/src/agent/runtime/agent-runtime-step.d.ts.map +1 -0
- package/esm/src/agent/runtime/agent-runtime-step.js +23 -0
- package/esm/src/agent/runtime/index.d.ts.map +1 -1
- package/esm/src/agent/runtime/index.js +45 -62
- package/esm/src/agent/runtime/model-transport.d.ts +23 -0
- package/esm/src/agent/runtime/model-transport.d.ts.map +1 -0
- package/esm/src/agent/runtime/model-transport.js +26 -0
- package/esm/src/agent/runtime/streamed-assistant-message.d.ts +8 -0
- package/esm/src/agent/runtime/streamed-assistant-message.d.ts.map +1 -0
- package/esm/src/agent/runtime/streamed-assistant-message.js +29 -0
- package/esm/src/agent/streaming/fork-runtime-step-progress.d.ts +19 -0
- package/esm/src/agent/streaming/fork-runtime-step-progress.d.ts.map +1 -0
- package/esm/src/agent/streaming/fork-runtime-step-progress.js +53 -0
- package/esm/src/agent/streaming/fork-runtime-stream.d.ts +1 -4
- package/esm/src/agent/streaming/fork-runtime-stream.d.ts.map +1 -1
- package/esm/src/agent/streaming/fork-runtime-stream.js +13 -52
- package/esm/src/cache/keys/builders/render.d.ts.map +1 -1
- package/esm/src/cache/keys/builders/render.js +3 -2
- package/esm/src/cache/request-cacheability.d.ts +3 -0
- package/esm/src/cache/request-cacheability.d.ts.map +1 -0
- package/esm/src/cache/request-cacheability.js +26 -0
- package/esm/src/html/hydration-script-builder/hydration-data-generator.d.ts.map +1 -1
- package/esm/src/html/hydration-script-builder/hydration-data-generator.js +1 -10
- package/esm/src/html/hydration-script-builder/templates/router.d.ts.map +1 -1
- package/esm/src/html/hydration-script-builder/templates/router.js +41 -10
- package/esm/src/observability/request-profiler.d.ts.map +1 -1
- package/esm/src/observability/request-profiler.js +1 -0
- package/esm/src/proxy/handler.d.ts.map +1 -1
- package/esm/src/proxy/handler.js +39 -29
- package/esm/src/proxy/main.js +35 -31
- package/esm/src/proxy/proxy-error-context.d.ts +20 -0
- package/esm/src/proxy/proxy-error-context.d.ts.map +1 -0
- package/esm/src/proxy/proxy-error-context.js +35 -0
- package/esm/src/proxy/request-lifecycle.d.ts +19 -0
- package/esm/src/proxy/request-lifecycle.d.ts.map +1 -0
- package/esm/src/proxy/request-lifecycle.js +27 -0
- package/esm/src/proxy/server-timing.d.ts +11 -0
- package/esm/src/proxy/server-timing.d.ts.map +1 -0
- package/esm/src/proxy/server-timing.js +61 -0
- package/esm/src/proxy/upstream-error-response.d.ts +5 -0
- package/esm/src/proxy/upstream-error-response.d.ts.map +1 -0
- package/esm/src/proxy/upstream-error-response.js +15 -0
- package/esm/src/release-assets/client-module-map.d.ts +3 -0
- package/esm/src/release-assets/client-module-map.d.ts.map +1 -0
- package/esm/src/release-assets/client-module-map.js +10 -0
- package/esm/src/rendering/orchestrator/module-loader/index.d.ts.map +1 -1
- package/esm/src/rendering/orchestrator/module-loader/index.js +13 -49
- package/esm/src/rendering/orchestrator/module-loader/module-cache-lookup.d.ts +25 -0
- package/esm/src/rendering/orchestrator/module-loader/module-cache-lookup.d.ts.map +1 -0
- package/esm/src/rendering/orchestrator/module-loader/module-cache-lookup.js +69 -0
- package/esm/src/rendering/orchestrator/pipeline.d.ts.map +1 -1
- package/esm/src/rendering/orchestrator/pipeline.js +9 -10
- package/esm/src/rendering/orchestrator/types.d.ts +2 -0
- package/esm/src/rendering/orchestrator/types.d.ts.map +1 -1
- package/esm/src/rendering/renderer.d.ts.map +1 -1
- package/esm/src/rendering/renderer.js +24 -19
- package/esm/src/server/handlers/request/module/page-data-endpoint-handler.d.ts +1 -0
- package/esm/src/server/handlers/request/module/page-data-endpoint-handler.d.ts.map +1 -1
- package/esm/src/server/handlers/request/module/page-data-endpoint-handler.js +98 -8
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +9 -9
package/esm/src/proxy/main.js
CHANGED
|
@@ -35,6 +35,9 @@ import { exit, getEnv, onSignal } from "../platform/compat/process.js";
|
|
|
35
35
|
import { createHttpServer, upgradeWebSocket } from "../platform/compat/http/index.js";
|
|
36
36
|
import { createProxyErrorResponse, jsonErrorResponse } from "./error-response.js";
|
|
37
37
|
import { handleReleaseAssetRequest, isReleaseAssetPath } from "./asset-handler.js";
|
|
38
|
+
import { runProxyRequestLifecycle } from "./request-lifecycle.js";
|
|
39
|
+
import { createUpstreamFailureResponse, createUpstreamTimeoutResponse, UPSTREAM_FAILURE_STATUS, UPSTREAM_TIMEOUT_STATUS, } from "./upstream-error-response.js";
|
|
40
|
+
import { createProxyServerTiming, markProxyServerTimingPhase, profileProxyServerTimingPhase, withProxyServerTimingHeader, } from "./server-timing.js";
|
|
38
41
|
function getLocalProjects() {
|
|
39
42
|
const raw = getEnv("LOCAL_PROJECTS");
|
|
40
43
|
return raw ? JSON.parse(raw) : {};
|
|
@@ -229,13 +232,13 @@ function handleWebSocketUpgrade(req, url) {
|
|
|
229
232
|
}
|
|
230
233
|
function forwardToServer(req, url) {
|
|
231
234
|
const startTime = performance.now();
|
|
235
|
+
const proxyTiming = createProxyServerTiming();
|
|
236
|
+
const withProxyTiming = (response) => withProxyServerTimingHeader(response, proxyTiming, performance.now() - startTime);
|
|
232
237
|
const requestId = dntShim.crypto.randomUUID();
|
|
233
238
|
const host = req.headers.get("host") || "";
|
|
234
|
-
const
|
|
235
|
-
const spanInfo = startServerSpan(req.method, url.pathname, parentContext);
|
|
236
|
-
const execute = async () => {
|
|
239
|
+
const execute = async (lifecycle) => {
|
|
237
240
|
try {
|
|
238
|
-
const ctx = await proxyHandler.processRequest(req, { url });
|
|
241
|
+
const ctx = await profileProxyServerTimingPhase(proxyTiming, "proxy.resolve_request", () => proxyHandler.processRequest(req, { url }));
|
|
239
242
|
return runWithProxyRequestContext({
|
|
240
243
|
requestId,
|
|
241
244
|
projectSlug: ctx.projectSlug,
|
|
@@ -250,8 +253,8 @@ function forwardToServer(req, url) {
|
|
|
250
253
|
const ms = Math.round(performance.now() - startTime);
|
|
251
254
|
const logLevel = getProxyFailureLogLevel(ctx.error.status, req.method, url.pathname);
|
|
252
255
|
proxyLogger[logLevel](`${ctx.error.status} ${req.method} ${url.pathname}`, { ms });
|
|
253
|
-
|
|
254
|
-
return createProxyErrorResponse(ctx.error);
|
|
256
|
+
lifecycle.end(ctx.error.status);
|
|
257
|
+
return withProxyTiming(createProxyErrorResponse(ctx.error));
|
|
255
258
|
}
|
|
256
259
|
const reqLogger = proxyLogger.child({
|
|
257
260
|
...(ctx.projectSlug && { project: ctx.projectSlug }),
|
|
@@ -287,9 +290,7 @@ function forwardToServer(req, url) {
|
|
|
287
290
|
let skipDedicated = false;
|
|
288
291
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
289
292
|
// Resolve dedicated server per attempt so retries can fall back to shared pool
|
|
290
|
-
const dedicatedServerUrl = skipDedicated
|
|
291
|
-
? null
|
|
292
|
-
: await serverResolver.resolve(ctx.environmentId);
|
|
293
|
+
const dedicatedServerUrl = skipDedicated ? null : await profileProxyServerTimingPhase(proxyTiming, "proxy.resolve_server", () => serverResolver.resolve(ctx.environmentId));
|
|
293
294
|
const baseUrl = dedicatedServerUrl ??
|
|
294
295
|
rendererRouter?.resolve(ctx.projectSlug) ??
|
|
295
296
|
PRODUCTION_SERVER_URL;
|
|
@@ -302,14 +303,16 @@ function forwardToServer(req, url) {
|
|
|
302
303
|
pathname: url.pathname,
|
|
303
304
|
method: req.method,
|
|
304
305
|
});
|
|
306
|
+
const retryDelayStartedAt = performance.now();
|
|
305
307
|
await new Promise((resolve) => dntShim.setTimeout(resolve, VERYFRONT_SERVER_RETRY_DELAY_MS)); // no cleanup needed: one-shot
|
|
308
|
+
markProxyServerTimingPhase(proxyTiming, "proxy.retry_delay", performance.now() - retryDelayStartedAt);
|
|
306
309
|
}
|
|
307
310
|
const abortController = new AbortController();
|
|
308
311
|
const timeoutId = dntShim.setTimeout(() => {
|
|
309
312
|
abortController.abort();
|
|
310
313
|
}, VERYFRONT_SERVER_REQUEST_TIMEOUT_MS);
|
|
311
314
|
try {
|
|
312
|
-
const response = await withSpan(ProxySpanNames.HTTP_CLIENT_FETCH, () => fetch(serverUrl.toString(), {
|
|
315
|
+
const response = await profileProxyServerTimingPhase(proxyTiming, "proxy.upstream", () => withSpan(ProxySpanNames.HTTP_CLIENT_FETCH, () => fetch(serverUrl.toString(), {
|
|
313
316
|
method: req.method,
|
|
314
317
|
headers: newHeaders,
|
|
315
318
|
body: req.body,
|
|
@@ -323,7 +326,7 @@ function forwardToServer(req, url) {
|
|
|
323
326
|
"proxy.project_slug": ctx.projectSlug || "",
|
|
324
327
|
"proxy.timeout_ms": VERYFRONT_SERVER_REQUEST_TIMEOUT_MS,
|
|
325
328
|
"proxy.retry_attempt": attempt,
|
|
326
|
-
});
|
|
329
|
+
}));
|
|
327
330
|
clearTimeout(timeoutId);
|
|
328
331
|
const ms = Math.round(performance.now() - startTime);
|
|
329
332
|
if (attempt > 0) {
|
|
@@ -332,27 +335,23 @@ function forwardToServer(req, url) {
|
|
|
332
335
|
else {
|
|
333
336
|
reqLogger.info(`${response.status} ${req.method} ${url.pathname}`, { ms });
|
|
334
337
|
}
|
|
335
|
-
|
|
336
|
-
return new Response(response.body, {
|
|
338
|
+
return withProxyTiming(new Response(response.body, {
|
|
337
339
|
status: response.status,
|
|
338
340
|
statusText: response.statusText,
|
|
339
341
|
headers: response.headers,
|
|
340
|
-
});
|
|
342
|
+
}));
|
|
341
343
|
}
|
|
342
344
|
catch (error) {
|
|
343
345
|
clearTimeout(timeoutId);
|
|
344
346
|
lastError = error;
|
|
345
347
|
if (error instanceof Error && error.name === "AbortError") {
|
|
346
348
|
const ms = Math.round(performance.now() - startTime);
|
|
347
|
-
proxyLogger.error(
|
|
349
|
+
proxyLogger.error(`${UPSTREAM_TIMEOUT_STATUS} ${req.method} ${url.pathname}`, {
|
|
348
350
|
ms,
|
|
349
351
|
timeoutMs: VERYFRONT_SERVER_REQUEST_TIMEOUT_MS,
|
|
350
352
|
});
|
|
351
|
-
|
|
352
|
-
return
|
|
353
|
-
error: "Gateway Timeout",
|
|
354
|
-
message: `Server request timed out after ${VERYFRONT_SERVER_REQUEST_TIMEOUT_MS}ms`,
|
|
355
|
-
});
|
|
353
|
+
lifecycle.end(UPSTREAM_TIMEOUT_STATUS, error);
|
|
354
|
+
return withProxyTiming(createUpstreamTimeoutResponse(VERYFRONT_SERVER_REQUEST_TIMEOUT_MS));
|
|
356
355
|
}
|
|
357
356
|
// Check if this is a retryable error and we have retries left
|
|
358
357
|
if (isRetryableConnectionError(error) && attempt < maxRetries) {
|
|
@@ -379,26 +378,31 @@ function forwardToServer(req, url) {
|
|
|
379
378
|
}
|
|
380
379
|
// All retries exhausted or non-retryable error
|
|
381
380
|
const ms = Math.round(performance.now() - startTime);
|
|
382
|
-
const logLevel = getProxyFailureLogLevel(
|
|
383
|
-
proxyLogger[logLevel](
|
|
384
|
-
|
|
385
|
-
return
|
|
386
|
-
error: "Proxy Error",
|
|
387
|
-
message: lastError instanceof Error ? lastError.message : "Unknown error",
|
|
388
|
-
});
|
|
381
|
+
const logLevel = getProxyFailureLogLevel(UPSTREAM_FAILURE_STATUS, req.method, url.pathname);
|
|
382
|
+
proxyLogger[logLevel](`${UPSTREAM_FAILURE_STATUS} ${req.method} ${url.pathname}`, { ms }, lastError);
|
|
383
|
+
lifecycle.end(UPSTREAM_FAILURE_STATUS, lastError);
|
|
384
|
+
return withProxyTiming(createUpstreamFailureResponse(lastError));
|
|
389
385
|
});
|
|
390
386
|
}
|
|
391
387
|
catch (error) {
|
|
392
388
|
const ms = Math.round(performance.now() - startTime);
|
|
393
389
|
proxyLogger.error(`500 ${req.method} ${url.pathname}`, { ms }, error);
|
|
394
|
-
|
|
395
|
-
return jsonErrorResponse(500, {
|
|
390
|
+
lifecycle.end(500, error);
|
|
391
|
+
return withProxyTiming(jsonErrorResponse(500, {
|
|
396
392
|
error: "Internal Proxy Error",
|
|
397
393
|
message: error instanceof Error ? error.message : "Unknown error",
|
|
398
|
-
});
|
|
394
|
+
}));
|
|
399
395
|
}
|
|
400
396
|
};
|
|
401
|
-
return
|
|
397
|
+
return runProxyRequestLifecycle({
|
|
398
|
+
req,
|
|
399
|
+
url,
|
|
400
|
+
startServerSpan,
|
|
401
|
+
endSpan,
|
|
402
|
+
extractContext,
|
|
403
|
+
withContext,
|
|
404
|
+
handle: execute,
|
|
405
|
+
});
|
|
402
406
|
}
|
|
403
407
|
/**
|
|
404
408
|
* Handle stats endpoint for monitoring.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { ParsedDomain } from "../server/utils/domain-parser.js";
|
|
2
|
+
import type { TokenScope } from "./token-manager.js";
|
|
3
|
+
import type { ProxyContext } from "./handler.js";
|
|
4
|
+
export type ProxyErrorSlug = "authentication-failed" | "project-not-found" | "release-not-found";
|
|
5
|
+
export interface ProxyErrorContextBase {
|
|
6
|
+
scope: TokenScope;
|
|
7
|
+
host: string;
|
|
8
|
+
parsedDomain: ParsedDomain;
|
|
9
|
+
}
|
|
10
|
+
export interface ProxyErrorContextOptions {
|
|
11
|
+
status: number;
|
|
12
|
+
message: string;
|
|
13
|
+
token?: string;
|
|
14
|
+
redirectUrl?: string;
|
|
15
|
+
slug?: ProxyErrorSlug;
|
|
16
|
+
}
|
|
17
|
+
export declare function createProxyErrorContext(base: ProxyErrorContextBase, options: ProxyErrorContextOptions): ProxyContext;
|
|
18
|
+
export declare function createProjectNotFoundProxyContext(base: ProxyErrorContextBase, message: "Preview project not found" | "Project not found", token?: string): ProxyContext;
|
|
19
|
+
export declare function createReleaseNotFoundProxyContext(base: ProxyErrorContextBase, token?: string): ProxyContext;
|
|
20
|
+
//# sourceMappingURL=proxy-error-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy-error-context.d.ts","sourceRoot":"","sources":["../../../src/src/proxy/proxy-error-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAEjD,MAAM,MAAM,cAAc,GACtB,uBAAuB,GACvB,mBAAmB,GACnB,mBAAmB,CAAC;AAExB,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,UAAU,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,cAAc,CAAC;CACvB;AAED,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,qBAAqB,EAC3B,OAAO,EAAE,wBAAwB,GAChC,YAAY,CAkBd;AAED,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,qBAAqB,EAC3B,OAAO,EAAE,2BAA2B,GAAG,mBAAmB,EAC1D,KAAK,CAAC,EAAE,MAAM,GACb,YAAY,CAOd;AAED,wBAAgB,iCAAiC,CAC/C,IAAI,EAAE,qBAAqB,EAC3B,KAAK,CAAC,EAAE,MAAM,GACb,YAAY,CAOd"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export function createProxyErrorContext(base, options) {
|
|
2
|
+
return {
|
|
3
|
+
token: options.token,
|
|
4
|
+
projectSlug: undefined,
|
|
5
|
+
projectId: undefined,
|
|
6
|
+
environment: base.scope,
|
|
7
|
+
contentSourceId: "error",
|
|
8
|
+
localPath: undefined,
|
|
9
|
+
host: base.host,
|
|
10
|
+
parsedDomain: base.parsedDomain,
|
|
11
|
+
isLocalProject: false,
|
|
12
|
+
error: {
|
|
13
|
+
status: options.status,
|
|
14
|
+
message: options.message,
|
|
15
|
+
redirectUrl: options.redirectUrl,
|
|
16
|
+
slug: options.slug,
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function createProjectNotFoundProxyContext(base, message, token) {
|
|
21
|
+
return createProxyErrorContext(base, {
|
|
22
|
+
status: 404,
|
|
23
|
+
message,
|
|
24
|
+
token,
|
|
25
|
+
slug: "project-not-found",
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
export function createReleaseNotFoundProxyContext(base, token) {
|
|
29
|
+
return createProxyErrorContext(base, {
|
|
30
|
+
status: 404,
|
|
31
|
+
message: "No active release found",
|
|
32
|
+
token,
|
|
33
|
+
slug: "release-not-found",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Context, Span } from "../observability/tracing/api-shim.js";
|
|
2
|
+
export interface ProxyRequestLifecycle {
|
|
3
|
+
end(statusCode: number, error?: Error): void;
|
|
4
|
+
}
|
|
5
|
+
export interface RunProxyRequestLifecycleOptions {
|
|
6
|
+
req: Request;
|
|
7
|
+
url: URL;
|
|
8
|
+
extractContext(headers: Headers): Context | undefined;
|
|
9
|
+
startServerSpan(method: string, path: string, parentContext?: Context): {
|
|
10
|
+
span: Span;
|
|
11
|
+
context: Context;
|
|
12
|
+
} | null;
|
|
13
|
+
withContext<T>(spanContext: Context, fn: () => Promise<T>): Promise<T>;
|
|
14
|
+
endSpan(span: Span | undefined, statusCode: number, error?: Error): void;
|
|
15
|
+
handle(lifecycle: ProxyRequestLifecycle): Promise<Response>;
|
|
16
|
+
}
|
|
17
|
+
/** Run a proxied HTTP request with tracing context and exactly-once span finalization. */
|
|
18
|
+
export declare function runProxyRequestLifecycle(options: RunProxyRequestLifecycleOptions): Promise<Response>;
|
|
19
|
+
//# sourceMappingURL=request-lifecycle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-lifecycle.d.ts","sourceRoot":"","sources":["../../../src/src/proxy/request-lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,sCAAsC,CAAC;AAE1E,MAAM,WAAW,qBAAqB;IACpC,GAAG,CAAC,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;CAC9C;AAED,MAAM,WAAW,+BAA+B;IAC9C,GAAG,EAAE,OAAO,CAAC;IACb,GAAG,EAAE,GAAG,CAAC;IACT,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;IACtD,eAAe,CACb,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,aAAa,CAAC,EAAE,OAAO,GACtB;QAAE,IAAI,EAAE,IAAI,CAAC;QAAC,OAAO,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IAC3C,WAAW,CAAC,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACvE,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC;IACzE,MAAM,CAAC,SAAS,EAAE,qBAAqB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;CAC7D;AAED,0FAA0F;AAC1F,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,+BAA+B,GACvC,OAAO,CAAC,QAAQ,CAAC,CA0BnB"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** Run a proxied HTTP request with tracing context and exactly-once span finalization. */
|
|
2
|
+
export async function runProxyRequestLifecycle(options) {
|
|
3
|
+
const parentContext = options.extractContext(options.req.headers);
|
|
4
|
+
const spanInfo = options.startServerSpan(options.req.method, options.url.pathname, parentContext);
|
|
5
|
+
let ended = false;
|
|
6
|
+
const lifecycle = {
|
|
7
|
+
end(statusCode, error) {
|
|
8
|
+
if (ended)
|
|
9
|
+
return;
|
|
10
|
+
ended = true;
|
|
11
|
+
options.endSpan(spanInfo?.span, statusCode, error);
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
const execute = async () => {
|
|
15
|
+
try {
|
|
16
|
+
const response = await options.handle(lifecycle);
|
|
17
|
+
lifecycle.end(response.status);
|
|
18
|
+
return response;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
const spanError = error instanceof Error ? error : new Error(String(error));
|
|
22
|
+
lifecycle.end(500, spanError);
|
|
23
|
+
throw error;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
return spanInfo?.context ? options.withContext(spanInfo.context, execute) : execute();
|
|
27
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface ProxyServerTiming {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
startedAt: number;
|
|
4
|
+
phases: Map<string, number>;
|
|
5
|
+
}
|
|
6
|
+
export declare function shouldEnableProxyServerTiming(): boolean;
|
|
7
|
+
export declare function createProxyServerTiming(enabled?: boolean): ProxyServerTiming;
|
|
8
|
+
export declare function markProxyServerTimingPhase(timing: ProxyServerTiming, name: string, durationMs?: number): void;
|
|
9
|
+
export declare function profileProxyServerTimingPhase<T>(timing: ProxyServerTiming, name: string, fn: () => Promise<T>): Promise<T>;
|
|
10
|
+
export declare function withProxyServerTimingHeader(response: Response, timing: ProxyServerTiming, totalMs?: number): Response;
|
|
11
|
+
//# sourceMappingURL=server-timing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-timing.d.ts","sourceRoot":"","sources":["../../../src/src/proxy/server-timing.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7B;AAcD,wBAAgB,6BAA6B,IAAI,OAAO,CAGvD;AAED,wBAAgB,uBAAuB,CACrC,OAAO,UAAkC,GACxC,iBAAiB,CAMnB;AAED,wBAAgB,0BAA0B,CACxC,MAAM,EAAE,iBAAiB,EACzB,IAAI,EAAE,MAAM,EACZ,UAAU,SAAI,GACb,IAAI,CAGN;AAED,wBAAsB,6BAA6B,CAAC,CAAC,EACnD,MAAM,EAAE,iBAAiB,EACzB,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GACnB,OAAO,CAAC,CAAC,CAAC,CASZ;AAED,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,iBAAiB,EACzB,OAAO,SAAuC,GAC7C,QAAQ,CAwBV"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { getEnv } from "../platform/compat/process.js";
|
|
2
|
+
function roundMs(value) {
|
|
3
|
+
return Math.round(value * 100) / 100;
|
|
4
|
+
}
|
|
5
|
+
function formatDuration(value) {
|
|
6
|
+
return Math.max(0, roundMs(value)).toFixed(2);
|
|
7
|
+
}
|
|
8
|
+
function sanitizeMetricName(name) {
|
|
9
|
+
return name.replace(/[^A-Za-z0-9!#$%&'*+\-.^_`|~]/g, "_");
|
|
10
|
+
}
|
|
11
|
+
export function shouldEnableProxyServerTiming() {
|
|
12
|
+
return getEnv("VERYFRONT_ENABLE_PROXY_SERVER_TIMING") === "1" ||
|
|
13
|
+
getEnv("VERYFRONT_ENABLE_SERVER_TIMING") === "1";
|
|
14
|
+
}
|
|
15
|
+
export function createProxyServerTiming(enabled = shouldEnableProxyServerTiming()) {
|
|
16
|
+
return {
|
|
17
|
+
enabled,
|
|
18
|
+
startedAt: performance.now(),
|
|
19
|
+
phases: new Map(),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function markProxyServerTimingPhase(timing, name, durationMs = 0) {
|
|
23
|
+
if (!timing.enabled)
|
|
24
|
+
return;
|
|
25
|
+
timing.phases.set(name, roundMs((timing.phases.get(name) ?? 0) + durationMs));
|
|
26
|
+
}
|
|
27
|
+
export async function profileProxyServerTimingPhase(timing, name, fn) {
|
|
28
|
+
if (!timing.enabled)
|
|
29
|
+
return await fn();
|
|
30
|
+
const startedAt = performance.now();
|
|
31
|
+
try {
|
|
32
|
+
return await fn();
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
markProxyServerTimingPhase(timing, name, performance.now() - startedAt);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
export function withProxyServerTimingHeader(response, timing, totalMs = performance.now() - timing.startedAt) {
|
|
39
|
+
if (!timing.enabled)
|
|
40
|
+
return response;
|
|
41
|
+
const metrics = [`proxy.total;dur=${formatDuration(totalMs)}`];
|
|
42
|
+
for (const [name, duration] of timing.phases.entries()) {
|
|
43
|
+
metrics.push(`${sanitizeMetricName(name)};dur=${formatDuration(duration)}`);
|
|
44
|
+
}
|
|
45
|
+
const value = metrics.join(", ");
|
|
46
|
+
try {
|
|
47
|
+
const existing = response.headers.get("Server-Timing");
|
|
48
|
+
response.headers.set("Server-Timing", existing ? `${existing}, ${value}` : value);
|
|
49
|
+
return response;
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
const headers = new Headers(response.headers);
|
|
53
|
+
const existing = headers.get("Server-Timing");
|
|
54
|
+
headers.set("Server-Timing", existing ? `${existing}, ${value}` : value);
|
|
55
|
+
return new Response(response.body, {
|
|
56
|
+
status: response.status,
|
|
57
|
+
statusText: response.statusText,
|
|
58
|
+
headers,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const UPSTREAM_TIMEOUT_STATUS = 504;
|
|
2
|
+
export declare const UPSTREAM_FAILURE_STATUS = 502;
|
|
3
|
+
export declare function createUpstreamTimeoutResponse(timeoutMs: number): Response;
|
|
4
|
+
export declare function createUpstreamFailureResponse(error: unknown): Response;
|
|
5
|
+
//# sourceMappingURL=upstream-error-response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upstream-error-response.d.ts","sourceRoot":"","sources":["../../../src/src/proxy/upstream-error-response.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAC3C,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAE3C,wBAAgB,6BAA6B,CAAC,SAAS,EAAE,MAAM,GAAG,QAAQ,CAKzE;AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,OAAO,GAAG,QAAQ,CAKtE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsonErrorResponse } from "./error-response.js";
|
|
2
|
+
export const UPSTREAM_TIMEOUT_STATUS = 504;
|
|
3
|
+
export const UPSTREAM_FAILURE_STATUS = 502;
|
|
4
|
+
export function createUpstreamTimeoutResponse(timeoutMs) {
|
|
5
|
+
return jsonErrorResponse(UPSTREAM_TIMEOUT_STATUS, {
|
|
6
|
+
error: "Gateway Timeout",
|
|
7
|
+
message: `Server request timed out after ${timeoutMs}ms`,
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export function createUpstreamFailureResponse(error) {
|
|
11
|
+
return jsonErrorResponse(UPSTREAM_FAILURE_STATUS, {
|
|
12
|
+
error: "Proxy Error",
|
|
13
|
+
message: error instanceof Error ? error.message : "Unknown error",
|
|
14
|
+
});
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-module-map.d.ts","sourceRoot":"","sources":["../../../src/src/release-assets/client-module-map.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAEjE,wBAAgB,wBAAwB,CACtC,QAAQ,CAAC,EAAE,oBAAoB,GAAG,IAAI,GACrC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,CASpC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { releaseAssetUrl } from "./constants.js";
|
|
2
|
+
export function buildReleaseAssetModules(manifest) {
|
|
3
|
+
if (!manifest)
|
|
4
|
+
return undefined;
|
|
5
|
+
const modules = {};
|
|
6
|
+
for (const [path, entry] of Object.entries(manifest.modules)) {
|
|
7
|
+
modules[path] = releaseAssetUrl(entry.contentHash, "js");
|
|
8
|
+
}
|
|
9
|
+
return Object.keys(modules).length > 0 ? modules : undefined;
|
|
10
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/src/rendering/orchestrator/module-loader/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/src/rendering/orchestrator/module-loader/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAiBzE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAOpE;;;;;;;;;GASG;AACH,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,cAAc,EAC5B,MAAM,EAAE,kBAAkB,EAC1B,eAAe,UAAQ,GACtB,OAAO,CAAC,MAAM,CAAC,CAsFjB;AAED,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,cAAc,CAAC;IACxB,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC;IACnC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAyBD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAI5D;AAED;;;;;;GAMG;AACH,wBAAsB,UAAU,CAC9B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CA6DlC"}
|
|
@@ -8,23 +8,18 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { rendererLogger } from "../../../utils/index.js";
|
|
10
10
|
import { getLocalAdapter } from "../../../platform/adapters/registry.js";
|
|
11
|
-
import { createFileSystem } from "../../../platform/compat/fs.js";
|
|
12
11
|
import { getProjectTmpDir } from "../../../modules/react-loader/index.js";
|
|
13
12
|
import { getHttpBundleCacheDir, getMdxEsmCacheDir } from "../../../utils/cache-dir.js";
|
|
14
13
|
import { join } from "../../../platform/compat/path/index.js";
|
|
15
|
-
import { invalidateMdxEsmModule
|
|
14
|
+
import { invalidateMdxEsmModule } from "../../../transforms/mdx/esm-module-loader/cache/index.js";
|
|
16
15
|
import { resolveModuleDependencies, rewriteResolvedDependencyImports, } from "./dependency-resolver.js";
|
|
17
16
|
import { persistTransformedModule } from "./module-persistence.js";
|
|
18
|
-
import { transformModuleCodeWithCache
|
|
17
|
+
import { transformModuleCodeWithCache } from "./module-transform-cache.js";
|
|
18
|
+
import { getModuleCacheKey, resolveCachedModulePath } from "./module-cache-lookup.js";
|
|
19
19
|
const logger = rendererLogger.component("module-loader");
|
|
20
20
|
// Re-export utilities
|
|
21
21
|
export { createEsmCache, createModuleCache, generateHash } from "./cache.js";
|
|
22
22
|
export { fetchEsmModule, rewriteEsmPaths } from "./esm-rewriter.js";
|
|
23
|
-
function getModuleCacheKey(filePath, projectId, projectDir, contentSourceId) {
|
|
24
|
-
const base = projectId ?? projectDir ?? "default";
|
|
25
|
-
const source = contentSourceId ?? "default";
|
|
26
|
-
return `${base}:${source}:${filePath}`;
|
|
27
|
-
}
|
|
28
23
|
function decodeFileContent(fileContent) {
|
|
29
24
|
if (typeof fileContent === "string")
|
|
30
25
|
return fileContent;
|
|
@@ -43,48 +38,17 @@ function decodeFileContent(fileContent) {
|
|
|
43
38
|
export async function transformModuleWithDeps(filePath, tmpDir, localAdapter, config, useLocalAdapter = false) {
|
|
44
39
|
const { moduleCache, projectDir, projectId, contentSourceId, adapter, mode } = config;
|
|
45
40
|
const cacheKey = getModuleCacheKey(filePath, projectId, projectDir, contentSourceId);
|
|
46
|
-
const cachedPath =
|
|
41
|
+
const cachedPath = await resolveCachedModulePath({
|
|
42
|
+
cacheKey,
|
|
43
|
+
filePath,
|
|
44
|
+
projectDir,
|
|
45
|
+
projectId,
|
|
46
|
+
contentSourceId,
|
|
47
|
+
moduleCache,
|
|
48
|
+
reactVersion: config.reactVersion,
|
|
49
|
+
});
|
|
47
50
|
if (cachedPath) {
|
|
48
|
-
|
|
49
|
-
// These would fail at runtime and indicate stale cache from before framework import fix
|
|
50
|
-
try {
|
|
51
|
-
const cachedCode = await createFileSystem().readTextFile(cachedPath);
|
|
52
|
-
if (UNRESOLVED_VF_MODULES_RE.test(cachedCode)) {
|
|
53
|
-
logger.warn("[ModuleLoader] In-memory cache contains unresolved _vf_modules, invalidating", {
|
|
54
|
-
filePath: filePath.slice(-60),
|
|
55
|
-
cachedPath: cachedPath.slice(-60),
|
|
56
|
-
});
|
|
57
|
-
moduleCache.delete(cacheKey);
|
|
58
|
-
// Don't return - fall through to re-transform
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
return cachedPath;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
catch (_) {
|
|
65
|
-
/* expected: cached file may no longer exist on disk */
|
|
66
|
-
moduleCache.delete(cacheKey);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
if (projectId && contentSourceId) {
|
|
70
|
-
const baseCacheDir = getMdxEsmCacheDir();
|
|
71
|
-
const projectKey = encodeURIComponent(projectId);
|
|
72
|
-
const sourceKey = encodeURIComponent(contentSourceId);
|
|
73
|
-
const mdxCacheDir = join(baseCacheDir, projectKey, sourceKey);
|
|
74
|
-
const mdxCacheResult = await lookupMdxEsmCache(filePath, mdxCacheDir, projectDir, undefined, {
|
|
75
|
-
projectId,
|
|
76
|
-
contentSourceId,
|
|
77
|
-
}, config.reactVersion);
|
|
78
|
-
if (mdxCacheResult.status === "hit") {
|
|
79
|
-
moduleCache.set(cacheKey, mdxCacheResult.path);
|
|
80
|
-
return mdxCacheResult.path;
|
|
81
|
-
}
|
|
82
|
-
if (mdxCacheResult.status === "corrupted") {
|
|
83
|
-
logger.warn("MDX-ESM cache corrupted, will re-transform", {
|
|
84
|
-
filePath,
|
|
85
|
-
reason: mdxCacheResult.reason,
|
|
86
|
-
});
|
|
87
|
-
}
|
|
51
|
+
return cachedPath;
|
|
88
52
|
}
|
|
89
53
|
const readAdapter = useLocalAdapter ? localAdapter : adapter;
|
|
90
54
|
let fileContent = decodeFileContent(await readAdapter.fs.readFile(filePath));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache lookup phase for the SSR module loader.
|
|
3
|
+
*
|
|
4
|
+
* @module rendering/orchestrator/module-loader/module-cache-lookup
|
|
5
|
+
*/
|
|
6
|
+
import { createFileSystem } from "../../../platform/compat/fs.js";
|
|
7
|
+
import { lookupMdxEsmCache } from "../../../transforms/mdx/esm-module-loader/cache/index.js";
|
|
8
|
+
export declare function getModuleCacheKey(filePath: string, projectId?: string, projectDir?: string, contentSourceId?: string): string;
|
|
9
|
+
type LookupMdxCache = typeof lookupMdxEsmCache;
|
|
10
|
+
type FileSystemReader = Pick<ReturnType<typeof createFileSystem>, "readTextFile">;
|
|
11
|
+
export interface ResolveCachedModulePathInput {
|
|
12
|
+
cacheKey: string;
|
|
13
|
+
filePath: string;
|
|
14
|
+
projectDir: string;
|
|
15
|
+
projectId?: string;
|
|
16
|
+
contentSourceId?: string;
|
|
17
|
+
reactVersion?: string;
|
|
18
|
+
moduleCache: Map<string, string>;
|
|
19
|
+
readTextFile?: (path: string) => Promise<string>;
|
|
20
|
+
fileSystem?: FileSystemReader;
|
|
21
|
+
lookupMdxCache?: LookupMdxCache;
|
|
22
|
+
}
|
|
23
|
+
export declare function resolveCachedModulePath(input: ResolveCachedModulePathInput): Promise<string | undefined>;
|
|
24
|
+
export {};
|
|
25
|
+
//# sourceMappingURL=module-cache-lookup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-cache-lookup.d.ts","sourceRoot":"","sources":["../../../../../src/src/rendering/orchestrator/module-loader/module-cache-lookup.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAEL,iBAAiB,EAClB,MAAM,0DAA0D,CAAC;AAOlE,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,MAAM,GACvB,MAAM,CAIR;AAED,KAAK,cAAc,GAAG,OAAO,iBAAiB,CAAC;AAC/C,KAAK,gBAAgB,GAAG,IAAI,CAAC,UAAU,CAAC,OAAO,gBAAgB,CAAC,EAAE,cAAc,CAAC,CAAC;AAElF,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;IACjD,UAAU,CAAC,EAAE,gBAAgB,CAAC;IAC9B,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC;AAuED,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,4BAA4B,GAClC,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAK7B"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache lookup phase for the SSR module loader.
|
|
3
|
+
*
|
|
4
|
+
* @module rendering/orchestrator/module-loader/module-cache-lookup
|
|
5
|
+
*/
|
|
6
|
+
import { join } from "../../../platform/compat/path/index.js";
|
|
7
|
+
import { createFileSystem } from "../../../platform/compat/fs.js";
|
|
8
|
+
import { lookupMdxEsmCache, } from "../../../transforms/mdx/esm-module-loader/cache/index.js";
|
|
9
|
+
import { getMdxEsmCacheDir } from "../../../utils/cache-dir.js";
|
|
10
|
+
import { rendererLogger } from "../../../utils/index.js";
|
|
11
|
+
import { UNRESOLVED_VF_MODULES_RE } from "./module-transform-cache.js";
|
|
12
|
+
const logger = rendererLogger.component("module-loader");
|
|
13
|
+
export function getModuleCacheKey(filePath, projectId, projectDir, contentSourceId) {
|
|
14
|
+
const base = projectId ?? projectDir ?? "default";
|
|
15
|
+
const source = contentSourceId ?? "default";
|
|
16
|
+
return `${base}:${source}:${filePath}`;
|
|
17
|
+
}
|
|
18
|
+
async function resolveInMemoryCachedPath(input) {
|
|
19
|
+
const cachedPath = input.moduleCache.get(input.cacheKey);
|
|
20
|
+
if (!cachedPath)
|
|
21
|
+
return undefined;
|
|
22
|
+
try {
|
|
23
|
+
const fileSystem = input.fileSystem ?? createFileSystem();
|
|
24
|
+
const readTextFile = input.readTextFile ??
|
|
25
|
+
((path) => fileSystem.readTextFile(path));
|
|
26
|
+
const cachedCode = await readTextFile(cachedPath);
|
|
27
|
+
if (!UNRESOLVED_VF_MODULES_RE.test(cachedCode))
|
|
28
|
+
return cachedPath;
|
|
29
|
+
logger.warn("[ModuleLoader] In-memory cache contains unresolved _vf_modules, invalidating", {
|
|
30
|
+
filePath: input.filePath.slice(-60),
|
|
31
|
+
cachedPath: cachedPath.slice(-60),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
catch (_) {
|
|
35
|
+
/* expected: cached file may no longer exist on disk */
|
|
36
|
+
}
|
|
37
|
+
input.moduleCache.delete(input.cacheKey);
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
async function resolveMdxEsmCachedPath(input) {
|
|
41
|
+
if (!input.projectId || !input.contentSourceId)
|
|
42
|
+
return undefined;
|
|
43
|
+
const baseCacheDir = getMdxEsmCacheDir();
|
|
44
|
+
const projectKey = encodeURIComponent(input.projectId);
|
|
45
|
+
const sourceKey = encodeURIComponent(input.contentSourceId);
|
|
46
|
+
const mdxCacheDir = join(baseCacheDir, projectKey, sourceKey);
|
|
47
|
+
const lookup = input.lookupMdxCache ?? lookupMdxEsmCache;
|
|
48
|
+
const mdxCacheResult = await lookup(input.filePath, mdxCacheDir, input.projectDir, undefined, {
|
|
49
|
+
projectId: input.projectId,
|
|
50
|
+
contentSourceId: input.contentSourceId,
|
|
51
|
+
}, input.reactVersion);
|
|
52
|
+
if (mdxCacheResult.status === "hit") {
|
|
53
|
+
input.moduleCache.set(input.cacheKey, mdxCacheResult.path);
|
|
54
|
+
return mdxCacheResult.path;
|
|
55
|
+
}
|
|
56
|
+
if (mdxCacheResult.status === "corrupted") {
|
|
57
|
+
logger.warn("MDX-ESM cache corrupted, will re-transform", {
|
|
58
|
+
filePath: input.filePath,
|
|
59
|
+
reason: mdxCacheResult.reason,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
export async function resolveCachedModulePath(input) {
|
|
65
|
+
const inMemoryPath = await resolveInMemoryCachedPath(input);
|
|
66
|
+
if (inMemoryPath)
|
|
67
|
+
return inMemoryPath;
|
|
68
|
+
return await resolveMdxEsmCachedPath(input);
|
|
69
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../../../src/src/rendering/orchestrator/pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;
|
|
1
|
+
{"version":3,"file":"pipeline.d.ts","sourceRoot":"","sources":["../../../../src/src/rendering/orchestrator/pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAuBH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA8ChF,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE1D;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACxE,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrF;AAED,MAAM,WAAW,oBAAoB;IACnC,YAAY,EAAE,YAAY,CAAC;IAC3B,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C,YAAY,EAAE,YAAY,CAAC;IAC3B,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,eAAe,EAAE,eAAe,CAAC;IACjC,OAAO,EAAE,cAAc,CAAC;IACxB,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,8EAA8E;IAC9E,iBAAiB,CAAC,EAAE,OAAO,qBAAqB,EAAE,sBAAsB,CAAC;CAC1E;AA0BD,qBAAa,cAAc;IACzB,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,kBAAkB,CAAqB;gBAEnC,MAAM,EAAE,oBAAoB;IAaxC;;;OAGG;IACH,gBAAgB,IAAI,IAAI;IAKxB,OAAO,CAAC,UAAU;YAIJ,0BAA0B;IAaxC;;;;;;;;;OASG;YACW,qBAAqB;IAyDnC;;;OAGG;YACW,mBAAmB;IAiGjC,OAAO,CAAC,uBAAuB;IAkCzB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC;IA8O9E,+EAA+E;IACzE,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC;YAsFzE,kBAAkB;YA2ClB,cAAc;IAW5B,OAAO,CAAC,uBAAuB;YAYjB,kBAAkB;IA8EhC,OAAO,CAAC,kBAAkB;YAQZ,uBAAuB;IAmBrC;;;;;;OAMG;IACH,OAAO,CAAC,aAAa;CAStB"}
|