14
14
15
15
import assert from 'node:assert'
16
16
import { spawn , spawnSync , StdioNull , StdioPipe } from 'node:child_process'
17
- import { AsyncLocalStorage , createHook } from 'node:async_hooks'
17
+ import { AsyncHook , AsyncLocalStorage , createHook } from 'node:async_hooks'
18
18
import { Readable , Writable } from 'node:stream'
19
19
import { inspect } from 'node:util'
20
20
import {
@@ -76,14 +76,13 @@ export interface Options {
76
76
}
77
77
78
78
const storage = new AsyncLocalStorage < Options > ( )
79
- const cwdHook = createHook ( {
79
+ const cwdHook : AsyncHook & { enabled ?: boolean } = createHook ( {
80
80
init : syncCwd ,
81
81
before : syncCwd ,
82
82
promiseResolve : syncCwd ,
83
83
after : syncCwd ,
84
84
destroy : syncCwd ,
85
85
} )
86
- cwdHook . enable ( )
87
86
88
87
export const defaults : Options = {
89
88
[ processCwd ] : process . cwd ( ) ,
@@ -172,6 +171,7 @@ export const $: Shell & Options = new Proxy<Shell & Options>(
172
171
{
173
172
set ( _ , key , value ) {
174
173
if ( key === 'cwdHook' ) {
174
+ cwdHook . enabled = ! ! value
175
175
if ( value ) cwdHook . enable ( )
176
176
else cwdHook . disable ( )
177
177
return true
@@ -184,13 +184,14 @@ export const $: Shell & Options = new Proxy<Shell & Options>(
184
184
} ,
185
185
get ( _ , key ) {
186
186
if ( key === 'sync' ) return $ ( { sync : true } )
187
+ if ( key === 'cwdHook' ) return cwdHook . enabled
187
188
188
189
const target = key in Function . prototype ? _ : getStore ( )
189
190
return Reflect . get ( target , key )
190
191
} ,
191
192
}
192
193
)
193
-
194
+ $ . cwdHook = true
194
195
try {
195
196
setupBash ( )
196
197
} catch ( err ) { }
0 commit comments