this repo has no description
www.jonmsterling.com/01HC/
1// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
2//
3// SPDX-License-Identifier: MPL-2.0
4
5import Foundation
6import TSCBasic
7import llbuild2fx
8
9extension Keys {
10 struct AnalyseImports: BuildKey {
11 typealias ValueType = [UnitName]
12 let blobId: LLBDataID
13
14 func computeValue(_ ctx: BuildContext<Self>) async throws -> [UnitName] {
15 let contents = try await ctx.load(blobId)
16 let code = try await String(decoding: Data(ctx.read(blob: contents.blob!)), as: UTF8.self)
17
18 var results: [UnitName] = []
19 let lines = code.split(separator: "\n", omittingEmptySubsequences: false)
20
21 for line in lines {
22 let trimmed = line.trimmingCharacters(in: .whitespaces)
23 guard trimmed.hasPrefix("import ") else { continue }
24 let parts = trimmed.split(separator: " ", maxSplits: 1, omittingEmptySubsequences: true)
25 if parts.count == 2 {
26 let name = parts[1].trimmingCharacters(in: .whitespaces)
27 results.append(UnitName(name: name))
28 }
29 }
30
31 return results
32 }
33 }
34}