From 03619e4c3cda8c0fe738be641c466f1e196012f8 Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Wed, 10 Jan 2024 09:08:03 -0800 Subject: [PATCH] feat: option to specify compression used for pack:deb (#1110) (#1241) * feat: option to specify compression used for pack:deb (#1110) This enables passing options to override what dpkg-deb uses by default, which is zstd on newer versions of Debian/Ubuntu and xz on older versions. Debian 11 can't read zstd so when building on newer Debian base for older, specifying may be necessary. This should aid in the resolution of heroku/cli#2240. Co-authored-by: Mike Donnalley * fix: use Flags.option * test: gzip test for pack deb * fix: no -Z option * test: debugging * test: debugging * test: debugging --------- Co-authored-by: Colin Dean --- README.md | 2 ++ src/commands/pack/deb.ts | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8ac35872..132a2556 100644 --- a/README.md +++ b/README.md @@ -232,6 +232,8 @@ USAGE FLAGS -r, --root= (required) [default: .] path to oclif CLI root -t, --tarball= optionally specify a path to a tarball already generated by NPM + -Z, --compression= optionally override compression, see output of + 'dpkg-deb --help' in the -Z description for valid options. DESCRIPTION pack CLI into debian package diff --git a/src/commands/pack/deb.ts b/src/commands/pack/deb.ts index 0a470580..004bd46e 100644 --- a/src/commands/pack/deb.ts +++ b/src/commands/pack/deb.ts @@ -52,13 +52,21 @@ APT::FTPArchive::Release { } export default class PackDeb extends Command { - static description = 'pack CLI into debian package' + static description = 'Pack CLI into debian package.' static flags = { - root: Flags.string({char: 'r', default: '.', description: 'path to oclif CLI root', required: true}), + compression: Flags.option({ + options: ['gzip', 'none', 'xz', 'zstd'] as const, + })({ + char: 'z', + description: + 'For more details see the `-Zcompress-type` section at https://man7.org/linux/man-pages/man1/dpkg-deb.1.html', + summary: 'Override the default compression used by dpkg-deb.', + }), + root: Flags.string({char: 'r', default: '.', description: 'Path to oclif CLI root.', required: true}), tarball: Flags.string({ char: 't', - description: 'optionally specify a path to a tarball already generated by NPM', + description: 'Optionally specify a path to a tarball already generated by NPM.', required: false, }), } @@ -107,7 +115,8 @@ export default class PackDeb extends Command { ) await exec(`sudo chown -R root "${workspace}"`) await exec(`sudo chgrp -R root "${workspace}"`) - await exec(`dpkg --build "${workspace}" "${path.join(dist, versionedDebBase)}"`) + const dpkgDeb = flags.compression ? `dpkg-deb --build "-Z${flags.compression}"` : 'dpkg-deb --build' + await exec(`${dpkgDeb} "${workspace}" "${path.join(dist, versionedDebBase)}"`) this.log(`finished building debian / ${arch}`) }