mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 10:02:59 +08:00
fix(desktop/esbuild): rebuild not working due to lack of package.json
This commit is contained in:
parent
6f8bf58456
commit
2da3d9b1ed
@ -8,23 +8,47 @@
|
|||||||
|
|
||||||
import { join, resolve } from "path";
|
import { join, resolve } from "path";
|
||||||
import { rebuild } from "@electron/rebuild"
|
import { rebuild } from "@electron/rebuild"
|
||||||
import { readFileSync } from "fs";
|
import { readFileSync, rmSync, writeFileSync } from "fs";
|
||||||
|
|
||||||
function getElectronVersion(distDir: string) {
|
const nativeDependencies = [
|
||||||
if (process.argv[3]) {
|
"better-sqlite3"
|
||||||
return process.argv[3];
|
];
|
||||||
}
|
|
||||||
|
|
||||||
const packageJsonPath = join(distDir, "package.json");
|
function parsePackageJson(distDir: string) {
|
||||||
|
const packageJsonPath = join(distDir, "../package.json");
|
||||||
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
||||||
|
let electronVersion: string;
|
||||||
|
|
||||||
const electronVersion = packageJson?.devDependencies?.electron ?? packageJson?.dependencies?.electron;
|
if (process.argv[3]) {
|
||||||
if (!electronVersion) {
|
electronVersion = process.argv[3];
|
||||||
console.error(`Unable to retrieve Electron version in '${resolve(packageJsonPath)}'.`);
|
} else {
|
||||||
process.exit(3);
|
electronVersion = packageJson?.devDependencies?.electron ?? packageJson?.dependencies?.electron;
|
||||||
|
if (!electronVersion) {
|
||||||
|
console.error(`Unable to retrieve Electron version in '${resolve(packageJsonPath)}'.`);
|
||||||
|
process.exit(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
electronVersion,
|
||||||
|
dependencies: packageJson?.dependencies ?? []
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function createFakePackageJson(distPath: string, dependencies: Record<string, string>) {
|
||||||
|
const finalDependencies = {};
|
||||||
|
for (const dep of nativeDependencies) {
|
||||||
|
finalDependencies[dep] = dependencies[dep];
|
||||||
}
|
}
|
||||||
|
|
||||||
return electronVersion;
|
const fakePackageJson = {
|
||||||
|
name: "trilium",
|
||||||
|
version: "1.0.0",
|
||||||
|
main: "index.js",
|
||||||
|
dependencies: finalDependencies,
|
||||||
|
devDependencies: {},
|
||||||
|
};
|
||||||
|
writeFileSync(distPath, JSON.stringify(fakePackageJson, null, 2), "utf-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
@ -34,16 +58,23 @@ function main() {
|
|||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const electronVersion = getElectronVersion(distDir);
|
const { electronVersion, dependencies } = parsePackageJson(distDir);
|
||||||
|
const packageJsonPath = join(distDir, "package.json");
|
||||||
|
createFakePackageJson(packageJsonPath, dependencies);
|
||||||
|
|
||||||
console.log(`Rebuilding ${distDir} with version ${electronVersion}...`);
|
console.log(`Rebuilding ${distDir} with version ${electronVersion}...`);
|
||||||
|
|
||||||
rebuild({
|
try {
|
||||||
// We force the project root path to avoid electron-rebuild from rebuilding the monorepo-level dependency and breaking the server.
|
rebuild({
|
||||||
projectRootPath: distDir,
|
// We force the project root path to avoid electron-rebuild from rebuilding the monorepo-level dependency and breaking the server.
|
||||||
buildPath: distDir,
|
projectRootPath: distDir,
|
||||||
force: true,
|
buildPath: distDir,
|
||||||
electronVersion,
|
force: true,
|
||||||
});
|
electronVersion,
|
||||||
|
});
|
||||||
|
} finally {
|
||||||
|
rmSync(packageJsonPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user