@@ -76,27 +76,12 @@ export let findProjectRootOfFile = (
76
76
}
77
77
} ;
78
78
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
- } ;
94
79
// If ReScript < 12.0.0-alpha.13, then we want `{project_root}/node_modules/rescript/{c.platformDir}/{binary}`.
95
80
// Otherwise, we want to dynamically import `{project_root}/node_modules/rescript` and from `binPaths` get the relevant binary.
96
81
// We won't know which version is in the project root until we read and parse `{project_root}/node_modules/rescript/package.json`
97
82
let findBinaryAsync = async (
98
83
projectRootPath : p . DocumentUri | null ,
99
- binary : "bsc.exe" | "rescript-editor-analysis.exe"
84
+ binary : "bsc.exe" | "rescript-editor-analysis.exe" | "rescript"
100
85
) => {
101
86
if ( config . extensionConfiguration . platformPath != null ) {
102
87
return path . join ( config . extensionConfiguration . platformPath , binary ) ;
@@ -111,16 +96,22 @@ let findBinaryAsync = async (
111
96
}
112
97
113
98
let rescriptVersion = null ;
99
+ let rescriptJSWrapperPath = null
114
100
try {
115
101
const rescriptPackageJSONPath = path . join ( rescriptDir , "package.json" ) ;
116
102
const rescriptPackageJSON = JSON . parse ( await fsAsync . readFile ( rescriptPackageJSONPath , "utf-8" ) ) ;
117
103
rescriptVersion = rescriptPackageJSON . version
104
+ rescriptJSWrapperPath = rescriptPackageJSON . bin . rescript
118
105
} catch ( error ) {
119
106
return null
120
107
}
121
108
122
109
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" ) ) {
124
115
// TODO: export `binPaths` from `rescript` package so that we don't need to
125
116
// copy the logic for figuring out `target`.
126
117
const target = `${ process . platform } -${ process . arch } ` ;
@@ -143,6 +134,9 @@ let findBinaryAsync = async (
143
134
}
144
135
}
145
136
137
+ export let findRescriptBinary = ( projectRootPath : p . DocumentUri | null ) =>
138
+ findBinaryAsync ( projectRootPath , "rescript" ) ;
139
+
146
140
export let findBscExeBinary = ( projectRootPath : p . DocumentUri | null ) =>
147
141
findBinaryAsync ( projectRootPath , "bsc.exe" ) ;
148
142
0 commit comments