@@ -37,13 +37,22 @@ type DoneFunction = (err?: Error) => void;
3737type PromisifiedHookFunction = ( buildPath : string , electronVersion : string , platform : string , arch : string ) => Promise < void > ;
3838type PromisifiedFinalizePackageTargetsHookFunction = ( targets : TargetDefinition [ ] ) => Promise < void > ;
3939
40+ /**
41+ * @deprecated Only use until \@electron/packager publishes a new major version with promise based hooks
42+ */
43+ function hidePromiseFromPromisify < P extends unknown [ ] > ( fn : ( ...args : P ) => Promise < void > ) : ( ...args : P ) => void {
44+ return ( ...args : P ) => {
45+ void fn ( ...args ) ;
46+ } ;
47+ }
48+
4049/**
4150 * Runs given hooks sequentially by mapping them to promises and iterating
4251 * through while awaiting
4352 */
4453function sequentialHooks ( hooks : HookFunction [ ] ) : PromisifiedHookFunction [ ] {
4554 return [
46- async ( buildPath : string , electronVersion : string , platform : string , arch : string , done : DoneFunction ) => {
55+ hidePromiseFromPromisify ( async ( buildPath : string , electronVersion : string , platform : string , arch : string , done : DoneFunction ) => {
4756 for ( const hook of hooks ) {
4857 try {
4958 await promisify ( hook ) ( buildPath , electronVersion , platform , arch ) ;
@@ -53,12 +62,12 @@ function sequentialHooks(hooks: HookFunction[]): PromisifiedHookFunction[] {
5362 }
5463 }
5564 done ( ) ;
56- } ,
65+ } ) ,
5766 ] as PromisifiedHookFunction [ ] ;
5867}
5968function sequentialFinalizePackageTargetsHooks ( hooks : FinalizePackageTargetsHookFunction [ ] ) : PromisifiedFinalizePackageTargetsHookFunction [ ] {
6069 return [
61- async ( targets : TargetDefinition [ ] , done : DoneFunction ) => {
70+ hidePromiseFromPromisify ( async ( targets : TargetDefinition [ ] , done : DoneFunction ) => {
6271 for ( const hook of hooks ) {
6372 try {
6473 await promisify ( hook ) ( targets ) ;
@@ -67,7 +76,7 @@ function sequentialFinalizePackageTargetsHooks(hooks: FinalizePackageTargetsHook
6776 }
6877 }
6978 done ( ) ;
70- } ,
79+ } ) ,
7180 ] as PromisifiedFinalizePackageTargetsHookFunction [ ] ;
7281}
7382
@@ -227,22 +236,22 @@ export const listrPackage = (
227236 const pruneEnabled = ! ( 'prune' in forgeConfig . packagerConfig ) || forgeConfig . packagerConfig . prune ;
228237
229238 const afterCopyHooks : HookFunction [ ] = [
230- async ( buildPath , electronVersion , platform , arch , done ) => {
239+ hidePromiseFromPromisify ( async ( buildPath , electronVersion , platform , arch , done ) => {
231240 signalDone ( signalCopyDone , { platform, arch } ) ;
232241 done ( ) ;
233- } ,
234- async ( buildPath , electronVersion , pPlatform , pArch , done ) => {
242+ } ) ,
243+ hidePromiseFromPromisify ( async ( buildPath , electronVersion , pPlatform , pArch , done ) => {
235244 const bins = await glob ( path . join ( buildPath , '**/.bin/**/*' ) ) ;
236245 for ( const bin of bins ) {
237246 await fs . remove ( bin ) ;
238247 }
239248 done ( ) ;
240- } ,
241- async ( buildPath , electronVersion , pPlatform , pArch , done ) => {
249+ } ) ,
250+ hidePromiseFromPromisify ( async ( buildPath , electronVersion , pPlatform , pArch , done ) => {
242251 await runHook ( forgeConfig , 'packageAfterCopy' , buildPath , electronVersion , pPlatform , pArch ) ;
243252 done ( ) ;
244- } ,
245- async ( buildPath , electronVersion , pPlatform , pArch , done ) => {
253+ } ) ,
254+ hidePromiseFromPromisify ( async ( buildPath , electronVersion , pPlatform , pArch , done ) => {
246255 const targetKey = getTargetKey ( { platform : pPlatform , arch : pArch } ) ;
247256 await listrCompatibleRebuildHook (
248257 buildPath ,
@@ -255,23 +264,23 @@ export const listrPackage = (
255264 ) ;
256265 signalRebuildDone . get ( targetKey ) ?. pop ( ) ?.( ) ;
257266 done ( ) ;
258- } ,
259- async ( buildPath , electronVersion , pPlatform , pArch , done ) => {
267+ } ) ,
268+ hidePromiseFromPromisify ( async ( buildPath , electronVersion , pPlatform , pArch , done ) => {
260269 const copiedPackageJSON = await readMutatedPackageJson ( buildPath , forgeConfig ) ;
261270 if ( copiedPackageJSON . config && copiedPackageJSON . config . forge ) {
262271 delete copiedPackageJSON . config . forge ;
263272 }
264273 await fs . writeJson ( path . resolve ( buildPath , 'package.json' ) , copiedPackageJSON , { spaces : 2 } ) ;
265274 done ( ) ;
266- } ,
275+ } ) ,
267276 ...( await resolveHooks ( forgeConfig . packagerConfig . afterCopy , ctx . dir ) ) ,
268277 ] ;
269278
270279 const afterCompleteHooks : HookFunction [ ] = [
271- async ( buildPath , electronVersion , pPlatform , pArch , done ) => {
280+ hidePromiseFromPromisify ( async ( buildPath , electronVersion , pPlatform , pArch , done ) => {
272281 signalPackageDone . get ( getTargetKey ( { platform : pPlatform , arch : pArch } ) ) ?. pop ( ) ?.( ) ;
273282 done ( ) ;
274- } ,
283+ } ) ,
275284 ...( await resolveHooks ( forgeConfig . packagerConfig . afterComplete , ctx . dir ) ) ,
276285 ] ;
277286
@@ -281,13 +290,15 @@ export const listrPackage = (
281290 afterPruneHooks . push ( ...( await resolveHooks ( forgeConfig . packagerConfig . afterPrune , ctx . dir ) ) ) ;
282291 }
283292
284- afterPruneHooks . push ( ( async ( buildPath , electronVersion , pPlatform , pArch , done ) => {
285- await runHook ( forgeConfig , 'packageAfterPrune' , buildPath , electronVersion , pPlatform , pArch ) ;
286- done ( ) ;
287- } ) as HookFunction ) ;
293+ afterPruneHooks . push (
294+ hidePromiseFromPromisify ( async ( buildPath , electronVersion , pPlatform , pArch , done ) => {
295+ await runHook ( forgeConfig , 'packageAfterPrune' , buildPath , electronVersion , pPlatform , pArch ) ;
296+ done ( ) ;
297+ } ) as HookFunction
298+ ) ;
288299
289300 const afterExtractHooks = [
290- ( async ( buildPath , electronVersion , pPlatform , pArch , done ) => {
301+ hidePromiseFromPromisify ( async ( buildPath , electronVersion , pPlatform , pArch , done ) => {
291302 await runHook ( forgeConfig , 'packageAfterExtract' , buildPath , electronVersion , pPlatform , pArch ) ;
292303 done ( ) ;
293304 } ) as HookFunction ,
0 commit comments