veryfront 0.1.1122 → 0.1.1124
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/extensions/ext-llm-openai/src/openai-responses-request-builder.d.ts.map +1 -1
- package/esm/extensions/ext-llm-openai/src/openai-responses-request-builder.js +5 -0
- package/esm/src/agent/hosted/child-lifecycle.d.ts.map +1 -1
- package/esm/src/agent/hosted/child-lifecycle.js +1 -12
- package/esm/src/agent/hosted/cloud-agent-chat-execution.d.ts +38 -0
- package/esm/src/agent/hosted/cloud-agent-chat-execution.d.ts.map +1 -0
- package/esm/src/agent/hosted/cloud-agent-chat-execution.js +349 -0
- package/esm/src/agent/hosted/cloud-agent-child-tools.d.ts +80 -0
- package/esm/src/agent/hosted/cloud-agent-child-tools.d.ts.map +1 -0
- package/esm/src/agent/hosted/cloud-agent-child-tools.js +280 -0
- package/esm/src/agent/hosted/cloud-agent-config.d.ts +69 -0
- package/esm/src/agent/hosted/cloud-agent-config.d.ts.map +1 -0
- package/esm/src/agent/hosted/cloud-agent-config.js +129 -0
- package/esm/src/agent/hosted/cloud-agent-paths.d.ts +42 -0
- package/esm/src/agent/hosted/cloud-agent-paths.d.ts.map +1 -0
- package/esm/src/agent/hosted/cloud-agent-paths.js +117 -0
- package/esm/src/agent/hosted/cloud-agent-provider-bootstrap.d.ts +49 -0
- package/esm/src/agent/hosted/cloud-agent-provider-bootstrap.d.ts.map +1 -0
- package/esm/src/agent/hosted/cloud-agent-provider-bootstrap.js +96 -0
- package/esm/src/agent/hosted/durable-child-fork-execution.d.ts.map +1 -1
- package/esm/src/agent/hosted/durable-child-fork-execution.js +1 -12
- package/esm/src/agent/hosted/runtime-request-config.js +2 -2
- package/esm/src/agent/hosted/stream-finalization.d.ts.map +1 -1
- package/esm/src/agent/hosted/stream-finalization.js +2 -26
- package/esm/src/agent/hosted/veryfront-cloud-agent-service.d.ts +11 -93
- package/esm/src/agent/hosted/veryfront-cloud-agent-service.d.ts.map +1 -1
- package/esm/src/agent/hosted/veryfront-cloud-agent-service.js +8 -901
- package/esm/src/agent/project/agent-runtime.d.ts.map +1 -1
- package/esm/src/agent/project/agent-runtime.js +3 -0
- package/esm/src/agent/runtime/chat-stream-handler.d.ts.map +1 -1
- package/esm/src/agent/runtime/chat-stream-handler.js +1 -28
- package/esm/src/agent/streaming/stream-outcome.d.ts +30 -0
- package/esm/src/agent/streaming/stream-outcome.d.ts.map +1 -0
- package/esm/src/agent/streaming/stream-outcome.js +62 -0
- package/esm/src/agent/types.d.ts +3 -0
- package/esm/src/agent/types.d.ts.map +1 -1
- package/esm/src/chat/message-prep.d.ts.map +1 -1
- package/esm/src/chat/message-prep.js +3 -6
- package/esm/src/chat/provider-errors.d.ts +3 -10
- package/esm/src/chat/provider-errors.d.ts.map +1 -1
- package/esm/src/chat/provider-errors.js +2 -9
- package/esm/src/embedding/veryfront-cloud/rag-store.d.ts.map +1 -1
- package/esm/src/embedding/veryfront-cloud/rag-store.js +5 -2
- package/esm/src/eval/studio.d.ts +1 -1
- package/esm/src/html/styles-builder/plugin-loader.d.ts.map +1 -1
- package/esm/src/html/styles-builder/plugin-loader.js +4 -2
- package/esm/src/modules/server/classify.d.ts +54 -0
- package/esm/src/modules/server/classify.d.ts.map +1 -0
- package/esm/src/modules/server/classify.js +50 -0
- package/esm/src/modules/server/fs-probe.d.ts +14 -0
- package/esm/src/modules/server/fs-probe.d.ts.map +1 -0
- package/esm/src/modules/server/fs-probe.js +17 -0
- package/esm/src/modules/server/module-batch-handler.d.ts.map +1 -1
- package/esm/src/modules/server/module-batch-handler.js +31 -45
- package/esm/src/modules/server/module-server.d.ts.map +1 -1
- package/esm/src/modules/server/module-server.js +77 -93
- package/esm/src/modules/server/module-transform.d.ts +73 -0
- package/esm/src/modules/server/module-transform.d.ts.map +1 -0
- package/esm/src/modules/server/module-transform.js +64 -0
- package/esm/src/modules/server/ssr-import-rewriter.d.ts +1 -1
- package/esm/src/modules/server/ssr-import-rewriter.d.ts.map +1 -1
- package/esm/src/observability/error-collector.d.ts.map +1 -1
- package/esm/src/observability/error-collector.js +4 -11
- package/esm/src/observability/log-buffer.d.ts.map +1 -1
- package/esm/src/observability/log-buffer.js +4 -11
- package/esm/src/observability/request-profiler.d.ts +4 -0
- package/esm/src/observability/request-profiler.d.ts.map +1 -1
- package/esm/src/observability/request-profiler.js +9 -4
- package/esm/src/platform/adapters/veryfront-api-client/operations.d.ts +3 -3
- package/esm/src/platform/adapters/veryfront-api-client/operations.d.ts.map +1 -1
- package/esm/src/platform/adapters/veryfront-api-client/operations.js +4 -4
- package/esm/src/platform/adapters/veryfront-api-client/retry-handler.d.ts +4 -15
- package/esm/src/platform/adapters/veryfront-api-client/retry-handler.d.ts.map +1 -1
- package/esm/src/platform/adapters/veryfront-api-client/retry-handler.js +6 -110
- package/esm/src/platform/adapters/veryfront-api-transport.d.ts +40 -0
- package/esm/src/platform/adapters/veryfront-api-transport.d.ts.map +1 -0
- package/esm/src/platform/adapters/veryfront-api-transport.js +142 -0
- package/esm/src/provider/runtime-loader/provider-http.d.ts.map +1 -1
- package/esm/src/provider/runtime-loader/provider-http.js +5 -1
- package/esm/src/proxy/server-timing.d.ts.map +1 -1
- package/esm/src/proxy/server-timing.js +2 -14
- package/esm/src/react/components/chat/agent-card.d.ts +2 -3
- package/esm/src/react/components/chat/agent-card.d.ts.map +1 -1
- package/esm/src/react/components/chat/agent-card.js +3 -12
- package/esm/src/react/components/chat/agent-picker-context.d.ts +2 -3
- package/esm/src/react/components/chat/agent-picker-context.d.ts.map +1 -1
- package/esm/src/react/components/chat/agent-picker-context.js +3 -13
- package/esm/src/react/components/chat/chat/components/attachment-pill.d.ts +2 -6
- package/esm/src/react/components/chat/chat/components/attachment-pill.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat/components/attachment-pill.js +3 -15
- package/esm/src/react/components/chat/chat/components/attachments-panel.d.ts +2 -12
- package/esm/src/react/components/chat/chat/components/attachments-panel.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat/components/attachments-panel.js +3 -21
- package/esm/src/react/components/chat/chat/components/branch-picker.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat/components/branch-picker.js +2 -11
- package/esm/src/react/components/chat/chat/components/inline-citation.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat/components/inline-citation.js +2 -11
- package/esm/src/react/components/chat/chat/components/message-actions.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat/components/message-actions.js +2 -11
- package/esm/src/react/components/chat/chat/components/message-feedback.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat/components/message-feedback.js +2 -11
- package/esm/src/react/components/chat/chat/components/reasoning.d.ts +2 -3
- package/esm/src/react/components/chat/chat/components/reasoning.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat/components/reasoning.js +3 -12
- package/esm/src/react/components/chat/chat/components/sidebar.d.ts +2 -3
- package/esm/src/react/components/chat/chat/components/sidebar.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat/components/sidebar.js +4 -22
- package/esm/src/react/components/chat/chat/components/sources.d.ts +2 -3
- package/esm/src/react/components/chat/chat/components/sources.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat/components/sources.js +3 -12
- package/esm/src/react/components/chat/chat/components/step-indicator.d.ts +2 -6
- package/esm/src/react/components/chat/chat/components/step-indicator.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat/components/step-indicator.js +3 -15
- package/esm/src/react/components/chat/chat/components/tool-ui.d.ts +2 -3
- package/esm/src/react/components/chat/chat/components/tool-ui.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat/components/tool-ui.js +3 -12
- package/esm/src/react/components/chat/chat/composition/chat-message-list.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat/composition/chat-message-list.js +2 -11
- package/esm/src/react/components/chat/chat/contexts/chat-context.d.ts +2 -2
- package/esm/src/react/components/chat/chat/contexts/chat-context.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat/contexts/chat-context.js +3 -12
- package/esm/src/react/components/chat/chat/contexts/composer-context.d.ts +2 -2
- package/esm/src/react/components/chat/chat/contexts/composer-context.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat/contexts/composer-context.js +3 -12
- package/esm/src/react/components/chat/chat/contexts/conversations-context.d.ts +2 -2
- package/esm/src/react/components/chat/chat/contexts/conversations-context.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat/contexts/conversations-context.js +3 -12
- package/esm/src/react/components/chat/chat/contexts/message-context.d.ts +2 -2
- package/esm/src/react/components/chat/chat/contexts/message-context.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat/contexts/message-context.js +3 -12
- package/esm/src/react/components/chat/chat-actions.d.ts +2 -6
- package/esm/src/react/components/chat/chat-actions.d.ts.map +1 -1
- package/esm/src/react/components/chat/chat-actions.js +3 -15
- package/esm/src/react/components/chat/model-selector.d.ts +2 -6
- package/esm/src/react/components/chat/model-selector.d.ts.map +1 -1
- package/esm/src/react/components/chat/model-selector.js +3 -15
- package/esm/src/react/components/create-strict-context.d.ts +44 -0
- package/esm/src/react/components/create-strict-context.d.ts.map +1 -0
- package/esm/src/react/components/create-strict-context.js +56 -0
- package/esm/src/react/components/ui/anchored-surface.d.ts +44 -0
- package/esm/src/react/components/ui/anchored-surface.d.ts.map +1 -0
- package/esm/src/react/components/ui/anchored-surface.js +58 -0
- package/esm/src/react/components/ui/app-shell.d.ts +2 -2
- package/esm/src/react/components/ui/app-shell.d.ts.map +1 -1
- package/esm/src/react/components/ui/app-shell.js +3 -7
- package/esm/src/react/components/ui/collapsible.d.ts.map +1 -1
- package/esm/src/react/components/ui/collapsible.js +3 -9
- package/esm/src/react/components/ui/color-mode.d.ts +2 -2
- package/esm/src/react/components/ui/color-mode.d.ts.map +1 -1
- package/esm/src/react/components/ui/color-mode.js +3 -11
- package/esm/src/react/components/ui/command.d.ts.map +1 -1
- package/esm/src/react/components/ui/command.js +2 -7
- package/esm/src/react/components/ui/dialog.d.ts +4 -7
- package/esm/src/react/components/ui/dialog.d.ts.map +1 -1
- package/esm/src/react/components/ui/dialog.js +13 -59
- package/esm/src/react/components/ui/disclosure.d.ts +12 -0
- package/esm/src/react/components/ui/disclosure.d.ts.map +1 -0
- package/esm/src/react/components/ui/disclosure.js +22 -0
- package/esm/src/react/components/ui/drawer.d.ts +5 -7
- package/esm/src/react/components/ui/drawer.d.ts.map +1 -1
- package/esm/src/react/components/ui/drawer.js +13 -57
- package/esm/src/react/components/ui/dropdown-menu.d.ts +4 -7
- package/esm/src/react/components/ui/dropdown-menu.d.ts.map +1 -1
- package/esm/src/react/components/ui/dropdown-menu.js +12 -31
- package/esm/src/react/components/ui/modal-surface.d.ts +43 -0
- package/esm/src/react/components/ui/modal-surface.d.ts.map +1 -0
- package/esm/src/react/components/ui/modal-surface.js +83 -0
- package/esm/src/react/components/ui/popover.d.ts +4 -7
- package/esm/src/react/components/ui/popover.d.ts.map +1 -1
- package/esm/src/react/components/ui/popover.js +11 -31
- package/esm/src/react/components/ui/select.d.ts.map +1 -1
- package/esm/src/react/components/ui/select.js +2 -7
- package/esm/src/react/components/ui/tabs.d.ts.map +1 -1
- package/esm/src/react/components/ui/tabs.js +3 -4
- package/esm/src/runs/schemas.d.ts +9 -9
- package/esm/src/server/handlers/dev/framework-candidates.generated.d.ts.map +1 -1
- package/esm/src/server/handlers/dev/framework-candidates.generated.js +253 -154
- package/esm/src/server/reload-notifier.d.ts +0 -1
- package/esm/src/server/reload-notifier.d.ts.map +1 -1
- package/esm/src/server/reload-notifier.js +7 -25
- package/esm/src/server/services/rsc/endpoints/rsc-bundles.generated.d.ts.map +1 -1
- package/esm/src/server/services/rsc/endpoints/rsc-bundles.generated.js +1 -1
- package/esm/src/utils/base64url.d.ts +9 -1
- package/esm/src/utils/base64url.d.ts.map +1 -1
- package/esm/src/utils/base64url.js +25 -11
- package/esm/src/utils/index.d.ts +3 -1
- package/esm/src/utils/index.d.ts.map +1 -1
- package/esm/src/utils/index.js +3 -1
- package/esm/src/utils/json.d.ts +19 -0
- package/esm/src/utils/json.d.ts.map +1 -0
- package/esm/src/utils/json.js +17 -0
- package/esm/src/utils/logger/redact.d.ts.map +1 -1
- package/esm/src/utils/logger/redact.js +7 -3
- package/esm/src/utils/subscriber-set.d.ts +19 -0
- package/esm/src/utils/subscriber-set.d.ts.map +1 -0
- package/esm/src/utils/subscriber-set.js +38 -0
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/esm/src/workflow/backends/redis/index.d.ts.map +1 -1
- package/esm/src/workflow/backends/redis/index.js +6 -7
- package/esm/src/workflow/claude-code/websocket-publisher.d.ts.map +1 -1
- package/esm/src/workflow/claude-code/websocket-publisher.js +8 -15
- package/esm/src/workflow/schemas/workflow.schema.d.ts +4 -4
- package/package.json +5 -5
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
*/
|
|
18
18
|
import { HTTP_BAD_REQUEST, HTTP_NOT_FOUND, HTTP_OK, MAX_BATCH_SIZE, serverLogger, } from "../../utils/index.js";
|
|
19
19
|
import { createSecureFs } from "../../security/index.js";
|
|
20
|
-
import { transformToESM } from "../../transforms/esm-transform.js";
|
|
21
20
|
import { createFileSystem } from "../../platform/compat/fs.js";
|
|
22
21
|
import { join } from "../../platform/compat/path/index.js";
|
|
23
|
-
import {
|
|
22
|
+
import { resolveSSRImportTargetModulePath, stripSSRModuleJsExtension, } from "./ssr-import-rewriter.js";
|
|
23
|
+
import { transformModuleToServable } from "./module-transform.js";
|
|
24
24
|
import { buildModuleTransformCacheKey } from "../../cache/keys.js";
|
|
25
25
|
import { withSpan } from "../../observability/tracing/otlp-setup.js";
|
|
26
26
|
import { getFrameworkSourceLookupDirs } from "../../platform/compat/framework-source-resolver.js";
|
|
@@ -28,6 +28,7 @@ import { LRUCache } from "../../utils/lru-wrapper.js";
|
|
|
28
28
|
import { registerLRUCache } from "../../cache/index.js";
|
|
29
29
|
import { sha256Short } from "../../cache/hash.js";
|
|
30
30
|
import { buildSourceMissCacheKey, clearSourceMissCache, hasSourceMiss, rememberSourceMiss, } from "./module-source-resolution-cache.js";
|
|
31
|
+
import { findFirstExistingFile } from "./fs-probe.js";
|
|
31
32
|
const logger = serverLogger.component("module-batch");
|
|
32
33
|
/** Slow request threshold in milliseconds */
|
|
33
34
|
const SLOW_REQUEST_THRESHOLD_MS = 500;
|
|
@@ -55,30 +56,6 @@ const FRAMEWORK_EXTENSIONS = [
|
|
|
55
56
|
".jsx",
|
|
56
57
|
".js", // Regular sources for dev mode
|
|
57
58
|
];
|
|
58
|
-
async function findFirstSecureFile(secureFs, paths) {
|
|
59
|
-
const results = await Promise.all(paths.map(async (path) => {
|
|
60
|
-
try {
|
|
61
|
-
const stat = await secureFs.stat(path);
|
|
62
|
-
return stat.isFile ? path : null;
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
}));
|
|
68
|
-
return results.find((path) => path !== null) ?? null;
|
|
69
|
-
}
|
|
70
|
-
async function findFirstPlatformFile(platformFs, paths) {
|
|
71
|
-
const results = await Promise.all(paths.map(async (path) => {
|
|
72
|
-
try {
|
|
73
|
-
const stat = await platformFs.stat(path);
|
|
74
|
-
return stat.isFile ? path : null;
|
|
75
|
-
}
|
|
76
|
-
catch {
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
}));
|
|
80
|
-
return results.find((path) => path !== null) ?? null;
|
|
81
|
-
}
|
|
82
59
|
/**
|
|
83
60
|
* Handle a batch module request
|
|
84
61
|
*/
|
|
@@ -231,7 +208,7 @@ async function loadAndTransformModule(modulePath, projectDir, adapter, secureFs,
|
|
|
231
208
|
});
|
|
232
209
|
if (hasSourceMiss(missCacheKey))
|
|
233
210
|
return null;
|
|
234
|
-
const sourcePath = await
|
|
211
|
+
const sourcePath = await findFirstExistingFile(secureFs, EXTENSIONS.map((ext) => join(projectDir, basePath + ext)));
|
|
235
212
|
if (sourcePath) {
|
|
236
213
|
const source = await secureFs.readFile(sourcePath);
|
|
237
214
|
return transformModule(source, sourcePath, modulePath, projectDir, adapter, secureFs, options);
|
|
@@ -243,7 +220,7 @@ async function loadAndTransformModule(modulePath, projectDir, adapter, secureFs,
|
|
|
243
220
|
const frameworkLookupDirs = getFrameworkSourceLookupDirs();
|
|
244
221
|
const platformFs = createFileSystem();
|
|
245
222
|
for (const lookupDir of frameworkLookupDirs) {
|
|
246
|
-
const frameworkPath = await
|
|
223
|
+
const frameworkPath = await findFirstExistingFile(platformFs, FRAMEWORK_EXTENSIONS.map((ext) => join(lookupDir, basePath + ext)));
|
|
247
224
|
if (frameworkPath) {
|
|
248
225
|
const source = await platformFs.readTextFile(frameworkPath);
|
|
249
226
|
return transformModule(source, frameworkPath, modulePath, projectDir, adapter, secureFs, options);
|
|
@@ -253,24 +230,33 @@ async function loadAndTransformModule(modulePath, projectDir, adapter, secureFs,
|
|
|
253
230
|
return null;
|
|
254
231
|
}
|
|
255
232
|
async function transformModule(source, sourceFile, modulePath, projectDir, adapter, secureFs, options) {
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
233
|
+
return transformModuleToServable({
|
|
234
|
+
source,
|
|
235
|
+
sourceFile,
|
|
236
|
+
projectDir,
|
|
237
|
+
adapter,
|
|
238
|
+
transformOpts: {
|
|
239
|
+
projectId: options.projectId ?? projectDir,
|
|
240
|
+
dev: options.dev,
|
|
241
|
+
ssr: options.ssr,
|
|
242
|
+
reactVersion: options.reactVersion,
|
|
243
|
+
},
|
|
244
|
+
isSSR: options.ssr,
|
|
245
|
+
ssrRewriteOptions: options.ssr
|
|
246
|
+
? {
|
|
247
|
+
projectSlug: options.projectSlug,
|
|
248
|
+
branch: options.branch,
|
|
249
|
+
resolveCacheBuster: createBatchSSRTargetCacheBusterResolver({
|
|
250
|
+
projectDir,
|
|
251
|
+
secureFs,
|
|
252
|
+
currentModulePath: modulePath,
|
|
253
|
+
}),
|
|
254
|
+
}
|
|
255
|
+
: undefined,
|
|
256
|
+
// No releaseRewriteOptions: the batch handler does not rewrite release
|
|
257
|
+
// dependency imports on the non-SSR path (intentional difference vs
|
|
258
|
+
// the module-server paths; noted in module-transform.ts JSDoc).
|
|
261
259
|
});
|
|
262
|
-
if (options.ssr) {
|
|
263
|
-
code = await applySSRImportRewritesAsync(code, {
|
|
264
|
-
projectSlug: options.projectSlug,
|
|
265
|
-
branch: options.branch,
|
|
266
|
-
resolveCacheBuster: createBatchSSRTargetCacheBusterResolver({
|
|
267
|
-
projectDir,
|
|
268
|
-
secureFs,
|
|
269
|
-
currentModulePath: modulePath,
|
|
270
|
-
}),
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
return code;
|
|
274
260
|
}
|
|
275
261
|
async function readBatchTargetSource(projectDir, secureFs, modulePath) {
|
|
276
262
|
const basePath = stripSSRModuleJsExtension(modulePath);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-server.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/server/module-server.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAG5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"module-server.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/server/module-server.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAG5E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AA4DtE;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAyDrD,CAAC;AAkEF,MAAM,WAAW,mBAAmB;IAClC,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;IAClB,6BAA6B;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,sBAAsB;IACtB,OAAO,EAAE,cAAc,CAAC;IACxB,uBAAuB;IACvB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,+DAA+D;IAC/D,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,gFAAgF;IAChF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mDAAmD;IACnD,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,uDAAuD;IACvD,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,sFAAsF;IACtF,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,sDAAsD;AACtD,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6czF;AAwUD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAGrD;AAiBD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CA8BlE"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/** Module Server - serves transformed ESM modules at /_vf_modules/* URLs */
|
|
2
2
|
import { join } from "../../platform/compat/path/index.js";
|
|
3
3
|
import { createFileSystem } from "../../platform/compat/fs.js";
|
|
4
|
-
import { transformToESM } from "../../transforms/esm-transform.js";
|
|
5
4
|
import { serverLogger, VERSION } from "../../utils/index.js";
|
|
6
5
|
import { HTTP_NOT_FOUND, HTTP_OK, HTTP_SERVER_ERROR } from "../../utils/index.js";
|
|
7
6
|
import { getContentTypeForPath } from "../../server/handlers/utils/content-types.js";
|
|
@@ -12,18 +11,21 @@ import { markRequestProfilePhase, metrics, profilePhase, } from "../../observabi
|
|
|
12
11
|
import { injectContext, withSpan } from "../../observability/tracing/otlp-setup.js";
|
|
13
12
|
import { injectNodePositions } from "../../transforms/plugins/babel-node-positions.js";
|
|
14
13
|
import { parseProjectDomain } from "../../server/utils/domain-parser.js";
|
|
15
|
-
import {
|
|
14
|
+
import { resolveSSRImportTargetModulePath, stripSSRModuleJsExtension, } from "./ssr-import-rewriter.js";
|
|
16
15
|
import { addHMRTimestamps } from "../../transforms/esm/import-rewriter.js";
|
|
17
16
|
import { replaceSpecifiers } from "../../transforms/esm/lexer.js";
|
|
18
17
|
import { FRAMEWORK_ROOT, resolveFrameworkSourcePath, } from "../../platform/compat/framework-source-resolver.js";
|
|
19
18
|
import { getReactUrls, REACT_DEFAULT_VERSION } from "../../utils/constants/cdn.js";
|
|
20
19
|
import { readLimitedCrossProjectSource } from "./cross-project-source-limit.js";
|
|
21
20
|
import { sha256Short } from "../../cache/hash.js";
|
|
22
|
-
import { getReleaseDependencyRewriteManifestState, hasReleaseDependencyImportSpecifiers,
|
|
21
|
+
import { getReleaseDependencyRewriteManifestState, hasReleaseDependencyImportSpecifiers, } from "../../release-assets/module-consumption.js";
|
|
23
22
|
import { RELEASE_ASSET_IMMUTABLE_MAX_AGE_SECONDS, RELEASE_MODULE_RUNTIME_VERSION_PARAM, RELEASE_MODULE_VERSION_PARAM, } from "../../release-assets/constants.js";
|
|
24
23
|
import { buildSourceMissCacheKey, hasSourceMiss, rememberSourceMiss, } from "./module-source-resolution-cache.js";
|
|
25
24
|
import { buildReleaseModuleResponseCacheKey, getReleaseModuleResponse, rememberReleaseModuleResponse, } from "./module-response-cache.js";
|
|
25
|
+
import { findFirstExistingFile } from "./fs-probe.js";
|
|
26
26
|
import { ensureFilenameDefaultExport } from "../loader-shared/filename-default-export.js";
|
|
27
|
+
import { classifyModuleRequest, DEV_MODULE_PREFIX } from "./classify.js";
|
|
28
|
+
import { transformModuleToServable } from "./module-transform.js";
|
|
27
29
|
const logger = serverLogger.component("module-server");
|
|
28
30
|
const PROJECT_FALLBACK_EMBEDDED_POLYFILLS = new Set(["deno"]);
|
|
29
31
|
/**
|
|
@@ -94,11 +96,6 @@ export default {};
|
|
|
94
96
|
// dnt rewrites #deno-config to relative deno.js in npm framework modules.
|
|
95
97
|
"deno": `export default ${JSON.stringify({ version: VERSION })};\n`,
|
|
96
98
|
};
|
|
97
|
-
const DEV_MODULE_PREFIX = /^\/(?:_vf_modules|_veryfront\/modules)\//;
|
|
98
|
-
const SNIPPET_MODULE_PREFIX = /^\/_vf_modules\/_snippets\/([a-f0-9]+)\.js/;
|
|
99
|
-
// Cross-project import patterns: /_vf_modules/_cross/<slug>[@<version>]/@/<path>
|
|
100
|
-
const CROSS_PROJECT_VERSIONED_PREFIX = /^\/_vf_modules\/_cross\/([a-z0-9-]+)@([\d^~x][\d.x^~-]*)\/\@\/(.+)$/;
|
|
101
|
-
const CROSS_PROJECT_LATEST_PREFIX = /^\/_vf_modules\/_cross\/([a-z0-9-]+)\/\@\/(.+)$/;
|
|
102
99
|
function appendReleaseModuleVersion(url, releaseId) {
|
|
103
100
|
if (url.includes(`${RELEASE_MODULE_VERSION_PARAM}=`) ||
|
|
104
101
|
url.includes(`${RELEASE_MODULE_RUNTIME_VERSION_PARAM}=`)) {
|
|
@@ -172,15 +169,15 @@ export function serveModule(req, options) {
|
|
|
172
169
|
pathname: url.pathname,
|
|
173
170
|
userAgent: debugUserAgent.slice(0, 50),
|
|
174
171
|
});
|
|
175
|
-
|
|
172
|
+
const kind = classifyModuleRequest(url);
|
|
173
|
+
if (kind.kind === "not-module") {
|
|
176
174
|
return createModuleResponse(method, "Module not found", HTTP_NOT_FOUND, {
|
|
177
175
|
"Content-Type": "text/plain; charset=utf-8",
|
|
178
176
|
"Cache-Control": "no-cache",
|
|
179
177
|
});
|
|
180
178
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const hash = snippetMatch[1];
|
|
179
|
+
if (kind.kind === "snippet") {
|
|
180
|
+
const { hash } = kind;
|
|
184
181
|
if (!hash) {
|
|
185
182
|
return createModuleResponse(method, "Missing snippet hash", HTTP_NOT_FOUND, {
|
|
186
183
|
"Content-Type": "text/plain; charset=utf-8",
|
|
@@ -205,9 +202,14 @@ export function serveModule(req, options) {
|
|
|
205
202
|
codeLength: snippetCode.length,
|
|
206
203
|
});
|
|
207
204
|
try {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
205
|
+
const transformedCode = await transformModuleToServable({
|
|
206
|
+
source: snippetCode,
|
|
207
|
+
sourceFile: `_snippets/${hash}.tsx`,
|
|
208
|
+
projectDir,
|
|
209
|
+
adapter,
|
|
210
|
+
transformOpts: { projectId: effectiveProjectId, dev, ssr: isSSR, reactVersion },
|
|
211
|
+
isSSR,
|
|
212
|
+
ssrRewriteOptions: {
|
|
211
213
|
projectSlug: snippetProjectSlug,
|
|
212
214
|
branch: snippetBranch,
|
|
213
215
|
resolveCacheBuster: createSSRTargetCacheBusterResolver({
|
|
@@ -220,14 +222,13 @@ export function serveModule(req, options) {
|
|
|
220
222
|
releaseId: options.releaseId,
|
|
221
223
|
reactVersion,
|
|
222
224
|
}),
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
else {
|
|
226
|
-
transformedCode = await rewriteReleaseDependencyImportsForModule(transformedCode, {
|
|
225
|
+
},
|
|
226
|
+
releaseRewriteOptions: {
|
|
227
227
|
releaseId: options.releaseId,
|
|
228
228
|
readDependencySource: (path) => platformFs.readTextFile(path),
|
|
229
|
-
}
|
|
230
|
-
|
|
229
|
+
},
|
|
230
|
+
profile: true,
|
|
231
|
+
});
|
|
231
232
|
logger.debug("Snippet transformed", {
|
|
232
233
|
hash,
|
|
233
234
|
isSSR,
|
|
@@ -247,12 +248,10 @@ export function serveModule(req, options) {
|
|
|
247
248
|
});
|
|
248
249
|
}
|
|
249
250
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const
|
|
254
|
-
const crossVersion = versionedMatch?.[2] ?? "latest";
|
|
255
|
-
const crossPath = versionedMatch?.[3] ?? latestMatch?.[2];
|
|
251
|
+
if (kind.kind === "cross-project-versioned" || kind.kind === "cross-project-latest") {
|
|
252
|
+
const crossProjectSlug = kind.slug;
|
|
253
|
+
const crossVersion = kind.kind === "cross-project-versioned" ? kind.version : "latest";
|
|
254
|
+
const crossPath = kind.path;
|
|
256
255
|
if (!crossProjectSlug || !crossPath) {
|
|
257
256
|
return createModuleResponse(method, "Invalid cross-project import path", HTTP_NOT_FOUND, {
|
|
258
257
|
"Content-Type": "text/plain; charset=utf-8",
|
|
@@ -276,15 +275,20 @@ export function serveModule(req, options) {
|
|
|
276
275
|
});
|
|
277
276
|
}
|
|
278
277
|
const isSSR = isSSRModuleRequest(req, url);
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
278
|
+
const code = await transformModuleToServable({
|
|
279
|
+
source,
|
|
280
|
+
sourceFile: crossPath,
|
|
281
|
+
projectDir,
|
|
282
|
+
adapter,
|
|
283
|
+
transformOpts: {
|
|
284
|
+
projectId: effectiveProjectId,
|
|
285
|
+
dev,
|
|
286
|
+
ssr: isSSR,
|
|
287
|
+
moduleServerUrl: `http://${url.host}`,
|
|
288
|
+
reactVersion,
|
|
289
|
+
},
|
|
290
|
+
isSSR,
|
|
291
|
+
ssrRewriteOptions: {
|
|
288
292
|
crossProjectRef: projectRef,
|
|
289
293
|
resolveCacheBuster: createSSRTargetCacheBusterResolver({
|
|
290
294
|
secureFs,
|
|
@@ -295,14 +299,13 @@ export function serveModule(req, options) {
|
|
|
295
299
|
releaseId: options.releaseId,
|
|
296
300
|
reactVersion,
|
|
297
301
|
}),
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
else {
|
|
301
|
-
code = await rewriteReleaseDependencyImportsForModule(code, {
|
|
302
|
+
},
|
|
303
|
+
releaseRewriteOptions: {
|
|
302
304
|
releaseId: options.releaseId,
|
|
303
305
|
readDependencySource: (path) => platformFs.readTextFile(path),
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
+
},
|
|
307
|
+
profile: true,
|
|
308
|
+
});
|
|
306
309
|
return createModuleResponse(method, code, HTTP_OK, {
|
|
307
310
|
"Content-Type": "application/javascript; charset=utf-8",
|
|
308
311
|
"Cache-Control": "no-cache",
|
|
@@ -316,6 +319,7 @@ export function serveModule(req, options) {
|
|
|
316
319
|
});
|
|
317
320
|
}
|
|
318
321
|
}
|
|
322
|
+
// dev-module path (kind.kind === "dev-module")
|
|
319
323
|
let modulePath = url.pathname.replace(DEV_MODULE_PREFIX, "");
|
|
320
324
|
modulePath = modulePath.replace(/^\/+/, "");
|
|
321
325
|
if (modulePath.startsWith("_vf_modules/")) {
|
|
@@ -436,10 +440,22 @@ export function serveModule(req, options) {
|
|
|
436
440
|
studioEmbed,
|
|
437
441
|
reactVersion,
|
|
438
442
|
};
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
+
// The dev-module path has two post-steps that stay outside
|
|
444
|
+
// transformModuleToServable to keep its API small:
|
|
445
|
+
// - HMR timestamp injection: runs after the full shared sequence
|
|
446
|
+
// (originally between the SSR rewrite and the non-SSR release
|
|
447
|
+
// rewrite; reordering is safe because they touch disjoint
|
|
448
|
+
// specifiers)
|
|
449
|
+
// - addReleaseVersionToFallbackImports: runs after the release rewrite
|
|
450
|
+
code = await transformModuleToServable({
|
|
451
|
+
source,
|
|
452
|
+
sourceFile,
|
|
453
|
+
projectDir,
|
|
454
|
+
adapter,
|
|
455
|
+
transformOpts,
|
|
456
|
+
isSSR,
|
|
457
|
+
postTransform: (c) => ensureFilenameDefaultExport(modulePath, c),
|
|
458
|
+
ssrRewriteOptions: {
|
|
443
459
|
projectSlug,
|
|
444
460
|
branch,
|
|
445
461
|
resolveCacheBuster: createSSRTargetCacheBusterResolver({
|
|
@@ -452,8 +468,15 @@ export function serveModule(req, options) {
|
|
|
452
468
|
releaseId: options.releaseId,
|
|
453
469
|
reactVersion,
|
|
454
470
|
}),
|
|
455
|
-
}
|
|
456
|
-
|
|
471
|
+
},
|
|
472
|
+
releaseRewriteOptions: {
|
|
473
|
+
releaseId: options.releaseId,
|
|
474
|
+
manifest: releaseDependencyRewriteEnabled ? releaseDependencyManifest : undefined,
|
|
475
|
+
manifestReadOptions: { refreshCachedNull: true },
|
|
476
|
+
readDependencySource: (path) => platformFs.readTextFile(path),
|
|
477
|
+
},
|
|
478
|
+
profile: true,
|
|
479
|
+
});
|
|
457
480
|
const hmrTimestamp = url.searchParams.get("t");
|
|
458
481
|
if (hmrTimestamp) {
|
|
459
482
|
code = await addHMRTimestamps(code, hmrTimestamp);
|
|
@@ -463,12 +486,6 @@ export function serveModule(req, options) {
|
|
|
463
486
|
});
|
|
464
487
|
}
|
|
465
488
|
if (!isSSR) {
|
|
466
|
-
code = await rewriteReleaseDependencyImportsForModule(code, {
|
|
467
|
-
releaseId: options.releaseId,
|
|
468
|
-
manifest: releaseDependencyRewriteEnabled ? releaseDependencyManifest : undefined,
|
|
469
|
-
manifestReadOptions: { refreshCachedNull: true },
|
|
470
|
-
readDependencySource: (path) => platformFs.readTextFile(path),
|
|
471
|
-
});
|
|
472
489
|
code = await addReleaseVersionToFallbackImports(code, modulePath, options.releaseId);
|
|
473
490
|
}
|
|
474
491
|
}
|
|
@@ -571,31 +588,7 @@ function createBrowserReactPackageShim(basePathWithoutExt, reactVersion = REACT_
|
|
|
571
588
|
async function findFrameworkPackageAssetFile(fs, basePathWithoutExt, extensions) {
|
|
572
589
|
if (hasUnsafePackageAssetPath(basePathWithoutExt))
|
|
573
590
|
return null;
|
|
574
|
-
return await
|
|
575
|
-
}
|
|
576
|
-
async function findFirstPlatformFile(fs, paths) {
|
|
577
|
-
const results = await Promise.all(paths.map(async (path) => {
|
|
578
|
-
try {
|
|
579
|
-
const stat = await fs.stat(path);
|
|
580
|
-
return stat.isFile ? path : null;
|
|
581
|
-
}
|
|
582
|
-
catch {
|
|
583
|
-
return null;
|
|
584
|
-
}
|
|
585
|
-
}));
|
|
586
|
-
return results.find((path) => path !== null) ?? null;
|
|
587
|
-
}
|
|
588
|
-
async function findFirstSecureFile(secureFs, paths) {
|
|
589
|
-
const results = await Promise.all(paths.map(async (path) => {
|
|
590
|
-
try {
|
|
591
|
-
const stat = await secureFs.stat(path);
|
|
592
|
-
return stat.isFile ? path : null;
|
|
593
|
-
}
|
|
594
|
-
catch {
|
|
595
|
-
return null;
|
|
596
|
-
}
|
|
597
|
-
}));
|
|
598
|
-
return results.find((path) => path !== null) ?? null;
|
|
591
|
+
return await findFirstExistingFile(fs, extensions.map((ext) => join(FRAMEWORK_ROOT, basePathWithoutExt + ext)));
|
|
599
592
|
}
|
|
600
593
|
async function findSourceFile(secureFs, projectDir, basePath, context, requestedModulePath = basePath) {
|
|
601
594
|
const { reactVersion } = context;
|
|
@@ -715,7 +708,7 @@ async function findSourceFile(secureFs, projectDir, basePath, context, requested
|
|
|
715
708
|
? extensions.filter((ext) => ext !== ".json")
|
|
716
709
|
: extensions;
|
|
717
710
|
// Project file lookups (using secureFs which may go through FSAdapter in proxy mode)
|
|
718
|
-
const projectFilePath = await
|
|
711
|
+
const projectFilePath = await findFirstExistingFile(secureFs, projectLookupExtensions.map((ext) => join(projectDir, basePathWithoutExt + ext)));
|
|
719
712
|
if (projectFilePath) {
|
|
720
713
|
logger.debug("Found file", { basePath, resolvedPath: projectFilePath });
|
|
721
714
|
return { path: projectFilePath, isFrameworkFile: false };
|
|
@@ -725,7 +718,7 @@ async function findSourceFile(secureFs, projectDir, basePath, context, requested
|
|
|
725
718
|
if (!basePathWithoutExt.startsWith(prefix))
|
|
726
719
|
continue;
|
|
727
720
|
const strippedPath = basePathWithoutExt.slice(prefix.length);
|
|
728
|
-
const strippedFilePath = await
|
|
721
|
+
const strippedFilePath = await findFirstExistingFile(secureFs, projectLookupExtensions.map((ext) => join(projectDir, strippedPath + ext)));
|
|
729
722
|
if (strippedFilePath) {
|
|
730
723
|
logger.debug("Found file after stripping prefix", {
|
|
731
724
|
originalPath: basePathWithoutExt,
|
|
@@ -735,7 +728,7 @@ async function findSourceFile(secureFs, projectDir, basePath, context, requested
|
|
|
735
728
|
return { path: strippedFilePath, isFrameworkFile: false };
|
|
736
729
|
}
|
|
737
730
|
}
|
|
738
|
-
const indexFilePath = await
|
|
731
|
+
const indexFilePath = await findFirstExistingFile(secureFs, projectLookupExtensions.map((ext) => join(projectDir, basePathWithoutExt, `index${ext}`)));
|
|
739
732
|
if (indexFilePath) {
|
|
740
733
|
logger.debug("Found index file", {
|
|
741
734
|
basePath: basePathWithoutExt,
|
|
@@ -746,7 +739,7 @@ async function findSourceFile(secureFs, projectDir, basePath, context, requested
|
|
|
746
739
|
// Try looking in common project directories
|
|
747
740
|
const commonDirs = ["components", "app", "pages", "lib", "src"];
|
|
748
741
|
for (const dir of commonDirs) {
|
|
749
|
-
const commonDirFilePath = await
|
|
742
|
+
const commonDirFilePath = await findFirstExistingFile(secureFs, projectLookupExtensions.map((ext) => join(projectDir, dir, basePathWithoutExt + ext)));
|
|
750
743
|
if (commonDirFilePath) {
|
|
751
744
|
logger.debug("Found file in common directory", {
|
|
752
745
|
basePath,
|
|
@@ -777,7 +770,7 @@ async function findSourceFile(secureFs, projectDir, basePath, context, requested
|
|
|
777
770
|
*/
|
|
778
771
|
export function isModuleRequest(req) {
|
|
779
772
|
const url = new URL(req.url);
|
|
780
|
-
return
|
|
773
|
+
return classifyModuleRequest(url).kind !== "not-module";
|
|
781
774
|
}
|
|
782
775
|
function getModuleHeaders(modulePath, options = {}) {
|
|
783
776
|
return {
|
|
@@ -831,15 +824,6 @@ function createDevModuleErrorBody(modulePath, errorMessage) {
|
|
|
831
824
|
}
|
|
832
825
|
return `// Transform Error\nthrow new Error(${JSON.stringify(errorMessage)});`;
|
|
833
826
|
}
|
|
834
|
-
async function profileModuleTransform(fn) {
|
|
835
|
-
const startedAt = performance.now();
|
|
836
|
-
try {
|
|
837
|
-
return await profilePhase("module.transform", fn);
|
|
838
|
-
}
|
|
839
|
-
finally {
|
|
840
|
-
metrics.recordModuleTransform(performance.now() - startedAt);
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
827
|
function classifyModuleServeStatus(status) {
|
|
844
828
|
if (status >= 200 && status < 300)
|
|
845
829
|
return "ok";
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module Transform — shared ESM transform + SSR / release-rewrite sequence.
|
|
3
|
+
*
|
|
4
|
+
* Unifies the three near-identical copies in module-server.ts and the fourth
|
|
5
|
+
* in module-batch-handler.ts: `transformToESM → (SSR) applySSRImportRewritesAsync
|
|
6
|
+
* or (non-SSR) rewriteReleaseDependencyImportsForModule`.
|
|
7
|
+
*
|
|
8
|
+
* Genuine differences that could not be cleanly unified:
|
|
9
|
+
* - `ensureFilenameDefaultExport` in the dev-module path runs between the ESM
|
|
10
|
+
* transform and the SSR rewrite; callers use `postTransform` for this.
|
|
11
|
+
* - HMR timestamp injection and `addReleaseVersionToFallbackImports` in the
|
|
12
|
+
* dev-module path run after the release rewrite; callers apply them manually
|
|
13
|
+
* on the returned code.
|
|
14
|
+
* - The batch handler (copy 4) never rewrites release dependencies on the
|
|
15
|
+
* non-SSR path; callers simply omit `releaseRewriteOptions`.
|
|
16
|
+
*
|
|
17
|
+
* @module modules/server/module-transform
|
|
18
|
+
*/
|
|
19
|
+
import type { RuntimeAdapter } from "../../platform/adapters/base.js";
|
|
20
|
+
import { type TransformOptions } from "../../transforms/esm-transform.js";
|
|
21
|
+
import { type SSRRewriteOptions } from "./ssr-import-rewriter.js";
|
|
22
|
+
import { type RewriteReleaseDependencyImportsOptions } from "../../release-assets/module-consumption.js";
|
|
23
|
+
/** Options for `transformModuleToServable`. */
|
|
24
|
+
export interface TransformModuleToServableOptions {
|
|
25
|
+
/** Raw source code to transform. */
|
|
26
|
+
source: string;
|
|
27
|
+
/** Source file path used for source-map generation and type detection. */
|
|
28
|
+
sourceFile: string;
|
|
29
|
+
/** Project root directory passed to the transform pipeline. */
|
|
30
|
+
projectDir: string;
|
|
31
|
+
/** Platform runtime adapter. */
|
|
32
|
+
adapter: RuntimeAdapter;
|
|
33
|
+
/** Options forwarded directly to `transformToESM`. */
|
|
34
|
+
transformOpts: TransformOptions;
|
|
35
|
+
/** Whether this is an SSR (server-side rendering) request. */
|
|
36
|
+
isSSR: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Optional hook called after `transformToESM` and before SSR / release
|
|
39
|
+
* rewrites. Use for steps like `ensureFilenameDefaultExport` that must
|
|
40
|
+
* occur between the two stages.
|
|
41
|
+
*/
|
|
42
|
+
postTransform?: (code: string) => string | Promise<string>;
|
|
43
|
+
/**
|
|
44
|
+
* SSR import-rewrite options. Required when `isSSR=true` (the transform
|
|
45
|
+
* throws otherwise, so an SSR module can never be served un-rewritten).
|
|
46
|
+
* Pass `projectSlug`/`branch` or `crossProjectRef` plus a `resolveCacheBuster`.
|
|
47
|
+
*/
|
|
48
|
+
ssrRewriteOptions?: SSRRewriteOptions;
|
|
49
|
+
/**
|
|
50
|
+
* Release-dependency import-rewrite options. Applied when `isSSR=false`.
|
|
51
|
+
* Omit (or pass `undefined`) to skip release dependency rewriting — used by
|
|
52
|
+
* the batch handler which has no non-SSR release rewrite step.
|
|
53
|
+
*/
|
|
54
|
+
releaseRewriteOptions?: RewriteReleaseDependencyImportsOptions;
|
|
55
|
+
/**
|
|
56
|
+
* When `true`, wraps `transformToESM` in observability profiling
|
|
57
|
+
* (`module.transform` phase + metrics). Set by module-server.ts; the batch
|
|
58
|
+
* handler leaves this `false`.
|
|
59
|
+
*/
|
|
60
|
+
profile?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Run the shared module-serving transform sequence:
|
|
64
|
+
*
|
|
65
|
+
* 1. `transformToESM` (optionally profiled)
|
|
66
|
+
* 2. Optional `postTransform` hook (e.g. `ensureFilenameDefaultExport`)
|
|
67
|
+
* 3a. If SSR: `applySSRImportRewritesAsync`
|
|
68
|
+
* 3b. If not SSR: `rewriteReleaseDependencyImportsForModule` (when options provided)
|
|
69
|
+
*
|
|
70
|
+
* @returns Transformed JavaScript source code ready to serve.
|
|
71
|
+
*/
|
|
72
|
+
export declare function transformModuleToServable(options: TransformModuleToServableOptions): Promise<string>;
|
|
73
|
+
//# sourceMappingURL=module-transform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module-transform.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/server/module-transform.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,EAAE,KAAK,gBAAgB,EAAkB,MAAM,mCAAmC,CAAC;AAE1F,OAAO,EAA+B,KAAK,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC/F,OAAO,EAEL,KAAK,sCAAsC,EAC5C,MAAM,4CAA4C,CAAC;AAEpD,+CAA+C;AAC/C,MAAM,WAAW,gCAAgC;IAC/C,oCAAoC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,0EAA0E;IAC1E,UAAU,EAAE,MAAM,CAAC;IACnB,+DAA+D;IAC/D,UAAU,EAAE,MAAM,CAAC;IACnB,gCAAgC;IAChC,OAAO,EAAE,cAAc,CAAC;IACxB,sDAAsD;IACtD,aAAa,EAAE,gBAAgB,CAAC;IAChC,8DAA8D;IAC9D,KAAK,EAAE,OAAO,CAAC;IACf;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3D;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,sCAAsC,CAAC;IAC/D;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;GASG;AACH,wBAAsB,yBAAyB,CAC7C,OAAO,EAAE,gCAAgC,GACxC,OAAO,CAAC,MAAM,CAAC,CA+BjB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Module Transform — shared ESM transform + SSR / release-rewrite sequence.
|
|
3
|
+
*
|
|
4
|
+
* Unifies the three near-identical copies in module-server.ts and the fourth
|
|
5
|
+
* in module-batch-handler.ts: `transformToESM → (SSR) applySSRImportRewritesAsync
|
|
6
|
+
* or (non-SSR) rewriteReleaseDependencyImportsForModule`.
|
|
7
|
+
*
|
|
8
|
+
* Genuine differences that could not be cleanly unified:
|
|
9
|
+
* - `ensureFilenameDefaultExport` in the dev-module path runs between the ESM
|
|
10
|
+
* transform and the SSR rewrite; callers use `postTransform` for this.
|
|
11
|
+
* - HMR timestamp injection and `addReleaseVersionToFallbackImports` in the
|
|
12
|
+
* dev-module path run after the release rewrite; callers apply them manually
|
|
13
|
+
* on the returned code.
|
|
14
|
+
* - The batch handler (copy 4) never rewrites release dependencies on the
|
|
15
|
+
* non-SSR path; callers simply omit `releaseRewriteOptions`.
|
|
16
|
+
*
|
|
17
|
+
* @module modules/server/module-transform
|
|
18
|
+
*/
|
|
19
|
+
import { INVALID_ARGUMENT } from "../../errors/index.js";
|
|
20
|
+
import { transformToESM } from "../../transforms/esm-transform.js";
|
|
21
|
+
import { metrics, profilePhase } from "../../observability/index.js";
|
|
22
|
+
import { applySSRImportRewritesAsync } from "./ssr-import-rewriter.js";
|
|
23
|
+
import { rewriteReleaseDependencyImportsForModule, } from "../../release-assets/module-consumption.js";
|
|
24
|
+
/**
|
|
25
|
+
* Run the shared module-serving transform sequence:
|
|
26
|
+
*
|
|
27
|
+
* 1. `transformToESM` (optionally profiled)
|
|
28
|
+
* 2. Optional `postTransform` hook (e.g. `ensureFilenameDefaultExport`)
|
|
29
|
+
* 3a. If SSR: `applySSRImportRewritesAsync`
|
|
30
|
+
* 3b. If not SSR: `rewriteReleaseDependencyImportsForModule` (when options provided)
|
|
31
|
+
*
|
|
32
|
+
* @returns Transformed JavaScript source code ready to serve.
|
|
33
|
+
*/
|
|
34
|
+
export async function transformModuleToServable(options) {
|
|
35
|
+
const { source, sourceFile, projectDir, adapter, transformOpts, isSSR, profile = false, } = options;
|
|
36
|
+
const doTransform = () => transformToESM(source, sourceFile, projectDir, adapter, transformOpts);
|
|
37
|
+
let code = profile ? await profiledTransform(doTransform) : await doTransform();
|
|
38
|
+
if (options.postTransform) {
|
|
39
|
+
code = await options.postTransform(code);
|
|
40
|
+
}
|
|
41
|
+
if (isSSR) {
|
|
42
|
+
if (!options.ssrRewriteOptions) {
|
|
43
|
+
throw INVALID_ARGUMENT.create({
|
|
44
|
+
detail: "transformModuleToServable requires ssrRewriteOptions when isSSR is true",
|
|
45
|
+
context: { sourceFile },
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
code = await applySSRImportRewritesAsync(code, options.ssrRewriteOptions);
|
|
49
|
+
}
|
|
50
|
+
else if (options.releaseRewriteOptions) {
|
|
51
|
+
code = await rewriteReleaseDependencyImportsForModule(code, options.releaseRewriteOptions);
|
|
52
|
+
}
|
|
53
|
+
return code;
|
|
54
|
+
}
|
|
55
|
+
/** Wrap a transform function with `module.transform` profiling and metrics. */
|
|
56
|
+
async function profiledTransform(fn) {
|
|
57
|
+
const startedAt = performance.now();
|
|
58
|
+
try {
|
|
59
|
+
return await profilePhase("module.transform", fn);
|
|
60
|
+
}
|
|
61
|
+
finally {
|
|
62
|
+
metrics.recordModuleTransform(performance.now() - startedAt);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -7,7 +7,7 @@ export interface SSRImportRewriteTarget {
|
|
|
7
7
|
}
|
|
8
8
|
export declare function stripSSRModuleJsExtension(path: string): string;
|
|
9
9
|
export declare function resolveSSRImportTargetModulePath(target: SSRImportRewriteTarget, currentModulePath: string): string;
|
|
10
|
-
interface SSRRewriteOptions {
|
|
10
|
+
export interface SSRRewriteOptions {
|
|
11
11
|
/** Project slug for multi-project routing */
|
|
12
12
|
projectSlug?: string | null;
|
|
13
13
|
/** Branch name for branch-aware routing */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-import-rewriter.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/server/ssr-import-rewriter.ts"],"names":[],"mappings":"AAQA,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;AAEnC,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,OAAO,GAAG,UAAU,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9D;AAWD,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,sBAAsB,EAC9B,iBAAiB,EAAE,MAAM,GACxB,MAAM,CAWR;AAED,
|
|
1
|
+
{"version":3,"file":"ssr-import-rewriter.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/server/ssr-import-rewriter.ts"],"names":[],"mappings":"AAQA,KAAK,WAAW,GAAG,MAAM,GAAG,MAAM,CAAC;AAEnC,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,OAAO,GAAG,UAAU,CAAC;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9D;AAWD,wBAAgB,gCAAgC,CAC9C,MAAM,EAAE,sBAAsB,EAC9B,iBAAiB,EAAE,MAAM,GACxB,MAAM,CAWR;AAED,MAAM,WAAW,iBAAiB;IAChC,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,mFAAmF;IACnF,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,8DAA8D;IAC9D,kBAAkB,CAAC,EAAE,CACnB,MAAM,EAAE,sBAAsB,KAC3B,WAAW,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;IAC9E,sEAAsE;IACtE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAwKD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAK5F;AA+CD,wBAAsB,2BAA2B,CAC/C,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE,iBAAsB,GAC9B,OAAO,CAAC,MAAM,CAAC,CAKjB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-collector.d.ts","sourceRoot":"","sources":["../../../src/src/observability/error-collector.ts"],"names":[],"mappings":"AAAA;;;;;4BAK4B;AAE5B,OAAO,EAAE,KAAK,aAAa,EAAoB,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"error-collector.d.ts","sourceRoot":"","sources":["../../../src/src/observability/error-collector.ts"],"names":[],"mappings":"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"}
|