Skip to content

Commit 71b8747

Browse files
committed
fix: output configured registry during publish
Closes: npm/statusboard#416
1 parent 08c6639 commit 71b8747

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

lib/commands/publish.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,15 @@ class Publish extends BaseCommand {
104104
const resolved = npa.resolve(manifest.name, manifest.version)
105105
const registry = npmFetch.pickRegistry(resolved, opts)
106106
const creds = this.npm.config.getCredentialsByURI(registry)
107+
const outputRegistry = replaceInfo(registry)
107108
if (!creds.token && !creds.username) {
108-
throw Object.assign(new Error('This command requires you to be logged in.'), {
109-
code: 'ENEEDAUTH',
110-
})
109+
throw Object.assign(
110+
new Error(`This command requires you to be logged in to ${outputRegistry}`), {
111+
code: 'ENEEDAUTH',
112+
}
113+
)
111114
}
115+
log.notice('', `Publishing to ${outputRegistry}`)
112116
await otplease(opts, opts => libpub(manifest, tarballData, opts))
113117
}
114118

test/lib/commands/publish.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,10 @@ t.test('can publish a tarball', async t => {
341341

342342
t.test('should check auth for default registry', async t => {
343343
t.plan(2)
344-
const Publish = t.mock('../../../lib/commands/publish.js')
345344
const npm = mockNpm()
345+
const registry = npm.config.get('registry')
346+
const errorMessage = `This command requires you to be logged in to ${registry}`
347+
const Publish = t.mock('../../../lib/commands/publish.js')
346348
npm.config.getCredentialsByURI = uri => {
347349
t.same(uri, npm.config.get('registry'), 'gets credentials for expected registry')
348350
return {}
@@ -351,14 +353,15 @@ t.test('should check auth for default registry', async t => {
351353

352354
await t.rejects(
353355
publish.exec([]),
354-
{ message: 'This command requires you to be logged in.', code: 'ENEEDAUTH' },
356+
{ message: errorMessage, code: 'ENEEDAUTH' },
355357
'throws when not logged in'
356358
)
357359
})
358360

359361
t.test('should check auth for configured registry', async t => {
360362
t.plan(2)
361363
const registry = 'https://some.registry'
364+
const errorMessage = 'This command requires you to be logged in to https://some.registry'
362365
const Publish = t.mock('../../../lib/commands/publish.js')
363366
const npm = mockNpm({
364367
flatOptions: { registry },
@@ -371,14 +374,15 @@ t.test('should check auth for configured registry', async t => {
371374

372375
await t.rejects(
373376
publish.exec([]),
374-
{ message: 'This command requires you to be logged in.', code: 'ENEEDAUTH' },
377+
{ message: errorMessage, code: 'ENEEDAUTH' },
375378
'throws when not logged in'
376379
)
377380
})
378381

379382
t.test('should check auth for scope specific registry', async t => {
380383
t.plan(2)
381384
const registry = 'https://some.registry'
385+
const errorMessage = 'This command requires you to be logged in to https://some.registry'
382386
const testDir = t.testdir({
383387
'package.json': JSON.stringify(
384388
{
@@ -402,7 +406,7 @@ t.test('should check auth for scope specific registry', async t => {
402406

403407
await t.rejects(
404408
publish.exec([testDir]),
405-
{ message: 'This command requires you to be logged in.', code: 'ENEEDAUTH' },
409+
{ message: errorMessage, code: 'ENEEDAUTH' },
406410
'throws when not logged in'
407411
)
408412
})
@@ -735,7 +739,7 @@ t.test('private workspaces', async t => {
735739
})
736740

737741
t.test('unexpected error', async t => {
738-
t.plan(1)
742+
t.plan(2)
739743

740744
const Publish = t.mock('../../../lib/commands/publish.js', {
741745
...mocks,
@@ -749,7 +753,9 @@ t.test('private workspaces', async t => {
749753
},
750754
},
751755
'proc-log': {
752-
notice () {},
756+
notice (__, msg) {
757+
t.match(msg, 'Publishing to https://registry.npmjs.org/')
758+
},
753759
verbose () {},
754760
},
755761
})

0 commit comments

Comments
 (0)