Skip to content

Commit 127a146

Browse files
committed
put urls on their own line for accessibility
1 parent 45c4d7d commit 127a146

File tree

2 files changed

+75
-3
lines changed

2 files changed

+75
-3
lines changed

lib/trust-cmd.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,26 @@ class TrustCommand extends BaseCommand {
7878
if (fromPackageJson && fromPackageJson[key]) {
7979
parts.push(`(${chalk.yellow(`from package.json`)})`)
8080
}
81-
if (urls && urls[key]) {
82-
parts.push(`(${chalk.blue(urls[key])})`)
83-
}
8481
lines.push(parts.join(' '))
8582
}
8683
}
8784
if (pad) {
8885
output.standard()
8986
}
9087
output.standard(lines.join('\n'))
88+
// Print URLs on their own lines after config, following the same order as rest keys
89+
if (urls) {
90+
const urlLines = []
91+
for (const key of Object.keys(rest)) {
92+
if (urls[key]) {
93+
urlLines.push(chalk.blue(urls[key]))
94+
}
95+
}
96+
if (urlLines.length > 0) {
97+
output.standard()
98+
output.standard(urlLines.join('\n'))
99+
}
100+
}
91101
if (pad) {
92102
output.standard()
93103
}

test/lib/trust-cmd.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,3 +784,65 @@ t.test('TrustCommand - logOptions with fromPackageJson and urls', async t => {
784784
t.ok(output.includes('from package.json'), 'shows fromPackageJson indicator')
785785
t.match(output, /https:\/\/github\.com\/npm\/cli\b/, 'shows URL')
786786
})
787+
788+
t.test('TrustCommand - logOptions with no urls', async t => {
789+
const { npm, joinedOutput } = await loadMockNpm(t, {
790+
config: {
791+
'//registry.npmjs.org/:_authToken': 'test-auth-token',
792+
},
793+
})
794+
795+
class TestTrustCmd extends TrustCommand {
796+
static name = 'test'
797+
static description = 'Test command'
798+
}
799+
800+
const cmd = new TestTrustCmd(npm)
801+
802+
// Call logOptions without urls object
803+
cmd.logOptions({
804+
values: {
805+
type: 'github',
806+
id: 'test-id',
807+
repository: 'npm/cli',
808+
file: 'workflow.yml',
809+
},
810+
})
811+
const output = joinedOutput()
812+
t.ok(output.includes('repository'), 'shows repository field')
813+
t.ok(output.includes('file'), 'shows file field')
814+
t.notOk(output.includes('Links to verify manually'), 'does not show links header when no urls')
815+
})
816+
817+
t.test('TrustCommand - logOptions with urls but all values are null', async t => {
818+
const { npm, joinedOutput } = await loadMockNpm(t, {
819+
config: {
820+
'//registry.npmjs.org/:_authToken': 'test-auth-token',
821+
},
822+
})
823+
824+
class TestTrustCmd extends TrustCommand {
825+
static name = 'test'
826+
static description = 'Test command'
827+
}
828+
829+
const cmd = new TestTrustCmd(npm)
830+
831+
// Call logOptions with urls object but all values are null/undefined
832+
cmd.logOptions({
833+
values: {
834+
type: 'github',
835+
id: 'test-id',
836+
repository: 'npm/cli',
837+
file: 'workflow.yml',
838+
},
839+
urls: {
840+
repository: null,
841+
file: undefined,
842+
},
843+
})
844+
const output = joinedOutput()
845+
t.ok(output.includes('repository'), 'shows repository field')
846+
t.ok(output.includes('file'), 'shows file field')
847+
t.notOk(output.includes('Links to verify manually'), 'does not show links header when all urls are null')
848+
})

0 commit comments

Comments
 (0)