Skip to content

Commit

Permalink
fix: handle $PATH on win32
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed May 10, 2024
1 parent 41c037c commit 0503336
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { spawn, spawnSync, StdioOptions, IOType } from 'node:child_process'
import { AsyncHook, AsyncLocalStorage, createHook } from 'node:async_hooks'
import { Readable, Writable } from 'node:stream'
import { inspect } from 'node:util'
import path from 'node:path'
import {
exec,
buildCmd,
Expand Down Expand Up @@ -591,14 +592,22 @@ function syncCwd() {
}

function injectNmBin(env: NodeJS.ProcessEnv, ...dirs: (string | undefined)[]) {
const extra = dirs
const pathKey =
process.platform === 'win32'
? Object.keys(env)
.reverse()
.find((key) => key.toUpperCase() === 'PATH') || 'Path'
: 'PATH'
const pathValue = dirs
.map((c) => c && path.resolve(c as string, 'node_modules', '.bin'))
.concat(env[pathKey])
.filter(Boolean)
.map((c) => `${c}/node_modules/.bin`)
.join(':')
.join(path.delimiter)

return extra
? { ...env, PATH: env.PATH ? `${extra}:${env.PATH}` : extra }
: env
return {
...env,
[pathKey]: pathValue,
}
}

export function cd(dir: string | ProcessOutput) {
Expand Down

0 comments on commit 0503336

Please sign in to comment.