Skip to content

Commit

Permalink
Update package
Browse files Browse the repository at this point in the history
  • Loading branch information
vmanot committed Dec 2, 2024
1 parent fa043d6 commit 6d80c19
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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())
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
46 changes: 0 additions & 46 deletions Sources/Merge/Intramodular/Process/_AsyncProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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, *)
Expand Down

0 comments on commit 6d80c19

Please sign in to comment.