11'use strict' ;
22
33const path = require ( 'path' ) ;
4- const niceTry = require ( 'nice-try' ) ;
54const resolveCommand = require ( './util/resolveCommand' ) ;
65const escape = require ( './util/escape' ) ;
76const readShebang = require ( './util/readShebang' ) ;
8- const semver = require ( 'semver' ) ;
97
108const isWin = process . platform === 'win32' ;
119const isExecutableRegExp = / \. (?: c o m | e x e ) $ / i;
1210const isCmdShimRegExp = / n o d e _ m o d u l e s [ \\ / ] .b i n [ \\ / ] [ ^ \\ / ] + \. c m d $ / i;
1311
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-
1712function detectShebang ( parsed ) {
1813 parsed . file = resolveCommand ( parsed ) ;
1914
@@ -67,35 +62,6 @@ function parseNonShell(parsed) {
6762 return parsed ;
6863}
6964
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-
9965function parse ( command , args , options ) {
10066 // Normalize arguments, similar to nodejs
10167 if ( args && ! Array . isArray ( args ) ) {
@@ -119,7 +85,7 @@ function parse(command, args, options) {
11985 } ;
12086
12187 // Delegate further parsing to shell or non-shell
122- return options . shell ? parseShell ( parsed ) : parseNonShell ( parsed ) ;
88+ return options . shell ? parsed : parseNonShell ( parsed ) ;
12389}
12490
12591module . exports = parse ;
0 commit comments