Skip to content

Commit 63d87cb

Browse files
committed
Move rush global folders into RushGlobalFolders class.
1 parent 88bb11f commit 63d87cb

13 files changed

Lines changed: 97 additions & 52 deletions

‎apps/rush-lib/src/api/RushConfiguration.ts‎

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ export class RushConfiguration {
186186
private _yarnCacheFolder: string;
187187
private _tempShrinkwrapFilename: string;
188188
private _tempShrinkwrapPreinstallFilename: string;
189-
private __rushUserFolder: string; // tslint:disable-line:variable-name
190-
private __rushNodeSpecificUserFolder: string; // tslint:disable-line:variable-name
191189
private _rushLinkJsonFilename: string;
192190
private _currentVariantJsonFilename: string;
193191
private _packageManagerToolVersion: string;
@@ -565,24 +563,6 @@ export class RushConfiguration {
565563
}
566564
}
567565

568-
/**
569-
* The absolute path to Rush's storage in the home directory for the current user, independent of node version.
570-
* On Windows, it would be something like `C:\Users\YourName\.rush\`.
571-
* @internal
572-
*/
573-
public get _rushUserFolder(): string {
574-
return this.__rushUserFolder;
575-
}
576-
577-
/**
578-
* The absolute path to Rush's storage in the home directory for the current user and node version.
579-
* On Windows, it would be something like `C:\Users\YourName\.rush\node-v3.4.5`.
580-
* @internal
581-
*/
582-
public get _rushNodeSpecificUserFolder(): string {
583-
return this.__rushNodeSpecificUserFolder;
584-
}
585-
586566
/**
587567
* The filename of the build dependency data file. By default this is
588568
* called 'rush-link.json' resides in the Rush common folder.
@@ -919,12 +899,6 @@ export class RushConfiguration {
919899
this._yarnCacheFolder = path.resolve(path.join(this._commonTempFolder, 'yarn-cache'));
920900

921901
this._changesFolder = path.join(this._commonFolder, RushConstants.changeFilesFolderName);
922-
this.__rushNodeSpecificUserFolder = path.join(Utilities.getHomeDirectory(), '.rush');
923-
924-
const normalizedNodeVersion: string = process.version.match(/^[a-z0-9\-\.]+$/i)
925-
? process.version
926-
: 'unknown-version';
927-
this.__rushUserFolder = path.join(this.__rushNodeSpecificUserFolder, `node-${normalizedNodeVersion}`);
928902

929903
this._rushLinkJsonFilename = path.join(this._commonTempFolder, 'rush-link.json');
930904
this._currentVariantJsonFilename = path.join(this._commonTempFolder, 'current-variant.json');
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
2+
// See LICENSE in the project root for license information.
3+
4+
import * as path from 'path';
5+
import { Utilities } from '../utilities/Utilities';
6+
7+
/**
8+
* This class provides global folders that are used for rush's internal install locations.
9+
*
10+
* @internal
11+
*/
12+
export class RushGlobalFolders {
13+
private _rushUserFolder: string;
14+
private _rushNodeSpecificUserFolder: string;
15+
16+
/**
17+
* The absolute path to Rush's storage in the home directory for the current user, independent of node version.
18+
* On Windows, it would be something like `C:\Users\YourName\.rush\`.
19+
*/
20+
public get rushGlobalFolder(): string {
21+
return this._rushUserFolder;
22+
}
23+
24+
/**
25+
* The absolute path to Rush's storage in the home directory for the current user and node version.
26+
* On Windows, it would be something like `C:\Users\YourName\.rush\node-v3.4.5`.
27+
*/
28+
public get rushNodeSpecificGlobalFolder(): string {
29+
return this._rushNodeSpecificUserFolder;
30+
}
31+
32+
public constructor() {
33+
this._rushNodeSpecificUserFolder = path.join(Utilities.getHomeDirectory(), '.rush');
34+
const normalizedNodeVersion: string = process.version.match(/^[a-z0-9\-\.]+$/i)
35+
? process.version
36+
: 'unknown-version';
37+
this._rushUserFolder = path.join(this._rushNodeSpecificUserFolder, `node-${normalizedNodeVersion}`);
38+
}
39+
}

‎apps/rush-lib/src/cli/RushCommandLineParser.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ import { GlobalScriptAction } from './scriptActions/GlobalScriptAction';
3232

3333
import { Telemetry } from '../logic/Telemetry';
3434
import { AlreadyReportedError } from '../utilities/AlreadyReportedError';
35+
import { RushGlobalFolders } from '../api/RushGlobalFolders';
3536

3637
export class RushCommandLineParser extends CommandLineParser {
3738
public telemetry: Telemetry | undefined;
3839
public rushConfiguration: RushConfiguration;
40+
public rushGlobalFolders: RushGlobalFolders;
3941

4042
private _debugParameter: CommandLineFlagParameter;
4143

@@ -110,6 +112,8 @@ export class RushCommandLineParser extends CommandLineParser {
110112
this.rushConfiguration = RushConfiguration.loadFromConfigurationFile(rushJsonFilename);
111113
}
112114

115+
this.rushGlobalFolders = new RushGlobalFolders();
116+
113117
this.addAction(new AddAction(this));
114118
this.addAction(new ChangeAction(this));
115119
this.addAction(new CheckAction(this));

‎apps/rush-lib/src/cli/actions/AddAction.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class AddAction extends BaseRushAction {
115115
return Promise.reject(new Error(`The SemVer specifier "${version}" is not valid.`));
116116
}
117117

118-
return new PackageJsonUpdater(this.rushConfiguration).doRushAdd({
118+
return new PackageJsonUpdater(this.rushConfiguration, this.rushGlobalFolders).doRushAdd({
119119
currentProject: project,
120120
packageName: packageName,
121121
initialVersion: version,

‎apps/rush-lib/src/cli/actions/BaseInstallAction.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export abstract class BaseInstallAction extends BaseRushAction {
8181

8282
this.eventHooksManager.handle(Event.preRushInstall, this.parser.isDebug);
8383

84-
const purgeManager: PurgeManager = new PurgeManager(this.rushConfiguration);
84+
const purgeManager: PurgeManager = new PurgeManager(this.rushConfiguration, this.rushGlobalFolders);
8585

8686
if (this._purgeParameter.value!) {
8787
console.log('The --purge flag was specified, so performing "rush purge"');
@@ -100,6 +100,7 @@ export abstract class BaseInstallAction extends BaseRushAction {
100100

101101
const installManager: InstallManager = new InstallManager(
102102
this.rushConfiguration,
103+
this.rushGlobalFolders,
103104
purgeManager,
104105
installManagerOptions
105106
);

‎apps/rush-lib/src/cli/actions/BaseRushAction.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { RushConfiguration } from '../../api/RushConfiguration';
1616
import { EventHooksManager } from '../../logic/EventHooksManager';
1717
import { RushCommandLineParser } from './../RushCommandLineParser';
1818
import { Utilities } from '../../utilities/Utilities';
19+
import { RushGlobalFolders } from '../../api/RushGlobalFolders';
1920

2021
export interface IBaseRushActionOptions extends ICommandLineActionOptions {
2122
/**
@@ -45,6 +46,10 @@ export abstract class BaseConfiglessRushAction extends CommandLineAction {
4546
return this._parser.rushConfiguration;
4647
}
4748

49+
protected get rushGlobalFolders(): RushGlobalFolders {
50+
return this._parser.rushGlobalFolders;
51+
}
52+
4853
protected get parser(): RushCommandLineParser {
4954
return this._parser;
5055
}

‎apps/rush-lib/src/cli/actions/PurgeAction.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class PurgeAction extends BaseRushAction {
3939
const stopwatch: Stopwatch = Stopwatch.start();
4040

4141
const unlinkManager: UnlinkManager = new UnlinkManager(this.rushConfiguration);
42-
const purgeManager: PurgeManager = new PurgeManager(this.rushConfiguration);
42+
const purgeManager: PurgeManager = new PurgeManager(this.rushConfiguration, this.rushGlobalFolders);
4343

4444
unlinkManager.unlink();
4545

‎apps/rush-lib/src/index.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export {
2424
RushConfigurationProject
2525
} from './api/RushConfigurationProject';
2626

27+
export {
28+
RushGlobalFolders as _RushGlobalFolders
29+
} from './api/RushGlobalFolders';
30+
2731
export {
2832
ApprovedPackagesItem,
2933
ApprovedPackagesConfiguration

‎apps/rush-lib/src/logic/InstallManager.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const MAX_INSTALL_ATTEMPTS: number = 2;
4949
* As a temporary workaround, augment the type.
5050
*/
5151
import { CreateOptions } from 'tar';
52+
import { RushGlobalFolders } from '../api/RushGlobalFolders';
5253

5354
export interface CreateOptions { // tslint:disable-line:interface-name
5455
/**
@@ -113,6 +114,7 @@ export interface IInstallManagerOptions {
113114
*/
114115
export class InstallManager {
115116
private _rushConfiguration: RushConfiguration;
117+
private _rushGlobalFolders: RushGlobalFolders;
116118
private _commonNodeModulesMarker: LastInstallFlag;
117119
private _commonTempFolderRecycler: AsyncRecycler;
118120

@@ -235,8 +237,14 @@ export class InstallManager {
235237
return this._commonNodeModulesMarker;
236238
}
237239

238-
constructor(rushConfiguration: RushConfiguration, purgeManager: PurgeManager, options: IInstallManagerOptions) {
240+
constructor(
241+
rushConfiguration: RushConfiguration,
242+
rushGlobalFolders: RushGlobalFolders,
243+
purgeManager: PurgeManager,
244+
options: IInstallManagerOptions
245+
) {
239246
this._rushConfiguration = rushConfiguration;
247+
this._rushGlobalFolders = rushGlobalFolders;
240248
this._commonTempFolderRecycler = purgeManager.commonTempFolderRecycler;
241249
this._options = options;
242250

@@ -341,7 +349,7 @@ export class InstallManager {
341349
*/
342350
public ensureLocalPackageManager(): Promise<void> {
343351
// Example: "C:\Users\YourName\.rush"
344-
const rushUserFolder: string = this._rushConfiguration._rushNodeSpecificUserFolder;
352+
const rushUserFolder: string = this._rushGlobalFolders.rushNodeSpecificGlobalFolder;
345353

346354
if (!FileSystem.exists(rushUserFolder)) {
347355
console.log('Creating ' + rushUserFolder);
@@ -925,7 +933,7 @@ export class InstallManager {
925933

926934
private _checkIfReleaseIsPublished(): Promise<boolean> {
927935
return Promise.resolve().then(() => {
928-
const lastCheckFile: string = path.join(this._rushConfiguration._rushNodeSpecificUserFolder,
936+
const lastCheckFile: string = path.join(this._rushGlobalFolders.rushNodeSpecificGlobalFolder,
929937
'rush-' + Rush.version, 'last-check.flag');
930938

931939
if (FileSystem.exists(lastCheckFile)) {

‎apps/rush-lib/src/logic/PackageJsonUpdater.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { VersionMismatchFinder } from '../api/VersionMismatchFinder';
1111
import { PurgeManager } from './PurgeManager';
1212
import { Utilities } from '../utilities/Utilities';
1313
import { DependencyType, PackageJsonEditor, PackageJsonDependency } from '../api/PackageJsonEditor';
14+
import { RushGlobalFolders } from '../api/RushGlobalFolders';
1415

1516
/**
1617
* The type of SemVer range specifier that is prepended to the version
@@ -94,9 +95,11 @@ export interface IUpdateProjectOptions {
9495
*/
9596
export class PackageJsonUpdater {
9697
private _rushConfiguration: RushConfiguration;
98+
private _rushGlobalFolders: RushGlobalFolders;
9799

98-
public constructor(rushConfiguration: RushConfiguration) {
100+
public constructor(rushConfiguration: RushConfiguration, rushGlobalFolders: RushGlobalFolders) {
99101
this._rushConfiguration = rushConfiguration;
102+
this._rushGlobalFolders = rushGlobalFolders;
100103
}
101104

102105
/**
@@ -182,7 +185,7 @@ export class PackageJsonUpdater {
182185
return Promise.resolve();
183186
}
184187

185-
const purgeManager: PurgeManager = new PurgeManager(this._rushConfiguration);
188+
const purgeManager: PurgeManager = new PurgeManager(this._rushConfiguration, this._rushGlobalFolders);
186189
const installManagerOptions: IInstallManagerOptions = {
187190
debug: debugInstall,
188191
allowShrinkwrapUpdates: true,
@@ -196,8 +199,10 @@ export class PackageJsonUpdater {
196199
};
197200
const installManager: InstallManager = new InstallManager(
198201
this._rushConfiguration,
202+
this._rushGlobalFolders,
199203
purgeManager,
200-
installManagerOptions);
204+
installManagerOptions
205+
);
201206

202207
console.log();
203208
console.log(colors.green('Running "rush update"'));

0 commit comments

Comments
 (0)