Skip to content

Commit 91b5cfe

Browse files
authored
Merge pull request #3840 from ulrikstrid/esy-monorepo-support
Esy monorepo support
2 parents 32ae22d + d12511d commit 91b5cfe

File tree

4 files changed

+220
-52
lines changed

4 files changed

+220
-52
lines changed

esy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"ocaml": "4.02.3000+BS"
99
},
1010
"resolutions": {
11-
"ocaml": "ulrikstrid/ocaml:package.json#e433d5b3fbe8963ac98257d1ed3b32c01515e07d"
11+
"ocaml": "bucklescript/ocaml:package.json#698e60f3cd2f442f2013e79860ce2f7b0a9624cb"
1212
},
1313
"esy": {
1414
"buildsInSource": true,

jscomp/bsb/bsb_pkg.ml

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

85+
(* Some package managers will implement "postinstall" caches, that do not
86+
* keep their build artifacts in the local node_modules. Similar to
87+
* npm_config_prefix, bs_custom_resolution allows these to specify the
88+
* exact location of build cache, but on a per-package basis. Implemented as
89+
* environment lookup to avoid invasive changes to bsconfig and mandates. *)
90+
let custom_resolution = lazy
91+
(match Sys.getenv "bs_custom_resolution" with
92+
| exception Not_found -> false
93+
| "true" -> true
94+
| _ -> false)
95+
96+
let pkg_name_as_variable package =
97+
Bsb_pkg_types.to_string package
98+
|> fun s -> Ext_string.split s '@'
99+
|> String.concat ""
100+
|> fun s -> Ext_string.split s '_'
101+
|> String.concat "__"
102+
|> fun s -> Ext_string.split s '/'
103+
|> String.concat "__slash__"
104+
|> fun s -> Ext_string.split s '.'
105+
|> String.concat "__dot__"
106+
|> fun s -> Ext_string.split s '-'
107+
|> String.concat "_"
108+
85109
(** TODO: collect all warnings and print later *)
86110
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
111+
if Lazy.force custom_resolution then
112+
begin
113+
Bsb_log.info "@{<info>Using Custom Resolution@}@.";
114+
let custom_pkg_loc = pkg_name_as_variable package ^ "__install" in
115+
let custom_pkg_location = lazy (Sys.getenv custom_pkg_loc) in
116+
match Lazy.force custom_pkg_location with
117+
| exception Not_found ->
118+
begin
119+
Bsb_log.error
120+
"@{<error>Custom resolution of package %s does not exist in var %s @}@."
121+
(Bsb_pkg_types.to_string package)
122+
custom_pkg_loc;
123+
Bsb_exception.package_not_found ~pkg:package ~json:None
124+
end
125+
| path when not (Sys.file_exists path) ->
126+
begin
127+
Bsb_log.error
128+
"@{<error>Custom resolution of package %s does not exist on disk: %s=%s @}@."
129+
(Bsb_pkg_types.to_string package)
130+
custom_pkg_loc
131+
path;
132+
Bsb_exception.package_not_found ~pkg:package ~json:None
133+
end
134+
| path ->
97135
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-
104-
136+
Bsb_log.info
137+
"@{<info>Custom Resolution of package %s in var %s found at %s@}@."
138+
(Bsb_pkg_types.to_string package)
139+
custom_pkg_loc
140+
path;
141+
path
142+
end
143+
end
144+
else
145+
match Coll.find_opt cache package with
146+
| None ->
147+
let result = resolve_bs_package_aux ~cwd package in
148+
Bsb_log.info "@{<info>Package@} %a -> %s@." Bsb_pkg_types.print package result ;
149+
Coll.add cache package result ;
150+
result
151+
| Some x
152+
->
153+
let result = resolve_bs_package_aux ~cwd package in
154+
if result <> x then
155+
begin
156+
Bsb_log.warn
157+
"@{<warning>Duplicated package:@} %a %s (chosen) vs %s in %s @."
158+
Bsb_pkg_types.print package x result cwd;
159+
end;
160+
x
105161

106162

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

lib/4.02.3/bsb.ml

Lines changed: 73 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8548,26 +8548,82 @@ let cache : string Coll.t = Coll.create 0
85488548
let to_list cb =
85498549
Coll.to_list cache cb
85508550

8551+
(* Some package managers will implement "postinstall" caches, that do not
8552+
* keep their build artifacts in the local node_modules. Similar to
8553+
* npm_config_prefix, bs_custom_resolution allows these to specify the
8554+
* exact location of build cache, but on a per-package basis. Implemented as
8555+
* environment lookup to avoid invasive changes to bsconfig and mandates. *)
8556+
let custom_resolution = lazy
8557+
(match Sys.getenv "bs_custom_resolution" with
8558+
| exception Not_found -> false
8559+
| "true" -> true
8560+
| _ -> false)
8561+
8562+
let pkg_name_as_variable package =
8563+
Bsb_pkg_types.to_string package
8564+
|> fun s -> Ext_string.split s '@'
8565+
|> String.concat ""
8566+
|> fun s -> Ext_string.split s '_'
8567+
|> String.concat "__"
8568+
|> fun s -> Ext_string.split s '/'
8569+
|> String.concat "__slash__"
8570+
|> fun s -> Ext_string.split s '.'
8571+
|> String.concat "__dot__"
8572+
|> fun s -> Ext_string.split s '-'
8573+
|> String.concat "_"
8574+
85518575
(** TODO: collect all warnings and print later *)
85528576
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
8577+
if Lazy.force custom_resolution then
8578+
begin
8579+
Bsb_log.info "@{<info>Using Custom Resolution@}@.";
8580+
let custom_pkg_loc = pkg_name_as_variable package ^ "__install" in
8581+
let custom_pkg_location = lazy (Sys.getenv custom_pkg_loc) in
8582+
match Lazy.force custom_pkg_location with
8583+
| exception Not_found ->
8584+
begin
8585+
Bsb_log.error
8586+
"@{<error>Custom resolution of package %s does not exist in var %s @}@."
8587+
(Bsb_pkg_types.to_string package)
8588+
custom_pkg_loc;
8589+
Bsb_exception.package_not_found ~pkg:package ~json:None
8590+
end
8591+
| path when not (Sys.file_exists path) ->
8592+
begin
8593+
Bsb_log.error
8594+
"@{<error>Custom resolution of package %s does not exist on disk: %s=%s @}@."
8595+
(Bsb_pkg_types.to_string package)
8596+
custom_pkg_loc
8597+
path;
8598+
Bsb_exception.package_not_found ~pkg:package ~json:None
8599+
end
8600+
| path ->
85638601
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
8569-
8570-
8602+
Bsb_log.info
8603+
"@{<info>Custom Resolution of package %s in var %s found at %s@}@."
8604+
(Bsb_pkg_types.to_string package)
8605+
custom_pkg_loc
8606+
path;
8607+
path
8608+
end
8609+
end
8610+
else
8611+
match Coll.find_opt cache package with
8612+
| None ->
8613+
let result = resolve_bs_package_aux ~cwd package in
8614+
Bsb_log.info "@{<info>Package@} %a -> %s@." Bsb_pkg_types.print package result ;
8615+
Coll.add cache package result ;
8616+
result
8617+
| Some x
8618+
->
8619+
let result = resolve_bs_package_aux ~cwd package in
8620+
if result <> x then
8621+
begin
8622+
Bsb_log.warn
8623+
"@{<warning>Duplicated package:@} %a %s (chosen) vs %s in %s @."
8624+
Bsb_pkg_types.print package x result cwd;
8625+
end;
8626+
x
85718627

85728628

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

lib/4.06.1/bsb.ml

Lines changed: 73 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8518,26 +8518,82 @@ let cache : string Coll.t = Coll.create 0
85188518
let to_list cb =
85198519
Coll.to_list cache cb
85208520

8521+
(* Some package managers will implement "postinstall" caches, that do not
8522+
* keep their build artifacts in the local node_modules. Similar to
8523+
* npm_config_prefix, bs_custom_resolution allows these to specify the
8524+
* exact location of build cache, but on a per-package basis. Implemented as
8525+
* environment lookup to avoid invasive changes to bsconfig and mandates. *)
8526+
let custom_resolution = lazy
8527+
(match Sys.getenv "bs_custom_resolution" with
8528+
| exception Not_found -> false
8529+
| "true" -> true
8530+
| _ -> false)
8531+
8532+
let pkg_name_as_variable package =
8533+
Bsb_pkg_types.to_string package
8534+
|> fun s -> Ext_string.split s '@'
8535+
|> String.concat ""
8536+
|> fun s -> Ext_string.split s '_'
8537+
|> String.concat "__"
8538+
|> fun s -> Ext_string.split s '/'
8539+
|> String.concat "__slash__"
8540+
|> fun s -> Ext_string.split s '.'
8541+
|> String.concat "__dot__"
8542+
|> fun s -> Ext_string.split s '-'
8543+
|> String.concat "_"
8544+
85218545
(** TODO: collect all warnings and print later *)
85228546
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
8547+
if Lazy.force custom_resolution then
8548+
begin
8549+
Bsb_log.info "@{<info>Using Custom Resolution@}@.";
8550+
let custom_pkg_loc = pkg_name_as_variable package ^ "__install" in
8551+
let custom_pkg_location = lazy (Sys.getenv custom_pkg_loc) in
8552+
match Lazy.force custom_pkg_location with
8553+
| exception Not_found ->
8554+
begin
8555+
Bsb_log.error
8556+
"@{<error>Custom resolution of package %s does not exist in var %s @}@."
8557+
(Bsb_pkg_types.to_string package)
8558+
custom_pkg_loc;
8559+
Bsb_exception.package_not_found ~pkg:package ~json:None
8560+
end
8561+
| path when not (Sys.file_exists path) ->
8562+
begin
8563+
Bsb_log.error
8564+
"@{<error>Custom resolution of package %s does not exist on disk: %s=%s @}@."
8565+
(Bsb_pkg_types.to_string package)
8566+
custom_pkg_loc
8567+
path;
8568+
Bsb_exception.package_not_found ~pkg:package ~json:None
8569+
end
8570+
| path ->
85338571
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
8539-
8540-
8572+
Bsb_log.info
8573+
"@{<info>Custom Resolution of package %s in var %s found at %s@}@."
8574+
(Bsb_pkg_types.to_string package)
8575+
custom_pkg_loc
8576+
path;
8577+
path
8578+
end
8579+
end
8580+
else
8581+
match Coll.find_opt cache package with
8582+
| None ->
8583+
let result = resolve_bs_package_aux ~cwd package in
8584+
Bsb_log.info "@{<info>Package@} %a -> %s@." Bsb_pkg_types.print package result ;
8585+
Coll.add cache package result ;
8586+
result
8587+
| Some x
8588+
->
8589+
let result = resolve_bs_package_aux ~cwd package in
8590+
if result <> x then
8591+
begin
8592+
Bsb_log.warn
8593+
"@{<warning>Duplicated package:@} %a %s (chosen) vs %s in %s @."
8594+
Bsb_pkg_types.print package x result cwd;
8595+
end;
8596+
x
85418597

85428598

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

0 commit comments

Comments
 (0)