fix(env): do not create a command shim for the Node.js executable (#3869)

This commit is contained in:
Zoltan Kochan
2021-10-14 14:26:00 +03:00
committed by GitHub
parent cd597bdf9f
commit 913d97a050
2 changed files with 12 additions and 3 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-env": patch
---
Do not create a command shim for Node.js, just a symlink to the executable.

View File

@@ -1,3 +1,4 @@
import { promises as fs } from 'fs'
import path from 'path'
import { docsUrl } from '@pnpm/cli-utils'
import PnpmError from '@pnpm/error'
@@ -64,15 +65,18 @@ export async function handler (opts: NvmNodeCommandOptions, params: string[]) {
useNodeVersion: nodeVersion,
})
const src = path.join(nodeDir, process.platform === 'win32' ? 'node.exe' : 'bin/node')
const dest = path.join(opts.bin, 'node')
const cmdShimOpts = { createPwshFile: false }
await cmdShim(src, dest, cmdShimOpts)
const dest = path.join(opts.bin, process.platform === 'win32' ? 'node.exe' : 'node')
try {
await fs.unlink(dest)
} catch (err) {}
await fs.symlink(src, dest, 'file')
try {
let npmDir = nodeDir
if (process.platform !== 'win32') {
npmDir = path.join(npmDir, 'lib')
}
npmDir = path.join(npmDir, 'node_modules/npm/bin')
const cmdShimOpts = { createPwshFile: false }
await cmdShim(path.join(npmDir, 'npm-cli.js'), path.join(opts.bin, 'npm'), cmdShimOpts)
await cmdShim(path.join(npmDir, 'npx-cli.js'), path.join(opts.bin, 'npx'), cmdShimOpts)
} catch (err) {