@@ -19,7 +19,10 @@ function debug() {
1919}
2020
2121const INCREMENTAL_FOLDER_NAME = "___incremental" ;
22- const INCREMENTAL_FILE_FOLDER_LOCATION = `lib/bs/${ INCREMENTAL_FOLDER_NAME } ` ;
22+ const INCREMENTAL_FILE_FOLDER_LOCATION = path . join (
23+ c . compilerDirPartialPath ,
24+ INCREMENTAL_FOLDER_NAME
25+ ) ;
2326
2427type RewatchCompilerArgs = {
2528 compiler_args : Array < string > ;
@@ -190,11 +193,11 @@ function getBscArgs(
190193) : Promise < Array < string > | RewatchCompilerArgs | null > {
191194 const buildNinjaPath = path . resolve (
192195 entry . project . rootPath ,
193- "lib/bs/build.ninja"
196+ c . buildNinjaPartialPath
194197 ) ;
195198 const rewatchLockfile = path . resolve (
196199 entry . project . workspaceRootPath ,
197- "lib/rewatch.lock"
200+ c . rewatchLockPartialPath
198201 ) ;
199202 let buildSystem : "bsb" | "rewatch" | null = null ;
200203
@@ -246,7 +249,13 @@ function getBscArgs(
246249 }
247250
248251 if ( buildSystem === "bsb" ) {
249- const fileStream = fs . createReadStream ( buildNinjaPath ) ;
252+ const fileStream = fs . createReadStream ( buildNinjaPath , {
253+ encoding : "utf8" ,
254+ } ) ;
255+ fileStream . on ( "error" , ( err ) => {
256+ console . error ( "File stream error:" , err ) ;
257+ resolveResult ( [ ] ) ;
258+ } ) ;
250259 const rl = readline . createInterface ( {
251260 input : fileStream ,
252261 crlfDelay : Infinity ,
@@ -256,6 +265,7 @@ function getBscArgs(
256265 let stopped = false ;
257266 const captured : Array < string > = [ ] ;
258267 rl . on ( "line" , ( line ) => {
268+ line = line . trim ( ) ; // Normalize line endings
259269 if ( stopped ) {
260270 return ;
261271 }
@@ -264,7 +274,8 @@ function getBscArgs(
264274 captureNextLine = false ;
265275 }
266276 if ( done ) {
267- fileStream . destroy ( ) ;
277+ // Not sure if fileStream.destroy is necessary, rl.close() will handle it gracefully.
278+ // fileStream.destroy();
268279 rl . close ( ) ;
269280 resolveResult ( captured ) ;
270281 stopped = true ;
@@ -278,6 +289,10 @@ function getBscArgs(
278289 done = true ;
279290 }
280291 } ) ;
292+ rl . on ( "error" , ( err ) => {
293+ console . error ( "Readline error:" , err ) ;
294+ resolveResult ( [ ] ) ;
295+ } ) ;
281296 rl . on ( "close" , ( ) => {
282297 resolveResult ( captured ) ;
283298 } ) ;
@@ -399,7 +414,7 @@ function triggerIncrementalCompilationOfFile(
399414
400415 let originalTypeFileLocation = path . resolve (
401416 projectRootPath ,
402- "lib/bs" ,
417+ c . compilerDirPartialPath ,
403418 path . relative ( projectRootPath , filePath )
404419 ) ;
405420
@@ -512,13 +527,13 @@ async function figureOutBscArgs(entry: IncrementallyCompiledFileInfo) {
512527 if ( isBsb ) {
513528 callArgs . push (
514529 "-I" ,
515- path . resolve ( entry . project . rootPath , "lib/bs" , value )
530+ path . resolve ( entry . project . rootPath , c . compilerDirPartialPath , value )
516531 ) ;
517532 } else {
518533 if ( value === "." ) {
519534 callArgs . push (
520535 "-I" ,
521- path . resolve ( entry . project . rootPath , "lib/ocaml" )
536+ path . resolve ( entry . project . rootPath , c . compilerOcamlDirPartialPath )
522537 ) ;
523538 } else {
524539 callArgs . push ( "-I" , value ) ;
0 commit comments