Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PackageToJS: Generalize --verbose flag to all commands #307

Merged
merged 1 commit into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Plugins/PackageToJS/Sources/PackageToJS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ struct PackageToJS {
var packageName: String?
/// Whether to explain the build plan (default: false)
var explain: Bool = false
/// Whether to print verbose output
var verbose: Bool = false
/// Whether to use CDN for dependency packages (default: false)
var useCDN: Bool = false
/// Whether to enable code coverage collection (default: false)
Expand Down Expand Up @@ -49,8 +51,6 @@ struct PackageToJS {
var inspect: Bool
/// The extra arguments to pass to node
var extraNodeArguments: [String]
/// Whether to print verbose output
var verbose: Bool
/// The options for packaging
var packageOptions: PackageOptions
}
Expand Down Expand Up @@ -99,7 +99,7 @@ struct PackageToJS {
try PackageToJS.runSingleTestingLibrary(
testRunner: testRunner, currentDirectoryURL: currentDirectoryURL,
extraArguments: extraArguments,
testParser: testOptions.verbose ? nil : FancyTestsParser(write: { print($0, terminator: "") }),
testParser: testOptions.packageOptions.verbose ? nil : FancyTestsParser(write: { print($0, terminator: "") }),
testOptions: testOptions
)
}
Expand Down
19 changes: 10 additions & 9 deletions Plugins/PackageToJS/Sources/PackageToJSPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ struct PackageToJSPlugin: CommandPlugin {
let productName = try buildOptions.product ?? deriveDefaultProduct(package: context.package)
let build = try buildWasm(
productName: productName, context: context,
enableCodeCoverage: buildOptions.packageOptions.enableCodeCoverage
options: buildOptions.packageOptions
)
guard build.succeeded else {
reportBuildFailure(build, arguments)
Expand Down Expand Up @@ -212,7 +212,7 @@ struct PackageToJSPlugin: CommandPlugin {
let productName = "\(context.package.displayName)PackageTests"
let build = try buildWasm(
productName: productName, context: context,
enableCodeCoverage: testOptions.packageOptions.enableCodeCoverage
options: testOptions.packageOptions
)
guard build.succeeded else {
reportBuildFailure(build, arguments)
Expand Down Expand Up @@ -284,12 +284,12 @@ struct PackageToJSPlugin: CommandPlugin {
}
}

private func buildWasm(productName: String, context: PluginContext, enableCodeCoverage: Bool) throws
private func buildWasm(productName: String, context: PluginContext, options: PackageToJS.PackageOptions) throws
-> PackageManager.BuildResult
{
var parameters = PackageManager.BuildParameters(
configuration: .inherit,
logging: .concise
logging: options.verbose ? .verbose : .concise
)
parameters.echoLogs = true
parameters.otherSwiftcFlags = ["-color-diagnostics"]
Expand All @@ -308,7 +308,7 @@ struct PackageToJSPlugin: CommandPlugin {
]

// Enable code coverage options if requested
if enableCodeCoverage {
if options.enableCodeCoverage {
parameters.otherSwiftcFlags += ["-profile-coverage-mapping", "-profile-generate"]
parameters.otherCFlags += ["-fprofile-instr-generate", "-fcoverage-mapping"]
}
Expand Down Expand Up @@ -356,9 +356,10 @@ extension PackageToJS.PackageOptions {
let packageName = extractor.extractOption(named: "package-name").last
let explain = extractor.extractFlag(named: "explain")
let useCDN = extractor.extractFlag(named: "use-cdn")
let verbose = extractor.extractFlag(named: "verbose")
let enableCodeCoverage = extractor.extractFlag(named: "enable-code-coverage")
return PackageToJS.PackageOptions(
outputPath: outputPath, packageName: packageName, explain: explain != 0, useCDN: useCDN != 0, enableCodeCoverage: enableCodeCoverage != 0
outputPath: outputPath, packageName: packageName, explain: explain != 0, verbose: verbose != 0, useCDN: useCDN != 0, enableCodeCoverage: enableCodeCoverage != 0
)
}
}
Expand Down Expand Up @@ -390,6 +391,7 @@ extension PackageToJS.BuildOptions {
--output <path> Path to the output directory (default: .build/plugins/PackageToJS/outputs/Package)
--package-name <name> Name of the package (default: lowercased Package.swift name)
--explain Whether to explain the build plan
--verbose Whether to print verbose output
--no-optimize Whether to disable wasm-opt optimization
--use-cdn Whether to use CDN for dependency packages
--enable-code-coverage Whether to enable code coverage collection
Expand Down Expand Up @@ -419,14 +421,12 @@ extension PackageToJS.TestOptions {
let prelude = extractor.extractOption(named: "prelude").last
let environment = extractor.extractOption(named: "environment").last
let inspect = extractor.extractFlag(named: "inspect")
let verbose = extractor.extractFlag(named: "verbose")
let extraNodeArguments = extractor.extractSingleDashOption(named: "Xnode")
let packageOptions = PackageToJS.PackageOptions.parse(from: &extractor)
var options = PackageToJS.TestOptions(
buildOnly: buildOnly != 0, listTests: listTests != 0,
filter: filter, prelude: prelude, environment: environment, inspect: inspect != 0,
extraNodeArguments: extraNodeArguments,
verbose: verbose != 0,
packageOptions: packageOptions
)

Expand All @@ -448,9 +448,10 @@ extension PackageToJS.TestOptions {
--prelude <path> Path to the prelude script
--environment <name> The environment to use for the tests (values: node, browser; default: node)
--inspect Whether to run tests in the browser with inspector enabled
--explain Whether to explain the build plan
--verbose Whether to print verbose output
--use-cdn Whether to use CDN for dependency packages
--enable-code-coverage Whether to enable code coverage collection
--verbose Whether to print verbose output
-Xnode <args> Extra arguments to pass to Node.js

EXAMPLES:
Expand Down