1
1
import { createRequire } from 'node:module'
2
2
3
- import type { ContextRPC } from '../types'
3
+ import type { ContextRPC , ResolvedConfig } from '../types'
4
4
5
5
const __require = createRequire ( import . meta. url )
6
6
let inspector : typeof import ( 'node:inspector' )
@@ -44,11 +44,7 @@ export function setupInspect(ctx: ContextRPC) {
44
44
}
45
45
}
46
46
47
- // In watch mode the inspector can persist re-runs if isolation is disabled and a single worker is used
48
- const isIsolatedSingleThread = config . pool === 'threads' && config . poolOptions ?. threads ?. isolate === false && config . poolOptions ?. threads ?. singleThread
49
- const isIsolatedSingleFork = config . pool === 'forks' && config . poolOptions ?. forks ?. isolate === false && config . poolOptions ?. forks ?. singleFork
50
-
51
- const keepOpen = config . watch && ( isIsolatedSingleFork || isIsolatedSingleThread )
47
+ const keepOpen = shouldKeepOpen ( config )
52
48
53
49
return function cleanup ( ) {
54
50
if ( isEnabled && ! keepOpen && inspector ) {
@@ -57,3 +53,20 @@ export function setupInspect(ctx: ContextRPC) {
57
53
}
58
54
}
59
55
}
56
+
57
+ export function closeInspector ( config : ResolvedConfig ) {
58
+ const keepOpen = shouldKeepOpen ( config )
59
+
60
+ if ( inspector && ! keepOpen ) {
61
+ inspector . close ( )
62
+ session ?. disconnect ( )
63
+ }
64
+ }
65
+
66
+ function shouldKeepOpen ( config : ResolvedConfig ) {
67
+ // In watch mode the inspector can persist re-runs if isolation is disabled and a single worker is used
68
+ const isIsolatedSingleThread = config . pool === 'threads' && config . poolOptions ?. threads ?. isolate === false && config . poolOptions ?. threads ?. singleThread
69
+ const isIsolatedSingleFork = config . pool === 'forks' && config . poolOptions ?. forks ?. isolate === false && config . poolOptions ?. forks ?. singleFork
70
+
71
+ return config . watch && ( isIsolatedSingleFork || isIsolatedSingleThread )
72
+ }
0 commit comments