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 f33775a0f1..f0a6bd6573 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 fb7b29dcae..72536460cf 100644 --- a/crates/vite_pm_cli/src/handlers.rs +++ b/crates/vite_pm_cli/src/handlers.rs @@ -272,6 +272,7 @@ pub async fn run_pm_subcommand( no_git_checks, publish_branch, report_summary, + provenance, force, json, recursive, @@ -287,6 +288,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