diff --git a/.changeset/proud-beds-clean.md b/.changeset/proud-beds-clean.md new file mode 100644 index 0000000000..f957ce8a25 --- /dev/null +++ b/.changeset/proud-beds-clean.md @@ -0,0 +1,5 @@ +--- +"@pnpm/plugin-commands-publishing": patch +--- + +`pnpm publish -r --dry-run` should not publish anything to the registry. diff --git a/packages/plugin-commands-publishing/src/recursivePublish.ts b/packages/plugin-commands-publishing/src/recursivePublish.ts index e493878616..d7aa03e987 100644 --- a/packages/plugin-commands-publishing/src/recursivePublish.ts +++ b/packages/plugin-commands-publishing/src/recursivePublish.ts @@ -24,6 +24,7 @@ Partial 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, diff --git a/packages/plugin-commands-publishing/test/recursivePublish.ts b/packages/plugin-commands-publishing/test/recursivePublish.ts index 23b1846851..a39499386e 100644 --- a/packages/plugin-commands-publishing/test/recursivePublish.ts +++ b/packages/plugin-commands-publishing/test/recursivePublish.ts @@ -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(), []),