Skip to content

Commit 1bc8d57

Browse files
committed
feat: nsis target for windows by default
BREAKING CHANGE: "nsis" target is default now. Not "squirrel" (Squirrel.Windows) If you have existing app, please set "build.win.target" to "squirrel". Auto-update — please see https://github.com/electron-userland/electron-builder/wiki/Auto-Update
1 parent aa05ac0 commit 1bc8d57

File tree

11 files changed

+48
-42
lines changed

11 files changed

+48
-42
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ _Note: Platform specific `7zip-bin-*` packages are `optionalDependencies`, which
1919

2020
Real project example — [onshape-desktop-shell](https://github.com/develar/onshape-desktop-shell).
2121

22-
Consider to use `nsis` target for Windows ([auto-update](https://github.com/electron-userland/electron-builder/issues/529) will be implemented this month) for new projects.
23-
2422
# Configuration
2523

2624
See [options](https://github.com/electron-userland/electron-builder/wiki/Options) for a full reference but consider following the simple guide outlined below first.

docs/Options.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,9 @@ Don't customize paths to background and icon, — just follow conventions.
8282
| linux | <a name="BuildMetadata-linux"></a>See [.build.linux](#LinuxBuildOptions).
8383
| compression | <a name="BuildMetadata-compression"></a>The compression level, one of `store`, `normal`, `maximum` (default: `normal`). If you want to rapidly test build, `store` can reduce build time significantly.
8484
| afterPack | <a name="BuildMetadata-afterPack"></a>*programmatic API only* The function to be run after pack (but before pack into distributable format and sign). Promise must be returned.
85-
| npmRebuild | <a name="BuildMetadata-npmRebuild"></a>*two package.json structure only* Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.
86-
| npmSkipBuildFromSource | <a name="BuildMetadata-npmSkipBuildFromSource"></a>*two package.json structure only* Whether to omit using [--build-from-source](https://github.com/mapbox/node-pre-gyp#options) flag when installing app native deps. Defaults to `false`.
87-
| npmArgs | <a name="BuildMetadata-npmArgs"></a>*two package.json structure only* Additional command line arguments to use when installing app native deps. Defaults to `null`.
85+
| npmRebuild | <a name="BuildMetadata-npmRebuild"></a>Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.
86+
| npmSkipBuildFromSource | <a name="BuildMetadata-npmSkipBuildFromSource"></a>Whether to omit using [--build-from-source](https://github.com/mapbox/node-pre-gyp#options) flag when installing app native deps. Defaults to `false`.
87+
| npmArgs | <a name="BuildMetadata-npmArgs"></a>Additional command line arguments to use when installing app native deps. Defaults to `null`.
8888
| nodeGypRebuild | <a name="BuildMetadata-nodeGypRebuild"></a>Whether to execute `node-gyp rebuild` before starting to package the app. Defaults to `false`.
8989
| electronDist | <a name="BuildMetadata-electronDist"></a>The path to custom Electron build (e.g. `~/electron/out/R`). Only macOS supported, file issue if need for Linux or Windows.
9090
| publish | <a name="BuildMetadata-publish"></a>See [.build.publish](#PublishConfiguration).
@@ -255,9 +255,9 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f
255255
| --- | ---
256256
| iconUrl | <a name="SquirrelWindowsOptions-iconUrl"></a><p>A URL to an ICO file to use as the application icon (displayed in Control Panel &gt; Programs and Features). Defaults to the Electron icon.</p> <p>Please note — [local icon file url is not accepted](https://github.com/atom/grunt-electron-installer/issues/73), must be https/http.</p> <ul> <li>If you don’t plan to build windows installer, you can omit it.</li> <li>If your project repository is public on GitHub, it will be <code>https://github.com/${u}/${p}/blob/master/build/icon.ico?raw=true</code> by default.</li> </ul>
257257
| loadingGif | <a name="SquirrelWindowsOptions-loadingGif"></a><p>The path to a .gif file to display during install. <code>build/install-spinner.gif</code> will be used if exists (it is a recommended way to set) (otherwise [default](https://github.com/electron/windows-installer/blob/master/resources/install-spinner.gif)).</p>
258-
| msi | <a name="SquirrelWindowsOptions-msi"></a>*Squirrel.Windows-only.* Whether to create an MSI installer. Defaults to `false` (MSI is not created).
259-
| remoteReleases | <a name="SquirrelWindowsOptions-remoteReleases"></a>*Squirrel.Windows-only.* A URL to your existing updates. Or `true` to automatically set to your GitHub repository. If given, these will be downloaded to create delta updates.
260-
| remoteToken | <a name="SquirrelWindowsOptions-remoteToken"></a>*Squirrel.Windows-only.* Authentication token for remote updates
258+
| msi | <a name="SquirrelWindowsOptions-msi"></a>Whether to create an MSI installer. Defaults to `false` (MSI is not created).
259+
| remoteReleases | <a name="SquirrelWindowsOptions-remoteReleases"></a>A URL to your existing updates. Or `true` to automatically set to your GitHub repository. If given, these will be downloaded to create delta updates.
260+
| remoteToken | <a name="SquirrelWindowsOptions-remoteToken"></a>Authentication token for remote updates
261261
| useAppIdAsId | <a name="SquirrelWindowsOptions-useAppIdAsId"></a>Use `appId` to identify package instead of `name`.
262262

263263
<a name="WinBuildOptions"></a>
@@ -267,7 +267,7 @@ Windows specific build options.
267267

268268
| Name | Description
269269
| --- | ---
270-
| target | <a name="WinBuildOptions-target"></a>Target package type: list of `nsis`, `squirrel`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `squirrel`.
270+
| target | <a name="WinBuildOptions-target"></a>Target package type: list of `nsis`, `squirrel`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `nsis`.
271271
| signingHashAlgorithms | <a name="WinBuildOptions-signingHashAlgorithms"></a>Array of signing algorithms used. Defaults to `['sha1', 'sha256']`
272272
| icon | <a name="WinBuildOptions-icon"></a>The path to application icon. Defaults to `build/icon.ico` (consider using this convention instead of complicating your configuration).
273273
| legalTrademarks | <a name="WinBuildOptions-legalTrademarks"></a>The trademarks and registered trademarks.

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,12 @@
131131
"transform-es2015-spread",
132132
"transform-es2015-destructuring",
133133
"array-includes",
134-
"transform-inline-imports-commonjs"
134+
[
135+
"transform-inline-imports-commonjs",
136+
{
137+
"excludeModules": "path"
138+
}
139+
]
135140
]
136141
},
137142
"ava": {

src/metadata.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,17 @@ export interface BuildMetadata {
195195
readonly afterPack?: (context: AfterPackContext) => Promise<any> | null
196196

197197
/*
198-
*two package.json structure only* Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.
198+
Whether to [rebuild](https://docs.npmjs.com/cli/rebuild) native dependencies (`npm rebuild`) before starting to package the app. Defaults to `true`.
199199
*/
200200
readonly npmRebuild?: boolean
201201

202202
/*
203-
*two package.json structure only* Whether to omit using [--build-from-source](https://github.com/mapbox/node-pre-gyp#options) flag when installing app native deps. Defaults to `false`.
203+
Whether to omit using [--build-from-source](https://github.com/mapbox/node-pre-gyp#options) flag when installing app native deps. Defaults to `false`.
204204
*/
205205
readonly npmSkipBuildFromSource?: boolean
206206

207207
/*
208-
*two package.json structure only* Additional command line arguments to use when installing app native deps. Defaults to `null`.
208+
Additional command line arguments to use when installing app native deps. Defaults to `null`.
209209
*/
210210
readonly npmArgs?: Array<string> | string | null
211211

src/options/winOptions.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { PlatformSpecificBuildOptions } from "../metadata"
77
*/
88
export interface WinBuildOptions extends PlatformSpecificBuildOptions {
99
/*
10-
Target package type: list of `nsis`, `squirrel`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `squirrel`.
10+
Target package type: list of `nsis`, `squirrel`, `7z`, `zip`, `tar.xz`, `tar.lz`, `tar.gz`, `tar.bz2`, `dir`. Defaults to `nsis`.
1111
*/
1212
readonly target?: Array<string> | null
1313

@@ -143,17 +143,17 @@ export interface SquirrelWindowsOptions extends WinBuildOptions {
143143
readonly loadingGif?: string | null
144144

145145
/*
146-
*Squirrel.Windows-only.* Whether to create an MSI installer. Defaults to `false` (MSI is not created).
146+
Whether to create an MSI installer. Defaults to `false` (MSI is not created).
147147
*/
148148
readonly msi?: boolean
149149

150150
/*
151-
*Squirrel.Windows-only.* A URL to your existing updates. Or `true` to automatically set to your GitHub repository. If given, these will be downloaded to create delta updates.
151+
A URL to your existing updates. Or `true` to automatically set to your GitHub repository. If given, these will be downloaded to create delta updates.
152152
*/
153153
readonly remoteReleases?: string | boolean | null
154154

155155
/*
156-
*Squirrel.Windows-only.* Authentication token for remote updates
156+
Authentication token for remote updates
157157
*/
158158
readonly remoteToken?: string | null
159159

src/platformPackager.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { AsarOptions } from "asar-electron-builder"
99
import { archiveApp } from "./targets/archive"
1010
import { Minimatch } from "minimatch"
1111
import { checkFileInArchive, createAsarArchive } from "./asarUtil"
12-
import { warn, log, task } from "./util/log"
12+
import { warn, log } from "./util/log"
1313
import { AppInfo } from "./appInfo"
1414
import { copyFiltered } from "./util/filter"
1515
import { pack } from "./packager/dirPackager"
@@ -182,7 +182,8 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
182182

183183
const resourcesPath = this.platform === Platform.MAC ? path.join(appOutDir, "Electron.app", "Contents", "Resources") : path.join(appOutDir, "resources")
184184

185-
const p = pack(this, appOutDir, platformName, Arch[arch], this.info.electronVersion, async() => {
185+
log(`Packaging for ${platformName} ${Arch[arch]} using electron ${this.info.electronVersion} to ${path.relative(this.projectDir, appOutDir)}`)
186+
await pack(this, appOutDir, platformName, Arch[arch], this.info.electronVersion, async () => {
186187
const ignoreFiles = new Set([path.resolve(this.info.appDir, outDir), path.resolve(this.info.appDir, this.buildResourcesDir)])
187188
// prune dev or not listed dependencies
188189
await dependencies(this.info.appDir, true, ignoreFiles)
@@ -244,7 +245,6 @@ export abstract class PlatformPackager<DC extends PlatformSpecificBuildOptions>
244245
promises.push(this.postInitApp(appOutDir))
245246
await BluebirdPromise.all(promises)
246247
})
247-
await task(`Packaging for platform ${platformName} ${Arch[arch]} using electron ${this.info.electronVersion} to ${path.relative(this.projectDir, appOutDir)}`, p)
248248

249249
await this.doCopyExtraFiles(extraResourceMatchers)
250250
await this.doCopyExtraFiles(extraFileMatchers)

src/targets/nsis.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@ import * as path from "path"
55
import BluebirdPromise from "bluebird-lst-c"
66
import { getBinFromBintray } from "../util/binDownload"
77
import { v5 as uuid5 } from "uuid-1345"
8-
import {
9-
normalizeExt, TargetEx, getPublishConfigs, getResolvedPublishConfig,
10-
ArtifactCreated
11-
} from "../platformPackager"
8+
import { normalizeExt, TargetEx, getPublishConfigs, getResolvedPublishConfig, ArtifactCreated } from "../platformPackager"
129
import { archiveApp } from "./archive"
13-
import { subTask, task, log } from "../util/log"
10+
import { subTask, log } from "../util/log"
1411
import { unlink, readFile, writeFile, createReadStream } from "fs-extra-p"
1512
import { SemVer } from "semver"
1613
import { NsisOptions } from "../options/winOptions"
@@ -56,6 +53,8 @@ export default class NsisTarget extends TargetEx {
5653
}
5754

5855
private async doBuild(appOutDir: string, arch: Arch) {
56+
log(`Packaging NSIS installer for arch ${Arch[arch]}`)
57+
5958
const publishConfigs = await this.publishConfigs
6059
if (publishConfigs != null) {
6160
await writeFile(path.join(appOutDir, "resources", "app-update.yml"), safeDump(publishConfigs[0]))
@@ -66,9 +65,14 @@ export default class NsisTarget extends TargetEx {
6665
return await archiveApp(packager.devMetadata.build.compression, "7z", archiveFile, appOutDir, false, true)
6766
}
6867

69-
finishBuild(): Promise<any> {
70-
return task("Building NSIS installer", this.buildInstaller()
71-
.then(() => BluebirdPromise.map(this.archs.values(), it => unlink(it))))
68+
async finishBuild(): Promise<any> {
69+
log("Building NSIS installer")
70+
try {
71+
await this.buildInstaller()
72+
}
73+
finally {
74+
await BluebirdPromise.map(this.archs.values(), it => unlink(it))
75+
}
7276
}
7377

7478
private async buildInstaller(): Promise<any> {

src/targets/squirrelWindows.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export default class SquirrelWindowsTarget extends TargetEx {
2020
}
2121

2222
async build(appOutDir: string, arch: Arch) {
23+
log(`Building Squirrel.Windows for arch ${Arch[arch]}`)
24+
2325
if (arch === Arch.ia32) {
2426
warn("For windows consider only distributing 64-bit or use nsis target, see https://github.com/electron-userland/electron-builder/issues/359#issuecomment-214851130")
2527
}

src/winPackager.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import BluebirdPromise from "bluebird-lst-c"
33
import { PlatformPackager, BuildInfo, Target, TargetEx } from "./platformPackager"
44
import { Platform, Arch } from "./metadata"
55
import * as path from "path"
6-
import { log, task } from "./util/log"
6+
import { log } from "./util/log"
77
import { exec, use } from "./util/util"
88
import { open, close, read } from "fs-extra-p"
99
import { sign, SignOptions, getSignVendorPath } from "./windowsCodeSign"
@@ -73,13 +73,13 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
7373
continue
7474
}
7575

76-
if (name === DEFAULT_TARGET || name === "squirrel") {
76+
if (name === "squirrel") {
7777
mapper("squirrel", () => {
7878
const targetClass: typeof SquirrelWindowsTarget = require("./targets/squirrelWindows").default
7979
return new targetClass(this)
8080
})
8181
}
82-
else if (name === "nsis") {
82+
else if (name === DEFAULT_TARGET || name === "nsis") {
8383
mapper(name, outDir => {
8484
const targetClass: typeof NsisTarget = require("./targets/nsis").default
8585
return new targetClass(this, outDir)
@@ -181,7 +181,7 @@ export class WinPackager extends PlatformPackager<WinBuildOptions> {
181181
protected packageInDistributableFormat(outDir: string, appOutDir: string, arch: Arch, targets: Array<Target>, promises: Array<Promise<any>>): void {
182182
for (let target of targets) {
183183
if (target instanceof TargetEx) {
184-
promises.push(task(`Building ${target.name} ${Arch[arch]}`, target.build(appOutDir, arch)))
184+
promises.push(target.build(appOutDir, arch))
185185
}
186186
else {
187187
const format = target.name

test/src/globTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ test("extraResources", async () => {
190190
//noinspection SpellCheckingInspection
191191
await assertPack("test-app", {
192192
// to check NuGet package
193-
targets: platform.createTarget(platform === Platform.WINDOWS ? null : DIR_TARGET),
193+
targets: platform.createTarget(platform === Platform.WINDOWS ? "squirrel" : DIR_TARGET),
194194
}, {
195195
projectDirCreated: projectDir => {
196196
return BluebirdPromise.all([

0 commit comments

Comments
 (0)