@@ -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 , & None , false , Target :: Bundler )
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 ( ) ;
@@ -119,7 +119,7 @@ fn it_creates_a_package_json_provided_path() {
119
119
let crate_data = manifest:: CrateData :: new ( & fixture. path , None ) . unwrap ( ) ;
120
120
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
121
121
assert ! ( crate_data
122
- . write_package_json( & out_dir, & None , false , Target :: Bundler )
122
+ . write_package_json( & out_dir, & None , & None , false , Target :: Bundler )
123
123
. is_ok( ) ) ;
124
124
let package_json_path = & fixture. path . join ( "pkg" ) . join ( "package.json" ) ;
125
125
fs:: metadata ( package_json_path) . unwrap ( ) ;
@@ -149,7 +149,13 @@ fn it_creates_a_package_json_provided_path_with_scope() {
149
149
let crate_data = manifest:: CrateData :: new ( & fixture. path , None ) . unwrap ( ) ;
150
150
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
151
151
assert ! ( crate_data
152
- . write_package_json( & out_dir, & Some ( "test" . to_string( ) ) , false , Target :: Bundler , )
152
+ . write_package_json(
153
+ & out_dir,
154
+ & Some ( "test" . to_string( ) ) ,
155
+ & None ,
156
+ false ,
157
+ Target :: Bundler ,
158
+ )
153
159
. is_ok( ) ) ;
154
160
let package_json_path = & fixture. path . join ( "pkg" ) . join ( "package.json" ) ;
155
161
fs:: metadata ( package_json_path) . unwrap ( ) ;
@@ -172,14 +178,50 @@ fn it_creates_a_package_json_provided_path_with_scope() {
172
178
assert_eq ! ( actual_files, expected_files) ;
173
179
}
174
180
181
+ #[ test]
182
+ fn it_creates_a_package_json_provided_path_with_package_name ( ) {
183
+ let fixture = fixture:: js_hello_world ( ) ;
184
+ let out_dir = fixture. path . join ( "pkg" ) ;
185
+ let crate_data = manifest:: CrateData :: new ( & fixture. path , None ) . unwrap ( ) ;
186
+ wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
187
+ assert ! ( crate_data
188
+ . write_package_json(
189
+ & out_dir,
190
+ & None ,
191
+ & Some ( "hello-world" . to_string( ) ) ,
192
+ false ,
193
+ Target :: Bundler ,
194
+ )
195
+ . is_ok( ) ) ;
196
+ let package_json_path = & fixture. path . join ( "pkg" ) . join ( "package.json" ) ;
197
+ fs:: metadata ( package_json_path) . unwrap ( ) ;
198
+ utils:: manifest:: read_package_json ( & fixture. path , & out_dir) . unwrap ( ) ;
199
+ let pkg = utils:: manifest:: read_package_json ( & fixture. path , & out_dir) . unwrap ( ) ;
200
+ assert_eq ! ( pkg. name, "hello-world" ) ;
201
+ assert_eq ! ( pkg. ty, "module" ) ;
202
+ assert_eq ! ( pkg. main, "js_hello_world.js" ) ;
203
+
204
+ let actual_files: HashSet < String > = pkg. files . into_iter ( ) . collect ( ) ;
205
+ let expected_files: HashSet < String > = [
206
+ "js_hello_world.d.ts" ,
207
+ "js_hello_world_bg.js" ,
208
+ "js_hello_world_bg.wasm" ,
209
+ "js_hello_world.js" ,
210
+ ]
211
+ . iter ( )
212
+ . map ( |& s| String :: from ( s) )
213
+ . collect ( ) ;
214
+ assert_eq ! ( actual_files, expected_files) ;
215
+ }
216
+
175
217
#[ test]
176
218
fn it_creates_a_pkg_json_with_correct_files_on_node ( ) {
177
219
let fixture = fixture:: js_hello_world ( ) ;
178
220
let out_dir = fixture. path . join ( "pkg" ) ;
179
221
let crate_data = manifest:: CrateData :: new ( & fixture. path , None ) . unwrap ( ) ;
180
222
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
181
223
assert ! ( crate_data
182
- . write_package_json( & out_dir, & None , false , Target :: Nodejs )
224
+ . write_package_json( & out_dir, & None , & None , false , Target :: Nodejs )
183
225
. is_ok( ) ) ;
184
226
let package_json_path = & out_dir. join ( "package.json" ) ;
185
227
fs:: metadata ( package_json_path) . unwrap ( ) ;
@@ -213,7 +255,7 @@ fn it_creates_a_pkg_json_with_correct_files_on_nomodules() {
213
255
let crate_data = manifest:: CrateData :: new ( & fixture. path , None ) . unwrap ( ) ;
214
256
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
215
257
assert ! ( crate_data
216
- . write_package_json( & out_dir, & None , false , Target :: NoModules )
258
+ . write_package_json( & out_dir, & None , & None , false , Target :: NoModules )
217
259
. is_ok( ) ) ;
218
260
let package_json_path = & out_dir. join ( "package.json" ) ;
219
261
fs:: metadata ( package_json_path) . unwrap ( ) ;
@@ -247,7 +289,7 @@ fn it_creates_a_package_json_with_correct_files_when_out_name_is_provided() {
247
289
let crate_data = manifest:: CrateData :: new ( & fixture. path , Some ( "index" . to_owned ( ) ) ) . unwrap ( ) ;
248
290
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
249
291
assert ! ( crate_data
250
- . write_package_json( & out_dir, & None , false , Target :: Bundler )
292
+ . write_package_json( & out_dir, & None , & None , false , Target :: Bundler )
251
293
. is_ok( ) ) ;
252
294
let package_json_path = & fixture. path . join ( "pkg" ) . join ( "package.json" ) ;
253
295
fs:: metadata ( package_json_path) . unwrap ( ) ;
@@ -280,7 +322,7 @@ fn it_creates_a_pkg_json_in_out_dir() {
280
322
let crate_data = manifest:: CrateData :: new ( & fixture. path , None ) . unwrap ( ) ;
281
323
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
282
324
assert ! ( crate_data
283
- . write_package_json( & out_dir, & None , false , Target :: Bundler )
325
+ . write_package_json( & out_dir, & None , & None , false , Target :: Bundler )
284
326
. is_ok( ) ) ;
285
327
286
328
let package_json_path = & fixture. path . join ( & out_dir) . join ( "package.json" ) ;
@@ -295,7 +337,7 @@ fn it_creates_a_package_json_with_correct_keys_when_types_are_skipped() {
295
337
let crate_data = manifest:: CrateData :: new ( & fixture. path , None ) . unwrap ( ) ;
296
338
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
297
339
assert ! ( crate_data
298
- . write_package_json( & out_dir, & None , true , Target :: Bundler )
340
+ . write_package_json( & out_dir, & None , & None , true , Target :: Bundler )
299
341
. is_ok( ) ) ;
300
342
let package_json_path = & out_dir. join ( "package.json" ) ;
301
343
fs:: metadata ( package_json_path) . unwrap ( ) ;
@@ -337,7 +379,7 @@ fn it_creates_a_package_json_with_npm_dependencies_provided_by_wasm_bindgen() {
337
379
)
338
380
. unwrap ( ) ;
339
381
assert ! ( crate_data
340
- . write_package_json( & out_dir, & None , true , Target :: Bundler )
382
+ . write_package_json( & out_dir, & None , & None , true , Target :: Bundler )
341
383
. is_ok( ) ) ;
342
384
let package_json_path = & out_dir. join ( "package.json" ) ;
343
385
fs:: metadata ( package_json_path) . unwrap ( ) ;
@@ -409,7 +451,7 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() {
409
451
410
452
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
411
453
crate_data
412
- . write_package_json ( & out_dir, & None , true , Target :: Bundler )
454
+ . write_package_json ( & out_dir, & None , & None , true , Target :: Bundler )
413
455
. unwrap ( ) ;
414
456
415
457
let pkg = utils:: manifest:: read_package_json ( & fixture. path , & out_dir) . unwrap ( ) ;
@@ -425,7 +467,7 @@ fn it_sets_homepage_field_if_available_in_cargo_toml() {
425
467
426
468
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
427
469
crate_data
428
- . write_package_json ( & out_dir, & None , true , Target :: Bundler )
470
+ . write_package_json ( & out_dir, & None , & None , true , Target :: Bundler )
429
471
. unwrap ( ) ;
430
472
431
473
let pkg = utils:: manifest:: read_package_json ( & fixture. path , & out_dir) . unwrap ( ) ;
@@ -464,7 +506,7 @@ fn it_sets_keywords_field_if_available_in_cargo_toml() {
464
506
465
507
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
466
508
crate_data
467
- . write_package_json ( & out_dir, & None , true , Target :: Bundler )
509
+ . write_package_json ( & out_dir, & None , & None , true , Target :: Bundler )
468
510
. unwrap ( ) ;
469
511
470
512
let pkg = utils:: manifest:: read_package_json ( & fixture. path , & out_dir) . unwrap ( ) ;
@@ -482,7 +524,7 @@ fn it_sets_keywords_field_if_available_in_cargo_toml() {
482
524
483
525
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
484
526
crate_data
485
- . write_package_json ( & out_dir, & None , true , Target :: Bundler )
527
+ . write_package_json ( & out_dir, & None , & None , true , Target :: Bundler )
486
528
. unwrap ( ) ;
487
529
488
530
let pkg = utils:: manifest:: read_package_json ( & fixture. path , & out_dir) . unwrap ( ) ;
@@ -581,7 +623,7 @@ fn it_lists_license_files_in_files_field_of_package_json() {
581
623
wasm_pack:: command:: utils:: create_pkg_dir ( & out_dir) . unwrap ( ) ;
582
624
license:: copy_from_crate ( & crate_data, & fixture. path , & out_dir) . unwrap ( ) ;
583
625
crate_data
584
- . write_package_json ( & out_dir, & None , false , Target :: Bundler )
626
+ . write_package_json ( & out_dir, & None , & None , false , Target :: Bundler )
585
627
. unwrap ( ) ;
586
628
587
629
let package_json_path = & fixture. path . join ( "pkg" ) . join ( "package.json" ) ;
0 commit comments