1
1
'use strict' ;
2
2
3
3
const path = require ( 'path' ) ;
4
- const niceTry = require ( 'nice-try' ) ;
5
4
const resolveCommand = require ( './util/resolveCommand' ) ;
6
5
const escape = require ( './util/escape' ) ;
7
6
const readShebang = require ( './util/readShebang' ) ;
8
- const semver = require ( 'semver' ) ;
9
7
10
8
const isWin = process . platform === 'win32' ;
11
9
const isExecutableRegExp = / \. (?: c o m | e x e ) $ / i;
12
10
const isCmdShimRegExp = / n o d e _ m o d u l e s [ \\ / ] .b i n [ \\ / ] [ ^ \\ / ] + \. c m d $ / i;
13
11
14
- // `options.shell` is supported in Node ^4.8.0, ^5.7.0 and >= 6.0.0
15
- const supportsShellOption = niceTry ( ( ) => semver . satisfies ( process . version , '^4.8.0 || ^5.7.0 || >= 6.0.0' , true ) ) || false ;
16
-
17
12
function detectShebang ( parsed ) {
18
13
parsed . file = resolveCommand ( parsed ) ;
19
14
@@ -67,35 +62,6 @@ function parseNonShell(parsed) {
67
62
return parsed ;
68
63
}
69
64
70
- function parseShell ( parsed ) {
71
- // If node supports the shell option, there's no need to mimic its behavior
72
- if ( supportsShellOption ) {
73
- return parsed ;
74
- }
75
-
76
- // Mimic node shell option
77
- // See https://github.com/nodejs/node/blob/b9f6a2dc059a1062776133f3d4fd848c4da7d150/lib/child_process.js#L335
78
- const shellCommand = [ parsed . command ] . concat ( parsed . args ) . join ( ' ' ) ;
79
-
80
- if ( isWin ) {
81
- parsed . command = typeof parsed . options . shell === 'string' ? parsed . options . shell : process . env . comspec || 'cmd.exe' ;
82
- parsed . args = [ '/d' , '/s' , '/c' , `"${ shellCommand } "` ] ;
83
- parsed . options . windowsVerbatimArguments = true ; // Tell node's spawn that the arguments are already escaped
84
- } else {
85
- if ( typeof parsed . options . shell === 'string' ) {
86
- parsed . command = parsed . options . shell ;
87
- } else if ( process . platform === 'android' ) {
88
- parsed . command = '/system/bin/sh' ;
89
- } else {
90
- parsed . command = '/bin/sh' ;
91
- }
92
-
93
- parsed . args = [ '-c' , shellCommand ] ;
94
- }
95
-
96
- return parsed ;
97
- }
98
-
99
65
function parse ( command , args , options ) {
100
66
// Normalize arguments, similar to nodejs
101
67
if ( args && ! Array . isArray ( args ) ) {
@@ -119,7 +85,7 @@ function parse(command, args, options) {
119
85
} ;
120
86
121
87
// Delegate further parsing to shell or non-shell
122
- return options . shell ? parseShell ( parsed ) : parseNonShell ( parsed ) ;
88
+ return options . shell ? parsed : parseNonShell ( parsed ) ;
123
89
}
124
90
125
91
module . exports = parse ;
0 commit comments