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: ensure SemVer instance passed to inc are not modified #427

Merged
merged 2 commits into from Apr 11, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion functions/inc.js
Expand Up @@ -7,7 +7,10 @@ const inc = (version, release, options, identifier) => {
}

try {
return new SemVer(version, options).inc(release, identifier).version
return new SemVer(
version instanceof SemVer ? version.version : version,
options
).inc(release, identifier).version
} catch (er) {
return null
}
Expand Down
10 changes: 10 additions & 0 deletions test/functions/inc.js
Expand Up @@ -10,10 +10,20 @@ test('increment versions test', (t) => {
t.equal(found, wanted, `${cmd} === ${wanted}`)

const parsed = parse(pre, options)
const parsedAsInput = parse(pre, options)
if (wanted) {
parsed.inc(what, id)
t.equal(parsed.version, wanted, `${cmd} object version updated`)
t.equal(parsed.raw, wanted, `${cmd} object raw field updated`)

const preIncObject = JSON.stringify(parsedAsInput)
inc(parsedAsInput, what, options, id)
const postIncObject = JSON.stringify(parsedAsInput)
t.equal(
postIncObject,
preIncObject,
`${cmd} didn't modify its input`
)
} else if (parsed) {
t.throws(() => {
parsed.inc(what, id)
Expand Down