Skip to content

Commit

Permalink
feat: allow passing compression option (@fcastilloec and @danielferro69
Browse files Browse the repository at this point in the history
…) (#342)

Co-authored-by: Felipe Castillo <[email protected]>
Co-authored-by: danielferro69 <[email protected]>
  • Loading branch information
3 people authored Aug 18, 2023
1 parent 1e9ab45 commit f8093ff
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
29 changes: 29 additions & 0 deletions test/installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.$/
)
})

0 comments on commit f8093ff

Please sign in to comment.