mirror of
https://github.com/pnpm/pnpm.git
synced 2026-04-05 07:46:10 -04:00
chore(setup): do not remove executable in setup (#3724)
The executable installed by package manager (e.g. Homebrew) should not be removed after the setup command is run. The installation script should remove that and install.sh do so.
This commit is contained in:
5
.changeset/poor-lobsters-turn.md
Normal file
5
.changeset/poor-lobsters-turn.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@pnpm/plugin-commands-setup": minor
|
||||
---
|
||||
|
||||
The original binary will not be removed after pnpm setup.
|
||||
@@ -33,22 +33,15 @@ function getExecPath () {
|
||||
return (require.main != null) ? require.main.filename : process.cwd()
|
||||
}
|
||||
|
||||
function moveCli (currentLocation: string, targetDir: string) {
|
||||
function copyCli (currentLocation: string, targetDir: string) {
|
||||
const newExecPath = path.join(targetDir, path.basename(currentLocation))
|
||||
if (path.relative(newExecPath, currentLocation) === '') return
|
||||
logger.info({
|
||||
message: `Moving pnpm CLI from ${currentLocation} to ${newExecPath}`,
|
||||
message: `Copying pnpm CLI from ${currentLocation} to ${newExecPath}`,
|
||||
prefix: process.cwd(),
|
||||
})
|
||||
fs.mkdirSync(targetDir, { recursive: true })
|
||||
try {
|
||||
fs.renameSync(currentLocation, newExecPath)
|
||||
} catch (err) {
|
||||
fs.copyFileSync(currentLocation, newExecPath)
|
||||
try {
|
||||
fs.unlinkSync(currentLocation)
|
||||
} catch (err) {}
|
||||
}
|
||||
fs.copyFileSync(currentLocation, newExecPath)
|
||||
}
|
||||
|
||||
export async function handler (
|
||||
@@ -59,7 +52,7 @@ export async function handler (
|
||||
const currentShell = process.env.SHELL ? path.basename(process.env.SHELL) : null
|
||||
const execPath = getExecPath()
|
||||
if (execPath.match(/\.[cm]?js$/) == null) {
|
||||
moveCli(execPath, opts.pnpmHomeDir)
|
||||
copyCli(execPath, opts.pnpmHomeDir)
|
||||
}
|
||||
const updateOutput = await updateShell(currentShell, opts.pnpmHomeDir)
|
||||
if (updateOutput === false) {
|
||||
|
||||
Reference in New Issue
Block a user