Skip to content

Commit cec9342

Browse files
committed
Use platform specific rewatch binary
1 parent 9f58cea commit cec9342

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

server/src/incrementalCompilation.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function getBscArgs(
223223
) {
224224
return Promise.resolve(rewatchCacheEntry.compilerArgs);
225225
}
226-
return new Promise((resolve, _reject) => {
226+
return new Promise(async(resolve, _reject) => {
227227
function resolveResult(result: Array<string> | RewatchCompilerArgs) {
228228
if (stat != null && Array.isArray(result)) {
229229
entry.buildNinja = {
@@ -295,6 +295,20 @@ function getBscArgs(
295295
entry.project.workspaceRootPath,
296296
"node_modules/@rolandpeelen/rewatch/rewatch"
297297
);
298+
if (semver.valid(project.rescriptVersion) &&
299+
semver.satisfies(project.rescriptVersion as string, ">11", { includePrerelease: true })) {
300+
const rescriptRewatchPath = await utils.findRewatchBinary(entry.project.workspaceRootPath)
301+
if (rescriptRewatchPath != null) {
302+
rewatchPath = rescriptRewatchPath;
303+
if (debug()) {
304+
console.log(`Found rewatch binary bundled with v12: ${rescriptRewatchPath}`)
305+
}
306+
} else {
307+
if (debug()) {
308+
console.log("Did not find rewatch binary bundled with v12")
309+
}
310+
}
311+
}
298312
const compilerArgs = JSON.parse(
299313
cp
300314
.execFileSync(rewatchPath, [
@@ -536,6 +550,10 @@ async function figureOutBscArgs(entry: IncrementallyCompiledFileInfo) {
536550
"-I",
537551
path.resolve(entry.project.rootPath, c.compilerOcamlDirPartialPath)
538552
);
553+
} else if (value.startsWith("..") && value.endsWith("ocaml")) {
554+
// This should be the lib/ocaml folder of the project
555+
// This is a hack to support incremental compilation in monorepos
556+
callArgs.push("-I", path.resolve(entry.project.incrementalFolderPath, "..", "..", "ocaml"));
539557
} else {
540558
callArgs.push("-I", value);
541559
}

server/src/utils.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export let findProjectRootOfFile = (
8181
// We won't know which version is in the project root until we read and parse `{project_root}/node_modules/rescript/package.json`
8282
let findBinary = async (
8383
projectRootPath: p.DocumentUri | null,
84-
binary: "bsc.exe" | "rescript-editor-analysis.exe" | "rescript"
84+
binary: "bsc.exe" | "rescript-editor-analysis.exe" | "rescript" | "rewatch.exe"
8585
) => {
8686
if (config.extensionConfiguration.platformPath != null) {
8787
return path.join(config.extensionConfiguration.platformPath, binary);
@@ -122,6 +122,8 @@ let findBinary = async (
122122
binaryPath = binPaths.bsc_exe
123123
} else if (binary == "rescript-editor-analysis.exe") {
124124
binaryPath = binPaths.rescript_editor_analysis_exe
125+
} else if (binary == "rewatch.exe") {
126+
binaryPath = binPaths.rewatch_exe
125127
}
126128
} else {
127129
binaryPath = path.join(rescriptDir, c.platformDir, binary)
@@ -143,6 +145,9 @@ export let findBscExeBinary = (projectRootPath: p.DocumentUri | null) =>
143145
export let findEditorAnalysisBinary = (projectRootPath: p.DocumentUri | null) =>
144146
findBinary(projectRootPath, "rescript-editor-analysis.exe");
145147

148+
export let findRewatchBinary = (projectRootPath: p.DocumentUri | null) =>
149+
findBinary(projectRootPath, "rewatch.exe");
150+
146151
type execResult =
147152
| {
148153
kind: "success";

0 commit comments

Comments
 (0)