@@ -79,7 +79,7 @@ fn it_creates_a_package_json_default_path() {
79
79
let crate_data = manifest:: CrateData :: new ( & fixture. path , None ) . unwrap ( ) ;
80
80
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
81
81
assert ! ( crate_data
82
- . write_package_json( & out_dir, & None , false , Target :: Bundler )
82
+ . write_package_json( & out_dir, & None , false , Target :: Bundler , false )
83
83
. is_ok( ) ) ;
84
84
let package_json_path = & fixture. path . join ( "pkg" ) . join ( "package.json" ) ;
85
85
fs:: metadata ( package_json_path) . unwrap ( ) ;
@@ -115,7 +115,7 @@ fn it_creates_a_package_json_provided_path() {
115
115
let crate_data = manifest:: CrateData :: new ( & fixture. path , None ) . unwrap ( ) ;
116
116
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
117
117
assert ! ( crate_data
118
- . write_package_json( & out_dir, & None , false , Target :: Bundler )
118
+ . write_package_json( & out_dir, & None , false , Target :: Bundler , false )
119
119
. is_ok( ) ) ;
120
120
let package_json_path = & fixture. path . join ( "pkg" ) . join ( "package.json" ) ;
121
121
fs:: metadata ( package_json_path) . unwrap ( ) ;
@@ -144,7 +144,13 @@ fn it_creates_a_package_json_provided_path_with_scope() {
144
144
let crate_data = manifest:: CrateData :: new ( & fixture. path , None ) . unwrap ( ) ;
145
145
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
146
146
assert ! ( crate_data
147
- . write_package_json( & out_dir, & Some ( "test" . to_string( ) ) , false , Target :: Bundler , )
147
+ . write_package_json(
148
+ & out_dir,
149
+ & Some ( "test" . to_string( ) ) ,
150
+ false ,
151
+ Target :: Bundler ,
152
+ false
153
+ )
148
154
. is_ok( ) ) ;
149
155
let package_json_path = & fixture. path . join ( "pkg" ) . join ( "package.json" ) ;
150
156
fs:: metadata ( package_json_path) . unwrap ( ) ;
@@ -173,7 +179,7 @@ fn it_creates_a_pkg_json_with_correct_files_on_node() {
173
179
let crate_data = manifest:: CrateData :: new ( & fixture. path , None ) . unwrap ( ) ;
174
180
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
175
181
assert ! ( crate_data
176
- . write_package_json( & out_dir, & None , false , Target :: Nodejs )
182
+ . write_package_json( & out_dir, & None , false , Target :: Nodejs , false )
177
183
. is_ok( ) ) ;
178
184
let package_json_path = & out_dir. join ( "package.json" ) ;
179
185
fs:: metadata ( package_json_path) . unwrap ( ) ;
@@ -207,7 +213,7 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() {
207
213
let crate_data = manifest:: CrateData :: new ( & fixture. path , None ) . unwrap ( ) ;
208
214
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
209
215
assert ! ( crate_data
210
- . write_package_json( & out_dir, & None , false , Target :: NoModules )
216
+ . write_package_json( & out_dir, & None , false , Target :: NoModules , false )
211
217
. is_ok( ) ) ;
212
218
let package_json_path = & out_dir. join ( "package.json" ) ;
213
219
fs:: metadata ( package_json_path) . unwrap ( ) ;
@@ -241,7 +247,7 @@ fn it_creates_a_package_json_with_correct_files_when_out_name_is_provided() {
241
247
let crate_data = manifest:: CrateData :: new ( & fixture. path , Some ( "index" . to_owned ( ) ) ) . unwrap ( ) ;
242
248
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
243
249
assert ! ( crate_data
244
- . write_package_json( & out_dir, & None , false , Target :: Bundler )
250
+ . write_package_json( & out_dir, & None , false , Target :: Bundler , false )
245
251
. is_ok( ) ) ;
246
252
let package_json_path = & fixture. path . join ( "pkg" ) . join ( "package.json" ) ;
247
253
fs:: metadata ( package_json_path) . unwrap ( ) ;
@@ -273,7 +279,7 @@ fn it_creates_a_pkg_json_in_out_dir() {
273
279
let crate_data = manifest:: CrateData :: new ( & fixture. path , None ) . unwrap ( ) ;
274
280
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
275
281
assert ! ( crate_data
276
- . write_package_json( & out_dir, & None , false , Target :: Bundler )
282
+ . write_package_json( & out_dir, & None , false , Target :: Bundler , false )
277
283
. is_ok( ) ) ;
278
284
279
285
let package_json_path = & fixture. path . join ( & out_dir) . join ( "package.json" ) ;
@@ -288,7 +294,7 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() {
288
294
let crate_data = manifest:: CrateData :: new ( & fixture. path , None ) . unwrap ( ) ;
289
295
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
290
296
assert ! ( crate_data
291
- . write_package_json( & out_dir, & None , true , Target :: Bundler )
297
+ . write_package_json( & out_dir, & None , true , Target :: Bundler , false )
292
298
. is_ok( ) ) ;
293
299
let package_json_path = & out_dir. join ( "package.json" ) ;
294
300
fs:: metadata ( package_json_path) . unwrap ( ) ;
@@ -314,13 +320,73 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() {
314
320
assert_eq ! ( actual_files, expected_files) ;
315
321
}
316
322
323
+ #[ test]
324
+ fn it_creates_a_package_json_with_correct_files_when_is_child_is_provided ( ) {
325
+ let fixture = fixture:: js_hello_world ( ) ;
326
+ let out_dir = fixture. path . join ( "pkg" ) ;
327
+ let crate_data = manifest:: CrateData :: new ( & fixture. path , Some ( "index" . to_owned ( ) ) ) . unwrap ( ) ;
328
+ let crate_data_child =
329
+ manifest:: CrateData :: new ( & fixture. path , Some ( "child" . to_owned ( ) ) ) . unwrap ( ) ;
330
+ wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
331
+ assert ! ( crate_data
332
+ . write_package_json( & out_dir, & None , false , Target :: Web , false )
333
+ . is_ok( ) ) ;
334
+ assert ! ( crate_data_child
335
+ . write_package_json( & out_dir, & None , false , Target :: Web , true )
336
+ . is_ok( ) ) ;
337
+ let package_json_path = & fixture. path . join ( "pkg" ) . join ( "package.json" ) ;
338
+ fs:: metadata ( package_json_path) . unwrap ( ) ;
339
+ utils:: manifest:: read_package_json ( & fixture. path , & out_dir) . unwrap ( ) ;
340
+ let pkg = utils:: manifest:: read_package_json ( & fixture. path , & out_dir) . unwrap ( ) ;
341
+ assert_eq ! ( pkg. name, "js-hello-world" ) ;
342
+ assert_eq ! ( pkg. repository. ty, "git" ) ;
343
+ assert_eq ! (
344
+ pkg. repository. url,
345
+ "https://github.com/rustwasm/wasm-pack.git"
346
+ ) ;
347
+ assert_eq ! ( pkg. module, "index.js" ) ;
348
+ assert_eq ! ( pkg. types, "index.d.ts" ) ;
349
+ assert_eq ! ( pkg. side_effects, false ) ;
350
+
351
+ let actual_files: HashSet < String > = pkg. files . into_iter ( ) . collect ( ) ;
352
+ let expected_files: HashSet < String > = [
353
+ "index_bg.wasm" ,
354
+ "index.d.ts" ,
355
+ "index.js" ,
356
+ "child_bg.wasm" ,
357
+ "child.d.ts" ,
358
+ "child.js" ,
359
+ ]
360
+ . iter ( )
361
+ . map ( |& s| String :: from ( s) )
362
+ . collect ( ) ;
363
+ assert_eq ! ( actual_files, expected_files) ;
364
+ }
365
+
317
366
#[ test]
318
367
fn it_errors_when_wasm_bindgen_is_not_declared ( ) {
319
368
let fixture = fixture:: bad_cargo_toml ( ) ;
320
369
let crate_data = manifest:: CrateData :: new ( & fixture. path , None ) . unwrap ( ) ;
321
370
assert ! ( crate_data. check_crate_config( ) . is_err( ) ) ;
322
371
}
323
372
373
+ #[ test]
374
+ fn it_errors_when_out_dir_of_child_does_not_exist ( ) {
375
+ let fixture = fixture:: js_hello_world ( ) ;
376
+ let out_dir = fixture. path . join ( "pkg" ) ;
377
+ let out_dir_child = fixture. path . join ( "pkg-child" ) ;
378
+ let crate_data = manifest:: CrateData :: new ( & fixture. path , Some ( "index" . to_owned ( ) ) ) . unwrap ( ) ;
379
+ let crate_data_child =
380
+ manifest:: CrateData :: new ( & fixture. path , Some ( "child" . to_owned ( ) ) ) . unwrap ( ) ;
381
+ wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
382
+ assert ! ( crate_data
383
+ . write_package_json( & out_dir, & None , false , Target :: Web , false )
384
+ . is_ok( ) ) ;
385
+ assert ! ( crate_data_child
386
+ . write_package_json( & out_dir_child, & None , false , Target :: Web , true )
387
+ . is_err( ) ) ;
388
+ }
389
+
324
390
#[ test]
325
391
fn it_sets_homepage_field_if_available_in_cargo_toml ( ) {
326
392
// When 'homepage' is available
@@ -353,7 +419,7 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() {
353
419
354
420
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
355
421
crate_data
356
- . write_package_json ( & out_dir, & None , true , Target :: Bundler )
422
+ . write_package_json ( & out_dir, & None , true , Target :: Bundler , false )
357
423
. unwrap ( ) ;
358
424
359
425
let pkg = utils:: manifest:: read_package_json ( & fixture. path , & out_dir) . unwrap ( ) ;
@@ -369,7 +435,7 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() {
369
435
370
436
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
371
437
crate_data
372
- . write_package_json ( & out_dir, & None , true , Target :: Bundler )
438
+ . write_package_json ( & out_dir, & None , true , Target :: Bundler , false )
373
439
. unwrap ( ) ;
374
440
375
441
let pkg = utils:: manifest:: read_package_json ( & fixture. path , & out_dir) . unwrap ( ) ;
@@ -408,7 +474,7 @@ fn it_sets_keywords_field_if_available_in_cargo_toml() {
408
474
409
475
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
410
476
crate_data
411
- . write_package_json ( & out_dir, & None , true , Target :: Bundler )
477
+ . write_package_json ( & out_dir, & None , true , Target :: Bundler , false )
412
478
. unwrap ( ) ;
413
479
414
480
let pkg = utils:: manifest:: read_package_json ( & fixture. path , & out_dir) . unwrap ( ) ;
@@ -426,7 +492,7 @@ fn it_sets_keywords_field_if_available_in_cargo_toml() {
426
492
427
493
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
428
494
crate_data
429
- . write_package_json ( & out_dir, & None , true , Target :: Bundler )
495
+ . write_package_json ( & out_dir, & None , true , Target :: Bundler , false )
430
496
. unwrap ( ) ;
431
497
432
498
let pkg = utils:: manifest:: read_package_json ( & fixture. path , & out_dir) . unwrap ( ) ;
@@ -527,7 +593,7 @@ fn it_lists_license_files_in_files_field_of_package_json() {
527
593
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
528
594
license:: copy_from_crate ( & crate_data, & fixture. path , & out_dir) . unwrap ( ) ;
529
595
crate_data
530
- . write_package_json ( & out_dir, & None , false , Target :: Bundler )
596
+ . write_package_json ( & out_dir, & None , false , Target :: Bundler , false )
531
597
. unwrap ( ) ;
532
598
533
599
let package_json_path = & fixture. path . join ( "pkg" ) . join ( "package.json" ) ;
0 commit comments