File tree 3 files changed +19
-9
lines changed
3 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ import {
38
38
parseDuration ,
39
39
quote ,
40
40
quotePowerShell ,
41
+ noquote ,
41
42
} from './util.js'
42
43
43
44
export interface Shell {
@@ -56,6 +57,7 @@ export interface Options {
56
57
[ processCwd ] : string
57
58
[ syncExec ] : boolean
58
59
cwd ?: string
60
+ cwdHook ?: boolean
59
61
ac ?: AbortController
60
62
input ?: string | Buffer | Readable | ProcessOutput | ProcessPromise
61
63
verbose : boolean
@@ -74,14 +76,14 @@ export interface Options {
74
76
}
75
77
76
78
const storage = new AsyncLocalStorage < Options > ( )
77
- const hook = createHook ( {
79
+ const cwdHook = createHook ( {
78
80
init : syncCwd ,
79
81
before : syncCwd ,
80
82
promiseResolve : syncCwd ,
81
83
after : syncCwd ,
82
84
destroy : syncCwd ,
83
85
} )
84
- hook . enable ( )
86
+ cwdHook . enable ( )
85
87
86
88
export const defaults : Options = {
87
89
[ processCwd ] : process . cwd ( ) ,
@@ -94,9 +96,7 @@ export const defaults: Options = {
94
96
quiet : false ,
95
97
prefix : '' ,
96
98
postfix : '' ,
97
- quote : ( ) => {
98
- throw new Error ( 'No quote function is defined: https://ï.at/no-quote-func' )
99
- } ,
99
+ quote : noquote ,
100
100
spawn,
101
101
spawnSync,
102
102
log,
@@ -171,6 +171,12 @@ export const $: Shell & Options = new Proxy<Shell & Options>(
171
171
} as Shell & Options ,
172
172
{
173
173
set ( _ , key , value ) {
174
+ if ( key === 'cwdHook' ) {
175
+ if ( value ) cwdHook . enable ( )
176
+ else cwdHook . disable ( )
177
+ return true
178
+ }
179
+
174
180
const target = key in Function . prototype ? _ : getStore ( )
175
181
Reflect . set ( target , key === 'sync' ? syncExec : key , value )
176
182
Original file line number Diff line number Diff line change @@ -42,6 +42,10 @@ export function normalizeMultilinePieces(
42
42
)
43
43
}
44
44
45
+ export function noquote ( ) : string {
46
+ throw new Error ( 'No quote function is defined: https://ï.at/no-quote-func' )
47
+ }
48
+
45
49
export function quote ( arg : string ) {
46
50
if ( / ^ [ a - z 0 - 9 / _ . \- @ : = ] + $ / i. test ( arg ) || arg === '' ) {
47
51
return arg
Original file line number Diff line number Diff line change @@ -263,25 +263,25 @@ describe('core', () => {
263
263
}
264
264
} )
265
265
266
- test ( 'cd() does affect parallel contexts' , async ( ) => {
266
+ test ( 'cd() does not affect parallel contexts' , async ( ) => {
267
267
const cwd = process . cwd ( )
268
268
try {
269
269
fs . mkdirpSync ( '/tmp/zx-cd-parallel/one/two' )
270
270
await Promise . all ( [
271
271
within ( async ( ) => {
272
272
assert . equal ( process . cwd ( ) , cwd )
273
- await sleep ( 1 )
274
273
cd ( '/tmp/zx-cd-parallel/one' )
274
+ await sleep ( Math . random ( ) * 15 )
275
275
assert . ok ( process . cwd ( ) . endsWith ( '/tmp/zx-cd-parallel/one' ) )
276
276
} ) ,
277
277
within ( async ( ) => {
278
278
assert . equal ( process . cwd ( ) , cwd )
279
- await sleep ( 2 )
279
+ await sleep ( Math . random ( ) * 15 )
280
280
assert . equal ( process . cwd ( ) , cwd )
281
281
} ) ,
282
282
within ( async ( ) => {
283
283
assert . equal ( process . cwd ( ) , cwd )
284
- await sleep ( 3 )
284
+ await sleep ( Math . random ( ) * 15 )
285
285
$ . cwd = '/tmp/zx-cd-parallel/one/two'
286
286
assert . equal ( process . cwd ( ) , cwd )
287
287
assert . ok (
You can’t perform that action at this time.
0 commit comments