veryfront 0.1.827 → 0.1.828

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.
Files changed (38) hide show
  1. package/esm/deno.js +1 -1
  2. package/esm/src/modules/react-loader/ssr-module-loader/import-rewriter.d.ts +2 -2
  3. package/esm/src/modules/react-loader/ssr-module-loader/import-rewriter.d.ts.map +1 -1
  4. package/esm/src/modules/react-loader/ssr-module-loader/import-rewriter.js +14 -22
  5. package/esm/src/modules/react-loader/ssr-module-loader/loader.js +2 -2
  6. package/esm/src/modules/react-loader/ssr-module-loader/ssr-cache-manager.d.ts.map +1 -1
  7. package/esm/src/modules/react-loader/ssr-module-loader/ssr-cache-manager.js +11 -4
  8. package/esm/src/modules/react-loader/ssr-module-loader/vf-module-resolver.d.ts +2 -2
  9. package/esm/src/modules/react-loader/ssr-module-loader/vf-module-resolver.d.ts.map +1 -1
  10. package/esm/src/modules/react-loader/ssr-module-loader/vf-module-resolver.js +22 -15
  11. package/esm/src/release-assets/build-executor.d.ts.map +1 -1
  12. package/esm/src/release-assets/build-executor.js +43 -62
  13. package/esm/src/release-assets/html-consumption.d.ts +2 -1
  14. package/esm/src/release-assets/html-consumption.d.ts.map +1 -1
  15. package/esm/src/release-assets/html-consumption.js +4 -2
  16. package/esm/src/rendering/rsc/component-analyzer.d.ts.map +1 -1
  17. package/esm/src/rendering/rsc/component-analyzer.js +2 -1
  18. package/esm/src/rendering/rsc/export-extractor.d.ts +5 -3
  19. package/esm/src/rendering/rsc/export-extractor.d.ts.map +1 -1
  20. package/esm/src/rendering/rsc/export-extractor.js +59 -36
  21. package/esm/src/transforms/mdx/esm-module-loader/cache/index.d.ts.map +1 -1
  22. package/esm/src/transforms/mdx/esm-module-loader/cache/index.js +8 -14
  23. package/esm/src/transforms/mdx/esm-module-loader/import-transformer.d.ts +1 -1
  24. package/esm/src/transforms/mdx/esm-module-loader/import-transformer.d.ts.map +1 -1
  25. package/esm/src/transforms/mdx/esm-module-loader/import-transformer.js +32 -26
  26. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/nested-imports.d.ts.map +1 -1
  27. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/nested-imports.js +7 -5
  28. package/esm/src/transforms/mdx/esm-module-loader/module-writer.d.ts.map +1 -1
  29. package/esm/src/transforms/mdx/esm-module-loader/module-writer.js +8 -8
  30. package/esm/src/transforms/pipeline/stages/ssr-vf-modules/import-finder.d.ts +2 -2
  31. package/esm/src/transforms/pipeline/stages/ssr-vf-modules/import-finder.d.ts.map +1 -1
  32. package/esm/src/transforms/pipeline/stages/ssr-vf-modules/import-finder.js +16 -26
  33. package/esm/src/transforms/pipeline/stages/ssr-vf-modules/index.js +1 -1
  34. package/esm/src/transforms/pipeline/stages/ssr-vf-modules/transform.d.ts.map +1 -1
  35. package/esm/src/transforms/pipeline/stages/ssr-vf-modules/transform.js +8 -5
  36. package/esm/src/utils/version-constant.d.ts +1 -1
  37. package/esm/src/utils/version-constant.js +1 -1
  38. package/package.json +1 -1
package/esm/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.827",
3
+ "version": "0.1.828",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "minimumDependencyAge": {
@@ -9,10 +9,10 @@
9
9
  /**
10
10
  * Rewrite a cross-project import specifier to use a local temp path.
11
11
  */
12
- export declare function rewriteCrossProjectImport(transformed: string, specifier: string, tempPath: string): string;
12
+ export declare function rewriteCrossProjectImport(transformed: string, specifier: string, tempPath: string): Promise<string>;
13
13
  /**
14
14
  * Rewrite local imports to use hashed temp paths.
15
15
  * This ensures each content version uses its own cached module file.
16
16
  */
17
- export declare function rewriteLocalImports(transformed: string, localImportPaths: Map<string, string>, fromFilePath: string, projectDir: string): string;
17
+ export declare function rewriteLocalImports(transformed: string, localImportPaths: Map<string, string>, fromFilePath: string, projectDir: string): Promise<string>;
18
18
  //# sourceMappingURL=import-rewriter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"import-rewriter.d.ts","sourceRoot":"","sources":["../../../../../src/src/modules/react-loader/ssr-module-loader/import-rewriter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAUH;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,MAAM,CAUR;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACrC,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GACjB,MAAM,CA8BR"}
1
+ {"version":3,"file":"import-rewriter.d.ts","sourceRoot":"","sources":["../../../../../src/src/modules/react-loader/ssr-module-loader/import-rewriter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;GAEG;AACH,wBAAsB,yBAAyB,CAC7C,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAYjB;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,gBAAgB,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACrC,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,MAAM,CAAC,CA2BjB"}
@@ -6,27 +6,24 @@
6
6
  *
7
7
  * @module module-system/react-loader/ssr-module-loader/import-rewriter
8
8
  */
9
- const IMPORT_FROM_PREFIX = "from\\s*[\"']";
10
- const IMPORT_FROM_SUFFIX = "[\"']";
11
- const REGEX_ESCAPE = /[.*+?^${}()|[\]\\]/g;
12
- function escapeRegExp(value) {
13
- return value.replace(REGEX_ESCAPE, "\\$&");
14
- }
9
+ import { replaceSpecifiers } from "../../../transforms/esm/lexer.js";
15
10
  /**
16
11
  * Rewrite a cross-project import specifier to use a local temp path.
17
12
  */
18
- export function rewriteCrossProjectImport(transformed, specifier, tempPath) {
13
+ export async function rewriteCrossProjectImport(transformed, specifier, tempPath) {
19
14
  const jsSpecifier = toJsExtension(specifier);
20
- const escapedSpecifier = escapeRegExp(specifier);
21
- const escapedJsSpecifier = escapeRegExp(jsSpecifier);
22
- const pattern = new RegExp(`${IMPORT_FROM_PREFIX}(${escapedSpecifier}|${escapedJsSpecifier})${IMPORT_FROM_SUFFIX}`, "g");
23
- return transformed.replace(pattern, `from "file://${tempPath}"`);
15
+ const replacement = `file://${tempPath}`;
16
+ const replacements = new Map([
17
+ [specifier, replacement],
18
+ [jsSpecifier, replacement],
19
+ ]);
20
+ return await replaceSpecifiers(transformed, (importSpecifier) => replacements.get(importSpecifier) ?? null);
24
21
  }
25
22
  /**
26
23
  * Rewrite local imports to use hashed temp paths.
27
24
  * This ensures each content version uses its own cached module file.
28
25
  */
29
- export function rewriteLocalImports(transformed, localImportPaths, fromFilePath, projectDir) {
26
+ export async function rewriteLocalImports(transformed, localImportPaths, fromFilePath, projectDir) {
30
27
  if (localImportPaths.size === 0)
31
28
  return transformed;
32
29
  const normalizedProjectDir = projectDir.replace(/\/$/, "");
@@ -34,23 +31,18 @@ export function rewriteLocalImports(transformed, localImportPaths, fromFilePath,
34
31
  const fromRelativeDir = fromFileDir.startsWith(normalizedProjectDir)
35
32
  ? fromFileDir.substring(normalizedProjectDir.length + 1)
36
33
  : fromFileDir;
37
- const replacementByPattern = new Map();
34
+ const replacements = new Map();
38
35
  for (const [specifierOrPath, tempPath] of localImportPaths) {
39
36
  const patterns = buildImportPatterns(specifierOrPath, fromRelativeDir, normalizedProjectDir);
40
37
  for (const pattern of patterns) {
41
- if (!replacementByPattern.has(pattern)) {
42
- replacementByPattern.set(pattern, tempPath);
38
+ if (!replacements.has(pattern)) {
39
+ replacements.set(pattern, `file://${tempPath}`);
43
40
  }
44
41
  }
45
42
  }
46
- if (replacementByPattern.size === 0)
43
+ if (replacements.size === 0)
47
44
  return transformed;
48
- const importPattern = Array.from(replacementByPattern.keys()).map(escapeRegExp).join("|");
49
- const regex = new RegExp(`${IMPORT_FROM_PREFIX}(${importPattern})${IMPORT_FROM_SUFFIX}`, "g");
50
- return transformed.replace(regex, (match, specifier) => {
51
- const tempPath = replacementByPattern.get(specifier);
52
- return tempPath === undefined ? match : `from "file://${tempPath}"`;
53
- });
45
+ return await replaceSpecifiers(transformed, (importSpecifier) => replacements.get(importSpecifier) ?? null);
54
46
  }
55
47
  /**
56
48
  * Build import patterns for a given specifier to match in transformed code.
@@ -397,9 +397,9 @@ export class SSRModuleLoader {
397
397
  };
398
398
  let transformed = await withSpan(SpanNames.SSR_TRANSFORM_SINGLE, () => transformToESM(code, filePath, this.options.projectDir, this.options.adapter, transformOpts), { "ssr.file": filePath.split("/").pop() || filePath });
399
399
  for (const [specifier, tempPath] of crossProjectPaths.entries()) {
400
- transformed = rewriteCrossProjectImport(transformed, specifier, tempPath);
400
+ transformed = await rewriteCrossProjectImport(transformed, specifier, tempPath);
401
401
  }
402
- transformed = rewriteLocalImports(transformed, localImportPaths, filePath, this.options.projectDir);
402
+ transformed = await rewriteLocalImports(transformed, localImportPaths, filePath, this.options.projectDir);
403
403
  transformed = await resolveVfModuleImports(transformed, {
404
404
  filePath,
405
405
  projectId: this.options.projectId,
@@ -1 +1 @@
1
- {"version":3,"file":"ssr-cache-manager.d.ts","sourceRoot":"","sources":["../../../../../src/src/modules/react-loader/ssr-module-loader/ssr-cache-manager.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAYlE,OAAO,KAAK,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAW3E;;;;;;;GAOG;AACH,qBAAa,eAAe;IAId,OAAO,CAAC,OAAO;IAH3B,OAAO,CAAC,EAAE,CAAsB;IAChC,OAAO,CAAC,gBAAgB,CAAqB;gBAEz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js";
15
15
  import { rendererLogger } from "../../../utils/index.js";
16
16
  import { hashCodeHex } from "../../../utils/hash-utils.js";
17
17
  import { ensureHttpBundlesExist } from "../../../transforms/esm/http-cache.js";
18
+ import { parseImports } from "../../../transforms/esm/lexer.js";
18
19
  import { getHttpBundleCacheDir, getMdxEsmCacheDir } from "../../../utils/cache-dir.js";
19
20
  import { globalModuleCache, globalTmpDirs } from "./cache/index.js";
20
21
  import { extractAllFilePathsRecursive, extractAllHttpBundlePathsRecursive, verifiedHttpBundlePaths, } from "./http-bundle-helpers.js";
@@ -23,7 +24,6 @@ import { ensureMdxModuleDependencies } from "../../../transforms/mdx/esm-module-
23
24
  const logger = rendererLogger.component("ssr-module-loader");
24
25
  /** Content length threshold: below this, use fast sync hash; above, use async SHA-256 */
25
26
  const SYNC_HASH_THRESHOLD = 10_000;
26
- const UNRESOLVED_VF_MODULE_IMPORT_PATTERN = /from\s*["']((?:file:\/\/)?\/?\/?_vf_modules\/[^"']+)["']/;
27
27
  /**
28
28
  * Manages caching concerns for SSR module loading:
29
29
  * - Cache key computation and config hashing
@@ -108,7 +108,7 @@ export class SSRCacheManager {
108
108
  if (options.checkLocalPaths && await this.hasMissingLocalPaths(code, filePath)) {
109
109
  return false;
110
110
  }
111
- if (this.hasUnresolvedVfModuleImports(code)) {
111
+ if (await this.hasUnresolvedVfModuleImports(code)) {
112
112
  logger.warn(source === "memory-cache"
113
113
  ? "[SSR-MODULE-LOADER] Memory cache has unresolved _vf_modules imports, invalidating"
114
114
  : "[SSR-MODULE-LOADER] Redis cache has unresolved _vf_modules imports, re-transforming", { file: filePath.slice(-40) });
@@ -156,8 +156,15 @@ export class SSRCacheManager {
156
156
  getFs() {
157
157
  return this.fs;
158
158
  }
159
- hasUnresolvedVfModuleImports(code) {
160
- return UNRESOLVED_VF_MODULE_IMPORT_PATTERN.test(code);
159
+ async hasUnresolvedVfModuleImports(code) {
160
+ const imports = await parseImports(code);
161
+ return imports.some((importSpecifier) => {
162
+ const rawPath = importSpecifier.n;
163
+ if (!rawPath)
164
+ return false;
165
+ const path = rawPath.replace(/^(?:file:\/\/)?\/+/, "");
166
+ return path.startsWith("_vf_modules/");
167
+ });
161
168
  }
162
169
  async hasMissingHttpBundles(code, filePath, source) {
163
170
  const bundlePaths = await extractAllHttpBundlePathsRecursive(code);
@@ -5,7 +5,7 @@
5
5
  */
6
6
  import type { RuntimeAdapter } from "../../../platform/adapters/base.js";
7
7
  interface VfModuleImport {
8
- original: string;
8
+ specifier: string;
9
9
  path: string;
10
10
  }
11
11
  interface ResolveVfModuleImportsOptions {
@@ -20,7 +20,7 @@ interface ResolveVfModuleImportsOptions {
20
20
  * Find /_vf_modules/ imports in transformed code.
21
21
  * Matches both /_vf_modules/... and file:///_vf_modules/... forms.
22
22
  */
23
- export declare function findVfModuleImports(code: string): VfModuleImport[];
23
+ export declare function findVfModuleImports(code: string): Promise<VfModuleImport[]>;
24
24
  /**
25
25
  * Resolve /_vf_modules/ imports to local cached modules and rewrite code.
26
26
  */
@@ -1 +1 @@
1
- {"version":3,"file":"vf-module-resolver.d.ts","sourceRoot":"","sources":["../../../../../src/src/modules/react-loader/ssr-module-loader/vf-module-resolver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAWzE,UAAU,cAAc;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,6BAA6B;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,cAAc,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,EAAE,CAelE;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,6BAA6B,GACrC,OAAO,CAAC,MAAM,CAAC,CAwDjB"}
1
+ {"version":3,"file":"vf-module-resolver.d.ts","sourceRoot":"","sources":["../../../../../src/src/modules/react-loader/ssr-module-loader/vf-module-resolver.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAWzE,UAAU,cAAc;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,6BAA6B;IACrC,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,OAAO,EAAE,cAAc,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC,CAoBjF;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,6BAA6B,GACrC,OAAO,CAAC,MAAM,CAAC,CAyDjB"}
@@ -7,24 +7,29 @@ import { join } from "../../../platform/compat/path/index.js";
7
7
  import { hashCodeHex } from "../../../utils/hash-utils.js";
8
8
  import { rendererLogger } from "../../../utils/index.js";
9
9
  import { getMdxEsmCacheDir } from "../../../utils/cache-dir.js";
10
+ import { parseImports, replaceSpecifiers } from "../../../transforms/esm/lexer.js";
10
11
  import { createModuleFetcherContext, fetchAndCacheModule, } from "../../../transforms/mdx/esm-module-loader/module-fetcher/index.js";
11
- import { VF_MODULE_IMPORT_PATTERN } from "../../../transforms/mdx/esm-module-loader/constants.js";
12
12
  const logger = rendererLogger.component("ssr-module-loader");
13
13
  /**
14
14
  * Find /_vf_modules/ imports in transformed code.
15
15
  * Matches both /_vf_modules/... and file:///_vf_modules/... forms.
16
16
  */
17
- export function findVfModuleImports(code) {
17
+ export async function findVfModuleImports(code) {
18
18
  const imports = [];
19
- const pattern = new RegExp(VF_MODULE_IMPORT_PATTERN.source, "g");
20
- let match;
21
- while ((match = pattern.exec(code)) !== null) {
22
- const rawPath = match[1];
19
+ const parsedImports = await parseImports(code);
20
+ for (const importSpecifier of parsedImports) {
21
+ const rawPath = importSpecifier.n;
23
22
  if (!rawPath)
24
23
  continue;
25
24
  // Normalize "file:///_vf_modules/..." and "/_vf_modules/..." to "_vf_modules/..."
26
25
  const path = rawPath.replace(/^(?:file:\/\/)?\/+/, "");
27
- imports.push({ original: match[0], path });
26
+ if (!path.startsWith("_vf_modules/"))
27
+ continue;
28
+ const queryStart = path.indexOf("?");
29
+ imports.push({
30
+ specifier: rawPath,
31
+ path: queryStart === -1 ? path : path.slice(0, queryStart),
32
+ });
28
33
  }
29
34
  return imports;
30
35
  }
@@ -32,7 +37,7 @@ export function findVfModuleImports(code) {
32
37
  * Resolve /_vf_modules/ imports to local cached modules and rewrite code.
33
38
  */
34
39
  export async function resolveVfModuleImports(code, options) {
35
- const imports = findVfModuleImports(code);
40
+ const imports = await findVfModuleImports(code);
36
41
  if (imports.length === 0)
37
42
  return code;
38
43
  logger.debug("Processing _vf_modules imports", {
@@ -49,10 +54,10 @@ export async function resolveVfModuleImports(code, options) {
49
54
  projectSlug: options.projectId,
50
55
  strictMissingModules: false,
51
56
  });
52
- const results = await Promise.all(imports.map(async ({ original, path }) => {
57
+ const results = await Promise.all(imports.map(async ({ specifier, path }) => {
53
58
  try {
54
59
  const cachedFilePath = await fetchAndCacheModule(path, fetcherContext);
55
- return { original, path, cachedFilePath };
60
+ return { specifier, path, cachedFilePath };
56
61
  }
57
62
  catch (error) {
58
63
  logger.warn("Failed to fetch _vf_modules import", {
@@ -60,13 +65,13 @@ export async function resolveVfModuleImports(code, options) {
60
65
  path,
61
66
  error: error instanceof Error ? error.message : String(error),
62
67
  });
63
- return { original, path, cachedFilePath: null };
68
+ return { specifier, path, cachedFilePath: null };
64
69
  }
65
70
  }));
66
- let transformed = code;
67
- for (const { original, path, cachedFilePath } of results) {
71
+ const replacements = new Map();
72
+ for (const { specifier, path, cachedFilePath } of results) {
68
73
  if (cachedFilePath) {
69
- transformed = transformed.replace(original, `from "file://${cachedFilePath}"`);
74
+ replacements.set(specifier, `file://${cachedFilePath}`);
70
75
  }
71
76
  else {
72
77
  logger.warn("Failed to resolve _vf_modules import", {
@@ -75,5 +80,7 @@ export async function resolveVfModuleImports(code, options) {
75
80
  });
76
81
  }
77
82
  }
78
- return transformed;
83
+ if (replacements.size === 0)
84
+ return code;
85
+ return await replaceSpecifiers(code, (specifier) => replacements.get(specifier) ?? null);
79
86
  }
@@ -1 +1 @@
1
- {"version":3,"file":"build-executor.d.ts","sourceRoot":"","sources":["../../../src/src/release-assets/build-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA+BH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AA0B/C,MAAM,WAAW,sBAAsB;IACrC,yDAAyD;IACzD,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,yDAAyD;IACzD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oCAAoC;IACpC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gDAAgD;IAChD,MAAM,EAAE,uBAAuB,CAAC;IAChC,sDAAsD;IAEtD,OAAO,EAAE,GAAG,CAAC;IACb;;;;OAIG;IACH,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAClC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,gCAAgC,CAAC;CACtD;AAED,MAAM,M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ChB,CAAC,CAqCD;AAkDD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,sBAAsB,EAC7B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,uBAAuB,CAAC,CA2ClC"}
1
+ {"version":3,"file":"build-executor.d.ts","sourceRoot":"","sources":["../../../src/src/release-assets/build-executor.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAiCH,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AA0B/C,MAAM,WAAW,sBAAsB;IACrC,yDAAyD;IACzD,gBAAgB,EAAE,MAAM,CAAC;IACzB,oBAAoB;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,oBAAoB;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,cAAc,EAAE,MAAM,CAAC;IACvB,yDAAyD;IACzD,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oCAAoC;IACpC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,gDAAgD;IAChD,MAAM,EAAE,uBAAuB,CAAC;IAChC,sDAAsD;IAEtD,OAAO,EAAE,GAAG,CAAC;IACb;;;;OAIG;IACH,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAClC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,gCAAgC,CAAC;CACtD;AAED,MAAM,MAAM,qBAAqB,GAAG,CAClC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,MAAM,EAElB,OAAO,EAAE,GAAG,EACZ,OAAO,EAAE;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,OAAO,CAAC;IAAC,GAAG,EAAE,OAAO,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,KAC9E,OAAO,CAAC,MAAM,CAAC,CAAC;AAErB,MAAM,WAAW,4BAA4B;IAC3C,oEAAoE;I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E,gCAAgC,CAAC;CACtD,GAAG,OAAO,CAAC;IACV,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC5C,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC,CAkCD;AAsDD,wBAAsB,+BAA+B,CAAC,OAAO,EAAE;IAC7D,QAAQ,EAAE,MAAM,CAAC;CAClB,GAAG,OAAO,CAAC;IACV,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC5C,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC,CAkCD;AAwZD,wBAAsB,8BAA8B,CAAC,OAAO,EAAE;IAC5D,OAAO,EAAE,MAAM,CAAC;IAEhB,OAAO,EAAE,GAAG,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,qBAAqB,CAAC;IAClC,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACrC,GAAG,OAAO,CAAC;IACV,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC5C,MAAM,EAAE,oBAAoB,EAAE,CAAC;IAC/B,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB,CAAC,CAqCD;AAkDD;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,sBAAsB,EAC7B,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,uBAAuB,CAAC,CA2ClC"}
@@ -16,6 +16,7 @@
16
16
  */
17
17
  import { serverLogger } from "../utils/index.js";
18
18
  import { VERSION } from "../utils/version.js";
19
+ import { resolve } from "../extensions/contracts.js";
19
20
  import { createFileSystem } from "../platform/compat/fs.js";
20
21
  import { getHostEnv } from "../platform/compat/process.js";
21
22
  import { dirname, join, normalize } from "../platform/compat/path/index.js";
@@ -88,66 +89,44 @@ function isBrowserModule(path) {
88
89
  return BROWSER_MODULE_DIRS.some((dir) => path.startsWith(dir));
89
90
  }
90
91
  /**
91
- * Statically resolve relative imports in a source file to logical paths.
92
- *
93
- * Parses `import/export ... from "..."` and bare `import "..."` statements.
94
- * Only relative specifiers (`./` or `../`) are resolved; package imports and
95
- * absolute URLs are skipped. Extension-less specifiers try each browser module
96
- * extension in order.
92
+ * Statically resolve runtime imports in a TS/JSX source file to logical paths.
93
+ * Uses the CodeParser AST contract so type-only imports do not enter route
94
+ * preload closure.
97
95
  */
98
- function resolveStaticImports(source, moduleLogicalPath, knownPaths) {
99
- const importRe = /(?:^|;|\n)\s*(?:import|export)\s+(?:[^'"]+\s+from\s+)?['"]([^'"]+)['"]/gm;
100
- const results = [];
101
- let m;
102
- while ((m = importRe.exec(source)) !== null) {
103
- const specifier = m[1];
104
- const isAlias = specifier.startsWith("@/");
105
- if (!isAlias && !specifier.startsWith("./") && !specifier.startsWith("../"))
106
- continue;
107
- const dir = moduleLogicalPath.includes("/")
108
- ? moduleLogicalPath.slice(0, moduleLogicalPath.lastIndexOf("/"))
109
- : ".";
110
- // `@/x` is a project-root alias (mirrors transforms/esm/path-resolver.ts).
111
- // Resolve the path segments manually (no path library needed for simple cases).
112
- const segments = (isAlias ? specifier.substring(2) : `${dir}/${specifier}`)
113
- .split("/").filter((s) => s !== "");
114
- const resolved = [];
115
- for (const seg of segments) {
116
- if (seg === "..") {
117
- resolved.pop();
118
- }
119
- else if (seg !== ".") {
120
- resolved.push(seg);
121
- }
122
- }
123
- const candidate = resolved.join("/");
124
- // If the specifier already has a known extension and exists, use it.
125
- if (knownPaths.has(candidate)) {
126
- results.push(candidate);
127
- continue;
128
- }
129
- // Try appending each browser module extension.
130
- let found = false;
131
- for (const ext of BROWSER_MODULE_EXTENSIONS) {
132
- const withExt = `${candidate}${ext}`;
133
- if (knownPaths.has(withExt)) {
134
- results.push(withExt);
135
- found = true;
136
- break;
137
- }
138
- }
139
- // Also try /index variants for directory imports.
140
- if (!found) {
141
- for (const ext of BROWSER_MODULE_EXTENSIONS) {
142
- const indexPath = `${candidate}/index${ext}`;
143
- if (knownPaths.has(indexPath)) {
144
- results.push(indexPath);
145
- break;
146
- }
147
- }
148
- }
149
- }
150
- return results;
96
+ async function collectStaticProjectModuleImports(source, moduleLogicalPath, knownPaths) {
97
+ return await collectAstStaticProjectModuleImports(source, moduleLogicalPath, knownPaths);
98
+ }
99
+ function readModuleSource(node) {
100
+ return typeof node.source?.value === "string" ? node.source.value : null;
101
+ }
102
+ function isTypeOnlyModuleDeclaration(node) {
103
+ if (node.importKind === "type" || node.exportKind === "type")
104
+ return true;
105
+ if (!node.specifiers?.length)
106
+ return false;
107
+ return node.specifiers.every((specifier) => specifier.importKind === "type" || specifier.exportKind === "type");
108
+ }
109
+ async function collectAstStaticProjectModuleImports(source, moduleLogicalPath, knownPaths) {
110
+ const parser = resolve("CodeParser");
111
+ const ast = await parser.parse({ code: source, filePath: moduleLogicalPath });
112
+ const results = new Set();
113
+ const visit = (path) => {
114
+ const node = path.node;
115
+ if (isTypeOnlyModuleDeclaration(node))
116
+ return;
117
+ const specifier = readModuleSource(node);
118
+ if (!specifier)
119
+ return;
120
+ const importedPath = resolveProjectModuleSpecifier(specifier, moduleLogicalPath, knownPaths);
121
+ if (importedPath)
122
+ results.add(importedPath);
123
+ };
124
+ parser.traverse(ast, {
125
+ ImportDeclaration: visit,
126
+ ExportNamedDeclaration: visit,
127
+ ExportAllDeclaration: visit,
128
+ });
129
+ return [...results];
151
130
  }
152
131
  function resolveKnownModulePath(path, knownPaths) {
153
132
  const normalized = normalizeLogicalPath(path
@@ -193,6 +172,8 @@ function normalizeProjectSpecifier(specifier, logicalPath) {
193
172
  return specifier;
194
173
  if (specifier.startsWith("_veryfront/"))
195
174
  return null;
175
+ if (specifier.startsWith("@/"))
176
+ return specifier.slice(2);
196
177
  if (specifier.startsWith("./") || specifier.startsWith("../")) {
197
178
  const dir = logicalPath.includes("/")
198
179
  ? logicalPath.slice(0, logicalPath.lastIndexOf("/"))
@@ -949,7 +930,7 @@ function addFrameworkDependencyUrlAliases(urls, dependencies) {
949
930
  * Returns all reachable logical paths (entries included).
950
931
  * Modules not in `sourceByPath` are recorded as closure gaps.
951
932
  */
952
- function collectClosure(entrypoints, sourceByPath, knownPaths) {
933
+ async function collectClosure(entrypoints, sourceByPath, knownPaths) {
953
934
  const visited = new Set();
954
935
  const queue = [...entrypoints];
955
936
  const gaps = [];
@@ -964,7 +945,7 @@ function collectClosure(entrypoints, sourceByPath, knownPaths) {
964
945
  gaps.push(`closure-missing:${current}`);
965
946
  continue;
966
947
  }
967
- const imports = resolveStaticImports(source, current, knownPaths);
948
+ const imports = await collectStaticProjectModuleImports(source, current, knownPaths);
968
949
  for (const imp of imports) {
969
950
  if (!visited.has(imp))
970
951
  queue.push(imp);
@@ -1261,7 +1242,7 @@ async function runBuildInner(input, tempDir, client, transform) {
1261
1242
  const route = routeForPage(logicalPath);
1262
1243
  if (!route)
1263
1244
  continue;
1264
- const { modules: closureModules, gaps: closureGaps } = collectClosure([logicalPath], sourceByPath, knownPaths);
1245
+ const { modules: closureModules, gaps: closureGaps } = await collectClosure([logicalPath], sourceByPath, knownPaths);
1265
1246
  // Include only modules we actually have in the manifest (transformed +
1266
1247
  // within size limit). Framework lib/* modules are excluded per contract
1267
1248
  // (they are embedded by the runtime, not shipped as release assets).
@@ -15,7 +15,8 @@ import type { ReleaseAssetManifest } from "./manifest-schema.js";
15
15
  * The HTML shell works with relative source paths like `pages/index.tsx` and
16
16
  * `/_vf_modules/pages/index.js` URLs. Manifest module keys use the logical
17
17
  * source path (e.g. `pages/index.tsx`). This strips a leading `/_vf_modules/`
18
- * and any `.js` URL extension so both forms resolve.
18
+ * prefix and URL query/hash data before the resolver compares source
19
+ * extensions.
19
20
  */
20
21
  export declare function normalizeManifestModuleKey(path: string): string;
21
22
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"html-consumption.d.ts","sourceRoot":"","sources":["../../../src/src/release-assets/html-consumption.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAIjE;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAI/D;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,oBAAoB,EAC9B,WAAW,EAAE,MAAM,GAClB,MAAM,GAAG,IAAI,CAcf;AAED,iFAAiF;AACjF,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,oBAAoB,EAC9B,KAAK,EAAE,MAAM,GACZ,MAAM,EAAE,CAcV"}
1
+ {"version":3,"file":"html-consumption.d.ts","sourceRoot":"","sources":["../../../src/src/release-assets/html-consumption.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAIjE;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK/D;AAED;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,QAAQ,EAAE,oBAAoB,EAC9B,WAAW,EAAE,MAAM,GAClB,MAAM,GAAG,IAAI,CAcf;AAED,iFAAiF;AACjF,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,oBAAoB,EAC9B,KAAK,EAAE,MAAM,GACZ,MAAM,EAAE,CAcV"}
@@ -17,11 +17,13 @@ const logger = serverLogger.component("release-asset-consume");
17
17
  * The HTML shell works with relative source paths like `pages/index.tsx` and
18
18
  * `/_vf_modules/pages/index.js` URLs. Manifest module keys use the logical
19
19
  * source path (e.g. `pages/index.tsx`). This strips a leading `/_vf_modules/`
20
- * and any `.js` URL extension so both forms resolve.
20
+ * prefix and URL query/hash data before the resolver compares source
21
+ * extensions.
21
22
  */
22
23
  export function normalizeManifestModuleKey(path) {
23
- let key = path.replace(/^\/?_vf_modules\//, "");
24
+ let key = String(path || "").replace(/^\/?_vf_modules\//, "");
24
25
  key = key.replace(/^\/+/, "");
26
+ key = key.replace(/[?#].*$/, "");
25
27
  return key;
26
28
  }
27
29
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"component-analyzer.d.ts","sourceRoot":"","sources":["../../../../src/src/rendering/rsc/component-analyzer.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAiB,MAAM,YAAY,CAAC;AACxF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAIzE,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,iBAAiB,GACpB,OAAO,CAAC,iBAAiB,CAAC,CAiB5B;AAuBD,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,MAAM,GAAE,MAAc,EACtB,EAAE,CAAC,EAAE,iBAAiB,GACrB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAiC3C"}
1
+ {"version":3,"file":"component-analyzer.d.ts","sourceRoot":"","sources":["../../../../src/src/rendering/rsc/component-analyzer.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAiB,MAAM,YAAY,CAAC;AACxF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAIzE,wBAAsB,gBAAgB,CACpC,QAAQ,EAAE,MAAM,EAChB,EAAE,EAAE,iBAAiB,GACpB,OAAO,CAAC,iBAAiB,CAAC,CAkB5B;AAuBD,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,MAAM,GAAE,MAAc,EACtB,EAAE,CAAC,EAAE,iBAAiB,GACrB,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAiC3C"}
@@ -12,10 +12,11 @@ export async function analyzeComponent(filePath, fs) {
12
12
  const hasUseServer = detectDirective(content, "use server");
13
13
  // Determine component type: directive takes precedence over file naming convention
14
14
  const type = hasUseClient || filePath.includes(".client.") ? "client" : "server";
15
+ const exports = await extractExportNames(content, filePath);
15
16
  return {
16
17
  type,
17
18
  filePath,
18
- exports: extractExportNames(content),
19
+ exports,
19
20
  id: generateComponentId(filePath),
20
21
  hasUseClient,
21
22
  hasUseServer,
@@ -1,6 +1,8 @@
1
1
  /**
2
- * Extract all export names from source code.
3
- * Handles export function/class/const, named exports, and default exports.
2
+ * Extract runtime export names from source code.
3
+ *
4
+ * Uses the CodeParser AST contract so export-looking strings, comments, and
5
+ * type-only exports do not enter RSC manifests.
4
6
  */
5
- export declare function extractExportNames(source: string): string[];
7
+ export declare function extractExportNames(source: string, filePath?: string): Promise<string[]>;
6
8
  //# sourceMappingURL=export-extractor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"export-extractor.d.ts","sourceRoot":"","sources":["../../../../src/src/rendering/rsc/export-extractor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAuC3D"}
1
+ {"version":3,"file":"export-extractor.d.ts","sourceRoot":"","sources":["../../../../src/src/rendering/rsc/export-extractor.ts"],"names":[],"mappings":"AAiEA;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,QAAQ,SAAkB,GACzB,OAAO,CAAC,MAAM,EAAE,CAAC,CAwBnB"}
@@ -1,42 +1,65 @@
1
+ import { resolve } from "../../extensions/contracts.js";
2
+ function readName(node) {
3
+ if (typeof node?.name === "string")
4
+ return node.name;
5
+ if (typeof node?.value === "string")
6
+ return node.value;
7
+ return null;
8
+ }
9
+ function isTypeOnlyDeclaration(declaration) {
10
+ if (!declaration)
11
+ return false;
12
+ if (declaration.declare === true)
13
+ return true;
14
+ return declaration.type === "TSInterfaceDeclaration" ||
15
+ declaration.type === "TSTypeAliasDeclaration";
16
+ }
17
+ function addDeclarationNames(names, declaration) {
18
+ if (!declaration || isTypeOnlyDeclaration(declaration))
19
+ return;
20
+ if (declaration.type === "FunctionDeclaration" ||
21
+ declaration.type === "ClassDeclaration" ||
22
+ declaration.type === "TSEnumDeclaration") {
23
+ const name = readName(declaration.id);
24
+ if (name)
25
+ names.add(name);
26
+ return;
27
+ }
28
+ if (declaration.type !== "VariableDeclaration")
29
+ return;
30
+ for (const declarator of declaration.declarations ?? []) {
31
+ const name = readName(declarator.id);
32
+ if (name)
33
+ names.add(name);
34
+ }
35
+ }
1
36
  /**
2
- * Extract all export names from source code.
3
- * Handles export function/class/const, named exports, and default exports.
37
+ * Extract runtime export names from source code.
38
+ *
39
+ * Uses the CodeParser AST contract so export-looking strings, comments, and
40
+ * type-only exports do not enter RSC manifests.
4
41
  */
5
- export function extractExportNames(source) {
42
+ export async function extractExportNames(source, filePath = "component.tsx") {
43
+ const parser = resolve("CodeParser");
44
+ const ast = await parser.parse({ code: source, filePath });
6
45
  const names = new Set();
7
- if (/export\s+default\s+/m.test(source)) {
8
- names.add("default");
9
- }
10
- for (const match of source.matchAll(/export\s+function\s+([A-Za-z0-9_]+)/g)) {
11
- if (match[1])
12
- names.add(match[1]);
13
- }
14
- for (const match of source.matchAll(/export\s+class\s+([A-Za-z0-9_]+)/g)) {
15
- if (match[1])
16
- names.add(match[1]);
17
- }
18
- for (const match of source.matchAll(/export\s+(?:const|let|var)\s+([A-Za-z0-9_]+)/g)) {
19
- if (match[1])
20
- names.add(match[1]);
21
- }
22
- for (const match of source.matchAll(/export\s*\{([^}]+)\}/g)) {
23
- const innerRaw = match[1];
24
- if (!innerRaw)
25
- continue;
26
- const inner = innerRaw.split(",");
27
- for (const seg of inner) {
28
- const part = seg.trim();
29
- if (!part)
30
- continue;
31
- const asMatch = part.match(/([A-Za-z0-9_]+)\s+as\s+([A-Za-z0-9_]+)/i);
32
- if (asMatch?.[2]) {
33
- names.add(asMatch[2]);
34
- continue;
46
+ parser.traverse(ast, {
47
+ ExportDefaultDeclaration() {
48
+ names.add("default");
49
+ },
50
+ ExportNamedDeclaration(path) {
51
+ const node = path.node;
52
+ if (node.exportKind === "type")
53
+ return;
54
+ addDeclarationNames(names, node.declaration);
55
+ for (const specifier of node.specifiers ?? []) {
56
+ if (specifier.exportKind === "type")
57
+ continue;
58
+ const name = readName(specifier.exported) ?? readName(specifier.local);
59
+ if (name)
60
+ names.add(name);
35
61
  }
36
- const plain = part.match(/^([A-Za-z0-9_]+)/);
37
- if (plain?.[1])
38
- names.add(plain[1]);
39
- }
40
- }
62
+ },
63
+ });
41
64
  return [...names];
42
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/cache/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAYH,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAI5D,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,MAAM,MAAM,iBAAiB,GACzB;IAAE,MAAM,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAClB;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC;AAK9D,eAAO,MAAM,kBAAkB,wBAE7B,CAAC;AA6IH,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAsBvF;AAED,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAezE;AAED,wBAAgB,oBAAoB,IAAI,IAAI,CAK3C;AAQD,2DAA2D;AAC3D,wBAAgB,kBA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AAM,CAAC;IAAC,eAAe,EAAE,MAAM,CAAA;CAAE,EAChE,YAAY,SAAwB,GACnC,OAAO,CAAC,iBAAiB,CAAC,CA+J5B"}
@@ -15,6 +15,7 @@ import { LRUCache } from "../../../../utils/lru-wrapper.js";
15
15
  import { registerCache } from "../../../../utils/memory/index.js";
16
16
  import { buildMdxEsmPathCacheKey, MDX_ESM_ALL_FILE_URL_PATTERN_SOURCE } from "../cache-format.js";
17
17
  import { ensureMdxModuleDependencies } from "../module-fetcher/dependency-recovery.js";
18
+ import { findStaticImportFromSpans } from "../utils/source-spans.js";
18
19
  export { getLocalFs } from "./local-fs.js";
19
20
  import { getLocalFs } from "./local-fs.js";
20
21
  const MAX_VERIFIED_MODULE_DEPS = 2_000;
@@ -105,27 +106,20 @@ async function findMissingFileDependencies(code) {
105
106
  }
106
107
  return missing;
107
108
  }
108
- /**
109
- * Pattern to match unresolved /_vf_modules/ imports that weren't converted to proper file:// paths.
110
- * Matches both:
111
- * - `from "/_vf_modules/..."` or `from "_vf_modules/..."` (unresolved)
112
- * - `from "file:///_vf_modules/..."` (malformed - points to non-existent root /_vf_modules/)
113
- * Note: Uses \s* instead of \s+ because minified code may have no space after `from`.
114
- * These imports will fail at runtime because they can't be resolved by Deno's dynamic import.
115
- */
116
- const UNRESOLVED_VF_MODULES_PATTERN = /from\s*["']((?:file:\/\/)?\/?\/?_vf_modules\/[^"']+)["']/g;
109
+ function matchUnresolvedVfModuleSpecifier(specifier) {
110
+ return specifier.match(/^((?:file:\/\/)?\/?\/?_vf_modules\/[^?]+)(?:\?.*)?$/)?.[1] ?? null;
111
+ }
117
112
  /**
118
113
  * Check if cached code has unresolved or malformed /_vf_modules/ imports.
119
114
  * These should have been resolved to proper file:// paths (e.g., file:///Users/.cache/...).
120
115
  * Returns true if any unresolved or malformed imports are found.
121
116
  */
122
117
  function hasUnresolvedVfModules(code) {
123
- const pattern = new RegExp(UNRESOLVED_VF_MODULES_PATTERN.source, "g");
124
- let match;
125
- while ((match = pattern.exec(code)) !== null) {
126
- const importPath = match[1];
118
+ const matches = findStaticImportFromSpans(code, matchUnresolvedVfModuleSpecifier);
119
+ const first = matches[0];
120
+ if (first) {
127
121
  logger.debug(`${LOG_PREFIX_MDX_LOADER} Cached module has unresolved _vf_modules import`, {
128
- importPath,
122
+ importPath: first.path,
129
123
  });
130
124
  return true;
131
125
  }
@@ -11,7 +11,7 @@ import type { ESMLoaderContext } from "./types.js";
11
11
  /**
12
12
  * Rewrite @/ aliased imports to /_vf_modules/ paths.
13
13
  */
14
- export declare function rewriteProjectAliasImports(code: string): string;
14
+ export declare function rewriteProjectAliasImports(code: string): Promise<string>;
15
15
  /**
16
16
  * Transform bare React specifiers to local file:// paths for Bun/Node.
17
17
  * This ensures the same React instance as react-dom-server.
@@ -1 +1 @@
1
- {"version":3,"file":"import-transformer.d.ts","sourceRoot":"","sources":["../../../../../src/src/transforms/mdx/esm-module-loader/import-transformer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAe5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAK/D;AAED;;;;GAIG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAK9E;AAyBD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,GAAG,MAAM,CAIjF;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,EACpC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,CA6HjB"}
1
+ {"version":3,"file":"import-transformer.d.ts","sourceRoot":"","sources":["../../../../../src/src/transforms/mdx/esm-module-loader/import-transformer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AAa5E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;GAEG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAO9E;AAED;;;;GAIG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAK9E;AAyBD;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,eAAe,GAAG,MAAM,CAIjF;AAOD;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,EACpC,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,MAAM,CAAC,CAwHjB"}
@@ -9,9 +9,9 @@
9
9
  import { join } from "../../../platform/compat/path/index.js";
10
10
  import { rendererLogger as logger } from "../../../utils/index.js";
11
11
  import { transformImportsWithMap } from "../../../modules/import-map/index.js";
12
- import { replaceSpecifiers } from "../../esm/lexer.js";
12
+ import { parseImports, replaceSpecifiers } from "../../esm/lexer.js";
13
13
  import { getLocalReactPaths, isReactSpecifier } from "../../../platform/compat/react-paths.js";
14
- import { ESBUILD_JSX_FACTORY, ESBUILD_JSX_FRAGMENT, FRAMEWORK_ROOT, JSX_IMPORT_PATTERN, LOG_PREFIX_MDX_LOADER, REACT_IMPORT_PATTERN, } from "./constants.js";
14
+ import { ESBUILD_JSX_FACTORY, ESBUILD_JSX_FRAGMENT, FRAMEWORK_ROOT, LOG_PREFIX_MDX_LOADER, } from "./constants.js";
15
15
  import { getLocalFs } from "./cache/index.js";
16
16
  import { buildMdxJsxCacheFileName } from "./cache-format.js";
17
17
  import { rewriteDntImports } from "./module-fetcher/index.js";
@@ -19,10 +19,13 @@ import { ensureCachedJsxModulePatched } from "./jsx-cache.js";
19
19
  /**
20
20
  * Rewrite @/ aliased imports to /_vf_modules/ paths.
21
21
  */
22
- export function rewriteProjectAliasImports(code) {
23
- return code.replace(/from\s*["']@\/([^"']+)["']/g, (_match, path) => {
22
+ export async function rewriteProjectAliasImports(code) {
23
+ return await replaceSpecifiers(code, (specifier) => {
24
+ if (!specifier.startsWith("@/"))
25
+ return null;
26
+ const path = specifier.slice(2);
24
27
  const jsPath = path.endsWith(".js") ? path : `${path}.js`;
25
- return `from "/_vf_modules/${jsPath}"`;
28
+ return `/_vf_modules/${jsPath}`;
26
29
  });
27
30
  }
28
31
  /**
@@ -65,6 +68,10 @@ export function transformImports(code, importMap) {
65
68
  resolveBare: true,
66
69
  });
67
70
  }
71
+ async function hasReactImport(code) {
72
+ const imports = await parseImports(code);
73
+ return imports.some((importSpecifier) => importSpecifier.n === "react");
74
+ }
68
75
  /**
69
76
  * Transform JSX/TSX imports using esbuild.
70
77
  * Optimized to process all imports in parallel batches for better performance.
@@ -72,25 +79,22 @@ export function transformImports(code, importMap) {
72
79
  export async function transformJsxImports(code, adapter, esmCacheDir) {
73
80
  const { transform } = await import("../../../extensions/bundler/index.js");
74
81
  const importsToProcess = [];
75
- let jsxMatch;
76
- while ((jsxMatch = JSX_IMPORT_PATTERN.exec(code)) !== null) {
77
- const [fullMatch, importClause, filePath, ext] = jsxMatch;
78
- if (!filePath || !importClause || !ext) {
79
- logger.warn(`${LOG_PREFIX_MDX_LOADER} Skipping JSX import with undefined fields`, {
80
- fullMatch,
81
- hasFilePath: !!filePath,
82
- hasImportClause: !!importClause,
83
- hasExt: !!ext,
84
- });
82
+ const imports = await parseImports(code);
83
+ for (const importSpecifier of imports) {
84
+ const specifier = importSpecifier.n;
85
+ if (!specifier?.startsWith("file://"))
85
86
  continue;
86
- }
87
- importsToProcess.push({ fullMatch, importClause, filePath, ext });
87
+ const filePath = specifier.slice("file://".length);
88
+ const ext = filePath.match(/\.(tsx?|jsx?)$/)?.[1];
89
+ if (!ext)
90
+ continue;
91
+ importsToProcess.push({ specifier, filePath, ext });
88
92
  }
89
93
  if (importsToProcess.length === 0)
90
94
  return code;
91
95
  const transformStart = performance.now();
92
96
  logger.debug(`${LOG_PREFIX_MDX_LOADER} Transforming ${importsToProcess.length} JSX imports in parallel`);
93
- const transformResults = await Promise.all(importsToProcess.map(async ({ fullMatch, importClause, filePath, ext }) => {
97
+ const transformResults = await Promise.all(importsToProcess.map(async ({ specifier, filePath, ext }) => {
94
98
  try {
95
99
  const isFrameworkFile = filePath.startsWith(FRAMEWORK_ROOT);
96
100
  let jsxCode;
@@ -115,8 +119,8 @@ export async function transformJsxImports(code, adapter, esmCacheDir) {
115
119
  const useCached = await ensureCachedJsxModulePatched(transformedPath, filePath);
116
120
  if (useCached) {
117
121
  return {
118
- original: fullMatch,
119
- transformed: `import ${importClause} from "file://${transformedPath}";`,
122
+ specifier,
123
+ replacement: `file://${transformedPath}`,
120
124
  cached: true,
121
125
  };
122
126
  }
@@ -140,7 +144,7 @@ export async function transformJsxImports(code, adapter, esmCacheDir) {
140
144
  format: "esm",
141
145
  });
142
146
  let transformed = result.code;
143
- if (!REACT_IMPORT_PATTERN.test(transformed)) {
147
+ if (!(await hasReactImport(transformed))) {
144
148
  transformed = `import React from 'react';\n${transformed}`;
145
149
  }
146
150
  // Rewrite _dnt.polyfills.js / _dnt.shims.js relative imports to absolute file:// paths.
@@ -149,8 +153,8 @@ export async function transformJsxImports(code, adapter, esmCacheDir) {
149
153
  transformed = await rewriteDntImports(transformed, filePath);
150
154
  await getLocalFs().writeTextFile(transformedPath, transformed);
151
155
  return {
152
- original: fullMatch,
153
- transformed: `import ${importClause} from "file://${transformedPath}";`,
156
+ specifier,
157
+ replacement: `file://${transformedPath}`,
154
158
  cached: false,
155
159
  };
156
160
  }
@@ -165,10 +169,12 @@ export async function transformJsxImports(code, adapter, esmCacheDir) {
165
169
  cached: transformResults.filter((r) => r?.cached).length,
166
170
  durationMs: (performance.now() - transformStart).toFixed(1),
167
171
  });
168
- let result = code;
172
+ const replacements = new Map();
169
173
  for (const t of transformResults) {
170
174
  if (t)
171
- result = result.replace(t.original, t.transformed);
175
+ replacements.set(t.specifier, t.replacement);
172
176
  }
173
- return result;
177
+ if (replacements.size === 0)
178
+ return code;
179
+ return await replaceSpecifiers(code, (specifier) => replacements.get(specifier) ?? null);
174
180
  }
@@ -1 +1 @@
1
- {"version":3,"file":"nested-imports.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/nested-imports.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAQtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAEjE;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,GACjB;IACD,SAAS,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACjF,QAAQ,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjF,CAkCA;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAO3F;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,kBAAkB,EAAE,EAC7B,WAAW,EAAE,MAAM,EACnB,oBAAoB,EAAE,OAAO,EAC7B,gBAAgB,CAAC,EAAE,MAAM,EACzB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM,CAAC,CAqCjB;AAED,MAAM,WAAW,+BAA+B;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,mBAAmB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC/E,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,+BAA+B,GACrC,OAAO,CAAC,MAAM,CAAC,CAuDjB"}
1
+ {"version":3,"file":"nested-imports.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/nested-imports.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAQtD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAMjE;;;GAGG;AACH,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,GACjB;IACD,SAAS,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACjF,QAAQ,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjF,CAkCA;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,EAAE,CAAA;CAAE,CAM3F;AAED;;GAEG;AACH,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,kBAAkB,EAAE,EAC7B,WAAW,EAAE,MAAM,EACnB,oBAAoB,EAAE,OAAO,EAC7B,gBAAgB,CAAC,EAAE,MAAM,EACzB,WAAW,CAAC,EAAE,MAAM,GACnB,OAAO,CAAC,MAAM,CAAC,CAqCjB;AAED,MAAM,WAAW,+BAA+B;IAC9C,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,mBAAmB,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC/E,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,wBAAsB,0BAA0B,CAC9C,KAAK,EAAE,+BAA+B,GACrC,OAAO,CAAC,MAAM,CAAC,CAuDjB"}
@@ -3,10 +3,13 @@
3
3
  *
4
4
  * @module transforms/mdx/esm-module-loader/module-fetcher/nested-imports
5
5
  */
6
- import { LOG_PREFIX_MDX_LOADER, UNRESOLVED_VF_MODULES_PATTERN } from "../constants.js";
6
+ import { LOG_PREFIX_MDX_LOADER } from "../constants.js";
7
7
  import { createStubModule } from "../utils/stub-module.js";
8
8
  import { findStaticImportFromSpans, replaceSourceSpans, } from "../utils/source-spans.js";
9
9
  import { buildMissingModuleError } from "../missing-module.js";
10
+ function matchUnresolvedVfModuleSpecifier(specifier) {
11
+ return specifier.match(/^((?:file:\/\/)?\/?\/?_vf_modules\/[^?]+)(?:\?.*)?$/)?.[1] ?? null;
12
+ }
10
13
  /**
11
14
  * Find nested module imports in code.
12
15
  * Matches both /_vf_modules/... and file:///_vf_modules/... patterns.
@@ -14,7 +17,7 @@ import { buildMissingModuleError } from "../missing-module.js";
14
17
  export function findNestedImports(moduleCode) {
15
18
  const vfModules = [];
16
19
  const relative = [];
17
- for (const { original, path: rawPath, start, end } of findStaticImportFromSpans(moduleCode, (specifier) => specifier.match(/^((?:file:\/\/)?\/?\/?_vf_modules\/[^?]+)(?:\?.*)?$/)?.[1])) {
20
+ for (const { original, path: rawPath, start, end } of findStaticImportFromSpans(moduleCode, matchUnresolvedVfModuleSpecifier)) {
18
21
  // Strip file:// prefix and leading slashes to get clean _vf_modules/... path
19
22
  vfModules.push({
20
23
  original,
@@ -37,11 +40,10 @@ export function findNestedImports(moduleCode) {
37
40
  * Check for unresolved /_vf_modules/ imports.
38
41
  */
39
42
  export function hasUnresolvedImports(moduleCode) {
40
- const pattern = new RegExp(UNRESOLVED_VF_MODULES_PATTERN.source, "g");
41
- const matches = [...moduleCode.matchAll(pattern)];
43
+ const matches = findStaticImportFromSpans(moduleCode, matchUnresolvedVfModuleSpecifier);
42
44
  return {
43
45
  count: matches.length,
44
- paths: matches.map((m) => m[1]).filter((p) => p !== undefined).slice(0, 5),
46
+ paths: matches.map((match) => match.path).slice(0, 5),
45
47
  };
46
48
  }
47
49
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"module-writer.d.ts","sourceRoot":"","sources":["../../../../../src/src/transforms/mdx/esm-module-loader/module-writer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAyBH,OAAO,KAAK,EAAkB,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAiDnD,wBAAsB,eAAe,CACnC,mBAAmB,EAAE,MAAM,EAC3B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,SAAS,CAAC,CA4VpB"}
1
+ {"version":3,"file":"module-writer.d.ts","sourceRoot":"","sources":["../../../../../src/src/transforms/mdx/esm-module-loader/module-writer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAyBH,OAAO,KAAK,EAAkB,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AA8CnD,wBAAsB,eAAe,CACnC,mBAAmB,EAAE,MAAM,EAC3B,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,SAAS,CAAC,CA2VpB"}
@@ -20,7 +20,7 @@ import { loadImportMap } from "../../../modules/import-map/index.js";
20
20
  import { cacheHttpImportsToLocal, ensureHttpBundlesExist } from "../../esm/http-cache.js";
21
21
  import { extractAllHttpBundlePathsRecursive, extractHttpBundlePaths, } from "../../../modules/react-loader/ssr-module-loader/http-bundle-helpers.js";
22
22
  import { setupSSRGlobals } from "../../../rendering/ssr-globals.js";
23
- import { LOG_PREFIX_MDX_LOADER, LOG_PREFIX_MDX_RENDERER, UNRESOLVED_VF_MODULES_PATTERN, } from "./constants.js";
23
+ import { LOG_PREFIX_MDX_LOADER, LOG_PREFIX_MDX_RENDERER } from "./constants.js";
24
24
  import { getLocalFs } from "./cache/index.js";
25
25
  import { hashString } from "./utils/hash.js";
26
26
  import { ssrVfModulesPlugin } from "../../pipeline/stages/ssr-vf-modules.js";
@@ -28,6 +28,7 @@ import { REACT_DEFAULT_VERSION } from "../../../utils/constants/cdn.js";
28
28
  import { extractFrameworkBundlePaths } from "../../shared/framework-bundle-paths.js";
29
29
  import { rewriteProjectAliasImports, transformImports, transformJsxImports, transformReactToLocalPaths, } from "./import-transformer.js";
30
30
  import { findMissingFrameworkBundles, findVfModuleImports, initializeCacheDir, processVfModuleImports, resolveProjectDir, } from "./loader-helpers.js";
31
+ import { hasUnresolvedImports } from "./module-fetcher/nested-imports.js";
31
32
  /** Singleflight for MDX module file writes to prevent race conditions */
32
33
  const mdxWriteFlight = new Singleflight();
33
34
  /**
@@ -64,7 +65,7 @@ export async function doLoadModuleESM(compiledProgramCode, context) {
64
65
  logger.debug(`${LOG_PREFIX_MDX_LOADER} Step: initializeCacheDir START`, { projectSlug });
65
66
  const esmCacheDir = await initializeCacheDir(context);
66
67
  logger.debug(`${LOG_PREFIX_MDX_LOADER} Step: initializeCacheDir DONE`, { projectSlug });
67
- let rewritten = rewriteProjectAliasImports(compiledProgramCode);
68
+ let rewritten = await rewriteProjectAliasImports(compiledProgramCode);
68
69
  const projectDir = resolveProjectDir(context);
69
70
  logger.debug(`${LOG_PREFIX_MDX_LOADER} Step: loadImportMap START`, { projectSlug });
70
71
  const importMap = await loadImportMap(projectDir, adapter);
@@ -103,12 +104,11 @@ export async function doLoadModuleESM(compiledProgramCode, context) {
103
104
  return cached;
104
105
  }
105
106
  logger.debug(`${LOG_PREFIX_MDX_LOADER} Module cache miss`, { projectSlug, compositeKey });
106
- const unresolvedMatches = [
107
- ...rewritten.matchAll(new RegExp(UNRESOLVED_VF_MODULES_PATTERN.source, "g")),
108
- ];
109
- if (unresolvedMatches.length > 0) {
110
- const unresolvedPaths = unresolvedMatches.map((m) => m[1]).slice(0, 5);
111
- const errorMsg = `MDX has ${unresolvedMatches.length} unresolved module imports: ${unresolvedPaths.join(", ")}`;
107
+ const unresolved = hasUnresolvedImports(rewritten);
108
+ if (unresolved.count > 0) {
109
+ const errorMsg = `MDX has ${unresolved.count} unresolved module imports: ${unresolved.paths
110
+ .slice(0, 5)
111
+ .join(", ")}`;
112
112
  logger.error(`${LOG_PREFIX_MDX_RENDERER} ${errorMsg}`);
113
113
  throw IMPORT_RESOLUTION_ERROR.create({ detail: errorMsg });
114
114
  }
@@ -5,10 +5,10 @@
5
5
  * Find all /_vf_modules/_veryfront/ imports in the code.
6
6
  * Only matches framework modules, not user project files.
7
7
  */
8
- export declare function findVfModuleImports(code: string): string[];
8
+ export declare function findVfModuleImports(code: string): Promise<string[]>;
9
9
  /**
10
10
  * Find all relative imports (./foo, ../bar) in the code.
11
11
  * Returns array of specifiers.
12
12
  */
13
- export declare function findRelativeImports(code: string): string[];
13
+ export declare function findRelativeImports(code: string): Promise<string[]>;
14
14
  //# sourceMappingURL=import-finder.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"import-finder.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/pipeline/stages/ssr-vf-modules/import-finder.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAc1D;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAiB1D"}
1
+ {"version":3,"file":"import-finder.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/pipeline/stages/ssr-vf-modules/import-finder.ts"],"names":[],"mappings":"AAAA;;GAEG;AAQH;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAUzE;AAED;;;GAGG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAUzE"}
@@ -1,39 +1,29 @@
1
1
  /**
2
2
  * Import discovery functions for the SSR VF Modules stage.
3
3
  */
4
+ import { parseImports } from "../../../esm/lexer.js";
5
+ function unique(values) {
6
+ return [...new Set(values)];
7
+ }
4
8
  /**
5
9
  * Find all /_vf_modules/_veryfront/ imports in the code.
6
10
  * Only matches framework modules, not user project files.
7
11
  */
8
- export function findVfModuleImports(code) {
9
- const imports = [];
10
- // Note: \s* allows zero whitespace (minified code: from"..." has no space)
11
- // Only match _veryfront/ framework modules, not user project files.
12
- // Handle both raw "/_vf_modules/..." specifiers and malformed
13
- // "file:///_vf_modules/..." variants that can leak out of stale caches.
14
- const pattern = /from\s*["']((?:file:\/\/)?\/_vf_modules\/_veryfront\/[^"']+)["']/g;
15
- let match;
16
- while ((match = pattern.exec(code)) !== null) {
17
- imports.push(match[1]);
18
- }
19
- return [...new Set(imports)];
12
+ export async function findVfModuleImports(code) {
13
+ const imports = await parseImports(code);
14
+ return unique(imports
15
+ .map((imp) => imp.n)
16
+ .filter((specifier) => specifier?.startsWith("/_vf_modules/_veryfront/") === true ||
17
+ specifier?.startsWith("file:///_vf_modules/_veryfront/") === true));
20
18
  }
21
19
  /**
22
20
  * Find all relative imports (./foo, ../bar) in the code.
23
21
  * Returns array of specifiers.
24
22
  */
25
- export function findRelativeImports(code) {
26
- const imports = [];
27
- // Match: from "./foo" or from "../bar"
28
- const fromPattern = /from\s*["'](\.\.?\/[^"']+)["']/g;
29
- // Match side-effect imports: import "./foo" or import "../bar" (no `from`)
30
- const sideEffectPattern = /import\s*["'](\.\.?\/[^"']+)["']/g;
31
- let match;
32
- while ((match = fromPattern.exec(code)) !== null) {
33
- imports.push(match[1]);
34
- }
35
- while ((match = sideEffectPattern.exec(code)) !== null) {
36
- imports.push(match[1]);
37
- }
38
- return [...new Set(imports)];
23
+ export async function findRelativeImports(code) {
24
+ const imports = await parseImports(code);
25
+ return unique(imports
26
+ .map((imp) => imp.n)
27
+ .filter((specifier) => specifier?.startsWith("./") === true ||
28
+ specifier?.startsWith("../") === true));
39
29
  }
@@ -52,7 +52,7 @@ export const ssrVfModulesPlugin = {
52
52
  condition: (ctx) => ctx.target === "ssr",
53
53
  async transform(ctx) {
54
54
  logInitOnce();
55
- const vfModuleImports = findVfModuleImports(ctx.code);
55
+ const vfModuleImports = await findVfModuleImports(ctx.code);
56
56
  logger.debug(`${LOG_PREFIX} Transform called`, {
57
57
  file: ctx.filePath?.slice(-60) ?? "<unknown>",
58
58
  count: vfModuleImports.length,
@@ -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;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"}
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,CAgPjB;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"}
@@ -8,7 +8,7 @@ import { join } from "../../../../platform/compat/path/index.js";
8
8
  import denoConfig from "../../../../../deno.js";
9
9
  import { rendererLogger as logger } from "../../../../utils/index.js";
10
10
  import { IMPORT_RESOLUTION_ERROR } from "../../../../errors/index.js";
11
- import { replaceSpecifiers } from "../../../esm/lexer.js";
11
+ import { parseImports, replaceSpecifiers } from "../../../esm/lexer.js";
12
12
  import { hashCodeHex } from "../../../../utils/hash-utils.js";
13
13
  import { LRUCache } from "../../../../utils/lru-wrapper.js";
14
14
  import { getHttpBundleCacheDir, getMdxEsmCacheDir } from "../../../../utils/cache-dir.js";
@@ -187,7 +187,7 @@ async function rewriteFallbackRelativeImports(code, sourcePath, ctx, visited = n
187
187
  visited.add(sourcePath);
188
188
  // Note: we do not early-return when there are no relative imports, because
189
189
  // react/react-dom specifiers still need rewriting below.
190
- const relativeImports = findRelativeImports(code);
190
+ const relativeImports = await findRelativeImports(code);
191
191
  // Built once and reused for both the relative-import loop (React re-export
192
192
  // rewriting) and the final specifier pass below.
193
193
  const reactImportMap = getReactImportMap(ctx.reactVersion);
@@ -312,8 +312,11 @@ export async function transformFrameworkCode(content, sourcePath, ctx, throwOnMi
312
312
  let transformed = result.code;
313
313
  // Collect and recursively resolve all #veryfront/ imports
314
314
  const veryfrontReplacements = new Map();
315
- for (const match of transformed.matchAll(/from\s+["'](#veryfront\/[^"']+)["']/g)) {
316
- const specifier = match[1];
315
+ const transformedImports = await parseImports(transformed);
316
+ for (const importSpecifier of transformedImports) {
317
+ const specifier = importSpecifier.n;
318
+ if (!specifier?.startsWith("#veryfront/"))
319
+ continue;
317
320
  if (veryfrontReplacements.has(specifier))
318
321
  continue;
319
322
  const resolved = await resolveAndTransformVeryfrontImport(specifier, ctx);
@@ -344,7 +347,7 @@ export async function transformFrameworkCode(content, sourcePath, ctx, throwOnMi
344
347
  const frameworkSrcDir = join(FRAMEWORK_ROOT, "src") + "/";
345
348
  const embeddedSrcDirPrefix = EMBEDDED_SRC_DIR + "/";
346
349
  {
347
- const relativeImports = findRelativeImports(transformed);
350
+ const relativeImports = await findRelativeImports(transformed);
348
351
  for (const specifier of relativeImports) {
349
352
  // Skip non-code imports (like deno.json, package.json, etc.)
350
353
  if (/\.(json|css|svg|png|jpg|jpeg|gif|ico|woff2?|ttf|eot)$/.test(specifier)) {
@@ -1,3 +1,3 @@
1
1
  /** Shared version value. */
2
- export declare const VERSION = "0.1.827";
2
+ export declare const VERSION = "0.1.828";
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.827";
4
+ export const VERSION = "0.1.828";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "veryfront",
3
- "version": "0.1.827",
3
+ "version": "0.1.828",
4
4
  "description": "The simplest way to build AI-powered apps",
5
5
  "keywords": [
6
6
  "react",