Skip to content

Commit 63ef9e5

Browse files
authored
Treat rescript as rescript build aka rescript -w support 🚀 (#6524)
* MVP * Always treat rescript as rescript build command * Update changelog and fix artifacts snapshot
1 parent fe60fcb commit 63ef9e5

File tree

5 files changed

+601
-514
lines changed

5 files changed

+601
-514
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#### :rocket: New Feature
1616
- Add support for type coercion for invariant type arguments such as array payloads. https://github.com/rescript-lang/rescript-compiler/pull/6518
17+
- Start treating `rescript` command the same as the `rescript build` command, so now you can do `rescript -w`. https://github.com/rescript-lang/rescript-compiler/pull/6524
1718

1819
#### :bug: Bug Fix
1920

jscomp/build_tests/cli_help/input.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,28 @@ assert.match(
9898
// FIXME: Should be 0
9999
assert.equal(out.status, 1);
100100

101+
// FIXME: Has the same problem with `rescript -w`
102+
out = child_process.spawnSync(`../../../rescript`, ["-w", "--help"], {
103+
encoding: "utf8",
104+
cwd: __dirname,
105+
});
106+
assert.equal(out.stdout, ">>>> Start compiling\n" + buildHelp);
107+
assert.match(
108+
out.stderr,
109+
new RegExp(
110+
"Uncaught Exception Error: ENOENT: no such file or directory, watch 'bsconfig.json'\n"
111+
)
112+
);
113+
114+
// Shows cli help with --help arg even if there are invalid arguments after it
115+
out = child_process.spawnSync(`../../../rescript`, ["--help", "-w"], {
116+
encoding: "utf8",
117+
cwd: __dirname,
118+
});
119+
assert.equal(out.stdout, cliHelp);
120+
assert.equal(out.stderr, "");
121+
assert.equal(out.status, 0);
122+
101123
// Shows build help with -h arg
102124
out = child_process.spawnSync(`../../../rescript`, ["build", "-h"], {
103125
encoding: "utf8",
@@ -108,12 +130,12 @@ assert.equal(out.stderr, "");
108130
assert.equal(out.status, 0);
109131

110132
// Exits with build help with unknown arg
111-
out = child_process.spawnSync(`../../../rescript`, ["build", "-wtf"], {
133+
out = child_process.spawnSync(`../../../rescript`, ["build", "-foo"], {
112134
encoding: "utf8",
113135
cwd: __dirname,
114136
});
115137
assert.equal(out.stdout, "");
116-
assert.equal(out.stderr, 'Error: Unknown option "-wtf".\n' + buildHelp);
138+
assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp);
117139
assert.equal(out.status, 2);
118140

119141
// Shows cli help with --help arg
@@ -143,22 +165,22 @@ assert.equal(out.stdout, cliHelp);
143165
assert.equal(out.stderr, "");
144166
assert.equal(out.status, 0);
145167

146-
// Shows cli help with unknown command
168+
// Exits with cli help with unknown command
147169
out = child_process.spawnSync(`../../../rescript`, ["built"], {
148170
encoding: "utf8",
149171
cwd: __dirname,
150172
});
151173
assert.equal(out.stdout, "");
152-
assert.equal(out.stderr, `Error: Unknown command or flag "built".\n` + cliHelp);
174+
assert.equal(out.stderr, `Error: Unknown command "built".\n` + cliHelp);
153175
assert.equal(out.status, 2);
154176

155-
// Shows cli help with unknown args
156-
out = child_process.spawnSync(`../../../rescript`, ["-w"], {
177+
// Exits with build help with unknown args
178+
out = child_process.spawnSync(`../../../rescript`, ["-foo"], {
157179
encoding: "utf8",
158180
cwd: __dirname,
159181
});
160182
assert.equal(out.stdout, "");
161-
assert.equal(out.stderr, `Error: Unknown command or flag "-w".\n` + cliHelp);
183+
assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + buildHelp);
162184
assert.equal(out.status, 2);
163185

164186
// Shows clean help with --help arg
@@ -180,12 +202,12 @@ assert.equal(out.stderr, "");
180202
assert.equal(out.status, 0);
181203

182204
// Exits with clean help with unknown arg
183-
out = child_process.spawnSync(`../../../rescript`, ["clean", "-wtf"], {
205+
out = child_process.spawnSync(`../../../rescript`, ["clean", "-foo"], {
184206
encoding: "utf8",
185207
cwd: __dirname,
186208
});
187209
assert.equal(out.stdout, "");
188-
assert.equal(out.stderr, 'Error: Unknown option "-wtf".\n' + cleanHelp);
210+
assert.equal(out.stderr, 'Error: Unknown option "-foo".\n' + cleanHelp);
189211
assert.equal(out.status, 2);
190212

191213
// Shows format help with --help arg

packages/artifacts.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ package.json
10611061
rescript
10621062
scripts/bin_path.js
10631063
scripts/rescript_arg.js
1064+
scripts/rescript_bsb.js
10641065
scripts/rescript_convert.js
10651066
scripts/rescript_dump.js
10661067
scripts/rescript_format.js

0 commit comments

Comments
 (0)