@@ -23,6 +23,19 @@ test('no cmd file', function (t) {
23
23
'\n\n' +
24
24
'"$basedir/src.exe" "$@"\nexit $?\n' )
25
25
t . throws ( ( ) => fs . readFileSync ( to + '.cmd' , 'utf8' ) , 'cmd file not created' )
26
+ t . equal ( fs . readFileSync ( `${ to } .ps1` , 'utf8' ) ,
27
+ '#!/usr/bin/env pwsh' +
28
+ '\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent' +
29
+ '\n' +
30
+ '\n$exe=""' +
31
+ '\nif ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {' +
32
+ '\n # Fix case when both the Windows and Linux builds of Node' +
33
+ '\n # are installed in the same directory' +
34
+ '\n $exe=".exe"' +
35
+ '\n}' +
36
+ '\n& "$basedir/src.exe" $args' +
37
+ '\nexit $LASTEXITCODE' +
38
+ '\n' )
26
39
} )
27
40
} )
28
41
@@ -42,6 +55,19 @@ test('no shebang', function (t) {
42
55
'"$basedir/src.exe" "$@"\nexit $?\n' )
43
56
t . equal ( fs . readFileSync ( to + '.cmd' , 'utf8' ) ,
44
57
'@"%~dp0\\src.exe" %*\r\n' )
58
+ t . equal ( fs . readFileSync ( `${ to } .ps1` , 'utf8' ) ,
59
+ '#!/usr/bin/env pwsh' +
60
+ '\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent' +
61
+ '\n' +
62
+ '\n$exe=""' +
63
+ '\nif ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {' +
64
+ '\n # Fix case when both the Windows and Linux builds of Node' +
65
+ '\n # are installed in the same directory' +
66
+ '\n $exe=".exe"' +
67
+ '\n}' +
68
+ '\n& "$basedir/src.exe" $args' +
69
+ '\nexit $LASTEXITCODE' +
70
+ '\n' )
45
71
} )
46
72
} )
47
73
@@ -52,6 +78,7 @@ test('env shebang', function (t) {
52
78
. then ( ( ) => {
53
79
console . error ( '%j' , fs . readFileSync ( to , 'utf8' ) )
54
80
console . error ( '%j' , fs . readFileSync ( to + '.cmd' , 'utf8' ) )
81
+ console . error ( '%j' , fs . readFileSync ( `${ to } .ps1` , 'utf8' ) )
55
82
56
83
t . equal ( fs . readFileSync ( to , 'utf8' ) ,
57
84
'#!/bin/sh' +
@@ -78,6 +105,26 @@ test('env shebang', function (t) {
78
105
'\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r' +
79
106
'\n node "%~dp0\\src.env" %*\r' +
80
107
'\n)' )
108
+ t . equal ( fs . readFileSync ( `${ to } .ps1` , 'utf8' ) ,
109
+ '#!/usr/bin/env pwsh' +
110
+ '\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent' +
111
+ '\n' +
112
+ '\n$exe=""' +
113
+ '\nif ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {' +
114
+ '\n # Fix case when both the Windows and Linux builds of Node' +
115
+ '\n # are installed in the same directory' +
116
+ '\n $exe=".exe"' +
117
+ '\n}' +
118
+ '\n$ret=0' +
119
+ '\nif (Test-Path "$basedir/node$exe") {' +
120
+ '\n & "$basedir/node$exe" "$basedir/src.env" $args' +
121
+ '\n $ret=$LASTEXITCODE' +
122
+ '\n} else {' +
123
+ '\n & "node$exe" "$basedir/src.env" $args' +
124
+ '\n $ret=$LASTEXITCODE' +
125
+ '\n}' +
126
+ '\nexit $ret' +
127
+ '\n' )
81
128
t . end ( )
82
129
} )
83
130
} )
@@ -164,6 +211,7 @@ test('env shebang with args', function (t) {
164
211
. then ( ( ) => {
165
212
console . error ( '%j' , fs . readFileSync ( to , 'utf8' ) )
166
213
console . error ( '%j' , fs . readFileSync ( to + '.cmd' , 'utf8' ) )
214
+ console . error ( '%j' , fs . readFileSync ( `${ to } .ps1` , 'utf8' ) )
167
215
168
216
t . equal ( fs . readFileSync ( to , 'utf8' ) ,
169
217
'#!/bin/sh' +
@@ -190,6 +238,26 @@ test('env shebang with args', function (t) {
190
238
'\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r' +
191
239
'\n node --expose_gc "%~dp0\\src.env.args" %*\r' +
192
240
'\n)' )
241
+ t . equal ( fs . readFileSync ( `${ to } .ps1` , 'utf8' ) ,
242
+ '#!/usr/bin/env pwsh' +
243
+ '\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent' +
244
+ '\n' +
245
+ '\n$exe=""' +
246
+ '\nif ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {' +
247
+ '\n # Fix case when both the Windows and Linux builds of Node' +
248
+ '\n # are installed in the same directory' +
249
+ '\n $exe=".exe"' +
250
+ '\n}' +
251
+ '\n$ret=0' +
252
+ '\nif (Test-Path "$basedir/node$exe") {' +
253
+ '\n & "$basedir/node$exe" --expose_gc "$basedir/src.env.args" $args' +
254
+ '\n $ret=$LASTEXITCODE' +
255
+ '\n} else {' +
256
+ '\n & "node$exe" --expose_gc "$basedir/src.env.args" $args' +
257
+ '\n $ret=$LASTEXITCODE' +
258
+ '\n}' +
259
+ '\nexit $ret' +
260
+ '\n' )
193
261
t . end ( )
194
262
} )
195
263
} )
@@ -201,6 +269,7 @@ test('explicit shebang', function (t) {
201
269
. then ( ( ) => {
202
270
console . error ( '%j' , fs . readFileSync ( to , 'utf8' ) )
203
271
console . error ( '%j' , fs . readFileSync ( to + '.cmd' , 'utf8' ) )
272
+ console . error ( '%j' , fs . readFileSync ( `${ to } .ps1` , 'utf8' ) )
204
273
205
274
t . equal ( fs . readFileSync ( to , 'utf8' ) ,
206
275
'#!/bin/sh' +
@@ -228,6 +297,27 @@ test('explicit shebang', function (t) {
228
297
'\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r' +
229
298
'\n /usr/bin/sh "%~dp0\\src.sh" %*\r' +
230
299
'\n)' )
300
+
301
+ t . equal ( fs . readFileSync ( `${ to } .ps1` , 'utf8' ) ,
302
+ '#!/usr/bin/env pwsh' +
303
+ '\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent' +
304
+ '\n' +
305
+ '\n$exe=""' +
306
+ '\nif ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {' +
307
+ '\n # Fix case when both the Windows and Linux builds of Node' +
308
+ '\n # are installed in the same directory' +
309
+ '\n $exe=".exe"' +
310
+ '\n}' +
311
+ '\n$ret=0' +
312
+ '\nif (Test-Path "$basedir//usr/bin/sh$exe") {' +
313
+ '\n & "$basedir//usr/bin/sh$exe" "$basedir/src.sh" $args' +
314
+ '\n $ret=$LASTEXITCODE' +
315
+ '\n} else {' +
316
+ '\n & "/usr/bin/sh$exe" "$basedir/src.sh" $args' +
317
+ '\n $ret=$LASTEXITCODE' +
318
+ '\n}' +
319
+ '\nexit $ret' +
320
+ '\n' )
231
321
t . end ( )
232
322
} )
233
323
} )
@@ -239,6 +329,7 @@ test('explicit shebang with args', function (t) {
239
329
. then ( ( ) => {
240
330
console . error ( '%j' , fs . readFileSync ( to , 'utf8' ) )
241
331
console . error ( '%j' , fs . readFileSync ( to + '.cmd' , 'utf8' ) )
332
+ console . error ( '%j' , fs . readFileSync ( `${ to } .ps1` , 'utf8' ) )
242
333
243
334
t . equal ( fs . readFileSync ( to , 'utf8' ) ,
244
335
'#!/bin/sh' +
@@ -266,6 +357,27 @@ test('explicit shebang with args', function (t) {
266
357
'\n @SET PATHEXT=%PATHEXT:;.JS;=;%\r' +
267
358
'\n /usr/bin/sh -x "%~dp0\\src.sh.args" %*\r' +
268
359
'\n)' )
360
+
361
+ t . equal ( fs . readFileSync ( `${ to } .ps1` , 'utf8' ) ,
362
+ '#!/usr/bin/env pwsh' +
363
+ '\n$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent' +
364
+ '\n' +
365
+ '\n$exe=""' +
366
+ '\nif ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {' +
367
+ '\n # Fix case when both the Windows and Linux builds of Node' +
368
+ '\n # are installed in the same directory' +
369
+ '\n $exe=".exe"' +
370
+ '\n}' +
371
+ '\n$ret=0' +
372
+ '\nif (Test-Path "$basedir//usr/bin/sh$exe") {' +
373
+ '\n & "$basedir//usr/bin/sh$exe" -x "$basedir/src.sh.args" $args' +
374
+ '\n $ret=$LASTEXITCODE' +
375
+ '\n} else {' +
376
+ '\n & "/usr/bin/sh$exe" -x "$basedir/src.sh.args" $args' +
377
+ '\n $ret=$LASTEXITCODE' +
378
+ '\n}' +
379
+ '\nexit $ret' +
380
+ '\n' )
269
381
t . end ( )
270
382
} )
271
383
} )
0 commit comments