-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathutils-legacy.ts
More file actions
59 lines (51 loc) · 1.58 KB
/
utils-legacy.ts
File metadata and controls
59 lines (51 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/**
* Legacy binary finding for ReScript < 12.
* This code is kept separate to avoid polluting the main utils with pre-v12 complexity.
*/
import * as fs from "fs";
import * as path from "path";
import { NormalizedPath } from "./utils";
type binaryName = "rescript-editor-analysis.exe" | "rescript-tools.exe";
// Legacy format: no hyphen (e.g., "darwinarm64")
const platformDir =
process.arch === "arm64" ? process.platform + process.arch : process.platform;
const getLegacyBinaryDevPath = (b: binaryName) =>
path.join(path.dirname(__dirname), "..", "analysis", b);
export const getLegacyBinaryProdPath = (b: binaryName) =>
path.join(
path.dirname(__dirname),
"..",
"server",
"analysis_binaries",
platformDir,
b,
);
/**
* Finds binaries for ReScript < 12 using old path structure.
* Tries project binary first, then falls back to builtin binaries.
*/
export const getBinaryPathLegacy = (
projectRootPath: NormalizedPath | null,
binaryName: binaryName,
): string | null => {
// Try project binary first
if (projectRootPath != null) {
const binaryFromCompilerPackage = path.join(
projectRootPath,
"node_modules",
"rescript",
platformDir,
binaryName,
);
if (fs.existsSync(binaryFromCompilerPackage)) {
return binaryFromCompilerPackage;
}
}
// Fall back to builtin binaries
if (fs.existsSync(getLegacyBinaryDevPath(binaryName))) {
return getLegacyBinaryDevPath(binaryName);
} else if (fs.existsSync(getLegacyBinaryProdPath(binaryName))) {
return getLegacyBinaryProdPath(binaryName);
}
return null;
};