From e23cecb4e335ea89840e28965f48099c936e93ef Mon Sep 17 00:00:00 2001 From: develar Date: Wed, 7 Mar 2018 19:39:24 +0100 Subject: [PATCH] feat(windows): ZIP compression for portable Close #2548 --- package.json | 2 +- packages/electron-builder-lib/package.json | 2 +- .../src/targets/nsis/NsisTarget.ts | 9 +++++- .../templates/nsis/portable.nsi | 18 ++++++++++- .../__snapshots__/portableTest.js.snap | 23 ++++++++++++++ test/src/linux/linuxPackagerTest.ts | 2 +- test/src/windows/portableTest.ts | 30 +++++++++++++++++-- yarn.lock | 6 ++-- 8 files changed, 81 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 4f10b12ba64..65f2a0893e5 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "ejs": "^2.5.7", "electron-download-tf": "4.3.4", "electron-is-dev": "^0.3.0", - "electron-osx-sign": "0.4.8", + "electron-osx-sign": "0.4.9", "fs-extra-p": "^4.5.2", "gitbook-plugin-footer": "^0.0.6", "hosted-git-info": "^2.5.0", diff --git a/packages/electron-builder-lib/package.json b/packages/electron-builder-lib/package.json index 19f7f83a7ca..396331ae934 100644 --- a/packages/electron-builder-lib/package.json +++ b/packages/electron-builder-lib/package.json @@ -48,7 +48,7 @@ "chromium-pickle-js": "^0.2.0", "builder-util-runtime": "0.0.0-semantic-release", "builder-util": "0.0.0-semantic-release", - "electron-osx-sign": "0.4.8", + "electron-osx-sign": "0.4.9", "electron-publish": "0.0.0-semantic-release", "fs-extra-p": "^4.5.2", "hosted-git-info": "^2.5.0", diff --git a/packages/electron-builder-lib/src/targets/nsis/NsisTarget.ts b/packages/electron-builder-lib/src/targets/nsis/NsisTarget.ts index 0e2bbfeee2f..e3f5ac9f48e 100644 --- a/packages/electron-builder-lib/src/targets/nsis/NsisTarget.ts +++ b/packages/electron-builder-lib/src/targets/nsis/NsisTarget.ts @@ -161,7 +161,12 @@ export class NsisTarget extends Target { } const packageFiles: { [arch: string]: PackageFileInfo } = {} - if (USE_NSIS_BUILT_IN_COMPRESSOR && this.archs.size === 1) { + if (this.isPortable && options.useZip) { + for (const [arch, dir] of this.archs.entries()) { + defines[arch === Arch.x64 ? "APP_DIR_64" : "APP_DIR_32"] = dir + } + } + else if (USE_NSIS_BUILT_IN_COMPRESSOR && this.archs.size === 1) { defines.APP_BUILD_DIR = this.archs.get(this.archs.keys().next().value) } else { @@ -194,6 +199,8 @@ export class NsisTarget extends Target { } else { // difference - 33.540 vs 33.601, only 61 KB (but zip is faster to decompress) + // do not use /SOLID - "With solid compression, files are uncompressed to temporary file before they are copied to their final destination", + // it is not good for portable installer (where built-in NSIS compression is used). http://forums.winamp.com/showpost.php?p=2982902&postcount=6 commands.SetCompressor = "zlib" if (!this.isWebInstaller) { defines.COMPRESS = "auto" diff --git a/packages/electron-builder-lib/templates/nsis/portable.nsi b/packages/electron-builder-lib/templates/nsis/portable.nsi index 41f79a62ce0..5f420afc861 100644 --- a/packages/electron-builder-lib/templates/nsis/portable.nsi +++ b/packages/electron-builder-lib/templates/nsis/portable.nsi @@ -15,7 +15,23 @@ Section StrCpy $INSTDIR $PLUGINSDIR\app SetOutPath $INSTDIR - !insertmacro extractEmbeddedAppPackage + !ifdef APP_DIR_64 + !ifdef APP_DIR_32 + ${if} ${RunningX64} + File /r "${APP_DIR_64}/*.*" + ${else} + File /r "${APP_DIR_32}/*.*" + ${endIf} + !else + File /r "${APP_DIR_64}/*.*" + !endif + !else + !ifdef APP_DIR_32 + File /r "${APP_DIR_32}/*.*" + !else + !insertmacro extractEmbeddedAppPackage + !endif + !endif System::Call 'Kernel32::SetEnvironmentVariable(t, t)i ("PORTABLE_EXECUTABLE_DIR", "$EXEDIR").r0' ${StdUtils.GetAllParameters} $R0 0 diff --git a/test/out/windows/__snapshots__/portableTest.js.snap b/test/out/windows/__snapshots__/portableTest.js.snap index a22f9a1a99d..415a175dd53 100644 --- a/test/out/windows/__snapshots__/portableTest.js.snap +++ b/test/out/windows/__snapshots__/portableTest.js.snap @@ -28,3 +28,26 @@ Object { ], } `; + +exports[`portable zip 1`] = ` +Object { + "win": Array [ + Object { + "arch": "x64", + "file": "Test App ßW 1.1.0.exe", + "safeArtifactName": "TestApp-1.1.0.exe", + }, + ], +} +`; + +exports[`portable zip several archs 1`] = ` +Object { + "win": Array [ + Object { + "file": "Test App ßW 1.1.0.exe", + "safeArtifactName": "TestApp-1.1.0.exe", + }, + ], +} +`; diff --git a/test/src/linux/linuxPackagerTest.ts b/test/src/linux/linuxPackagerTest.ts index ae0fbc60faf..cb02ef4909e 100644 --- a/test/src/linux/linuxPackagerTest.ts +++ b/test/src/linux/linuxPackagerTest.ts @@ -12,7 +12,7 @@ test.ifNotWindows("AppImage", app({ config: { publish: { provider: "generic", - url: "https://example.com/downloads" + url: "https://example.com/downloads", }, }, })) diff --git a/test/src/windows/portableTest.ts b/test/src/windows/portableTest.ts index bc2a809a245..bebb697fe9a 100644 --- a/test/src/windows/portableTest.ts +++ b/test/src/windows/portableTest.ts @@ -1,4 +1,4 @@ -import { Platform } from "electron-builder" +import { Platform, Arch } from "electron-builder" import * as path from "path" import { app, copyTestAsset } from "../helpers/packTester" @@ -13,17 +13,41 @@ test.ifAll.ifNotCiMac("portable", app({ } })) +test.ifAll.ifNotCi("portable zip", app({ + targets: Platform.WINDOWS.createTarget("portable"), + config: { + publish: null, + portable: { + useZip: true, + }, + compression: "normal", + } +})) + +test.ifAll.ifNotCi("portable zip several archs", app({ + targets: Platform.WINDOWS.createTarget("portable", Arch.ia32, Arch.x64), + config: { + publish: null, + portable: { + useZip: true, + }, + compression: "store", + } +})) + test.ifNotCiMac("portable - artifactName and request execution level", app({ targets: Platform.WINDOWS.createTarget(["portable"]), config: { nsis: { + //tslint:disable-next-line:no-invalid-template-strings artifactName: "${productName}Installer.${version}.${ext}", installerIcon: "foo test space.ico", }, portable: { requestExecutionLevel: "admin", - artifactName: "${productName}Portable.${version}.${ext}" - } + //tslint:disable-next-line:no-invalid-template-strings + artifactName: "${productName}Portable.${version}.${ext}", + }, }, }, { projectDirCreated: projectDir => { diff --git a/yarn.lock b/yarn.lock index 6c75c35d795..3a791e9ee54 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1690,9 +1690,9 @@ electron-is-dev@^0.3.0: version "0.3.0" resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-0.3.0.tgz#14e6fda5c68e9e4ecbeff9ccf037cbd7c05c5afe" -electron-osx-sign@0.4.8: - version "0.4.8" - resolved "https://registry.yarnpkg.com/electron-osx-sign/-/electron-osx-sign-0.4.8.tgz#f0b9fadded9e1e54ec35fa89877b5c6c34c7bc40" +electron-osx-sign@0.4.9: + version "0.4.9" + resolved "https://registry.yarnpkg.com/electron-osx-sign/-/electron-osx-sign-0.4.9.tgz#575d2a24c2c8bcae41bdfbe61462318ea0f2460a" dependencies: bluebird "^3.5.0" compare-version "^0.1.2"