Skip to content

Commit a6b60e9

Browse files
committed
fix(bun): make lazy cwdSyncHook init
closes google#847
1 parent cd8b511 commit a6b60e9

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/core.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,18 @@ export interface Options {
8484
}
8585

8686
const storage = new AsyncLocalStorage<Options>()
87-
const cwdSyncHook: AsyncHook & { enabled?: boolean } = createHook({
88-
init: syncCwd,
89-
before: syncCwd,
90-
promiseResolve: syncCwd,
91-
after: syncCwd,
92-
destroy: syncCwd,
93-
})
87+
let cwdSyncHook: AsyncHook
9488

9589
export function syncProcessCwd(flag: boolean = true) {
90+
cwdSyncHook =
91+
cwdSyncHook ||
92+
createHook({
93+
init: syncCwd,
94+
before: syncCwd,
95+
promiseResolve: syncCwd,
96+
after: syncCwd,
97+
destroy: syncCwd,
98+
})
9699
if (flag) cwdSyncHook.enable()
97100
else cwdSyncHook.disable()
98101
}

0 commit comments

Comments
 (0)