mirror of
https://github.com/pnpm/pnpm.git
synced 2025-12-23 23:29:17 -05:00
feat(pack): add pack-gzip-level (#6406)
This options allows specifying custom compression level. close #6393 --------- Co-authored-by: Zoltan Kochan <z@kochan.io>
This commit is contained in:
7
.changeset/khaki-bats-learn.md
Normal file
7
.changeset/khaki-bats-learn.md
Normal file
@@ -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).
|
||||
@@ -159,6 +159,7 @@ export interface Config {
|
||||
dedupePeerDependents?: boolean
|
||||
patchesDir?: string
|
||||
ignoreWorkspaceCycles?: boolean
|
||||
packGzipLevel?: number
|
||||
|
||||
registries: Registries
|
||||
ignoreWorkspaceRootCheck: boolean
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<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[]
|
||||
}
|
||||
@@ -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<void> {
|
||||
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', () => {
|
||||
|
||||
@@ -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()) {
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user