File tree Expand file tree Collapse file tree 2 files changed +34
-19
lines changed
Plugins/PackageToJS/Sources Expand file tree Collapse file tree 2 files changed +34
-19
lines changed Original file line number Diff line number Diff line change @@ -30,23 +30,6 @@ struct PackageToJS {
30
30
}
31
31
}
32
32
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
-
50
33
struct PackageToJSError : Swift . Error , CustomStringConvertible {
51
34
let description : String
52
35
@@ -297,3 +280,28 @@ struct PackagingPlanner {
297
280
}
298
281
}
299
282
}
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
+ }
Original file line number Diff line number Diff line change 1
1
#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
3
10
import PackagePlugin
4
11
5
12
/// The main entry point for the PackageToJS plugin.
@@ -209,7 +216,7 @@ struct PackageToJSPlugin: CommandPlugin {
209
216
let node = try which ( " node " )
210
217
let arguments = [ " --experimental-wasi-unstable-preview1 " , testRunner. path] + extraArguments
211
218
print ( " Running test... " )
212
- print ( " $ \( ( [ node. path] + arguments) . map { " \" \( $0 ) \" " } . joined ( separator : " " ) ) " )
219
+ logCommandExecution ( node. path, arguments)
213
220
214
221
let task = Process ( )
215
222
task. executableURL = node
You can’t perform that action at this time.
0 commit comments