@@ -4,6 +4,7 @@ const { EOL } = require('os');
44const meow = require ( 'meow' ) ;
55const path = require ( 'path' ) ;
66const { red, dim } = require ( 'picocolors' ) ;
7+ const { isPlainObject } = require ( './utils/validateTypes' ) ;
78
89const checkInvalidCLIOptions = require ( './utils/checkInvalidCLIOptions' ) ;
910const getFormatterOptionsText = require ( './utils/getFormatterOptionsText' ) ;
@@ -47,6 +48,7 @@ const EXIT_CODE_ERROR = 2;
4748 * @property {string } [syntax]
4849 * @property {string } [version]
4950 * @property {boolean } [allowEmptyInput]
51+ * @property {string } [globbyOptions]
5052 */
5153
5254/**
@@ -72,6 +74,7 @@ const EXIT_CODE_ERROR = 2;
7274 * @property {boolean } [quiet]
7375 * @property {any } [printConfig]
7476 * @property {boolean } [fix]
77+ * @property {Record<string, unknown> } [globbyOptions]
7578 * @property {boolean } [ignoreDisables]
7679 * @property {any } [ignorePath]
7780 * @property {string } [outputFile]
@@ -236,6 +239,10 @@ const meowOptions = {
236239 --allow-empty-input, --aei
237240
238241 When glob pattern matches no files, the process will exit without throwing an error.
242+
243+ --globby-options, --go
244+
245+ Options in JSON format passed to globby.
239246 ` ,
240247 flags : {
241248 allowEmptyInput : {
@@ -337,6 +344,10 @@ const meowOptions = {
337344 alias : 'v' ,
338345 type : 'boolean' ,
339346 } ,
347+ globbyOptions : {
348+ alias : 'go' ,
349+ type : 'string' ,
350+ } ,
340351 } ,
341352} ;
342353
@@ -397,6 +408,21 @@ module.exports = async (argv) => {
397408 : path . resolve ( process . cwd ( ) , cli . flags . configBasedir ) ;
398409 }
399410
411+ if ( cli . flags . globbyOptions ) {
412+ try {
413+ optionsBase . globbyOptions = await parseGlobbyOptions ( cli . flags . globbyOptions ) ;
414+ } catch ( error ) {
415+ if ( typeof error === 'string' ) {
416+ process . stderr . write ( `${ error } ${ EOL } ` ) ;
417+ process . exitCode = EXIT_CODE_ERROR ;
418+
419+ return ;
420+ }
421+
422+ throw error ;
423+ }
424+ }
425+
400426 if ( cli . flags . stdinFilename ) {
401427 optionsBase . codeFilename = cli . flags . stdinFilename ;
402428 }
@@ -542,6 +568,30 @@ function handleError(err) {
542568 process . exitCode = exitCode ;
543569}
544570
571+ /**
572+ * @param {string } value
573+ * @returns {Promise<Record<string, unknown>> }
574+ */
575+ function parseGlobbyOptions ( value ) {
576+ const errorMessage = ( ) =>
577+ `Invalid option ${ red ( '"--globby-options"' ) } .` +
578+ ` The value ${ red ( `"${ value } "` ) } is not valid JSON object.` ;
579+
580+ let options ;
581+
582+ try {
583+ options = JSON . parse ( value ) ;
584+ } catch ( _ ) {
585+ return Promise . reject ( errorMessage ( ) ) ;
586+ }
587+
588+ if ( isPlainObject ( options ) ) {
589+ return Promise . resolve ( options ) ;
590+ }
591+
592+ return Promise . reject ( errorMessage ( ) ) ;
593+ }
594+
545595/**
546596 * @param {string[] } argv
547597 * @returns {CLIOptions }
0 commit comments