@@ -2,6 +2,7 @@ import type { FastifyInstance } from 'fastify';
22import fastifyPlugin from 'fastify-plugin' ;
33import launchEditor from 'launch-editor' ;
44import open from 'open' ;
5+ import { parseSourceFilename } from '../../utils/parseSourceFilename.js' ;
56
67interface OpenURLRequestBody {
78 url : string ;
@@ -18,7 +19,10 @@ function parseRequestBody<T>(body: unknown): T {
1819 throw new Error ( `Unsupported body type: ${ typeof body } ` ) ;
1920}
2021
21- async function devtoolsPlugin ( instance : FastifyInstance ) {
22+ async function devtoolsPlugin (
23+ instance : FastifyInstance ,
24+ { rootDir } : { rootDir : string }
25+ ) {
2226 // reference implementation in `@react-native-community/cli-server-api`:
2327 // https://github.com/react-native-community/cli/blob/46436a12478464752999d34ed86adf3212348007/packages/cli-server-api/src/openURLMiddleware.ts
2428 instance . route ( {
@@ -37,11 +41,9 @@ async function devtoolsPlugin(instance: FastifyInstance) {
3741 method : [ 'POST' ] ,
3842 url : '/open-stack-frame' ,
3943 handler : async ( request , reply ) => {
40- const { file, lineNumber } = parseRequestBody < OpenStackFrameRequestBody > (
41- request . body
42- ) ;
43- // TODO fix rewriting of `webpack://` to rootDir of the project
44- launchEditor ( `${ file } :${ lineNumber } ` , process . env . REACT_EDITOR ) ;
44+ const body = parseRequestBody < OpenStackFrameRequestBody > ( request . body ) ;
45+ const filepath = parseSourceFilename ( body . file , rootDir ) ;
46+ launchEditor ( `${ filepath } :${ body . lineNumber } ` , process . env . REACT_EDITOR ) ;
4547 reply . send ( 'OK' ) ;
4648 } ,
4749 } ) ;
0 commit comments