@@ -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"
@@ -235,15 +235,30 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
235235 if ( server . config . appType !== "custom" ) {
236236 return
237237 }
238+ if ( server . config . server . port ) {
239+ process . rdt_port = server . config . server . port ?? 5173
240+ port = process . rdt_port
241+ }
242+
238243 server . httpServer ?. on ( "listening" , ( ) => {
239244 process . rdt_port = server . config . server . port ?? 5173
245+ port = process . rdt_port
240246 } )
241247 //@ts -ignore - vite 5/6 compat
242248 const channel = server . hot . channels . find ( ( channel ) => channel . name === "ws" ) ?? server . environments ?. client . hot
243-
249+ const editor = args ?. editor ?? DEFAULT_EDITOR_CONFIG
250+ const openInEditor = async ( path : string | undefined , lineNum : string | undefined ) => {
251+ if ( ! path ) {
252+ return
253+ }
254+ editor . open ( path , lineNum )
255+ }
244256 server . middlewares . use ( ( req , res , next ) =>
245257 handleDevToolsViteRequest ( req , res , next , ( parsedData ) => {
246258 const { type, data, routine } = parsedData
259+ if ( routine === "open-source" ) {
260+ return handleOpenSource ( { data : { type : data . type , data } , openInEditor, appDir } )
261+ }
247262 if ( routine === "request-event" ) {
248263 unusedEvents . set ( parsedData . id + parsedData . startTime , parsedData )
249264 for ( const client of server . hot . channels ) {
@@ -295,7 +310,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
295310 } )
296311
297312 if ( ! server . config . isProduction ) {
298- channel ?. on ( "remove-event" , ( data , client ) => {
313+ channel ?. on ( "remove-event" , ( data ) => {
299314 const parsedData = data
300315 const { id, startTime } = parsedData
301316
@@ -319,13 +334,6 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
319334 } )
320335 )
321336 } )
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- }
329337
330338 server . hot . on ( "open-source" , ( data : OpenSourceData ) => handleOpenSource ( { data, openInEditor, appDir } ) )
331339 server . hot . on ( "add-route" , ( data : WriteFileData ) => handleWriteFile ( { ...data , openInEditor } ) )
@@ -362,7 +370,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
362370 }
363371
364372 const column = line . indexOf ( "console." )
365- const logMessage = `" ${ chalk . magenta ( "LOG" ) } ${ chalk . blueBright ( `${ id . replace ( normalizePath ( process . cwd ( ) ) , "" ) } : ${ lineNumber + 1 } : ${ column + 1 } ` ) } \\n → " `
373+ const logMessage = `' ${ chalk . magenta ( "LOG" ) } ${ chalk . blueBright ( `http://localhost: ${ port } /open-source?source= ${ encodeURIComponent ( id . replace ( normalizePath ( process . cwd ( ) ) , "" ) ) } &line= ${ lineNumber + 1 } &column= ${ column + 1 } ` ) } \\n → ' `
366374 if ( line . includes ( "console.log(" ) ) {
367375 const newLine = `console.log(${ logMessage } ,`
368376 return line . replace ( "console.log(" , newLine )
0 commit comments