@vitejs/devtools-rolldown 0.1.23 → 0.2.0
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/dist/index.mjs +1656 -216
- package/dist/nitro.json +2 -2
- package/dist/public/200.html +1 -1
- package/dist/public/404.html +1 -1
- package/dist/public/_nuxt/0O2Pj8hl.js +1 -0
- package/dist/public/_nuxt/5bJuVons.js +1 -0
- package/dist/public/_nuxt/{B6PLDwAm.js → BCw50qmU.js} +4 -4
- package/dist/public/_nuxt/BFhxncQ2.js +1 -0
- package/dist/public/_nuxt/BGZZhyQu.js +1 -0
- package/dist/public/_nuxt/{dedBpiqn.js → BJmyRiUp.js} +1 -1
- package/dist/public/_nuxt/B_J3ZfKi.js +1 -0
- package/dist/public/_nuxt/Ba09nynh.js +1 -0
- package/dist/public/_nuxt/{CtfgqrR6.js → BbKimAk2.js} +1 -1
- package/dist/public/_nuxt/Bq4MVFqu.js +1 -0
- package/dist/public/_nuxt/BufyvRUO.js +1 -0
- package/dist/public/_nuxt/CE_-BS6_.js +1 -0
- package/dist/public/_nuxt/{_z5g9W2Q.js → CJF5NhpB.js} +1 -1
- package/dist/public/_nuxt/CWXuMikD.js +1 -0
- package/dist/public/_nuxt/Cj4ehwvT.js +1 -0
- package/dist/public/_nuxt/D3WsuaG8.js +1 -0
- package/dist/public/_nuxt/DAw3vtMH.js +1 -0
- package/dist/public/_nuxt/DHF6DbDV.js +1 -0
- package/dist/public/_nuxt/DNBEBkdT.js +1 -0
- package/dist/public/_nuxt/DPbQuX9J.js +7 -0
- package/dist/public/_nuxt/{DataVirtualList.B_Uggh0w.css → DataVirtualList.CX8PXv9n.css} +1 -1
- package/dist/public/_nuxt/Dc_O_zZb.js +1 -0
- package/dist/public/_nuxt/DjrbEfG8.js +1 -0
- package/dist/public/_nuxt/DlfUjYwO.js +1 -0
- package/dist/public/_nuxt/DpwellRX.js +1 -0
- package/dist/public/_nuxt/DtFq1Eli.js +1 -0
- package/dist/public/_nuxt/KGWAKIjl.js +1 -0
- package/dist/public/_nuxt/Q0g2p3Tn.js +1 -0
- package/dist/public/_nuxt/SDYr5o4O.js +1 -0
- package/dist/public/_nuxt/{_session_.Dk6Grde1.css → _session_.QzrJ09_g.css} +1 -1
- package/dist/public/_nuxt/builds/latest.json +1 -1
- package/dist/public/_nuxt/builds/meta/d4e8dc3d-d7dc-4d8e-aaaf-9c79a90654e5.json +1 -0
- package/dist/public/_nuxt/{diff.worker-CvsEE-qa.js → diff.worker-CjOQCDrL.js} +1 -1
- package/dist/public/_nuxt/entry.BrGSg7M5.css +1 -0
- package/dist/public/_nuxt/error-404.DW67vBSK.css +1 -0
- package/dist/public/_nuxt/error-500.pZFkQgH5.css +1 -0
- package/dist/public/_nuxt/packages.BSzke_vb.css +1 -0
- package/dist/public/_nuxt/qbQBI5vg.js +1 -0
- package/dist/public/_nuxt/{LBCmYgDk.js → uN6JDFSt.js} +1 -1
- package/dist/public/_nuxt/vpxPj2yJ.js +1 -0
- package/dist/public/index.html +1 -1
- package/package.json +10 -11
- package/dist/public/_nuxt/-nSv7b_c2.js +0 -1
- package/dist/public/_nuxt/BGfhRWSX.js +0 -1
- package/dist/public/_nuxt/BNZzKgvO.js +0 -7
- package/dist/public/_nuxt/BNrUSHd9.js +0 -1
- package/dist/public/_nuxt/BRoY9F4B.js +0 -1
- package/dist/public/_nuxt/Ba06j5HF.js +0 -1
- package/dist/public/_nuxt/BdES0TNB.js +0 -1
- package/dist/public/_nuxt/C4TkllWS.js +0 -1
- package/dist/public/_nuxt/C9xBafiu.js +0 -1
- package/dist/public/_nuxt/CGpzF1Fi.js +0 -1
- package/dist/public/_nuxt/CSmrzcuw.js +0 -1
- package/dist/public/_nuxt/CZ4Hed_B.js +0 -1
- package/dist/public/_nuxt/CiUxnt4q.js +0 -1
- package/dist/public/_nuxt/CwkL5c9p.js +0 -1
- package/dist/public/_nuxt/D0ELUVmr.js +0 -1
- package/dist/public/_nuxt/D2fxAMpL.js +0 -1
- package/dist/public/_nuxt/D5Xmlx1F.js +0 -1
- package/dist/public/_nuxt/D7E3leYJ.js +0 -1
- package/dist/public/_nuxt/DJiAfyJ9.js +0 -1
- package/dist/public/_nuxt/DS9O9jUU.js +0 -1
- package/dist/public/_nuxt/DYWABjKK.js +0 -1
- package/dist/public/_nuxt/DiwqOTKG.js +0 -1
- package/dist/public/_nuxt/DuyiIaXF.js +0 -1
- package/dist/public/_nuxt/FMlLtEkh.js +0 -1
- package/dist/public/_nuxt/I45WLXVn.js +0 -1
- package/dist/public/_nuxt/MF_ZggB1.js +0 -1
- package/dist/public/_nuxt/a5P2pi4b.js +0 -1
- package/dist/public/_nuxt/builds/meta/4b89da51-8485-4b1c-9d33-36610376f0b4.json +0 -1
- package/dist/public/_nuxt/entry.CuajcsxN.css +0 -1
- package/dist/public/_nuxt/error-404.3xPYxf32.css +0 -1
- package/dist/public/_nuxt/error-500.CUtwZWQI.css +0 -1
- package/dist/public/_nuxt/rtwgPkwM2.js +0 -1
- /package/dist/public/_nuxt/{DWG474Ej.js → B0JGLC34.js} +0 -0
- /package/dist/public/_nuxt/{tBStlNYu.js → BDNMzG2s.js} +0 -0
- /package/dist/public/_nuxt/{WhNLRjQY.js → BydIxJFY.js} +0 -0
- /package/dist/public/_nuxt/{BkPBhH2x.js → D2rOmk5_.js} +0 -0
- /package/dist/public/_nuxt/{DYINlKP5.js → TaF09Eka.js} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -3,58 +3,31 @@ import { createRequire } from "node:module";
|
|
|
3
3
|
import { defineRpcFunction } from "@vitejs/devtools-kit";
|
|
4
4
|
import fs, { existsSync } from "node:fs";
|
|
5
5
|
import process$1 from "node:process";
|
|
6
|
-
import { join } from "pathe";
|
|
7
|
-
import {
|
|
8
|
-
import { consoleReporter, createLogger, defineDiagnostics } from "logs-sdk";
|
|
9
|
-
import { ansiFormatter } from "logs-sdk/formatters/ansi";
|
|
6
|
+
import { basename, dirname, join } from "pathe";
|
|
7
|
+
import { defineDiagnostics, reporterLog } from "nostics";
|
|
10
8
|
import fs$1 from "node:fs/promises";
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
9
|
+
import { Buffer as Buffer$1 } from "node:buffer";
|
|
10
|
+
import { createHash } from "node:crypto";
|
|
11
|
+
import { parseToEvent } from "@rolldown/debug";
|
|
13
12
|
import { diffLines } from "diff";
|
|
14
13
|
//#region \0rolldown/runtime.js
|
|
15
14
|
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod), cb = null), mod.exports);
|
|
16
15
|
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
message: (p) => `JSON parse stream skip bad line ${p.line}: ${p.error}\n${p.preview}`,
|
|
27
|
-
level: "warn"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
})],
|
|
31
|
-
formatter: ansiFormatter(colors),
|
|
32
|
-
reporters: consoleReporter
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/node/diagnostics.ts
|
|
18
|
+
const diagnostics = defineDiagnostics({
|
|
19
|
+
docsBase: "https://devtools.vite.dev/errors",
|
|
20
|
+
reporters: [reporterLog],
|
|
21
|
+
codes: {
|
|
22
|
+
RDDT0001: { why: "Rolldown logs directory `.rolldown` not found, you might want to run build with `build.rolldownOptions.devtools` enabled first." },
|
|
23
|
+
RDDT0002: { why: (p) => `Rolldown log reader skipped bad line ${p.line}: ${p.error}\n${p.preview}` }
|
|
24
|
+
}
|
|
33
25
|
});
|
|
34
26
|
//#endregion
|
|
35
|
-
//#region src/node/utils/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
await pipeline(stream, split2(), async (source) => {
|
|
40
|
-
for await (const line of source) {
|
|
41
|
-
lineNumber += 1;
|
|
42
|
-
if (!line) continue;
|
|
43
|
-
try {
|
|
44
|
-
const parsed = JSON.parse(line);
|
|
45
|
-
const result = processor ? processor(parsed) : parsed;
|
|
46
|
-
values.push(result);
|
|
47
|
-
} catch (e) {
|
|
48
|
-
const preview = line.length > 256 ? `${line.slice(0, 256)}...` : line;
|
|
49
|
-
logger.RDDT0002({
|
|
50
|
-
line: lineNumber,
|
|
51
|
-
error: e.message,
|
|
52
|
-
preview
|
|
53
|
-
}).log();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
return values;
|
|
27
|
+
//#region src/node/utils/format.ts
|
|
28
|
+
function getContentByteSize(content) {
|
|
29
|
+
if (!content) return 0;
|
|
30
|
+
return Buffer$1.byteLength(content);
|
|
58
31
|
}
|
|
59
32
|
//#endregion
|
|
60
33
|
//#region src/shared/utils/guess-chunk-name.ts
|
|
@@ -93,12 +66,6 @@ function getInitialChunkIds(chunks) {
|
|
|
93
66
|
return initialChunkIds;
|
|
94
67
|
}
|
|
95
68
|
//#endregion
|
|
96
|
-
//#region src/node/utils/format.ts
|
|
97
|
-
function getContentByteSize(content) {
|
|
98
|
-
if (!content) return 0;
|
|
99
|
-
return new TextEncoder().encode(content).length;
|
|
100
|
-
}
|
|
101
|
-
//#endregion
|
|
102
69
|
//#region src/node/rolldown/events-manager.ts
|
|
103
70
|
const MODULE_BUILD_START_HOOKS = [
|
|
104
71
|
"HookResolveIdCallStart",
|
|
@@ -110,8 +77,29 @@ const MODULE_BUILD_END_HOOKS = [
|
|
|
110
77
|
"HookLoadCallEnd",
|
|
111
78
|
"HookTransformCallEnd"
|
|
112
79
|
];
|
|
80
|
+
function getContentInfo(content) {
|
|
81
|
+
if (!content) return { byteSize: 0 };
|
|
82
|
+
return { byteSize: getContentByteSize(content) };
|
|
83
|
+
}
|
|
84
|
+
function getContentRef(content) {
|
|
85
|
+
return typeof content === "string" && content.startsWith("$ref:") ? content.slice(5) : void 0;
|
|
86
|
+
}
|
|
87
|
+
function getEventId(event, index) {
|
|
88
|
+
return `${"timestamp" in event ? event.timestamp : "x"}#${index}`;
|
|
89
|
+
}
|
|
90
|
+
function getLastEventSnapshot(event) {
|
|
91
|
+
if (!("action" in event)) return event;
|
|
92
|
+
const snapshot = {
|
|
93
|
+
action: event.action,
|
|
94
|
+
event_id: event.event_id
|
|
95
|
+
};
|
|
96
|
+
if ("timestamp" in event) snapshot.timestamp = event.timestamp;
|
|
97
|
+
if ("session_id" in event) snapshot.session_id = event.session_id;
|
|
98
|
+
return snapshot;
|
|
99
|
+
}
|
|
113
100
|
var RolldownEventsManager = class {
|
|
114
|
-
|
|
101
|
+
eventCount = 0;
|
|
102
|
+
lastEvent;
|
|
115
103
|
chunks = /* @__PURE__ */ new Map();
|
|
116
104
|
assets = /* @__PURE__ */ new Map();
|
|
117
105
|
chunkAssetMap = /* @__PURE__ */ new Map();
|
|
@@ -122,18 +110,34 @@ var RolldownEventsManager = class {
|
|
|
122
110
|
plugin_build_metrics = /* @__PURE__ */ new Map();
|
|
123
111
|
build_start_time = 0;
|
|
124
112
|
build_end_time = 0;
|
|
125
|
-
|
|
126
|
-
if (key in event
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
113
|
+
getEventContentInfo(event, key) {
|
|
114
|
+
if (!(key in event)) return getContentInfo(void 0);
|
|
115
|
+
const content = event[key];
|
|
116
|
+
const refKey = getContentRef(content);
|
|
117
|
+
if (refKey) return this.source_refs.get(refKey) ?? getContentInfo(void 0);
|
|
118
|
+
return typeof content === "string" ? getContentInfo(content) : getContentInfo(void 0);
|
|
132
119
|
}
|
|
133
120
|
recordBuildMetrics(event) {
|
|
134
|
-
if (MODULE_BUILD_START_HOOKS.includes(event.action))
|
|
135
|
-
|
|
121
|
+
if (MODULE_BUILD_START_HOOKS.includes(event.action)) {
|
|
122
|
+
if (event.action === "HookResolveIdCallStart") this.module_build_hook_events.set(event.call_id, {
|
|
123
|
+
action: event.action,
|
|
124
|
+
timestamp: event.timestamp,
|
|
125
|
+
importer: event.importer,
|
|
126
|
+
module_request: event.module_request,
|
|
127
|
+
import_kind: event.import_kind
|
|
128
|
+
});
|
|
129
|
+
else if (event.action === "HookLoadCallStart") this.module_build_hook_events.set(event.call_id, {
|
|
130
|
+
action: event.action,
|
|
131
|
+
timestamp: event.timestamp
|
|
132
|
+
});
|
|
133
|
+
else if (event.action === "HookTransformCallStart") this.module_build_hook_events.set(event.call_id, {
|
|
134
|
+
action: event.action,
|
|
135
|
+
timestamp: event.timestamp,
|
|
136
|
+
contentInfo: this.getEventContentInfo(event, "content")
|
|
137
|
+
});
|
|
138
|
+
} else if (MODULE_BUILD_END_HOOKS.includes(event.action)) {
|
|
136
139
|
const start = this.module_build_hook_events.get(event.call_id);
|
|
140
|
+
this.module_build_hook_events.delete(event.call_id);
|
|
137
141
|
const module_id = event.action === "HookResolveIdCallEnd" ? event.resolved_id : event.module_id;
|
|
138
142
|
if (start) {
|
|
139
143
|
const pluginId = event.plugin_id;
|
|
@@ -156,6 +160,7 @@ var RolldownEventsManager = class {
|
|
|
156
160
|
calls: []
|
|
157
161
|
};
|
|
158
162
|
if (event.action === "HookResolveIdCallEnd") {
|
|
163
|
+
if (start.action !== "HookResolveIdCallStart") return;
|
|
159
164
|
module_build_metrics.resolve_ids.push({
|
|
160
165
|
...info,
|
|
161
166
|
type: "resolve",
|
|
@@ -170,10 +175,11 @@ var RolldownEventsManager = class {
|
|
|
170
175
|
module: start.module_request
|
|
171
176
|
});
|
|
172
177
|
} else if (event.action === "HookLoadCallEnd") {
|
|
178
|
+
if (start.action !== "HookLoadCallStart") return;
|
|
173
179
|
module_build_metrics.loads.push({
|
|
174
180
|
...info,
|
|
175
181
|
type: "load",
|
|
176
|
-
content:
|
|
182
|
+
content: null
|
|
177
183
|
});
|
|
178
184
|
plugin_build_metrics.calls.push({
|
|
179
185
|
...info,
|
|
@@ -182,21 +188,21 @@ var RolldownEventsManager = class {
|
|
|
182
188
|
unchanged: !event.content
|
|
183
189
|
});
|
|
184
190
|
} else if (event.action === "HookTransformCallEnd") {
|
|
185
|
-
|
|
186
|
-
const
|
|
191
|
+
if (start.action !== "HookTransformCallStart") return;
|
|
192
|
+
const sourceContentInfo = start.contentInfo;
|
|
193
|
+
const transformedContentInfo = this.getEventContentInfo(event, "content");
|
|
187
194
|
module_build_metrics.transforms.push({
|
|
188
195
|
...info,
|
|
189
196
|
type: "transform",
|
|
190
|
-
content_from:
|
|
191
|
-
content_to:
|
|
192
|
-
source_code_size:
|
|
193
|
-
transformed_code_size:
|
|
197
|
+
content_from: null,
|
|
198
|
+
content_to: null,
|
|
199
|
+
source_code_size: sourceContentInfo.byteSize,
|
|
200
|
+
transformed_code_size: transformedContentInfo.byteSize
|
|
194
201
|
});
|
|
195
202
|
plugin_build_metrics.calls.push({
|
|
196
203
|
...info,
|
|
197
204
|
type: "transform",
|
|
198
|
-
module: event.module_id
|
|
199
|
-
unchanged: _start.content === _end.content
|
|
205
|
+
module: event.module_id
|
|
200
206
|
});
|
|
201
207
|
}
|
|
202
208
|
this.plugin_build_metrics.set(pluginId, plugin_build_metrics);
|
|
@@ -205,15 +211,17 @@ var RolldownEventsManager = class {
|
|
|
205
211
|
}
|
|
206
212
|
}
|
|
207
213
|
handleEvent(raw) {
|
|
208
|
-
const event =
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
this.events.push(event);
|
|
214
|
+
const event = raw;
|
|
215
|
+
event.event_id = getEventId(raw, this.eventCount);
|
|
216
|
+
this.eventCount += 1;
|
|
217
|
+
this.lastEvent = getLastEventSnapshot(event);
|
|
213
218
|
if (event.action === "BuildStart") this.build_start_time = +event.timestamp;
|
|
214
|
-
if (event.action === "BuildEnd")
|
|
219
|
+
if (event.action === "BuildEnd") {
|
|
220
|
+
this.build_end_time = +event.timestamp;
|
|
221
|
+
if (!this.module_build_hook_events.size) this.source_refs.clear();
|
|
222
|
+
}
|
|
215
223
|
if (event.action === "StringRef") {
|
|
216
|
-
this.source_refs.set(event.id, event.content);
|
|
224
|
+
this.source_refs.set(event.id, getContentInfo(event.content));
|
|
217
225
|
return;
|
|
218
226
|
}
|
|
219
227
|
if (event.action === "ChunkGraphReady") {
|
|
@@ -225,7 +233,6 @@ var RolldownEventsManager = class {
|
|
|
225
233
|
});
|
|
226
234
|
return;
|
|
227
235
|
}
|
|
228
|
-
this.interpretSourceRefs(event, "content");
|
|
229
236
|
this.recordBuildMetrics(event);
|
|
230
237
|
if ("module_id" in event) {
|
|
231
238
|
if (this.modules.has(event.module_id)) return;
|
|
@@ -243,6 +250,7 @@ var RolldownEventsManager = class {
|
|
|
243
250
|
}
|
|
244
251
|
if (event.action === "ModuleGraphReady") {
|
|
245
252
|
this.module_build_hook_events.clear();
|
|
253
|
+
this.source_refs.clear();
|
|
246
254
|
for (const module of event.modules) {
|
|
247
255
|
this.modules.set(module.id, {
|
|
248
256
|
...module,
|
|
@@ -262,51 +270,1371 @@ var RolldownEventsManager = class {
|
|
|
262
270
|
return event;
|
|
263
271
|
}
|
|
264
272
|
dispose() {
|
|
265
|
-
this.
|
|
273
|
+
this.eventCount = 0;
|
|
274
|
+
this.lastEvent = void 0;
|
|
275
|
+
this.chunks.clear();
|
|
276
|
+
this.assets.clear();
|
|
277
|
+
this.chunkAssetMap.clear();
|
|
278
|
+
this.modules.clear();
|
|
279
|
+
this.source_refs.clear();
|
|
280
|
+
this.module_build_hook_events.clear();
|
|
281
|
+
this.module_build_metrics.clear();
|
|
282
|
+
this.plugin_build_metrics.clear();
|
|
283
|
+
this.build_start_time = 0;
|
|
284
|
+
this.build_end_time = 0;
|
|
285
|
+
}
|
|
286
|
+
snapshot() {
|
|
287
|
+
return {
|
|
288
|
+
eventCount: this.eventCount,
|
|
289
|
+
lastEvent: this.lastEvent,
|
|
290
|
+
chunks: Array.from(this.chunks.entries()),
|
|
291
|
+
modules: Array.from(this.modules.entries()).map(([id, module]) => {
|
|
292
|
+
const { build_metrics, ...snapshot } = module;
|
|
293
|
+
return [id, snapshot];
|
|
294
|
+
}),
|
|
295
|
+
source_refs: Array.from(this.source_refs.entries()),
|
|
296
|
+
module_build_hook_events: Array.from(this.module_build_hook_events.entries()),
|
|
297
|
+
module_build_metrics: Array.from(this.module_build_metrics.entries()),
|
|
298
|
+
plugin_build_metrics: Array.from(this.plugin_build_metrics.entries()),
|
|
299
|
+
build_start_time: this.build_start_time,
|
|
300
|
+
build_end_time: this.build_end_time
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
restore(snapshot) {
|
|
304
|
+
this.eventCount = snapshot.eventCount;
|
|
305
|
+
this.lastEvent = snapshot.lastEvent;
|
|
306
|
+
this.chunks = new Map(snapshot.chunks);
|
|
307
|
+
this.assets.clear();
|
|
308
|
+
this.chunkAssetMap.clear();
|
|
309
|
+
this.source_refs = new Map(snapshot.source_refs);
|
|
310
|
+
this.module_build_hook_events = new Map(snapshot.module_build_hook_events);
|
|
311
|
+
this.module_build_metrics = new Map(snapshot.module_build_metrics);
|
|
312
|
+
this.modules = new Map(snapshot.modules.map(([id, module]) => [id, {
|
|
313
|
+
...module,
|
|
314
|
+
build_metrics: this.module_build_metrics.get(id)
|
|
315
|
+
}]));
|
|
316
|
+
this.plugin_build_metrics = new Map(snapshot.plugin_build_metrics);
|
|
317
|
+
this.build_start_time = snapshot.build_start_time;
|
|
318
|
+
this.build_end_time = snapshot.build_end_time;
|
|
266
319
|
}
|
|
267
320
|
[Symbol.dispose]() {
|
|
268
321
|
this.dispose();
|
|
269
322
|
}
|
|
270
323
|
};
|
|
271
324
|
//#endregion
|
|
325
|
+
//#region src/node/rolldown/log-cache.ts
|
|
326
|
+
const ROLLDOWN_LOG_CACHE_DIR = ".cache";
|
|
327
|
+
const ROLLDOWN_LOG_SESSION_SUMMARY_CACHE_FILENAME = "session-summary.json";
|
|
328
|
+
const ROLLDOWN_LOG_READER_INDEX_CACHE_FILENAME = "reader-index.json";
|
|
329
|
+
const ROLLDOWN_LOG_PACKAGE_SUMMARY_CACHE_FILENAME = "package-summary.json";
|
|
330
|
+
const ROLLDOWN_LOG_PLUGIN_SUMMARY_CACHE_FILENAME = "plugin-summary.json";
|
|
331
|
+
const ROLLDOWN_LOG_MODULE_METRICS_SUMMARY_CACHE_FILENAME = "module-metrics-summary.json";
|
|
332
|
+
const ROLLDOWN_LOG_CACHE_VERSION = 1;
|
|
333
|
+
var RolldownLogCacheFile = class RolldownLogCacheFile {
|
|
334
|
+
filepath;
|
|
335
|
+
constructor(filepath) {
|
|
336
|
+
this.filepath = filepath;
|
|
337
|
+
}
|
|
338
|
+
static forLogFile(logFilepath, filename) {
|
|
339
|
+
if (basename(logFilepath) !== "logs.json") return void 0;
|
|
340
|
+
return new RolldownLogCacheFile(join(dirname(logFilepath), ROLLDOWN_LOG_CACHE_DIR, filename));
|
|
341
|
+
}
|
|
342
|
+
async read(stat) {
|
|
343
|
+
try {
|
|
344
|
+
const cache = JSON.parse(await fs$1.readFile(this.filepath, "utf8"));
|
|
345
|
+
if (!this.matches(stat, cache)) return void 0;
|
|
346
|
+
return cache.data;
|
|
347
|
+
} catch {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async write(stat, data) {
|
|
352
|
+
try {
|
|
353
|
+
const temporaryFilepath = `${this.filepath}.tmp`;
|
|
354
|
+
await fs$1.mkdir(dirname(this.filepath), { recursive: true });
|
|
355
|
+
await fs$1.writeFile(temporaryFilepath, JSON.stringify(this.createFile(stat, data)), "utf8");
|
|
356
|
+
await fs$1.rename(temporaryFilepath, this.filepath);
|
|
357
|
+
} catch {}
|
|
358
|
+
}
|
|
359
|
+
createFile(stat, data) {
|
|
360
|
+
return {
|
|
361
|
+
version: ROLLDOWN_LOG_CACHE_VERSION,
|
|
362
|
+
log: {
|
|
363
|
+
size: stat.size,
|
|
364
|
+
mtime: stat.mtime.getTime()
|
|
365
|
+
},
|
|
366
|
+
data
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
matches(stat, cache) {
|
|
370
|
+
return cache.version === ROLLDOWN_LOG_CACHE_VERSION && cache.log.size === stat.size && cache.log.mtime === stat.mtime.getTime();
|
|
371
|
+
}
|
|
372
|
+
};
|
|
373
|
+
function createMetricSummary() {
|
|
374
|
+
return {
|
|
375
|
+
count: 0,
|
|
376
|
+
duration: 0
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
function addMetricSummary(summary, duration) {
|
|
380
|
+
summary.count += 1;
|
|
381
|
+
summary.duration += duration;
|
|
382
|
+
}
|
|
383
|
+
function compactModuleBuildMetrics(metrics) {
|
|
384
|
+
const resolveDuration = metrics.resolve_ids.reduce((total, item) => total + item.duration, 0);
|
|
385
|
+
const loadDuration = metrics.loads.reduce((total, item) => total + item.duration, 0);
|
|
386
|
+
const transformDuration = metrics.transforms.reduce((total, item) => total + item.duration, 0);
|
|
387
|
+
const resolve_ids = metrics.resolve_ids.length ? [{
|
|
388
|
+
...metrics.resolve_ids[0],
|
|
389
|
+
id: "",
|
|
390
|
+
duration: resolveDuration,
|
|
391
|
+
timestamp_start: metrics.resolve_ids[0].timestamp_start,
|
|
392
|
+
timestamp_end: metrics.resolve_ids.at(-1).timestamp_end
|
|
393
|
+
}] : [];
|
|
394
|
+
const loads = metrics.loads.length ? [{
|
|
395
|
+
...metrics.loads[0],
|
|
396
|
+
id: "",
|
|
397
|
+
content: null,
|
|
398
|
+
duration: loadDuration,
|
|
399
|
+
timestamp_start: metrics.loads[0].timestamp_start,
|
|
400
|
+
timestamp_end: metrics.loads.at(-1).timestamp_end
|
|
401
|
+
}] : [];
|
|
402
|
+
const transformsByPlugin = /* @__PURE__ */ new Map();
|
|
403
|
+
let finalTransformedCodeSize = 0;
|
|
404
|
+
for (const transform of metrics.transforms) {
|
|
405
|
+
if (transform.transformed_code_size) finalTransformedCodeSize = transform.transformed_code_size;
|
|
406
|
+
if (!transform.transformed_code_size || transform.source_code_size === transform.transformed_code_size) continue;
|
|
407
|
+
const item = transformsByPlugin.get(transform.plugin_id);
|
|
408
|
+
if (item) {
|
|
409
|
+
item.duration += transform.duration;
|
|
410
|
+
item.timestamp_end = transform.timestamp_end;
|
|
411
|
+
item.transformed_code_size = transform.transformed_code_size;
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
transformsByPlugin.set(transform.plugin_id, {
|
|
415
|
+
...transform,
|
|
416
|
+
id: "",
|
|
417
|
+
content_from: null,
|
|
418
|
+
content_to: null
|
|
419
|
+
});
|
|
420
|
+
}
|
|
421
|
+
const transforms = Array.from(transformsByPlugin.values());
|
|
422
|
+
const remainingDuration = transformDuration - transforms.reduce((total, item) => total + item.duration, 0);
|
|
423
|
+
if (remainingDuration > 0 && metrics.transforms.length) transforms.push({
|
|
424
|
+
...metrics.transforms[0],
|
|
425
|
+
id: "",
|
|
426
|
+
plugin_name: "",
|
|
427
|
+
plugin_id: 0,
|
|
428
|
+
content_from: null,
|
|
429
|
+
content_to: null,
|
|
430
|
+
source_code_size: 0,
|
|
431
|
+
transformed_code_size: 0,
|
|
432
|
+
duration: remainingDuration,
|
|
433
|
+
timestamp_start: metrics.transforms[0].timestamp_start,
|
|
434
|
+
timestamp_end: metrics.transforms.at(-1).timestamp_end
|
|
435
|
+
});
|
|
436
|
+
if (finalTransformedCodeSize && metrics.transforms.length) transforms.push({
|
|
437
|
+
...metrics.transforms.at(-1),
|
|
438
|
+
id: "",
|
|
439
|
+
plugin_name: "",
|
|
440
|
+
plugin_id: 0,
|
|
441
|
+
content_from: null,
|
|
442
|
+
content_to: null,
|
|
443
|
+
source_code_size: finalTransformedCodeSize,
|
|
444
|
+
transformed_code_size: finalTransformedCodeSize,
|
|
445
|
+
duration: 0
|
|
446
|
+
});
|
|
447
|
+
return {
|
|
448
|
+
resolve_ids,
|
|
449
|
+
loads,
|
|
450
|
+
transforms
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
function createPluginBuildMetricsSummary(metrics) {
|
|
454
|
+
const summary = {
|
|
455
|
+
plugin_id: metrics.plugin_id,
|
|
456
|
+
plugin_name: metrics.plugin_name,
|
|
457
|
+
total: createMetricSummary(),
|
|
458
|
+
resolve: createMetricSummary(),
|
|
459
|
+
load: createMetricSummary(),
|
|
460
|
+
transform: createMetricSummary()
|
|
461
|
+
};
|
|
462
|
+
for (const call of metrics.calls) {
|
|
463
|
+
addMetricSummary(summary.total, call.duration);
|
|
464
|
+
if (call.type === "resolve") addMetricSummary(summary.resolve, call.duration);
|
|
465
|
+
else if (call.type === "load") addMetricSummary(summary.load, call.duration);
|
|
466
|
+
else if (call.type === "transform") addMetricSummary(summary.transform, call.duration);
|
|
467
|
+
}
|
|
468
|
+
return summary;
|
|
469
|
+
}
|
|
470
|
+
var RolldownLogCache = class {
|
|
471
|
+
sessionSummaryCache;
|
|
472
|
+
moduleMetricsSummaryCache;
|
|
473
|
+
pluginSummaryCache;
|
|
474
|
+
readerIndexCache;
|
|
475
|
+
packageSummaryCache;
|
|
476
|
+
completeSessionWriteAttempted = false;
|
|
477
|
+
summaryWriteAttempted = false;
|
|
478
|
+
packageSummaryWriteAttempted = false;
|
|
479
|
+
constructor(logFilepath, options) {
|
|
480
|
+
if (options.completeSession) {
|
|
481
|
+
this.sessionSummaryCache = RolldownLogCacheFile.forLogFile(logFilepath, ROLLDOWN_LOG_SESSION_SUMMARY_CACHE_FILENAME);
|
|
482
|
+
this.moduleMetricsSummaryCache = RolldownLogCacheFile.forLogFile(logFilepath, ROLLDOWN_LOG_MODULE_METRICS_SUMMARY_CACHE_FILENAME);
|
|
483
|
+
this.pluginSummaryCache = RolldownLogCacheFile.forLogFile(logFilepath, ROLLDOWN_LOG_PLUGIN_SUMMARY_CACHE_FILENAME);
|
|
484
|
+
this.readerIndexCache = RolldownLogCacheFile.forLogFile(logFilepath, ROLLDOWN_LOG_READER_INDEX_CACHE_FILENAME);
|
|
485
|
+
}
|
|
486
|
+
this.packageSummaryCache = RolldownLogCacheFile.forLogFile(logFilepath, ROLLDOWN_LOG_PACKAGE_SUMMARY_CACHE_FILENAME);
|
|
487
|
+
}
|
|
488
|
+
shouldWriteCompleteSession() {
|
|
489
|
+
return !this.completeSessionWriteAttempted;
|
|
490
|
+
}
|
|
491
|
+
shouldWritePackageSummary() {
|
|
492
|
+
return !this.packageSummaryWriteAttempted;
|
|
493
|
+
}
|
|
494
|
+
shouldWriteSummary() {
|
|
495
|
+
return !this.summaryWriteAttempted;
|
|
496
|
+
}
|
|
497
|
+
resetCompleteSessionWriteAttempt() {
|
|
498
|
+
this.completeSessionWriteAttempted = false;
|
|
499
|
+
this.summaryWriteAttempted = false;
|
|
500
|
+
}
|
|
501
|
+
resetSummaryWriteAttempt() {
|
|
502
|
+
this.summaryWriteAttempted = false;
|
|
503
|
+
}
|
|
504
|
+
resetPackageSummaryWriteAttempt() {
|
|
505
|
+
this.packageSummaryWriteAttempted = false;
|
|
506
|
+
}
|
|
507
|
+
async restoreCompleteSession(stat, state) {
|
|
508
|
+
if (state.lastBytes || state.manager.eventCount) return false;
|
|
509
|
+
const [sessionSummaryCache, moduleMetricsCache, pluginSummaryCacheExists, indexCache] = await Promise.all([
|
|
510
|
+
this.sessionSummaryCache?.read(stat),
|
|
511
|
+
this.moduleMetricsSummaryCache?.read(stat),
|
|
512
|
+
this.pluginSummaryCache?.read(stat),
|
|
513
|
+
this.readerIndexCache?.read(stat)
|
|
514
|
+
]);
|
|
515
|
+
if (!sessionSummaryCache || !moduleMetricsCache || !pluginSummaryCacheExists || !indexCache) return false;
|
|
516
|
+
if (sessionSummaryCache.reader.lastBytes !== stat.size || indexCache.reader.lastBytes !== stat.size) return false;
|
|
517
|
+
this.restoreSessionSnapshot(sessionSummaryCache, state, moduleMetricsCache);
|
|
518
|
+
this.restoreReaderIndexSnapshot(indexCache, state);
|
|
519
|
+
this.completeSessionWriteAttempted = true;
|
|
520
|
+
this.summaryWriteAttempted = true;
|
|
521
|
+
return true;
|
|
522
|
+
}
|
|
523
|
+
async restoreSummary(stat, state) {
|
|
524
|
+
if (state.lastBytes || state.manager.eventCount) return false;
|
|
525
|
+
const [sessionSummaryCache, moduleMetricsCache, _pluginSummaryCache, indexCache] = await Promise.all([
|
|
526
|
+
this.sessionSummaryCache?.read(stat),
|
|
527
|
+
this.moduleMetricsSummaryCache?.read(stat),
|
|
528
|
+
this.pluginSummaryCache?.read(stat),
|
|
529
|
+
this.readerIndexCache?.read(stat)
|
|
530
|
+
]);
|
|
531
|
+
if (!sessionSummaryCache) return false;
|
|
532
|
+
if (sessionSummaryCache.reader.lastBytes !== stat.size) return false;
|
|
533
|
+
this.restoreSessionSnapshot(sessionSummaryCache, state, moduleMetricsCache);
|
|
534
|
+
const hasCompleteCache = !!moduleMetricsCache && !!_pluginSummaryCache && !!indexCache;
|
|
535
|
+
if (indexCache?.reader.lastBytes === stat.size) this.restoreReaderIndexSnapshot(indexCache, state);
|
|
536
|
+
else this.clearReaderIndexState(state);
|
|
537
|
+
this.summaryWriteAttempted = true;
|
|
538
|
+
this.completeSessionWriteAttempted = hasCompleteCache;
|
|
539
|
+
return hasCompleteCache ? "complete" : "summary";
|
|
540
|
+
}
|
|
541
|
+
async restorePackageSummary(stat, state) {
|
|
542
|
+
if (state.manager.eventCount) return false;
|
|
543
|
+
const cache = await this.packageSummaryCache?.read(stat);
|
|
544
|
+
if (!cache) return false;
|
|
545
|
+
if (cache.packageSummaryTimestamp !== stat.mtime.getTime()) return false;
|
|
546
|
+
this.restorePackageSummarySnapshot(cache, state);
|
|
547
|
+
this.packageSummaryWriteAttempted = true;
|
|
548
|
+
return true;
|
|
549
|
+
}
|
|
550
|
+
async writeCompleteSession(stat, state) {
|
|
551
|
+
this.completeSessionWriteAttempted = true;
|
|
552
|
+
this.summaryWriteAttempted = true;
|
|
553
|
+
await Promise.all([
|
|
554
|
+
this.sessionSummaryCache?.write(stat, this.createSessionSummarySnapshot(state)),
|
|
555
|
+
this.moduleMetricsSummaryCache?.write(stat, this.createModuleMetricsSummarySnapshot(state)),
|
|
556
|
+
this.pluginSummaryCache?.write(stat, this.createPluginSummarySnapshot(state)),
|
|
557
|
+
this.readerIndexCache?.write(stat, this.createReaderIndexSnapshot(state))
|
|
558
|
+
]);
|
|
559
|
+
}
|
|
560
|
+
async writeSummary(stat, state) {
|
|
561
|
+
this.summaryWriteAttempted = true;
|
|
562
|
+
await Promise.all([
|
|
563
|
+
this.sessionSummaryCache?.write(stat, this.createSessionSummarySnapshot(state)),
|
|
564
|
+
this.moduleMetricsSummaryCache?.write(stat, this.createModuleMetricsSummarySnapshot(state)),
|
|
565
|
+
this.pluginSummaryCache?.write(stat, this.createPluginSummarySnapshot(state)),
|
|
566
|
+
this.readerIndexCache?.write(stat, this.createReaderIndexSnapshot(state))
|
|
567
|
+
]);
|
|
568
|
+
}
|
|
569
|
+
async writePackageSummary(stat, state) {
|
|
570
|
+
this.packageSummaryWriteAttempted = true;
|
|
571
|
+
await this.packageSummaryCache?.write(stat, this.createPackageSummarySnapshot(state));
|
|
572
|
+
}
|
|
573
|
+
createSessionSummarySnapshot(state) {
|
|
574
|
+
const manager = state.manager.snapshot();
|
|
575
|
+
return {
|
|
576
|
+
reader: {
|
|
577
|
+
lastBytes: state.lastBytes,
|
|
578
|
+
lastTimestamp: state.lastTimestamp,
|
|
579
|
+
lineNumber: state.lineNumber
|
|
580
|
+
},
|
|
581
|
+
meta: state.meta,
|
|
582
|
+
manager: {
|
|
583
|
+
eventCount: manager.eventCount,
|
|
584
|
+
lastEvent: manager.lastEvent,
|
|
585
|
+
chunks: manager.chunks,
|
|
586
|
+
modules: manager.modules,
|
|
587
|
+
build_start_time: manager.build_start_time,
|
|
588
|
+
build_end_time: manager.build_end_time
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
createModuleMetricsSummarySnapshot(state) {
|
|
593
|
+
return { metrics: state.manager.snapshot().module_build_metrics.map(([module, metrics]) => [module, compactModuleBuildMetrics(metrics)]) };
|
|
594
|
+
}
|
|
595
|
+
createPluginSummarySnapshot(state) {
|
|
596
|
+
return { plugins: state.manager.snapshot().plugin_build_metrics.map(([pluginId, metrics]) => [pluginId, createPluginBuildMetricsSummary(metrics)]) };
|
|
597
|
+
}
|
|
598
|
+
createReaderIndexSnapshot(state) {
|
|
599
|
+
return { reader: {
|
|
600
|
+
lastBytes: state.lastBytes,
|
|
601
|
+
lastTimestamp: state.lastTimestamp,
|
|
602
|
+
moduleEventIndex: Array.from(state.moduleEventIndex.entries()).map(([module, index]) => [module, {
|
|
603
|
+
resolveIds: Array.from(index.resolveIds.entries()),
|
|
604
|
+
loads: Array.from(index.loads.entries()),
|
|
605
|
+
transforms: Array.from(index.transforms.entries())
|
|
606
|
+
}]),
|
|
607
|
+
stringRefIndex: Array.from(state.stringRefIndex.entries()),
|
|
608
|
+
pendingHookCallStarts: Array.from(state.pendingHookCallStarts.entries()),
|
|
609
|
+
assetsReadyLocations: state.assetsReadyLocations
|
|
610
|
+
} };
|
|
611
|
+
}
|
|
612
|
+
createPackageSummarySnapshot(state) {
|
|
613
|
+
return {
|
|
614
|
+
packageSummaryTimestamp: state.packageSummaryTimestamp,
|
|
615
|
+
manager: state.manager.snapshot()
|
|
616
|
+
};
|
|
617
|
+
}
|
|
618
|
+
restoreSessionSnapshot(session, state, moduleMetrics) {
|
|
619
|
+
state.lastBytes = session.reader.lastBytes;
|
|
620
|
+
state.lastTimestamp = session.reader.lastTimestamp;
|
|
621
|
+
state.lineNumber = session.reader.lineNumber;
|
|
622
|
+
state.meta = session.meta;
|
|
623
|
+
state.metricsSummaryOnly = true;
|
|
624
|
+
state.manager.restore({
|
|
625
|
+
eventCount: session.manager.eventCount,
|
|
626
|
+
lastEvent: session.manager.lastEvent,
|
|
627
|
+
chunks: session.manager.chunks,
|
|
628
|
+
modules: session.manager.modules,
|
|
629
|
+
source_refs: [],
|
|
630
|
+
module_build_hook_events: [],
|
|
631
|
+
module_build_metrics: moduleMetrics?.metrics ?? [],
|
|
632
|
+
plugin_build_metrics: [],
|
|
633
|
+
build_start_time: session.manager.build_start_time,
|
|
634
|
+
build_end_time: session.manager.build_end_time
|
|
635
|
+
});
|
|
636
|
+
}
|
|
637
|
+
restoreReaderIndexSnapshot(snapshot, state) {
|
|
638
|
+
state.moduleEventIndex = new Map(snapshot.reader.moduleEventIndex.map(([module, item]) => [module, {
|
|
639
|
+
resolveIds: new Map(item.resolveIds),
|
|
640
|
+
loads: new Map(item.loads),
|
|
641
|
+
transforms: new Map(item.transforms)
|
|
642
|
+
}]));
|
|
643
|
+
state.stringRefIndex = new Map(snapshot.reader.stringRefIndex);
|
|
644
|
+
state.pendingHookCallStarts = new Map(snapshot.reader.pendingHookCallStarts);
|
|
645
|
+
state.assetsReadyLocations = snapshot.reader.assetsReadyLocations;
|
|
646
|
+
}
|
|
647
|
+
restorePackageSummarySnapshot(snapshot, state) {
|
|
648
|
+
state.manager.restore(snapshot.manager);
|
|
649
|
+
state.packageSummaryTimestamp = snapshot.packageSummaryTimestamp;
|
|
650
|
+
}
|
|
651
|
+
clearReaderIndexState(state) {
|
|
652
|
+
state.moduleEventIndex = /* @__PURE__ */ new Map();
|
|
653
|
+
state.stringRefIndex = /* @__PURE__ */ new Map();
|
|
654
|
+
state.pendingHookCallStarts = /* @__PURE__ */ new Map();
|
|
655
|
+
state.assetsReadyLocations = [];
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
//#endregion
|
|
272
659
|
//#region src/node/rolldown/events-reader.ts
|
|
273
660
|
const readers = /* @__PURE__ */ new Map();
|
|
661
|
+
const MAX_READERS = 32;
|
|
662
|
+
const MAX_MODULE_METRICS_CACHE = 32;
|
|
663
|
+
const MAX_MODULE_METRICS_CACHE_BYTES = 64 * 1024 * 1024;
|
|
664
|
+
const READ_STREAM_HIGH_WATER_MARK = 1024 * 1024;
|
|
665
|
+
const LINE_FEED = "\n".charCodeAt(0);
|
|
666
|
+
const CARRIAGE_RETURN = "\r".charCodeAt(0);
|
|
667
|
+
const ACTION_PREVIEW_BYTES = 512;
|
|
668
|
+
const PACKAGE_SUMMARY_MAX_PARSED_LINE_BYTES = 1024 * 1024;
|
|
669
|
+
const PACKAGE_SUMMARY_ACTIONS = new Set([
|
|
670
|
+
"ChunkGraphReady",
|
|
671
|
+
"HookTransformCallEnd",
|
|
672
|
+
"ModuleGraphReady",
|
|
673
|
+
"StringRef"
|
|
674
|
+
]);
|
|
675
|
+
const PACKAGE_SUMMARY_LARGE_LINE_ACTIONS = new Set(["HookTransformCallEnd", "StringRef"]);
|
|
676
|
+
function getDeferredContent(event, refs) {
|
|
677
|
+
if (typeof event.content !== "string") return {
|
|
678
|
+
value: null,
|
|
679
|
+
ref: null
|
|
680
|
+
};
|
|
681
|
+
const ref = getContentRef(event.content);
|
|
682
|
+
if (ref) {
|
|
683
|
+
refs.add(ref);
|
|
684
|
+
return {
|
|
685
|
+
value: null,
|
|
686
|
+
ref
|
|
687
|
+
};
|
|
688
|
+
}
|
|
689
|
+
return {
|
|
690
|
+
value: event.content,
|
|
691
|
+
ref: null
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
function resolveDeferredContent(content, refs) {
|
|
695
|
+
if (content.ref) return refs.get(content.ref) ?? `$ref:${content.ref}`;
|
|
696
|
+
return content.value;
|
|
697
|
+
}
|
|
698
|
+
function cloneModuleBuildMetrics(metrics) {
|
|
699
|
+
return {
|
|
700
|
+
resolve_ids: metrics.resolve_ids.map((item) => ({ ...item })),
|
|
701
|
+
loads: metrics.loads.map((item) => ({ ...item })),
|
|
702
|
+
transforms: metrics.transforms.map((item) => ({ ...item }))
|
|
703
|
+
};
|
|
704
|
+
}
|
|
705
|
+
function getContentCacheBytes(content) {
|
|
706
|
+
return content ? getContentByteSize(content) : 0;
|
|
707
|
+
}
|
|
708
|
+
function getContentHash(content) {
|
|
709
|
+
return createHash("sha1").update(content ?? "").digest("hex");
|
|
710
|
+
}
|
|
711
|
+
function getModuleBuildMetricsCacheBytes(metrics) {
|
|
712
|
+
return metrics.loads.reduce((total, load) => total + getContentCacheBytes(load.content), 0) + metrics.transforms.reduce((total, transform) => total + getContentCacheBytes(transform.content_from) + getContentCacheBytes(transform.content_to), 0);
|
|
713
|
+
}
|
|
714
|
+
function isPromiseLike(value) {
|
|
715
|
+
return !!value && typeof value.then === "function";
|
|
716
|
+
}
|
|
717
|
+
function stripLineEnd(line) {
|
|
718
|
+
if (line.at(-1) === CARRIAGE_RETURN) return line.subarray(0, -1).toString("utf8");
|
|
719
|
+
return line.toString("utf8");
|
|
720
|
+
}
|
|
721
|
+
function appendPreview(preview, segment) {
|
|
722
|
+
if (preview.length >= ACTION_PREVIEW_BYTES || !segment.length) return preview;
|
|
723
|
+
const remaining = ACTION_PREVIEW_BYTES - preview.length;
|
|
724
|
+
const next = segment.subarray(0, Math.min(remaining, segment.length));
|
|
725
|
+
return preview.length ? Buffer$1.concat([preview, next], preview.length + next.length) : Buffer$1.from(next);
|
|
726
|
+
}
|
|
727
|
+
function getPreviewAction(preview) {
|
|
728
|
+
return preview.toString("utf8").match(/"action":"([^"]+)"/)?.[1];
|
|
729
|
+
}
|
|
730
|
+
function getReferencedContentByteSize(content, refs) {
|
|
731
|
+
if (typeof content !== "string") return 0;
|
|
732
|
+
const ref = getContentRef(content);
|
|
733
|
+
if (ref) return refs.get(ref) ?? 0;
|
|
734
|
+
return getContentByteSize(content);
|
|
735
|
+
}
|
|
736
|
+
function getPreviewStringValue(preview, key) {
|
|
737
|
+
const match = preview.toString("utf8").match(new RegExp(`"${key}":"((?:\\\\.|[^"])*)"`));
|
|
738
|
+
if (!match) return void 0;
|
|
739
|
+
try {
|
|
740
|
+
return JSON.parse(`"${match[1]}"`);
|
|
741
|
+
} catch {
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
function estimateContentByteSizeFromLine(preview, location) {
|
|
746
|
+
const marker = Buffer$1.from("\"content\":\"");
|
|
747
|
+
const index = preview.indexOf(marker);
|
|
748
|
+
if (index === -1) return 0;
|
|
749
|
+
const contentStart = index + marker.length;
|
|
750
|
+
return Math.max(0, location.length - contentStart - 128);
|
|
751
|
+
}
|
|
752
|
+
function pruneReaders() {
|
|
753
|
+
if (readers.size <= MAX_READERS) return;
|
|
754
|
+
for (const reader of Array.from(readers.values())) {
|
|
755
|
+
if (readers.size <= MAX_READERS) return;
|
|
756
|
+
if (!reader.hasPendingRead()) reader.dispose();
|
|
757
|
+
}
|
|
758
|
+
}
|
|
274
759
|
var RolldownEventsReader = class RolldownEventsReader {
|
|
275
760
|
filepath;
|
|
761
|
+
cacheKey;
|
|
276
762
|
lastBytes = 0;
|
|
277
763
|
lastTimestamp = 0;
|
|
278
764
|
manager = new RolldownEventsManager();
|
|
279
765
|
meta;
|
|
280
766
|
pendingRead;
|
|
281
|
-
|
|
767
|
+
pendingSummaryRead;
|
|
768
|
+
lineNumber = 0;
|
|
769
|
+
moduleEventIndex = /* @__PURE__ */ new Map();
|
|
770
|
+
stringRefIndex = /* @__PURE__ */ new Map();
|
|
771
|
+
pendingHookCallStarts = /* @__PURE__ */ new Map();
|
|
772
|
+
moduleMetricsCache = /* @__PURE__ */ new Map();
|
|
773
|
+
moduleMetricsCacheBytes = 0;
|
|
774
|
+
pendingModuleMetrics = /* @__PURE__ */ new Map();
|
|
775
|
+
assetsReadyLocations = [];
|
|
776
|
+
assetsHydrated = false;
|
|
777
|
+
pendingPackageSummaryRead;
|
|
778
|
+
packageSummaryTimestamp = 0;
|
|
779
|
+
summaryOnly = false;
|
|
780
|
+
packageSummaryOnly = false;
|
|
781
|
+
metricsSummaryOnly = false;
|
|
782
|
+
logCache;
|
|
783
|
+
constructor(filepath, cacheKey = filepath) {
|
|
282
784
|
this.filepath = filepath;
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
readers.
|
|
785
|
+
this.cacheKey = cacheKey;
|
|
786
|
+
this.logCache = new RolldownLogCache(filepath, { completeSession: cacheKey === filepath });
|
|
787
|
+
}
|
|
788
|
+
static get(filepath, cacheKey = filepath) {
|
|
789
|
+
if (readers.has(cacheKey)) {
|
|
790
|
+
const reader = readers.get(cacheKey);
|
|
791
|
+
readers.delete(cacheKey);
|
|
792
|
+
readers.set(cacheKey, reader);
|
|
793
|
+
return reader;
|
|
794
|
+
}
|
|
795
|
+
const reader = new RolldownEventsReader(filepath, cacheKey);
|
|
796
|
+
readers.set(cacheKey, reader);
|
|
797
|
+
pruneReaders();
|
|
288
798
|
return reader;
|
|
289
799
|
}
|
|
800
|
+
static peek(filepath, cacheKey = filepath) {
|
|
801
|
+
return readers.get(cacheKey);
|
|
802
|
+
}
|
|
290
803
|
async read() {
|
|
291
804
|
if (this.pendingRead) return this.pendingRead;
|
|
805
|
+
if (this.pendingSummaryRead) await this.pendingSummaryRead;
|
|
292
806
|
this.pendingRead = this.readChanges().finally(() => {
|
|
293
807
|
this.pendingRead = void 0;
|
|
294
808
|
});
|
|
295
809
|
return this.pendingRead;
|
|
296
810
|
}
|
|
811
|
+
async readSummary() {
|
|
812
|
+
if (this.pendingRead) return this.pendingRead;
|
|
813
|
+
if (this.pendingSummaryRead) return this.pendingSummaryRead;
|
|
814
|
+
this.pendingSummaryRead = this.readSummaryChanges().finally(() => {
|
|
815
|
+
this.pendingSummaryRead = void 0;
|
|
816
|
+
});
|
|
817
|
+
return this.pendingSummaryRead;
|
|
818
|
+
}
|
|
297
819
|
async readChanges() {
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
820
|
+
const stat = await fs.promises.stat(this.filepath);
|
|
821
|
+
const mtime = stat.mtime.getTime();
|
|
822
|
+
if (this.summaryOnly || this.packageSummaryOnly) this.resetReadState();
|
|
823
|
+
if (await this.logCache.restoreCompleteSession(stat, this.createLogCacheState())) {
|
|
824
|
+
this.clearModuleMetricsCache();
|
|
825
|
+
this.pendingModuleMetrics.clear();
|
|
826
|
+
this.summaryOnly = false;
|
|
827
|
+
this.packageSummaryOnly = false;
|
|
828
|
+
this.assetsHydrated = false;
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
if (mtime <= this.lastTimestamp) {
|
|
832
|
+
if (this.hasCompleteSession() && this.logCache.shouldWriteCompleteSession()) await this.logCache.writeCompleteSession(stat, this.createLogCacheState());
|
|
833
|
+
return;
|
|
834
|
+
}
|
|
835
|
+
let changed = false;
|
|
836
|
+
await this.readEventLines(this.lastBytes, (event, location) => {
|
|
837
|
+
changed = true;
|
|
838
|
+
if (event.action === "SessionMeta") this.meta = event;
|
|
839
|
+
this.manager.handleEvent(event);
|
|
840
|
+
this.indexEvent(event, location);
|
|
841
|
+
}, {
|
|
842
|
+
skipAction: "AssetsReady",
|
|
843
|
+
onSkippedLine: (line) => this.recordAssetsReadyLocation(line)
|
|
844
|
+
});
|
|
845
|
+
if (changed) {
|
|
846
|
+
this.clearModuleMetricsCache();
|
|
847
|
+
this.pendingModuleMetrics.clear();
|
|
848
|
+
this.logCache.resetCompleteSessionWriteAttempt();
|
|
849
|
+
}
|
|
850
|
+
this.lastTimestamp = mtime;
|
|
851
|
+
this.lastBytes = stat.size;
|
|
852
|
+
this.metricsSummaryOnly = false;
|
|
853
|
+
await this.logCache.writeCompleteSession(stat, this.createLogCacheState());
|
|
854
|
+
}
|
|
855
|
+
async readSummaryChanges() {
|
|
856
|
+
const stat = await fs.promises.stat(this.filepath);
|
|
857
|
+
const mtime = stat.mtime.getTime();
|
|
858
|
+
if (this.manager.eventCount && mtime <= this.lastTimestamp) {
|
|
859
|
+
if (this.logCache.shouldWriteSummary()) await this.logCache.writeSummary(stat, this.createLogCacheState());
|
|
860
|
+
return;
|
|
861
|
+
}
|
|
862
|
+
const restoredSummary = await this.logCache.restoreSummary(stat, this.createLogCacheState());
|
|
863
|
+
if (restoredSummary) {
|
|
864
|
+
this.clearModuleMetricsCache();
|
|
865
|
+
this.pendingModuleMetrics.clear();
|
|
866
|
+
this.summaryOnly = restoredSummary !== "complete";
|
|
867
|
+
this.packageSummaryOnly = false;
|
|
868
|
+
this.assetsHydrated = false;
|
|
869
|
+
return;
|
|
870
|
+
}
|
|
871
|
+
if (this.manager.eventCount || this.lastBytes) this.resetReadState();
|
|
872
|
+
let changed = false;
|
|
873
|
+
await this.readEventLines(0, (event, location) => {
|
|
874
|
+
changed = true;
|
|
875
|
+
if (event.action === "SessionMeta") this.meta = event;
|
|
301
876
|
this.manager.handleEvent(event);
|
|
302
|
-
|
|
877
|
+
this.indexEvent(event, location);
|
|
878
|
+
}, {
|
|
879
|
+
skipAction: "AssetsReady",
|
|
880
|
+
onSkippedLine: (line) => this.recordAssetsReadyLocation(line)
|
|
881
|
+
});
|
|
882
|
+
if (changed) {
|
|
883
|
+
this.clearModuleMetricsCache();
|
|
884
|
+
this.pendingModuleMetrics.clear();
|
|
885
|
+
this.logCache.resetSummaryWriteAttempt();
|
|
886
|
+
}
|
|
887
|
+
this.lastTimestamp = mtime;
|
|
888
|
+
this.lastBytes = stat.size;
|
|
889
|
+
this.summaryOnly = false;
|
|
890
|
+
this.packageSummaryOnly = false;
|
|
891
|
+
this.metricsSummaryOnly = false;
|
|
892
|
+
await this.logCache.writeSummary(stat, this.createLogCacheState());
|
|
893
|
+
}
|
|
894
|
+
async readEventLines(start, processor, options = {}) {
|
|
895
|
+
const stream = fs.createReadStream(this.filepath, {
|
|
896
|
+
start,
|
|
897
|
+
highWaterMark: READ_STREAM_HIGH_WATER_MARK
|
|
898
|
+
});
|
|
899
|
+
let absoluteOffset = start;
|
|
900
|
+
let lineStartOffset = start;
|
|
901
|
+
let parts = [];
|
|
902
|
+
let partsLength = 0;
|
|
903
|
+
let preview = Buffer$1.alloc(0);
|
|
904
|
+
let skipCurrentLine = false;
|
|
905
|
+
let lineAction;
|
|
906
|
+
const processLine = async (line, location) => {
|
|
907
|
+
this.lineNumber += 1;
|
|
908
|
+
const text = stripLineEnd(line);
|
|
909
|
+
if (!text) return;
|
|
910
|
+
try {
|
|
911
|
+
const result = processor(parseToEvent(text), location);
|
|
912
|
+
if (isPromiseLike(result)) await result;
|
|
913
|
+
} catch (e) {
|
|
914
|
+
const preview = text.length > 256 ? `${text.slice(0, 256)}...` : text;
|
|
915
|
+
diagnostics.RDDT0002({
|
|
916
|
+
line: this.lineNumber,
|
|
917
|
+
error: e.message,
|
|
918
|
+
preview
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
};
|
|
922
|
+
const appendSegmentPreview = (segment) => {
|
|
923
|
+
if (skipCurrentLine) return;
|
|
924
|
+
preview = appendPreview(preview, segment);
|
|
925
|
+
lineAction = lineAction ?? getPreviewAction(preview);
|
|
926
|
+
const lineBytes = partsLength + segment.length;
|
|
927
|
+
if (lineAction && (options.skipAction === lineAction || options.onlyActions && !options.onlyActions.has(lineAction) || options.maxLineBytes != null && lineBytes > options.maxLineBytes && !!options.largeLineActions?.has(lineAction))) {
|
|
928
|
+
skipCurrentLine = true;
|
|
929
|
+
parts = [];
|
|
930
|
+
partsLength = 0;
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
const processSkippedLine = (location) => {
|
|
934
|
+
this.lineNumber += 1;
|
|
935
|
+
options.onSkippedLine?.({
|
|
936
|
+
action: lineAction,
|
|
937
|
+
location,
|
|
938
|
+
preview
|
|
939
|
+
});
|
|
940
|
+
};
|
|
941
|
+
const resetLine = (nextLineStartOffset) => {
|
|
942
|
+
parts = [];
|
|
943
|
+
partsLength = 0;
|
|
944
|
+
preview = Buffer$1.alloc(0);
|
|
945
|
+
skipCurrentLine = false;
|
|
946
|
+
lineAction = void 0;
|
|
947
|
+
lineStartOffset = nextLineStartOffset;
|
|
948
|
+
};
|
|
949
|
+
for await (const chunk of stream) {
|
|
950
|
+
const buffer = Buffer$1.isBuffer(chunk) ? chunk : Buffer$1.from(chunk);
|
|
951
|
+
let segmentStart = 0;
|
|
952
|
+
let newline = buffer.indexOf(LINE_FEED);
|
|
953
|
+
while (newline !== -1) {
|
|
954
|
+
const segment = buffer.subarray(segmentStart, newline);
|
|
955
|
+
if (!partsLength && !preview.length) lineStartOffset = absoluteOffset + segmentStart;
|
|
956
|
+
appendSegmentPreview(segment);
|
|
957
|
+
const location = {
|
|
958
|
+
offset: lineStartOffset,
|
|
959
|
+
length: absoluteOffset + newline + 1 - lineStartOffset
|
|
960
|
+
};
|
|
961
|
+
if (skipCurrentLine) processSkippedLine(location);
|
|
962
|
+
else {
|
|
963
|
+
let line = segment;
|
|
964
|
+
if (partsLength) {
|
|
965
|
+
parts.push(segment);
|
|
966
|
+
line = Buffer$1.concat(parts, partsLength + segment.length);
|
|
967
|
+
}
|
|
968
|
+
await processLine(line, location);
|
|
969
|
+
}
|
|
970
|
+
segmentStart = newline + 1;
|
|
971
|
+
resetLine(absoluteOffset + segmentStart);
|
|
972
|
+
newline = buffer.indexOf(LINE_FEED, segmentStart);
|
|
973
|
+
}
|
|
974
|
+
if (segmentStart < buffer.length) {
|
|
975
|
+
if (!partsLength && !preview.length) lineStartOffset = absoluteOffset + segmentStart;
|
|
976
|
+
const tail = buffer.subarray(segmentStart);
|
|
977
|
+
appendSegmentPreview(tail);
|
|
978
|
+
if (!skipCurrentLine) {
|
|
979
|
+
parts.push(tail);
|
|
980
|
+
partsLength += tail.length;
|
|
981
|
+
}
|
|
982
|
+
}
|
|
983
|
+
absoluteOffset += buffer.length;
|
|
984
|
+
}
|
|
985
|
+
if (skipCurrentLine) processSkippedLine({
|
|
986
|
+
offset: lineStartOffset,
|
|
987
|
+
length: absoluteOffset - lineStartOffset
|
|
988
|
+
});
|
|
989
|
+
else if (partsLength) await processLine(Buffer$1.concat(parts, partsLength), {
|
|
990
|
+
offset: lineStartOffset,
|
|
991
|
+
length: partsLength
|
|
303
992
|
});
|
|
304
|
-
|
|
305
|
-
|
|
993
|
+
}
|
|
994
|
+
async readAssets() {
|
|
995
|
+
await this.read();
|
|
996
|
+
if (this.assetsHydrated) return;
|
|
997
|
+
this.manager.assets.clear();
|
|
998
|
+
this.manager.chunkAssetMap.clear();
|
|
999
|
+
const events = await this.readEventsAt(this.assetsReadyLocations);
|
|
1000
|
+
for (const event of events) if (event?.action === "AssetsReady") this.manager.handleEvent(event);
|
|
1001
|
+
this.assetsHydrated = true;
|
|
1002
|
+
}
|
|
1003
|
+
recordAssetsReadyLocation(line) {
|
|
1004
|
+
if (line.action !== "AssetsReady") return;
|
|
1005
|
+
this.assetsReadyLocations.push(line.location);
|
|
1006
|
+
this.assetsHydrated = false;
|
|
1007
|
+
}
|
|
1008
|
+
async readPackageSummary() {
|
|
1009
|
+
if (this.pendingPackageSummaryRead) return this.pendingPackageSummaryRead;
|
|
1010
|
+
this.pendingPackageSummaryRead = this.readPackageSummaryChanges().finally(() => {
|
|
1011
|
+
this.pendingPackageSummaryRead = void 0;
|
|
1012
|
+
});
|
|
1013
|
+
return this.pendingPackageSummaryRead;
|
|
1014
|
+
}
|
|
1015
|
+
async ensurePackageSummaryCache() {
|
|
1016
|
+
const stat = await fs.promises.stat(this.filepath);
|
|
1017
|
+
this.packageSummaryTimestamp = stat.mtime.getTime();
|
|
1018
|
+
if (this.logCache.shouldWritePackageSummary()) await this.logCache.writePackageSummary(stat, this.createLogCacheState());
|
|
1019
|
+
}
|
|
1020
|
+
async readPackageSummaryChanges() {
|
|
1021
|
+
const stat = await fs.promises.stat(this.filepath);
|
|
1022
|
+
const mtime = stat.mtime.getTime();
|
|
1023
|
+
if (mtime <= this.packageSummaryTimestamp) {
|
|
1024
|
+
if (this.packageSummaryOnly && this.logCache.shouldWritePackageSummary()) await this.logCache.writePackageSummary(stat, this.createLogCacheState());
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
if (await this.logCache.restorePackageSummary(stat, this.createLogCacheState())) {
|
|
1028
|
+
this.clearModuleMetricsCache();
|
|
1029
|
+
this.pendingModuleMetrics.clear();
|
|
1030
|
+
this.packageSummaryOnly = true;
|
|
1031
|
+
this.summaryOnly = false;
|
|
1032
|
+
return;
|
|
1033
|
+
}
|
|
1034
|
+
this.disposeData();
|
|
1035
|
+
const sourceRefSizes = /* @__PURE__ */ new Map();
|
|
1036
|
+
await this.readEventLines(0, (event) => {
|
|
1037
|
+
if (event.action === "StringRef") {
|
|
1038
|
+
sourceRefSizes.set(event.id, getContentByteSize(event.content));
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
if (event.action === "HookTransformCallEnd") {
|
|
1042
|
+
this.recordPackageTransformEnd(event, sourceRefSizes);
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
1045
|
+
if (event.action === "ChunkGraphReady" || event.action === "ModuleGraphReady") this.manager.handleEvent(event);
|
|
1046
|
+
}, {
|
|
1047
|
+
onlyActions: PACKAGE_SUMMARY_ACTIONS,
|
|
1048
|
+
maxLineBytes: PACKAGE_SUMMARY_MAX_PARSED_LINE_BYTES,
|
|
1049
|
+
largeLineActions: PACKAGE_SUMMARY_LARGE_LINE_ACTIONS,
|
|
1050
|
+
onSkippedLine: (line) => this.recordPackageSummarySkippedLine(line, sourceRefSizes)
|
|
1051
|
+
});
|
|
1052
|
+
for (const [id, metrics] of this.manager.module_build_metrics) {
|
|
1053
|
+
const module = this.manager.modules.get(id);
|
|
1054
|
+
if (module) module.build_metrics = metrics;
|
|
1055
|
+
}
|
|
1056
|
+
this.packageSummaryTimestamp = mtime;
|
|
1057
|
+
this.packageSummaryOnly = true;
|
|
1058
|
+
this.summaryOnly = false;
|
|
1059
|
+
this.logCache.resetPackageSummaryWriteAttempt();
|
|
1060
|
+
await this.logCache.writePackageSummary(stat, this.createLogCacheState());
|
|
1061
|
+
}
|
|
1062
|
+
recordPackageSummarySkippedLine(line, sourceRefSizes) {
|
|
1063
|
+
if (line.action === "StringRef") {
|
|
1064
|
+
const id = getPreviewStringValue(line.preview, "id");
|
|
1065
|
+
if (id) sourceRefSizes.set(id, estimateContentByteSizeFromLine(line.preview, line.location));
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
if (line.action === "HookTransformCallEnd") {
|
|
1069
|
+
const moduleId = getPreviewStringValue(line.preview, "module_id");
|
|
1070
|
+
if (moduleId) this.recordPackageTransformSize(moduleId, estimateContentByteSizeFromLine(line.preview, line.location));
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
recordPackageTransformEnd(event, refs) {
|
|
1074
|
+
if (!event.module_id) return;
|
|
1075
|
+
this.recordPackageTransformSize(event.module_id, getReferencedContentByteSize(event.content, refs), event);
|
|
1076
|
+
}
|
|
1077
|
+
recordPackageTransformSize(moduleId, transformedCodeSize, event) {
|
|
1078
|
+
const moduleBuildMetrics = this.manager.module_build_metrics.get(moduleId) ?? {
|
|
1079
|
+
resolve_ids: [],
|
|
1080
|
+
loads: [],
|
|
1081
|
+
transforms: []
|
|
1082
|
+
};
|
|
1083
|
+
moduleBuildMetrics.transforms.push({
|
|
1084
|
+
type: "transform",
|
|
1085
|
+
id: "",
|
|
1086
|
+
plugin_name: event?.plugin_name ?? "",
|
|
1087
|
+
plugin_id: event?.plugin_id ?? 0,
|
|
1088
|
+
content_from: null,
|
|
1089
|
+
content_to: null,
|
|
1090
|
+
source_code_size: 0,
|
|
1091
|
+
transformed_code_size: transformedCodeSize,
|
|
1092
|
+
timestamp_start: +(event?.timestamp ?? 0),
|
|
1093
|
+
timestamp_end: +(event?.timestamp ?? 0),
|
|
1094
|
+
duration: 0
|
|
1095
|
+
});
|
|
1096
|
+
this.manager.module_build_metrics.set(moduleId, moduleBuildMetrics);
|
|
1097
|
+
}
|
|
1098
|
+
getModuleEventIndex(module) {
|
|
1099
|
+
let index = this.moduleEventIndex.get(module);
|
|
1100
|
+
if (!index) {
|
|
1101
|
+
index = {
|
|
1102
|
+
resolveIds: /* @__PURE__ */ new Map(),
|
|
1103
|
+
loads: /* @__PURE__ */ new Map(),
|
|
1104
|
+
transforms: /* @__PURE__ */ new Map()
|
|
1105
|
+
};
|
|
1106
|
+
this.moduleEventIndex.set(module, index);
|
|
1107
|
+
}
|
|
1108
|
+
return index;
|
|
1109
|
+
}
|
|
1110
|
+
indexEvent(event, location) {
|
|
1111
|
+
if (event.action === "StringRef") {
|
|
1112
|
+
this.stringRefIndex.set(event.id, location);
|
|
1113
|
+
return;
|
|
1114
|
+
}
|
|
1115
|
+
if (event.action === "HookResolveIdCallStart" && event.call_id) {
|
|
1116
|
+
this.pendingHookCallStarts.set(event.call_id, { location });
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
if (event.action === "HookResolveIdCallEnd" && event.call_id) {
|
|
1120
|
+
const start = this.pendingHookCallStarts.get(event.call_id);
|
|
1121
|
+
this.pendingHookCallStarts.delete(event.call_id);
|
|
1122
|
+
if (!start || !event.event_id || !event.resolved_id) return;
|
|
1123
|
+
this.getModuleEventIndex(event.resolved_id).resolveIds.set(event.event_id, {
|
|
1124
|
+
start: start.location,
|
|
1125
|
+
end: location
|
|
1126
|
+
});
|
|
1127
|
+
return;
|
|
1128
|
+
}
|
|
1129
|
+
if (event.action === "HookLoadCallStart" && event.call_id && event.module_id) {
|
|
1130
|
+
this.pendingHookCallStarts.set(event.call_id, {
|
|
1131
|
+
module: event.module_id,
|
|
1132
|
+
location
|
|
1133
|
+
});
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
if (event.action === "HookLoadCallEnd" && event.module_id && event.event_id) {
|
|
1137
|
+
const start = event.call_id ? this.pendingHookCallStarts.get(event.call_id) : void 0;
|
|
1138
|
+
if (event.call_id) this.pendingHookCallStarts.delete(event.call_id);
|
|
1139
|
+
if (!start) return;
|
|
1140
|
+
this.getModuleEventIndex(event.module_id).loads.set(event.event_id, {
|
|
1141
|
+
start: start.location,
|
|
1142
|
+
end: location
|
|
1143
|
+
});
|
|
1144
|
+
return;
|
|
1145
|
+
}
|
|
1146
|
+
if (event.action === "HookTransformCallStart" && event.call_id && event.module_id) {
|
|
1147
|
+
this.pendingHookCallStarts.set(event.call_id, {
|
|
1148
|
+
module: event.module_id,
|
|
1149
|
+
location
|
|
1150
|
+
});
|
|
1151
|
+
return;
|
|
1152
|
+
}
|
|
1153
|
+
if (event.action === "HookTransformCallEnd" && event.call_id) {
|
|
1154
|
+
const start = this.pendingHookCallStarts.get(event.call_id);
|
|
1155
|
+
this.pendingHookCallStarts.delete(event.call_id);
|
|
1156
|
+
if (!start) return;
|
|
1157
|
+
if (!event.event_id) return;
|
|
1158
|
+
this.getModuleEventIndex(event.module_id ?? start.module).transforms.set(event.event_id, {
|
|
1159
|
+
start: start.location,
|
|
1160
|
+
end: location
|
|
1161
|
+
});
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
if (event.action === "ModuleGraphReady") this.pendingHookCallStarts.clear();
|
|
1165
|
+
}
|
|
1166
|
+
async readEventsAt(locations) {
|
|
1167
|
+
if (!locations.length) return [];
|
|
1168
|
+
const file = await fs.promises.open(this.filepath, "r");
|
|
1169
|
+
try {
|
|
1170
|
+
const events = [];
|
|
1171
|
+
for (const location of locations) {
|
|
1172
|
+
const buffer = Buffer$1.allocUnsafe(location.length);
|
|
1173
|
+
const { bytesRead } = await file.read(buffer, 0, location.length, location.offset);
|
|
1174
|
+
let end = bytesRead;
|
|
1175
|
+
if (end > 0 && buffer[end - 1] === LINE_FEED) end -= 1;
|
|
1176
|
+
if (end > 0 && buffer[end - 1] === CARRIAGE_RETURN) end -= 1;
|
|
1177
|
+
const text = buffer.subarray(0, end).toString("utf8");
|
|
1178
|
+
if (!text) {
|
|
1179
|
+
events.push(void 0);
|
|
1180
|
+
continue;
|
|
1181
|
+
}
|
|
1182
|
+
try {
|
|
1183
|
+
events.push(parseToEvent(text));
|
|
1184
|
+
} catch {
|
|
1185
|
+
events.push(void 0);
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
return events;
|
|
1189
|
+
} finally {
|
|
1190
|
+
await file.close();
|
|
1191
|
+
}
|
|
1192
|
+
}
|
|
1193
|
+
async readStringRefs(refs) {
|
|
1194
|
+
const values = /* @__PURE__ */ new Map();
|
|
1195
|
+
if (!refs.size) return values;
|
|
1196
|
+
const ids = [];
|
|
1197
|
+
const locations = [];
|
|
1198
|
+
for (const id of refs) {
|
|
1199
|
+
const location = this.stringRefIndex.get(id);
|
|
1200
|
+
if (!location) continue;
|
|
1201
|
+
ids.push(id);
|
|
1202
|
+
locations.push(location);
|
|
1203
|
+
}
|
|
1204
|
+
const events = await this.readEventsAt(locations);
|
|
1205
|
+
for (const [index, event] of events.entries()) if (event?.action === "StringRef") values.set(ids[index], event.content);
|
|
1206
|
+
return values;
|
|
1207
|
+
}
|
|
1208
|
+
async readModuleBuildMetrics(module) {
|
|
1209
|
+
await this.read();
|
|
1210
|
+
const cached = this.moduleMetricsCache.get(module);
|
|
1211
|
+
if (cached) {
|
|
1212
|
+
this.moduleMetricsCache.delete(module);
|
|
1213
|
+
this.moduleMetricsCache.set(module, cached);
|
|
1214
|
+
return cloneModuleBuildMetrics(cached.metrics);
|
|
1215
|
+
}
|
|
1216
|
+
if (this.metricsSummaryOnly) {
|
|
1217
|
+
const metrics = await this.hydrateModuleBuildMetricsFromIndex(module);
|
|
1218
|
+
if (metrics) {
|
|
1219
|
+
this.setCachedModuleBuildMetrics(module, metrics);
|
|
1220
|
+
return cloneModuleBuildMetrics(metrics);
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1223
|
+
const pending = this.pendingModuleMetrics.get(module);
|
|
1224
|
+
if (pending) return cloneModuleBuildMetrics(await pending);
|
|
1225
|
+
const promise = this.hydrateModuleBuildMetrics(module);
|
|
1226
|
+
this.pendingModuleMetrics.set(module, promise);
|
|
1227
|
+
try {
|
|
1228
|
+
const metrics = await promise;
|
|
1229
|
+
this.setCachedModuleBuildMetrics(module, metrics);
|
|
1230
|
+
return cloneModuleBuildMetrics(metrics);
|
|
1231
|
+
} finally {
|
|
1232
|
+
this.pendingModuleMetrics.delete(module);
|
|
1233
|
+
}
|
|
1234
|
+
}
|
|
1235
|
+
async hydratePluginBuildMetrics(pluginId) {
|
|
1236
|
+
await this.read();
|
|
1237
|
+
let metrics = this.manager.plugin_build_metrics.get(pluginId);
|
|
1238
|
+
if (!metrics && this.metricsSummaryOnly) {
|
|
1239
|
+
metrics = await this.hydratePluginBuildMetricsFromIndex(pluginId);
|
|
1240
|
+
if (metrics) this.manager.plugin_build_metrics.set(pluginId, metrics);
|
|
1241
|
+
}
|
|
1242
|
+
if (!metrics) return;
|
|
1243
|
+
const transformCalls = metrics.calls.filter((call) => call.type === "transform" && call.unchanged == null);
|
|
1244
|
+
if (!transformCalls.length) return;
|
|
1245
|
+
const refs = /* @__PURE__ */ new Set();
|
|
1246
|
+
const transformEventIndexes = [];
|
|
1247
|
+
const locations = [];
|
|
1248
|
+
for (const call of transformCalls) {
|
|
1249
|
+
const location = this.moduleEventIndex.get(call.module)?.transforms.get(call.id);
|
|
1250
|
+
if (!location) {
|
|
1251
|
+
transformEventIndexes.push(void 0);
|
|
1252
|
+
continue;
|
|
1253
|
+
}
|
|
1254
|
+
transformEventIndexes.push(locations.length);
|
|
1255
|
+
locations.push(location.start, location.end);
|
|
1256
|
+
}
|
|
1257
|
+
const events = await this.readEventsAt(locations);
|
|
1258
|
+
const contents = transformCalls.map((call, index) => {
|
|
1259
|
+
const eventIndex = transformEventIndexes[index];
|
|
1260
|
+
if (eventIndex == null) return {
|
|
1261
|
+
call,
|
|
1262
|
+
content_from: void 0,
|
|
1263
|
+
content_to: void 0
|
|
1264
|
+
};
|
|
1265
|
+
const start = events[eventIndex];
|
|
1266
|
+
const end = events[eventIndex + 1];
|
|
1267
|
+
return {
|
|
1268
|
+
call,
|
|
1269
|
+
content_from: start?.action === "HookTransformCallStart" ? getDeferredContent(start, refs) : {
|
|
1270
|
+
value: null,
|
|
1271
|
+
ref: null
|
|
1272
|
+
},
|
|
1273
|
+
content_to: end?.action === "HookTransformCallEnd" ? getDeferredContent(end, refs) : {
|
|
1274
|
+
value: null,
|
|
1275
|
+
ref: null
|
|
1276
|
+
}
|
|
1277
|
+
};
|
|
1278
|
+
});
|
|
1279
|
+
const refValues = await this.readStringRefs(refs);
|
|
1280
|
+
for (const item of contents) {
|
|
1281
|
+
if (!item.content_from || !item.content_to) {
|
|
1282
|
+
item.call.unchanged = false;
|
|
1283
|
+
continue;
|
|
1284
|
+
}
|
|
1285
|
+
const contentFrom = resolveDeferredContent(item.content_from, refValues);
|
|
1286
|
+
const contentTo = resolveDeferredContent(item.content_to, refValues);
|
|
1287
|
+
item.call.unchanged = getContentHash(contentFrom) === getContentHash(contentTo);
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
clearModuleMetricsCache() {
|
|
1291
|
+
this.moduleMetricsCache.clear();
|
|
1292
|
+
this.moduleMetricsCacheBytes = 0;
|
|
1293
|
+
}
|
|
1294
|
+
setCachedModuleBuildMetrics(module, metrics) {
|
|
1295
|
+
const bytes = getModuleBuildMetricsCacheBytes(metrics);
|
|
1296
|
+
const previous = this.moduleMetricsCache.get(module);
|
|
1297
|
+
if (previous) {
|
|
1298
|
+
this.moduleMetricsCacheBytes -= previous.bytes;
|
|
1299
|
+
this.moduleMetricsCache.delete(module);
|
|
1300
|
+
}
|
|
1301
|
+
if (bytes > MAX_MODULE_METRICS_CACHE_BYTES) return;
|
|
1302
|
+
this.moduleMetricsCache.set(module, {
|
|
1303
|
+
metrics,
|
|
1304
|
+
bytes
|
|
1305
|
+
});
|
|
1306
|
+
this.moduleMetricsCacheBytes += bytes;
|
|
1307
|
+
while (this.moduleMetricsCache.size > MAX_MODULE_METRICS_CACHE || this.moduleMetricsCacheBytes > MAX_MODULE_METRICS_CACHE_BYTES) {
|
|
1308
|
+
const firstKey = this.moduleMetricsCache.keys().next().value;
|
|
1309
|
+
if (firstKey == null) break;
|
|
1310
|
+
const deleted = this.moduleMetricsCache.get(firstKey);
|
|
1311
|
+
this.moduleMetricsCache.delete(firstKey);
|
|
1312
|
+
if (deleted) this.moduleMetricsCacheBytes -= deleted.bytes;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
async readIndexedHookEvents(calls) {
|
|
1316
|
+
const locations = calls.flatMap(([, call]) => [call.start, call.end]);
|
|
1317
|
+
const events = await this.readEventsAt(locations);
|
|
1318
|
+
return calls.map(([id], index) => ({
|
|
1319
|
+
id,
|
|
1320
|
+
start: events[index * 2],
|
|
1321
|
+
end: events[index * 2 + 1]
|
|
1322
|
+
}));
|
|
1323
|
+
}
|
|
1324
|
+
async hydrateModuleBuildMetricsFromIndex(module) {
|
|
1325
|
+
const index = this.moduleEventIndex.get(module);
|
|
1326
|
+
if (!index) return void 0;
|
|
1327
|
+
const [resolveEvents, loadEvents, transformEvents] = await Promise.all([
|
|
1328
|
+
this.readIndexedHookEvents(Array.from(index.resolveIds.entries())),
|
|
1329
|
+
this.readIndexedHookEvents(Array.from(index.loads.entries())),
|
|
1330
|
+
this.readIndexedHookEvents(Array.from(index.transforms.entries()))
|
|
1331
|
+
]);
|
|
1332
|
+
const refs = /* @__PURE__ */ new Set();
|
|
1333
|
+
const resolve_ids = [];
|
|
1334
|
+
for (const item of resolveEvents) {
|
|
1335
|
+
const start = item.start;
|
|
1336
|
+
const end = item.end;
|
|
1337
|
+
if (start?.action !== "HookResolveIdCallStart" || end?.action !== "HookResolveIdCallEnd") continue;
|
|
1338
|
+
resolve_ids.push({
|
|
1339
|
+
type: "resolve",
|
|
1340
|
+
id: item.id,
|
|
1341
|
+
plugin_name: end.plugin_name,
|
|
1342
|
+
plugin_id: end.plugin_id,
|
|
1343
|
+
importer: start.importer,
|
|
1344
|
+
module_request: start.module_request,
|
|
1345
|
+
import_kind: start.import_kind,
|
|
1346
|
+
resolved_id: end.resolved_id,
|
|
1347
|
+
timestamp_start: +start.timestamp,
|
|
1348
|
+
timestamp_end: +end.timestamp,
|
|
1349
|
+
duration: +end.timestamp - +start.timestamp
|
|
1350
|
+
});
|
|
1351
|
+
}
|
|
1352
|
+
const loads = [];
|
|
1353
|
+
for (const item of loadEvents) {
|
|
1354
|
+
const start = item.start;
|
|
1355
|
+
const end = item.end;
|
|
1356
|
+
if (start?.action !== "HookLoadCallStart" || end?.action !== "HookLoadCallEnd") continue;
|
|
1357
|
+
loads.push({
|
|
1358
|
+
type: "load",
|
|
1359
|
+
id: item.id,
|
|
1360
|
+
plugin_name: end.plugin_name,
|
|
1361
|
+
plugin_id: end.plugin_id,
|
|
1362
|
+
content: getDeferredContent(end, refs),
|
|
1363
|
+
timestamp_start: +start.timestamp,
|
|
1364
|
+
timestamp_end: +end.timestamp,
|
|
1365
|
+
duration: +end.timestamp - +start.timestamp
|
|
1366
|
+
});
|
|
1367
|
+
}
|
|
1368
|
+
const transforms = [];
|
|
1369
|
+
for (const item of transformEvents) {
|
|
1370
|
+
const start = item.start;
|
|
1371
|
+
const end = item.end;
|
|
1372
|
+
if (start?.action !== "HookTransformCallStart" || end?.action !== "HookTransformCallEnd") continue;
|
|
1373
|
+
transforms.push({
|
|
1374
|
+
type: "transform",
|
|
1375
|
+
id: item.id,
|
|
1376
|
+
plugin_name: end.plugin_name,
|
|
1377
|
+
plugin_id: end.plugin_id,
|
|
1378
|
+
content_from: getDeferredContent(start, refs),
|
|
1379
|
+
content_to: getDeferredContent(end, refs),
|
|
1380
|
+
timestamp_start: +start.timestamp,
|
|
1381
|
+
timestamp_end: +end.timestamp,
|
|
1382
|
+
duration: +end.timestamp - +start.timestamp,
|
|
1383
|
+
source_code_size: 0,
|
|
1384
|
+
transformed_code_size: 0
|
|
1385
|
+
});
|
|
1386
|
+
}
|
|
1387
|
+
const refValues = await this.readStringRefs(refs);
|
|
1388
|
+
return {
|
|
1389
|
+
resolve_ids,
|
|
1390
|
+
loads: loads.map((load) => ({
|
|
1391
|
+
...load,
|
|
1392
|
+
content: resolveDeferredContent(load.content, refValues)
|
|
1393
|
+
})),
|
|
1394
|
+
transforms: transforms.map((transform) => {
|
|
1395
|
+
const content_from = resolveDeferredContent(transform.content_from, refValues);
|
|
1396
|
+
const content_to = resolveDeferredContent(transform.content_to, refValues);
|
|
1397
|
+
return {
|
|
1398
|
+
...transform,
|
|
1399
|
+
content_from,
|
|
1400
|
+
content_to,
|
|
1401
|
+
source_code_size: getContentByteSize(content_from ?? ""),
|
|
1402
|
+
transformed_code_size: getContentByteSize(content_to ?? "")
|
|
1403
|
+
};
|
|
1404
|
+
})
|
|
1405
|
+
};
|
|
1406
|
+
}
|
|
1407
|
+
async hydratePluginBuildMetricsFromIndex(pluginId) {
|
|
1408
|
+
const calls = [];
|
|
1409
|
+
for (const [module, index] of this.moduleEventIndex) {
|
|
1410
|
+
for (const [id, location] of index.resolveIds) calls.push({
|
|
1411
|
+
module,
|
|
1412
|
+
type: "resolve",
|
|
1413
|
+
id,
|
|
1414
|
+
location
|
|
1415
|
+
});
|
|
1416
|
+
for (const [id, location] of index.loads) calls.push({
|
|
1417
|
+
module,
|
|
1418
|
+
type: "load",
|
|
1419
|
+
id,
|
|
1420
|
+
location
|
|
1421
|
+
});
|
|
1422
|
+
for (const [id, location] of index.transforms) calls.push({
|
|
1423
|
+
module,
|
|
1424
|
+
type: "transform",
|
|
1425
|
+
id,
|
|
1426
|
+
location
|
|
1427
|
+
});
|
|
1428
|
+
}
|
|
1429
|
+
const events = await this.readIndexedHookEvents(calls.map((call) => [call.id, call.location]));
|
|
1430
|
+
const metrics = {
|
|
1431
|
+
plugin_id: pluginId,
|
|
1432
|
+
plugin_name: "",
|
|
1433
|
+
calls: []
|
|
1434
|
+
};
|
|
1435
|
+
for (const [index, item] of events.entries()) {
|
|
1436
|
+
const call = calls[index];
|
|
1437
|
+
const start = item.start;
|
|
1438
|
+
const end = item.end;
|
|
1439
|
+
if (!start || !end || !("plugin_id" in end) || end.plugin_id !== pluginId) continue;
|
|
1440
|
+
const timestamp_start = "timestamp" in start ? +start.timestamp : 0;
|
|
1441
|
+
const timestamp_end = "timestamp" in end ? +end.timestamp : 0;
|
|
1442
|
+
metrics.plugin_name = end.plugin_name;
|
|
1443
|
+
metrics.calls.push({
|
|
1444
|
+
type: call.type,
|
|
1445
|
+
id: call.id,
|
|
1446
|
+
duration: timestamp_end - timestamp_start,
|
|
1447
|
+
plugin_id: pluginId,
|
|
1448
|
+
plugin_name: end.plugin_name,
|
|
1449
|
+
module: call.type === "resolve" && start.action === "HookResolveIdCallStart" ? start.module_request : call.module,
|
|
1450
|
+
timestamp_start,
|
|
1451
|
+
timestamp_end,
|
|
1452
|
+
unchanged: call.type === "load" && end.action === "HookLoadCallEnd" ? !end.content : void 0
|
|
1453
|
+
});
|
|
1454
|
+
}
|
|
1455
|
+
metrics.calls.sort((a, b) => a.timestamp_start - b.timestamp_start);
|
|
1456
|
+
return metrics.calls.length ? metrics : void 0;
|
|
1457
|
+
}
|
|
1458
|
+
async hydrateModuleBuildMetrics(module) {
|
|
1459
|
+
const summary = this.manager.module_build_metrics.get(module) ?? {
|
|
1460
|
+
resolve_ids: [],
|
|
1461
|
+
loads: [],
|
|
1462
|
+
transforms: []
|
|
1463
|
+
};
|
|
1464
|
+
const index = this.moduleEventIndex.get(module);
|
|
1465
|
+
const refs = /* @__PURE__ */ new Set();
|
|
1466
|
+
const loadEventIndexes = [];
|
|
1467
|
+
const loadLocations = [];
|
|
1468
|
+
for (const load of summary.loads) {
|
|
1469
|
+
const location = index?.loads.get(load.id)?.end;
|
|
1470
|
+
if (!location) {
|
|
1471
|
+
loadEventIndexes.push(void 0);
|
|
1472
|
+
continue;
|
|
1473
|
+
}
|
|
1474
|
+
loadEventIndexes.push(loadLocations.length);
|
|
1475
|
+
loadLocations.push(location);
|
|
1476
|
+
}
|
|
1477
|
+
const transformEventIndexes = [];
|
|
1478
|
+
const transformLocations = [];
|
|
1479
|
+
for (const transform of summary.transforms) {
|
|
1480
|
+
const location = index?.transforms.get(transform.id);
|
|
1481
|
+
if (!location) {
|
|
1482
|
+
transformEventIndexes.push(void 0);
|
|
1483
|
+
continue;
|
|
1484
|
+
}
|
|
1485
|
+
transformEventIndexes.push(transformLocations.length);
|
|
1486
|
+
transformLocations.push(location.start, location.end);
|
|
1487
|
+
}
|
|
1488
|
+
const loadEvents = await this.readEventsAt(loadLocations);
|
|
1489
|
+
const transformEvents = await this.readEventsAt(transformLocations);
|
|
1490
|
+
const loads = summary.loads.map((load, index) => {
|
|
1491
|
+
const eventIndex = loadEventIndexes[index];
|
|
1492
|
+
const event = eventIndex == null ? void 0 : loadEvents[eventIndex];
|
|
1493
|
+
return {
|
|
1494
|
+
...load,
|
|
1495
|
+
content: event?.action === "HookLoadCallEnd" ? getDeferredContent(event, refs) : {
|
|
1496
|
+
value: load.content,
|
|
1497
|
+
ref: null
|
|
1498
|
+
}
|
|
1499
|
+
};
|
|
1500
|
+
});
|
|
1501
|
+
const transforms = summary.transforms.map((transform, index) => {
|
|
1502
|
+
const eventIndex = transformEventIndexes[index];
|
|
1503
|
+
const start = eventIndex == null ? void 0 : transformEvents[eventIndex];
|
|
1504
|
+
const end = eventIndex == null ? void 0 : transformEvents[eventIndex + 1];
|
|
1505
|
+
return {
|
|
1506
|
+
...transform,
|
|
1507
|
+
content_from: start?.action === "HookTransformCallStart" ? getDeferredContent(start, refs) : {
|
|
1508
|
+
value: transform.content_from,
|
|
1509
|
+
ref: null
|
|
1510
|
+
},
|
|
1511
|
+
content_to: end?.action === "HookTransformCallEnd" ? getDeferredContent(end, refs) : {
|
|
1512
|
+
value: transform.content_to,
|
|
1513
|
+
ref: null
|
|
1514
|
+
}
|
|
1515
|
+
};
|
|
1516
|
+
});
|
|
1517
|
+
const refValues = await this.readStringRefs(refs);
|
|
1518
|
+
return {
|
|
1519
|
+
resolve_ids: summary.resolve_ids.map((resolve) => ({ ...resolve })),
|
|
1520
|
+
loads: loads.map((load) => ({
|
|
1521
|
+
...load,
|
|
1522
|
+
content: resolveDeferredContent(load.content, refValues)
|
|
1523
|
+
})),
|
|
1524
|
+
transforms: transforms.map((transform) => {
|
|
1525
|
+
const content_from = resolveDeferredContent(transform.content_from, refValues);
|
|
1526
|
+
const content_to = resolveDeferredContent(transform.content_to, refValues);
|
|
1527
|
+
return {
|
|
1528
|
+
...transform,
|
|
1529
|
+
content_from,
|
|
1530
|
+
content_to,
|
|
1531
|
+
source_code_size: getContentByteSize(content_from ?? ""),
|
|
1532
|
+
transformed_code_size: getContentByteSize(content_to ?? "")
|
|
1533
|
+
};
|
|
1534
|
+
})
|
|
1535
|
+
};
|
|
1536
|
+
}
|
|
1537
|
+
hasPendingRead() {
|
|
1538
|
+
return !!this.pendingRead || !!this.pendingSummaryRead || !!this.pendingPackageSummaryRead;
|
|
1539
|
+
}
|
|
1540
|
+
hasReadData() {
|
|
1541
|
+
return this.lastBytes > 0 || this.manager.eventCount > 0;
|
|
1542
|
+
}
|
|
1543
|
+
createLogCacheState() {
|
|
1544
|
+
return Object.defineProperties({}, {
|
|
1545
|
+
lastBytes: {
|
|
1546
|
+
get: () => this.lastBytes,
|
|
1547
|
+
set: (value) => {
|
|
1548
|
+
this.lastBytes = value;
|
|
1549
|
+
}
|
|
1550
|
+
},
|
|
1551
|
+
lastTimestamp: {
|
|
1552
|
+
get: () => this.lastTimestamp,
|
|
1553
|
+
set: (value) => {
|
|
1554
|
+
this.lastTimestamp = value;
|
|
1555
|
+
}
|
|
1556
|
+
},
|
|
1557
|
+
lineNumber: {
|
|
1558
|
+
get: () => this.lineNumber,
|
|
1559
|
+
set: (value) => {
|
|
1560
|
+
this.lineNumber = value;
|
|
1561
|
+
}
|
|
1562
|
+
},
|
|
1563
|
+
moduleEventIndex: {
|
|
1564
|
+
get: () => this.moduleEventIndex,
|
|
1565
|
+
set: (value) => {
|
|
1566
|
+
this.moduleEventIndex = value;
|
|
1567
|
+
}
|
|
1568
|
+
},
|
|
1569
|
+
stringRefIndex: {
|
|
1570
|
+
get: () => this.stringRefIndex,
|
|
1571
|
+
set: (value) => {
|
|
1572
|
+
this.stringRefIndex = value;
|
|
1573
|
+
}
|
|
1574
|
+
},
|
|
1575
|
+
pendingHookCallStarts: {
|
|
1576
|
+
get: () => this.pendingHookCallStarts,
|
|
1577
|
+
set: (value) => {
|
|
1578
|
+
this.pendingHookCallStarts = value;
|
|
1579
|
+
}
|
|
1580
|
+
},
|
|
1581
|
+
assetsReadyLocations: {
|
|
1582
|
+
get: () => this.assetsReadyLocations,
|
|
1583
|
+
set: (value) => {
|
|
1584
|
+
this.assetsReadyLocations = value;
|
|
1585
|
+
}
|
|
1586
|
+
},
|
|
1587
|
+
meta: {
|
|
1588
|
+
get: () => this.meta,
|
|
1589
|
+
set: (value) => {
|
|
1590
|
+
this.meta = value;
|
|
1591
|
+
}
|
|
1592
|
+
},
|
|
1593
|
+
manager: { get: () => this.manager },
|
|
1594
|
+
packageSummaryTimestamp: {
|
|
1595
|
+
get: () => this.packageSummaryTimestamp,
|
|
1596
|
+
set: (value) => {
|
|
1597
|
+
this.packageSummaryTimestamp = value;
|
|
1598
|
+
}
|
|
1599
|
+
},
|
|
1600
|
+
metricsSummaryOnly: {
|
|
1601
|
+
get: () => this.metricsSummaryOnly,
|
|
1602
|
+
set: (value) => {
|
|
1603
|
+
this.metricsSummaryOnly = value;
|
|
1604
|
+
}
|
|
1605
|
+
}
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
hasCompleteSession() {
|
|
1609
|
+
return this.hasReadData() && !this.summaryOnly && !this.packageSummaryOnly;
|
|
1610
|
+
}
|
|
1611
|
+
isReadingCompleteSession() {
|
|
1612
|
+
return !!this.pendingRead;
|
|
306
1613
|
}
|
|
307
1614
|
dispose() {
|
|
308
|
-
readers.delete(this.
|
|
1615
|
+
readers.delete(this.cacheKey);
|
|
1616
|
+
this.disposeData();
|
|
1617
|
+
}
|
|
1618
|
+
resetReadState() {
|
|
1619
|
+
this.lastBytes = 0;
|
|
1620
|
+
this.lastTimestamp = 0;
|
|
1621
|
+
this.disposeData();
|
|
1622
|
+
}
|
|
1623
|
+
disposeData() {
|
|
309
1624
|
this.manager.dispose();
|
|
1625
|
+
this.lineNumber = 0;
|
|
1626
|
+
this.moduleEventIndex.clear();
|
|
1627
|
+
this.stringRefIndex.clear();
|
|
1628
|
+
this.pendingHookCallStarts.clear();
|
|
1629
|
+
this.clearModuleMetricsCache();
|
|
1630
|
+
this.pendingModuleMetrics.clear();
|
|
1631
|
+
this.assetsReadyLocations = [];
|
|
1632
|
+
this.assetsHydrated = false;
|
|
1633
|
+
this.summaryOnly = false;
|
|
1634
|
+
this.packageSummaryOnly = false;
|
|
1635
|
+
this.metricsSummaryOnly = false;
|
|
1636
|
+
this.logCache.resetCompleteSessionWriteAttempt();
|
|
1637
|
+
this.logCache.resetPackageSummaryWriteAttempt();
|
|
310
1638
|
}
|
|
311
1639
|
[Symbol.dispose]() {
|
|
312
1640
|
this.dispose();
|
|
@@ -322,16 +1650,17 @@ var RolldownLogsManager = class {
|
|
|
322
1650
|
async list() {
|
|
323
1651
|
if (!existsSync(this.dir)) return [];
|
|
324
1652
|
const sessions = await fs$1.readdir(this.dir, { withFileTypes: true });
|
|
325
|
-
return await Promise.all(sessions.filter((d) => d.isDirectory()).filter((d) => existsSync(join(this.dir, d.name, "meta.json"))).map(async (d) => {
|
|
1653
|
+
return (await Promise.all(sessions.filter((d) => d.isDirectory()).filter((d) => existsSync(join(this.dir, d.name, "meta.json"))).map(async (d) => {
|
|
326
1654
|
const reader = RolldownEventsReader.get(join(this.dir, d.name, "meta.json"));
|
|
327
1655
|
await reader.read();
|
|
328
|
-
const meta = reader.
|
|
1656
|
+
const meta = reader.meta;
|
|
1657
|
+
if (!meta) return;
|
|
329
1658
|
return {
|
|
330
1659
|
id: d.name,
|
|
331
1660
|
timestamp: meta.timestamp,
|
|
332
1661
|
meta
|
|
333
1662
|
};
|
|
334
|
-
}));
|
|
1663
|
+
}))).filter((entry) => !!entry);
|
|
335
1664
|
}
|
|
336
1665
|
async loadSession(session) {
|
|
337
1666
|
const reader = RolldownEventsReader.get(join(this.dir, session, "logs.json"));
|
|
@@ -339,7 +1668,44 @@ var RolldownLogsManager = class {
|
|
|
339
1668
|
if (!reader.meta) {
|
|
340
1669
|
const metaReader = RolldownEventsReader.get(join(this.dir, session, "meta.json"));
|
|
341
1670
|
await metaReader.read();
|
|
342
|
-
reader.meta = metaReader.
|
|
1671
|
+
reader.meta = metaReader.meta;
|
|
1672
|
+
}
|
|
1673
|
+
return reader;
|
|
1674
|
+
}
|
|
1675
|
+
async loadSessionSummary(session) {
|
|
1676
|
+
const reader = RolldownEventsReader.get(join(this.dir, session, "logs.json"));
|
|
1677
|
+
await reader.readSummary();
|
|
1678
|
+
if (!reader.meta) {
|
|
1679
|
+
const metaReader = RolldownEventsReader.get(join(this.dir, session, "meta.json"));
|
|
1680
|
+
await metaReader.read();
|
|
1681
|
+
reader.meta = metaReader.meta;
|
|
1682
|
+
}
|
|
1683
|
+
return reader;
|
|
1684
|
+
}
|
|
1685
|
+
async loadAssetSession(session) {
|
|
1686
|
+
const reader = await this.loadSession(session);
|
|
1687
|
+
await reader.readAssets();
|
|
1688
|
+
return reader;
|
|
1689
|
+
}
|
|
1690
|
+
async loadPackageSession(session) {
|
|
1691
|
+
const filepath = join(this.dir, session, "logs.json");
|
|
1692
|
+
const loadedReader = RolldownEventsReader.peek(filepath);
|
|
1693
|
+
if (loadedReader?.hasCompleteSession() || loadedReader?.isReadingCompleteSession()) {
|
|
1694
|
+
await loadedReader.read();
|
|
1695
|
+
await loadedReader.ensurePackageSummaryCache();
|
|
1696
|
+
if (!loadedReader.meta) {
|
|
1697
|
+
const metaReader = RolldownEventsReader.get(join(this.dir, session, "meta.json"));
|
|
1698
|
+
await metaReader.read();
|
|
1699
|
+
loadedReader.meta = metaReader.meta;
|
|
1700
|
+
}
|
|
1701
|
+
return loadedReader;
|
|
1702
|
+
}
|
|
1703
|
+
const reader = RolldownEventsReader.get(filepath, `${filepath}:package-summary`);
|
|
1704
|
+
await reader.readPackageSummary();
|
|
1705
|
+
if (!reader.meta) {
|
|
1706
|
+
const metaReader = RolldownEventsReader.get(join(this.dir, session, "meta.json"));
|
|
1707
|
+
await metaReader.read();
|
|
1708
|
+
reader.meta = metaReader.meta;
|
|
343
1709
|
}
|
|
344
1710
|
return reader;
|
|
345
1711
|
}
|
|
@@ -352,7 +1718,7 @@ function getLogsManager(context) {
|
|
|
352
1718
|
if (!manager) {
|
|
353
1719
|
const dirs = [join(context.cwd, "node_modules", ".rolldown"), join(process$1.cwd(), "node_modules", ".rolldown")];
|
|
354
1720
|
const dir = dirs.find((dir) => existsSync(dir));
|
|
355
|
-
if (!dir)
|
|
1721
|
+
if (!dir) diagnostics.RDDT0001();
|
|
356
1722
|
manager = new RolldownLogsManager(dir ?? dirs[0]);
|
|
357
1723
|
}
|
|
358
1724
|
return manager;
|
|
@@ -367,7 +1733,7 @@ const rolldownGetAssetDetails = defineRpcFunction({
|
|
|
367
1733
|
setup: (context) => {
|
|
368
1734
|
const manager = getLogsManager(context);
|
|
369
1735
|
return { handler: async ({ session, id }) => {
|
|
370
|
-
const reader = await manager.
|
|
1736
|
+
const reader = await manager.loadAssetSession(session);
|
|
371
1737
|
const assets = reader.manager.assets;
|
|
372
1738
|
const chunks = reader.manager.chunks;
|
|
373
1739
|
const asset = assets.get(id);
|
|
@@ -395,7 +1761,7 @@ const rolldownGetAssetsList = defineRpcFunction({
|
|
|
395
1761
|
setup: (context) => {
|
|
396
1762
|
const manager = getLogsManager(context);
|
|
397
1763
|
return { handler: async ({ session }) => {
|
|
398
|
-
const reader = await manager.
|
|
1764
|
+
const reader = await manager.loadAssetSession(session);
|
|
399
1765
|
return Array.from(reader.manager.assets.values());
|
|
400
1766
|
} };
|
|
401
1767
|
}
|
|
@@ -410,7 +1776,7 @@ const rolldownGetChunkInfo = defineRpcFunction({
|
|
|
410
1776
|
setup: (context) => {
|
|
411
1777
|
const manager = getLogsManager(context);
|
|
412
1778
|
return { handler: async ({ session, id }) => {
|
|
413
|
-
const reader = await manager.
|
|
1779
|
+
const reader = await manager.loadAssetSession(session);
|
|
414
1780
|
const chunk = reader.manager.chunks.get(id);
|
|
415
1781
|
chunk.asset = reader.manager.chunkAssetMap.get(chunk.chunk_id);
|
|
416
1782
|
return chunk;
|
|
@@ -427,7 +1793,7 @@ const rolldownGetChunksGraph = defineRpcFunction({
|
|
|
427
1793
|
setup: (context) => {
|
|
428
1794
|
const manager = getLogsManager(context);
|
|
429
1795
|
return { handler: async ({ session }) => {
|
|
430
|
-
const reader = await manager.
|
|
1796
|
+
const reader = await manager.loadAssetSession(session);
|
|
431
1797
|
const chunks = Array.from(reader.manager.chunks.values());
|
|
432
1798
|
chunks.forEach((chunk) => {
|
|
433
1799
|
chunk.asset = reader.manager.chunkAssetMap.get(chunk.chunk_id);
|
|
@@ -446,9 +1812,10 @@ const rolldownGetModuleInfo = defineRpcFunction({
|
|
|
446
1812
|
setup: (context) => {
|
|
447
1813
|
const manager = getLogsManager(context);
|
|
448
1814
|
return { handler: async ({ session, module }) => {
|
|
449
|
-
const reader = await manager.
|
|
450
|
-
if (!reader.manager.
|
|
1815
|
+
const reader = await manager.loadAssetSession(session);
|
|
1816
|
+
if (!reader.manager.eventCount) return null;
|
|
451
1817
|
const moduleInfo = reader.manager.modules.get(module);
|
|
1818
|
+
const moduleMetrics = await reader.readModuleBuildMetrics(module);
|
|
452
1819
|
const info = {
|
|
453
1820
|
id: module,
|
|
454
1821
|
imports: [],
|
|
@@ -461,8 +1828,8 @@ const rolldownGetModuleInfo = defineRpcFunction({
|
|
|
461
1828
|
transforms: []
|
|
462
1829
|
},
|
|
463
1830
|
...moduleInfo || {},
|
|
464
|
-
loads:
|
|
465
|
-
resolve_ids:
|
|
1831
|
+
loads: moduleMetrics.loads,
|
|
1832
|
+
resolve_ids: moduleMetrics.resolve_ids
|
|
466
1833
|
};
|
|
467
1834
|
info.chunks = Array.from(reader.manager.chunks.values()).filter((chunk) => chunk.modules.includes(module)).map((chunk) => ({
|
|
468
1835
|
type: "chunk",
|
|
@@ -479,19 +1846,6 @@ const rolldownGetModuleInfo = defineRpcFunction({
|
|
|
479
1846
|
}
|
|
480
1847
|
});
|
|
481
1848
|
//#endregion
|
|
482
|
-
//#region src/node/rpc/functions/rolldown-get-module-raw-events.ts
|
|
483
|
-
const rolldownGetModuleRawEvents = defineRpcFunction({
|
|
484
|
-
name: "vite:rolldown:get-module-raw-events",
|
|
485
|
-
type: "query",
|
|
486
|
-
jsonSerializable: true,
|
|
487
|
-
setup: (context) => {
|
|
488
|
-
const manager = getLogsManager(context);
|
|
489
|
-
return { handler: async ({ session, module }) => {
|
|
490
|
-
return { events: (await manager.loadSession(session)).manager.events.filter((event) => "module_id" in event && event.module_id !== module) };
|
|
491
|
-
} };
|
|
492
|
-
}
|
|
493
|
-
});
|
|
494
|
-
//#endregion
|
|
495
1849
|
//#region src/node/rpc/functions/rolldown-get-module-transforms.ts
|
|
496
1850
|
const rolldownGetModuleTransforms = defineRpcFunction({
|
|
497
1851
|
name: "vite:rolldown:get-module-transforms",
|
|
@@ -501,9 +1855,8 @@ const rolldownGetModuleTransforms = defineRpcFunction({
|
|
|
501
1855
|
const manager = getLogsManager(context);
|
|
502
1856
|
return { handler: async ({ session, module }) => {
|
|
503
1857
|
const reader = await manager.loadSession(session);
|
|
504
|
-
const
|
|
505
|
-
|
|
506
|
-
if (!events.length) return transforms.map((transform) => ({
|
|
1858
|
+
const { transforms } = await reader.readModuleBuildMetrics(module);
|
|
1859
|
+
if (!reader.manager.eventCount) return transforms.map((transform) => ({
|
|
507
1860
|
...transform,
|
|
508
1861
|
diff_added: 0,
|
|
509
1862
|
diff_removed: 0
|
|
@@ -1033,6 +2386,96 @@ var require_logger = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1033
2386
|
}
|
|
1034
2387
|
}));
|
|
1035
2388
|
//#endregion
|
|
2389
|
+
//#region ../../node_modules/.pnpm/split2@4.2.0/node_modules/split2/index.js
|
|
2390
|
+
var require_split2 = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
2391
|
+
const { Transform } = __require("stream");
|
|
2392
|
+
const { StringDecoder } = __require("string_decoder");
|
|
2393
|
+
const kLast = Symbol("last");
|
|
2394
|
+
const kDecoder = Symbol("decoder");
|
|
2395
|
+
function transform(chunk, enc, cb) {
|
|
2396
|
+
let list;
|
|
2397
|
+
if (this.overflow) {
|
|
2398
|
+
list = this[kDecoder].write(chunk).split(this.matcher);
|
|
2399
|
+
if (list.length === 1) return cb();
|
|
2400
|
+
list.shift();
|
|
2401
|
+
this.overflow = false;
|
|
2402
|
+
} else {
|
|
2403
|
+
this[kLast] += this[kDecoder].write(chunk);
|
|
2404
|
+
list = this[kLast].split(this.matcher);
|
|
2405
|
+
}
|
|
2406
|
+
this[kLast] = list.pop();
|
|
2407
|
+
for (let i = 0; i < list.length; i++) try {
|
|
2408
|
+
push(this, this.mapper(list[i]));
|
|
2409
|
+
} catch (error) {
|
|
2410
|
+
return cb(error);
|
|
2411
|
+
}
|
|
2412
|
+
this.overflow = this[kLast].length > this.maxLength;
|
|
2413
|
+
if (this.overflow && !this.skipOverflow) {
|
|
2414
|
+
cb(/* @__PURE__ */ new Error("maximum buffer reached"));
|
|
2415
|
+
return;
|
|
2416
|
+
}
|
|
2417
|
+
cb();
|
|
2418
|
+
}
|
|
2419
|
+
function flush(cb) {
|
|
2420
|
+
this[kLast] += this[kDecoder].end();
|
|
2421
|
+
if (this[kLast]) try {
|
|
2422
|
+
push(this, this.mapper(this[kLast]));
|
|
2423
|
+
} catch (error) {
|
|
2424
|
+
return cb(error);
|
|
2425
|
+
}
|
|
2426
|
+
cb();
|
|
2427
|
+
}
|
|
2428
|
+
function push(self, val) {
|
|
2429
|
+
if (val !== void 0) self.push(val);
|
|
2430
|
+
}
|
|
2431
|
+
function noop(incoming) {
|
|
2432
|
+
return incoming;
|
|
2433
|
+
}
|
|
2434
|
+
function split(matcher, mapper, options) {
|
|
2435
|
+
matcher = matcher || /\r?\n/;
|
|
2436
|
+
mapper = mapper || noop;
|
|
2437
|
+
options = options || {};
|
|
2438
|
+
switch (arguments.length) {
|
|
2439
|
+
case 1:
|
|
2440
|
+
if (typeof matcher === "function") {
|
|
2441
|
+
mapper = matcher;
|
|
2442
|
+
matcher = /\r?\n/;
|
|
2443
|
+
} else if (typeof matcher === "object" && !(matcher instanceof RegExp) && !matcher[Symbol.split]) {
|
|
2444
|
+
options = matcher;
|
|
2445
|
+
matcher = /\r?\n/;
|
|
2446
|
+
}
|
|
2447
|
+
break;
|
|
2448
|
+
case 2: if (typeof matcher === "function") {
|
|
2449
|
+
options = mapper;
|
|
2450
|
+
mapper = matcher;
|
|
2451
|
+
matcher = /\r?\n/;
|
|
2452
|
+
} else if (typeof mapper === "object") {
|
|
2453
|
+
options = mapper;
|
|
2454
|
+
mapper = noop;
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
options = Object.assign({}, options);
|
|
2458
|
+
options.autoDestroy = true;
|
|
2459
|
+
options.transform = transform;
|
|
2460
|
+
options.flush = flush;
|
|
2461
|
+
options.readableObjectMode = true;
|
|
2462
|
+
const stream = new Transform(options);
|
|
2463
|
+
stream[kLast] = "";
|
|
2464
|
+
stream[kDecoder] = new StringDecoder("utf8");
|
|
2465
|
+
stream.matcher = matcher;
|
|
2466
|
+
stream.mapper = mapper;
|
|
2467
|
+
stream.maxLength = options.maxLength;
|
|
2468
|
+
stream.skipOverflow = options.skipOverflow || false;
|
|
2469
|
+
stream.overflow = false;
|
|
2470
|
+
stream._destroy = function(err, cb) {
|
|
2471
|
+
this._writableState.errorEmitted = false;
|
|
2472
|
+
cb(err);
|
|
2473
|
+
};
|
|
2474
|
+
return stream;
|
|
2475
|
+
}
|
|
2476
|
+
module.exports = split;
|
|
2477
|
+
}));
|
|
2478
|
+
//#endregion
|
|
1036
2479
|
//#region ../../node_modules/.pnpm/@pnpm+logger@1001.0.1/node_modules/@pnpm/logger/lib/ndjsonParse.js
|
|
1037
2480
|
var require_ndjsonParse = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1038
2481
|
var __importDefault = exports && exports.__importDefault || function(mod) {
|
|
@@ -1040,7 +2483,7 @@ var require_ndjsonParse = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
|
1040
2483
|
};
|
|
1041
2484
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1042
2485
|
exports.parse = parse;
|
|
1043
|
-
const split2_1 = __importDefault(
|
|
2486
|
+
const split2_1 = __importDefault(require_split2());
|
|
1044
2487
|
const opts = { strict: true };
|
|
1045
2488
|
function parse() {
|
|
1046
2489
|
function parseRow(row) {
|
|
@@ -9893,66 +11336,84 @@ function getPackageDirPath(path) {
|
|
|
9893
11336
|
}
|
|
9894
11337
|
//#endregion
|
|
9895
11338
|
//#region src/node/rpc/functions/rolldown-get-packages.ts
|
|
9896
|
-
|
|
9897
|
-
const
|
|
9898
|
-
|
|
9899
|
-
|
|
9900
|
-
|
|
9901
|
-
|
|
9902
|
-
|
|
9903
|
-
|
|
9904
|
-
|
|
9905
|
-
|
|
9906
|
-
if ((modulesMap.get(importer)?.imports?.map((i) => i.module_id) || []).some((i) => getPackageDirPath(i) === packageDir)) result.push(importer);
|
|
9907
|
-
result.push(...getImporters(importer, packageDir, visited));
|
|
11339
|
+
function createPackageManifestReader() {
|
|
11340
|
+
const manifestCache = /* @__PURE__ */ new Map();
|
|
11341
|
+
return (dir) => {
|
|
11342
|
+
let promise = manifestCache.get(dir);
|
|
11343
|
+
if (!promise) {
|
|
11344
|
+
promise = (0, import_lib.readProjectManifestOnly)(dir).catch((err) => {
|
|
11345
|
+
if (err?.code === "ERR_PNPM_NO_IMPORTER_MANIFEST_FOUND") return null;
|
|
11346
|
+
throw err;
|
|
11347
|
+
});
|
|
11348
|
+
manifestCache.set(dir, promise);
|
|
9908
11349
|
}
|
|
9909
|
-
return
|
|
11350
|
+
return promise;
|
|
9910
11351
|
};
|
|
9911
|
-
|
|
9912
|
-
|
|
11352
|
+
}
|
|
11353
|
+
async function getPackagesManifest(reader, readPackageManifest = createPackageManifestReader()) {
|
|
11354
|
+
const modulesMap = reader.manager.modules;
|
|
11355
|
+
const chunks = Array.from(reader.manager.chunks.values());
|
|
11356
|
+
const packagesMap = /* @__PURE__ */ new Map();
|
|
11357
|
+
const packageImportersMap = /* @__PURE__ */ new Map();
|
|
11358
|
+
const packageModules = chunks.flatMap((chunk) => chunk.modules).filter(isNodeModulePath).map((path) => {
|
|
11359
|
+
const moduleBuildMetrics = modulesMap.get(path)?.build_metrics;
|
|
9913
11360
|
return {
|
|
9914
|
-
path
|
|
9915
|
-
dir: getPackageDirPath(
|
|
9916
|
-
transformedCodeSize: moduleBuildMetrics?.transforms[moduleBuildMetrics
|
|
11361
|
+
path,
|
|
11362
|
+
dir: getPackageDirPath(path),
|
|
11363
|
+
transformedCodeSize: moduleBuildMetrics?.transforms[moduleBuildMetrics.transforms.length - 1]?.transformed_code_size ?? 0
|
|
9917
11364
|
};
|
|
9918
11365
|
});
|
|
9919
|
-
|
|
9920
|
-
|
|
9921
|
-
let
|
|
9922
|
-
|
|
9923
|
-
|
|
9924
|
-
|
|
9925
|
-
}
|
|
9926
|
-
|
|
9927
|
-
|
|
9928
|
-
|
|
9929
|
-
const
|
|
9930
|
-
|
|
9931
|
-
|
|
11366
|
+
const packageModulePaths = /* @__PURE__ */ new Map();
|
|
11367
|
+
for (const item of packageModules) {
|
|
11368
|
+
let paths = packageModulePaths.get(item.dir);
|
|
11369
|
+
if (!paths) {
|
|
11370
|
+
paths = /* @__PURE__ */ new Set();
|
|
11371
|
+
packageModulePaths.set(item.dir, paths);
|
|
11372
|
+
}
|
|
11373
|
+
paths.add(item.path);
|
|
11374
|
+
}
|
|
11375
|
+
const getPackageImporters = (packageDir) => {
|
|
11376
|
+
const cached = packageImportersMap.get(packageDir);
|
|
11377
|
+
if (cached) return cached;
|
|
11378
|
+
const importers = /* @__PURE__ */ new Set();
|
|
11379
|
+
for (const path of packageModulePaths.get(packageDir) ?? []) for (const importer of modulesMap.get(path)?.importers ?? []) {
|
|
11380
|
+
if (importer.startsWith(packageDir)) continue;
|
|
11381
|
+
if (modulesMap.get(importer)?.imports?.some((i) => getPackageDirPath(i.module_id) === packageDir)) importers.add(importer);
|
|
11382
|
+
}
|
|
11383
|
+
const result = Array.from(importers).sort((a, b) => a.localeCompare(b));
|
|
11384
|
+
packageImportersMap.set(packageDir, result);
|
|
11385
|
+
return result;
|
|
11386
|
+
};
|
|
11387
|
+
const manifests = await Promise.all(packageModules.map(async (item) => ({
|
|
11388
|
+
item,
|
|
11389
|
+
manifest: await readPackageManifest(item.dir)
|
|
11390
|
+
})));
|
|
11391
|
+
for (const { item, manifest } of manifests) {
|
|
11392
|
+
const packageKey = manifest ? `${manifest.name}@${manifest.version}` : `${item.dir}`;
|
|
11393
|
+
const packageInfo = packagesMap.get(packageKey);
|
|
11394
|
+
const importers = packageInfo ? [] : getPackageImporters(item.dir).map((path) => ({
|
|
11395
|
+
path,
|
|
9932
11396
|
version: ""
|
|
9933
11397
|
}));
|
|
9934
|
-
|
|
9935
|
-
|
|
9936
|
-
|
|
9937
|
-
|
|
9938
|
-
|
|
9939
|
-
|
|
9940
|
-
|
|
9941
|
-
|
|
9942
|
-
|
|
9943
|
-
|
|
9944
|
-
|
|
11398
|
+
const file = {
|
|
11399
|
+
path: item.path,
|
|
11400
|
+
transformedCodeSize: item.transformedCodeSize,
|
|
11401
|
+
importers
|
|
11402
|
+
};
|
|
11403
|
+
if (packageInfo) {
|
|
11404
|
+
packageInfo.files.push(file);
|
|
11405
|
+
packageInfo.transformedCodeSize += item.transformedCodeSize;
|
|
11406
|
+
continue;
|
|
11407
|
+
}
|
|
11408
|
+
packagesMap.set(packageKey, {
|
|
11409
|
+
name: manifest?.name || item.dir,
|
|
9945
11410
|
version: manifest?.version || "(unknown)",
|
|
9946
|
-
dir:
|
|
9947
|
-
files: [
|
|
9948
|
-
|
|
9949
|
-
transformedCodeSize: p.transformedCodeSize,
|
|
9950
|
-
importers
|
|
9951
|
-
}],
|
|
9952
|
-
transformedCodeSize: p.transformedCodeSize
|
|
11411
|
+
dir: item.dir,
|
|
11412
|
+
files: [file],
|
|
11413
|
+
transformedCodeSize: item.transformedCodeSize
|
|
9953
11414
|
});
|
|
9954
|
-
}
|
|
9955
|
-
return
|
|
11415
|
+
}
|
|
11416
|
+
return packagesMap;
|
|
9956
11417
|
}
|
|
9957
11418
|
const rolldownGetPackages = defineRpcFunction({
|
|
9958
11419
|
name: "vite:rolldown:get-packages",
|
|
@@ -9962,41 +11423,34 @@ const rolldownGetPackages = defineRpcFunction({
|
|
|
9962
11423
|
setup: (context) => {
|
|
9963
11424
|
const manager = getLogsManager(context);
|
|
9964
11425
|
return { handler: async ({ session }) => {
|
|
9965
|
-
const reader = await manager.
|
|
11426
|
+
const reader = await manager.loadPackageSession(session);
|
|
9966
11427
|
const modulesMap = reader.manager.modules;
|
|
9967
|
-
const
|
|
9968
|
-
const
|
|
9969
|
-
|
|
9970
|
-
|
|
9971
|
-
|
|
9972
|
-
|
|
9973
|
-
|
|
9974
|
-
|
|
9975
|
-
|
|
9976
|
-
|
|
9977
|
-
|
|
9978
|
-
if (duplicated) files = await Promise.all(files.map(async (f) => {
|
|
9979
|
-
const importers = await Promise.all(f.importers.map(async (i) => {
|
|
9980
|
-
let manifest = null;
|
|
9981
|
-
try {
|
|
9982
|
-
if (isNodeModulePath(i.path)) manifest = await (0, import_lib.readProjectManifestOnly)(getPackageDirPath(i.path));
|
|
9983
|
-
} catch (err) {
|
|
9984
|
-
if (err?.code !== "ERR_PNPM_NO_IMPORTER_MANIFEST_FOUND") throw err;
|
|
9985
|
-
}
|
|
11428
|
+
const packageNameCounts = /* @__PURE__ */ new Map();
|
|
11429
|
+
const readPackageManifest = createPackageManifestReader();
|
|
11430
|
+
const packagesMap = await getPackagesManifest(reader, readPackageManifest);
|
|
11431
|
+
const packages = Array.from(packagesMap.values());
|
|
11432
|
+
for (const item of packages) packageNameCounts.set(item.name, (packageNameCounts.get(item.name) ?? 0) + 1);
|
|
11433
|
+
return (await Promise.all(packages.map(async (item) => {
|
|
11434
|
+
const duplicated = (packageNameCounts.get(item.name) ?? 0) > 1;
|
|
11435
|
+
const files = duplicated ? await Promise.all(item.files.map(async (file) => {
|
|
11436
|
+
const importers = await Promise.all(file.importers.map(async (importer) => {
|
|
11437
|
+
if (!isNodeModulePath(importer.path)) return importer;
|
|
11438
|
+
const manifest = await readPackageManifest(getPackageDirPath(importer.path));
|
|
9986
11439
|
return {
|
|
9987
|
-
...
|
|
11440
|
+
...importer,
|
|
9988
11441
|
version: manifest?.version ?? ""
|
|
9989
11442
|
};
|
|
9990
11443
|
}));
|
|
9991
11444
|
return {
|
|
9992
|
-
...
|
|
11445
|
+
...file,
|
|
9993
11446
|
importers
|
|
9994
11447
|
};
|
|
9995
|
-
}));
|
|
11448
|
+
})) : item.files;
|
|
9996
11449
|
return {
|
|
9997
|
-
...
|
|
11450
|
+
...item,
|
|
9998
11451
|
duplicated,
|
|
9999
|
-
files
|
|
11452
|
+
files,
|
|
11453
|
+
type: item.files.some((f) => modulesMap.get(f.path)?.importers?.some((i) => i.includes(reader.meta.cwd))) ? "direct" : "transitive"
|
|
10000
11454
|
};
|
|
10001
11455
|
}))).filter((i) => !!i.transformedCodeSize);
|
|
10002
11456
|
} };
|
|
@@ -10012,7 +11466,7 @@ const rolldownGetPackageDetails = defineRpcFunction({
|
|
|
10012
11466
|
setup: (context) => {
|
|
10013
11467
|
const manager = getLogsManager(context);
|
|
10014
11468
|
return { handler: async ({ session, id }) => {
|
|
10015
|
-
return (await getPackagesManifest(await manager.
|
|
11469
|
+
return (await getPackagesManifest(await manager.loadPackageSession(session))).get(id);
|
|
10016
11470
|
} };
|
|
10017
11471
|
}
|
|
10018
11472
|
});
|
|
@@ -10027,6 +11481,7 @@ const rolldownGetPluginDetails = defineRpcFunction({
|
|
|
10027
11481
|
const manager = getLogsManager(context);
|
|
10028
11482
|
return { handler: async ({ session, id }) => {
|
|
10029
11483
|
const reader = await manager.loadSession(session);
|
|
11484
|
+
await reader.hydratePluginBuildMetrics(+id);
|
|
10030
11485
|
const pluginBuildMetrics = reader.manager.plugin_build_metrics.get(+id);
|
|
10031
11486
|
if (!pluginBuildMetrics) return {
|
|
10032
11487
|
plugin_name: reader.meta.plugins.find((p) => p.plugin_id === +id)?.name,
|
|
@@ -10049,19 +11504,6 @@ const rolldownGetPluginDetails = defineRpcFunction({
|
|
|
10049
11504
|
}
|
|
10050
11505
|
});
|
|
10051
11506
|
//#endregion
|
|
10052
|
-
//#region src/node/rpc/functions/rolldown-get-raw-events.ts
|
|
10053
|
-
const rolldownGetRawEvents = defineRpcFunction({
|
|
10054
|
-
name: "vite:rolldown:get-raw-events",
|
|
10055
|
-
type: "query",
|
|
10056
|
-
jsonSerializable: true,
|
|
10057
|
-
setup: (context) => {
|
|
10058
|
-
const manager = getLogsManager(context);
|
|
10059
|
-
return { handler: async ({ session }) => {
|
|
10060
|
-
return (await manager.loadSession(session)).manager.events;
|
|
10061
|
-
} };
|
|
10062
|
-
}
|
|
10063
|
-
});
|
|
10064
|
-
//#endregion
|
|
10065
11507
|
//#region src/node/rpc/functions/rolldown-get-session-compare-summary.ts
|
|
10066
11508
|
const rolldownGetSessionCompareSummary = defineRpcFunction({
|
|
10067
11509
|
name: "vite:rolldown:get-session-compare-summary",
|
|
@@ -10071,7 +11513,7 @@ const rolldownGetSessionCompareSummary = defineRpcFunction({
|
|
|
10071
11513
|
setup: async (context) => {
|
|
10072
11514
|
const manager = getLogsManager(context);
|
|
10073
11515
|
return { handler: async ({ sessions }) => {
|
|
10074
|
-
const reader = await Promise.all(sessions.map((s) => manager.
|
|
11516
|
+
const reader = await Promise.all(sessions.map((s) => manager.loadAssetSession(s)));
|
|
10075
11517
|
return sessions.map((s, index) => {
|
|
10076
11518
|
const _reader = reader[index];
|
|
10077
11519
|
const assets = Array.from(_reader.manager.assets.values());
|
|
@@ -10104,7 +11546,7 @@ const rolldownGetSessionSummary = defineRpcFunction({
|
|
|
10104
11546
|
setup: async (context) => {
|
|
10105
11547
|
const manager = getLogsManager(context);
|
|
10106
11548
|
return { handler: async ({ session }) => {
|
|
10107
|
-
const reader = await manager.
|
|
11549
|
+
const reader = await manager.loadSessionSummary(session);
|
|
10108
11550
|
return {
|
|
10109
11551
|
id: session,
|
|
10110
11552
|
meta: reader.meta,
|
|
@@ -10129,10 +11571,8 @@ const rpcFunctions = [
|
|
|
10129
11571
|
} };
|
|
10130
11572
|
}
|
|
10131
11573
|
}),
|
|
10132
|
-
rolldownGetRawEvents,
|
|
10133
11574
|
rolldownGetSessionSummary,
|
|
10134
11575
|
rolldownGetModuleInfo,
|
|
10135
|
-
rolldownGetModuleRawEvents,
|
|
10136
11576
|
rolldownGetModuleTransforms,
|
|
10137
11577
|
rolldownGetChunksGraph,
|
|
10138
11578
|
rolldownGetAssetsList,
|