Skip to content

Commit a5ac845

Browse files
MiniGodbcoe
authored andcommitted
fix: stop suggesting npm publish if package.json was not updated (#319)
1 parent aed52f2 commit a5ac845

File tree

4 files changed

+15
-12
lines changed

4 files changed

+15
-12
lines changed

lib/lifecycles/bump.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,8 @@ function bumpVersion (releaseAs, currentVersion, args) {
162162
*/
163163
function updateConfigs (args, newVersion) {
164164
const dotgit = DotGitignore()
165-
Bump.pkgFiles.concat(Bump.lockFiles).forEach((filename) => {
166-
configsToUpdate[path.resolve(process.cwd(), filename)] = false
167-
})
168-
Object.keys(configsToUpdate).forEach(function (configPath) {
165+
Bump.pkgFiles.concat(Bump.lockFiles).forEach(function (filename) {
166+
let configPath = path.resolve(process.cwd(), filename)
169167
try {
170168
if (dotgit.ignore(configPath)) return
171169
let stat = fs.lstatSync(configPath)
@@ -174,13 +172,12 @@ function updateConfigs (args, newVersion) {
174172
let indent = detectIndent(data).indent
175173
let newline = detectNewline(data)
176174
let config = JSON.parse(data)
177-
let filename = path.basename(configPath)
178175
checkpoint(args, 'bumping version in ' + filename + ' from %s to %s', [config.version, newVersion])
179176
config.version = newVersion
180177
writeFile(args, configPath, stringifyPackage(config, indent, newline))
181178
// flag any config files that we modify the version # for
182179
// as having been updated.
183-
configsToUpdate[configPath] = true
180+
configsToUpdate[filename] = true
184181
}
185182
} catch (err) {
186183
if (err.code !== 'ENOENT') console.warn(err.message)

lib/lifecycles/commit.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ function execCommit (args, newVersion) {
2525
// commit any of the config files that we've updated
2626
// the version # for.
2727
Object.keys(bump.getUpdatedConfigs()).forEach(function (p) {
28-
if (bump.getUpdatedConfigs()[p]) {
29-
msg += ' and %s'
30-
paths.unshift(path.basename(p))
31-
toAdd += ' ' + path.relative(process.cwd(), p)
32-
}
28+
msg += ' and %s'
29+
paths.unshift(p)
30+
toAdd += ' ' + path.relative(process.cwd(), p)
3331
})
3432

3533
if (args.commitAll) {

lib/lifecycles/tag.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const bump = require('../lifecycles/bump')
12
const chalk = require('chalk')
23
const checkpoint = require('../checkpoint')
34
const figures = require('figures')
@@ -28,7 +29,7 @@ function execTag (newVersion, pkgPrivate, args) {
2829
.then(() => runExec('', 'git rev-parse --abbrev-ref HEAD'))
2930
.then((currentBranch) => {
3031
let message = 'git push --follow-tags origin ' + currentBranch.trim()
31-
if (pkgPrivate !== true) {
32+
if (pkgPrivate !== true && bump.getUpdatedConfigs()['package.json']) {
3233
message += ' && npm publish'
3334
if (args.prerelease !== undefined) {
3435
if (args.prerelease === '') {

test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,6 +1030,13 @@ describe('standard-version', function () {
10301030
output.stdout.should.include('v5.1.0')
10311031
})
10321032
})
1033+
1034+
it('does not display `npm publish` if there is no package.json', function () {
1035+
shell.rm('package.json')
1036+
const result = execCli()
1037+
result.code.should.equal(0)
1038+
result.stdout.should.not.match(/npm publish/)
1039+
})
10331040
})
10341041

10351042
describe('configuration', () => {

0 commit comments

Comments
 (0)