Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent adding invalid dist-tag #7195

Merged
merged 1 commit into from
Feb 1, 2024
Merged
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
3 changes: 3 additions & 0 deletions lib/commands/dist-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ class DistTag extends BaseCommand {

log.verbose('dist-tag add', defaultTag, 'to', spec.name + '@' + version)

// make sure new spec with tag is valid, this will throw if invalid
npa(`${spec.name}@${defaultTag}`)

if (!spec.name || !version || !defaultTag) {
throw this.usageError('must provide a spec with a name and version, and a tag to add')
}
Expand Down
9 changes: 9 additions & 0 deletions test/lib/commands/dist-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,15 @@ t.test('add missing pkg name', async t => {
)
})

t.test('add invalid tag', async t => {
const { distTag } = await mockDist(t)
await t.rejects(
distTag.exec(['add', '@tag']),
{ code: 'EINVALIDTAGNAME' },
'should exit with invalid tag name error'
)
})

t.test('set existing version', async t => {
const { distTag, logs } = await mockDist(t)
await distTag.exec(['set', '@scoped/another@0.6.0', 'b'])
Expand Down
Loading