Skip to content

Commit e60b5cd

Browse files
authored
Rewatch: check if filename case for interface and implementation matches (#8144)
* Rewatch: check if filename case for interface and implementation matches * CHANGELOG * Another case test
1 parent 1792d23 commit e60b5cd

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#### :nail_care: Polish
3232

3333
- Rewatch: enable `--create-sourcedirs` by default (now deprecated when explicitly used). https://github.com/rescript-lang/rescript/pull/8092
34+
- Rewatch: check if filename case for interface and implementation matches. https://github.com/rescript-lang/rescript/pull/8144
3435

3536
#### :house: Internal
3637

rewatch/src/build/packages.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,20 @@ pub fn parse_packages(build_state: &mut BuildState) -> Result<()> {
811811
};
812812
match source_files.get(&implementation_filename) {
813813
None => {
814+
if let Some(implementation_path) = source_files.keys().find(|path| {
815+
let extension = path.extension().and_then(|ext| ext.to_str());
816+
matches!(extension, Some(ext) if helpers::is_implementation_file(ext))
817+
&& helpers::file_path_to_module_name(path, &namespace) == module_name
818+
}) {
819+
let implementation_display =
820+
implementation_path.to_string_lossy().to_string();
821+
let interface_display = file.to_string_lossy().to_string();
822+
return Err(anyhow!(
823+
"Implementation and interface have different path names or different cases: `{}` vs `{}`",
824+
implementation_display,
825+
interface_display
826+
));
827+
}
814828
println!(
815829
"{} No implementation file found for interface file (skipping): {}",
816830
LINE_CLEAR,

tests/build_tests/case/input.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@ import * as assert from "node:assert";
22
import { setup } from "#dev/process";
33
import { normalizeNewlines } from "#dev/utils";
44

5-
const { execBuildLegacy } = setup(import.meta.dirname);
5+
const { execBuild } = setup(import.meta.dirname);
66

7-
const { stderr } = await execBuildLegacy();
7+
const { stderr } = await execBuild();
88

99
if (
1010
![
11-
"Error: Invalid rescript.json: implementation and interface have different path names or different cases src/demo vs src/Demo\n",
11+
"Could not initialize build: Implementation and interface have different path names or different cases: `src/demo.res` vs `src/Demo.resi`\n",
1212
// Windows: path separator
13-
"Error: Invalid rescript.json: implementation and interface have different path names or different cases src\\demo vs src\\Demo\n",
14-
// Linux: files are parsed in different order
15-
"Error: Invalid rescript.json: implementation and interface have different path names or different cases src/Demo vs src/demo\n",
13+
"Could not initialize build: Implementation and interface have different path names or different cases: `src\\demo.res` vs `src\\Demo.resi`\n",
1614
].includes(normalizeNewlines(stderr))
1715
) {
1816
assert.fail(stderr);

tests/build_tests/case2/input.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ import * as assert from "node:assert";
44
import { setup } from "#dev/process";
55
import { normalizeNewlines } from "#dev/utils";
66

7-
const { execBuildLegacy } = setup(import.meta.dirname);
7+
const { execBuild } = setup(import.meta.dirname);
88

9-
const { stderr } = await execBuildLegacy();
9+
const { stderr } = await execBuild();
1010

1111
if (
1212
![
13-
"Error: Invalid rescript.json: implementation and interface have different path names or different cases src/X vs src/x\n",
13+
"Could not initialize build: Implementation and interface have different path names or different cases: `src/X.res` vs `src/x.resi`\n",
1414
// Windows: path separator
15-
"Error: Invalid rescript.json: implementation and interface have different path names or different cases src\\X vs src\\x\n",
16-
// Linux: files are parsed in different order
17-
"Error: Invalid rescript.json: implementation and interface have different path names or different cases src/x vs src/X\n",
15+
"Could not initialize build: Implementation and interface have different path names or different cases: `src\\X.res` vs `src\\x.resi`\n",
1816
].includes(normalizeNewlines(stderr))
1917
) {
2018
assert.fail(stderr);

0 commit comments

Comments
 (0)