@@ -38,51 +38,33 @@ export let findProjectRootOfFile = (
3838 }
3939} ;
4040
41- export let findBscBinaryFromProjectRoot = (
42- source : p . DocumentUri
43- ) : null | p . DocumentUri => {
44- let dir = path . dirname ( source ) ;
45- // The rescript package's rescript command is a JS wrapper. `rescript format`
46- // also invokes another JS wrapper. _That_ JS wrapper ultimately calls the
47- // (unexposed) bsc -format anyway.
48- let bscNativeReScriptPath = path . join ( dir , c . bscNativeReScriptPartialPath ) ;
49-
50- if ( fs . existsSync ( bscNativeReScriptPath ) ) {
51- return bscNativeReScriptPath ;
52- } else if ( dir === source ) {
53- // reached the top
41+ export let findBinary = (
42+ binaryDirPath : p . DocumentUri | null ,
43+ binaryName : string
44+ ) : p . DocumentUri | null => {
45+ if ( binaryDirPath == null ) {
5446 return null ;
47+ }
48+ let binaryPath : p . DocumentUri = path . join ( binaryDirPath , binaryName ) ;
49+ if ( fs . existsSync ( binaryPath ) ) {
50+ return binaryPath ;
5551 } else {
56- return findBscBinaryFromProjectRoot ( dir ) ;
52+ return null ;
5753 }
5854} ;
5955
60- export let findBscBinaryFromConfig = (
61- pathToBinaryDirFromConfig : p . DocumentUri
62- ) : null | p . DocumentUri => {
63- let bscPath = path . join ( pathToBinaryDirFromConfig , c . bscBinName ) ;
64- if ( fs . existsSync ( bscPath ) ) {
65- return bscPath ;
66- }
67- return null ;
56+ export let findRescriptBinary = (
57+ binaryDirPath : p . DocumentUri | string
58+ ) : p . DocumentUri | null => {
59+ return findBinary ( binaryDirPath , c . rescriptBinName ) ;
6860} ;
6961
70- let findBuildBinaryBase = ( rescriptPath : string ) : string | null => {
71- if ( fs . existsSync ( rescriptPath ) ) {
72- return rescriptPath ;
73- }
74- return null ;
62+ export let findBscBinary = (
63+ binaryDirPath : p . DocumentUri | string
64+ ) : p . DocumentUri | null => {
65+ return findBinary ( binaryDirPath , c . bscBinName ) ;
7566} ;
7667
77- export let findRescriptBinaryFromConfig = (
78- pathToBinaryDirFromConfig : p . DocumentUri
79- ) =>
80- findBuildBinaryBase ( path . join ( pathToBinaryDirFromConfig , c . rescriptBinName ) ) ;
81-
82- export let findRescriptBinaryFromProjectRoot = (
83- projectRootPath : p . DocumentUri
84- ) => findBuildBinaryBase ( path . join ( projectRootPath , c . rescriptNodePartialPath ) ) ;
85-
8668type execResult =
8769 | {
8870 kind : "success" ;
0 commit comments