diff --git a/.changeset/lovely-colts-hear.md b/.changeset/lovely-colts-hear.md new file mode 100644 index 00000000000..c2ad4851817 --- /dev/null +++ b/.changeset/lovely-colts-hear.md @@ -0,0 +1,5 @@ +--- +"app-builder-lib": patch +--- + +refactor: enabling `getBin` to accept a different repo as a download source (useful for testing) diff --git a/packages/app-builder-lib/src/binDownload.ts b/packages/app-builder-lib/src/binDownload.ts index 9ad96d7284e..ccdb8ebc3d8 100644 --- a/packages/app-builder-lib/src/binDownload.ts +++ b/packages/app-builder-lib/src/binDownload.ts @@ -1,5 +1,6 @@ import { executeAppBuilder } from "builder-util" import { Nullish } from "builder-util-runtime" +import { sanitizeFileName } from "builder-util/out/filename" const versionToPromise = new Map>() @@ -16,41 +17,39 @@ export function getBinFromCustomLoc(name: string, version: string, binariesLocUr return getBin(dirName, binariesLocUrl, checksum) } -export function getBinFromUrl(name: string, version: string, checksum: string): Promise { - const dirName = `${name}-${version}` +export function getBinFromUrl(releaseName: string, filenameWithExt: string, checksum: string, githubOrgRepo = "electron-userland/electron-builder-binaries"): Promise { let url: string if (process.env.ELECTRON_BUILDER_BINARIES_DOWNLOAD_OVERRIDE_URL) { - url = process.env.ELECTRON_BUILDER_BINARIES_DOWNLOAD_OVERRIDE_URL + "/" + dirName + ".7z" + url = process.env.ELECTRON_BUILDER_BINARIES_DOWNLOAD_OVERRIDE_URL + "/" + filenameWithExt } 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/" + `https://github.com/${githubOrgRepo}/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}` + releaseName + url = `${baseUrl}${middleUrl}/${filenameWithExt}` } - return getBin(dirName, url, checksum) + return getBin(releaseName, url, checksum) } export function getBin(name: string, url?: string | null, checksum?: string | null): Promise { // Old cache is ignored if cache environment variable changes - const cacheName = `${process.env.ELECTRON_BUILDER_CACHE}${name}` + const cacheName = sanitizeFileName(`${process.env.ELECTRON_BUILDER_CACHE ?? ""}${name}`) let promise = versionToPromise.get(cacheName) // if rejected, we will try to download again if (promise != null) { return promise } - promise = doGetBin(name, url, checksum) + promise = doGetBin(cacheName, url, checksum) versionToPromise.set(cacheName, promise) return promise } diff --git a/packages/app-builder-lib/src/targets/MsiTarget.ts b/packages/app-builder-lib/src/targets/MsiTarget.ts index 3f26fbc65bd..f33ed503053 100644 --- a/packages/app-builder-lib/src/targets/MsiTarget.ts +++ b/packages/app-builder-lib/src/targets/MsiTarget.ts @@ -86,7 +86,7 @@ export default class MsiTarget extends Target { await packager.info.emitMsiProjectCreated(projectFile) // noinspection SpellCheckingInspection - const vendorPath = await getBinFromUrl("wix", "4.0.0.5512.2", "/X5poahdCc3199Vt6AP7gluTlT1nxi9cbbHhZhCMEu+ngyP1LiBMn+oZX7QAZVaKeBMc2SjVp7fJqNLqsUnPNQ==") + const vendorPath = await getBinFromUrl("wix-4.0.0.5512.2", "wix-4.0.0.5512.2.7z", "/X5poahdCc3199Vt6AP7gluTlT1nxi9cbbHhZhCMEu+ngyP1LiBMn+oZX7QAZVaKeBMc2SjVp7fJqNLqsUnPNQ==") // noinspection SpellCheckingInspection const candleArgs = ["-arch", wixArch === Arch.ia32 ? "x86" : "x64", `-dappDir=${vm.toVmFile(appOutDir)}`].concat(this.getCommonWixArgs()) diff --git a/packages/app-builder-lib/src/targets/nsis/nsisUtil.ts b/packages/app-builder-lib/src/targets/nsis/nsisUtil.ts index 4a7004fa887..f5773bbbaeb 100644 --- a/packages/app-builder-lib/src/targets/nsis/nsisUtil.ts +++ b/packages/app-builder-lib/src/targets/nsis/nsisUtil.ts @@ -33,8 +33,7 @@ export const NSIS_PATH = () => { } } // Warning: Don't use v3.0.4.2 - https://github.com/electron-userland/electron-builder/issues/6334 - // noinspection SpellCheckingInspection - return getBinFromUrl("nsis", "3.0.4.1", "VKMiizYdmNdJOWpRGz4trl4lD++BvYP2irAXpMilheUP0pc93iKlWAoP843Vlraj8YG19CVn0j+dCo/hURz9+Q==") + return getBinFromUrl("nsis-3.0.4.1", "nsis-3.0.4.1.7z", "VKMiizYdmNdJOWpRGz4trl4lD++BvYP2irAXpMilheUP0pc93iKlWAoP843Vlraj8YG19CVn0j+dCo/hURz9+Q==") }) } @@ -44,7 +43,7 @@ export const NSIS_RESOURCES_PATH = () => { const { checksum, url, version } = options.customNsisResources return getBinFromCustomLoc("nsis-resources", version, url, checksum) } - return getBinFromUrl("nsis-resources", "3.4.1", "Dqd6g+2buwwvoG1Vyf6BHR1b+25QMmPcwZx40atOT57gH27rkjOei1L0JTldxZu4NFoEmW4kJgZ3DlSWVON3+Q==") + return getBinFromUrl("nsis-resources-3.4.1", "nsis-resources-3.4.1.7z", "Dqd6g+2buwwvoG1Vyf6BHR1b+25QMmPcwZx40atOT57gH27rkjOei1L0JTldxZu4NFoEmW4kJgZ3DlSWVON3+Q==") }) } diff --git a/packages/app-builder-lib/src/targets/tools.ts b/packages/app-builder-lib/src/targets/tools.ts index 9a12ed5e955..59f4f89e38a 100644 --- a/packages/app-builder-lib/src/targets/tools.ts +++ b/packages/app-builder-lib/src/targets/tools.ts @@ -2,11 +2,13 @@ import * as path from "path" import { getBinFromUrl } from "../binDownload" export function getLinuxToolsPath() { - //noinspection SpellCheckingInspection - return getBinFromUrl("linux-tools", "mac-10.12.3", "SQ8fqIRVXuQVWnVgaMTDWyf2TLAJjJYw3tRSqQJECmgF6qdM7Kogfa6KD49RbGzzMYIFca9Uw3MdsxzOPRWcYw==") + return getBinFromUrl("linux-tools-mac-10.12.3", "linux-tools-mac-10.12.3.7z", "SQ8fqIRVXuQVWnVgaMTDWyf2TLAJjJYw3tRSqQJECmgF6qdM7Kogfa6KD49RbGzzMYIFca9Uw3MdsxzOPRWcYw==") } export async function getFpmPath() { + if (process.env.CUSTOM_FPM_PATH != null) { + return path.resolve(process.env.CUSTOM_FPM_PATH) + } const exec = "fpm" if (process.platform === "win32" || process.env.USE_SYSTEM_FPM === "true") { return exec @@ -21,7 +23,15 @@ export async function getFpmPath() { checksum = "OnzvBdsHE5djcXcAT87rwbnZwS789ZAd2ehuIO42JWtBAHNzXKxV4o/24XFX5No4DJWGO2YSGQttW+zn7d/4rQ==" archSuffix = "-x86" } - return path.join(await getBinFromUrl("fpm", "1.9.3-2.3.1-linux" + archSuffix, checksum), exec) + const fileName = "fpm-1.9.3-2.3.1-linux" + archSuffix + return path.join(await getBinFromUrl(fileName, fileName + ".7z", checksum), exec) } - return path.join(await getBinFromUrl("fpm", "1.9.3-20150715-2.2.2-mac", "oXfq+0H2SbdrbMik07mYloAZ8uHrmf6IJk+Q3P1kwywuZnKTXSaaeZUJNlWoVpRDWNu537YxxpBQWuTcF+6xfw=="), exec) + return path.join( + await getBinFromUrl( + "fpm-1.9.3-20150715-2.2.2-mac", + "fpm-1.9.3-20150715-2.2.2-mac.7z", + "oXfq+0H2SbdrbMik07mYloAZ8uHrmf6IJk+Q3P1kwywuZnKTXSaaeZUJNlWoVpRDWNu537YxxpBQWuTcF+6xfw==" + ), + exec + ) } diff --git a/packages/builder-util/src/log.ts b/packages/builder-util/src/log.ts index 4385813cbc7..9017a965dd6 100644 --- a/packages/builder-util/src/log.ts +++ b/packages/builder-util/src/log.ts @@ -25,7 +25,7 @@ export class Logger { constructor(protected readonly stream: WritableStream) { if (this.shouldDisableNonErrorLoggingVitest) { - this.log(`non-error logging is silenced during VITEST workfloww when DEBUG=electron-builder flag is not set`) + this.log(`non-error logging is silenced during VITEST workflow when DEBUG=electron-builder flag is not set`) } } diff --git a/test/src/binDownloadTest.ts b/test/src/binDownloadTest.ts index 58f0251d8f2..327017d18e3 100644 --- a/test/src/binDownloadTest.ts +++ b/test/src/binDownloadTest.ts @@ -1,29 +1,45 @@ import { getBinFromUrl } from "app-builder-lib/out/binDownload" test("download binary from Github", async ({ expect }) => { - const bin = await getBinFromUrl("linux-tools", "mac-10.12.3", "SQ8fqIRVXuQVWnVgaMTDWyf2TLAJjJYw3tRSqQJECmgF6qdM7Kogfa6KD49RbGzzMYIFca9Uw3MdsxzOPRWcYw==") + const bin = await getBinFromUrl( + "linux-tools-mac-10.12.3", + "linux-tools-mac-10.12.3.7z", + "SQ8fqIRVXuQVWnVgaMTDWyf2TLAJjJYw3tRSqQJECmgF6qdM7Kogfa6KD49RbGzzMYIFca9Uw3MdsxzOPRWcYw==" + ) expect(bin).toBeTruthy() }) test("download binary from Mirror with custom dir", async ({ expect }) => { 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 + const bin = await getBinFromUrl( + "linux-tools-mac-10.12.3", + "linux-tools-mac-10.12.3.7z", + "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 ({ expect }) => { 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 + const bin = await getBinFromUrl( + "linux-tools-mac-10.12.3", + "linux-tools-mac-10.12.3.7z", + "SQ8fqIRVXuQVWnVgaMTDWyf2TLAJjJYw3tRSqQJECmgF6qdM7Kogfa6KD49RbGzzMYIFca9Uw3MdsxzOPRWcYw==" + ) + delete process.env.ELECTRON_BUILDER_BINARIES_MIRROR expect(bin).toBeTruthy() }) test("download binary from Mirror with Url override", async ({ expect }) => { 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 + const bin = await getBinFromUrl( + "linux-tools-mac-10.12.3", + "linux-tools-mac-10.12.3.7z", + "SQ8fqIRVXuQVWnVgaMTDWyf2TLAJjJYw3tRSqQJECmgF6qdM7Kogfa6KD49RbGzzMYIFca9Uw3MdsxzOPRWcYw==" + ) + delete process.env.ELECTRON_BUILDER_BINARIES_DOWNLOAD_OVERRIDE_URL expect(bin).toBeTruthy() }) diff --git a/test/src/linux/debTest.ts b/test/src/linux/debTest.ts index 348858c925f..8e70dbbf4b4 100644 --- a/test/src/linux/debTest.ts +++ b/test/src/linux/debTest.ts @@ -2,9 +2,11 @@ import { Arch, Platform } from "electron-builder" import * as fs from "fs/promises" import { app, execShell, getTarExecutable } from "../helpers/packTester" +const defaultDebTarget = Platform.LINUX.createTarget("deb", Arch.x64) + test.ifNotWindows("deb", ({ expect }) => app(expect, { - targets: Platform.LINUX.createTarget("deb"), + targets: defaultDebTarget, }) ) @@ -12,7 +14,7 @@ test.ifNotWindows("arm", ({ expect }) => app(expect, { targets: Platform.LINUX.c test.ifNotWindows("custom depends", ({ expect }) => app(expect, { - targets: Platform.LINUX.createTarget("deb"), + targets: defaultDebTarget, config: { linux: { executableName: "Boo", @@ -36,7 +38,7 @@ test.ifNotWindows("custom depends", ({ expect }) => test.ifNotWindows("top-level exec name", ({ expect }) => app(expect, { - targets: Platform.LINUX.createTarget("deb"), + targets: defaultDebTarget, config: { productName: "foo", executableName: "Boo", @@ -46,7 +48,7 @@ test.ifNotWindows("top-level exec name", ({ expect }) => test.ifNotWindows("no quotes for safe exec name", ({ expect }) => app(expect, { - targets: Platform.LINUX.createTarget("deb"), + targets: defaultDebTarget, config: { productName: "foo", linux: { @@ -65,7 +67,7 @@ test.ifNotWindows("executable path in postinst script", ({ expect }) => app( expect, { - targets: Platform.LINUX.createTarget("deb"), + targets: defaultDebTarget, config: { productName: "foo", linux: { @@ -90,7 +92,7 @@ test.ifNotWindows("deb file associations", ({ expect }) => app( expect, { - targets: Platform.LINUX.createTarget("deb"), + targets: defaultDebTarget, config: { fileAssociations: [ { diff --git a/test/src/updater/blackboxUpdateTest.ts b/test/src/updater/blackboxUpdateTest.ts index 76d512303de..8e2bef4b277 100644 --- a/test/src/updater/blackboxUpdateTest.ts +++ b/test/src/updater/blackboxUpdateTest.ts @@ -308,7 +308,7 @@ async function runTestWithinServer(doTest: (rootDirectory: string, updateConfigP // Math.random() / Math.random() is used to avoid zero // Math.floor(((Math.random() / Math.random()) * 1000) % 65535) is used to avoid port number collision const port = 8000 + Math.floor(((Math.random() / Math.random()) * 1000) % 65535) - const serverBin = await getBinFromUrl("ran", "0.1.3", "imfA3LtT6umMM0BuQ29MgO3CJ9uleN5zRBi3sXzcTbMOeYZ6SQeN7eKr3kXZikKnVOIwbH+DDO43wkiR/qTdkg==") + const serverBin = await getBinFromUrl("ran-0.1.3", "ran-0.1.3.7z", "imfA3LtT6umMM0BuQ29MgO3CJ9uleN5zRBi3sXzcTbMOeYZ6SQeN7eKr3kXZikKnVOIwbH+DDO43wkiR/qTdkg==") const httpServerProcess = doSpawn(path.join(serverBin, process.platform, "ran"), [`-root=${root}`, `-port=${port}`, "-gzip=false", "-listdir=true"]) const updateConfig = await writeUpdateConfig({ diff --git a/test/src/updater/differentialUpdateTest.ts b/test/src/updater/differentialUpdateTest.ts index d6a3ef91a8c..1cf13b2aaf1 100644 --- a/test/src/updater/differentialUpdateTest.ts +++ b/test/src/updater/differentialUpdateTest.ts @@ -188,7 +188,7 @@ async function testBlockMap(expect: ExpectStatic, oldDir: string, newDir: string ) const port = 8000 + (updaterClass.name.charCodeAt(0) as number) + Math.floor(Math.random() * 10000) - const serverBin = await getBinFromUrl("ran", "0.1.3", "imfA3LtT6umMM0BuQ29MgO3CJ9uleN5zRBi3sXzcTbMOeYZ6SQeN7eKr3kXZikKnVOIwbH+DDO43wkiR/qTdkg==") + const serverBin = await getBinFromUrl("ran-0.1.3", "ran-0.1.3.7z", "imfA3LtT6umMM0BuQ29MgO3CJ9uleN5zRBi3sXzcTbMOeYZ6SQeN7eKr3kXZikKnVOIwbH+DDO43wkiR/qTdkg==") const httpServerProcess = doSpawn(path.join(serverBin, process.platform, "ran"), [`-root=${newDir}`, `-port=${port}`, "-gzip=false", "-listdir=true"]) // Mac uses electron's native autoUpdater to serve updates to, we mock here since electron API isn't available within jest runtime