Skip to content

Commit 286f8ec

Browse files
authored
Remove macOS Monterey requirement from Package.swift (#144)
This currently prevents Tokamak from being built on macOS 11 or earlier macOS versions. I think the original concern is no longer an issue, where back-deployment with Xcode 13.2 to old macOS versions will become available really soon. In fact, beta versions of Xcode 13.2 are already available on GitHub Actions if we need to test with those. * Remove macOS Monterey requirement from `Package.swift` * Add `async` example code, clarify versions in `README.md`
1 parent 40b1614 commit 286f8ec

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

Package.swift

-6
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@ import PackageDescription
44

55
let package = Package(
66
name: "JavaScriptKit",
7-
platforms: [
8-
// This package doesn't work on macOS host, but should be able to be built for it
9-
// for developing on Xcode. This minimum version requirement is to prevent availability
10-
// errors for Concurrency API, whose runtime support is shipped from macOS 12.0
11-
.macOS("12.0")
12-
],
137
products: [
148
.library(name: "JavaScriptKit", targets: ["JavaScriptKit"]),
159
.library(name: "JavaScriptEventLoop", targets: ["JavaScriptEventLoop"]),

README.md

+46-2
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,56 @@ import JavaScriptEventLoop
8585
JavaScriptEventLoop.installGlobalExecutor()
8686
```
8787

88+
Then you can `await` on the `value` property of `JSPromise` instances, like in the example below:
89+
90+
```swift
91+
import JavaScriptKit
92+
import JavaScriptEventLoop
93+
94+
let alert = JSObject.global.alert.function!
95+
let document = JSObject.global.document
96+
97+
private let jsFetch = JSObject.global.fetch.function!
98+
func fetch(_ url: String) -> JSPromise {
99+
JSPromise(jsFetch(url).object!)!
100+
}
101+
102+
JavaScriptEventLoop.installGlobalExecutor()
103+
104+
struct Response: Decodable {
105+
let uuid: String
106+
}
107+
108+
var asyncButtonElement = document.createElement("button")
109+
asyncButtonElement.innerText = "Fetch UUID demo"
110+
asyncButtonElement.onclick = .object(JSClosure { _ in
111+
Task {
112+
do {
113+
let response = try await fetch("https://httpbin.org/uuid").value
114+
let json = try await JSPromise(response.json().object!)!.value
115+
let parsedResponse = try JSValueDecoder().decode(Response.self, from: json)
116+
alert(parsedResponse.uuid)
117+
} catch {
118+
print(error)
119+
}
120+
}
121+
122+
return .undefined
123+
})
124+
125+
_ = document.body.appendChild(asyncButtonElement)
126+
```
127+
88128
## Requirements
89129

90130
### For developers
91131

92-
- macOS 11 and Xcode 13.0. *Xcode 13.1 is currently not supported.*
93-
- [Swift 5.4 or later](https://swift.org/download/) and Ubuntu 18.04 if you'd like to use Linux.
132+
- macOS 11 and Xcode 13.2 or later versions, which support Swift Concurrency back-deployment.
133+
To use earlier versions of Xcode on macOS 11 you'll have to
134+
add `.unsafeFlags(["-Xfrontend", "-disable-availability-checking"])` in `Package.swift` manifest of
135+
your package that depends on JavaScriptKit. You can also use Xcode 13.0 and 13.1 on macOS Monterey,
136+
since this OS does not need back-deployment.
137+
- [Swift 5.5 or later](https://swift.org/download/) and Ubuntu 18.04 if you'd like to use Linux.
94138
Other Linux distributions are currently not supported.
95139

96140
### For users of apps depending

0 commit comments

Comments
 (0)