/** * @file `glob` (async) and `globSync` — fast-glob wrappers with a * `node:fs.glob` fast-path when the option surface lines up. * `canUseNodeFsGlob` is the per-call gate. Trailing-slash workaround for * fast-glob ignore patterns * ───────────────────────────────────────────────────────── TL;DR: when you * pass `ignore: ['**\/dist/']` to fast-glob, the `dist` directory still gets * walked. Strip the trailing slash before passing it to fast-glob and the * ignore actually takes effect. Why this exists ─────────────── The gitignore * convention is to write directory entries with a trailing slash: `dist/`, * `node_modules/`, `coverage/`. Tools that translate gitignore lines into * glob patterns (including socket-cli's `globWithGitIgnore` helper, * npm-packlist, etc.) preserve that slash. fast-glob has TWO independent * filters that handle the trailing slash differently: * * 1. The DEEP filter decides whether to walk INTO a candidate directory. The * deep filter compiles `**\/dist/` into a regex that requires a trailing * slash on the input, but it tests `entryPath = 'dist'` (no slash, because * readdir entries don't include one). So fast-glob walks in anyway. * 2. The ENTRY filter (post-walk) retries with a trailing slash appended for * directory entries — so it correctly excludes the results, but only AFTER * the entire subtree has been walked. Net effect: a `dist/` ignore pattern * correctly removes contents from the result array, but only after * walking. On a 300k-file `dist/` under tight memory this is the * difference between "instant" and "OOM kill". Stripping the trailing * slash makes it `**\/dist`, which both filters interpret correctly. */ import { getNodeFs } from '../node/fs.js'; import { getNodeFsPromises } from '../node/fs/promises.js'; import type { FastGlobOptions, Pattern } from './types.js'; /** * Whether the caller's option bag is fully expressible with `node:fs.glob` * (`cwd` + `exclude`). Any other option means we must fall back to fast-glob, * which exposes the wider surface. * * Exported for unit tests; not part of the public API. * * @internal */ export declare function canUseNodeFsGlob(options: FastGlobOptions | undefined): boolean; /** * `node:fs.glob` / `node:fs.globSync` have no `onlyFiles` notion — they * return directories alongside files. fast-glob (the path this fast path * mirrors) defaults to `onlyFiles: true`, so the two engines must agree on * the default or the same pattern over the same tree returns a different * result set depending on which engine ran. Resolves each entry to an * absolute path relative to the effective cwd and drops directories via a * `stat` call — the same filtering fast-glob itself has to do internally. */ export declare function filterToFilesAsync(entries: string[], cwd: string | undefined, fsPromises: ReturnType): Promise; /** * Sync twin of {@link filterToFilesAsync}. */ export declare function filterToFilesSync(entries: string[], cwd: string | undefined, fs: ReturnType): string[]; /** * Asynchronously find files matching glob patterns. * * @example * ;```typescript * const files = await glob('src/*.ts', { cwd: '/tmp/project' }) * console.log(files) // ['src/index.ts', 'src/utils.ts'] * ``` */ export declare function glob(patterns: Pattern | Pattern[], options?: FastGlobOptions | undefined): Promise; /** * Synchronously find files matching glob patterns. Wrapper around * fast-glob.sync. * * @example * ;```typescript * const files = globSync('*.json', { cwd: '/tmp/project' }) * console.log(files) // ['package.json', 'tsconfig.json'] * ``` */ export declare function globSync(patterns: Pattern | Pattern[], options?: FastGlobOptions | undefined): string[];