Passa al contenuto principale
Versione: 9.x

Filtraggio

Il filtraggio consente di limitare i comandi a specifici sottoinsiemi di pacchetti.

pnpm supporta una ricca sintassi di selettori per la selezione dei pacchetti per nome o per relazione.

Selectors may be specified via the --filter (or -F) flag:

pnpm --filter <package_selector> <command>

Corrispondenza

--filter &lt;package_name>

To select an exact package, just specify its name (@scope/pkg) or use a pattern to select a set of packages (@scope/*).

Esempi:

pnpm --filter "@babel/core" test
pnpm --filter "@babel/*" test
pnpm --filter "*core" test

Specifying the scope of the package is optional, so --filter=core will pick @babel/core if core is not found. However, if the workspace has multiple packages with the same name (for instance, @babel/core and @types/core), then filtering without scope will pick nothing.

--filter &lt;package_name>...

To select a package and its dependencies (direct and non-direct), suffix the package name with an ellipsis: <package_name>.... For instance, the next command will run tests of foo and all of its dependencies:

pnpm --filter foo... test

Puoi usare uno schema per selezionare un set di pacchetti radice:

pnpm --filter "@babel/preset-*..." test

--filter &lt;package_name>^...

Per selezionare SOLO le dipendenze di un pacchetto (sia diretto che non diretto), aggiungi al nome il suffisso con i suddetti puntini di sospensione preceduti da un gallone. For instance, the next command will run tests for all of foo's dependencies:

pnpm --filter "foo^..." test

--filter ...&lt;package_name>

To select a package and its dependent packages (direct and non-direct), prefix the package name with an ellipsis: ...<package_name>. For instance, this will run the tests of foo and all packages dependent on it:

pnpm --filter ...foo test

--filter "...^&lt;package_name>"

Per selezionare SOLO i dipendenti di un pacchetto (sia diretti che non diretti), prefissare il nome del pacchetto con un'ellissi seguita da un gallone. For instance, this will run tests for all packages dependent on foo:

pnpm --filter "...^foo" test

--filter ./<glob>, --filter {<glob>}

Un modello glob relativo ai progetti corrispondenti della cartella di lavoro corrente.

pnpm --filter "./packages/**" <cmd>

Include tutti i progetti che si trovano nella cartella specificata.

Può essere utilizzato con gli operatori puntini di sospensione e gallone per selezionare anche dipendenti/dipendenze:

pnpm --filter ...{<directory>} <cmd>
pnpm --filter {<directory>}... <cmd>
pnpm --filter ...{<directory>}... <cmd>

It may also be combined with [<since>]. Ad esempio, per selezionare tutti i progetti modificati all'interno di una cartella:

pnpm --filter "{packages/**}[origin/master]" <cmd>
pnpm --filter "...{packages/**}[origin/master]" <cmd>
pnpm --filter "{packages/**}[origin/master]..." <cmd>
pnpm --filter "...{packages/**}[origin/master]..." <cmd>

Oppure puoi selezionare tutti i pacchetti da una cartella con nomi che corrispondono al modello:

pnpm --filter "@babel/*{components/**}" <cmd>
pnpm --filter "@babel/*{components/**}[origin/master]" <cmd>
pnpm --filter "...@babel/*{components/**}[origin/master]" <cmd>

--filter "[&lt;since>]"

Seleziona tutti i pacchetti modificati dopo il commit/branch specificato. May be suffixed or prefixed with ... to include dependencies/dependents.

For example, the next command will run tests in all changed packages since master and on any dependent packages:

pnpm --filter "...[origin/master]" test

--fail-if-no-match

Use this flag if you want the CLI to fail if no packages have matched the filters.

Esclusione

Tutti i selettori di filtro possono funzionare come operatori di esclusione quando hanno uno "!" iniziale. In zsh (and possibly other shells), "!" should be escaped: \!.

For instance, this will run a command in all projects except for foo:

pnpm --filter=!foo <cmd>

And this will run a command in all projects that are not under the lib directory:

pnpm --filter=!./lib <cmd>

Molteplicità

Quando i pacchetti vengono filtrati, viene preso ogni pacchetto che corrisponde ad almeno uno dei selettori. Puoi usare tutti i filtri che vuoi:

pnpm --filter ...foo --filter bar --filter baz... test

--filter-prod &lt;filtering_pattern>

Acts the same a --filter but omits devDependencies when selecting dependency projects from the workspace.

--test-pattern &lt;glob>

test-pattern allows detecting whether the modified files are related to tests. Se lo sono, i pacchetti dipendenti di tali pacchetti modificati non sono inclusi.

Questa opzione è utile con il filtro "modificato da". Ad esempio, il prossimo comando eseguirà i test in tutti i pacchetti modificati e, se le modifiche sono nel del pacchetto, i test verranno eseguiti anche nei pacchetti dipendenti:

pnpm --filter="...[origin/master]" --test-pattern="test/*" test

--changed-files-ignore-pattern &lt;glob>

Consente di ignorare i file modificati dai modelli glob durante il filtraggio per i progetti modificati dal commit/ramo specificato.

Esempio di utilizzo:

pnpm --filter="...[origin/master]" --changed-files-ignore-pattern="**/README.md" run build