Repository navigation
Add PathFilter module, PathFilter-based FileSystem.glob and IgnoreFile parsers - #10274
Conversation
🦋 Changeset detectedLatest commit: 65bf0c3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 33 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
|
@effect-bot This is garbage. Try again. Review prior art. Build a good general abstraction first before implement concrete ignore file formats. |
|
Thanks for the feedback, @fubhy. I've added it to the tracking issue (EFF-3231). The rework will start with a review of prior art and a general exclusion abstraction, and the concrete |
eb0987f to
36834ed
Compare
|
@effect-bot instead of glob using a path finder as a |
|
Good point. I've added it to the rework in EFF-3231. On this PR,
The design proposal will cover deriving the walker from a |
|
@effect-bot Alternatively, we could replace |
|
Thanks. I've added this to the rework in EFF-3231, next to the "derive the walker from the filter" idea, because the two choices depend on each other. Some initial notes:
The design proposal will cover whether |
dfc39a7 to
116b11f
Compare
|
@effect-bot but even the |
|
Yes. A glob pattern is just an include rule, and I think the design should go this way. Then It also fixes the
Compatibility: // glob(pattern, { root, dot, exclude }) would mean: walk `root` with
PathFilter.make([
PathFilter.include(pattern, { dot }),
...exclude.map((p) => PathFilter.exclude(p))
])The primitive underneath would be a walker driven by a I've added this to the design work in EFF-3231. The proposal will cover making |
|
@effect-bot |
|
You're right, sorry, that was wrong. The So my compatibility point doesn't apply. We don't need to keep I've corrected this in EFF-3231 so the design proposal drops the wrapper requirement. |
7997bf7 to
d64bb9a
Compare
The rest of an absolute pattern keeps its positive, root-relative meaning: a leading ! or drive-shaped name is escaped and leading empty segments are dropped. The literal prefix stops at a decoded / so escaped separators are still rejected, and / or /** return the filesystem root again.
A single absolute string is compiled as one Glob pattern, stepped past its filesystem root and walked from there, so braces, normalization and root matches follow the compiler. This drops the lexical prefix split and its escapes, and shares the .. and escaped / check with filter rules.
The adapter passed a hand-written include rule to select, repeating the constructor's defaults. It now hands the compiled matcher to include.
435662d to
65bf0c3
Compare
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
…e parsers (#10274) Co-authored-by: Tim <[email protected]>
Adds a general
PathFiltermodule (unstable): an ordered list of exclusion and inclusion rules with a default for unmatched paths.FileSystem.globnow takes a singlePathFilter.Input(a filter, a pattern, or patterns and rules) plusroot, and derives its traversal from the rules.IgnoreFile(experimental) parses.gitignoreand.dockerignoresources intoPathFilters.Model
The redesign follows prior art: ripgrep's
ignorecrate, gitdir.c, mobypatternmatcherwith BuildKitfsutil, node-ignore and pythonpathspec.ExcludeorIncludewith:Globstring or a customPathMatcher;directoryOnly;scopedirectory;subtreepolicy.barrierexclusion can be included again.subtreeis the only place Git and Docker differ:barrier: Git exclusions and the default forexclude.inherit: Docker; a match on a directory also counts for everything inside it, if it changed the directory's result at that point in rule order (BuildKit'sMatchesUsingParentResults).self: Git!and the default forinclude.PathFilter.matchreturnsNone,ExcludeorIncludetogether with the rule that decided it.excludesis the boolean form.{ directory }argument; a trailing/means nothing.defaultfor paths no rule decides:make,emptyand theIgnoreFileparsers keep them, whileselectbuilds a selection, which drops them.matchreturnsNonefor such a path andexcludesapplies the default.PathFilter.Inputis a filter, a string, or an iterable of strings and rules. A string includes paths and a!string excludes them (\!for a literal!). An input with at least one including string is a selection. Including strings skip dot names;!strings match them.fromInputconverts an input and returns a filter unchanged, with its default.select(rules, { dot })builds a selection from strings and rules;dotapplies to its including strings.restrict(self, by)(curried:restrict(by)(self)) keeps a path only whenselfkeeps it andbydoesn't exclude it. The two are evaluated separately, so an ignore file's!keep.logcan't add a path the selection dropped. Formatch, the last restriction that excludes the path decides it, even through its default; otherwiseselfdoes.concatappends the rules of two filters with the same default. Different defaults or a restricted operand are defects.includeandexcludetake aPathMatcheroverload, so a custom matcher's parameters are inferred.PathFilterorFileSystem.FileSystem.globglob(input: PathFilter.Input, options?: { root })finds the paths underrootthat the filter keeps. The pattern argument and thedotandexcludeoptions are gone; composition lives inPathFilter.root, depth-first with entries sorted by name.rootitself is never a result.barrierexclusion stops.matchesBelow.Globrule with only literal states, soglob("src/index.ts")reads no directory, as before. A custom matcher lists.link/never matches a link to a directory. A link is followed only for inclusions that reach it through explicit segments, never through**, a default or an inherited inclusion. Exclusions keep applying inside."/abs/dir/**"keeps its previous behavior: it ignoresroot, returns absolute paths, anddir/**includesdir."/"and"/**"include the filesystem root. The pattern is compiled whole as aGlobpattern, as before, so braces, normalization and dropped branches behave the same; the walk starts at its filesystem root and looks up its leading literal names. Absolute patterns anywhere else (in a list, after!, inselectorrestrict),..segments, escaped/and UNC paths make the effect die.Breaking (minor,
FileSystemis unstable)fs.glob("**/*.ts")fs.glob(p, { dot: true })fs.glob(PathFilter.select(p, { dot: true }))fs.glob(p, { exclude: ["**/*.test.ts"] })fs.glob([p, "!**/*.test.ts"])fs.glob("../a/*.ts", { root })fs.glob("*.ts", { root: path.join(root, "../a") })fs.glob(".")fs.exists(root)fs.glob("/abs/dir/**")itself is unchanged;fs.glob("/abs/dir/**", { dot: true })becomesfs.glob(PathFilter.select("**", { dot: true }), { root: "/abs/dir" })with relative results. Moving a prefix intorootalso drops that directory from the results, sincerootis never a result. A directory-only pattern such aslink/no longer matches a link to a directory. Everything else about string patterns is unchanged: results, ordering, the spelling of probed names, and read-error handling. The differential check below covers this.IgnoreFilegitignore(source, { scope? })returns aPathFilterand never fails; as in Git, a malformed line matches nothing.dockerignore(source)returnsResult<PathFilter, ParseError>..gitignorefiles withPathFilter.concat, giving each one its directory asscope, and remove what they ignore from a selection withPathFilter.restrict.matchesBelowhint uses BuildKit's rule for skipping directories, applied per pattern. It strips only one trailing/**or/*, so!d/*/**still keepsd/sub/keepreachable.BuildKit compatibility
Docker rules follow BuildKit's walk (
tonistiigi/fsutilMatchesUsingParentResults), not moby'sMatchesOrParentMatches: a pattern that repeats a directory's result so far is not passed down, sod,!d/keep,dkeepsd/keep. Directory skipping starts from the inherited exclusion, soglobstill readsdthere.The one intended difference is the single trailing-glob strip above: BuildKit strips both from
!node_modules/*/**and dropsnode_modules/pkg/index.ts; this keeps it.Validation
PathFilter,IgnoreFile,Glob,FileSystemandNodeFileSystem, 278 tests.NodeFileSystem,PathFilter,IgnoreFileandFileSystem, 245 tests.DenoFileSystem,PathFilter,IgnoreFileandFileSystem, 198 tests and 1 skipped.PathFilterandFileSystemon TypeScript 5.9 and 6.0. The flat mobypatternmatcher_test.gotable is unchanged.pnpm check,pnpm lint,pnpm jsdocs --check,pnpm circularand the doctests (23) pass.58b3ad4086): random trees with dot names, nested directories, a link to a directory and a dangling link, and random patterns (braces, classes,**,.*, escapes, trailing/) with and withoutdotand a gitignore filter. About 22,500 comparisons across typed and untyped (Unknown) listings: identical, apart from 80 cases of a trailing-/pattern meeting the link, the documentedlink/change.dockerignoreagainst BuildKit's walk (120,000 path checks and 1,500 real-tree filters, 0 mismatches),PathFilter.matchagainst an independent evaluator, and Docker/Git oracles forIgnoreFile.Closes EFF-3231