diff --git a/lib/commands/publish.js b/lib/commands/publish.js index a18b6f0c81bcc..f912f59d55f6a 100644 --- a/lib/commands/publish.js +++ b/lib/commands/publish.js @@ -194,7 +194,7 @@ class Publish extends BaseCommand { const access = opts.access === null ? 'default' : opts.access const verb = this.isStage ? 'Staging' : 'Publishing' - let msg = `${verb} to ${outputRegistry} with tag ${defaultTag} and ${access} access` + let msg = `${verb} to ${outputRegistry} with tag ${opts.defaultTag} and ${access} access` if (dryRun) { msg = `${msg} (dry-run)` } @@ -249,7 +249,7 @@ class Publish extends BaseCommand { ? `+ ${pkgContents.id} (staged with id ${stageId})` : `+ ${pkgContents.id} (staged)` output.standard(stagedMsg, { [META]: true, redact: false }) - log.notice(this.#command, `package ${pkgContents.id} has been staged with tag ${defaultTag}`) + log.notice(this.#command, `package ${pkgContents.id} has been staged with tag ${opts.defaultTag}`) } else { output.standard(`+ ${pkgContents.id}`) } diff --git a/test/lib/commands/publish.js b/test/lib/commands/publish.js index 9ddca285488a7..7b6cace939343 100644 --- a/test/lib/commands/publish.js +++ b/test/lib/commands/publish.js @@ -172,6 +172,54 @@ for (const allowDirectory of ['none', 'root']) { }) } +t.test('dry-run with publishConfig.tag', async t => { + const packageJson = { + ...pkgJson, + publishConfig: { tag: 'next' }, + } + const { joinedOutput, npm, logs, registry } = await loadNpmWithRegistry(t, { + config: { + 'dry-run': true, + ...auth, + }, + prefixDir: { + 'package.json': JSON.stringify(packageJson, null, 2), + }, + authorization: token, + }) + registry.publish(pkg, { noPut: true }) + await npm.exec('publish', []) + t.equal(joinedOutput(), `+ ${pkg}@1.0.0`) + t.ok( + logs.notice.includes('Publishing to https://registry.npmjs.org/ with tag next and default access (dry-run)'), + 'notice reports the publishConfig tag' + ) +}) + +t.test('CLI --tag overrides publishConfig.tag in notice', async t => { + const packageJson = { + ...pkgJson, + publishConfig: { tag: 'next' }, + } + const { npm, logs, registry } = await loadNpmWithRegistry(t, { + config: { + 'dry-run': true, + ...auth, + }, + argv: ['--tag', 'beta'], + prefixDir: { + 'package.json': JSON.stringify(packageJson, null, 2), + }, + authorization: token, + }) + registry.publish(pkg, { noPut: true }) + await npm.exec('publish', []) + t.ok( + logs.notice.includes('Publishing to https://registry.npmjs.org/ with tag beta and default access (dry-run)'), + 'notice reports the CLI tag' + ) +}) + t.test('foreground-scripts defaults to true', async t => { const { outputs, npm, logs, registry } = await loadNpmWithRegistry(t, { config: { diff --git a/test/lib/commands/stage/index.js b/test/lib/commands/stage/index.js index 127c0ea825288..8a82fe5a1095c 100644 --- a/test/lib/commands/stage/index.js +++ b/test/lib/commands/stage/index.js @@ -267,6 +267,30 @@ t.test('respects publishConfig', async t => { t.match(logs.warn, [/Unknown publishConfig/]) }) +t.test('reports publishConfig.tag in notices', async t => { + const { npm, logs } = await loadMockNpm(t, { + config: authConfig, + prefixDir: { + 'package.json': JSON.stringify({ + ...pkgJson, + publishConfig: { tag: 'next' }, + }), + }, + }) + const registry = new MockRegistry({ + tap: t, + registry: npm.config.get('registry'), + authorization: token, + }) + registry.nock.post('/-/stage/package/@npmcli%2ftest-package').reply(201, {}) + await npm.exec('stage', ['publish']) + t.ok(logs.notice.some(n => /Staging to .* with tag next and default access/.test(n)), 'staging notice reports the publishConfig tag') + t.ok( + logs.notice.includes(`stage package ${pkg}@1.0.0 has been staged with tag next`), + 'staged notice reports the publishConfig tag' + ) +}) + t.test('warns about auto-corrected package.json errors', async t => { const { npm, logs } = await loadMockNpm(t, { config: authConfig,