Skip to content

Commit e18a3cd

Browse files
authored
Merge pull request #1107 from nojaf/rescript-lockfile
Use Rewatch when rescript.lock is found
2 parents 36cb694 + 9500946 commit e18a3cd

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

server/src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export let compilerOcamlDirPartialPath = path.join("lib", "ocaml");
3535
export let compilerLogPartialPath = path.join("lib", "bs", ".compiler.log");
3636
export let buildNinjaPartialPath = path.join("lib", "bs", "build.ninja");
3737
export let rewatchLockPartialPath = path.join("lib", "rewatch.lock");
38+
export let rescriptLockPartialPath = path.join("lib", "rescript.lock");
3839
export let resExt = ".res";
3940
export let resiExt = ".resi";
4041
export let cmiExt = ".cmi";

server/src/incrementalCompilation.ts

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ function getBscArgs(
191191
entry.project.workspaceRootPath,
192192
c.rewatchLockPartialPath
193193
);
194+
const rescriptLockfile = path.resolve(
195+
entry.project.workspaceRootPath,
196+
c.rescriptLockPartialPath
197+
);
194198
let buildSystem: "bsb" | "rewatch" | null = null;
195199

196200
let stat: fs.Stats | null = null;
@@ -202,9 +206,16 @@ function getBscArgs(
202206
stat = fs.statSync(rewatchLockfile);
203207
buildSystem = "rewatch";
204208
} catch {}
209+
try {
210+
stat = fs.statSync(rescriptLockfile);
211+
buildSystem = "rewatch";
212+
}
213+
catch {}
205214
if (buildSystem == null) {
206215
console.log("Did not find build.ninja or rewatch.lock, cannot proceed..");
207216
return Promise.resolve(null);
217+
} else if (debug()) {
218+
console.log(`Using build system: ${buildSystem} for ${entry.file.sourceFilePath}`);
208219
}
209220
const bsbCacheEntry = entry.buildNinja;
210221
const rewatchCacheEntry = entry.buildRewatch;
@@ -298,20 +309,28 @@ function getBscArgs(
298309
entry.project.workspaceRootPath,
299310
"node_modules/@rolandpeelen/rewatch/rewatch"
300311
);
312+
let rescriptRewatchPath = null;
301313
if (semver.valid(project.rescriptVersion) &&
302314
semver.satisfies(project.rescriptVersion as string, ">11", { includePrerelease: true })) {
303-
const rescriptRewatchPath = await utils.findRewatchBinary(entry.project.workspaceRootPath)
304-
if (rescriptRewatchPath != null) {
305-
rewatchPath = rescriptRewatchPath;
306-
if (debug()) {
307-
console.log(`Found rewatch binary bundled with v12: ${rescriptRewatchPath}`)
308-
}
309-
} else {
310-
if (debug()) {
311-
console.log("Did not find rewatch binary bundled with v12")
312-
}
315+
rescriptRewatchPath = await utils.findRewatchBinary(entry.project.workspaceRootPath)
316+
}
317+
318+
if (semver.valid(project.rescriptVersion) &&
319+
semver.satisfies(project.rescriptVersion as string, ">=12.0.0-beta.1", { includePrerelease: true })) {
320+
rescriptRewatchPath = await utils.findRescriptExeBinary(entry.project.workspaceRootPath)
321+
}
322+
323+
if (rescriptRewatchPath != null) {
324+
rewatchPath = rescriptRewatchPath;
325+
if (debug()) {
326+
console.log(`Found rewatch binary bundled with v12: ${rescriptRewatchPath}`)
327+
}
328+
} else {
329+
if (debug()) {
330+
console.log("Did not find rewatch binary bundled with v12")
313331
}
314332
}
333+
315334
const rewatchArguments = semver.satisfies(project.rescriptVersion, ">12.0.0-alpha.14", { includePrerelease: true }) ? [
316335
"compiler-args",
317336
"--rescript-version",

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" | "rewatch.exe"
84+
binary: "bsc.exe" | "rescript-editor-analysis.exe" | "rescript" | "rewatch.exe" | "rescript.exe"
8585
) => {
8686
if (config.extensionConfiguration.platformPath != null) {
8787
return path.join(config.extensionConfiguration.platformPath, binary);
@@ -124,6 +124,8 @@ let findBinary = async (
124124
binaryPath = binPaths.rescript_editor_analysis_exe
125125
} else if (binary == "rewatch.exe") {
126126
binaryPath = binPaths.rewatch_exe
127+
} else if (binary == "rescript.exe") {
128+
binaryPath = binPaths.rescript_exe
127129
}
128130
} else {
129131
binaryPath = path.join(rescriptDir, c.platformDir, binary)
@@ -148,6 +150,9 @@ export let findEditorAnalysisBinary = (projectRootPath: p.DocumentUri | null) =>
148150
export let findRewatchBinary = (projectRootPath: p.DocumentUri | null) =>
149151
findBinary(projectRootPath, "rewatch.exe");
150152

153+
export let findRescriptExeBinary = (projectRootPath: p.DocumentUri | null) =>
154+
findBinary(projectRootPath, "rescript.exe");
155+
151156
type execResult =
152157
| {
153158
kind: "success";

0 commit comments

Comments
 (0)