Skip to content

Commit 22c8fb6

Browse files
Ensuring in most cases (no --ignore-path option used) ignored folders are never even entered
1 parent 6478420 commit 22c8fb6

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

package-lock.json

+23-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"specialist": "^1.4.0",
5151
"tiny-editorconfig": "^1.0.0",
5252
"tiny-jsonc": "^1.0.1",
53-
"tiny-readdir-glob": "^1.22.24",
53+
"tiny-readdir-glob-gitignore": "^1.0.2",
5454
"tiny-spinner": "^2.0.3",
5555
"worktank": "^2.6.1",
5656
"zeptomatch": "^2.0.0",

src/index.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ async function runGlobs(options: Options, pluginsOptions: PluginsOptions): Promi
4949

5050
const rootPath = process.cwd();
5151
const projectPath = getProjectPath(rootPath);
52-
const [filesPaths, filesNames, filesNamesToPaths, filesFoundPaths, foldersFoundPaths] = await getTargetsPaths(rootPath, options.globs, options.withNodeModules); // prettier-ignore
52+
const ignoreFiles = options.ignorePath ? [] : [".gitignore", ".prettierignore"];
53+
const [filesPaths, filesNames, filesNamesToPaths, filesFoundPaths, foldersFoundPaths] = await getTargetsPaths(rootPath, options.globs, ignoreFiles, options.withNodeModules); // prettier-ignore
5354
const filesPathsTargets = filesPaths.filter(negate(isBinaryPath)).sort();
5455
const [foldersPathsTargets, foldersExtraPaths] = getExpandedFoldersPaths(foldersFoundPaths, projectPath);
5556
const filesExtraPaths = await getFoldersChildrenPaths([rootPath, ...foldersExtraPaths]);
@@ -102,7 +103,7 @@ async function runGlobs(options: Options, pluginsOptions: PluginsOptions): Promi
102103
//TODO: Maybe do work in chunks here, as keeping too many formatted files in memory can be a problem
103104
const filesResults = await Promise.allSettled(
104105
filesPathsTargets.map(async (filePath) => {
105-
const isIgnored = () => (ignoreManual ? ignoreManual(filePath) : getIgnoreResolved(filePath, ignoreNames));
106+
const isIgnored = () => !ignoreFiles.length && (ignoreManual ? ignoreManual(filePath) : getIgnoreResolved(filePath, ignoreNames));
106107
const isCacheable = () => cache?.has(filePath, isIgnored);
107108
const ignored = cache ? !(await isCacheable()) : await isIgnored();
108109
if (ignored) return;

src/utils.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { text as stream2text } from "node:stream/consumers";
1010
import url from "node:url";
1111
import resolveTimeout from "promise-resolve-timeout";
1212
import { exit } from "specialist";
13-
import readdir from "tiny-readdir-glob";
13+
import readdir from "tiny-readdir-glob-gitignore";
1414
import zeptomatchEscape from "zeptomatch-escape";
1515
import zeptomatchIsStatic from "zeptomatch-is-static";
1616
import type { ContextOptions, FormatOptions, FunctionMaybe, Key, LogLevel, Options, PrettierConfigWithOverrides, PrettierPlugin } from "./types.js";
@@ -87,11 +87,13 @@ async function getFoldersChildrenPaths(foldersPaths: string[]): Promise<string[]
8787
return childrenPaths;
8888
}
8989

90-
function getGlobPaths(rootPath: string, globs: string[], withNodeModules: boolean) {
90+
function getGlobPaths(rootPath: string, globs: string[], ignoreFiles: string[], withNodeModules: boolean) {
9191
return readdir(globs, {
9292
cwd: rootPath,
9393
followSymlinks: false,
9494
ignore: `**/{.git,.sl,.svn,.hg,.DS_Store,Thumbs.db${withNodeModules ? "" : ",node_modules"}}`,
95+
ignoreFiles,
96+
ignoreFilesFindAbove: false,
9597
});
9698
}
9799

@@ -184,6 +186,7 @@ const getStdin = once(async (): Promise<string | undefined> => {
184186
async function getTargetsPaths(
185187
rootPath: string,
186188
globs: string[],
189+
ignoreFiles: string[],
187190
withNodeModules: boolean,
188191
): Promise<[string[], string[], Record<string, string[]>, string[], string[]]> {
189192
const targetFiles: string[] = [];
@@ -204,7 +207,7 @@ async function getTargetsPaths(
204207
}
205208
}
206209

207-
const result = await getGlobPaths(rootPath, targetGlobs, withNodeModules);
210+
const result = await getGlobPaths(rootPath, targetGlobs, ignoreFiles, withNodeModules);
208211
const filesPaths = [...targetFiles, ...result.files];
209212
const filesNames = [...targetFilesNames, ...result.filesFoundNames];
210213
const filesNamesToPaths = result.filesFoundNamesToPaths;

0 commit comments

Comments
 (0)