@react-devtools-plus/scan 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +23 -0
- package/.turbo/turbo-prepare$colon$type.log +6 -0
- package/LICENSE +21 -0
- package/README.md +172 -0
- package/dist/index.cjs +18394 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +304 -0
- package/dist/index.d.ts +304 -0
- package/dist/index.js +18350 -0
- package/dist/index.js.map +1 -0
- package/package.json +50 -0
- package/src/adapter.ts +1257 -0
- package/src/index.ts +134 -0
- package/src/plugin.ts +638 -0
- package/src/types.ts +271 -0
- package/tsconfig.json +9 -0
- package/tsup.config.ts +22 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for React DevTools Scan integration
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import type { Options as ReactScanOptions } from 'react-scan'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Integration modes for React Scan
|
|
9
|
+
*/
|
|
10
|
+
export type IntegrationMode = 'overlay' | 'panel' | 'both'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Extended options for React DevTools Scan integration
|
|
14
|
+
*/
|
|
15
|
+
export interface ReactDevtoolsScanOptions extends ReactScanOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Integration mode - how scan should be displayed
|
|
18
|
+
* - 'overlay': Show as overlay on the page (default react-scan behavior)
|
|
19
|
+
* - 'panel': Integrate into DevTools panel
|
|
20
|
+
* - 'both': Show both overlay and panel integration
|
|
21
|
+
*
|
|
22
|
+
* @default 'overlay'
|
|
23
|
+
*/
|
|
24
|
+
integrationMode?: IntegrationMode
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Whether to sync state with DevTools panel
|
|
28
|
+
*
|
|
29
|
+
* @default true
|
|
30
|
+
*/
|
|
31
|
+
syncWithDevtools?: boolean
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Scan instance interface
|
|
36
|
+
*/
|
|
37
|
+
/**
|
|
38
|
+
* Performance metrics for a component
|
|
39
|
+
*/
|
|
40
|
+
export interface ComponentPerformanceData {
|
|
41
|
+
componentName: string
|
|
42
|
+
renderCount: number
|
|
43
|
+
totalTime: number
|
|
44
|
+
averageTime: number
|
|
45
|
+
unnecessaryRenders: number
|
|
46
|
+
lastRenderTime: number | null
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Aggregated performance summary
|
|
51
|
+
*/
|
|
52
|
+
export interface PerformanceSummary {
|
|
53
|
+
totalRenders: number
|
|
54
|
+
totalComponents: number
|
|
55
|
+
unnecessaryRenders: number
|
|
56
|
+
averageRenderTime: number
|
|
57
|
+
slowestComponents: ComponentPerformanceData[]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Component info for selection
|
|
62
|
+
*/
|
|
63
|
+
export interface ComponentInfo {
|
|
64
|
+
componentName: string
|
|
65
|
+
fiber: any // Fiber reference
|
|
66
|
+
domElement: Element | null
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Change info for a single prop/state/context value
|
|
71
|
+
*/
|
|
72
|
+
export interface ChangeInfo {
|
|
73
|
+
name: string
|
|
74
|
+
previousValue: any
|
|
75
|
+
currentValue: any
|
|
76
|
+
count: number
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Aggregated changes for a component render
|
|
81
|
+
*/
|
|
82
|
+
export interface AggregatedChanges {
|
|
83
|
+
propsChanges: ChangeInfo[]
|
|
84
|
+
stateChanges: ChangeInfo[]
|
|
85
|
+
contextChanges: ChangeInfo[]
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Focused component render info with changes
|
|
90
|
+
*/
|
|
91
|
+
export interface FocusedComponentRenderInfo {
|
|
92
|
+
componentName: string
|
|
93
|
+
renderCount: number
|
|
94
|
+
changes: AggregatedChanges
|
|
95
|
+
timestamp: number
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface ScanInstance {
|
|
99
|
+
/**
|
|
100
|
+
* Get current scan options
|
|
101
|
+
*/
|
|
102
|
+
getOptions: () => ReactDevtoolsScanOptions
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Update scan options at runtime
|
|
106
|
+
*/
|
|
107
|
+
setOptions: (options: Partial<ReactDevtoolsScanOptions>) => void
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Start scanning
|
|
111
|
+
*/
|
|
112
|
+
start: () => void
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Stop scanning
|
|
116
|
+
*/
|
|
117
|
+
stop: () => void
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Check if scanning is active
|
|
121
|
+
*/
|
|
122
|
+
isActive: () => boolean
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Hide the React Scan toolbar
|
|
126
|
+
*/
|
|
127
|
+
hideToolbar: () => void
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Show the React Scan toolbar
|
|
131
|
+
*/
|
|
132
|
+
showToolbar: () => void
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Get toolbar visibility state
|
|
136
|
+
*/
|
|
137
|
+
getToolbarVisibility: () => boolean
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Get performance data for all components
|
|
141
|
+
*/
|
|
142
|
+
getPerformanceData: () => ComponentPerformanceData[]
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Get aggregated performance summary
|
|
146
|
+
*/
|
|
147
|
+
getPerformanceSummary: () => PerformanceSummary
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Clear all performance data
|
|
151
|
+
*/
|
|
152
|
+
clearPerformanceData: () => void
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Start component inspection mode
|
|
156
|
+
*/
|
|
157
|
+
startInspecting: () => void
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Stop component inspection mode
|
|
161
|
+
*/
|
|
162
|
+
stopInspecting: () => void
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Check if inspection mode is active
|
|
166
|
+
*/
|
|
167
|
+
isInspecting: () => boolean
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Focus on a specific component by fiber
|
|
171
|
+
*/
|
|
172
|
+
focusComponent: (fiber: any) => void
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Get currently focused component
|
|
176
|
+
*/
|
|
177
|
+
getFocusedComponent: () => ComponentInfo | null
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Subscribe to inspection state changes
|
|
181
|
+
*/
|
|
182
|
+
onInspectStateChange: (callback: (state: any) => void) => () => void
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Get current FPS
|
|
186
|
+
*/
|
|
187
|
+
getFPS: () => number
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Get focused component render info with changes
|
|
191
|
+
*/
|
|
192
|
+
getFocusedComponentRenderInfo: () => FocusedComponentRenderInfo | null
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Subscribe to focused component changes (re-renders)
|
|
196
|
+
*/
|
|
197
|
+
onFocusedComponentChange: (callback: (info: FocusedComponentRenderInfo) => void) => () => void
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Clear the focused component's change history
|
|
201
|
+
*/
|
|
202
|
+
clearFocusedComponentChanges: () => void
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Set the focused component by name for render tracking
|
|
206
|
+
* This is used when inspectState.kind is not 'focused' but we still want to track renders
|
|
207
|
+
*/
|
|
208
|
+
setFocusedComponentByName: (componentName: string) => void
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Get the component tree with render counts
|
|
212
|
+
*/
|
|
213
|
+
getComponentTree: () => ComponentTreeNode[]
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Clear component render count tracking
|
|
217
|
+
*/
|
|
218
|
+
clearComponentTree: () => void
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Component render information
|
|
223
|
+
*/
|
|
224
|
+
export interface RenderInfo {
|
|
225
|
+
componentName: string
|
|
226
|
+
renderTime: number
|
|
227
|
+
timestamp: number
|
|
228
|
+
reason?: string
|
|
229
|
+
unnecessary?: boolean
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Component statistics
|
|
234
|
+
*/
|
|
235
|
+
export interface ComponentStats {
|
|
236
|
+
id: string
|
|
237
|
+
name: string
|
|
238
|
+
renderCount: number
|
|
239
|
+
totalTime: number
|
|
240
|
+
averageTime: number
|
|
241
|
+
lastRenderTime: number
|
|
242
|
+
renders: RenderInfo[]
|
|
243
|
+
unnecessary?: number
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Component tree node
|
|
248
|
+
*/
|
|
249
|
+
export interface ComponentTreeNode {
|
|
250
|
+
id: string
|
|
251
|
+
name: string
|
|
252
|
+
type: string
|
|
253
|
+
renderCount: number
|
|
254
|
+
lastRenderTime: number
|
|
255
|
+
averageTime?: number
|
|
256
|
+
unnecessary?: number
|
|
257
|
+
children: ComponentTreeNode[]
|
|
258
|
+
fiber?: any
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Performance data aggregation
|
|
263
|
+
*/
|
|
264
|
+
export interface PerformanceData {
|
|
265
|
+
components: Map<string, ComponentStats>
|
|
266
|
+
totalRenders: number
|
|
267
|
+
averageRenderTime: number
|
|
268
|
+
slowestComponents: ComponentStats[]
|
|
269
|
+
mostRenderedComponents: ComponentStats[]
|
|
270
|
+
timestamp: number
|
|
271
|
+
}
|
package/tsconfig.json
ADDED
package/tsup.config.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { defineConfig } from 'tsup'
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
entry: {
|
|
5
|
+
index: 'src/index.ts',
|
|
6
|
+
},
|
|
7
|
+
format: ['esm', 'cjs'],
|
|
8
|
+
// Use es2017 for maximum compatibility with Webpack 4
|
|
9
|
+
// Node 14+ and modern browsers support ES2017
|
|
10
|
+
target: 'es2017',
|
|
11
|
+
dts: {
|
|
12
|
+
resolve: true,
|
|
13
|
+
},
|
|
14
|
+
outDir: 'dist',
|
|
15
|
+
clean: true,
|
|
16
|
+
shims: true,
|
|
17
|
+
splitting: false,
|
|
18
|
+
sourcemap: true,
|
|
19
|
+
external: ['react', 'react-dom'],
|
|
20
|
+
noExternal: ['react-scan'],
|
|
21
|
+
skipNodeModulesBundle: false,
|
|
22
|
+
})
|