Skip to content

Commit 816b945

Browse files
Fix possible windows bugs in incremental compilation
1 parent 2837e08 commit 816b945

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

server/src/constants.ts

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export let rescriptJsonPartialPath = "rescript.json";
4545
export let compilerDirPartialPath = path.join("lib", "bs");
4646
export let compilerLogPartialPath = path.join("lib", "bs", ".compiler.log");
4747
export let buildNinjaPartialPath = path.join("lib", "bs", "build.ninja");
48+
export let rewatchLockPartialPath = path.join("lib", "rewatch.lock");
4849
export let resExt = ".res";
4950
export let resiExt = ".resi";
5051
export let cmiExt = ".cmi";

server/src/incrementalCompilation.ts

+17-5
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ function getBscArgs(
190190
): Promise<Array<string> | RewatchCompilerArgs | null> {
191191
const buildNinjaPath = path.resolve(
192192
entry.project.rootPath,
193-
"lib/bs/build.ninja"
193+
c.buildNinjaPartialPath
194194
);
195195
const rewatchLockfile = path.resolve(
196196
entry.project.workspaceRootPath,
197-
"lib/rewatch.lock"
197+
c.rewatchLockPartialPath
198198
);
199199
let buildSystem: "bsb" | "rewatch" | null = null;
200200

@@ -246,7 +246,13 @@ function getBscArgs(
246246
}
247247

248248
if (buildSystem === "bsb") {
249-
const fileStream = fs.createReadStream(buildNinjaPath);
249+
const fileStream = fs.createReadStream(buildNinjaPath, {
250+
encoding: "utf8",
251+
});
252+
fileStream.on("error", (err) => {
253+
console.error("File stream error:", err);
254+
resolveResult([]);
255+
});
250256
const rl = readline.createInterface({
251257
input: fileStream,
252258
crlfDelay: Infinity,
@@ -256,6 +262,7 @@ function getBscArgs(
256262
let stopped = false;
257263
const captured: Array<string> = [];
258264
rl.on("line", (line) => {
265+
line = line.trim(); // Normalize line endings
259266
if (stopped) {
260267
return;
261268
}
@@ -264,7 +271,8 @@ function getBscArgs(
264271
captureNextLine = false;
265272
}
266273
if (done) {
267-
fileStream.destroy();
274+
// Not sure if fileStream.destroy is necessary, rl.close() will handle it gracefully.
275+
// fileStream.destroy();
268276
rl.close();
269277
resolveResult(captured);
270278
stopped = true;
@@ -278,6 +286,10 @@ function getBscArgs(
278286
done = true;
279287
}
280288
});
289+
rl.on("error", (err) => {
290+
console.error("Readline error:", err);
291+
resolveResult([]);
292+
});
281293
rl.on("close", () => {
282294
resolveResult(captured);
283295
});
@@ -399,7 +411,7 @@ function triggerIncrementalCompilationOfFile(
399411

400412
let originalTypeFileLocation = path.resolve(
401413
projectRootPath,
402-
"lib/bs",
414+
c.compilerDirPartialPath,
403415
path.relative(projectRootPath, filePath)
404416
);
405417

0 commit comments

Comments
 (0)