firefly-compiler 0.4.59 → 0.4.61

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -97,6 +97,34 @@ extend self: NodeSystem {
97
97
  }
98
98
  return ff_core_List.List_toMap(result, ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String);
99
99
  """
100
+
101
+ which(
102
+ command: String
103
+ workingDirectory: Option[Path] = None
104
+ environment: Option[Map[String, String]] = None
105
+ ): Option[String] {
106
+ let out = if(internalIsWindows()) {
107
+ self.execute(
108
+ "cmd.exe",
109
+ ["/c", "where", command],
110
+ workingDirectory = workingDirectory
111
+ environment = environment
112
+ windowsWhich = False
113
+ )
114
+ } else {
115
+ self.execute(
116
+ "which",
117
+ [command],
118
+ workingDirectory = workingDirectory
119
+ environment = environment
120
+ windowsWhich = False
121
+ )
122
+ }
123
+ out.standardOut.toString().lines().filter {line =>
124
+ out.exitCode == 0 &&
125
+ (!internalIsWindows() || line.split('\\').last().any {_.contains(".")})
126
+ }.first()
127
+ }
100
128
 
101
129
  execute(
102
130
  command: String
@@ -106,7 +134,7 @@ extend self: NodeSystem {
106
134
  environment: Option[Map[String, String]] = None
107
135
  maxBuffer: Int = 16777216
108
136
  killSignal: Int = 9
109
- windowsShell: Bool = True
137
+ windowsWhich: Bool = True
110
138
  ): ProcessResult
111
139
  target node async """
112
140
  import * as childProcess from 'node:child_process';
@@ -118,11 +146,10 @@ extend self: NodeSystem {
118
146
  ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String
119
147
  );
120
148
  }
121
- if(windowsShell_ && process.platform === 'win32') {
122
- arguments_ = ['/C', ...[command_, ...arguments_].map(argument =>
123
- argument.replaceAll(/([^A-Za-z0-9/_-])/g, "^$1")
124
- )];
125
- command_ = process.env.ComSpec || 'cmd.exe';
149
+ if(windowsWhich_ && process.platform === 'win32') {
150
+ command_ =
151
+ (await NodeSystem_which$(self_, command_, workingDirectory_, environment_, $task)).value_ ||
152
+ command_;
126
153
  }
127
154
  const newProcess = childProcess.spawn(command_, arguments_, {
128
155
  cwd: workingDirectory_.value_,
@@ -194,3 +221,15 @@ internalProcessError(problem: String): Error {
194
221
  error
195
222
  } grab()
196
223
  }
224
+
225
+ internalFindCommand(out: String): String {
226
+ out.lines().find {line =>
227
+ let l = line.lower()
228
+ l.endsWith(".exe") || l.endsWith(".cmd") || l.endsWith(".bat") || l.endsWith(".com")
229
+ }.else {""}
230
+ }
231
+
232
+ internalIsWindows(): Bool
233
+ target node sync """
234
+ return process.platform === 'win32';
235
+ """
@@ -127,6 +127,21 @@ return error_
127
127
  })))
128
128
  }
129
129
 
130
+ export function internalFindCommand_(out_) {
131
+ return ff_core_Option.Option_else(ff_core_List.List_find(ff_core_String.String_lines(out_), ((line_) => {
132
+ const l_ = ff_core_String.String_lower(line_);
133
+ return (((ff_core_String.String_endsWith(l_, ".exe") || ff_core_String.String_endsWith(l_, ".cmd")) || ff_core_String.String_endsWith(l_, ".bat")) || ff_core_String.String_endsWith(l_, ".com"))
134
+ })), (() => {
135
+ return ""
136
+ }))
137
+ }
138
+
139
+ export function internalIsWindows_() {
140
+
141
+ return process.platform === 'win32';
142
+
143
+ }
144
+
130
145
  export async function internalAssets_$(system_, $task) {
131
146
  return system_.assets_
132
147
  }
@@ -148,6 +163,19 @@ return error_
148
163
  })))
149
164
  }
150
165
 
166
+ export async function internalFindCommand_$(out_, $task) {
167
+ return ff_core_Option.Option_else(ff_core_List.List_find(ff_core_String.String_lines(out_), ((line_) => {
168
+ const l_ = ff_core_String.String_lower(line_);
169
+ return (((ff_core_String.String_endsWith(l_, ".exe") || ff_core_String.String_endsWith(l_, ".cmd")) || ff_core_String.String_endsWith(l_, ".bat")) || ff_core_String.String_endsWith(l_, ".com"))
170
+ })), (() => {
171
+ return ""
172
+ }))
173
+ }
174
+
175
+ export async function internalIsWindows_$($task) {
176
+ throw new Error('Function internalIsWindows is missing on this target in async context.');
177
+ }
178
+
151
179
  export function NodeSystem_arguments(self_) {
152
180
  throw new Error('Function NodeSystem_arguments is missing on this target in sync context.');
153
181
  }
@@ -244,7 +272,18 @@ export function NodeSystem_environment(self_) {
244
272
  throw new Error('Function NodeSystem_environment is missing on this target in sync context.');
245
273
  }
246
274
 
247
- export function NodeSystem_execute(self_, command_, arguments_, standardIn_ = ff_core_Buffer.new_(0), workingDirectory_ = ff_core_Option.None(), environment_ = ff_core_Option.None(), maxBuffer_ = 16777216, killSignal_ = 9, windowsShell_ = true) {
275
+ export function NodeSystem_which(self_, command_, workingDirectory_ = ff_core_Option.None(), environment_ = ff_core_Option.None()) {
276
+ const out_ = (ff_core_NodeSystem.internalIsWindows_()
277
+ ? ff_core_NodeSystem.NodeSystem_execute(self_, "cmd.exe", ["/c", "where", command_], ff_core_Buffer.new_(0, false), workingDirectory_, environment_, 16777216, 9, false)
278
+ : ff_core_NodeSystem.NodeSystem_execute(self_, "which", [command_], ff_core_Buffer.new_(0, false), workingDirectory_, environment_, 16777216, 9, false));
279
+ return ff_core_List.List_first(ff_core_List.List_filter(ff_core_String.String_lines(ff_core_Buffer.Buffer_toString(out_.standardOut_, "utf8")), ((line_) => {
280
+ return ((out_.exitCode_ === 0) && ((!ff_core_NodeSystem.internalIsWindows_()) || ff_core_Option.Option_any(ff_core_List.List_last(ff_core_String.String_split(line_, 92)), ((_w1) => {
281
+ return ff_core_String.String_contains(_w1, ".")
282
+ }))))
283
+ })))
284
+ }
285
+
286
+ export function NodeSystem_execute(self_, command_, arguments_, standardIn_ = ff_core_Buffer.new_(0), workingDirectory_ = ff_core_Option.None(), environment_ = ff_core_Option.None(), maxBuffer_ = 16777216, killSignal_ = 9, windowsWhich_ = true) {
248
287
  throw new Error('Function NodeSystem_execute is missing on this target in sync context.');
249
288
  }
250
289
 
@@ -358,7 +397,18 @@ export async function NodeSystem_environment$(self_, $task) {
358
397
 
359
398
  }
360
399
 
361
- export async function NodeSystem_execute$(self_, command_, arguments_, standardIn_ = ff_core_Buffer.new_(0), workingDirectory_ = ff_core_Option.None(), environment_ = ff_core_Option.None(), maxBuffer_ = 16777216, killSignal_ = 9, windowsShell_ = true, $task) {
400
+ export async function NodeSystem_which$(self_, command_, workingDirectory_ = ff_core_Option.None(), environment_ = ff_core_Option.None(), $task) {
401
+ const out_ = (ff_core_NodeSystem.internalIsWindows_()
402
+ ? (await ff_core_NodeSystem.NodeSystem_execute$(self_, "cmd.exe", ["/c", "where", command_], ff_core_Buffer.new_(0, false), workingDirectory_, environment_, 16777216, 9, false, $task))
403
+ : (await ff_core_NodeSystem.NodeSystem_execute$(self_, "which", [command_], ff_core_Buffer.new_(0, false), workingDirectory_, environment_, 16777216, 9, false, $task)));
404
+ return ff_core_List.List_first(ff_core_List.List_filter(ff_core_String.String_lines(ff_core_Buffer.Buffer_toString(out_.standardOut_, "utf8")), ((line_) => {
405
+ return ((out_.exitCode_ === 0) && ((!ff_core_NodeSystem.internalIsWindows_()) || ff_core_Option.Option_any(ff_core_List.List_last(ff_core_String.String_split(line_, 92)), ((_w1) => {
406
+ return ff_core_String.String_contains(_w1, ".")
407
+ }))))
408
+ })))
409
+ }
410
+
411
+ export async function NodeSystem_execute$(self_, command_, arguments_, standardIn_ = ff_core_Buffer.new_(0), workingDirectory_ = ff_core_Option.None(), environment_ = ff_core_Option.None(), maxBuffer_ = 16777216, killSignal_ = 9, windowsWhich_ = true, $task) {
362
412
 
363
413
  const childProcess = import$3;
364
414
  const environment = environment_.value_ !== void 0 ? {} : process.env;
@@ -369,11 +419,10 @@ export async function NodeSystem_execute$(self_, command_, arguments_, standardI
369
419
  ff_core_Ordering.ff_core_Ordering_Order$ff_core_String_String
370
420
  );
371
421
  }
372
- if(windowsShell_ && process.platform === 'win32') {
373
- arguments_ = ['/C', ...[command_, ...arguments_].map(argument =>
374
- argument.replaceAll(/([^A-Za-z0-9/_-])/g, "^$1")
375
- )];
376
- command_ = process.env.ComSpec || 'cmd.exe';
422
+ if(windowsWhich_ && process.platform === 'win32') {
423
+ command_ =
424
+ (await NodeSystem_which$(self_, command_, workingDirectory_, environment_, $task)).value_ ||
425
+ command_;
377
426
  }
378
427
  const newProcess = childProcess.spawn(command_, arguments_, {
379
428
  cwd: workingDirectory_.value_,
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "description": "Firefly compiler",
5
5
  "author": "Firefly team",
6
6
  "license": "MIT",
7
- "version": "0.4.59",
7
+ "version": "0.4.61",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/Ahnfelt/firefly-boot"
@@ -4,7 +4,7 @@
4
4
  "description": "Firefly language support",
5
5
  "author": "Firefly team",
6
6
  "license": "MIT",
7
- "version": "0.4.59",
7
+ "version": "0.4.61",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/Ahnfelt/firefly-boot"