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
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions .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).
1 change: 1 addition & 0 deletions config/config/src/Config.ts
Expand Up @@ -159,6 +159,7 @@ export interface Config {
dedupePeerDependents?: boolean
patchesDir?: string
ignoreWorkspaceCycles?: boolean
packGzipLevel?: number

registries: Registries
ignoreWorkspaceRootCheck: boolean
Expand Down
1 change: 1 addition & 0 deletions config/config/src/index.ts
Expand Up @@ -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,
Expand Down
9 changes: 7 additions & 2 deletions releasing/plugin-commands-publishing/src/pack.ts
Expand Up @@ -30,6 +30,9 @@ export function rcOptionsTypes () {
export function cliOptionsTypes () {
return {
'pack-destination': String,
...pick([
'pack-gzip-level',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider also adding this to help() below so it shows up in pnpm pack --help for discoverability?

], allTypes),
}
}

Expand All @@ -55,7 +58,7 @@ export function help () {
}

export async function handler (
opts: Pick<UniversalOptions, 'dir'> & Pick<Config, 'ignoreScripts' | 'rawConfig' | 'embedReadme'> & Partial<Pick<Config, 'extraBinPaths' | 'extraEnv'>> & {
opts: Pick<UniversalOptions, 'dir'> & Pick<Config, 'ignoreScripts' | 'rawConfig' | 'embedReadme' | 'packGzipLevel'> & Partial<Pick<Config, 'extraBinPaths' | 'extraEnv'>> & {
argv: {
original: string[]
}
Expand Down Expand Up @@ -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)
Expand All @@ -133,6 +137,7 @@ async function packPkg (opts: {
projectDir: string
embedReadme?: boolean
modulesDir: string
packGzipLevel?: number
}): Promise<void> {
const {
destFile,
Expand Down Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion releasing/plugin-commands-publishing/src/publish.ts
Expand Up @@ -133,7 +133,7 @@ export async function publish (
engineStrict?: boolean
recursive?: boolean
workspaceDir?: string
} & Pick<Config, 'allProjects' | 'gitChecks' | 'ignoreScripts' | 'publishBranch' | 'embedReadme'>,
} & Pick<Config, 'allProjects' | 'gitChecks' | 'ignoreScripts' | 'publishBranch' | 'embedReadme' | 'packGzipLevel'>,
params: string[]
) {
if (opts.gitChecks !== false && await isGitRepo()) {
Expand Down
29 changes: 29 additions & 0 deletions releasing/plugin-commands-publishing/test/pack.ts
Expand Up @@ -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)
})