diff --git a/.changeset/khaki-bats-learn.md b/.changeset/khaki-bats-learn.md new file mode 100644 index 00000000000..b9f931dab6d --- /dev/null +++ b/.changeset/khaki-bats-learn.md @@ -0,0 +1,7 @@ +--- +"@pnpm/plugin-commands-publishing": minor +"@pnpm/config": minor +"pnpm": minor +--- + +A custom compression level may be specified for the `pnpm pack` command using the `pack-gzip-level` setting [#6393](https://github.com/pnpm/pnpm/issues/6393). diff --git a/config/config/src/Config.ts b/config/config/src/Config.ts index badd6dad997..da4df01b337 100644 --- a/config/config/src/Config.ts +++ b/config/config/src/Config.ts @@ -159,6 +159,7 @@ export interface Config { dedupePeerDependents?: boolean patchesDir?: string ignoreWorkspaceCycles?: boolean + packGzipLevel?: number registries: Registries ignoreWorkspaceRootCheck: boolean diff --git a/config/config/src/index.ts b/config/config/src/index.ts index 114f7b782de..5f45f03a89a 100644 --- a/config/config/src/index.ts +++ b/config/config/src/index.ts @@ -85,6 +85,7 @@ export const types = Object.assign({ 'npm-path': String, offline: Boolean, 'only-built-dependencies': [String], + 'pack-gzip-level': Number, 'package-import-method': ['auto', 'hardlink', 'clone', 'copy'], 'patches-dir': String, pnpmfile: String, diff --git a/releasing/plugin-commands-publishing/src/pack.ts b/releasing/plugin-commands-publishing/src/pack.ts index 2aaa72af6a2..9ad2f2cf6cb 100644 --- a/releasing/plugin-commands-publishing/src/pack.ts +++ b/releasing/plugin-commands-publishing/src/pack.ts @@ -30,6 +30,9 @@ export function rcOptionsTypes () { export function cliOptionsTypes () { return { 'pack-destination': String, + ...pick([ + 'pack-gzip-level', + ], allTypes), } } @@ -55,7 +58,7 @@ export function help () { } export async function handler ( - opts: Pick & Pick & Partial> & { + opts: Pick & Pick & Partial> & { argv: { original: string[] } @@ -110,6 +113,7 @@ export async function handler ( projectDir: dir, embedReadme: opts.embedReadme, modulesDir: path.join(opts.dir, 'node_modules'), + packGzipLevel: opts.packGzipLevel, }) if (!opts.ignoreScripts) { await _runScriptsIfPresent(['postpack'], entryManifest) @@ -133,6 +137,7 @@ async function packPkg (opts: { projectDir: string embedReadme?: boolean modulesDir: string + packGzipLevel?: number }): Promise { const { destFile, @@ -160,7 +165,7 @@ async function packPkg (opts: { pack.entry({ mode, mtime, name }, fs.readFileSync(source)) } const tarball = fs.createWriteStream(destFile) - pack.pipe(createGzip()).pipe(tarball) + pack.pipe(createGzip({ level: opts.packGzipLevel })).pipe(tarball) pack.finalize() return new Promise((resolve, reject) => { tarball.on('close', () => { diff --git a/releasing/plugin-commands-publishing/src/publish.ts b/releasing/plugin-commands-publishing/src/publish.ts index 19a0ec15c35..1d53857798b 100644 --- a/releasing/plugin-commands-publishing/src/publish.ts +++ b/releasing/plugin-commands-publishing/src/publish.ts @@ -133,7 +133,7 @@ export async function publish ( engineStrict?: boolean recursive?: boolean workspaceDir?: string - } & Pick, + } & Pick, params: string[] ) { if (opts.gitChecks !== false && await isGitRepo()) { diff --git a/releasing/plugin-commands-publishing/test/pack.ts b/releasing/plugin-commands-publishing/test/pack.ts index a50745ba368..358455dcc91 100644 --- a/releasing/plugin-commands-publishing/test/pack.ts +++ b/releasing/plugin-commands-publishing/test/pack.ts @@ -280,3 +280,32 @@ test('pack to custom destination directory', async () => { expect(output).toBe(path.resolve('custom-dest/custom-dest-0.0.0.tgz')) }) + +test('pack: custom pack-gzip-level', async () => { + prepare({ + name: 'test-publish-package.json', + version: '0.0.0', + }) + + const packOpts = { + ...DEFAULT_OPTS, + argv: { original: [] }, + dir: process.cwd(), + extraBinPaths: [], + } + await pack.handler({ + ...packOpts, + packGzipLevel: 9, + packDestination: path.resolve('../small'), + }) + + await pack.handler({ + ...packOpts, + packGzipLevel: 0, + packDestination: path.resolve('../big'), + }) + + const tgz1 = fs.statSync(path.resolve('../small/test-publish-package.json-0.0.0.tgz')) + const tgz2 = fs.statSync(path.resolve('../big/test-publish-package.json-0.0.0.tgz')) + expect(tgz1.size).not.toEqual(tgz2.size) +})