Skip to content

Commit

Permalink
feat(nsis): Option to not pack "elevate.exe"
Browse files Browse the repository at this point in the history
Close #1620, Close #1621
  • Loading branch information
MariaDima authored and develar committed Jun 8, 2017
1 parent e700b78 commit 69c3614
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
6 changes: 6 additions & 0 deletions packages/electron-builder/src/options/winOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand Down
14 changes: 9 additions & 5 deletions packages/electron-builder/src/targets/nsis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
19 changes: 18 additions & 1 deletion test/src/helpers/winHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion test/src/windows/installerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand Down Expand Up @@ -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)
}
}))
7 changes: 5 additions & 2 deletions test/src/windows/oneClickInstallerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"])

Expand All @@ -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)
}
}))
Expand Down Expand Up @@ -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)
},
}))
Expand Down

0 comments on commit 69c3614

Please sign in to comment.