Skip to content

Commit f38e696

Browse files
authored
feat(pacquet): port deploy command (#12668)
Port the existing TypeScript deploy command to pacquet. The new pacquet deploy command validates workspace selection and target directory rules, copies the selected project using the package packlist by default, generates deploy-local manifest and lockfile files for shared-lockfile deploys, and runs the pacquet install engine in deploy mode. This also wires deploy config defaults and config overrides, keeps install root discovery configurable so generated deploy lockfiles are resolved from the deploy directory, and adds integration coverage for shared-lockfile deploys, legacy deploys, and non-empty target validation.
1 parent ec76ca3 commit f38e696

34 files changed

Lines changed: 2949 additions & 128 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@pnpm/releasing.commands": patch
3+
"pnpm": patch
4+
---
5+
6+
Hardened `pnpm deploy --force` so it refuses unsafe deploy targets such as workspace roots, parent directories, out-of-workspace paths, and symlinked target parents.

‎Cargo.lock‎

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pacquet/crates/cli/Cargo.toml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pacquet-modules-yaml = { workspace = true }
3232
pacquet-network = { workspace = true }
3333
pacquet-config = { workspace = true }
3434
pacquet-default-reporter = { workspace = true }
35+
pacquet-deps-path = { workspace = true }
3536
pacquet-pack = { workspace = true }
3637
pacquet-package-manifest = { workspace = true }
3738
pacquet-package-manager = { workspace = true }
@@ -45,9 +46,11 @@ pacquet-resolving-resolver-base = { workspace = true }
4546
pacquet-store-dir = { workspace = true }
4647
pacquet-tarball = { workspace = true }
4748
pacquet-diagnostics = { workspace = true }
49+
pacquet-directory-fetcher = { workspace = true }
4850
pacquet-workspace = { workspace = true }
4951
pacquet-workspace-manifest-writer = { workspace = true }
5052
pacquet-workspace-projects-graph = { workspace = true }
53+
pacquet-workspace-projects-filter = { workspace = true }
5154
pacquet-workspace-state = { workspace = true }
5255

5356
chrono = { workspace = true }
@@ -73,6 +76,7 @@ tabled = { workspace = true }
7376
tempfile = { workspace = true }
7477
tokio = { workspace = true }
7578
tracing = { workspace = true }
79+
url = { workspace = true }
7680
which = { workspace = true }
7781
base64 = { workspace = true }
7882
wax = { workspace = true }

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

Lines changed: 80 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod cat_index;
77
pub mod config;
88
pub mod create;
99
pub mod dedupe;
10+
pub mod deploy;
1011
pub mod dist_tag;
1112
pub mod dlx;
1213
pub mod exec;
@@ -57,6 +58,7 @@ use clap::{Parser, Subcommand, ValueEnum};
5758
use config::ConfigArgs;
5859
use create::CreateArgs;
5960
use dedupe::DedupeArgs;
61+
use deploy::DeployArgs;
6062
use dist_tag::DistTagArgs;
6163
use dlx::DlxArgs;
6264
use exec::ExecArgs;
@@ -282,6 +284,8 @@ pub enum CliCommand {
282284
Import(ImportArgs),
283285
/// Deduplicate packages in the lockfile
284286
Dedupe(DedupeArgs),
287+
/// Deploy a package from a workspace
288+
Deploy(DeployArgs),
285289
/// Remove extraneous packages
286290
Prune(PruneArgs),
287291
/// Fetch packages from the lockfile into the virtual store
@@ -376,6 +380,7 @@ impl CliArgs {
376380
| CliCommand::Link(_)
377381
| CliCommand::Import(_)
378382
| CliCommand::Dedupe(_)
383+
| CliCommand::Deploy(_)
379384
| CliCommand::Prune(_)
380385
| CliCommand::Fetch(_)
381386
| CliCommand::Unlink(_)
@@ -721,30 +726,7 @@ impl CliArgs {
721726
// mutable through `Config::leak`'s
722727
// `&'static mut Config` return.
723728
let cfg = config()?;
724-
cfg.offline = cfg.offline || args.offline;
725-
cfg.prefer_offline = cfg.prefer_offline || args.prefer_offline;
726-
cfg.frozen_store = cfg.frozen_store || args.frozen_store;
727-
// `--ignore-scripts` enables (never toggles off) the
728-
// config value, matching the "enable" CLI flags above.
729-
cfg.ignore_scripts = cfg.ignore_scripts || args.ignore_scripts;
730-
cfg.workspace_concurrency =
731-
args.resolve_workspace_concurrency(cfg.workspace_concurrency);
732-
// Network overrides: a passed `--network-concurrency` /
733-
// `--fetch-timeout` / `--user-agent` replaces the
734-
// config-resolved value for this invocation, matching
735-
// pnpm's "CLI wins" precedence.
736-
if let Some(network_concurrency) = args.network_concurrency {
737-
cfg.network_concurrency = network_concurrency;
738-
}
739-
if let Some(fetch_timeout) = args.fetch_timeout {
740-
cfg.fetch_timeout = fetch_timeout;
741-
}
742-
if let Some(user_agent) = args.user_agent.clone() {
743-
cfg.user_agent = user_agent;
744-
}
745-
if let Some(pnpr_server) = args.pnpr_server.clone() {
746-
cfg.pnpr_server = Some(pnpr_server);
747-
}
729+
apply_install_cli_config(cfg, &args);
748730
let require_lockfile = args.frozen_lockfile;
749731
let frozen_lockfile = args.frozen_lockfile;
750732
// Config dependencies are workspace-level state: their
@@ -788,6 +770,33 @@ impl CliArgs {
788770
}
789771
Ok(())
790772
}),
773+
CliCommand::Deploy(args) => Box::pin(async move {
774+
#[allow(
775+
clippy::large_stack_frames,
776+
reason = "the three monomorphized deploy futures would otherwise each reserve their full size in this frame"
777+
)]
778+
{
779+
let cfg = config()?;
780+
apply_install_cli_config(cfg, &args.install_args);
781+
let (config_root, package_manager_to_sync) =
782+
derive_config_root_and_package_manager_to_sync(cfg, dir_ref)
783+
.wrap_err("derive workspace root and package manager policy")?;
784+
let pipeline =
785+
DeployPipeline { args, cfg, config_root, package_manager_to_sync };
786+
match reporter {
787+
ReporterType::Default | ReporterType::AppendOnly => {
788+
Box::pin(pipeline.run::<DefaultReporter>(dir_ref)).await?;
789+
}
790+
ReporterType::Ndjson => {
791+
Box::pin(pipeline.run::<NdjsonReporter>(dir_ref)).await?;
792+
}
793+
ReporterType::Silent => {
794+
Box::pin(pipeline.run::<SilentReporter>(dir_ref)).await?;
795+
}
796+
}
797+
}
798+
Ok(())
799+
}),
791800
CliCommand::Test => {
792801
let manifest = PackageManifest::from_path(manifest_path_ref.clone())
793802
.wrap_err("getting the package.json in current directory")?;
@@ -1079,6 +1088,33 @@ impl InstallPipeline {
10791088
}
10801089
}
10811090

1091+
struct DeployPipeline {
1092+
args: DeployArgs,
1093+
cfg: &'static mut Config,
1094+
config_root: PathBuf,
1095+
package_manager_to_sync: Option<PackageManagerToSync>,
1096+
}
1097+
1098+
impl DeployPipeline {
1099+
async fn run<Reporter: self::Reporter + 'static>(self, dir_ref: &Path) -> miette::Result<()> {
1100+
let DeployPipeline { args, cfg, config_root, package_manager_to_sync } = self;
1101+
if let Some(pm) = package_manager_to_sync.as_ref() {
1102+
config_deps::sync_package_manager_dependencies(
1103+
cfg,
1104+
&config_root,
1105+
&pm.specifier,
1106+
&pm.version,
1107+
false,
1108+
)
1109+
.await?;
1110+
}
1111+
config_deps::install_config_deps::<Reporter>(cfg, &config_root, false).await?;
1112+
config_deps::run_update_config_hooks::<Reporter>(cfg, &config_root).await?;
1113+
let cfg: &'static Config = cfg;
1114+
Box::pin(args.run::<Reporter>(cfg, dir_ref)).await
1115+
}
1116+
}
1117+
10821118
/// Shared workspace-root and package-manager policy derivation used by the
10831119
/// install, dedupe, and prune dispatch paths.
10841120
fn derive_config_root_and_package_manager_to_sync(
@@ -1092,6 +1128,26 @@ fn derive_config_root_and_package_manager_to_sync(
10921128
Ok((config_root, package_manager_to_sync))
10931129
}
10941130

1131+
fn apply_install_cli_config(cfg: &mut Config, args: &InstallArgs) {
1132+
cfg.offline = cfg.offline || args.offline;
1133+
cfg.prefer_offline = cfg.prefer_offline || args.prefer_offline;
1134+
cfg.frozen_store = cfg.frozen_store || args.frozen_store;
1135+
cfg.ignore_scripts = cfg.ignore_scripts || args.ignore_scripts;
1136+
cfg.workspace_concurrency = args.resolve_workspace_concurrency(cfg.workspace_concurrency);
1137+
if let Some(network_concurrency) = args.network_concurrency {
1138+
cfg.network_concurrency = network_concurrency;
1139+
}
1140+
if let Some(fetch_timeout) = args.fetch_timeout {
1141+
cfg.fetch_timeout = fetch_timeout;
1142+
}
1143+
if let Some(user_agent) = args.user_agent.clone() {
1144+
cfg.user_agent = user_agent;
1145+
}
1146+
if let Some(pnpr_server) = args.pnpr_server.clone() {
1147+
cfg.pnpr_server = Some(pnpr_server);
1148+
}
1149+
}
1150+
10951151
/// The reporter-generic body of `pacquet dedupe`: snapshots the lockfile
10961152
/// (when `--check`), runs config-dependency installation and `updateConfig`
10971153
/// hooks, then dispatches to the install pipeline. The snapshot wraps the

0 commit comments

Comments
 (0)