veryfront 0.1.735 → 0.1.737
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm/deno.js +1 -1
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/index.d.ts.map +1 -1
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/index.js +22 -65
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/nested-imports.d.ts +14 -0
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/nested-imports.d.ts.map +1 -1
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/nested-imports.js +50 -1
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/path-cache-lookup.d.ts +24 -0
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/path-cache-lookup.d.ts.map +1 -0
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/path-cache-lookup.js +32 -0
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +1 -1
package/esm/deno.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAO5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAGH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAO5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAcxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAS9F;;GAEG;AACH,qBAAa,yBAA0B,SAAQ,KAAK;gBACtC,cAAc,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;CAOtD;AAED;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,KAAK;gBAC1C,SAAS,EAAE,MAAM;CAI9B;AAcD;;;GAGG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,oBAAoB,EAC7B,gBAAgB,CAAC,EAAE,MAAM,EACzB,OAAO,GAAE,GAAG,CAAC,MAAM,CAAa,GAC/B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAwFxB;AA2ND;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,cAAc,EACvB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE;IACR,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,GACA,oBAAoB,CAUtB"}
|
|
@@ -18,18 +18,17 @@ import { loadImportMap } from "../../../../modules/import-map/index.js";
|
|
|
18
18
|
import { getHttpBundleCacheDir } from "../../../../utils/cache-dir.js";
|
|
19
19
|
import { REACT_DEFAULT_VERSION } from "../../../../utils/constants/cdn.js";
|
|
20
20
|
import { LOG_PREFIX_MDX_LOADER } from "../constants.js";
|
|
21
|
-
import {
|
|
21
|
+
import { getModulePathCache } from "../cache/index.js";
|
|
22
22
|
import { hashString } from "../utils/hash.js";
|
|
23
23
|
import { resolveModuleFile } from "../resolution/file-finder.js";
|
|
24
24
|
import { buildMissingModuleError } from "../missing-module.js";
|
|
25
25
|
import { getTransformCacheKey, getVersionedPathCacheKey } from "./cache-keys.js";
|
|
26
26
|
import { rewriteDntImports, rewriteVeryfrontImports } from "./import-rewriter.js";
|
|
27
|
-
import {
|
|
28
|
-
import { validateCachedModule } from "./framework-validator.js";
|
|
29
|
-
import { recordModuleToSession } from "./render-sessions.js";
|
|
27
|
+
import { resolveNestedModuleImports } from "./nested-imports.js";
|
|
30
28
|
import { readDistributedCache, writeDistributedCache } from "./distributed-cache.js";
|
|
31
29
|
import { fetchModuleViaHTTP } from "./http-fetcher.js";
|
|
32
30
|
import { cacheModule, normalizePath } from "./module-cache.js";
|
|
31
|
+
import { readValidCachedModulePath } from "./path-cache-lookup.js";
|
|
33
32
|
// Re-export extracted modules for backward compatibility
|
|
34
33
|
export { rewriteDntImports } from "./import-rewriter.js";
|
|
35
34
|
export { endRenderSession, hasRenderSession, startRenderSession } from "./render-sessions.js";
|
|
@@ -153,28 +152,20 @@ async function doFetchAndCacheModule(normalizedPath, context, fetchAndCacheModul
|
|
|
153
152
|
const effectiveReactVersion = context.reactVersion ?? REACT_DEFAULT_VERSION;
|
|
154
153
|
const pathCache = await getModulePathCache(esmCacheDir);
|
|
155
154
|
const versionedKey = getVersionedPathCacheKey(normalizedPath, effectiveReactVersion);
|
|
156
|
-
const cachedPath =
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
contentSourceId: context.contentSourceId,
|
|
166
|
-
}
|
|
167
|
-
: undefined)) {
|
|
168
|
-
recordModuleToSession(normalizedPath);
|
|
169
|
-
return cachedPath;
|
|
170
|
-
}
|
|
155
|
+
const cachedPath = await readValidCachedModulePath({
|
|
156
|
+
normalizedPath,
|
|
157
|
+
pathCache,
|
|
158
|
+
versionedKey,
|
|
159
|
+
log,
|
|
160
|
+
recoveryOptions: context.contentSourceId
|
|
161
|
+
? {
|
|
162
|
+
projectId: context.projectId,
|
|
163
|
+
contentSourceId: context.contentSourceId,
|
|
171
164
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
}
|
|
177
|
-
}
|
|
165
|
+
: undefined,
|
|
166
|
+
});
|
|
167
|
+
if (cachedPath)
|
|
168
|
+
return cachedPath;
|
|
178
169
|
try {
|
|
179
170
|
const resolved = await resolveModuleFile(normalizedPath, adapter, projectDir);
|
|
180
171
|
if (!resolved) {
|
|
@@ -265,49 +256,15 @@ async function doFetchAndCacheModule(normalizedPath, context, fetchAndCacheModul
|
|
|
265
256
|
// This ensures we don't cache code with unresolved /_vf_modules/ paths.
|
|
266
257
|
needsDistributedCacheWrite = true;
|
|
267
258
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
259
|
+
moduleCode = await resolveNestedModuleImports({
|
|
260
|
+
moduleCode,
|
|
261
|
+
esmCacheDir,
|
|
271
262
|
normalizedPath,
|
|
272
|
-
|
|
273
|
-
relativeCount: relative.length,
|
|
274
|
-
vfModulePaths: vfModules.map((m) => m.path).slice(0, 5),
|
|
275
|
-
relativePaths: relative.map((m) => m.path).slice(0, 5),
|
|
276
|
-
});
|
|
277
|
-
log.debug(`${LOG_PREFIX_MDX_LOADER} [fetchAndCacheModule] processing vfModules START`, {
|
|
263
|
+
strictMissingModules: context.strictMissingModules ?? true,
|
|
278
264
|
projectSlug,
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
});
|
|
282
|
-
const vfStart = performance.now();
|
|
283
|
-
const nestedResults = await Promise.all(vfModules.map(async ({ original, path }) => ({
|
|
284
|
-
original,
|
|
285
|
-
nestedFilePath: await fetchAndCacheModuleFn(path, normalizedPath),
|
|
286
|
-
nestedPath: path,
|
|
287
|
-
})));
|
|
288
|
-
log.debug(`${LOG_PREFIX_MDX_LOADER} [fetchAndCacheModule] processing vfModules DONE`, {
|
|
289
|
-
projectSlug,
|
|
290
|
-
normalizedPath,
|
|
291
|
-
vfMs: (performance.now() - vfStart).toFixed(1),
|
|
292
|
-
});
|
|
293
|
-
moduleCode = await processNestedImports(moduleCode, nestedResults, esmCacheDir, context.strictMissingModules ?? true, normalizedPath, projectSlug);
|
|
294
|
-
log.debug(`${LOG_PREFIX_MDX_LOADER} [fetchAndCacheModule] processing relative imports START`, {
|
|
295
|
-
projectSlug,
|
|
296
|
-
normalizedPath,
|
|
297
|
-
count: relative.length,
|
|
298
|
-
});
|
|
299
|
-
const relStart = performance.now();
|
|
300
|
-
const relativeResults = await Promise.all(relative.map(async ({ original, path }) => ({
|
|
301
|
-
original,
|
|
302
|
-
nestedFilePath: await fetchAndCacheModuleFn(path, normalizedPath),
|
|
303
|
-
relativePath: path,
|
|
304
|
-
})));
|
|
305
|
-
log.debug(`${LOG_PREFIX_MDX_LOADER} [fetchAndCacheModule] processing relative imports DONE`, {
|
|
306
|
-
projectSlug,
|
|
307
|
-
normalizedPath,
|
|
308
|
-
relMs: (performance.now() - relStart).toFixed(1),
|
|
265
|
+
fetchAndCacheModule: fetchAndCacheModuleFn,
|
|
266
|
+
log,
|
|
309
267
|
});
|
|
310
|
-
moduleCode = await processNestedImports(moduleCode, relativeResults, esmCacheDir, context.strictMissingModules ?? true, normalizedPath, projectSlug);
|
|
311
268
|
// Write to distributed cache AFTER nested imports are resolved.
|
|
312
269
|
// This ensures other pods get fully-resolved code without /_vf_modules/ paths.
|
|
313
270
|
if (needsDistributedCacheWrite && distResult?.distributedCache && transformCacheKey) {
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @module transforms/mdx/esm-module-loader/module-fetcher/nested-imports
|
|
5
5
|
*/
|
|
6
6
|
import type { NestedImportResult } from "../types.js";
|
|
7
|
+
import type { Logger } from "../../../../utils/logger/logger.js";
|
|
7
8
|
/**
|
|
8
9
|
* Find nested module imports in code.
|
|
9
10
|
* Matches both /_vf_modules/... and file:///_vf_modules/... patterns.
|
|
@@ -29,4 +30,17 @@ export declare function hasUnresolvedImports(moduleCode: string): {
|
|
|
29
30
|
* Process nested imports by replacing them with file:// paths or stub modules.
|
|
30
31
|
*/
|
|
31
32
|
export declare function processNestedImports(moduleCode: string, results: NestedImportResult[], esmCacheDir: string, strictMissingModules: boolean, parentModulePath?: string, projectSlug?: string): Promise<string>;
|
|
33
|
+
export interface ResolveNestedModuleImportsInput {
|
|
34
|
+
moduleCode: string;
|
|
35
|
+
esmCacheDir: string;
|
|
36
|
+
normalizedPath: string;
|
|
37
|
+
projectSlug: string;
|
|
38
|
+
strictMissingModules: boolean;
|
|
39
|
+
fetchAndCacheModule: (path: string, parent?: string) => Promise<string | null>;
|
|
40
|
+
log?: Logger;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Resolve nested /_vf_modules and relative imports into local file:// cache paths.
|
|
44
|
+
*/
|
|
45
|
+
export declare function resolveNestedModuleImports(input: ResolveNestedModuleImportsInput): Promise<string>;
|
|
32
46
|
//# sourceMappingURL=nested-imports.d.ts.map
|
|
@@ -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;
|
|
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;AAQH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAGtD,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,CAAA;KAAE,CAAC,CAAC;IACrD,QAAQ,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACrD,CAqBA;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,CAyBjB;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,CAwEjB"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module transforms/mdx/esm-module-loader/module-fetcher/nested-imports
|
|
5
5
|
*/
|
|
6
|
-
import { RELATIVE_IMPORT_PATTERN, UNRESOLVED_VF_MODULES_PATTERN, VF_MODULE_IMPORT_PATTERN, } from "../constants.js";
|
|
6
|
+
import { LOG_PREFIX_MDX_LOADER, RELATIVE_IMPORT_PATTERN, UNRESOLVED_VF_MODULES_PATTERN, VF_MODULE_IMPORT_PATTERN, } from "../constants.js";
|
|
7
7
|
import { createStubModule } from "../utils/stub-module.js";
|
|
8
8
|
import { buildMissingModuleError } from "../missing-module.js";
|
|
9
9
|
/**
|
|
@@ -67,3 +67,52 @@ export async function processNestedImports(moduleCode, results, esmCacheDir, str
|
|
|
67
67
|
}
|
|
68
68
|
return result;
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Resolve nested /_vf_modules and relative imports into local file:// cache paths.
|
|
72
|
+
*/
|
|
73
|
+
export async function resolveNestedModuleImports(input) {
|
|
74
|
+
let moduleCode = input.moduleCode;
|
|
75
|
+
const { vfModules, relative } = findNestedImports(moduleCode);
|
|
76
|
+
input.log?.debug(`${LOG_PREFIX_MDX_LOADER} [fetchAndCacheModule] found nested imports`, {
|
|
77
|
+
projectSlug: input.projectSlug,
|
|
78
|
+
normalizedPath: input.normalizedPath,
|
|
79
|
+
vfModulesCount: vfModules.length,
|
|
80
|
+
relativeCount: relative.length,
|
|
81
|
+
vfModulePaths: vfModules.map((module) => module.path).slice(0, 5),
|
|
82
|
+
relativePaths: relative.map((module) => module.path).slice(0, 5),
|
|
83
|
+
});
|
|
84
|
+
input.log?.debug(`${LOG_PREFIX_MDX_LOADER} [fetchAndCacheModule] processing vfModules START`, {
|
|
85
|
+
projectSlug: input.projectSlug,
|
|
86
|
+
normalizedPath: input.normalizedPath,
|
|
87
|
+
count: vfModules.length,
|
|
88
|
+
});
|
|
89
|
+
const vfStart = performance.now();
|
|
90
|
+
const nestedResults = await Promise.all(vfModules.map(async ({ original, path }) => ({
|
|
91
|
+
original,
|
|
92
|
+
nestedFilePath: await input.fetchAndCacheModule(path, input.normalizedPath),
|
|
93
|
+
nestedPath: path,
|
|
94
|
+
})));
|
|
95
|
+
input.log?.debug(`${LOG_PREFIX_MDX_LOADER} [fetchAndCacheModule] processing vfModules DONE`, {
|
|
96
|
+
projectSlug: input.projectSlug,
|
|
97
|
+
normalizedPath: input.normalizedPath,
|
|
98
|
+
vfMs: (performance.now() - vfStart).toFixed(1),
|
|
99
|
+
});
|
|
100
|
+
moduleCode = await processNestedImports(moduleCode, nestedResults, input.esmCacheDir, input.strictMissingModules, input.normalizedPath, input.projectSlug);
|
|
101
|
+
input.log?.debug(`${LOG_PREFIX_MDX_LOADER} [fetchAndCacheModule] processing relative imports START`, {
|
|
102
|
+
projectSlug: input.projectSlug,
|
|
103
|
+
normalizedPath: input.normalizedPath,
|
|
104
|
+
count: relative.length,
|
|
105
|
+
});
|
|
106
|
+
const relStart = performance.now();
|
|
107
|
+
const relativeResults = await Promise.all(relative.map(async ({ original, path }) => ({
|
|
108
|
+
original,
|
|
109
|
+
nestedFilePath: await input.fetchAndCacheModule(path, input.normalizedPath),
|
|
110
|
+
relativePath: path,
|
|
111
|
+
})));
|
|
112
|
+
input.log?.debug(`${LOG_PREFIX_MDX_LOADER} [fetchAndCacheModule] processing relative imports DONE`, {
|
|
113
|
+
projectSlug: input.projectSlug,
|
|
114
|
+
normalizedPath: input.normalizedPath,
|
|
115
|
+
relMs: (performance.now() - relStart).toFixed(1),
|
|
116
|
+
});
|
|
117
|
+
return await processNestedImports(moduleCode, relativeResults, input.esmCacheDir, input.strictMissingModules, input.normalizedPath, input.projectSlug);
|
|
118
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validated path-cache lookups for MDX ESM module fetching.
|
|
3
|
+
*
|
|
4
|
+
* @module transforms/mdx/esm-module-loader/module-fetcher/path-cache-lookup
|
|
5
|
+
*/
|
|
6
|
+
import type { Logger } from "../../../../utils/logger/logger.js";
|
|
7
|
+
interface MdxRecoveryOptions {
|
|
8
|
+
projectId: string;
|
|
9
|
+
contentSourceId: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ReadValidCachedModulePathInput {
|
|
12
|
+
normalizedPath: string;
|
|
13
|
+
pathCache: Map<string, string>;
|
|
14
|
+
versionedKey: string;
|
|
15
|
+
log: Logger;
|
|
16
|
+
recoveryOptions?: MdxRecoveryOptions;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Return a cached module path only when the path-cache entry points to an
|
|
20
|
+
* existing file whose contents pass the full cached-module validator.
|
|
21
|
+
*/
|
|
22
|
+
export declare function readValidCachedModulePath(input: ReadValidCachedModulePathInput): Promise<string | null>;
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=path-cache-lookup.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-cache-lookup.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/path-cache-lookup.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAKjE,UAAU,kBAAkB;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,MAAM,WAAW,8BAA8B;IAC7C,cAAc,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,eAAe,CAAC,EAAE,kBAAkB,CAAC;CACtC;AAED;;;GAGG;AACH,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,8BAA8B,GACpC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA6BxB"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validated path-cache lookups for MDX ESM module fetching.
|
|
3
|
+
*
|
|
4
|
+
* @module transforms/mdx/esm-module-loader/module-fetcher/path-cache-lookup
|
|
5
|
+
*/
|
|
6
|
+
import { getLocalFs } from "../cache/index.js";
|
|
7
|
+
import { validateCachedModule } from "./framework-validator.js";
|
|
8
|
+
import { recordModuleToSession } from "./render-sessions.js";
|
|
9
|
+
/**
|
|
10
|
+
* Return a cached module path only when the path-cache entry points to an
|
|
11
|
+
* existing file whose contents pass the full cached-module validator.
|
|
12
|
+
*/
|
|
13
|
+
export async function readValidCachedModulePath(input) {
|
|
14
|
+
const cachedPath = input.pathCache.get(input.versionedKey);
|
|
15
|
+
if (!cachedPath)
|
|
16
|
+
return null;
|
|
17
|
+
try {
|
|
18
|
+
const stat = await getLocalFs().stat(cachedPath);
|
|
19
|
+
if (!stat?.isFile)
|
|
20
|
+
return null;
|
|
21
|
+
const cachedCode = await getLocalFs().readTextFile(cachedPath);
|
|
22
|
+
if (await validateCachedModule(input.normalizedPath, cachedPath, cachedCode, input.log, input.pathCache, input.versionedKey, input.recoveryOptions)) {
|
|
23
|
+
recordModuleToSession(input.normalizedPath);
|
|
24
|
+
return cachedPath;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
catch (_) {
|
|
28
|
+
/* expected: cached file may no longer exist on disk */
|
|
29
|
+
input.pathCache.delete(input.versionedKey);
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|