nodejs / nodejs/node

Support negated pattern-list syntax in `fs.glob`

Offen
#63,959 4 Kommentare 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature request
Vorherrschende Sprache
JavaScript
Sterne
122k
Forks
37.3k
Ø Merge
4 T. 2 Std.
Gemergte PRs (30 T.)
283

Beschreibung

What problem would this feature solve?

Node's fs.glob() accepts an array of patterns, but entries beginning with ! are not interpreted as exclusions:

globSync([
  'src/**/*.js',
  '!src/generated/**',
]);

Node.js does support negative extglobs such as !(pattern), but that is a different feature. An extglob negates part of a single pattern while negated pattern-list syntax applies an exclusion to the matches (based on other entries in the array).

Node.js also provides options.exclude, but it cannot fully represent ordered pattern lists where a later positive pattern re-includes a path.

Ecosystem

Leading-! entries are supported by packages such as globby and tinyglobby:

await globby(['src/**/*.js', '!src/generated/**']);
await glob(['src/**/*.js', '!src/generated/**']); // tinyglobby

Supporting this syntax would make migration to the built-in API easier and allow existing pattern arrays from configuration files and CLI arguments to be reused unchanged.

What feature are you proposing?

When pattern is an array, interpret entries beginning with ! as negated pattern-list entries:

globSync([
  'src/**/*.js',
  '!src/generated/**',
]);

Patterns should be processed in order:

  • A positive pattern adds matching paths.
  • A negated pattern removes matching paths.
  • A later positive pattern can re-include previously removed paths.

For example:

globSync([
  'src/**/*.js',
  '!src/generated/**',
  'src/generated/keep.js',
]);

This should include src/generated/keep.js.

The existing options.exclude API should remain available for global exclusions and exclusion callbacks.

What alternatives have you considered?

Applications can split positive and negative entries:

globSync(include, { exclude });

However, this loses ordering semantics and cannot represent later re-inclusion without additional processing.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit den in diesem Issue beschriebenen fs.glob- und globSync-APIs und führe anschließend die bereitgestellten Pattern-Array-Beispiele aus, um das aktuelle Verhalten festzustellen. Als abgeschlossen gilt die Aufgabe, wenn Einträge mit führendem ! Treffer der Reihe nach entfernen, spätere positive Einträge sie wieder einschließen und options.exclude weiterhin für globale Ausschlüsse und Callbacks verfügbar ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
javascript
Bereich
operating-systems
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Aktiv
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
62/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.