Skip to content

Commit 369abba

Browse files
authored
Merge pull request #4045 from Coobaha/feat/duplicated-symlinks
Fix duplicated packages warning for same symlinked packages
2 parents dbb0780 + f292bfd commit 369abba

34 files changed

+428
-6
lines changed

jscomp/bsb/bsb_pkg.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ let resolve_bs_package ~cwd (package : t) =
151151
| Some x
152152
->
153153
let result = resolve_bs_package_aux ~cwd package in
154-
if result <> x then
154+
if not (Bsb_real_path.is_same_paths_via_io result x) then
155155
begin
156156
Bsb_log.warn
157157
"@{<warning>Duplicated package:@} %a %s (chosen) vs %s in %s @."

jscomp/bsb/bsb_real_path.ml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
let (//) = Filename.concat
2+
3+
let getchdir s =
4+
let p = Sys.getcwd () in
5+
Unix.chdir s;
6+
p
7+
8+
let normalize s = getchdir (getchdir s)
9+
10+
let real_path p =
11+
match (try Some (Sys.is_directory p) with Sys_error _ -> None) with
12+
| None ->
13+
let rec resolve dir =
14+
if Sys.file_exists dir then normalize dir else
15+
let parent = Filename.dirname dir in
16+
if dir = parent then dir
17+
else (resolve parent) // (Filename.basename dir)
18+
in
19+
let p =
20+
if Filename.is_relative p then (Sys.getcwd ()) // p
21+
else p
22+
in
23+
resolve p
24+
| Some true -> normalize p
25+
| Some false ->
26+
let dir = normalize (Filename.dirname p) in
27+
match Filename.basename p with
28+
| "." -> dir
29+
| base -> dir // base
30+
31+
32+
let is_same_paths_via_io a b =
33+
if a = b
34+
then true
35+
else (real_path a) = (real_path b)

jscomp/bsb/bsb_real_path.mli

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
val real_path : string -> string
2+
3+
val is_same_paths_via_io : string -> string -> bool
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.merlin
2+
**/lib
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
Special tests for duplicated symlink warnings
2+
3+
4+
```
5+
.
6+
├── a
7+
│   ├── node_modules
8+
│   │   ├── c -> ../../c
9+
│   │   └── z
10+
│   │   ├── lib
11+
│   │   │   ├── bs
12+
│   │   │   └── ocaml
13+
│   │   └── src
14+
│   └── src
15+
├── b
16+
│   ├── node_modules
17+
│   │   └── c -> ../../c
18+
│   └── src
19+
├── c
20+
│   └── src
21+
├── node_modules
22+
│   ├── a -> ../a
23+
│   ├── b -> ../b
24+
│   └── z
25+
│   └── src
26+
└── out.expected
27+
└── src
28+
29+
```
30+
31+
`c` is symlinked everywhere, while `z` is actually conflicting package.
32+
33+
`out.expected` has exactly 1 warning for `z` conflict
34+
35+
Run `node ./jscomp/build_tests/duplicated_symlinked_packages/input.js` to check the tests against previous snapshots.
36+
Run `node ./jscomp/build_tests/duplicated_symlinked_packages/input.js update` to update the snapshots (assuming you've made some changes to duplicated)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "a",
3+
"version": "0.1.0",
4+
"sources": {
5+
"dir" : "src",
6+
"subdirs" : true
7+
},
8+
"package-specs": {
9+
"module": "commonjs",
10+
"in-source": true
11+
},
12+
"suffix": ".bs.js",
13+
"bs-dependencies": [
14+
"c",
15+
"z"
16+
],
17+
"warnings": {
18+
"error" : "+101"
19+
},
20+
"namespace": true,
21+
"refmt": 3
22+
}

jscomp/build_tests/duplicated_symlinked_packages/a/node_modules/c

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/build_tests/duplicated_symlinked_packages/a/node_modules/z/bsconfig.json

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/build_tests/duplicated_symlinked_packages/a/node_modules/z/package.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/build_tests/duplicated_symlinked_packages/a/node_modules/z/src/.git_keep

Whitespace-only changes.

0 commit comments

Comments
 (0)