@vitejs/devtools-vite 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dirs.d.mts +1 -3
- package/dist/dirs.mjs +1 -2
- package/dist/index.d.mts +1 -8
- package/dist/index.mjs +414 -278
- package/dist/nitro.json +2 -2
- package/dist/public/200.html +1 -1
- package/dist/public/404.html +1 -1
- package/dist/public/_nuxt/BG--lX9h.js +2 -0
- package/dist/public/_nuxt/BG3xwZh0.js +3 -0
- package/dist/public/_nuxt/BHvJDY_a.js +1 -0
- package/dist/public/_nuxt/BRJBCNrs.js +1 -0
- package/dist/public/_nuxt/B_-pr0hI.js +1 -0
- package/dist/public/_nuxt/{mSprtK4_.js → B_NKCZsG.js} +5 -5
- package/dist/public/_nuxt/{BQP5SyRf.js → CEBMiqg6.js} +1 -1
- package/dist/public/_nuxt/Ct3C12NP.js +4 -0
- package/dist/public/_nuxt/Cya-tyvy.js +1 -0
- package/dist/public/_nuxt/DEyNBz-F.js +2 -0
- package/dist/public/_nuxt/DSAFJh4r.js +1 -0
- package/dist/public/_nuxt/DbCy1lFc.js +1 -0
- package/dist/public/_nuxt/Dp2A4F6Z.js +1 -0
- package/dist/public/_nuxt/builds/latest.json +1 -1
- package/dist/public/_nuxt/builds/meta/13f74333-301c-46d6-87fb-e1b6264a3189.json +1 -0
- package/dist/public/_nuxt/{entry.CiImqaiE.css → entry.bKphV1Y3.css} +1 -1
- package/dist/public/_nuxt/error-404.BtjbGiHS.css +1 -0
- package/dist/public/_nuxt/error-500.DqJ9a5ig.css +1 -0
- package/dist/public/_nuxt/n6SbU7pj.js +1 -0
- package/dist/public/_nuxt/rpc.CVTFzytL.css +1 -0
- package/dist/public/index.html +1 -1
- package/package.json +9 -9
- package/dist/public/_nuxt/-2hSMOj2.js +0 -1
- package/dist/public/_nuxt/B48W2q7f.js +0 -1
- package/dist/public/_nuxt/Bd-dcbuk.js +0 -1
- package/dist/public/_nuxt/CgY19zhT.js +0 -3
- package/dist/public/_nuxt/CjMCFT1j.js +0 -1
- package/dist/public/_nuxt/CqzDam8I.js +0 -1
- package/dist/public/_nuxt/D4ZxPEz8.js +0 -4
- package/dist/public/_nuxt/D5PRIZYS.js +0 -1
- package/dist/public/_nuxt/DaPjiAxH.js +0 -1
- package/dist/public/_nuxt/DnZCvkEg.js +0 -1
- package/dist/public/_nuxt/builds/meta/66be3f43-4a09-44c2-ae4a-823a2e23609d.json +0 -1
- package/dist/public/_nuxt/davnVqEL.js +0 -2
- package/dist/public/_nuxt/error-404.CfNyXncy.css +0 -1
- package/dist/public/_nuxt/error-500.BK534K7U.css +0 -1
- package/dist/public/_nuxt/tNxfX9P9.js +0 -1
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { Buffer } from "node:buffer";
|
|
|
9
9
|
import { relative } from "pathe";
|
|
10
10
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
11
11
|
import { open } from "node:fs/promises";
|
|
12
|
-
|
|
12
|
+
// src/node/diagnostics.ts
|
|
13
13
|
const diagnostics = /* #__PURE__ */ defineDiagnostics({
|
|
14
14
|
docsBase: "https://devtools.vite.dev/errors",
|
|
15
15
|
reporters: [createConsoleReporter()],
|
|
@@ -19,11 +19,14 @@ const diagnostics = /* #__PURE__ */ defineDiagnostics({
|
|
|
19
19
|
VDT0003: {
|
|
20
20
|
why: (p) => `Vite inspect storage failed while ${p.operation}.`,
|
|
21
21
|
fix: "Restart the Vite dev server. If the error persists, clear the Vite cache directory and reinstall dependencies."
|
|
22
|
+
},
|
|
23
|
+
VDT0004: {
|
|
24
|
+
why: (p) => `Vite inspect could not write the ${p.archive} archive to disk and now keeps new records in memory.`,
|
|
25
|
+
fix: "Check that the Vite cache directory is writable and has free disk space, then restart the Vite dev server to resume writing to disk."
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
});
|
|
25
|
-
|
|
26
|
-
//#region src/node/inspect/utils.ts
|
|
29
|
+
// src/node/inspect/utils.ts
|
|
27
30
|
const DUMMY_LOAD_PLUGIN_NAME = "__load__";
|
|
28
31
|
function serializePlugin(plugin) {
|
|
29
32
|
return JSON.parse(JSON.stringify(plugin, (key, value) => {
|
|
@@ -82,8 +85,8 @@ async function getAllModuleIds(ctx) {
|
|
|
82
85
|
}
|
|
83
86
|
return result;
|
|
84
87
|
}
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
// src/node/inspect/module.ts
|
|
89
|
+
const MODULES_LIST_SLICE_MS = 4;
|
|
87
90
|
async function getModulesList(ctx, pluginCtx) {
|
|
88
91
|
const moduleGraph = ctx.env.mode === "dev" ? ctx.env.moduleGraph : void 0;
|
|
89
92
|
const getDeps = moduleGraph ? (id) => Array.from(moduleGraph.getModuleById(id)?.importedModules || []).map((module) => module.id || "").filter(Boolean) : pluginCtx ? (id) => Array.from(pluginCtx.getModuleInfo(id)?.importedIds || []) : () => [];
|
|
@@ -110,7 +113,7 @@ async function getModulesList(ctx, pluginCtx) {
|
|
|
110
113
|
return map;
|
|
111
114
|
}, {});
|
|
112
115
|
const ids = new Set(Object.keys(transformsById).concat(Object.keys(transformedIdMap)));
|
|
113
|
-
|
|
116
|
+
const toModuleInfo = (id) => {
|
|
114
117
|
let totalTime = 0;
|
|
115
118
|
const transforms = transformsById[id] || [];
|
|
116
119
|
const transformPlugins = transforms.map((transform) => {
|
|
@@ -141,7 +144,17 @@ async function getModulesList(ctx, pluginCtx) {
|
|
|
141
144
|
sourceSize: firstTransform?.hasResult ? firstTransform.resultSize : 0,
|
|
142
145
|
distSize: lastTransform?.hasResult ? lastTransform.resultSize : 0
|
|
143
146
|
};
|
|
144
|
-
}
|
|
147
|
+
};
|
|
148
|
+
const modules = [];
|
|
149
|
+
let sliceStart = performance.now();
|
|
150
|
+
for (const id of Array.from(ids).sort()) {
|
|
151
|
+
modules.push(toModuleInfo(id));
|
|
152
|
+
if (performance.now() - sliceStart > MODULES_LIST_SLICE_MS) {
|
|
153
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
154
|
+
sliceStart = performance.now();
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return modules;
|
|
145
158
|
}
|
|
146
159
|
function createGraphModuleIdResolver(moduleIds, extensions = []) {
|
|
147
160
|
const moduleIdMap = /* @__PURE__ */ new Map();
|
|
@@ -177,8 +190,7 @@ function removeResolvedExtension(id, extensions) {
|
|
|
177
190
|
const extension = extensions.find((extension) => path.endsWith(extension));
|
|
178
191
|
return extension ? `${path.slice(0, -extension.length)}${query}` : void 0;
|
|
179
192
|
}
|
|
180
|
-
|
|
181
|
-
//#region src/node/inspect/plugins.ts
|
|
193
|
+
// src/node/inspect/plugins.ts
|
|
182
194
|
async function getPluginMetrics(ctx) {
|
|
183
195
|
const map = {};
|
|
184
196
|
const defaultMetricInfo = () => ({
|
|
@@ -240,8 +252,7 @@ async function withGraphModuleIds(ctx, calls) {
|
|
|
240
252
|
graphModuleId: resolveGraphModuleId(call.module)
|
|
241
253
|
}));
|
|
242
254
|
}
|
|
243
|
-
|
|
244
|
-
//#region src/node/inspect/server.ts
|
|
255
|
+
// src/node/inspect/server.ts
|
|
245
256
|
const timestampRE = /\bt=\d{13}&?\b/;
|
|
246
257
|
const trailingSeparatorRE = /[?&]$/;
|
|
247
258
|
const transformRequestStorage = new AsyncLocalStorage();
|
|
@@ -337,8 +348,8 @@ function setupMiddlewarePerformance(vite, middlewares) {
|
|
|
337
348
|
});
|
|
338
349
|
});
|
|
339
350
|
}
|
|
340
|
-
|
|
341
|
-
|
|
351
|
+
// src/node/inspect/store/payload.ts
|
|
352
|
+
const MAX_SIZE_BUCKET = 53;
|
|
342
353
|
async function createInspectPayloadStore(filename) {
|
|
343
354
|
if (!filename) return new MemoryInspectPayloadStore();
|
|
344
355
|
return new FileInspectPayloadStore(await open(filename, "w+"));
|
|
@@ -375,6 +386,8 @@ var FileInspectPayloadStore = class {
|
|
|
375
386
|
file;
|
|
376
387
|
nextOffset = 0;
|
|
377
388
|
freeRanges = [];
|
|
389
|
+
freeRangesBySize = /* @__PURE__ */ new Map();
|
|
390
|
+
fallback;
|
|
378
391
|
constructor(file) {
|
|
379
392
|
this.file = file;
|
|
380
393
|
}
|
|
@@ -394,11 +407,23 @@ var FileInspectPayloadStore = class {
|
|
|
394
407
|
range
|
|
395
408
|
});
|
|
396
409
|
}
|
|
397
|
-
|
|
410
|
+
if (!this.fallback) try {
|
|
411
|
+
await this.writeAllocatedPayloads(writes);
|
|
412
|
+
return ranges;
|
|
413
|
+
} catch (error) {
|
|
414
|
+
this.fallback = /* @__PURE__ */ new Map();
|
|
415
|
+
diagnostics.VDT0004({
|
|
416
|
+
archive: "payload",
|
|
417
|
+
cause: error instanceof Error ? error : new Error(String(error))
|
|
418
|
+
});
|
|
419
|
+
}
|
|
420
|
+
for (const { buffer, range } of writes) this.fallback.set(range.offset, buffer);
|
|
398
421
|
return ranges;
|
|
399
422
|
}
|
|
400
423
|
async read(range) {
|
|
401
424
|
if (range.length === 0) return "";
|
|
425
|
+
const fallback = this.fallback?.get(range.offset);
|
|
426
|
+
if (fallback?.length === range.length) return fallback.toString();
|
|
402
427
|
const buffer = Buffer.allocUnsafe(range.length);
|
|
403
428
|
let readOffset = 0;
|
|
404
429
|
while (readOffset < buffer.length) {
|
|
@@ -410,33 +435,38 @@ var FileInspectPayloadStore = class {
|
|
|
410
435
|
}
|
|
411
436
|
async close() {
|
|
412
437
|
this.freeRanges.length = 0;
|
|
438
|
+
this.freeRangesBySize.clear();
|
|
439
|
+
this.fallback?.clear();
|
|
413
440
|
await this.file.close();
|
|
414
441
|
}
|
|
415
442
|
reclaim(ranges) {
|
|
416
|
-
|
|
417
|
-
this.
|
|
443
|
+
for (const range of ranges) this.fallback?.delete(range.offset);
|
|
444
|
+
for (const range of ranges) if (range.length > 0) this.insertFreeRange(range.offset, range.length);
|
|
418
445
|
}
|
|
419
446
|
allocate(length) {
|
|
420
447
|
if (length === 0) return {
|
|
421
448
|
offset: this.nextOffset,
|
|
422
449
|
length
|
|
423
450
|
};
|
|
424
|
-
let
|
|
425
|
-
for (let
|
|
426
|
-
const range
|
|
427
|
-
|
|
428
|
-
|
|
451
|
+
let best;
|
|
452
|
+
for (let bucket = sizeBucket(length); bucket <= MAX_SIZE_BUCKET; bucket++) {
|
|
453
|
+
for (const range of this.freeRangesBySize.get(bucket) ?? []) {
|
|
454
|
+
if (range.length < length) continue;
|
|
455
|
+
if (!best || range.length < best.length || range.length === best.length && range.offset < best.offset) best = range;
|
|
456
|
+
}
|
|
457
|
+
if (best) break;
|
|
429
458
|
}
|
|
430
|
-
if (
|
|
431
|
-
const range = this.freeRanges[bestIndex];
|
|
459
|
+
if (best) {
|
|
432
460
|
const allocated = {
|
|
433
|
-
offset:
|
|
461
|
+
offset: best.offset,
|
|
434
462
|
length
|
|
435
463
|
};
|
|
436
|
-
|
|
464
|
+
this.removeFromSizeBucket(best);
|
|
465
|
+
if (best.length === length) this.freeRanges.splice(this.findFreeRangeIndex(best.offset), 1);
|
|
437
466
|
else {
|
|
438
|
-
|
|
439
|
-
|
|
467
|
+
best.offset += length;
|
|
468
|
+
best.length -= length;
|
|
469
|
+
this.addToSizeBucket(best);
|
|
440
470
|
}
|
|
441
471
|
return allocated;
|
|
442
472
|
}
|
|
@@ -447,6 +477,55 @@ var FileInspectPayloadStore = class {
|
|
|
447
477
|
this.nextOffset += length;
|
|
448
478
|
return allocated;
|
|
449
479
|
}
|
|
480
|
+
insertFreeRange(offset, length) {
|
|
481
|
+
let end = offset + length;
|
|
482
|
+
let index = this.findFreeRangeIndex(offset);
|
|
483
|
+
let start = offset;
|
|
484
|
+
const previous = this.freeRanges[index - 1];
|
|
485
|
+
if (previous && previous.offset + previous.length >= start) {
|
|
486
|
+
index -= 1;
|
|
487
|
+
start = previous.offset;
|
|
488
|
+
end = Math.max(end, previous.offset + previous.length);
|
|
489
|
+
}
|
|
490
|
+
let removeCount = 0;
|
|
491
|
+
while (index + removeCount < this.freeRanges.length && this.freeRanges[index + removeCount].offset <= end) {
|
|
492
|
+
const next = this.freeRanges[index + removeCount];
|
|
493
|
+
end = Math.max(end, next.offset + next.length);
|
|
494
|
+
removeCount += 1;
|
|
495
|
+
}
|
|
496
|
+
for (let i = index; i < index + removeCount; i++) this.removeFromSizeBucket(this.freeRanges[i]);
|
|
497
|
+
const merged = {
|
|
498
|
+
offset: start,
|
|
499
|
+
length: end - start
|
|
500
|
+
};
|
|
501
|
+
this.freeRanges.splice(index, removeCount, merged);
|
|
502
|
+
this.addToSizeBucket(merged);
|
|
503
|
+
}
|
|
504
|
+
findFreeRangeIndex(offset) {
|
|
505
|
+
let low = 0;
|
|
506
|
+
let high = this.freeRanges.length;
|
|
507
|
+
while (low < high) {
|
|
508
|
+
const middle = low + high >>> 1;
|
|
509
|
+
if (this.freeRanges[middle].offset < offset) low = middle + 1;
|
|
510
|
+
else high = middle;
|
|
511
|
+
}
|
|
512
|
+
return low;
|
|
513
|
+
}
|
|
514
|
+
addToSizeBucket(range) {
|
|
515
|
+
const bucket = sizeBucket(range.length);
|
|
516
|
+
let ranges = this.freeRangesBySize.get(bucket);
|
|
517
|
+
if (!ranges) {
|
|
518
|
+
ranges = /* @__PURE__ */ new Set();
|
|
519
|
+
this.freeRangesBySize.set(bucket, ranges);
|
|
520
|
+
}
|
|
521
|
+
ranges.add(range);
|
|
522
|
+
}
|
|
523
|
+
removeFromSizeBucket(range) {
|
|
524
|
+
const bucket = sizeBucket(range.length);
|
|
525
|
+
const ranges = this.freeRangesBySize.get(bucket);
|
|
526
|
+
ranges?.delete(range);
|
|
527
|
+
if (ranges?.size === 0) this.freeRangesBySize.delete(bucket);
|
|
528
|
+
}
|
|
450
529
|
async writeAllocatedPayloads(writes) {
|
|
451
530
|
const ordered = writes.toSorted((a, b) => a.range.offset - b.range.offset);
|
|
452
531
|
let buffers = [];
|
|
@@ -473,20 +552,10 @@ var FileInspectPayloadStore = class {
|
|
|
473
552
|
offset += bytesWritten;
|
|
474
553
|
}
|
|
475
554
|
}
|
|
476
|
-
mergeFreeRanges() {
|
|
477
|
-
this.freeRanges.sort((a, b) => a.offset - b.offset);
|
|
478
|
-
const merged = [];
|
|
479
|
-
for (const range of this.freeRanges) {
|
|
480
|
-
const previous = merged.at(-1);
|
|
481
|
-
if (!previous || range.offset > previous.offset + previous.length) {
|
|
482
|
-
merged.push({ ...range });
|
|
483
|
-
continue;
|
|
484
|
-
}
|
|
485
|
-
previous.length = Math.max(previous.length, range.offset + range.length - previous.offset);
|
|
486
|
-
}
|
|
487
|
-
this.freeRanges = merged;
|
|
488
|
-
}
|
|
489
555
|
};
|
|
556
|
+
function sizeBucket(length) {
|
|
557
|
+
return Math.floor(Math.log2(length));
|
|
558
|
+
}
|
|
490
559
|
function consumeBuffers$1(input, bytes) {
|
|
491
560
|
const buffers = input.slice();
|
|
492
561
|
let consumed = bytes;
|
|
@@ -497,8 +566,7 @@ function consumeBuffers$1(input, bytes) {
|
|
|
497
566
|
if (buffers.length > 0 && consumed > 0) buffers[0] = buffers[0].subarray(consumed);
|
|
498
567
|
return buffers;
|
|
499
568
|
}
|
|
500
|
-
|
|
501
|
-
//#region src/node/inspect/store/plugin-calls.ts
|
|
569
|
+
// src/node/inspect/store/plugin-calls.ts
|
|
502
570
|
const RECORD_SIZE = 40;
|
|
503
571
|
const RECORDS_PER_SEGMENT = 256;
|
|
504
572
|
const SEGMENT_HEADER_SIZE = 32;
|
|
@@ -787,10 +855,35 @@ var BinaryInspectPluginCallStore = class {
|
|
|
787
855
|
};
|
|
788
856
|
var FilePluginCallStorage = class {
|
|
789
857
|
file;
|
|
858
|
+
fallback;
|
|
790
859
|
constructor(file) {
|
|
791
860
|
this.file = file;
|
|
792
861
|
}
|
|
793
862
|
async write(input, startPosition) {
|
|
863
|
+
if (!this.fallback) try {
|
|
864
|
+
await this.writeFile(input, startPosition);
|
|
865
|
+
return;
|
|
866
|
+
} catch (error) {
|
|
867
|
+
this.fallback = {
|
|
868
|
+
start: startPosition,
|
|
869
|
+
storage: new MemoryPluginCallStorage()
|
|
870
|
+
};
|
|
871
|
+
diagnostics.VDT0004({
|
|
872
|
+
archive: "plugin call",
|
|
873
|
+
cause: error instanceof Error ? error : new Error(String(error))
|
|
874
|
+
});
|
|
875
|
+
}
|
|
876
|
+
await this.fallback.storage.write(input, startPosition - this.fallback.start);
|
|
877
|
+
}
|
|
878
|
+
async read(position, length) {
|
|
879
|
+
if (this.fallback && position >= this.fallback.start) return this.fallback.storage.read(position - this.fallback.start, length);
|
|
880
|
+
return this.readFile(position, length);
|
|
881
|
+
}
|
|
882
|
+
async close() {
|
|
883
|
+
await this.fallback?.storage.close();
|
|
884
|
+
await this.file.close();
|
|
885
|
+
}
|
|
886
|
+
async writeFile(input, startPosition) {
|
|
794
887
|
let buffers = input;
|
|
795
888
|
let position = startPosition;
|
|
796
889
|
while (buffers.length > 0) {
|
|
@@ -800,7 +893,7 @@ var FilePluginCallStorage = class {
|
|
|
800
893
|
position += bytesWritten;
|
|
801
894
|
}
|
|
802
895
|
}
|
|
803
|
-
async
|
|
896
|
+
async readFile(position, length) {
|
|
804
897
|
const buffer = Buffer.allocUnsafe(length);
|
|
805
898
|
let offset = 0;
|
|
806
899
|
while (offset < buffer.length) {
|
|
@@ -810,9 +903,6 @@ var FilePluginCallStorage = class {
|
|
|
810
903
|
}
|
|
811
904
|
return buffer.subarray(0, offset);
|
|
812
905
|
}
|
|
813
|
-
async close() {
|
|
814
|
-
await this.file.close();
|
|
815
|
-
}
|
|
816
906
|
};
|
|
817
907
|
var MemoryPluginCallStorage = class {
|
|
818
908
|
buffer = Buffer.alloc(0);
|
|
@@ -906,8 +996,7 @@ function yieldToEventLoop() {
|
|
|
906
996
|
function toError$1(error) {
|
|
907
997
|
return error instanceof Error ? error : new Error(String(error));
|
|
908
998
|
}
|
|
909
|
-
|
|
910
|
-
//#region src/node/inspect/store/index.ts
|
|
999
|
+
// src/node/inspect/store/index.ts
|
|
911
1000
|
const DEFAULT_MAX_BATCH_ITEMS = 256;
|
|
912
1001
|
const DEFAULT_MAX_BATCH_BYTES = 8388608;
|
|
913
1002
|
async function createViteInspectStore(options = {}) {
|
|
@@ -944,6 +1033,7 @@ var PayloadViteInspectStore = class {
|
|
|
944
1033
|
peakQueuedItems = 0;
|
|
945
1034
|
peakQueuedBytes = 0;
|
|
946
1035
|
writeBatches = 0;
|
|
1036
|
+
changeVersion = 0;
|
|
947
1037
|
activeReaders = 0;
|
|
948
1038
|
readerWaiters = [];
|
|
949
1039
|
constructor(payloads, pluginCalls, options) {
|
|
@@ -1088,6 +1178,9 @@ var PayloadViteInspectStore = class {
|
|
|
1088
1178
|
for (const resolveIds of data.resolveIds.values()) for (const resolveId of resolveIds) moduleIds.add(resolveId.result);
|
|
1089
1179
|
return Array.from(moduleIds);
|
|
1090
1180
|
}
|
|
1181
|
+
getChangeVersion() {
|
|
1182
|
+
return this.changeVersion;
|
|
1183
|
+
}
|
|
1091
1184
|
getStats() {
|
|
1092
1185
|
return {
|
|
1093
1186
|
maxBatchItems: this.maxBatchItems,
|
|
@@ -1119,6 +1212,7 @@ var PayloadViteInspectStore = class {
|
|
|
1119
1212
|
}
|
|
1120
1213
|
enqueue(write) {
|
|
1121
1214
|
if (this.closing || this.closed || this.lastWriteError) return;
|
|
1215
|
+
if (write.operation !== "clearPendingLoadMetrics") this.changeVersion += 1;
|
|
1122
1216
|
const estimatedBytes = estimateWriteBytes(write);
|
|
1123
1217
|
this.queue.push({
|
|
1124
1218
|
write,
|
|
@@ -1204,19 +1298,38 @@ var PayloadViteInspectStore = class {
|
|
|
1204
1298
|
const values = [];
|
|
1205
1299
|
const prepared = [];
|
|
1206
1300
|
const pluginCallWrites = [];
|
|
1207
|
-
const
|
|
1208
|
-
const
|
|
1209
|
-
|
|
1210
|
-
|
|
1301
|
+
const moduleStates = /* @__PURE__ */ new Map();
|
|
1302
|
+
const getModuleState = (scope, moduleId) => {
|
|
1303
|
+
let scoped = moduleStates.get(scope);
|
|
1304
|
+
if (!scoped) {
|
|
1305
|
+
scoped = /* @__PURE__ */ new Map();
|
|
1306
|
+
moduleStates.set(scope, scoped);
|
|
1307
|
+
}
|
|
1308
|
+
let state = scoped.get(moduleId);
|
|
1211
1309
|
if (!state) {
|
|
1310
|
+
state = {};
|
|
1311
|
+
scoped.set(moduleId, state);
|
|
1312
|
+
}
|
|
1313
|
+
return state;
|
|
1314
|
+
};
|
|
1315
|
+
const pushCode = (state, value) => {
|
|
1316
|
+
if (value != null && state.latest?.value === value) return state.latest.index;
|
|
1317
|
+
const index = values.push(value) - 1;
|
|
1318
|
+
if (value != null) state.latest = {
|
|
1319
|
+
value,
|
|
1320
|
+
index
|
|
1321
|
+
};
|
|
1322
|
+
return index;
|
|
1323
|
+
};
|
|
1324
|
+
const hasSource = (state, scope, moduleId, transformRequest) => {
|
|
1325
|
+
if (!state.source) {
|
|
1212
1326
|
const stored = this.scopes.get(scope)?.transforms.get(moduleId);
|
|
1213
|
-
state = {
|
|
1327
|
+
state.source = {
|
|
1214
1328
|
hasSource: stored?.items.some((item) => item.hasResult) ?? false,
|
|
1215
1329
|
transformRequest: stored?.transformRequest
|
|
1216
1330
|
};
|
|
1217
|
-
sourceState.set(key, state);
|
|
1218
1331
|
}
|
|
1219
|
-
return state.hasSource && (!transformRequest || state.transformRequest === transformRequest);
|
|
1332
|
+
return state.source.hasSource && (!transformRequest || state.source.transformRequest === transformRequest);
|
|
1220
1333
|
};
|
|
1221
1334
|
for (const write of writes) {
|
|
1222
1335
|
const pluginCall = getQueuedPluginCall(write);
|
|
@@ -1227,23 +1340,24 @@ var PayloadViteInspectStore = class {
|
|
|
1227
1340
|
if (write.operation === "recordPluginCall" && write.info.type !== "load") continue;
|
|
1228
1341
|
const item = { write };
|
|
1229
1342
|
if (write.operation === "recordTransform") {
|
|
1230
|
-
const
|
|
1231
|
-
if (!hasSource(write.scope, write.moduleId, write.transformRequest)) {
|
|
1232
|
-
|
|
1233
|
-
|
|
1343
|
+
const state = getModuleState(write.scope, write.moduleId);
|
|
1344
|
+
if (!hasSource(state, write.scope, write.moduleId, write.transformRequest)) {
|
|
1345
|
+
state.latest = void 0;
|
|
1346
|
+
item.sourceIndex = pushCode(state, write.preTransformCode);
|
|
1347
|
+
state.source = {
|
|
1234
1348
|
hasSource: true,
|
|
1235
1349
|
transformRequest: write.transformRequest
|
|
1236
|
-
}
|
|
1350
|
+
};
|
|
1237
1351
|
}
|
|
1238
|
-
item.resultIndex =
|
|
1239
|
-
item.sourcemapIndex = pushSerializedPayload(values, write.info.sourcemaps);
|
|
1352
|
+
item.resultIndex = pushCode(state, write.info.result);
|
|
1240
1353
|
} else if (write.operation === "recordLoad") {
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1354
|
+
const state = getModuleState(write.scope, write.moduleId);
|
|
1355
|
+
state.latest = void 0;
|
|
1356
|
+
item.resultIndex = pushCode(state, write.info.result);
|
|
1357
|
+
state.source = {
|
|
1244
1358
|
hasSource: write.info.result != null,
|
|
1245
1359
|
transformRequest: write.transformRequest
|
|
1246
|
-
}
|
|
1360
|
+
};
|
|
1247
1361
|
}
|
|
1248
1362
|
prepared.push(item);
|
|
1249
1363
|
}
|
|
@@ -1252,8 +1366,8 @@ var PayloadViteInspectStore = class {
|
|
|
1252
1366
|
}
|
|
1253
1367
|
applyPreparedWrite(prepared, ranges) {
|
|
1254
1368
|
const { write } = prepared;
|
|
1255
|
-
if (write.operation === "recordTransform") this.applyTransform(write, rangeAt(ranges, prepared.resultIndex), rangeAt(ranges, prepared.sourceIndex)
|
|
1256
|
-
else if (write.operation === "recordLoad") this.applyLoad(write, rangeAt(ranges, prepared.resultIndex)
|
|
1369
|
+
if (write.operation === "recordTransform") this.applyTransform(write, rangeAt(ranges, prepared.resultIndex), rangeAt(ranges, prepared.sourceIndex));
|
|
1370
|
+
else if (write.operation === "recordLoad") this.applyLoad(write, rangeAt(ranges, prepared.resultIndex));
|
|
1257
1371
|
else if (write.operation === "recordPluginCall" && write.info.type === "load") {
|
|
1258
1372
|
const data = this.getScope(write.scope);
|
|
1259
1373
|
let pendingLoadMetrics = data.pendingLoadMetrics.get(write.transformRequest);
|
|
@@ -1267,26 +1381,18 @@ var PayloadViteInspectStore = class {
|
|
|
1267
1381
|
pendingLoadMetrics.set(write.info.module, metrics);
|
|
1268
1382
|
}
|
|
1269
1383
|
addMetric(metrics, write.info.plugin_id, write.info.plugin_name, write.info.duration);
|
|
1270
|
-
} else if (write.operation === "recordResolveId") {
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
result: write.info.result,
|
|
1281
|
-
resultPublicId: write.resultPublicId,
|
|
1282
|
-
name: write.info.name,
|
|
1283
|
-
pluginId: write.info.plugin_id,
|
|
1284
|
-
start: write.info.start,
|
|
1285
|
-
end: write.info.end
|
|
1286
|
-
});
|
|
1287
|
-
}
|
|
1384
|
+
} else if (write.operation === "recordResolveId") addResolveId(this.getScope(write.scope), {
|
|
1385
|
+
sourceId: write.sourceId,
|
|
1386
|
+
sourcePublicId: write.sourcePublicId,
|
|
1387
|
+
result: write.info.result,
|
|
1388
|
+
resultPublicId: write.resultPublicId,
|
|
1389
|
+
name: write.info.name,
|
|
1390
|
+
pluginId: write.info.plugin_id,
|
|
1391
|
+
start: write.info.start,
|
|
1392
|
+
end: write.info.end
|
|
1393
|
+
});
|
|
1288
1394
|
}
|
|
1289
|
-
applyTransform(write, result, source
|
|
1395
|
+
applyTransform(write, result, source) {
|
|
1290
1396
|
const data = this.getScope(write.scope);
|
|
1291
1397
|
let transforms = data.transforms.get(write.moduleId);
|
|
1292
1398
|
if (!transforms || write.transformRequest && transforms.transformRequest !== write.transformRequest) {
|
|
@@ -1297,7 +1403,7 @@ var PayloadViteInspectStore = class {
|
|
|
1297
1403
|
invokeCount: transforms?.invokeCount ?? 0,
|
|
1298
1404
|
items: []
|
|
1299
1405
|
};
|
|
1300
|
-
data
|
|
1406
|
+
setTransforms(data, write.moduleId, transforms);
|
|
1301
1407
|
}
|
|
1302
1408
|
if (!transforms.items.some((item) => item.hasResult)) {
|
|
1303
1409
|
this.commitDeclinedLoadMetrics(data, write.publicModuleId, write.transformRequest);
|
|
@@ -1307,23 +1413,22 @@ var PayloadViteInspectStore = class {
|
|
|
1307
1413
|
result: source,
|
|
1308
1414
|
resultSize: source?.length ?? 0,
|
|
1309
1415
|
start: write.info.start,
|
|
1310
|
-
end: write.info.start
|
|
1311
|
-
sourcemaps
|
|
1416
|
+
end: write.info.start
|
|
1312
1417
|
});
|
|
1313
1418
|
transforms.invokeCount += 1;
|
|
1314
1419
|
}
|
|
1315
|
-
transforms.items.push(toStoredTransformInfo(write.info, result
|
|
1420
|
+
transforms.items.push(toStoredTransformInfo(write.info, result));
|
|
1316
1421
|
}
|
|
1317
|
-
applyLoad(write, result
|
|
1422
|
+
applyLoad(write, result) {
|
|
1318
1423
|
const data = this.getScope(write.scope);
|
|
1319
1424
|
this.commitDeclinedLoadMetrics(data, write.publicModuleId, write.transformRequest);
|
|
1320
1425
|
const existing = data.transforms.get(write.moduleId);
|
|
1321
1426
|
if (existing) this.payloads.reclaim(collectPayloadRanges(existing.items));
|
|
1322
|
-
data
|
|
1427
|
+
setTransforms(data, write.moduleId, {
|
|
1323
1428
|
transformRequest: write.transformRequest,
|
|
1324
1429
|
publicModuleId: write.publicModuleId,
|
|
1325
1430
|
invokeCount: (existing?.invokeCount ?? 0) + 1,
|
|
1326
|
-
items: [toStoredTransformInfo(write.info, result
|
|
1431
|
+
items: [toStoredTransformInfo(write.info, result)]
|
|
1327
1432
|
});
|
|
1328
1433
|
}
|
|
1329
1434
|
commitDeclinedLoadMetrics(data, publicModuleId, transformRequest) {
|
|
@@ -1340,32 +1445,51 @@ var PayloadViteInspectStore = class {
|
|
|
1340
1445
|
this.pluginCalls.invalidate(scope, /* @__PURE__ */ new Set([publicModuleId]));
|
|
1341
1446
|
return;
|
|
1342
1447
|
}
|
|
1343
|
-
const invalidIds = /* @__PURE__ */ new Set(
|
|
1344
|
-
const invalidPublicIds = /* @__PURE__ */ new Set(
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1448
|
+
const invalidIds = /* @__PURE__ */ new Set();
|
|
1449
|
+
const invalidPublicIds = /* @__PURE__ */ new Set();
|
|
1450
|
+
const pendingIds = [];
|
|
1451
|
+
const pendingPublicIds = [];
|
|
1452
|
+
const linkedResolveIds = /* @__PURE__ */ new Set();
|
|
1453
|
+
const addInvalid = (id, publicId) => {
|
|
1454
|
+
if (!invalidIds.has(id)) {
|
|
1455
|
+
invalidIds.add(id);
|
|
1456
|
+
pendingIds.push(id);
|
|
1457
|
+
}
|
|
1458
|
+
if (!invalidPublicIds.has(publicId)) {
|
|
1459
|
+
invalidPublicIds.add(publicId);
|
|
1460
|
+
pendingPublicIds.push(publicId);
|
|
1461
|
+
}
|
|
1462
|
+
};
|
|
1463
|
+
const linkResolveIds = (items) => {
|
|
1464
|
+
for (const item of items ?? []) {
|
|
1465
|
+
if (linkedResolveIds.has(item)) continue;
|
|
1466
|
+
linkedResolveIds.add(item);
|
|
1467
|
+
addInvalid(item.sourceId, item.sourcePublicId);
|
|
1468
|
+
addInvalid(item.result, item.resultPublicId);
|
|
1469
|
+
}
|
|
1470
|
+
};
|
|
1471
|
+
addInvalid(moduleId, publicModuleId);
|
|
1472
|
+
while (pendingIds.length > 0 || pendingPublicIds.length > 0) {
|
|
1473
|
+
const id = pendingIds.pop();
|
|
1474
|
+
if (id !== void 0) {
|
|
1475
|
+
const transforms = data.transforms.get(id);
|
|
1476
|
+
if (transforms) addInvalid(id, transforms.publicModuleId);
|
|
1477
|
+
linkResolveIds(data.resolveIdsById.get(id));
|
|
1478
|
+
continue;
|
|
1353
1479
|
}
|
|
1480
|
+
const publicId = pendingPublicIds.pop();
|
|
1481
|
+
for (const transformId of data.transformIdsByPublicId.get(publicId) ?? []) addInvalid(transformId, data.transforms.get(transformId).publicModuleId);
|
|
1482
|
+
linkResolveIds(data.resolveIdsByPublicId.get(publicId));
|
|
1354
1483
|
}
|
|
1355
1484
|
const reclaimed = [];
|
|
1356
|
-
for (const
|
|
1357
|
-
|
|
1485
|
+
for (const id of invalidIds) {
|
|
1486
|
+
const transforms = data.transforms.get(id);
|
|
1487
|
+
if (!transforms) continue;
|
|
1358
1488
|
reclaimed.push(...collectPayloadRanges(transforms.items));
|
|
1359
|
-
data
|
|
1489
|
+
deleteTransforms(data, id);
|
|
1360
1490
|
}
|
|
1361
1491
|
this.payloads.reclaim(reclaimed);
|
|
1362
|
-
|
|
1363
|
-
const remaining = resolveIds.filter((resolveId) => {
|
|
1364
|
-
return !matchesInvalid(sourceId, resolveId.sourcePublicId, invalidIds, invalidPublicIds) && !matchesInvalid(resolveId.result, resolveId.resultPublicId, invalidIds, invalidPublicIds);
|
|
1365
|
-
});
|
|
1366
|
-
if (remaining.length > 0) data.resolveIds.set(sourceId, remaining);
|
|
1367
|
-
else data.resolveIds.delete(sourceId);
|
|
1368
|
-
}
|
|
1492
|
+
deleteResolveIds(data, linkedResolveIds);
|
|
1369
1493
|
for (const id of invalidPublicIds) {
|
|
1370
1494
|
data.declinedLoadMetrics.delete(id);
|
|
1371
1495
|
for (const [request, pendingLoadMetrics] of data.pendingLoadMetrics) {
|
|
@@ -1388,7 +1512,7 @@ var PayloadViteInspectStore = class {
|
|
|
1388
1512
|
this.scopes.delete(scope);
|
|
1389
1513
|
}
|
|
1390
1514
|
async restoreTransformInfo(info) {
|
|
1391
|
-
const
|
|
1515
|
+
const result = info.result ? await this.payloads.read(info.result) : void 0;
|
|
1392
1516
|
return {
|
|
1393
1517
|
name: info.name,
|
|
1394
1518
|
plugin_id: info.pluginId,
|
|
@@ -1396,7 +1520,6 @@ var PayloadViteInspectStore = class {
|
|
|
1396
1520
|
start: info.start,
|
|
1397
1521
|
end: info.end,
|
|
1398
1522
|
order: info.order,
|
|
1399
|
-
sourcemaps: sourcemaps == null ? void 0 : parsePayload(sourcemaps),
|
|
1400
1523
|
error: info.error
|
|
1401
1524
|
};
|
|
1402
1525
|
}
|
|
@@ -1422,6 +1545,9 @@ var PayloadViteInspectStore = class {
|
|
|
1422
1545
|
data = {
|
|
1423
1546
|
transforms: /* @__PURE__ */ new Map(),
|
|
1424
1547
|
resolveIds: /* @__PURE__ */ new Map(),
|
|
1548
|
+
transformIdsByPublicId: /* @__PURE__ */ new Map(),
|
|
1549
|
+
resolveIdsById: /* @__PURE__ */ new Map(),
|
|
1550
|
+
resolveIdsByPublicId: /* @__PURE__ */ new Map(),
|
|
1425
1551
|
declinedLoadMetrics: /* @__PURE__ */ new Map(),
|
|
1426
1552
|
pendingLoadMetrics: /* @__PURE__ */ new Map()
|
|
1427
1553
|
};
|
|
@@ -1480,22 +1606,64 @@ function addMetric(metrics, pluginId, pluginName, duration) {
|
|
|
1480
1606
|
metric.invokeCount += 1;
|
|
1481
1607
|
metric.totalTime += duration;
|
|
1482
1608
|
}
|
|
1483
|
-
function
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1609
|
+
function setTransforms(data, id, transforms) {
|
|
1610
|
+
deleteTransforms(data, id);
|
|
1611
|
+
data.transforms.set(id, transforms);
|
|
1612
|
+
addToIndex(data.transformIdsByPublicId, transforms.publicModuleId, id);
|
|
1613
|
+
}
|
|
1614
|
+
function deleteTransforms(data, id) {
|
|
1615
|
+
const existing = data.transforms.get(id);
|
|
1616
|
+
if (!existing) return;
|
|
1617
|
+
data.transforms.delete(id);
|
|
1618
|
+
removeFromIndex(data.transformIdsByPublicId, existing.publicModuleId, id);
|
|
1619
|
+
}
|
|
1620
|
+
function addResolveId(data, item) {
|
|
1621
|
+
let items = data.resolveIds.get(item.sourceId);
|
|
1622
|
+
if (!items) {
|
|
1623
|
+
items = [];
|
|
1624
|
+
data.resolveIds.set(item.sourceId, items);
|
|
1625
|
+
}
|
|
1626
|
+
items.push(item);
|
|
1627
|
+
addToIndex(data.resolveIdsById, item.sourceId, item);
|
|
1628
|
+
addToIndex(data.resolveIdsById, item.result, item);
|
|
1629
|
+
addToIndex(data.resolveIdsByPublicId, item.sourcePublicId, item);
|
|
1630
|
+
addToIndex(data.resolveIdsByPublicId, item.resultPublicId, item);
|
|
1631
|
+
}
|
|
1632
|
+
function deleteResolveIds(data, items) {
|
|
1633
|
+
const sourceIds = /* @__PURE__ */ new Set();
|
|
1634
|
+
for (const item of items) {
|
|
1635
|
+
sourceIds.add(item.sourceId);
|
|
1636
|
+
removeFromIndex(data.resolveIdsById, item.sourceId, item);
|
|
1637
|
+
removeFromIndex(data.resolveIdsById, item.result, item);
|
|
1638
|
+
removeFromIndex(data.resolveIdsByPublicId, item.sourcePublicId, item);
|
|
1639
|
+
removeFromIndex(data.resolveIdsByPublicId, item.resultPublicId, item);
|
|
1640
|
+
}
|
|
1641
|
+
for (const sourceId of sourceIds) {
|
|
1642
|
+
const remaining = data.resolveIds.get(sourceId).filter((item) => !items.has(item));
|
|
1643
|
+
if (remaining.length > 0) data.resolveIds.set(sourceId, remaining);
|
|
1644
|
+
else data.resolveIds.delete(sourceId);
|
|
1645
|
+
}
|
|
1646
|
+
}
|
|
1647
|
+
function addToIndex(index, key, value) {
|
|
1648
|
+
let values = index.get(key);
|
|
1649
|
+
if (!values) {
|
|
1650
|
+
values = /* @__PURE__ */ new Set();
|
|
1651
|
+
index.set(key, values);
|
|
1652
|
+
}
|
|
1653
|
+
values.add(value);
|
|
1489
1654
|
}
|
|
1490
|
-
function
|
|
1491
|
-
|
|
1655
|
+
function removeFromIndex(index, key, value) {
|
|
1656
|
+
const values = index.get(key);
|
|
1657
|
+
if (!values) return;
|
|
1658
|
+
values.delete(value);
|
|
1659
|
+
if (values.size === 0) index.delete(key);
|
|
1492
1660
|
}
|
|
1493
1661
|
function collectPayloadRanges(items) {
|
|
1494
1662
|
const ranges = /* @__PURE__ */ new Map();
|
|
1495
|
-
for (const item of items)
|
|
1663
|
+
for (const item of items) if (item.result) ranges.set(`${item.result.offset}:${item.result.length}`, item.result);
|
|
1496
1664
|
return Array.from(ranges.values());
|
|
1497
1665
|
}
|
|
1498
|
-
function toStoredTransformInfo(info, result
|
|
1666
|
+
function toStoredTransformInfo(info, result) {
|
|
1499
1667
|
return {
|
|
1500
1668
|
name: info.name,
|
|
1501
1669
|
pluginId: info.plugin_id,
|
|
@@ -1505,44 +1673,20 @@ function toStoredTransformInfo(info, result, sourcemaps) {
|
|
|
1505
1673
|
start: info.start,
|
|
1506
1674
|
end: info.end,
|
|
1507
1675
|
order: info.order,
|
|
1508
|
-
sourcemaps,
|
|
1509
1676
|
error: info.error
|
|
1510
1677
|
};
|
|
1511
1678
|
}
|
|
1512
|
-
function pushSerializedPayload(values, value) {
|
|
1513
|
-
const serialized = serializePayload(value);
|
|
1514
|
-
if (serialized == null) return void 0;
|
|
1515
|
-
return values.push(serialized) - 1;
|
|
1516
|
-
}
|
|
1517
|
-
function serializePayload(value) {
|
|
1518
|
-
if (value == null) return void 0;
|
|
1519
|
-
try {
|
|
1520
|
-
return JSON.stringify(value);
|
|
1521
|
-
} catch {
|
|
1522
|
-
return JSON.stringify(String(value));
|
|
1523
|
-
}
|
|
1524
|
-
}
|
|
1525
|
-
function parsePayload(value) {
|
|
1526
|
-
try {
|
|
1527
|
-
return JSON.parse(value);
|
|
1528
|
-
} catch {
|
|
1529
|
-
return;
|
|
1530
|
-
}
|
|
1531
|
-
}
|
|
1532
1679
|
function rangeAt(ranges, index) {
|
|
1533
1680
|
return index == null ? void 0 : ranges[index];
|
|
1534
1681
|
}
|
|
1535
|
-
function scopeKey(scope, moduleId) {
|
|
1536
|
-
return `${scope}\0${moduleId}`;
|
|
1537
|
-
}
|
|
1538
1682
|
function positiveInteger(value, fallback) {
|
|
1539
1683
|
return Number.isFinite(value) && value > 0 ? Math.max(1, Math.floor(value)) : fallback;
|
|
1540
1684
|
}
|
|
1541
1685
|
function estimateWriteBytes(write) {
|
|
1542
1686
|
const pluginCall = write.operation === "invalidate" || write.operation === "clearScope" || write.operation === "clearPendingLoadMetrics" ? void 0 : getQueuedPluginCall(write);
|
|
1543
1687
|
const pluginCallBytes = pluginCall ? 48 + estimateStringBytes(pluginCall.id) + estimateStringBytes(pluginCall.plugin_name) + estimateStringBytes(pluginCall.module) : 0;
|
|
1544
|
-
if (write.operation === "recordTransform") return pluginCallBytes + estimateStringBytes(write.info.result) + estimateStringBytes(write.preTransformCode)
|
|
1545
|
-
if (write.operation === "recordLoad") return pluginCallBytes + estimateStringBytes(write.info.result)
|
|
1688
|
+
if (write.operation === "recordTransform") return pluginCallBytes + estimateStringBytes(write.info.result) + estimateStringBytes(write.preTransformCode);
|
|
1689
|
+
if (write.operation === "recordLoad") return pluginCallBytes + estimateStringBytes(write.info.result);
|
|
1546
1690
|
return pluginCallBytes;
|
|
1547
1691
|
}
|
|
1548
1692
|
function getQueuedPluginCall(write) {
|
|
@@ -1551,13 +1695,6 @@ function getQueuedPluginCall(write) {
|
|
|
1551
1695
|
function estimateStringBytes(value) {
|
|
1552
1696
|
return typeof value === "string" ? value.length * 2 : 0;
|
|
1553
1697
|
}
|
|
1554
|
-
function estimateTopLevelSourcemapBytes(value) {
|
|
1555
|
-
if (value == null) return 0;
|
|
1556
|
-
if (typeof value === "string") return value.length * 2;
|
|
1557
|
-
if (typeof value !== "object") return 0;
|
|
1558
|
-
const mappings = value.mappings;
|
|
1559
|
-
return estimateStringBytes(mappings);
|
|
1560
|
-
}
|
|
1561
1698
|
function reportStorageError(operation, error) {
|
|
1562
1699
|
diagnostics.VDT0003({
|
|
1563
1700
|
operation,
|
|
@@ -1567,8 +1704,7 @@ function reportStorageError(operation, error) {
|
|
|
1567
1704
|
function toError(error) {
|
|
1568
1705
|
return error instanceof Error ? error : new Error(String(error));
|
|
1569
1706
|
}
|
|
1570
|
-
|
|
1571
|
-
//#region src/node/inspect/context.ts
|
|
1707
|
+
// src/node/inspect/context.ts
|
|
1572
1708
|
let viteCount = 0;
|
|
1573
1709
|
const contextMap = /* @__PURE__ */ new WeakMap();
|
|
1574
1710
|
function setViteInspectContext(devtoolsCtx, ctx) {
|
|
@@ -1677,6 +1813,7 @@ var ViteInspectViteContext = class {
|
|
|
1677
1813
|
return envContext;
|
|
1678
1814
|
}
|
|
1679
1815
|
};
|
|
1816
|
+
const MAX_PUBLIC_MODULE_ID_CACHE_SIZE = 1e5;
|
|
1680
1817
|
var ViteInspectEnvironmentContext = class {
|
|
1681
1818
|
inspectContext;
|
|
1682
1819
|
viteContext;
|
|
@@ -1684,6 +1821,9 @@ var ViteInspectEnvironmentContext = class {
|
|
|
1684
1821
|
scope;
|
|
1685
1822
|
pluginCallCount = 0;
|
|
1686
1823
|
graphModuleIdResolver;
|
|
1824
|
+
modulesList;
|
|
1825
|
+
publicModuleIds = /* @__PURE__ */ new Map();
|
|
1826
|
+
publicModuleIdsRoot;
|
|
1687
1827
|
constructor(inspectContext, viteContext, env) {
|
|
1688
1828
|
this.inspectContext = inspectContext;
|
|
1689
1829
|
this.viteContext = viteContext;
|
|
@@ -1796,7 +1936,17 @@ var ViteInspectEnvironmentContext = class {
|
|
|
1796
1936
|
return this.env.getTopLevelConfig().root;
|
|
1797
1937
|
}
|
|
1798
1938
|
getPublicModuleId(id) {
|
|
1799
|
-
|
|
1939
|
+
const root = this.getModuleIdBaseRoot();
|
|
1940
|
+
if (root !== this.publicModuleIdsRoot || this.publicModuleIds.size >= MAX_PUBLIC_MODULE_ID_CACHE_SIZE) {
|
|
1941
|
+
this.publicModuleIds.clear();
|
|
1942
|
+
this.publicModuleIdsRoot = root;
|
|
1943
|
+
}
|
|
1944
|
+
let publicId = this.publicModuleIds.get(id);
|
|
1945
|
+
if (publicId === void 0) {
|
|
1946
|
+
publicId = normalizeModuleId(this.normalizeId(id), root);
|
|
1947
|
+
this.publicModuleIds.set(id, publicId);
|
|
1948
|
+
}
|
|
1949
|
+
return publicId;
|
|
1800
1950
|
}
|
|
1801
1951
|
async getModuleId(id) {
|
|
1802
1952
|
const normalizedId = this.getPublicModuleId(id);
|
|
@@ -1830,10 +1980,24 @@ var ViteInspectEnvironmentContext = class {
|
|
|
1830
1980
|
};
|
|
1831
1981
|
}
|
|
1832
1982
|
async getModulesList(pluginCtx) {
|
|
1983
|
+
const store = this.inspectContext.store;
|
|
1984
|
+
await store.flush();
|
|
1985
|
+
const version = store.getChangeVersion();
|
|
1986
|
+
if (!pluginCtx && this.modulesList?.version === version) {
|
|
1987
|
+
this.graphModuleIdResolver ??= this.createGraphModuleIdResolver(this.modulesList.modules);
|
|
1988
|
+
return this.modulesList.modules;
|
|
1989
|
+
}
|
|
1833
1990
|
const modules = await getModulesList(this, pluginCtx);
|
|
1834
|
-
this.graphModuleIdResolver = createGraphModuleIdResolver(modules
|
|
1991
|
+
this.graphModuleIdResolver = this.createGraphModuleIdResolver(modules);
|
|
1992
|
+
if (!pluginCtx) this.modulesList = {
|
|
1993
|
+
version,
|
|
1994
|
+
modules
|
|
1995
|
+
};
|
|
1835
1996
|
return modules;
|
|
1836
1997
|
}
|
|
1998
|
+
createGraphModuleIdResolver(modules) {
|
|
1999
|
+
return createGraphModuleIdResolver(modules.map((module) => module.id), this.env.getTopLevelConfig().resolve?.extensions ?? []);
|
|
2000
|
+
}
|
|
1837
2001
|
async getGraphModuleIdResolver() {
|
|
1838
2002
|
if (!this.graphModuleIdResolver) await this.getModulesList();
|
|
1839
2003
|
return this.graphModuleIdResolver;
|
|
@@ -1876,8 +2040,7 @@ var ViteInspectEnvironmentContext = class {
|
|
|
1876
2040
|
this.graphModuleIdResolver = void 0;
|
|
1877
2041
|
}
|
|
1878
2042
|
};
|
|
1879
|
-
|
|
1880
|
-
//#region src/node/rpc/inspect-module-updated.ts
|
|
2043
|
+
// src/node/rpc/inspect-module-updated.ts
|
|
1881
2044
|
const VITE_INSPECT_MODULE_UPDATED_STATE_KEY = "vite:inspect:module-updated";
|
|
1882
2045
|
function getViteInspectModuleUpdatedState(context) {
|
|
1883
2046
|
return context.rpc.sharedState.get(VITE_INSPECT_MODULE_UPDATED_STATE_KEY, { initialValue: {
|
|
@@ -1891,8 +2054,7 @@ function notifyViteInspectModuleUpdated(state, ids = null) {
|
|
|
1891
2054
|
value.updatedAt = Date.now();
|
|
1892
2055
|
});
|
|
1893
2056
|
}
|
|
1894
|
-
|
|
1895
|
-
//#region src/node/rpc/functions/vite-clear-module-transform.ts
|
|
2057
|
+
// src/node/rpc/functions/vite-clear-module-transform.ts
|
|
1896
2058
|
const viteClearModuleTransform = defineRpcFunction({
|
|
1897
2059
|
name: "vite:inspect:clear-module-transform",
|
|
1898
2060
|
type: "action",
|
|
@@ -1906,8 +2068,7 @@ const viteClearModuleTransform = defineRpcFunction({
|
|
|
1906
2068
|
} };
|
|
1907
2069
|
}
|
|
1908
2070
|
});
|
|
1909
|
-
|
|
1910
|
-
//#region src/node/rpc/functions/vite-env-info.ts
|
|
2071
|
+
// src/node/rpc/functions/vite-env-info.ts
|
|
1911
2072
|
const viteEnvInfo = defineRpcFunction({
|
|
1912
2073
|
name: "vite:env-info",
|
|
1913
2074
|
type: "query",
|
|
@@ -1939,8 +2100,7 @@ const viteEnvInfo = defineRpcFunction({
|
|
|
1939
2100
|
} };
|
|
1940
2101
|
}
|
|
1941
2102
|
});
|
|
1942
|
-
|
|
1943
|
-
//#region src/node/rpc/functions/vite-get-metadata.ts
|
|
2103
|
+
// src/node/rpc/functions/vite-get-metadata.ts
|
|
1944
2104
|
const viteGetMetadata = defineRpcFunction({
|
|
1945
2105
|
name: "vite:inspect:get-metadata",
|
|
1946
2106
|
type: "query",
|
|
@@ -1952,8 +2112,7 @@ const viteGetMetadata = defineRpcFunction({
|
|
|
1952
2112
|
return { handler: async () => ctx.getMetadata() };
|
|
1953
2113
|
}
|
|
1954
2114
|
});
|
|
1955
|
-
|
|
1956
|
-
//#region src/node/rpc/functions/vite-get-module-transform-info.ts
|
|
2115
|
+
// src/node/rpc/functions/vite-get-module-transform-info.ts
|
|
1957
2116
|
const viteGetModuleTransformInfo = defineRpcFunction({
|
|
1958
2117
|
name: "vite:inspect:get-module-transform-info",
|
|
1959
2118
|
type: "query",
|
|
@@ -1967,8 +2126,7 @@ const viteGetModuleTransformInfo = defineRpcFunction({
|
|
|
1967
2126
|
return { handler: async (query, id) => ctx.queryEnv(query).getModuleTransformInfo(id) };
|
|
1968
2127
|
}
|
|
1969
2128
|
});
|
|
1970
|
-
|
|
1971
|
-
//#region src/node/rpc/functions/vite-get-modules-list.ts
|
|
2129
|
+
// src/node/rpc/functions/vite-get-modules-list.ts
|
|
1972
2130
|
const viteGetModulesList = defineRpcFunction({
|
|
1973
2131
|
name: "vite:inspect:get-modules-list",
|
|
1974
2132
|
type: "query",
|
|
@@ -1982,8 +2140,7 @@ const viteGetModulesList = defineRpcFunction({
|
|
|
1982
2140
|
return { handler: async (query) => ctx.queryEnv(query).getModulesList() };
|
|
1983
2141
|
}
|
|
1984
2142
|
});
|
|
1985
|
-
|
|
1986
|
-
//#region src/node/rpc/functions/vite-get-plugin-details.ts
|
|
2143
|
+
// src/node/rpc/functions/vite-get-plugin-details.ts
|
|
1987
2144
|
const viteGetPluginDetails = defineRpcFunction({
|
|
1988
2145
|
name: "vite:inspect:get-plugin-details",
|
|
1989
2146
|
type: "query",
|
|
@@ -1994,8 +2151,7 @@ const viteGetPluginDetails = defineRpcFunction({
|
|
|
1994
2151
|
return { handler: async (query, id) => ctx.queryEnv(query).getPluginDetails(Number(id)) };
|
|
1995
2152
|
}
|
|
1996
2153
|
});
|
|
1997
|
-
|
|
1998
|
-
//#region src/node/rpc/functions/vite-get-plugin-metrics.ts
|
|
2154
|
+
// src/node/rpc/functions/vite-get-plugin-metrics.ts
|
|
1999
2155
|
const viteGetPluginMetrics = defineRpcFunction({
|
|
2000
2156
|
name: "vite:inspect:get-plugin-metrics",
|
|
2001
2157
|
type: "query",
|
|
@@ -2009,8 +2165,7 @@ const viteGetPluginMetrics = defineRpcFunction({
|
|
|
2009
2165
|
return { handler: async (query) => ctx.queryEnv(query).getPluginMetrics() };
|
|
2010
2166
|
}
|
|
2011
2167
|
});
|
|
2012
|
-
|
|
2013
|
-
//#region src/node/rpc/functions/vite-get-server-metrics.ts
|
|
2168
|
+
// src/node/rpc/functions/vite-get-server-metrics.ts
|
|
2014
2169
|
const viteGetServerMetrics = defineRpcFunction({
|
|
2015
2170
|
name: "vite:inspect:get-server-metrics",
|
|
2016
2171
|
type: "query",
|
|
@@ -2024,8 +2179,7 @@ const viteGetServerMetrics = defineRpcFunction({
|
|
|
2024
2179
|
return { handler: async (query) => ctx.getViteContext(query.vite).data.serverMetrics };
|
|
2025
2180
|
}
|
|
2026
2181
|
});
|
|
2027
|
-
|
|
2028
|
-
//#region src/node/rpc/functions/vite-meta-info.ts
|
|
2182
|
+
// src/node/rpc/functions/vite-meta-info.ts
|
|
2029
2183
|
const viteMetaInfo = defineRpcFunction({
|
|
2030
2184
|
name: "vite:meta-info",
|
|
2031
2185
|
type: "query",
|
|
@@ -2042,8 +2196,7 @@ const viteMetaInfo = defineRpcFunction({
|
|
|
2042
2196
|
} };
|
|
2043
2197
|
}
|
|
2044
2198
|
});
|
|
2045
|
-
|
|
2046
|
-
//#region src/node/rpc/functions/vite-resolve-id.ts
|
|
2199
|
+
// src/node/rpc/functions/vite-resolve-id.ts
|
|
2047
2200
|
const viteResolveId = defineRpcFunction({
|
|
2048
2201
|
name: "vite:inspect:resolve-id",
|
|
2049
2202
|
type: "query",
|
|
@@ -2057,8 +2210,7 @@ const viteResolveId = defineRpcFunction({
|
|
|
2057
2210
|
return { handler: async (query, id) => ctx.queryEnv(query).resolveId(id) };
|
|
2058
2211
|
}
|
|
2059
2212
|
});
|
|
2060
|
-
|
|
2061
|
-
//#region src/node/rpc/index.ts
|
|
2213
|
+
// src/node/rpc/index.ts
|
|
2062
2214
|
const viteRpcFunctions = [viteMetaInfo, viteEnvInfo];
|
|
2063
2215
|
const inspectRpcFunctions = [
|
|
2064
2216
|
viteClearModuleTransform,
|
|
@@ -2071,8 +2223,7 @@ const inspectRpcFunctions = [
|
|
|
2071
2223
|
viteGetServerMetrics
|
|
2072
2224
|
];
|
|
2073
2225
|
[...viteRpcFunctions, ...inspectRpcFunctions];
|
|
2074
|
-
|
|
2075
|
-
//#region src/node/inspect/hijack.ts
|
|
2226
|
+
// src/node/inspect/hijack.ts
|
|
2076
2227
|
function hijackHook(plugin, name, wrapper) {
|
|
2077
2228
|
const hook = plugin[name];
|
|
2078
2229
|
if (!hook) return;
|
|
@@ -2097,118 +2248,105 @@ function hijackHook(plugin, name, wrapper) {
|
|
|
2097
2248
|
};
|
|
2098
2249
|
}
|
|
2099
2250
|
}
|
|
2251
|
+
function now() {
|
|
2252
|
+
return performance.timeOrigin + performance.now();
|
|
2253
|
+
}
|
|
2254
|
+
function isThenable(value) {
|
|
2255
|
+
return value != null && typeof value.then === "function";
|
|
2256
|
+
}
|
|
2257
|
+
function measureHook(fn, context, args, settled) {
|
|
2258
|
+
const start = now();
|
|
2259
|
+
let resultValue;
|
|
2260
|
+
try {
|
|
2261
|
+
resultValue = fn.apply(context, args);
|
|
2262
|
+
} catch (error) {
|
|
2263
|
+
settled(void 0, error, start, now());
|
|
2264
|
+
throw error;
|
|
2265
|
+
}
|
|
2266
|
+
if (!isThenable(resultValue)) {
|
|
2267
|
+
settled(resultValue, void 0, start, now());
|
|
2268
|
+
return resultValue;
|
|
2269
|
+
}
|
|
2270
|
+
return Promise.resolve(resultValue).then((value) => {
|
|
2271
|
+
settled(value, void 0, start, now());
|
|
2272
|
+
return value;
|
|
2273
|
+
}, (error) => {
|
|
2274
|
+
settled(void 0, error, start, now());
|
|
2275
|
+
throw error;
|
|
2276
|
+
});
|
|
2277
|
+
}
|
|
2100
2278
|
const hijackedPlugins = /* @__PURE__ */ new WeakSet();
|
|
2101
2279
|
function hijackPlugin(plugin, ctx) {
|
|
2102
2280
|
if (hijackedPlugins.has(plugin)) return;
|
|
2103
2281
|
hijackedPlugins.add(plugin);
|
|
2104
|
-
hijackHook(plugin, "transform",
|
|
2282
|
+
hijackHook(plugin, "transform", (fn, context, args, order) => {
|
|
2105
2283
|
const code = args[0];
|
|
2106
2284
|
const id = args[1];
|
|
2107
2285
|
const transformRequest = trackTransformRequestId(id);
|
|
2108
2286
|
const envContext = ctx.filter(id) ? ctx.getEnvContext(context?.environment) : void 0;
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
resultValue = await fn.apply(context, args);
|
|
2114
|
-
} catch (err) {
|
|
2115
|
-
error = err;
|
|
2116
|
-
}
|
|
2117
|
-
const end = Date.now();
|
|
2118
|
-
const result = error ? "[Error]" : typeof resultValue === "string" ? resultValue : resultValue?.code?.toString();
|
|
2119
|
-
if (envContext && !isTransformRequestStale(transformRequest)) {
|
|
2120
|
-
const sourcemaps = typeof resultValue === "string" ? null : resultValue?.map;
|
|
2287
|
+
if (!envContext) return fn.apply(context, args);
|
|
2288
|
+
return measureHook(fn, context, args, (resultValue, error, start, end) => {
|
|
2289
|
+
if (isTransformRequestStale(transformRequest)) return;
|
|
2290
|
+
const result = error ? "[Error]" : typeof resultValue === "string" ? resultValue : resultValue?.code?.toString();
|
|
2121
2291
|
envContext.recordTransform(id, {
|
|
2122
2292
|
name: plugin.name,
|
|
2123
2293
|
result,
|
|
2124
2294
|
start,
|
|
2125
2295
|
end,
|
|
2126
2296
|
order,
|
|
2127
|
-
sourcemaps,
|
|
2128
2297
|
error: error ? parseError(error) : void 0
|
|
2129
2298
|
}, code, plugin);
|
|
2130
|
-
}
|
|
2131
|
-
if (error) throw error;
|
|
2132
|
-
return resultValue;
|
|
2299
|
+
});
|
|
2133
2300
|
});
|
|
2134
|
-
hijackHook(plugin, "load",
|
|
2301
|
+
hijackHook(plugin, "load", (fn, context, args) => {
|
|
2135
2302
|
const id = args[0];
|
|
2136
2303
|
const transformRequest = trackTransformRequestId(id);
|
|
2137
2304
|
const envContext = ctx.getEnvContext(context?.environment);
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
};
|
|
2157
|
-
if (result != null && envContext && !isTransformRequestStale(transformRequest)) envContext.recordLoad(id, {
|
|
2158
|
-
...info,
|
|
2159
|
-
result
|
|
2160
|
-
}, plugin);
|
|
2161
|
-
else if (envContext && !isTransformRequestStale(transformRequest)) envContext.recordLoadCall(id, {
|
|
2162
|
-
name: plugin.name,
|
|
2163
|
-
start,
|
|
2164
|
-
end,
|
|
2165
|
-
error: error ? parseError(error) : void 0
|
|
2166
|
-
}, plugin);
|
|
2167
|
-
if (error) throw error;
|
|
2168
|
-
return resultValue;
|
|
2305
|
+
if (!envContext) return fn.apply(context, args);
|
|
2306
|
+
return measureHook(fn, context, args, (resultValue, error, start, end) => {
|
|
2307
|
+
if (isTransformRequestStale(transformRequest)) return;
|
|
2308
|
+
const result = error ? "[Error]" : typeof resultValue === "string" ? resultValue : resultValue?.code;
|
|
2309
|
+
if (result != null) envContext.recordLoad(id, {
|
|
2310
|
+
name: plugin.name,
|
|
2311
|
+
result,
|
|
2312
|
+
start,
|
|
2313
|
+
end,
|
|
2314
|
+
error: error ? parseError(error) : void 0
|
|
2315
|
+
}, plugin);
|
|
2316
|
+
else envContext.recordLoadCall(id, {
|
|
2317
|
+
name: plugin.name,
|
|
2318
|
+
start,
|
|
2319
|
+
end,
|
|
2320
|
+
error: error ? parseError(error) : void 0
|
|
2321
|
+
}, plugin);
|
|
2322
|
+
});
|
|
2169
2323
|
});
|
|
2170
|
-
hijackHook(plugin, "resolveId",
|
|
2324
|
+
hijackHook(plugin, "resolveId", (fn, context, args) => {
|
|
2171
2325
|
const id = args[0];
|
|
2172
2326
|
const transformRequest = trackTransformRequestId(id);
|
|
2173
2327
|
const envContext = ctx.filter(id) ? ctx.getEnvContext(context?.environment) : void 0;
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
name: plugin.name,
|
|
2194
|
-
result,
|
|
2195
|
-
start,
|
|
2196
|
-
end,
|
|
2197
|
-
error
|
|
2198
|
-
}, plugin);
|
|
2199
|
-
else envContext.recordResolveIdCall(id, {
|
|
2200
|
-
name: plugin.name,
|
|
2201
|
-
result,
|
|
2202
|
-
start,
|
|
2203
|
-
end,
|
|
2204
|
-
error
|
|
2205
|
-
}, plugin);
|
|
2206
|
-
if (error) throw error;
|
|
2207
|
-
return resultValue;
|
|
2328
|
+
if (!envContext) return fn.apply(context, args);
|
|
2329
|
+
return measureHook(fn, context, args, (resultValue, error, start, end) => {
|
|
2330
|
+
if (isTransformRequestStale(transformRequest)) return;
|
|
2331
|
+
const result = error ? stringifyError(error) : typeof resultValue === "object" ? resultValue?.id : resultValue;
|
|
2332
|
+
if (result) envContext.recordResolveId(id, {
|
|
2333
|
+
name: plugin.name,
|
|
2334
|
+
result,
|
|
2335
|
+
start,
|
|
2336
|
+
end,
|
|
2337
|
+
error
|
|
2338
|
+
}, plugin);
|
|
2339
|
+
else envContext.recordResolveIdCall(id, {
|
|
2340
|
+
name: plugin.name,
|
|
2341
|
+
result,
|
|
2342
|
+
start,
|
|
2343
|
+
end,
|
|
2344
|
+
error
|
|
2345
|
+
}, plugin);
|
|
2346
|
+
});
|
|
2208
2347
|
});
|
|
2209
2348
|
}
|
|
2210
|
-
|
|
2211
|
-
//#region src/node/inspect/plugin.ts
|
|
2349
|
+
// src/node/inspect/plugin.ts
|
|
2212
2350
|
function DevToolsViteInspect() {
|
|
2213
2351
|
let inspectContext;
|
|
2214
2352
|
let inspectContextPromise;
|
|
@@ -2336,8 +2474,7 @@ function DevToolsViteInspect() {
|
|
|
2336
2474
|
sharedDuringBuild: true
|
|
2337
2475
|
};
|
|
2338
2476
|
}
|
|
2339
|
-
|
|
2340
|
-
//#region src/node/plugin.ts
|
|
2477
|
+
// src/node/plugin.ts
|
|
2341
2478
|
const VITE_DEVTOOLS_BASE = "/__devtools-vite/";
|
|
2342
2479
|
function DevToolsViteUI() {
|
|
2343
2480
|
return [DevToolsViteInspect(), DevToolsViteUIPlugin()];
|
|
@@ -2359,5 +2496,4 @@ function DevToolsViteUIPlugin() {
|
|
|
2359
2496
|
} }
|
|
2360
2497
|
};
|
|
2361
2498
|
}
|
|
2362
|
-
//#endregion
|
|
2363
2499
|
export { DevToolsViteInspect, DevToolsViteUI, DevToolsViteUIPlugin };
|