Skip to content

Commit 2c7369d

Browse files
authored
feat(pacquet-cli): port the pack-app command (#12669)
Ports pnpm's `pack-app` command into pacquet. It packs a CommonJS entry file into a standalone executable for one or more target platforms, embedding a Node.js binary through the Node.js Single Executable Applications API. Reuses pacquet's node-version resolution, network client, detect-libc, and `node@runtime:` installs. Two intentional divergences from pnpm, both forced by pacquet being a Rust binary rather than a Node.js script: the SEA builder is always downloaded (pnpm reuses its running interpreter), and the runtime install spawns the pacquet binary (mirroring pnpm's runPnpmCli). Ports the upstream Jest validation suite (17 tests) covering the fail-fast branches. The download / SEA-injection / signing paths need network, Node.js, and subprocesses and are out of unit-test scope, matching upstream coverage. Ported from 9f3df6b9b4.
1 parent 6312916 commit 2c7369d

8 files changed

Lines changed: 1566 additions & 8 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@pnpm/releasing.commands": patch
3+
"pnpm": patch
4+
---
5+
6+
`pnpm pack-app` now rejects `--entry` / `pnpm.app.entry` and `--output-dir` / `pnpm.app.outputDir` values that are absolute paths or escape the project directory via `..` (or a symlink that resolves outside it), and refuses to write the produced executable when its target path already exists as a symlink (or other non-regular file). This prevents a repository-controlled `package.json` from embedding host files (such as an SSH key) into the produced executable, writing build artifacts outside the project, or overwriting an arbitrary file through a committed symlink. The new error codes are `ERR_PNPM_PACK_APP_ENTRY_OUTSIDE_PROJECT`, `ERR_PNPM_PACK_APP_OUTPUT_DIR_OUTSIDE_PROJECT`, and `ERR_PNPM_PACK_APP_OUTPUT_FILE_NOT_REGULAR`.
7+
8+
When ad-hoc signing macOS targets, `pnpm pack-app` now runs the system `codesign` by absolute path and resolves `ldid` to a location outside the project, so a repository-controlled `node_modules/.bin` on `PATH` cannot hijack the signer.

‎Cargo.lock‎

Lines changed: 2 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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ path = "src/bin/main.rs"
1818
pacquet-catalogs-config = { workspace = true }
1919
pacquet-cmd-shim = { workspace = true }
2020
pacquet-crypto-hash = { workspace = true }
21+
pacquet-detect-libc = { workspace = true }
22+
pacquet-engine-runtime-node-resolver = { workspace = true }
2123
pacquet-pnpr-client = { workspace = true }
2224
pacquet-env-installer = { workspace = true }
2325
pacquet-executor = { workspace = true }

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ pub mod link;
2020
pub mod list;
2121
pub mod outdated;
2222
pub mod pack;
23+
pub mod pack_app;
2324
pub mod patch;
2425
pub mod patch_commit;
2526
pub mod patch_remove;
@@ -67,6 +68,7 @@ use list::ListArgs;
6768
use miette::{Context, IntoDiagnostic};
6869
use outdated::{OutdatedArgs, OutdatedOutcome};
6970
use pack::PackArgs;
71+
use pack_app::PackAppArgs;
7072
use pacquet_config::{Config, Host};
7173
use pacquet_default_reporter::DefaultReporter;
7274
use pacquet_executor::execute_shell;
@@ -251,6 +253,9 @@ pub enum CliCommand {
251253
/// Manage the pnpm configuration files.
252254
#[clap(visible_alias = "c")]
253255
Config(ConfigArgs),
256+
/// Pack a `CommonJS` entry file into a standalone executable for one or more target platforms.
257+
#[clap(name = "pack-app")]
258+
PackApp(PackAppArgs),
254259
/// Managing the package store.
255260
#[clap(subcommand)]
256261
Store(StoreCommand),
@@ -841,6 +846,16 @@ impl CliArgs {
841846
args.run(config()?, dir_ref)?;
842847
Box::pin(std::future::ready(Ok(())))
843848
}
849+
// `pack-app` reads `pnpm.app` from package.json, resolves a
850+
// Node.js version over the network, and shells out to build the
851+
// SEA executables. It needs config (proxy / TLS / registry) and
852+
// the canonicalized `--dir` but no lockfile or install
853+
// pipeline, so it dispatches off `config()` like the other
854+
// read-only commands.
855+
CliCommand::PackApp(args) => {
856+
let cfg: &Config = config()?;
857+
Box::pin(async move { args.run(cfg, dir_ref).await })
858+
}
844859
CliCommand::Store(command) => {
845860
command.run(|| config().map(|m| &*m))?;
846861
Box::pin(std::future::ready(Ok(())))

0 commit comments

Comments
 (0)