Skip to content

Commit 7041b5d

Browse files
committed
feat(nsis): NSIS Web Installer
Close #1207
1 parent 22746bd commit 7041b5d

File tree

9 files changed

+69
-39
lines changed

9 files changed

+69
-39
lines changed

docs/Options.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ Most of the options accept `null` — for example, to explicitly set that DMG ic
3737
* [mac macOS Specific Options](#MacOptions)
3838
* [mas MAS (Mac Application Store) Specific Options](#MasBuildOptions)
3939
* [nsis](#NsisOptions)
40+
* [nsis Web Installer Specific Options](#NsisWebOptions)
4041
* [pkg macOS Product Archive Options](#PkgOptions)
4142
* [protocols URL Protocol Schemes](#Protocol)
4243
* [squirrelWindows](#SquirrelWindowsOptions)
@@ -191,6 +192,13 @@ See [NSIS target notes](https://github.com/electron-userland/electron-builder/wi
191192
| menuCategory | <a name="NsisOptions-menuCategory"></a>Whether to create submenu for start menu shortcut and program files directory. Defaults to `false`. If `true`, company name will be used. Or string value.
192193
| artifactName | <a name="NsisOptions-artifactName"></a>The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to `${productName} Setup ${version}.${ext}`.
193194

195+
<a name="NsisWebOptions"></a>
196+
### `nsis` Web Installer Specific Options
197+
| Name | Description
198+
| --- | ---
199+
| appPackageUrl | <a name="NsisWebOptions-appPackageUrl"></a><p>The application package download URL. Optional — by default computed using publish configuration.</p> <p>URL like <code>https://example.com/download/latest</code> allows web installer to be version independent (installer will download latest application package).</p> <p>Custom <code>X-Arch</code> http header is set to <code>32</code> or <code>64</code>.</p>
200+
| artifactName | <a name="NsisWebOptions-artifactName"></a>The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to `${productName} Web Setup ${version}.${ext}`.
201+
194202
<a name="PkgOptions"></a>
195203
### `pkg` macOS Product Archive Options
196204
| Name | Description
@@ -214,7 +222,7 @@ Please note — on macOS [you need to register an `open-url` event handler](http
214222
<a name="SquirrelWindowsOptions"></a>
215223
### `squirrelWindows`
216224

217-
To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency.
225+
To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency. Squirrel.Windows target is maintained, but deprecated. Please use `nsis` instead.
218226

219227
| Name | Description
220228
| --- | ---

docs/Publishing Artifacts.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ But please consider using automatic rules instead of explicitly specifying `publ
6666

6767
<!-- do not edit. start of generated block -->
6868
* [publish](#PublishConfiguration)
69+
* [publish Amazon S3](#S3Options)
6970
* [publish Bintray](#BintrayOptions)
70-
* [publish Generic (any https server)](#GenericServerOptions)
71+
* [publish Generic (any HTTP(S) server)](#GenericServerOptions)
7172
* [publish GitHub](#GithubOptions)
72-
* [publish S3](#S3Options)
7373

7474
<a name="PublishConfiguration"></a>
7575
### `publish`
@@ -89,6 +89,19 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f
8989
| **provider** | <a name="PublishConfiguration-provider"></a>The provider, one of `github`, `s3`, `bintray`, `generic`.
9090
| owner | <a name="PublishConfiguration-owner"></a>The owner.
9191

92+
<a name="S3Options"></a>
93+
### `publish` Amazon S3
94+
95+
[Getting your credentials](http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/getting-your-credentials.html).
96+
97+
| Name | Description
98+
| --- | ---
99+
| **bucket** | <a name="S3Options-bucket"></a>The bucket name.
100+
| path | <a name="S3Options-path"></a>The directory path. Defaults to `/`.
101+
| channel | <a name="S3Options-channel"></a>The channel. Defaults to `latest`.
102+
| acl | <a name="S3Options-acl"></a>The ACL. Defaults to `public-read`.
103+
| storageClass | <a name="S3Options-storageClass"></a>The type of storage to use for the object. One of `STANDARD`, `REDUCED_REDUNDANCY`, `STANDARD_IA`. Defaults to `STANDARD`.
104+
92105
<a name="BintrayOptions"></a>
93106
### `publish` Bintray
94107
| Name | Description
@@ -98,10 +111,10 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f
98111
| user | <a name="BintrayOptions-user"></a>The Bintray user account. Used in cases where the owner is an organization.
99112

100113
<a name="GenericServerOptions"></a>
101-
### `publish` Generic (any https server)
114+
### `publish` Generic (any HTTP(S) server)
102115
| Name | Description
103116
| --- | ---
104-
| **url** | <a name="GenericServerOptions-url"></a>The base url. e.g. `https://s3.amazonaws.com/bucket_name`. You can use `${os}` (expanded to `mac`, `linux` or `win` according to target platform) and `${arch}` macros.
117+
| **url** | <a name="GenericServerOptions-url"></a>The base url. e.g. `https://bucket_name.s3.amazonaws.com`. You can use `${os}` (expanded to `mac`, `linux` or `win` according to target platform) and `${arch}` macros.
105118
| channel | <a name="GenericServerOptions-channel"></a>The channel. Defaults to `latest`.
106119

107120
<a name="GithubOptions"></a>
@@ -113,17 +126,4 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f
113126
| host | <a name="GithubOptions-host"></a>The host (including the port if need). Defaults to `github.com`.
114127
| protocol | <a name="GithubOptions-protocol"></a><p>The protocol, one of <code>https</code> or <code>http</code>. Defaults to <code>https</code>.</p> <p>GitHub Publisher supports only <code>https</code>.</p>
115128

116-
<a name="S3Options"></a>
117-
### `publish` S3
118-
119-
[Getting your credentials](http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/getting-your-credentials.html).
120-
121-
| Name | Description
122-
| --- | ---
123-
| **bucket** | <a name="S3Options-bucket"></a>The bucket name.
124-
| path | <a name="S3Options-path"></a>The directory path. Defaults to `/`.
125-
| channel | <a name="S3Options-channel"></a>The channel. Defaults to `latest`.
126-
| acl | <a name="S3Options-acl"></a>The ACL. Defaults to `public-read`.
127-
| storageClass | <a name="S3Options-storageClass"></a>The type of storage to use for the object. One of `STANDARD`, `REDUCED_REDUNDANCY`, `STANDARD_IA`. Defaults to `STANDARD`.
128-
129129
<!-- end of generated block -->

packages/electron-builder-http/src/publishOptions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ export interface PublishConfiguration {
3030
}
3131

3232
/*
33-
### `publish` Generic (any https server)
33+
### `publish` Generic (any HTTP(S) server)
3434
*/
3535
export interface GenericServerOptions extends PublishConfiguration {
3636
/*
37-
The base url. e.g. `https://s3.amazonaws.com/bucket_name`. You can use `${os}` (expanded to `mac`, `linux` or `win` according to target platform) and `${arch}` macros.
37+
The base url. e.g. `https://bucket_name.s3.amazonaws.com`. You can use `${os}` (expanded to `mac`, `linux` or `win` according to target platform) and `${arch}` macros.
3838
*/
3939
url: string
4040

@@ -45,7 +45,7 @@ export interface GenericServerOptions extends PublishConfiguration {
4545
}
4646

4747
/*
48-
### `publish` S3
48+
### `publish` Amazon S3
4949
5050
[Getting your credentials](http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/getting-your-credentials.html).
5151
*/
@@ -79,7 +79,7 @@ export interface S3Options extends PublishConfiguration {
7979
}
8080

8181
export function s3Url(options: S3Options) {
82-
let url = `https://s3.amazonaws.com/${options.bucket}`
82+
let url = `https://${options.bucket}.s3.amazonaws.com`
8383
if (options.path != null) {
8484
url += `/${options.path}`
8585
}

packages/electron-builder/src/options/winOptions.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,29 @@ export interface NsisOptions {
152152
readonly artifactName?: string | null
153153
}
154154

155+
/*
156+
### `nsis` Web Installer Specific Options
157+
*/
155158
export interface NsisWebOptions extends NsisOptions {
156159
/*
157160
The application package download URL. Optional — by default computed using publish configuration.
158161
159162
URL like `https://example.com/download/latest` allows web installer to be version independent (installer will download latest application package).
163+
164+
Custom `X-Arch` http header is set to `32` or `64`.
160165
*/
161166
readonly appPackageUrl?: string | null
167+
168+
/*
169+
The [artifact file name pattern](https://github.com/electron-userland/electron-builder/wiki/Options#artifact-file-name-pattern). Defaults to `${productName} Web Setup ${version}.${ext}`.
170+
*/
171+
readonly artifactName?: string | null
162172
}
163173

164174
/*
165175
### `squirrelWindows`
166176
167-
To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency.
177+
To use Squirrel.Windows please install `electron-builder-squirrel-windows` dependency. Squirrel.Windows target is maintained, but deprecated. Please use `nsis` instead.
168178
*/
169179
export interface SquirrelWindowsOptions extends WinBuildOptions {
170180
/*

packages/electron-builder/src/targets/nsis.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export default class NsisTarget extends Target {
8080
const appInfo = packager.appInfo
8181
const version = appInfo.version
8282
const options = this.options
83-
const installerFilename = packager.expandArtifactNamePattern(options, "exe", null, "${productName} Setup ${version}.${ext}")
83+
const installerFilename = packager.expandArtifactNamePattern(options, "exe", null, "${productName} " + (this.isWebInstaller ? "Web " : "") + "Setup ${version}.${ext}")
8484
const iconPath = await packager.getResource(options.installerIcon, "installerIcon.ico") || await packager.getIconPath()
8585
const oneClick = options.oneClick !== false
8686

@@ -134,9 +134,9 @@ export default class NsisTarget extends Target {
134134
throw new Error("Cannot compute app package download URL")
135135
}
136136

137-
computeDownloadUrl(publishConfigs[0], null, packager.appInfo.version, {
137+
appPackageUrl = computeDownloadUrl(publishConfigs[0], null, packager.appInfo.version, {
138138
os: Platform.WINDOWS.buildConfigurationKey,
139-
arch: Arch[Arch.x64]
139+
arch: ""
140140
})
141141

142142
defines.APP_PACKAGE_URL_IS_INCOMLETE = null
@@ -172,7 +172,7 @@ export default class NsisTarget extends Target {
172172
await subTask(`Executing makensis — installer`, this.executeMakensis(defines, commands, true, await this.computeScript(defines, commands, installerPath)))
173173
await packager.sign(installerPath)
174174

175-
packager.dispatchArtifactCreated(installerPath, this, `${packager.appInfo.name}-Setup-${version}.exe`)
175+
packager.dispatchArtifactCreated(installerPath, this, `${packager.appInfo.name}-${this.isWebInstaller ? "Web-" : ""}Setup-${version}.exe`)
176176
}
177177

178178
private get isWebInstaller(): boolean {

packages/electron-builder/templates/nsis/installSection.nsh

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,30 +147,41 @@ SetOutPath $INSTDIR
147147
File /r "${APP_BUILD_DIR}/*.*"
148148
!else
149149
!ifdef APP_PACKAGE_URL
150-
StrCpy $0 "${APP_PACKAGE_URL}"
150+
Var /GLOBAL packageUrl
151+
Var /GLOBAL packageArch
152+
153+
StrCpy $packageUrl "${APP_PACKAGE_URL}"
154+
StrCpy $packageArch "${APP_PACKAGE_URL}"
155+
151156
!ifdef APP_PACKAGE_URL_IS_INCOMLETE
152157
!ifdef APP_64_NAME
153158
!ifdef APP_32_NAME
154159
${if} ${RunningX64}
155-
StrCpy $0 "$0/${APP_64_NAME}"
160+
StrCpy $packageUrl "$packageUrl/${APP_64_NAME}"
156161
${else}
157-
StrCpy $0 "$0/${APP_32_NAME}"
162+
StrCpy $packageUrl "$packageUrl/${APP_32_NAME}"
158163
${endif}
159164
!else
160-
StrCpy $0 "$0/${APP_64_NAME}"
165+
StrCpy $packageUrl "$packageUrl/${APP_64_NAME}"
161166
!endif
162167
!else
163-
StrCpy $0 "$0/${APP_32_NAME}"
168+
StrCpy $packageUrl "$packageUrl/${APP_32_NAME}"
164169
!endif
165170
!endif
166171

172+
${if} ${RunningX64}
173+
StrCpy $packageArch "64"
174+
${else}
175+
StrCpy $packageArch "32"
176+
${endif}
177+
167178
download:
168-
inetc::get /RESUME "$0" "$PLUGINSDIR\package.7z"
169-
pop $0
179+
inetc::get /header "X-Arch: $packageArch" /RESUME "" "$packageUrl" "$PLUGINSDIR\package.7z" /END
180+
Pop $0
170181
${if} $0 == "Cancelled"
171182
quit
172183
${elseif} $0 != "OK"
173-
messagebox MB_RETRYCANCEL|MB_ICONEXCLAMATION "Unable to download application package (status: $0).$\r$\n$\r$\nPlease check you Internet connection and retry." IDRETRY download
184+
Messagebox MB_RETRYCANCEL|MB_ICONEXCLAMATION "Unable to download application package from $packageUrl (status: $0).$\r$\n$\r$\nPlease check you Internet connection and retry." IDRETRY download
174185
quit
175186
${endif}
176187

test/out/windows/__snapshots__/nsisTest.js.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ Object {
112112

113113
exports[`test web installer 1`] = `
114114
Array [
115-
"Test App ßW Setup 1.1.0.exe",
115+
"Test App ßW Web Setup 1.1.0.exe",
116116
"TestApp-1.1.0-x64.nsis.7z",
117117
]
118118
`;
119119

120120
exports[`test web installer 2`] = `
121121
Array [
122-
"TestApp-Setup-1.1.0.exe",
122+
"TestApp-Web-Setup-1.1.0.exe",
123123
]
124124
`;

test/src/helpers/runTests.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ async function runTests() {
9292
args.push(...baseForLinuxTests)
9393
}
9494
else if (circleNodeIndex === 2) {
95-
args.push("snapTest", "nsisUpdaterTest", "linuxArchiveTest")
95+
args.push("snapTest", "nsisUpdaterTest")
9696
}
9797
else {
98-
args.push("windows.*")
98+
args.push("windows.*", "linuxArchiveTest")
9999
}
100100
console.log(`Test files for node ${circleNodeIndex}: ${args.join(", ")}`)
101101
}

test/src/windows/nsisTest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ test.ifDevOrLinuxCi("file associations only perMachine", appThrows(/Please set p
230230
test.ifNotCiMac("web installer", app({
231231
targets: Platform.WINDOWS.createTarget(["nsis-web"], Arch.x64),
232232
config: {
233+
compression: process.env.COMPRESSION || "store",
233234
publish: {
234235
provider: "s3",
235236
bucket: "develar",

0 commit comments

Comments
 (0)