Skip to content

Commit b2a134c

Browse files
committed
Fix: avoid make parse-time Swift execution causing timeout
1 parent f47c310 commit b2a134c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Scripts/PackageTargetsParser.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ struct ErrorMessage: LocalizedError {
1818
/// A struct that parses a JSON file containing a "tags" array, extracting the "name" field from each element.
1919
struct PackageTargetsParser {
2020

21+
struct Root: Decodable {
22+
struct Tag: Decodable {
23+
let name: String
24+
}
25+
let tags: [Tag]
26+
}
27+
2128
/// Parses the provided JSON file and extracts the "name" values from the "tags" array.
2229
///
2330
/// - Parameter path: The path to the JSON file to be parsed.
@@ -42,12 +49,8 @@ struct PackageTargetsParser {
4249
/// ```
4350
func parse(from path: String) throws -> [String] {
4451
let data = try Data(contentsOf: URL(fileURLWithPath: path))
45-
let json = try JSONSerialization.jsonObject(with: data, options: [])
46-
if let dict = json as? [String: Any], let tags = dict["tags"] as? [[String: Any]] {
47-
return tags.compactMap { $0["name"] as? String }
48-
} else {
49-
throw ErrorMessage(message: "Properties not found.")
50-
}
52+
let root = try JSONDecoder().decode(Root.self, from: data)
53+
return root.tags.map(\.name)
5154
}
5255
}
5356

0 commit comments

Comments
 (0)