@@ -81,18 +81,63 @@ echo "Releasing from branch: ${CURRENT_BRANCH}"
8181
8282CURRENT_VERSION=" $( node -p " require('./package.json').version" ) "
8383NEW_VERSION=" $( node -e "
84- const semver = require('semver')
8584 const current = require('./package.json').version
8685 const arg = process.argv[1]
87- const next = semver.valid(arg) || semver.inc(current, arg)
88- if (!next) {
86+ const exactVersionPattern = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/
87+
88+ const parseCoreVersion = (value) => {
89+ const match = value.match(/^(\d+)\.(\d+)\.(\d+)/)
90+ if (!match) {
91+ return null
92+ }
93+
94+ return {
95+ major: Number(match[1]),
96+ minor: Number(match[2]),
97+ patch: Number(match[3]),
98+ }
99+ }
100+
101+ let next = null
102+
103+ if (exactVersionPattern.test(arg)) {
104+ next = arg
105+ } else {
106+ const parsed = parseCoreVersion(current)
107+
108+ if (!parsed) {
109+ process.exit(1)
110+ }
111+
112+ if (arg === 'major') {
113+ next = String(parsed.major + 1) + '.0.0'
114+ } else if (arg === 'minor') {
115+ next = parsed.major + '.' + String(parsed.minor + 1) + '.0'
116+ } else if (arg === 'patch') {
117+ next = parsed.major + '.' + parsed.minor + '.' + String(parsed.patch + 1)
118+ }
119+ }
120+
121+ if (next === null) {
89122 process.exit(1)
90123 }
124+
91125 process.stdout.write(next)
92126" " ${VERSION_ARG} " ) "
93127TAG=" v${NEW_VERSION} "
128+ ALLOW_SAME_VERSION=false
129+
130+ if [[ " ${VERSION_ARG} " == " ${CURRENT_VERSION} " ]]; then
131+ ALLOW_SAME_VERSION=true
132+ fi
94133
95134if [[ " ${DRY_RUN} " == " true" ]]; then
135+ NPM_VERSION_COMMAND=" npm version \" ${VERSION_ARG} \" --no-git-tag-version"
136+
137+ if [[ " ${ALLOW_SAME_VERSION} " == " true" ]]; then
138+ NPM_VERSION_COMMAND=" ${NPM_VERSION_COMMAND} --allow-same-version"
139+ fi
140+
96141 cat << EOF
97142Dry run only. No files or tags will be changed.
98143
@@ -104,7 +149,7 @@ Will push: ${PUSH}
104149Will publish: ${PUBLISH}
105150
106151Commands:
107- npm version " ${VERSION_ARG} " --no-git-tag-version
152+ ${NPM_VERSION_COMMAND}
108153 git add package.json$( [[ -f yarn.lock ]] && printf ' yarn.lock' ) $( [[ -f package-lock.json ]] && printf ' package-lock.json' )
109154 git commit -m "release: ${TAG} "
110155 git tag "${TAG} "
124169 exit 0
125170fi
126171
127- npm version " ${VERSION_ARG} " --no-git-tag-version
172+ NPM_VERSION_ARGS=(" ${VERSION_ARG} " --no-git-tag-version)
173+
174+ if [[ " ${ALLOW_SAME_VERSION} " == " true" ]]; then
175+ NPM_VERSION_ARGS+=(--allow-same-version)
176+ fi
177+
178+ npm version " ${NPM_VERSION_ARGS[@]} "
128179
129180git add package.json
130181
0 commit comments