@@ -99,16 +99,20 @@ object Runner {
99
99
}
100
100
}
101
101
102
- def runJvm (
102
+ private def envCommand (env : Map [String , String ]): Seq [String ] =
103
+ env.toVector.sortBy(_._1).map {
104
+ case (k, v) =>
105
+ s " $k= $v"
106
+ }
107
+
108
+ def jvmCommand (
103
109
javaCommand : String ,
104
110
javaArgs : Seq [String ],
105
111
classPath : Seq [File ],
106
112
mainClass : String ,
107
113
args : Seq [String ],
108
- logger : Logger ,
109
- allowExecve : Boolean = false ,
110
- cwd : Option [os.Path ] = None
111
- ): Process = {
114
+ extraEnv : Map [String , String ] = Map .empty
115
+ ): Seq [String ] = {
112
116
113
117
val command =
114
118
Seq (javaCommand) ++
@@ -120,10 +124,27 @@ object Runner {
120
124
) ++
121
125
args
122
126
127
+ envCommand(extraEnv) ++ command
128
+ }
129
+
130
+ def runJvm (
131
+ javaCommand : String ,
132
+ javaArgs : Seq [String ],
133
+ classPath : Seq [File ],
134
+ mainClass : String ,
135
+ args : Seq [String ],
136
+ logger : Logger ,
137
+ allowExecve : Boolean = false ,
138
+ cwd : Option [os.Path ] = None ,
139
+ extraEnv : Map [String , String ] = Map .empty
140
+ ): Process = {
141
+
142
+ val command = jvmCommand(javaCommand, javaArgs, classPath, mainClass, args, Map .empty)
143
+
123
144
if (allowExecve)
124
- maybeExec(" java" , command, logger, cwd = cwd)
145
+ maybeExec(" java" , command, logger, cwd = cwd, extraEnv = extraEnv )
125
146
else
126
- run(command, logger, cwd = cwd)
147
+ run(command, logger, cwd = cwd, extraEnv = extraEnv )
127
148
}
128
149
129
150
private def endsWithCaseInsensitive (s : String , suffix : String ): Boolean =
@@ -155,6 +176,23 @@ object Runner {
155
176
}
156
177
}
157
178
179
+ def jsCommand (
180
+ entrypoint : File ,
181
+ args : Seq [String ],
182
+ jsDom : Boolean = false
183
+ ): Seq [String ] = {
184
+
185
+ val nodePath = findInPath(" node" ).fold(" node" )(_.toString)
186
+ val command = Seq (nodePath, entrypoint.getAbsolutePath) ++ args
187
+
188
+ if (jsDom)
189
+ // FIXME We'd need to replicate what JSDOMNodeJSEnv does under-the-hood to get the command in that case.
190
+ // --command is mostly for debugging purposes, so I'm not sure it matters much here…
191
+ sys.error(" Cannot get command when JSDOM is enabled." )
192
+ else
193
+ " node" +: command.tail
194
+ }
195
+
158
196
def runJs (
159
197
entrypoint : File ,
160
198
args : Seq [String ],
@@ -168,31 +206,17 @@ object Runner {
168
206
import logger .{log , debug }
169
207
170
208
val nodePath = findInPath(" node" ).fold(" node" )(_.toString)
171
- val command = Seq (nodePath, entrypoint.getAbsolutePath) ++ args
172
209
173
- log(
174
- s " Running ${command.mkString(" " )}" ,
175
- " Running" + System .lineSeparator() +
176
- command.iterator.map(_ + System .lineSeparator()).mkString
177
- )
210
+ if (! jsDom && allowExecve && Execve .available()) {
178
211
179
- lazy val envJs =
180
- if (jsDom)
181
- new JSDOMNodeJSEnv (
182
- JSDOMNodeJSEnv .Config ()
183
- .withExecutable(nodePath)
184
- .withArgs(Nil )
185
- .withEnv(Map .empty)
186
- )
187
- else new NodeJSEnv (
188
- NodeJSEnv .Config ()
189
- .withExecutable(nodePath)
190
- .withArgs(Nil )
191
- .withEnv(Map .empty)
192
- .withSourceMap(sourceMap)
212
+ val command = Seq (nodePath, entrypoint.getAbsolutePath) ++ args
213
+
214
+ log(
215
+ s " Running ${command.mkString(" " )}" ,
216
+ " Running" + System .lineSeparator() +
217
+ command.iterator.map(_ + System .lineSeparator()).mkString
193
218
)
194
219
195
- if (! jsDom && allowExecve && Execve .available()) {
196
220
debug(" execve available" )
197
221
Execve .execve(
198
222
command.head,
@@ -202,6 +226,23 @@ object Runner {
202
226
sys.error(" should not happen" )
203
227
}
204
228
else {
229
+
230
+ val envJs =
231
+ if (jsDom)
232
+ new JSDOMNodeJSEnv (
233
+ JSDOMNodeJSEnv .Config ()
234
+ .withExecutable(nodePath)
235
+ .withArgs(Nil )
236
+ .withEnv(Map .empty)
237
+ )
238
+ else new NodeJSEnv (
239
+ NodeJSEnv .Config ()
240
+ .withExecutable(nodePath)
241
+ .withArgs(Nil )
242
+ .withEnv(Map .empty)
243
+ .withSourceMap(sourceMap)
244
+ )
245
+
205
246
val inputs = Seq (
206
247
if (esModule) Input .ESModule (entrypoint.toPath)
207
248
else Input .Script (entrypoint.toPath)
0 commit comments