Skip to content
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

Pass deep option to ignore filter to avoid unnecessary recursion #251

Merged
merged 2 commits into from
Jun 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions ignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@ const getIsIgnoredPredicate = (files, cwd) => {
const normalizeOptions = (options = {}) => ({
cwd: toPath(options.cwd) || process.cwd(),
suppressErrors: Boolean(options.suppressErrors),
deep: options.deep ? Number.parseInt(options.deep, 10) : Number.POSITIVE_INFINITY,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Number.parseInt call seems wrong. The deep option is documented to be a number. If anything, we should throw if it's not a number.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I tend to agree. What would you think about a simple typeof check defaulting to Number.POSITIVE_INFINITY, without throwing? That way, fast-glob remains in charge of validating its own options.

Happy to implement the throwing too, maybe using https://www.npmjs.com/package/@sindresorhus/is?

});

export const isIgnoredByIgnoreFiles = async (patterns, options) => {
const {cwd, suppressErrors} = normalizeOptions(options);
const {cwd, suppressErrors, deep} = normalizeOptions(options);

const paths = await fastGlob(patterns, {cwd, suppressErrors, ...ignoreFilesGlobOptions});
const paths = await fastGlob(patterns, {cwd, suppressErrors, deep, ...ignoreFilesGlobOptions});

const files = await Promise.all(
paths.map(async filePath => ({
Expand All @@ -77,9 +78,9 @@ export const isIgnoredByIgnoreFiles = async (patterns, options) => {
};

export const isIgnoredByIgnoreFilesSync = (patterns, options) => {
const {cwd, suppressErrors} = normalizeOptions(options);
const {cwd, suppressErrors, deep} = normalizeOptions(options);

const paths = fastGlob.sync(patterns, {cwd, suppressErrors, ...ignoreFilesGlobOptions});
const paths = fastGlob.sync(patterns, {cwd, suppressErrors, deep, ...ignoreFilesGlobOptions});

const files = paths.map(filePath => ({
filePath,
Expand Down