@@ -29,6 +29,17 @@ const WORKSPACE_PACKAGES_TO_VENDOR = {
2929 'unraid-api-plugin-connect' : 'packages/unraid-api-plugin-connect' ,
3030} as const ;
3131
32+ const REPOSITORY_ROOT = resolve ( '..' ) ;
33+
34+ const LOCAL_PATCHED_DEPENDENCIES = [
35+ {
36+ packageName : '@runonflux/nat-upnp' ,
37+ patchPath : join ( REPOSITORY_ROOT , 'patches/@runonflux__nat-upnp@1.0.2.patch' ) ,
38+ validationPath : 'build/src/nat-upnp/client.js' ,
39+ validationMarker : 'No trusted gateway addresses found' ,
40+ } ,
41+ ] as const ;
42+
3243/**
3344 * Packs a workspace package and installs it as a tarball dependency.
3445 */
@@ -49,6 +60,34 @@ const packAndInstallWorkspacePackage = async (pkgName: string, pkgPath: string,
4960 await $ `npm install ${ tarballPattern } ` ;
5061} ;
5162
63+ const applyLocalPatchesToProductionDependencies = async ( ) => {
64+ for ( const dependency of LOCAL_PATCHED_DEPENDENCIES ) {
65+ const dependencyPath = resolve ( 'node_modules' , dependency . packageName ) ;
66+
67+ if ( ! existsSync ( dependencyPath ) ) {
68+ throw new Error ( `Patched dependency ${ dependency . packageName } was not installed` ) ;
69+ }
70+
71+ if ( ! existsSync ( dependency . patchPath ) ) {
72+ throw new Error ( `Patch file not found: ${ dependency . patchPath } ` ) ;
73+ }
74+
75+ console . log ( `Applying local patch to ${ dependency . packageName } ...` ) ;
76+ const reverseCheck =
77+ await $ `GIT_DIR=/dev/null git -C ${ dependencyPath } apply --reverse --check --no-index ${ dependency . patchPath } `
78+ . nothrow ( )
79+ . quiet ( ) ;
80+ if ( reverseCheck . exitCode !== 0 ) {
81+ await $ `GIT_DIR=/dev/null git -C ${ dependencyPath } apply --no-index ${ dependency . patchPath } ` ;
82+ }
83+
84+ const patchedSource = await readFile ( join ( dependencyPath , dependency . validationPath ) , 'utf-8' ) ;
85+ if ( ! patchedSource . includes ( dependency . validationMarker ) ) {
86+ throw new Error ( `Patch validation failed for ${ dependency . packageName } ` ) ;
87+ }
88+ }
89+ } ;
90+
5291/**------------------------------------------------------------------------
5392 * Build Script
5493 *
@@ -138,6 +177,8 @@ try {
138177 }
139178 }
140179
180+ await applyLocalPatchesToProductionDependencies ( ) ;
181+
141182 // Clean the release directory
142183 await $ `rm -rf ../release/*` ;
143184
0 commit comments