1- import type { ModuleInfo , RolldownResolveInfo } from '../../../shared/types'
1+ import type { ModuleInfo } from '../../../shared/types'
22import { defineRpcFunction } from '../utils'
33
4- const DURATION_THRESHOLD = 10
5-
64export const rolldownGetModuleInfo = defineRpcFunction ( {
75 name : 'vite:rolldown:get-module-info' ,
86 type : 'query' ,
@@ -15,79 +13,24 @@ export const rolldownGetModuleInfo = defineRpcFunction({
1513 if ( ! events . length )
1614 return null
1715
16+ const moduleInfo = reader . manager . modules . get ( module )
17+
1818 const info : Omit < ModuleInfo , 'transforms' > = {
1919 id : module ,
20- loads : [ ] ,
2120 imports : [ ] ,
2221 importers : [ ] ,
23- resolve_ids : [ ] ,
2422 chunks : [ ] ,
2523 assets : [ ] ,
2624 build_metrics : {
2725 resolve_ids : [ ] ,
2826 loads : [ ] ,
2927 transforms : [ ] ,
3028 } ,
31- ...reader . manager . modules . get ( module ) || { } ,
29+ ...moduleInfo || { } ,
30+ loads : moduleInfo ?. build_metrics ?. loads ?? [ ] ,
31+ resolve_ids : moduleInfo ?. build_metrics ?. resolve_ids ?? [ ] ,
3232 }
3333
34- events . forEach ( ( start , index ) => {
35- if ( start . action !== 'HookLoadCallStart' || start . module_id !== module )
36- return
37-
38- const end = events . find ( e => e . action === 'HookLoadCallEnd' && e . call_id === start . call_id , index )
39- if ( ! end || end . action !== 'HookLoadCallEnd' ) {
40- console . error ( `[rolldown] Load call end not found for ${ start . call_id } ` )
41- return
42- }
43- const duration = + end . timestamp - + start . timestamp
44- if ( ! end . content && duration < DURATION_THRESHOLD )
45- return
46-
47- info . loads . push ( {
48- type : 'load' ,
49- id : start . event_id ,
50- plugin_name : start . plugin_name ,
51- plugin_id : start . plugin_id ,
52- content : end . content ,
53- timestamp_start : + start . timestamp ,
54- timestamp_end : + end . timestamp ,
55- duration,
56- } )
57- } )
58-
59- events . forEach ( ( end ) => {
60- if ( end . action !== 'HookResolveIdCallEnd' || end . resolved_id !== module )
61- return
62- const start = events . find ( e => e . action === 'HookResolveIdCallStart' && e . call_id === end . call_id )
63- if ( ! start || start . action !== 'HookResolveIdCallStart' ) {
64- console . error ( `[rolldown] resolveId call start not found for ${ end . event_id } ` )
65- return
66- }
67-
68- const duration = + end . timestamp - + start . timestamp
69- const data : RolldownResolveInfo = {
70- type : 'resolve' ,
71- id : end . event_id ,
72- importer : start . importer ,
73- module_request : start . module_request ,
74- import_kind : start . import_kind ,
75- plugin_name : end . plugin_name ,
76- plugin_id : end . plugin_id ,
77- resolved_id : end . resolved_id ,
78- timestamp_start : + start . timestamp ,
79- timestamp_end : + end . timestamp ,
80- duration,
81- }
82-
83- // In Rolldown, resolveId might be called multiple times with different threads of Rust
84- // If that happens, we only keep the last one
85- const existingIndex = info . resolve_ids . findIndex ( r => r . importer === start . importer && r . module_request === start . module_request && r . import_kind === start . import_kind && r . plugin_id === end . plugin_id )
86- if ( existingIndex >= 0 )
87- info . resolve_ids . splice ( existingIndex , 1 )
88- info . resolve_ids . push ( data )
89- } )
90-
9134 info . chunks = Array . from ( reader . manager . chunks . values ( ) )
9235 . filter ( chunk => chunk . modules . includes ( module ) )
9336 . map ( chunk => ( {
0 commit comments