From 55ebed1c595e412beb1b027b9414d6f051130937 Mon Sep 17 00:00:00 2001 From: develar Date: Tue, 21 Mar 2017 10:45:45 +0100 Subject: [PATCH] fix: S3 urls on mac Close #1386 --- packages/electron-builder-util/src/util.ts | 9 ++++ packages/electron-builder/src/asarUtil.ts | 2 +- packages/electron-builder/src/packager.ts | 9 +--- .../src/publish/PublishManager.ts | 54 +++++++++---------- .../electron-publisher-s3/src/s3Publisher.ts | 21 ++++---- test/fixtures/test-app-one/package.json | 4 +- test/fixtures/test-app/package.json | 4 +- test/src/BuildTest.ts | 2 +- 8 files changed, 53 insertions(+), 52 deletions(-) diff --git a/packages/electron-builder-util/src/util.ts b/packages/electron-builder-util/src/util.ts index c9beb820411..49a78eba4a2 100644 --- a/packages/electron-builder-util/src/util.ts +++ b/packages/electron-builder-util/src/util.ts @@ -304,4 +304,13 @@ export function isPullRequest() { } return isSet(process.env.TRAVIS_PULL_REQUEST) || isSet(process.env.CI_PULL_REQUEST) || isSet(process.env.CI_PULL_REQUESTS) +} + +export function safeStringifyJson(data: any) { + return JSON.stringify(data, (name, value) => { + if (name.endsWith("Password") || name.endsWith("Token") || name.includes("password") || name.includes("token")) { + return "" + } + return value + }, 2) } \ No newline at end of file diff --git a/packages/electron-builder/src/asarUtil.ts b/packages/electron-builder/src/asarUtil.ts index 2a8863d537f..3d299c4a8a4 100644 --- a/packages/electron-builder/src/asarUtil.ts +++ b/packages/electron-builder/src/asarUtil.ts @@ -233,7 +233,7 @@ export class AsarPackager { private writeAsarFile(files: Array, transformedFiles: Array): Promise { const headerPickle = pickle.createEmpty() - headerPickle.writeString(JSON.stringify(this.fs.header, (name, value) => name === "data" ? undefined : value)) + headerPickle.writeString(JSON.stringify(this.fs.header)) const headerBuf = headerPickle.toBuffer() const sizePickle = pickle.createEmpty() diff --git a/packages/electron-builder/src/packager.ts b/packages/electron-builder/src/packager.ts index 85711b66aeb..fc6572a1707 100644 --- a/packages/electron-builder/src/packager.ts +++ b/packages/electron-builder/src/packager.ts @@ -1,7 +1,7 @@ import BluebirdPromise from "bluebird-lst" import { Arch, Platform, SourceRepositoryInfo, Target } from "electron-builder-core" import { CancellationToken } from "electron-builder-http/out/CancellationToken" -import { computeDefaultAppDirectory, debug, exec, isEmptyOrSpaces, Lazy, use } from "electron-builder-util" +import { computeDefaultAppDirectory, debug, exec, isEmptyOrSpaces, Lazy, safeStringifyJson, use } from "electron-builder-util" import { deepAssign } from "electron-builder-util/out/deepAssign" import { log, warn } from "electron-builder-util/out/log" import { all, executeFinally } from "electron-builder-util/out/promise" @@ -155,12 +155,7 @@ export class Packager implements BuildInfo { this.checkMetadata(appPackageFile, devPackageFile) - debug(`Effective config: ${JSON.stringify(this.config, (name, value) => { - if (name.endsWith("Password") || name.endsWith("Token") || name.includes("password") || name.includes("token")) { - return "" - } - return value - }, 2)}`) + debug(`Effective config: ${safeStringifyJson(this.config)}`) checkConflictingOptions(this.config) this.electronVersion = await getElectronVersion(this.config, projectDir, this.isPrepackedAppAsar ? this.metadata : null) diff --git a/packages/electron-builder/src/publish/PublishManager.ts b/packages/electron-builder/src/publish/PublishManager.ts index 02b69381451..3e013055e18 100644 --- a/packages/electron-builder/src/publish/PublishManager.ts +++ b/packages/electron-builder/src/publish/PublishManager.ts @@ -3,7 +3,7 @@ import { createHash } from "crypto" import { Platform, PlatformSpecificBuildOptions, Target } from "electron-builder-core" import { CancellationToken } from "electron-builder-http/out/CancellationToken" import { BintrayOptions, GenericServerOptions, GithubOptions, githubUrl, PublishConfiguration, PublishProvider, S3Options, s3Url, UpdateInfo, VersionInfo } from "electron-builder-http/out/publishOptions" -import { asArray, debug, isEmptyOrSpaces, isPullRequest } from "electron-builder-util" +import { asArray, debug, isEmptyOrSpaces, isPullRequest, safeStringifyJson } from "electron-builder-util" import { log, warn } from "electron-builder-util/out/log" import { throwError } from "electron-builder-util/out/promise" import { HttpPublisher, PublishContext, Publisher, PublishOptions } from "electron-publish" @@ -87,11 +87,6 @@ export class PublishManager implements PublishContext { } } - const providerClass = requireProviderClass(publishConfig.provider) - if (providerClass != null && providerClass.modifyPublishConfig != null) { - publishConfig = await providerClass.modifyPublishConfig(publishConfig) - } - await writeFile(path.join(packager.getResourcesDir(event.appOutDir), "app-update.yml"), safeDump(publishConfig)) }) @@ -200,7 +195,7 @@ export async function getPublishConfigsForUpdateInfo(packager: PlatformPackager< // default publish config is github, file should be generated regardless of publish state (user can test installer locally or manage the release process manually) const repositoryInfo = await packager.info.repositoryInfo if (repositoryInfo != null && repositoryInfo.type === "github") { - const resolvedPublishConfig = await getResolvedPublishConfig(packager.info, {provider: repositoryInfo.type}, false) + const resolvedPublishConfig = await getResolvedPublishConfig(packager, {provider: repositoryInfo.type}, false) if (resolvedPublishConfig != null) { return [resolvedPublishConfig] } @@ -390,7 +385,7 @@ export async function getPublishConfigs(packager: PlatformPackager, targetS if (serviceName != null) { debug(`Detect ${serviceName} as publish provider`) - return [(await getResolvedPublishConfig(packager.info, {provider: serviceName}))!] + return [(await getResolvedPublishConfig(packager, {provider: serviceName}))!] } } @@ -398,23 +393,8 @@ export async function getPublishConfigs(packager: PlatformPackager, targetS return [] } - debug(`Explicit publish provider: ${JSON.stringify(publishers, null, 2)}`) - return await (>>BluebirdPromise.map(asArray(publishers), it => getResolvedPublishConfig(packager.info, typeof it === "string" ? {provider: it} : it))) - .then(publishConfigs => expandPublishConfigs(packager, publishConfigs)) -} - -function expandPublishConfigs(packager: PlatformPackager, publishConfigs: Array) { - return publishConfigs.map(publishConfig => expandPublishConfig(packager, publishConfig)) -} - -function expandPublishConfig(packager: PlatformPackager, publishConfig: any): PublishConfiguration { - return Object.keys(publishConfig).reduce((expandedPublishConfig: {[key: string]: string}, key) => { - const option = publishConfig[key] - if (option != null) { - expandedPublishConfig[key] = packager.expandMacro(option, null) - } - return expandedPublishConfig - }, {}) + debug(`Explicit publish provider: ${safeStringifyJson(publishers)}`) + return await (>>BluebirdPromise.map(asArray(publishers), it => getResolvedPublishConfig(packager, typeof it === "string" ? {provider: it} : it))) } function sha256(file: string) { @@ -443,7 +423,23 @@ function getCiTag() { return tag != null && tag.length > 0 ? tag : null } -async function getResolvedPublishConfig(packager: BuildInfo, options: PublishConfiguration, errorIfCannot: boolean = true): Promise { +function expandPublishConfig(options: any, packager: PlatformPackager): void { + for (const name of Object.keys(options)) { + const value = options[name] + if (typeof value === "string") { + const expanded = packager.expandMacro(value, null) + if (expanded !== value) { + options[name] = expanded + } + } + } +} + + +async function getResolvedPublishConfig(packager: PlatformPackager, options: PublishConfiguration, errorIfCannot: boolean = true): Promise { + options = Object.assign(Object.create(null), options) + expandPublishConfig(options, packager) + const provider = options.provider if (provider === "generic") { if ((options).url == null) { @@ -453,8 +449,8 @@ async function getResolvedPublishConfig(packager: BuildInfo, options: PublishCon } const providerClass = requireProviderClass(options.provider) - if (providerClass != null && providerClass.checkPublishConfig != null) { - providerClass.checkPublishConfig(options) + if (providerClass != null && providerClass.checkAndResolveOptions != null) { + await providerClass.checkAndResolveOptions(options) return options } @@ -476,7 +472,7 @@ async function getResolvedPublishConfig(packager: BuildInfo, options: PublishCon } async function getInfo() { - const info = await packager.repositoryInfo + const info = await packager.info.repositoryInfo if (info != null) { return info } diff --git a/packages/electron-publisher-s3/src/s3Publisher.ts b/packages/electron-publisher-s3/src/s3Publisher.ts index a2c6a8ef86a..f84c0ab7c93 100644 --- a/packages/electron-publisher-s3/src/s3Publisher.ts +++ b/packages/electron-publisher-s3/src/s3Publisher.ts @@ -24,22 +24,19 @@ export default class S3Publisher extends Publisher { } } - static async modifyPublishConfig(options: S3Options) { - if (options.bucket.includes(".") && options.region == null) { + static async checkAndResolveOptions(options: S3Options) { + const bucket = options.bucket + if (bucket == null) { + throw new Error(`Please specify "bucket" for "s3" update server`) + } + + if (bucket.includes(".") && options.region == null) { // on dotted bucket names, we need to use a path-based endpoint URL. Path-based endpoint URLs need to include the region. - const s3 = new S3({signatureVersion: "v4"}) - const region = (await s3.getBucketLocation({Bucket: options.bucket}).promise()).LocationConstraint - return Object.assign({region: region}, options) + const s3 = new S3({signatureVersion: "v4"}); + (options).region = (await s3.getBucketLocation({Bucket: bucket}).promise()).LocationConstraint } - return options } - static checkPublishConfig(options: S3Options) { - if (options.bucket == null) { - throw new Error(`Please specify "bucket" for "s3" update server`) - } - } - // http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-creating-buckets.html async upload(file: string, safeArtifactName?: string): Promise { const fileName = basename(file) diff --git a/test/fixtures/test-app-one/package.json b/test/fixtures/test-app-one/package.json index fff2adc5867..169703129a6 100755 --- a/test/fixtures/test-app-one/package.json +++ b/test/fixtures/test-app-one/package.json @@ -10,7 +10,6 @@ "build": { "electronVersion": "1.6.3", "appId": "org.electron-builder.testApp", - "iconUrl": "https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico", "compression": "store", "npmRebuild": false, "mac": { @@ -19,6 +18,9 @@ "linux": { "category": "Development", "packageCategory": "devel" + }, + "squirrelWindows": { + "iconUrl": "https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico" } } } \ No newline at end of file diff --git a/test/fixtures/test-app/package.json b/test/fixtures/test-app/package.json index 854368ce136..ab507b32313 100755 --- a/test/fixtures/test-app/package.json +++ b/test/fixtures/test-app/package.json @@ -3,11 +3,13 @@ "build": { "electronVersion": "1.6.3", "appId": "org.electron-builder.testApp", - "iconUrl": "https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico", "compression": "store", "npmRebuild": false, "mac": { "category": "your.app.category.type" + }, + "squirrelWindows": { + "iconUrl": "https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico" } } } diff --git a/test/src/BuildTest.ts b/test/src/BuildTest.ts index 69c41093968..fd9a724391a 100644 --- a/test/src/BuildTest.ts +++ b/test/src/BuildTest.ts @@ -59,7 +59,7 @@ test("cli", async () => { test("build in the app package.json", appTwoThrows(linuxDirTarget, { projectDirCreated: it => modifyPackageJson(it, data => { data.build = { - "iconUrl": "bar", + "productName": "bar", } }, true) }))