11'use strict' ;
22
3+ const isString = ( a ) => typeof a === 'string' ;
34const path = require ( 'path' ) ;
45const { EventEmitter} = require ( 'events' ) ;
56const util = require ( 'util' ) ;
@@ -10,10 +11,9 @@ const tryCatch = require('try-catch');
1011const tildify = require ( 'tildify' ) ;
1112const untildify = require ( 'untildify' ) ;
1213
13- const WIN = process . platform === 'win32' ;
14-
1514const find = require ( 'glob' ) ;
1615const win = require ( 'win32' ) ;
16+ const WIN = process . platform === 'win32' ;
1717
1818const newLine = ( error ) => {
1919 error . message += '\n' ;
@@ -56,10 +56,20 @@ Spawnify.prototype._onMessage = function onMessage(command, options) {
5656 const isCDWin = regExpCDWin . test ( command ) ;
5757
5858 const symbolsExec = [
59- '~' , '>' , '<' , '#' ,
60- '*' , '&' , '{' , '}' ,
61- '|' , '\'' , '"' , ';' ,
62- '`' , '$' ,
59+ '~' ,
60+ '>' ,
61+ '<' ,
62+ '#' ,
63+ '*' ,
64+ '&' ,
65+ '{' ,
66+ '}' ,
67+ '|' ,
68+ `'` ,
69+ '"' ,
70+ ';' ,
71+ '`' ,
72+ '$' ,
6373 ] ;
6474
6575 const isSymbol = isContain ( command , symbolsExec ) ;
@@ -68,13 +78,12 @@ Spawnify.prototype._onMessage = function onMessage(command, options) {
6878 assert ( command , 'options could not be empty!' ) ;
6979
7080 if ( isCD || isCDWin && WIN || isVolume ) {
71- command = command
72- . replace ( WIN ? regExpCDWin : regExpCD , '' ) ;
81+ command = command . replace ( WIN ? regExpCDWin : regExpCD , '' ) ;
7382
7483 this . _onCD ( command || '~' , dir ) ;
7584 } else {
7685 if ( WIN )
77- command = ' cmd /C ' + command ;
86+ command = ` cmd /C ${ command } ` ;
7887
7988 const [ firstChar ] = command ;
8089
@@ -190,7 +199,8 @@ Spawnify.prototype._setListeners = function setListeners(child) {
190199 } ) ;
191200
192201 if ( child . stdout ) {
193- child . stdout
202+ child
203+ . stdout
194204 . pipe ( win . unicodify ( ) )
195205 . setEncoding ( 'utf8' )
196206 . on ( 'data' , ( data ) => {
@@ -203,7 +213,9 @@ Spawnify.prototype._setListeners = function setListeners(child) {
203213 }
204214
205215 if ( child . stderr ) {
206- child . stderr . pipe ( win . unicodify ( ) )
216+ child
217+ . stderr
218+ . pipe ( win . unicodify ( ) )
207219 . setEncoding ( 'utf8' )
208220 . on ( 'data' , ( error ) => {
209221 this . _emit ( 'error' , Error ( error ) ) ;
@@ -261,8 +273,8 @@ Spawnify.prototype._onCD = function onCD(command, currDir) {
261273 const strs = [
262274 CD ,
263275 paramDir ,
264- '\'' + paramDir + '\'' ,
265- '"' + paramDir + '"' ,
276+ `' ${ paramDir } '` ,
277+ `" ${ paramDir } "` ,
266278 ] ;
267279
268280 for ( const str of strs ) {
@@ -279,7 +291,9 @@ Spawnify.prototype._onCD = function onCD(command, currDir) {
279291 }
280292
281293 if ( ! isWildCard )
282- return this . _set ( 'exec' , command , { cwd : paramDir } ) ;
294+ return this . _set ( 'exec' , command , {
295+ cwd : paramDir ,
296+ } ) ;
283297
284298 find ( paramDir , ( error , dirs ) => {
285299 let cwd ;
@@ -299,7 +313,7 @@ Spawnify.prototype._getFirstWord = function getFirstWord(str) {
299313 const regStrQuotes = '^"(.*)"' ;
300314 const regExp = RegExp ( regStr + regStrEnd ) ;
301315 const regExpQuotes = RegExp ( regStrQuotes + regStrEnd + '?' ) ;
302- const is = typeof str === 'string' ;
316+ const is = isString ( str ) ;
303317
304318 if ( ! is )
305319 return str ;
@@ -314,15 +328,18 @@ Spawnify.prototype._getFirstWord = function getFirstWord(str) {
314328} ;
315329
316330function getRegStrEnd ( ) {
317- const chars = [ 's' , ';' , '&&' , '\\' , '|' ] ;
331+ const chars = [
332+ 's' ,
333+ ';' ,
334+ '&&' ,
335+ '\\' ,
336+ '|' ,
337+ ] ;
318338 const escaped = chars
319- . map ( ( char ) => {
320- return '\\' + char ;
321- } ) . join ( '|' ) ;
339+ . map ( ( char ) => `\${char}` )
340+ . join ( '|' ) ;
322341
323- const regStr = '(' + escaped + ')' ;
324-
325- return regStr ;
342+ return `(${ escaped } )` ;
326343}
327344
328345function isContain ( str , symbols ) {
@@ -333,4 +350,3 @@ function isContain(str, symbols) {
333350 return str . includes ( symbol ) ;
334351 } ) ;
335352}
336-
0 commit comments