@@ -96,7 +96,7 @@ val suffix_cmti : string
9696val commonjs : string
9797val amdjs : string
9898val goog : string
99-
99+ val es6 : string
100100val unused_attribute : string
101101end = struct
102102#1 " literals.ml"
@@ -196,6 +196,7 @@ let suffix_js = ".js"
196196let commonjs = " commonjs"
197197let amdjs = " amdjs"
198198let goog = " goog"
199+ let es6 = " es6"
199200
200201let unused_attribute = " Unused attribute "
201202end
@@ -825,8 +826,10 @@ val concat4 : string -> string -> string -> string -> string
825826
826827val inter2 : string -> string -> string
827828val inter3 : string -> string -> string -> string
828-
829+ val inter4 : string -> string -> string -> string -> string
829830val concat_array : string -> string array -> string
831+
832+ val single_colon : string
830833end = struct
831834#1 " ext_string.ml"
832835(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -1210,7 +1213,7 @@ let empty = ""
12101213external compare : string -> string -> int = " caml_string_length_based_compare" " noalloc" ;;
12111214
12121215let single_space = " "
1213-
1216+ let single_colon = " : "
12141217let concat3 a b c = a ^ b ^ c
12151218let concat4 a b c d = a ^ b ^ c ^ d
12161219
@@ -1219,6 +1222,8 @@ let inter2 a b = a ^ single_space ^ b
12191222let inter3 a b c =
12201223 a ^ single_space ^ b ^ single_space ^ c
12211224
1225+ let inter4 a b c d =
1226+ a ^ single_space ^ b ^ single_space ^ c ^ single_space ^ d
12221227(* * TODO: improve perf *)
12231228let concat_array sep (s : string array ) =
12241229 String. concat sep (Array. to_list s)
@@ -2858,6 +2863,12 @@ val no_dev: bool ref
28582863
28592864(* * default not install, only when -make-world, its dependencies will be installed *)
28602865val install : bool ref
2866+
2867+ val supported_format : string -> bool
2868+
2869+ val package_flag : format :string -> string -> string
2870+
2871+ val package_output : format :string -> string -> string
28612872end = struct
28622873#1 " bsb_config.ml"
28632874(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -2890,23 +2901,66 @@ let lib_amd = "lib"//"amdjs"
28902901let lib_goog = " lib" // " goog"
28912902let lib_ocaml = Js_config. lib_ocaml_dir
28922903let lib_bs = " lib" // " bs"
2904+ let lib_es6 = " lib" // " es6"
28932905let rev_lib_bs = " .." // " .."
2906+
2907+
28942908let rev_lib_bs_prefix p = rev_lib_bs // p
28952909let common_js_prefix p = lib_js // p
28962910let amd_js_prefix p = lib_amd // p
28972911let goog_prefix p = lib_goog // p
2912+ let es6_prefix p = lib_es6 // p
2913+
28982914let ocaml_bin_install_prefix p = lib_ocaml // p
28992915
29002916let lazy_src_root_dir = " $src_root_dir"
29012917let proj_rel path = lazy_src_root_dir // path
2902-
2918+
29032919(* * it may not be a bad idea to hard code the binary path
29042920 of bsb in configuration time
29052921*)
29062922
29072923let no_dev = ref false
29082924
29092925let install = ref false
2926+
2927+ let supported_format x =
2928+ x = Literals. amdjs ||
2929+ x = Literals. commonjs ||
2930+ x = Literals. goog ||
2931+ x = Literals. es6
2932+
2933+ let bs_package_output = " -bs-package-output"
2934+
2935+ (* * Assume input is valid
2936+ {[ -bs-package-output commonjs:lib/js/jscomp/test ]}
2937+ *)
2938+ let package_flag ~format :fmt dir =
2939+ Ext_string. inter2
2940+ bs_package_output
2941+ (Ext_string. concat3
2942+ fmt
2943+ Ext_string. single_colon
2944+ (if fmt = Literals. amdjs then
2945+ amd_js_prefix dir
2946+ else if fmt = Literals. commonjs then
2947+ common_js_prefix dir
2948+ else if fmt = Literals. es6 then
2949+ es6_prefix dir
2950+ else goog_prefix dir))
2951+ (* * js output for each package *)
2952+ let package_output ~format :s output =
2953+ let prefix =
2954+ if s = Literals. commonjs then
2955+ common_js_prefix
2956+ else if s = Literals. amdjs then
2957+ amd_js_prefix
2958+ else if s = Literals. es6 then
2959+ es6_prefix
2960+ else goog_prefix
2961+ in
2962+ (proj_rel @@ prefix output )
2963+ (* output_file_sans_extension ^ Literals.suffix_js *)
29102964end
29112965module Ext_array : sig
29122966#1 " ext_array.mli"
@@ -6983,14 +7037,16 @@ let package_specs_overriden = ref false
69837037
69847038let get_package_specs () = ! package_specs
69857039
7040+
7041+
69867042let set_package_specs_from_array arr =
69877043 if not ! package_specs_overriden then
69887044 let new_package_specs =
69897045 arr
69907046 |> get_list_string
69917047 |> List. fold_left (fun acc x ->
69927048 let v =
6993- if x = Literals. amdjs || x = Literals. commonjs || x = Literals. goog then String_set. add x acc
7049+ if Bsb_config. supported_format x then String_set. add x acc
69947050 else
69957051 failwith (" Unkonwn package spec" ^ x) in
69967052 v
@@ -7006,7 +7062,7 @@ let internal_override_package_specs str =
70067062 package_specs :=
70077063 List. fold_left (fun acc x ->
70087064 let v =
7009- if x = Literals. amdjs || x = Literals. commonjs || x = Literals. goog then String_set. add x acc
7065+ if Bsb_config. supported_format x then String_set. add x acc
70107066 else
70117067 failwith (" Unkonwn package spec" ^ x) in
70127068 v
@@ -8021,15 +8077,8 @@ let handle_file_group oc ~package_specs ~js_post_build_cmd acc (group: Bsb_buil
80218077 let output_cmj = output_file_sans_extension ^ Literals. suffix_cmj in
80228078 let output_js =
80238079 String_set. fold (fun s acc ->
8024- let prefix =
8025- if s = Literals. commonjs then
8026- Bsb_config. common_js_prefix
8027- else if s = Literals. amdjs then
8028- Bsb_config. amd_js_prefix
8029- else Bsb_config. goog_prefix
8030- in
8031- (Bsb_config. proj_rel @@ prefix
8032- output_file_sans_extension ^ Literals. suffix_js) :: acc
8080+ Bsb_config. package_output ~format: s (output_file_sans_extension ^ Literals. suffix_js)
8081+ :: acc
80338082 ) package_specs []
80348083 in
80358084 (* let output_mldeps = output_file_sans_extension ^ Literals.suffix_mldeps in *)
@@ -8039,14 +8088,9 @@ let handle_file_group oc ~package_specs ~js_post_build_cmd acc (group: Bsb_buil
80398088 ( " bs_package_flags" ,
80408089 `Append
80418090 (String_set. fold (fun s acc ->
8042- acc ^ " -bs-package-output " ^ s ^ " :" ^
8043- if s = Literals. amdjs then
8044- (Bsb_config. amd_js_prefix @@ Filename. dirname output_cmi)
8045- else if s = Literals. commonjs then
8046- (Bsb_config. common_js_prefix @@ Filename. dirname output_cmi)
8047- else
8048- (Bsb_config. goog_prefix @@ Filename. dirname output_cmi)
8049- ) package_specs " " )
8091+ Ext_string. inter2 acc (Bsb_config. package_flag ~format: s (Filename. dirname output_cmi))
8092+
8093+ ) package_specs Ext_string. empty)
80508094 ) ::
80518095 (if group.dir_index = 0 then [] else
80528096 [(" bsc_extra_includes" ,
@@ -8816,6 +8860,7 @@ let lib_amdjs = "lib" // "amdjs"
88168860let lib_goog = " lib" // " goog"
88178861let lib_js = " lib" // " js"
88188862let lib_ocaml = " lib" // " ocaml" (* installed binary artifacts *)
8863+ let lib_es6 = " lib" // " es6"
88198864let clean_bs_garbage cwd =
88208865 print_string " Doing cleaning in " ;
88218866 print_endline cwd;
@@ -8828,7 +8873,8 @@ let clean_bs_garbage cwd =
88288873 aux lib_amdjs ;
88298874 aux lib_goog;
88308875 aux lib_js ;
8831- aux lib_ocaml
8876+ aux lib_ocaml;
8877+ aux lib_es6 ;
88328878 with
88338879 e ->
88348880 prerr_endline (" Failed to clean due to " ^ Printexc. to_string e)
0 commit comments