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: use electron-winstaller instead of self module #8344

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 44 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
87eb7bf
use electron-winstaller
Jul 17, 2024
3a0d1f5
fix ut
Jul 17, 2024
d209266
add nuspecTemplate
Jul 17, 2024
182eea7
custom template.nuspectemplat
Jul 17, 2024
b65450d
add patch for electron-winstaller: change exe to producname
Jul 17, 2024
272b4c8
update wine docker config
Jul 17, 2024
8910083
update snap
Jul 17, 2024
62c9bb5
update snap
Jul 17, 2024
e2d54ff
update wine docker
Jul 17, 2024
74316e3
update dockerfile
Jul 17, 2024
9f1a99a
update dockerimage
Jul 17, 2024
fd017b7
add appId and exe options
Jul 18, 2024
4202527
delete patch
Jul 18, 2024
5170902
change encode
Jul 18, 2024
a4a2f50
update 7zip
Jul 20, 2024
5ffdffd
use [email protected]: update 7zip and nuget
Jul 20, 2024
8e5b9d2
update [email protected]
Jul 20, 2024
6376b95
delete decompress-zip
Jul 20, 2024
006d3cb
remove directory
Jul 20, 2024
8c960cb
delete directory
Jul 20, 2024
b0e6941
update docker file
Jul 20, 2024
4bc85f2
update wine docker config
Jul 20, 2024
463c687
add vender path
Jul 21, 2024
4e5502d
change to getBin
Jul 21, 2024
d9459d9
add sign option
Jul 21, 2024
61c79cb
add shouldSign function
Jul 21, 2024
4d9cb0a
change shouldSign to async/await
Jul 21, 2024
232a90d
add template.nuspectemplate into files
beyondkmp Jul 22, 2024
b26c7a8
add vendorDirectory option
Jul 25, 2024
a5d6bee
Merge branch 'master' into win-installer
Jul 25, 2024
d36fefd
update 7zip arch
Jul 25, 2024
04c50fd
fix 7zip arch
Jul 26, 2024
2fb5700
fix name
Jul 26, 2024
023559f
Merge branch 'master' into win-installer
beyondkmp Nov 1, 2024
253c3aa
delete docker config
beyondkmp Nov 1, 2024
b7ff107
Merge branch 'master' into win-installer
beyondkmp Nov 1, 2024
10931d5
Merge branch 'master' into win-installer
beyondkmp Nov 2, 2024
7733641
use adm-zip to decode
beyondkmp Nov 3, 2024
71b7629
fix sign issue
beyondkmp Nov 3, 2024
be20ec0
delete docker config
beyondkmp Nov 3, 2024
8d7dc91
update docker config
PayneFuRC Nov 5, 2024
d1e4a41
Merge branch 'master' into win-installer
beyondkmp Nov 5, 2024
2bf2205
add changeset
PayneFuRC Nov 5, 2024
d6180f5
delete deb
PayneFuRC Nov 5, 2024
a97660f
Merge branch 'master' into win-installer
beyondkmp Nov 5, 2024
277f958
add comments
PayneFuRC Nov 5, 2024
34fc8eb
update comments
PayneFuRC Nov 5, 2024
4eabc28
Merge branch 'master' into win-installer
beyondkmp Nov 7, 2024
04ce3fd
Merge branch 'master' into win-installer
beyondkmp Nov 11, 2024
8e2086f
update pnpm lock file
beyondkmp Nov 11, 2024
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
6 changes: 6 additions & 0 deletions .changeset/breezy-seas-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"app-builder-lib": patch
"electron-builder-squirrel-windows": patch
---

use electron-winstaller instead of self module
4 changes: 4 additions & 0 deletions docker/wine/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
ARG IMAGE_VERSION=latest
FROM electronuserland/builder:$IMAGE_VERSION


ENV WINEARCH=win64
ENV WINEPREFIX=/root/.wine64

RUN dpkg --add-architecture i386 && \
curl -Lo /usr/share/keyrings/winehq.asc https://dl.winehq.org/wine-builds/winehq.key && \
echo 'deb [signed-by=/usr/share/keyrings/winehq.asc] https://dl.winehq.org/wine-builds/ubuntu/ focal main' > /etc/apt/sources.list.d/winehq.list && \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ export interface SquirrelWindowsOptions extends TargetSpecificOptions {
*/
readonly useAppIdAsId?: boolean

/**
* The custom squirrel.windows.exe path. Defaults to `https://github.com/electron-userland/electron-builder-binaries/tree/master/Squirrel.Windows`.
*/
readonly vendorDirectory?: string

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update doc comment

/**
*  The custom file path to `squirrel.windows.exe` for usage with [electron-winstaller](https://github.com/electron/windows-installer) `vendorDirectory`.
*/

Defaults to https://github.com/electron-userland/electron-builder-binaries/tree/master/Squirrel.Windows

Also, is this true with the current setup? I don't see any default value being set for vendorDirectory. As this is currently coded, it looks like it'll default to the vendor files that come with electron/windows-installer

Copy link
Collaborator Author

@beyondkmp beyondkmp Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

/**
   * The custom squirrel.windows.exe path. If not specified will use the Squirrel.Windows that is shipped with electron-installer(https://github.com/electron/windows-installer/tree/main/vendor).
   * After https://github.com/electron-userland/electron-builder-binaries/pull/56 merged, will add `electron-builder-binaries` to get the latest version of squirrel.
   */

The squirrel windows in this electron-userland/electron-builder-binaries#56 is the same as the one in https://github.com/electron/windows-installer/tree/main/vendor, so when this value is empty, it defaults to using the squirrel windows from windows-installer.

/**
* https://github.com/electron-userland/electron-builder/issues/1743
* @private
Expand Down
6 changes: 3 additions & 3 deletions packages/electron-builder-squirrel-windows/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
"bugs": "https://github.com/electron-userland/electron-builder/issues",
"homepage": "https://github.com/electron-userland/electron-builder",
"files": [
"out"
"out",
"template.nuspectemplate"
],
mmaietta marked this conversation as resolved.
Show resolved Hide resolved
"dependencies": {
"app-builder-lib": "workspace:*",
"archiver": "^5.3.1",
"builder-util": "workspace:*",
"fs-extra": "^10.1.0"
"electron-winstaller":"5.4.0"
},
"devDependencies": {
"@types/archiver": "5.3.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { sanitizeFileName } from "builder-util/out/filename"
import { InvalidConfigurationError, log, isEmptyOrSpaces } from "builder-util"
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"
import { convertVersion, SquirrelBuilder, SquirrelOptions } from "./squirrelPack"
import * as fs from "fs"
import { Options as SquirrelOptions, createWindowsInstaller, convertVersion } from "electron-winstaller"

export default class SquirrelWindowsTarget extends Target {
//tslint:disable-next-line:no-object-literal-type-assertion
Expand All @@ -22,10 +22,7 @@ export default class SquirrelWindowsTarget extends Target {
const version = packager.appInfo.version
const sanitizedName = sanitizeFileName(this.appName)

// tslint:disable-next-line:no-invalid-template-strings
const setupFile = packager.expandArtifactNamePattern(this.options, "exe", arch, "${productName} Setup ${version}.${ext}")
const packageFile = `${sanitizedName}-${convertVersion(version)}-full.nupkg`

const installerOutDir = path.join(this.outDir, `squirrel-windows${getArchSuffix(arch)}`)
const artifactPath = path.join(installerOutDir, setupFile)

Expand All @@ -40,8 +37,15 @@ export default class SquirrelWindowsTarget extends Target {
}

const distOptions = await this.computeEffectiveDistOptions()
const squirrelBuilder = new SquirrelBuilder(distOptions, installerOutDir, packager)
await squirrelBuilder.buildInstaller({ setupFile, packageFile }, appOutDir, this.outDir, arch)
if (distOptions.vendorDirectory) {
this.select7zipArch(distOptions.vendorDirectory, arch)
}

await createWindowsInstaller({
...distOptions,
appDirectory: appOutDir,
outputDirectory: installerOutDir,
})

await packager.info.callArtifactBuildCompleted({
file: artifactPath,
Expand Down Expand Up @@ -79,6 +83,13 @@ export default class SquirrelWindowsTarget extends Target {
return this.options.name || this.packager.appInfo.name
}

private select7zipArch(vendorDirectory: string, arch: Arch) {
// Copy the 7-Zip executable for the configured architecture.
const resolvedArch = getArchSuffix(arch) === "" ? process.arch : getArchSuffix(arch)
fs.copyFileSync(path.join(vendorDirectory, `7z-${resolvedArch}.exe`), path.join(vendorDirectory, "7z.exe"))
fs.copyFileSync(path.join(vendorDirectory, `7z-${resolvedArch}.dll`), path.join(vendorDirectory, "7z.dll"))
}

async computeEffectiveDistOptions(): Promise<SquirrelOptions> {
const packager = this.packager
let iconUrl = this.options.iconUrl
Expand All @@ -98,24 +109,33 @@ export default class SquirrelWindowsTarget extends Target {
const appInfo = packager.appInfo
const projectUrl = await appInfo.computePackageUrl()
const appName = this.appName
const vendorDirectory = this.options.vendorDirectory
const options: SquirrelOptions = {
name: appName,
productName: this.options.name || appInfo.productName,
appId: this.options.useAppIdAsId ? appInfo.id : appName,
version: appInfo.version,
description: appInfo.description,
// better to explicitly set to empty string, to avoid any nugget errors
exe: `${this.packager.platformSpecificBuildOptions.executableName || this.options.name || appInfo.productName}.exe`,
authors: appInfo.companyName || "",
iconUrl,
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 getBinFromUrl("Squirrel.Windows", "1.9.0", "zJHk4CMATM7jHJ2ojRH1n3LkOnaIezDk5FAzJmlSEQSiEdRuB4GGLCegLDtsRCakfHIVfKh3ysJHLjynPkXwhQ=="),
mmaietta marked this conversation as resolved.
Show resolved Hide resolved
vendorDirectory,
nuspecTemplate: path.join(__dirname, "..", "template.nuspectemplate"),
...(this.options as any),
}

if (await (await packager.signingManager.value).cscInfo.value) {
options.windowsSign = {
hookFunction: async (file: string) => {
await packager.sign(file)
},
}
}

if (isEmptyOrSpaces(options.description)) {
options.description = options.productName
options.description = this.options.name || appInfo.productName
}

if (options.remoteToken == null) {
Expand Down
Loading
Loading