Skip to content

Commit 9f5da93

Browse files
committed
feat: extract amazon & azure cloud build cache plugins
1 parent da5cc91 commit 9f5da93

Some content is hidden

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

46 files changed

+647
-71
lines changed

apps/rush-lib/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
},
2020
"license": "MIT",
2121
"dependencies": {
22-
"@azure/identity": "~1.0.0",
23-
"@azure/storage-blob": "~12.3.0",
2422
"@pnpm/link-bins": "~5.3.7",
2523
"@rushstack/heft-config-file": "workspace:*",
2624
"@rushstack/node-core-library": "workspace:*",

apps/rush-lib/src/api/BuildCacheConfiguration.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,25 @@ interface IBaseBuildCacheJson {
2828
cacheProvider: string;
2929
cacheEntryNamePattern?: string;
3030
}
31-
interface ILocalBuildCacheJson extends IBaseBuildCacheJson {
31+
32+
/**
33+
* @public
34+
*/
35+
export interface ILocalBuildCacheJson extends IBaseBuildCacheJson {
3236
readonly cacheProvider: 'local-only';
3337
}
3438

35-
interface ICloudBuildCacheJson extends IBaseBuildCacheJson {
39+
/**
40+
* @public
41+
*/
42+
export interface ICloudBuildCacheJson extends IBaseBuildCacheJson {
3643
readonly cacheProvider: string;
3744
[otherConfigKey: string]: JsonObject;
3845
}
3946

47+
/**
48+
* @public
49+
*/
4050
export type IBuildCacheJson = ICloudBuildCacheJson | ILocalBuildCacheJson;
4151

4252
interface IBuildCacheConfigurationOptions {

apps/rush-lib/src/api/EnvironmentConfiguration.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ export const enum EnvironmentVariableNames {
154154
/**
155155
* Provides Rush-specific environment variable data. All Rush environment variables must start with "RUSH_". This class
156156
* is designed to be used by RushConfiguration.
157+
* @public
157158
*
158159
* @remarks
159160
* Initialize will throw if any unknown parameters are present.
@@ -474,7 +475,7 @@ export class EnvironmentConfiguration {
474475
* this function returns undefined.
475476
*
476477
* @example
477-
* If the following path exists on disk: C:\Folder1\folder2\
478+
* If the following path exists on disk: `C:\Folder1\folder2\`
478479
* _normalizeFirstExistingFolderPath('c:\\folder1\\folder2\\temp\\subfolder')
479480
* returns 'C:\\Folder1\\folder2\\temp\\subfolder'
480481
*/

apps/rush-lib/src/index.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export {
2626

2727
export { PackageManagerName, PackageManager } from './api/packageManager/PackageManager';
2828

29-
export { EnvironmentVariableNames } from './api/EnvironmentConfiguration';
29+
export { EnvironmentVariableNames, EnvironmentConfiguration } from './api/EnvironmentConfiguration';
3030

3131
export { RushConfigurationProject } from './api/RushConfigurationProject';
3232

@@ -70,6 +70,20 @@ export { Logger, ILogger, ILoggerOptions } from './pluginFramework/logging/Logge
7070

7171
export { RushLifecycleHooks, IRushLifecycle } from './pluginFramework/RushLifeCycle';
7272

73-
export { IBuildCacheJson } from './api/BuildCacheConfiguration';
73+
export { IBuildCacheJson, ILocalBuildCacheJson, ICloudBuildCacheJson } from './api/BuildCacheConfiguration';
7474

7575
export { CloudBuildCacheProviderBase } from './logic/buildCache/CloudBuildCacheProviderBase';
76+
77+
export { RushConstants } from './logic/RushConstants';
78+
79+
export { CredentialCache, ICredentialCacheOptions, ICredentialCacheEntry } from './logic/CredentialCache';
80+
81+
export { RushUserConfiguration } from './api/RushUserConfiguration';
82+
83+
export {
84+
WebClient,
85+
IPutFetchOptions,
86+
IGetFetchOptions,
87+
WebClientResponse,
88+
WebClientProxy
89+
} from './utilities/WebClient';

apps/rush-lib/src/logic/CredentialCache.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ interface ICacheEntryJson {
2222
credential: string;
2323
}
2424

25+
/**
26+
* @beta
27+
*/
2528
export interface ICredentialCacheEntry {
2629
expires?: Date;
2730
credential: string;
2831
}
2932

33+
/**
34+
* @beta
35+
*/
3036
export interface ICredentialCacheOptions {
3137
supportEditing: boolean;
3238
}

apps/rush-lib/src/logic/RushConstants.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
/**
55
* Constants used by the Rush tool.
6+
* @public
67
*
78
* @remarks
89
*
@@ -40,7 +41,7 @@ export class RushConstants {
4041
public static readonly commonFolderName: string = 'common';
4142

4243
/**
43-
* The NPM scope ("@rush-temp") that is used for Rush's temporary projects.
44+
* The NPM scope ("\@rush-temp") that is used for Rush's temporary projects.
4445
*/
4546
public static readonly rushTempNpmScope: string = '@rush-temp';
4647

@@ -60,7 +61,7 @@ export class RushConstants {
6061
/**
6162
* The folder name ("variants") under which named variant configurations for
6263
* alternate dependency sets may be found.
63-
* Example: "C:\MyRepo\common\config\rush\variants"
64+
* Example: `C:\MyRepo\common\config\rush\variants`
6465
*/
6566
public static readonly rushVariantsFolderName: string = 'variants';
6667

@@ -164,7 +165,7 @@ export class RushConstants {
164165
public static readonly rushWebSiteUrl: string = 'https://rushjs.io';
165166

166167
/**
167-
* The name of the NPM package for the Rush tool ("@microsoft/rush").
168+
* The name of the NPM package for the Rush tool ("\@microsoft/rush").
168169
*/
169170
public static readonly rushPackageName: string = '@microsoft/rush';
170171

apps/rush-lib/src/logic/buildCache/CloudBuildCacheProviderBase.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
import { ITerminal } from '@rushstack/node-core-library';
55

6+
/**
7+
* @beta
8+
*/
69
export abstract class CloudBuildCacheProviderBase {
710
public abstract readonly isCacheWriteAllowed: boolean;
811

apps/rush-lib/src/pluginFramework/PluginManager.ts

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
// See LICENSE in the project root for license information.
33

44
import { InternalError, Terminal } from '@rushstack/node-core-library';
5+
56
import { IRushPluginConfigJson, RushConfiguration } from '../api/RushConfiguration';
67
import { Autoinstaller } from '../logic/Autoinstaller';
7-
import AmazonS3BuildCachePlugin from '../plugins/AmazonS3BuildCachePlugin';
8-
import AzureStorageBuildCachePlugin from '../plugins/AzureStorageBuildCachePlugin';
98
import { IRushPlugin } from './IRushPlugin';
109
import { RushSession } from './RushSession';
1110

@@ -31,8 +30,6 @@ export class PluginManager {
3130
private _terminal: Terminal;
3231
private _rushConfiguration: RushConfiguration;
3332
private _rushSession: RushSession;
34-
private _appliedPlugins: IRushPlugin[] = [];
35-
private _appliedPluginNames: Set<string> = new Set<string>();
3633

3734
public constructor(options: IPluginManagerOptions) {
3835
this._terminal = options.terminal;
@@ -44,10 +41,7 @@ export class PluginManager {
4441
return this._rushConfiguration.rushConfigurationJson.rushPlugins || [];
4542
}
4643

47-
public initializeDefaultPlugins(): void {
48-
this._applyPlugin(new AzureStorageBuildCachePlugin());
49-
this._applyPlugin(new AmazonS3BuildCachePlugin());
50-
}
44+
public initializeDefaultPlugins(): void {}
5145

5246
public async initializePluginsFromConfigFileAsync(): Promise<void> {
5347
const rushPluginConfigurations: IRushPluginConfigJson[] = this.rushPluginConfigurations;
@@ -88,22 +82,16 @@ export class PluginManager {
8882
options
8983
);
9084

91-
if (this._appliedPluginNames.has(plugin.pluginName)) {
92-
throw new Error(
93-
`Error applying plugin "${resolvedPluginPath}": A plugin with name "${plugin.pluginName}" has ` +
94-
'already been applied'
95-
);
96-
} else {
97-
this._applyPlugin(plugin, options);
98-
}
85+
this._applyPlugin(plugin, options);
9986
}
10087

10188
private _loadAndValidatePluginPackage(resolvedPluginPath: string, options?: object): IRushPlugin {
102-
let pluginPackage: IRushPlugin;
89+
type IRushPluginCtor = new () => IRushPlugin<object | void>;
90+
let pluginPackage: IRushPluginCtor;
10391
try {
10492
// eslint-disable-next-line @typescript-eslint/no-var-requires
105-
const loadedPluginPackage: IRushPlugin | { default: IRushPlugin } = require(resolvedPluginPath);
106-
pluginPackage = (loadedPluginPackage as { default: IRushPlugin }).default || loadedPluginPackage;
93+
const loadedPluginPackage: IRushPluginCtor | { default: IRushPluginCtor } = require(resolvedPluginPath);
94+
pluginPackage = (loadedPluginPackage as { default: IRushPluginCtor }).default || loadedPluginPackage;
10795
} catch (e) {
10896
throw new InternalError(`Error loading plugin package from "${resolvedPluginPath}": ${e}`);
10997
}
@@ -114,38 +102,38 @@ export class PluginManager {
114102

115103
this._terminal.writeVerboseLine(`Loaded plugin package from "${resolvedPluginPath}"`);
116104

117-
if (!pluginPackage.apply || typeof pluginPackage.apply !== 'function') {
105+
const plugin: IRushPlugin<object | void> = new pluginPackage();
106+
107+
if (!plugin.apply || typeof pluginPackage.apply !== 'function') {
118108
throw new InternalError(
119109
`Plugin packages must define an "apply" function. The plugin loaded from "${resolvedPluginPath}" ` +
120110
'either doesn\'t define an "apply" property, or its value isn\'t a function.'
121111
);
122112
}
123113

124-
if (!pluginPackage.pluginName || typeof pluginPackage.pluginName !== 'string') {
114+
if (!plugin.pluginName || typeof plugin.pluginName !== 'string') {
125115
throw new InternalError(
126116
`Plugin packages must define a "pluginName" property. The plugin loaded from "${resolvedPluginPath}" ` +
127117
'either doesn\'t define a "pluginName" property, or its value isn\'t a string.'
128118
);
129119
}
130120

131-
if (options && pluginPackage.optionsSchema) {
121+
if (options && plugin.optionsSchema) {
132122
try {
133-
pluginPackage.optionsSchema.validateObject(options, 'rush.json');
123+
plugin.optionsSchema.validateObject(options, 'rush.json');
134124
} catch (e) {
135125
throw new Error(
136-
`Provided options for plugin "${pluginPackage.pluginName}" did not match the provided plugin schema.\n${e}`
126+
`Provided options for plugin "${plugin.pluginName}" did not match the provided plugin schema.\n${e}`
137127
);
138128
}
139129
}
140130

141-
return pluginPackage;
131+
return plugin;
142132
}
143133

144134
private _applyPlugin(plugin: IRushPlugin<object | void>, options?: object): void {
145135
try {
146136
plugin.apply(this._rushSession, this._rushConfiguration, options);
147-
this._appliedPlugins.push(plugin);
148-
this._appliedPluginNames.add(plugin.pluginName);
149137
} catch (e) {
150138
throw new InternalError(`Error applying "${plugin.pluginName}": ${e}`);
151139
}

apps/rush-lib/src/utilities/WebClient.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { Import } from '@rushstack/node-core-library';
66

77
const createHttpsProxyAgent: typeof import('https-proxy-agent') = Import.lazy('https-proxy-agent', require);
88

9+
/**
10+
* @public
11+
*/
912
export type WebClientResponse = fetch.Response;
1013

1114
export interface IWebFetchOptionsBase {
@@ -14,21 +17,33 @@ export interface IWebFetchOptionsBase {
1417
headers?: fetch.Headers;
1518
}
1619

20+
/**
21+
* @public
22+
*/
1723
export interface IGetFetchOptions extends IWebFetchOptionsBase {
1824
verb: 'GET' | never;
1925
}
2026

27+
/**
28+
* @public
29+
*/
2130
export interface IPutFetchOptions extends IWebFetchOptionsBase {
2231
verb: 'PUT';
2332
body?: Buffer;
2433
}
2534

35+
/**
36+
* @public
37+
*/
2638
export enum WebClientProxy {
2739
None,
2840
Detect,
2941
Fiddler
3042
}
3143

44+
/**
45+
* @public
46+
*/
3247
export class WebClient {
3348
public readonly standardHeaders: fetch.Headers = new fetch.Headers();
3449

common/config/rush/browser-approved-packages.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
{
33
"$schema": "https://developer.microsoft.com/json-schemas/rush/v5/approved-packages.schema.json",
44
"packages": [
5+
{
6+
"name": "@rushstack/rush-amazon-s3-build-cache-plugin",
7+
"allowedCategories": [ "libraries" ]
8+
},
9+
{
10+
"name": "@rushstack/rush-azure-storage-build-cache-plugin",
11+
"allowedCategories": [ "libraries" ]
12+
},
13+
{
14+
"name": "@rushstack/rush-lib",
15+
"allowedCategories": [ "libraries" ]
16+
},
517
{
618
"name": "react",
719
"allowedCategories": [ "tests" ]

0 commit comments

Comments
 (0)