MCPcopy
hub / github.com/npm/node-semver / inc

Method inc

classes/semver.js:210–347  ·  view source on GitHub ↗
(release, identifier, identifierBase)

Source from the content-addressed store, hash-verified

208 // preminor will bump the version up to the next minor release, and immediately
209 // down to pre-release. premajor and prepatch work the same way.
210 inc (release, identifier, identifierBase) {
211 if (release.startsWith('pre')) {
212 if (!identifier && identifierBase === false) {
213 throw new Error('invalid increment argument: identifier is empty')
214 }
215 // Avoid an invalid semver results
216 if (identifier) {
217 const match = `-${identifier}`.match(this.options.loose ? re[t.PRERELEASELOOSE] : re[t.PRERELEASE])
218 if (!match || match[1] !== identifier) {
219 throw new Error(`invalid identifier: ${identifier}`)
220 }
221 }
222 }
223
224 switch (release) {
225 case 'premajor':
226 this.prerelease.length = 0
227 this.patch = 0
228 this.minor = 0
229 this.major++
230 this.inc('pre', identifier, identifierBase)
231 break
232 case 'preminor':
233 this.prerelease.length = 0
234 this.patch = 0
235 this.minor++
236 this.inc('pre', identifier, identifierBase)
237 break
238 case 'prepatch':
239 // If this is already a prerelease, it will bump to the next version
240 // drop any prereleases that might already exist, since they are not
241 // relevant at this point.
242 this.prerelease.length = 0
243 this.inc('patch', identifier, identifierBase)
244 this.inc('pre', identifier, identifierBase)
245 break
246 // If the input is a non-prerelease version, this acts the same as
247 // prepatch.
248 case 'prerelease':
249 if (this.prerelease.length === 0) {
250 this.inc('patch', identifier, identifierBase)
251 }
252 this.inc('pre', identifier, identifierBase)
253 break
254 case 'release':
255 if (this.prerelease.length === 0) {
256 throw new Error(`version ${this.raw} is not a prerelease`)
257 }
258 this.prerelease.length = 0
259 break
260
261 case 'major':
262 // If this is a pre-major version, bump up to the same major version.
263 // Otherwise increment major.
264 // 1.0.0-5 bumps to 1.0.0
265 // 1.1.0 bumps to 2.0.0
266 if (
267 this.minor !== 0 ||

Callers 4

semver.jsFile · 0.80
inc.jsFile · 0.80
incFunction · 0.80
mainFunction · 0.80

Calls 2

formatMethod · 0.95
isPrereleaseIdentifierFunction · 0.85

Tested by

no test coverage detected