Skip to content

Commit

Permalink
feat: grab latest electron version from github if not specified
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Jun 6, 2017
1 parent 9014d74 commit a826df2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
16 changes: 16 additions & 0 deletions packages/electron-builder/src/util/readPackageJson.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Ajv from "ajv"
import { CancellationToken } from "electron-builder-http/out/CancellationToken"
import { debug } from "electron-builder-util"
import { log, warn } from "electron-builder-util/out/log"
import { httpExecutor } from "electron-builder-util/out/nodeHttpExecutor"
import { readFile, readJson } from "fs-extra-p"
import { safeLoad } from "js-yaml"
import JSON5 from "json5"
Expand Down Expand Up @@ -112,6 +114,20 @@ export async function getElectronVersion(config: Config | null | undefined, proj
const packageJsonPath = path.join(projectDir, "package.json")
const electronPrebuiltDep = findFromElectronPrebuilt(projectMetadata || await readJson(packageJsonPath))
if (electronPrebuiltDep == null) {
try {
const releaseInfo = await httpExecutor.request<any>({
hostname: "github.com",
path: "/electron/electron/releases/latest",
headers: {
Accept: "application/json",
},
}, new CancellationToken())
return (releaseInfo.tag_name.startsWith("v")) ? releaseInfo.tag_name.substring(1) : releaseInfo.tag_name
}
catch (e) {
warn(e)
}

throw new Error(`Cannot find electron dependency to get electron version in the '${packageJsonPath}'`)
}

Expand Down
6 changes: 6 additions & 0 deletions test/out/__snapshots__/ExtraBuildTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ Object {
}
`;

exports[`retrieve latest electron version 1`] = `
Object {
"linux": Array [],
}
`;

exports[`scheme validation 1`] = `
"Config is invalid:
{
Expand Down
10 changes: 9 additions & 1 deletion test/src/ExtraBuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { move, readFile } from "fs-extra-p"
import { safeLoad } from "js-yaml"
import * as path from "path"
import { assertThat } from "./helpers/fileAssert"
import { app, appThrows, assertPack } from "./helpers/packTester"
import { app, appThrows, assertPack, modifyPackageJson } from "./helpers/packTester"
import { expectUpdateMetadata } from "./helpers/winHelper"

function createBuildResourcesTest(platform: Platform) {
Expand Down Expand Up @@ -56,6 +56,14 @@ test.ifAll.ifLinuxOrDevMac("prepackaged", app({
}
}))

test.ifAll.ifLinuxOrDevMac("retrieve latest electron version", app({
targets: linuxDirTarget,
}, {
projectDirCreated: projectDir => modifyPackageJson(projectDir, data => {
delete data.build.electronVersion
}),
}))

test.ifAll.ifDevOrLinuxCi("override targets in the config", app({
targets: linuxDirTarget,
}, {
Expand Down

0 comments on commit a826df2

Please sign in to comment.