Skip to content

Commit

Permalink
fix: S3 urls on mac
Browse files Browse the repository at this point in the history
Close #1386
  • Loading branch information
develar committed Mar 21, 2017
1 parent 3782e34 commit 55ebed1
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 52 deletions.
9 changes: 9 additions & 0 deletions packages/electron-builder-util/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<stripped sensitive data>"
}
return value
}, 2)
}
2 changes: 1 addition & 1 deletion packages/electron-builder/src/asarUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export class AsarPackager {

private writeAsarFile(files: Array<string>, transformedFiles: Array<string | Buffer | null | true>): Promise<any> {
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()
Expand Down
9 changes: 2 additions & 7 deletions packages/electron-builder/src/packager.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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 "<stripped sensitive data>"
}
return value
}, 2)}`)
debug(`Effective config: ${safeStringifyJson(this.config)}`)
checkConflictingOptions(this.config)

this.electronVersion = await getElectronVersion(this.config, projectDir, this.isPrepackedAppAsar ? this.metadata : null)
Expand Down
54 changes: 25 additions & 29 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
})

Expand Down Expand Up @@ -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]
}
Expand Down Expand Up @@ -390,31 +385,16 @@ export async function getPublishConfigs(packager: PlatformPackager<any>, targetS

if (serviceName != null) {
debug(`Detect ${serviceName} as publish provider`)
return [(await getResolvedPublishConfig(packager.info, {provider: serviceName}))!]
return [(await getResolvedPublishConfig(packager, {provider: serviceName}))!]
}
}

if (publishers == null) {
return []
}

debug(`Explicit publish provider: ${JSON.stringify(publishers, null, 2)}`)
return await (<Promise<Array<PublishConfiguration>>>BluebirdPromise.map(asArray(publishers), it => getResolvedPublishConfig(packager.info, typeof it === "string" ? {provider: it} : it)))
.then(publishConfigs => expandPublishConfigs(packager, publishConfigs))
}

function expandPublishConfigs(packager: PlatformPackager<any>, publishConfigs: Array<PublishConfiguration>) {
return publishConfigs.map(publishConfig => expandPublishConfig(packager, publishConfig))
}

function expandPublishConfig(packager: PlatformPackager<any>, publishConfig: any): PublishConfiguration {
return <PublishConfiguration>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 (<Promise<Array<PublishConfiguration>>>BluebirdPromise.map(asArray(publishers), it => getResolvedPublishConfig(packager, typeof it === "string" ? {provider: it} : it)))
}

function sha256(file: string) {
Expand Down Expand Up @@ -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<PublishConfiguration | null> {
function expandPublishConfig(options: any, packager: PlatformPackager<any>): 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<any>, options: PublishConfiguration, errorIfCannot: boolean = true): Promise<PublishConfiguration | null> {
options = Object.assign(Object.create(null), options)
expandPublishConfig(options, packager)

const provider = options.provider
if (provider === "generic") {
if ((<GenericServerOptions>options).url == null) {
Expand All @@ -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
}

Expand All @@ -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
}
Expand Down
21 changes: 9 additions & 12 deletions packages/electron-publisher-s3/src/s3Publisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"});
(<any>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<any> {
const fileName = basename(file)
Expand Down
4 changes: 3 additions & 1 deletion test/fixtures/test-app-one/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -19,6 +18,9 @@
"linux": {
"category": "Development",
"packageCategory": "devel"
},
"squirrelWindows": {
"iconUrl": "https://raw.githubusercontent.com/szwacz/electron-boilerplate/master/resources/windows/icon.ico"
}
}
}
4 changes: 3 additions & 1 deletion test/fixtures/test-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
2 changes: 1 addition & 1 deletion test/src/BuildTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}))
Expand Down

0 comments on commit 55ebed1

Please sign in to comment.