| 
									
										
										
										
											2025-05-01 12:45:42 +03:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @module | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This script is used internally by the `rebuild-deps` target of the `desktop`. Normally we could use | 
					
						
							|  |  |  |  * `electron-rebuild` CLI directly, but it would rebuild the monorepo-level dependencies and breaks | 
					
						
							|  |  |  |  * the server build (and it doesn't expose a CLI option to override this). | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-07 08:44:07 +03:00
										 |  |  | import { join, resolve } from "path"; | 
					
						
							| 
									
										
										
										
											2025-05-02 23:24:32 +03:00
										 |  |  | import { rebuild } from "@electron/rebuild" | 
					
						
							| 
									
										
										
										
											2025-05-01 12:45:42 +03:00
										 |  |  | import { readFileSync } from "fs"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-06 09:09:56 +03:00
										 |  |  | function getElectronVersion(distDir: string) { | 
					
						
							|  |  |  |     if (process.argv[3]) { | 
					
						
							|  |  |  |         return process.argv[3]; | 
					
						
							| 
									
										
										
										
											2025-05-05 09:52:26 +03:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-06 09:09:56 +03:00
										 |  |  |     const packageJsonPath = join(distDir, "package.json"); | 
					
						
							| 
									
										
										
										
											2025-05-01 12:45:42 +03:00
										 |  |  |     const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")); | 
					
						
							| 
									
										
										
										
											2025-05-07 09:03:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-07 08:44:07 +03:00
										 |  |  |     const electronVersion = packageJson?.devDependencies?.electron ?? packageJson?.dependencies?.electron; | 
					
						
							|  |  |  |     if (!electronVersion) { | 
					
						
							|  |  |  |         console.error(`Unable to retrieve Electron version in '${resolve(packageJsonPath)}'.`); | 
					
						
							|  |  |  |         process.exit(3); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-07 09:03:54 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return electronVersion; | 
					
						
							| 
									
										
										
										
											2025-05-01 12:45:42 +03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function main() { | 
					
						
							| 
									
										
										
										
											2025-05-07 08:44:07 +03:00
										 |  |  |     const distDir = resolve(process.argv[2]); | 
					
						
							| 
									
										
										
										
											2025-05-06 09:09:56 +03:00
										 |  |  |     if (!distDir) { | 
					
						
							|  |  |  |         console.error("Missing root dir as argument."); | 
					
						
							|  |  |  |         process.exit(1); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2025-05-05 09:52:26 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-06 09:09:56 +03:00
										 |  |  |     const electronVersion = getElectronVersion(distDir); | 
					
						
							|  |  |  |     console.log(`Rebuilding ${distDir} with version ${electronVersion}...`); | 
					
						
							| 
									
										
										
										
											2025-05-01 12:45:42 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  |     rebuild({ | 
					
						
							|  |  |  |         // We force the project root path to avoid electron-rebuild from rebuilding the monorepo-level dependency and breaking the server.
 | 
					
						
							|  |  |  |         projectRootPath: distDir, | 
					
						
							|  |  |  |         buildPath: distDir, | 
					
						
							|  |  |  |         force: true, | 
					
						
							| 
									
										
										
										
											2025-05-05 09:52:26 +03:00
										 |  |  |         electronVersion, | 
					
						
							| 
									
										
										
										
											2025-05-01 12:45:42 +03:00
										 |  |  |     }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | main(); |