Skip to content

Commit

Permalink
feat(windows): ZIP compression for portable
Browse files Browse the repository at this point in the history
Close #2548
  • Loading branch information
develar committed Mar 7, 2018
1 parent 5081536 commit e23cecb
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 8 additions & 1 deletion packages/electron-builder-lib/src/targets/nsis/NsisTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"
Expand Down
18 changes: 17 additions & 1 deletion packages/electron-builder-lib/templates/nsis/portable.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions test/out/windows/__snapshots__/portableTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
],
}
`;
2 changes: 1 addition & 1 deletion test/src/linux/linuxPackagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test.ifNotWindows("AppImage", app({
config: {
publish: {
provider: "generic",
url: "https://example.com/downloads"
url: "https://example.com/downloads",
},
},
}))
Expand Down
30 changes: 27 additions & 3 deletions test/src/windows/portableTest.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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 => {
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

[email protected].8:
version "0.4.8"
resolved "https://registry.yarnpkg.com/electron-osx-sign/-/electron-osx-sign-0.4.8.tgz#f0b9fadded9e1e54ec35fa89877b5c6c34c7bc40"
[email protected].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"
Expand Down

0 comments on commit e23cecb

Please sign in to comment.