@@ -65,15 +65,6 @@ export class UnityHub {
6565 let output : string = '' ;
6666 let exitCode : number = 0 ;
6767
68- function processOutput ( data : Buffer ) {
69- const chunk = data . toString ( ) ;
70- output += chunk ;
71-
72- if ( ! options . silent ) {
73- process . stdout . write ( chunk ) ;
74- }
75- }
76-
7768 const filteredArgs = args . filter ( arg => arg !== '--headless' && arg !== '--' ) ;
7869 const executable = process . platform === 'linux' ? 'unity-hub' : this . executable ;
7970 const execArgs = process . platform === 'linux' ? [ '--headless' , ...filteredArgs ] : [ '--' , '--headless' , ...filteredArgs ] ;
@@ -86,16 +77,57 @@ export class UnityHub {
8677 fs . accessSync ( this . executable , fs . constants . R_OK | fs . constants . X_OK ) ;
8778 }
8879
80+ const ignoredLines = [
81+ `This error originated either by throwing inside of an async function without a catch block` ,
82+ `Unexpected error attempting to determine if executable file exists` ,
83+ `dri3 extension not supported` ,
84+ `Failed to connect to the bus:` ,
85+ `Checking for beta autoupdate feature for deb/rpm distributions` ,
86+ `Found package-type: deb` ,
87+ `XPC error for connection com.apple.backupd.sandbox.xpc: Connection invalid`
88+ ] ;
89+
8990 try {
9091 exitCode = await new Promise < number > ( ( resolve , reject ) => {
92+ const tasksComplete = 'All Tasks Completed Successfully.' ;
9193 const child = spawn ( executable , execArgs , {
9294 stdio : [ 'ignore' , 'pipe' , 'pipe' ] ,
9395 } ) ;
94-
9596 const sigintHandler = ( ) => child . kill ( 'SIGINT' ) ;
9697 const sigtermHandler = ( ) => child . kill ( 'SIGTERM' ) ;
9798 process . once ( 'SIGINT' , sigintHandler ) ;
9899 process . once ( 'SIGTERM' , sigtermHandler ) ;
100+ function processOutput ( data : Buffer ) {
101+ try {
102+ const chunk = data . toString ( ) ;
103+ let outputLines : string [ ] = [ ] ;
104+ const lines = chunk . split ( '\n' ) ;
105+
106+ for ( const line of lines ) {
107+ if ( line . trim ( ) . length === 0 ||
108+ ignoredLines . some ( ignored => line . includes ( ignored ) ) ) {
109+ continue ;
110+ }
111+
112+ outputLines . push ( line ) ;
113+ }
114+
115+ const outputLine = outputLines . join ( '\n' ) ;
116+ output += `${ outputLine } \n` ;
117+
118+ if ( ! options . silent ) {
119+ process . stdout . write ( `${ outputLine } \n` ) ;
120+ }
121+
122+ if ( output . includes ( tasksComplete ) ) {
123+ child . kill ( 'SIGTERM' ) ;
124+ }
125+ } catch ( error : any ) {
126+ if ( error . code !== 'EPIPE' ) {
127+ throw error ;
128+ }
129+ }
130+ }
99131 child . stdout . on ( 'data' , processOutput ) ;
100132 child . stderr . on ( 'data' , processOutput ) ;
101133 child . on ( 'error' , ( error ) => {
@@ -130,16 +162,6 @@ export class UnityHub {
130162 throw new Error ( `Failed to execute Unity Hub: [${ exitCode } ] ${ errorMessage } ` ) ;
131163 }
132164 }
133-
134- const ignoredLines = [
135- `This error originated either by throwing inside of an async function without a catch block` ,
136- `Unexpected error attempting to determine if executable file exists` ,
137- `dri3 extension not supported` ,
138- `Failed to connect to the bus:` ,
139- `Checking for beta autoupdate feature for deb/rpm distributions` ,
140- `Found package-type: deb` ,
141- `XPC error for connection com.apple.backupd.sandbox.xpc: Connection invalid`
142- ] ;
143165 output = output . split ( '\n' )
144166 . filter ( line => line . trim ( ) . length > 0 )
145167 . filter ( line => ! ignoredLines . some ( ignored => line . includes ( ignored ) ) )
0 commit comments