@@ -74,7 +74,41 @@ export function useRegistryScript<T extends Record<string | symbol, any>, O = Em
7474 const scriptInput = defu ( finalScriptInput , userOptions . scriptInput , { key : registryKey } ) as any as UseScriptInput
7575 const scriptOptions = Object . assign ( userOptions ?. scriptOptions || { } , options . scriptOptions || { } )
7676 if ( import . meta. dev ) {
77- scriptOptions . devtools = defu ( scriptOptions . devtools , { registryKey } )
77+ // Capture where the component was loaded from
78+ const error = new Error ( 'Stack trace for component location' )
79+ const stack = error . stack ?. split ( '\n' )
80+ const callerLine = stack ?. find ( line =>
81+ line . includes ( '.vue' )
82+ && ! line . includes ( 'useRegistryScript' )
83+ && ! line . includes ( 'node_modules' ) ,
84+ )
85+
86+ let loadedFrom = 'unknown'
87+ if ( callerLine ) {
88+ // Extract URL pattern like "https://localhost:3000/_nuxt/pages/features/custom-registry.vue?t=1758609859248:14:31"
89+ // Handle both with and without query parameters
90+ const urlMatch = callerLine . match ( / h t t p s ? : \/ \/ [ ^ / ] + \/ _ n u x t \/ ( .+ \. v u e ) (?: \? [ ^ ) ] * ) ? : ( \d + ) : ( \d + ) / )
91+ || callerLine . match ( / \( h t t p s ? : \/ \/ [ ^ / ] + \/ _ n u x t \/ ( .+ \. v u e ) (?: \? [ ^ ) ] * ) ? : ( \d + ) : ( \d + ) \) / )
92+
93+ if ( urlMatch ) {
94+ const [ , filePath , line , column ] = urlMatch
95+ loadedFrom = `./${ filePath } :${ line } :${ column } `
96+ }
97+ else {
98+ // Try to extract any .vue file path with line:column
99+ const vueMatch = callerLine . match ( / ( [ ^ / \s ] + \. v u e ) : ( \d + ) : ( \d + ) / )
100+ if ( vueMatch ) {
101+ const [ , fileName , line , column ] = vueMatch
102+ loadedFrom = `./${ fileName } :${ line } :${ column } `
103+ }
104+ else {
105+ // Fallback to original cleaning
106+ loadedFrom = callerLine . trim ( ) . replace ( / ^ \s * a t \s + / , '' )
107+ }
108+ }
109+ }
110+
111+ scriptOptions . devtools = defu ( scriptOptions . devtools , { registryKey, loadedFrom } )
78112 if ( options . schema ) {
79113 const registryMeta : Record < string , string > = { }
80114 for ( const k in options . schema . entries ) {
@@ -107,13 +141,3 @@ export function useRegistryScript<T extends Record<string | symbol, any>, O = Em
107141 }
108142 return useScript < T > ( scriptInput , scriptOptions as NuxtUseScriptOptions < T > )
109143}
110-
111- export function pick ( obj : Record < string , any > , keys : string [ ] ) {
112- const res : Record < string , any > = { }
113- for ( const k of keys ) {
114- if ( k in obj ) {
115- res [ k ] = obj [ k ]
116- }
117- }
118- return res
119- }
0 commit comments