veryfront 0.0.86 → 0.0.89
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/_dnt.shims.d.ts +14 -14
- package/esm/_dnt.shims.d.ts.map +1 -1
- package/esm/deno.d.ts +0 -1
- package/esm/deno.js +8 -9
- package/esm/proxy/main.d.ts +2 -0
- package/esm/proxy/main.d.ts.map +1 -0
- package/esm/proxy/main.js +400 -0
- package/esm/src/cli/commands/init/config-generator.js +1 -1
- package/esm/src/cli/index/arg-parser.d.ts.map +1 -1
- package/esm/src/cli/index/arg-parser.js +1 -0
- package/esm/src/cli/index/command-router.d.ts.map +1 -1
- package/esm/src/cli/index/command-router.js +54 -39
- package/esm/src/cli/index/types.d.ts +4 -0
- package/esm/src/cli/index/types.d.ts.map +1 -1
- package/esm/src/cli/mcp/advanced-tools.d.ts +2 -2
- package/esm/src/cli/templates/manifest.d.ts +448 -448
- package/esm/src/cli/templates/manifest.js +480 -480
- package/esm/src/config/loader.d.ts.map +1 -1
- package/esm/src/config/loader.js +5 -4
- package/esm/src/html/utils.js +2 -2
- package/esm/src/modules/import-map/default-import-map.d.ts +1 -11
- package/esm/src/modules/import-map/default-import-map.d.ts.map +1 -1
- package/esm/src/modules/import-map/default-import-map.js +3 -20
- package/esm/src/modules/import-map/loader.d.ts.map +1 -1
- package/esm/src/modules/import-map/loader.js +7 -22
- package/esm/src/modules/import-map/resolver.d.ts.map +1 -1
- package/esm/src/modules/import-map/resolver.js +12 -8
- package/esm/src/modules/react-loader/component-loader.d.ts.map +1 -1
- package/esm/src/modules/react-loader/component-loader.js +2 -0
- package/esm/src/modules/react-loader/ssr-module-loader/loader.d.ts +1 -6
- package/esm/src/modules/react-loader/ssr-module-loader/loader.d.ts.map +1 -1
- package/esm/src/modules/react-loader/ssr-module-loader/loader.js +40 -32
- package/esm/src/modules/react-loader/ssr-module-loader/types.d.ts +2 -0
- package/esm/src/modules/react-loader/ssr-module-loader/types.d.ts.map +1 -1
- package/esm/src/modules/react-loader/types.d.ts +2 -0
- package/esm/src/modules/react-loader/types.d.ts.map +1 -1
- package/esm/src/modules/react-loader/unified-loader.d.ts.map +1 -1
- package/esm/src/modules/react-loader/unified-loader.js +7 -4
- package/esm/src/modules/server/module-batch-handler.d.ts +2 -0
- package/esm/src/modules/server/module-batch-handler.d.ts.map +1 -1
- package/esm/src/modules/server/module-batch-handler.js +3 -1
- package/esm/src/modules/server/module-server.d.ts +2 -0
- package/esm/src/modules/server/module-server.d.ts.map +1 -1
- package/esm/src/modules/server/module-server.js +4 -2
- package/esm/src/modules/server/ssr-import-rewriter.d.ts.map +1 -1
- package/esm/src/modules/server/ssr-import-rewriter.js +9 -17
- package/esm/src/platform/compat/path-helper.d.ts +7 -7
- package/esm/src/platform/compat/path-helper.d.ts.map +1 -1
- package/esm/src/react/compat/ssr-adapter/string-renderer.js +1 -1
- package/esm/src/react/components/Head.d.ts.map +1 -1
- package/esm/src/react/components/Head.js +6 -2
- package/esm/src/react/components/ai/agent-card.d.ts +1 -1
- package/esm/src/react/components/ai/agent-card.d.ts.map +1 -1
- package/esm/src/react/components/ai/chat/composition/api.d.ts +5 -4
- package/esm/src/react/components/ai/chat/composition/api.d.ts.map +1 -1
- package/esm/src/react/components/ai/chat/index.d.ts +7 -2
- package/esm/src/react/components/ai/chat/index.d.ts.map +1 -1
- package/esm/src/react/components/ai/message.d.ts +2 -2
- package/esm/src/react/components/ai/message.d.ts.map +1 -1
- package/esm/src/react/primitives/agent-primitives.d.ts +3 -3
- package/esm/src/react/primitives/agent-primitives.d.ts.map +1 -1
- package/esm/src/react/primitives/chat-container.d.ts +1 -1
- package/esm/src/react/primitives/chat-container.d.ts.map +1 -1
- package/esm/src/react/primitives/input-box.d.ts +3 -3
- package/esm/src/react/primitives/input-box.d.ts.map +1 -1
- package/esm/src/react/primitives/input-box.js +6 -2
- package/esm/src/react/primitives/message-list.d.ts +4 -4
- package/esm/src/react/primitives/message-list.d.ts.map +1 -1
- package/esm/src/react/primitives/tool-primitives.d.ts +3 -3
- package/esm/src/react/primitives/tool-primitives.d.ts.map +1 -1
- package/esm/src/rendering/component-handling.d.ts +2 -0
- package/esm/src/rendering/component-handling.d.ts.map +1 -1
- package/esm/src/rendering/component-handling.js +4 -2
- package/esm/src/rendering/layouts/layout-applicator.d.ts.map +1 -1
- package/esm/src/rendering/layouts/layout-applicator.js +2 -0
- package/esm/src/rendering/orchestrator/module-loader/index.d.ts +3 -0
- package/esm/src/rendering/orchestrator/module-loader/index.d.ts.map +1 -1
- package/esm/src/rendering/orchestrator/module-loader/index.js +74 -19
- package/esm/src/rendering/orchestrator/pipeline.d.ts.map +1 -1
- package/esm/src/rendering/orchestrator/pipeline.js +2 -0
- package/esm/src/rendering/rsc/server-renderer/tree-processor.d.ts.map +1 -1
- package/esm/src/rendering/rsc/server-renderer/tree-processor.js +3 -1
- package/esm/src/rendering/ssr-globals/context.d.ts +6 -1
- package/esm/src/rendering/ssr-globals/context.d.ts.map +1 -1
- package/esm/src/transforms/esm/http-bundler.d.ts +15 -4
- package/esm/src/transforms/esm/http-bundler.d.ts.map +1 -1
- package/esm/src/transforms/esm/http-bundler.js +105 -12
- package/esm/src/transforms/esm/http-cache.d.ts.map +1 -1
- package/esm/src/transforms/esm/http-cache.js +26 -27
- package/esm/src/transforms/esm/import-rewriter.d.ts.map +1 -1
- package/esm/src/transforms/esm/import-rewriter.js +3 -3
- package/esm/src/transforms/esm/package-registry.d.ts +15 -13
- package/esm/src/transforms/esm/package-registry.d.ts.map +1 -1
- package/esm/src/transforms/esm/package-registry.js +45 -32
- package/esm/src/transforms/esm/react-imports.d.ts.map +1 -1
- package/esm/src/transforms/esm/react-imports.js +3 -7
- package/esm/src/transforms/esm/types.d.ts +2 -0
- package/esm/src/transforms/esm/types.d.ts.map +1 -1
- package/esm/src/transforms/mdx/esm-module-loader/cache/index.d.ts +14 -0
- package/esm/src/transforms/mdx/esm-module-loader/cache/index.d.ts.map +1 -1
- package/esm/src/transforms/mdx/esm-module-loader/cache/index.js +67 -0
- package/esm/src/transforms/mdx/esm-module-loader/loader.d.ts.map +1 -1
- package/esm/src/transforms/mdx/esm-module-loader/loader.js +1 -1
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/index.d.ts +1 -0
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/index.d.ts.map +1 -1
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/index.js +1 -0
- package/esm/src/transforms/mdx/esm-module-loader/types.d.ts +4 -0
- package/esm/src/transforms/mdx/esm-module-loader/types.d.ts.map +1 -1
- package/esm/src/transforms/pipeline/context.d.ts.map +1 -1
- package/esm/src/transforms/pipeline/context.js +7 -15
- package/esm/src/transforms/pipeline/stages/finalize.d.ts.map +1 -1
- package/esm/src/transforms/pipeline/stages/finalize.js +1 -1
- package/esm/src/utils/constants/cdn.d.ts.map +1 -1
- package/esm/src/utils/constants/cdn.js +22 -11
- package/esm/src/utils/hash-utils.d.ts +2 -0
- package/esm/src/utils/hash-utils.d.ts.map +1 -1
- package/esm/src/utils/hash-utils.js +4 -0
- package/package.json +1 -1
- package/src/deno.js +8 -9
- package/src/proxy/main.ts +471 -0
- package/src/src/cli/commands/init/config-generator.ts +1 -1
- package/src/src/cli/index/arg-parser.ts +1 -0
- package/src/src/cli/index/command-router.ts +57 -40
- package/src/src/cli/index/types.ts +5 -0
- package/src/src/cli/templates/manifest.js +480 -480
- package/src/src/config/loader.ts +5 -4
- package/src/src/html/utils.ts +2 -2
- package/src/src/modules/import-map/default-import-map.ts +3 -25
- package/src/src/modules/import-map/loader.ts +7 -23
- package/src/src/modules/import-map/resolver.ts +13 -8
- package/src/src/modules/react-loader/component-loader.ts +2 -0
- package/src/src/modules/react-loader/ssr-module-loader/loader.ts +51 -37
- package/src/src/modules/react-loader/ssr-module-loader/types.ts +2 -0
- package/src/src/modules/react-loader/types.ts +2 -0
- package/src/src/modules/react-loader/unified-loader.ts +7 -4
- package/src/src/modules/server/module-batch-handler.ts +7 -0
- package/src/src/modules/server/module-server.ts +6 -1
- package/src/src/modules/server/ssr-import-rewriter.ts +9 -17
- package/src/src/react/compat/ssr-adapter/stream-renderer.ts +1 -1
- package/src/src/react/compat/ssr-adapter/string-renderer.ts +2 -2
- package/src/src/react/components/Head.tsx +6 -2
- package/src/src/react/primitives/input-box.tsx +4 -2
- package/src/src/rendering/component-handling.ts +6 -0
- package/src/src/rendering/layouts/layout-applicator.ts +4 -5
- package/src/src/rendering/orchestrator/module-loader/index.ts +91 -20
- package/src/src/rendering/orchestrator/pipeline.ts +2 -0
- package/src/src/rendering/orchestrator/ssr-orchestrator.ts +1 -1
- package/src/src/rendering/rsc/server-renderer/tree-processor.ts +13 -3
- package/src/src/transforms/esm/http-bundler.ts +101 -11
- package/src/src/transforms/esm/http-cache.ts +27 -28
- package/src/src/transforms/esm/import-rewriter.ts +5 -3
- package/src/src/transforms/esm/package-registry.ts +46 -32
- package/src/src/transforms/esm/react-imports.ts +3 -7
- package/src/src/transforms/esm/types.ts +2 -0
- package/src/src/transforms/mdx/esm-module-loader/cache/index.ts +84 -0
- package/src/src/transforms/mdx/esm-module-loader/loader.ts +1 -0
- package/src/src/transforms/mdx/esm-module-loader/module-fetcher/index.ts +2 -1
- package/src/src/transforms/mdx/esm-module-loader/types.ts +4 -0
- package/src/src/transforms/pipeline/context.ts +7 -18
- package/src/src/transforms/pipeline/stages/finalize.ts +6 -1
- package/src/src/transforms/plugins/babel-node-positions.ts +2 -2
- package/src/src/utils/constants/cdn.ts +21 -12
- package/src/src/utils/hash-utils.ts +5 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/src/config/loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/src/config/loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAgBnE,YAAY,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAqSlD;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,SAAS,CACvB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,gBAAgB,GACzB,OAAO,CAAC,eAAe,CAAC,CAsE1B;AAED,wBAAgB,gBAAgB,IAAI,IAAI,CAGvC;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,UAAU,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI,CAI9E"}
|
package/esm/src/config/loader.js
CHANGED
|
@@ -6,7 +6,8 @@ import { isBun } from "../platform/compat/runtime.js";
|
|
|
6
6
|
import { serverLogger } from "../utils/logger/logger.js";
|
|
7
7
|
import { getReactImportMap, REACT_DEFAULT_VERSION } from "../utils/constants/cdn.js";
|
|
8
8
|
import { DEFAULT_CACHE_DIR } from "../utils/constants/server.js";
|
|
9
|
-
|
|
9
|
+
// React version is now passed per-request via TransformOptions.reactVersion
|
|
10
|
+
// No longer using global singleton: import { setReactVersion } from "#veryfront/transforms/esm/package-registry.ts";
|
|
10
11
|
import { buildConfigCacheKey } from "../cache/keys.js";
|
|
11
12
|
import { DEFAULT_PORT } from "./defaults.js";
|
|
12
13
|
import { createFileSystem } from "../platform/compat/fs.js";
|
|
@@ -174,10 +175,10 @@ function validateAndCacheConfig(userConfig, cacheKey) {
|
|
|
174
175
|
validateCorsConfig(userConfig);
|
|
175
176
|
validateConfigShape(userConfig);
|
|
176
177
|
const merged = mergeConfigs(userConfig);
|
|
177
|
-
//
|
|
178
|
+
// React version is now passed per-request via TransformOptions.reactVersion
|
|
179
|
+
// Config stores it at merged.react.version, accessed wherever needed
|
|
178
180
|
if (merged.react?.version) {
|
|
179
|
-
|
|
180
|
-
serverLogger.debug("[CONFIG] React version set from config", { version: merged.react.version });
|
|
181
|
+
serverLogger.debug("[CONFIG] React version from config", { version: merged.react.version });
|
|
181
182
|
}
|
|
182
183
|
configCacheByProject.set(cacheKey, { revision: cacheRevision, config: merged });
|
|
183
184
|
return merged;
|
package/esm/src/html/utils.js
CHANGED
|
@@ -62,8 +62,8 @@ const PLATFORM_UTILITIES = {
|
|
|
62
62
|
const CDN_URL_TEMPLATES = {
|
|
63
63
|
"esm.sh": {
|
|
64
64
|
react: (v) => `https://esm.sh/react@${v}?target=es2022`,
|
|
65
|
-
reactDom: (v) => `https://esm.sh/react-dom@${v}?target=es2022`,
|
|
66
|
-
reactDomClient: (v) => `https://esm.sh/react-dom@${v}/client?target=es2022`,
|
|
65
|
+
reactDom: (v) => `https://esm.sh/react-dom@${v}?external=react&target=es2022`,
|
|
66
|
+
reactDomClient: (v) => `https://esm.sh/react-dom@${v}/client?external=react&target=es2022`,
|
|
67
67
|
jsxRuntime: (v) => `https://esm.sh/react@${v}/jsx-runtime?target=es2022`,
|
|
68
68
|
jsxDevRuntime: (v) => `https://esm.sh/react@${v}/jsx-dev-runtime?target=es2022`,
|
|
69
69
|
veryfrontAgentReact: (v) => `https://esm.sh/veryfront@${v}/agent/react?external=react,react-dom&target=es2022`,
|
|
@@ -1,17 +1,7 @@
|
|
|
1
1
|
import type { ImportMapConfig } from "./types.js";
|
|
2
|
-
/**
|
|
3
|
-
* Get React import map for SSR in Deno.
|
|
4
|
-
* Uses npm: specifiers which Deno handles natively with automatic deduplication.
|
|
5
|
-
* See: https://deno.com/blog/not-using-npm-specifiers-doing-it-wrong
|
|
6
|
-
*
|
|
7
|
-
* This replaces the previous shared-*.ts approach which required manual re-exports.
|
|
8
|
-
*/
|
|
9
|
-
export declare function getDenoReactImportMap(): Record<string, string>;
|
|
10
2
|
/**
|
|
11
3
|
* Get the default import map for SSR transforms.
|
|
12
|
-
*
|
|
13
|
-
* For Deno SSR: Uses npm: specifiers with automatic deduplication.
|
|
14
|
-
* For other runtimes: Uses esm.sh URLs with external=react.
|
|
4
|
+
* Uses esm.sh URLs consistently (NO npm: specifiers per plan requirements).
|
|
15
5
|
*/
|
|
16
6
|
export declare function getDefaultImportMap(): ImportMapConfig;
|
|
17
7
|
//# sourceMappingURL=default-import-map.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default-import-map.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/import-map/default-import-map.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"default-import-map.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/import-map/default-import-map.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA0ClD;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,eAAe,CAOrD"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as dntShim from "../../../_dnt.shims.js";
|
|
2
|
-
import {
|
|
3
|
-
import { getDenoNpmReactMap, getReactImportMap, } from "../../transforms/esm/package-registry.js";
|
|
2
|
+
import { getReactImportMap } from "../../transforms/esm/package-registry.js";
|
|
4
3
|
function ensureTrailingSlash(path) {
|
|
5
4
|
return path.endsWith("/") ? path : `${path}/`;
|
|
6
5
|
}
|
|
@@ -34,30 +33,14 @@ function getVeryfrontSsrImportMap() {
|
|
|
34
33
|
"veryfront/react/fonts": fonts,
|
|
35
34
|
};
|
|
36
35
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Get React import map for SSR in Deno.
|
|
39
|
-
* Uses npm: specifiers which Deno handles natively with automatic deduplication.
|
|
40
|
-
* See: https://deno.com/blog/not-using-npm-specifiers-doing-it-wrong
|
|
41
|
-
*
|
|
42
|
-
* This replaces the previous shared-*.ts approach which required manual re-exports.
|
|
43
|
-
*/
|
|
44
|
-
export function getDenoReactImportMap() {
|
|
45
|
-
return getDenoNpmReactMap();
|
|
46
|
-
}
|
|
47
36
|
/**
|
|
48
37
|
* Get the default import map for SSR transforms.
|
|
49
|
-
*
|
|
50
|
-
* For Deno SSR: Uses npm: specifiers with automatic deduplication.
|
|
51
|
-
* For other runtimes: Uses esm.sh URLs with external=react.
|
|
38
|
+
* Uses esm.sh URLs consistently (NO npm: specifiers per plan requirements).
|
|
52
39
|
*/
|
|
53
40
|
export function getDefaultImportMap() {
|
|
54
|
-
const reactMap =
|
|
41
|
+
const reactMap = getReactImportMap();
|
|
55
42
|
const veryfrontMap = getVeryfrontSsrImportMap();
|
|
56
|
-
// For Deno SSR, add scopes so that esm.sh modules with external=react
|
|
57
|
-
// resolve their bare `react` imports to npm: specifiers.
|
|
58
|
-
const scopes = isDeno ? { "https://esm.sh/": getDenoReactImportMap() } : undefined;
|
|
59
43
|
return {
|
|
60
44
|
imports: { ...veryfrontMap, ...reactMap },
|
|
61
|
-
scopes,
|
|
62
45
|
};
|
|
63
46
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/import-map/loader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/import-map/loader.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAEtE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAqDlD,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,eAAe,CAAC,CA+C1B"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { rendererLogger as logger } from "../../utils/index.js";
|
|
2
2
|
import { dirname, join } from "../../platform/compat/path/index.js";
|
|
3
3
|
import { getConfig } from "../../config/index.js";
|
|
4
|
-
import { getDefaultImportMap
|
|
4
|
+
import { getDefaultImportMap } from "./default-import-map.js";
|
|
5
5
|
import { mergeImportMaps } from "./merger.js";
|
|
6
6
|
import { withSpan } from "../../observability/tracing/otlp-setup.js";
|
|
7
|
-
import {
|
|
7
|
+
import { getReactImportMap } from "../../transforms/esm/package-registry.js";
|
|
8
8
|
function normalizeImportMapForRuntime(importMap) {
|
|
9
9
|
const normalizeValue = (value) => {
|
|
10
10
|
if (!value.startsWith("npm:"))
|
|
11
11
|
return value;
|
|
12
|
+
// Convert npm: specifiers to esm.sh URLs (should not happen with new code)
|
|
12
13
|
const spec = value.slice(4);
|
|
13
14
|
const [base, query] = spec.split("?");
|
|
14
15
|
const url = `https://esm.sh/${base}`;
|
|
@@ -17,35 +18,19 @@ function normalizeImportMapForRuntime(importMap) {
|
|
|
17
18
|
let imports = importMap.imports
|
|
18
19
|
? Object.fromEntries(Object.entries(importMap.imports).map(([k, v]) => [k, normalizeValue(v)]))
|
|
19
20
|
: undefined;
|
|
20
|
-
|
|
21
|
+
const scopes = importMap.scopes
|
|
21
22
|
? Object.fromEntries(Object.entries(importMap.scopes).map(([scope, mappings]) => [
|
|
22
23
|
scope,
|
|
23
24
|
Object.fromEntries(Object.entries(mappings).map(([k, v]) => [k, normalizeValue(v)])),
|
|
24
25
|
]))
|
|
25
26
|
: undefined;
|
|
26
|
-
// CRITICAL: For Deno SSR, always use shared-*.ts files for React.
|
|
27
|
-
// Project configs may have esm.sh URLs which would create multiple React instances.
|
|
28
27
|
// Override React mappings AFTER all other processing to ensure single instance.
|
|
29
|
-
//
|
|
30
|
-
if (
|
|
31
|
-
const reactMap =
|
|
32
|
-
// Remove any esm.sh "react/" prefix mapping that would break subpath resolution
|
|
28
|
+
// Remove any "react/" prefix match since we have explicit mappings.
|
|
29
|
+
if (imports) {
|
|
30
|
+
const reactMap = getReactImportMap();
|
|
33
31
|
delete imports["react/"];
|
|
34
32
|
imports = { ...imports, ...reactMap };
|
|
35
33
|
}
|
|
36
|
-
// For Deno SSR, ensure esm.sh scope has React mappings to shared-*.ts files.
|
|
37
|
-
// This is critical because esm.sh modules with external=react have bare `react`
|
|
38
|
-
// imports that need to resolve to our shared React instance.
|
|
39
|
-
if (isDeno) {
|
|
40
|
-
const reactMap = getDenoReactImportMap();
|
|
41
|
-
const esmShScope = scopes?.["https://esm.sh/"] ?? {};
|
|
42
|
-
// Remove any "react/" prefix match from scope as well
|
|
43
|
-
delete esmShScope["react/"];
|
|
44
|
-
scopes = {
|
|
45
|
-
...scopes,
|
|
46
|
-
"https://esm.sh/": { ...esmShScope, ...reactMap },
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
34
|
return { imports, scopes };
|
|
50
35
|
}
|
|
51
36
|
function mergeWithDefault(importMap) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/import-map/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA8ClD,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,eAAe,EAC1B,KAAK,CAAC,EAAE,MAAM,GACb,MAAM,
|
|
1
|
+
{"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/import-map/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AA8ClD,wBAAgB,aAAa,CAC3B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,eAAe,EAC1B,KAAK,CAAC,EAAE,MAAM,GACb,MAAM,CAuDR"}
|
|
@@ -46,21 +46,25 @@ export function resolveImport(specifier, importMap, scope) {
|
|
|
46
46
|
if (isEsmShUrl(specifier)) {
|
|
47
47
|
const esmShPackage = extractEsmShPackage(specifier);
|
|
48
48
|
if (esmShPackage) {
|
|
49
|
+
const subpath = extractEsmShSubpath(specifier);
|
|
50
|
+
// Always check for explicit subpath mapping first (e.g., "react/jsx-runtime")
|
|
51
|
+
// This takes priority over appending subpath to base package mapping
|
|
52
|
+
if (subpath) {
|
|
53
|
+
const fullKey = esmShPackage + subpath; // e.g., "react/jsx-runtime"
|
|
54
|
+
const subpathMapping = scopedImports?.[fullKey] ?? importMap.imports?.[fullKey];
|
|
55
|
+
if (subpathMapping)
|
|
56
|
+
return subpathMapping;
|
|
57
|
+
}
|
|
49
58
|
const mapping = scopedImports?.[esmShPackage] ?? importMap.imports?.[esmShPackage];
|
|
50
59
|
if (mapping) {
|
|
51
|
-
const subpath = extractEsmShSubpath(specifier);
|
|
52
60
|
if (!subpath)
|
|
53
61
|
return mapping;
|
|
54
|
-
// If mapping target is a file path (not HTTP URL or npm: specifier),
|
|
55
|
-
//
|
|
56
|
-
// npm: specifiers are URL-like and should have subpaths appended
|
|
62
|
+
// If mapping target is a file path (not HTTP URL or npm: specifier),
|
|
63
|
+
// fall back to base mapping since explicit subpath wasn't found above
|
|
57
64
|
const isFilePath = !mapping.startsWith("http://") && !mapping.startsWith("https://") &&
|
|
58
65
|
!mapping.startsWith("npm:");
|
|
59
66
|
if (isFilePath) {
|
|
60
|
-
|
|
61
|
-
const subpathMapping = scopedImports?.[fullKey] ?? importMap.imports?.[fullKey];
|
|
62
|
-
// Use explicit subpath mapping if available, otherwise fall back to base mapping
|
|
63
|
-
return subpathMapping ?? mapping;
|
|
67
|
+
return mapping;
|
|
64
68
|
}
|
|
65
69
|
return mapping + subpath;
|
|
66
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component-loader.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/react-loader/component-loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AACpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAKtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAMvD,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"component-loader.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/react-loader/component-loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AACpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAKtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAMvD,wBAAgB,uBAAuB,CACrC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CA0DvD"}
|
|
@@ -19,6 +19,7 @@ export function loadComponentFromSource(source, filePath, projectDir, adapter, o
|
|
|
19
19
|
adapter,
|
|
20
20
|
dev,
|
|
21
21
|
contentSourceId: options?.contentSourceId,
|
|
22
|
+
reactVersion: options?.reactVersion,
|
|
22
23
|
});
|
|
23
24
|
return loader.loadModule(filePath, source);
|
|
24
25
|
}
|
|
@@ -28,6 +29,7 @@ export function loadComponentFromSource(source, filePath, projectDir, adapter, o
|
|
|
28
29
|
moduleServerUrl: options?.moduleServerUrl ?? "/_vf_modules",
|
|
29
30
|
vendorBundleHash: options?.vendorBundleHash,
|
|
30
31
|
ssr: false,
|
|
32
|
+
reactVersion: options?.reactVersion,
|
|
31
33
|
};
|
|
32
34
|
const transformedCode = await transformToESM(source, filePath, projectDir, adapter, transformOpts);
|
|
33
35
|
const tmpDir = await getProjectTmpDir(projectId);
|
|
@@ -53,14 +53,9 @@ export declare class SSRModuleLoader {
|
|
|
53
53
|
*/
|
|
54
54
|
private toJsExtension;
|
|
55
55
|
private ensureDependenciesExist;
|
|
56
|
-
/**
|
|
57
|
-
* Fast sync hash for small strings (project IDs, etc.)
|
|
58
|
-
* Use hashContentAsync for large file content.
|
|
59
|
-
*/
|
|
60
|
-
private hashCode;
|
|
61
56
|
/**
|
|
62
57
|
* Async hash for large content using Web Crypto API.
|
|
63
|
-
*
|
|
58
|
+
* Falls back to sync hash for small files.
|
|
64
59
|
*/
|
|
65
60
|
private hashContentAsync;
|
|
66
61
|
private getTempPath;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../../../src/src/modules/react-loader/ssr-module-loader/loader.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../../../src/src/modules/react-loader/ssr-module-loader/loader.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAuCpC,OAAO,KAAK,EAAoB,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAiC3E;;;;;GAKG;AACH,qBAAa,eAAe;IAId,OAAO,CAAC,OAAO;IAH3B,OAAO,CAAC,EAAE,CAAsB;IAChC,OAAO,CAAC,mBAAmB,CAAuB;gBAE9B,OAAO,EAAE,sBAAsB;IAEnD;;OAEG;IACH,UAAU,CACR,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAsGxD,OAAO,CAAC,mBAAmB;IAiC3B,OAAO,CAAC,wBAAwB;IAwBhC,OAAO,CAAC,WAAW;IAenB,OAAO,CAAC,yBAAyB;IAuBjC,OAAO,CAAC,kBAAkB;IAK1B;;OAEG;YACW,2BAA2B;IAmGzC,OAAO,CAAC,yBAAyB;YAiBnB,2BAA2B;IA0TzC;;;OAGG;YACW,mBAAmB;IA2CjC,OAAO,CAAC,yBAAyB;IAYjC;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IA4B3B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAuB3B,OAAO,CAAC,wBAAwB;IAehC,OAAO,CAAC,2BAA2B;IAiBnC,OAAO,CAAC,2BAA2B;IAWnC;;OAEG;IACH,OAAO,CAAC,mBAAmB;IA4B3B;;OAEG;IACH,OAAO,CAAC,aAAa;YAIP,uBAAuB;IAyCrC;;;OAGG;YACW,gBAAgB;YAgBhB,WAAW;YAeX,YAAY;CA4B3B"}
|
|
@@ -6,15 +6,15 @@
|
|
|
6
6
|
* @module module-system/react-loader/ssr-module-loader/loader
|
|
7
7
|
*/
|
|
8
8
|
import * as dntShim from "../../../../_dnt.shims.js";
|
|
9
|
-
import {
|
|
10
|
-
import { cwd } from "../../../platform/compat/process.js";
|
|
9
|
+
import { join } from "../../../platform/compat/path/index.js";
|
|
11
10
|
import { transformToESM } from "../../../transforms/esm/index.js";
|
|
12
11
|
import { TRANSFORM_CACHE_VERSION } from "../../../transforms/esm/package-registry.js";
|
|
13
|
-
import { buildSSRModuleCacheKey
|
|
12
|
+
import { buildSSRModuleCacheKey } from "../../../cache/keys.js";
|
|
14
13
|
import { parseLocalImports, } from "../../../transforms/esm/import-parser.js";
|
|
15
14
|
import { createFileSystem } from "../../../platform/compat/fs.js";
|
|
16
15
|
import { createError, toError } from "../../../errors/veryfront-error.js";
|
|
17
16
|
import { rendererLogger as logger } from "../../../utils/index.js";
|
|
17
|
+
import { hashCodeHex } from "../../../utils/hash-utils.js";
|
|
18
18
|
import { getApiBaseUrlEnv } from "../../../config/env.js";
|
|
19
19
|
import { injectContext, withSpan } from "../../../observability/tracing/otlp-setup.js";
|
|
20
20
|
import { SpanNames } from "../../../observability/tracing/span-names.js";
|
|
@@ -22,7 +22,8 @@ import { extractComponent } from "../extract-component.js";
|
|
|
22
22
|
import { CIRCUIT_BREAKER_RESET_MS, CIRCUIT_BREAKER_THRESHOLD, IN_PROGRESS_WAIT_TIMEOUT_MS, MAX_CONCURRENT_TRANSFORMS, MAX_TRANSFORM_DEPTH, TRANSFORM_ACQUIRE_TIMEOUT_MS, TRANSFORM_BATCH_SIZE, } from "./constants.js";
|
|
23
23
|
import { withTimeoutThrow } from "../../../rendering/utils/stream-utils.js";
|
|
24
24
|
import { failedComponents, getFromRedis, globalCrossProjectCache, globalInProgress, globalModuleCache, globalTmpDirs, isSSRDistributedCacheEnabled, setInRedis, transformSemaphore, } from "./cache/index.js";
|
|
25
|
-
import {
|
|
25
|
+
import { getHttpBundleCacheDir, getMdxEsmCacheDir } from "../../../utils/cache-dir.js";
|
|
26
|
+
import { lookupMdxEsmCache } from "../../../transforms/mdx/esm-module-loader/cache/index.js";
|
|
26
27
|
import { ensureHttpBundlesExist } from "../../../transforms/esm/http-cache.js";
|
|
27
28
|
import { LRUCache } from "../../../utils/lru-wrapper.js";
|
|
28
29
|
/** Pattern to match HTTP bundle file:// paths in transformed code */
|
|
@@ -190,7 +191,9 @@ export class SSRModuleLoader {
|
|
|
190
191
|
if (!this.options.contentSourceId) {
|
|
191
192
|
throw new Error(`Missing contentSourceId for SSR module cache (project: ${this.options.projectId}, file: ${filePath})`);
|
|
192
193
|
}
|
|
193
|
-
|
|
194
|
+
// Include reactVersion in cache key to ensure different versions don't share cached modules
|
|
195
|
+
const reactVersion = this.options.reactVersion ?? "default";
|
|
196
|
+
return buildSSRModuleCacheKey(TRANSFORM_CACHE_VERSION, this.options.projectId, `${this.options.contentSourceId}:${reactVersion}:${filePath}`);
|
|
194
197
|
}
|
|
195
198
|
isProductionContentSource() {
|
|
196
199
|
const sourceId = this.options.contentSourceId;
|
|
@@ -259,6 +262,7 @@ export class SSRModuleLoader {
|
|
|
259
262
|
dev: this.options.dev,
|
|
260
263
|
ssr: true,
|
|
261
264
|
apiBaseUrl: this.options.apiBaseUrl,
|
|
265
|
+
reactVersion: this.options.reactVersion,
|
|
262
266
|
};
|
|
263
267
|
const filePathWithExt = syntheticFilePath.endsWith(ext)
|
|
264
268
|
? syntheticFilePath
|
|
@@ -397,6 +401,25 @@ export class SSRModuleLoader {
|
|
|
397
401
|
// Fall through to re-transform, which will create HTTP bundles locally
|
|
398
402
|
}
|
|
399
403
|
}
|
|
404
|
+
// Check MDX-ESM cache to share modules with MDX loader and avoid duplicate React contexts
|
|
405
|
+
if (this.options.projectId && this.options.contentSourceId) {
|
|
406
|
+
const baseCacheDir = getMdxEsmCacheDir();
|
|
407
|
+
const projectKey = hashCodeHex(this.options.projectId);
|
|
408
|
+
const sourceKey = hashCodeHex(this.options.contentSourceId);
|
|
409
|
+
const mdxCacheDir = join(baseCacheDir, projectKey, sourceKey);
|
|
410
|
+
const mdxCachedPath = await lookupMdxEsmCache(filePath, mdxCacheDir, this.options.projectDir, contentHash);
|
|
411
|
+
if (mdxCachedPath) {
|
|
412
|
+
const entry = { tempPath: mdxCachedPath, contentHash };
|
|
413
|
+
globalModuleCache.set(contentCacheKey, entry);
|
|
414
|
+
globalModuleCache.set(filePathCacheKey, entry);
|
|
415
|
+
logger.debug("[SSR-MODULE-LOADER] Reusing MDX-ESM cache", {
|
|
416
|
+
file: filePath.slice(-40),
|
|
417
|
+
cachedPath: mdxCachedPath.slice(-60),
|
|
418
|
+
});
|
|
419
|
+
await this.ensureDependenciesExist(code, filePath, depth);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
}
|
|
400
423
|
const existingTransform = globalInProgress.get(inProgressKey);
|
|
401
424
|
if (existingTransform) {
|
|
402
425
|
try {
|
|
@@ -459,6 +482,7 @@ export class SSRModuleLoader {
|
|
|
459
482
|
dev: this.options.dev,
|
|
460
483
|
ssr: true,
|
|
461
484
|
apiBaseUrl: this.options.apiBaseUrl,
|
|
485
|
+
reactVersion: this.options.reactVersion,
|
|
462
486
|
};
|
|
463
487
|
let transformed = await withSpan(SpanNames.SSR_TRANSFORM_SINGLE, () => transformToESM(code, filePath, this.options.projectDir, this.options.adapter, transformOpts), { "ssr.file": filePath.split("/").pop() || filePath });
|
|
464
488
|
for (const [specifier, tempPath] of crossProjectPaths.entries()) {
|
|
@@ -683,26 +707,13 @@ export class SSRModuleLoader {
|
|
|
683
707
|
}));
|
|
684
708
|
}
|
|
685
709
|
}
|
|
686
|
-
/**
|
|
687
|
-
* Fast sync hash for small strings (project IDs, etc.)
|
|
688
|
-
* Use hashContentAsync for large file content.
|
|
689
|
-
*/
|
|
690
|
-
hashCode(str) {
|
|
691
|
-
let hash = 0;
|
|
692
|
-
for (let i = 0; i < str.length; i++) {
|
|
693
|
-
const char = str.charCodeAt(i);
|
|
694
|
-
hash = (hash << 5) - hash + char;
|
|
695
|
-
hash = hash & hash;
|
|
696
|
-
}
|
|
697
|
-
return Math.abs(hash).toString(16);
|
|
698
|
-
}
|
|
699
710
|
/**
|
|
700
711
|
* Async hash for large content using Web Crypto API.
|
|
701
|
-
*
|
|
712
|
+
* Falls back to sync hash for small files.
|
|
702
713
|
*/
|
|
703
714
|
async hashContentAsync(content) {
|
|
704
715
|
if (content.length < 10000)
|
|
705
|
-
return
|
|
716
|
+
return hashCodeHex(content);
|
|
706
717
|
try {
|
|
707
718
|
const data = new TextEncoder().encode(content);
|
|
708
719
|
const hashBuffer = await dntShim.crypto.subtle.digest("SHA-256", data);
|
|
@@ -713,7 +724,7 @@ export class SSRModuleLoader {
|
|
|
713
724
|
.join("");
|
|
714
725
|
}
|
|
715
726
|
catch {
|
|
716
|
-
return
|
|
727
|
+
return hashCodeHex(content);
|
|
717
728
|
}
|
|
718
729
|
}
|
|
719
730
|
async getTempPath(filePath, contentHash) {
|
|
@@ -729,26 +740,23 @@ export class SSRModuleLoader {
|
|
|
729
740
|
return join(tmpDir, jsPath);
|
|
730
741
|
}
|
|
731
742
|
async ensureTmpDir() {
|
|
732
|
-
let projectDir = this.options.projectDir;
|
|
733
743
|
const { projectId, contentSourceId } = this.options;
|
|
734
744
|
if (!projectId) {
|
|
735
|
-
throw new Error(`Missing projectId for SSR temp directory (projectDir: ${projectDir})`);
|
|
745
|
+
throw new Error(`Missing projectId for SSR temp directory (projectDir: ${this.options.projectDir})`);
|
|
736
746
|
}
|
|
737
747
|
if (!contentSourceId) {
|
|
738
748
|
throw new Error(`Missing contentSourceId for SSR temp directory (project: ${projectId})`);
|
|
739
749
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
const
|
|
744
|
-
const
|
|
745
|
-
const cacheKey = `${
|
|
750
|
+
// Use the same cache directory as MDX-ESM loader to share module instances.
|
|
751
|
+
// This prevents issues like React context being created twice in separate files.
|
|
752
|
+
const baseCacheDir = getMdxEsmCacheDir();
|
|
753
|
+
const projectKey = hashCodeHex(projectId);
|
|
754
|
+
const sourceKey = hashCodeHex(contentSourceId);
|
|
755
|
+
const cacheKey = `${baseCacheDir}|${projectKey}|${sourceKey}`;
|
|
746
756
|
const existingDir = globalTmpDirs.get(cacheKey);
|
|
747
757
|
if (existingDir)
|
|
748
758
|
return existingDir;
|
|
749
|
-
const
|
|
750
|
-
const sourceKey = this.hashCode(contentSourceId);
|
|
751
|
-
const tmpDir = join(baseDir, "veryfront-ssr", projectKey, sourceKey);
|
|
759
|
+
const tmpDir = join(baseCacheDir, projectKey, sourceKey);
|
|
752
760
|
await this.fs.mkdir(tmpDir, { recursive: true });
|
|
753
761
|
globalTmpDirs.set(cacheKey, tmpDir);
|
|
754
762
|
return tmpDir;
|
|
@@ -14,6 +14,8 @@ export interface SSRModuleLoaderOptions {
|
|
|
14
14
|
apiBaseUrl?: string;
|
|
15
15
|
/** Content source ID for cache isolation (branch name or release ID) */
|
|
16
16
|
contentSourceId?: string;
|
|
17
|
+
/** React version for transforms (defaults to DEFAULT_REACT_VERSION) */
|
|
18
|
+
reactVersion?: string;
|
|
17
19
|
}
|
|
18
20
|
export interface ModuleCacheEntry {
|
|
19
21
|
tempPath: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/src/modules/react-loader/ssr-module-loader/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,cAAc,CAAC;IACxB,GAAG,EAAE,OAAO,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,eAAe,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/src/modules/react-loader/ssr-module-loader/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE,MAAM,WAAW,sBAAsB;IACrC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,cAAc,CAAC;IACxB,GAAG,EAAE,OAAO,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,uEAAuE;IACvE,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,OAAO,CAAC;CACvB"}
|
|
@@ -8,6 +8,8 @@ export interface LoadComponentOptions {
|
|
|
8
8
|
ssr?: boolean;
|
|
9
9
|
/** Content source ID for cache isolation (branch name or release ID) */
|
|
10
10
|
contentSourceId?: string;
|
|
11
|
+
/** React version for transforms (from project config) */
|
|
12
|
+
reactVersion?: string;
|
|
11
13
|
}
|
|
12
14
|
export interface ComponentSource {
|
|
13
15
|
name: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/react-loader/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAEpC,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mFAAmF;IACnF,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,wEAAwE;IACxE,eAAe,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/react-loader/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAEpC,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,mFAAmF;IACnF,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,wEAAwE;IACxE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unified-loader.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/react-loader/unified-loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAMtE,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"unified-loader.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/react-loader/unified-loader.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAMtE,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAKtF,wBAAgB,qBAAqB,CACnC,UAAU,EAAE,eAAe,EAAE,EAC7B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,cAAc,EACvB,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,YAAY,CAAC,CAmCvB"}
|
|
@@ -3,12 +3,14 @@ import { transformToESM } from "../../transforms/esm/index.js";
|
|
|
3
3
|
import { rendererLogger as logger } from "../../utils/index.js";
|
|
4
4
|
import { withSpan } from "../../observability/tracing/otlp-setup.js";
|
|
5
5
|
import { getProjectTmpDir } from "./temp-directory.js";
|
|
6
|
+
import { DEFAULT_REACT_VERSION } from "../../transforms/esm/package-registry.js";
|
|
6
7
|
export function loadComponentsUnified(components, projectDir, adapter, options) {
|
|
7
8
|
return withSpan("modules.loadComponentsUnified", async () => {
|
|
8
9
|
const projectId = options?.projectId ?? projectDir;
|
|
9
10
|
const dev = options?.dev ?? true;
|
|
10
11
|
const moduleServerUrl = options?.moduleServerUrl;
|
|
11
|
-
const
|
|
12
|
+
const reactVersion = options?.reactVersion;
|
|
13
|
+
const transformOpts = { projectId, dev, moduleServerUrl, reactVersion };
|
|
12
14
|
const transformedComponents = await transformAllComponents(components, projectDir, adapter, transformOpts);
|
|
13
15
|
const baseTmp = await getProjectTmpDir(projectId);
|
|
14
16
|
const uniqueTmp = `unified-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
@@ -16,7 +18,7 @@ export function loadComponentsUnified(components, projectDir, adapter, options)
|
|
|
16
18
|
await adapter.fs.mkdir(tmpDir, { recursive: true });
|
|
17
19
|
try {
|
|
18
20
|
await writeComponentFiles(tmpDir, transformedComponents, adapter);
|
|
19
|
-
const entryCode = generateEntryPoint(transformedComponents);
|
|
21
|
+
const entryCode = generateEntryPoint(transformedComponents, reactVersion);
|
|
20
22
|
await adapter.fs.writeFile(join(tmpDir, "entry.js"), entryCode);
|
|
21
23
|
return await importUnifiedComponents(tmpDir, transformedComponents);
|
|
22
24
|
}
|
|
@@ -34,13 +36,14 @@ function transformAllComponents(components, projectDir, adapter, transformOpts)
|
|
|
34
36
|
async function writeComponentFiles(tmpDir, components, adapter) {
|
|
35
37
|
await Promise.all(components.map((comp) => adapter.fs.writeFile(join(tmpDir, `${comp.name}.js`), comp.code)));
|
|
36
38
|
}
|
|
37
|
-
function generateEntryPoint(components) {
|
|
39
|
+
function generateEntryPoint(components, reactVersion) {
|
|
40
|
+
const version = reactVersion ?? DEFAULT_REACT_VERSION;
|
|
38
41
|
const imports = components
|
|
39
42
|
.map((comp) => `import { default as ${comp.name} } from './${comp.name}.js'`)
|
|
40
43
|
.join("\n");
|
|
41
44
|
const exports = components.map((comp) => comp.name).join(", ");
|
|
42
45
|
return `
|
|
43
|
-
import * as React from 'https://esm.sh/react
|
|
46
|
+
import * as React from 'https://esm.sh/react@${version}?target=es2022'
|
|
44
47
|
${imports}
|
|
45
48
|
|
|
46
49
|
export { ${exports} }
|
|
@@ -29,6 +29,8 @@ export interface BatchHandlerOptions {
|
|
|
29
29
|
* When not set, users can import from any directory in the project.
|
|
30
30
|
*/
|
|
31
31
|
allowedImportDirs?: string[];
|
|
32
|
+
/** React version for transforms (from project config) */
|
|
33
|
+
reactVersion?: string;
|
|
32
34
|
}
|
|
33
35
|
/**
|
|
34
36
|
* Handle a batch module request
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-batch-handler.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/server/module-batch-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AASlD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AActE,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,cAAc,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"module-batch-handler.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/server/module-batch-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AASlD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AActE,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,cAAc,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAWD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CAyK/G;AAqJD;;GAEG;AACH,wBAAgB,eAAe,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAY1D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAKrE"}
|
|
@@ -61,7 +61,7 @@ export function handleModuleBatch(req, options) {
|
|
|
61
61
|
headers: { "Content-Type": "text/plain" },
|
|
62
62
|
});
|
|
63
63
|
}
|
|
64
|
-
const { projectDir, adapter, projectSlug, projectId, branch, dev = false, allowedImportDirs, } = options;
|
|
64
|
+
const { projectDir, adapter, projectSlug, projectId, branch, dev = false, allowedImportDirs, reactVersion, } = options;
|
|
65
65
|
const projectKey = projectId || projectSlug || "default";
|
|
66
66
|
const userAgent = req.headers.get("user-agent") ?? "";
|
|
67
67
|
const isSSR = url.searchParams.get("ssr") === "true" || userAgent.startsWith("Deno/");
|
|
@@ -98,6 +98,7 @@ export function handleModuleBatch(req, options) {
|
|
|
98
98
|
projectSlug,
|
|
99
99
|
branch,
|
|
100
100
|
projectId,
|
|
101
|
+
reactVersion,
|
|
101
102
|
});
|
|
102
103
|
const transformDurationMs = performance.now() - moduleStart;
|
|
103
104
|
if (!code) {
|
|
@@ -207,6 +208,7 @@ async function transformModule(source, sourceFile, projectDir, adapter, options)
|
|
|
207
208
|
projectId: options.projectId ?? projectDir,
|
|
208
209
|
dev: options.dev,
|
|
209
210
|
ssr: options.ssr,
|
|
211
|
+
reactVersion: options.reactVersion,
|
|
210
212
|
});
|
|
211
213
|
if (options.ssr) {
|
|
212
214
|
code = applySSRImportRewrites(code, {
|
|
@@ -23,6 +23,8 @@ export interface ModuleServerOptions {
|
|
|
23
23
|
* When not set, users can import from any directory in the project.
|
|
24
24
|
*/
|
|
25
25
|
allowedImportDirs?: string[];
|
|
26
|
+
/** React version for transforms (from project config) */
|
|
27
|
+
reactVersion?: string;
|
|
26
28
|
}
|
|
27
29
|
/** Serve transformed module at /_vf_modules/* path */
|
|
28
30
|
export declare function serveModule(req: dntShim.Request, options: ModuleServerOptions): Promise<dntShim.Response>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-server.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/server/module-server.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AAIlD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAsBtE,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;
|
|
1
|
+
{"version":3,"file":"module-server.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/server/module-server.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AAIlD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAsBtE,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;CACvB;AAED,sDAAsD;AACtD,wBAAgB,WAAW,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,CA0SzG;AAqJD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,CAAC,OAAO,GAAG,OAAO,CAG7D"}
|
|
@@ -24,7 +24,7 @@ export function serveModule(req, options) {
|
|
|
24
24
|
const url = new URL(req.url);
|
|
25
25
|
return withSpan("modules.serve", async () => {
|
|
26
26
|
const startTime = performance.now();
|
|
27
|
-
const { projectId, projectDir, adapter, dev = true, projectUUID, allowedImportDirs, } = options;
|
|
27
|
+
const { projectId, projectDir, adapter, dev = true, projectUUID, allowedImportDirs, reactVersion, } = options;
|
|
28
28
|
const effectiveProjectId = projectUUID ?? projectId;
|
|
29
29
|
const method = req.method.toUpperCase();
|
|
30
30
|
const isHeadRequest = method === "HEAD";
|
|
@@ -83,7 +83,7 @@ export function serveModule(req, options) {
|
|
|
83
83
|
codeLength: snippetCode.length,
|
|
84
84
|
});
|
|
85
85
|
try {
|
|
86
|
-
let transformedCode = await transformToESM(snippetCode, `_snippets/${hash}.tsx`, projectDir, adapter, { projectId: effectiveProjectId, dev, ssr: isSSR });
|
|
86
|
+
let transformedCode = await transformToESM(snippetCode, `_snippets/${hash}.tsx`, projectDir, adapter, { projectId: effectiveProjectId, dev, ssr: isSSR, reactVersion });
|
|
87
87
|
if (isSSR && transformedCode) {
|
|
88
88
|
transformedCode = applySSRImportRewrites(transformedCode, {
|
|
89
89
|
projectSlug: snippetProjectSlug,
|
|
@@ -151,6 +151,7 @@ export function serveModule(req, options) {
|
|
|
151
151
|
dev,
|
|
152
152
|
ssr: isSSR,
|
|
153
153
|
moduleServerUrl: `http://${url.host}`,
|
|
154
|
+
reactVersion,
|
|
154
155
|
});
|
|
155
156
|
if (isSSR && code) {
|
|
156
157
|
code = applySSRImportRewrites(code, { crossProjectRef: projectRef });
|
|
@@ -218,6 +219,7 @@ export function serveModule(req, options) {
|
|
|
218
219
|
dev,
|
|
219
220
|
ssr: isSSR,
|
|
220
221
|
studioEmbed,
|
|
222
|
+
reactVersion,
|
|
221
223
|
};
|
|
222
224
|
code = await transformToESM(source, sourceFile, projectDir, adapter, transformOpts);
|
|
223
225
|
if (isSSR && code) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-import-rewriter.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/server/ssr-import-rewriter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ssr-import-rewriter.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/server/ssr-import-rewriter.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,iBAAiB;IAChC,6CAA6C;IAC7C,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,6BAA6B;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,+CAA+C;IAC/C,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAsFD,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,iBAAsB,GAAG,MAAM,CAK5F"}
|