@@ -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,35 @@ 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 " ) + extractor. extractSingleDashOption ( named: " c " ) ) . last
388
399
let packageName = extractor. extractOption ( named: " package-name " ) . last
389
400
let explain = extractor. extractFlag ( named: " explain " )
390
401
let useCDN = extractor. extractFlag ( named: " use-cdn " )
391
402
let verbose = extractor. extractFlag ( named: " verbose " )
392
403
let enableCodeCoverage = extractor. extractFlag ( named: " enable-code-coverage " )
393
404
return PackageToJS . PackageOptions (
394
405
outputPath: outputPath,
406
+ configuration: configuration,
395
407
packageName: packageName,
396
408
explain: explain != 0 ,
397
409
verbose: verbose != 0 ,
398
410
useCDN: useCDN != 0 ,
399
411
enableCodeCoverage: enableCodeCoverage != 0
400
412
)
401
413
}
414
+
415
+ static func optionsHelp( ) -> String {
416
+ return """
417
+ --output <path> Path to the output directory (default: .build/plugins/PackageToJS/outputs/Package)
418
+ -c, --configuration <name> The build configuration to use (values: debug, release; default: debug)
419
+ --package-name <name> Name of the package (default: lowercased Package.swift name)
420
+ --use-cdn Whether to use CDN for dependency packages
421
+ --enable-code-coverage Whether to enable code coverage collection
422
+ --explain Whether to explain the build plan
423
+ --verbose Whether to print verbose output
424
+ """
425
+ }
402
426
}
403
427
404
428
extension PackageToJS . BuildOptions {
@@ -431,15 +455,10 @@ extension PackageToJS.BuildOptions {
431
455
USAGE: swift package --swift-sdk <swift-sdk> [SwiftPM options] js [options] [subcommand]
432
456
433
457
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)
458
+ --product <product> Product to build (default: executable target if there's only one)
459
+ --no-optimize Whether to disable wasm-opt optimization
460
+ --debug-info-format The format of debug info to keep in the final wasm file (values: none, dwarf, name; default: none)
461
+ \( PackageToJS . PackageOptions. optionsHelp ( ) )
443
462
444
463
SUBCOMMANDS:
445
464
test Builds and runs tests
@@ -449,7 +468,7 @@ extension PackageToJS.BuildOptions {
449
468
# Build a specific product
450
469
$ swift package --swift-sdk wasm32-unknown-wasi js --product Example
451
470
# Build in release configuration
452
- $ swift package --swift-sdk wasm32-unknown-wasi -c release plugin js
471
+ $ swift package --swift-sdk wasm32-unknown-wasi js -c release
453
472
454
473
# Run tests
455
474
$ swift package --swift-sdk wasm32-unknown-wasi js test
@@ -492,15 +511,12 @@ extension PackageToJS.TestOptions {
492
511
USAGE: swift package --swift-sdk <swift-sdk> [SwiftPM options] js test [options]
493
512
494
513
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
514
+ --build-only Whether to build only
515
+ --prelude <path> Path to the prelude script
516
+ --environment <name> The environment to use for the tests (values: node, browser; default: node)
517
+ --inspect Whether to run tests in the browser with inspector enabled
518
+ -Xnode <args> Extra arguments to pass to Node.js
519
+ \( PackageToJS . PackageOptions. optionsHelp ( ) )
504
520
505
521
EXAMPLES:
506
522
$ swift package --swift-sdk wasm32-unknown-wasi js test
0 commit comments