9
9
type ILockStepVersionJson ,
10
10
type IIndividualVersionJson ,
11
11
VersionFormatForCommit ,
12
- VersionFormatForPublish ,
13
- type IVersionPolicyDependencyJson
12
+ VersionFormatForPublish
14
13
} from './VersionPolicyConfiguration' ;
15
14
import type { PackageJsonEditor } from './PackageJsonEditor' ;
16
15
import type { RushConfiguration } from './RushConfiguration' ;
@@ -57,42 +56,54 @@ export enum VersionPolicyDefinitionName {
57
56
* @public
58
57
*/
59
58
export abstract class VersionPolicy {
60
- private _versionFormatForCommit : VersionFormatForCommit ;
61
- private _versionFormatForPublish : VersionFormatForPublish ;
59
+ /**
60
+ * Serialized json for the policy
61
+ *
62
+ * @internal
63
+ */
64
+ public readonly _json : IVersionPolicyJson ;
65
+
66
+ private get _versionFormatForCommit ( ) : VersionFormatForCommit {
67
+ return this . _json . dependencies ?. versionFormatForCommit ?? VersionFormatForCommit . original ;
68
+ }
69
+
70
+ private get _versionFormatForPublish ( ) : VersionFormatForPublish {
71
+ return this . _json . dependencies ?. versionFormatForPublish ?? VersionFormatForPublish . original ;
72
+ }
62
73
63
74
/**
64
75
* Version policy name
65
76
*/
66
- public readonly policyName : string ;
77
+ public get policyName ( ) : string {
78
+ return this . _json . policyName ;
79
+ }
67
80
68
81
/**
69
82
* Version policy definition name
70
83
*/
71
- public readonly definitionName : VersionPolicyDefinitionName ;
84
+ public get definitionName ( ) : VersionPolicyDefinitionName {
85
+ return Enum . getValueByKey ( VersionPolicyDefinitionName , this . _json . definitionName ) ;
86
+ }
72
87
73
88
/**
74
89
* Determines if a version policy wants to opt out of changelog files.
75
90
*/
76
- public readonly exemptFromRushChange : boolean ;
91
+ public get exemptFromRushChange ( ) : boolean {
92
+ return this . _json . exemptFromRushChange ?? false ;
93
+ }
77
94
78
95
/**
79
96
* Determines if a version policy wants to opt in to including email.
80
97
*/
81
- public readonly includeEmailInChangeFile : boolean ;
98
+ public get includeEmailInChangeFile ( ) : boolean {
99
+ return this . _json . includeEmailInChangeFile ?? false ;
100
+ }
82
101
83
102
/**
84
103
* @internal
85
104
*/
86
105
public constructor ( versionPolicyJson : IVersionPolicyJson ) {
87
- this . policyName = versionPolicyJson . policyName ;
88
- this . definitionName = Enum . getValueByKey ( VersionPolicyDefinitionName , versionPolicyJson . definitionName ) ;
89
- this . exemptFromRushChange = versionPolicyJson . exemptFromRushChange || false ;
90
- this . includeEmailInChangeFile = versionPolicyJson . includeEmailInChangeFile || false ;
91
-
92
- const jsonDependencies : IVersionPolicyDependencyJson = versionPolicyJson . dependencies || { } ;
93
- this . _versionFormatForCommit = jsonDependencies . versionFormatForCommit || VersionFormatForCommit . original ;
94
- this . _versionFormatForPublish =
95
- jsonDependencies . versionFormatForPublish || VersionFormatForPublish . original ;
106
+ this . _json = versionPolicyJson ;
96
107
}
97
108
98
109
/**
@@ -140,13 +151,6 @@ export abstract class VersionPolicy {
140
151
*/
141
152
public abstract bump ( bumpType ?: BumpType , identifier ?: string ) : void ;
142
153
143
- /**
144
- * Serialized json for the policy
145
- *
146
- * @internal
147
- */
148
- public abstract get _json ( ) : IVersionPolicyJson ;
149
-
150
154
/**
151
155
* Validates the specified version and throws if the version does not satisfy the policy.
152
156
*
@@ -211,34 +215,34 @@ export abstract class VersionPolicy {
211
215
* @public
212
216
*/
213
217
export class LockStepVersionPolicy extends VersionPolicy {
218
+ public declare _json : ILockStepVersionJson ;
214
219
private _version : semver . SemVer ;
215
220
216
221
/**
217
222
* The type of bump for next bump.
218
223
*/
219
224
// nextBump is probably not needed. It can be prerelease only.
220
225
// Other types of bumps can be passed in as a parameter to bump method, so can identifier.
221
- public readonly nextBump : BumpType | undefined ;
226
+ public get nextBump ( ) : BumpType | undefined {
227
+ return this . _json . nextBump !== undefined ? Enum . getValueByKey ( BumpType , this . _json . nextBump ) : undefined ;
228
+ }
222
229
223
230
/**
224
231
* The main project for the version policy.
225
232
*
226
233
* If the value is provided, change logs will only be generated in that project.
227
234
* If the value is not provided, change logs will be hosted in each project associated with the policy.
228
235
*/
229
- public readonly mainProject : string | undefined ;
236
+ public get mainProject ( ) : string | undefined {
237
+ return this . _json . mainProject ;
238
+ }
230
239
231
240
/**
232
241
* @internal
233
242
*/
234
243
public constructor ( versionPolicyJson : ILockStepVersionJson ) {
235
244
super ( versionPolicyJson ) ;
236
245
this . _version = new semver . SemVer ( versionPolicyJson . version ) ;
237
- this . nextBump =
238
- versionPolicyJson . nextBump !== undefined
239
- ? Enum . getValueByKey ( BumpType , versionPolicyJson . nextBump )
240
- : undefined ;
241
- this . mainProject = versionPolicyJson . mainProject ;
242
246
}
243
247
244
248
/**
@@ -248,26 +252,6 @@ export class LockStepVersionPolicy extends VersionPolicy {
248
252
return this . _version . format ( ) ;
249
253
}
250
254
251
- /**
252
- * Serialized json for this policy
253
- *
254
- * @internal
255
- */
256
- public get _json ( ) : ILockStepVersionJson {
257
- const json : ILockStepVersionJson = {
258
- policyName : this . policyName ,
259
- definitionName : VersionPolicyDefinitionName [ this . definitionName ] ,
260
- version : this . version
261
- } ;
262
- if ( this . nextBump !== undefined ) {
263
- json . nextBump = BumpType [ this . nextBump ] ;
264
- }
265
- if ( this . mainProject !== undefined ) {
266
- json . mainProject = this . mainProject ;
267
- }
268
- return json ;
269
- }
270
-
271
255
/**
272
256
* Returns an updated package json that satisfies the version policy.
273
257
*
@@ -303,6 +287,7 @@ export class LockStepVersionPolicy extends VersionPolicy {
303
287
}
304
288
305
289
this . _version . inc ( this . _getReleaseType ( nextBump ) , identifier ) ;
290
+ this . _json . version = this . version ;
306
291
}
307
292
308
293
/**
@@ -315,6 +300,7 @@ export class LockStepVersionPolicy extends VersionPolicy {
315
300
return false ;
316
301
}
317
302
this . _version = newVersion ;
303
+ this . _json . version = this . version ;
318
304
return true ;
319
305
}
320
306
@@ -348,33 +334,20 @@ export class LockStepVersionPolicy extends VersionPolicy {
348
334
* @public
349
335
*/
350
336
export class IndividualVersionPolicy extends VersionPolicy {
337
+ public declare readonly _json : IIndividualVersionJson ;
338
+
351
339
/**
352
340
* The major version that has been locked
353
341
*/
354
- public readonly lockedMajor : number | undefined ;
342
+ public get lockedMajor ( ) : number | undefined {
343
+ return this . _json . lockedMajor ;
344
+ }
355
345
356
346
/**
357
347
* @internal
358
348
*/
359
349
public constructor ( versionPolicyJson : IIndividualVersionJson ) {
360
350
super ( versionPolicyJson ) ;
361
- this . lockedMajor = versionPolicyJson . lockedMajor ;
362
- }
363
-
364
- /**
365
- * Serialized json for this policy
366
- *
367
- * @internal
368
- */
369
- public get _json ( ) : IIndividualVersionJson {
370
- const json : IIndividualVersionJson = {
371
- policyName : this . policyName ,
372
- definitionName : VersionPolicyDefinitionName [ this . definitionName ]
373
- } ;
374
- if ( this . lockedMajor !== undefined ) {
375
- json . lockedMajor = this . lockedMajor ;
376
- }
377
- return json ;
378
351
}
379
352
380
353
/**
0 commit comments