Skip to content

Commit d8358e6

Browse files
committed
BridgeJS: Improve diagnostics with multi-module AOT
1 parent f63bc56 commit d8358e6

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

Plugins/BridgeJS/Sources/BridgeJSCommandPlugin/BridgeJSCommandPlugin.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ extension BridgeJSCommandPlugin.Context {
164164
guard let dependencyTarget = bridgeJSTargets[dependency.name] else { continue }
165165
let dependencySkeletonPath = dependencyTarget.directoryURL
166166
.appending(path: "Generated/JavaScript/BridgeJS.json")
167+
guard FileManager.default.fileExists(atPath: dependencySkeletonPath.path) else {
168+
throw BridgeJSCommandPluginError(
169+
"""
170+
Dependency '\(dependencyTarget.name)' is configured for BridgeJS, but its AOT skeleton has not been generated yet. \
171+
Run `swift package bridge-js --target \(dependencyTarget.name)` to generate it first, \
172+
or run without `--target` to process in dependency order.
173+
"""
174+
)
175+
}
167176
generateArguments.append(contentsOf: [
168177
"--dependency-skeleton",
169178
"\(dependencyTarget.name)=\(dependencySkeletonPath.path)",
@@ -206,6 +215,14 @@ private func printStderr(_ message: String) {
206215
fputs(message + "\n", stderr)
207216
}
208217

218+
struct BridgeJSCommandPluginError: Error, CustomStringConvertible {
219+
let description: String
220+
221+
init(_ message: String) {
222+
self.description = message
223+
}
224+
}
225+
209226
extension SwiftSourceModuleTarget {
210227
func hasDependency(named name: String) -> Bool {
211228
return dependencies.contains(where: {

Tests/JavaScriptEventLoopTests/JSClosure+AsyncTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ class JSClosureAsyncTests: XCTestCase {
7272
)!.value()
7373
XCTAssertEqual(result, 42.0)
7474
}
75-
75+
7676
func testAsyncOneshotClosureWithPriority() async throws {
7777
let priority = UnsafeSendableBox<TaskPriority?>(nil)
7878
let closure = JSOneshotClosure.async(priority: .high) { _ in
@@ -83,7 +83,7 @@ class JSClosureAsyncTests: XCTestCase {
8383
XCTAssertEqual(result, 42.0)
8484
XCTAssertEqual(priority.value, .high)
8585
}
86-
86+
8787
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
8888
func testAsyncOneshotClosureWithTaskExecutor() async throws {
8989
let executor = AnyTaskExecutor()
@@ -93,7 +93,7 @@ class JSClosureAsyncTests: XCTestCase {
9393
let result = try await JSPromise(from: closure.function!())!.value()
9494
XCTAssertEqual(result, 42.0)
9595
}
96-
96+
9797
@available(macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *)
9898
func testAsyncOneshotClosureWithTaskExecutorPreference() async throws {
9999
let executor = AnyTaskExecutor()

0 commit comments

Comments
 (0)