veryfront 0.1.753 → 0.1.755
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/cache/dependency-graph.d.ts +9 -1
- package/esm/src/cache/dependency-graph.d.ts.map +1 -1
- package/esm/src/cache/dependency-graph.js +43 -11
- package/esm/src/modules/react-loader/ssr-module-loader/loader.d.ts.map +1 -1
- package/esm/src/modules/react-loader/ssr-module-loader/loader.js +9 -6
- package/esm/src/modules/react-loader/ssr-module-loader/ssr-dependency-validator.d.ts +3 -2
- package/esm/src/modules/react-loader/ssr-module-loader/ssr-dependency-validator.d.ts.map +1 -1
- package/esm/src/modules/react-loader/ssr-module-loader/ssr-dependency-validator.js +4 -3
- package/esm/src/modules/server/module-batch-handler.d.ts.map +1 -1
- package/esm/src/modules/server/module-batch-handler.js +47 -35
- package/esm/src/transforms/esm/types.d.ts +3 -0
- package/esm/src/transforms/esm/types.d.ts.map +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 +17 -15
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/persistence.d.ts +34 -0
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/persistence.d.ts.map +1 -0
- package/esm/src/transforms/mdx/esm-module-loader/module-fetcher/persistence.js +30 -0
- package/esm/src/transforms/pipeline/index.d.ts.map +1 -1
- package/esm/src/transforms/pipeline/index.js +3 -3
- package/esm/src/transforms/pipeline/types.d.ts +3 -0
- package/esm/src/transforms/pipeline/types.d.ts.map +1 -1
- 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
|
@@ -16,11 +16,19 @@ export declare class DependencyGraph {
|
|
|
16
16
|
private hasTransitiveDependency;
|
|
17
17
|
private collectDependents;
|
|
18
18
|
}
|
|
19
|
+
export interface DependencyHashCache {
|
|
20
|
+
graph: DependencyGraph;
|
|
21
|
+
contentHashes: Map<string, string>;
|
|
22
|
+
completedModules: Set<string>;
|
|
23
|
+
inProgressModules: Map<string, Promise<void>>;
|
|
24
|
+
buildQueue: Promise<void>;
|
|
25
|
+
}
|
|
26
|
+
export declare function createDependencyHashCache(): DependencyHashCache;
|
|
19
27
|
export declare function extractImports(code: string): Promise<string[]>;
|
|
20
28
|
/**
|
|
21
29
|
* Filter imports to only local/relative paths (excludes npm, URLs, and framework imports).
|
|
22
30
|
*/
|
|
23
31
|
export declare function filterLocalImports(specifiers: string[]): string[];
|
|
24
32
|
export declare function normalizeSpecifierToPath(specifier: string, fromFile: string, projectDir: string): string;
|
|
25
|
-
export declare function computeDepsHash(filePath: string, getContent: (path: string) => Promise<string>, projectDir: string): Promise<string>;
|
|
33
|
+
export declare function computeDepsHash(filePath: string, getContent: (path: string) => Promise<string>, projectDir: string, cache?: DependencyHashCache): Promise<string>;
|
|
26
34
|
//# sourceMappingURL=dependency-graph.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dependency-graph.d.ts","sourceRoot":"","sources":["../../../src/src/cache/dependency-graph.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,qBAAa,eAAe;IAC1B,OAAO,CAAC,YAAY,CAAkC;IACtD,OAAO,CAAC,UAAU,CAAkC;IAEpD,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,GAAG,IAAI;IAczD,qBAAqB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE;IAIjD,yBAAyB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE;IAUrD,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE;IAUzC,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO;IAInD,KAAK,IAAI,IAAI;IAKb,aAAa,IAAI,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C,KAAK,EAAE,eAAe,CAAC;IACvB,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,gBAAgB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IAC9B,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;IAC9C,UAAU,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED,wBAAgB,yBAAyB,IAAI,mBAAmB,CAQ/D;AAED,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAGpE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAWjE;AAED,wBAAgB,wBAAwB,CACtC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GACjB,MAAM,CAsBR;AAMD,wBAAsB,eAAe,CACnC,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,EAC7C,UAAU,EAAE,MAAM,EAClB,KAAK,GAAE,mBAAiD,GACvD,OAAO,CAAC,MAAM,CAAC,CAgBjB"}
|
|
@@ -79,6 +79,15 @@ export class DependencyGraph {
|
|
|
79
79
|
path.delete(filePath);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
|
+
export function createDependencyHashCache() {
|
|
83
|
+
return {
|
|
84
|
+
graph: new DependencyGraph(),
|
|
85
|
+
contentHashes: new Map(),
|
|
86
|
+
completedModules: new Set(),
|
|
87
|
+
inProgressModules: new Map(),
|
|
88
|
+
buildQueue: Promise.resolve(),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
82
91
|
export async function extractImports(code) {
|
|
83
92
|
const parsed = await parseAllImports(code);
|
|
84
93
|
return parsed.imports.map((imp) => imp.specifier);
|
|
@@ -120,31 +129,54 @@ export function normalizeSpecifierToPath(specifier, fromFile, projectDir) {
|
|
|
120
129
|
function normalizeExtension(path) {
|
|
121
130
|
return path.replace(/\.(tsx?|jsx)$/, ".js");
|
|
122
131
|
}
|
|
123
|
-
export async function computeDepsHash(filePath, getContent, projectDir) {
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
await buildDependencyGraph(filePath, graph, contentHashes, getContent, projectDir);
|
|
127
|
-
const deps = [filePath, ...graph.getTransitiveDependencies(filePath)].sort();
|
|
132
|
+
export async function computeDepsHash(filePath, getContent, projectDir, cache = createDependencyHashCache()) {
|
|
133
|
+
await enqueueDependencyGraphBuild(cache, () => buildDependencyGraph(filePath, cache, getContent, projectDir));
|
|
134
|
+
const deps = [filePath, ...cache.graph.getTransitiveDependencies(filePath)].sort();
|
|
128
135
|
const combinedHash = deps
|
|
129
|
-
.map((dep) => contentHashes.get(dep) ?? "")
|
|
136
|
+
.map((dep) => cache.contentHashes.get(dep) ?? "")
|
|
130
137
|
.filter(Boolean)
|
|
131
138
|
.join(":");
|
|
132
139
|
return computeHash(combinedHash);
|
|
133
140
|
}
|
|
134
|
-
async function
|
|
141
|
+
async function enqueueDependencyGraphBuild(cache, build) {
|
|
142
|
+
const queuedBuild = cache.buildQueue.then(build);
|
|
143
|
+
cache.buildQueue = queuedBuild.catch(() => { });
|
|
144
|
+
await queuedBuild;
|
|
145
|
+
}
|
|
146
|
+
async function buildDependencyGraph(filePath, cache, getContent, projectDir, visited = new Set()) {
|
|
147
|
+
if (cache.completedModules.has(filePath))
|
|
148
|
+
return;
|
|
135
149
|
if (visited.has(filePath))
|
|
136
150
|
return;
|
|
137
151
|
visited.add(filePath);
|
|
152
|
+
const inProgress = cache.inProgressModules.get(filePath);
|
|
153
|
+
if (inProgress) {
|
|
154
|
+
await inProgress;
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const buildPromise = buildDependencyGraphFresh(filePath, cache, getContent, projectDir, visited);
|
|
158
|
+
cache.inProgressModules.set(filePath, buildPromise);
|
|
159
|
+
try {
|
|
160
|
+
await buildPromise;
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
cache.inProgressModules.delete(filePath);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async function buildDependencyGraphFresh(filePath, cache, getContent, projectDir, visited) {
|
|
138
167
|
try {
|
|
139
168
|
const content = await getContent(filePath);
|
|
140
|
-
contentHashes.set(filePath, await computeHash(content));
|
|
169
|
+
cache.contentHashes.set(filePath, await computeHash(content));
|
|
141
170
|
const allImports = await extractImports(content);
|
|
142
171
|
const normalizedDeps = filterLocalImports(allImports).map((spec) => normalizeSpecifierToPath(spec, filePath, projectDir));
|
|
143
|
-
graph.addModule(filePath, normalizedDeps);
|
|
144
|
-
await Promise.all(normalizedDeps.map((dep) => buildDependencyGraph(dep,
|
|
172
|
+
cache.graph.addModule(filePath, normalizedDeps);
|
|
173
|
+
await Promise.all(normalizedDeps.map((dep) => buildDependencyGraph(dep, cache, getContent, projectDir, visited)));
|
|
145
174
|
}
|
|
146
175
|
catch (_) {
|
|
147
176
|
// expected: file may not exist or imports may fail to parse
|
|
148
|
-
graph.addModule(filePath, []);
|
|
177
|
+
cache.graph.addModule(filePath, []);
|
|
178
|
+
}
|
|
179
|
+
finally {
|
|
180
|
+
cache.completedModules.add(filePath);
|
|
149
181
|
}
|
|
150
182
|
}
|
|
@@ -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,4BAA4B,CAAC;AAsCzD,OAAO,KAAK,EAAoB,sBAAsB,EAAE,MAAM,YAAY,CAAC;
|
|
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,4BAA4B,CAAC;AAsCzD,OAAO,KAAK,EAAoB,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAsB3E;;;;;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;YAYrC,qBAAqB;YAgDrB,0BAA0B;IAwHxC,aAAa,CACX,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAgD7B,UAAU,CACd,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;YAK1C,2BAA2B;IAYzC,OAAO,CAAC,yBAAyB;YAkBnB,2BAA2B;CAkW1C"}
|
|
@@ -34,6 +34,7 @@ import { resolveVfModuleImports } from "./vf-module-resolver.js";
|
|
|
34
34
|
import { registerCSSImport } from "../css-import-collector.js";
|
|
35
35
|
import { injectNodePositions } from "../../../transforms/plugins/babel-node-positions.js";
|
|
36
36
|
import { ensureMdxModuleDependencies } from "../../../transforms/mdx/esm-module-loader/module-fetcher/dependency-recovery.js";
|
|
37
|
+
import { createDependencyHashCache, } from "../../../cache/dependency-graph.js";
|
|
37
38
|
const logger = rendererLogger.component("ssr-module-loader");
|
|
38
39
|
/**
|
|
39
40
|
* SSR Module Loader with Redis Support.
|
|
@@ -49,7 +50,7 @@ export class SSRModuleLoader {
|
|
|
49
50
|
constructor(options) {
|
|
50
51
|
this.options = options;
|
|
51
52
|
this.cache = new SSRCacheManager(options);
|
|
52
|
-
this.depValidator = new SSRDependencyValidator((filePath) => this.cache.getCacheKey(filePath), (filePath, source, depth) => this.transformWithDependencies(filePath, source, depth), (crossImport) => this.transformCrossProjectImport(crossImport), options.adapter, options.projectDir);
|
|
53
|
+
this.depValidator = new SSRDependencyValidator((filePath) => this.cache.getCacheKey(filePath), (filePath, source, depth, dependencyHashCache) => this.transformWithDependencies(filePath, source, depth, dependencyHashCache), (crossImport) => this.transformCrossProjectImport(crossImport), options.adapter, options.projectDir);
|
|
53
54
|
}
|
|
54
55
|
async withTransformCapacity(filePath, mode, operation) {
|
|
55
56
|
const useSemaphore = getMaxConcurrentTransforms() > 0;
|
|
@@ -176,7 +177,8 @@ export class SSRModuleLoader {
|
|
|
176
177
|
this.circuitBreaker.check(circuitKey, filePath);
|
|
177
178
|
this.depValidator.reset();
|
|
178
179
|
try {
|
|
179
|
-
|
|
180
|
+
const dependencyHashCache = createDependencyHashCache();
|
|
181
|
+
await this.transformWithDependencies(filePath, source, 0, dependencyHashCache);
|
|
180
182
|
if (this.depValidator.missingDependencies.length > 0) {
|
|
181
183
|
this.depValidator.throwMissingDependencies(filePath);
|
|
182
184
|
}
|
|
@@ -215,14 +217,14 @@ export class SSRModuleLoader {
|
|
|
215
217
|
withTransformCapacity: (syntheticFilePath, operation) => this.withTransformCapacity(syntheticFilePath, "plain", operation),
|
|
216
218
|
});
|
|
217
219
|
}
|
|
218
|
-
transformWithDependencies(filePath, source, depth = 0) {
|
|
220
|
+
transformWithDependencies(filePath, source, depth = 0, dependencyHashCache = createDependencyHashCache()) {
|
|
219
221
|
const fileName = filePath.split("/").pop() || filePath;
|
|
220
|
-
return withSpan(SpanNames.SSR_TRANSFORM_DEPENDENCIES, () => this.doTransformWithDependencies(filePath, source, depth), {
|
|
222
|
+
return withSpan(SpanNames.SSR_TRANSFORM_DEPENDENCIES, () => this.doTransformWithDependencies(filePath, source, depth, dependencyHashCache), {
|
|
221
223
|
"ssr.file": fileName,
|
|
222
224
|
"ssr.depth": depth,
|
|
223
225
|
});
|
|
224
226
|
}
|
|
225
|
-
async doTransformWithDependencies(filePath, source, depth = 0) {
|
|
227
|
+
async doTransformWithDependencies(filePath, source, depth = 0, dependencyHashCache = createDependencyHashCache()) {
|
|
226
228
|
if (depth > MAX_TRANSFORM_DEPTH) {
|
|
227
229
|
logger.warn("Max transform depth exceeded", {
|
|
228
230
|
file: filePath.slice(-40),
|
|
@@ -365,7 +367,7 @@ export class SSRModuleLoader {
|
|
|
365
367
|
// children also need slots (10 batch x 2 depth = 21 slots, but limit is 17).
|
|
366
368
|
const crossProjectPaths = new Map();
|
|
367
369
|
const localFs = createFileSystem();
|
|
368
|
-
const localImportPaths = await this.depValidator.processLocalImports(parseResult.imports, filePath, depth, localFs);
|
|
370
|
+
const localImportPaths = await this.depValidator.processLocalImports(parseResult.imports, filePath, depth, localFs, dependencyHashCache);
|
|
369
371
|
for (let i = 0; i < parseResult.crossProjectImports.length; i += TRANSFORM_BATCH_SIZE) {
|
|
370
372
|
const batch = parseResult.crossProjectImports.slice(i, i + TRANSFORM_BATCH_SIZE);
|
|
371
373
|
await Promise.all(batch.map(async (crossImport) => {
|
|
@@ -391,6 +393,7 @@ export class SSRModuleLoader {
|
|
|
391
393
|
ssr: true,
|
|
392
394
|
apiBaseUrl: this.options.apiBaseUrl,
|
|
393
395
|
reactVersion: this.options.reactVersion,
|
|
396
|
+
dependencyHashCache,
|
|
394
397
|
};
|
|
395
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 });
|
|
396
399
|
for (const [specifier, tempPath] of crossProjectPaths.entries()) {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import type { CrossProjectImport, MissingImport } from "../../../transforms/esm/import-parser.js";
|
|
10
10
|
import { createFileSystem } from "../../../platform/compat/fs.js";
|
|
11
11
|
import type { RuntimeAdapter } from "../../../platform/adapters/base.js";
|
|
12
|
+
import { type DependencyHashCache } from "../../../cache/dependency-graph.js";
|
|
12
13
|
/**
|
|
13
14
|
* Manages dependency validation for SSR module loading:
|
|
14
15
|
* - Pre-flight checks for local file existence
|
|
@@ -23,7 +24,7 @@ export declare class SSRDependencyValidator {
|
|
|
23
24
|
private projectDir;
|
|
24
25
|
/** Accumulated missing dependencies across the transform tree. */
|
|
25
26
|
missingDependencies: MissingImport[];
|
|
26
|
-
constructor(getCacheKey: (filePath: string) => string, transformWithDependencies: (filePath: string, source: string | undefined, depth: number) => Promise<void>, transformCrossProjectImport: (crossProjectImport: CrossProjectImport) => Promise<string>, adapter: RuntimeAdapter, projectDir: string);
|
|
27
|
+
constructor(getCacheKey: (filePath: string) => string, transformWithDependencies: (filePath: string, source: string | undefined, depth: number, dependencyHashCache: DependencyHashCache) => Promise<void>, transformCrossProjectImport: (crossProjectImport: CrossProjectImport) => Promise<string>, adapter: RuntimeAdapter, projectDir: string);
|
|
27
28
|
/** Reset missing dependencies for a new load cycle. */
|
|
28
29
|
reset(): void;
|
|
29
30
|
/**
|
|
@@ -42,6 +43,6 @@ export declare class SSRDependencyValidator {
|
|
|
42
43
|
processLocalImports(imports: Array<{
|
|
43
44
|
absolutePath: string;
|
|
44
45
|
specifier: string;
|
|
45
|
-
}>, fromFilePath: string, depth: number, localFs: ReturnType<typeof createFileSystem
|
|
46
|
+
}>, fromFilePath: string, depth: number, localFs: ReturnType<typeof createFileSystem>, dependencyHashCache: DependencyHashCache): Promise<Map<string, string>>;
|
|
46
47
|
}
|
|
47
48
|
//# sourceMappingURL=ssr-dependency-validator.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ssr-dependency-validator.d.ts","sourceRoot":"","sources":["../../../../../src/src/modules/react-loader/ssr-module-loader/ssr-dependency-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAGlG,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAGlE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"ssr-dependency-validator.d.ts","sourceRoot":"","sources":["../../../../../src/src/modules/react-loader/ssr-module-loader/ssr-dependency-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,0CAA0C,CAAC;AAGlG,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAGlE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAGzE,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,oCAAoC,CAAC;AAI5C;;;;;GAKG;AACH,qBAAa,sBAAsB;IAK/B,OAAO,CAAC,WAAW;IACnB,OAAO,CAAC,yBAAyB;IAMjC,OAAO,CAAC,2BAA2B;IAGnC,OAAO,CAAC,OAAO;IACf,OAAO,CAAC,UAAU;IAfpB,kEAAkE;IAClE,mBAAmB,EAAE,aAAa,EAAE,CAAM;gBAGhC,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,EACzC,yBAAyB,EAAE,CACjC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,KAAK,EAAE,MAAM,EACb,mBAAmB,EAAE,mBAAmB,KACrC,OAAO,CAAC,IAAI,CAAC,EACV,2BAA2B,EAAE,CACnC,kBAAkB,EAAE,kBAAkB,KACnC,OAAO,CAAC,MAAM,CAAC,EACZ,OAAO,EAAE,cAAc,EACvB,UAAU,EAAE,MAAM;IAG5B,uDAAuD;IACvD,KAAK,IAAI,IAAI;IAIb;;OAEG;IACH,wBAAwB,CAAC,QAAQ,EAAE,MAAM,GAAG,KAAK;IAwBjD;;;OAGG;IACG,uBAAuB,CAC3B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,KAAK,GAAE,MAAU,GAChB,OAAO,CAAC,IAAI,CAAC;IAgDhB;;;OAGG;IACG,mBAAmB,CACvB,OAAO,EAAE,KAAK,CAAC;QAAE,YAAY,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAAC,EAC3D,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,EAC5C,mBAAmB,EAAE,mBAAmB,GACvC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAwChC"}
|
|
@@ -13,6 +13,7 @@ import { createError, toError } from "../../../errors/veryfront-error.js";
|
|
|
13
13
|
import { rendererLogger } from "../../../utils/index.js";
|
|
14
14
|
import { MAX_TRANSFORM_DEPTH, TRANSFORM_BATCH_SIZE } from "./constants.js";
|
|
15
15
|
import { globalModuleCache } from "./cache/index.js";
|
|
16
|
+
import { createDependencyHashCache, } from "../../../cache/dependency-graph.js";
|
|
16
17
|
const logger = rendererLogger.component("ssr-module-loader");
|
|
17
18
|
/**
|
|
18
19
|
* Manages dependency validation for SSR module loading:
|
|
@@ -77,7 +78,7 @@ export class SSRDependencyValidator {
|
|
|
77
78
|
this.missingDependencies.push(...parseResult.missing);
|
|
78
79
|
}
|
|
79
80
|
const localFs = createFileSystem();
|
|
80
|
-
await this.processLocalImports(parseResult.imports, filePath, depth, localFs);
|
|
81
|
+
await this.processLocalImports(parseResult.imports, filePath, depth, localFs, createDependencyHashCache());
|
|
81
82
|
for (let i = 0; i < parseResult.crossProjectImports.length; i += TRANSFORM_BATCH_SIZE) {
|
|
82
83
|
const batch = parseResult.crossProjectImports.slice(i, i + TRANSFORM_BATCH_SIZE);
|
|
83
84
|
await Promise.all(batch.map(async (crossImport) => {
|
|
@@ -98,7 +99,7 @@ export class SSRDependencyValidator {
|
|
|
98
99
|
* Process local imports in batches, recursively transforming dependencies
|
|
99
100
|
* and building a map of specifier -> temp file path.
|
|
100
101
|
*/
|
|
101
|
-
async processLocalImports(imports, fromFilePath, depth, localFs) {
|
|
102
|
+
async processLocalImports(imports, fromFilePath, depth, localFs, dependencyHashCache) {
|
|
102
103
|
const importPathMap = new Map();
|
|
103
104
|
for (let i = 0; i < imports.length; i += TRANSFORM_BATCH_SIZE) {
|
|
104
105
|
const batch = imports.slice(i, i + TRANSFORM_BATCH_SIZE);
|
|
@@ -107,7 +108,7 @@ export class SSRDependencyValidator {
|
|
|
107
108
|
const depSource = imp.absolutePath.startsWith("/")
|
|
108
109
|
? await localFs.readTextFile(imp.absolutePath)
|
|
109
110
|
: await this.adapter.fs.readFile(imp.absolutePath);
|
|
110
|
-
await this.transformWithDependencies(imp.absolutePath, depSource, depth + 1);
|
|
111
|
+
await this.transformWithDependencies(imp.absolutePath, depSource, depth + 1, dependencyHashCache);
|
|
111
112
|
const depCacheKey = this.getCacheKey(imp.absolutePath);
|
|
112
113
|
const depEntry = globalModuleCache.get(depCacheKey);
|
|
113
114
|
if (depEntry) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"module-batch-handler.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/server/module-batch-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AASH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAiGtE,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,cAAc,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6K/F;
|
|
1
|
+
{"version":3,"file":"module-batch-handler.d.ts","sourceRoot":"","sources":["../../../../src/src/modules/server/module-batch-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AASH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAiGtE,MAAM,WAAW,mBAAmB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,cAAc,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC7B,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,CA6K/F;AA2QD;;GAEG;AACH,wBAAgB,eAAe,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAc1D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,CAKrE"}
|
|
@@ -179,7 +179,7 @@ export function handleModuleBatch(req, options) {
|
|
|
179
179
|
headers: { "Content-Type": "text/plain" },
|
|
180
180
|
});
|
|
181
181
|
}
|
|
182
|
-
const
|
|
182
|
+
const bundleStream = createBatchBundleStream(successes, failures);
|
|
183
183
|
const duration = performance.now() - startTime;
|
|
184
184
|
const isSlow = duration > SLOW_REQUEST_THRESHOLD_MS;
|
|
185
185
|
const logMethod = isSlow ? logger.warn.bind(logger) : logger.info.bind(logger);
|
|
@@ -202,7 +202,7 @@ export function handleModuleBatch(req, options) {
|
|
|
202
202
|
})),
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
|
-
return new Response(
|
|
205
|
+
return new Response(bundleStream, {
|
|
206
206
|
status: HTTP_OK,
|
|
207
207
|
headers: {
|
|
208
208
|
"Content-Type": "application/javascript; charset=utf-8",
|
|
@@ -336,50 +336,62 @@ function createBatchSSRTargetCacheBusterResolver(options) {
|
|
|
336
336
|
return promise;
|
|
337
337
|
};
|
|
338
338
|
}
|
|
339
|
+
function createBatchBundleStream(successes, failures) {
|
|
340
|
+
const encoder = new TextEncoder();
|
|
341
|
+
return new ReadableStream({
|
|
342
|
+
start(controller) {
|
|
343
|
+
let isFirstChunk = true;
|
|
344
|
+
for (const chunk of generateBatchBundleChunks(successes, failures)) {
|
|
345
|
+
if (!isFirstChunk)
|
|
346
|
+
controller.enqueue(encoder.encode("\n"));
|
|
347
|
+
controller.enqueue(encoder.encode(chunk));
|
|
348
|
+
isFirstChunk = false;
|
|
349
|
+
}
|
|
350
|
+
controller.close();
|
|
351
|
+
},
|
|
352
|
+
});
|
|
353
|
+
}
|
|
339
354
|
/**
|
|
340
|
-
* Generate the batch bundle code
|
|
341
|
-
* Creates a module that exports all loaded modules by path
|
|
355
|
+
* Generate the batch bundle code chunks.
|
|
356
|
+
* Creates a module that exports all loaded modules by path.
|
|
342
357
|
*/
|
|
343
|
-
function
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
"",
|
|
351
|
-
];
|
|
358
|
+
function* generateBatchBundleChunks(successes, failures) {
|
|
359
|
+
yield "// Veryfront Module Batch Bundle";
|
|
360
|
+
yield "// Generated: " + new Date().toISOString();
|
|
361
|
+
yield `// Modules: ${successes.length} loaded, ${failures.length} failed`;
|
|
362
|
+
yield "";
|
|
363
|
+
yield "const __vf_batch_modules = new Map();";
|
|
364
|
+
yield "";
|
|
352
365
|
for (let i = 0; i < successes.length; i++) {
|
|
353
366
|
const item = successes[i];
|
|
354
367
|
if (!item)
|
|
355
368
|
continue;
|
|
356
369
|
const { path, code } = item;
|
|
357
370
|
const varName = `__mod_${i}`;
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
371
|
+
yield `// Module: ${path}`;
|
|
372
|
+
yield `const ${varName} = await (async () => {`;
|
|
373
|
+
yield " const exports = {};";
|
|
374
|
+
yield " const module = { exports };";
|
|
375
|
+
yield " // --- Module code start ---";
|
|
376
|
+
yield transformExportsForBundle(code);
|
|
377
|
+
yield " // --- Module code end ---";
|
|
378
|
+
yield " return exports;";
|
|
379
|
+
yield "})();";
|
|
380
|
+
yield `__vf_batch_modules.set("${path}", ${varName});`;
|
|
381
|
+
yield "";
|
|
369
382
|
}
|
|
370
383
|
for (const { path, error } of failures) {
|
|
371
|
-
|
|
372
|
-
|
|
384
|
+
yield `// Failed: ${path} - ${error}`;
|
|
385
|
+
yield `__vf_batch_modules.set("${path}", { __vf_error: "${error}" });`;
|
|
373
386
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
return parts.join("\n");
|
|
387
|
+
yield "";
|
|
388
|
+
yield "export const batchModules = __vf_batch_modules;";
|
|
389
|
+
yield "";
|
|
390
|
+
yield "export function getModule(path) {";
|
|
391
|
+
yield " return __vf_batch_modules.get(path);";
|
|
392
|
+
yield "}";
|
|
393
|
+
yield "";
|
|
394
|
+
yield "export default { batchModules, getModule };";
|
|
383
395
|
}
|
|
384
396
|
/**
|
|
385
397
|
* Transform module code for inclusion in batch bundle
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { RuntimeAdapter } from "../../platform/adapters/base.js";
|
|
2
|
+
import type { DependencyHashCache } from "../../cache/dependency-graph.js";
|
|
2
3
|
export interface TransformOptions {
|
|
3
4
|
dev?: boolean;
|
|
4
5
|
projectId: string;
|
|
@@ -10,6 +11,8 @@ export interface TransformOptions {
|
|
|
10
11
|
studioEmbed?: boolean;
|
|
11
12
|
/** React version for transforms (from project config, defaults to DEFAULT_REACT_VERSION) */
|
|
12
13
|
reactVersion?: string;
|
|
14
|
+
/** Internal per-render dependency hash cache. */
|
|
15
|
+
dependencyHashCache?: DependencyHashCache;
|
|
13
16
|
}
|
|
14
17
|
export interface TransformContext {
|
|
15
18
|
source: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/src/transforms/esm/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/src/transforms/esm/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAE3E,MAAM,WAAW,gBAAgB;IAC/B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,4FAA4F;IAC5F,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iDAAiD;IACjD,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;CAC3C;AAED,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,cAAc,CAAC;IACxB,OAAO,EAAE,gBAAgB,CAAC;CAC3B"}
|
|
@@ -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;AAG5E,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;AAG5E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAexD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,GACnB,MAAM,sBAAsB,CAAC;AAS9B;;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;AA8JD;;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"}
|
|
@@ -20,10 +20,11 @@ import { resolveModuleFile } from "../resolution/file-finder.js";
|
|
|
20
20
|
import { buildMissingModuleError } from "../missing-module.js";
|
|
21
21
|
import { getTransformCacheKey, getVersionedPathCacheKey } from "./cache-keys.js";
|
|
22
22
|
import { resolveNestedModuleImports } from "./nested-imports.js";
|
|
23
|
-
import { readDistributedCache
|
|
23
|
+
import { readDistributedCache } from "./distributed-cache.js";
|
|
24
24
|
import { fetchModuleViaHTTP } from "./http-fetcher.js";
|
|
25
25
|
import { cacheModule, normalizePath } from "./module-cache.js";
|
|
26
26
|
import { readValidCachedModulePath } from "./path-cache-lookup.js";
|
|
27
|
+
import { persistResolvedModule } from "./persistence.js";
|
|
27
28
|
import { transformResolvedModuleSource } from "./source-transform.js";
|
|
28
29
|
// Re-export extracted modules for backward compatibility
|
|
29
30
|
export { rewriteDntImports } from "./import-rewriter.js";
|
|
@@ -219,23 +220,24 @@ async function doFetchAndCacheModule(normalizedPath, context, fetchAndCacheModul
|
|
|
219
220
|
fetchAndCacheModule: fetchAndCacheModuleFn,
|
|
220
221
|
log,
|
|
221
222
|
});
|
|
222
|
-
|
|
223
|
-
// This ensures other pods get fully-resolved code without /_vf_modules/ paths.
|
|
224
|
-
if (needsDistributedCacheWrite && distResult?.distributedCache && transformCacheKey) {
|
|
225
|
-
writeDistributedCache(distResult.distributedCache, transformCacheKey, projectId, contentSourceId, moduleCode, normalizedPath, log);
|
|
226
|
-
}
|
|
227
|
-
log.debug(`${LOG_PREFIX_MDX_LOADER} [fetchAndCacheModule] cacheModule START`, {
|
|
228
|
-
projectSlug,
|
|
223
|
+
return await persistResolvedModule({
|
|
229
224
|
normalizedPath,
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
225
|
+
moduleCode,
|
|
226
|
+
esmCacheDir,
|
|
227
|
+
pathCache,
|
|
228
|
+
log,
|
|
234
229
|
projectSlug,
|
|
235
|
-
|
|
236
|
-
|
|
230
|
+
reactVersion: effectiveReactVersion,
|
|
231
|
+
distributedCacheWrite: needsDistributedCacheWrite && distResult?.distributedCache && transformCacheKey &&
|
|
232
|
+
contentSourceId
|
|
233
|
+
? {
|
|
234
|
+
distributedCache: distResult.distributedCache,
|
|
235
|
+
transformCacheKey,
|
|
236
|
+
projectId,
|
|
237
|
+
contentSourceId,
|
|
238
|
+
}
|
|
239
|
+
: undefined,
|
|
237
240
|
});
|
|
238
|
-
return finalCachedPath;
|
|
239
241
|
}
|
|
240
242
|
catch (error) {
|
|
241
243
|
log.warn(`${LOG_PREFIX_MDX_LOADER} Failed to process ${normalizedPath}`, error);
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Final persistence phase for the MDX ESM module fetcher.
|
|
3
|
+
*
|
|
4
|
+
* @module transforms/mdx/esm-module-loader/module-fetcher/persistence
|
|
5
|
+
*/
|
|
6
|
+
import type { Logger } from "../../../../utils/logger/logger.js";
|
|
7
|
+
import { cacheModule } from "./module-cache.js";
|
|
8
|
+
import { writeDistributedCache } from "./distributed-cache.js";
|
|
9
|
+
type CacheLocalModuleFn = typeof cacheModule;
|
|
10
|
+
type WriteDistributedCacheFn = typeof writeDistributedCache;
|
|
11
|
+
type DistributedCache = Parameters<WriteDistributedCacheFn>[0];
|
|
12
|
+
export interface PersistResolvedModuleInput {
|
|
13
|
+
normalizedPath: string;
|
|
14
|
+
moduleCode: string;
|
|
15
|
+
esmCacheDir: string;
|
|
16
|
+
pathCache: Map<string, string>;
|
|
17
|
+
log: Logger;
|
|
18
|
+
projectSlug: string;
|
|
19
|
+
reactVersion?: string;
|
|
20
|
+
distributedCacheWrite?: {
|
|
21
|
+
distributedCache: DistributedCache;
|
|
22
|
+
transformCacheKey: string;
|
|
23
|
+
projectId: string;
|
|
24
|
+
contentSourceId: string;
|
|
25
|
+
};
|
|
26
|
+
cacheLocalModule?: CacheLocalModuleFn;
|
|
27
|
+
writeToDistributedCache?: WriteDistributedCacheFn;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Persist fully resolved module code to distributed and local caches.
|
|
31
|
+
*/
|
|
32
|
+
export declare function persistResolvedModule(input: PersistResolvedModuleInput): Promise<string | null>;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=persistence.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../../../../../src/src/transforms/mdx/esm-module-loader/module-fetcher/persistence.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oCAAoC,CAAC;AAEjE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,KAAK,kBAAkB,GAAG,OAAO,WAAW,CAAC;AAC7C,KAAK,uBAAuB,GAAG,OAAO,qBAAqB,CAAC;AAC5D,KAAK,gBAAgB,GAAG,UAAU,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAC,CAAC;AAE/D,MAAM,WAAW,0BAA0B;IACzC,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,qBAAqB,CAAC,EAAE;QACtB,gBAAgB,EAAE,gBAAgB,CAAC;QACnC,iBAAiB,EAAE,MAAM,CAAC;QAC1B,SAAS,EAAE,MAAM,CAAC;QAClB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,gBAAgB,CAAC,EAAE,kBAAkB,CAAC;IACtC,uBAAuB,CAAC,EAAE,uBAAuB,CAAC;CACnD;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CACzC,KAAK,EAAE,0BAA0B,GAChC,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAoCxB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Final persistence phase for the MDX ESM module fetcher.
|
|
3
|
+
*
|
|
4
|
+
* @module transforms/mdx/esm-module-loader/module-fetcher/persistence
|
|
5
|
+
*/
|
|
6
|
+
import { LOG_PREFIX_MDX_LOADER } from "../constants.js";
|
|
7
|
+
import { cacheModule } from "./module-cache.js";
|
|
8
|
+
import { writeDistributedCache } from "./distributed-cache.js";
|
|
9
|
+
/**
|
|
10
|
+
* Persist fully resolved module code to distributed and local caches.
|
|
11
|
+
*/
|
|
12
|
+
export async function persistResolvedModule(input) {
|
|
13
|
+
const writeToDistributedCache = input.writeToDistributedCache ?? writeDistributedCache;
|
|
14
|
+
const cacheLocalModule = input.cacheLocalModule ?? cacheModule;
|
|
15
|
+
if (input.distributedCacheWrite) {
|
|
16
|
+
writeToDistributedCache(input.distributedCacheWrite.distributedCache, input.distributedCacheWrite.transformCacheKey, input.distributedCacheWrite.projectId, input.distributedCacheWrite.contentSourceId, input.moduleCode, input.normalizedPath, input.log);
|
|
17
|
+
}
|
|
18
|
+
input.log.debug(`${LOG_PREFIX_MDX_LOADER} [fetchAndCacheModule] cacheModule START`, {
|
|
19
|
+
projectSlug: input.projectSlug,
|
|
20
|
+
normalizedPath: input.normalizedPath,
|
|
21
|
+
});
|
|
22
|
+
const cacheStart = performance.now();
|
|
23
|
+
const finalCachedPath = await cacheLocalModule(input.normalizedPath, input.moduleCode, input.esmCacheDir, input.pathCache, input.log, input.reactVersion);
|
|
24
|
+
input.log.debug(`${LOG_PREFIX_MDX_LOADER} [fetchAndCacheModule] cacheModule DONE`, {
|
|
25
|
+
projectSlug: input.projectSlug,
|
|
26
|
+
normalizedPath: input.normalizedPath,
|
|
27
|
+
cacheMs: (performance.now() - cacheStart).toFixed(1),
|
|
28
|
+
});
|
|
29
|
+
return finalCachedPath;
|
|
30
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/transforms/pipeline/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAEhB,eAAe,EAChB,MAAM,YAAY,CAAC;AA0HpB,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,gBAAgB,EACzB,MAAM,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/src/transforms/pipeline/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAYH,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EAEhB,eAAe,EAChB,MAAM,YAAY,CAAC;AA0HpB,wBAAgB,WAAW,CACzB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,gBAAgB,EACzB,MAAM,CAAC,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC,CAyI1B;AAqBD,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,OAAO,EAChB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,MAAM,CAAC,CASjB;AAmCD,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,OAAO,EACL,sBAAsB,EACtB,0BAA0B,EAC1B,SAAS,EACT,KAAK,EACL,KAAK,EACL,YAAY,GACb,MAAM,cAAc,CAAC"}
|
|
@@ -118,7 +118,7 @@ export function runPipeline(source, filePath, projectDir, options, config) {
|
|
|
118
118
|
studioEmbed: ctx.studioEmbed,
|
|
119
119
|
dev: ctx.dev,
|
|
120
120
|
});
|
|
121
|
-
const depsHash = await computeDepsHashSafe(filePath, projectDir, options.readFile);
|
|
121
|
+
const depsHash = await computeDepsHashSafe(filePath, projectDir, options.readFile, options.dependencyHashCache);
|
|
122
122
|
const cacheKey = generateCacheKey(filePath, ctx.contentHash, options.ssr ?? false, options.studioEmbed ?? false, { depsHash, configHash, projectId: options.projectId });
|
|
123
123
|
const cached = await getCachedTransformAsync(cacheKey);
|
|
124
124
|
if (cached) {
|
|
@@ -204,11 +204,11 @@ export function runPipeline(source, filePath, projectDir, options, config) {
|
|
|
204
204
|
"transform.studio_embed": options.studioEmbed ?? false,
|
|
205
205
|
});
|
|
206
206
|
}
|
|
207
|
-
async function computeDepsHashSafe(filePath, projectDir, readFile) {
|
|
207
|
+
async function computeDepsHashSafe(filePath, projectDir, readFile, dependencyHashCache) {
|
|
208
208
|
if (!readFile)
|
|
209
209
|
return undefined;
|
|
210
210
|
try {
|
|
211
|
-
return await computeDepsHash(filePath, readFile, projectDir);
|
|
211
|
+
return await computeDepsHash(filePath, readFile, projectDir, dependencyHashCache);
|
|
212
212
|
}
|
|
213
213
|
catch (err) {
|
|
214
214
|
logger.debug("depsHash computation failed, skipping", {
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Defines the plugin-based architecture for ESM transforms.
|
|
5
5
|
* Each stage handles one concern, making the pipeline testable and maintainable.
|
|
6
6
|
*/
|
|
7
|
+
import type { DependencyHashCache } from "../../cache/dependency-graph.js";
|
|
7
8
|
/**
|
|
8
9
|
* Transform stages in execution order.
|
|
9
10
|
* Each stage runs after the previous completes.
|
|
@@ -54,6 +55,8 @@ export interface TransformOptions {
|
|
|
54
55
|
reactVersion?: string;
|
|
55
56
|
/** File reader for dependency hash computation. When provided, enables dependency-aware cache invalidation. */
|
|
56
57
|
readFile?: (path: string) => Promise<string>;
|
|
58
|
+
/** Internal per-render dependency hash cache. */
|
|
59
|
+
dependencyHashCache?: DependencyHashCache;
|
|
57
60
|
}
|
|
58
61
|
/**
|
|
59
62
|
* Context passed through the transform pipeline.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/src/transforms/pipeline/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,oBAAY,cAAc;IACxB,4BAA4B;IAC5B,KAAK,IAAI;IACT,mCAAmC;IACnC,OAAO,IAAI;IACX,0BAA0B;IAC1B,eAAe,IAAI;IACnB,wEAAwE;IACxE,aAAa,IAAI;IACjB,oEAAoE;IACpE,eAAe,IAAI;IACnB,4DAA4D;IAC5D,gBAAgB,IAAI;IACpB,uEAAuE;IACvE,YAAY,IAAI;IAChB,iDAAiD;IACjD,QAAQ,IAAI;CACb;AAED;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,SAAS,CAAC;AAEhD;;GAEG;AACH,MAAM,W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