File tree 1 file changed +16
-1
lines changed
packages/vitest/src/node/cli
1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -196,11 +196,26 @@ export function createCLI(options: CliParseOptions = {}): CAC {
196
196
return cli
197
197
}
198
198
199
+ function splitArgv ( argv : string ) : string [ ] {
200
+ const reg = / ( [ ' " ] ) (?: (? ! \1) .) + \1/ g
201
+ argv = argv . replace ( reg , match => match . replace ( / \s / g, '\x00' ) )
202
+ return argv . split ( ' ' ) . map ( ( arg : string ) => {
203
+ arg = arg . replace ( / \0 / g, ' ' )
204
+ if ( arg . startsWith ( '"' ) && arg . endsWith ( '"' ) ) {
205
+ return arg . slice ( 1 , - 1 )
206
+ }
207
+ if ( arg . startsWith ( `'` ) && arg . endsWith ( `'` ) ) {
208
+ return arg . slice ( 1 , - 1 )
209
+ }
210
+ return arg
211
+ } )
212
+ }
213
+
199
214
export function parseCLI ( argv : string | string [ ] , config : CliParseOptions = { } ) : {
200
215
filter : string [ ]
201
216
options : CliOptions
202
217
} {
203
- const arrayArgs = typeof argv === 'string' ? argv . split ( ' ' ) : argv
218
+ const arrayArgs = typeof argv === 'string' ? splitArgv ( argv ) : argv
204
219
if ( arrayArgs [ 0 ] !== 'vitest' ) {
205
220
throw new Error ( `Expected "vitest" as the first argument, received "${ arrayArgs [ 0 ] } "` )
206
221
}
You can’t perform that action at this time.
0 commit comments