Skip to content

Commit

Permalink
fix: error message updates
Browse files Browse the repository at this point in the history
  • Loading branch information
reggi committed Dec 6, 2024
1 parent 80c87f1 commit ceb143f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class Publish extends BaseCommand {
const isDefaultTag = this.npm.config.isDefault('tag')

if (isPreRelease && isDefaultTag) {
throw new Error('You must specify a tag using --tag when publishing a prerelease version')
throw new Error('You must specify a tag using --tag when publishing a prerelease version.')
}

// If we are not in JSON mode then we show the user the contents of the tarball
Expand Down Expand Up @@ -161,7 +161,8 @@ class Publish extends BaseCommand {
const latestSemverIsGreater = !!latestVersion && semver.gte(latestVersion, manifest.version)

if (latestSemverIsGreater && isDefaultTag) {
throw new Error('Cannot publish a lower version without an explicit tag.')
/* eslint-disable-next-line max-len */
throw new Error(`Cannot implicitly apply the "latest" tag because published version ${latestVersion} is higher than the new version ${manifest.version}. You must specify a tag using --tag.`)
}

const access = opts.access === null ? 'default' : opts.access
Expand Down
3 changes: 2 additions & 1 deletion test/lib/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,8 @@ t.test('latest dist tag', (t) => {
registry.publish(pkg, { noPut: true, packuments })
await t.rejects(async () => {
await npm.exec('publish', [])
}, new Error('Cannot publish a lower version without an explicit tag.'))
/* eslint-disable-next-line max-len */
}, new Error('Cannot implicitly apply the "latest" tag because published version 100.0.0 is higher than the new version 99.0.0. You must specify a tag using --tag.'))
})

t.test('ALLOWS publish when latest is HIGHER than publishing version and flag', async t => {
Expand Down

0 comments on commit ceb143f

Please sign in to comment.