Skip to content

Commit 95b76f9

Browse files
bmiddhaCopilot
andcommitted
refactor(rush-lib): use native private fields
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 8ebd5bf2-c44b-42d5-be25-e7936d4b0a14
1 parent 9c5a1c2 commit 95b76f9

121 files changed

Lines changed: 2191 additions & 2188 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

libraries/rush-lib/src/api/ApprovedPackagesConfiguration.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,36 +59,36 @@ const _jsonSchema: JsonSchema = JsonSchema.fromLoadedObject(schemaJson);
5959
export class ApprovedPackagesConfiguration {
6060
public items: ApprovedPackagesItem[] = [];
6161

62-
private _itemsByName: Map<string, ApprovedPackagesItem> = new Map<string, ApprovedPackagesItem>();
62+
#itemsByName: Map<string, ApprovedPackagesItem> = new Map<string, ApprovedPackagesItem>();
6363

64-
private _loadedJson!: IApprovedPackagesJson;
65-
private _jsonFilename: string;
64+
#loadedJson!: IApprovedPackagesJson;
65+
#jsonFilename: string;
6666

6767
public constructor(jsonFilename: string) {
68-
this._jsonFilename = jsonFilename;
68+
this.#jsonFilename = jsonFilename;
6969
this.clear();
7070
}
7171

7272
/**
7373
* Clears all the settings, returning to an empty state.
7474
*/
7575
public clear(): void {
76-
this._itemsByName.clear();
77-
this._loadedJson = {
76+
this.#itemsByName.clear();
77+
this.#loadedJson = {
7878
// Ensure this comes first in the key ordering
7979
$schema: '',
8080
packages: []
8181
};
8282
}
8383

8484
public getItemByName(packageName: string): ApprovedPackagesItem | undefined {
85-
return this._itemsByName.get(packageName);
85+
return this.#itemsByName.get(packageName);
8686
}
8787

8888
public addOrUpdatePackage(packageName: string, reviewCategory: string): boolean {
8989
let changed: boolean = false;
9090

91-
let item: ApprovedPackagesItem | undefined = this._itemsByName.get(packageName);
91+
let item: ApprovedPackagesItem | undefined = this.#itemsByName.get(packageName);
9292
if (!item) {
9393
item = new ApprovedPackagesItem(packageName);
9494
this._addItem(item);
@@ -107,7 +107,7 @@ export class ApprovedPackagesConfiguration {
107107
* If the file exists, calls loadFromFile().
108108
*/
109109
public tryLoadFromFile(approvedPackagesPolicyEnabled: boolean): boolean {
110-
if (!FileSystem.exists(this._jsonFilename)) {
110+
if (!FileSystem.exists(this.#jsonFilename)) {
111111
return false;
112112
}
113113

@@ -116,7 +116,7 @@ export class ApprovedPackagesConfiguration {
116116
if (!approvedPackagesPolicyEnabled) {
117117
// eslint-disable-next-line no-console
118118
console.log(
119-
`Warning: Ignoring "${path.basename(this._jsonFilename)}" because the` +
119+
`Warning: Ignoring "${path.basename(this.#jsonFilename)}" because the` +
120120
` "approvedPackagesPolicy" setting was not specified in ${RushConstants.rushJsonFilename}`
121121
);
122122
}
@@ -129,14 +129,14 @@ export class ApprovedPackagesConfiguration {
129129
*/
130130
public loadFromFile(): void {
131131
const approvedPackagesJson: IApprovedPackagesJson = JsonFile.loadAndValidate(
132-
this._jsonFilename,
132+
this.#jsonFilename,
133133
_jsonSchema
134134
);
135135

136136
this.clear();
137137

138138
for (const browserPackage of approvedPackagesJson.packages) {
139-
this._addItemJson(browserPackage, this._jsonFilename);
139+
this._addItemJson(browserPackage, this.#jsonFilename);
140140
}
141141
}
142142

@@ -148,9 +148,9 @@ export class ApprovedPackagesConfiguration {
148148
// (which passed schema validation).
149149

150150
// eslint-disable-next-line dot-notation
151-
this._loadedJson['$schema'] = JsonSchemaUrls.approvedPackages;
151+
this.#loadedJson['$schema'] = JsonSchemaUrls.approvedPackages;
152152

153-
this._loadedJson.packages = [];
153+
this.#loadedJson.packages = [];
154154

155155
this.items.sort((a: ApprovedPackagesItem, b: ApprovedPackagesItem) => {
156156
return a.packageName.localeCompare(b.packageName);
@@ -166,11 +166,11 @@ export class ApprovedPackagesConfiguration {
166166
allowedCategories: allowedCategories
167167
};
168168

169-
this._loadedJson.packages.push(itemJson);
169+
this.#loadedJson.packages.push(itemJson);
170170
}
171171

172172
// Save the file
173-
let body: string = JsonFile.stringify(this._loadedJson);
173+
let body: string = JsonFile.stringify(this.#loadedJson);
174174

175175
// Unindent the allowedCategories array to improve readability
176176
body = body.replace(/("allowedCategories": +\[)([^\]]+)/g, (substring: string, ...args: string[]) => {
@@ -180,7 +180,7 @@ export class ApprovedPackagesConfiguration {
180180
// Add a header
181181
body = '// DO NOT ADD COMMENTS IN THIS FILE. They will be lost when the Rush tool resaves it.\n' + body;
182182

183-
FileSystem.writeFile(this._jsonFilename, body, {
183+
FileSystem.writeFile(this.#jsonFilename, body, {
184184
convertLineEndings: NewlineKind.CrLf
185185
});
186186
}
@@ -189,7 +189,7 @@ export class ApprovedPackagesConfiguration {
189189
* Helper function only used by the constructor when loading the file.
190190
*/
191191
private _addItemJson(itemJson: IApprovedPackagesItemJson, jsonFilename: string): void {
192-
if (this._itemsByName.has(itemJson.name)) {
192+
if (this.#itemsByName.has(itemJson.name)) {
193193
throw new Error(
194194
`Error loading package review file ${jsonFilename}:\n` +
195195
` the name "${itemJson.name}" appears more than once`
@@ -210,10 +210,10 @@ export class ApprovedPackagesConfiguration {
210210
* list and set.
211211
*/
212212
private _addItem(item: ApprovedPackagesItem): void {
213-
if (this._itemsByName.has(item.packageName)) {
213+
if (this.#itemsByName.has(item.packageName)) {
214214
throw new InternalError('Duplicate key');
215215
}
216216
this.items.push(item);
217-
this._itemsByName.set(item.packageName, item);
217+
this.#itemsByName.set(item.packageName, item);
218218
}
219219
}

libraries/rush-lib/src/api/ChangeFile.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import { Git } from '../logic/Git';
1515
* This class represents a single change file.
1616
*/
1717
export class ChangeFile {
18-
private _changeFileData: IChangeFile;
19-
private _rushConfiguration: RushConfiguration;
18+
#changeFileData: IChangeFile;
19+
#rushConfiguration: RushConfiguration;
2020

2121
/**
2222
* @internal
@@ -30,16 +30,16 @@ export class ChangeFile {
3030
throw new Error(`rushConfiguration does not have a value`);
3131
}
3232

33-
this._changeFileData = changeFileData;
34-
this._rushConfiguration = rushConfiguration;
33+
this.#changeFileData = changeFileData;
34+
this.#rushConfiguration = rushConfiguration;
3535
}
3636

3737
/**
3838
* Adds a change entry into the change file
3939
* @param data - change information
4040
*/
4141
public addChange(data: IChangeInfo): void {
42-
this._changeFileData.changes.push(data);
42+
this.#changeFileData.changes.push(data);
4343
}
4444

4545
/**
@@ -48,7 +48,7 @@ export class ChangeFile {
4848
*/
4949
public getChanges(packageName: string): IChangeInfo[] {
5050
const changes: IChangeInfo[] = [];
51-
for (const info of this._changeFileData.changes) {
51+
for (const info of this.#changeFileData.changes) {
5252
if (info.packageName === packageName) {
5353
changes.push(info);
5454
}
@@ -63,7 +63,7 @@ export class ChangeFile {
6363
*/
6464
public writeSync(): string {
6565
const filePath: string = this.generatePath();
66-
JsonFile.save(this._changeFileData, filePath, {
66+
JsonFile.save(this.#changeFileData, filePath, {
6767
ensureFolderExists: true
6868
});
6969
return filePath;
@@ -76,7 +76,7 @@ export class ChangeFile {
7676
*/
7777
public generatePath(): string {
7878
let branch: string | undefined = undefined;
79-
const git: Git = new Git(this._rushConfiguration);
79+
const git: Git = new Git(this.#rushConfiguration);
8080
const repoInfo: gitInfo.GitRepoInfo | undefined = git.getGitInfo();
8181
branch = repoInfo && repoInfo.branch;
8282
if (!branch) {
@@ -94,8 +94,8 @@ export class ChangeFile {
9494
? this._escapeFilename(`${branch}_${timestamp}.json`)
9595
: `${timestamp}.json`;
9696
const filePath: string = path.join(
97-
this._rushConfiguration.changesFolder,
98-
...this._changeFileData.packageName.split('/'),
97+
this.#rushConfiguration.changesFolder,
98+
...this.#changeFileData.packageName.split('/'),
9999
filename
100100
);
101101
return filePath;

libraries/rush-lib/src/api/CobuildConfiguration.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ export class CobuildConfiguration {
7676
*/
7777
public readonly cobuildWithoutCacheAllowed: boolean;
7878

79-
private _cobuildLockProvider: ICobuildLockProvider | undefined;
80-
private readonly _cobuildLockProviderFactory: CobuildLockProviderFactory;
81-
private readonly _cobuildJson: ICobuildJson;
79+
#cobuildLockProvider: ICobuildLockProvider | undefined;
80+
readonly #cobuildLockProviderFactory: CobuildLockProviderFactory;
81+
readonly #cobuildJson: ICobuildJson;
8282

8383
private constructor(options: ICobuildConfigurationOptions) {
8484
const { cobuildJson, cobuildLockProviderFactory, rushConfiguration } = options;
@@ -91,8 +91,8 @@ export class CobuildConfiguration {
9191
this.cobuildWithoutCacheAllowed =
9292
rushConfiguration.experimentsConfiguration.configuration.allowCobuildWithoutCache ?? false;
9393

94-
this._cobuildLockProviderFactory = cobuildLockProviderFactory;
95-
this._cobuildJson = cobuildJson;
94+
this.#cobuildLockProviderFactory = cobuildLockProviderFactory;
95+
this.#cobuildJson = cobuildJson;
9696
}
9797

9898
/**
@@ -127,25 +127,25 @@ export class CobuildConfiguration {
127127
public async createLockProviderAsync(terminal: ITerminal): Promise<void> {
128128
if (this.cobuildFeatureEnabled) {
129129
terminal.writeLine(`Running cobuild (runner ${this.cobuildContextId}/${this.cobuildRunnerId})`);
130-
const cobuildLockProvider: ICobuildLockProvider = await this._cobuildLockProviderFactory(
131-
this._cobuildJson
130+
const cobuildLockProvider: ICobuildLockProvider = await this.#cobuildLockProviderFactory(
131+
this.#cobuildJson
132132
);
133-
this._cobuildLockProvider = cobuildLockProvider;
134-
await this._cobuildLockProvider.connectAsync();
133+
this.#cobuildLockProvider = cobuildLockProvider;
134+
await this.#cobuildLockProvider.connectAsync();
135135
}
136136
}
137137

138138
public async destroyLockProviderAsync(): Promise<void> {
139139
if (this.cobuildFeatureEnabled) {
140-
await this._cobuildLockProvider?.disconnectAsync();
140+
await this.#cobuildLockProvider?.disconnectAsync();
141141
}
142142
}
143143

144144
public getCobuildLockProvider(): ICobuildLockProvider {
145-
if (!this._cobuildLockProvider) {
145+
if (!this.#cobuildLockProvider) {
146146
throw new Error(`Cobuild lock provider has not been created`);
147147
}
148-
return this._cobuildLockProvider;
148+
return this.#cobuildLockProvider;
149149
}
150150
}
151151

libraries/rush-lib/src/api/CommandLineConfiguration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ export class CommandLineConfiguration {
233233
/**
234234
* A map of bulk command names to their corresponding synthetic phase identifiers
235235
*/
236-
private readonly _syntheticPhasesByTranslatedBulkCommandName: Map<string, IPhase> = new Map();
236+
readonly #syntheticPhasesByTranslatedBulkCommandName: Map<string, IPhase> = new Map();
237237

238238
/**
239239
* Use CommandLineConfiguration.loadFromFile()
@@ -545,7 +545,7 @@ export class CommandLineConfiguration {
545545
if (normalizedParameter.associatedCommands) {
546546
for (const associatedCommandName of normalizedParameter.associatedCommands) {
547547
const syntheticPhase: IPhase | undefined =
548-
this._syntheticPhasesByTranslatedBulkCommandName.get(associatedCommandName);
548+
this.#syntheticPhasesByTranslatedBulkCommandName.get(associatedCommandName);
549549
if (syntheticPhase) {
550550
// If this parameter was associated with a bulk command, include the association
551551
// with the synthetic phase
@@ -730,7 +730,7 @@ export class CommandLineConfiguration {
730730
}
731731

732732
this.phases.set(phaseName, phase);
733-
this._syntheticPhasesByTranslatedBulkCommandName.set(command.name, phase);
733+
this.#syntheticPhasesByTranslatedBulkCommandName.set(command.name, phase);
734734

735735
const phases: Set<IPhase> = new Set([phase]);
736736

0 commit comments

Comments
 (0)