zero-com 1.12.0 → 1.12.1
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/lib/rollup.js +17 -2
- package/package.json +1 -1
package/lib/rollup.js
CHANGED
|
@@ -21,6 +21,10 @@ function zeroComRollupPlugin(options = {}) {
|
|
|
21
21
|
const compilationId = (0, common_1.generateCompilationId)();
|
|
22
22
|
const registry = new Map();
|
|
23
23
|
const project = (0, common_1.createProject)();
|
|
24
|
+
// Cache transform results by filePath → { content, result } to avoid re-running
|
|
25
|
+
// ts-morph on every SSR request in Vite dev mode (ssrLoadModule re-invokes transform
|
|
26
|
+
// for each navigation even when the file hasn't changed).
|
|
27
|
+
const transformCache = new Map();
|
|
24
28
|
let isVite = false;
|
|
25
29
|
let scanDir = optContextDir !== null && optContextDir !== void 0 ? optContextDir : process.cwd();
|
|
26
30
|
return {
|
|
@@ -33,6 +37,7 @@ function zeroComRollupPlugin(options = {}) {
|
|
|
33
37
|
if (!optContextDir)
|
|
34
38
|
scanDir = process.cwd();
|
|
35
39
|
(0, common_1.buildRegistry)(scanDir, registry, project);
|
|
40
|
+
transformCache.clear();
|
|
36
41
|
for (const fileRegistry of registry.values()) {
|
|
37
42
|
for (const info of fileRegistry.values()) {
|
|
38
43
|
console.log(`[ZeroComRollupPlugin] ${info.funcId}`);
|
|
@@ -43,6 +48,7 @@ function zeroComRollupPlugin(options = {}) {
|
|
|
43
48
|
if (!common_1.FILE_EXTENSIONS.slice(1).includes(path_1.default.extname(id)))
|
|
44
49
|
return;
|
|
45
50
|
(0, common_1.updateRegistryForFile)(id, scanDir, registry, project);
|
|
51
|
+
transformCache.clear();
|
|
46
52
|
},
|
|
47
53
|
// Rollup path: resolveId marks files, load transforms them.
|
|
48
54
|
// Skipped in Vite because meta doesn't propagate from resolveId to load.
|
|
@@ -89,16 +95,25 @@ function zeroComRollupPlugin(options = {}) {
|
|
|
89
95
|
return null;
|
|
90
96
|
if (!(0, common_1.mightNeedTransform)(code, id, registry))
|
|
91
97
|
return null;
|
|
98
|
+
// Return cached result if content hasn't changed (avoids re-running ts-morph
|
|
99
|
+
// on every SSR request in Vite dev mode where ssrLoadModule re-invokes transform)
|
|
100
|
+
const cached = transformCache.get(id);
|
|
101
|
+
if (cached && cached.content === code)
|
|
102
|
+
return cached.result;
|
|
92
103
|
// Derive effective target: explicit option takes precedence, otherwise infer from Vite's ssr flag
|
|
93
104
|
const ssr = typeof viteOptions === 'object' && viteOptions !== null && 'ssr' in viteOptions
|
|
94
105
|
? viteOptions.ssr
|
|
95
106
|
: undefined;
|
|
96
107
|
const effectiveTarget = target !== null && target !== void 0 ? target : (ssr === false ? 'client' : ssr === true ? 'server' : undefined);
|
|
97
108
|
const result = (0, common_1.transformSourceFile)(id, code, registry, { development, target: effectiveTarget }, project);
|
|
98
|
-
if (!result.transformed)
|
|
109
|
+
if (!result.transformed) {
|
|
110
|
+
transformCache.set(id, { content: code, result: null });
|
|
99
111
|
return null;
|
|
112
|
+
}
|
|
113
|
+
const out = { code: result.content, map: (_a = result.map) !== null && _a !== void 0 ? _a : null };
|
|
114
|
+
transformCache.set(id, { content: code, result: out });
|
|
100
115
|
console.log(`[ZeroComRollupPlugin] Transformed: ${path_1.default.relative(process.cwd(), id)}`);
|
|
101
|
-
return
|
|
116
|
+
return out;
|
|
102
117
|
},
|
|
103
118
|
renderChunk(code) {
|
|
104
119
|
if (development)
|