Skip to content

Commit 2995a90

Browse files
Small compile-speed optimization
1 parent f2b17d8 commit 2995a90

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

Plugins/PackageToJS/Sources/PackageToJS.swift

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,6 @@ struct PackageToJS {
3030
}
3131
}
3232

33-
func which(_ executable: String) throws -> URL {
34-
let pathSeparator: Character
35-
#if os(Windows)
36-
pathSeparator = ";"
37-
#else
38-
pathSeparator = ":"
39-
#endif
40-
let paths = ProcessInfo.processInfo.environment["PATH"]!.split(separator: pathSeparator)
41-
for path in paths {
42-
let url = URL(fileURLWithPath: String(path)).appendingPathComponent(executable)
43-
if FileManager.default.isExecutableFile(atPath: url.path) {
44-
return url
45-
}
46-
}
47-
throw PackageToJSError("Executable \(executable) not found in PATH")
48-
}
49-
5033
struct PackageToJSError: Swift.Error, CustomStringConvertible {
5134
let description: String
5235

@@ -297,3 +280,28 @@ struct PackagingPlanner {
297280
}
298281
}
299282
}
283+
284+
// MARK: - Utilities
285+
286+
func which(_ executable: String) throws -> URL {
287+
let pathSeparator: Character
288+
#if os(Windows)
289+
pathSeparator = ";"
290+
#else
291+
pathSeparator = ":"
292+
#endif
293+
let paths = ProcessInfo.processInfo.environment["PATH"]!.split(separator: pathSeparator)
294+
for path in paths {
295+
let url = URL(fileURLWithPath: String(path)).appendingPathComponent(executable)
296+
if FileManager.default.isExecutableFile(atPath: url.path) {
297+
return url
298+
}
299+
}
300+
throw PackageToJSError("Executable \(executable) not found in PATH")
301+
}
302+
303+
func logCommandExecution(_ command: String, _ arguments: [String]) {
304+
var fullArguments = [command]
305+
fullArguments.append(contentsOf: arguments)
306+
print("$ \(fullArguments.map { "\"\($0)\"" }.joined(separator: " "))")
307+
}

Plugins/PackageToJS/Sources/PackageToJSPlugin.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
#if canImport(PackagePlugin)
2-
@preconcurrency import Foundation // For "stderr"
2+
import struct Foundation.URL
3+
import struct Foundation.Data
4+
import class Foundation.Process
5+
import class Foundation.ProcessInfo
6+
import class Foundation.FileManager
7+
import func Foundation.fputs
8+
import func Foundation.exit
9+
@preconcurrency import var Foundation.stderr
310
import PackagePlugin
411

512
/// The main entry point for the PackageToJS plugin.
@@ -209,7 +216,7 @@ struct PackageToJSPlugin: CommandPlugin {
209216
let node = try which("node")
210217
let arguments = ["--experimental-wasi-unstable-preview1", testRunner.path] + extraArguments
211218
print("Running test...")
212-
print("$ \(([node.path] + arguments).map { "\"\($0)\"" }.joined(separator: " "))")
219+
logCommandExecution(node.path, arguments)
213220

214221
let task = Process()
215222
task.executableURL = node

0 commit comments

Comments
 (0)