Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)`
}
Expand Down Expand Up @@ -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}`)
}
Expand Down
48 changes: 48 additions & 0 deletions test/lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
24 changes: 24 additions & 0 deletions test/lib/commands/stage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading