Skip to content

Commit d0673e7

Browse files
committed
fix: print version number that updater.writeVersion returns
Closes expo-community/standard-version-expo#18. Closes expo-community/standard-version-expo#10.
1 parent f6a7430 commit d0673e7

File tree

5 files changed

+46
-3
lines changed

5 files changed

+46
-3
lines changed

lib/lifecycles/bump.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,17 @@ function updateConfigs (args, newVersion) {
149149

150150
if (!stat.isFile()) return
151151
const contents = fs.readFileSync(configPath, 'utf8')
152+
const newContents = updater.updater.writeVersion(contents, newVersion)
153+
const realNewVersion = updater.updater.readVersion(newContents)
152154
checkpoint(
153155
args,
154156
'bumping version in ' + updater.filename + ' from %s to %s',
155-
[updater.updater.readVersion(contents), newVersion]
157+
[updater.updater.readVersion(contents), realNewVersion]
156158
)
157159
writeFile(
158160
args,
159161
configPath,
160-
updater.updater.writeVersion(contents, newVersion)
162+
newContents
161163
)
162164
// flag any config files that we modify the version # for
163165
// as having been updated.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"mockery": "^2.1.0",
6666
"nyc": "^14.1.1",
6767
"shelljs": "^0.8.4",
68-
"std-mocks": "^1.0.1"
68+
"std-mocks": "^1.0.1",
69+
"strip-ansi": "^6.0.0"
6970
}
7071
}

test/core.spec.js

+32
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const { Readable } = require('stream')
99
const mockFS = require('mock-fs')
1010
const mockery = require('mockery')
1111
const stdMocks = require('std-mocks')
12+
const stripAnsi = require('strip-ansi')
1213

1314
const cli = require('../command')
1415
const formatCommitMessage = require('../lib/format-commit-message')
@@ -526,6 +527,37 @@ describe('standard-version', function () {
526527
})
527528
fs.readFileSync('VERSION_TRACKER.txt', 'utf-8').should.equal('1.1.0')
528529
})
530+
531+
it('displays the new version from custom bumper with --dry-run', async function () {
532+
const updater = 'increment-updater.js'
533+
const updaterModule = require('./mocks/updater/increment-updater')
534+
mock({
535+
bump: 'minor',
536+
fs: {
537+
'increment-version.txt': fs.readFileSync(
538+
'./test/mocks/increment-version.txt'
539+
)
540+
}
541+
})
542+
mockery.registerMock(resolve(process.cwd(), updater), updaterModule)
543+
544+
const origInfo = console.info
545+
const capturedOutput = []
546+
console.info = (...args) => {
547+
capturedOutput.push(...args)
548+
origInfo(...args)
549+
}
550+
try {
551+
await exec({
552+
bumpFiles: [{ filename: 'increment-version.txt', updater: 'increment-updater.js' }],
553+
dryRun: true
554+
})
555+
const logOutput = capturedOutput.join(' ')
556+
stripAnsi(logOutput).should.include('bumping version in increment-version.txt from 1 to 2')
557+
} finally {
558+
console.info = origInfo
559+
}
560+
})
529561
})
530562

531563
describe('custom `packageFiles` support', function () {

test/mocks/increment-version.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports.readVersion = function (contents) {
2+
return Number.parseInt(contents)
3+
}
4+
5+
module.exports.writeVersion = function (contents, version) {
6+
return this.readVersion(contents) + 1
7+
}

0 commit comments

Comments
 (0)