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:
Kaito Udagawa
2021-08-30 01:46:39 +09:00
committed by GitHub
parent 40690fa58e
commit ade0fa92f4
2 changed files with 9 additions and 11 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-setup": minor
---
The original binary will not be removed after pnpm setup.

View File

@@ -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) {