diff --git a/.devcontainer/.dockerignore b/.devcontainer/.dockerignore new file mode 100644 index 0000000000..cfecf53afa --- /dev/null +++ b/.devcontainer/.dockerignore @@ -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 \ No newline at end of file diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 90768e7639..f6906258a3 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -2,10 +2,14 @@ FROM mcr.microsoft.com/devcontainers/rust:1-1-bookworm LABEL org.opencontainers.image.authors="Christoph Knittel " 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" diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index d03f934de1..d95de65de4 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -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": { @@ -23,5 +27,7 @@ ] } }, - "postCreateCommand": ".devcontainer/postCreate.sh" + "postCreateCommand": ".devcontainer/postCreate.sh", + "remoteUser": "vscode", + "containerUser": "vscode" } diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh index 79db8cc4f0..c8288d1c83 100755 --- a/.devcontainer/postCreate.sh +++ b/.devcontainer/postCreate.sh @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index a80a23a4dc..f82d7a6234 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/rewatch/src/build/compile.rs b/rewatch/src/build/compile.rs index e5816347c8..38d623f13e 100644 --- a/rewatch/src/build/compile.rs +++ b/rewatch/src/build/compile.rs @@ -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); let has_interface = module.get_interface().is_some(); let is_type_dev = module.is_type_dev; let to_mjs_args = compiler_args( @@ -631,16 +632,14 @@ 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() @@ -648,23 +647,20 @@ 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}.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")), ); } diff --git a/rewatch/testrepo/package.json b/rewatch/testrepo/package.json index 34f0d22239..f42be392d8 100644 --- a/rewatch/testrepo/package.json +++ b/rewatch/testrepo/package.json @@ -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": { diff --git a/rewatch/testrepo/packages/file-casing-no-namespace/package.json b/rewatch/testrepo/packages/file-casing-no-namespace/package.json new file mode 100644 index 0000000000..97925cdac6 --- /dev/null +++ b/rewatch/testrepo/packages/file-casing-no-namespace/package.json @@ -0,0 +1,9 @@ +{ + "name": "@testrepo/file-casing-no-namespace", + "version": "0.0.1", + "keywords": [ + "rescript" + ], + "author": "", + "license": "MIT" +} diff --git a/rewatch/testrepo/packages/file-casing-no-namespace/rescript.json b/rewatch/testrepo/packages/file-casing-no-namespace/rescript.json new file mode 100644 index 0000000000..d1d6797059 --- /dev/null +++ b/rewatch/testrepo/packages/file-casing-no-namespace/rescript.json @@ -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 + } +} diff --git a/rewatch/testrepo/packages/file-casing-no-namespace/src/Consume.mjs b/rewatch/testrepo/packages/file-casing-no-namespace/src/Consume.mjs new file mode 100644 index 0000000000..9f00487db9 --- /dev/null +++ b/rewatch/testrepo/packages/file-casing-no-namespace/src/Consume.mjs @@ -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 */ diff --git a/rewatch/testrepo/packages/file-casing-no-namespace/src/Consume.res b/rewatch/testrepo/packages/file-casing-no-namespace/src/Consume.res new file mode 100644 index 0000000000..e2d9a26460 --- /dev/null +++ b/rewatch/testrepo/packages/file-casing-no-namespace/src/Consume.res @@ -0,0 +1 @@ +let x = Produce.meh(1) \ No newline at end of file diff --git a/rewatch/testrepo/packages/file-casing-no-namespace/src/produce.mjs b/rewatch/testrepo/packages/file-casing-no-namespace/src/produce.mjs new file mode 100644 index 0000000000..2dc987f1bd --- /dev/null +++ b/rewatch/testrepo/packages/file-casing-no-namespace/src/produce.mjs @@ -0,0 +1,11 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +function meh(param) { + return true; +} + +export { + meh, +} +/* No side effect */ diff --git a/rewatch/testrepo/packages/file-casing-no-namespace/src/produce.res b/rewatch/testrepo/packages/file-casing-no-namespace/src/produce.res new file mode 100644 index 0000000000..194a02d465 --- /dev/null +++ b/rewatch/testrepo/packages/file-casing-no-namespace/src/produce.res @@ -0,0 +1,3 @@ +let meh = (_: int) => { + true +} \ No newline at end of file diff --git a/rewatch/testrepo/packages/file-casing/rescript.json b/rewatch/testrepo/packages/file-casing/rescript.json index 50914c1025..39a3626510 100644 --- a/rewatch/testrepo/packages/file-casing/rescript.json +++ b/rewatch/testrepo/packages/file-casing/rescript.json @@ -1,5 +1,6 @@ { "name": "@testrepo/file-casing", + "namespace": "FileCasing", "sources": [ { "dir": "src", diff --git a/rewatch/testrepo/packages/file-casing/src/Consume.mjs b/rewatch/testrepo/packages/file-casing/src/Consume.mjs index 68f3c4874b..0603a732aa 100644 --- a/rewatch/testrepo/packages/file-casing/src/Consume.mjs +++ b/rewatch/testrepo/packages/file-casing/src/Consume.mjs @@ -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, diff --git a/rewatch/testrepo/rescript.json b/rewatch/testrepo/rescript.json index 008a339de5..ae437e38dd 100644 --- a/rewatch/testrepo/rescript.json +++ b/rewatch/testrepo/rescript.json @@ -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" ] } diff --git a/rewatch/testrepo/yarn.lock b/rewatch/testrepo/yarn.lock index 8317e98114..808197041f 100644 --- a/rewatch/testrepo/yarn.lock +++ b/rewatch/testrepo/yarn.lock @@ -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" diff --git a/rewatch/tests/format.sh b/rewatch/tests/format.sh index 6520a33a42..ccfef0f4e4 100755 --- a/rewatch/tests/format.sh +++ b/rewatch/tests/format.sh @@ -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 diff --git a/rewatch/tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt b/rewatch/tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt index 612ef06fad..9df0205a5d 100644 --- a/rewatch/tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt +++ b/rewatch/tests/snapshots/bs-dev-dependency-used-by-non-dev-source.txt @@ -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. diff --git a/rewatch/tests/snapshots/dependency-cycle.txt b/rewatch/tests/snapshots/dependency-cycle.txt index fc917ef90a..cc25fb9c92 100644 --- a/rewatch/tests/snapshots/dependency-cycle.txt +++ b/rewatch/tests/snapshots/dependency-cycle.txt @@ -1,4 +1,4 @@ -Cleaned 0/56 +Cleaned 0/60 Parsed 1 source files Compiled 0 modules diff --git a/rewatch/tests/snapshots/remove-file.txt b/rewatch/tests/snapshots/remove-file.txt index 44af3f1f88..a19c44e596 100644 --- a/rewatch/tests/snapshots/remove-file.txt +++ b/rewatch/tests/snapshots/remove-file.txt @@ -1,4 +1,4 @@ -Cleaned 1/56 +Cleaned 1/60 Parsed 0 source files Compiled 1 modules diff --git a/rewatch/tests/snapshots/rename-file-internal-dep-namespace.txt b/rewatch/tests/snapshots/rename-file-internal-dep-namespace.txt index 081e01497b..d42004a89d 100644 --- a/rewatch/tests/snapshots/rename-file-internal-dep-namespace.txt +++ b/rewatch/tests/snapshots/rename-file-internal-dep-namespace.txt @@ -1,5 +1,7 @@ -Cleaned 2/56 +Cleaned 2/60 Parsed 2 source files +[rewatch] Copying file InternalDep to ocaml build path +[rewatch] Copying file Other_module2-@NewNamespace to ocaml build path Compiled 3 modules The field 'bs-dependencies' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version. diff --git a/rewatch/tests/snapshots/rename-file-internal-dep.txt b/rewatch/tests/snapshots/rename-file-internal-dep.txt index fb5ccbd7b3..d74a045181 100644 --- a/rewatch/tests/snapshots/rename-file-internal-dep.txt +++ b/rewatch/tests/snapshots/rename-file-internal-dep.txt @@ -1,5 +1,6 @@ -Cleaned 2/56 +Cleaned 2/60 Parsed 2 source files +[rewatch] Copying file InternalDep2 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. diff --git a/rewatch/tests/snapshots/rename-file-with-interface.txt b/rewatch/tests/snapshots/rename-file-with-interface.txt index 002228c2af..3e014015b5 100644 --- a/rewatch/tests/snapshots/rename-file-with-interface.txt +++ b/rewatch/tests/snapshots/rename-file-with-interface.txt @@ -1,6 +1,8 @@  No implementation file found for interface file (skipping): src/ModuleWithInterface.resi -Cleaned 2/56 +Cleaned 2/60 Parsed 1 source files +[rewatch] Copying file ModuleWithInterface2 to ocaml build path +[rewatch] Copying file Main 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. diff --git a/rewatch/tests/snapshots/rename-file.txt b/rewatch/tests/snapshots/rename-file.txt index 4b0a9ca875..b2461d5e2b 100644 --- a/rewatch/tests/snapshots/rename-file.txt +++ b/rewatch/tests/snapshots/rename-file.txt @@ -1,5 +1,6 @@ -Cleaned 1/56 +Cleaned 1/60 Parsed 1 source files +[rewatch] Copying file Main2 to ocaml build path Compiled 1 modules The field 'bs-dependencies' found in the package config of '@testrepo/deprecated-config' is deprecated and will be removed in a future version. diff --git a/rewatch/tests/snapshots/rename-interface-file.txt b/rewatch/tests/snapshots/rename-interface-file.txt index a0da89ae4b..41549a4a22 100644 --- a/rewatch/tests/snapshots/rename-interface-file.txt +++ b/rewatch/tests/snapshots/rename-interface-file.txt @@ -1,6 +1,8 @@  No implementation file found for interface file (skipping): src/ModuleWithInterface2.resi -Cleaned 1/56 +Cleaned 1/60 Parsed 1 source files +[rewatch] Copying file ModuleWithInterface to ocaml build path +[rewatch] Copying file Dep02 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. diff --git a/rewatch/tests/suffix.sh b/rewatch/tests/suffix.sh index 4586fcb05a..aa67fcfde9 100755 --- a/rewatch/tests/suffix.sh +++ b/rewatch/tests/suffix.sh @@ -31,7 +31,7 @@ fi # Count files with new extension file_count=$(find ./packages -name *.res.js | wc -l) -if [ "$file_count" -eq 28 ]; +if [ "$file_count" -eq 36 ]; then success "Found files with correct suffix" else