@@ -17,7 +17,7 @@ import {
1717} from "@pipelab/plugin-core" ;
1818
1919import { dirname , join , basename , delimiter } from "node:path" ;
20- import { cp , readFile , writeFile , rm } from "node:fs/promises" ;
20+ import { cp , readFile , writeFile , rm , mkdir } from "node:fs/promises" ;
2121import { existsSync } from "node:fs" ;
2222import { platform as osPlatform , arch as osArch } from "node:os" ;
2323import { kebabCase } from "change-case" ;
@@ -570,6 +570,25 @@ export const forge = async (
570570 log ( `Staging build in ${ destinationFolder } ` ) ;
571571
572572 try {
573+ const shimDir = join ( destinationFolder , ".bin" ) ;
574+ await mkdir ( shimDir , { recursive : true } ) ;
575+
576+ const pnpmCjsPath = paths . pnpm ;
577+
578+ // Write pnpm.cmd for Windows support
579+ await writeFile (
580+ join ( shimDir , "pnpm.cmd" ) ,
581+ `@echo off\r\n"${ node } " "${ pnpmCjsPath } " %*\r\n` ,
582+ "utf8" ,
583+ ) ;
584+
585+ // Write pnpm shell script for Unix/Linux/macOS support
586+ await writeFile (
587+ join ( shimDir , "pnpm" ) ,
588+ `#!/bin/sh\nexec "${ node } " "${ pnpmCjsPath } " "$@"\n` ,
589+ { encoding : "utf8" , mode : 0o755 } ,
590+ ) ;
591+
573592 const forge = join (
574593 destinationFolder ,
575594 "node_modules" ,
@@ -786,7 +805,7 @@ export const forge = async (
786805 env : {
787806 DEBUG : completeConfiguration . enableExtraLogging ? "*" : "" ,
788807 ELECTRON_NO_ASAR : "1" ,
789- PATH : `${ dirname ( node ) } ${ delimiter } ${ process . env . PATH } ` ,
808+ PATH : `${ shimDir } ${ delimiter } ${ dirname ( node ) } ${ delimiter } ${ process . env . PATH } ` ,
790809 // DEBUG: "electron-packager"
791810 } ,
792811 cancelSignal : abortSignal ,
@@ -853,6 +872,13 @@ export const forge = async (
853872 e instanceof Error ? `${ e . message } \n${ e . stack } ` : String ( e ) ,
854873 ) ;
855874 }
856- await rm ( destinationFolder , { recursive : true , force : true } ) ;
875+ try {
876+ await rm ( destinationFolder , { recursive : true , force : true } ) ;
877+ } catch ( e ) {
878+ log (
879+ "Failed to clean up staging directory:" ,
880+ e instanceof Error ? `${ e . message } \n${ e . stack } ` : String ( e ) ,
881+ ) ;
882+ }
857883 }
858884} ;
0 commit comments