Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758import Foundation
@testable import ParcelDev
struct ScriptTestTool: Sendable { static let root = URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent() .deletingLastPathComponent() static let current = ScriptTestTool(root: root, environment: ProcessInfo.processInfo.environment) private static let toolEnvironment: Result<[String: String], any Error> = Result { let environment = ProcessInfo.processInfo.environment let result = try DevProcess.run("mise", ["env", "--json"], directory: root, environment: environment) guard result.status == 0 else { throw DevError("Pinned tool environment failed (\(result.status)): \(result.errorOutput)") } let configured = try JSONDecoder().decode([String: String].self, from: result.stdout) guard let path = configured["PATH"], !path.isEmpty else { throw DevError("Pinned tool environment must include PATH") } return environment.merging(configured) { _, selected in selected } } static var pinnedEnvironment: [String: String] { get throws { try toolEnvironment.get() } }
private let resolution: Result<URL, any Error>
init(root: URL, environment: [String: String]) { resolution = Result { try Self.resolve(root: root, environment: environment) } }
var binary: URL { get throws { try resolution.get() } }
private static func resolve(root: URL, environment: [String: String]) throws -> URL { var environment = environment if let override = environment["PARCEL_DEV_BINARY"] { guard !override.isEmpty else { throw DevError("PARCEL_DEV_BINARY must not be empty") } environment["PARCEL_DEV_BINARY"] = URL(fileURLWithPath: override, relativeTo: root).standardizedFileURL.path } let wrapper = root.appendingPathComponent("Scripts/parcel-dev.sh") let result = try DevProcess.run("/bin/sh", [wrapper.path, "--path"], directory: root, environment: environment) guard result.status == 0 else { throw DevError( "Developer tool resolution failed (\(result.status)) via \(wrapper.path): \(result.errorOutput)\(result.output)" ) } guard let output = String(data: result.stdout, encoding: .utf8), output.hasSuffix("\n") else { throw DevError("Developer tool resolver must return one UTF-8 path followed by a newline: \(wrapper.path)") } let path = String(output.dropLast()) guard path.hasPrefix("/"), !path.contains("\n"), !path.contains("\r"), !path.contains("\0") else { throw DevError("Developer tool resolver returned an invalid absolute path: \(wrapper.path)") } let binary = URL(fileURLWithPath: path).resolvingSymlinksInPath() guard try binary.resourceValues(forKeys: [.isRegularFileKey]).isRegularFile == true, FileManager.default.isExecutableFile(atPath: binary.path) else { throw DevError("Developer tool is not an executable file: \(binary.path)") } return binary }}