@@ -12,29 +12,25 @@ import { processOnExit } from './dev.js'
12
12
const isErrnoException = ( value : unknown ) : value is NodeJS . ErrnoException =>
13
13
value instanceof Error && Object . hasOwn ( value , 'code' )
14
14
15
- const createStripAnsiControlCharsStream = ( ) : Transform => new Transform ( {
16
- transform ( chunk , _encoding , callback ) {
17
- const text = typeof chunk === 'string' ? chunk : chunk . toString ( )
18
- callback ( null , stripVTControlCharacters ( text ) )
19
- }
20
- } )
15
+ const createStripAnsiControlCharsStream = ( ) : Transform =>
16
+ new Transform ( {
17
+ transform ( chunk , _encoding , callback ) {
18
+ callback ( null , stripVTControlCharacters ( typeof chunk === 'string' ? chunk : ( chunk as unknown ) ?. toString ( ) ?? '' ) )
19
+ } ,
20
+ } )
21
21
22
22
const cleanupWork : ( ( ) => Promise < void > ) [ ] = [ ]
23
23
24
24
let cleanupStarted = false
25
25
26
- /**
27
- * @param {object } input
28
- * @param {number= } input.exitCode The exit code to return when exiting the process after cleanup
29
- */
30
26
const cleanupBeforeExit = async ( { exitCode } : { exitCode ?: number | undefined } = { } ) => {
31
27
// If cleanup has started, then wherever started it will be responsible for exiting
32
28
if ( ! cleanupStarted ) {
33
29
cleanupStarted = true
34
30
try {
35
- // @ts -expect-error TS(7005) FIXME: Variable 'cleanupWork' implicitly has an 'any[]' t... Remove this comment to see the full error message
36
31
await Promise . all ( cleanupWork . map ( ( cleanup ) => cleanup ( ) ) )
37
32
} finally {
33
+ // eslint-disable-next-line n/no-process-exit
38
34
process . exit ( exitCode )
39
35
}
40
36
}
@@ -70,7 +66,7 @@ export const runCommand = (
70
66
// In this case, we want to manually control when to clear and when to render a frame, so we turn this off.
71
67
stopSpinner ( { error : false , spinner } )
72
68
}
73
- const pipeDataWithSpinner = ( writeStream : NodeJS . WriteStream , chunk : any ) => {
69
+ const pipeDataWithSpinner = ( writeStream : NodeJS . WriteStream , chunk : string | Uint8Array ) => {
74
70
if ( spinner ?. isSpinning ) {
75
71
spinner . clear ( )
76
72
}
@@ -79,14 +75,19 @@ export const runCommand = (
79
75
} )
80
76
}
81
77
82
- commandProcess . stdout ?. pipe ( createStripAnsiControlCharsStream ( ) ) . on ( 'data' , pipeDataWithSpinner . bind ( null , process . stdout ) )
83
- commandProcess . stderr ?. pipe ( createStripAnsiControlCharsStream ( ) ) . on ( 'data' , pipeDataWithSpinner . bind ( null , process . stderr ) )
78
+ commandProcess . stdout
79
+ ?. pipe ( createStripAnsiControlCharsStream ( ) )
80
+ . on ( 'data' , pipeDataWithSpinner . bind ( null , process . stdout ) )
81
+ commandProcess . stderr
82
+ ?. pipe ( createStripAnsiControlCharsStream ( ) )
83
+ . on ( 'data' , pipeDataWithSpinner . bind ( null , process . stderr ) )
84
84
if ( commandProcess . stdin != null ) {
85
- process . stdin ? .pipe ( commandProcess . stdin )
85
+ process . stdin . pipe ( commandProcess . stdin )
86
86
}
87
87
88
88
// we can't try->await->catch since we don't want to block on the framework server which
89
89
// is a long running process
90
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
90
91
commandProcess . then ( async ( ) => {
91
92
const result = await commandProcess
92
93
const [ commandWithoutArgs ] = command . split ( ' ' )
@@ -98,9 +99,10 @@ export const runCommand = (
98
99
)
99
100
} else {
100
101
const errorMessage = result . failed
101
- ? // @ts -expect-error TS(2339) FIXME: Property 'shortMessage' does not exist on type 'Ex... Remove this comment to see the full error message
102
- `${ NETLIFYDEVERR } ${ result . shortMessage } `
103
- : `${ NETLIFYDEVWARN } "${ command } " exited with code ${ result . exitCode } `
102
+ ? // @ts -expect-error FIXME(serhalp): We use `reject: false` which means the resolved value is either the resolved value
103
+ // or the rejected value, but the types aren't smart enough to know this.
104
+ `${ NETLIFYDEVERR } ${ result . shortMessage as string } `
105
+ : `${ NETLIFYDEVWARN } "${ command } " exited with code ${ result . exitCode . toString ( ) } `
104
106
105
107
log ( `${ errorMessage } . Shutting down Netlify Dev server` )
106
108
}
@@ -114,18 +116,10 @@ export const runCommand = (
114
116
return commandProcess
115
117
}
116
118
117
- /**
118
- *
119
- * @param {object } config
120
- * @param {string } config.command
121
- * @param {* } config.error
122
- * @returns
123
- */
124
- // @ts -expect-error TS(7031) FIXME: Binding element 'command' implicitly has an 'any' ... Remove this comment to see the full error message
125
- const isNonExistingCommandError = ( { command, error : commandError } ) => {
119
+ const isNonExistingCommandError = ( { command, error : commandError } : { command : string ; error : unknown } ) => {
126
120
// `ENOENT` is only returned for non Windows systems
127
121
// See https://github.com/sindresorhus/execa/pull/447
128
- if ( commandError . code === 'ENOENT' ) {
122
+ if ( isErrnoException ( commandError ) && commandError . code === 'ENOENT' ) {
129
123
return true
130
124
}
131
125
@@ -136,6 +130,7 @@ const isNonExistingCommandError = ({ command, error: commandError }) => {
136
130
137
131
// this only works on English versions of Windows
138
132
return (
133
+ commandError instanceof Error &&
139
134
typeof commandError . message === 'string' &&
140
135
commandError . message . includes ( 'is not recognized as an internal or external command' )
141
136
)
0 commit comments