@@ -316,8 +316,17 @@ struct PackageToJSPlugin: CommandPlugin {
316
316
) throws
317
317
-> PackageManager . BuildResult
318
318
{
319
+ let buildConfiguration : PackageManager . BuildConfiguration
320
+ if let configuration = options. configuration {
321
+ guard let _buildConfiguration = PackageManager . BuildConfiguration ( rawValue: configuration) else {
322
+ fatalError ( " Invalid build configuration: \( configuration) " )
323
+ }
324
+ buildConfiguration = _buildConfiguration
325
+ } else {
326
+ buildConfiguration = . debug
327
+ }
319
328
var parameters = PackageManager . BuildParameters (
320
- configuration: . inherit ,
329
+ configuration: buildConfiguration ,
321
330
logging: options. verbose ? . verbose : . concise
322
331
)
323
332
parameters. echoLogs = true
@@ -385,20 +394,37 @@ private func printStderr(_ message: String) {
385
394
extension PackageToJS . PackageOptions {
386
395
static func parse( from extractor: inout ArgumentExtractor ) -> PackageToJS . PackageOptions {
387
396
let outputPath = extractor. extractOption ( named: " output " ) . last
397
+ let configuration : String ? = (
398
+ extractor. extractOption ( named: " configuration " ) +
399
+ extractor. extractSingleDashOption ( named: " c " )
400
+ ) . last
388
401
let packageName = extractor. extractOption ( named: " package-name " ) . last
389
402
let explain = extractor. extractFlag ( named: " explain " )
390
403
let useCDN = extractor. extractFlag ( named: " use-cdn " )
391
404
let verbose = extractor. extractFlag ( named: " verbose " )
392
405
let enableCodeCoverage = extractor. extractFlag ( named: " enable-code-coverage " )
393
406
return PackageToJS . PackageOptions (
394
407
outputPath: outputPath,
408
+ configuration: configuration,
395
409
packageName: packageName,
396
410
explain: explain != 0 ,
397
411
verbose: verbose != 0 ,
398
412
useCDN: useCDN != 0 ,
399
413
enableCodeCoverage: enableCodeCoverage != 0
400
414
)
401
415
}
416
+
417
+ static func optionsHelp( ) -> String {
418
+ return """
419
+ --output <path> Path to the output directory (default: .build/plugins/PackageToJS/outputs/Package)
420
+ -c, --configuration <name> The build configuration to use (values: debug, release; default: debug)
421
+ --package-name <name> Name of the package (default: lowercased Package.swift name)
422
+ --use-cdn Whether to use CDN for dependency packages
423
+ --enable-code-coverage Whether to enable code coverage collection
424
+ --explain Whether to explain the build plan
425
+ --verbose Whether to print verbose output
426
+ """
427
+ }
402
428
}
403
429
404
430
extension PackageToJS . BuildOptions {
@@ -431,15 +457,10 @@ extension PackageToJS.BuildOptions {
431
457
USAGE: swift package --swift-sdk <swift-sdk> [SwiftPM options] js [options] [subcommand]
432
458
433
459
OPTIONS:
434
- --product <product> Product to build (default: executable target if there's only one)
435
- --output <path> Path to the output directory (default: .build/plugins/PackageToJS/outputs/Package)
436
- --package-name <name> Name of the package (default: lowercased Package.swift name)
437
- --explain Whether to explain the build plan
438
- --verbose Whether to print verbose output
439
- --no-optimize Whether to disable wasm-opt optimization
440
- --use-cdn Whether to use CDN for dependency packages
441
- --enable-code-coverage Whether to enable code coverage collection
442
- --debug-info-format The format of debug info to keep in the final wasm file (values: none, dwarf, name; default: none)
460
+ --product <product> Product to build (default: executable target if there's only one)
461
+ --no-optimize Whether to disable wasm-opt optimization
462
+ --debug-info-format The format of debug info to keep in the final wasm file (values: none, dwarf, name; default: none)
463
+ \( PackageToJS . PackageOptions. optionsHelp ( ) )
443
464
444
465
SUBCOMMANDS:
445
466
test Builds and runs tests
@@ -449,7 +470,7 @@ extension PackageToJS.BuildOptions {
449
470
# Build a specific product
450
471
$ swift package --swift-sdk wasm32-unknown-wasi js --product Example
451
472
# Build in release configuration
452
- $ swift package --swift-sdk wasm32-unknown-wasi -c release plugin js
473
+ $ swift package --swift-sdk wasm32-unknown-wasi js -c release
453
474
454
475
# Run tests
455
476
$ swift package --swift-sdk wasm32-unknown-wasi js test
@@ -492,15 +513,12 @@ extension PackageToJS.TestOptions {
492
513
USAGE: swift package --swift-sdk <swift-sdk> [SwiftPM options] js test [options]
493
514
494
515
OPTIONS:
495
- --build-only Whether to build only
496
- --prelude <path> Path to the prelude script
497
- --environment <name> The environment to use for the tests (values: node, browser; default: node)
498
- --inspect Whether to run tests in the browser with inspector enabled
499
- --explain Whether to explain the build plan
500
- --verbose Whether to print verbose output
501
- --use-cdn Whether to use CDN for dependency packages
502
- --enable-code-coverage Whether to enable code coverage collection
503
- -Xnode <args> Extra arguments to pass to Node.js
516
+ --build-only Whether to build only
517
+ --prelude <path> Path to the prelude script
518
+ --environment <name> The environment to use for the tests (values: node, browser; default: node)
519
+ --inspect Whether to run tests in the browser with inspector enabled
520
+ -Xnode <args> Extra arguments to pass to Node.js
521
+ \( PackageToJS . PackageOptions. optionsHelp ( ) )
504
522
505
523
EXAMPLES:
506
524
$ swift package --swift-sdk wasm32-unknown-wasi js test
0 commit comments