Skip to content

Commit ebb4096

Browse files
kairoscizkochan
andauthored
feat(pacquet-cli): implement pnpm peers command (#12706)
Add the peers command to pacquet-cli, which checks for unmet or missing peer dependency issues by walking the lockfile, mirroring the TypeScript CLI: one shared visited set across importers so each package is evaluated once, missing-peer ranges merged via interval intersection to detect conflicts, peerDependencyRules filtering (ignoreMissing, allowAny, allowedVersions with parent-scoped selectors), deterministic BTreeMap-ordered output, and a PeersOutcome mapped to exit code 1 in the dispatch layer. Importer link: targets resolve relative to the importer directory and are rejected when they escape the lockfile directory. Also fix the TypeScript peers-checker to drop conflicts of missing peers removed by peerDependencyRules.ignoreMissing, so the JSON output no longer reports a conflict while the text output reports no issues. Related to: #11633 --------- Co-authored-by: Zoltan Kochan <[email protected]>
1 parent fdfe172 commit ebb4096

11 files changed

Lines changed: 1725 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@pnpm/deps.inspection.peers-checker": patch
3+
"pnpm": patch
4+
---
5+
6+
`pnpm peers` no longer reports a conflict for a missing peer dependency that is ignored via `pnpm.peerDependencyRules.ignoreMissing`.

‎pacquet/crates/cli/src/cli_args.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub mod patch;
3232
pub mod patch_commit;
3333
pub mod patch_remove;
3434
pub(crate) mod patch_state;
35+
pub mod peers;
3536
pub mod ping;
3637
pub mod prefix;
3738
pub mod prune;

‎pacquet/crates/cli/src/cli_args/cli_command.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use super::{
3030
patch::PatchArgs,
3131
patch_commit::PatchCommitArgs,
3232
patch_remove::PatchRemoveArgs,
33+
peers::PeersArgs,
3334
ping::PingArgs,
3435
prefix::PrefixArgs,
3536
prune::PruneArgs,
@@ -180,6 +181,9 @@ pub enum CliCommand {
180181
/// Remove existing patch files.
181182
#[clap(name = "patch-remove")]
182183
PatchRemove(PatchRemoveArgs),
184+
/// Checks for unmet or missing peer dependency issues.
185+
#[clap(name = "peers")]
186+
Peers(PeersArgs),
183187
/// Set a script in package.json
184188
#[clap(visible_alias = "ss")]
185189
SetScript(SetScriptArgs),

‎pacquet/crates/cli/src/cli_args/dispatch.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ fn route<'a>(command: CliCommand, ctx: &RunCtx<'a>) -> miette::Result<CommandFut
242242
CliCommand::Patch(args) => dispatch_install::patch(ctx, args),
243243
CliCommand::PatchCommit(args) => dispatch_install::patch_commit(ctx, args),
244244
CliCommand::PatchRemove(args) => dispatch_install::patch_remove(ctx, args),
245+
CliCommand::Peers(args) => dispatch_query::peers(ctx, args),
245246
CliCommand::SetScript(args) => dispatch_script::set_script(ctx, args),
246247
CliCommand::Test => dispatch_script::test(ctx),
247248
CliCommand::Run(args) => dispatch_script::run(ctx, args),

‎pacquet/crates/cli/src/cli_args/dispatch_query.rs‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use super::{
1616
outdated::{OutdatedArgs, OutdatedOutcome},
1717
pack::PackArgs,
1818
pack_app::PackAppArgs,
19+
peers::{PeersArgs, PeersOutcome},
1920
ping::PingArgs,
2021
prefix::PrefixArgs,
2122
repo::RepoArgs,
@@ -108,6 +109,22 @@ pub(super) fn sbom<'a>(ctx: &RunCtx<'a>, args: SbomArgs) -> miette::Result<Comma
108109
Ok(Box::pin(args.run((ctx.state)(true)?)))
109110
}
110111

112+
pub(super) fn peers<'a>(ctx: &RunCtx<'a>, args: PeersArgs) -> miette::Result<CommandFuture<'a>> {
113+
let cfg: &Config = (ctx.config)()?;
114+
let recursive = ctx.recursive;
115+
let dir = ctx.dir;
116+
Ok(Box::pin(async move {
117+
if args.run(cfg, dir, recursive)? == PeersOutcome::IssuesFound {
118+
#[expect(
119+
clippy::exit,
120+
reason = "`peers` exits non-zero when peer issues are found, mirroring pnpm"
121+
)]
122+
std::process::exit(1);
123+
}
124+
Ok(())
125+
}))
126+
}
127+
111128
// `whoami` is a read-only registry query: it resolves the default registry's
112129
// auth header from config and GETs `-/whoami`, with no lockfile or install
113130
// pipeline. It needs an async future for the request but no reporter-typed

0 commit comments

Comments
 (0)