From 913d97a050e8de60990134c8ea46d83a7e9bea64 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Thu, 14 Oct 2021 14:26:00 +0300 Subject: [PATCH] fix(env): do not create a command shim for the Node.js executable (#3869) --- .changeset/hungry-pillows-begin.md | 5 +++++ packages/plugin-commands-env/src/env.ts | 10 +++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 .changeset/hungry-pillows-begin.md diff --git a/.changeset/hungry-pillows-begin.md b/.changeset/hungry-pillows-begin.md new file mode 100644 index 0000000000..1b7563c058 --- /dev/null +++ b/.changeset/hungry-pillows-begin.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-env": patch +--- + +Do not create a command shim for Node.js, just a symlink to the executable. diff --git a/packages/plugin-commands-env/src/env.ts b/packages/plugin-commands-env/src/env.ts index 9d4827cfb0..703a2cf293 100644 --- a/packages/plugin-commands-env/src/env.ts +++ b/packages/plugin-commands-env/src/env.ts @@ -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) {