Skip to content

feat: create pnpx for bundled pnpm - #8241

Merged
zkochan merged 3 commits into
mainfrom
add-pnpx-to-setup-8230
Jun 26, 2024
Merged

zkochan merged 3 commits into
mainfrom
add-pnpx-to-setup-8230

Conversation

@KSXGitHub

Copy link
Copy Markdown
Contributor

Resolves #8230

@KSXGitHub
KSXGitHub requested a review from zkochan as a code owner June 26, 2024 12:09
@zkochan

zkochan commented Jun 26, 2024

Copy link
Copy Markdown
Member

This will work. Alternatively, we could also just update the shell config files and add aliases. We already update the shell config files in order to extend the PATH env variable.

@KSXGitHub

Copy link
Copy Markdown
Contributor Author

we could also just update the shell config files and add aliases

It wouldn't work on Windows Command Prompt though. And I don't know how PowerShell's version of rc file works.

@KSXGitHub

Copy link
Copy Markdown
Contributor Author

we could also just update the shell config files and add aliases

Also, this definitely wouldn't work in CI environment.

@zkochan

zkochan commented Jun 26, 2024

Copy link
Copy Markdown
Member

OK, add a comment about it to the function. Why this approach instead of aliases.

@zkochan
zkochan merged commit 3beb895 into main Jun 26, 2024
@zkochan
zkochan deleted the add-pnpx-to-setup-8230 branch June 26, 2024 13:52
zkochan pushed a commit that referenced this pull request Jul 5, 2024
zkochan added a commit that referenced this pull request Sep 14, 2026
…14797)

The alias bins looked pnpm up on PATH, so the pnpm that ran was whichever
one PATH named first. That failed where the directory holding them was
not on PATH, even with the native binary sitting next to them, and it let
any other pnpm ahead of that directory silently handle calls meant for
the local install.

Every form now names its sibling. The POSIX script walks `$0` through its
symlinks and execs the pnpm in that directory; the walk matters because
`$0` is the shim or symlink the alias was launched through, and the
sibling to find is the one in the package, not in whichever directory
linked it. Its hop cap matches the `pnpm` placeholder script, which walks
`$0` for the same reason. The `.cmd` calls "%~dp0pnpm.cmd" with `call`, so
control returns and the exit code is the shim's; the `.ps1` calls
"$basedir\pnpm.ps1" and ends in `exit $LastExitCode`, which it dropped
before. The Windows wrappers have one sibling to name because `pnpm
setup` installs via `pnpm add -g` and link_bins writes a bare pnpm.exe
only for the `node` bin name, so every other bin gets the
pnpm/pnpm.cmd/pnpm.ps1 shim trio.

Only the v12 tarball regressed. The v11 `pnpm` package's bins are real
entry points that resolve relative to themselves, and v12 replaced them
with these scripts. The other three writers have always been PATH-based:
`pnpm setup` in both stacks since #8241, and `@pnpm/exe`'s
prepare.js. All four change here, which puts the fix in both stacks as
the version policy requires.

Two asymmetries are deliberate. `@pnpm/exe`'s POSIX aliases also check
that the sibling is executable, because the placeholder its install
script replaces is not, and the EACCES from exec'ing that placeholder
would say nothing about the script having been skipped. Its .cmd and .ps1
stay on PATH, because that same install script hardlinks the binary onto
pn.exe/pnpx.exe/pnx.exe and points `bin` at them, so those wrappers only
run when it did not — and then there is no sibling to resolve.

Closes #14803.

---------

Co-authored-by: Zoltan Kochan <[email protected]>
biisal pushed a commit to biisal/pnpm that referenced this pull request Sep 15, 2026
…npm#14797)

The alias bins looked pnpm up on PATH, so the pnpm that ran was whichever
one PATH named first. That failed where the directory holding them was
not on PATH, even with the native binary sitting next to them, and it let
any other pnpm ahead of that directory silently handle calls meant for
the local install.

Every form now names its sibling. The POSIX script walks `$0` through its
symlinks and execs the pnpm in that directory; the walk matters because
`$0` is the shim or symlink the alias was launched through, and the
sibling to find is the one in the package, not in whichever directory
linked it. Its hop cap matches the `pnpm` placeholder script, which walks
`$0` for the same reason. The `.cmd` calls "%~dp0pnpm.cmd" with `call`, so
control returns and the exit code is the shim's; the `.ps1` calls
"$basedir\pnpm.ps1" and ends in `exit $LastExitCode`, which it dropped
before. The Windows wrappers have one sibling to name because `pnpm
setup` installs via `pnpm add -g` and link_bins writes a bare pnpm.exe
only for the `node` bin name, so every other bin gets the
pnpm/pnpm.cmd/pnpm.ps1 shim trio.

Only the v12 tarball regressed. The v11 `pnpm` package's bins are real
entry points that resolve relative to themselves, and v12 replaced them
with these scripts. The other three writers have always been PATH-based:
`pnpm setup` in both stacks since pnpm#8241, and `@pnpm/exe`'s
prepare.js. All four change here, which puts the fix in both stacks as
the version policy requires.

Two asymmetries are deliberate. `@pnpm/exe`'s POSIX aliases also check
that the sibling is executable, because the placeholder its install
script replaces is not, and the EACCES from exec'ing that placeholder
would say nothing about the script having been skipped. Its .cmd and .ps1
stay on PATH, because that same install script hardlinks the binary onto
pn.exe/pnpx.exe/pnx.exe and points `bin` at them, so those wrappers only
run when it did not — and then there is no sibling to resolve.

Closes pnpm#14803.

---------

Co-authored-by: Zoltan Kochan <[email protected]>
u9g pushed a commit to u9g/pnpm that referenced this pull request Sep 25, 2026
…npm#14797)

The alias bins looked pnpm up on PATH, so the pnpm that ran was whichever
one PATH named first. That failed where the directory holding them was
not on PATH, even with the native binary sitting next to them, and it let
any other pnpm ahead of that directory silently handle calls meant for
the local install.

Every form now names its sibling. The POSIX script walks `$0` through its
symlinks and execs the pnpm in that directory; the walk matters because
`$0` is the shim or symlink the alias was launched through, and the
sibling to find is the one in the package, not in whichever directory
linked it. Its hop cap matches the `pnpm` placeholder script, which walks
`$0` for the same reason. The `.cmd` calls "%~dp0pnpm.cmd" with `call`, so
control returns and the exit code is the shim's; the `.ps1` calls
"$basedir\pnpm.ps1" and ends in `exit $LastExitCode`, which it dropped
before. The Windows wrappers have one sibling to name because `pnpm
setup` installs via `pnpm add -g` and link_bins writes a bare pnpm.exe
only for the `node` bin name, so every other bin gets the
pnpm/pnpm.cmd/pnpm.ps1 shim trio.

Only the v12 tarball regressed. The v11 `pnpm` package's bins are real
entry points that resolve relative to themselves, and v12 replaced them
with these scripts. The other three writers have always been PATH-based:
`pnpm setup` in both stacks since pnpm#8241, and `@pnpm/exe`'s
prepare.js. All four change here, which puts the fix in both stacks as
the version policy requires.

Two asymmetries are deliberate. `@pnpm/exe`'s POSIX aliases also check
that the sibling is executable, because the placeholder its install
script replaces is not, and the EACCES from exec'ing that placeholder
would say nothing about the script having been skipped. Its .cmd and .ps1
stay on PATH, because that same install script hardlinks the binary onto
pn.exe/pnpx.exe/pnx.exe and points `bin` at them, so those wrappers only
run when it did not — and then there is no sibling to resolve.

Closes pnpm#14803.

---------

Co-authored-by: Zoltan Kochan <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Install script does not install pnpx

2 participants