diff --git a/src/build.rs b/src/build.rs index 48a1c88..851f8c3 100644 --- a/src/build.rs +++ b/src/build.rs @@ -1285,10 +1285,13 @@ pub fn build(filter: &Option, path: &str, no_timing: bool) -> Resu let mut compiled_modules = AHashSet::::new(); let dirty_modules = build_state .modules - .iter() + .iter_mut() .filter_map(|(module_name, module)| { if module.compile_dirty { Some(module_name.to_owned()) + } else if !module.deps.is_disjoint(&deleted_module_names) { + module.compile_dirty = true; + Some(module_name.to_owned()) } else { None } diff --git a/tests/compile.sh b/tests/compile.sh index d0f3ff6..955e1a4 100755 --- a/tests/compile.sh +++ b/tests/compile.sh @@ -1,3 +1,4 @@ +cd $(dirname $0) source "./utils.sh" cd ../testrepo @@ -43,6 +44,14 @@ rewatch build --no-timing=true &> ../tests/snapshots/rename-file-with-interface. mv ./packages/main/src/ModuleWithInterface2.res ./packages/main/src/ModuleWithInterface.res rewatch build &> /dev/null +# when deleting a file that other files depend on, the compile should fail +rm packages/dep02/src/Dep02.res +rewatch build --no-timing=true &> ../tests/snapshots/remove-file.txt +# replace the absolute path so the snapshot is the same on all machines +replace "s/$(pwd | sed "s/\//\\\\\//g")//g" ../tests/snapshots/remove-file.txt +git checkout -- packages/dep02/src/Dep02.res +rewatch build &> /dev/null + # make sure we don't have changes in the test repo if git diff --exit-code ./; then @@ -72,6 +81,15 @@ then success "Snapshots are correct" else error "Snapshots are incorrect:" - printf "${changed_snapshots}\n" + # print filenames in the snapshot dir call bold with the filename + # and then cat their contents + printf "\n\n" + for file in $changed_snapshots; do + bold $file + # show diff of file vs contents in git + git diff $file $file + printf "\n\n" + done + exit 1 fi \ No newline at end of file diff --git a/tests/snapshots/remove-file.txt b/tests/snapshots/remove-file.txt new file mode 100644 index 0000000..c686ce9 --- /dev/null +++ b/tests/snapshots/remove-file.txt @@ -0,0 +1,23 @@ +[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] ๐Ÿงน Cleaning up previous build... [3/7] ๏ธโœ… Cleaned 1/9 0.00s + [4/7] ๏ธโœ… Parsed 0 source files in 0.00s + [5/7] ๏ธโœ… Collected deps in 0.00s + [6/7] ๏ธ๐Ÿ›‘ Compiled 2 modules in 0.00s + + We've found a bug for you! + /packages/dep01/src/Dep01.res:3:9-17 + + 1 โ”‚ let log = () => { + 2 โ”‚ Js.log("02") + 3 โ”‚ Dep02.log() + 4 โ”‚ } + 5 โ”‚ + + The module or file Dep02 can't be found. + - If it's a third-party dependency: + - Did you list it in bsconfig.json? + - Did you run `rescript build` instead of `rescript build -with-deps` + (latter builds third-parties)? + - Did you include the file's directory in bsconfig.json? + diff --git a/tests/utils.sh b/tests/utils.sh index d4a8957..0d04b1b 100644 --- a/tests/utils.sh +++ b/tests/utils.sh @@ -3,4 +3,13 @@ overwrite() { echo -e "\r\033[1A\033[0K$@"; } success() { echo -e "- โœ… \033[32m$1\033[0m"; } error() { echo -e "- ๐Ÿ›‘ \033[31m$1\033[0m"; } bold() { echo -e "\033[1m$1\033[0m"; } -rewatch() { RUST_BACKTRACE=1 ../target/release/rewatch --no-timing=true $1; } \ No newline at end of file +rewatch() { RUST_BACKTRACE=1 ../target/release/rewatch --no-timing=true $1; } + +replace() { + if [[ $OSTYPE == 'darwin'* ]]; + then + sed -i '' $1 $2; + else + sed -i $1 $2; + fi +} \ No newline at end of file diff --git a/tests/watch.sh b/tests/watch.sh index 338135b..20546d8 100755 --- a/tests/watch.sh +++ b/tests/watch.sh @@ -3,15 +3,6 @@ cd ../testrepo bold "Test: It should watch" -replace() { - if [[ $OSTYPE == 'darwin'* ]]; - then - sed -i '' $1 $2; - else - sed -i $1 $2; - fi -} - if rewatch clean &> /dev/null; then success "Repo Cleaned"