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

Use vite as dev server instead of built-in one #509

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
45 changes: 4 additions & 41 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ let package = Package(
url: "https://github.com/apple/swift-argument-parser.git",
.upToNextMinor(from: "1.3.0")
),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.34.0"),
.package(
url: "https://github.com/swiftwasm/WasmTransformer",
.upToNextMinor(from: "0.5.0")
Expand All @@ -44,12 +43,6 @@ let package = Package(
),
.executableTarget(
name: "carton-frontend",
dependencies: [
"CartonFrontend"
]
),
.executableTarget(
name: "carton-frontend-slim",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"CartonHelpers",
Expand All @@ -64,7 +57,7 @@ let package = Package(
description: "Produces an optimized app bundle for distribution."
)
),
dependencies: ["carton-frontend-slim"],
dependencies: ["carton-frontend"],
exclude: [
"CartonCore/README.md",
"CartonPluginShared/README.md",
Expand All @@ -78,7 +71,7 @@ let package = Package(
description: "Run the tests in a WASI environment."
)
),
dependencies: ["carton-frontend-slim"],
dependencies: ["carton-frontend"],
exclude: [
"CartonCore/README.md",
"CartonPluginShared/README.md",
Expand All @@ -99,27 +92,6 @@ let package = Package(
]
),
.executableTarget(name: "carton-plugin-helper"),
.target(
name: "CartonFrontend",
dependencies: [
"CartonKit"
]
),
.target(
name: "CartonKit",
dependencies: [
.product(name: "NIOWebSocket", package: "swift-nio"),
.product(name: "NIOHTTP1", package: "swift-nio"),
.product(name: "NIO", package: "swift-nio"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
"CartonHelpers",
"WasmTransformer",
],
exclude: ["Utilities/README.md"],
swiftSettings: [
.enableUpcomingFeature("BareSlashRegexLiterals")
]
),
.target(
name: "SwiftToolchain",
dependencies: [
Expand Down Expand Up @@ -151,13 +123,6 @@ let package = Package(
name: "CartonCore",
exclude: ["README.md"]
),
.target(
name: "WebDriver",
dependencies: [
.product(name: "NIO", package: "swift-nio"),
"CartonHelpers",
]
),
// This target is used only for release automation tasks and
// should not be installed by `carton` users.
.executableTarget(
Expand All @@ -171,20 +136,18 @@ let package = Package(
.testTarget(
name: "CartonTests",
dependencies: [
"CartonFrontend",
"carton",
"CartonHelpers",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
),
.testTarget(
name: "CartonCommandTests",
dependencies: [
"CartonFrontend",
"SwiftToolchain",
"WebDriver",
"CartonHelpers",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
),
.testTarget(name: "WebDriverTests", dependencies: ["WebDriver"]),
]
)
3 changes: 1 addition & 2 deletions Plugins/CartonBundlePlugin/CartonBundlePluginCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct CartonBundlePluginCommand: CommandPlugin {

func performCommand(context: PluginContext, arguments: [String]) async throws {
try checkSwiftVersion()
try checkHelpFlag(arguments, frontend: "carton-frontend-slim", subcommand: "bundle", context: context)
try checkHelpFlag(arguments, subcommand: "bundle", context: context)

var extractor = ArgumentExtractor(arguments)
let options = Options.parse(from: &extractor)
Expand Down Expand Up @@ -86,7 +86,6 @@ struct CartonBundlePluginCommand: CommandPlugin {
} + extractor.remainingArguments
let frontend = try makeCartonFrontendProcess(
context: context,
frontend: "carton-frontend-slim",
arguments: frontendArguments
)
try frontend.checkRun(printsLoadingMessage: false, forwardExit: true)
Expand Down
7 changes: 6 additions & 1 deletion Plugins/CartonDevPlugin/CartonDevPluginCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ struct CartonDevPluginCommand: CommandPlugin {
var args: [String] = [
"dev",
"--main-wasm-path", productArtifact.path.string,
"--plugin-work-directory", context.pluginWorkDirectory.string,
"--build-request", buildRequestPipe,
"--build-response", buildResponsePipe
]
Expand All @@ -100,7 +101,11 @@ struct CartonDevPluginCommand: CommandPlugin {
args += extractor.remainingArguments

let frontend = try makeCartonFrontendProcess(context: context, arguments: args)
frontend.forwardTerminationSignals()
let signalSources = frontend.forwardTerminationSignals()
defer { signalSources.forEach { $0.cancel() } }
frontend.terminationHandler = { _ in
frontend.forwardExit()
}

try frontend.run()

Expand Down
4 changes: 2 additions & 2 deletions Plugins/CartonTestPlugin/CartonTestPluginCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct CartonTestPluginCommand: CommandPlugin {
func performCommand(context: PluginContext, arguments: [String]) async throws {
try checkSwiftVersion()
try checkHelpFlag(
arguments, frontend: "carton-frontend-slim", subcommand: "test", context: context)
arguments, subcommand: "test", context: context)

let productName = "\(context.package.displayName)PackageTests"

Expand Down Expand Up @@ -116,7 +116,7 @@ struct CartonTestPluginCommand: CommandPlugin {
}
args += extractor.remainingArguments
let frontend = try makeCartonFrontendProcess(
context: context, frontend: "carton-frontend-slim", arguments: args)
context: context, arguments: args)
try frontend.checkRun(printsLoadingMessage: false, forwardExit: true)
}

Expand Down
19 changes: 14 additions & 5 deletions Sources/CartonCore/FoundationProcessEx.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ import Foundation

extension Foundation.Process {
// Monitor termination/interrruption signals to forward them to child process
public func setSignalForwarding(_ signalNo: Int32) {
public func setSignalForwarding(_ signalNo: Int32) -> DispatchSourceSignal {
signal(signalNo, SIG_IGN)
let signalSource = DispatchSource.makeSignalSource(signal: signalNo)
signalSource.setEventHandler { [self] in
signalSource.cancel()
kill(processIdentifier, signalNo)
}
signalSource.resume()
return signalSource
}

public func forwardTerminationSignals() {
setSignalForwarding(SIGINT)
setSignalForwarding(SIGTERM)
public func forwardTerminationSignals() -> [DispatchSourceSignal] {
return [
setSignalForwarding(SIGINT),
setSignalForwarding(SIGTERM),
]
}

public var commandLine: String {
Expand Down Expand Up @@ -44,8 +47,14 @@ extension Foundation.Process {
print("Running \(try commandLine)")
}

let signalSources = forwardTerminationSignals()
defer {
for signalSource in signalSources {
signalSource.cancel()
}
}

try run()
forwardTerminationSignals()
waitUntilExit()

if forwardExit {
Expand Down
29 changes: 0 additions & 29 deletions Sources/CartonFrontend/CartonFrontendCommand.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import CartonHelpers
import Dispatch
import Foundation

Expand Down
4 changes: 2 additions & 2 deletions Sources/CartonHelpers/StaticArchive.swift

Large diffs are not rendered by default.

91 changes: 0 additions & 91 deletions Sources/WebDriver/CommandWebDriverService.swift

This file was deleted.

Loading