Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 24f1c4c

Browse files
Merge pull request #309 from swiftwasm/yt/configuration-option
Add `--configuration` option to `swift package js` command
2 parents f147dc5 + 344c855 commit 24f1c4c

File tree

3 files changed

+39
-21
lines changed

3 files changed

+39
-21
lines changed

‎Plugins/PackageToJS/Sources/PackageToJS.swift‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ struct PackageToJS {
44
struct PackageOptions {
55
/// Path to the output directory
66
var outputPath: String?
7+
/// The build configuration to use (default: debug)
8+
var configuration: String?
79
/// Name of the package (default: lowercased Package.swift name)
810
var packageName: String?
911
/// Whether to explain the build plan (default: false)

‎Plugins/PackageToJS/Sources/PackageToJSPlugin.swift‎

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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,35 @@ private func printStderr(_ message: String) {
385394
extension 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") + extractor.extractSingleDashOption(named: "c")).last
388399
let packageName = extractor.extractOption(named: "package-name").last
389400
let explain = extractor.extractFlag(named: "explain")
390401
let useCDN = extractor.extractFlag(named: "use-cdn")
391402
let verbose = extractor.extractFlag(named: "verbose")
392403
let enableCodeCoverage = extractor.extractFlag(named: "enable-code-coverage")
393404
return PackageToJS.PackageOptions(
394405
outputPath: outputPath,
406+
configuration: configuration,
395407
packageName: packageName,
396408
explain: explain != 0,
397409
verbose: verbose != 0,
398410
useCDN: useCDN != 0,
399411
enableCodeCoverage: enableCodeCoverage != 0
400412
)
401413
}
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+
}
402426
}
403427

404428
extension PackageToJS.BuildOptions {
@@ -431,15 +455,10 @@ extension PackageToJS.BuildOptions {
431455
USAGE: swift package --swift-sdk <swift-sdk> [SwiftPM options] js [options] [subcommand]
432456
433457
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())
443462
444463
SUBCOMMANDS:
445464
test Builds and runs tests
@@ -449,7 +468,7 @@ extension PackageToJS.BuildOptions {
449468
# Build a specific product
450469
$ swift package --swift-sdk wasm32-unknown-wasi js --product Example
451470
# 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
453472
454473
# Run tests
455474
$ swift package --swift-sdk wasm32-unknown-wasi js test
@@ -492,15 +511,12 @@ extension PackageToJS.TestOptions {
492511
USAGE: swift package --swift-sdk <swift-sdk> [SwiftPM options] js test [options]
493512
494513
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())
504520
505521
EXAMPLES:
506522
$ swift package --swift-sdk wasm32-unknown-wasi js test

‎Plugins/PackageToJS/Tests/ExampleTests.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ extension Trait where Self == ConditionTrait {
242242
@Test(.requireEmbeddedSwift) func embedded() throws {
243243
try withPackage(at: "Examples/Embedded") { packageDir, runSwift in
244244
try runSwift(
245-
["package", "--triple", "wasm32-unknown-none-wasm", "-c", "release", "js"],
245+
["package", "--triple", "wasm32-unknown-none-wasm", "js", "-c", "release"],
246246
[
247247
"JAVASCRIPTKIT_EXPERIMENTAL_EMBEDDED_WASM": "true"
248248
]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /