Skip to content

Commit f406559

Browse files
authored
🐛 - Fix rename bug inside of a namespace (#117)
1 parent d1efa2f commit f406559

16 files changed

+106
-25
lines changed

src/build/clean.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,11 @@ pub fn cleanup_previous_build(
237237
.map(|module_name| {
238238
// if the module is a namespace, we need to mark the whole namespace as dirty when a module has been deleted
239239
if let Some(namespace) = helpers::get_namespace_from_module_name(module_name) {
240-
return namespace;
240+
return vec![namespace, module_name.to_string()];
241241
}
242-
module_name.to_string()
242+
vec![module_name.to_string()]
243243
})
244+
.flatten()
244245
.collect::<AHashSet<String>>();
245246

246247
build_state.deleted_modules = deleted_module_names;

src/build/deps.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ fn get_dep_modules(
4444
_ => dep_first,
4545
};
4646
let namespaced_name = dep.to_owned() + "-" + namespace;
47-
if package_modules.contains(&namespaced_name) {
47+
if package_modules.contains(&namespaced_name) || valid_modules.contains(&namespaced_name)
48+
{
4849
namespaced_name
4950
} else {
5051
dep.to_string()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Generated by ReScript, PLEASE EDIT WITH CARE
2+
3+
4+
var value = 1;
5+
6+
export {
7+
value ,
8+
}
9+
/* No side effect */
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let value = 1

testrepo/packages/main/src/Main.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

33
import * as Dep01 from "@testrepo/dep01/src/Dep01.mjs";
4+
import * as InternalDep from "./InternalDep.mjs";
45

56
console.log("01");
67

78
Dep01.log();
89

10+
console.log(InternalDep.value);
11+
912
var $$Array;
1013

1114
var $$String;

testrepo/packages/main/src/Main.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Js.log("01")
22
Dep01.log()
33

4+
Js.log(InternalDep.value)
5+
46
module Array = Belt.Array
57
module String = Js.String

testrepo/packages/main/src/output.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ Hello world
44
02
55
a
66
b
7+
1

tests/compile.sh

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ bold "Test: It should compile"
88
if rewatch clean &> /dev/null;
99
then
1010
success "Repo Cleaned"
11-
else
11+
else
1212
error "Error Cleaning Repo"
1313
exit 1
1414
fi
1515

16-
if rewatch &> /dev/null;
16+
if rewatch &> /dev/null;
1717
then
1818
success "Repo Built"
19-
else
19+
else
2020
error "Error Building Repo"
2121
exit 1
2222
fi
2323

2424

25-
if git diff --exit-code ./;
25+
if git diff --exit-code ./;
2626
then
2727
success "Testrepo has no changes"
28-
else
28+
else
2929
error "Build has changed"
3030
exit 1
3131
fi
@@ -35,6 +35,21 @@ node ./packages/main/src/Main.mjs > ./packages/main/src/output.txt
3535
mv ./packages/main/src/Main.res ./packages/main/src/Main2.res
3636
rewatch build --no-timing=true &> ../tests/snapshots/rename-file.txt
3737
mv ./packages/main/src/Main2.res ./packages/main/src/Main.res
38+
39+
# Rename a file with a dependent - this should trigger an error
40+
mv ./packages/main/src/InternalDep.res ./packages/main/src/InternalDep2.res
41+
rewatch build --no-timing=true &> ../tests/snapshots/rename-file-internal-dep.txt
42+
# replace the absolute path so the snapshot is the same on all machines
43+
replace "s/$(pwd | sed "s/\//\\\\\//g")//g" ../tests/snapshots/rename-file-internal-dep.txt
44+
mv ./packages/main/src/InternalDep2.res ./packages/main/src/InternalDep.res
45+
46+
# Rename a file with a dependent in a namespaced package - this should trigger an error (regression)
47+
mv ./packages/new-namespace/src/Other_module.res ./packages/new-namespace/src/Other_module2.res
48+
rewatch build --no-timing=true &> ../tests/snapshots/rename-file-internal-dep-namespace.txt
49+
# replace the absolute path so the snapshot is the same on all machines
50+
replace "s/$(pwd | sed "s/\//\\\\\//g")//g" ../tests/snapshots/rename-file-internal-dep-namespace.txt
51+
mv ./packages/new-namespace/src/Other_module2.res ./packages/new-namespace/src/Other_module.res
52+
3853
rewatch build &> /dev/null
3954
mv ./packages/main/src/ModuleWithInterface.resi ./packages/main/src/ModuleWithInterface2.resi
4055
rewatch build --no-timing=true &> ../tests/snapshots/rename-interface-file.txt
@@ -66,10 +81,10 @@ git checkout -- packages/new-namespace/src/NS_alias.res
6681
rewatch build &> /dev/null
6782

6883
# make sure we don't have changes in the test repo
69-
if git diff --exit-code ./;
84+
if git diff --exit-code ./;
7085
then
7186
success "Output is correct"
72-
else
87+
else
7388
error "Output is incorrect"
7489
exit 1
7590
fi
@@ -81,18 +96,18 @@ new_files=$(git ls-files --others --exclude-standard ./)
8196
if [[ $new_files = "" ]];
8297
then
8398
success "No new files created"
84-
else
99+
else
85100
error "❌ - New files created"
86101
printf "${new_files}\n"
87102
exit 1
88103
fi
89104

90105
# see if the snapshots have changed
91106
changed_snapshots=$(git ls-files --modified ../tests/snapshots)
92-
if git diff --exit-code ../tests/snapshots &> /dev/null;
107+
if git diff --exit-code ../tests/snapshots &> /dev/null;
93108
then
94109
success "Snapshots are correct"
95-
else
110+
else
96111
error "Snapshots are incorrect:"
97112
# print filenames in the snapshot dir call bold with the filename
98113
# and then cat their contents
@@ -105,4 +120,4 @@ else
105120
done
106121

107122
exit 1
108-
fi
123+
fi

tests/snapshots/dependency-cycle.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[1/7]📦 Building package tree...[1/7] 📦 Built package tree in 0.00s
22
[2/7] 🕵️ Finding source files...[2/7] 🕵️ Found source files in 0.00s
33
[3/7] 📝 Reading compile state...[3/7] 📝 Read compile state 0.00s
4-
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 0/10 0.00s
4+
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 0/11 0.00s
55
[5/7] 🧱 Parsed 1 source files in 0.00s
66
[6/7] ️🌴 Collected deps in 0.00s
77
[7/7] ️🛑 Compiled 0 modules in 0.00s

tests/snapshots/remove-file.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[1/7]📦 Building package tree...[1/7] 📦 Built package tree in 0.00s
22
[2/7] 🕵️ Finding source files...[2/7] 🕵️ Found source files in 0.00s
33
[3/7] 📝 Reading compile state...[3/7] 📝 Read compile state 0.00s
4-
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 1/10 0.00s
4+
[4/7] 🧹 Cleaning up previous build...[4/7] 🧹 Cleaned 1/11 0.00s
55
[5/7] 🧱 Parsed 0 source files in 0.00s
66
[6/7] ️🌴 Collected deps in 0.00s
77
[7/7] ️🛑 Compiled 1 modules in 0.00s

0 commit comments

Comments
 (0)