@@ -62,7 +62,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
6262 const includeClient = args ?. includeInProd ?. client ?? false
6363 const includeServer = args ?. includeInProd ?. server ?? false
6464 const includeDevtools = args ?. includeInProd ?. devTools ?? false
65-
65+ let port = 5173
6666 let routes : Route [ ] = [ ]
6767 let flatRoutes : Route [ ] = [ ]
6868 const appDir = args ?. appDir || "./app"
@@ -237,13 +237,23 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
237237 }
238238 server . httpServer ?. on ( "listening" , ( ) => {
239239 process . rdt_port = server . config . server . port ?? 5173
240+ port = process . rdt_port
240241 } )
241242 //@ts -ignore - vite 5/6 compat
242243 const channel = server . hot . channels . find ( ( channel ) => channel . name === "ws" ) ?? server . environments ?. client . hot
243-
244+ const editor = args ?. editor ?? DEFAULT_EDITOR_CONFIG
245+ const openInEditor = async ( path : string | undefined , lineNum : string | undefined ) => {
246+ if ( ! path ) {
247+ return
248+ }
249+ editor . open ( path , lineNum )
250+ }
244251 server . middlewares . use ( ( req , res , next ) =>
245252 handleDevToolsViteRequest ( req , res , next , ( parsedData ) => {
246253 const { type, data, routine } = parsedData
254+ if ( routine === "open-source" ) {
255+ return handleOpenSource ( { data : { type : data . type , data } , openInEditor, appDir } )
256+ }
247257 if ( routine === "request-event" ) {
248258 unusedEvents . set ( parsedData . id + parsedData . startTime , parsedData )
249259 for ( const client of server . hot . channels ) {
@@ -295,7 +305,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
295305 } )
296306
297307 if ( ! server . config . isProduction ) {
298- channel ?. on ( "remove-event" , ( data , client ) => {
308+ channel ?. on ( "remove-event" , ( data ) => {
299309 const parsedData = data
300310 const { id, startTime } = parsedData
301311
@@ -319,13 +329,6 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
319329 } )
320330 )
321331 } )
322- const editor = args ?. editor ?? DEFAULT_EDITOR_CONFIG
323- const openInEditor = async ( path : string | undefined , lineNum : string | undefined ) => {
324- if ( ! path ) {
325- return
326- }
327- editor . open ( path , lineNum )
328- }
329332
330333 server . hot . on ( "open-source" , ( data : OpenSourceData ) => handleOpenSource ( { data, openInEditor, appDir } ) )
331334 server . hot . on ( "add-route" , ( data : WriteFileData ) => handleWriteFile ( { ...data , openInEditor } ) )
@@ -362,7 +365,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
362365 }
363366
364367 const column = line . indexOf ( "console." )
365- const logMessage = `" ${ chalk . magenta ( "LOG" ) } ${ chalk . blueBright ( `${ id . replace ( normalizePath ( process . cwd ( ) ) , "" ) } : ${ lineNumber + 1 } : ${ column + 1 } ` ) } \\n → " `
368+ const logMessage = `' ${ chalk . magenta ( "LOG" ) } ${ chalk . blueBright ( `http://localhost: ${ port } /open-source?source= ${ id . replace ( normalizePath ( process . cwd ( ) ) , "" ) } &line= ${ lineNumber + 1 } &column= ${ column + 1 } ` ) } \\n → ' `
366369 if ( line . includes ( "console.log(" ) ) {
367370 const newLine = `console.log(${ logMessage } ,`
368371 return line . replace ( "console.log(" , newLine )
0 commit comments