Skip to content

Commit c10f600

Browse files
committed
Fix types for stats option
Fixes #139
1 parent a58d117 commit c10f600

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

index.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ console.log(paths);
179179
*/
180180
export function globby(
181181
patterns: string | readonly string[],
182-
options: Options & {objectMode: true}
182+
options: Options & ({objectMode: true} | {stats: true})
183183
): Promise<GlobEntry[]>;
184184
export function globby(
185185
patterns: string | readonly string[],
@@ -197,7 +197,7 @@ Note that glob patterns can only contain forward-slashes, not backward-slashes,
197197
*/
198198
export function globbySync(
199199
patterns: string | readonly string[],
200-
options: Options & {objectMode: true}
200+
options: Options & ({objectMode: true} | {stats: true})
201201
): GlobEntry[];
202202
export function globbySync(
203203
patterns: string | readonly string[],
@@ -224,7 +224,7 @@ for await (const path of globbyStream('*.tmp')) {
224224
*/
225225
export function globbyStream(
226226
patterns: string | readonly string[],
227-
options: Options & {objectMode: true}
227+
options: Options & ({objectMode: true} | {stats: true})
228228
): GlobbyEntryStream;
229229
export function globbyStream(
230230
patterns: string | readonly string[],

index.test-d.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ expectType<Promise<string[]>>(globby('*.tmp', {
3333
expectType<Promise<string[]>>(globby('*.tmp', {gitignore: true}));
3434
expectType<Promise<string[]>>(globby('*.tmp', {ignore: ['**/b.tmp']}));
3535
expectType<Promise<GlobEntry[]>>(globby('*.tmp', {objectMode: true}));
36+
expectType<Promise<GlobEntry[]>>(globby('*.tmp', {stats: true}));
3637

3738
// Globby (sync)
3839
expectType<string[]>(globbySync('*.tmp'));
@@ -49,6 +50,7 @@ expectType<string[]>(globbySync('*.tmp', {
4950
expectType<string[]>(globbySync('*.tmp', {gitignore: true}));
5051
expectType<string[]>(globbySync('*.tmp', {ignore: ['**/b.tmp']}));
5152
expectType<GlobEntry[]>(globbySync('*.tmp', {objectMode: true}));
53+
expectType<GlobEntry[]>(globbySync('*.tmp', {stats: true}));
5254

5355
// Globby (stream)
5456
expectType<GlobbyStream>(globbyStream('*.tmp'));
@@ -65,7 +67,9 @@ expectType<GlobbyStream>(globbyStream('*.tmp', {
6567
expectType<GlobbyStream>(globbyStream('*.tmp', {gitignore: true}));
6668
expectType<GlobbyStream>(globbyStream('*.tmp', {ignore: ['**/b.tmp']}));
6769
expectType<GlobbyEntryStream>(globbyStream('*.tmp', {objectMode: true}));
70+
expectType<GlobbyEntryStream>(globbyStream('*.tmp', {stats: true}));
6871
expectType<GlobbyEntryStream>(globbyStream('*.tmp', {objectMode: true, gitignore: true}));
72+
expectType<GlobbyEntryStream>(globbyStream('*.tmp', {stats: true, gitignore: true}));
6973

7074
// eslint-disable-next-line unicorn/prefer-top-level-await
7175
(async () => {
@@ -88,6 +92,16 @@ expectType<GlobbyEntryStream>(globbyStream('*.tmp', {objectMode: true, gitignore
8892
expectType<GlobEntry[]>(streamResult);
8993
})();
9094

95+
// eslint-disable-next-line unicorn/prefer-top-level-await
96+
(async () => {
97+
const streamResult = [];
98+
for await (const entry of globbyStream('*.tmp', {stats: true})) {
99+
streamResult.push(entry);
100+
}
101+
102+
expectType<GlobEntry[]>(streamResult);
103+
})();
104+
91105
// GenerateGlobTasks
92106
expectType<Promise<GlobTask[]>>(generateGlobTasks('*.tmp'));
93107
expectType<Promise<GlobTask[]>>(generateGlobTasks(['a.tmp', '*.tmp', '!{c,d,e}.tmp']));

tests/globby.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,27 @@ test('unique when using objectMode option', async t => {
743743
t.true(isUnique(result.map(({path}) => path)));
744744
});
745745

746+
test('stats option returns Entry objects with stats', async t => {
747+
const result = await runGlobby(t, '*.tmp', {cwd, stats: true});
748+
t.true(result.length > 0);
749+
for (const entry of result) {
750+
t.truthy(entry.path);
751+
t.truthy(entry.name);
752+
// Note: stats property exists but is filtered out in stabilizeResult for testing
753+
}
754+
});
755+
756+
test('gitignore option and stats option', async t => {
757+
const result = await runGlobby(t, 'fixtures/gitignore/*', {gitignore: true, stats: true});
758+
t.is(result.length, 1);
759+
t.truthy(result[0].path);
760+
});
761+
762+
test('unique when using stats option', async t => {
763+
const result = await runGlobby(t, ['a.tmp', '*.tmp'], {cwd, stats: true});
764+
t.true(isUnique(result.map(({path}) => path)));
765+
});
766+
746767
// Known limitation: ** in parentheses doesn't work (fast-glob #484)
747768
test.failing('** inside parentheses', async t => {
748769
const testDir = temporaryDirectory();

0 commit comments

Comments
 (0)