veryfront 0.1.734 → 0.1.736

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.734",
3
+ "version": "0.1.736",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "minimumDependencyAge": "P2D",
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAO5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAexD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAS9F;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;CAOtD;AAED;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,KAAK;gBAC1C,SAAS,EAAE,MAAM;CAI9B;AAcD;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,oBAAoB,EAC7B,gBAAgB,CAAC,EAAE,MAAM,EACzB,OAAO,GAAE,GAAG,CAAC,MAAM,CAAa,GAC/B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAwFxB;AAoSD;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,cAAc,EACvB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE;IACR,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,GACA,oBAAoB,CAUtB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAO5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAcxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAS9F;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;CAOtD;AAED;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,KAAK;gBAC1C,SAAS,EAAE,MAAM;CAI9B;AAcD;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,oBAAoB,EAC7B,gBAAgB,CAAC,EAAE,MAAM,EACzB,OAAO,GAAE,GAAG,CAAC,MAAM,CAAa,GAC/B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAwFxB;AAiRD;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,cAAc,EACvB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE;IACR,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,GACA,oBAAoB,CAUtB"}
@@ -18,18 +18,17 @@ import { loadImportMap } from "../../../../modules/import-map/index.js";
18
18
  import { getHttpBundleCacheDir } from "../../../../utils/cache-dir.js";
19
19
  import { REACT_DEFAULT_VERSION } from "../../../../utils/constants/cdn.js";
20
20
  import { LOG_PREFIX_MDX_LOADER } from "../constants.js";
21
- import { getLocalFs, getModulePathCache } from "../cache/index.js";
21
+ import { getModulePathCache } from "../cache/index.js";
22
22
  import { hashString } from "../utils/hash.js";
23
23
  import { resolveModuleFile } from "../resolution/file-finder.js";
24
24
  import { buildMissingModuleError } from "../missing-module.js";
25
25
  import { getTransformCacheKey, getVersionedPathCacheKey } from "./cache-keys.js";
26
26
  import { rewriteDntImports, rewriteVeryfrontImports } from "./import-rewriter.js";
27
27
  import { findNestedImports, processNestedImports } from "./nested-imports.js";
28
- import { validateCachedModule } from "./framework-validator.js";
29
- import { recordModuleToSession } from "./render-sessions.js";
30
28
  import { readDistributedCache, writeDistributedCache } from "./distributed-cache.js";
31
29
  import { fetchModuleViaHTTP } from "./http-fetcher.js";
32
30
  import { cacheModule, normalizePath } from "./module-cache.js";
31
+ import { readValidCachedModulePath } from "./path-cache-lookup.js";
33
32
  // Re-export extracted modules for backward compatibility
34
33
  export { rewriteDntImports } from "./import-rewriter.js";
35
34
  export { endRenderSession, hasRenderSession, startRenderSession } from "./render-sessions.js";
@@ -153,28 +152,20 @@ async function doFetchAndCacheModule(normalizedPath, context, fetchAndCacheModul
153
152
  const effectiveReactVersion = context.reactVersion ?? REACT_DEFAULT_VERSION;
154
153
  const pathCache = await getModulePathCache(esmCacheDir);
155
154
  const versionedKey = getVersionedPathCacheKey(normalizedPath, effectiveReactVersion);
156
- const cachedPath = pathCache.get(versionedKey);
157
- if (cachedPath) {
158
- try {
159
- const stat = await getLocalFs().stat(cachedPath);
160
- if (stat?.isFile) {
161
- const cachedCode = await getLocalFs().readTextFile(cachedPath);
162
- if (await validateCachedModule(normalizedPath, cachedPath, cachedCode, log, pathCache, versionedKey, context.contentSourceId
163
- ? {
164
- projectId: context.projectId,
165
- contentSourceId: context.contentSourceId,
166
- }
167
- : undefined)) {
168
- recordModuleToSession(normalizedPath);
169
- return cachedPath;
170
- }
155
+ const cachedPath = await readValidCachedModulePath({
156
+ normalizedPath,
157
+ pathCache,
158
+ versionedKey,
159
+ log,
160
+ recoveryOptions: context.contentSourceId
161
+ ? {
162
+ projectId: context.projectId,
163
+ contentSourceId: context.contentSourceId,
171
164
  }
172
- }
173
- catch (_) {
174
- /* expected: cached file may no longer exist on disk */
175
- pathCache.delete(versionedKey);
176
- }
177
- }
165
+ : undefined,
166
+ });
167
+ if (cachedPath)
168
+ return cachedPath;
178
169
  try {
179
170
  const resolved = await resolveModuleFile(normalizedPath, adapter, projectDir);
180
171
  if (!resolved) {
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Validated path-cache lookups for MDX ESM module fetching.
3
+ *
4
+ * @module transforms/mdx/esm-module-loader/module-fetcher/path-cache-lookup
5
+ */
6
+ import type { Logger } from "../../../../utils/logger/logger.js";
7
+ interface MdxRecoveryOptions {
8
+ projectId: string;
9
+ contentSourceId: string;
10
+ }
11
+ export interface ReadValidCachedModulePathInput {
12
+ normalizedPath: string;
13
+ pathCache: Map<string, string>;
14
+ versionedKey: string;
15
+ log: Logger;
16
+ recoveryOptions?: MdxRecoveryOptions;
17
+ }
18
+ /**
19
+ * Return a cached module path only when the path-cache entry points to an
20
+ * existing file whose contents pass the full cached-module validator.
21
+ */
22
+ export declare function readValidCachedModulePath(input: ReadValidCachedModulePathInput): Promise<string | null>;
23
+ export {};
24
+ //# sourceMappingURL=path-cache-lookup.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path-cache-lookup.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/path-cache-lookup.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAKjE,UAAU,kBAAkB;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,8BAA8B;IAC7C,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,eAAe,CAAC,EAAE,kBAAkB,CAAC;CACtC;AAED;;;GAGG;AACH,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,8BAA8B,GACpC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA6BxB"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Validated path-cache lookups for MDX ESM module fetching.
3
+ *
4
+ * @module transforms/mdx/esm-module-loader/module-fetcher/path-cache-lookup
5
+ */
6
+ import { getLocalFs } from "../cache/index.js";
7
+ import { validateCachedModule } from "./framework-validator.js";
8
+ import { recordModuleToSession } from "./render-sessions.js";
9
+ /**
10
+ * Return a cached module path only when the path-cache entry points to an
11
+ * existing file whose contents pass the full cached-module validator.
12
+ */
13
+ export async function readValidCachedModulePath(input) {
14
+ const cachedPath = input.pathCache.get(input.versionedKey);
15
+ if (!cachedPath)
16
+ return null;
17
+ try {
18
+ const stat = await getLocalFs().stat(cachedPath);
19
+ if (!stat?.isFile)
20
+ return null;
21
+ const cachedCode = await getLocalFs().readTextFile(cachedPath);
22
+ if (await validateCachedModule(input.normalizedPath, cachedPath, cachedCode, input.log, input.pathCache, input.versionedKey, input.recoveryOptions)) {
23
+ recordModuleToSession(input.normalizedPath);
24
+ return cachedPath;
25
+ }
26
+ }
27
+ catch (_) {
28
+ /* expected: cached file may no longer exist on disk */
29
+ input.pathCache.delete(input.versionedKey);
30
+ }
31
+ return null;
32
+ }
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Specifier resolution helpers for the SSR VF Modules stage.
3
+ *
4
+ * @module transforms/pipeline/stages/ssr-vf-modules/specifier-resolver
5
+ */
6
+ export interface FrameworkSpecifierResolverInput {
7
+ denoConfigStubUrl: string | null;
8
+ veryfrontReplacements: ReadonlyMap<string, string>;
9
+ relativeReplacements: ReadonlyMap<string, string>;
10
+ reactVersion: string;
11
+ reactImportMap?: Record<string, string>;
12
+ }
13
+ /**
14
+ * Resolve a bare `react` / `react-dom` (or subpath) specifier to its esm.sh
15
+ * URL for the given React version. Returns `null` for anything that is not a
16
+ * React specifier.
17
+ */
18
+ export declare function resolveReactSpecifier(specifier: string, reactVersion: string, reactImportMap?: Record<string, string>): string | null;
19
+ /**
20
+ * If `resolvedPath` is one of veryfront's React re-export modules
21
+ * (`FRAMEWORK_ROOT/react/*.js`), return the esm.sh URL it should be rewritten
22
+ * to for the given React version. Returns `null` for anything else.
23
+ */
24
+ export declare function reactReExportToEsmUrl(resolvedPath: string, reactVersion: string, reactImportMap?: Record<string, string>): string | null;
25
+ /**
26
+ * Build the final specifier resolver for transformed framework code.
27
+ */
28
+ export declare function createFrameworkSpecifierResolver(input: FrameworkSpecifierResolverInput): (specifier: string) => string | null;
29
+ //# sourceMappingURL=specifier-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"specifier-resolver.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/pipeline/stages/ssr-vf-modules/specifier-resolver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,MAAM,WAAW,+BAA+B;IAC9C,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,qBAAqB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnD,oBAAoB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClD,YAAY,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACzC;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,cAAc,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAmC,GACvE,MAAM,GAAG,IAAI,CAef;AAkBD;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACtC,MAAM,GAAG,IAAI,CAKf;AAED;;GAEG;AACH,wBAAgB,gCAAgC,CAC9C,KAAK,EAAE,+BAA+B,GACrC,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAkBtC"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Specifier resolution helpers for the SSR VF Modules stage.
3
+ *
4
+ * @module transforms/pipeline/stages/ssr-vf-modules/specifier-resolver
5
+ */
6
+ import { join } from "../../../../platform/compat/path/index.js";
7
+ import { buildReactUrl, getReactImportMap } from "../../../import-rewriter/url-builder.js";
8
+ import { FRAMEWORK_ROOT } from "./constants.js";
9
+ /**
10
+ * Resolve a bare `react` / `react-dom` (or subpath) specifier to its esm.sh
11
+ * URL for the given React version. Returns `null` for anything that is not a
12
+ * React specifier.
13
+ */
14
+ export function resolveReactSpecifier(specifier, reactVersion, reactImportMap = getReactImportMap(reactVersion)) {
15
+ const mapped = reactImportMap[specifier];
16
+ if (mapped)
17
+ return mapped;
18
+ if (specifier.startsWith("react/")) {
19
+ return buildReactUrl("react", reactVersion, "/" + specifier.slice("react/".length), true);
20
+ }
21
+ if (specifier.startsWith("react-dom/")) {
22
+ return buildReactUrl("react-dom", reactVersion, "/" + specifier.slice("react-dom/".length), true);
23
+ }
24
+ return null;
25
+ }
26
+ /**
27
+ * veryfront's own React re-export modules under `FRAMEWORK_ROOT/react/`
28
+ * mapped to the bare specifier they stand in for.
29
+ */
30
+ const REACT_REEXPORT_SPECIFIERS = {
31
+ "react.js": "react",
32
+ "react-dom.js": "react-dom",
33
+ "react-dom-client.js": "react-dom/client",
34
+ "react-dom-server.js": "react-dom/server",
35
+ "jsx-runtime.js": "react/jsx-runtime",
36
+ "jsx-dev-runtime.js": "react/jsx-dev-runtime",
37
+ };
38
+ /** `FRAMEWORK_ROOT/react/` prefix, precomputed (invariant per process). */
39
+ const REACT_REEXPORT_DIR = join(FRAMEWORK_ROOT, "react") + "/";
40
+ /**
41
+ * If `resolvedPath` is one of veryfront's React re-export modules
42
+ * (`FRAMEWORK_ROOT/react/*.js`), return the esm.sh URL it should be rewritten
43
+ * to for the given React version. Returns `null` for anything else.
44
+ */
45
+ export function reactReExportToEsmUrl(resolvedPath, reactVersion, reactImportMap) {
46
+ if (!resolvedPath.startsWith(REACT_REEXPORT_DIR))
47
+ return null;
48
+ const specifier = REACT_REEXPORT_SPECIFIERS[resolvedPath.slice(REACT_REEXPORT_DIR.length)];
49
+ if (!specifier)
50
+ return null;
51
+ return resolveReactSpecifier(specifier, reactVersion, reactImportMap);
52
+ }
53
+ /**
54
+ * Build the final specifier resolver for transformed framework code.
55
+ */
56
+ export function createFrameworkSpecifierResolver(input) {
57
+ const reactImportMap = input.reactImportMap ?? getReactImportMap(input.reactVersion);
58
+ return (specifier) => {
59
+ if (specifier === "#deno-config") {
60
+ return input.denoConfigStubUrl;
61
+ }
62
+ if (specifier.startsWith("#veryfront/")) {
63
+ return input.veryfrontReplacements.get(specifier) ?? null;
64
+ }
65
+ if (specifier.startsWith("./") || specifier.startsWith("../")) {
66
+ return input.relativeReplacements.get(specifier) ?? null;
67
+ }
68
+ return resolveReactSpecifier(specifier, input.reactVersion, reactImportMap);
69
+ };
70
+ }
@@ -25,12 +25,7 @@ export declare function isCyclePlaceholder(code: string): boolean;
25
25
  * - contentHash: Content-based invalidation
26
26
  */
27
27
  export declare function cacheTransformedCode(transformed: string, vfModulePath: string, fs: ReturnType<typeof createFileSystem>): Promise<string>;
28
- /**
29
- * If `resolvedPath` is one of veryfront's React re-export modules
30
- * (`FRAMEWORK_ROOT/react/*.js`), return the esm.sh URL it should be rewritten
31
- * to for the given React version. Returns `null` for anything else.
32
- */
33
- export declare function reactReExportToEsmUrl(resolvedPath: string, reactVersion: string, reactImportMap?: Record<string, string>): string | null;
28
+ export { reactReExportToEsmUrl } from "./specifier-resolver.js";
34
29
  /**
35
30
  * Core transformation logic for framework TypeScript/TSX files.
36
31
  * Compiles to JavaScript and recursively resolves all imports:
@@ -1 +1 @@
1
- {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/pipeline/stages/ssr-vf-modules/transform.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAcrE,OAAO,EAOL,KAAK,gBAAgB,EAGtB,MAAM,gBAAgB,CAAC;AAKxB;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAExD;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,oBAAoB,CACxC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,EAAE,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,GACtC,OAAO,CAAC,MAAM,CAAC,CA2BjB;AA8ED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACtC,MAAM,GAAG,IAAI,CAKf;AAwMD;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,gBAAgB,EACrB,oBAAoB,UAAQ,EAC5B,KAAK,SAAI,GACR,OAAO,CAAC,MAAM,CAAC,CAsPjB;AAED;;;GAGG;AACH,wBAAsB,kCAAkC,CACtD,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,gBAAgB,GACpB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA4CxB;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,GACtC,OAAO,CAAC,MAAM,CAAC,CAEjB"}
1
+ {"version":3,"file":"transform.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/pipeline/stages/ssr-vf-modules/transform.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAmBrE,OAAO,EAOL,KAAK,gBAAgB,EAGtB,MAAM,gBAAgB,CAAC;AAKxB;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAExD;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,oBAAoB,CACxC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,EACpB,EAAE,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,GACtC,OAAO,CAAC,MAAM,CAAC,CA2BjB;AAgBD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAwMhE;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,GAAG,EAAE,gBAAgB,EACrB,oBAAoB,UAAQ,EAC5B,KAAK,SAAI,GACR,OAAO,CAAC,MAAM,CAAC,CA8OjB;AAED;;;GAGG;AACH,wBAAsB,kCAAkC,CACtD,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,gBAAgB,GACpB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA4CxB;AAED;;;GAGG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,GACtC,OAAO,CAAC,MAAM,CAAC,CAEjB"}
@@ -14,9 +14,10 @@ import { LRUCache } from "../../../../utils/lru-wrapper.js";
14
14
  import { getHttpBundleCacheDir, getMdxEsmCacheDir } from "../../../../utils/cache-dir.js";
15
15
  import { cacheHttpImportsToLocal } from "../../../esm/http-cache.js";
16
16
  import { loadImportMap } from "../../../../modules/import-map/index.js";
17
- import { buildReactUrl, getReactImportMap } from "../../../import-rewriter/url-builder.js";
17
+ import { getReactImportMap } from "../../../import-rewriter/url-builder.js";
18
18
  import { findRelativeImports } from "./import-finder.js";
19
19
  import { resolveRelativeFrameworkImport, resolveVeryfrontSourcePath } from "./path-resolver.js";
20
+ import { createFrameworkSpecifierResolver, reactReExportToEsmUrl, resolveReactSpecifier, } from "./specifier-resolver.js";
20
21
  import { EMBEDDED_SRC_DIR, FRAMEWORK_ROOT, frameworkFileCache, frameworkWriteFlight, LOG_PREFIX, MAX_RELATIVE_IMPORT_DEPTH, transformingFiles, veryfrontTransformCache, } from "./constants.js";
21
22
  import { buildFrameworkVfModuleCacheFileName } from "../../../mdx/esm-module-loader/cache-format.js";
22
23
  const DENO_CONFIG_STUB_CODE = `export default ${JSON.stringify(denoConfig)};`;
@@ -77,70 +78,7 @@ const FALLBACK_TRANSFORM_CACHE_MAX_ENTRIES = 2000;
77
78
  const fallbackTransformCache = new LRUCache({
78
79
  maxEntries: FALLBACK_TRANSFORM_CACHE_MAX_ENTRIES,
79
80
  });
80
- /**
81
- * Resolve a bare `react` / `react-dom` (or subpath) specifier to its esm.sh
82
- * URL for the given React version. Returns `null` for anything that is not a
83
- * React specifier.
84
- *
85
- * Both the main transform path and the depth-limit fallback use this so a
86
- * framework module always links against the single esm.sh React bundle used
87
- * during SSR. Leaving `react` bare would resolve it to the project's own
88
- * React copy — a second React instance whose dispatcher is null, which makes
89
- * the first hook throw "Cannot read properties of null (reading 'useEffect')".
90
- */
91
- function resolveReactSpecifier(specifier, reactVersion, reactImportMap = getReactImportMap(reactVersion)) {
92
- const mapped = reactImportMap[specifier];
93
- if (mapped)
94
- return mapped;
95
- if (specifier.startsWith("react/")) {
96
- return buildReactUrl("react", reactVersion, "/" + specifier.slice("react/".length), true);
97
- }
98
- if (specifier.startsWith("react-dom/")) {
99
- return buildReactUrl("react-dom", reactVersion, "/" + specifier.slice("react-dom/".length), true);
100
- }
101
- return null;
102
- }
103
- /**
104
- * veryfront's own React re-export modules under `FRAMEWORK_ROOT/react/`
105
- * mapped to the bare specifier they stand in for. Each re-export bridges to
106
- * project React via `export * from "react"` (etc.), which during SSR resolves
107
- * to the project's `node_modules` copy — a *different* React instance than
108
- * the esm.sh react-dom bundle uses. The dnt build rewrites framework
109
- * `import ... from "react"` to a relative import of these files, so a
110
- * framework module that does `useEffect` ends up reading a null dispatcher.
111
- * Rewriting these imports straight to the esm.sh bundle keeps every SSR
112
- * module on a single React instance.
113
- *
114
- * Keys must match the compiled re-export filenames under
115
- * `FRAMEWORK_ROOT/react/`, which the build emits from the `react/*.ts` source
116
- * modules (`react.ts`, `react-dom.ts`, `react-dom-client.ts`,
117
- * `react-dom-server.ts`, `jsx-runtime.ts`, `jsx-dev-runtime.ts`). If one is
118
- * renamed or added, update this map too: a stale key silently reintroduces
119
- * the dual-React-instance bug.
120
- */
121
- const REACT_REEXPORT_SPECIFIERS = {
122
- "react.js": "react",
123
- "react-dom.js": "react-dom",
124
- "react-dom-client.js": "react-dom/client",
125
- "react-dom-server.js": "react-dom/server",
126
- "jsx-runtime.js": "react/jsx-runtime",
127
- "jsx-dev-runtime.js": "react/jsx-dev-runtime",
128
- };
129
- /** `FRAMEWORK_ROOT/react/` prefix, precomputed (invariant per process). */
130
- const REACT_REEXPORT_DIR = join(FRAMEWORK_ROOT, "react") + "/";
131
- /**
132
- * If `resolvedPath` is one of veryfront's React re-export modules
133
- * (`FRAMEWORK_ROOT/react/*.js`), return the esm.sh URL it should be rewritten
134
- * to for the given React version. Returns `null` for anything else.
135
- */
136
- export function reactReExportToEsmUrl(resolvedPath, reactVersion, reactImportMap) {
137
- if (!resolvedPath.startsWith(REACT_REEXPORT_DIR))
138
- return null;
139
- const specifier = REACT_REEXPORT_SPECIFIERS[resolvedPath.slice(REACT_REEXPORT_DIR.length)];
140
- if (!specifier)
141
- return null;
142
- return resolveReactSpecifier(specifier, reactVersion, reactImportMap);
143
- }
81
+ export { reactReExportToEsmUrl } from "./specifier-resolver.js";
144
82
  /**
145
83
  * Pick an esbuild loader for a file path, honoring the embedded `.src`
146
84
  * suffix used in compiled binaries (`foo.ts.src` → `ts`). Recognizes
@@ -490,21 +428,13 @@ export async function transformFrameworkCode(content, sourcePath, ctx, throwOnMi
490
428
  const stubPath = await cacheTransformedCode(DENO_CONFIG_STUB_CODE, "#deno-config-stub", ctx.fs);
491
429
  denoConfigStubUrl = `file://${stubPath}`;
492
430
  }
493
- transformed = await replaceSpecifiers(transformed, (specifier) => {
494
- // Handle Deno import-map aliases
495
- if (specifier === "#deno-config") {
496
- return denoConfigStubUrl;
497
- }
498
- // Handle #veryfront/ imports
499
- if (specifier.startsWith("#veryfront/")) {
500
- return veryfrontReplacements.get(specifier) ?? null;
501
- }
502
- // Handle relative imports
503
- if (specifier.startsWith("./") || specifier.startsWith("../")) {
504
- return relativeReplacements.get(specifier) ?? null;
505
- }
506
- return resolveReactSpecifier(specifier, ctx.reactVersion, reactImportMap);
507
- });
431
+ transformed = await replaceSpecifiers(transformed, createFrameworkSpecifierResolver({
432
+ denoConfigStubUrl,
433
+ veryfrontReplacements,
434
+ relativeReplacements,
435
+ reactVersion: ctx.reactVersion,
436
+ reactImportMap,
437
+ }));
508
438
  // Cache HTTP imports to local filesystem
509
439
  const importMap = await loadImportMap(ctx.projectDir);
510
440
  const cacheResult = await cacheHttpImportsToLocal(transformed, {
@@ -1,3 +1,3 @@
1
1
  /** Shared version value. */
2
- export declare const VERSION = "0.1.734";
2
+ export declare const VERSION = "0.1.736";
3
3
  //# sourceMappingURL=version-constant.d.ts.map
@@ -1,4 +1,4 @@
1
1
  // Keep in sync with deno.json version.
2
2
  // scripts/release.ts updates this constant during releases.
3
3
  /** Shared version value. */
4
- export const VERSION = "0.1.734";
4
+ export const VERSION = "0.1.736";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfront",
3
- "version": "0.1.734",
3
+ "version": "0.1.736",
4
4
  "description": "The simplest way to build AI-powered apps",
5
5
  "keywords": [
6
6
  "react",