File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -18,8 +18,19 @@ const assertPatternsInput = patterns => {
1818 }
1919} ;
2020
21- const checkCwdOption = options => {
22- if ( options && options . cwd && ! fs . statSync ( options . cwd ) . isDirectory ( ) ) {
21+ const checkCwdOption = ( options = { } ) => {
22+ if ( ! options . cwd ) {
23+ return ;
24+ }
25+
26+ let stat ;
27+ try {
28+ stat = fs . statSync ( options . cwd ) ;
29+ } catch ( _ ) {
30+ return ;
31+ }
32+
33+ if ( ! stat . isDirectory ( ) ) {
2334 throw new Error ( 'The `cwd` option must be a path to a directory' ) ;
2435 }
2536} ;
Original file line number Diff line number Diff line change @@ -362,3 +362,13 @@ test('throws when specifying a file as cwd - stream', t => {
362362 globby . stream ( '*' , { cwd : isFile } ) ;
363363 } , 'The `cwd` option must be a path to a directory' ) ;
364364} ) ;
365+
366+ test ( 'don\'t throw when specifying a non-existing cwd directory - async' , async t => {
367+ const actual = await globby ( '.' , { cwd : '/unknown' } ) ;
368+ t . is ( actual . length , 0 ) ;
369+ } ) ;
370+
371+ test ( 'don\'t throw when specifying a non-existing cwd directory - sync' , t => {
372+ const actual = globby . sync ( '.' , { cwd : '/unknown' } ) ;
373+ t . is ( actual . length , 0 ) ;
374+ } ) ;
You can’t perform that action at this time.
0 commit comments