@@ -76,27 +76,12 @@ export let findProjectRootOfFile = (
7676 }
7777} ;
7878
79- // Check if binaryName exists inside binaryDirPath and return the joined path.
80- export let findBinary = (
81- binaryDirPath : p . DocumentUri | null ,
82- binaryName : string
83- ) : p . DocumentUri | null => {
84- if ( binaryDirPath == null ) {
85- return null ;
86- }
87- let binaryPath : p . DocumentUri = path . join ( binaryDirPath , binaryName ) ;
88- if ( fs . existsSync ( binaryPath ) ) {
89- return binaryPath ;
90- } else {
91- return null ;
92- }
93- } ;
9479// If ReScript < 12.0.0-alpha.13, then we want `{project_root}/node_modules/rescript/{c.platformDir}/{binary}`.
9580// Otherwise, we want to dynamically import `{project_root}/node_modules/rescript` and from `binPaths` get the relevant binary.
9681// We won't know which version is in the project root until we read and parse `{project_root}/node_modules/rescript/package.json`
9782let findBinaryAsync = async (
9883 projectRootPath : p . DocumentUri | null ,
99- binary : "bsc.exe" | "rescript-editor-analysis.exe"
84+ binary : "bsc.exe" | "rescript-editor-analysis.exe" | "rescript"
10085) => {
10186 if ( config . extensionConfiguration . platformPath != null ) {
10287 return path . join ( config . extensionConfiguration . platformPath , binary ) ;
@@ -111,16 +96,22 @@ let findBinaryAsync = async (
11196 }
11297
11398 let rescriptVersion = null ;
99+ let rescriptJSWrapperPath = null
114100 try {
115101 const rescriptPackageJSONPath = path . join ( rescriptDir , "package.json" ) ;
116102 const rescriptPackageJSON = JSON . parse ( await fsAsync . readFile ( rescriptPackageJSONPath , "utf-8" ) ) ;
117103 rescriptVersion = rescriptPackageJSON . version
104+ rescriptJSWrapperPath = rescriptPackageJSON . bin . rescript
118105 } catch ( error ) {
119106 return null
120107 }
121108
122109 let binaryPath : string | null = null
123- if ( semver . gte ( rescriptVersion , "12.0.0-alpha.13" ) ) {
110+ if ( binary == "rescript" ) {
111+ // Can't use the native bsb/rescript since we might need the watcher -w
112+ // flag, which is only in the JS wrapper
113+ binaryPath = path . join ( rescriptDir , rescriptJSWrapperPath )
114+ } else if ( semver . gte ( rescriptVersion , "12.0.0-alpha.13" ) ) {
124115 // TODO: export `binPaths` from `rescript` package so that we don't need to
125116 // copy the logic for figuring out `target`.
126117 const target = `${ process . platform } -${ process . arch } ` ;
@@ -143,6 +134,9 @@ let findBinaryAsync = async (
143134 }
144135}
145136
137+ export let findRescriptBinary = ( projectRootPath : p . DocumentUri | null ) =>
138+ findBinaryAsync ( projectRootPath , "rescript" ) ;
139+
146140export let findBscExeBinary = ( projectRootPath : p . DocumentUri | null ) =>
147141 findBinaryAsync ( projectRootPath , "bsc.exe" ) ;
148142
0 commit comments