@vltpkg/semver 1.0.0-rc.2 → 1.0.0-rc.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,367 +0,0 @@
1
- import { syntaxError, typeError } from '@vltpkg/error-cause';
2
- import { fastSplit } from '@vltpkg/fast-split';
3
- const maybeNumber = (s) => {
4
- if (!/^[0-9]+$/.test(s))
5
- return s;
6
- const n = Number(s);
7
- return n <= Number.MAX_SAFE_INTEGER ? n : s;
8
- };
9
- const safeNumber = (s, version, field) => {
10
- const n = Number(s);
11
- if (n > Number.MAX_SAFE_INTEGER) {
12
- throw invalidVersion(version, `invalid ${field}, must be <= ${Number.MAX_SAFE_INTEGER}`);
13
- }
14
- return n;
15
- };
16
- const re = {
17
- prefix: /^[ v=]+/,
18
- main: /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/,
19
- prerelease: /-([0-9a-zA-Z_.-]+)(?:$|\+)/,
20
- build: /\+([0-9a-zA-Z_.-]+)$/,
21
- full: /^[ v=]*(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-([0-9a-zA-Z_.-]+))?(?:\+([0-9a-zA-Z_.-]+))?$/,
22
- };
23
- const invalidVersion = (version, message) => {
24
- const er = syntaxError(`invalid version: ${message}`, { version }, Version);
25
- return er;
26
- };
27
- /**
28
- * Values of valid increment types.
29
- */
30
- export const versionIncrements = [
31
- 'major',
32
- 'minor',
33
- 'patch',
34
- 'pre',
35
- 'premajor',
36
- 'preminor',
37
- 'prepatch',
38
- 'prerelease',
39
- ];
40
- /**
41
- * A parsed object representation of a SemVer version string
42
- *
43
- * This is a bit less forgiving than node-semver, in that prerelease versions
44
- * MUST start with '-'. Otherwise, the allowed syntax is identical.
45
- */
46
- export class Version {
47
- /** raw string provided to create this Version */
48
- raw;
49
- /** major version number */
50
- major;
51
- /** minor version number */
52
- minor;
53
- /** patch version number */
54
- patch;
55
- /**
56
- * List of `'.'`-separated strings and numbers indicating that this
57
- * version is a prerelease.
58
- *
59
- * This is undefined if the version does not have a prerelease section.
60
- */
61
- prerelease;
62
- /**
63
- * List of `'.'`-separated strings in the `build` section.
64
- *
65
- * This is undefined if the version does not have a build.
66
- */
67
- build;
68
- /** Canonical strict form of this version */
69
- toString() {
70
- return `${this.major}.${this.minor}.${this.patch}${this.prerelease ? '-' + this.prerelease.join('.') : ''}${this.build ? '+' + this.build.join('.') : ''}`;
71
- }
72
- /** Generate a `Version` object from a SemVer string */
73
- static parse(version) {
74
- version = version.replace(re.prefix, '').trim();
75
- if (version.length > 256) {
76
- throw invalidVersion(version, 'must be less than 256 characters');
77
- }
78
- const parsed = re.full.exec(version);
79
- if (!parsed) {
80
- const main = re.main.exec(version);
81
- if (!main) {
82
- throw invalidVersion(version, 'no Major.minor.patch tuple present');
83
- }
84
- else {
85
- throw invalidVersion(version, 'invalid build or patch section');
86
- }
87
- }
88
- const [_, major_, minor_, patch_, prerelease, build] = parsed;
89
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
90
- const major = safeNumber(major_, version, 'major');
91
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
92
- const minor = safeNumber(minor_, version, 'minor');
93
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
94
- const patch = safeNumber(patch_, version, 'patch');
95
- return new Version(version, major, minor, patch, prerelease, build);
96
- }
97
- constructor(version, major, minor, patch, prerelease, build) {
98
- this.raw = version;
99
- this.major = major;
100
- this.minor = minor;
101
- this.patch = patch;
102
- // has prerelease and/or build
103
- if (prerelease) {
104
- this.prerelease = fastSplit(prerelease, '.', -1, c => {
105
- if (!c) {
106
- throw invalidVersion(version, 'invalid prerelease, empty identifiers not allowed');
107
- }
108
- return maybeNumber(c);
109
- });
110
- }
111
- if (build) {
112
- this.build = fastSplit(build, '.', -1, c => {
113
- if (!c) {
114
- throw invalidVersion(version, 'invalid build metadata, empty identifiers not allowed');
115
- }
116
- });
117
- }
118
- }
119
- /**
120
- * Return 1 if this is > the provided version, -1 if we're less, or 0 if
121
- * they are equal.
122
- *
123
- * No special handling for prerelease versions, this is just a precedence
124
- * comparison.
125
- *
126
- * This can be used to sort a list of versions by precedence:
127
- *
128
- * ```ts
129
- * const versions: Version[] = getVersionsSomehow()
130
- * const sorted = versions.sort((a, b) => a.compare(b))
131
- * ```
132
- */
133
- compare(v) {
134
- if (this.major > v.major)
135
- return 1;
136
- if (this.major < v.major)
137
- return -1;
138
- if (this.minor > v.minor)
139
- return 1;
140
- if (this.minor < v.minor)
141
- return -1;
142
- if (this.patch > v.patch)
143
- return 1;
144
- if (this.patch < v.patch)
145
- return -1;
146
- // main tuple is equal now
147
- // if the version has no pr, we're definitely less than or equal to
148
- if (!v.prerelease?.length)
149
- return !this.prerelease?.length ? 0 : -1;
150
- // v has a pr. if we don't, we're > it
151
- if (!this.prerelease?.length)
152
- return 1;
153
- // we both have prereleases
154
- const len = Math.max(this.prerelease.length, v.prerelease.length);
155
- const me = this.prerelease;
156
- const thee = v.prerelease;
157
- for (let i = 0; i < len; i++) {
158
- const m = me[i];
159
- const t = thee[i];
160
- if (m === t)
161
- continue;
162
- // having a field is > not having it
163
- if (t === undefined)
164
- return 1;
165
- if (m === undefined)
166
- return -1;
167
- // string parts are higher precedence than
168
- if (typeof m !== typeof t) {
169
- return typeof m === 'string' ? 1 : -1;
170
- }
171
- return m > t ? 1 : -1;
172
- }
173
- return 0;
174
- }
175
- /**
176
- * The inverse of compare, for sorting version lists in reverse order
177
- */
178
- rcompare(v) {
179
- return -1 * this.compare(v);
180
- }
181
- /** true if this version is > the argument */
182
- greaterThan(v) {
183
- return this.compare(v) === 1;
184
- }
185
- /** true if this version is >= the argument */
186
- greaterThanEqual(v) {
187
- return this.compare(v) > -1;
188
- }
189
- /** true if this version is < the argument */
190
- lessThan(v) {
191
- return this.compare(v) === -1;
192
- }
193
- /** true if this version is &lt;= the argument */
194
- lessThanEqual(v) {
195
- return this.compare(v) < 1;
196
- }
197
- /** true if these two versions have equal SemVer precedence */
198
- equals(v) {
199
- return this.compare(v) === 0;
200
- }
201
- /** just compare the M.m.p parts of the version */
202
- tupleEquals(v) {
203
- return (this.major === v.major &&
204
- this.minor === v.minor &&
205
- this.patch === v.patch);
206
- }
207
- /** true if this version satisfies the range */
208
- satisfies(r) {
209
- return r.test(this);
210
- }
211
- /**
212
- * Increment the version in place, in the manner specified.
213
- *
214
- * Part behaviors:
215
- *
216
- * - `'major'` If the version is a `M.0.0-...` version with a prerelease, then
217
- * simply drop the prerelease. Otherwise, set the minor and patch to 0, and
218
- * increment the major. So `1.0.0-beta` becomes `1.0.0`, and `1.2.3` becomes
219
- * `2.0.0`
220
- *
221
- * - `'minor'` If the version is a `M.m.0-...` version with a prerelease, then
222
- * simply drop the prerelease. Otherwise, set the patch to 0, and increment the
223
- * minor. So `1.2.0-beta` becomes `1.2.0`, and `1.2.3` becomes `1.3.0`.
224
- *
225
- * - `'patch'` If the version has a prerelease, then simply drop the
226
- * prerelease. Otherwise, increment the patch value. So `1.2.3-beta` becomes
227
- * `1.2.3` and `1.2.3` becomes `1.2.4`.
228
- *
229
- * - `'premajor'` Set the patch and minor versions to `0`, increment the major
230
- * version, and add a prerelease, using the optional identifier.
231
- *
232
- * - `'preminor'` Set the patch version to `0`, increment the minor version,
233
- * and add a prerelease, using the optional identifier.
234
- *
235
- * - `'prepatch'` If a prerelease is already present, increment the patch
236
- * version, otherwise leave it untouched, and add a prerelease, using the
237
- * optional identifier.
238
- *
239
- * - `'prerelease'` If a prerelease version is present, then behave the same as
240
- * `'prepatch'`. Otherwise, add a prerelease, using the optional identifier.
241
- *
242
- * - `'pre'` This is mostly for use by the other prerelease incrementers.
243
- *
244
- * - If a prerelease identifier is provided:
245
- *
246
- * Update that named portion of the prerelease. For example,
247
- * `inc('1.2.3-beta.4', 'pre', 'beta')` would result in `1.2.3-beta.5`.
248
- *
249
- * If there is no prerelease identifier by that name, then replace the
250
- * prerelease with `[name]`. So `inc('1.2.3-alpha.4', 'pre', 'beta')`
251
- * would result in `1.2.3-beta`.
252
- *
253
- * If the prerelease identifer is present, but has no numeric value
254
- * following it, then add `0`. So `inc('1.2.3-beta', 'pre', 'beta')`
255
- * would result in `1.2.3-beta.0`.
256
- *
257
- * - If no prerelease identifier is provided:
258
- *
259
- * If there is no current prerelease, then set the prerelease to `0`. So,
260
- * `inc('1.2.3', 'pre')` becomes `1.2.3-0`.
261
- *
262
- * If the last item in the prerelease is numeric, then increment it. So,
263
- * `inc('1.2.3-beta.3', 'pre')` becomes `1.2.3-beta.4`.
264
- */
265
- inc(part, prereleaseIdentifier) {
266
- switch (part) {
267
- case 'premajor':
268
- this.prerelease = undefined;
269
- this.patch = 0;
270
- this.minor = 0;
271
- this.major++;
272
- this.inc('pre', prereleaseIdentifier);
273
- break;
274
- case 'preminor':
275
- this.prerelease = undefined;
276
- this.patch = 0;
277
- this.minor++;
278
- this.inc('pre', prereleaseIdentifier);
279
- break;
280
- case 'prepatch':
281
- this.prerelease = undefined;
282
- this.inc('patch');
283
- this.inc('pre', prereleaseIdentifier);
284
- break;
285
- case 'prerelease':
286
- if (!this.prerelease?.length)
287
- this.inc('patch', prereleaseIdentifier);
288
- this.inc('pre', prereleaseIdentifier);
289
- break;
290
- case 'pre': {
291
- // this is a bit different than node-semver's logic, but simpler
292
- // always do zero-based incrementing, and either bump the existing
293
- // numeric pr value, or add a `.0` after the identifier.
294
- if (!prereleaseIdentifier) {
295
- if (!this.prerelease?.length) {
296
- this.prerelease = [0];
297
- break;
298
- }
299
- const last = this.prerelease[this.prerelease.length - 1];
300
- if (typeof last === 'number') {
301
- this.prerelease[this.prerelease.length - 1] = last + 1;
302
- }
303
- else {
304
- this.prerelease.push(0);
305
- }
306
- break;
307
- }
308
- if (!this.prerelease?.length) {
309
- this.prerelease = [prereleaseIdentifier];
310
- break;
311
- }
312
- const i = this.prerelease.indexOf(maybeNumber(prereleaseIdentifier));
313
- if (i === -1) {
314
- this.prerelease = [prereleaseIdentifier];
315
- break;
316
- }
317
- const baseValue = this.prerelease[i + 1];
318
- if (typeof baseValue === 'number') {
319
- this.prerelease[i + 1] = baseValue + 1;
320
- break;
321
- }
322
- if (i === this.prerelease.length - 1) {
323
- this.prerelease.push(0);
324
- break;
325
- }
326
- this.prerelease.splice(i + 1, 0, 0);
327
- break;
328
- }
329
- case 'major':
330
- if (!this.prerelease?.length || this.minor || this.patch)
331
- this.major++;
332
- this.prerelease = undefined;
333
- this.patch = 0;
334
- this.minor = 0;
335
- break;
336
- case 'minor':
337
- if (!this.prerelease?.length || this.patch)
338
- this.minor++;
339
- this.prerelease = undefined;
340
- this.patch = 0;
341
- break;
342
- case 'patch':
343
- if (!this.prerelease?.length)
344
- this.patch++;
345
- this.prerelease = undefined;
346
- break;
347
- default:
348
- throw typeError('Invalid increment identifier', {
349
- version: this,
350
- found: part,
351
- validOptions: [
352
- 'major',
353
- 'minor',
354
- 'patch',
355
- 'premajor',
356
- 'preminor',
357
- 'prepatch',
358
- 'prerelease',
359
- 'pre',
360
- ],
361
- }, this.inc);
362
- }
363
- this.raw = this.toString();
364
- return this;
365
- }
366
- }
367
- //# sourceMappingURL=version.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAA;AAG9C,MAAM,WAAW,GAAG,CAAC,CAAS,EAAmB,EAAE;IACjD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,CAAC,CAAA;IACjC,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;IACnB,OAAO,CAAC,IAAI,MAAM,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;AAC7C,CAAC,CAAA;AAED,MAAM,UAAU,GAAG,CACjB,C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","sourcesContent":["import { syntaxError, typeError } from '@vltpkg/error-cause'\nimport { fastSplit } from '@vltpkg/fast-split'\nimport type { Range } from './range.ts'\n\nconst maybeNumber = (s: string): number | string => {\n if (!/^[0-9]+$/.test(s)) return s\n const n = Number(s)\n return n <= Number.MAX_SAFE_INTEGER ? n : s\n}\n\nconst safeNumber = (\n s: string,\n version: string,\n field: string,\n): number => {\n const n = Number(s)\n if (n > Number.MAX_SAFE_INTEGER) {\n throw invalidVersion(\n version,\n `invalid ${field}, must be <= ${Number.MAX_SAFE_INTEGER}`,\n )\n }\n return n\n}\n\nconst re = {\n prefix: /^[ v=]+/,\n main: /^(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)/,\n prerelease: /-([0-9a-zA-Z_.-]+)(?:$|\\+)/,\n build: /\\+([0-9a-zA-Z_.-]+)$/,\n full: /^[ v=]*(0|[1-9]\\d*)\\.(0|[1-9]\\d*)\\.(0|[1-9]\\d*)(?:-([0-9a-zA-Z_.-]+))?(?:\\+([0-9a-zA-Z_.-]+))?$/,\n} as const\n\nconst invalidVersion = (\n version: string,\n message: string,\n): SyntaxError => {\n const er = syntaxError(\n `invalid version: ${message}`,\n { version },\n Version,\n )\n return er\n}\n\n/**\n * Values of valid increment types.\n */\nexport const versionIncrements = [\n 'major',\n 'minor',\n 'patch',\n 'pre',\n 'premajor',\n 'preminor',\n 'prepatch',\n 'prerelease',\n] as const\n\n/**\n * Types of incrementing supported by {@link Version#inc}\n */\nexport type IncrementType = (typeof versionIncrements)[number]\n\n/**\n * A parsed object representation of a SemVer version string\n *\n * This is a bit less forgiving than node-semver, in that prerelease versions\n * MUST start with '-'. Otherwise, the allowed syntax is identical.\n */\nexport class Version {\n /** raw string provided to create this Version */\n raw: string\n\n /** major version number */\n major: number\n /** minor version number */\n minor: number\n /** patch version number */\n patch: number\n /**\n * List of `'.'`-separated strings and numbers indicating that this\n * version is a prerelease.\n *\n * This is undefined if the version does not have a prerelease section.\n */\n prerelease?: (number | string)[]\n /**\n * List of `'.'`-separated strings in the `build` section.\n *\n * This is undefined if the version does not have a build.\n */\n build?: string[]\n\n /** Canonical strict form of this version */\n toString() {\n return `${this.major}.${this.minor}.${this.patch}${\n this.prerelease ? '-' + this.prerelease.join('.') : ''\n }${this.build ? '+' + this.build.join('.') : ''}`\n }\n\n /** Generate a `Version` object from a SemVer string */\n static parse(version: string) {\n version = version.replace(re.prefix, '').trim()\n if (version.length > 256) {\n throw invalidVersion(\n version,\n 'must be less than 256 characters',\n )\n }\n\n const parsed = re.full.exec(version)\n if (!parsed) {\n const main = re.main.exec(version)\n if (!main) {\n throw invalidVersion(\n version,\n 'no Major.minor.patch tuple present',\n )\n } else {\n throw invalidVersion(\n version,\n 'invalid build or patch section',\n )\n }\n }\n const [_, major_, minor_, patch_, prerelease, build] = parsed\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const major = safeNumber(major_!, version, 'major')\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const minor = safeNumber(minor_!, version, 'minor')\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const patch = safeNumber(patch_!, version, 'patch')\n\n return new Version(\n version,\n major,\n minor,\n patch,\n prerelease,\n build,\n )\n }\n\n constructor(\n version: string,\n major: number,\n minor: number,\n patch: number,\n prerelease: string | undefined,\n build: string | undefined,\n ) {\n this.raw = version\n this.major = major\n this.minor = minor\n this.patch = patch\n\n // has prerelease and/or build\n if (prerelease) {\n this.prerelease = fastSplit(prerelease, '.', -1, c => {\n if (!c) {\n throw invalidVersion(\n version,\n 'invalid prerelease, empty identifiers not allowed',\n )\n }\n return maybeNumber(c)\n })\n }\n if (build) {\n this.build = fastSplit(build, '.', -1, c => {\n if (!c) {\n throw invalidVersion(\n version,\n 'invalid build metadata, empty identifiers not allowed',\n )\n }\n })\n }\n }\n\n /**\n * Return 1 if this is > the provided version, -1 if we're less, or 0 if\n * they are equal.\n *\n * No special handling for prerelease versions, this is just a precedence\n * comparison.\n *\n * This can be used to sort a list of versions by precedence:\n *\n * ```ts\n * const versions: Version[] = getVersionsSomehow()\n * const sorted = versions.sort((a, b) => a.compare(b))\n * ```\n */\n compare(v: Version): -1 | 0 | 1 {\n if (this.major > v.major) return 1\n if (this.major < v.major) return -1\n if (this.minor > v.minor) return 1\n if (this.minor < v.minor) return -1\n if (this.patch > v.patch) return 1\n if (this.patch < v.patch) return -1\n // main tuple is equal now\n // if the version has no pr, we're definitely less than or equal to\n if (!v.prerelease?.length)\n return !this.prerelease?.length ? 0 : -1\n // v has a pr. if we don't, we're > it\n if (!this.prerelease?.length) return 1\n // we both have prereleases\n const len = Math.max(this.prerelease.length, v.prerelease.length)\n const me = this.prerelease\n const thee = v.prerelease\n for (let i = 0; i < len; i++) {\n const m = me[i]\n const t = thee[i]\n if (m === t) continue\n // having a field is > not having it\n if (t === undefined) return 1\n if (m === undefined) return -1\n // string parts are higher precedence than\n if (typeof m !== typeof t) {\n return typeof m === 'string' ? 1 : -1\n }\n return m > t ? 1 : -1\n }\n return 0\n }\n\n /**\n * The inverse of compare, for sorting version lists in reverse order\n */\n rcompare(v: Version) {\n return -1 * this.compare(v)\n }\n\n /** true if this version is > the argument */\n greaterThan(v: Version) {\n return this.compare(v) === 1\n }\n\n /** true if this version is >= the argument */\n greaterThanEqual(v: Version) {\n return this.compare(v) > -1\n }\n\n /** true if this version is < the argument */\n lessThan(v: Version) {\n return this.compare(v) === -1\n }\n\n /** true if this version is &lt;= the argument */\n lessThanEqual(v: Version) {\n return this.compare(v) < 1\n }\n\n /** true if these two versions have equal SemVer precedence */\n equals(v: Version) {\n return this.compare(v) === 0\n }\n\n /** just compare the M.m.p parts of the version */\n tupleEquals(v: Version) {\n return (\n this.major === v.major &&\n this.minor === v.minor &&\n this.patch === v.patch\n )\n }\n\n /** true if this version satisfies the range */\n satisfies(r: Range) {\n return r.test(this)\n }\n\n /**\n * Increment the version in place, in the manner specified.\n *\n * Part behaviors:\n *\n * - `'major'` If the version is a `M.0.0-...` version with a prerelease, then\n * simply drop the prerelease. Otherwise, set the minor and patch to 0, and\n * increment the major. So `1.0.0-beta` becomes `1.0.0`, and `1.2.3` becomes\n * `2.0.0`\n *\n * - `'minor'` If the version is a `M.m.0-...` version with a prerelease, then\n * simply drop the prerelease. Otherwise, set the patch to 0, and increment the\n * minor. So `1.2.0-beta` becomes `1.2.0`, and `1.2.3` becomes `1.3.0`.\n *\n * - `'patch'` If the version has a prerelease, then simply drop the\n * prerelease. Otherwise, increment the patch value. So `1.2.3-beta` becomes\n * `1.2.3` and `1.2.3` becomes `1.2.4`.\n *\n * - `'premajor'` Set the patch and minor versions to `0`, increment the major\n * version, and add a prerelease, using the optional identifier.\n *\n * - `'preminor'` Set the patch version to `0`, increment the minor version,\n * and add a prerelease, using the optional identifier.\n *\n * - `'prepatch'` If a prerelease is already present, increment the patch\n * version, otherwise leave it untouched, and add a prerelease, using the\n * optional identifier.\n *\n * - `'prerelease'` If a prerelease version is present, then behave the same as\n * `'prepatch'`. Otherwise, add a prerelease, using the optional identifier.\n *\n * - `'pre'` This is mostly for use by the other prerelease incrementers.\n *\n * - If a prerelease identifier is provided:\n *\n * Update that named portion of the prerelease. For example,\n * `inc('1.2.3-beta.4', 'pre', 'beta')` would result in `1.2.3-beta.5`.\n *\n * If there is no prerelease identifier by that name, then replace the\n * prerelease with `[name]`. So `inc('1.2.3-alpha.4', 'pre', 'beta')`\n * would result in `1.2.3-beta`.\n *\n * If the prerelease identifer is present, but has no numeric value\n * following it, then add `0`. So `inc('1.2.3-beta', 'pre', 'beta')`\n * would result in `1.2.3-beta.0`.\n *\n * - If no prerelease identifier is provided:\n *\n * If there is no current prerelease, then set the prerelease to `0`. So,\n * `inc('1.2.3', 'pre')` becomes `1.2.3-0`.\n *\n * If the last item in the prerelease is numeric, then increment it. So,\n * `inc('1.2.3-beta.3', 'pre')` becomes `1.2.3-beta.4`.\n */\n inc(part: IncrementType, prereleaseIdentifier?: string) {\n switch (part) {\n case 'premajor':\n this.prerelease = undefined\n this.patch = 0\n this.minor = 0\n this.major++\n this.inc('pre', prereleaseIdentifier)\n break\n\n case 'preminor':\n this.prerelease = undefined\n this.patch = 0\n this.minor++\n this.inc('pre', prereleaseIdentifier)\n break\n\n case 'prepatch':\n this.prerelease = undefined\n this.inc('patch')\n this.inc('pre', prereleaseIdentifier)\n break\n\n case 'prerelease':\n if (!this.prerelease?.length)\n this.inc('patch', prereleaseIdentifier)\n this.inc('pre', prereleaseIdentifier)\n break\n\n case 'pre': {\n // this is a bit different than node-semver's logic, but simpler\n // always do zero-based incrementing, and either bump the existing\n // numeric pr value, or add a `.0` after the identifier.\n if (!prereleaseIdentifier) {\n if (!this.prerelease?.length) {\n this.prerelease = [0]\n break\n }\n const last = this.prerelease[this.prerelease.length - 1]\n if (typeof last === 'number') {\n this.prerelease[this.prerelease.length - 1] = last + 1\n } else {\n this.prerelease.push(0)\n }\n break\n }\n if (!this.prerelease?.length) {\n this.prerelease = [prereleaseIdentifier]\n break\n }\n const i = this.prerelease.indexOf(\n maybeNumber(prereleaseIdentifier),\n )\n if (i === -1) {\n this.prerelease = [prereleaseIdentifier]\n break\n }\n const baseValue = this.prerelease[i + 1]\n if (typeof baseValue === 'number') {\n this.prerelease[i + 1] = baseValue + 1\n break\n }\n if (i === this.prerelease.length - 1) {\n this.prerelease.push(0)\n break\n }\n this.prerelease.splice(i + 1, 0, 0)\n break\n }\n\n case 'major':\n if (!this.prerelease?.length || this.minor || this.patch)\n this.major++\n this.prerelease = undefined\n this.patch = 0\n this.minor = 0\n break\n\n case 'minor':\n if (!this.prerelease?.length || this.patch) this.minor++\n this.prerelease = undefined\n this.patch = 0\n break\n\n case 'patch':\n if (!this.prerelease?.length) this.patch++\n this.prerelease = undefined\n break\n\n default:\n throw typeError(\n 'Invalid increment identifier',\n {\n version: this,\n found: part,\n validOptions: [\n 'major',\n 'minor',\n 'patch',\n 'premajor',\n 'preminor',\n 'prepatch',\n 'prerelease',\n 'pre',\n ],\n },\n this.inc,\n )\n }\n\n this.raw = this.toString()\n return this\n }\n}\n"]}