Skip to content

Commit

Permalink
🐛 - Fix marking modules that depend on deleted modules dirty
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrolich committed Jul 27, 2023
1 parent b4a64b0 commit ddd597f
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1285,10 +1285,13 @@ pub fn build(filter: &Option<regex::Regex>, path: &str, no_timing: bool) -> Resu
let mut compiled_modules = AHashSet::<String>::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
}
Expand Down
20 changes: 19 additions & 1 deletion tests/compile.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
cd $(dirname $0)
source "./utils.sh"
cd ../testrepo

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
23 changes: 23 additions & 0 deletions tests/snapshots/remove-file.txt
Original file line number Diff line number Diff line change
@@ -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?

Expand Down
11 changes: 10 additions & 1 deletion tests/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
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
}
9 changes: 0 additions & 9 deletions tests/watch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit ddd597f

Please sign in to comment.