Skip to content

Commit d21cdfb

Browse files
authored
Merge pull request #1898 from BuckleScript/private_module_tests
fix #1895
2 parents 9513ffb + 3405cf0 commit d21cdfb

File tree

8 files changed

+101
-19
lines changed

8 files changed

+101
-19
lines changed

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@
77
/*.cm[ioxatj]
88
/*.cmx[as]
99
/*.cmti
10-
/*.annot
10+
/*.annot
11+
jscomp/build_tests

jscomp/bin/bsb.ml

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9848,7 +9848,8 @@ let (|?) m (key, cb) =
98489848
m |> Ext_json.test key cb
98499849

98509850

9851-
let warning_unused_file : _ format = "@{<warning>IGNORED@}: file %s under %s is ignored because it can't be turned into a valid module name. The build system transforms a file name into a module name by upper-casing the first letter@."
9851+
let warning_unused_file : _ format =
9852+
"@{<warning>IGNORED@}: file %s under %s is ignored because it can't be turned into a valid module name. The build system transforms a file name into a module name by upper-casing the first letter@."
98529853

98539854
type cxt = {
98549855
no_dev : bool ;
@@ -9858,6 +9859,31 @@ type cxt = {
98589859
cut_generators : bool
98599860
}
98609861

9862+
let collect_pub_modules
9863+
(xs : Ext_json_types.t array)
9864+
(cache : Bsb_build_cache.t) : String_set.t =
9865+
let set = ref String_set.empty in
9866+
for i = 0 to Array.length xs - 1 do
9867+
let v = Array.unsafe_get xs i in
9868+
match v with
9869+
| Str { str ; loc }
9870+
->
9871+
if String_map.mem str cache then
9872+
set := String_set.add str !set
9873+
else
9874+
begin
9875+
Format.fprintf Format.err_formatter
9876+
"@{<warning>IGNORED@} %S in public is ignored since it is not\
9877+
an existing module@." str
9878+
end
9879+
| _ ->
9880+
Bsb_exception.failf
9881+
~loc:(Ext_json.loc_of v)
9882+
"public excpect a list of strings"
9883+
done ;
9884+
!set
9885+
(* String_set.of_list (Bsb_build_util.get_list_string xs) *)
9886+
98619887
let handle_list_files acc
98629888
({ cwd = dir ; root} : cxt)
98639889
loc_start loc_end
@@ -10047,8 +10073,8 @@ and parsing_source_dir_map
1004710073
| Some (Arr {loc_start;loc_end; content = [||] }) ->
1004810074
(* [ ] populatd by scanning the dir (just once) *)
1004910075
let tasks, files =
10050-
handle_list_files !cur_sources cxt
10051-
loc_start loc_end (is_input_or_output generators) in
10076+
handle_list_files !cur_sources cxt
10077+
loc_start loc_end (is_input_or_output generators) in
1005210078
cur_update_queue := tasks ;
1005310079
cur_sources := files
1005410080

@@ -10091,6 +10117,7 @@ and parsing_source_dir_map
1009110117
| Some x -> Bsb_exception.failwith_config x "files field expect array or object "
1009210118

1009310119
end;
10120+
let cur_sources = !cur_sources in
1009410121
x
1009510122
|? (Bsb_build_schemas.resources ,
1009610123
`Arr (fun s ->
@@ -10102,12 +10129,12 @@ and parsing_source_dir_map
1010210129
Bsb_exception.failf ~loc "invalid str for %s " s
1010310130
))
1010410131
|? (Bsb_build_schemas.public, `Arr (fun s ->
10105-
public := Export_set (String_set.of_list (Bsb_build_util.get_list_string s ) )
10132+
public := Export_set (collect_pub_modules s cur_sources)
1010610133
) )
1010710134
|> ignore ;
1010810135
let cur_file =
1010910136
{dir = dir;
10110-
sources = !cur_sources;
10137+
sources = cur_sources;
1011110138
resources = !resources;
1011210139
public = !public;
1011310140
dir_index = cxt.dir_index ;
@@ -12150,7 +12177,7 @@ let emit_impl_build
1215012177
| None ->
1215112178
filename_sans_extension
1215212179
| Some pkg ->
12153-
Ext_package_name.make ~pkg filename_sans_extension
12180+
Ext_package_name.make ~pkg filename_sans_extension
1215412181
in
1215512182
let file_cmi = output_filename_sans_extension ^ Literals.suffix_cmi in
1215612183
let output_cmj = output_filename_sans_extension ^ Literals.suffix_cmj in
@@ -12222,7 +12249,7 @@ let emit_intf_build
1222212249
| None ->
1222312250
filename_sans_extension
1222412251
| Some pkg ->
12225-
Ext_package_name.make ~pkg filename_sans_extension
12252+
Ext_package_name.make ~pkg filename_sans_extension
1222612253
in
1222712254
let output_cmi = output_filename_sans_extension ^ Literals.suffix_cmi in
1222812255
let common_shadows =
@@ -12318,7 +12345,8 @@ let handle_file_group
1231812345
match group.public with
1231912346
| Export_all -> true
1232012347
| Export_none -> false
12321-
| Export_set set -> String_set.mem module_name set in
12348+
| Export_set set ->
12349+
String_set.mem module_name set in
1232212350
if installable then
1232312351
String_hash_set.add files_to_install (Bsb_build_cache.filename_sans_suffix_of_module_info module_info);
1232412352
(handle_module_info group.dir_index

jscomp/bsb/bsb_ninja_file_groups.ml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ let emit_impl_build
106106
| None ->
107107
filename_sans_extension
108108
| Some pkg ->
109-
Ext_package_name.make ~pkg filename_sans_extension
109+
Ext_package_name.make ~pkg filename_sans_extension
110110
in
111111
let file_cmi = output_filename_sans_extension ^ Literals.suffix_cmi in
112112
let output_cmj = output_filename_sans_extension ^ Literals.suffix_cmj in
@@ -178,7 +178,7 @@ let emit_intf_build
178178
| None ->
179179
filename_sans_extension
180180
| Some pkg ->
181-
Ext_package_name.make ~pkg filename_sans_extension
181+
Ext_package_name.make ~pkg filename_sans_extension
182182
in
183183
let output_cmi = output_filename_sans_extension ^ Literals.suffix_cmi in
184184
let common_shadows =
@@ -274,7 +274,8 @@ let handle_file_group
274274
match group.public with
275275
| Export_all -> true
276276
| Export_none -> false
277-
| Export_set set -> String_set.mem module_name set in
277+
| Export_set set ->
278+
String_set.mem module_name set in
278279
if installable then
279280
String_hash_set.add files_to_install (Bsb_build_cache.filename_sans_suffix_of_module_info module_info);
280281
(handle_module_info group.dir_index

jscomp/bsb/bsb_parse_sources.ml

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ let (|?) m (key, cb) =
7676
m |> Ext_json.test key cb
7777

7878

79-
let warning_unused_file : _ format = "@{<warning>IGNORED@}: file %s under %s is ignored because it can't be turned into a valid module name. The build system transforms a file name into a module name by upper-casing the first letter@."
79+
let warning_unused_file : _ format =
80+
"@{<warning>IGNORED@}: file %s under %s is ignored because it can't be turned into a valid module name. The build system transforms a file name into a module name by upper-casing the first letter@."
8081

8182
type cxt = {
8283
no_dev : bool ;
@@ -86,6 +87,31 @@ type cxt = {
8687
cut_generators : bool
8788
}
8889

90+
let collect_pub_modules
91+
(xs : Ext_json_types.t array)
92+
(cache : Bsb_build_cache.t) : String_set.t =
93+
let set = ref String_set.empty in
94+
for i = 0 to Array.length xs - 1 do
95+
let v = Array.unsafe_get xs i in
96+
match v with
97+
| Str { str ; loc }
98+
->
99+
if String_map.mem str cache then
100+
set := String_set.add str !set
101+
else
102+
begin
103+
Format.fprintf Format.err_formatter
104+
"@{<warning>IGNORED@} %S in public is ignored since it is not\
105+
an existing module@." str
106+
end
107+
| _ ->
108+
Bsb_exception.failf
109+
~loc:(Ext_json.loc_of v)
110+
"public excpect a list of strings"
111+
done ;
112+
!set
113+
(* String_set.of_list (Bsb_build_util.get_list_string xs) *)
114+
89115
let handle_list_files acc
90116
({ cwd = dir ; root} : cxt)
91117
loc_start loc_end
@@ -275,8 +301,8 @@ and parsing_source_dir_map
275301
| Some (Arr {loc_start;loc_end; content = [||] }) ->
276302
(* [ ] populatd by scanning the dir (just once) *)
277303
let tasks, files =
278-
handle_list_files !cur_sources cxt
279-
loc_start loc_end (is_input_or_output generators) in
304+
handle_list_files !cur_sources cxt
305+
loc_start loc_end (is_input_or_output generators) in
280306
cur_update_queue := tasks ;
281307
cur_sources := files
282308

@@ -319,6 +345,7 @@ and parsing_source_dir_map
319345
| Some x -> Bsb_exception.failwith_config x "files field expect array or object "
320346

321347
end;
348+
let cur_sources = !cur_sources in
322349
x
323350
|? (Bsb_build_schemas.resources ,
324351
`Arr (fun s ->
@@ -330,12 +357,12 @@ and parsing_source_dir_map
330357
Bsb_exception.failf ~loc "invalid str for %s " s
331358
))
332359
|? (Bsb_build_schemas.public, `Arr (fun s ->
333-
public := Export_set (String_set.of_list (Bsb_build_util.get_list_string s ) )
360+
public := Export_set (collect_pub_modules s cur_sources)
334361
) )
335362
|> ignore ;
336363
let cur_file =
337364
{dir = dir;
338-
sources = !cur_sources;
365+
sources = cur_sources;
339366
resources = !resources;
340367
public = !public;
341368
dir_index = cxt.dir_index ;

jscomp/build_tests/priv/input.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,12 @@
22

33
var child_process = require('child_process')
44

5-
child_process.execSync(`bsb -clean-world && bsb -make-world`, {cwd:__dirname, stdio:[0,1,2]})
5+
var output = child_process.spawnSync(
6+
`bsb -clean-world && bsb -make-world`,
7+
{cwd:__dirname, shell: true, encoding : 'utf8'})
8+
9+
10+
var assert = require('assert')
11+
assert.ok(output.stderr.match(/IGNORED/))
12+
613

jscomp/build_tests/priv/node_modules/liba/bsconfig.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/build_tests/priv/src/demo.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/build_tests/priv/src/main.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)