Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/glob/__tests__/internal-globber.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,22 @@ describe('globber', () => {
}
})

it('captures large number of files', async () => {
const root = path.join(getTestTemp(), 'large-number-of-files')
await fs.mkdir(root, {recursive: true})

const promises: Promise<void>[] = []
for (let i = 0; i < 150000; i++) {
promises.push(
fs.writeFile(path.join(root, `item-${i}.txt`), 'test file content')
)
}

await Promise.all(promises)
const itemPaths = await glob(`${root}${path.sep}*`)
expect(itemPaths.length).toEqual(150000)
})

it('defaults to followSymbolicLinks=true', async () => {
// Create the following layout:
// <root>
Expand Down
11 changes: 7 additions & 4 deletions packages/glob/src/internal-globber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,13 @@ export class DefaultGlobber implements Globber {

// Push the child items in reverse
const childLevel = item.level + 1
const childItems = (await fs.promises.readdir(item.path)).map(
x => new SearchState(path.join(item.path, x), childLevel)
)
stack.push(...childItems.reverse())
const childItems = await fs.promises.readdir(item.path)

for (let i = childItems.length - 1; i >= 0; i--) {
stack.push(
new SearchState(path.join(item.path, childItems[i]), childLevel)
)
}
}
// File
else if (match & MatchKind.File) {
Expand Down