@@ -95,20 +95,20 @@ const osxSignConfig =
9595function copyNativeDependency (
9696 dependency : string ,
9797 destinationRoot : string ,
98- ) : void {
98+ ) : boolean {
9999 const source = path . resolve ( "../../node_modules" , dependency ) ;
100100 if ( ! existsSync ( source ) ) {
101101 // Fallback to local node_modules
102102 const localSource = path . resolve ( "node_modules" , dependency ) ;
103103 if ( existsSync ( localSource ) ) {
104104 copySync ( dependency , destinationRoot , localSource ) ;
105- return ;
105+ return true ;
106106 }
107107
108108 console . warn (
109109 `[forge] Native dependency "${ dependency } " not found, skipping copy` ,
110110 ) ;
111- return ;
111+ return false ;
112112 }
113113
114114 const nodeModulesDir = path . join ( destinationRoot , "node_modules" ) ;
@@ -123,6 +123,7 @@ function copyNativeDependency(
123123 destination ,
124124 ) } `,
125125 ) ;
126+ return true ;
126127}
127128
128129function copySync ( dependency : string , destinationRoot : string , source : string ) {
@@ -256,36 +257,50 @@ const config: ForgeConfig = {
256257 postStart : async ( _forgeConfig , child ) => {
257258 electronChild = child ;
258259 } ,
259- packageAfterCopy : async ( _forgeConfig , buildPath ) => {
260- // Resolve the target arch (cross-builds set npm_config_arch); fall back
261- // to the host so non-cross builds keep their existing behavior.
262- const targetArch = process . env . npm_config_arch ?? process . arch ;
263-
260+ packageAfterCopy : async (
261+ _forgeConfig ,
262+ buildPath ,
263+ _electronVersion ,
264+ platform ,
265+ targetArch ,
266+ ) => {
264267 copyNativeDependency ( "node-pty" , buildPath ) ;
265268 copyNativeDependency ( "node-addon-api" , buildPath ) ;
266269 copyNativeDependency ( "@parcel/watcher" , buildPath ) ;
267270
268271 // Platform-specific native dependencies
269- if ( process . platform === "darwin" ) {
272+ if ( platform === "darwin" ) {
270273 const watcherPkg =
271274 targetArch === "x64"
272275 ? "@parcel/watcher-darwin-x64"
273276 : "@parcel/watcher-darwin-arm64" ;
274- copyNativeDependency ( watcherPkg , buildPath ) ;
277+ if ( ! copyNativeDependency ( watcherPkg , buildPath ) ) {
278+ throw new Error (
279+ `[forge] Missing required native dependency "${ watcherPkg } " for darwin-${ targetArch } ` ,
280+ ) ;
281+ }
275282 copyNativeDependency ( "file-icon" , buildPath ) ;
276283 copyNativeDependency ( "p-map" , buildPath ) ;
277- } else if ( process . platform === "win32" ) {
284+ } else if ( platform === "win32" ) {
278285 const watcherPkg =
279286 targetArch === "arm64"
280287 ? "@parcel/watcher-win32-arm64"
281288 : "@parcel/watcher-win32-x64" ;
282- copyNativeDependency ( watcherPkg , buildPath ) ;
283- } else if ( process . platform === "linux" ) {
289+ if ( ! copyNativeDependency ( watcherPkg , buildPath ) ) {
290+ throw new Error (
291+ `[forge] Missing required native dependency "${ watcherPkg } " for win32-${ targetArch } ` ,
292+ ) ;
293+ }
294+ } else if ( platform === "linux" ) {
284295 const watcherPkg =
285296 targetArch === "arm64"
286297 ? "@parcel/watcher-linux-arm64-glibc"
287298 : "@parcel/watcher-linux-x64-glibc" ;
288- copyNativeDependency ( watcherPkg , buildPath ) ;
299+ if ( ! copyNativeDependency ( watcherPkg , buildPath ) ) {
300+ throw new Error (
301+ `[forge] Missing required native dependency "${ watcherPkg } " for linux-${ targetArch } ` ,
302+ ) ;
303+ }
289304 }
290305
291306 // Copy @parcel /watcher's hoisted dependencies
@@ -304,6 +319,16 @@ const config: ForgeConfig = {
304319 copyNativeDependency ( "file-uri-to-path" , buildPath ) ;
305320 copyNativeDependency ( "prebuild-install" , buildPath ) ;
306321 } ,
322+ packageAfterPrune : async ( _forgeConfig , buildPath ) => {
323+ // @parcel /watcher tries @parcel /watcher-{platform}-{arch} first, then
324+ // falls back to build/Release/watcher.node. Remove that fallback from
325+ // release bundles so a host-compiled binary cannot shadow the required
326+ // target-specific optional dependency.
327+ rmSync ( path . join ( buildPath , "node_modules/@parcel/watcher/build" ) , {
328+ recursive : true ,
329+ force : true ,
330+ } ) ;
331+ } ,
307332 } ,
308333 publishers : [
309334 new PublisherGithub ( {
0 commit comments