@@ -22,7 +22,7 @@ import { exec } from "child_process";
2222import { Writable } from "stream" ;
2323import { WorkspaceContext } from "../WorkspaceContext" ;
2424import { Version } from "../utilities/version" ;
25- import { execFileStreamOutput } from "../utilities/utilities" ;
25+ import { destructuredPromise , execFileStreamOutput } from "../utilities/utilities" ;
2626import configuration from "../configuration" ;
2727import { FolderContext } from "../FolderContext" ;
2828
@@ -101,28 +101,21 @@ function configureZipArchiver(zipFilePath: string): {
101101 done : Promise < void > ;
102102} {
103103 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 } ,
106107 } ) ;
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 ( ) ;
112112 } ) ;
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 ) ;
122115 reject ( err ) ;
123116 } ) ;
124117 archive . pipe ( output ) ;
125- return { archive, done } ;
118+ return { archive, done : promise } ;
126119}
127120
128121export async function promptForDiagnostics ( ctx : WorkspaceContext ) {
0 commit comments