-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(typescript-estree): replace globby
w/ fast-glob
#9518
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import debug from 'debug'; | ||
import { sync as globSync } from 'globby'; | ||
import { sync as globSync } from 'fast-glob'; | ||
import isGlob from 'is-glob'; | ||
|
||
import type { CanonicalPath } from '../create-program/shared'; | ||
|
@@ -56,15 +56,15 @@ export function resolveProjectList( | |
|
||
const projectFolderIgnoreList = ( | ||
options.projectFolderIgnoreList ?? ['**/node_modules/**'] | ||
) | ||
.reduce<string[]>((acc, folder) => { | ||
if (typeof folder === 'string') { | ||
acc.push(folder); | ||
} | ||
return acc; | ||
}, []) | ||
// prefix with a ! for not match glob | ||
.map(folder => (folder.startsWith('!') ? folder : `!${folder}`)); | ||
).reduce<string[]>((acc, folder) => { | ||
if (typeof folder === 'string') { | ||
acc.push( | ||
// prefix with a ! for not match glob | ||
folder.startsWith('!') ? folder : `!${folder}`, | ||
); | ||
} | ||
return acc; | ||
}, []); | ||
|
||
const cacheKey = getHash({ | ||
project: sanitizedProjects, | ||
|
@@ -93,16 +93,23 @@ export function resolveProjectList( | |
const nonGlobProjects = sanitizedProjects.filter(project => !isGlob(project)); | ||
const globProjects = sanitizedProjects.filter(project => isGlob(project)); | ||
|
||
let globProjectPaths: string[] = []; | ||
|
||
if (globProjects.length > 0) { | ||
// Although fast-glob supports multiple patterns, fast-glob returns arbitrary order of results | ||
// to improve performance. To ensure the order is correct, we need to call fast-glob for each pattern | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OOC, does the order matter? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a unit test case against the order, so yes, it does matter. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But why does the order matter? Shouldn't the unit test just check that the needed files are linted? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Folks sometimes do things like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha, thanks! |
||
// separately and then concatenate the results in patterns' order. | ||
globProjectPaths = globProjects.flatMap(pattern => | ||
globSync(pattern, { | ||
cwd: options.tsconfigRootDir, | ||
ignore: projectFolderIgnoreList, | ||
}), | ||
); | ||
} | ||
|
||
const uniqueCanonicalProjectPaths = new Map( | ||
nonGlobProjects | ||
.concat( | ||
globProjects.length === 0 | ||
? [] | ||
: globSync([...globProjects, ...projectFolderIgnoreList], { | ||
cwd: options.tsconfigRootDir, | ||
dot: true, | ||
}), | ||
) | ||
.concat(globProjectPaths) | ||
.map(project => [ | ||
getCanonicalFileName( | ||
ensureAbsolutePath(project, options.tsconfigRootDir), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bonus change, replace the
.reduce.map
chain with a single.reduce
to avoid unnecessary iteration.