Skip to content

Commit

Permalink
Support objectMode option in the TypeScript types (#178)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
Purpzie and sindresorhus authored Jun 16, 2021
1 parent c1a3b32 commit a08264f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
16 changes: 13 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {Options as FastGlobOptions} from 'fast-glob';
import {Options as FastGlobOptions, Entry as FastGlobEntry} from 'fast-glob';

declare namespace globby {
type ExpandDirectoriesOption =
| boolean
| readonly string[]
| {files?: readonly string[]; extensions?: readonly string[]};

type Entry = FastGlobEntry;

interface GlobbyOptions extends FastGlobOptions {
/**
If set to `true`, `globby` will automatically glob directories for you. If you define an `Array` it will only glob files that matches the patterns inside the `Array`. You can also define an `Object` with `files` and `extensions` like in the example below.
Expand Down Expand Up @@ -88,10 +90,13 @@ declare const globby: {
@param options - See the [`fast-glob` options](https:/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
@returns The matching paths.
*/
sync: (
sync: ((
patterns: string | readonly string[],
options: globby.GlobbyOptions & {objectMode: true}
) => globby.Entry[]) & ((
patterns: string | readonly string[],
options?: globby.GlobbyOptions
) => string[];
) => string[]);

/**
Find files and directories using glob patterns.
Expand Down Expand Up @@ -146,6 +151,11 @@ declare const globby: {

readonly gitignore: Gitignore;

(
patterns: string | readonly string[],
options: globby.GlobbyOptions & {objectMode: true}
): Promise<globby.Entry[]>;

/**
Find files and directories using glob patterns.
Expand Down
2 changes: 2 additions & 0 deletions index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ expectType<Promise<string[]>>(
);
expectType<Promise<string[]>>(globby('*.tmp', {gitignore: true}));
expectType<Promise<string[]>>(globby('*.tmp', {ignore: ['**/b.tmp']}));
expectType<Promise<globby.Entry[]>>(globby('*.tmp', {objectMode: true}));

// Globby (sync)
expectType<string[]>(globbySync('*.tmp'));
Expand All @@ -45,6 +46,7 @@ expectType<string[]>(
);
expectType<string[]>(globbySync('*.tmp', {gitignore: true}));
expectType<string[]>(globbySync('*.tmp', {ignore: ['**/b.tmp']}));
expectType<globby.Entry[]>(globbySync('*.tmp', {objectMode: true}));

// Globby (stream)
expectType<NodeJS.ReadableStream>(globbyStream('*.tmp'));
Expand Down

0 comments on commit a08264f

Please sign in to comment.