diff --git a/index.d.ts b/index.d.ts index b124362..13cfb5d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -111,6 +111,16 @@ declare const globby: { options?: globby.GlobbyOptions ): string[]; + /** + @param patterns - See supported `minimatch` [patterns](https://github.com/isaacs/minimatch#usage). + @param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-1) in addition to the ones in this package. + @returns The stream of matching paths. + */ + stream( + patterns: string | readonly string[], + options?: globby.GlobbyOptions + ): NodeJS.ReadableStream; + /** Note that you should avoid running the same tasks multiple times as they contain a file system cache. Instead, run this method each time to ensure file system changes are taken into consideration. diff --git a/index.test-d.ts b/index.test-d.ts index 4e7a3f0..e71dff2 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -4,6 +4,7 @@ import { GlobTask, FilterFunction, sync as globbySync, + stream as globbyStream, generateGlobTasks, hasMagic, gitignore @@ -45,6 +46,33 @@ expectType( expectType(globbySync('*.tmp', {gitignore: true})); expectType(globbySync('*.tmp', {ignore: ['**/b.tmp']})); +// Globby (stream) +expectType(globbyStream('*.tmp')); +expectType(globbyStream(['a.tmp', '*.tmp', '!{c,d,e}.tmp'])); + +expectType(globbyStream('*.tmp', {expandDirectories: false})); +expectType(globbyStream('*.tmp', {expandDirectories: ['a*', 'b*']})); +expectType( + globbyStream('*.tmp', { + expandDirectories: { + files: ['a', 'b'], + extensions: ['tmp'] + } + }) +); +expectType(globbyStream('*.tmp', {gitignore: true})); +expectType(globbyStream('*.tmp', {ignore: ['**/b.tmp']})); + +(async () => { + const streamResult = []; + for await (const path of globbyStream('*.tmp')) { + streamResult.push(path); + } + // `NodeJS.ReadableStream` is not generic, unfortunately, + // so it seems `(string | Buffer)[]` is the best we can get here + expectType<(string | Buffer)[]>(streamResult); +})(); + // GenerateGlobTasks expectType(generateGlobTasks('*.tmp')); expectType(generateGlobTasks(['a.tmp', '*.tmp', '!{c,d,e}.tmp']));