Skip to content

Commit

Permalink
fix(electron-updater): Autoupdater problem on mac if space in the URL
Browse files Browse the repository at this point in the history
  • Loading branch information
develar committed Feb 1, 2017
1 parent a2f64bb commit e5d58e2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions .idea/codeStyleSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ export class PublishManager {

if (publishOptions.publish != null && publishOptions.publish !== "never") {
this.isPublish = publishOptions.publish !== "onTag" || getCiTag() != null
if (this.isPublish && !isAuthTokenSet()) {
throw new Error(`Publish is set to ${publishOptions.publish}, but neither GH_TOKEN nor BT_TOKEN is not set`)
}
}
}
else if (publishOptions.publish !== "never") {
log("Current build is a part of pull request, publishing will be skipped")
}

packager.addAfterPackHandler(async event => {
if (!(event.electronPlatformName == "darwin" || event.packager.platform === Platform.WINDOWS)) {
Expand Down Expand Up @@ -264,11 +264,11 @@ function isAuthTokenSet() {
function computeDownloadUrl(publishConfig: PublishConfiguration, fileName: string, version: string) {
if (publishConfig.provider === "generic") {
const baseUrl = url.parse((<GenericServerOptions>publishConfig).url)
return url.format(Object.assign({}, baseUrl, {pathname: path.posix.resolve(baseUrl.pathname || "/", fileName)}))
return url.format(Object.assign({}, baseUrl, {pathname: path.posix.resolve(baseUrl.pathname || "/", encodeURI(fileName))}))
}
else {
const gh = <GithubOptions>publishConfig
return `https://github.com${`/${gh.owner}/${gh.repo}/releases`}/download/v${version}/${fileName}`
return `https://github.com${`/${gh.owner}/${gh.repo}/releases`}/download/v${version}/${encodeURI(fileName)}`
}
}

Expand Down
7 changes: 7 additions & 0 deletions test/out/mac/__snapshots__/macPackagerTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ Array [
]
`;

exports[`test one-package 3`] = `
Object {
"url": "https://develar.s3.amazonaws.com/test/Test%20App%20%C3%9FW-1.1.0-mac.zip",
"version": "1.1.0",
}
`;

exports[`test two-package 1`] = `
Array [
Object {
Expand Down
8 changes: 8 additions & 0 deletions test/src/mac/macPackagerTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { assertPack, platform, app, appThrows } from "../helpers/packTester"
import { Platform, createTargets } from "electron-builder"
import { readJson } from "fs-extra-p"
import { DIR_TARGET } from "electron-builder/out/targets/targetFactory"
import { copyFile } from "electron-builder-util/out/fs"
import * as path from "path"
Expand All @@ -10,6 +11,10 @@ test.ifMac("two-package", () => assertPack("test-app", {targets: createTargets([
test.ifMac("one-package", app({
targets: Platform.MAC.createTarget(),
config: {
publish: {
provider: "generic",
url: "https://develar.s3.amazonaws.com/test",
},
mac: {
fileAssociations: [
{
Expand All @@ -33,6 +38,9 @@ test.ifMac("one-package", app({
expect(info).toMatchSnapshot()
await assertThat(path.join(appDir, "Contents", "Resources", "foo.icns")).isFile()
},
packed: async context => {
expect(await readJson(path.join(context.outDir, "latest-mac.json"))).toMatchSnapshot()
},
}))

test.ifMac("electronDist", appThrows(/ENOENT: no such file or directory/, {
Expand Down
2 changes: 1 addition & 1 deletion test/src/nsisUpdaterTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test("file url generic", async () => {
expect(actualEvents).toMatchSnapshot()
})

test("sha2 mismatch error event", async () => {
test.ifNotCiWin("sha2 mismatch error event", async () => {
const updater = new NsisUpdater()
updater.updateConfigPath = await writeUpdateConfig(<GenericServerOptions>{
provider: "generic",
Expand Down

0 comments on commit e5d58e2

Please sign in to comment.