@zkochan/cmd-shim
Advanced tools
Comparing version
@@ -45,2 +45,3 @@ declare namespace cmdShim { | ||
nodeExecPath?: string; | ||
prependToPath?: string; | ||
} | ||
@@ -47,0 +48,0 @@ } |
42
index.js
@@ -210,2 +210,3 @@ 'use strict'; | ||
const nodePath = normalizePathEnvVar(opts.nodePath).win32; | ||
const prependToPath = normalizePathEnvVar(opts.prependToPath).win32; | ||
if (!prog) { | ||
@@ -233,2 +234,5 @@ prog = quotedPathToTarget; | ||
let cmd = '@SETLOCAL\r\n'; | ||
if (prependToPath) { | ||
cmd += `@SET "PATH=${prependToPath}:%PATH%"\r\n`; | ||
} | ||
if (nodePath) { | ||
@@ -312,2 +316,7 @@ cmd += `\ | ||
`; | ||
if (opts.prependToPath) { | ||
sh += `\ | ||
export PATH="${opts.prependToPath}:$PATH" | ||
`; | ||
} | ||
if (shNodePath) { | ||
@@ -356,5 +365,8 @@ sh += `\ | ||
let args = opts.args || ''; | ||
let normalizedPathEnvVar = normalizePathEnvVar(opts.nodePath); | ||
const nodePath = normalizedPathEnvVar.win32; | ||
const shNodePath = normalizedPathEnvVar.posix; | ||
let normalizedNodePathEnvVar = normalizePathEnvVar(opts.nodePath); | ||
const nodePath = normalizedNodePathEnvVar.win32; | ||
const shNodePath = normalizedNodePathEnvVar.posix; | ||
let normalizedPrependPathEnvVar = normalizePathEnvVar(opts.prependToPath); | ||
const prependPath = normalizedPrependPathEnvVar.win32; | ||
const shPrependPath = normalizedPrependPathEnvVar.posix; | ||
if (!pwshProg) { | ||
@@ -407,7 +419,11 @@ pwshProg = quotedPathToTarget; | ||
$exe="" | ||
${(nodePath || prependPath) ? '$pathsep=":"\n' : ''}\ | ||
${nodePath ? `\ | ||
$pathsep=":" | ||
$env_node_path=$env:NODE_PATH | ||
$new_node_path="${nodePath}" | ||
` : ''}\ | ||
${prependPath ? `\ | ||
$env_path=$env:PATH | ||
$prepend_path="${prependPath}" | ||
` : ''}\ | ||
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { | ||
@@ -417,9 +433,14 @@ # Fix case when both the Windows and Linux builds of Node | ||
$exe=".exe" | ||
${nodePath ? ' $pathsep=";"\n' : ''}\ | ||
${(nodePath || prependPath) ? ' $pathsep=";"\n' : ''}\ | ||
}`; | ||
if (shNodePath) { | ||
if (shNodePath || shPrependPath) { | ||
pwsh += `\ | ||
else { | ||
$new_node_path="${shNodePath}" | ||
${shNodePath ? ` $new_node_path="${shNodePath}"\n` : ''}\ | ||
${shPrependPath ? ` $prepend_path="${shPrependPath}"\n` : ''}\ | ||
} | ||
`; | ||
} | ||
if (shNodePath) { | ||
pwsh += `\ | ||
if ([string]::IsNullOrEmpty($env_node_path)) { | ||
@@ -432,2 +453,7 @@ $env:NODE_PATH=$new_node_path | ||
} | ||
if (opts.prependToPath) { | ||
pwsh += ` | ||
$env:PATH="$prepend_path$pathsep$env:PATH" | ||
`; | ||
} | ||
if (pwshLongProg) { | ||
@@ -454,2 +480,3 @@ pwsh += ` | ||
${nodePath ? '$env:NODE_PATH=$env_node_path\n' : ''}\ | ||
${prependPath ? '$env:PATH=$env_path\n' : ''}\ | ||
exit $ret | ||
@@ -467,2 +494,3 @@ `; | ||
${nodePath ? '$env:NODE_PATH=$env_node_path\n' : ''}\ | ||
${prependPath ? '$env:PATH=$env_path\n' : ''}\ | ||
exit $LASTEXITCODE | ||
@@ -469,0 +497,0 @@ `; |
{ | ||
"name": "@zkochan/cmd-shim", | ||
"version": "5.2.2", | ||
"version": "5.3.0", | ||
"description": "Used in pnpm for command line application support", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -38,2 +38,3 @@ # @zkochan/cmd-shim | ||
- `opts.nodePath` - _String_ - sets the [NODE_PATH](https://nodejs.org/api/cli.html#cli_node_path_path) env variable. | ||
- `opts.prependToPath` - _String_ - prepends the passed path to PATH before executing the Node.js program. | ||
- `opts.nodeExecPath` - _String_ - sets the path to the Node.js executable. | ||
@@ -40,0 +41,0 @@ - `opts.createCmdFile` - _Boolean_ - is `true` on Windows by default. If true, creates a cmd file. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
36221
5.8%588
5.19%53
1.92%