@@ -13,6 +13,13 @@ import type {
13
13
let runCounter = 0 ;
14
14
const debug = createDebugLogger ( { namespace : globalDebuggerNamespace } ) ;
15
15
16
+ const nodejsDebugStringRegExps = [
17
+ / ^ D e b u g g e r a t t a c h e d \. ( \n | $ ) / gm,
18
+ / ^ D e b u g g e r l i s t e n i n g o n .+ ( \n | $ ) / gm,
19
+ / ^ F o r h e l p , s e e : h t t p s : \/ \/ n o d e j s \. o r g \/ e n \/ d o c s \/ i n s p e c t o r ( \n | $ ) / gm,
20
+ / ^ W a i t i n g f o r t h e d e b u g g e r t o d i s c o n n e c t \. \. \. ( \n | $ ) / gm
21
+ ] ;
22
+
16
23
export type { Subprocess } from 'execa' with { 'resolution-mode' : 'import' } ;
17
24
export type * from 'universe+run:types.ts' ;
18
25
@@ -27,6 +34,9 @@ export type * from 'universe+run:types.ts';
27
34
*
28
35
* 2. Coerces output to a string. Set `coerceOutputToString: false` (or `lines:
29
36
* true`) to override this.
37
+ *
38
+ * 3. Elides Node.js debugger strings. Set `elideNodeDebuggerStringsFromStderr:
39
+ * false` to override this.
30
40
*/
31
41
export async function run (
32
42
file : string ,
@@ -48,6 +58,7 @@ export async function run<OptionsType extends RunOptions = DefaultRunOptions>(
48
58
const {
49
59
useIntermediate,
50
60
coerceOutputToString = true ,
61
+ elideNodeDebuggerStringsFromStderr = true ,
51
62
...execaOptions
52
63
} = options || ( { } as RunOptions ) ;
53
64
@@ -57,7 +68,9 @@ export async function run<OptionsType extends RunOptions = DefaultRunOptions>(
57
68
58
69
const shouldCoerceOutputToString = coerceOutputToString && ! execaOptions . lines ;
59
70
runDebug ( 'output coercion: %O' , shouldCoerceOutputToString ) ;
71
+ runDebug ( 'debug elision: %O' , elideNodeDebuggerStringsFromStderr ) ;
60
72
73
+ const stripFinalNewline = ( await import ( 'strip-final-newline' ) ) . default ;
61
74
const intermediateResult = ( await import ( 'execa' ) ) . execa ( file , args , execaOptions ) ;
62
75
63
76
await useIntermediate ?.( intermediateResult ) ;
@@ -70,6 +83,25 @@ export async function run<OptionsType extends RunOptions = DefaultRunOptions>(
70
83
finalResult . stderr = finalResult . stderr ?. toString ( ) ?? '' ;
71
84
}
72
85
86
+ if ( elideNodeDebuggerStringsFromStderr ) {
87
+ /* istanbul ignore else */
88
+ if ( typeof finalResult . stderr === 'string' ) {
89
+ let { stderr } = finalResult ;
90
+
91
+ nodejsDebugStringRegExps . forEach ( ( regExp ) => {
92
+ stderr = stderr . replaceAll ( regExp , '' ) ;
93
+ } ) ;
94
+
95
+ finalResult . stderr =
96
+ execaOptions . stripFinalNewline === false ? stderr : stripFinalNewline ( stderr ) ;
97
+ } else if ( Array . isArray ( finalResult . stderr ) ) {
98
+ finalResult . stderr = finalResult . stderr . filter ( ( filterTarget_ ) => {
99
+ const filterTarget = String ( filterTarget_ ) ;
100
+ return nodejsDebugStringRegExps . every ( ( regExp ) => ! filterTarget . match ( regExp ) ) ;
101
+ } ) ;
102
+ }
103
+ }
104
+
73
105
runDebug ( 'execution result: %O' , finalResult ) ;
74
106
return finalResult ;
75
107
}
@@ -94,6 +126,7 @@ export async function runWithInheritedIo(
94
126
return run ( file , args , {
95
127
...options ,
96
128
coerceOutputToString : false ,
129
+ elideNodeDebuggerStringsFromStderr : false ,
97
130
stdio : 'inherit'
98
131
} ) as Promise < Omit < RunReturnType , 'all' | 'stdout' | 'stderr' | 'stdio' > > ;
99
132
}
@@ -108,6 +141,9 @@ export async function runWithInheritedIo(
108
141
*
109
142
* 2. Coerces output to a string. Set `coerceOutputToString: false` (or `lines:
110
143
* true`) to override this.
144
+ *
145
+ * 3. Elides Node.js debugger strings. Set `elideNodeDebuggerStringsFromStderr:
146
+ * false` to override this.
111
147
*/
112
148
export async function runNoRejectOnBadExit (
113
149
file : string ,
@@ -142,6 +178,9 @@ export async function runNoRejectOnBadExit<
142
178
*
143
179
* 2. Coerces output to a string. Set `coerceOutputToString: false` (or
144
180
* `lines: true`) to override this.
181
+ *
182
+ * 3. Elides Node.js debugger strings. Set `elideNodeDebuggerStringsFromStderr:
183
+ * false` to override this.
145
184
*/
146
185
export function runnerFactory < FactoryOptionsType extends RunOptions = DefaultRunOptions > (
147
186
file : string ,
0 commit comments