Skip to content

Fix rewatch compilation of file starting with a lowercase letter #7700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions .devcontainer/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
*~
_build
*.obj
*.out
*.compile
*.native
*.byte
*.cmo
*.annot
*.cmi
*.cmx
*.cmt
*.cmti
*.cma
*.a
*.cmxa
*.obj
*~
*.annot
*.mj
*.bak
*.swp
*.swo
*.flambda
*.jsx
*.lambda
*.rawlambda
*.s
*.o
*.lam
*.0.js
*#
*.log
.#*
*.cmj
*.rawlambda
*.lambda
*.zip
*.mlast
*.mliast

.idea
.DS_Store

node_modules
*.dump
coverage

.ninja_log
.bsdeps
.bsbuild
lib/ocaml
tests/build_tests/*/lib/
#ignore temporary directory
*.goog.js
*.jsoo.js
*.so
tmp/
tracing*.json

_opam

.env
playground/packages/
playground/stdlib/
playground/*.cmj
playground/*.cmi
playground/.netrc
playground/compiler.*js

rewatch/target/
rewatch/rewatch

tests/tools_tests/**/*.res.js
tests/tools_tests/lib
tests/analysis_tests*/lib
tests/analysis_tests/**/*.bs.js

/linux/*.exe
/linuxarm64/*.exe
/darwin/*.exe
/darwinarm64/*.exe
/win32/*.exe

.yarn/*
!.yarn/patches
!.yarn/plugins
!.yarn/releases
!.yarn/sdks
!.yarn/versions

*.tsbuildinfo

# package tarballs
package.tgz
*.exe

/ninja/ninja
/ninja/build.ninja
10 changes: 7 additions & 3 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ FROM mcr.microsoft.com/devcontainers/rust:1-1-bookworm
LABEL org.opencontainers.image.authors="Christoph Knittel <[email protected]>"
LABEL org.opencontainers.image.description="Docker image for ReScript development."

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
RUN sudo apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends \
yarn \
opam \
cmake \
ninja-build \
musl-tools \
python-is-python3 \
&& rm -rf /var/lib/apt/lists/*

# Install OPAM
ARG OPAM_VERSION=2.4.1
RUN printf '\n\n' | bash -c "sh <(curl -fsSL https://raw.githubusercontent.com/ocaml/opam/master/shell/install.sh) --version $OPAM_VERSION"
10 changes: 8 additions & 2 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
"name": "ReScript Compiler",
"build": {
"context": ".",
"dockerfile": "Dockerfile"
"dockerfile": "Dockerfile",
"args": {
"USER_UID": "${localEnv:UID}",
"USER_GID": "${localEnv:GID}"
}
},
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {
Expand All @@ -23,5 +27,7 @@
]
}
},
"postCreateCommand": ".devcontainer/postCreate.sh"
"postCreateCommand": ".devcontainer/postCreate.sh",
"remoteUser": "vscode",
"containerUser": "vscode"
}
12 changes: 6 additions & 6 deletions .devcontainer/postCreate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

# Install dev dependencies from OPAM
opam init -y --bare --disable-sandboxing
opam switch create 5.3.0 --packages ocaml-option-static
opam install . --deps-only -y

# For IDE support, install the OCaml language server
opam install ocaml-lsp-server -y
opam switch create 5.3.0
opam install . --deps-only --with-test --with-dev-setup -y

# Add OPAM environment setup to shell startup script
echo 'eval $(opam env)' >> ~/.zshrc
echo 'eval $(opam env)' >> ~/.bashrc

npm install --ignore-scripts
nvm install

corepack enable
printf "\n" | yarn
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
- Fix fatal error when JSX expression used without configuring JSX in `rescript.json`. https://github.com/rescript-lang/rescript/pull/7656
- Rewatch: Only allow access to `"bs-dev-dependencies"` from `"type": "dev"` source files. https://github.com/rescript-lang/rescript/pull/7650
- Fix comment attached to array element. https://github.com/rescript-lang/rescript/pull/7672
- Rewatch: fix compilation of files starting with a lowercase letter. https://github.com/rescript-lang/rescript/pull/7700

#### :nail_care: Polish

Expand All @@ -101,6 +102,7 @@
- Rewatch: simplify getting bsc path. https://github.com/rescript-lang/rescript/pull/7634
- Rewatch: only get `"type": "dev"` source files for local packages. https://github.com/rescript-lang/rescript/pull/7646
- Rewatch: add support for `rescript -w` for compatibility. https://github.com/rescript-lang/rescript/pull/7649
- Fix dev container. https://github.com/rescript-lang/rescript/pull/7700

# 12.0.0-beta.1

Expand Down
30 changes: 13 additions & 17 deletions rewatch/src/build/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,8 @@ fn compile_file(
ast_path.to_string_lossy()
)),
}?;
let module_name = helpers::file_path_to_module_name(implementation_file_path, &package.namespace);
let basename =
helpers::file_path_to_compiler_asset_basename(implementation_file_path, &package.namespace);
Comment on lines +581 to +582
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the fix

let has_interface = module.get_interface().is_some();
let is_type_dev = module.is_type_dev;
let to_mjs_args = compiler_args(
Expand Down Expand Up @@ -631,40 +632,35 @@ fn compile_file(
// because editor tooling doesn't support namespace entries yet
// we just remove the @ for now. This makes sure the editor support
// doesn't break
.join(format!("{module_name}.cmi")),
ocaml_build_path_abs.join(format!("{module_name}.cmi")),
.join(format!("{basename}.cmi")),
ocaml_build_path_abs.join(format!("{basename}.cmi")),
);
let _ = std::fs::copy(
package
.get_build_path()
.join(dir)
.join(format!("{module_name}.cmj")),
ocaml_build_path_abs.join(format!("{module_name}.cmj")),
package.get_build_path().join(dir).join(format!("{basename}.cmj")),
ocaml_build_path_abs.join(format!("{basename}.cmj")),
);
println!("[rewatch] Copying file {basename} to ocaml build path");
let _ = std::fs::copy(
package
.get_build_path()
.join(dir)
// because editor tooling doesn't support namespace entries yet
// we just remove the @ for now. This makes sure the editor support
// doesn't break
.join(format!("{module_name}.cmt")),
ocaml_build_path_abs.join(format!("{module_name}.cmt")),
.join(format!("{basename}.cmt")),
ocaml_build_path_abs.join(format!("{basename}.cmt")),
);
} else {
let _ = std::fs::copy(
package
.get_build_path()
.join(dir)
.join(format!("{module_name}.cmti")),
ocaml_build_path_abs.join(format!("{module_name}.cmti")),
.join(format!("{basename}.cmti")),
ocaml_build_path_abs.join(format!("{basename}.cmti")),
);
let _ = std::fs::copy(
package
.get_build_path()
.join(dir)
.join(format!("{module_name}.cmi")),
ocaml_build_path_abs.join(format!("{module_name}.cmi")),
package.get_build_path().join(dir).join(format!("{basename}.cmi")),
ocaml_build_path_abs.join(format!("{basename}.cmi")),
);
}

Expand Down
4 changes: 3 additions & 1 deletion rewatch/testrepo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
"packages/with-dev-deps",
"packages/compiled-by-legacy",
"packages/nonexisting-dev-files",
"packages/deprecated-config"
"packages/deprecated-config",
"packages/file-casing",
"packages/file-casing-no-namespace"
]
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@testrepo/file-casing-no-namespace",
"version": "0.0.1",
"keywords": [
"rescript"
],
"author": "",
"license": "MIT"
}
21 changes: 21 additions & 0 deletions rewatch/testrepo/packages/file-casing-no-namespace/rescript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "@testrepo/file-casing-no-namespace",
"sources": [
{
"dir": "src",
"subdirs": true
}
],
"package-specs": [
{
"module": "es6",
"in-source": true
}
],
"suffix": ".mjs",
"dependencies": [],
"compiler-flags": [],
"jsx": {
"version": 4
}
}
10 changes: 10 additions & 0 deletions rewatch/testrepo/packages/file-casing-no-namespace/src/Consume.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Produce from "./produce.mjs";

let x = Produce.meh(1);

export {
x,
}
/* x Not a pure module */
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let x = Produce.meh(1)
11 changes: 11 additions & 0 deletions rewatch/testrepo/packages/file-casing-no-namespace/src/produce.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Generated by ReScript, PLEASE EDIT WITH CARE


function meh(param) {
return true;
}

export {
meh,
}
/* No side effect */
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let meh = (_: int) => {
true
}
1 change: 1 addition & 0 deletions rewatch/testrepo/packages/file-casing/rescript.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "@testrepo/file-casing",
"namespace": "FileCasing",
"sources": [
{
"dir": "src",
Expand Down
4 changes: 2 additions & 2 deletions rewatch/testrepo/packages/file-casing/src/Consume.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Generated by ReScript, PLEASE EDIT WITH CARE

import * as Produce$NamespaceCasingAPI from "./produce.mjs";
import * as Produce$FileCasing from "./produce.mjs";

let x = Produce$NamespaceCasingAPI.meh(1);
let x = Produce$FileCasing.meh(1);

export {
x,
Expand Down
4 changes: 3 additions & 1 deletion rewatch/testrepo/rescript.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"@testrepo/with-dev-deps",
"@testrepo/compiled-by-legacy",
"@testrepo/nonexisting-dev-files",
"@testrepo/deprecated-config"
"@testrepo/deprecated-config",
"@testrepo/file-casing",
"@testrepo/file-casing-no-namespace"
]
}
12 changes: 12 additions & 0 deletions rewatch/testrepo/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ __metadata:
languageName: unknown
linkType: soft

"@testrepo/file-casing-no-namespace@workspace:packages/file-casing-no-namespace":
version: 0.0.0-use.local
resolution: "@testrepo/file-casing-no-namespace@workspace:packages/file-casing-no-namespace"
languageName: unknown
linkType: soft

"@testrepo/file-casing@workspace:packages/file-casing":
version: 0.0.0-use.local
resolution: "@testrepo/file-casing@workspace:packages/file-casing"
languageName: unknown
linkType: soft

"@testrepo/main@workspace:packages/main":
version: 0.0.0-use.local
resolution: "@testrepo/main@workspace:packages/main"
Expand Down
4 changes: 2 additions & 2 deletions rewatch/tests/format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ bold "Test: It should format all files"
git diff --name-only ./
error_output=$("$REWATCH_EXECUTABLE" format --all)
git_diff_file_count=$(git diff --name-only ./ | wc -l | xargs)
if [ $? -eq 0 ] && [ $git_diff_file_count -eq 4 ];
if [ $? -eq 0 ] && [ $git_diff_file_count -eq 8 ];
then
success "Test package formatted. Got $git_diff_file_count changed files."
git restore .
else
error "Error formatting test package"
echo "Expected 4 files to be changed, got $git_diff_file_count"
echo "Expected 8 files to be changed, got $git_diff_file_count"
echo $error_output
exit 1
fi
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Cleaned 0/56
Cleaned 0/60
Parsed 2 source files
[rewatch] Copying file NS_alias-@NewNamespace to ocaml build path
Compiled 2 modules

The field 'bs-dependencies' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version.
Expand Down
2 changes: 1 addition & 1 deletion rewatch/tests/snapshots/dependency-cycle.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Cleaned 0/56
Cleaned 0/60
Parsed 1 source files
Compiled 0 modules

Expand Down
2 changes: 1 addition & 1 deletion rewatch/tests/snapshots/remove-file.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Cleaned 1/56
Cleaned 1/60
Parsed 0 source files
Compiled 1 modules

Expand Down
Loading