@@ -54,17 +54,32 @@ export let findBscNativeOfFile = (
54
54
let bscNativePath = path . join ( dir , c . bscNativePartialPath ) ;
55
55
56
56
if ( fs . existsSync ( bscNativeReScriptPath ) ) {
57
- return bscNativeReScriptPath
57
+ return bscNativeReScriptPath ;
58
58
} else if ( fs . existsSync ( bscNativePath ) ) {
59
- return bscNativePath
59
+ return bscNativePath ;
60
60
} else if ( dir === source ) {
61
61
// reached the top
62
- return null
62
+ return null ;
63
63
} else {
64
64
return findBscNativeOfFile ( dir ) ;
65
65
}
66
66
} ;
67
67
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
+
68
83
type execResult =
69
84
| {
70
85
kind : "success" ;
@@ -129,10 +144,14 @@ export let runAnalysisAfterSanityCheck = (
129
144
return JSON . parse ( stdout . toString ( ) ) ;
130
145
} ;
131
146
132
- export let runBsbWatcherUsingValidBsbNodePath = (
133
- bsbNodePath : p . DocumentUri ,
147
+ export let runBuildWatcherUsingValidBuildPath = (
148
+ buildPath : p . DocumentUri ,
149
+ isRescript : boolean ,
134
150
projectRootPath : p . DocumentUri
135
151
) => {
152
+ let cwdEnv = {
153
+ cwd : projectRootPath ,
154
+ } ;
136
155
if ( process . platform === "win32" ) {
137
156
/*
138
157
- a node.js script in node_modules/.bin on windows is wrapped in a
@@ -146,13 +165,17 @@ export let runBsbWatcherUsingValidBsbNodePath = (
146
165
(since the path might have spaces), which `execFile` would have done
147
166
for you under the hood
148
167
*/
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
+ }
152
173
} 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
+ }
156
179
}
157
180
} ;
158
181
0 commit comments