@@ -316,8 +316,17 @@ struct PackageToJSPlugin: CommandPlugin {
316316 ) throws
317317 -> PackageManager . BuildResult
318318 {
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+ }
319328 var parameters = PackageManager . BuildParameters (
320- configuration: . inherit ,
329+ configuration: buildConfiguration ,
321330 logging: options. verbose ? . verbose : . concise
322331 )
323332 parameters. echoLogs = true
@@ -385,20 +394,37 @@ private func printStderr(_ message: String) {
385394extension PackageToJS . PackageOptions {
386395 static func parse( from extractor: inout ArgumentExtractor ) -> PackageToJS . PackageOptions {
387396 let outputPath = extractor. extractOption ( named: " output " ) . last
397+ let configuration : String ? = (
398+ extractor. extractOption ( named: " configuration " ) +
399+ extractor. extractSingleDashOption ( named: " c " )
400+ ) . last
388401 let packageName = extractor. extractOption ( named: " package-name " ) . last
389402 let explain = extractor. extractFlag ( named: " explain " )
390403 let useCDN = extractor. extractFlag ( named: " use-cdn " )
391404 let verbose = extractor. extractFlag ( named: " verbose " )
392405 let enableCodeCoverage = extractor. extractFlag ( named: " enable-code-coverage " )
393406 return PackageToJS . PackageOptions (
394407 outputPath: outputPath,
408+ configuration: configuration,
395409 packageName: packageName,
396410 explain: explain != 0 ,
397411 verbose: verbose != 0 ,
398412 useCDN: useCDN != 0 ,
399413 enableCodeCoverage: enableCodeCoverage != 0
400414 )
401415 }
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+ }
402428}
403429
404430extension PackageToJS . BuildOptions {
@@ -431,15 +457,10 @@ extension PackageToJS.BuildOptions {
431457 USAGE: swift package --swift-sdk <swift-sdk> [SwiftPM options] js [options] [subcommand]
432458
433459 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 ( ) )
443464
444465 SUBCOMMANDS:
445466 test Builds and runs tests
@@ -449,7 +470,7 @@ extension PackageToJS.BuildOptions {
449470 # Build a specific product
450471 $ swift package --swift-sdk wasm32-unknown-wasi js --product Example
451472 # 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
453474
454475 # Run tests
455476 $ swift package --swift-sdk wasm32-unknown-wasi js test
@@ -492,15 +513,12 @@ extension PackageToJS.TestOptions {
492513 USAGE: swift package --swift-sdk <swift-sdk> [SwiftPM options] js test [options]
493514
494515 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 ( ) )
504522
505523 EXAMPLES:
506524 $ swift package --swift-sdk wasm32-unknown-wasi js test
0 commit comments