diff --git a/package.json b/package.json index f0845140a16..46dc8c9e47e 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "chalk": "^1.1.3", "chromium-pickle-js": "^0.2.0", "cuint": "^0.2.2", - "electron-download-tf": "3.1.0", + "electron-download-tf": "3.2.0", "electron-macos-sign": "~1.5.0", "fs-extra-p": "^3.1.0", "hosted-git-info": "^2.1.5", @@ -67,7 +67,7 @@ "convert-source-map": "^1.3.0", "decompress-zip": "^0.3.0", "depcheck": "^0.6.7", - "electron-download-tf": "3.1.0", + "electron-download-tf": "3.2.0", "jest-cli": "^18.1.0", "jest-environment-node-debug": "^0.0.2", "path-sort": "^0.1.0", diff --git a/packages/electron-builder/package.json b/packages/electron-builder/package.json index 0a50788cdb3..14306239b88 100644 --- a/packages/electron-builder/package.json +++ b/packages/electron-builder/package.json @@ -52,7 +52,7 @@ "electron-builder-core": "0.0.0-semantic-release", "electron-builder-http": "0.0.0-semantic-release", "electron-builder-util": "0.0.0-semantic-release", - "electron-download-tf": "3.1.0", + "electron-download-tf": "3.2.0", "electron-macos-sign": "~1.5.0", "fs-extra-p": "^3.1.0", "hosted-git-info": "^2.1.5", diff --git a/packages/electron-builder/src/options/winOptions.ts b/packages/electron-builder/src/options/winOptions.ts index 8ea1f9e39a6..59f11ef4f83 100644 --- a/packages/electron-builder/src/options/winOptions.ts +++ b/packages/electron-builder/src/options/winOptions.ts @@ -142,6 +142,9 @@ export interface NsisOptions { 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. */ readonly menuCategory?: boolean | string + + // defaults to false + readonly useZip?: boolean } /* diff --git a/packages/electron-builder/src/packager.ts b/packages/electron-builder/src/packager.ts index aee0ee6fd80..e3baca2e13d 100644 --- a/packages/electron-builder/src/packager.ts +++ b/packages/electron-builder/src/packager.ts @@ -102,7 +102,7 @@ export class Packager implements BuildInfo { const projectDir = this.projectDir const fileOrPackageConfig = await loadConfig(projectDir) - const config = fileOrPackageConfig == null ? configFromOptions : deepAssign(fileOrPackageConfig, configFromOptions) + const config = deepAssign({}, fileOrPackageConfig, configFromOptions) const extraMetadata = this.options.extraMetadata if (extraMetadata != null) { diff --git a/packages/electron-builder/src/targets/archive.ts b/packages/electron-builder/src/targets/archive.ts index f881edc448c..293f852304f 100644 --- a/packages/electron-builder/src/targets/archive.ts +++ b/packages/electron-builder/src/targets/archive.ts @@ -54,6 +54,9 @@ export async function archive(compression: CompressionLevel | n, format: string, //noinspection SpellCheckingInspection args.push("-mfb=258", "-mpass=15") } + else if (!storeOnly) { + args.push("-mpass=7") + } } else if (compression === "maximum") { args.push("-mx=9") diff --git a/packages/electron-builder/src/targets/nsis.ts b/packages/electron-builder/src/targets/nsis.ts index 28f535ae502..7c99e04fed4 100644 --- a/packages/electron-builder/src/targets/nsis.ts +++ b/packages/electron-builder/src/targets/nsis.ts @@ -22,10 +22,12 @@ const ELECTRON_BUILDER_NS_UUID = "50e065bc-3134-11e6-9bab-38c9862bdaf3" const nsisPathPromise = getBinFromBintray("nsis", NSIS_VERSION, NSIS_SHA2) +const USE_NSIS_BUILT_IN_COMPRESSOR = false + export default class NsisTarget extends Target { private readonly options: NsisOptions = this.packager.config.nsis || Object.create(null) - private archs: Map> = new Map() + private archs: Map = new Map() private readonly nsisTemplatesDir = path.join(__dirname, "..", "..", "templates", "nsis") @@ -38,9 +40,8 @@ export default class NsisTarget extends Target { } } - build(appOutDir: string, arch: Arch) { - this.archs.set(arch, this.doBuild(appOutDir, arch)) - return BluebirdPromise.resolve(null) + async build(appOutDir: string, arch: Arch) { + this.archs.set(arch, appOutDir) } private async doBuild(appOutDir: string, arch: Arch) { @@ -49,21 +50,25 @@ export default class NsisTarget extends Target { await copyFile(path.join(await nsisPathPromise, "elevate.exe"), path.join(appOutDir, "resources", "elevate.exe"), null, false) const packager = this.packager - const archiveFile = path.join(this.outDir, `${packager.appInfo.name}-${packager.appInfo.version}-${Arch[arch]}.nsis.7z`) - return await archive(packager.config.compression, "7z", archiveFile, appOutDir, true) + const format = this.options.useZip ? "zip" : "7z" + const archiveFile = path.join(this.outDir, `${packager.appInfo.name}-${packager.appInfo.version}-${Arch[arch]}.nsis.${format}`) + return await archive(packager.config.compression, format, archiveFile, appOutDir, true) } async finishBuild(): Promise { log("Building NSIS installer") + const filesToDelete: Array = [] try { - await this.buildInstaller() + await this.buildInstaller(filesToDelete) } finally { - await BluebirdPromise.map(this.archs.values(), it => unlink(it)) + if (filesToDelete.length > 0) { + await BluebirdPromise.map(filesToDelete, it => unlink(it)) + } } } - private async buildInstaller(): Promise { + private async buildInstaller(filesToDelete: Array): Promise { const packager = this.packager const appInfo = packager.appInfo const version = appInfo.version @@ -94,8 +99,15 @@ export default class NsisTarget extends Target { defines.MUI_UNICON = iconPath } - for (const [arch, file] of this.archs) { - defines[arch === Arch.x64 ? "APP_64" : "APP_32"] = await file + if (this.archs.size === 1 && USE_NSIS_BUILT_IN_COMPRESSOR) { + defines.APP_BUILD_DIR = this.archs.get(this.archs.keys().next().value) + } + else { + await BluebirdPromise.map(this.archs.keys(), async arch => { + const file = await this.doBuild(this.archs.get(arch)!, arch) + defines[arch === Arch.x64 ? "APP_64" : "APP_32"] = file + filesToDelete.push(file) + }) } const installerHeader = oneClick ? null : await packager.getResource(options.installerHeader, "installerHeader.bmp") @@ -156,16 +168,18 @@ export default class NsisTarget extends Target { if (packager.config.compression === "store") { commands.SetCompress = "off" - defines.COMPRESS = "off" } else { commands.SetCompressor = "lzma" - // default is 8: test app installer size 37.2 vs 36 if dict size 64 - commands.SetCompressorDictSize = "64" - defines.COMPRESS = "auto" } + if (this.options.useZip) { + defines.ZIP_COMPRESSION = null + } + + defines.COMPRESSION_METHOD = this.options.useZip ? "zip" : "7z" + if (oneClick) { defines.ONE_CLICK = null } diff --git a/packages/electron-builder/templates/nsis/installSection.nsh b/packages/electron-builder/templates/nsis/installSection.nsh index ee7eeee2f4f..bea7a87e8b4 100644 --- a/packages/electron-builder/templates/nsis/installSection.nsh +++ b/packages/electron-builder/templates/nsis/installSection.nsh @@ -108,23 +108,45 @@ ${endif} SetOutPath $INSTDIR -SetCompress off -!ifdef APP_32 - File /oname=$PLUGINSDIR\app-32.7z "${APP_32}" -!endif -!ifdef APP_64 - File /oname=$PLUGINSDIR\app-64.7z "${APP_64}" -!endif -SetCompress "${COMPRESS}" - -!ifdef APP_64 - ${if} ${RunningX64} - Nsis7z::Extract "$PLUGINSDIR\app-64.7z" - ${else} - Nsis7z::Extract "$PLUGINSDIR\app-32.7z" - ${endif} +!ifdef APP_BUILD_DIR + File /r "${APP_BUILD_DIR}/*.*" !else - Nsis7z::Extract "$PLUGINSDIR\app-32.7z" + !ifdef COMPRESS + SetCompress off + !endif + + !ifdef APP_32 + File /oname=$PLUGINSDIR\app-32.${COMPRESSION_METHOD} "${APP_32}" + !endif + !ifdef APP_64 + File /oname=$PLUGINSDIR\app-64.${COMPRESSION_METHOD} "${APP_64}" + !endif + + !ifdef COMPRESS + SetCompress "${COMPRESS}" + !endif + + !ifdef APP_64 + ${if} ${RunningX64} + !ifdef ZIP_COMPRESSION + nsisunz::Unzip "$PLUGINSDIR\app-64.zip" "$INSTDIR" + !else + Nsis7z::Extract "$PLUGINSDIR\app-64.7z" + !endif + ${else} + !ifdef ZIP_COMPRESSION + nsisunz::Unzip "$PLUGINSDIR\app-32.zip" "$INSTDIR" + !else + Nsis7z::Extract "$PLUGINSDIR\app-32.7z" + !endif + ${endif} + !else + !ifdef ZIP_COMPRESSION + nsisunz::Unzip "$PLUGINSDIR\app-32.zip" "$INSTDIR" + !else + Nsis7z::Extract "$PLUGINSDIR\app-32.7z" + !endif + !endif !endif File "/oname=${UNINSTALL_FILENAME}" "${UNINSTALLER_OUT_FILE}" diff --git a/yarn.lock b/yarn.lock index 0ddc14676f0..96478f6da1f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -776,7 +776,7 @@ dashdash@^1.12.0: dependencies: assert-plus "^1.0.0" -debug@^2.1.1, debug@^2.1.3, debug@^2.2.0, debug@^2.3.2, debug@^2.6.0: +debug@^2.1.1, debug@^2.1.3, debug@^2.2.0, debug@^2.6.0: version "2.6.0" resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.0.tgz#bc596bcabe7617f11d9fa15361eded5608b8499b" dependencies: @@ -875,18 +875,18 @@ ecc-jsbn@~0.1.1: dependencies: jsbn "~0.1.0" -electron-download-tf@3.1.0: - version "3.1.0" - resolved "https://registry.yarnpkg.com/electron-download-tf/-/electron-download-tf-3.1.0.tgz#c6d62c0e0a4c63b67295f57b6b66514c13b8ed8d" +electron-download-tf@3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/electron-download-tf/-/electron-download-tf-3.2.0.tgz#690443d2e7d068f000358f86b9d504303711ad10" dependencies: - debug "^2.3.2" - fs-extra "^1.0.0" + debug "^2.6.0" + fs-extra "^2.0.0" minimist "^1.2.0" nugget "^2.0.1" path-exists "^3.0.0" rc "^1.1.6" semver "^5.3.0" - sumchecker "^1.2.0" + sumchecker "^2.0.1" electron-macos-sign@~1.5.0: version "1.5.0" @@ -920,10 +920,6 @@ error-ex@^1.2.0: dependencies: is-arrayish "^0.2.1" -es6-promise@^4.0.5: - version "4.0.5" - resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.0.5.tgz#7882f30adde5b240ccfa7f7d78c548330951ae42" - escape-string-regexp@^1.0.2: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" @@ -1064,14 +1060,6 @@ fs-extra-p@^3.1.0: bluebird-lst-c "^1.0.6" fs-extra "^2.0.0" -fs-extra@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-1.0.0.tgz#cd3ce5f7e7cb6145883fcae3191e9877f8587950" - dependencies: - graceful-fs "^4.1.2" - jsonfile "^2.1.0" - klaw "^1.0.0" - fs-extra@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-2.0.0.tgz#337352bded4a0b714f3eb84de8cea765e9d37600" @@ -1165,7 +1153,7 @@ got@^5.0.0: unzip-response "^1.0.2" url-parse-lax "^1.0.0" -graceful-fs@^4.1.0, graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.3, graceful-fs@^4.1.6, graceful-fs@^4.1.9: +graceful-fs@^4.1.0, graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.3, graceful-fs@^4.1.6: version "4.1.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" @@ -1764,12 +1752,6 @@ kind-of@^3.0.2: dependencies: is-buffer "^1.0.2" -klaw@^1.0.0: - version "1.3.1" - resolved "https://registry.yarnpkg.com/klaw/-/klaw-1.3.1.tgz#4088433b46b3b1ba259d78785d8e96f73ba02439" - optionalDependencies: - graceful-fs "^4.1.9" - latest-version@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/latest-version/-/latest-version-2.0.0.tgz#56f8d6139620847b8017f8f1f4d78e211324168b" @@ -2659,12 +2641,11 @@ strip-json-comments@~1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-1.0.4.tgz#1e15fbcac97d3ee99bf2d73b4c656b082bbafb91" -sumchecker@^1.2.0: - version "1.3.0" - resolved "https://registry.yarnpkg.com/sumchecker/-/sumchecker-1.3.0.tgz#6e3004d7bf3b5ad5567abf13a828946d8a19911b" +sumchecker@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/sumchecker/-/sumchecker-2.0.1.tgz#9ce42ecefc5fce2c602d3623315c52b57a2d69dd" dependencies: debug "^2.2.0" - es6-promise "^4.0.5" supports-color@^2.0.0: version "2.0.0"