From 6d80c195b12e12d7a56f656e3d4482a31c6a703d Mon Sep 17 00:00:00 2001 From: Vatsal Manot Date: Mon, 2 Dec 2024 21:10:49 +0530 Subject: [PATCH] Update package --- .../Console/_StandardOutputRewriter.swift | 2 + .../Process/_AsyncProcess+Initializers.swift | 55 +++++++++++++++++++ .../Intramodular/Process/_AsyncProcess.swift | 46 ---------------- 3 files changed, 57 insertions(+), 46 deletions(-) create mode 100644 Sources/Merge/Intramodular/Process/_AsyncProcess+Initializers.swift diff --git a/Sources/Merge/Intramodular/Console/_StandardOutputRewriter.swift b/Sources/Merge/Intramodular/Console/_StandardOutputRewriter.swift index 3236a9e..adbe37a 100644 --- a/Sources/Merge/Intramodular/Console/_StandardOutputRewriter.swift +++ b/Sources/Merge/Intramodular/Console/_StandardOutputRewriter.swift @@ -126,6 +126,7 @@ public class _StandardOutputRewriter: @unchecked Sendable { } let buffer: Data = isStdout ? self.stdoutBuffer : self.stderrBuffer + self.processData(data, buffer: buffer, isStdout: isStdout) if self.isRunning { @@ -151,6 +152,7 @@ public class _StandardOutputRewriter: @unchecked Sendable { if let line = String(data: lineData, encoding: .utf8), let modifiedLine = modifyLine(line) { let fileHandle = FileHandle(fileDescriptor: isStdout ? originalSTDOUTDescriptor : originalSTDERRDescriptor) + fileHandle.write(modifiedLine.data(using: .utf8) ?? Data()) } } diff --git a/Sources/Merge/Intramodular/Process/_AsyncProcess+Initializers.swift b/Sources/Merge/Intramodular/Process/_AsyncProcess+Initializers.swift new file mode 100644 index 0000000..b2ffb43 --- /dev/null +++ b/Sources/Merge/Intramodular/Process/_AsyncProcess+Initializers.swift @@ -0,0 +1,55 @@ +// +// Copyright (c) Vatsal Manot +// + +import Combine +import Diagnostics +import Foundation +@_spi(Internal) import Swallow +import System + +// MARK: - Initializers + +#if os(macOS) || targetEnvironment(macCatalyst) +@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) +@available(macCatalyst, unavailable) +extension _AsyncProcess { + public convenience init( + executableURL: URL?, + arguments: [String], + currentDirectoryURL: URL? = nil, + environmentVariables: [String: String] = [:], + options: [_AsyncProcess.Option]? + ) throws { + #if os(macOS) + try self.init( + existingProcess: nil, + options: options + ) + + self.process.executableURL = executableURL ?? URL(fileURLWithPath: "/bin/zsh") + self.process.arguments = arguments + self.process.currentDirectoryURL = currentDirectoryURL?._fromURLToFileURL() + self.process.environment = environmentVariables + #else + fatalError(.unsupported) + #endif + } + + public convenience init( + launchPath: String?, + arguments: [String], + currentDirectoryURL: URL? = nil, + environmentVariables: [String: String] = [:], + options: [_AsyncProcess.Option]? + ) throws { + try self.init( + executableURL: launchPath.map({ URL(fileURLWithPath: $0) }), + arguments: arguments, + currentDirectoryURL: currentDirectoryURL, + environmentVariables: environmentVariables, + options: options + ) + } +} +#endif diff --git a/Sources/Merge/Intramodular/Process/_AsyncProcess.swift b/Sources/Merge/Intramodular/Process/_AsyncProcess.swift index 9a4777a..6174873 100644 --- a/Sources/Merge/Intramodular/Process/_AsyncProcess.swift +++ b/Sources/Merge/Intramodular/Process/_AsyncProcess.swift @@ -641,52 +641,6 @@ extension _AsyncProcess { } #endif -// MARK: - Initializers - -#if os(macOS) || targetEnvironment(macCatalyst) -@available(macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0, *) -@available(macCatalyst, unavailable) -extension _AsyncProcess { - public convenience init( - executableURL: URL?, - arguments: [String], - currentDirectoryURL: URL? = nil, - environmentVariables: [String: String] = [:], - options: [_AsyncProcess.Option]? - ) throws { - #if os(macOS) - try self.init( - existingProcess: nil, - options: options - ) - - self.process.executableURL = executableURL ?? URL(fileURLWithPath: "/bin/zsh") - self.process.arguments = arguments - self.process.currentDirectoryURL = currentDirectoryURL?._fromURLToFileURL() - self.process.environment = environmentVariables - #else - fatalError(.unsupported) - #endif - } - - public convenience init( - launchPath: String?, - arguments: [String], - currentDirectoryURL: URL? = nil, - environmentVariables: [String: String] = [:], - options: [_AsyncProcess.Option]? - ) throws { - try self.init( - executableURL: launchPath.map({ URL(fileURLWithPath: $0) }), - arguments: arguments, - currentDirectoryURL: currentDirectoryURL, - environmentVariables: environmentVariables, - options: options - ) - } -} -#endif - // MARK: - Conformances @available(macOS 11.0, *)