Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/dirty-foxes-invite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pnpm/tools.plugin-commands-self-updater": patch
"pnpm": patch
---

`pnpm self-update` should always install the non-executable pnpm package (pnpm in the registry) and never the `@pnpm/exe` package, when installing v11 or newer. We currently cannot ship `@pnpm/exe` as `pkg` doesn't work with ESM [#10190](https://github.com/pnpm/pnpm/pull/10190).
26 changes: 16 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions tools/plugin-commands-self-updater/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@
"@zkochan/rimraf": "catalog:",
"path-temp": "catalog:",
"ramda": "catalog:",
"rename-overwrite": "catalog:",
"render-help": "catalog:"
"render-help": "catalog:",
"semver": "catalog:",
"symlink-dir": "catalog:"
},
"peerDependencies": {
"@pnpm/logger": "catalog:"
Expand All @@ -56,6 +57,7 @@
"@pnpm/tools.plugin-commands-self-updater": "workspace:*",
"@types/cross-spawn": "catalog:",
"@types/ramda": "catalog:",
"@types/semver": "catalog:",
"cross-spawn": "catalog:",
"nock": "catalog:"
},
Expand Down
13 changes: 10 additions & 3 deletions tools/plugin-commands-self-updater/src/installPnpmToTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { runPnpmCli } from '@pnpm/exec.pnpm-cli-runner'
import { getToolDirPath } from '@pnpm/tools.path'
import { sync as rimraf } from '@zkochan/rimraf'
import { fastPathTemp as pathTemp } from 'path-temp'
import renameOverwrite from 'rename-overwrite'
import semver from 'semver'
import symlinkDir from 'symlink-dir'
import { type SelfUpdateCommandOptions } from './selfUpdate.js'

export interface InstallPnpmToToolsResult {
Expand All @@ -15,7 +16,9 @@ export interface InstallPnpmToToolsResult {
}

export async function installPnpmToTools (pnpmVersion: string, opts: SelfUpdateCommandOptions): Promise<InstallPnpmToToolsResult> {
const currentPkgName = getCurrentPackageName()
// We have moved pnpm to esm and that prevents us from using pkg to bundle pnpm to an executable.
// Related issue: https://github.com/yao-pkg/pkg/issues/16
const currentPkgName = semver.gt(pnpmVersion, '11.0.0-alpha') ? 'pnpm' : getCurrentPackageName()
const dir = getToolDirPath({
pnpmHomeDir: opts.pnpmHomeDir,
tool: {
Expand Down Expand Up @@ -50,7 +53,11 @@ export async function installPnpmToTools (pnpmVersion: string, opts: SelfUpdateC
'--config.node-linker=hoisted',
'--config.bin=bin',
], { cwd: stage })
renameOverwrite.sync(stage, dir)
// We need the operation of installing pnpm to be atomic.
// However, we cannot use a rename as that breaks the command shim created for pnpm.
// Hence, we use a symlink.
// In future we may switch back to rename if we will move Node.js out of the pnpm subdirectory.
symlinkDir.sync(stage, dir)
} catch (err: unknown) {
try {
rimraf(stage)
Expand Down
Loading