diff --git a/src/build/clean.rs b/src/build/clean.rs index e4bde12a..f4e3c1c5 100644 --- a/src/build/clean.rs +++ b/src/build/clean.rs @@ -237,10 +237,11 @@ pub fn cleanup_previous_build( .map(|module_name| { // if the module is a namespace, we need to mark the whole namespace as dirty when a module has been deleted if let Some(namespace) = helpers::get_namespace_from_module_name(module_name) { - return namespace; + return vec![namespace, module_name.to_string()]; } - module_name.to_string() + vec![module_name.to_string()] }) + .flatten() .collect::>(); build_state.deleted_modules = deleted_module_names; diff --git a/src/build/deps.rs b/src/build/deps.rs index dad31311..5bd19395 100644 --- a/src/build/deps.rs +++ b/src/build/deps.rs @@ -44,7 +44,8 @@ fn get_dep_modules( _ => dep_first, }; let namespaced_name = dep.to_owned() + "-" + namespace; - if package_modules.contains(&namespaced_name) { + if package_modules.contains(&namespaced_name) || valid_modules.contains(&namespaced_name) + { namespaced_name } else { dep.to_string() diff --git a/testrepo/packages/main/src/InternalDep.mjs b/testrepo/packages/main/src/InternalDep.mjs new file mode 100644 index 00000000..29e1467c --- /dev/null +++ b/testrepo/packages/main/src/InternalDep.mjs @@ -0,0 +1,9 @@ +// Generated by ReScript, PLEASE EDIT WITH CARE + + +var value = 1; + +export { + value , +} +/* No side effect */ diff --git a/testrepo/packages/main/src/InternalDep.res b/testrepo/packages/main/src/InternalDep.res new file mode 100644 index 00000000..3c37c33b --- /dev/null +++ b/testrepo/packages/main/src/InternalDep.res @@ -0,0 +1 @@ +let value = 1 diff --git a/testrepo/packages/main/src/Main.mjs b/testrepo/packages/main/src/Main.mjs index 887a8e63..fab942be 100644 --- a/testrepo/packages/main/src/Main.mjs +++ b/testrepo/packages/main/src/Main.mjs @@ -1,11 +1,14 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Dep01 from "@testrepo/dep01/src/Dep01.mjs"; +import * as InternalDep from "./InternalDep.mjs"; console.log("01"); Dep01.log(); +console.log(InternalDep.value); + var $$Array; var $$String; diff --git a/testrepo/packages/main/src/Main.res b/testrepo/packages/main/src/Main.res index 6b435d95..619e734d 100644 --- a/testrepo/packages/main/src/Main.res +++ b/testrepo/packages/main/src/Main.res @@ -1,5 +1,7 @@ Js.log("01") Dep01.log() +Js.log(InternalDep.value) + module Array = Belt.Array module String = Js.String diff --git a/testrepo/packages/main/src/output.txt b/testrepo/packages/main/src/output.txt index 75714967..821eb9c3 100644 --- a/testrepo/packages/main/src/output.txt +++ b/testrepo/packages/main/src/output.txt @@ -4,3 +4,4 @@ Hello world 02 a b +1 diff --git a/tests/compile.sh b/tests/compile.sh index 2b7173ee..2697d274 100755 --- a/tests/compile.sh +++ b/tests/compile.sh @@ -8,24 +8,24 @@ bold "Test: It should compile" if rewatch clean &> /dev/null; then success "Repo Cleaned" -else +else error "Error Cleaning Repo" exit 1 fi -if rewatch &> /dev/null; +if rewatch &> /dev/null; then success "Repo Built" -else +else error "Error Building Repo" exit 1 fi -if git diff --exit-code ./; +if git diff --exit-code ./; then success "Testrepo has no changes" -else +else error "Build has changed" exit 1 fi @@ -35,6 +35,21 @@ node ./packages/main/src/Main.mjs > ./packages/main/src/output.txt mv ./packages/main/src/Main.res ./packages/main/src/Main2.res rewatch build --no-timing=true &> ../tests/snapshots/rename-file.txt mv ./packages/main/src/Main2.res ./packages/main/src/Main.res + +# Rename a file with a dependent - this should trigger an error +mv ./packages/main/src/InternalDep.res ./packages/main/src/InternalDep2.res +rewatch build --no-timing=true &> ../tests/snapshots/rename-file-internal-dep.txt +# replace the absolute path so the snapshot is the same on all machines +replace "s/$(pwd | sed "s/\//\\\\\//g")//g" ../tests/snapshots/rename-file-internal-dep.txt +mv ./packages/main/src/InternalDep2.res ./packages/main/src/InternalDep.res + +# Rename a file with a dependent in a namespaced package - this should trigger an error (regression) +mv ./packages/new-namespace/src/Other_module.res ./packages/new-namespace/src/Other_module2.res +rewatch build --no-timing=true &> ../tests/snapshots/rename-file-internal-dep-namespace.txt +# replace the absolute path so the snapshot is the same on all machines +replace "s/$(pwd | sed "s/\//\\\\\//g")//g" ../tests/snapshots/rename-file-internal-dep-namespace.txt +mv ./packages/new-namespace/src/Other_module2.res ./packages/new-namespace/src/Other_module.res + rewatch build &> /dev/null mv ./packages/main/src/ModuleWithInterface.resi ./packages/main/src/ModuleWithInterface2.resi rewatch build --no-timing=true &> ../tests/snapshots/rename-interface-file.txt @@ -66,10 +81,10 @@ git checkout -- packages/new-namespace/src/NS_alias.res rewatch build &> /dev/null # make sure we don't have changes in the test repo -if git diff --exit-code ./; +if git diff --exit-code ./; then success "Output is correct" -else +else error "Output is incorrect" exit 1 fi @@ -81,7 +96,7 @@ new_files=$(git ls-files --others --exclude-standard ./) if [[ $new_files = "" ]]; then success "No new files created" -else +else error "โŒ - New files created" printf "${new_files}\n" exit 1 @@ -89,10 +104,10 @@ fi # see if the snapshots have changed changed_snapshots=$(git ls-files --modified ../tests/snapshots) -if git diff --exit-code ../tests/snapshots &> /dev/null; +if git diff --exit-code ../tests/snapshots &> /dev/null; then success "Snapshots are correct" -else +else error "Snapshots are incorrect:" # print filenames in the snapshot dir call bold with the filename # and then cat their contents @@ -105,4 +120,4 @@ else done exit 1 -fi \ No newline at end of file +fi diff --git a/tests/snapshots/dependency-cycle.txt b/tests/snapshots/dependency-cycle.txt index 10c4e559..ff0f93b5 100644 --- a/tests/snapshots/dependency-cycle.txt +++ b/tests/snapshots/dependency-cycle.txt @@ -1,7 +1,7 @@ [1/7]๐Ÿ“ฆ Building package tree... [1/7] ๐Ÿ“ฆ Built package tree in 0.00s [2/7] ๐Ÿ•ต๏ธ Finding source files... [2/7] ๐Ÿ•ต๏ธ Found source files in 0.00s [3/7] ๐Ÿ“ Reading compile state... [3/7] ๐Ÿ“ Read compile state 0.00s -[4/7] ๐Ÿงน Cleaning up previous build... [4/7] ๐Ÿงน Cleaned 0/10 0.00s +[4/7] ๐Ÿงน Cleaning up previous build... [4/7] ๐Ÿงน Cleaned 0/11 0.00s  [5/7] ๐Ÿงฑ Parsed 1 source files in 0.00s  [6/7] ๏ธ๐ŸŒด Collected deps in 0.00s  [7/7] ๏ธ๐Ÿ›‘ Compiled 0 modules in 0.00s diff --git a/tests/snapshots/remove-file.txt b/tests/snapshots/remove-file.txt index 228ef79c..08447639 100644 --- a/tests/snapshots/remove-file.txt +++ b/tests/snapshots/remove-file.txt @@ -1,7 +1,7 @@ [1/7]๐Ÿ“ฆ Building package tree... [1/7] ๐Ÿ“ฆ Built package tree in 0.00s [2/7] ๐Ÿ•ต๏ธ Finding source files... [2/7] ๐Ÿ•ต๏ธ Found source files in 0.00s [3/7] ๐Ÿ“ Reading compile state... [3/7] ๐Ÿ“ Read compile state 0.00s -[4/7] ๐Ÿงน Cleaning up previous build... [4/7] ๐Ÿงน Cleaned 1/10 0.00s +[4/7] ๐Ÿงน Cleaning up previous build... [4/7] ๐Ÿงน Cleaned 1/11 0.00s  [5/7] ๐Ÿงฑ Parsed 0 source files in 0.00s  [6/7] ๏ธ๐ŸŒด Collected deps in 0.00s  [7/7] ๏ธ๐Ÿ›‘ Compiled 1 modules in 0.00s diff --git a/tests/snapshots/rename-file-internal-dep-namespace.txt b/tests/snapshots/rename-file-internal-dep-namespace.txt new file mode 100644 index 00000000..5230dcfb --- /dev/null +++ b/tests/snapshots/rename-file-internal-dep-namespace.txt @@ -0,0 +1,24 @@ +[1/7]๐Ÿ“ฆ Building package tree... [1/7] ๐Ÿ“ฆ Built package tree in 0.00s +[2/7] ๐Ÿ•ต๏ธ Finding source files... [2/7] ๐Ÿ•ต๏ธ Found source files in 0.00s +[3/7] ๐Ÿ“ Reading compile state... [3/7] ๐Ÿ“ Read compile state 0.00s +[4/7] ๐Ÿงน Cleaning up previous build... [4/7] ๐Ÿงน Cleaned 2/11 0.00s + [5/7] ๐Ÿงฑ Parsed 2 source files in 0.00s + [6/7] ๏ธ๐ŸŒด Collected deps in 0.00s + [7/7] ๏ธ๐Ÿ›‘ Compiled 3 modules in 0.00s + + We've found a bug for you! + /packages/new-namespace/src/NS_alias.res:2:1-16 + + 1 โ”‚ let hello_world = () => "Hello world" + 2 โ”‚ Other_module.bla() + 3 โ”‚ + + The module or file Other_module can't be found. + - If it's a third-party dependency: + - Did you add it to the "bs-dependencies" or "bs-dev-dependencies" in bsconfig.json? + - Did you include the file's directory to the "sources" in bsconfig.json? + + + Hint: Did you mean Other_module2? + +Error Building:  ๏ธ๐Ÿ›‘ Error Running Incremental Build:  ๏ธ๐Ÿ›‘ Failed to Compile. See Errors Above diff --git a/tests/snapshots/rename-file-internal-dep.txt b/tests/snapshots/rename-file-internal-dep.txt new file mode 100644 index 00000000..c22caa42 --- /dev/null +++ b/tests/snapshots/rename-file-internal-dep.txt @@ -0,0 +1,24 @@ +[1/7]๐Ÿ“ฆ Building package tree... [1/7] ๐Ÿ“ฆ Built package tree in 0.00s +[2/7] ๐Ÿ•ต๏ธ Finding source files... [2/7] ๐Ÿ•ต๏ธ Found source files in 0.00s +[3/7] ๐Ÿ“ Reading compile state... [3/7] ๐Ÿ“ Read compile state 0.00s +[4/7] ๐Ÿงน Cleaning up previous build... [4/7] ๐Ÿงน Cleaned 2/11 0.00s + [5/7] ๐Ÿงฑ Parsed 2 source files in 0.00s + [6/7] ๏ธ๐ŸŒด Collected deps in 0.00s + [7/7] ๏ธ๐Ÿ›‘ Compiled 2 modules in 0.00s + + We've found a bug for you! + /packages/main/src/Main.res:4:8-24 + + 2 โ”‚ Dep01.log() + 3 โ”‚ + 4 โ”‚ Js.log(InternalDep.value) + 5 โ”‚ + 6 โ”‚ module Array = Belt.Array + + The module or file InternalDep can't be found. + - If it's a third-party dependency: + - Did you add it to the "bs-dependencies" or "bs-dev-dependencies" in bsconfig.json? + - Did you include the file's directory to the "sources" in bsconfig.json? + + +Error Building:  ๏ธ๐Ÿ›‘ Error Running Incremental Build:  ๏ธ๐Ÿ›‘ Failed to Compile. See Errors Above diff --git a/tests/snapshots/rename-file-with-interface.txt b/tests/snapshots/rename-file-with-interface.txt index e16ce550..30534637 100644 --- a/tests/snapshots/rename-file-with-interface.txt +++ b/tests/snapshots/rename-file-with-interface.txt @@ -2,7 +2,7 @@ [2/7] ๐Ÿ•ต๏ธ Finding source files... Warning: No implementation file found for interface file (skipping): src/ModuleWithInterface.resi  [2/7] ๐Ÿ•ต๏ธ Found source files in 0.00s [3/7] ๐Ÿ“ Reading compile state... [3/7] ๐Ÿ“ Read compile state 0.00s -[4/7] ๐Ÿงน Cleaning up previous build... [4/7] ๐Ÿงน Cleaned 2/10 0.00s +[4/7] ๐Ÿงน Cleaning up previous build... [4/7] ๐Ÿงน Cleaned 2/11 0.00s  [5/7] ๐Ÿงฑ Parsed 1 source files in 0.00s  [6/7] ๏ธ๐ŸŒด Collected deps in 0.00s  [7/7] ๐Ÿคบ ๏ธCompiled 1 modules in 0.00s diff --git a/tests/snapshots/rename-file.txt b/tests/snapshots/rename-file.txt index 68d3ebf1..43550cc6 100644 --- a/tests/snapshots/rename-file.txt +++ b/tests/snapshots/rename-file.txt @@ -1,7 +1,7 @@ [1/7]๐Ÿ“ฆ Building package tree... [1/7] ๐Ÿ“ฆ Built package tree in 0.00s [2/7] ๐Ÿ•ต๏ธ Finding source files... [2/7] ๐Ÿ•ต๏ธ Found source files in 0.00s [3/7] ๐Ÿ“ Reading compile state... [3/7] ๐Ÿ“ Read compile state 0.00s -[4/7] ๐Ÿงน Cleaning up previous build... [4/7] ๐Ÿงน Cleaned 1/10 0.00s +[4/7] ๐Ÿงน Cleaning up previous build... [4/7] ๐Ÿงน Cleaned 1/11 0.00s  [5/7] ๐Ÿงฑ Parsed 1 source files in 0.00s  [6/7] ๏ธ๐ŸŒด Collected deps in 0.00s  [7/7] ๐Ÿคบ ๏ธCompiled 1 modules in 0.00s diff --git a/tests/snapshots/rename-interface-file.txt b/tests/snapshots/rename-interface-file.txt index d9805848..a46d80f6 100644 --- a/tests/snapshots/rename-interface-file.txt +++ b/tests/snapshots/rename-interface-file.txt @@ -2,7 +2,7 @@ [2/7] ๐Ÿ•ต๏ธ Finding source files... Warning: No implementation file found for interface file (skipping): src/ModuleWithInterface2.resi  [2/7] ๐Ÿ•ต๏ธ Found source files in 0.00s [3/7] ๐Ÿ“ Reading compile state... [3/7] ๐Ÿ“ Read compile state 0.00s -[4/7] ๐Ÿงน Cleaning up previous build... [4/7] ๐Ÿงน Cleaned 1/10 0.00s +[4/7] ๐Ÿงน Cleaning up previous build... [4/7] ๐Ÿงน Cleaned 1/11 0.00s  [5/7] ๐Ÿงฑ Parsed 1 source files in 0.00s  [6/7] ๏ธ๐ŸŒด Collected deps in 0.00s  [7/7] ๐Ÿคบ ๏ธCompiled 1 modules in 0.00s diff --git a/tests/suffix.sh b/tests/suffix.sh index a7fe9787..6790d99f 100755 --- a/tests/suffix.sh +++ b/tests/suffix.sh @@ -8,7 +8,7 @@ sleep 1 if rewatch clean &> /dev/null; then success "Repo Cleaned" -else +else error "Error Cleaning Repo" exit 1 fi @@ -19,7 +19,7 @@ replace "s/.mjs/.res.js/g" bsconfig.json if rewatch build &> /dev/null; then success "Repo Built" -else +else error "Error building repo" exit 1 fi @@ -27,10 +27,10 @@ fi # Count files with new extension file_count=$(find . -name *.res.js | wc -l) -if [ "$file_count" -eq 9 ]; +if [ "$file_count" -eq 10 ]; then success "Found files with correct suffix" -else +else error "Suffix not correctly used" exit 1 fi @@ -38,7 +38,7 @@ fi if rewatch clean &> /dev/null; then success "Repo Cleaned" -else +else error "Error Cleaning Repo" exit 1 fi @@ -50,7 +50,7 @@ replace "s/.res.js/.mjs/g" bsconfig.json if rewatch build &> /dev/null; then success "Repo Built" -else +else error "Error building repo" exit 1 fi