|
| 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" |
0 commit comments