Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: configurable electron-builder-binaries host #3761

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions packages/app-builder-lib/src/binDownload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,29 @@ export function download(url: string, output: string, checksum?: string | null):
return executeAppBuilder(args) as Promise<any>
}

export function getBinFromGithub(name: string, version: string, checksum: string): Promise<string> {
export function getBinFromUrl(name: string, version: string, checksum: string): Promise<string> {
const dirName = `${name}-${version}`
return getBin(dirName, `https://github.com/electron-userland/electron-builder-binaries/releases/download/${dirName}/${dirName}.7z`, checksum)
let url: string
if (process.env.ELECTRON_BUILDER_BINARIES_DOWNLOAD_OVERRIDE_URL) {
url = process.env.ELECTRON_BUILDER_BINARIES_DOWNLOAD_OVERRIDE_URL + "/" + dirName + ".7z"
}
else {

const baseUrl = process.env.NPM_CONFIG_ELECTRON_BUILDER_BINARIES_MIRROR ||
process.env.npm_config_electron_builder_binaries_mirror ||
process.env.npm_package_config_electron_builder_binaries_mirror ||
process.env.ELECTRON_BUILDER_BINARIES_MIRROR ||
"https://github.com/electron-userland/electron-builder-binaries/releases/download/"
const middleUrl = process.env.NPM_CONFIG_ELECTRON_BUILDER_BINARIES_CUSTOM_DIR ||
process.env.npm_config_electron_builder_binaries_custom_dir ||
process.env.npm_package_config_electron_builder_binaries_custom_dir ||
process.env.ELECTRON_BUILDER_BINARIES_CUSTOM_DIR ||
dirName
const urlSuffix = dirName + ".7z"
url = `${baseUrl}${middleUrl}/${urlSuffix}`
}

return getBin(dirName, url, checksum)
}

export function getBin(name: string, url?: string | null, checksum?: string | null): Promise<string> {
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/targets/MsiTarget.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BluebirdPromise from "bluebird-lst"
import { Arch, log, deepAssign } from "builder-util"
import { UUID } from "builder-util-runtime"
import { getBinFromGithub } from "../binDownload"
import { getBinFromUrl } from "../binDownload"
import { walk } from "builder-util/out/fs"
import { createHash } from "crypto"
import * as ejs from "ejs"
Expand Down Expand Up @@ -71,7 +71,7 @@ export default class MsiTarget extends Target {
}

// noinspection SpellCheckingInspection
const vendorPath = await getBinFromGithub("wix", "4.0.0.5512.2", "/X5poahdCc3199Vt6AP7gluTlT1nxi9cbbHhZhCMEu+ngyP1LiBMn+oZX7QAZVaKeBMc2SjVp7fJqNLqsUnPNQ==")
const vendorPath = await getBinFromUrl("wix", "4.0.0.5512.2", "/X5poahdCc3199Vt6AP7gluTlT1nxi9cbbHhZhCMEu+ngyP1LiBMn+oZX7QAZVaKeBMc2SjVp7fJqNLqsUnPNQ==")

// noinspection SpellCheckingInspection
const candleArgs = [
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/targets/nsis/NsisTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { path7za } from "7zip-bin"
import BluebirdPromise from "bluebird-lst"
import { Arch, asArray, AsyncTaskManager, getPlatformIconFileName, InvalidConfigurationError, log, spawnAndWrite, use, exec } from "builder-util"
import { PackageFileInfo, UUID, CURRENT_APP_PACKAGE_FILE_NAME, CURRENT_APP_INSTALLER_FILE_NAME } from "builder-util-runtime"
import { getBinFromGithub } from "../../binDownload"
import { getBinFromUrl } from "../../binDownload"
import { statOrNull, walk } from "builder-util/out/fs"
import { hashFile } from "../../util/hash"
import _debug from "debug"
Expand Down Expand Up @@ -30,7 +30,7 @@ const debug = _debug("electron-builder:nsis")
const ELECTRON_BUILDER_NS_UUID = UUID.parse("50e065bc-3134-11e6-9bab-38c9862bdaf3")

// noinspection SpellCheckingInspection
const nsisResourcePathPromise = new Lazy(() => getBinFromGithub("nsis-resources", "3.3.0", "4okc98BD0v9xDcSjhPVhAkBMqos+FvD/5/H72fTTIwoHTuWd2WdD7r+1j72hxd+ZXxq1y3FRW0x6Z3jR0VfpMw=="))
const nsisResourcePathPromise = new Lazy(() => getBinFromUrl("nsis-resources", "3.3.0", "4okc98BD0v9xDcSjhPVhAkBMqos+FvD/5/H72fTTIwoHTuWd2WdD7r+1j72hxd+ZXxq1y3FRW0x6Z3jR0VfpMw=="))

const USE_NSIS_BUILT_IN_COMPRESSOR = false

Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/targets/nsis/nsisUtil.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BluebirdPromise from "bluebird-lst"
import { Arch, log } from "builder-util"
import { PackageFileInfo } from "builder-util-runtime"
import { getBinFromGithub } from "../../binDownload"
import { getBinFromUrl } from "../../binDownload"
import { copyFile } from "builder-util/out/fs"
import { unlink } from "fs-extra-p"
import { Lazy } from "lazy-val"
Expand All @@ -17,7 +17,7 @@ export const NSIS_PATH = new Lazy(() => {
return Promise.resolve(custom.trim())
}
// noinspection SpellCheckingInspection
return getBinFromGithub("nsis", "3.0.3.2", "tUrlDPQtbjcooNbTrjUzLupttWlATLDNWqK57TVr+gAt3wkaxFxBS3k80AzEFJbmSeOWrUooO72FFOVGXcoxhA==")
return getBinFromUrl("nsis", "3.0.3.2", "tUrlDPQtbjcooNbTrjUzLupttWlATLDNWqK57TVr+gAt3wkaxFxBS3k80AzEFJbmSeOWrUooO72FFOVGXcoxhA==")
})

export class AppPackageHelper {
Expand Down
4 changes: 2 additions & 2 deletions packages/app-builder-lib/src/targets/tools.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getBin, getBinFromGithub } from "../binDownload"
import { getBin, getBinFromUrl } from "../binDownload"
import { Lazy } from "lazy-val"
import * as path from "path"

export function getLinuxToolsPath() {
//noinspection SpellCheckingInspection
return getBinFromGithub("linux-tools", "mac-10.12.3", "SQ8fqIRVXuQVWnVgaMTDWyf2TLAJjJYw3tRSqQJECmgF6qdM7Kogfa6KD49RbGzzMYIFca9Uw3MdsxzOPRWcYw==")
return getBinFromUrl("linux-tools", "mac-10.12.3", "SQ8fqIRVXuQVWnVgaMTDWyf2TLAJjJYw3tRSqQJECmgF6qdM7Kogfa6KD49RbGzzMYIFca9Uw3MdsxzOPRWcYw==")
}

export const fpmPath = new Lazy(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { InvalidConfigurationError, log } from "builder-util"
import { getBinFromGithub } from "app-builder-lib/out/binDownload"
import { getBinFromUrl } from "app-builder-lib/out/binDownload"
import { Arch, getArchSuffix, SquirrelWindowsOptions, Target } from "app-builder-lib"
import { WinPackager } from "app-builder-lib/out/winPackager"
import * as path from "path"
Expand Down Expand Up @@ -107,7 +107,7 @@ export default class SquirrelWindowsTarget extends Target {
extraMetadataSpecs: projectUrl == null ? null : `\n <projectUrl>${projectUrl}</projectUrl>`,
copyright: appInfo.copyright,
packageCompressionLevel: parseInt((process.env.ELECTRON_BUILDER_COMPRESSION_LEVEL || packager.compression === "store" ? 0 : 9) as any, 10),
vendorPath: await getBinFromGithub("Squirrel.Windows", "1.9.0", "zJHk4CMATM7jHJ2ojRH1n3LkOnaIezDk5FAzJmlSEQSiEdRuB4GGLCegLDtsRCakfHIVfKh3ysJHLjynPkXwhQ=="),
vendorPath: await getBinFromUrl("Squirrel.Windows", "1.9.0", "zJHk4CMATM7jHJ2ojRH1n3LkOnaIezDk5FAzJmlSEQSiEdRuB4GGLCegLDtsRCakfHIVfKh3ysJHLjynPkXwhQ=="),
...this.options as any,
}

Expand Down
29 changes: 29 additions & 0 deletions test/src/binDownloadTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { getBinFromUrl } from "app-builder-lib/out/binDownload"

test("download binary from Github", async () => {
const bin = await getBinFromUrl("linux-tools", "mac-10.12.3", "SQ8fqIRVXuQVWnVgaMTDWyf2TLAJjJYw3tRSqQJECmgF6qdM7Kogfa6KD49RbGzzMYIFca9Uw3MdsxzOPRWcYw==")
expect(bin).toBeTruthy()
})

test("download binary from Mirror with custom dir", async () => {
process.env.ELECTRON_BUILDER_BINARIES_MIRROR = "https://github.com/electron-userland/electron-builder-binaries/releases/download/"
process.env.ELECTRON_BUILDER_BINARIES_CUSTOM_DIR = "linux-tools-mac-10.12.3"
const bin = await getBinFromUrl("linux-tools", "mac-10.12.3", "SQ8fqIRVXuQVWnVgaMTDWyf2TLAJjJYw3tRSqQJECmgF6qdM7Kogfa6KD49RbGzzMYIFca9Uw3MdsxzOPRWcYw==")
delete process.env.ELECTRON_BUILDER_BINARIES_MIRROR
delete process.env.ELECTRON_BUILDER_BINARIES_CUSTOM_DIR
expect(bin).toBeTruthy()
})

test("download binary from Mirror", async () => {
process.env.ELECTRON_BUILDER_BINARIES_MIRROR = "https://github.com/electron-userland/electron-builder-binaries/releases/download/"
const bin = await getBinFromUrl("linux-tools", "mac-10.12.3", "SQ8fqIRVXuQVWnVgaMTDWyf2TLAJjJYw3tRSqQJECmgF6qdM7Kogfa6KD49RbGzzMYIFca9Uw3MdsxzOPRWcYw==")
delete process.env.ELECTRON_BUILDER_BINARIES_MIRROR
expect(bin).toBeTruthy()
})

test("download binary from Mirror with Url override", async () => {
process.env.ELECTRON_BUILDER_BINARIES_DOWNLOAD_OVERRIDE_URL = "https://github.com/electron-userland/electron-builder-binaries/releases/download/linux-tools-mac-10.12.3"
const bin = await getBinFromUrl("linux-tools", "mac-10.12.3", "SQ8fqIRVXuQVWnVgaMTDWyf2TLAJjJYw3tRSqQJECmgF6qdM7Kogfa6KD49RbGzzMYIFca9Uw3MdsxzOPRWcYw==")
delete process.env.ELECTRON_BUILDER_BINARIES_DOWNLOAD_OVERRIDE_URL
expect(bin).toBeTruthy()
})
4 changes: 2 additions & 2 deletions test/src/updater/differentialUpdateTest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BluebirdPromise from "bluebird-lst"
import { doSpawn } from "builder-util"
import { GenericServerOptions, S3Options } from "builder-util-runtime"
import { getBinFromGithub } from "app-builder-lib/out/binDownload"
import { getBinFromUrl } from "app-builder-lib/out/binDownload"
import { Arch, Configuration, Platform } from "electron-builder"
import { AppImageUpdater } from "electron-updater/out/AppImageUpdater"
import { MacUpdater } from "electron-updater/out/MacUpdater"
Expand Down Expand Up @@ -282,7 +282,7 @@ async function testBlockMap(oldDir: string, newDir: string, updaterClass: any, a
const port = 8000 + updaterClass.name.charCodeAt(0) + Math.floor(Math.random() * 10000)

// noinspection SpellCheckingInspection
const httpServerProcess = doSpawn(path.join(await getBinFromGithub("ran", "0.1.3", "imfA3LtT6umMM0BuQ29MgO3CJ9uleN5zRBi3sXzcTbMOeYZ6SQeN7eKr3kXZikKnVOIwbH+DDO43wkiR/qTdkg=="), process.platform, "ran"), [
const httpServerProcess = doSpawn(path.join(await getBinFromUrl("ran", "0.1.3", "imfA3LtT6umMM0BuQ29MgO3CJ9uleN5zRBi3sXzcTbMOeYZ6SQeN7eKr3kXZikKnVOIwbH+DDO43wkiR/qTdkg=="), process.platform, "ran"), [
`-root=${newDir}`,
`-port=${port}`,
"-gzip=false",
Expand Down