Skip to content

Use Rewatch when rescript.lock is found #1107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions server/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export let compilerOcamlDirPartialPath = path.join("lib", "ocaml");
export let compilerLogPartialPath = path.join("lib", "bs", ".compiler.log");
export let buildNinjaPartialPath = path.join("lib", "bs", "build.ninja");
export let rewatchLockPartialPath = path.join("lib", "rewatch.lock");
export let rescriptLockPartialPath = path.join("lib", "rescript.lock");
export let resExt = ".res";
export let resiExt = ".resi";
export let cmiExt = ".cmi";
Expand Down
39 changes: 29 additions & 10 deletions server/src/incrementalCompilation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ function getBscArgs(
entry.project.workspaceRootPath,
c.rewatchLockPartialPath
);
const rescriptLockfile = path.resolve(
entry.project.workspaceRootPath,
c.rescriptLockPartialPath
);
let buildSystem: "bsb" | "rewatch" | null = null;

let stat: fs.Stats | null = null;
Expand All @@ -202,9 +206,16 @@ function getBscArgs(
stat = fs.statSync(rewatchLockfile);
buildSystem = "rewatch";
} catch {}
try {
stat = fs.statSync(rescriptLockfile);
buildSystem = "rewatch";
}
catch {}
if (buildSystem == null) {
console.log("Did not find build.ninja or rewatch.lock, cannot proceed..");
return Promise.resolve(null);
} else if (debug()) {
console.log(`Using build system: ${buildSystem} for ${entry.file.sourceFilePath}`);
}
const bsbCacheEntry = entry.buildNinja;
const rewatchCacheEntry = entry.buildRewatch;
Expand Down Expand Up @@ -298,20 +309,28 @@ function getBscArgs(
entry.project.workspaceRootPath,
"node_modules/@rolandpeelen/rewatch/rewatch"
);
let rescriptRewatchPath = null;
if (semver.valid(project.rescriptVersion) &&
semver.satisfies(project.rescriptVersion as string, ">11", { includePrerelease: true })) {
const rescriptRewatchPath = await utils.findRewatchBinary(entry.project.workspaceRootPath)
if (rescriptRewatchPath != null) {
rewatchPath = rescriptRewatchPath;
if (debug()) {
console.log(`Found rewatch binary bundled with v12: ${rescriptRewatchPath}`)
}
} else {
if (debug()) {
console.log("Did not find rewatch binary bundled with v12")
}
rescriptRewatchPath = await utils.findRewatchBinary(entry.project.workspaceRootPath)
}

if (semver.valid(project.rescriptVersion) &&
semver.satisfies(project.rescriptVersion as string, ">=12.0.0-beta.1", { includePrerelease: true })) {
rescriptRewatchPath = await utils.findRescriptExeBinary(entry.project.workspaceRootPath)
}

if (rescriptRewatchPath != null) {
rewatchPath = rescriptRewatchPath;
if (debug()) {
console.log(`Found rewatch binary bundled with v12: ${rescriptRewatchPath}`)
}
} else {
if (debug()) {
console.log("Did not find rewatch binary bundled with v12")
}
}

const rewatchArguments = semver.satisfies(project.rescriptVersion, ">12.0.0-alpha.14", { includePrerelease: true }) ? [
"compiler-args",
"--rescript-version",
Expand Down
7 changes: 6 additions & 1 deletion server/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export let findProjectRootOfFile = (
// We won't know which version is in the project root until we read and parse `{project_root}/node_modules/rescript/package.json`
let findBinary = async (
projectRootPath: p.DocumentUri | null,
binary: "bsc.exe" | "rescript-editor-analysis.exe" | "rescript" | "rewatch.exe"
binary: "bsc.exe" | "rescript-editor-analysis.exe" | "rescript" | "rewatch.exe" | "rescript.exe"
) => {
if (config.extensionConfiguration.platformPath != null) {
return path.join(config.extensionConfiguration.platformPath, binary);
Expand Down Expand Up @@ -124,6 +124,8 @@ let findBinary = async (
binaryPath = binPaths.rescript_editor_analysis_exe
} else if (binary == "rewatch.exe") {
binaryPath = binPaths.rewatch_exe
} else if (binary == "rescript.exe") {
binaryPath = binPaths.rescript_exe
}
} else {
binaryPath = path.join(rescriptDir, c.platformDir, binary)
Expand All @@ -148,6 +150,9 @@ export let findEditorAnalysisBinary = (projectRootPath: p.DocumentUri | null) =>
export let findRewatchBinary = (projectRootPath: p.DocumentUri | null) =>
findBinary(projectRootPath, "rewatch.exe");

export let findRescriptExeBinary = (projectRootPath: p.DocumentUri | null) =>
findBinary(projectRootPath, "rescript.exe");

type execResult =
| {
kind: "success";
Expand Down