Skip to content

Commit e23cecb

Browse files
committed
feat(windows): ZIP compression for portable
Close #2548
1 parent 5081536 commit e23cecb

File tree

8 files changed

+81
-11
lines changed

8 files changed

+81
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"ejs": "^2.5.7",
4141
"electron-download-tf": "4.3.4",
4242
"electron-is-dev": "^0.3.0",
43-
"electron-osx-sign": "0.4.8",
43+
"electron-osx-sign": "0.4.9",
4444
"fs-extra-p": "^4.5.2",
4545
"gitbook-plugin-footer": "^0.0.6",
4646
"hosted-git-info": "^2.5.0",

packages/electron-builder-lib/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
"chromium-pickle-js": "^0.2.0",
4949
"builder-util-runtime": "0.0.0-semantic-release",
5050
"builder-util": "0.0.0-semantic-release",
51-
"electron-osx-sign": "0.4.8",
51+
"electron-osx-sign": "0.4.9",
5252
"electron-publish": "0.0.0-semantic-release",
5353
"fs-extra-p": "^4.5.2",
5454
"hosted-git-info": "^2.5.0",

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,12 @@ export class NsisTarget extends Target {
161161
}
162162

163163
const packageFiles: { [arch: string]: PackageFileInfo } = {}
164-
if (USE_NSIS_BUILT_IN_COMPRESSOR && this.archs.size === 1) {
164+
if (this.isPortable && options.useZip) {
165+
for (const [arch, dir] of this.archs.entries()) {
166+
defines[arch === Arch.x64 ? "APP_DIR_64" : "APP_DIR_32"] = dir
167+
}
168+
}
169+
else if (USE_NSIS_BUILT_IN_COMPRESSOR && this.archs.size === 1) {
165170
defines.APP_BUILD_DIR = this.archs.get(this.archs.keys().next().value)
166171
}
167172
else {
@@ -194,6 +199,8 @@ export class NsisTarget extends Target {
194199
}
195200
else {
196201
// difference - 33.540 vs 33.601, only 61 KB (but zip is faster to decompress)
202+
// do not use /SOLID - "With solid compression, files are uncompressed to temporary file before they are copied to their final destination",
203+
// it is not good for portable installer (where built-in NSIS compression is used). http://forums.winamp.com/showpost.php?p=2982902&postcount=6
197204
commands.SetCompressor = "zlib"
198205
if (!this.isWebInstaller) {
199206
defines.COMPRESS = "auto"

packages/electron-builder-lib/templates/nsis/portable.nsi

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,23 @@ Section
1515
StrCpy $INSTDIR $PLUGINSDIR\app
1616
SetOutPath $INSTDIR
1717

18-
!insertmacro extractEmbeddedAppPackage
18+
!ifdef APP_DIR_64
19+
!ifdef APP_DIR_32
20+
${if} ${RunningX64}
21+
File /r "${APP_DIR_64}/*.*"
22+
${else}
23+
File /r "${APP_DIR_32}/*.*"
24+
${endIf}
25+
!else
26+
File /r "${APP_DIR_64}/*.*"
27+
!endif
28+
!else
29+
!ifdef APP_DIR_32
30+
File /r "${APP_DIR_32}/*.*"
31+
!else
32+
!insertmacro extractEmbeddedAppPackage
33+
!endif
34+
!endif
1935

2036
System::Call 'Kernel32::SetEnvironmentVariable(t, t)i ("PORTABLE_EXECUTABLE_DIR", "$EXEDIR").r0'
2137
${StdUtils.GetAllParameters} $R0 0

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,26 @@ Object {
2828
],
2929
}
3030
`;
31+
32+
exports[`portable zip 1`] = `
33+
Object {
34+
"win": Array [
35+
Object {
36+
"arch": "x64",
37+
"file": "Test App ßW 1.1.0.exe",
38+
"safeArtifactName": "TestApp-1.1.0.exe",
39+
},
40+
],
41+
}
42+
`;
43+
44+
exports[`portable zip several archs 1`] = `
45+
Object {
46+
"win": Array [
47+
Object {
48+
"file": "Test App ßW 1.1.0.exe",
49+
"safeArtifactName": "TestApp-1.1.0.exe",
50+
},
51+
],
52+
}
53+
`;

test/src/linux/linuxPackagerTest.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test.ifNotWindows("AppImage", app({
1212
config: {
1313
publish: {
1414
provider: "generic",
15-
url: "https://example.com/downloads"
15+
url: "https://example.com/downloads",
1616
},
1717
},
1818
}))

test/src/windows/portableTest.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Platform } from "electron-builder"
1+
import { Platform, Arch } from "electron-builder"
22
import * as path from "path"
33
import { app, copyTestAsset } from "../helpers/packTester"
44

@@ -13,17 +13,41 @@ test.ifAll.ifNotCiMac("portable", app({
1313
}
1414
}))
1515

16+
test.ifAll.ifNotCi("portable zip", app({
17+
targets: Platform.WINDOWS.createTarget("portable"),
18+
config: {
19+
publish: null,
20+
portable: {
21+
useZip: true,
22+
},
23+
compression: "normal",
24+
}
25+
}))
26+
27+
test.ifAll.ifNotCi("portable zip several archs", app({
28+
targets: Platform.WINDOWS.createTarget("portable", Arch.ia32, Arch.x64),
29+
config: {
30+
publish: null,
31+
portable: {
32+
useZip: true,
33+
},
34+
compression: "store",
35+
}
36+
}))
37+
1638
test.ifNotCiMac("portable - artifactName and request execution level", app({
1739
targets: Platform.WINDOWS.createTarget(["portable"]),
1840
config: {
1941
nsis: {
42+
//tslint:disable-next-line:no-invalid-template-strings
2043
artifactName: "${productName}Installer.${version}.${ext}",
2144
installerIcon: "foo test space.ico",
2245
},
2346
portable: {
2447
requestExecutionLevel: "admin",
25-
artifactName: "${productName}Portable.${version}.${ext}"
26-
}
48+
//tslint:disable-next-line:no-invalid-template-strings
49+
artifactName: "${productName}Portable.${version}.${ext}",
50+
},
2751
},
2852
}, {
2953
projectDirCreated: projectDir => {

yarn.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,9 +1690,9 @@ electron-is-dev@^0.3.0:
16901690
version "0.3.0"
16911691
resolved "https://registry.yarnpkg.com/electron-is-dev/-/electron-is-dev-0.3.0.tgz#14e6fda5c68e9e4ecbeff9ccf037cbd7c05c5afe"
16921692

1693-
electron-osx-sign@0.4.8:
1694-
version "0.4.8"
1695-
resolved "https://registry.yarnpkg.com/electron-osx-sign/-/electron-osx-sign-0.4.8.tgz#f0b9fadded9e1e54ec35fa89877b5c6c34c7bc40"
1693+
electron-osx-sign@0.4.9:
1694+
version "0.4.9"
1695+
resolved "https://registry.yarnpkg.com/electron-osx-sign/-/electron-osx-sign-0.4.9.tgz#575d2a24c2c8bcae41bdfbe61462318ea0f2460a"
16961696
dependencies:
16971697
bluebird "^3.5.0"
16981698
compare-version "^0.1.2"

0 commit comments

Comments
 (0)