Skip to content

Commit 9f9353f

Browse files
committed
(!! new) Deprecate -bs-suffix; add extensions to -bs-package-output
Additionally involed: - Split `cmj_case` type into new, simplified `leading_case` type and aformentioned `package_info` changes - Store file-extension(s) in `.cmj` files - Bump `cmj_magic_number`, as it now contains new information Backwards-compatibility is maintained.
1 parent cb874ff commit 9f9353f

34 files changed

+1007
-899
lines changed

jscomp/common/bs_warnings.ml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ let to_string t =
3939

4040
let warning_formatter = Format.err_formatter
4141

42-
let print_string_warning (loc : Location.t) x =
42+
let print_string_warning (loc : Location.t) ?(kind = "Warning") x =
4343
if loc.loc_ghost then
4444
Format.fprintf warning_formatter "File %s@." !Location.input_name
4545
else Location.print warning_formatter loc;
46-
Format.fprintf warning_formatter "@{<error>Warning@}: %s@." x
46+
Format.fprintf warning_formatter "@{<error>%s@}: %s@." kind x
4747

4848

4949
let prerr_bs_ffi_warning loc x =
@@ -72,6 +72,14 @@ let () =
7272
| _ -> None)
7373

7474

75+
let warn_deprecated_bs_suffix_flag () =
76+
if not !Clflags.bs_quiet then (
77+
print_string_warning Location.none ~kind:"DEPRECATED"
78+
"`-bs-suffix` used; consider using third field of `-bs-package-output` \
79+
instead";
80+
Format.pp_print_flush warning_formatter () )
81+
82+
7583
let warn_missing_primitive loc txt =
7684
if (not !Js_config.no_warn_unimplemented_external) && not !Clflags.bs_quiet
7785
then (

jscomp/common/bs_warnings.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type t = Unsafe_poly_variant_type
2626

2727
val prerr_bs_ffi_warning : Location.t -> t -> unit
2828

29+
val warn_deprecated_bs_suffix_flag : unit -> unit
30+
2931
val warn_missing_primitive : Location.t -> string -> unit
3032

3133
val warn_literal_overflow : Location.t -> unit

jscomp/common/js_config.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ val syntax_only : bool ref
6969
val binary_ast : bool ref
7070
val simple_binary_ast : bool ref
7171

72-
val bs_suffix : bool ref
7372
val debug : bool ref
7473

7574
val cmi_only : bool ref

jscomp/core/js_cmj_format.ml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,27 @@ type effect = string option
3434
(* we don't force people to use package *)
3535
let single_na = Single Lam_arity.na
3636

37-
type cmj_case = Ext_namespace.file_kind
38-
3937
type keyed_cmj_values = (string * cmj_value) array
4038

4139
type t = {
4240
values : keyed_cmj_values;
4341
pure : bool;
4442
package_info : Js_package_info.t;
45-
cmj_case : cmj_case;
43+
leading_case : Ext_namespace.leading_case;
4644
}
4745

4846
let empty_values = [||]
4947

50-
let mk ~values ~effect ~package_info ~cmj_case : t =
48+
let mk ~values ~effect ~package_info ~leading_case : t =
5149
{
5250
values = Map_string.to_sorted_array values;
5351
pure = effect = None;
5452
package_info;
55-
cmj_case;
53+
leading_case;
5654
}
5755

5856

59-
let cmj_magic_number = "BUCKLE20171012"
57+
let cmj_magic_number = "BUCKLE20200410"
6058
let cmj_magic_number_length = String.length cmj_magic_number
6159

6260
let digest_length = 16 (*16 chars *)
@@ -176,24 +174,22 @@ let is_pure (cmj_table : t) = cmj_table.pure
176174

177175
let get_package_info (cmj_table : t) = cmj_table.package_info
178176

179-
let get_cmj_case (cmj_table : t) = cmj_table.cmj_case
177+
let get_leading_case (cmj_table : t) = cmj_table.leading_case
180178

181179
(* start dumping *)
182180

183181
let f fmt = Printf.fprintf stdout fmt
184182

185-
let pp_cmj_case (cmj_case : cmj_case) : unit =
186-
match cmj_case with
187-
| Little_js -> f "case : little, .js\n"
188-
| Little_bs -> f "case : little, .bs.js\n"
189-
| Upper_js -> f "case: upper, .js\n"
190-
| Upper_bs -> f "case: upper, .bs.js\n"
183+
let pp_leading_case (leading_case : Ext_namespace.leading_case) : unit =
184+
match leading_case with
185+
| Upper -> f "case: upper\n"
186+
| Lower -> f "case: lower\n"
191187

192188

193-
let pp_cmj ({ values; pure; package_info; cmj_case } : t) =
189+
let pp_cmj ({ values; pure; package_info; leading_case } : t) =
194190
f "package info: %s\n"
195191
(Format.asprintf "%a" Js_package_info.dump_package_info package_info);
196-
pp_cmj_case cmj_case;
192+
pp_leading_case leading_case;
197193

198194
f "effect: %s\n" (if pure then "pure" else "not pure");
199195
Ext_array.iter values (fun (k, { arity; persistent_closed_lambda }) ->

jscomp/core/js_cmj_format.mli

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,13 @@ type cmj_value = {
4646

4747
type effect = string option
4848

49-
type cmj_case = Ext_namespace.file_kind
50-
5149
type t
5250

5351
val mk :
5452
values:cmj_value Map_string.t ->
5553
effect:effect ->
5654
package_info:Js_package_info.t ->
57-
cmj_case:cmj_case ->
55+
leading_case:Ext_namespace.leading_case ->
5856
t
5957

6058
val query_by_name : t -> string -> arity * Lam.t option
@@ -63,7 +61,7 @@ val is_pure : t -> bool
6361

6462
val get_package_info : t -> Js_package_info.t
6563

66-
val get_cmj_case : t -> cmj_case
64+
val get_leading_case : t -> Ext_namespace.leading_case
6765

6866
val single_na : arity
6967

jscomp/core/js_dump_import_export.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ val imports :
3939
Ext_pp_scope.t ->
4040
Ext_pp.t ->
4141
(Ident.t * string) list ->
42-
Ext_pp_scope.t
42+
Ext_pp_scope.t

jscomp/core/js_dump_program.ml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,24 +53,25 @@ let dump_program (x : J.program) oc =
5353
ignore (program (P.from_channel oc) Ext_pp_scope.empty x)
5454

5555

56-
let node_program ~output_dir f (x : J.deps_program) =
56+
let node_program ~output_dir ~ext f (x : J.deps_program) =
5757
P.string f L.strict_directive;
5858
P.newline f;
5959
let cxt =
6060
Js_dump_import_export.requires L.require Ext_pp_scope.empty f
6161
(Ext_list.map x.modules (fun x ->
6262
( Lam_module_ident.id x,
63-
Js_name_of_module_id.string_of_module_id x ~output_dir NodeJS )))
63+
Js_name_of_module_id.string_of_module_id x ~output_dir ~ext NodeJS
64+
)))
6465
in
6566
program f cxt x.program
6667

6768

68-
let es6_program ~output_dir fmt f (x : J.deps_program) =
69+
let es6_program ~output_dir ~ext fmt f (x : J.deps_program) =
6970
let cxt =
7071
Js_dump_import_export.imports Ext_pp_scope.empty f
7172
(Ext_list.map x.modules (fun x ->
7273
( Lam_module_ident.id x,
73-
Js_name_of_module_id.string_of_module_id x ~output_dir fmt )))
74+
Js_name_of_module_id.string_of_module_id x ~output_dir ~ext fmt )))
7475
in
7576
let () = P.force_newline f in
7677
let cxt = Js_dump.statement_list true cxt f x.program.block in
@@ -85,7 +86,7 @@ let es6_program ~output_dir fmt f (x : J.deps_program) =
8586
Linguist::FileBlob.new('jscomp/test/test_u.js').generated?
8687
]} *)
8788

88-
let pp_deps_program ~output_prefix (kind : Js_package_info.module_system)
89+
let pp_deps_program ~output_prefix ~ext (kind : Js_package_info.module_system)
8990
(program : J.deps_program) (f : Ext_pp.t) =
9091
if not !Js_config.no_version_header then (
9192
P.string f Bs_version.header;
@@ -96,8 +97,8 @@ let pp_deps_program ~output_prefix (kind : Js_package_info.module_system)
9697
let output_dir = Filename.dirname output_prefix in
9798
ignore
9899
( match kind with
99-
| Es6 | Es6_global -> es6_program ~output_dir kind f program
100-
| NodeJS -> node_program ~output_dir f program );
100+
| Es6 | Es6_global -> es6_program ~output_dir ~ext kind f program
101+
| NodeJS -> node_program ~output_dir ~ext f program );
101102
P.newline f;
102103
P.string f
103104
( match program.side_effect with
@@ -107,5 +108,5 @@ let pp_deps_program ~output_prefix (kind : Js_package_info.module_system)
107108
P.flush f ()
108109

109110

110-
let dump_deps_program ~output_prefix kind x (oc : out_channel) =
111-
pp_deps_program ~output_prefix kind x (P.from_channel oc)
111+
let dump_deps_program ~output_prefix ~ext kind x (oc : out_channel) =
112+
pp_deps_program ~output_prefix ~ext kind x (P.from_channel oc)

jscomp/core/js_dump_program.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ val dump_program : J.program -> out_channel -> unit
2727

2828
val pp_deps_program :
2929
output_prefix:string ->
30+
ext:string ->
3031
Js_package_info.module_system ->
3132
J.deps_program ->
3233
Ext_pp.t ->
3334
unit
3435

3536
val dump_deps_program :
3637
output_prefix:string ->
38+
ext:string ->
3739
Js_package_info.module_system ->
3840
J.deps_program ->
3941
out_channel ->

jscomp/core/js_name_of_module_id.ml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ let get_runtime_module_path (dep_module_id : Lam_module_ident.t)
4747
module_system
4848
in
4949
let js_file =
50-
Ext_namespace.js_name_of_modulename dep_module_id.id.name Little_js
50+
Ext_namespace.js_filename_of_modulename ~name:dep_module_id.id.name
51+
~ext:".js" Lower
5152
in
5253
match loc with
5354
| Package_not_found -> assert false
54-
| Package_script ->
55-
Js_package_info.runtime_package_path module_system js_file
55+
| Package_script -> Js_package_info.runtime_package_path module_system js_file
5656
| Package_found pkg -> (
5757
let dep_path =
5858
"lib" // Js_package_info.runtime_dir_of_module_system module_system
@@ -82,8 +82,8 @@ let get_runtime_module_path (dep_module_id : Lam_module_ident.t)
8282

8383
(* [output_dir] is decided by the command line argument *)
8484
let string_of_module_id (dep_module_id : Lam_module_ident.t)
85-
~(output_dir : string) (module_system : Js_package_info.module_system) :
86-
string =
85+
~(output_dir : string) ~(ext : string)
86+
(module_system : Js_package_info.module_system) : string =
8787
let current_package_info = Js_current_package_info.get_packages_info () in
8888
fix_path_for_windows
8989
( match dep_module_id.kind with
@@ -99,12 +99,12 @@ let string_of_module_id (dep_module_id : Lam_module_ident.t)
9999
get_runtime_module_path dep_module_id current_package_info module_system
100100
| Ml -> (
101101
let query = Js_package_info.query_package_location_by_module_system in
102-
let current_loc = query current_package_info module_system
103-
in
102+
let current_loc = query current_package_info module_system in
104103
match Lam_compile_env.get_package_path_from_cmj dep_module_id with
105-
| cmj_path, dep_package_info, little -> (
104+
| cmj_path, dep_package_info, case -> (
106105
let js_file =
107-
Ext_namespace.js_name_of_modulename dep_module_id.id.name little
106+
Ext_namespace.js_filename_of_modulename
107+
~name:dep_module_id.id.name ~ext case
108108
in
109109
let dep_loc = query dep_package_info module_system in
110110
match (dep_loc, current_loc) with
@@ -179,6 +179,6 @@ let string_of_module_id_in_browser (x : Lam_module_ident.t) =
179179

180180

181181
let string_of_module_id (id : Lam_module_ident.t) ~output_dir:(_ : string)
182-
(_module_system : Js_package_info.module_system) =
182+
~ext:(_ : string) (_module_system : Js_package_info.module_system) =
183183
string_of_module_id_in_browser id
184184
#end

jscomp/core/js_name_of_module_id.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
val string_of_module_id :
2626
Lam_module_ident.t ->
2727
output_dir:string ->
28+
ext:string ->
2829
Js_package_info.module_system ->
2930
string
3031
(** generate the mdoule path so that it can be spliced here:

jscomp/core/js_package_info.ml

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ type location_descriptor = {
4949

5050
type package_name = Pkg_empty | Pkg_runtime | Pkg_normal of string
5151

52+
let deprecated_use_bs_extension = ref false
53+
5254
let runtime_package_name = "bs-platform"
5355

5456
let ( // ) = Filename.concat
@@ -105,6 +107,7 @@ let dump_location_descriptor (fmt : Format.formatter)
105107
(string_of_module_system ms)
106108
path extension
107109

110+
108111
let dump_package_name fmt (x : package_name) =
109112
match x with
110113
| Pkg_empty -> Format.fprintf fmt "@empty_pkg@"
@@ -168,17 +171,33 @@ let get_output_dir (info : t) ~package_dir module_system =
168171
Filename.concat package_dir (get_js_path info module_system)
169172

170173

174+
let deprecated_set_bs_extension () =
175+
Bs_warnings.warn_deprecated_bs_suffix_flag ();
176+
deprecated_use_bs_extension := true
177+
178+
179+
let deprecated_get_default_extension () =
180+
if !deprecated_use_bs_extension then Literals.suffix_bs_js
181+
else Literals.suffix_js
182+
183+
184+
(* FIXME: The deprecated -bs-suffix will only affect -bs-package-output flags
185+
passed *after* it. *)
171186
let append_location_descriptor_of_string (packages_info : t) (s : string) : t =
172-
let module_system, path, extension = match Ext_string.split ~keep_empty:false s ':' with
173-
| [ module_system; path; extension ] -> module_system, path, extension
174-
| [ module_system; path ] -> module_system, path, "js"
175-
| [ path ] -> "NodeJS", path, "js"
176-
| _ -> Ext_arg.bad_argf "invalid value for -bs-package-output: %s" s
187+
let module_system, path, extension =
188+
match Ext_string.split ~keep_empty:false s ':' with
189+
| [ module_system; path; extension ] -> (module_system, path, extension)
190+
| [ module_system; path ] ->
191+
(module_system, path, deprecated_get_default_extension ())
192+
| [ path ] -> ("NodeJS", path, deprecated_get_default_extension ())
193+
| _ -> Ext_arg.bad_argf "invalid value for -bs-package-output: %s" s
177194
in
178195
let module_system =
179-
match module_system_of_string module_system with
196+
match module_system_of_string module_system with
180197
| Some x -> x
181-
| None -> Ext_arg.bad_argf "invalid module system in -bs-package-output: %s" module_system
198+
| None ->
199+
Ext_arg.bad_argf "invalid module system in -bs-package-output: %s"
200+
module_system
182201
in
183202
{
184203
packages_info with

jscomp/core/js_package_info.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ val is_empty : t -> bool
4848

4949
val dump_package_info : Format.formatter -> t -> unit
5050

51+
val deprecated_set_bs_extension : unit -> unit
52+
5153
val append_location_descriptor_of_string : t -> string -> t
5254
(** used by command line option e.g [-bs-package-output commonjs:xx/path:ext] *)
5355

jscomp/core/lam_compile_env.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ let get_package_path_from_cmj (id : Lam_module_ident.t) =
9696
| Some (Ml { cmj_table; cmj_path }) ->
9797
( cmj_path,
9898
Js_cmj_format.get_package_info cmj_table,
99-
Js_cmj_format.get_cmj_case cmj_table )
99+
Js_cmj_format.get_leading_case cmj_table )
100100
| Some (External | Runtime _) ->
101101
assert false
102102
(* called by {!Js_name_of_module_id.string_of_module_id} can not be
@@ -112,7 +112,7 @@ let get_package_path_from_cmj (id : Lam_module_ident.t) =
112112
id +> Ml cmj_load_info;
113113
( cmj_load_info.cmj_path,
114114
Js_cmj_format.get_package_info cmj_table,
115-
Js_cmj_format.get_cmj_case cmj_table ) )
115+
Js_cmj_format.get_leading_case cmj_table ) )
116116

117117

118118
let add = Lam_module_ident.Hash_set.add

jscomp/core/lam_compile_env.mli

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,15 @@ val query_external_id_info : Ident.t -> string -> ident_info
6363
val is_pure_module : Lam_module_ident.t -> bool
6464

6565
val get_package_path_from_cmj :
66-
Lam_module_ident.t -> string * Js_package_info.t * Js_cmj_format.cmj_case
66+
Lam_module_ident.t -> string * Js_package_info.t * Ext_namespace.leading_case
6767

68-
(* The second argument is mostly from [runtime] modules will change the input
69-
[hard_dependencies] [get_required_modules extra hard_dependencies] [extra]
70-
maybe removed if it is pure and not in [hard_dependencies] *)
7168
val get_required_modules :
7269
Lam_module_ident.Hash_set.t ->
7370
Lam_module_ident.Hash_set.t ->
7471
Lam_module_ident.t list
72+
(** The second argument is mostly from [runtime] modules
73+
74+
will change the input [hard_dependencies]
75+
76+
[get_required_modules extra hard_dependencies] - [extra] maybe removed if it
77+
is pure and not in [hard_dependencies] *)

0 commit comments

Comments
 (0)