@@ -272,26 +272,19 @@ pub fn get_runtime_path(project_context: &ProjectContext) -> anyhow::Result<Path
272272 Ok ( canonicalized. to_stripped_verbatim_path ( ) )
273273}
274274
275- pub fn get_rescript_legacy ( project_context : & ProjectContext ) -> PathBuf {
275+ pub fn get_rescript_legacy_path ( project_context : & ProjectContext ) -> anyhow:: Result < PathBuf > {
276+ let resolver = Resolver :: new ( ResolveOptions :: default ( ) ) ;
276277 let root_path = project_context. get_root_path ( ) ;
277- let node_modules_rescript = root_path. join ( "node_modules" ) . join ( "rescript" ) ;
278- let rescript_legacy_path = if node_modules_rescript. exists ( ) {
279- node_modules_rescript
280- . join ( "cli" )
281- . join ( "rescript-legacy.js" )
282- . canonicalize ( )
283- . map ( StrippedVerbatimPath :: to_stripped_verbatim_path)
284- } else {
285- // If the root folder / node_modules doesn't exist, something is wrong.
286- // The only way this can happen is if we are inside the rescript repository.
287- root_path
288- . join ( "cli" )
289- . join ( "rescript-legacy.js" )
290- . canonicalize ( )
291- . map ( StrippedVerbatimPath :: to_stripped_verbatim_path)
292- } ;
293278
294- rescript_legacy_path. unwrap_or_else ( |_| panic ! ( "Could not find rescript-legacy.exe" ) )
279+ let rescript_resolved: oxc_resolver:: Resolution = resolver. resolve ( root_path, "rescript/package.json" ) ?;
280+ let rescript_package_json_path = rescript_resolved. full_path ( ) ;
281+ let rescript_path = rescript_package_json_path
282+ . parent ( )
283+ . ok_or_else ( || anyhow ! ( "Failed to get parent directory of rescript package.json" ) ) ?;
284+ let rescript_legacy_path = rescript_path. join ( "cli" ) . join ( "rescript-legacy.js" ) ;
285+
286+ let canonicalized = rescript_legacy_path. to_path_buf ( ) . canonicalize ( ) ?;
287+ Ok ( canonicalized. to_stripped_verbatim_path ( ) )
295288}
296289
297290pub fn string_ends_with_any ( s : & Path , suffixes : & [ & str ] ) -> bool {
0 commit comments