Skip to content

Commit a33eeec

Browse files
authored
feat(pnpm): publish pnpm v12 (the Rust port) as pnpm and @pnpm/exe (#12670)
Make the pacquet Rust port installable from npm as pnpm v12, published with equal content under two names — `pnpm` and `@pnpm/exe` — on the `next-12` dist-tag (never `latest`, which keeps serving the production TypeScript pnpm v11). First release is 12.0.0-alpha.0. CLI presents as pnpm: clap name/bin_name are `pnpm`; PACQUET_VERSION holds the pnpm 12.x version; the default User-Agent is the plain `pnpm/<version>` form; the reporter footer reads `Done in ... using pnpm v<version>`; the `pnpm link` / `pnpm patch` / `pnpm patch-commit` hints now name pnpm (parity fixes); and launched as `pnpx`/`pnx`, the binary injects the `dlx` subcommand itself by detecting its current_exe name (porting pnpm's buildArgv). npm packaging mirrors how `@pnpm/exe` ships pnpm: both the `pnpm` and `@pnpm/exe` wrappers ship root-level placeholder bins (pnpm/pn/pnpx/pnx) plus an install.js preinstall that hardlinks the host's native binary over the placeholder (no Node launcher). Native binaries publish as `@pnpm/exe.<platform>-<arch>[-musl]` (file `pnpm` inside). `pacquet`/`@pnpm/pacquet` are no longer published. installPnpm initializes v12 exactly like `@pnpm/exe`: linkExePlatformBinary takes the wrapper name and resolves the native binary via require, and PNPM_ALLOW_BUILDS includes both names so the GVS hash is per-platform. resolvePackageManagerIntegrities already resolves both `pnpm` and `@pnpm/exe`, so publishing `@pnpm/exe@12` makes self-update / version-switch work with no v12-specific logic. From v12 the install always uses the `pnpm` package (even from a `@pnpm/exe` build), via pnpmPackageNameToInstall(). The configDependencies install-engine path still installs the published `pacquet`/`@pnpm/pacquet` releases (which ship `@pacquet/<target>` binaries) and is left untouched.
1 parent 103b99b commit a33eeec

31 files changed

Lines changed: 749 additions & 332 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@pnpm/engine.pm.commands": minor
3+
"pnpm": minor
4+
---
5+
6+
`pnpm self-update` and `packageManager` version-switching can now install and link pnpm v12 (the Rust port), published with equal content under both the `pnpm` and `@pnpm/exe` names on the `next-12` dist-tag. Its native binaries ship as `@pnpm/exe.<platform>-<arch>` packages, which pnpm's built-in installer links directly — no Node.js launcher, so the command pays no Node startup cost. v12 is initialized exactly like `@pnpm/exe`, including per-platform global-virtual-store hashing. From v12 onward the install converges on the unscoped `pnpm` package (the Rust exe) — even when updating from the SEA `@pnpm/exe` build.

‎.github/workflows/pacquet-release-to-npm.yml‎

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
name: Release Pacquet
1+
name: Release pnpm (Rust)
22

3-
# Manual-trigger only. Type the version to publish — the workflow patches
4-
# pacquet/npm/pacquet/package.json with it before generating per-platform
5-
# packages and publishing. No git tag is created and no GitHub release
6-
# asset is uploaded; npm is the authoritative artifact store.
3+
# Manual-trigger only: patches the version into pacquet/npm/pnpm/package.json,
4+
# generates the per-platform packages, and publishes (no git tag / release asset
5+
# — npm is the artifact store). Ships the Rust port under two names, `pnpm` and
6+
# `@pnpm/exe`, both depending on the `@pnpm/exe.<target>` natives. The `tag`
7+
# defaults to `next-12` so a release never touches the production `latest`.
78
on:
89
workflow_dispatch:
910
inputs:
1011
version:
11-
description: 'Version to publish (e.g. 0.2.3 or 0.2.3-rc.1)'
12+
description: 'Version to publish (e.g. 12.0.0-alpha.0)'
1213
required: true
1314
type: string
15+
tag:
16+
# A `choice` (not free-form) so a mistaken `latest` can't move the
17+
# production `pnpm` dist-tag. `latest` is intentionally omitted.
18+
description: 'npm dist-tag to publish under'
19+
required: true
20+
default: 'next-12'
21+
type: choice
22+
options:
23+
- next-12
24+
- next
1425

1526
concurrency:
1627
group: ${{ github.workflow }}-${{ github.ref }}
@@ -160,18 +171,15 @@ jobs:
160171
exit 1
161172
fi
162173
163-
- name: Inject version into pacquet/npm/pacquet/package.json
164-
# The committed package.json has no `version` field; the version comes
165-
# from the workflow_dispatch input. Patching it here means
166-
# generate-packages.mjs (which copies the version into each
167-
# per-platform manifest) and `pnpm publish` (which reads from
168-
# package.json) both see the right value.
174+
- name: Inject version into pacquet/npm/pnpm/package.json
175+
# The committed package.json has no `version`; patch it from the input so
176+
# generate-packages.mjs and `pnpm publish` both pick it up.
169177
env:
170178
VERSION: ${{ inputs.version }}
171179
run: |
172-
jq --arg v "$VERSION" '.version = $v' pacquet/npm/pacquet/package.json > pacquet/npm/pacquet/package.json.tmp
173-
mv pacquet/npm/pacquet/package.json.tmp pacquet/npm/pacquet/package.json
174-
cat pacquet/npm/pacquet/package.json
180+
jq --arg v "$VERSION" '.version = $v' pacquet/npm/pnpm/package.json > pacquet/npm/pnpm/package.json.tmp
181+
mv pacquet/npm/pnpm/package.json.tmp pacquet/npm/pnpm/package.json
182+
cat pacquet/npm/pnpm/package.json
175183
176184
- name: Install pnpm and Node
177185
uses: pnpm/setup@77cf06832101b3ac8c65caaf76a21643936d07a4
@@ -195,22 +203,19 @@ jobs:
195203

196204
- name: Generate npm packages
197205
run: |
198-
node pacquet/npm/pacquet/scripts/generate-packages.mjs
199-
cat pacquet/npm/pacquet/package.json
200-
for package in pacquet/npm/pacquet* pacquet/npm/pnpm-pacquet; do cat $package/package.json ; echo ; done
201-
202-
- name: Publish npm packages as latest
203-
# Auth is via npm's trusted publishing: `id-token: write` above grants
204-
# this job an OIDC token that pnpm/npm exchange with the registry,
205-
# so no NPM_TOKEN is needed. `--provenance` attaches the same OIDC
206-
# token to a provenance attestation on each tarball.
207-
# The trailing slash on $package/ changes it to publishing the directory.
208-
# `pnpm-pacquet` is the `@pnpm/pacquet` scoped alias mirror —
209-
# same shim and same `@pacquet/<target>` optional deps as the
210-
# unscoped `pacquet`. Published alongside so users can adopt
211-
# either name; the per-target binary sub-packages stay under
212-
# the `@pacquet/` scope (no need to mirror those).
206+
node pacquet/npm/pnpm/scripts/generate-packages.mjs
207+
cat pacquet/npm/pnpm/package.json
208+
for package in pacquet/npm/pacquet-* pacquet/npm/pnpm*; do cat $package/package.json ; echo ; done
209+
210+
- name: Publish npm packages
211+
# Auth via npm trusted publishing (the `id-token: write` OIDC token), so
212+
# no NPM_TOKEN; `--provenance` attests each tarball. The trailing slash
213+
# publishes the directory. The glob covers the native sub-packages (build
214+
# dirs `pacquet-*`, published as `@pnpm/exe.<target>`) plus the `pnpm` and
215+
# `@pnpm/exe` (`pnpm-exe`) wrappers.
216+
env:
217+
TAG: ${{ inputs.tag }}
213218
run: |
214-
for package in pacquet/npm/pacquet* pacquet/npm/pnpm-pacquet; do
215-
pnpm publish "$package/" --tag latest --access public --provenance --no-git-checks
219+
for package in pacquet/npm/pacquet-* pacquet/npm/pnpm*; do
220+
pnpm publish "$package/" --tag "$TAG" --access public --provenance --no-git-checks
216221
done

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ use why::WhyArgs;
110110

111111
/// Experimental package manager for node.js written in rust.
112112
#[derive(Debug, Parser)]
113-
#[clap(name = "pacquet")]
114-
#[clap(bin_name = "pacquet")]
113+
#[clap(name = "pnpm")]
114+
#[clap(bin_name = "pnpm")]
115115
#[clap(version = pacquet_config::PACQUET_VERSION)]
116116
#[clap(about = "Experimental package manager for node.js")]
117117
pub struct CliArgs {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ pub struct LinkArgs {
2222
#[derive(Debug, Display, Error, Diagnostic)]
2323
#[non_exhaustive]
2424
pub enum LinkError {
25-
#[display("You must provide a parameter. Usage: pacquet link <dir>")]
25+
#[display("You must provide a parameter. Usage: pnpm link <dir>")]
2626
#[diagnostic(code(ERR_PNPM_LINK_BAD_PARAMS))]
2727
NoParams,
2828

29-
#[display(r#"Cannot link by package name. Use a relative or absolute path instead, e.g. "pacquet link ./{name}""#)]
29+
#[display(r#"Cannot link by package name. Use a relative or absolute path instead, e.g. "pnpm link ./{name}""#)]
3030
#[diagnostic(code(ERR_PNPM_LINK_BAD_PARAMS))]
3131
LinkByName {
3232
#[error(not(source))]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub struct PatchArgs {
3636
#[derive(Debug, Display, Error, Diagnostic)]
3737
#[non_exhaustive]
3838
pub enum PatchError {
39-
#[display("`pacquet patch` requires the package name")]
39+
#[display("`pnpm patch` requires the package name")]
4040
#[diagnostic(code(ERR_PNPM_MISSING_PACKAGE_NAME))]
4141
MissingPackageName,
4242

@@ -538,7 +538,7 @@ fn print_success(edit_dir: &Path) {
538538

539539
fn render_success(edit_dir: &Path, colors_enabled: bool) -> String {
540540
let edit_dir = edit_dir.display().to_string();
541-
let command = format!("pacquet patch-commit {}", shell_quote(&edit_dir));
541+
let command = format!("pnpm patch-commit {}", shell_quote(&edit_dir));
542542
let edit_dir = if colors_enabled { edit_dir.blue().to_string() } else { edit_dir };
543543
let command = if colors_enabled { command.green().to_string() } else { command };
544544
render_success_parts(&edit_dir, &command)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn success_message_colors_edit_dir_and_commit_command_when_enabled() {
9797
assert!(rendered.contains("\u{1b}[34m/tmp/edit-dir\u{1b}[39m"), "{rendered:?}");
9898
assert!(
9999
rendered.contains(&format!(
100-
"\u{1b}[32mpacquet patch-commit {quote}/tmp/edit-dir{quote}\u{1b}[39m",
100+
"\u{1b}[32mpnpm patch-commit {quote}/tmp/edit-dir{quote}\u{1b}[39m",
101101
)),
102102
"{rendered:?}",
103103
);
@@ -112,7 +112,7 @@ fn success_message_is_plain_when_colors_are_disabled() {
112112
assert_eq!(
113113
rendered,
114114
format!(
115-
"Patch: You can now edit the package at:\n\n /tmp/edit-dir\n\nTo commit your changes, run:\n\n pacquet patch-commit {quote}/tmp/edit-dir{quote}\n\n",
115+
"Patch: You can now edit the package at:\n\n /tmp/edit-dir\n\nTo commit your changes, run:\n\n pnpm patch-commit {quote}/tmp/edit-dir{quote}\n\n",
116116
),
117117
);
118118
}
@@ -123,7 +123,7 @@ fn success_message_shell_quotes_single_quotes_in_edit_dir() {
123123
let edit_dir = Path::new("/tmp/patch user's dir");
124124
let rendered = render_success(edit_dir, false);
125125

126-
assert!(rendered.contains(r"pacquet patch-commit '/tmp/patch user'\''s dir'"), "{rendered}");
126+
assert!(rendered.contains(r"pnpm patch-commit '/tmp/patch user'\''s dir'"), "{rendered}");
127127
}
128128

129129
#[cfg(unix)]

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use config_overrides::ConfigOverrides;
1010
use miette::set_panic_hook;
1111
use pacquet_diagnostics::enable_tracing_by_env;
1212
use state::State;
13+
use std::{ffi::OsString, path::Path};
1314

1415
pub fn main() -> miette::Result<()> {
1516
enable_tracing_by_env();
@@ -19,7 +20,7 @@ pub fn main() -> miette::Result<()> {
1920
// arbitrary, so a `--config.registry=...` from pnpm's forwarded flags
2021
// would otherwise error out as "unexpected argument". Each extracted
2122
// token is layered onto `Config` after `.npmrc` / yaml run.
22-
let (config_overrides, argv) = ConfigOverrides::extract(std::env::args_os());
23+
let (config_overrides, argv) = ConfigOverrides::extract(argv_with_alias_subcommand());
2324
// The default reporter's `Done in ... using pacquet v<version>` footer needs
2425
// the version before the first event (including the fast path's).
2526
pacquet_default_reporter::set_package_version(pacquet_config::PACQUET_VERSION);
@@ -67,6 +68,27 @@ pub fn main() -> miette::Result<()> {
6768
/// same room on every platform, including Windows (1 MiB default).
6869
const MAIN_STACK_SIZE: usize = 32 * 1024 * 1024;
6970

71+
/// Process argv with a leading `dlx` injected when launched as `pnpx`/`pnx`
72+
/// (shorthand for `pnpm dlx`), mirroring pnpm's `buildArgv`. Only the Windows
73+
/// hardlink aliases rely on this — the Unix alias scripts inject `dlx`
74+
/// themselves — and there `current_exe` is the only signal of the launch name.
75+
fn argv_with_alias_subcommand() -> Vec<OsString> {
76+
let exe = std::env::current_exe().ok();
77+
let exe_name =
78+
exe.as_deref().and_then(Path::file_stem).map(|stem| stem.to_string_lossy().to_lowercase());
79+
inject_alias_subcommand(exe_name.as_deref(), std::env::args_os().collect())
80+
}
81+
82+
/// Insert a leading `dlx` token after the program name when `exe_name` is a
83+
/// `pnpx`/`pnx` alias. Split out from [`argv_with_alias_subcommand`] so the
84+
/// argv rewrite is unit-testable without depending on `current_exe`.
85+
fn inject_alias_subcommand(exe_name: Option<&str>, mut argv: Vec<OsString>) -> Vec<OsString> {
86+
if matches!(exe_name, Some("pnpx" | "pnx")) {
87+
argv.insert(argv.len().min(1), OsString::from("dlx"));
88+
}
89+
argv
90+
}
91+
7092
/// Size rayon's global pool at `2 × available_parallelism`. The link
7193
/// phase is dominated by clonefile / hardlink syscalls that block the
7294
/// calling thread on the kernel's metadata journal, not by CPU work,
@@ -123,3 +145,6 @@ fn configure_rayon_pool() {
123145
.max(4);
124146
let _ = rayon::ThreadPoolBuilder::new().num_threads(n).build_global();
125147
}
148+
149+
#[cfg(test)]
150+
mod tests;

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use super::inject_alias_subcommand;
2+
use std::ffi::OsString;
3+
4+
fn argv(parts: &[&str]) -> Vec<OsString> {
5+
parts.iter().map(OsString::from).collect()
6+
}
7+
8+
#[test]
9+
fn pnpx_and_pnx_inject_dlx_after_the_program_name() {
10+
for alias in ["pnpx", "pnx"] {
11+
let result = inject_alias_subcommand(Some(alias), argv(&[alias, "create-vite", "app"]));
12+
assert_eq!(result, argv(&[alias, "dlx", "create-vite", "app"]));
13+
}
14+
}
15+
16+
#[test]
17+
fn pnpm_pn_and_pacquet_names_are_left_untouched() {
18+
for name in ["pnpm", "pn", "pacquet", "PNPX-not-exact"] {
19+
let original = argv(&[name, "install"]);
20+
assert_eq!(inject_alias_subcommand(Some(name), original.clone()), original);
21+
}
22+
}
23+
24+
#[test]
25+
fn an_unknown_executable_name_is_left_untouched() {
26+
let original = argv(&["whatever", "install"]);
27+
assert_eq!(inject_alias_subcommand(None, original.clone()), original);
28+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//! Covers the `current_exe`-based `dlx` injection (`argv_with_alias_subcommand`)
2+
//! that pnpm relies on for the Windows `pnpx`/`pnx` hardlinks, exercised on Unix
3+
//! by copying the binary under the alias name — the same code runs everywhere.
4+
#![cfg(unix)]
5+
6+
use std::{fs, os::unix::fs::PermissionsExt, process::Command};
7+
8+
use tempfile::TempDir;
9+
10+
#[test]
11+
fn launched_as_pnpx_injects_the_dlx_subcommand() {
12+
let pacquet = env!("CARGO_BIN_EXE_pacquet");
13+
14+
let dir = TempDir::new().expect("create temp dir");
15+
let pnpx = dir.path().join("pnpx");
16+
fs::copy(pacquet, &pnpx).expect("copy the binary under the pnpx name");
17+
fs::set_permissions(&pnpx, fs::Permissions::from_mode(0o755)).expect("make pnpx executable");
18+
19+
let via_pnpx = Command::new(&pnpx).arg("--help").output().expect("run `pnpx --help`");
20+
let via_dlx = Command::new(pacquet).args(["dlx", "--help"]).output().expect("run `dlx --help`");
21+
22+
assert!(via_pnpx.status.success(), "`pnpx --help` exited with a failure status");
23+
assert!(via_dlx.status.success(), "`dlx --help` (the control) exited with a failure status");
24+
let pnpx_help = String::from_utf8(via_pnpx.stdout).expect("pnpx help is UTF-8");
25+
let dlx_help = String::from_utf8(via_dlx.stdout).expect("dlx help is UTF-8");
26+
assert_eq!(pnpx_help, dlx_help, "`pnpx --help` should equal `dlx --help` (dlx was injected)");
27+
}

‎pacquet/crates/config/src/defaults.rs‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,13 @@ pub fn default_fetch_retry_maxtimeout() -> u64 {
273273
60_000
274274
}
275275

276-
/// pacquet's user-facing release version — the same value
277-
/// `pacquet --version` prints. Single source of truth so the CLI
276+
/// The CLI's user-facing release version — the same value
277+
/// `pnpm --version` prints. Single source of truth so the CLI
278278
/// version string and the default `User-Agent` (`default_user_agent`)
279-
/// can't drift apart.
280-
pub const PACQUET_VERSION: &str = "0.2.2";
279+
/// can't drift apart. The release workflow patches this constant to the
280+
/// version being published; the committed value tracks the current
281+
/// pre-release line.
282+
pub const PACQUET_VERSION: &str = "12.0.0-alpha.0";
281283

282284
pub fn default_fetch_timeout() -> u64 {
283285
pacquet_network::DEFAULT_FETCH_TIMEOUT_MS
@@ -286,14 +288,14 @@ pub fn default_fetch_timeout() -> u64 {
286288
/// Default `User-Agent`, mirroring pnpm v11's
287289
/// [`config/reader/src/index.ts:293`](https://github.com/pnpm/pnpm/blob/1819226b51/config/reader/src/index.ts#L293)
288290
/// format `${name}/${version} npm/? node/${nodeVersion} ${platform} ${arch}`.
289-
/// The `name/version` segment is `pnpm/pacquet-<version>` so registries can
290-
/// tell pacquet's traffic apart from the TypeScript pnpm CLI. pacquet has no
291-
/// embedded Node runtime, so the `node/` segment is the `?` placeholder pnpm
292-
/// already uses for `npm/`. Platform and arch use Node's naming via
291+
/// The `name/version` segment is `pnpm/<version>`, matching the TypeScript
292+
/// pnpm CLI exactly. There is no embedded Node runtime, so the `node/`
293+
/// segment is the `?` placeholder pnpm already uses for `npm/`. Platform and
294+
/// arch use Node's naming via
293295
/// [`pacquet_detect_libc::host_platform`] / [`pacquet_detect_libc::host_arch`].
294296
pub fn default_user_agent() -> String {
295297
format!(
296-
"pnpm/pacquet-{PACQUET_VERSION} npm/? node/? {} {}",
298+
"pnpm/{PACQUET_VERSION} npm/? node/? {} {}",
297299
pacquet_detect_libc::host_platform(),
298300
pacquet_detect_libc::host_arch(),
299301
)

0 commit comments

Comments
 (0)