From 6dc463eff7df1c1c48537175dde8393b9bfe18b7 Mon Sep 17 00:00:00 2001 From: cpojer Date: Mon, 11 May 2026 03:46:32 +0000 Subject: [PATCH] feat: Forward `--provenance` flag when publishing a package. (#1549) This required a `--` in between before, which is confusing. This PR makes it so `--provenance` is an actual flag for `vp pm publish`. --- crates/vite_install/src/commands/publish.rs | 57 +++++++++++++++++++ crates/vite_pm_cli/src/cli.rs | 4 ++ crates/vite_pm_cli/src/handlers.rs | 2 + .../command-publish-bun/snap.txt | 1 + .../command-publish-pnpm10/snap.txt | 1 + .../command-publish-pnpm11/snap.txt | 1 + 6 files changed, 66 insertions(+) diff --git a/crates/vite_install/src/commands/publish.rs b/crates/vite_install/src/commands/publish.rs index 185c1d329f..2ec0e3ccf1 100644 --- a/crates/vite_install/src/commands/publish.rs +++ b/crates/vite_install/src/commands/publish.rs @@ -20,6 +20,7 @@ pub struct PublishCommandOptions<'a> { pub no_git_checks: bool, pub publish_branch: Option<&'a str>, pub report_summary: bool, + pub provenance: bool, pub force: bool, pub json: bool, pub recursive: bool, @@ -99,6 +100,10 @@ impl PackageManager { args.push("--report-summary".into()); } + if options.provenance { + args.push("--provenance".into()); + } + if options.force { args.push("--force".into()); } @@ -152,6 +157,10 @@ impl PackageManager { args.push(otp.to_string()); } + if options.provenance { + args.push("--provenance".into()); + } + if options.force { args.push("--force".into()); } @@ -208,6 +217,10 @@ impl PackageManager { output::warn("--report-summary not supported by bun, ignoring flag"); } + if options.provenance { + output::warn("--provenance not supported by bun publish, ignoring flag"); + } + if options.force { output::warn("--force not supported by bun publish, ignoring flag"); } @@ -429,6 +442,50 @@ mod tests { assert_eq!(result.args, vec!["publish"]); } + #[test] + fn test_pnpm_publish_provenance() { + let pm = create_mock_package_manager(PackageManagerType::Pnpm, "10.0.0"); + let result = pm.resolve_publish_command(&PublishCommandOptions { + provenance: true, + ..Default::default() + }); + assert_eq!(result.bin_path, "pnpm"); + assert_eq!(result.args, vec!["publish", "--provenance"]); + } + + #[test] + fn test_npm_publish_provenance() { + let pm = create_mock_package_manager(PackageManagerType::Npm, "11.0.0"); + let result = pm.resolve_publish_command(&PublishCommandOptions { + provenance: true, + ..Default::default() + }); + assert_eq!(result.bin_path, "npm"); + assert_eq!(result.args, vec!["publish", "--provenance"]); + } + + #[test] + fn test_yarn_publish_provenance() { + let pm = create_mock_package_manager(PackageManagerType::Yarn, "4.0.0"); + let result = pm.resolve_publish_command(&PublishCommandOptions { + provenance: true, + ..Default::default() + }); + assert_eq!(result.bin_path, "npm"); + assert_eq!(result.args, vec!["publish", "--provenance"]); + } + + #[test] + fn test_bun_publish_provenance_ignored() { + let pm = create_mock_package_manager(PackageManagerType::Bun, "1.2.0"); + let result = pm.resolve_publish_command(&PublishCommandOptions { + provenance: true, + ..Default::default() + }); + assert_eq!(result.bin_path, "bun"); + assert_eq!(result.args, vec!["publish"]); + } + #[test] fn test_pnpm_publish_otp() { let pm = create_mock_package_manager(PackageManagerType::Pnpm, "10.0.0"); diff --git a/crates/vite_pm_cli/src/cli.rs b/crates/vite_pm_cli/src/cli.rs index 024a5c92bc..520208354d 100644 --- a/crates/vite_pm_cli/src/cli.rs +++ b/crates/vite_pm_cli/src/cli.rs @@ -696,6 +696,10 @@ pub enum PmCommands { #[arg(long)] report_summary: bool, + /// Publish with provenance + #[arg(long)] + provenance: bool, + /// Force publish #[arg(long)] force: bool, diff --git a/crates/vite_pm_cli/src/handlers.rs b/crates/vite_pm_cli/src/handlers.rs index 585a056385..b71c08f4a7 100644 --- a/crates/vite_pm_cli/src/handlers.rs +++ b/crates/vite_pm_cli/src/handlers.rs @@ -269,6 +269,7 @@ pub async fn run_pm_subcommand( no_git_checks, publish_branch, report_summary, + provenance, force, json, recursive, @@ -284,6 +285,7 @@ pub async fn run_pm_subcommand( no_git_checks, publish_branch: publish_branch.as_deref(), report_summary, + provenance, force, json, recursive, diff --git a/packages/cli/snap-tests-global/command-publish-bun/snap.txt b/packages/cli/snap-tests-global/command-publish-bun/snap.txt index 46aade5cc5..5c4e6ed6a0 100644 --- a/packages/cli/snap-tests-global/command-publish-bun/snap.txt +++ b/packages/cli/snap-tests-global/command-publish-bun/snap.txt @@ -15,6 +15,7 @@ Options: --no-git-checks Skip git checks --publish-branch Set the branch name to publish from --report-summary Save publish summary + --provenance Publish with provenance --force Force publish --json Output in JSON format -r, --recursive Publish all workspace packages diff --git a/packages/cli/snap-tests-global/command-publish-pnpm10/snap.txt b/packages/cli/snap-tests-global/command-publish-pnpm10/snap.txt index 6114de883d..1f5cb54fca 100644 --- a/packages/cli/snap-tests-global/command-publish-pnpm10/snap.txt +++ b/packages/cli/snap-tests-global/command-publish-pnpm10/snap.txt @@ -15,6 +15,7 @@ Options: --no-git-checks Skip git checks --publish-branch Set the branch name to publish from --report-summary Save publish summary + --provenance Publish with provenance --force Force publish --json Output in JSON format -r, --recursive Publish all workspace packages diff --git a/packages/cli/snap-tests-global/command-publish-pnpm11/snap.txt b/packages/cli/snap-tests-global/command-publish-pnpm11/snap.txt index 1838047bf3..9467fcf9b6 100644 --- a/packages/cli/snap-tests-global/command-publish-pnpm11/snap.txt +++ b/packages/cli/snap-tests-global/command-publish-pnpm11/snap.txt @@ -15,6 +15,7 @@ Options: --no-git-checks Skip git checks --publish-branch Set the branch name to publish from --report-summary Save publish summary + --provenance Publish with provenance --force Force publish --json Output in JSON format -r, --recursive Publish all workspace packages