@@ -54,17 +54,32 @@ export let findBscNativeOfFile = (
5454 let bscNativePath = path . join ( dir , c . bscNativePartialPath ) ;
5555
5656 if ( fs . existsSync ( bscNativeReScriptPath ) ) {
57- return bscNativeReScriptPath
57+ return bscNativeReScriptPath ;
5858 } else if ( fs . existsSync ( bscNativePath ) ) {
59- return bscNativePath
59+ return bscNativePath ;
6060 } else if ( dir === source ) {
6161 // reached the top
62- return null
62+ return null ;
6363 } else {
6464 return findBscNativeOfFile ( dir ) ;
6565 }
6666} ;
6767
68+ // TODO: this doesn't handle file:/// scheme
69+ export let findNodeBuildOfProjectRoot = (
70+ projectRootPath : p . DocumentUri
71+ ) : null | { buildPath : p . DocumentUri ; isReScript : boolean } => {
72+ let rescriptNodePath = path . join ( projectRootPath , c . rescriptNodePartialPath ) ;
73+ let bsbNodePath = path . join ( projectRootPath , c . bsbNodePartialPath ) ;
74+
75+ if ( fs . existsSync ( rescriptNodePath ) ) {
76+ return { buildPath : rescriptNodePath , isReScript : true } ;
77+ } else if ( fs . existsSync ( bsbNodePath ) ) {
78+ return { buildPath : bsbNodePath , isReScript : false } ;
79+ }
80+ return null ;
81+ } ;
82+
6883type execResult =
6984 | {
7085 kind : "success" ;
@@ -129,10 +144,14 @@ export let runAnalysisAfterSanityCheck = (
129144 return JSON . parse ( stdout . toString ( ) ) ;
130145} ;
131146
132- export let runBsbWatcherUsingValidBsbNodePath = (
133- bsbNodePath : p . DocumentUri ,
147+ export let runBuildWatcherUsingValidBuildPath = (
148+ buildPath : p . DocumentUri ,
149+ isRescript : boolean ,
134150 projectRootPath : p . DocumentUri
135151) => {
152+ let cwdEnv = {
153+ cwd : projectRootPath ,
154+ } ;
136155 if ( process . platform === "win32" ) {
137156 /*
138157 - a node.js script in node_modules/.bin on windows is wrapped in a
@@ -146,13 +165,17 @@ export let runBsbWatcherUsingValidBsbNodePath = (
146165 (since the path might have spaces), which `execFile` would have done
147166 for you under the hood
148167 */
149- return childProcess . exec ( `"${ bsbNodePath } ".cmd -w` , {
150- cwd : projectRootPath ,
151- } ) ;
168+ if ( isRescript ) {
169+ return childProcess . exec ( `"${ buildPath } ".cmd build -w` , cwdEnv ) ;
170+ } else {
171+ return childProcess . exec ( `"${ buildPath } ".cmd -w` , cwdEnv ) ;
172+ }
152173 } else {
153- return childProcess . execFile ( bsbNodePath , [ "-w" ] , {
154- cwd : projectRootPath ,
155- } ) ;
174+ if ( isRescript ) {
175+ return childProcess . execFile ( buildPath , [ "build" , "-w" ] , cwdEnv ) ;
176+ } else {
177+ return childProcess . execFile ( buildPath , [ "-w" ] , cwdEnv ) ;
178+ }
156179 }
157180} ;
158181
0 commit comments