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