File tree Expand file tree Collapse file tree 3 files changed +31
-1
lines changed
packages/electron-builder/src/util Expand file tree Collapse file tree 3 files changed +31
-1
lines changed Original file line number Diff line number Diff line change 1
1
import Ajv from "ajv"
2
+ import { CancellationToken } from "electron-builder-http/out/CancellationToken"
2
3
import { debug } from "electron-builder-util"
3
4
import { log , warn } from "electron-builder-util/out/log"
5
+ import { httpExecutor } from "electron-builder-util/out/nodeHttpExecutor"
4
6
import { readFile , readJson } from "fs-extra-p"
5
7
import { safeLoad } from "js-yaml"
6
8
import JSON5 from "json5"
@@ -112,6 +114,20 @@ export async function getElectronVersion(config: Config | null | undefined, proj
112
114
const packageJsonPath = path . join ( projectDir , "package.json" )
113
115
const electronPrebuiltDep = findFromElectronPrebuilt ( projectMetadata || await readJson ( packageJsonPath ) )
114
116
if ( electronPrebuiltDep == null ) {
117
+ try {
118
+ const releaseInfo = await httpExecutor . request < any > ( {
119
+ hostname : "github.com" ,
120
+ path : "/electron/electron/releases/latest" ,
121
+ headers : {
122
+ Accept : "application/json" ,
123
+ } ,
124
+ } , new CancellationToken ( ) )
125
+ return ( releaseInfo . tag_name . startsWith ( "v" ) ) ? releaseInfo . tag_name . substring ( 1 ) : releaseInfo . tag_name
126
+ }
127
+ catch ( e ) {
128
+ warn ( e )
129
+ }
130
+
115
131
throw new Error ( `Cannot find electron dependency to get electron version in the '${ packageJsonPath } '` )
116
132
}
117
133
Original file line number Diff line number Diff line change @@ -79,6 +79,12 @@ Object {
79
79
}
80
80
` ;
81
81
82
+ exports [` retrieve latest electron version 1` ] = `
83
+ Object {
84
+ " linux" : Array [],
85
+ }
86
+ ` ;
87
+
82
88
exports [` scheme validation 1` ] = `
83
89
"Config is invalid:
84
90
{
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import { move, readFile } from "fs-extra-p"
4
4
import { safeLoad } from "js-yaml"
5
5
import * as path from "path"
6
6
import { assertThat } from "./helpers/fileAssert"
7
- import { app , appThrows , assertPack } from "./helpers/packTester"
7
+ import { app , appThrows , assertPack , modifyPackageJson } from "./helpers/packTester"
8
8
import { expectUpdateMetadata } from "./helpers/winHelper"
9
9
10
10
function createBuildResourcesTest ( platform : Platform ) {
@@ -56,6 +56,14 @@ test.ifAll.ifLinuxOrDevMac("prepackaged", app({
56
56
}
57
57
} ) )
58
58
59
+ test . ifAll . ifLinuxOrDevMac ( "retrieve latest electron version" , app ( {
60
+ targets : linuxDirTarget ,
61
+ } , {
62
+ projectDirCreated : projectDir => modifyPackageJson ( projectDir , data => {
63
+ delete data . build . electronVersion
64
+ } ) ,
65
+ } ) )
66
+
59
67
test . ifAll . ifDevOrLinuxCi ( "override targets in the config" , app ( {
60
68
targets : linuxDirTarget ,
61
69
} , {
You can’t perform that action at this time.
0 commit comments