Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support objectMode option in the TypeScript types #178

Merged
merged 4 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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://github.com/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