@oxog/reactscope 1.0.0 → 1.1.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/README.md +47 -15
- package/dist/{chunk-IFCS6ABF.cjs → chunk-33CBEAOF.cjs} +106 -32
- package/dist/chunk-33CBEAOF.cjs.map +1 -0
- package/dist/{chunk-JESQX3XO.js → chunk-3Q6YBIBW.js} +28 -2
- package/dist/chunk-3Q6YBIBW.js.map +1 -0
- package/dist/{chunk-6L3WUS6V.cjs → chunk-6ALDCO2Q.cjs} +28 -2
- package/dist/chunk-6ALDCO2Q.cjs.map +1 -0
- package/dist/{chunk-4TZAECHG.cjs → chunk-7MVKPUC4.cjs} +5 -21
- package/dist/chunk-7MVKPUC4.cjs.map +1 -0
- package/dist/chunk-ACLEEAEC.cjs +83 -0
- package/dist/chunk-ACLEEAEC.cjs.map +1 -0
- package/dist/{chunk-LZO35OCP.js → chunk-AZ6OARKV.js} +2 -2
- package/dist/{chunk-LZO35OCP.js.map → chunk-AZ6OARKV.js.map} +1 -1
- package/dist/{chunk-KCUWALXE.cjs → chunk-C3IBGU7L.cjs} +5 -2
- package/dist/chunk-C3IBGU7L.cjs.map +1 -0
- package/dist/{chunk-M65L55OT.js → chunk-C4LJVRF5.js} +11 -8
- package/dist/chunk-C4LJVRF5.js.map +1 -0
- package/dist/{chunk-MPOQNCGP.js → chunk-E4PZKXY7.js} +5 -21
- package/dist/chunk-E4PZKXY7.js.map +1 -0
- package/dist/chunk-E7W2FVWO.js +78 -0
- package/dist/chunk-E7W2FVWO.js.map +1 -0
- package/dist/{chunk-H4W4UBLZ.cjs → chunk-EUYOAT56.cjs} +11 -8
- package/dist/chunk-EUYOAT56.cjs.map +1 -0
- package/dist/{chunk-RYAIO3BO.js → chunk-F3KDHISM.js} +5 -4
- package/dist/chunk-F3KDHISM.js.map +1 -0
- package/dist/{chunk-I427KZYN.cjs → chunk-KRRXA4SI.cjs} +2 -2
- package/dist/{chunk-I427KZYN.cjs.map → chunk-KRRXA4SI.cjs.map} +1 -1
- package/dist/{chunk-U2OPUU5R.js → chunk-MBFJ6ULY.js} +40 -18
- package/dist/chunk-MBFJ6ULY.js.map +1 -0
- package/dist/chunk-OMETOKM7.cjs +86 -0
- package/dist/chunk-OMETOKM7.cjs.map +1 -0
- package/dist/chunk-QT2GSPHP.js +21 -0
- package/dist/chunk-QT2GSPHP.js.map +1 -0
- package/dist/{chunk-OJGWFS55.cjs → chunk-U3TL6KFZ.cjs} +41 -19
- package/dist/chunk-U3TL6KFZ.cjs.map +1 -0
- package/dist/chunk-UQFSIGZW.cjs +24 -0
- package/dist/chunk-UQFSIGZW.cjs.map +1 -0
- package/dist/{chunk-6LHJL6MV.js → chunk-W7SGZQRF.js} +106 -32
- package/dist/chunk-W7SGZQRF.js.map +1 -0
- package/dist/{chunk-ZTO5ZZVE.js → chunk-XWZXCGPY.js} +5 -2
- package/dist/chunk-XWZXCGPY.js.map +1 -0
- package/dist/chunk-YG5FHHRH.js +80 -0
- package/dist/chunk-YG5FHHRH.js.map +1 -0
- package/dist/{chunk-QYMRRTSN.cjs → chunk-YL2LJ27D.cjs} +6 -5
- package/dist/chunk-YL2LJ27D.cjs.map +1 -0
- package/dist/index.cjs +428 -369
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +33 -7
- package/dist/index.d.ts +33 -7
- package/dist/index.js +403 -343
- package/dist/index.js.map +1 -1
- package/dist/plugins/console-reporter/index.d.cts +1 -1
- package/dist/plugins/console-reporter/index.d.ts +1 -1
- package/dist/plugins/dashboard-ui/index.cjs +4 -3
- package/dist/plugins/dashboard-ui/index.d.cts +5 -1
- package/dist/plugins/dashboard-ui/index.d.ts +5 -1
- package/dist/plugins/dashboard-ui/index.js +2 -1
- package/dist/plugins/json-exporter/index.cjs +5 -3
- package/dist/plugins/json-exporter/index.d.cts +1 -1
- package/dist/plugins/json-exporter/index.d.ts +1 -1
- package/dist/plugins/json-exporter/index.js +3 -1
- package/dist/plugins/lifecycle-tracker/index.cjs +4 -3
- package/dist/plugins/lifecycle-tracker/index.d.cts +8 -1
- package/dist/plugins/lifecycle-tracker/index.d.ts +8 -1
- package/dist/plugins/lifecycle-tracker/index.js +2 -1
- package/dist/plugins/memory-tracker/index.d.cts +1 -1
- package/dist/plugins/memory-tracker/index.d.ts +1 -1
- package/dist/plugins/network-correlator/index.cjs +4 -4
- package/dist/plugins/network-correlator/index.d.cts +5 -1
- package/dist/plugins/network-correlator/index.d.ts +5 -1
- package/dist/plugins/network-correlator/index.js +2 -2
- package/dist/plugins/props-differ/index.cjs +4 -3
- package/dist/plugins/props-differ/index.d.cts +1 -1
- package/dist/plugins/props-differ/index.d.ts +1 -1
- package/dist/plugins/props-differ/index.js +2 -1
- package/dist/plugins/render-tracker/index.d.cts +1 -1
- package/dist/plugins/render-tracker/index.d.ts +1 -1
- package/dist/plugins/timeline-recorder/index.cjs +5 -4
- package/dist/plugins/timeline-recorder/index.d.cts +1 -1
- package/dist/plugins/timeline-recorder/index.d.ts +1 -1
- package/dist/plugins/timeline-recorder/index.js +3 -2
- package/dist/plugins/wasted-render-detector/index.cjs +4 -3
- package/dist/plugins/wasted-render-detector/index.d.cts +5 -8
- package/dist/plugins/wasted-render-detector/index.d.ts +5 -8
- package/dist/plugins/wasted-render-detector/index.js +2 -1
- package/dist/{types-DKPG_emi.d.ts → types-DNhmA1Tk.d.cts} +22 -1
- package/dist/{types-DKPG_emi.d.cts → types-DNhmA1Tk.d.ts} +22 -1
- package/package.json +20 -9
- package/dist/chunk-4TZAECHG.cjs.map +0 -1
- package/dist/chunk-6L3WUS6V.cjs.map +0 -1
- package/dist/chunk-6LHJL6MV.js.map +0 -1
- package/dist/chunk-H4W4UBLZ.cjs.map +0 -1
- package/dist/chunk-IFCS6ABF.cjs.map +0 -1
- package/dist/chunk-JESQX3XO.js.map +0 -1
- package/dist/chunk-KCUWALXE.cjs.map +0 -1
- package/dist/chunk-M65L55OT.js.map +0 -1
- package/dist/chunk-MPOQNCGP.js.map +0 -1
- package/dist/chunk-OJGWFS55.cjs.map +0 -1
- package/dist/chunk-QYMRRTSN.cjs.map +0 -1
- package/dist/chunk-RYAIO3BO.js.map +0 -1
- package/dist/chunk-U2OPUU5R.js.map +0 -1
- package/dist/chunk-ZTO5ZZVE.js.map +0 -1
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/utils/tree.ts
|
|
2
|
+
function createTree() {
|
|
3
|
+
return {
|
|
4
|
+
root: null,
|
|
5
|
+
nodeMap: /* @__PURE__ */ new Map()
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
function createNode(id, name, metrics = null, depth = 0) {
|
|
9
|
+
return {
|
|
10
|
+
id,
|
|
11
|
+
name,
|
|
12
|
+
children: [],
|
|
13
|
+
metrics,
|
|
14
|
+
depth,
|
|
15
|
+
isExpanded: true
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
function addChild(parent, child) {
|
|
19
|
+
const existingIndex = parent.children.findIndex((c) => c.id === child.id);
|
|
20
|
+
if (existingIndex !== -1) {
|
|
21
|
+
parent.children[existingIndex] = child;
|
|
22
|
+
} else {
|
|
23
|
+
parent.children.push(child);
|
|
24
|
+
}
|
|
25
|
+
child.depth = parent.depth + 1;
|
|
26
|
+
}
|
|
27
|
+
function removeNode(tree, nodeId) {
|
|
28
|
+
const node = tree.nodeMap.get(nodeId);
|
|
29
|
+
if (!node) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
for (const potentialParent of tree.nodeMap.values()) {
|
|
33
|
+
const childIndex = potentialParent.children.findIndex((c) => c.id === nodeId);
|
|
34
|
+
if (childIndex !== -1) {
|
|
35
|
+
potentialParent.children.splice(childIndex, 1);
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (tree.root?.id === nodeId) {
|
|
40
|
+
tree.root = null;
|
|
41
|
+
}
|
|
42
|
+
const removeDescendants = (n) => {
|
|
43
|
+
tree.nodeMap.delete(n.id);
|
|
44
|
+
for (const child of n.children) {
|
|
45
|
+
removeDescendants(child);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
removeDescendants(node);
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
function findNode(tree, nodeId) {
|
|
52
|
+
return tree.nodeMap.get(nodeId);
|
|
53
|
+
}
|
|
54
|
+
function getRootNodes(tree) {
|
|
55
|
+
const childIds = /* @__PURE__ */ new Set();
|
|
56
|
+
for (const node of tree.nodeMap.values()) {
|
|
57
|
+
for (const child of node.children) {
|
|
58
|
+
childIds.add(child.id);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
const roots = [];
|
|
62
|
+
for (const node of tree.nodeMap.values()) {
|
|
63
|
+
if (!childIds.has(node.id)) {
|
|
64
|
+
roots.push(node);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return roots;
|
|
68
|
+
}
|
|
69
|
+
function setSubtreeDepth(node, depth) {
|
|
70
|
+
node.depth = depth;
|
|
71
|
+
for (const child of node.children) {
|
|
72
|
+
setSubtreeDepth(child, depth + 1);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { addChild, createNode, createTree, findNode, getRootNodes, removeNode, setSubtreeDepth };
|
|
77
|
+
//# sourceMappingURL=chunk-E7W2FVWO.js.map
|
|
78
|
+
//# sourceMappingURL=chunk-E7W2FVWO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/tree.ts"],"names":[],"mappings":";AAKO,SAAS,UAAA,GAA4B;AAC1C,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,IAAA;AAAA,IACN,OAAA,sBAAa,GAAA;AAAI,GACnB;AACF;AAKO,SAAS,WACd,EAAA,EACA,IAAA,EACA,OAAA,GAAmC,IAAA,EACnC,QAAQ,CAAA,EACE;AACV,EAAA,OAAO;AAAA,IACL,EAAA;AAAA,IACA,IAAA;AAAA,IACA,UAAU,EAAC;AAAA,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AAQ,MAAA,CAAO,CAAA,CAAE,EAAE,CAAA;AACxB,IAAA,KAAA,MAAW,KAAA,IAAS,EAAE,QAAA,EAAU;AAC9B,MAAA,iBAAA,CAAkB,KAAK,CAAA;AAAA,IACzB;AAAA,EACF,CAAA;AACA,EAAA,iBAAA,CAAkB,IAAI,CAAA;AAEtB,EAAA,OAAO,IAAA;AACT;AAKO,SAAS,QAAA,CAAS,MAAqB,MAAA,EAAsC;AAClF,EAAA,OAAO,IAAA,CAAK,OAAA,CAAQ,GAAA,CAAI,MAAM,CAAA;AAChC;AA6PO,SAAS,aAAa,IAAA,EAAiC;AAC5D,EAAA,MAAM,QAAA,uBAAe,GAAA,EAAY;AACjC,EAAA,KAAA,MAAW,IAAA,IAAQ,IAAA,CAAK,OAAA,CAAQ,MAAA,EAAO,EAAG;AACxC,IAAA,KAAA,MAAW,KAAA,IAAS,KAAK,QAAA,EAAU;AACjC,MAAA,QAAA,CAAS,GAAA,CAAI,MAAM,EAAE,CAAA;AAAA,IACvB;AAAA,EACF;AACA,EAAA,MAAM,QAAoB,EAAC;AAC3B,EAAA,KAAA,MAAW,IAAA,IAAQ,IAAA,CAAK,OAAA,CAAQ,MAAA,EAAO,EAAG;AACxC,IAAA,IAAI,CAAC,QAAA,CAAS,GAAA,CAAI,IAAA,CAAK,EAAE,CAAA,EAAG;AAC1B,MAAA,KAAA,CAAM,KAAK,IAAI,CAAA;AAAA,IACjB;AAAA,EACF;AACA,EAAA,OAAO,KAAA;AACT;AAKO,SAAS,eAAA,CAAgB,MAAgB,KAAA,EAAqB;AACnE,EAAA,IAAA,CAAK,KAAA,GAAQ,KAAA;AACb,EAAA,KAAA,MAAW,KAAA,IAAS,KAAK,QAAA,EAAU;AACjC,IAAA,eAAA,CAAgB,KAAA,EAAO,QAAQ,CAAC,CAAA;AAAA,EAClC;AACF","file":"chunk-E7W2FVWO.js","sourcesContent":["import type { ComponentTree, TreeNode, ComponentMetrics } from '../types'\n\n/**\n * Create an empty component tree.\n */\nexport function createTree(): ComponentTree {\n return {\n root: null,\n nodeMap: new Map(),\n }\n}\n\n/**\n * Create a new tree node.\n */\nexport function createNode(\n id: string,\n name: string,\n metrics: ComponentMetrics | null = null,\n depth = 0\n): TreeNode {\n return {\n id,\n name,\n children: [],\n metrics,\n depth,\n isExpanded: true,\n }\n}\n\n/**\n * Add a child node to a parent node.\n */\nexport function addChild(parent: TreeNode, child: TreeNode): void {\n // Check if child already exists\n const existingIndex = parent.children.findIndex((c) => c.id === child.id)\n if (existingIndex !== -1) {\n // Replace existing\n parent.children[existingIndex] = child\n } else {\n parent.children.push(child)\n }\n child.depth = parent.depth + 1\n}\n\n/**\n * Remove a node from the tree.\n */\nexport function removeNode(tree: ComponentTree, nodeId: string): boolean {\n const node = tree.nodeMap.get(nodeId)\n if (!node) {\n return false\n }\n\n // Remove from parent's children\n for (const potentialParent of tree.nodeMap.values()) {\n const childIndex = potentialParent.children.findIndex((c) => c.id === nodeId)\n if (childIndex !== -1) {\n potentialParent.children.splice(childIndex, 1)\n break\n }\n }\n\n // If this was the root, clear it\n if (tree.root?.id === nodeId) {\n tree.root = null\n }\n\n // Remove all descendants from nodeMap\n const removeDescendants = (n: TreeNode) => {\n tree.nodeMap.delete(n.id)\n for (const child of n.children) {\n removeDescendants(child)\n }\n }\n removeDescendants(node)\n\n return true\n}\n\n/**\n * Find a node by ID.\n */\nexport function findNode(tree: ComponentTree, nodeId: string): TreeNode | undefined {\n return tree.nodeMap.get(nodeId)\n}\n\n/**\n * Update a node's metrics.\n */\nexport function updateNodeMetrics(tree: ComponentTree, nodeId: string, metrics: ComponentMetrics): boolean {\n const node = tree.nodeMap.get(nodeId)\n if (!node) {\n return false\n }\n node.metrics = metrics\n return true\n}\n\n/**\n * Traverse the tree depth-first (pre-order).\n */\nexport function traverseDepthFirst(\n tree: ComponentTree,\n callback: (node: TreeNode, depth: number) => void | boolean\n): void {\n if (!tree.root) {\n return\n }\n\n const traverse = (node: TreeNode, depth: number): boolean => {\n const result = callback(node, depth)\n if (result === false) {\n return false\n }\n\n for (const child of node.children) {\n if (traverse(child, depth + 1) === false) {\n return false\n }\n }\n return true\n }\n\n traverse(tree.root, 0)\n}\n\n/**\n * Traverse the tree breadth-first.\n */\nexport function traverseBreadthFirst(\n tree: ComponentTree,\n callback: (node: TreeNode, depth: number) => void | boolean\n): void {\n if (!tree.root) {\n return\n }\n\n const queue: Array<{ node: TreeNode; depth: number }> = [{ node: tree.root, depth: 0 }]\n\n while (queue.length > 0) {\n const item = queue.shift()!\n const result = callback(item.node, item.depth)\n\n if (result === false) {\n break\n }\n\n for (const child of item.node.children) {\n queue.push({ node: child, depth: item.depth + 1 })\n }\n }\n}\n\n/**\n * Get all ancestors of a node (from parent to root).\n */\nexport function getAncestors(tree: ComponentTree, nodeId: string): TreeNode[] {\n const ancestors: TreeNode[] = []\n const targetNode = tree.nodeMap.get(nodeId)\n\n if (!targetNode) {\n return ancestors\n }\n\n // Find parent by searching all nodes\n const findParent = (targetId: string): TreeNode | null => {\n for (const node of tree.nodeMap.values()) {\n if (node.children.some((c) => c.id === targetId)) {\n return node\n }\n }\n return null\n }\n\n let currentId = nodeId\n let parent = findParent(currentId)\n\n while (parent) {\n ancestors.push(parent)\n currentId = parent.id\n parent = findParent(currentId)\n }\n\n return ancestors\n}\n\n/**\n * Get all descendants of a node.\n */\nexport function getDescendants(tree: ComponentTree, nodeId: string): TreeNode[] {\n const descendants: TreeNode[] = []\n const node = tree.nodeMap.get(nodeId)\n\n if (!node) {\n return descendants\n }\n\n const collect = (n: TreeNode) => {\n for (const child of n.children) {\n descendants.push(child)\n collect(child)\n }\n }\n\n collect(node)\n return descendants\n}\n\n/**\n * Flatten the tree into an array (depth-first order).\n */\nexport function flattenTree(tree: ComponentTree): TreeNode[] {\n const nodes: TreeNode[] = []\n\n traverseDepthFirst(tree, (node) => {\n nodes.push(node)\n })\n\n return nodes\n}\n\n/**\n * Get the depth of a node.\n */\nexport function getNodeDepth(tree: ComponentTree, nodeId: string): number {\n const node = tree.nodeMap.get(nodeId)\n if (!node) {\n return -1\n }\n return node.depth\n}\n\n/**\n * Check if a node is an ancestor of another node.\n */\nexport function isAncestor(tree: ComponentTree, ancestorId: string, descendantId: string): boolean {\n const ancestors = getAncestors(tree, descendantId)\n return ancestors.some((a) => a.id === ancestorId)\n}\n\n/**\n * Get the path from root to a node.\n */\nexport function getPath(tree: ComponentTree, nodeId: string): TreeNode[] {\n const ancestors = getAncestors(tree, nodeId)\n const node = tree.nodeMap.get(nodeId)\n\n if (!node) {\n return []\n }\n\n return [...ancestors.reverse(), node]\n}\n\n/**\n * Count total nodes in the tree.\n */\nexport function countNodes(tree: ComponentTree): number {\n return tree.nodeMap.size\n}\n\n/**\n * Get maximum depth of the tree.\n */\nexport function getMaxDepth(tree: ComponentTree): number {\n let maxDepth = -1\n\n traverseDepthFirst(tree, (_node, depth) => {\n if (depth > maxDepth) {\n maxDepth = depth\n }\n })\n\n return maxDepth\n}\n\n/**\n * Toggle node expansion state.\n */\nexport function toggleNode(tree: ComponentTree, nodeId: string): boolean {\n const node = tree.nodeMap.get(nodeId)\n if (!node) {\n return false\n }\n node.isExpanded = !node.isExpanded\n return true\n}\n\n/**\n * Expand all nodes.\n */\nexport function expandAll(tree: ComponentTree): void {\n for (const node of tree.nodeMap.values()) {\n node.isExpanded = true\n }\n}\n\n/**\n * Collapse all nodes.\n */\nexport function collapseAll(tree: ComponentTree): void {\n for (const node of tree.nodeMap.values()) {\n node.isExpanded = false\n }\n}\n\n/**\n * Filter tree nodes by a predicate.\n */\nexport function filterTree(\n tree: ComponentTree,\n predicate: (node: TreeNode) => boolean\n): TreeNode[] {\n const matching: TreeNode[] = []\n\n for (const node of tree.nodeMap.values()) {\n if (predicate(node)) {\n matching.push(node)\n }\n }\n\n return matching\n}\n\n/**\n * Search tree nodes by name (case-insensitive).\n */\nexport function searchTree(tree: ComponentTree, query: string): TreeNode[] {\n const lowerQuery = query.toLowerCase()\n\n return filterTree(tree, (node) => node.name.toLowerCase().includes(lowerQuery))\n}\n\n/**\n * Get every top-level node: nodes that are not a child of another node.\n * A tree can have several of them (e.g. sibling `<Scope>`s directly under the provider).\n */\nexport function getRootNodes(tree: ComponentTree): TreeNode[] {\n const childIds = new Set<string>()\n for (const node of tree.nodeMap.values()) {\n for (const child of node.children) {\n childIds.add(child.id)\n }\n }\n const roots: TreeNode[] = []\n for (const node of tree.nodeMap.values()) {\n if (!childIds.has(node.id)) {\n roots.push(node)\n }\n }\n return roots\n}\n\n/**\n * Set the depth of a node and recompute the depth of all its descendants.\n */\nexport function setSubtreeDepth(node: TreeNode, depth: number): void {\n node.depth = depth\n for (const child of node.children) {\n setSubtreeDepth(child, depth + 1)\n }\n}\n"]}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var chunkACLEEAEC_cjs = require('./chunk-ACLEEAEC.cjs');
|
|
4
|
+
var chunkOMETOKM7_cjs = require('./chunk-OMETOKM7.cjs');
|
|
5
|
+
|
|
3
6
|
// src/plugins/json-exporter/json-exporter.ts
|
|
4
7
|
var JSONExporterPlugin = class {
|
|
5
8
|
constructor() {
|
|
@@ -8,14 +11,14 @@ var JSONExporterPlugin = class {
|
|
|
8
11
|
this.kernel = null;
|
|
9
12
|
this.api = {
|
|
10
13
|
exportAll: () => {
|
|
11
|
-
return
|
|
14
|
+
return chunkACLEEAEC_cjs.safeStringify(this.getSerializableMetrics(), 2);
|
|
12
15
|
},
|
|
13
16
|
exportComponent: (componentId) => {
|
|
14
17
|
const metrics = this.kernel?.getMetrics().get(componentId);
|
|
15
18
|
if (!metrics) {
|
|
16
19
|
return JSON.stringify({ error: "Component not found" });
|
|
17
20
|
}
|
|
18
|
-
return
|
|
21
|
+
return chunkACLEEAEC_cjs.safeStringify(this.serializeMetrics(metrics), 2);
|
|
19
22
|
},
|
|
20
23
|
exportSummary: () => {
|
|
21
24
|
return this.generateSummary();
|
|
@@ -42,7 +45,7 @@ var JSONExporterPlugin = class {
|
|
|
42
45
|
if (!this.kernel) {
|
|
43
46
|
return {
|
|
44
47
|
components: [],
|
|
45
|
-
tree: { root: null },
|
|
48
|
+
tree: { root: null, roots: [] },
|
|
46
49
|
timeline: [],
|
|
47
50
|
session: { start: 0, end: 0, duration: 0 }
|
|
48
51
|
};
|
|
@@ -55,11 +58,11 @@ var JSONExporterPlugin = class {
|
|
|
55
58
|
name: metrics.componentName,
|
|
56
59
|
metrics: this.serializeMetrics(metrics)
|
|
57
60
|
}));
|
|
58
|
-
const
|
|
61
|
+
const roots = chunkOMETOKM7_cjs.getRootNodes(tree).map((node) => this.serializeTree(node)).filter((node) => node !== null);
|
|
59
62
|
return {
|
|
60
63
|
components,
|
|
61
|
-
tree: { root:
|
|
62
|
-
timeline: metricsStore.getTimeline(),
|
|
64
|
+
tree: { root: this.serializeTree(tree.root), roots },
|
|
65
|
+
timeline: chunkACLEEAEC_cjs.toSerializable(metricsStore.getTimeline()),
|
|
63
66
|
session: {
|
|
64
67
|
start: metricsStore.getSessionStart(),
|
|
65
68
|
end: Date.now(),
|
|
@@ -145,5 +148,5 @@ function createJSONExporterPlugin() {
|
|
|
145
148
|
|
|
146
149
|
exports.JSONExporterPlugin = JSONExporterPlugin;
|
|
147
150
|
exports.createJSONExporterPlugin = createJSONExporterPlugin;
|
|
148
|
-
//# sourceMappingURL=chunk-
|
|
149
|
-
//# sourceMappingURL=chunk-
|
|
151
|
+
//# sourceMappingURL=chunk-EUYOAT56.cjs.map
|
|
152
|
+
//# sourceMappingURL=chunk-EUYOAT56.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugins/json-exporter/json-exporter.ts"],"names":["safeStringify","getRootNodes","toSerializable"],"mappings":";;;;;;AA4BO,IAAM,qBAAN,MAA2C;AAAA,EAA3C,WAAA,GAAA;AACL,IAAA,IAAA,CAAS,IAAA,GAAO,eAAA;AAChB,IAAA,IAAA,CAAS,OAAA,GAAU,OAAA;AAEnB,IAAA,IAAA,C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IAAA,CAAK,GAAA,CAAI,SAAA,EAAU;AAChC,IAAA,MAAM,IAAA,GAAO,IAAI,IAAA,CAAK,CAAC,IAAI,CAAA,EAAG,EAAE,IAAA,EAAM,kBAAA,EAAoB,CAAA;AAC1D,IAAA,MAAM,GAAA,GAAM,GAAA,CAAI,eAAA,CAAgB,IAAI,CAAA;AAEpC,IAAA,MAAM,IAAA,GAAO,QAAA,IAAY,CAAA,kBAAA,EAAqB,IAAA,CAAK,KAAK,CAAA,KAAA,CAAA;AAExD,IAAA,MAAM,IAAA,GAAO,QAAA,CAAS,aAAA,CAAc,GAAG,CAAA;AACvC,IAAA,IAAA,CAAK,IAAA,GAAO,GAAA;AACZ,IAAA,IAAA,CAAK,QAAA,GAAW,IAAA;AAChB,IAAA,IAAA,CAAK,KAAA,EAAM;AAEX,IAAA,GAAA,CAAI,gBAAgB,GAAG,CAAA;AAAA,EACzB;AACF;AAKO,SAAS,wBAAA,GAA+C;AAC7D,EAAA,OAAO,IAAI,kBAAA,EAAmB;AAChC","file":"chunk-EUYOAT56.cjs","sourcesContent":["import type {\n Kernel,\n Plugin,\n ExportSummary,\n ComponentSummary,\n SerializableMetrics,\n SerializableTreeNode,\n ComponentMetrics,\n TreeNode,\n TimelineEvent,\n} from '../../types'\nimport { safeStringify, toSerializable } from '../../utils/serialize'\nimport { getRootNodes } from '../../utils/tree'\n\nexport interface JSONExporterAPI {\n [key: string]: unknown\n exportAll(): string\n exportComponent(componentId: string): string\n exportSummary(): ExportSummary\n downloadJSON(filename?: string): void\n getSerializableMetrics(): SerializableMetrics\n exportToClipboard(): Promise<void>\n}\n\n/**\n * JSON Exporter Plugin\n * Exports metrics as JSON for CI/CD integration.\n */\nexport class JSONExporterPlugin implements Plugin {\n readonly name = 'json-exporter'\n readonly version = '1.0.0'\n\n private kernel: Kernel | null = null\n\n readonly api: JSONExporterAPI = {\n exportAll: () => {\n return safeStringify(this.getSerializableMetrics(), 2)\n },\n\n exportComponent: (componentId: string) => {\n const metrics = this.kernel?.getMetrics().get(componentId)\n if (!metrics) {\n return JSON.stringify({ error: 'Component not found' })\n }\n return safeStringify(this.serializeMetrics(metrics), 2)\n },\n\n exportSummary: () => {\n return this.generateSummary()\n },\n\n downloadJSON: (filename?: string) => {\n this.download(filename)\n },\n\n getSerializableMetrics: () => {\n return this.getSerializableMetrics()\n },\n\n exportToClipboard: async () => {\n const json = this.api.exportAll()\n await navigator.clipboard.writeText(json)\n },\n }\n\n install(kernel: Kernel): void {\n this.kernel = kernel\n }\n\n uninstall(): void {\n this.kernel = null\n }\n\n private getSerializableMetrics(): SerializableMetrics {\n if (!this.kernel) {\n return {\n components: [],\n tree: { root: null, roots: [] },\n timeline: [],\n session: { start: 0, end: 0, duration: 0 },\n }\n }\n\n const metricsStore = this.kernel.getMetrics()\n const allMetrics = metricsStore.getAll()\n const tree = metricsStore.getTree()\n\n const components = Array.from(allMetrics.entries()).map(([id, metrics]) => ({\n id,\n name: metrics.componentName,\n metrics: this.serializeMetrics(metrics),\n }))\n\n const roots = getRootNodes(tree)\n .map((node) => this.serializeTree(node))\n .filter((node): node is SerializableTreeNode => node !== null)\n\n return {\n components,\n tree: { root: this.serializeTree(tree.root), roots },\n timeline: toSerializable(metricsStore.getTimeline()) as TimelineEvent[],\n session: {\n start: metricsStore.getSessionStart(),\n end: Date.now(),\n duration: metricsStore.getSessionDuration(),\n },\n }\n }\n\n private serializeMetrics(metrics: ComponentMetrics): ComponentMetrics {\n return {\n ...metrics,\n renderHistory: [...metrics.renderHistory],\n childIds: [...metrics.childIds],\n }\n }\n\n private serializeTree(node: TreeNode | null): SerializableTreeNode | null {\n if (!node) return null\n\n return {\n id: node.id,\n name: node.name,\n children: node.children.map((child) => this.serializeTree(child)).filter(Boolean) as SerializableTreeNode[],\n depth: node.depth,\n }\n }\n\n private generateSummary(): ExportSummary {\n if (!this.kernel) {\n return {\n totalComponents: 0,\n totalRenders: 0,\n totalWastedRenders: 0,\n averageRenderTime: 0,\n slowestComponents: [],\n mostWastedComponents: [],\n timestamp: new Date().toISOString(),\n duration: 0,\n }\n }\n\n const metricsStore = this.kernel.getMetrics()\n const allMetrics = Array.from(metricsStore.getAll().values())\n\n let totalRenders = 0\n let totalWastedRenders = 0\n let totalRenderTime = 0\n\n const componentStats: ComponentSummary[] = []\n\n for (const metrics of allMetrics) {\n totalRenders += metrics.renderCount\n totalWastedRenders += metrics.wastedRenderCount\n totalRenderTime += metrics.totalRenderTime\n\n componentStats.push({\n componentId: metrics.componentId,\n componentName: metrics.componentName,\n renderCount: metrics.renderCount,\n averageRenderTime: metrics.averageRenderTime,\n wastedRenderCount: metrics.wastedRenderCount,\n })\n }\n\n const slowestComponents = [...componentStats]\n .sort((a, b) => b.averageRenderTime - a.averageRenderTime)\n .slice(0, 10)\n\n const mostWastedComponents = [...componentStats]\n .sort((a, b) => b.wastedRenderCount - a.wastedRenderCount)\n .slice(0, 10)\n\n return {\n totalComponents: allMetrics.length,\n totalRenders,\n totalWastedRenders,\n averageRenderTime: totalRenders > 0 ? totalRenderTime / totalRenders : 0,\n slowestComponents,\n mostWastedComponents,\n timestamp: new Date().toISOString(),\n duration: metricsStore.getSessionDuration(),\n }\n }\n\n private download(filename?: string): void {\n const json = this.api.exportAll()\n const blob = new Blob([json], { type: 'application/json' })\n const url = URL.createObjectURL(blob)\n\n const name = filename ?? `reactscope-export-${Date.now()}.json`\n\n const link = document.createElement('a')\n link.href = url\n link.download = name\n link.click()\n\n URL.revokeObjectURL(url)\n }\n}\n\n/**\n * Create a new JSON exporter plugin instance.\n */\nexport function createJSONExporterPlugin(): JSONExporterPlugin {\n return new JSONExporterPlugin()\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { uid } from './chunk-
|
|
1
|
+
import { uid } from './chunk-AZ6OARKV.js';
|
|
2
|
+
import { safeStringify } from './chunk-YG5FHHRH.js';
|
|
2
3
|
|
|
3
4
|
// src/plugins/timeline-recorder/timeline-recorder.ts
|
|
4
5
|
var TimelineRecorderPlugin = class {
|
|
@@ -27,7 +28,7 @@ var TimelineRecorderPlugin = class {
|
|
|
27
28
|
this.clearRecording();
|
|
28
29
|
},
|
|
29
30
|
exportRecording: () => {
|
|
30
|
-
return
|
|
31
|
+
return safeStringify(this.getRecording(), 2);
|
|
31
32
|
},
|
|
32
33
|
getTimeRange: () => {
|
|
33
34
|
return {
|
|
@@ -127,5 +128,5 @@ function createTimelineRecorderPlugin() {
|
|
|
127
128
|
}
|
|
128
129
|
|
|
129
130
|
export { TimelineRecorderPlugin, createTimelineRecorderPlugin };
|
|
130
|
-
//# sourceMappingURL=chunk-
|
|
131
|
-
//# sourceMappingURL=chunk-
|
|
131
|
+
//# sourceMappingURL=chunk-F3KDHISM.js.map
|
|
132
|
+
//# sourceMappingURL=chunk-F3KDHISM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/plugins/timeline-recorder/timeline-recorder.ts"],"names":[],"mappings":";;;;AA4BO,IAAM,yBAAN,MAA+C;AAAA,EAA/C,WAAA,GAAA;AACL,IAAA,IAAA,CAAS,IAAA,GAAO,mBAAA;AAChB,IAAA,IAAA,CAAS,OAAA,GAAU,OAAA;AAEnB,IAAA,IAAA,CAAQ,SAAA,GAAY,KAAA;AACpB,IAAA,IAAA,CAAQ,SAA6B,EAAC;AACtC,IAAA,IAAA,CAAQ,SAAA,GAA2B,IAAA;AACnC,IAAA,IAAA,CAAQ,OAAA,GAAyB,IAAA;AACjC,IAAA,IAAA,CAAQ,SAAA,GAAY,GAAA;AAEpB,IAAA,IAAA,CAAS,GAAA,GAA2B;AAAA,MAClC,gBAAgB,MAAM;AACpB,QAAA,IAAA,CAAK,cAAA,EAAe;AAAA,MACtB,CAAA;AAAA,MAEA,eAAe,MAAM;AACnB,QAAA,IAAA,CAAK,aAAA,EAAc;AAAA,MACrB,CAAA;AAAA,MAEA,aAAa,MAAM;AACjB,QAAA,OAAO,IAAA,CAAK,SAAA;AAAA,MACd,CAAA;AAAA,MAEA,cAAc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\n} from '../../types'\nimport { uid } from '../../utils/uid'\nimport { safeStringify } from '../../utils/serialize'\n\nexport interface TimelineRecorderAPI {\n [key: string]: unknown\n startRecording(): void\n stopRecording(): void\n isRecording(): boolean\n getRecording(): TimelineRecording\n clearRecording(): void\n exportRecording(): string\n getTimeRange(): { start: number; end: number }\n getEventsByType(type: string): TimestampedEvent[]\n seekTo(timestamp: number): TimestampedEvent[]\n getEventCount(): number\n}\n\n/**\n * Timeline Recorder Plugin\n * Records events over time for playback/analysis.\n */\nexport class TimelineRecorderPlugin implements Plugin {\n readonly name = 'timeline-recorder'\n readonly version = '1.0.0'\n\n private recording = false\n private events: TimestampedEvent[] = []\n private startTime: number | null = null\n private endTime: number | null = null\n private maxEvents = 10000\n\n readonly api: TimelineRecorderAPI = {\n startRecording: () => {\n this.startRecording()\n },\n\n stopRecording: () => {\n this.stopRecording()\n },\n\n isRecording: () => {\n return this.recording\n },\n\n getRecording: () => {\n return this.getRecording()\n },\n\n clearRecording: () => {\n this.clearRecording()\n },\n\n exportRecording: () => {\n return safeStringify(this.getRecording(), 2)\n },\n\n getTimeRange: () => {\n return {\n start: this.startTime ?? 0,\n end: this.endTime ?? Date.now(),\n }\n },\n\n getEventsByType: (type: string) => {\n return this.events.filter((e) => e.type === type)\n },\n\n seekTo: (timestamp: number) => {\n return this.events.filter((e) => e.timestamp <= timestamp)\n },\n\n getEventCount: () => {\n return this.events.length\n },\n }\n\n readonly hooks = {\n onRender: (event: KernelEvent) => {\n this.recordEvent(event)\n },\n\n onMount: (event: KernelEvent) => {\n this.recordEvent(event)\n },\n\n onUnmount: (event: KernelEvent) => {\n this.recordEvent(event)\n },\n\n onPropsChange: (event: KernelEvent) => {\n this.recordEvent(event)\n },\n\n onStateChange: (event: KernelEvent) => {\n this.recordEvent(event)\n },\n }\n\n install(kernel: Kernel): void {\n this.maxEvents = kernel.getOptions().maxHistorySize ?? 10000\n }\n\n uninstall(): void {\n this.stopRecording()\n this.events = []\n }\n\n private startRecording(): void {\n if (this.recording) return\n\n this.recording = true\n this.startTime = Date.now()\n this.endTime = null\n this.events = []\n }\n\n private stopRecording(): void {\n if (!this.recording) return\n\n this.recording = false\n this.endTime = Date.now()\n }\n\n private recordEvent(event: KernelEvent): void {\n if (!this.recording) return\n\n const timestampedEvent: TimestampedEvent = {\n id: uid(),\n type: event.type,\n timestamp: event.timestamp,\n data: event as unknown as Record<string, unknown>,\n }\n\n this.events.push(timestampedEvent)\n\n // Limit events\n if (this.events.length > this.maxEvents) {\n this.events = this.events.slice(-this.maxEvents)\n }\n }\n\n private getRecording(): TimelineRecording {\n const componentIds = new Set<string>()\n\n for (const event of this.events) {\n const data = event.data as { componentId?: string }\n if (data.componentId) {\n componentIds.add(data.componentId)\n }\n }\n\n const duration =\n this.startTime !== null\n ? (this.endTime ?? Date.now()) - this.startTime\n : 0\n\n return {\n events: [...this.events],\n startTime: this.startTime ?? 0,\n endTime: this.endTime,\n metadata: {\n componentCount: componentIds.size,\n eventCount: this.events.length,\n duration,\n },\n }\n }\n\n private clearRecording(): void {\n this.events = []\n this.startTime = null\n this.endTime = null\n this.recording = false\n }\n}\n\n/**\n * Create a new timeline recorder plugin instance.\n */\nexport function createTimelineRecorderPlugin(): TimelineRecorderPlugin {\n return new TimelineRecorderPlugin()\n}\n"]}
|
|
@@ -25,5 +25,5 @@ function createIdGenerator(prefix = "") {
|
|
|
25
25
|
|
|
26
26
|
exports.createIdGenerator = createIdGenerator;
|
|
27
27
|
exports.uid = uid;
|
|
28
|
-
//# sourceMappingURL=chunk-
|
|
29
|
-
//# sourceMappingURL=chunk-
|
|
28
|
+
//# sourceMappingURL=chunk-KRRXA4SI.cjs.map
|
|
29
|
+
//# sourceMappingURL=chunk-KRRXA4SI.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/uid.ts"],"names":[],"mappings":";;;AAGA,IAAI,OAAA,GAAU,CAAA;AAKd,IAAI,aAAA,GAAgB,CAAA;AAMb,SAAS,GAA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AAA,CAAA,EAAI,QAAQ,QAAA,CAAS,EAAE,CAAC,CAAA,CAAA,GAAK,EAAA;AAE1D,EAAA,OAAO,CAAA,EAAG,SAAS,CAAA,CAAA,EAAI,MAAM,GAAG,MAAM,CAAA,CAAA;AACxC;AAMO,SAAS,iBAAA,CAAkB,SAAS,EAAA,EAAkB;AAC3D,EAAA,OAAO,MAAc;AACnB,IAAA,MAAM,OAAO,GAAA,EAAI;AACjB,IAAA,OAAO,MAAA,GAAS,CAAA,EAAG,MAAM,CAAA,CAAA,EAAI,IAAI,CAAA,CAAA,GAAK,IAAA;AAAA,EACxC,CAAA;AACF","file":"chunk-KRRXA4SI.cjs","sourcesContent":["/**\n * Counter for ensuring uniqueness within the same millisecond\n */\nlet counter = 0\n\n/**\n * Last timestamp used for ID generation\n */\nlet lastTimestamp = 0\n\n/**\n * Generate a unique ID.\n * Format: timestamp-random where timestamp is base36 encoded.\n */\nexport function uid(): string {\n const now = Date.now()\n\n // Reset counter if we're in a new millisecond\n if (now !== lastTimestamp) {\n counter = 0\n lastTimestamp = now\n } else {\n counter++\n }\n\n const timestamp = now.toString(36)\n const random = Math.random().toString(36).substring(2, 8)\n const suffix = counter > 0 ? `-${counter.toString(36)}` : ''\n\n return `${timestamp}-${random}${suffix}`\n}\n\n/**\n * Create an ID generator with an optional prefix.\n * Each call returns a new unique ID.\n */\nexport function createIdGenerator(prefix = ''): () => string {\n return (): string => {\n const base = uid()\n return prefix ? `${prefix}-${base}` : base\n }\n}\n\n/**\n * Generate a short unique ID (shorter but less collision resistant).\n * Useful for component display names.\n */\nexport function shortId(): string {\n return Math.random().toString(36).substring(2, 9)\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { uid } from './chunk-
|
|
1
|
+
import { uid } from './chunk-AZ6OARKV.js';
|
|
2
2
|
|
|
3
3
|
// src/plugins/network-correlator/network-correlator.ts
|
|
4
4
|
var NetworkCorrelatorPlugin = class {
|
|
@@ -91,15 +91,14 @@ var NetworkCorrelatorPlugin = class {
|
|
|
91
91
|
if (entry.name.startsWith("data:") || entry.name.startsWith("chrome-extension:")) {
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
94
|
+
const status = entry.responseStatus;
|
|
94
95
|
const request = {
|
|
95
96
|
id: uid(),
|
|
96
97
|
url: entry.name,
|
|
97
98
|
method: "GET",
|
|
98
|
-
// PerformanceResourceTiming doesn't expose method
|
|
99
99
|
startTime: entry.startTime,
|
|
100
100
|
endTime: entry.responseEnd,
|
|
101
|
-
status:
|
|
102
|
-
// PerformanceResourceTiming doesn't expose status
|
|
101
|
+
status: typeof status === "number" ? status : 0,
|
|
103
102
|
size: entry.transferSize || 0
|
|
104
103
|
};
|
|
105
104
|
this.requests.push(request);
|
|
@@ -113,25 +112,48 @@ var NetworkCorrelatorPlugin = class {
|
|
|
113
112
|
if (this.renderEvents.length > this.maxHistorySize) {
|
|
114
113
|
this.renderEvents = this.renderEvents.slice(-this.maxHistorySize);
|
|
115
114
|
}
|
|
115
|
+
const renderTime = this.toPerformanceTime(event.timestamp);
|
|
116
|
+
const from = Math.max(0, this.requests.length - 200);
|
|
117
|
+
for (let i = this.requests.length - 1; i >= from; i--) {
|
|
118
|
+
const request = this.requests[i];
|
|
119
|
+
if (this.isInWindow(request, renderTime)) {
|
|
120
|
+
this.addCorrelation(request, [event]);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/** Render events carry `Date.now()` timestamps; requests use `performance.now()` time. */
|
|
125
|
+
toPerformanceTime(timestamp) {
|
|
126
|
+
const origin = typeof performance !== "undefined" ? performance.timeOrigin : 0;
|
|
127
|
+
return timestamp - origin;
|
|
128
|
+
}
|
|
129
|
+
isInWindow(request, renderTime) {
|
|
130
|
+
return renderTime >= request.endTime && renderTime <= request.endTime + this.correlationWindow;
|
|
116
131
|
}
|
|
117
132
|
findCorrelations(request) {
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const correlatedRenders = this.renderEvents.filter((render) => {
|
|
122
|
-
const renderTime = render.timestamp - performance.timeOrigin;
|
|
123
|
-
return renderTime >= windowStart && renderTime <= windowEnd;
|
|
124
|
-
});
|
|
133
|
+
const correlatedRenders = this.renderEvents.filter(
|
|
134
|
+
(render) => this.isInWindow(request, this.toPerformanceTime(render.timestamp))
|
|
135
|
+
);
|
|
125
136
|
if (correlatedRenders.length > 0) {
|
|
126
|
-
this.
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
137
|
+
this.addCorrelation(request, correlatedRenders);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
addCorrelation(request, renders) {
|
|
141
|
+
let correlation = this.correlations.find((c) => c.request.id === request.id);
|
|
142
|
+
if (!correlation) {
|
|
143
|
+
correlation = { request, renders: [], timeGap: 0 };
|
|
144
|
+
this.correlations.push(correlation);
|
|
131
145
|
if (this.correlations.length > this.maxHistorySize) {
|
|
132
146
|
this.correlations = this.correlations.slice(-this.maxHistorySize);
|
|
133
147
|
}
|
|
134
148
|
}
|
|
149
|
+
for (const render of renders) {
|
|
150
|
+
if (!correlation.renders.includes(render)) {
|
|
151
|
+
correlation.renders.push(render);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
correlation.renders.sort((a, b) => a.timestamp - b.timestamp);
|
|
155
|
+
const first = correlation.renders[0];
|
|
156
|
+
correlation.timeGap = first ? this.toPerformanceTime(first.timestamp) - request.endTime : 0;
|
|
135
157
|
}
|
|
136
158
|
getRequestsForComponent(componentId) {
|
|
137
159
|
const componentRequests = [];
|
|
@@ -166,5 +188,5 @@ function createNetworkCorrelatorPlugin() {
|
|
|
166
188
|
}
|
|
167
189
|
|
|
168
190
|
export { NetworkCorrelatorPlugin, createNetworkCorrelatorPlugin };
|
|
169
|
-
//# sourceMappingURL=chunk-
|
|
170
|
-
//# sourceMappingURL=chunk-
|
|
191
|
+
//# sourceMappingURL=chunk-MBFJ6ULY.js.map
|
|
192
|
+
//# sourceMappingUR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AAA;AAEtD,IAAA,OAAO;AAAA,MACL,aAAA,EAAe,KAAK,QAAA,CAAS,MAAA;AAAA,MAC7B,WAAA;AAAA,MACA;AAAA,KACF;AAAA,EACF;AACF;AAKO,SAAS,6BAAA,GAAyD;AACvE,EAAA,OAAO,IAAI,uBAAA,EAAwB;AACrC","file":"chunk-MBFJ6ULY.js","sourcesContent":["import type {\n Kernel,\n Plugin,\n RenderEvent,\n NetworkRequest,\n Correlation,\n RequestStats,\n} from '../../types'\nimport { uid } from '../../utils/uid'\n\nexport interface NetworkCorrelatorAPI {\n [key: string]: unknown\n getRequestsForComponent(componentId: string): NetworkRequest[]\n getRendersForRequest(requestId: string): RenderEvent[]\n getCorrelations(): Correlation[]\n startCapturing(): void\n stopCapturing(): void\n isCapturing(): boolean\n getRequestStats(): RequestStats\n clearRequests(): void\n getAllRequests(): NetworkRequest[]\n}\n\n/**\n * Network Correlator Plugin\n * Correlates renders with network requests.\n */\nexport class NetworkCorrelatorPlugin implements Plugin {\n readonly name = 'network-correlator'\n readonly version = '1.0.0'\n\n private capturing = false\n private requests: NetworkRequest[] = []\n private renderEvents: RenderEvent[] = []\n private correlations: Correlation[] = []\n private observer: PerformanceObserver | null = null\n private maxHistorySize = 1000\n private correlationWindow = 100 // ms - time window to correlate request completion with renders\n\n readonly api: NetworkCorrelatorAPI = {\n getRequestsForComponent: (componentId: string) => {\n return this.getRequestsForComponent(componentId)\n },\n\n getRendersForRequest: (requestId: string) => {\n const correlation = this.correlations.find((c) => c.request.id === requestId)\n return correlation?.renders ?? []\n },\n\n getCorrelations: () => {\n return [...this.correlations]\n },\n\n startCapturing: () => {\n this.startCapturing()\n },\n\n stopCapturing: () => {\n this.stopCapturing()\n },\n\n isCapturing: () => {\n return this.capturing\n },\n\n getRequestStats: () => {\n return this.getStats()\n },\n\n clearRequests: () => {\n this.requests = []\n this.correlations = []\n },\n\n getAllRequests: () => {\n return [...this.requests]\n },\n }\n\n readonly hooks = {\n onRender: (event: RenderEvent) => {\n if (this.capturing) {\n this.recordRenderEvent(event)\n }\n },\n }\n\n install(kernel: Kernel): void {\n this.maxHistorySize = kernel.getOptions().maxHistorySize ?? 1000\n }\n\n uninstall(): void {\n this.stopCapturing()\n this.requests = []\n this.renderEvents = []\n this.correlations = []\n }\n\n private startCapturing(): void {\n if (this.capturing) return\n\n this.capturing = true\n\n // Use PerformanceObserver to capture network requests\n if (typeof PerformanceObserver !== 'undefined') {\n try {\n this.observer = new PerformanceObserver((list) => {\n for (const entry of list.getEntries()) {\n if (entry.entryType === 'resource') {\n this.recordRequest(entry as PerformanceResourceTiming)\n }\n }\n })\n\n this.observer.observe({ entryTypes: ['resource'] })\n } catch (error) {\n console.warn('[ReactScope] PerformanceObserver not supported:', error)\n }\n }\n }\n\n private stopCapturing(): void {\n if (!this.capturing) return\n\n this.capturing = false\n\n if (this.observer) {\n this.observer.disconnect()\n this.observer = null\n }\n }\n\n private recordRequest(entry: PerformanceResourceTiming): void {\n // Filter out data URLs, extensions, etc.\n if (entry.name.startsWith('data:') || entry.name.startsWith('chrome-extension:')) {\n return\n }\n\n // Resource Timing does not expose the HTTP method; the status is only\n // available in newer browsers (`responseStatus`) and is 0 when unknown.\n const status = (entry as PerformanceResourceTiming & { responseStatus?: number }).responseStatus\n const request: NetworkRequest = {\n id: uid(),\n url: entry.name,\n method: 'GET',\n startTime: entry.startTime,\n endTime: entry.responseEnd,\n status: typeof status === 'number' ? status : 0,\n size: entry.transferSize || 0,\n }\n\n this.requests.push(request)\n\n // Limit history\n if (this.requests.length > this.maxHistorySize) {\n this.requests = this.requests.slice(-this.maxHistorySize)\n }\n\n // Find correlated renders (renders that happened shortly after request completed)\n this.findCorrelations(request)\n }\n\n private recordRenderEvent(event: RenderEvent): void {\n this.renderEvents.push(event)\n\n // Limit history\n if (this.renderEvents.length > this.maxHistorySize) {\n this.renderEvents = this.renderEvents.slice(-this.maxHistorySize)\n }\n\n // The resource entry is often observed before the renders it causes.\n const renderTime = this.toPerformanceTime(event.timestamp)\n // Only recent requests can be in the window; bound the scan.\n const from = Math.max(0, this.requests.length - 200)\n for (let i = this.requests.length - 1; i >= from; i--) {\n const request = this.requests[i]!\n if (this.isInWindow(request, renderTime)) {\n this.addCorrelation(request, [event])\n }\n }\n }\n\n /** Render events carry `Date.now()` timestamps; requests use `performance.now()` time. */\n private toPerformanceTime(timestamp: number): number {\n const origin = typeof performance !== 'undefined' ? performance.timeOrigin : 0\n return timestamp - origin\n }\n\n private isInWindow(request: NetworkRequest, renderTime: number): boolean {\n return renderTime >= request.endTime && renderTime <= request.endTime + this.correlationWindow\n }\n\n private findCorrelations(request: NetworkRequest): void {\n // Renders already recorded within the correlation window after completion\n const correlatedRenders = this.renderEvents.filter((render) =>\n this.isInWindow(request, this.toPerformanceTime(render.timestamp))\n )\n\n if (correlatedRenders.length > 0) {\n this.addCorrelation(request, correlatedRenders)\n }\n }\n\n private addCorrelation(request: NetworkRequest, renders: RenderEvent[]): void {\n let correlation = this.correlations.find((c) => c.request.id === request.id)\n if (!correlation) {\n correlation = { request, renders: [], timeGap: 0 }\n this.correlations.push(correlation)\n\n // Limit correlations\n if (this.correlations.length > this.maxHistorySize) {\n this.correlations = this.correlations.slice(-this.maxHistorySize)\n }\n }\n\n for (const render of renders) {\n if (!correlation.renders.includes(render)) {\n correlation.renders.push(render)\n }\n }\n correlation.renders.sort((a, b) => a.timestamp - b.timestamp)\n const first = correlation.renders[0]\n correlation.timeGap = first ? this.toPerformanceTime(first.timestamp) - request.endTime : 0\n }\n\n private getRequestsForComponent(componentId: string): NetworkRequest[] {\n const componentRequests: NetworkRequest[] = []\n\n for (const correlation of this.correlations) {\n if (correlation.renders.some((r) => r.componentId === componentId)) {\n componentRequests.push(correlation.request)\n }\n }\n\n return componentRequests\n }\n\n private getStats(): RequestStats {\n if (this.requests.length === 0) {\n return {\n totalRequests: 0,\n averageTime: 0,\n slowestRequest: null,\n }\n }\n\n const times = this.requests.map((r) => r.endTime - r.startTime)\n const averageTime = times.reduce((a, b) => a + b, 0) / times.length\n\n const slowestIndex = times.indexOf(Math.max(...times))\n const slowestRequest = this.requests[slowestIndex] ?? null\n\n return {\n totalRequests: this.requests.length,\n averageTime,\n slowestRequest,\n }\n }\n}\n\n/**\n * Create a new network correlator plugin instance.\n */\nexport function createNetworkCorrelatorPlugin(): NetworkCorrelatorPlugin {\n return new NetworkCorrelatorPlugin()\n}\n"]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/utils/tree.ts
|
|
4
|
+
function createTree() {
|
|
5
|
+
return {
|
|
6
|
+
root: null,
|
|
7
|
+
nodeMap: /* @__PURE__ */ new Map()
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function createNode(id, name, metrics = null, depth = 0) {
|
|
11
|
+
return {
|
|
12
|
+
id,
|
|
13
|
+
name,
|
|
14
|
+
children: [],
|
|
15
|
+
metrics,
|
|
16
|
+
depth,
|
|
17
|
+
isExpanded: true
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function addChild(parent, child) {
|
|
21
|
+
const existingIndex = parent.children.findIndex((c) => c.id === child.id);
|
|
22
|
+
if (existingIndex !== -1) {
|
|
23
|
+
parent.children[existingIndex] = child;
|
|
24
|
+
} else {
|
|
25
|
+
parent.children.push(child);
|
|
26
|
+
}
|
|
27
|
+
child.depth = parent.depth + 1;
|
|
28
|
+
}
|
|
29
|
+
function removeNode(tree, nodeId) {
|
|
30
|
+
const node = tree.nodeMap.get(nodeId);
|
|
31
|
+
if (!node) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
for (const potentialParent of tree.nodeMap.values()) {
|
|
35
|
+
const childIndex = potentialParent.children.findIndex((c) => c.id === nodeId);
|
|
36
|
+
if (childIndex !== -1) {
|
|
37
|
+
potentialParent.children.splice(childIndex, 1);
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (tree.root?.id === nodeId) {
|
|
42
|
+
tree.root = null;
|
|
43
|
+
}
|
|
44
|
+
const removeDescendants = (n) => {
|
|
45
|
+
tree.nodeMap.delete(n.id);
|
|
46
|
+
for (const child of n.children) {
|
|
47
|
+
removeDescendants(child);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
removeDescendants(node);
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
function findNode(tree, nodeId) {
|
|
54
|
+
return tree.nodeMap.get(nodeId);
|
|
55
|
+
}
|
|
56
|
+
function getRootNodes(tree) {
|
|
57
|
+
const childIds = /* @__PURE__ */ new Set();
|
|
58
|
+
for (const node of tree.nodeMap.values()) {
|
|
59
|
+
for (const child of node.children) {
|
|
60
|
+
childIds.add(child.id);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const roots = [];
|
|
64
|
+
for (const node of tree.nodeMap.values()) {
|
|
65
|
+
if (!childIds.has(node.id)) {
|
|
66
|
+
roots.push(node);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return roots;
|
|
70
|
+
}
|
|
71
|
+
function setSubtreeDepth(node, depth) {
|
|
72
|
+
node.depth = depth;
|
|
73
|
+
for (const child of node.children) {
|
|
74
|
+
setSubtreeDepth(child, depth + 1);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
exports.addChild = addChild;
|
|
79
|
+
exports.createNode = createNode;
|
|
80
|
+
exports.createTree = createTree;
|
|
81
|
+
exports.findNode = findNode;
|
|
82
|
+
exports.getRootNodes = getRootNodes;
|
|
83
|
+
exports.removeNode = removeNode;
|
|
84
|
+
exports.setSubtreeDepth = setSubtreeDepth;
|
|
85
|
+
//# sourceMappingURL=chunk-OMETOKM7.cjs.map
|
|
86
|
+
//# sourceMappingURL=chunk-OMETOKM7.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils/tree.ts"],"names":[],"mappings":";;;AAKO,SAAS,UAAA,GAA4B;AAC1C,EAAA,OAAO;A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A,GAAQ,KAAA;AACb,EAAA,KAAA,MAAW,KAAA,IAAS,KAAK,QAAA,EAAU;AACjC,IAAA,eAAA,CAAgB,KAAA,EAAO,QAAQ,CAAC,CAAA;AAAA,EAClC;AACF","file":"chunk-OMETOKM7.cjs","sourcesContent":["import type { ComponentTree, TreeNode, ComponentMetrics } from '../types'\n\n/**\n * Create an empty component tree.\n */\nexport function createTree(): ComponentTree {\n return {\n root: null,\n nodeMap: new Map(),\n }\n}\n\n/**\n * Create a new tree node.\n */\nexport function createNode(\n id: string,\n name: string,\n metrics: ComponentMetrics | null = null,\n depth = 0\n): TreeNode {\n return {\n id,\n name,\n children: [],\n metrics,\n depth,\n isExpanded: true,\n }\n}\n\n/**\n * Add a child node to a parent node.\n */\nexport function addChild(parent: TreeNode, child: TreeNode): void {\n // Check if child already exists\n const existingIndex = parent.children.findIndex((c) => c.id === child.id)\n if (existingIndex !== -1) {\n // Replace existing\n parent.children[existingIndex] = child\n } else {\n parent.children.push(child)\n }\n child.depth = parent.depth + 1\n}\n\n/**\n * Remove a node from the tree.\n */\nexport function removeNode(tree: ComponentTree, nodeId: string): boolean {\n const node = tree.nodeMap.get(nodeId)\n if (!node) {\n return false\n }\n\n // Remove from parent's children\n for (const potentialParent of tree.nodeMap.values()) {\n const childIndex = potentialParent.children.findIndex((c) => c.id === nodeId)\n if (childIndex !== -1) {\n potentialParent.children.splice(childIndex, 1)\n break\n }\n }\n\n // If this was the root, clear it\n if (tree.root?.id === nodeId) {\n tree.root = null\n }\n\n // Remove all descendants from nodeMap\n const removeDescendants = (n: TreeNode) => {\n tree.nodeMap.delete(n.id)\n for (const child of n.children) {\n removeDescendants(child)\n }\n }\n removeDescendants(node)\n\n return true\n}\n\n/**\n * Find a node by ID.\n */\nexport function findNode(tree: ComponentTree, nodeId: string): TreeNode | undefined {\n return tree.nodeMap.get(nodeId)\n}\n\n/**\n * Update a node's metrics.\n */\nexport function updateNodeMetrics(tree: ComponentTree, nodeId: string, metrics: ComponentMetrics): boolean {\n const node = tree.nodeMap.get(nodeId)\n if (!node) {\n return false\n }\n node.metrics = metrics\n return true\n}\n\n/**\n * Traverse the tree depth-first (pre-order).\n */\nexport function traverseDepthFirst(\n tree: ComponentTree,\n callback: (node: TreeNode, depth: number) => void | boolean\n): void {\n if (!tree.root) {\n return\n }\n\n const traverse = (node: TreeNode, depth: number): boolean => {\n const result = callback(node, depth)\n if (result === false) {\n return false\n }\n\n for (const child of node.children) {\n if (traverse(child, depth + 1) === false) {\n return false\n }\n }\n return true\n }\n\n traverse(tree.root, 0)\n}\n\n/**\n * Traverse the tree breadth-first.\n */\nexport function traverseBreadthFirst(\n tree: ComponentTree,\n callback: (node: TreeNode, depth: number) => void | boolean\n): void {\n if (!tree.root) {\n return\n }\n\n const queue: Array<{ node: TreeNode; depth: number }> = [{ node: tree.root, depth: 0 }]\n\n while (queue.length > 0) {\n const item = queue.shift()!\n const result = callback(item.node, item.depth)\n\n if (result === false) {\n break\n }\n\n for (const child of item.node.children) {\n queue.push({ node: child, depth: item.depth + 1 })\n }\n }\n}\n\n/**\n * Get all ancestors of a node (from parent to root).\n */\nexport function getAncestors(tree: ComponentTree, nodeId: string): TreeNode[] {\n const ancestors: TreeNode[] = []\n const targetNode = tree.nodeMap.get(nodeId)\n\n if (!targetNode) {\n return ancestors\n }\n\n // Find parent by searching all nodes\n const findParent = (targetId: string): TreeNode | null => {\n for (const node of tree.nodeMap.values()) {\n if (node.children.some((c) => c.id === targetId)) {\n return node\n }\n }\n return null\n }\n\n let currentId = nodeId\n let parent = findParent(currentId)\n\n while (parent) {\n ancestors.push(parent)\n currentId = parent.id\n parent = findParent(currentId)\n }\n\n return ancestors\n}\n\n/**\n * Get all descendants of a node.\n */\nexport function getDescendants(tree: ComponentTree, nodeId: string): TreeNode[] {\n const descendants: TreeNode[] = []\n const node = tree.nodeMap.get(nodeId)\n\n if (!node) {\n return descendants\n }\n\n const collect = (n: TreeNode) => {\n for (const child of n.children) {\n descendants.push(child)\n collect(child)\n }\n }\n\n collect(node)\n return descendants\n}\n\n/**\n * Flatten the tree into an array (depth-first order).\n */\nexport function flattenTree(tree: ComponentTree): TreeNode[] {\n const nodes: TreeNode[] = []\n\n traverseDepthFirst(tree, (node) => {\n nodes.push(node)\n })\n\n return nodes\n}\n\n/**\n * Get the depth of a node.\n */\nexport function getNodeDepth(tree: ComponentTree, nodeId: string): number {\n const node = tree.nodeMap.get(nodeId)\n if (!node) {\n return -1\n }\n return node.depth\n}\n\n/**\n * Check if a node is an ancestor of another node.\n */\nexport function isAncestor(tree: ComponentTree, ancestorId: string, descendantId: string): boolean {\n const ancestors = getAncestors(tree, descendantId)\n return ancestors.some((a) => a.id === ancestorId)\n}\n\n/**\n * Get the path from root to a node.\n */\nexport function getPath(tree: ComponentTree, nodeId: string): TreeNode[] {\n const ancestors = getAncestors(tree, nodeId)\n const node = tree.nodeMap.get(nodeId)\n\n if (!node) {\n return []\n }\n\n return [...ancestors.reverse(), node]\n}\n\n/**\n * Count total nodes in the tree.\n */\nexport function countNodes(tree: ComponentTree): number {\n return tree.nodeMap.size\n}\n\n/**\n * Get maximum depth of the tree.\n */\nexport function getMaxDepth(tree: ComponentTree): number {\n let maxDepth = -1\n\n traverseDepthFirst(tree, (_node, depth) => {\n if (depth > maxDepth) {\n maxDepth = depth\n }\n })\n\n return maxDepth\n}\n\n/**\n * Toggle node expansion state.\n */\nexport function toggleNode(tree: ComponentTree, nodeId: string): boolean {\n const node = tree.nodeMap.get(nodeId)\n if (!node) {\n return false\n }\n node.isExpanded = !node.isExpanded\n return true\n}\n\n/**\n * Expand all nodes.\n */\nexport function expandAll(tree: ComponentTree): void {\n for (const node of tree.nodeMap.values()) {\n node.isExpanded = true\n }\n}\n\n/**\n * Collapse all nodes.\n */\nexport function collapseAll(tree: ComponentTree): void {\n for (const node of tree.nodeMap.values()) {\n node.isExpanded = false\n }\n}\n\n/**\n * Filter tree nodes by a predicate.\n */\nexport function filterTree(\n tree: ComponentTree,\n predicate: (node: TreeNode) => boolean\n): TreeNode[] {\n const matching: TreeNode[] = []\n\n for (const node of tree.nodeMap.values()) {\n if (predicate(node)) {\n matching.push(node)\n }\n }\n\n return matching\n}\n\n/**\n * Search tree nodes by name (case-insensitive).\n */\nexport function searchTree(tree: ComponentTree, query: string): TreeNode[] {\n const lowerQuery = query.toLowerCase()\n\n return filterTree(tree, (node) => node.name.toLowerCase().includes(lowerQuery))\n}\n\n/**\n * Get every top-level node: nodes that are not a child of another node.\n * A tree can have several of them (e.g. sibling `<Scope>`s directly under the provider).\n */\nexport function getRootNodes(tree: ComponentTree): TreeNode[] {\n const childIds = new Set<string>()\n for (const node of tree.nodeMap.values()) {\n for (const child of node.children) {\n childIds.add(child.id)\n }\n }\n const roots: TreeNode[] = []\n for (const node of tree.nodeMap.values()) {\n if (!childIds.has(node.id)) {\n roots.push(node)\n }\n }\n return roots\n}\n\n/**\n * Set the depth of a node and recompute the depth of all its descendants.\n */\nexport function setSubtreeDepth(node: TreeNode, depth: number): void {\n node.depth = depth\n for (const child of node.children) {\n setSubtreeDepth(child, depth + 1)\n }\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/kernel/retention.ts
|
|
2
|
+
function retentionLimit(kernel) {
|
|
3
|
+
const size = kernel.getOptions().maxHistorySize;
|
|
4
|
+
return typeof size === "number" && size >= 1 ? Math.floor(size) : 1e3;
|
|
5
|
+
}
|
|
6
|
+
function pruneComponentMap(map, kernel) {
|
|
7
|
+
if (!kernel) return;
|
|
8
|
+
const limit = retentionLimit(kernel);
|
|
9
|
+
if (map.size <= limit) return;
|
|
10
|
+
const store = kernel.getMetrics();
|
|
11
|
+
for (const id of Array.from(map.keys())) {
|
|
12
|
+
if (map.size <= limit) break;
|
|
13
|
+
if (!store.get(id)) {
|
|
14
|
+
map.delete(id);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { pruneComponentMap, retentionLimit };
|
|
20
|
+
//# sourceMappingURL=chunk-QT2GSPHP.js.map
|
|
21
|
+
//# sourceMappingURL=chunk-QT2GSPHP.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/kernel/retention.ts"],"names":[],"mappings":";AAMO,SAAS,eAAe,MAAA,EAAwB;AACrD,EAAA,MAAM,IAAA,GAAO,MAAA,CAAO,UAAA,EAAW,CAAE,cAAA;AACjC,EAAA,OAAO,OAAO,SAAS,QAAA,IAAY,IAAA,IAAQ,IAAI,IAAA,CAAK,KAAA,CAAM,IAAI,CAAA,GAAI,GAAA;AACpE;AAMO,SAAS,iBAAA,CAAkB,KAA2B,MAAA,EAA6B;AACxF,EAAA,IAAI,CAAC,MAAA,EAAQ;AACb,EAAA,MAAM,KAAA,GAAQ,eAAe,MAAM,CAAA;AACnC,EAAA,IAAI,GAAA,CAAI,QAAQ,KAAA,EAAO;AACvB,EAAA,MAAM,KAAA,GAAQ,OAAO,UAAA,EAAW;AAChC,EAAA,KAAA,MAAW,MAAM,KAAA,CAAM,IAAA,CAAK,GAAA,CAAI,IAAA,EAAM,CAAA,EAAG;AACvC,IAAA,IAAI,GAAA,CAAI,QAAQ,KAAA,EAAO;AACvB,IAAA,IAAI,CAAC,KAAA,CAAM,GAAA,CAAI,EAAE,CAAA,EAAG;AAClB,MAAA,GAAA,CAAI,OAAO,EAAE,CAAA;AAAA,IACf;AAAA,EACF;AACF","file":"chunk-QT2GSPHP.js","sourcesContent":["import type { Kernel } from '../types'\n\n/**\n * How many entries a history buffer (and how many unmounted components) a kernel\n * keeps: its `maxHistorySize` option, 1000 by default.\n */\nexport function retentionLimit(kernel: Kernel): number {\n const size = kernel.getOptions().maxHistorySize\n return typeof size === 'number' && size >= 1 ? Math.floor(size) : 1000\n}\n\n/**\n * Drop per-component plugin data for components the metrics store no longer\n * holds, once the map grows past the kernel's retention limit.\n */\nexport function pruneComponentMap(map: Map<string, unknown>, kernel: Kernel | null): void {\n if (!kernel) return\n const limit = retentionLimit(kernel)\n if (map.size <= limit) return\n const store = kernel.getMetrics()\n for (const id of Array.from(map.keys())) {\n if (map.size <= limit) break\n if (!store.get(id)) {\n map.delete(id)\n }\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkKRRXA4SI_cjs = require('./chunk-KRRXA4SI.cjs');
|
|
4
4
|
|
|
5
5
|
// src/plugins/network-correlator/network-correlator.ts
|
|
6
6
|
var NetworkCorrelatorPlugin = class {
|
|
@@ -93,15 +93,14 @@ var NetworkCorrelatorPlugin = class {
|
|
|
93
93
|
if (entry.name.startsWith("data:") || entry.name.startsWith("chrome-extension:")) {
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
|
+
const status = entry.responseStatus;
|
|
96
97
|
const request = {
|
|
97
|
-
id:
|
|
98
|
+
id: chunkKRRXA4SI_cjs.uid(),
|
|
98
99
|
url: entry.name,
|
|
99
100
|
method: "GET",
|
|
100
|
-
// PerformanceResourceTiming doesn't expose method
|
|
101
101
|
startTime: entry.startTime,
|
|
102
102
|
endTime: entry.responseEnd,
|
|
103
|
-
status:
|
|
104
|
-
// PerformanceResourceTiming doesn't expose status
|
|
103
|
+
status: typeof status === "number" ? status : 0,
|
|
105
104
|
size: entry.transferSize || 0
|
|
106
105
|
};
|
|
107
106
|
this.requests.push(request);
|
|
@@ -115,25 +114,48 @@ var NetworkCorrelatorPlugin = class {
|
|
|
115
114
|
if (this.renderEvents.length > this.maxHistorySize) {
|
|
116
115
|
this.renderEvents = this.renderEvents.slice(-this.maxHistorySize);
|
|
117
116
|
}
|
|
117
|
+
const renderTime = this.toPerformanceTime(event.timestamp);
|
|
118
|
+
const from = Math.max(0, this.requests.length - 200);
|
|
119
|
+
for (let i = this.requests.length - 1; i >= from; i--) {
|
|
120
|
+
const request = this.requests[i];
|
|
121
|
+
if (this.isInWindow(request, renderTime)) {
|
|
122
|
+
this.addCorrelation(request, [event]);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/** Render events carry `Date.now()` timestamps; requests use `performance.now()` time. */
|
|
127
|
+
toPerformanceTime(timestamp) {
|
|
128
|
+
const origin = typeof performance !== "undefined" ? performance.timeOrigin : 0;
|
|
129
|
+
return timestamp - origin;
|
|
130
|
+
}
|
|
131
|
+
isInWindow(request, renderTime) {
|
|
132
|
+
return renderTime >= request.endTime && renderTime <= request.endTime + this.correlationWindow;
|
|
118
133
|
}
|
|
119
134
|
findCorrelations(request) {
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const correlatedRenders = this.renderEvents.filter((render) => {
|
|
124
|
-
const renderTime = render.timestamp - performance.timeOrigin;
|
|
125
|
-
return renderTime >= windowStart && renderTime <= windowEnd;
|
|
126
|
-
});
|
|
135
|
+
const correlatedRenders = this.renderEvents.filter(
|
|
136
|
+
(render) => this.isInWindow(request, this.toPerformanceTime(render.timestamp))
|
|
137
|
+
);
|
|
127
138
|
if (correlatedRenders.length > 0) {
|
|
128
|
-
this.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
139
|
+
this.addCorrelation(request, correlatedRenders);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
addCorrelation(request, renders) {
|
|
143
|
+
let correlation = this.correlations.find((c) => c.request.id === request.id);
|
|
144
|
+
if (!correlation) {
|
|
145
|
+
correlation = { request, renders: [], timeGap: 0 };
|
|
146
|
+
this.correlations.push(correlation);
|
|
133
147
|
if (this.correlations.length > this.maxHistorySize) {
|
|
134
148
|
this.correlations = this.correlations.slice(-this.maxHistorySize);
|
|
135
149
|
}
|
|
136
150
|
}
|
|
151
|
+
for (const render of renders) {
|
|
152
|
+
if (!correlation.renders.includes(render)) {
|
|
153
|
+
correlation.renders.push(render);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
correlation.renders.sort((a, b) => a.timestamp - b.timestamp);
|
|
157
|
+
const first = correlation.renders[0];
|
|
158
|
+
correlation.timeGap = first ? this.toPerformanceTime(first.timestamp) - request.endTime : 0;
|
|
137
159
|
}
|
|
138
160
|
getRequestsForComponent(componentId) {
|
|
139
161
|
const componentRequests = [];
|
|
@@ -169,5 +191,5 @@ function createNetworkCorrelatorPlugin() {
|
|
|
169
191
|
|
|
170
192
|
exports.NetworkCorrelatorPlugin = NetworkCorrelatorPlugin;
|
|
171
193
|
exports.createNetworkCorrelatorPlugin = createNetworkCorrelatorPlugin;
|
|
172
|
-
//# sourceMappingURL=chunk-
|
|
173
|
-
//# sourceMappingURL=chunk-
|
|
194
|
+
//# sourceMappingURL=chunk-U3TL6KFZ.cjs.map
|
|
195
|
+
//# sourceMappingURL=chunk-U3TL6KFZ.cjs.map
|