Skip to content

Commit

Permalink
fix(electron-updater): Incorrect comparison of version numbers (elect…
Browse files Browse the repository at this point in the history
…ron-updater)

Close #1488
  • Loading branch information
develar committed Apr 22, 2017
1 parent 19c8ee4 commit 17ac619
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 108 deletions.
25 changes: 25 additions & 0 deletions docs/Home.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
**Basics**

* [[Options]]
* [[Auto Update]]
* [[Code Signing]]
* [[Publishing Artifacts]]
* [[Multi Platform Build]]
* [[NSIS]]
* [[Docker]]
* [[Donations]]

**Tutorials**

* [[Loading App Dependencies Manually]]
* [[Two package.json Structure]]
* [[macOS Kernel Extensions]]

**Programmatic API**

* [[electron-builder]]
* [[electron-builder-core]]
* [[electron-builder-util]]
* [[electron-builder-http]]
* [[electron-publish]]
* [[electron-updater]]
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
"ajv": "^5.0.4-beta.2",
"ajv-keywords": "^2.0.1-beta.2",
"archiver": "^1.3.0",
"aws-sdk": "^2.41.0",
"aws-sdk": "^2.45.0",
"bluebird-lst": "^1.0.2",
"chalk": "^1.1.3",
"chromium-pickle-js": "^0.2.0",
"cuint": "^0.2.2",
"debug": "^2.6.3",
"debug": "^2.6.4",
"electron-download-tf": "4.2.1",
"electron-is-dev": "^0.1.2",
"electron-osx-sign": "0.4.4",
Expand All @@ -50,7 +50,7 @@
"minimatch": "^3.0.3",
"node-emoji": "^1.5.1",
"node-forge": "^0.7.1",
"normalize-package-data": "^2.3.6",
"normalize-package-data": "^2.3.8",
"parse-color": "^1.0.0",
"plist": "^2.0.1",
"sanitize-filename": "^1.6.1",
Expand All @@ -64,10 +64,10 @@
"yargs": "^7.1.0"
},
"devDependencies": {
"@types/electron": "^1.4.35",
"@types/electron": "^1.4.37",
"@types/ini": "^1.3.29",
"@types/jest": "^19.2.2",
"@types/js-yaml": "^3.5.29",
"@types/js-yaml": "^3.5.30",
"@types/node-forge": "^0.6.8",
"@types/source-map-support": "^0.2.28",
"@types/xml2js": "^0.0.33",
Expand All @@ -85,7 +85,7 @@
"globby": "^6.1.0",
"jest-cli": "^19.0.2",
"jest-environment-node-debug": "^2.0.0",
"jest-junit": "^1.4.0",
"jest-junit": "^1.5.1",
"jsdoc-to-markdown": "^3.0.0",
"path-sort": "^0.1.0",
"source-map-support": "^0.4.14",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder-http/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"//": "client can also install js-yaml to load yaml",
"dependencies": {
"debug": "2.6.3",
"debug": "2.6.4",
"fs-extra-p": "^4.1.0"
},
"typings": "./out/electron-builder-http.d.ts"
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"stat-mode": "^0.2.2",
"bluebird-lst": "^1.0.2",
"chalk": "^1.1.3",
"debug": "2.6.3",
"debug": "2.6.4",
"node-emoji": "^1.5.1",
"electron-builder-http": "~0.0.0-semantic-release",
"source-map-support": "^0.4.14",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
"js-yaml": "^3.8.3",
"minimatch": "^3.0.3",
"node-forge": "^0.7.1",
"normalize-package-data": "^2.3.6",
"normalize-package-data": "^2.3.8",
"parse-color": "^1.0.0",
"plist": "^2.0.1",
"sanitize-filename": "^1.6.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import isCi from "is-ci"
import { safeDump } from "js-yaml"
import * as path from "path"
import { prerelease } from "semver"
import { WriteStream as TtyWriteStream } from "tty"
import * as url from "url"
import { Packager } from "../packager"
import { ArtifactCreated, BuildInfo } from "../packagerApi"
Expand All @@ -29,7 +30,7 @@ export class PublishManager implements PublishContext {

private isPublish = false

readonly progress = (<NodeJS.WritableStream>process.stdout).isTTY ? new MultiProgress() : null
readonly progress = (<TtyWriteStream>process.stdout).isTTY ? new MultiProgress() : null

constructor(packager: Packager, private readonly publishOptions: PublishOptions, readonly cancellationToken: CancellationToken) {
if (!isPullRequest()) {
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-publisher-s3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
],
"dependencies": {
"fs-extra-p": "^4.1.0",
"aws-sdk": "^2.41.0",
"aws-sdk": "^2.45.0",
"mime": "^1.3.4",
"electron-publish": "~0.0.0-semantic-release",
"electron-builder-util": "~0.0.0-semantic-release"
Expand Down
10 changes: 7 additions & 3 deletions packages/electron-updater/src/AppUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ export abstract class AppUpdater extends EventEmitter {
throw new Error(`App version is not valid semver version: "${currentVersionString}`)
}

const versionPrereleaseComponent = getVersionPreleaseComponents(this.currentVersion)
this.allowDowngrade = versionPrereleaseComponent != null && versionPrereleaseComponent.length > 0
this.allowDowngrade = hasPrereleaseComponents(this.currentVersion)
this.allowPrerelease = this.allowDowngrade

if (options != null) {
Expand Down Expand Up @@ -196,7 +195,7 @@ export abstract class AppUpdater extends EventEmitter {
throw new Error(`Latest version (from update server) is not valid semver version: "${latestVersion}`)
}

if (this.allowDowngrade ? isVersionsEqual(latestVersion, this.currentVersion) : !isVersionGreaterThan(latestVersion, this.currentVersion)) {
if (this.allowDowngrade && !hasPrereleaseComponents(latestVersion) ? isVersionsEqual(latestVersion, this.currentVersion) : !isVersionGreaterThan(latestVersion, this.currentVersion)) {
this.updateAvailable = false
if (this.logger != null) {
this.logger.info(`Update for version ${this.currentVersion} is not available (latest version: ${versionInfo.version}, downgrade is ${this.allowDowngrade ? "allowed" : "disallowed"}.`)
Expand Down Expand Up @@ -325,4 +324,9 @@ export abstract class AppUpdater extends EventEmitter {
throw new Error(`Unsupported provider: ${provider}`)
}
}
}

function hasPrereleaseComponents(version: string) {
const versionPrereleaseComponent = getVersionPreleaseComponents(version)
return versionPrereleaseComponent != null && versionPrereleaseComponent.length > 0
}
14 changes: 8 additions & 6 deletions test/out/__snapshots__/nsisUpdaterTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Object {

exports[`downgrade (disallowed) 1`] = `undefined`;

exports[`downgrade (disallowed, beta) 1`] = `undefined`;

exports[`file url 1`] = `
Object {
"name": "TestApp Setup 1.1.0.exe",
Expand Down Expand Up @@ -79,19 +81,19 @@ Object {

exports[`file url github pre-release 1`] = `
Object {
"name": "TestApp-Setup-1.1.0.exe",
"name": "TestApp-Setup-1.5.2-beta.3.exe",
"sha2": "f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2",
"url": "https://github.com/develar/__test_nsis_release/releases/download/v1.5.0/TestApp-Setup-1.1.0.exe",
"url": "https://github.com/develar/__test_nsis_release/releases/download/v1.5.2-beta.3/TestApp-Setup-1.5.2-beta.3.exe",
}
`;

exports[`file url github pre-release 2`] = `
Object {
"path": "TestApp Setup 1.1.0.exe",
"releaseName": "1.5.0",
"releaseNotes": "<p>Test pre-release. qefr</p>",
"path": "TestApp Setup 1.5.2-beta.3.exe",
"releaseName": "v1.5.2-beta.3",
"releaseNotes": "No content.",
"sha2": "f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2",
"version": "1.5.0",
"version": "1.5.2-beta.3",
}
`;

Expand Down
81 changes: 36 additions & 45 deletions test/src/nsisUpdaterTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@ if (process.env.ELECTRON_BUILDER_OFFLINE === "true") {

const tmpDir = new TmpDir()

const g = (<any>global)
g.__test_app = {
getVersion: function () {
return "0.0.1"
},
function createTestApp(version: string) {
return {
getVersion: () => version,

getAppPath: function () {
},
getAppPath: function () {
},

on: function () {
// ignored
},
on: function () {
// ignored
},
}
}

const g = (<any>global)
g.__test_app = createTestApp("0.0.1")

process.env.TEST_UPDATER_PLATFORM = "win32"

test("check updates - no versions at all", async () => {
Expand Down Expand Up @@ -66,19 +68,7 @@ async function testUpdateFromBintray(app: any) {
test("file url", () => testUpdateFromBintray(null))

test("downgrade (disallowed)", async () => {
const updater = new NsisUpdater(null, {
getVersion: function () {
return "2.0.0"
},

getAppPath: function () {
},

on: function () {
// ignored
},
}
)
const updater = new NsisUpdater(null, createTestApp("2.0.0"))
updater.updateConfigPath = await writeUpdateConfig(<BintrayOptions>{
provider: "bintray",
owner: "actperepo",
Expand All @@ -100,18 +90,30 @@ test("downgrade (disallowed)", async () => {
expect(actualEvents).toEqual(expectedEvents)
})

test("downgrade (allowed)", () => testUpdateFromBintray({
getVersion: function () {
return "2.0.0-beta.1"
},
test("downgrade (disallowed, beta)", async () => {
const updater = new NsisUpdater(null, createTestApp("1.5.2-beta.4"))
updater.updateConfigPath = await writeUpdateConfig(<GithubOptions>{
provider: "github",
owner: "develar",
repo: "__test_nsis_release",
})

const actualEvents: Array<string> = []
const expectedEvents = ["checking-for-update", "update-not-available"]
for (const eventName of expectedEvents) {
updater.addListener(eventName, () => {
actualEvents.push(eventName)
})
}

const updateCheckResult = await updater.checkForUpdates()
expect(updateCheckResult.fileInfo).toMatchSnapshot()
expect(updateCheckResult.downloadPromise).toBeUndefined()

getAppPath: function () {
},
expect(actualEvents).toEqual(expectedEvents)
})

on: function () {
// ignored
},
}))
test("downgrade (allowed)", () => testUpdateFromBintray(createTestApp("2.0.0-beta.1")))

test("file url generic", async () => {
const updater = new NsisUpdater()
Expand Down Expand Up @@ -210,18 +212,7 @@ test("file url github", async () => {
})

test("file url github pre-release", async () => {
const updater = new NsisUpdater(null, {
getVersion: function () {
return "1.6.0-beta.1"
},

getAppPath: function () {
},

on: function () {
// ignored
},
})
const updater = new NsisUpdater(null, createTestApp("1.5.0-beta.1"))
updater.updateConfigPath = await writeUpdateConfig(<GithubOptions>{
provider: "github",
owner: "develar",
Expand Down
Loading

0 comments on commit 17ac619

Please sign in to comment.