Skip to content

Commit

Permalink
Add globby.stream typescript definition
Browse files Browse the repository at this point in the history
  • Loading branch information
futpib committed Jun 14, 2019
1 parent e3e933a commit 69940a0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions index.d.ts
Expand Up @@ -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.
Expand Down
28 changes: 28 additions & 0 deletions index.test-d.ts
Expand Up @@ -4,6 +4,7 @@ import {
GlobTask,
FilterFunction,
sync as globbySync,
stream as globbyStream,
generateGlobTasks,
hasMagic,
gitignore
Expand Down Expand Up @@ -45,6 +46,33 @@ expectType<string[]>(
expectType<string[]>(globbySync('*.tmp', {gitignore: true}));
expectType<string[]>(globbySync('*.tmp', {ignore: ['**/b.tmp']}));

// Globby (stream)
expectType<NodeJS.ReadableStream>(globbyStream('*.tmp'));
expectType<NodeJS.ReadableStream>(globbyStream(['a.tmp', '*.tmp', '!{c,d,e}.tmp']));

expectType<NodeJS.ReadableStream>(globbyStream('*.tmp', {expandDirectories: false}));
expectType<NodeJS.ReadableStream>(globbyStream('*.tmp', {expandDirectories: ['a*', 'b*']}));
expectType<NodeJS.ReadableStream>(
globbyStream('*.tmp', {
expandDirectories: {
files: ['a', 'b'],
extensions: ['tmp']
}
})
);
expectType<NodeJS.ReadableStream>(globbyStream('*.tmp', {gitignore: true}));
expectType<NodeJS.ReadableStream>(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<GlobTask[]>(generateGlobTasks('*.tmp'));
expectType<GlobTask[]>(generateGlobTasks(['a.tmp', '*.tmp', '!{c,d,e}.tmp']));
Expand Down

0 comments on commit 69940a0

Please sign in to comment.