diff --git a/lib/commands/publish.js b/lib/commands/publish.js index c59588fefb241..8e14bbb312f5d 100644 --- a/lib/commands/publish.js +++ b/lib/commands/publish.js @@ -115,12 +115,14 @@ class Publish extends BaseCommand { // so that we send the latest and greatest thing to the registry // note that publishConfig might have changed as well! manifest = await this.#getManifest(spec, opts, true) - - const isPreRelease = Boolean(semver.parse(manifest.version).prerelease.length) + const force = this.npm.config.get('force') 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.') + if (!force) { + const isPreRelease = Boolean(semver.parse(manifest.version).prerelease.length) + if (isPreRelease && isDefaultTag) { + 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 diff --git a/test/lib/commands/publish.js b/test/lib/commands/publish.js index 10dc9b33deda4..63ae6afd84ffc 100644 --- a/test/lib/commands/publish.js +++ b/test/lib/commands/publish.js @@ -854,6 +854,28 @@ t.test('prerelease dist tag', (t) => { await npm.exec('publish', []) }) + t.test('does not abort when prerelease and force', async t => { + const packageJson = { + ...pkgJson, + version: '1.0.0-0', + publishConfig: { registry: alternateRegistry }, + } + const { npm, registry } = await loadNpmWithRegistry(t, { + config: { + loglevel: 'silent', + force: true, + [`${alternateRegistry.slice(6)}/:_authToken`]: 'test-other-token', + }, + prefixDir: { + 'package.json': JSON.stringify(packageJson, null, 2), + }, + registry: alternateRegistry, + authorization: 'test-other-token', + }) + registry.publish(pkg, { packageJson }) + await npm.exec('publish', []) + }) + t.end() })