Skip to content

Commit cf369ce

Browse files
authoredMar 17, 2022
fix: bind cwd to spawn call (#352)
1 parent 3794306 commit cf369ce

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed
 

‎src/index.mjs

+2-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export function registerGlobals() {
5858
export function $(pieces, ...args) {
5959
let {verbose, shell, prefix, spawn, maxBuffer = 200 * 1024 * 1024 /* 200 MiB*/} = $
6060
let __from = (new Error().stack.split(/^\s*at\s/m)[2]).trim()
61+
let cwd = process.cwd()
6162

6263
let cmd = pieces[0], i = 0
6364
while (i < args.length) {
@@ -81,7 +82,7 @@ export function $(pieces, ...args) {
8182
}
8283

8384
let child = spawn(prefix + cmd, {
84-
cwd: process.cwd(),
85+
cwd,
8586
shell: typeof shell === 'string' ? shell : true,
8687
stdio: [promise._inheritStdin ? 'inherit' : 'pipe', 'pipe', 'pipe'],
8788
windowsHide: true,

‎test.mjs

+8-2
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,16 @@ if (test('The cd() works with relative paths')) {
204204
try {
205205
fs.mkdirpSync('/tmp/zx-cd-test/one/two')
206206
cd('/tmp/zx-cd-test/one/two')
207+
let p1 = $`pwd`
207208
cd('..')
209+
let p2 = $`pwd`
208210
cd('..')
209-
let pwd = (await $`pwd`).stdout.trim()
210-
assert.equal(path.basename(pwd), 'zx-cd-test')
211+
let p3 = $`pwd`
212+
213+
let results = (await Promise.all([p1, p2, p3]))
214+
.map(p => path.basename(p.stdout.trim()))
215+
216+
assert.deepEqual(results, ['two', 'one', 'zx-cd-test'])
211217
} finally {
212218
fs.rmSync('/tmp/zx-cd-test', {recursive: true})
213219
cd(__dirname)

0 commit comments

Comments
 (0)
Please sign in to comment.