Skip to content

Commit 6f781b8

Browse files
committed
@nodelib/fs.walk → fdir
1 parent e7abd6b commit 6f781b8

3 files changed

Lines changed: 21 additions & 23 deletions

File tree

packages/knip/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"generate-plugin-defs": "node ./scripts/generate-plugin-defs.js && (oxfmt src/plugins/index.ts src/types/PluginNames.ts src/schema/plugins.ts || true)"
9292
},
9393
"dependencies": {
94-
"@nodelib/fs.walk": "^1.2.3",
94+
"fdir": "^6.5.0",
9595
"formatly": "^0.3.0",
9696
"get-tsconfig": "4.14.0",
9797
"jiti": "^2.6.0",

packages/knip/src/util/glob-core.ts

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { readFileSync } from 'node:fs';
2-
import { promisify } from 'node:util';
3-
import { walk as _walk, type Entry } from '@nodelib/fs.walk';
2+
import { fdir } from 'fdir';
43
import { glob as tinyGlob, type GlobOptions as TinyGlobOptions } from 'tinyglobby';
54
import picomatch from 'picomatch';
65
import { GLOBAL_IGNORE_PATTERNS } from '../constants.ts';
@@ -9,9 +8,7 @@ import { debugLogObject } from './debug.ts';
98
import { isDirectory, isFile } from './fs.ts';
109
import { timerify } from './Performance.ts';
1110
import { expandIgnorePatterns, parseAndConvertGitignorePatterns } from './parse-and-convert-gitignores.ts';
12-
import { dirname, join, relative, toPosix } from './path.ts';
13-
14-
const walk = promisify(_walk);
11+
import { basename, dirname, join, relative, toPosix } from './path.ts';
1512

1613
type Options = { gitignore: boolean; cwd: string };
1714

@@ -170,22 +167,23 @@ export const findAndParseGitignores = async (cwd: string, workspaceDirs?: Set<st
170167
}
171168
}
172169

173-
const entryFilter = (entry: Entry) => {
174-
if (entry.dirent.isFile() && entry.name === '.gitignore') {
175-
addFile(entry.path);
176-
return true;
177-
}
178-
return false;
170+
const walkGitignores = async () => {
171+
await new fdir()
172+
.withFullPaths()
173+
.exclude((_dirName: string, dirPath: string) => {
174+
const absPath = toPosix(dirPath.endsWith('/') ? dirPath.slice(0, -1) : dirPath);
175+
return (isRelevantDir && !isRelevantDir(absPath)) || getMatcher()(relative(cwd, absPath));
176+
})
177+
.filter((filePath: string, isDir: boolean) => {
178+
if (isDir || basename(filePath) !== '.gitignore') return false;
179+
addFile(filePath);
180+
return true;
181+
})
182+
.crawl(cwd)
183+
.withPromise();
179184
};
180185

181-
const deepFilter = (entry: Entry) =>
182-
(!isRelevantDir || isRelevantDir(toPosix(entry.path))) && !getMatcher()(relative(cwd, entry.path));
183-
184-
await walk(cwd, {
185-
concurrency: 16,
186-
entryFilter,
187-
deepFilter,
188-
});
186+
await timerify(walkGitignores)();
189187

190188
// tinyglobby's `ignore` can't express unignores (see tinyglobby/fast-glob #86). Drop cached
191189
// ignore patterns shadowed by any unignore path (and its ancestor dirs) so glob() sees a

pnpm-lock.yaml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)