Skip to content

Commit 39f1863

Browse files
Test cleaning same-named modules in separate packages
Build two non-namespaced dependencies independently and assert both Foo.mjs outputs exist before cleaning their common root. Check both outputs are removed so name-based module deduplication cannot silently leave a package behind. Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
1 parent 8bb7f0e commit 39f1863

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
set -e
3+
cd "$(dirname "$0")"
4+
source "../utils.sh"
5+
6+
bold "Test: Clean removes same-named modules from every package"
7+
8+
test_dir=$(pwd)
9+
fixture=$(mktemp -d)
10+
trap 'cd "$test_dir"; rm -rf "$fixture"' EXIT
11+
cd "$fixture"
12+
13+
node <<'NODE'
14+
const fs = require("fs");
15+
const config = name => ({
16+
name,
17+
sources: ["src"],
18+
namespace: false,
19+
"package-specs": {module: "esmodule", "in-source": true},
20+
suffix: ".mjs",
21+
});
22+
const dependencies = ["clean-duplicate-a", "clean-duplicate-b"];
23+
fs.mkdirSync("src");
24+
fs.writeFileSync("src/Main.res", "let value = 0\n");
25+
fs.writeFileSync("rescript.json", JSON.stringify({...config("clean-duplicates"), dependencies}));
26+
for (const [index, name] of dependencies.entries()) {
27+
const directory = `node_modules/${name}`;
28+
fs.mkdirSync(`${directory}/src`, {recursive: true});
29+
fs.writeFileSync(`${directory}/package.json`, JSON.stringify({name, version: "1.0.0"}));
30+
fs.writeFileSync(`${directory}/rescript.json`, JSON.stringify(config(name)));
31+
fs.writeFileSync(`${directory}/src/Foo.res`, `let value = ${index}\n`);
32+
}
33+
NODE
34+
35+
# Build separately so both packages have real output before root-level cleanup.
36+
for package in clean-duplicate-a clean-duplicate-b; do
37+
if ! output=$(cd "node_modules/$package" && rewatch build 2>&1); then
38+
error "Could not build $package"
39+
printf '%s\n' "$output" >&2
40+
exit 1
41+
fi
42+
if [ ! -f "node_modules/$package/src/Foo.mjs" ]; then
43+
error "Test setup did not produce $package/src/Foo.mjs"
44+
exit 1
45+
fi
46+
done
47+
48+
if ! output=$(rewatch clean 2>&1); then
49+
error "Could not clean packages with same-named modules"
50+
printf '%s\n' "$output" >&2
51+
exit 1
52+
fi
53+
54+
for package in clean-duplicate-a clean-duplicate-b; do
55+
if [ -f "node_modules/$package/src/Foo.mjs" ]; then
56+
error "Clean left $package/src/Foo.mjs behind"
57+
exit 1
58+
fi
59+
done
60+
61+
success "Same-named modules cleaned from both packages"

‎rewatch/tests/suite.sh‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ fi
164164
./clean/03-clean-node-modules.sh &&
165165
./clean/04-clean-rebuild-no-compiler-update.sh &&
166166
./clean/05-clean-invalid-module-graph.sh &&
167+
./clean/06-clean-duplicate-names-across-packages.sh &&
167168

168169
# Experimental tests
169170
./experimental/01-experimental-features-emit.sh &&

0 commit comments

Comments
 (0)