Skip to content

Commit 3a28601

Browse files
Fix read permission error on ignore files search (#259)
1 parent bd76374 commit 3a28601

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

fixtures/bad-permissions/noread/unreadable.js

Whitespace-only changes.

ignore.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ import slash from 'slash';
88
import {toPath} from 'unicorn-magic';
99
import {isNegativePattern} from './utilities.js';
1010

11+
const defaultIgnoredDirectories = [
12+
'**/node_modules',
13+
'**/flow-typed',
14+
'**/coverage',
15+
'**/.git',
16+
];
1117
const ignoreFilesGlobOptions = {
12-
ignore: [
13-
'**/node_modules',
14-
'**/flow-typed',
15-
'**/coverage',
16-
'**/.git',
17-
],
1818
absolute: true,
1919
dot: true,
2020
};
@@ -62,12 +62,13 @@ const normalizeOptions = (options = {}) => ({
6262
cwd: toPath(options.cwd) ?? process.cwd(),
6363
suppressErrors: Boolean(options.suppressErrors),
6464
deep: typeof options.deep === 'number' ? options.deep : Number.POSITIVE_INFINITY,
65+
ignore: [...options.ignore ?? [], ...defaultIgnoredDirectories],
6566
});
6667

6768
export const isIgnoredByIgnoreFiles = async (patterns, options) => {
68-
const {cwd, suppressErrors, deep} = normalizeOptions(options);
69+
const {cwd, suppressErrors, deep, ignore} = normalizeOptions(options);
6970

70-
const paths = await fastGlob(patterns, {cwd, suppressErrors, deep, ...ignoreFilesGlobOptions});
71+
const paths = await fastGlob(patterns, {cwd, suppressErrors, deep, ignore, ...ignoreFilesGlobOptions});
7172

7273
const files = await Promise.all(
7374
paths.map(async filePath => ({
@@ -80,9 +81,9 @@ export const isIgnoredByIgnoreFiles = async (patterns, options) => {
8081
};
8182

8283
export const isIgnoredByIgnoreFilesSync = (patterns, options) => {
83-
const {cwd, suppressErrors, deep} = normalizeOptions(options);
84+
const {cwd, suppressErrors, deep, ignore} = normalizeOptions(options);
8485

85-
const paths = fastGlob.sync(patterns, {cwd, suppressErrors, deep, ...ignoreFilesGlobOptions});
86+
const paths = fastGlob.sync(patterns, {cwd, suppressErrors, deep, ignore, ...ignoreFilesGlobOptions});
8687

8788
const files = paths.map(filePath => ({
8889
filePath,

tests/ignore.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import {chmod} from 'node:fs/promises';
12
import path from 'node:path';
23
import test from 'ava';
34
import slash from 'slash';
@@ -186,3 +187,21 @@ test('custom ignore files', async t => {
186187
],
187188
);
188189
});
190+
191+
test.serial('bad permissions', async t => {
192+
const cwd = path.join(PROJECT_ROOT, 'fixtures/bad-permissions');
193+
const noReadDirectory = path.join(cwd, 'noread');
194+
195+
await chmod(noReadDirectory, 0o000);
196+
197+
await t.notThrowsAsync(
198+
runIsIgnoredByIgnoreFiles(
199+
t,
200+
'**/*',
201+
{cwd, ignore: ['noread']},
202+
() => {},
203+
),
204+
);
205+
206+
t.teardown(() => chmod(noReadDirectory, 0o755));
207+
});

0 commit comments

Comments
 (0)