veryfront 0.1.95 → 0.1.96

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 (53) hide show
  1. package/esm/deno.js +1 -1
  2. package/esm/src/html/schemas/html.schema.d.ts +2 -2
  3. package/esm/src/modules/react-loader/ssr-module-loader/loader.d.ts.map +1 -1
  4. package/esm/src/modules/react-loader/ssr-module-loader/loader.js +32 -1
  5. package/esm/src/modules/react-loader/ssr-module-loader/ssr-cache-manager.d.ts.map +1 -1
  6. package/esm/src/modules/react-loader/ssr-module-loader/ssr-cache-manager.js +31 -2
  7. package/esm/src/modules/react-loader/ssr-module-loader/vf-module-resolver.d.ts.map +1 -1
  8. package/esm/src/modules/react-loader/ssr-module-loader/vf-module-resolver.js +1 -0
  9. package/esm/src/rendering/orchestrator/module-loader/index.d.ts.map +1 -1
  10. package/esm/src/rendering/orchestrator/module-loader/index.js +6 -1
  11. package/esm/src/transforms/mdx/esm-module-loader/cache/index.d.ts +5 -1
  12. package/esm/src/transforms/mdx/esm-module-loader/cache/index.d.ts.map +1 -1
  13. package/esm/src/transforms/mdx/esm-module-loader/cache/index.js +18 -2
  14. package/esm/src/transforms/mdx/esm-module-loader/cache-format.d.ts +2 -1
  15. package/esm/src/transforms/mdx/esm-module-loader/cache-format.d.ts.map +1 -1
  16. package/esm/src/transforms/mdx/esm-module-loader/cache-format.js +12 -5
  17. package/esm/src/transforms/mdx/esm-module-loader/loader-helpers.d.ts.map +1 -1
  18. package/esm/src/transforms/mdx/esm-module-loader/loader-helpers.js +1 -0
  19. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/cache-keys.d.ts +1 -1
  20. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/cache-keys.d.ts.map +1 -1
  21. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/cache-keys.js +2 -2
  22. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/dependency-recovery.d.ts +23 -0
  23. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/dependency-recovery.d.ts.map +1 -0
  24. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/dependency-recovery.js +112 -0
  25. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/distributed-cache.d.ts +2 -2
  26. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/distributed-cache.d.ts.map +1 -1
  27. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/distributed-cache.js +33 -4
  28. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/framework-validator.d.ts +6 -1
  29. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/framework-validator.d.ts.map +1 -1
  30. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/framework-validator.js +31 -1
  31. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/index.d.ts +1 -0
  32. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/index.d.ts.map +1 -1
  33. package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/index.js +15 -6
  34. package/esm/src/transforms/mdx/esm-module-loader/types.d.ts +1 -0
  35. package/esm/src/transforms/mdx/esm-module-loader/types.d.ts.map +1 -1
  36. package/esm/src/utils/version.d.ts +1 -1
  37. package/esm/src/utils/version.js +1 -1
  38. package/package.json +1 -1
  39. package/src/deno.js +1 -1
  40. package/src/src/modules/react-loader/ssr-module-loader/loader.ts +34 -0
  41. package/src/src/modules/react-loader/ssr-module-loader/ssr-cache-manager.ts +34 -2
  42. package/src/src/modules/react-loader/ssr-module-loader/vf-module-resolver.ts +1 -0
  43. package/src/src/rendering/orchestrator/module-loader/index.ts +12 -1
  44. package/src/src/transforms/mdx/esm-module-loader/cache/index.ts +18 -1
  45. package/src/src/transforms/mdx/esm-module-loader/cache-format.ts +33 -1
  46. package/src/src/transforms/mdx/esm-module-loader/loader-helpers.ts +1 -0
  47. package/src/src/transforms/mdx/esm-module-loader/module-fetcher/cache-keys.ts +2 -1
  48. package/src/src/transforms/mdx/esm-module-loader/module-fetcher/dependency-recovery.ts +173 -0
  49. package/src/src/transforms/mdx/esm-module-loader/module-fetcher/distributed-cache.ts +43 -3
  50. package/src/src/transforms/mdx/esm-module-loader/module-fetcher/framework-validator.ts +37 -0
  51. package/src/src/transforms/mdx/esm-module-loader/module-fetcher/index.ts +26 -11
  52. package/src/src/transforms/mdx/esm-module-loader/types.ts +1 -0
  53. package/src/src/utils/version.ts +1 -1
package/esm/deno.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default {
2
2
  "name": "veryfront",
3
- "version": "0.1.95",
3
+ "version": "0.1.96",
4
4
  "license": "Apache-2.0",
5
5
  "nodeModulesDir": "auto",
6
6
  "exclude": [
@@ -64,6 +64,7 @@ export declare const HTMLGenerationOptionsSchema: z.ZodObject<{
64
64
  id: string;
65
65
  }[] | undefined;
66
66
  frontmatter?: Record<string, unknown> | undefined;
67
+ isLocalProject?: boolean | undefined;
67
68
  nestedLayouts?: {
68
69
  kind: string;
69
70
  path?: string | undefined;
@@ -82,7 +83,6 @@ export declare const HTMLGenerationOptionsSchema: z.ZodObject<{
82
83
  colorSchemeFromParam?: boolean | undefined;
83
84
  colorSchemeFromHeader?: boolean | undefined;
84
85
  projectClasses?: Set<string> | undefined;
85
- isLocalProject?: boolean | undefined;
86
86
  noHmr?: boolean | undefined;
87
87
  }, {
88
88
  mode: "production" | "development";
@@ -97,6 +97,7 @@ export declare const HTMLGenerationOptionsSchema: z.ZodObject<{
97
97
  id: string;
98
98
  }[] | undefined;
99
99
  frontmatter?: Record<string, unknown> | undefined;
100
+ isLocalProject?: boolean | undefined;
100
101
  nestedLayouts?: {
101
102
  kind: string;
102
103
  path?: string | undefined;
@@ -115,7 +116,6 @@ export declare const HTMLGenerationOptionsSchema: z.ZodObject<{
115
116
  colorSchemeFromParam?: boolean | undefined;
116
117
  colorSchemeFromHeader?: boolean | undefined;
117
118
  projectClasses?: Set<string> | undefined;
118
- isLocalProject?: boolean | undefined;
119
119
  noHmr?: boolean | undefined;
120
120
  }>;
121
121
  export declare const HydrationDataSchema: z.ZodObject<{
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../../../src/src/modules/react-loader/ssr-module-loader/loader.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAiCpC,OAAO,KAAK,EAAoB,sBAAsB,EAAE,MAAM,YAAY,CAAC;AA0B3E;;;;;GAKG;AACH,qBAAa,eAAe;IAKd,OAAO,CAAC,OAAO;IAJ3B,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,cAAc,CAA2B;IACjD,OAAO,CAAC,YAAY,CAAyB;gBAEzB,OAAO,EAAE,sBAAsB;IAWnD,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,4BAA4B;YAetB,qBAAqB;YAuCrB,0BAA0B;IA2FxC,UAAU,CACR,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;YA+C1C,2BAA2B;IAYzC,OAAO,CAAC,yBAAyB;YAiBnB,2BAA2B;CA0V1C"}
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../../../src/src/modules/react-loader/ssr-module-loader/loader.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,KAAK,KAAK,MAAM,OAAO,CAAC;AAiCpC,OAAO,KAAK,EAAoB,sBAAsB,EAAE,MAAM,YAAY,CAAC;AA2B3E;;;;;GAKG;AACH,qBAAa,eAAe;IAKd,OAAO,CAAC,OAAO;IAJ3B,OAAO,CAAC,KAAK,CAAkB;IAC/B,OAAO,CAAC,cAAc,CAA2B;IACjD,OAAO,CAAC,YAAY,CAAyB;gBAEzB,OAAO,EAAE,sBAAsB;IAWnD,OAAO,CAAC,mBAAmB;IAY3B,OAAO,CAAC,4BAA4B;YAetB,qBAAqB;YAuCrB,0BAA0B;IAwHxC,UAAU,CACR,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;YA+C1C,2BAA2B;IAYzC,OAAO,CAAC,yBAAyB;YAiBnB,2BAA2B;CA8V1C"}
@@ -32,6 +32,7 @@ import { preflightLocalImports } from "./preflight-imports.js";
32
32
  import { resolveVfModuleImports } from "./vf-module-resolver.js";
33
33
  import { registerCSSImport } from "../css-import-collector.js";
34
34
  import { injectNodePositions } from "../../../transforms/plugins/babel-node-positions.js";
35
+ import { ensureMdxModuleDependencies } from "../../../transforms/mdx/esm-module-loader/module-fetcher/dependency-recovery.js";
35
36
  const logger = rendererLogger.component("ssr-module-loader");
36
37
  const MISSING_HTTP_BUNDLE_PATTERN = /veryfront-http-bundle\/http-([a-f0-9]+)\.mjs/;
37
38
  /**
@@ -145,6 +146,33 @@ export class SSRModuleLoader {
145
146
  throw importError;
146
147
  }
147
148
  if (classifiedError.type === "module-not-found") {
149
+ if (this.options.contentSourceId) {
150
+ try {
151
+ const cachedCode = await this.cache.getFs().readTextFile(cacheEntry.tempPath);
152
+ const recovered = await ensureMdxModuleDependencies(cachedCode, {
153
+ projectId: this.options.projectId,
154
+ contentSourceId: this.options.contentSourceId,
155
+ log: logger,
156
+ });
157
+ if (recovered.missing.length === 0 && recovered.recovered.length > 0) {
158
+ const retryTempPath = cacheEntry.tempPath.replace(/\.mjs$/, "") +
159
+ `-recovered-${cacheEntry.contentHash}.mjs`;
160
+ await this.cache.getFs().writeTextFile(retryTempPath, cachedCode);
161
+ logger.info("Recovered vfmod dependencies for cached SSR module, retrying import", {
162
+ file: filePath.slice(-40),
163
+ recovered: recovered.recovered.slice(0, 5),
164
+ retryTempPath,
165
+ });
166
+ return (await import(`file://${retryTempPath}?v=${cacheEntry.contentHash}&retry=1`));
167
+ }
168
+ }
169
+ catch (recoveryError) {
170
+ logger.debug("Failed to recover vfmod dependencies for cached SSR module", {
171
+ file: filePath.slice(-40),
172
+ error: recoveryError instanceof Error ? recoveryError.message : String(recoveryError),
173
+ });
174
+ }
175
+ }
148
176
  logger.error("[SSR-MODULE-LOADER] Cached module has missing dependency, invalidating cache", {
149
177
  file: filePath.slice(-40),
150
178
  tempPath: cacheEntry.tempPath,
@@ -267,7 +295,10 @@ export class SSRModuleLoader {
267
295
  const projectKey = hashCodeHex(this.options.projectId);
268
296
  const sourceKey = this.options.contentSourceId;
269
297
  const mdxCacheDir = join(baseCacheDir, projectKey, sourceKey);
270
- const mdxCacheResult = await lookupMdxEsmCache(filePath, mdxCacheDir, this.options.projectDir, contentHash);
298
+ const mdxCacheResult = await lookupMdxEsmCache(filePath, mdxCacheDir, this.options.projectDir, contentHash, {
299
+ projectId: this.options.projectId,
300
+ contentSourceId: this.options.contentSourceId,
301
+ });
271
302
  if (mdxCacheResult.status === "hit") {
272
303
  const entry = { tempPath: mdxCacheResult.path, contentHash };
273
304
  globalModuleCache.set(contentCacheKey, entry);
@@ -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;AAU3E;;;;;;;GAOG;AACH,qBAAa,eAAe;IAId,OAAO,CAAC,OAAO;IAH3B,OAAO,CAAC,EAAE,CAAsB;IAChC,OAAO,CAAC,gBAAgB,CAAqB;gBAEzB,OAAO,EAAE,sBAAsB;IAEnD,4DAA4D;IAC5D,aAAa,IAAI,MAAM;IAUvB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAkB/B,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAiBlD,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAK1E,yBAAyB,IAAI,OAAO;IAoB9B,kBAAkB,CACtB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,cAAc,GAAG,aAAa,EACtC,OAAO,EAAE;QAAE,eAAe,EAAE,OAAO,CAAC;QAAC,qBAAqB,EAAE,OAAO,CAAA;KAAE,GACpE,OAAO,CAAC,OAAO,CAAC;IAgCb,wBAAwB,CAC5B,WAAW,EAAE,gBAAgB,EAC7B,eAAe,EAAE,MAAM,EACvB,gBAAgB,EAAE,MAAM,EACxB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,CAAC;IAuBnB,4BAA4B,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,gBAAgB,GAAG,IAAI;IAOnF,oCAAoC,CAClC,eAAe,EAAE,MAAM,EACvB,gBAAgB,EAAE,MAAM,EACxB,UAAU,CAAC,EAAE,gBAAgB,GAC5B,IAAI;IAQP,wDAAwD;IACxD,KAAK,IAAI,UAAU,CAAC,OAAO,gBAAgB,CAAC;IAI5C,OAAO,CAAC,4BAA4B;YAItB,qBAAqB;YAsBrB,oBAAoB;YAqBpB,YAAY;CA2B3B"}
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;gBAEzB,OAAO,EAAE,sBAAsB;IAEnD,4DAA4D;IAC5D,aAAa,IAAI,MAAM;IAUvB,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAkB/B,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAiBlD,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAK1E,yBAAyB,IAAI,OAAO;IAoB9B,kBAAkB,CACtB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,cAAc,GAAG,aAAa,EACtC,OAAO,EAAE;QAAE,eAAe,EAAE,OAAO,CAAC;QAAC,qBAAqB,EAAE,OAAO,CAAA;KAAE,GACpE,OAAO,CAAC,OAAO,CAAC;IAgCb,wBAAwB,CAC5B,WAAW,EAAE,gBAAgB,EAC7B,eAAe,EAAE,MAAM,EACvB,gBAAgB,EAAE,MAAM,EACxB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,OAAO,CAAC;IAuBnB,4BAA4B,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,gBAAgB,GAAG,IAAI;IAOnF,oCAAoC,CAClC,eAAe,EAAE,MAAM,EACvB,gBAAgB,EAAE,MAAM,EACxB,UAAU,CAAC,EAAE,gBAAgB,GAC5B,IAAI;IAQP,wDAAwD;IACxD,KAAK,IAAI,UAAU,CAAC,OAAO,gBAAgB,CAAC;IAI5C,OAAO,CAAC,4BAA4B;YAItB,qBAAqB;YAsBrB,oBAAoB;YAoDpB,YAAY;CA2B3B"}
@@ -19,6 +19,7 @@ import { getHttpBundleCacheDir, getMdxEsmCacheDir } from "../../../utils/cache-d
19
19
  import { globalModuleCache, globalTmpDirs } from "./cache/index.js";
20
20
  import { extractAllFilePaths, extractHttpBundlePaths, verifiedHttpBundlePaths, } from "./http-bundle-helpers.js";
21
21
  import { buildTempModulePath, buildTmpDirPath, getTmpDirCacheKey } from "./tmp-paths.js";
22
+ import { ensureMdxModuleDependencies } from "../../../transforms/mdx/esm-module-loader/module-fetcher/dependency-recovery.js";
22
23
  const logger = rendererLogger.component("ssr-module-loader");
23
24
  /** Content length threshold: below this, use fast sync hash; above, use async SHA-256 */
24
25
  const SYNC_HASH_THRESHOLD = 10_000;
@@ -122,7 +123,7 @@ export class SSRCacheManager {
122
123
  try {
123
124
  const cachedCode = await this.fs.readTextFile(cachedEntry.tempPath);
124
125
  const isValid = await this.validateCachedCode(cachedCode, filePath, "memory-cache", {
125
- checkLocalPaths: false,
126
+ checkLocalPaths: true,
126
127
  checkInvalidEsmShPath: false,
127
128
  });
128
129
  if (!isValid) {
@@ -177,11 +178,13 @@ export class SSRCacheManager {
177
178
  }
178
179
  async hasMissingLocalPaths(code, filePath) {
179
180
  const allPaths = extractAllFilePaths(code);
181
+ let hasMissingPath = false;
180
182
  for (const path of allPaths) {
181
183
  try {
182
184
  const stat = await this.fs.stat(path);
183
185
  if (!stat.isFile) {
184
- return true;
186
+ hasMissingPath = true;
187
+ break;
185
188
  }
186
189
  }
187
190
  catch (error) {
@@ -190,6 +193,32 @@ export class SSRCacheManager {
190
193
  missingPath: path.slice(-60),
191
194
  error,
192
195
  });
196
+ hasMissingPath = true;
197
+ break;
198
+ }
199
+ }
200
+ if (hasMissingPath &&
201
+ this.options.projectId &&
202
+ this.options.contentSourceId) {
203
+ const recovered = await ensureMdxModuleDependencies(code, {
204
+ projectId: this.options.projectId,
205
+ contentSourceId: this.options.contentSourceId,
206
+ log: logger,
207
+ });
208
+ if (recovered.recovered.length > 0) {
209
+ logger.debug("Recovered missing local vfmod dependencies for SSR cache entry", {
210
+ file: filePath.slice(-40),
211
+ recovered: recovered.recovered.slice(0, 5),
212
+ });
213
+ }
214
+ }
215
+ for (const path of allPaths) {
216
+ try {
217
+ const stat = await this.fs.stat(path);
218
+ if (!stat.isFile)
219
+ return true;
220
+ }
221
+ catch (_) {
193
222
  return true;
194
223
  }
195
224
  }
@@ -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,CAuDjB"}
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"}
@@ -44,6 +44,7 @@ export async function resolveVfModuleImports(code, options) {
44
44
  const projectKey = hashCodeHex(options.projectId);
45
45
  const esmCacheDir = join(baseCacheDir, projectKey, options.contentSourceId);
46
46
  const fetcherContext = createModuleFetcherContext(esmCacheDir, options.adapter, options.projectDir, options.projectId, {
47
+ contentSourceId: options.contentSourceId,
47
48
  reactVersion: options.reactVersion,
48
49
  projectSlug: options.projectId,
49
50
  strictMissingModules: false,
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/src/rendering/orchestrator/module-loader/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AA2BzE,OAAO,EAAE,cAAc,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC7E,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAkJpE,wBAAsB,uBAAuB,CAC3C,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,cAAc,EAC5B,MAAM,EAAE,kBAAkB,EAC1B,eAAe,UAAQ,GACtB,OAAO,CAAC,MAAM,CAAC,CA4RjB;AAED,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,OAAO,EAAE,cAAc,CAAC;IACxB,IAAI,EAAE,aAAa,GAAG,YAAY,CAAC;IACnC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,QAAQ,EAA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OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAqClC"}
@@ -162,7 +162,12 @@ export async function transformModuleWithDeps(filePath, tmpDir, localAdapter, co
162
162
  const projectKey = encodeURIComponent(projectId);
163
163
  const sourceKey = encodeURIComponent(contentSourceId);
164
164
  const mdxCacheDir = join(baseCacheDir, projectKey, sourceKey);
165
- const mdxCacheResult = await lookupMdxEsmCache(filePath, mdxCacheDir, projectDir);
165
+ const mdxCacheResult = await lookupMdxEsmCache(filePath, mdxCacheDir, projectDir, undefined, contentSourceId
166
+ ? {
167
+ projectId,
168
+ contentSourceId,
169
+ }
170
+ : undefined);
166
171
  if (mdxCacheResult.status === "hit") {
167
172
  moduleCache.set(cacheKey, mdxCacheResult.path);
168
173
  return mdxCacheResult.path;
@@ -32,5 +32,9 @@ export declare function clearHttpBundleCache(): Promise<void>;
32
32
  * Call this on server startup to prevent stale module issues.
33
33
  */
34
34
  export declare function clearAllLocalCaches(): Promise<void>;
35
- export declare function lookupMdxEsmCache(filePath: string, cacheDir: string, projectDir?: string, _contentHash?: string): Promise<CacheLookupResult>;
35
+ export declare function lookupMdxEsmCache(filePath: string, cacheDir: string, projectDir?: string, _contentHash?: string, // Intentionally unused - kept for API compatibility
36
+ recoveryOptions?: {
37
+ projectId: string;
38
+ contentSourceId: string;
39
+ }): Promise<CacheLookupResult>;
36
40
  //# sourceMappingURL=index.d.ts.map
@@ -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;AASH,OAAO,EAEL,KAAK,UAAU,EAEhB,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAG5D,MAAM,MAAM,iBAAiB,GACzB;IAAE,MAAM,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC/B;IAAE,MA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REFIX_MDX_LOADER } from "../constants.js";
13
13
  import { LRUCache } from "../../../../utils/lru-wrapper.js";
14
14
  import { buildMdxEsmPathCacheKey, MDX_ESM_ALL_FILE_URL_PATTERN_SOURCE } from "../cache-format.js";
15
+ import { ensureMdxModuleDependencies } from "../module-fetcher/dependency-recovery.js";
15
16
  const MAX_VERIFIED_MODULE_DEPS = 2_000;
16
17
  export const verifiedModuleDeps = new LRUCache({
17
18
  maxEntries: MAX_VERIFIED_MODULE_DEPS,
@@ -285,7 +286,8 @@ function toMdxEsmCacheKey(filePath, projectDir) {
285
286
  const jsPath = relativePath.replace(/\.(tsx?|jsx|mdx)$/, ".js");
286
287
  return buildMdxEsmPathCacheKey(`_vf_modules/${jsPath}`);
287
288
  }
288
- export async function lookupMdxEsmCache(filePath, cacheDir, projectDir, _contentHash) {
289
+ export async function lookupMdxEsmCache(filePath, cacheDir, projectDir, _contentHash, // Intentionally unused - kept for API compatibility
290
+ recoveryOptions) {
289
291
  const cache = await getModulePathCache(cacheDir);
290
292
  const cacheKey = toMdxEsmCacheKey(filePath, projectDir);
291
293
  const cachedPath = cache.get(cacheKey);
@@ -339,7 +341,21 @@ export async function lookupMdxEsmCache(filePath, cacheDir, projectDir, _content
339
341
  // CRITICAL: Check that all file:// dependencies actually exist on disk.
340
342
  // The distributed cache may contain code referencing file:// paths from other pods
341
343
  // that don't exist locally (e.g., HTTP bundles, MDX-ESM modules).
342
- const missingDeps = await findMissingFileDependencies(cachedCode);
344
+ let missingDeps = await findMissingFileDependencies(cachedCode);
345
+ if (missingDeps.length > 0 && recoveryOptions) {
346
+ const recovered = await ensureMdxModuleDependencies(cachedCode, {
347
+ ...recoveryOptions,
348
+ log: logger,
349
+ });
350
+ if (recovered.recovered.length > 0) {
351
+ logger.debug(`${LOG_PREFIX_MDX_LOADER} Recovered cached MDX-ESM dependencies`, {
352
+ filePath,
353
+ cachedPath,
354
+ recovered: recovered.recovered.slice(0, 5),
355
+ });
356
+ }
357
+ missingDeps = await findMissingFileDependencies(cachedCode);
358
+ }
343
359
  if (missingDeps.length > 0) {
344
360
  logger.warn(`${LOG_PREFIX_MDX_LOADER} Cached module has ${missingDeps.length} missing file dependencies, invalidating`, { filePath, cachedPath, missingDeps: missingDeps.slice(0, 5) });
345
361
  cache.delete(cacheKey);
@@ -2,9 +2,10 @@ export declare const MDX_ESM_ALL_FILE_URL_PATTERN_SOURCE: string;
2
2
  export declare const MDX_ESM_MJS_FILE_URL_PATTERN_SOURCE: string;
3
3
  export declare const MDX_ESM_CACHE_NAMESPACE: string;
4
4
  export declare const FRAMEWORK_VF_MODULE_CACHE_NAMESPACE: string;
5
- export declare function buildMdxEsmTransformCacheKey(projectId: string, normalizedPath: string, contentHash: string): string;
5
+ export declare function buildMdxEsmTransformCacheKey(projectId: string, contentSourceId: string, normalizedPath: string, contentHash: string): string;
6
6
  export declare function buildMdxEsmPathCacheKey(normalizedPath: string): string;
7
7
  export declare function buildMdxEsmModuleFileName(contentHash: string): string;
8
+ export declare function buildMdxEsmModuleRecoveryCacheKey(projectId: string, contentSourceId: string, fileName: string): string;
8
9
  export declare function buildMdxJsxCacheFileName(filePath: string): string;
9
10
  export declare function buildFrameworkVfModuleCacheFileName(pathHash: string, envKey: string, contentHash: string): string;
10
11
  //# sourceMappingURL=cache-format.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cache-format.d.ts","sourceRoot":"","sources":["../../../../../src/src/transforms/mdx/esm-module-loader/cache-format.ts"],"names":[],"mappings":"AAuEA,eAAO,MAAM,mCAAmC,QAA8B,CAAC;AAC/E,eAAO,MAAM,mCAAmC,QAA8B,CAAC;AAE/E,eAAO,MAAM,uBAAuB,QAGnC,CAAC;AAEF,eAAO,MAAM,mCAAmC,QAG/C,CAAC;AAEF,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,GAClB,MAAM,CAOR;AAED,wBAAgB,uBAAuB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAClB,MAAM,CAOR"}
1
+ {"version":3,"file":"cache-format.d.ts","sourceRoot":"","sources":["../../../../../src/src/transforms/mdx/esm-module-loader/cache-format.ts"],"names":[],"mappings":"AAwFA,eAAO,MAAM,mCAAmC,QAA8B,CAAC;AAC/E,eAAO,MAAM,mCAAmC,QAA8B,CAAC;AAE/E,eAAO,MAAM,uBAAuB,QAGnC,CAAC;AAEF,eAAO,MAAM,mCAAmC,QAG/C,CAAC;AAEF,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,GAClB,MAAM,CAQR;AAED,wBAAgB,uBAAuB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAEtE;AAED,wBAAgB,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,wBAAgB,iCAAiC,CAC/C,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,QAAQ,EAAE,MAAM,GACf,MAAM,CAOR;AAED,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED,wBAAgB,mCAAmC,CACjD,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAClB,MAAM,CAOR"}
@@ -5,8 +5,8 @@ import { hashString } from "./utils/hash.js";
5
5
  const ALL_FILE_URL_PATTERN_SOURCE = /file:\/\/([^"'\s]+)/.source;
6
6
  const MJS_FILE_URL_PATTERN_SOURCE = /file:\/\/([^"'\s]+\.mjs)/.source;
7
7
  const CACHE_NAMESPACE_SENTINEL = "__vf_cache_namespace__";
8
- function formatMdxEsmTransformCacheKey(namespace, projectId, normalizedPath, contentHash) {
9
- return `${namespace}:${projectId}:${normalizedPath}:${contentHash}:ssr`;
8
+ function formatMdxEsmTransformCacheKey(namespace, projectId, contentSourceId, normalizedPath, contentHash) {
9
+ return `${namespace}:${projectId}:${contentSourceId}:${normalizedPath}:${contentHash}:ssr`;
10
10
  }
11
11
  function formatMdxEsmPathCacheKey(namespace, normalizedPath) {
12
12
  return `${namespace}:${normalizedPath}`;
@@ -14,6 +14,9 @@ function formatMdxEsmPathCacheKey(namespace, normalizedPath) {
14
14
  function formatMdxEsmModuleFileName(namespace, contentHash) {
15
15
  return `vfmod-${namespace}-${contentHash}.mjs`;
16
16
  }
17
+ function formatMdxEsmModuleRecoveryCacheKey(namespace, projectId, contentSourceId, fileName) {
18
+ return `${namespace}:${projectId}:${contentSourceId}:${fileName}:vfmod`;
19
+ }
17
20
  function formatMdxJsxCacheFileName(namespace, filePath) {
18
21
  return `jsx-${namespace}-${hashString(filePath)}.mjs`;
19
22
  }
@@ -22,9 +25,10 @@ function formatFrameworkVfModuleCacheFileName(namespace, pathHash, envKey, conte
22
25
  }
23
26
  function buildMdxEsmCacheSchemaSample() {
24
27
  return {
25
- transformKey: formatMdxEsmTransformCacheKey(CACHE_NAMESPACE_SENTINEL, "__vf_project__", "_vf_modules/pages/index.js", "deadbeef"),
28
+ transformKey: formatMdxEsmTransformCacheKey(CACHE_NAMESPACE_SENTINEL, "__vf_project__", "preview-main", "_vf_modules/pages/index.js", "deadbeef"),
26
29
  pathKey: formatMdxEsmPathCacheKey(CACHE_NAMESPACE_SENTINEL, "_vf_modules/pages/index.js"),
27
30
  moduleFile: formatMdxEsmModuleFileName(CACHE_NAMESPACE_SENTINEL, "deadbeef"),
31
+ moduleRecoveryKey: formatMdxEsmModuleRecoveryCacheKey(CACHE_NAMESPACE_SENTINEL, "__vf_project__", "preview-main", formatMdxEsmModuleFileName(CACHE_NAMESPACE_SENTINEL, "deadbeef")),
28
32
  jsxFile: formatMdxJsxCacheFileName(CACHE_NAMESPACE_SENTINEL, "/tmp/project/Button.tsx"),
29
33
  unresolvedVfModulesPattern: UNRESOLVED_VF_MODULES_PATTERN.source,
30
34
  allFileUrlPattern: ALL_FILE_URL_PATTERN_SOURCE,
@@ -44,8 +48,8 @@ export const MDX_ESM_ALL_FILE_URL_PATTERN_SOURCE = ALL_FILE_URL_PATTERN_SOURCE;
44
48
  export const MDX_ESM_MJS_FILE_URL_PATTERN_SOURCE = MJS_FILE_URL_PATTERN_SOURCE;
45
49
  export const MDX_ESM_CACHE_NAMESPACE = createCacheNamespace("mdx-esm", buildMdxEsmCacheSchemaSample());
46
50
  export const FRAMEWORK_VF_MODULE_CACHE_NAMESPACE = createCacheNamespace("vf-framework", buildFrameworkVfModuleCacheSchemaSample());
47
- export function buildMdxEsmTransformCacheKey(projectId, normalizedPath, contentHash) {
48
- return formatMdxEsmTransformCacheKey(MDX_ESM_CACHE_NAMESPACE, projectId, normalizedPath, contentHash);
51
+ export function buildMdxEsmTransformCacheKey(projectId, contentSourceId, normalizedPath, contentHash) {
52
+ return formatMdxEsmTransformCacheKey(MDX_ESM_CACHE_NAMESPACE, projectId, contentSourceId, normalizedPath, contentHash);
49
53
  }
50
54
  export function buildMdxEsmPathCacheKey(normalizedPath) {
51
55
  return formatMdxEsmPathCacheKey(MDX_ESM_CACHE_NAMESPACE, normalizedPath);
@@ -53,6 +57,9 @@ export function buildMdxEsmPathCacheKey(normalizedPath) {
53
57
  export function buildMdxEsmModuleFileName(contentHash) {
54
58
  return formatMdxEsmModuleFileName(MDX_ESM_CACHE_NAMESPACE, contentHash);
55
59
  }
60
+ export function buildMdxEsmModuleRecoveryCacheKey(projectId, contentSourceId, fileName) {
61
+ return formatMdxEsmModuleRecoveryCacheKey(MDX_ESM_CACHE_NAMESPACE, projectId, contentSourceId, fileName);
62
+ }
56
63
  export function buildMdxJsxCacheFileName(filePath) {
57
64
  return formatMdxJsxCacheFileName(MDX_ESM_CACHE_NAMESPACE, filePath);
58
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"loader-helpers.d.ts","sourceRoot":"","sources":["../../../../../src/src/transforms/mdx/esm-module-loader/loader-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAcH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;GAGG;AACH,wBAAsB,2BAA2B,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAapF;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAWnE;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAgCnF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAW3F;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,KAAK,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EAClD,OAAO,EAAE,gBAAgB,EACzB,UAAU,EAAE,MAAM,EAClB,oBAAoB,EAAE,OAAO,GAC5B,OAAO,CAAC,MAAM,CAAC,CAuGjB"}
1
+ {"version":3,"file":"loader-helpers.d.ts","sourceRoot":"","sources":["../../../../../src/src/transforms/mdx/esm-module-loader/loader-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAcH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;GAGG;AACH,wBAAsB,2BAA2B,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAapF;AAED,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAWnE;AAED;;;GAGG;AACH,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAgCnF;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAW3F;AAED;;GAEG;AACH,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,KAAK,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EAClD,OAAO,EAAE,gBAAgB,EACzB,UAAU,EAAE,MAAM,EAClB,oBAAoB,EAAE,OAAO,GAC5B,OAAO,CAAC,MAAM,CAAC,CAwGjB"}
@@ -126,6 +126,7 @@ export async function processVfModuleImports(code, imports, context, projectDir,
126
126
  });
127
127
  }
128
128
  const fetcherContext = createModuleFetcherContext(context.esmCacheDir, adapter, projectDir, context.projectId, {
129
+ contentSourceId: context.contentSourceId,
129
130
  reactVersion: context.reactVersion,
130
131
  projectSlug: context.projectSlug,
131
132
  logger: logger.child({
@@ -10,6 +10,6 @@
10
10
  * CRITICAL: The :ssr suffix is required to avoid cache collisions with browser-mode transforms
11
11
  * that use relative paths (../lib/utils.js) instead of absolute paths (/_vf_modules/lib/utils.js).
12
12
  */
13
- export declare function getTransformCacheKey(projectId: string, normalizedPath: string, contentHash: string): string;
13
+ export declare function getTransformCacheKey(projectId: string, contentSourceId: string, normalizedPath: string, contentHash: string): string;
14
14
  export declare function getVersionedPathCacheKey(normalizedPath: string): string;
15
15
  //# sourceMappingURL=cache-keys.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cache-keys.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/cache-keys.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,GAClB,MAAM,CAER;AAED,wBAAgB,wBAAwB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAEvE"}
1
+ {"version":3,"file":"cache-keys.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/cache-keys.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,GAClB,MAAM,CAER;AAED,wBAAgB,wBAAwB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAEvE"}
@@ -11,8 +11,8 @@ import { buildMdxEsmPathCacheKey, buildMdxEsmTransformCacheKey } from "../cache-
11
11
  * CRITICAL: The :ssr suffix is required to avoid cache collisions with browser-mode transforms
12
12
  * that use relative paths (../lib/utils.js) instead of absolute paths (/_vf_modules/lib/utils.js).
13
13
  */
14
- export function getTransformCacheKey(projectId, normalizedPath, contentHash) {
15
- return buildMdxEsmTransformCacheKey(projectId, normalizedPath, contentHash);
14
+ export function getTransformCacheKey(projectId, contentSourceId, normalizedPath, contentHash) {
15
+ return buildMdxEsmTransformCacheKey(projectId, contentSourceId, normalizedPath, contentHash);
16
16
  }
17
17
  export function getVersionedPathCacheKey(normalizedPath) {
18
18
  return buildMdxEsmPathCacheKey(normalizedPath);
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Distributed recovery for missing MDX ESM module dependencies.
3
+ *
4
+ * Restores missing vfmod files on fresh pods from the distributed transform
5
+ * cache, scoped to the current project and content source.
6
+ *
7
+ * @module transforms/mdx/esm-module-loader/module-fetcher/dependency-recovery
8
+ */
9
+ import type { CacheBackend } from "../../../../cache/types.js";
10
+ import type { Logger } from "../../../../utils/logger/logger.js";
11
+ interface EnsureMdxModuleDependenciesOptions {
12
+ projectId: string;
13
+ contentSourceId: string;
14
+ log: Logger;
15
+ distributedCache?: CacheBackend | null;
16
+ }
17
+ interface EnsureMdxModuleDependenciesResult {
18
+ recovered: string[];
19
+ missing: string[];
20
+ }
21
+ export declare function ensureMdxModuleDependencies(code: string, options: EnsureMdxModuleDependenciesOptions): Promise<EnsureMdxModuleDependenciesResult>;
22
+ export {};
23
+ //# sourceMappingURL=dependency-recovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependency-recovery.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/dependency-recovery.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAWjE,UAAU,kCAAkC;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;CACxC;AAED,UAAU,iCAAiC;IACzC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAiHD,wBAAsB,2BAA2B,CAC/C,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,kCAAkC,GAC1C,OAAO,CAAC,iCAAiC,CAAC,CAuB5C"}
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Distributed recovery for missing MDX ESM module dependencies.
3
+ *
4
+ * Restores missing vfmod files on fresh pods from the distributed transform
5
+ * cache, scoped to the current project and content source.
6
+ *
7
+ * @module transforms/mdx/esm-module-loader/module-fetcher/dependency-recovery
8
+ */
9
+ import { basename, dirname } from "../../../../platform/compat/path/index.js";
10
+ import { detokenizeAllCachePaths } from "../../../../cache/index.js";
11
+ import { getDistributedTransformBackend } from "../../../esm/transform-cache.js";
12
+ import { ensureHttpBundlesExist } from "../../../esm/http-cache.js";
13
+ import { extractHttpBundlePaths } from "../../../../modules/react-loader/ssr-module-loader/http-bundle-helpers.js";
14
+ import { getHttpBundleCacheDir } from "../../../../utils/cache-dir.js";
15
+ import { LOG_PREFIX_MDX_LOADER } from "../constants.js";
16
+ import { getLocalFs } from "../cache/index.js";
17
+ import { buildMdxEsmModuleRecoveryCacheKey } from "../cache-format.js";
18
+ const MDX_VFMOD_FILE_URL_PATTERN = /file:\/\/([^"'\s]+veryfront-mdx-esm\/[^"'\s]+\.mjs)/gi;
19
+ function extractMdxModuleDependencyPaths(code) {
20
+ const paths = [];
21
+ const seen = new Set();
22
+ let match;
23
+ while ((match = MDX_VFMOD_FILE_URL_PATTERN.exec(code)) !== null) {
24
+ const rawPath = match[1];
25
+ if (!rawPath)
26
+ continue;
27
+ const cleanPath = rawPath.replace(/\?.*$/, "");
28
+ if (seen.has(cleanPath))
29
+ continue;
30
+ seen.add(cleanPath);
31
+ paths.push(cleanPath);
32
+ }
33
+ return paths;
34
+ }
35
+ async function ensureHttpBundleDependencies(code, log) {
36
+ const bundlePaths = extractHttpBundlePaths(code);
37
+ if (bundlePaths.length === 0)
38
+ return true;
39
+ const failed = await ensureHttpBundlesExist(bundlePaths, getHttpBundleCacheDir());
40
+ if (failed.length === 0)
41
+ return true;
42
+ log.warn(`${LOG_PREFIX_MDX_LOADER} Failed to recover HTTP bundles for vfmod dependency`, {
43
+ failed,
44
+ totalBundles: bundlePaths.length,
45
+ });
46
+ return false;
47
+ }
48
+ async function ensureModuleFileAndDeps(absolutePath, distributedCache, options, visited, recovered) {
49
+ if (visited.has(absolutePath))
50
+ return true;
51
+ visited.add(absolutePath);
52
+ const localFs = getLocalFs();
53
+ try {
54
+ const stat = await localFs.stat(absolutePath);
55
+ if (stat?.isFile) {
56
+ const existingCode = await localFs.readTextFile(absolutePath);
57
+ if (!(await ensureHttpBundleDependencies(existingCode, options.log)))
58
+ return false;
59
+ for (const nestedPath of extractMdxModuleDependencyPaths(existingCode)) {
60
+ if (!(await ensureModuleFileAndDeps(nestedPath, distributedCache, options, visited, recovered))) {
61
+ return false;
62
+ }
63
+ }
64
+ return true;
65
+ }
66
+ }
67
+ catch (_) {
68
+ /* expected: dependency may not exist on this pod yet */
69
+ }
70
+ const recoveryKey = buildMdxEsmModuleRecoveryCacheKey(options.projectId, options.contentSourceId, basename(absolutePath));
71
+ const portableCode = await distributedCache.get(recoveryKey);
72
+ if (!portableCode) {
73
+ options.log.debug(`${LOG_PREFIX_MDX_LOADER} No distributed vfmod recovery entry`, {
74
+ dependencyPath: absolutePath,
75
+ recoveryKey,
76
+ });
77
+ return false;
78
+ }
79
+ const recoveredCode = detokenizeAllCachePaths(portableCode);
80
+ if (!(await ensureHttpBundleDependencies(recoveredCode, options.log)))
81
+ return false;
82
+ for (const nestedPath of extractMdxModuleDependencyPaths(recoveredCode)) {
83
+ if (!(await ensureModuleFileAndDeps(nestedPath, distributedCache, options, visited, recovered))) {
84
+ return false;
85
+ }
86
+ }
87
+ await localFs.mkdir(dirname(absolutePath), { recursive: true });
88
+ await localFs.writeTextFile(absolutePath, recoveredCode);
89
+ recovered.add(absolutePath);
90
+ options.log.debug(`${LOG_PREFIX_MDX_LOADER} Recovered vfmod dependency from distributed cache`, {
91
+ dependencyPath: absolutePath,
92
+ recoveryKey,
93
+ });
94
+ return true;
95
+ }
96
+ export async function ensureMdxModuleDependencies(code, options) {
97
+ const distributedCache = options.distributedCache ?? (await getDistributedTransformBackend());
98
+ if (!distributedCache)
99
+ return { recovered: [], missing: extractMdxModuleDependencyPaths(code) };
100
+ const visited = new Set();
101
+ const recovered = new Set();
102
+ const missing = [];
103
+ for (const dependencyPath of extractMdxModuleDependencyPaths(code)) {
104
+ const ok = await ensureModuleFileAndDeps(dependencyPath, distributedCache, options, visited, recovered);
105
+ if (!ok)
106
+ missing.push(dependencyPath);
107
+ }
108
+ return {
109
+ recovered: [...recovered],
110
+ missing,
111
+ };
112
+ }
@@ -36,7 +36,7 @@ interface DistributedCacheReadResult {
36
36
  * Returns null only if no distributed cache backend is available.
37
37
  * Otherwise returns `{ code, distributedCache }` where `code` may be null (cache miss).
38
38
  */
39
- export declare function readDistributedCache(transformCacheKey: string, normalizedPath: string, projectSlug: string, projectDir: string, reactVersion: string | undefined, log: Logger): Promise<DistributedCacheReadResult | null>;
39
+ export declare function readDistributedCache(transformCacheKey: string, projectId: string, contentSourceId: string | undefined, normalizedPath: string, projectSlug: string, projectDir: string, reactVersion: string | undefined, log: Logger): Promise<DistributedCacheReadResult | null>;
40
40
  /**
41
41
  * Write a fully-resolved module to the distributed transform cache.
42
42
  *
@@ -45,6 +45,6 @@ export declare function readDistributedCache(transformCacheKey: string, normaliz
45
45
  *
46
46
  * This is fire-and-forget: errors are logged but do not propagate.
47
47
  */
48
- export declare function writeDistributedCache(distributedCache: DistributedCache, transformCacheKey: string, moduleCode: string, normalizedPath: string, log: Logger): void;
48
+ export declare function writeDistributedCache(distributedCache: DistributedCache, transformCacheKey: string, projectId: string, contentSourceId: string, moduleCode: string, normalizedPath: string, log: Logger): void;
49
49
  export {};
50
50
  //# sourceMappingURL=distributed-cache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"distributed-cache.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/distributed-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AASjE,OAAO,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AAWjF,qDAAqD;AACrD,KAAK,gBAAgB,GAAG,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,8BAA8B,CAAC,CAAC,CAAC,CAAC;AAEhG;;;;;GAKG;AACH,UAAU,0BAA0B;IAClC,4EAA4E;IAC5E,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,4DAA4D;IAC5D,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,oBAAoB,CACxC,iBAAiB,EAAE,MAAM,EACzB,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC,CAoG5C;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,gBAAgB,EAAE,gBAAgB,EAClC,iBAAiB,EAAE,MAAM,EACzB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EACtB,GAAG,EAAE,MAAM,GACV,IAAI,CAqCN"}
1
+ {"version":3,"file":"distributed-cache.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/distributed-cache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AASjE,OAAO,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AAcjF,qDAAqD;AACrD,KAAK,gBAAgB,GAAG,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,8BAA8B,CAAC,CAAC,CAAC,CAAC;AAEhG;;;;;GAKG;AACH,UAAU,0BAA0B;IAClC,4EAA4E;IAC5E,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,4DAA4D;IAC5D,gBAAgB,EAAE,gBAAgB,CAAC;CACpC;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,oBAAoB,CACxC,iBAAiB,EAAE,MAAM,EACzB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,GAAG,SAAS,EACnC,cAAc,EAAE,MAAM,EACtB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,GAAG,SAAS,EAChC,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,0BAA0B,GAAG,IAAI,CAAC,CAoH5C;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CACnC,gBAAgB,EAAE,gBAAgB,EAClC,iBAAiB,EAAE,MAAM,EACzB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,MAAM,EACvB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,MAAM,EACtB,GAAG,EAAE,MAAM,GACV,IAAI,CAsDN"}