Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pack): add pack-gzip-level #6406

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 17 additions & 2 deletions releasing/plugin-commands-publishing/src/pack.ts
@@ -1,6 +1,6 @@
import fs from 'fs'
import path from 'path'
import { createGzip } from 'zlib'
import { createGzip, type ZlibOptions } from 'zlib'
import { PnpmError } from '@pnpm/error'
import { types as allTypes, type UniversalOptions, type Config } from '@pnpm/config'
import { readProjectManifest } from '@pnpm/cli-utils'
Expand Down Expand Up @@ -127,6 +127,21 @@ async function readReadmeFile (filesMap: Record<string, string>) {
return readmeFile
}

function getGzipConfig () {
const gzipConfig: ZlibOptions = {}

const level = process.env.PNPM_PACK_GZIP_LEVEL
jankaifer marked this conversation as resolved.
Show resolved Hide resolved
if (level !== undefined) {
const parsedLevel = parseInt(level)
if (isNaN(parsedLevel)) {
throw new PnpmError('INVALID_GZIP_LEVEL', `Invalid gzip level: '${level}'`)
jankaifer marked this conversation as resolved.
Show resolved Hide resolved
}
gzipConfig.level = parsedLevel
}

return gzipConfig
}

async function packPkg (opts: {
destFile: string
filesMap: Record<string, string>
Expand Down Expand Up @@ -160,7 +175,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(getGzipConfig())).pipe(tarball)
pack.finalize()
return new Promise((resolve, reject) => {
tarball.on('close', () => {
Expand Down