Skip to content

Commit 9bf213a

Browse files
committed
tools: fix experimental embed command output, and expose JS function for retrieving the correct OCaml binary to call for the platform you are on
1 parent 8634477 commit 9bf213a

File tree

5 files changed

+40
-10
lines changed

5 files changed

+40
-10
lines changed

tools/npm/RescriptTools.res

+13
Original file line numberDiff line numberDiff line change
@@ -1 +1,14 @@
11
module Docgen = Tools_Docgen
2+
3+
/** Returns the full file system path to the `rescript-tools` binary for the current platform, side stepping the JS that wraps the CLI.
4+
5+
You can use this when you're already running a JS process and want to avoid the overhead of starting another one.
6+
7+
## Examples
8+
```rescript
9+
// Prints the current ReScript Tools version.
10+
let stringifiedJson = ChildProcess.execFileSync(RescriptTools.getBinaryPath(), ["-v"])
11+
```
12+
*/
13+
@module("./getBinaryPath.js")
14+
external getBinaryPath: unit => string = "getBinaryPath"

tools/npm/cli.js

+5-8
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
"use strict";
44

55
const child_process = require("child_process");
6-
const path = require("path");
7-
8-
const platformArch =
9-
process.arch === "x64" ? process.platform : process.platform + process.arch;
10-
11-
const binPath = path.join(__dirname, "..", "binaries", platformArch, "rescript-tools.exe");
6+
const { getBinaryPath } = require("./getBinaryPath");
127

138
const args = process.argv.slice(2);
149

15-
const spawn = child_process.spawnSync(binPath, args, { stdio: "inherit" });
10+
const spawn = child_process.spawnSync(getBinaryPath(), args, {
11+
stdio: "inherit",
12+
});
1613

1714
if (spawn.status != null) {
18-
process.exit(spawn.status)
15+
process.exit(spawn.status);
1916
}

tools/npm/getBinaryPath.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
const path = require("path");
2+
3+
function getBinaryPath() {
4+
const platformArch =
5+
process.arch === "x64" ? process.platform : process.platform + process.arch;
6+
7+
const binPath = path.join(
8+
__dirname,
9+
"..",
10+
"binaries",
11+
platformArch,
12+
"rescript-tools.exe"
13+
);
14+
return binPath;
15+
}
16+
17+
module.exports = {
18+
getBinaryPath,
19+
};

tools/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
],
1515
"files": [
1616
"npm/cli.js",
17+
"npm/getBinaryPath.js",
1718
"npm/*.res",
1819
"npm/*.resi",
1920
"binaries",

tools/src/tools.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,8 @@ let extractEmbedded ~extensionPoints ~filename =
477477
|> List.map (fun (loc, extensionName, contents) ->
478478
stringifyObject
479479
[
480-
("extensionName", Some extensionName);
481-
("contents", Some contents);
480+
("extensionName", Some (wrapInQuotes extensionName));
481+
("contents", Some (wrapInQuotes contents));
482482
("loc", Some (Analysis.Utils.cmtLocToRange loc |> stringifyRange));
483483
])
484484
|> array

0 commit comments

Comments
 (0)