@@ -62,7 +62,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
62
62
const includeClient = args ?. includeInProd ?. client ?? false
63
63
const includeServer = args ?. includeInProd ?. server ?? false
64
64
const includeDevtools = args ?. includeInProd ?. devTools ?? false
65
-
65
+ let port = 5173
66
66
let routes : Route [ ] = [ ]
67
67
let flatRoutes : Route [ ] = [ ]
68
68
const appDir = args ?. appDir || "./app"
@@ -235,15 +235,30 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
235
235
if ( server . config . appType !== "custom" ) {
236
236
return
237
237
}
238
+ if ( server . config . server . port ) {
239
+ process . rdt_port = server . config . server . port ?? 5173
240
+ port = process . rdt_port
241
+ }
242
+
238
243
server . httpServer ?. on ( "listening" , ( ) => {
239
244
process . rdt_port = server . config . server . port ?? 5173
245
+ port = process . rdt_port
240
246
} )
241
247
//@ts -ignore - vite 5/6 compat
242
248
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
+ }
244
256
server . middlewares . use ( ( req , res , next ) =>
245
257
handleDevToolsViteRequest ( req , res , next , ( parsedData ) => {
246
258
const { type, data, routine } = parsedData
259
+ if ( routine === "open-source" ) {
260
+ return handleOpenSource ( { data : { type : data . type , data } , openInEditor, appDir } )
261
+ }
247
262
if ( routine === "request-event" ) {
248
263
unusedEvents . set ( parsedData . id + parsedData . startTime , parsedData )
249
264
for ( const client of server . hot . channels ) {
@@ -295,7 +310,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
295
310
} )
296
311
297
312
if ( ! server . config . isProduction ) {
298
- channel ?. on ( "remove-event" , ( data , client ) => {
313
+ channel ?. on ( "remove-event" , ( data ) => {
299
314
const parsedData = data
300
315
const { id, startTime } = parsedData
301
316
@@ -319,13 +334,6 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
319
334
} )
320
335
)
321
336
} )
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
- }
329
337
330
338
server . hot . on ( "open-source" , ( data : OpenSourceData ) => handleOpenSource ( { data, openInEditor, appDir } ) )
331
339
server . hot . on ( "add-route" , ( data : WriteFileData ) => handleWriteFile ( { ...data , openInEditor } ) )
@@ -362,7 +370,7 @@ export const reactRouterDevTools: (args?: ReactRouterViteConfig) => Plugin[] = (
362
370
}
363
371
364
372
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 → ' `
366
374
if ( line . includes ( "console.log(" ) ) {
367
375
const newLine = `console.log(${ logMessage } ,`
368
376
return line . replace ( "console.log(" , newLine )
0 commit comments