Skip to content

Commit a012c34

Browse files
committed
pass config to -project arg
1 parent 2b6df7b commit a012c34

File tree

5 files changed

+64
-30
lines changed

5 files changed

+64
-30
lines changed

jscomp/bsb_exe/rescript_main.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ let () = Bsb_log.setup ()
2626

2727
let separator = "--"
2828

29+
(* FIXME: should be swapped in v12 *)
30+
let project_path = ref "bsconfig.json"
31+
2932
let watch_mode = ref false
3033

3134
let make_world = ref false
@@ -148,9 +151,10 @@ let build_subcommand ~start argv argv_len =
148151
( "-regen",
149152
unit_set_spec force_regenerate,
150153
"*internal* \n\
151-
Always regenerate build.ninja no matter bsconfig.json is changed or \
154+
Always regenerate build.ninja no matter rescript.json is changed or \
152155
not" );
153156
("-verbose", call_spec Bsb_log.verbose, "Set the output to be verbose");
157+
("-project", string_set_spec project_path, "Project file (rescript.json) path");
154158
|]
155159
failed_annon;
156160

rescript

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ var path = require("path");
1313
var fs = require("fs");
1414
var bsc_exe = require("./scripts/bin_path").bsc_exe;
1515
var rescript_exe = require("./scripts/bin_path").rescript_exe;
16-
var bsconfig = "bsconfig.json";
1716

1817
var LAST_BUILD_START = 0;
1918
var LAST_FIRED_EVENT = 0;
@@ -28,13 +27,23 @@ var lockFileName = path.join(cwd, ".bsb.lock");
2827
process.env.BSB_PROJECT_ROOT = cwd;
2928
// console.log('BSB_PROJECT_ROOT:', process.env.BSB_PROJECT_ROOT)
3029

30+
var bsConfig = "bsconfig.json"
31+
var resConfig = "rescript.json";
32+
var resConfigFile = path.join(cwd, resConfig);
33+
if (!fs.existsSync(resConfigFile)) {
34+
resConfig = bsConfig;
35+
resConfigFile = path.join(cwd, bsConfig);
36+
}
37+
3138
// If the project uses gentype and uses custom file extension
3239
// via generatedFileExtension, ignore them in watch mode
33-
var bsConfigFile = path.join(cwd, bsconfig);
3440
var genTypeFileExtension = undefined;
3541

36-
if (fs.existsSync(bsConfigFile)) {
37-
var genTypeConfig = require(bsConfigFile).gentypeconfig
42+
if (fs.existsSync(resConfigFile)) {
43+
if (resConfig === bsConfig) {
44+
console.warn("bsconfig.json is deprecated. Use rescript.json instead.");
45+
}
46+
var genTypeConfig = require(resConfigFile).gentypeconfig
3847
if (genTypeConfig) {
3948
genTypeFileExtension = genTypeConfig.generatedFileExtension
4049
}
@@ -249,29 +258,25 @@ if (
249258
require("./scripts/rescript_format.js").main(
250259
process.argv.slice(3),
251260
rescript_exe,
252-
bsc_exe
253-
);
254-
break;
255-
case "dump":
256-
require("./scripts/rescript_dump.js").main(
257-
process.argv.slice(3),
258-
rescript_exe,
259-
bsc_exe
261+
bsc_exe,
262+
resConfigFile
260263
);
261264
break;
262265
case "dump":
263266
require("./scripts/rescript_dump.js").main(
264267
process.argv.slice(3),
265268
rescript_exe,
266-
bsc_exe
269+
bsc_exe,
270+
resConfigFile
267271
);
268272
break;
269273
case "convert":
270274
// Todo
271275
require("./scripts/rescript_convert.js").main(
272276
process.argv.slice(3),
273277
rescript_exe,
274-
bsc_exe
278+
bsc_exe,
279+
resConfigFile
275280
);
276281
break;
277282
case "-h":
@@ -312,6 +317,11 @@ if (
312317
}
313318

314319
verbose = delegate_args.includes("-verbose");
320+
321+
if (!delegate_args.includes("-config")) {
322+
delegate_args = delegate_args.concat(["-project", resConfigFile]);
323+
}
324+
315325
/**
316326
* @type {child_process.ChildProcess}
317327
*/
@@ -373,7 +383,7 @@ if (
373383
watch_generated = watch_config.generated;
374384
// close and remove all unused watchers
375385
watchers = watchers.filter(function (watcher) {
376-
if (watcher.dir === bsconfig) {
386+
if (watcher.dir === resConfig) {
377387
return true;
378388
} else if (watch_files.indexOf(watcher.dir) < 0) {
379389
dlog(`${watcher.dir} is no longer watched`);
@@ -583,7 +593,7 @@ if (
583593
}
584594
}
585595

586-
watchers.push({ watcher: fs.watch(bsconfig, on_change), dir: bsconfig });
596+
watchers.push({ watcher: fs.watch(resConfig, on_change), dir: resConfig });
587597
build(0);
588598
}
589599
}

scripts/rescript_convert.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function handleOneFile(file, bsc_exe) {
6767
* @param {string} rescript_exe
6868
* @param {string} bsc_exe
6969
*/
70-
function main(argv, rescript_exe, bsc_exe) {
70+
function main(argv, rescript_exe, bsc_exe, project_path) {
7171
try {
7272
/**
7373
* @type {string[]}
@@ -88,7 +88,7 @@ function main(argv, rescript_exe, bsc_exe) {
8888
// TODO: check the rest arguments
8989
var output = child_process.spawnSync(
9090
rescript_exe,
91-
["info", "-list-files"],
91+
["info", "-list-files", "-project", project_path],
9292
{
9393
encoding: "utf-8",
9494
}

scripts/rescript_dump.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ var specs = [];
1515
* @param {string} rescript_exe
1616
* @param {string} bsc_exe
1717
*/
18-
function main(argv, rescript_exe, bsc_exe) {
18+
function main(argv, rescript_exe, bsc_exe, project_path) {
1919
var target;
2020
arg.parse_exn(dump_usage, argv, specs, xs => {
2121
if (xs.length !== 1) {
@@ -30,9 +30,11 @@ function main(argv, rescript_exe, bsc_exe) {
3030
process.exit(2);
3131
}
3232

33-
var output = child_process.spawnSync(rescript_exe, ["build", "--", target], {
34-
encoding: "utf-8",
35-
});
33+
var output = child_process.spawnSync(
34+
rescript_exe,
35+
["build", "-project", project_path, "--", target],
36+
{ encoding: "utf-8" }
37+
);
3638
if (output.status !== 0) {
3739
console.log(output.stdout);
3840
console.error(output.stderr);

scripts/rescript_format.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,21 @@ async function readStdin() {
7373
* @param {(x: string) => boolean} isSupportedFile
7474
* @param {boolean} checkFormatting
7575
*/
76-
async function formatFiles(files, bsc_exe, isSupportedFile, checkFormatting) {
76+
async function formatFiles(
77+
files,
78+
bsc_exe,
79+
project_path,
80+
isSupportedFile,
81+
checkFormatting
82+
) {
7783
var incorrectlyFormattedFiles = 0;
7884
try {
7985
const _promises = await Promise.all(
8086
files.map(async file => {
8187
if (isSupportedFile(file)) {
8288
const flags = checkFormatting
83-
? ["-format", file]
84-
: ["-o", file, "-format", file];
89+
? ["-project", project_path, "-format", file]
90+
: ["-project", project_path, "-o", file, "-format", file];
8591
const { stdout } = await asyncExecFile(bsc_exe, flags);
8692
if (check.val) {
8793
const original = await asyncFs.readFile(file, "utf-8");
@@ -115,7 +121,7 @@ async function formatFiles(files, bsc_exe, isSupportedFile, checkFormatting) {
115121
* @param {string} rescript_exe
116122
* @param {string} bsc_exe
117123
*/
118-
async function main(argv, rescript_exe, bsc_exe) {
124+
async function main(argv, rescript_exe, bsc_exe, project_path) {
119125
var isSupportedFile = hasExtension(formattedFileExtensions);
120126
var isSupportedStd = hasExtension(formattedStdExtensions);
121127

@@ -160,7 +166,13 @@ async function main(argv, rescript_exe, bsc_exe) {
160166
process.exit(2);
161167
}
162168
files = output.stdout.split("\n").map(x => x.trim());
163-
await formatFiles(files, bsc_exe, isSupportedFile, check.val);
169+
await formatFiles(
170+
files,
171+
bsc_exe,
172+
project_path,
173+
isSupportedFile,
174+
check.val
175+
);
164176
} else if (use_stdin) {
165177
if (check.val) {
166178
console.error("format -stdin cannot be used with -check flag");
@@ -183,7 +195,7 @@ async function main(argv, rescript_exe, bsc_exe) {
183195
process.addListener("exit", () => fs.unlinkSync(filename));
184196
child_process.execFile(
185197
bsc_exe,
186-
["-format", filename],
198+
["-project", project_path, "-format", filename],
187199
(error, stdout, stderr) => {
188200
if (error === null) {
189201
process.stdout.write(stdout);
@@ -214,7 +226,13 @@ async function main(argv, rescript_exe, bsc_exe) {
214226
process.exit(2);
215227
}
216228
}
217-
await formatFiles(files, bsc_exe, isSupportedFile, check.val);
229+
await formatFiles(
230+
files,
231+
bsc_exe,
232+
project_path,
233+
isSupportedFile,
234+
check.val
235+
);
218236
}
219237
} catch (e) {
220238
if (e instanceof arg.ArgError) {

0 commit comments

Comments
 (0)