Skip to content

Commit fcad0dc

Browse files
cknittclaude
andcommitted
Reject the reserved package name "_" in rescript.json
Both build systems now refuse a rescript.json whose "name" is "_", with a config error naming the file. The legacy build system had this check (covered by tests/build_tests/xpkg); it was lost when bsb was removed. Diagnostic (text): /path/to/rescript.json: "_" is a reserved package name Area: rewatch tests Output: unchanged Tests: +rewatch-ocaml/tests/config_acceptance_cases.tsv (top-level/reserved-name) +tests/rewatch_ounit_tests/config_tests.ml (validation_tests) +rewatch/src/config.rs (test_reserved_package_name) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Kr4cjoUi2f5VpMvE6wT9bo Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent 58da277 commit fcad0dc

5 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Reject the reserved package name `_` in `rescript.json`, as the legacy build system did.

‎rewatch-ocaml/config.ml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ let load path =
326326
| Some value -> string path "name" value
327327
| None -> fail path "missing required field \"name\""
328328
in
329+
if name = "_" then fail path "\"_\" is a reserved package name";
329330
let configured_suffix =
330331
optional_member "suffix" fields |> Option.map (string path "suffix")
331332
in

‎rewatch-ocaml/tests/config_acceptance_cases.tsv‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ top-level string-root reject "config-shape"
176176
top-level null-name reject {"name":null}
177177
top-level boolean-name reject {"name":true}
178178
top-level empty-name accept {"name":""}
179+
top-level reserved-name reject {"name":"_"}
179180
top-level unknown-field accept {"name":"config-shape","future":{"anything":true}}
180181
top-level editor-arbitrary accept {"name":"config-shape","editor":[true,null,1]}
181182
top-level reanalyze-arbitrary accept {"name":"config-shape","reanalyze":{"anything":true}}

‎rewatch/src/config.rs‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,9 @@ impl Config {
716716
let read =
717717
fs::read_to_string(path).map_err(|e| anyhow!("Could not read '{}': {}", path.display(), e))?;
718718
let mut config = Config::new_from_json_string(&read)?;
719+
if config.name == "_" {
720+
return Err(anyhow!("{}: \"_\" is a reserved package name", path.display()));
721+
}
719722
config.set_path(path.to_path_buf())?;
720723
Ok(config)
721724
}
@@ -2436,6 +2439,19 @@ pub mod tests {
24362439
);
24372440
}
24382441

2442+
#[test]
2443+
fn test_reserved_package_name() {
2444+
let tmp = tempfile::tempdir().expect("tempdir");
2445+
let path = tmp.path().join("rescript.json");
2446+
std::fs::write(&path, r#"{ "name": "_" }"#).expect("write");
2447+
2448+
let error = Config::new(&path).unwrap_err().to_string();
2449+
assert!(
2450+
error.contains(path.to_string_lossy().as_ref()) && error.contains("reserved package name"),
2451+
"Error should name the config path and the reserved name, got: {error}"
2452+
);
2453+
}
2454+
24392455
#[test]
24402456
fn test_bsconfig_json_filename_deprecation() {
24412457
let tmp = tempfile::tempdir().expect("tempdir");

‎tests/rewatch_ounit_tests/config_tests.ml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,15 @@ let validation_tests =
249249
with Config.Error message -> contains message "jsx.version"
250250
in
251251
check rejected "unsupported JSX versions are rejected without panicking";
252+
write_file path {|{"name":"_"}|};
253+
let rejected =
254+
try
255+
ignore (Config.load path);
256+
false
257+
with Config.Error message ->
258+
contains message path && contains message "reserved package name"
259+
in
260+
check rejected "the package name _ is reserved";
252261
write_file path
253262
{|{"name":"internal-path","path":"ignored","gentypeconfig":{}}|};
254263
let alias_dir = Filename.concat root "alias" in

0 commit comments

Comments
 (0)