Skip to content

Commit a027302

Browse files
committed
Do not shadow resovle_bs_package
1 parent d18ba7c commit a027302

File tree

3 files changed

+69
-81
lines changed

3 files changed

+69
-81
lines changed

jscomp/bsb/bsb_pkg.ml

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -82,25 +82,6 @@ let cache : string Coll.t = Coll.create 0
8282
let to_list cb =
8383
Coll.to_list cache cb
8484

85-
(** TODO: collect all warnings and print later *)
86-
let resolve_bs_package ~cwd (package : t) =
87-
match Coll.find_opt cache package with
88-
| None ->
89-
let result = resolve_bs_package_aux ~cwd package in
90-
Bsb_log.info "@{<info>Package@} %a -> %s@." Bsb_pkg_types.print package result ;
91-
Coll.add cache package result ;
92-
result
93-
| Some x
94-
->
95-
let result = resolve_bs_package_aux ~cwd package in
96-
if result <> x then
97-
begin
98-
Bsb_log.warn
99-
"@{<warning>Duplicated package:@} %a %s (chosen) vs %s in %s @."
100-
Bsb_pkg_types.print package x result cwd;
101-
end;
102-
x
103-
10485
(* Some package managers will implement "postinstall" caches, that do not
10586
* keep their build artifacts in the local node_modules. Similar to
10687
* npm_config_prefix, bs_custom_resolution allows these to specify the
@@ -125,41 +106,56 @@ let pkg_name_as_variable pkg =
125106
|> Str.global_replace regex_dot "__dot__"
126107
|> Str.global_replace regex_hyphen "_"
127108

128-
let resolve_bs_package ~cwd (pkg : t) =
109+
let resolve_bs_package ~cwd (package : t) =
129110
if custom_resolution () then
130111
begin
131112
Bsb_log.info "@{<info>Using Custom Resolution@}@.";
132-
let custom_pkg_loc = pkg_name_as_variable pkg ^ "__install" in
113+
let custom_pkg_loc = pkg_name_as_variable package ^ "__install" in
133114
match Sys.getenv custom_pkg_loc with
134115
| exception Not_found ->
135116
begin
136117
Bsb_log.error
137118
"@{<error>Custom resolution of package %s does not exist in var %s @}@."
138-
(Bsb_pkg_types.to_string pkg)
119+
(Bsb_pkg_types.to_string package)
139120
custom_pkg_loc;
140-
Bsb_exception.package_not_found ~pkg ~json:None
121+
Bsb_exception.package_not_found ~pkg:package ~json:None
141122
end
142123
| path when not (Sys.file_exists path) ->
143124
begin
144125
Bsb_log.error
145126
"@{<error>Custom resolution of package %s does not exist on disk: %s=%s @}@."
146-
(Bsb_pkg_types.to_string pkg)
127+
(Bsb_pkg_types.to_string package)
147128
custom_pkg_loc
148129
path;
149-
Bsb_exception.package_not_found ~pkg ~json:None
130+
Bsb_exception.package_not_found ~pkg:package ~json:None
150131
end
151132
| path ->
152133
begin
153134
Bsb_log.info
154135
"@{<info>Custom Resolution of package %s in var %s found at %s@}@."
155-
(Bsb_pkg_types.to_string pkg)
136+
(Bsb_pkg_types.to_string package)
156137
custom_pkg_loc
157138
path;
158139
path
159140
end
160141
end
161142
else
162-
resolve_bs_package ~cwd pkg
143+
match Coll.find_opt cache package with
144+
| None ->
145+
let result = resolve_bs_package_aux ~cwd package in
146+
Bsb_log.info "@{<info>Package@} %a -> %s@." Bsb_pkg_types.print package result ;
147+
Coll.add cache package result ;
148+
result
149+
| Some x
150+
->
151+
let result = resolve_bs_package_aux ~cwd package in
152+
if result <> x then
153+
begin
154+
Bsb_log.warn
155+
"@{<warning>Duplicated package:@} %a %s (chosen) vs %s in %s @."
156+
Bsb_pkg_types.print package x result cwd;
157+
end;
158+
x
163159

164160

165161
(** The package does not need to be a bspackage

lib/4.02.3/bsb.ml

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8547,25 +8547,6 @@ let cache : string Coll.t = Coll.create 0
85478547

85488548
let to_list cb =
85498549
Coll.to_list cache cb
8550-
8551-
(** TODO: collect all warnings and print later *)
8552-
let resolve_bs_package ~cwd (package : t) =
8553-
match Coll.find_opt cache package with
8554-
| None ->
8555-
let result = resolve_bs_package_aux ~cwd package in
8556-
Bsb_log.info "@{<info>Package@} %a -> %s@." Bsb_pkg_types.print package result ;
8557-
Coll.add cache package result ;
8558-
result
8559-
| Some x
8560-
->
8561-
let result = resolve_bs_package_aux ~cwd package in
8562-
if result <> x then
8563-
begin
8564-
Bsb_log.warn
8565-
"@{<warning>Duplicated package:@} %a %s (chosen) vs %s in %s @."
8566-
Bsb_pkg_types.print package x result cwd;
8567-
end;
8568-
x
85698550

85708551
(* Some package managers will implement "postinstall" caches, that do not
85718552
* keep their build artifacts in the local node_modules. Similar to
@@ -8591,41 +8572,56 @@ let pkg_name_as_variable pkg =
85918572
|> Str.global_replace regex_dot "__dot__"
85928573
|> Str.global_replace regex_hyphen "_"
85938574

8594-
let resolve_bs_package ~cwd (pkg : t) =
8575+
let resolve_bs_package ~cwd (package : t) =
85958576
if custom_resolution () then
85968577
begin
85978578
Bsb_log.info "@{<info>Using Custom Resolution@}@.";
8598-
let custom_pkg_loc = pkg_name_as_variable pkg ^ "__install" in
8579+
let custom_pkg_loc = pkg_name_as_variable package ^ "__install" in
85998580
match Sys.getenv custom_pkg_loc with
86008581
| exception Not_found ->
86018582
begin
86028583
Bsb_log.error
86038584
"@{<error>Custom resolution of package %s does not exist in var %s @}@."
8604-
(Bsb_pkg_types.to_string pkg)
8585+
(Bsb_pkg_types.to_string package)
86058586
custom_pkg_loc;
8606-
Bsb_exception.package_not_found ~pkg ~json:None
8587+
Bsb_exception.package_not_found ~pkg:package ~json:None
86078588
end
86088589
| path when not (Sys.file_exists path) ->
86098590
begin
86108591
Bsb_log.error
86118592
"@{<error>Custom resolution of package %s does not exist on disk: %s=%s @}@."
8612-
(Bsb_pkg_types.to_string pkg)
8593+
(Bsb_pkg_types.to_string package)
86138594
custom_pkg_loc
86148595
path;
8615-
Bsb_exception.package_not_found ~pkg ~json:None
8596+
Bsb_exception.package_not_found ~pkg:package ~json:None
86168597
end
86178598
| path ->
86188599
begin
86198600
Bsb_log.info
86208601
"@{<info>Custom Resolution of package %s in var %s found at %s@}@."
8621-
(Bsb_pkg_types.to_string pkg)
8602+
(Bsb_pkg_types.to_string package)
86228603
custom_pkg_loc
86238604
path;
86248605
path
86258606
end
86268607
end
86278608
else
8628-
resolve_bs_package ~cwd pkg
8609+
match Coll.find_opt cache package with
8610+
| None ->
8611+
let result = resolve_bs_package_aux ~cwd package in
8612+
Bsb_log.info "@{<info>Package@} %a -> %s@." Bsb_pkg_types.print package result ;
8613+
Coll.add cache package result ;
8614+
result
8615+
| Some x
8616+
->
8617+
let result = resolve_bs_package_aux ~cwd package in
8618+
if result <> x then
8619+
begin
8620+
Bsb_log.warn
8621+
"@{<warning>Duplicated package:@} %a %s (chosen) vs %s in %s @."
8622+
Bsb_pkg_types.print package x result cwd;
8623+
end;
8624+
x
86298625

86308626

86318627

lib/4.06.1/bsb.ml

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8517,25 +8517,6 @@ let cache : string Coll.t = Coll.create 0
85178517

85188518
let to_list cb =
85198519
Coll.to_list cache cb
8520-
8521-
(** TODO: collect all warnings and print later *)
8522-
let resolve_bs_package ~cwd (package : t) =
8523-
match Coll.find_opt cache package with
8524-
| None ->
8525-
let result = resolve_bs_package_aux ~cwd package in
8526-
Bsb_log.info "@{<info>Package@} %a -> %s@." Bsb_pkg_types.print package result ;
8527-
Coll.add cache package result ;
8528-
result
8529-
| Some x
8530-
->
8531-
let result = resolve_bs_package_aux ~cwd package in
8532-
if result <> x then
8533-
begin
8534-
Bsb_log.warn
8535-
"@{<warning>Duplicated package:@} %a %s (chosen) vs %s in %s @."
8536-
Bsb_pkg_types.print package x result cwd;
8537-
end;
8538-
x
85398520

85408521
(* Some package managers will implement "postinstall" caches, that do not
85418522
* keep their build artifacts in the local node_modules. Similar to
@@ -8561,41 +8542,56 @@ let pkg_name_as_variable pkg =
85618542
|> Str.global_replace regex_dot "__dot__"
85628543
|> Str.global_replace regex_hyphen "_"
85638544

8564-
let resolve_bs_package ~cwd (pkg : t) =
8545+
let resolve_bs_package ~cwd (package : t) =
85658546
if custom_resolution () then
85668547
begin
85678548
Bsb_log.info "@{<info>Using Custom Resolution@}@.";
8568-
let custom_pkg_loc = pkg_name_as_variable pkg ^ "__install" in
8549+
let custom_pkg_loc = pkg_name_as_variable package ^ "__install" in
85698550
match Sys.getenv custom_pkg_loc with
85708551
| exception Not_found ->
85718552
begin
85728553
Bsb_log.error
85738554
"@{<error>Custom resolution of package %s does not exist in var %s @}@."
8574-
(Bsb_pkg_types.to_string pkg)
8555+
(Bsb_pkg_types.to_string package)
85758556
custom_pkg_loc;
8576-
Bsb_exception.package_not_found ~pkg ~json:None
8557+
Bsb_exception.package_not_found ~pkg:package ~json:None
85778558
end
85788559
| path when not (Sys.file_exists path) ->
85798560
begin
85808561
Bsb_log.error
85818562
"@{<error>Custom resolution of package %s does not exist on disk: %s=%s @}@."
8582-
(Bsb_pkg_types.to_string pkg)
8563+
(Bsb_pkg_types.to_string package)
85838564
custom_pkg_loc
85848565
path;
8585-
Bsb_exception.package_not_found ~pkg ~json:None
8566+
Bsb_exception.package_not_found ~pkg:package ~json:None
85868567
end
85878568
| path ->
85888569
begin
85898570
Bsb_log.info
85908571
"@{<info>Custom Resolution of package %s in var %s found at %s@}@."
8591-
(Bsb_pkg_types.to_string pkg)
8572+
(Bsb_pkg_types.to_string package)
85928573
custom_pkg_loc
85938574
path;
85948575
path
85958576
end
85968577
end
85978578
else
8598-
resolve_bs_package ~cwd pkg
8579+
match Coll.find_opt cache package with
8580+
| None ->
8581+
let result = resolve_bs_package_aux ~cwd package in
8582+
Bsb_log.info "@{<info>Package@} %a -> %s@." Bsb_pkg_types.print package result ;
8583+
Coll.add cache package result ;
8584+
result
8585+
| Some x
8586+
->
8587+
let result = resolve_bs_package_aux ~cwd package in
8588+
if result <> x then
8589+
begin
8590+
Bsb_log.warn
8591+
"@{<warning>Duplicated package:@} %a %s (chosen) vs %s in %s @."
8592+
Bsb_pkg_types.print package x result cwd;
8593+
end;
8594+
x
85998595

86008596

86018597

0 commit comments

Comments
 (0)