From f8093fff8459699a42117eea7ad757a523efc2f2 Mon Sep 17 00:00:00 2001 From: Keeley Hammond Date: Fri, 18 Aug 2023 12:22:39 -0700 Subject: [PATCH] feat: allow passing compression option (@fcastilloec and @danielferro69) (#342) Co-authored-by: Felipe Castillo Co-authored-by: danielferro69 --- README.md | 10 ++++++++++ src/installer.js | 10 ++++++++++ test/installer.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/README.md b/README.md index 46790ab..a4f51a6 100644 --- a/README.md +++ b/README.md @@ -193,6 +193,7 @@ Even though you can pass most of these options through the command-line interfac { "dest": "dist/installers/", "icon": "resources/Icon.png", + "compression": "gzip", "categories": [ "Utility" ], @@ -430,6 +431,15 @@ Default: [`resources/desktop.ejs`](https://github.com/electron-userland/electron The absolute path to a custom template for the generated [FreeDesktop.org desktop entry](http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html) file. +#### options.compression +Type: `String` +Default: `xz` + +Set the compression type used by dpkg-deb when building .deb package +Allowed values: `'xz', 'gzip', 'bzip2', 'lzma', 'zstd', 'none'` + +Used by `dpkg-deb` to set the compression type. You can read more about it on the [manual page of `dpkg-deb`](https://man7.org/linux/man-pages/man1/dpkg-deb.1.html) + ### Installed Package The package installs the Electron application into `/usr/lib`, since there are diff --git a/src/installer.js b/src/installer.js index 66c4810..d31385c 100644 --- a/src/installer.js +++ b/src/installer.js @@ -115,6 +115,11 @@ class DebianInstaller extends common.ElectronInstaller { if (process.platform === 'darwin') { command.unshift('--root-owner-group') } + + if (this.options.compression) { + command.unshift(`-Z${this.options.compression}`) + } + command.unshift('dpkg-deb') const output = await spawn('fakeroot', command, this.options.logger) @@ -168,6 +173,11 @@ class DebianInstaller extends common.ElectronInstaller { this.options.productDescription = this.normalizeExtendedDescription(this.options.productDescription) } + const compressionTypes = ['xz', 'gzip', 'bzip2', 'lzma', 'zstd', 'none'] + if (this.options.compression && !compressionTypes.includes(this.options.compression)) { + throw new Error('Invalid compression type. xz, gzip, bzip2, lzma, zstd, or none are supported.') + } + // Create array with unique values from default & user-supplied dependencies for (const prop of ['depends', 'recommends', 'suggests', 'enhances', 'preDepends']) { this.options[prop] = common.mergeUserSpecified(this.userSupplied, prop, this.defaults) diff --git a/test/installer.js b/test/installer.js index 1806b96..daf2957 100644 --- a/test/installer.js +++ b/test/installer.js @@ -251,4 +251,33 @@ describe('module', function () { chai.expect(installer.transformVersion('1.2.3-beta.4')).to.equal('1.2.3~beta.4') }) }) + + describeInstaller( + 'with different compression type', + { + src: 'test/fixtures/app-with-asar/', + options: { + arch: 'i386', + compression: 'gzip' + } + }, + 'generates a .deb package with gzip', + async outputDir => { + await assertASARDebExists(outputDir) + + const output = await spawn('file', [path.join(outputDir, 'footest_i386.deb')]) + chai.expect(output).to.contain('compression gz') + } + ) + + describeInstallerWithException( + 'with wrong compression type', + { + src: 'test/fixtures/app-with-asar/', + options: { + compression: 'invalid' + } + }, + /^Invalid compression type. xz, gzip, bzip2, lzma, zstd, or none are supported.$/ + ) })