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

オープン
#63,959 コメント 4 件 リアクション 3 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
62/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
javascript

調査の方向性

Issue に記載されている fs.glob および globSync API から始め、続いて提供されているパターン配列の例を実行して現在の動作を確認します。先頭が ! のエントリが一致を順番に削除し、後続の正のエントリがそれらを再度含め、options.exclude がグローバルな除外と callbacks に引き続き利用できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

feature request
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.

主要言語
JavaScript
スター
122k
フォーク
37.4k
平均マージ
4日 4時間
マージ済み PR(30日)
276

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

nodejs/node のほかの issue

nodejs/node の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。