mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-11-04 07:01:31 +08:00 
			
		
		
		
	feat(nx/desktop): integrate rebuild at monorepo level
This commit is contained in:
		
							parent
							
								
									cf492a5f47
								
							
						
					
					
						commit
						19f6f3352d
					
				@ -19,7 +19,6 @@
 | 
				
			|||||||
    "@triliumnext/server": "workspace:*",
 | 
					    "@triliumnext/server": "workspace:*",
 | 
				
			||||||
    "copy-webpack-plugin": "13.0.0",
 | 
					    "copy-webpack-plugin": "13.0.0",
 | 
				
			||||||
    "electron": "35.2.2",    
 | 
					    "electron": "35.2.2",    
 | 
				
			||||||
    "@electron/rebuild": "4.0.1",
 | 
					 | 
				
			||||||
    "@electron-forge/cli": "7.8.0",
 | 
					    "@electron-forge/cli": "7.8.0",
 | 
				
			||||||
    "@electron-forge/maker-deb": "7.8.0",
 | 
					    "@electron-forge/maker-deb": "7.8.0",
 | 
				
			||||||
    "@electron-forge/maker-dmg": "7.8.0",
 | 
					    "@electron-forge/maker-dmg": "7.8.0",
 | 
				
			||||||
@ -55,12 +54,10 @@
 | 
				
			|||||||
        "cache": true,
 | 
					        "cache": true,
 | 
				
			||||||
        "configurations": {
 | 
					        "configurations": {
 | 
				
			||||||
          "default": {
 | 
					          "default": {
 | 
				
			||||||
            "command": "cross-env DEBUG=* tsx scripts/rebuild.mts",
 | 
					            "command": "cross-env DEBUG=* tsx scripts/electron-rebuild.mts {projectRoot}/dist"
 | 
				
			||||||
            "cwd": "{projectRoot}"
 | 
					 | 
				
			||||||
          },
 | 
					          },
 | 
				
			||||||
          "nixos": {
 | 
					          "nixos": {
 | 
				
			||||||
            "command": "cross-env DEBUG=* tsx scripts/rebuild.mts $(nix-shell -p electron_33 --run \"electron --version\")",
 | 
					            "command": "cross-env DEBUG=* tsx scripts/electron-rebuild.mts {projectRoot}/dist $(nix-shell -p electron_33 --run \"electron --version\")"
 | 
				
			||||||
            "cwd": "{projectRoot}"
 | 
					 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
 | 
				
			|||||||
@ -4,7 +4,6 @@
 | 
				
			|||||||
  "private": true,
 | 
					  "private": true,
 | 
				
			||||||
  "description": "Desktop version of Trilium which imports the demo database (presented to new users at start-up) or the user guide and other documentation and saves the modifications for committing.",
 | 
					  "description": "Desktop version of Trilium which imports the demo database (presented to new users at start-up) or the user guide and other documentation and saves the modifications for committing.",
 | 
				
			||||||
  "devDependencies": {
 | 
					  "devDependencies": {
 | 
				
			||||||
    "@electron/rebuild": "4.0.1",
 | 
					 | 
				
			||||||
    "@triliumnext/client": "workspace:*",
 | 
					    "@triliumnext/client": "workspace:*",
 | 
				
			||||||
    "@triliumnext/desktop": "workspace:*",
 | 
					    "@triliumnext/desktop": "workspace:*",
 | 
				
			||||||
    "@types/fs-extra": "11.0.4",
 | 
					    "@types/fs-extra": "11.0.4",
 | 
				
			||||||
@ -17,17 +16,17 @@
 | 
				
			|||||||
    "targets": {
 | 
					    "targets": {
 | 
				
			||||||
      "rebuild-deps": {
 | 
					      "rebuild-deps": {
 | 
				
			||||||
        "executor": "nx:run-commands",
 | 
					        "executor": "nx:run-commands",
 | 
				
			||||||
        "dependsOn": [ "build" ],
 | 
					        "dependsOn": [
 | 
				
			||||||
 | 
					          "build"
 | 
				
			||||||
 | 
					        ],
 | 
				
			||||||
        "defaultConfiguration": "default",
 | 
					        "defaultConfiguration": "default",
 | 
				
			||||||
        "cache": true,
 | 
					        "cache": true,
 | 
				
			||||||
        "configurations": {
 | 
					        "configurations": {
 | 
				
			||||||
          "default": {
 | 
					          "default": {
 | 
				
			||||||
            "command": "cross-env DEBUG=* tsx scripts/rebuild.mts",
 | 
					            "command": "cross-env DEBUG=* tsx scripts/electron-rebuild.mts {projectRoot}/dist"
 | 
				
			||||||
            "cwd": "{projectRoot}"
 | 
					 | 
				
			||||||
          },
 | 
					          },
 | 
				
			||||||
          "nixos": {
 | 
					          "nixos": {
 | 
				
			||||||
            "command": "electron-rebuild -f -v $(nix-shell -p electron_35 --run \"electron --version\") dist/main.js -m dist",
 | 
					            "command": "cross-env DEBUG=* tsx scripts/electron-rebuild.mts {projectRoot}/dist $(nix-shell -p electron_33 --run \"electron --version\")"
 | 
				
			||||||
            "cwd": "{projectRoot}"
 | 
					 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      },
 | 
					      },
 | 
				
			||||||
 | 
				
			|||||||
@ -1,37 +0,0 @@
 | 
				
			|||||||
/**
 | 
					 | 
				
			||||||
 * @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).
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// TODO: Deduplicate with apps/desktop/scripts/rebuild.ts.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import { fileURLToPath } from "url";
 | 
					 | 
				
			||||||
import { dirname, join } from "path";
 | 
					 | 
				
			||||||
import { rebuild } from "@electron/rebuild"
 | 
					 | 
				
			||||||
import { readFileSync } from "fs";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
const scriptDir = dirname(fileURLToPath(import.meta.url));
 | 
					 | 
				
			||||||
const rootDir = join(scriptDir, "..");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function getElectronVersion() {
 | 
					 | 
				
			||||||
    const packageJsonPath = join(rootDir, "package.json");
 | 
					 | 
				
			||||||
    const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
 | 
					 | 
				
			||||||
    return packageJson.devDependencies.electron;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
function main() {
 | 
					 | 
				
			||||||
    const distDir = join(rootDir, "dist");
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    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,
 | 
					 | 
				
			||||||
        electronVersion: getElectronVersion(),
 | 
					 | 
				
			||||||
    });
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
main();
 | 
					 | 
				
			||||||
@ -25,6 +25,7 @@
 | 
				
			|||||||
  "private": true,
 | 
					  "private": true,
 | 
				
			||||||
  "devDependencies": {
 | 
					  "devDependencies": {
 | 
				
			||||||
    "@eslint/js": "^9.8.0",
 | 
					    "@eslint/js": "^9.8.0",
 | 
				
			||||||
 | 
					    "@electron/rebuild": "4.0.1",
 | 
				
			||||||
    "@nx/devkit": "20.8.1",
 | 
					    "@nx/devkit": "20.8.1",
 | 
				
			||||||
    "@nx/esbuild": "20.8.1",
 | 
					    "@nx/esbuild": "20.8.1",
 | 
				
			||||||
    "@nx/eslint": "20.8.1",
 | 
					    "@nx/eslint": "20.8.1",
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										9
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										9
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							@ -15,6 +15,9 @@ importers:
 | 
				
			|||||||
        specifier: ^4.21.2
 | 
					        specifier: ^4.21.2
 | 
				
			||||||
        version: 4.21.2
 | 
					        version: 4.21.2
 | 
				
			||||||
    devDependencies:
 | 
					    devDependencies:
 | 
				
			||||||
 | 
					      '@electron/rebuild':
 | 
				
			||||||
 | 
					        specifier: 4.0.1
 | 
				
			||||||
 | 
					        version: 4.0.1
 | 
				
			||||||
      '@eslint/js':
 | 
					      '@eslint/js':
 | 
				
			||||||
        specifier: ^9.8.0
 | 
					        specifier: ^9.8.0
 | 
				
			||||||
        version: 9.25.0
 | 
					        version: 9.25.0
 | 
				
			||||||
@ -354,9 +357,6 @@ importers:
 | 
				
			|||||||
      '@electron-forge/plugin-auto-unpack-natives':
 | 
					      '@electron-forge/plugin-auto-unpack-natives':
 | 
				
			||||||
        specifier: 7.8.0
 | 
					        specifier: 7.8.0
 | 
				
			||||||
        version: 7.8.0
 | 
					        version: 7.8.0
 | 
				
			||||||
      '@electron/rebuild':
 | 
					 | 
				
			||||||
        specifier: 4.0.1
 | 
					 | 
				
			||||||
        version: 4.0.1
 | 
					 | 
				
			||||||
      '@triliumnext/server':
 | 
					      '@triliumnext/server':
 | 
				
			||||||
        specifier: workspace:*
 | 
					        specifier: workspace:*
 | 
				
			||||||
        version: link:../server
 | 
					        version: link:../server
 | 
				
			||||||
@ -407,9 +407,6 @@ importers:
 | 
				
			|||||||
        specifier: 7.0.1
 | 
					        specifier: 7.0.1
 | 
				
			||||||
        version: 7.0.1
 | 
					        version: 7.0.1
 | 
				
			||||||
    devDependencies:
 | 
					    devDependencies:
 | 
				
			||||||
      '@electron/rebuild':
 | 
					 | 
				
			||||||
        specifier: 4.0.1
 | 
					 | 
				
			||||||
        version: 4.0.1
 | 
					 | 
				
			||||||
      '@triliumnext/client':
 | 
					      '@triliumnext/client':
 | 
				
			||||||
        specifier: workspace:*
 | 
					        specifier: workspace:*
 | 
				
			||||||
        version: link:../client
 | 
					        version: link:../client
 | 
				
			||||||
 | 
				
			|||||||
@ -6,29 +6,29 @@
 | 
				
			|||||||
 * the server build (and it doesn't expose a CLI option to override this).
 | 
					 * the server build (and it doesn't expose a CLI option to override this).
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { fileURLToPath } from "url";
 | 
					import path, { join } from "path";
 | 
				
			||||||
import { dirname, join } from "path";
 | 
					 | 
				
			||||||
import { rebuild } from "@electron/rebuild"
 | 
					import { rebuild } from "@electron/rebuild"
 | 
				
			||||||
import { readFileSync } from "fs";
 | 
					import { readFileSync } from "fs";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const scriptDir = dirname(fileURLToPath(import.meta.url));
 | 
					function getElectronVersion(distDir: string) {
 | 
				
			||||||
const rootDir = join(scriptDir, "..");
 | 
					    if (process.argv[3]) {
 | 
				
			||||||
 | 
					        return process.argv[3];
 | 
				
			||||||
function getElectronVersion() {
 | 
					 | 
				
			||||||
    if (process.argv[2]) {
 | 
					 | 
				
			||||||
        return process.argv[2];
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const packageJsonPath = join(rootDir, "package.json");
 | 
					    const packageJsonPath = join(distDir, "package.json");
 | 
				
			||||||
    const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
 | 
					    const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
 | 
				
			||||||
    return packageJson.devDependencies.electron;
 | 
					    return packageJson.devDependencies.electron;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function main() {
 | 
					function main() {
 | 
				
			||||||
    const distDir = join(rootDir, "dist");
 | 
					    const distDir = path.resolve(process.argv[2]);
 | 
				
			||||||
    const electronVersion = getElectronVersion();
 | 
					    if (!distDir) {
 | 
				
			||||||
 | 
					        console.error("Missing root dir as argument.");
 | 
				
			||||||
 | 
					        process.exit(1);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    console.log(`Rebuilding with version ${electronVersion}...`);
 | 
					    const electronVersion = getElectronVersion(distDir);
 | 
				
			||||||
 | 
					    console.log(`Rebuilding ${distDir} with version ${electronVersion}...`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    rebuild({
 | 
					    rebuild({
 | 
				
			||||||
        // We force the project root path to avoid electron-rebuild from rebuilding the monorepo-level dependency and breaking the server.
 | 
					        // We force the project root path to avoid electron-rebuild from rebuilding the monorepo-level dependency and breaking the server.
 | 
				
			||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user