fix: pnpm publish -r --dry-run

close #2712
PR #2715
This commit is contained in:
Zoltan Kochan
2020-07-26 15:07:13 +03:00
committed by GitHub
parent e8a6305282
commit d44ff97f82
3 changed files with 33 additions and 2 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/plugin-commands-publishing": patch
---
`pnpm publish -r --dry-run` should not publish anything to the registry.

View File

@@ -24,6 +24,7 @@ Partial<Pick<Config,
| 'tag'
| 'ca'
| 'cert'
| 'dryRun'
| 'extraBinPaths'
| 'fetchRetries'
| 'fetchRetryFactor'
@@ -73,7 +74,13 @@ export default async function (
}, pkg.manifest.name, pkg.manifest.version))
})
const publishedPkgDirs = new Set(pkgsToPublish.map(({ dir }) => dir))
const access = opts.cliOptions['access'] ? ['--access', opts.cliOptions['access']] : []
const appendedArgs = []
if (opts.cliOptions['access']) {
appendedArgs.push(`--access=${opts.cliOptions['access']}`)
}
if (opts.dryRun) {
appendedArgs.push('--dry-run')
}
const chunks = sortPackages(opts.selectedProjectsGraph)
for (const chunk of chunks) {
for (const pkgDir of chunk) {
@@ -89,7 +96,7 @@ export default async function (
'pnpm-temp',
'--registry',
pickRegistryForPackage(opts.registries, pkg.manifest.name!),
...access,
...appendedArgs,
],
},
gitChecks: false,

View File

@@ -2,6 +2,7 @@ import { readProjects } from '@pnpm/filter-workspace-packages'
import { publish } from '@pnpm/plugin-commands-publishing'
import { preparePackages } from '@pnpm/prepare'
import { REGISTRY_MOCK_PORT } from '@pnpm/registry-mock'
import crossSpawn = require('cross-spawn')
import execa = require('execa')
import fs = require('mz/fs')
import test = require('tape')
@@ -66,6 +67,24 @@ test('recursive publish', async (t) => {
await fs.writeFile('.npmrc', CREDENTIALS, 'utf8')
t.comment('packages not published, when dryRun is true')
await publish.handler({
...DEFAULT_OPTS,
...await readProjects(process.cwd(), []),
dir: process.cwd(),
dryRun: true,
recursive: true,
}, [])
{
const { status } = crossSpawn.sync('npm', ['view', pkg1.name, 'versions', '--registry', `http://localhost:${REGISTRY_MOCK_PORT}`, '--json'])
t.deepEqual(status, 1)
}
{
const { status } = crossSpawn.sync('npm', ['view', pkg2.name, 'versions', '--registry', `http://localhost:${REGISTRY_MOCK_PORT}`, '--json'])
t.deepEqual(status, 1)
}
await publish.handler({
...DEFAULT_OPTS,
...await readProjects(process.cwd(), []),