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

fix: Do not pack "elevate.exe" when not needed #1621

Closed
Closed
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
3 changes: 2 additions & 1 deletion docs/Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ Configuration Options
* <a name="NsisOptions-artifactName"></a>`artifactName` String - The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to `${productName} Setup ${version}.${ext}`.
* <a name="NsisOptions-unicode"></a>`unicode` = `true` Boolean - Whether to create [Unicode installer](http://nsis.sourceforge.net/Docs/Chapter1.html#intro-unicode).
* <a name="NsisOptions-deleteAppDataOnUninstall"></a>`deleteAppDataOnUninstall` = `false` Boolean - *one-click installer only.* Whether to delete app data on uninstall.
* <a name="NsisOptions-doNotPackElevateHelper"></a>`doNotPackElevateHelper` = `false` Boolean - Whether to pack the elevate executable.
* <a name="Config-nsisWeb"></a>`nsisWeb`<a name="NsisWebOptions"></a> - Web Installer specific options.
* <a name="NsisWebOptions-appPackageUrl"></a>`appPackageUrl` String - The application package download URL. Optional — by default computed using publish configuration.

Expand Down Expand Up @@ -341,4 +342,4 @@ Some standard fields should be defined in the `package.json`.
<!-- end of generated block -->

## Build Version Management
`CFBundleVersion` (macOS) and `FileVersion` (Windows) will be set automatically to `version.build_number` on CI server (Travis, AppVeyor, CircleCI and Bamboo supported).
`CFBundleVersion` (macOS) and `FileVersion` (Windows) will be set automatically to `version.build_number` on CI server (Travis, AppVeyor, CircleCI and Bamboo supported).
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
* @default false
*/
readonly doNotPackElevateHelper?: boolean
}

/**
Expand Down
8 changes: 3 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,9 @@ 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),
])
if (this.options.doNotPackElevateHelper !== true) {
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
9 changes: 8 additions & 1 deletion test/src/helpers/winHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { diff, WineManager } from "./wine"

export async function expectUpdateMetadata(context: PackedContext, arch: Arch = Arch.ia32, requireCodeSign: boolean = false): Promise<void> {
const data = safeLoad(await readFile(path.join(context.getResources(Platform.WINDOWS, arch), "app-update.yml"), "utf-8"))

if (requireCodeSign && process.env.CSC_KEY_PASSWORD != null) {
expect(data.publisherName).toEqual(["Developer ID Installer: Vladimir Krivosheev (X8C9Z9L4HW)"])
delete data.publisherName
Expand All @@ -19,7 +20,7 @@ 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 doTest(outDir: string, perUser: boolean, productFilename = "TestApp Setup", name = "TestApp", menuCategory: string | null = null, doNotPackElevateHelper = false) {
if (process.env.DO_WINE !== "true") {
return BluebirdPromise.resolve()
}
Expand Down Expand Up @@ -59,6 +60,12 @@ export async function doTest(outDir: string, perUser: boolean, productFilename =
await assertThat(path.join(startMenuDir, `${productFilename}.lnk`)).isFile()
}

if (doNotPackElevateHelper) {
await assertThat(path.join(instDir, name, "resources", "elevate.exe")).doesNotExist()
} else {
await assertThat(path.join(instDir, name, "resources", "elevate.exe")).isFile()
}

let fsAfter = await listFiles()

let fsChanges = diff(fsBefore, fsAfter, driveC)
Expand Down
3 changes: 2 additions & 1 deletion test/src/windows/oneClickInstallerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ test("one-click", app({
},
nsis: {
deleteAppDataOnUninstall: true,
doNotPackElevateHelper: true
},
}
}, {
signed: true,
packed: async (context) => {
await doTest(context.outDir, true)
await doTest(context.outDir, true, "TestApp Setup", "TestApp", null, true)
await expectUpdateMetadata(context, Arch.ia32, true)
}
}))
Expand Down