@@ -22,7 +22,7 @@ import { exec } from "child_process";
22
22
import { Writable } from "stream" ;
23
23
import { WorkspaceContext } from "../WorkspaceContext" ;
24
24
import { Version } from "../utilities/version" ;
25
- import { execFileStreamOutput } from "../utilities/utilities" ;
25
+ import { destructuredPromise , execFileStreamOutput } from "../utilities/utilities" ;
26
26
import configuration from "../configuration" ;
27
27
import { FolderContext } from "../FolderContext" ;
28
28
@@ -101,28 +101,21 @@ function configureZipArchiver(zipFilePath: string): {
101
101
done : Promise < void > ;
102
102
} {
103
103
const output = fs . createWriteStream ( zipFilePath ) ;
104
- const archive = archiver ( "zip" , {
105
- zlib : { level : 9 } , // Maximum compression
104
+ // Create an archive with max compression
105
+ const archive = archiver . create ( "zip" , {
106
+ zlib : { level : 9 } ,
106
107
} ) ;
107
- let resolve : ( ) => void ;
108
- let reject : ( error : unknown ) => void ;
109
- const done = new Promise < void > ( ( res , rej ) => {
110
- resolve = res ;
111
- reject = rej ;
108
+ const { promise, resolve, reject } = destructuredPromise < void > ( ) ;
109
+ output . once ( "close" , ( ) => {
110
+ archive . removeListener ( "error" , reject ) ;
111
+ resolve ( ) ;
112
112
} ) ;
113
- output . on ( "close" , async ( ) => {
114
- try {
115
- resolve ( ) ;
116
- } catch ( error ) {
117
- reject ( error ) ;
118
- }
119
- } ) ;
120
-
121
- archive . on ( "error" , ( err : Error ) => {
113
+ archive . once ( "error" , err => {
114
+ output . removeListener ( "close" , resolve ) ;
122
115
reject ( err ) ;
123
116
} ) ;
124
117
archive . pipe ( output ) ;
125
- return { archive, done } ;
118
+ return { archive, done : promise } ;
126
119
}
127
120
128
121
export async function promptForDiagnostics ( ctx : WorkspaceContext ) {
0 commit comments