Skip to content

Commit 35bff8c

Browse files
BellezaEmporiumdevelar
authored andcommitted
feat: Make electron-builder compatible with electron-nightly. (#4473)
* Update electronVersion.ts The nightly version of Electron is named "electron-nightly". Therefore, using the actual version, electron-builder cannot find it. This change is to make electron-builder compatible with the nightly builds. * Update package.json Update the 7-zip optional dep with develar's latest build. * Update electronVersion.ts Try #1, dirty but should work * Update electronVersion.ts My bad, sorry. * Update electronVersion.ts ? * Update electronVersion.ts Hmm. * Update electronVersion.ts * Update electronVersion.ts * Update electronVersion.ts * Update electronVersion.ts * Update electronVersion.ts * Update electronVersion.ts * Update electronVersion.ts * Update electronVersion.ts * Update electronVersion.ts * Fixing for test * Updated all deps * Revert "Updated all deps" This reverts commit 76c3d15. * Revert "Update package.json" This reverts commit 18e39fe.
1 parent 0ca2ccc commit 35bff8c

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

packages/app-builder-lib/src/electron/electronVersion.ts

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { getConfig } from "../util/config"
1010

1111
export type MetadataValue = Lazy<{ [key: string]: any } | null>
1212

13-
const electronPackages = ["electron", "electron-prebuilt", "electron-prebuilt-compile"]
13+
const electronPackages = ["electron", "electron-prebuilt", "electron-prebuilt-compile", "electron-nightly"]
1414

1515
export async function getElectronVersion(projectDir: string, config?: Configuration, projectMetadata: MetadataValue = new Lazy(() => orNullIfFileNotExist(readJson(path.join(projectDir, "package.json"))))): Promise<string> {
1616
if (config == null) {
@@ -36,6 +36,20 @@ export async function getElectronVersionFromInstalled(projectDir: string) {
3636
return null
3737
}
3838

39+
export async function getElectronPackage(projectDir: string) {
40+
for (const name of electronPackages) {
41+
try {
42+
return (await readJson(path.join(projectDir, "node_modules", name, "package.json")))
43+
}
44+
catch (e) {
45+
if (e.code !== "ENOENT") {
46+
log.warn({name, error: e}, `cannot find electron in package.json`)
47+
}
48+
}
49+
}
50+
return null
51+
}
52+
3953
/** @internal */
4054
export async function computeElectronVersion(projectDir: string, projectMetadata: MetadataValue): Promise<string> {
4155
const result = await getElectronVersionFromInstalled(projectDir)
@@ -44,8 +58,26 @@ export async function computeElectronVersion(projectDir: string, projectMetadata
4458
}
4559

4660
const electronVersionFromMetadata = findFromPackageMetadata(await projectMetadata!!.value)
61+
const electronPackageName = findFromPackageMetadata(await projectMetadata!!.value)
4762

48-
if (electronVersionFromMetadata === "latest") {
63+
if (electronPackageName === "electron-nightly") {
64+
log.warn("You are using a nightly version of electron, be warned that those builds are highly unstable.")
65+
try {
66+
const releaseInfo = JSON.parse((await httpExecutor.request({
67+
hostname: "github.com",
68+
path: "/electron/nightlies/releases/latest",
69+
headers: {
70+
accept: "application/json",
71+
},
72+
}))!!)
73+
return (releaseInfo.tag_name.startsWith("v")) ? releaseInfo.tag_name.substring(1) : releaseInfo.tag_name
74+
}
75+
catch (e) {
76+
log.warn(e)
77+
}
78+
throw new InvalidConfigurationError(`Cannot find electron in '${path.join(projectDir, "package.json")}'`)
79+
}
80+
else if (electronPackageName === "electron" || electronPackageName === "electron-prebuilt" || electronPackageName === "electron-prebuilt-compile" && electronVersionFromMetadata === "latest") {
4981
log.warn("Electron version is set to \"latest\", but it is recommended to set it to some more restricted version range.")
5082
try {
5183
const releaseInfo = JSON.parse((await httpExecutor.request({
@@ -85,4 +117,4 @@ function findFromPackageMetadata(packageData: any): string | null {
85117
}
86118
}
87119
return null
88-
}
120+
}

0 commit comments

Comments
 (0)