diff --git a/packages/electron-builder/src/options/winOptions.ts b/packages/electron-builder/src/options/winOptions.ts index fae42e16f82..6a6a56a33d4 100644 --- a/packages/electron-builder/src/options/winOptions.ts +++ b/packages/electron-builder/src/options/winOptions.ts @@ -231,6 +231,12 @@ export interface NsisOptions extends CommonNsisOptions, TargetSpecificOptions { * @default false */ readonly deleteAppDataOnUninstall?: boolean + + /** + * Whether to pack the elevate executable (required for electron-updater if per-machine installer used or can be used in the future). Ignored if `perMachine` is set to `true`. + * @default true + */ + readonly packElevateHelper?: boolean } /** diff --git a/packages/electron-builder/src/targets/nsis.ts b/packages/electron-builder/src/targets/nsis.ts index 2f68398bdf4..9b006a8e393 100644 --- a/packages/electron-builder/src/targets/nsis.ts +++ b/packages/electron-builder/src/targets/nsis.ts @@ -13,7 +13,6 @@ import sanitizeFileName from "sanitize-filename" import { v5 as uuid5 } from "uuid-1345" import { NsisOptions, PortableOptions } from "../options/winOptions" import { normalizeExt } from "../platformPackager" -import { getSignVendorPath } from "../windowsCodeSign" import { WinPackager } from "../winPackager" import { archive } from "./archive" import { bundledLanguages, getLicenseFiles, lcid, toLangWithRegion } from "./license" @@ -105,10 +104,15 @@ export class NsisTarget extends Target { /** @private */ async buildAppPackage(appOutDir: string, arch: Arch) { - await BluebirdPromise.all([ - copyFile(path.join(await nsisPathPromise, "elevate.exe"), path.join(appOutDir, "resources", "elevate.exe"), null, false), - copyFile(path.join(await getSignVendorPath(), "windows-10", Arch[arch], "signtool.exe"), path.join(appOutDir, "resources", "signtool.exe"), null, false), - ]) + let isPackElevateHelper = this.options.packElevateHelper + if (isPackElevateHelper === false && this.options.perMachine === true) { + isPackElevateHelper = true + warn("`packElevateHelper = false` is ignored, because `perMachine` is set to `true`") + } + + if (isPackElevateHelper !== false) { + await copyFile(path.join(await nsisPathPromise, "elevate.exe"), path.join(appOutDir, "resources", "elevate.exe"), null, false) + } const packager = this.packager const format = this.options.useZip ? "zip" : "7z" diff --git a/test/src/helpers/winHelper.ts b/test/src/helpers/winHelper.ts index 55ca82a69f5..22c6c1907de 100644 --- a/test/src/helpers/winHelper.ts +++ b/test/src/helpers/winHelper.ts @@ -19,7 +19,17 @@ export async function expectUpdateMetadata(context: PackedContext, arch: Arch = expect(data).toMatchSnapshot() } -export async function doTest(outDir: string, perUser: boolean, productFilename = "TestApp Setup", name = "TestApp", menuCategory: string | null = null) { +export async function checkHelpers(resourceDir: string, packElevateHelper: boolean) { + const elevateHelperExecutable = path.join(resourceDir, "elevate.exe") + if (packElevateHelper) { + await assertThat(elevateHelperExecutable).isFile() + } + else { + await assertThat(elevateHelperExecutable).doesNotExist() + } +} + +export async function doTest(outDir: string, perUser: boolean, productFilename = "TestApp Setup", name = "TestApp", menuCategory: string | null = null, packElevateHelper = true) { if (process.env.DO_WINE !== "true") { return BluebirdPromise.resolve() } @@ -59,6 +69,13 @@ export async function doTest(outDir: string, perUser: boolean, productFilename = await assertThat(path.join(startMenuDir, `${productFilename}.lnk`)).isFile() } + if (packElevateHelper) { + await assertThat(path.join(instDir, name, "resources", "elevate.exe")).isFile() + } + else { + await assertThat(path.join(instDir, name, "resources", "elevate.exe")).doesNotExist() + } + let fsAfter = await listFiles() let fsChanges = diff(fsBefore, fsAfter, driveC) diff --git a/test/src/windows/installerTest.ts b/test/src/windows/installerTest.ts index c61e1944a5b..4ceb1e5897b 100644 --- a/test/src/windows/installerTest.ts +++ b/test/src/windows/installerTest.ts @@ -4,7 +4,7 @@ import { readFile } from "fs-extra-p" import { safeLoad } from "js-yaml" import * as path from "path" import { app, assertPack, copyTestAsset } from "../helpers/packTester" -import { doTest, expectUpdateMetadata } from "../helpers/winHelper" +import { checkHelpers, doTest, expectUpdateMetadata } from "../helpers/winHelper" const nsisTarget = Platform.WINDOWS.createTarget(["nsis"]) @@ -112,6 +112,7 @@ test.ifAll("allowToChangeInstallationDirectory", app({ delete updateInfo.sha512 delete updateInfo.releaseDate expect(updateInfo).toMatchSnapshot() + await checkHelpers(context.getResources(Platform.WINDOWS), true) await doTest(context.outDir, false) } })) \ No newline at end of file diff --git a/test/src/windows/oneClickInstallerTest.ts b/test/src/windows/oneClickInstallerTest.ts index 3e26bcaa655..a12c6893f31 100644 --- a/test/src/windows/oneClickInstallerTest.ts +++ b/test/src/windows/oneClickInstallerTest.ts @@ -5,7 +5,7 @@ import { safeLoad } from "js-yaml" import * as path from "path" import { assertThat } from "../helpers/fileAssert" import { app, appThrows, assertPack, copyTestAsset, modifyPackageJson } from "../helpers/packTester" -import { doTest, expectUpdateMetadata } from "../helpers/winHelper" +import { checkHelpers, doTest, expectUpdateMetadata } from "../helpers/winHelper" const nsisTarget = Platform.WINDOWS.createTarget(["nsis"]) @@ -19,12 +19,14 @@ test("one-click", app({ }, nsis: { deleteAppDataOnUninstall: true, + packElevateHelper: false }, } }, { signed: true, packed: async (context) => { - await doTest(context.outDir, true) + await checkHelpers(context.getResources(Platform.WINDOWS, Arch.ia32), false) + await doTest(context.outDir, true, "TestApp Setup", "TestApp", null, false) await expectUpdateMetadata(context, Arch.ia32, true) } })) @@ -81,6 +83,7 @@ test.ifDevOrLinuxCi("perMachine, no run after finish", app({ delete updateInfo.sha512 delete updateInfo.releaseDate expect(updateInfo).toMatchSnapshot() + await checkHelpers(context.getResources(Platform.WINDOWS, Arch.ia32), true) await doTest(context.outDir, false) }, }))