Skip to content

Commit eba0f1c

Browse files
committed
Make things lazy
1 parent 988adf2 commit eba0f1c

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

jscomp/bsb/bsb_pkg.ml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ let to_list cb =
8787
* npm_config_prefix, bs_custom_resolution allows these to specify the
8888
* exact location of build cache, but on a per-package basis. Implemented as
8989
* environment lookup to avoid invasive changes to bsconfig and mandates. *)
90-
let custom_resolution () =
91-
match Sys.getenv "bs_custom_resolution" with
90+
let custom_resolution = lazy
91+
(match Sys.getenv "bs_custom_resolution" with
9292
| exception Not_found -> false
9393
| "true" -> true
94-
| _ -> false
94+
| _ -> false)
95+
9596

9697
let regex_at = Str.regexp "@"
9798
let regex_unders = Str.regexp "_+"
@@ -108,11 +109,12 @@ let pkg_name_as_variable pkg =
108109

109110
(** TODO: collect all warnings and print later *)
110111
let resolve_bs_package ~cwd (package : t) =
111-
if custom_resolution () then
112+
if Lazy.force custom_resolution then
112113
begin
113114
Bsb_log.info "@{<info>Using Custom Resolution@}@.";
114115
let custom_pkg_loc = pkg_name_as_variable package ^ "__install" in
115-
match Sys.getenv custom_pkg_loc with
116+
let custom_pkg_location = lazy (Sys.getenv custom_pkg_loc) in
117+
match Lazy.force custom_pkg_location with
116118
| exception Not_found ->
117119
begin
118120
Bsb_log.error

lib/4.02.3/bsb.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8547,17 +8547,18 @@ let cache : string Coll.t = Coll.create 0
85478547

85488548
let to_list cb =
85498549
Coll.to_list cache cb
8550-
8550+
85518551
(* Some package managers will implement "postinstall" caches, that do not
85528552
* keep their build artifacts in the local node_modules. Similar to
85538553
* npm_config_prefix, bs_custom_resolution allows these to specify the
85548554
* exact location of build cache, but on a per-package basis. Implemented as
85558555
* environment lookup to avoid invasive changes to bsconfig and mandates. *)
8556-
let custom_resolution () =
8557-
match Sys.getenv "bs_custom_resolution" with
8556+
let custom_resolution = lazy
8557+
(match Sys.getenv "bs_custom_resolution" with
85588558
| exception Not_found -> false
85598559
| "true" -> true
8560-
| _ -> false
8560+
| _ -> false)
8561+
85618562

85628563
let regex_at = Str.regexp "@"
85638564
let regex_unders = Str.regexp "_+"
@@ -8574,11 +8575,12 @@ let pkg_name_as_variable pkg =
85748575

85758576
(** TODO: collect all warnings and print later *)
85768577
let resolve_bs_package ~cwd (package : t) =
8577-
if custom_resolution () then
8578+
if Lazy.force custom_resolution then
85788579
begin
85798580
Bsb_log.info "@{<info>Using Custom Resolution@}@.";
85808581
let custom_pkg_loc = pkg_name_as_variable package ^ "__install" in
8581-
match Sys.getenv custom_pkg_loc with
8582+
let custom_pkg_location = lazy (Sys.getenv custom_pkg_loc) in
8583+
match Lazy.force custom_pkg_location with
85828584
| exception Not_found ->
85838585
begin
85848586
Bsb_log.error
@@ -8625,7 +8627,6 @@ let resolve_bs_package ~cwd (package : t) =
86258627
x
86268628

86278629

8628-
86298630
(** The package does not need to be a bspackage
86308631
example:
86318632
{[

lib/4.06.1/bsb.ml

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8517,17 +8517,18 @@ let cache : string Coll.t = Coll.create 0
85178517

85188518
let to_list cb =
85198519
Coll.to_list cache cb
8520-
8520+
85218521
(* Some package managers will implement "postinstall" caches, that do not
85228522
* keep their build artifacts in the local node_modules. Similar to
85238523
* npm_config_prefix, bs_custom_resolution allows these to specify the
85248524
* exact location of build cache, but on a per-package basis. Implemented as
85258525
* environment lookup to avoid invasive changes to bsconfig and mandates. *)
8526-
let custom_resolution () =
8527-
match Sys.getenv "bs_custom_resolution" with
8526+
let custom_resolution = lazy
8527+
(match Sys.getenv "bs_custom_resolution" with
85288528
| exception Not_found -> false
85298529
| "true" -> true
8530-
| _ -> false
8530+
| _ -> false)
8531+
85318532

85328533
let regex_at = Str.regexp "@"
85338534
let regex_unders = Str.regexp "_+"
@@ -8544,11 +8545,12 @@ let pkg_name_as_variable pkg =
85448545

85458546
(** TODO: collect all warnings and print later *)
85468547
let resolve_bs_package ~cwd (package : t) =
8547-
if custom_resolution () then
8548+
if Lazy.force custom_resolution then
85488549
begin
85498550
Bsb_log.info "@{<info>Using Custom Resolution@}@.";
85508551
let custom_pkg_loc = pkg_name_as_variable package ^ "__install" in
8551-
match Sys.getenv custom_pkg_loc with
8552+
let custom_pkg_location = lazy (Sys.getenv custom_pkg_loc) in
8553+
match Lazy.force custom_pkg_location with
85528554
| exception Not_found ->
85538555
begin
85548556
Bsb_log.error
@@ -8595,7 +8597,6 @@ let resolve_bs_package ~cwd (package : t) =
85958597
x
85968598

85978599

8598-
85998600
(** The package does not need to be a bspackage
86008601
example:
86018602
{[

0 commit comments

Comments
 (0)