@rushstack/rush-amazon-s3-build-cache-plugin 5.98.0 → 5.99.0

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.
@@ -8,6 +8,10 @@ const AmazonS3Client_1 = require("./AmazonS3Client");
8
8
  const WebClient_1 = require("./WebClient");
9
9
  const DEFAULT_S3_REGION = 'us-east-1';
10
10
  class AmazonS3BuildCacheProvider {
11
+ get isCacheWriteAllowed() {
12
+ var _a;
13
+ return (_a = rush_sdk_1.EnvironmentConfiguration.buildCacheWriteAllowed) !== null && _a !== void 0 ? _a : this._isCacheWriteAllowedByConfiguration;
14
+ }
11
15
  constructor(options, rushSession) {
12
16
  this._rushSession = rushSession;
13
17
  this._options = options;
@@ -15,10 +19,6 @@ class AmazonS3BuildCacheProvider {
15
19
  this._environmentCredential = rush_sdk_1.EnvironmentConfiguration.buildCacheCredential;
16
20
  this._isCacheWriteAllowedByConfiguration = options.isCacheWriteAllowed;
17
21
  }
18
- get isCacheWriteAllowed() {
19
- var _a;
20
- return (_a = rush_sdk_1.EnvironmentConfiguration.buildCacheWriteAllowed) !== null && _a !== void 0 ? _a : this._isCacheWriteAllowedByConfiguration;
21
- }
22
22
  get _s3Endpoint() {
23
23
  const options = this._options;
24
24
  if ('s3Bucket' in options) {
@@ -1 +1 @@
1
- {"version":3,"file":"AmazonS3BuildCacheProvider.js","sourceRoot":"","sources":["../src/AmazonS3BuildCacheProvider.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,kDAQ6B;AAE7B,qDAAwE;AACxE,2CAAwC;AA0BxC,MAAM,iBAAiB,GAAgB,WAAW,CAAC;AACnD,MAAa,0BAA0B;IAgBrC,YACE,OAA8F,EAC9F,WAAwB;QAExB,IAAI,CAAC,YAAY,GAAG,WAAW,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,QAAQ,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BAAgB,CAAC,mBAAmB,EAAE,CAAC;QAC/C,CAAC,CACF,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,sCAAsC,CAAC,QAAmB;QACrE,MAAM,IAAI,KAAK,CACb,0EAA0E;YACxE,4FAA4F;YAC5F,wDAAwD;YACxD,sDAAsD,CACzD,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,4BAA4B,CAAC,QAAmB;QAC3D,MAAM,0BAAe,CAAC,UAAU,CAC9B;YACE,cAAc,EAAE,IAAI;SACrB,EACD,KAAK,EAAE,gBAAiC,EAAE,EAAE;YAC1C,gBAAgB,CAAC,gBAAgB,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YAC3D,MAAM,gBAAgB,CAAC,mBAAmB,EAAE,CAAC;QAC/C,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAhLD,gEAgLC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { ITerminal } from '@rushstack/node-core-library';\nimport {\n ICloudBuildCacheProvider,\n ICredentialCacheEntry,\n CredentialCache,\n RushSession,\n RushConstants,\n EnvironmentVariableNames,\n EnvironmentConfiguration\n} from '@rushstack/rush-sdk';\n\nimport { AmazonS3Client, IAmazonS3Credentials } from './AmazonS3Client';\nimport { WebClient } from './WebClient';\n\n/**\n * @public\n */\nexport interface IAmazonS3BuildCacheProviderOptionsBase {\n s3Region: string;\n s3Prefix: string | undefined;\n isCacheWriteAllowed: boolean;\n}\n\n/**\n * Advanced options where user has the specify the full http endpoint\n * @public\n */\nexport interface IAmazonS3BuildCacheProviderOptionsAdvanced extends IAmazonS3BuildCacheProviderOptionsBase {\n s3Endpoint: string;\n}\n/**\n * Simple options where user only provides the bucket and the endpoint is automatically built\n * @public\n */\nexport interface IAmazonS3BuildCacheProviderOptionsSimple extends IAmazonS3BuildCacheProviderOptionsBase {\n s3Bucket: string;\n}\n\nconst DEFAULT_S3_REGION: 'us-east-1' = 'us-east-1';\nexport class AmazonS3BuildCacheProvider implements ICloudBuildCacheProvider {\n private readonly _options:\n | IAmazonS3BuildCacheProviderOptionsSimple\n | IAmazonS3BuildCacheProviderOptionsAdvanced;\n private readonly _s3Prefix: string | undefined;\n private readonly _environmentCredential: string | undefined;\n private readonly _isCacheWriteAllowedByConfiguration: boolean;\n private __credentialCacheId: string | undefined;\n private _rushSession: RushSession;\n\n public get isCacheWriteAllowed(): boolean {\n return EnvironmentConfiguration.buildCacheWriteAllowed ?? this._isCacheWriteAllowedByConfiguration;\n }\n\n private __s3Client: AmazonS3Client | undefined;\n\n public constructor(\n options: IAmazonS3BuildCacheProviderOptionsSimple | IAmazonS3BuildCacheProviderOptionsAdvanced,\n rushSession: RushSession\n ) {\n this._rushSession = rushSession;\n this._options = options;\n this._s3Prefix = options.s3Prefix;\n this._environmentCredential = EnvironmentConfiguration.buildCacheCredential;\n this._isCacheWriteAllowedByConfiguration = options.isCacheWriteAllowed;\n }\n\n private get _s3Endpoint(): string {\n const options: IAmazonS3BuildCacheProviderOptionsSimple | IAmazonS3BuildCacheProviderOptionsAdvanced =\n this._options;\n if ('s3Bucket' in options) {\n // options: IAmazonS3BuildCacheProviderOptionsSimple\n const bucket: string = options.s3Bucket;\n if (options.s3Region === DEFAULT_S3_REGION) {\n return `https://${bucket}.s3.amazonaws.com`;\n } else {\n return `https://${bucket}.s3-${options.s3Region}.amazonaws.com`;\n }\n }\n // options: IAmazonS3BuildCacheProviderOptionsAdvanced\n return options.s3Endpoint;\n }\n\n private get _credentialCacheId(): string {\n if (!this.__credentialCacheId) {\n const cacheIdParts: string[] = ['aws-s3', this._options.s3Region, this._s3Endpoint];\n\n if (this._isCacheWriteAllowedByConfiguration) {\n cacheIdParts.push('cacheWriteAllowed');\n }\n\n this.__credentialCacheId = cacheIdParts.join('|');\n }\n\n return this.__credentialCacheId;\n }\n\n private async _getS3ClientAsync(terminal: ITerminal): Promise<AmazonS3Client> {\n if (!this.__s3Client) {\n let credentials: IAmazonS3Credentials | undefined = AmazonS3Client.tryDeserializeCredentials(\n this._environmentCredential\n );\n\n if (!credentials) {\n let cacheEntry: ICredentialCacheEntry | undefined;\n await CredentialCache.usingAsync(\n {\n supportEditing: false\n },\n (credentialsCache: CredentialCache) => {\n cacheEntry = credentialsCache.tryGetCacheEntry(this._credentialCacheId);\n }\n );\n\n if (cacheEntry) {\n const expirationTime: number | undefined = cacheEntry.expires?.getTime();\n if (expirationTime && expirationTime < Date.now()) {\n throw new Error(\n 'Cached Amazon S3 credentials have expired. ' +\n `Update the credentials by running \"rush ${RushConstants.updateCloudCredentialsCommandName}\".`\n );\n } else {\n credentials = AmazonS3Client.tryDeserializeCredentials(cacheEntry?.credential);\n }\n } else if (this._isCacheWriteAllowedByConfiguration) {\n throw new Error(\n \"An Amazon S3 credential hasn't been provided, or has expired. \" +\n `Update the credentials by running \"rush ${RushConstants.updateCloudCredentialsCommandName}\", ` +\n `or provide an <AccessKeyId>:<SecretAccessKey> pair in the ` +\n `${EnvironmentVariableNames.RUSH_BUILD_CACHE_CREDENTIAL} environment variable`\n );\n }\n }\n\n this.__s3Client = new AmazonS3Client(\n credentials,\n {\n ...this._options,\n // advanced options\n s3Endpoint: this._s3Endpoint\n },\n new WebClient(),\n terminal\n );\n }\n\n return this.__s3Client;\n }\n\n public async tryGetCacheEntryBufferByIdAsync(\n terminal: ITerminal,\n cacheId: string\n ): Promise<Buffer | undefined> {\n try {\n const client: AmazonS3Client = await this._getS3ClientAsync(terminal);\n return await client.getObjectAsync(this._s3Prefix ? `${this._s3Prefix}/${cacheId}` : cacheId);\n } catch (e) {\n terminal.writeWarningLine(`Error getting cache entry from S3: ${e}`);\n return undefined;\n }\n }\n\n public async trySetCacheEntryBufferAsync(\n terminal: ITerminal,\n cacheId: string,\n objectBuffer: Buffer\n ): Promise<boolean> {\n if (!this.isCacheWriteAllowed) {\n terminal.writeErrorLine('Writing to S3 cache is not allowed in the current configuration.');\n return false;\n }\n\n terminal.writeDebugLine('Uploading object with cacheId: ', cacheId);\n\n try {\n const client: AmazonS3Client = await this._getS3ClientAsync(terminal);\n await client.uploadObjectAsync(this._s3Prefix ? `${this._s3Prefix}/${cacheId}` : cacheId, objectBuffer);\n return true;\n } catch (e) {\n terminal.writeWarningLine(`Error uploading cache entry to S3: ${e}`);\n return false;\n }\n }\n\n public async updateCachedCredentialAsync(terminal: ITerminal, credential: string): Promise<void> {\n await CredentialCache.usingAsync(\n {\n supportEditing: true\n },\n async (credentialsCache: CredentialCache) => {\n credentialsCache.setCacheEntry(this._credentialCacheId, { credential });\n await credentialsCache.saveIfModifiedAsync();\n }\n );\n }\n\n public async updateCachedCredentialInteractiveAsync(terminal: ITerminal): Promise<void> {\n throw new Error(\n 'The interactive cloud credentials flow is not supported for Amazon S3.\\n' +\n 'Provide your credentials to rush using the --credential flag instead. Credentials must be ' +\n 'in the form of <ACCESS KEY ID>:<SECRET ACCESS KEY> or ' +\n '<ACCESS KEY ID>:<SECRET ACCESS KEY>:<SESSION TOKEN>.'\n );\n }\n\n public async deleteCachedCredentialsAsync(terminal: ITerminal): Promise<void> {\n await CredentialCache.usingAsync(\n {\n supportEditing: true\n },\n async (credentialsCache: CredentialCache) => {\n credentialsCache.deleteCacheEntry(this._credentialCacheId);\n await credentialsCache.saveIfModifiedAsync();\n }\n );\n }\n}\n"]}
1
+ {"version":3,"file":"AmazonS3BuildCacheProvider.js","sourceRoot":"","sources":["../src/AmazonS3BuildCacheProvider.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,kDAQ6B;AAE7B,qDAAwE;AACxE,2CAAwC;AA0BxC,MAAM,iBAAiB,GAAgB,WAAW,CAAC;AACnD,MAAa,0BAA0B;IAUrC,IAAW,mBAAmB;;QAC5B,OAAO,MAAA,mCAAwB,CAAC,sBAAsB,mCAAI,IAAI,CAAC,mCAAmC,CAAC;IACrG,CAAC;IAID,YACE,OAA8F,EAC9F,WAAwB;QAExB,IAAI,CAAC,YAAY,GAAG,WA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AAC,mBAAmB,EAAE,CAAC;QAC/C,CAAC,CACF,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,sCAAsC,CAAC,QAAmB;QACrE,MAAM,IAAI,KAAK,CACb,0EAA0E;YACxE,4FAA4F;YAC5F,wDAAwD;YACxD,sDAAsD,CACzD,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,4BAA4B,CAAC,QAAmB;QAC3D,MAAM,0BAAe,CAAC,UAAU,CAC9B;YACE,cAAc,EAAE,IAAI;SACrB,EACD,KAAK,EAAE,gBAAiC,EAAE,EAAE;YAC1C,gBAAgB,CAAC,gBAAgB,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;YAC3D,MAAM,gBAAgB,CAAC,mBAAmB,EAAE,CAAC;QAC/C,CAAC,CACF,CAAC;IACJ,CAAC;CACF;AAhLD,gEAgLC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { ITerminal } from '@rushstack/node-core-library';\nimport {\n ICloudBuildCacheProvider,\n ICredentialCacheEntry,\n CredentialCache,\n RushSession,\n RushConstants,\n EnvironmentVariableNames,\n EnvironmentConfiguration\n} from '@rushstack/rush-sdk';\n\nimport { AmazonS3Client, IAmazonS3Credentials } from './AmazonS3Client';\nimport { WebClient } from './WebClient';\n\n/**\n * @public\n */\nexport interface IAmazonS3BuildCacheProviderOptionsBase {\n s3Region: string;\n s3Prefix: string | undefined;\n isCacheWriteAllowed: boolean;\n}\n\n/**\n * Advanced options where user has the specify the full http endpoint\n * @public\n */\nexport interface IAmazonS3BuildCacheProviderOptionsAdvanced extends IAmazonS3BuildCacheProviderOptionsBase {\n s3Endpoint: string;\n}\n/**\n * Simple options where user only provides the bucket and the endpoint is automatically built\n * @public\n */\nexport interface IAmazonS3BuildCacheProviderOptionsSimple extends IAmazonS3BuildCacheProviderOptionsBase {\n s3Bucket: string;\n}\n\nconst DEFAULT_S3_REGION: 'us-east-1' = 'us-east-1';\nexport class AmazonS3BuildCacheProvider implements ICloudBuildCacheProvider {\n private readonly _options:\n | IAmazonS3BuildCacheProviderOptionsSimple\n | IAmazonS3BuildCacheProviderOptionsAdvanced;\n private readonly _s3Prefix: string | undefined;\n private readonly _environmentCredential: string | undefined;\n private readonly _isCacheWriteAllowedByConfiguration: boolean;\n private __credentialCacheId: string | undefined;\n private _rushSession: RushSession;\n\n public get isCacheWriteAllowed(): boolean {\n return EnvironmentConfiguration.buildCacheWriteAllowed ?? this._isCacheWriteAllowedByConfiguration;\n }\n\n private __s3Client: AmazonS3Client | undefined;\n\n public constructor(\n options: IAmazonS3BuildCacheProviderOptionsSimple | IAmazonS3BuildCacheProviderOptionsAdvanced,\n rushSession: RushSession\n ) {\n this._rushSession = rushSession;\n this._options = options;\n this._s3Prefix = options.s3Prefix;\n this._environmentCredential = EnvironmentConfiguration.buildCacheCredential;\n this._isCacheWriteAllowedByConfiguration = options.isCacheWriteAllowed;\n }\n\n private get _s3Endpoint(): string {\n const options: IAmazonS3BuildCacheProviderOptionsSimple | IAmazonS3BuildCacheProviderOptionsAdvanced =\n this._options;\n if ('s3Bucket' in options) {\n // options: IAmazonS3BuildCacheProviderOptionsSimple\n const bucket: string = options.s3Bucket;\n if (options.s3Region === DEFAULT_S3_REGION) {\n return `https://${bucket}.s3.amazonaws.com`;\n } else {\n return `https://${bucket}.s3-${options.s3Region}.amazonaws.com`;\n }\n }\n // options: IAmazonS3BuildCacheProviderOptionsAdvanced\n return options.s3Endpoint;\n }\n\n private get _credentialCacheId(): string {\n if (!this.__credentialCacheId) {\n const cacheIdParts: string[] = ['aws-s3', this._options.s3Region, this._s3Endpoint];\n\n if (this._isCacheWriteAllowedByConfiguration) {\n cacheIdParts.push('cacheWriteAllowed');\n }\n\n this.__credentialCacheId = cacheIdParts.join('|');\n }\n\n return this.__credentialCacheId;\n }\n\n private async _getS3ClientAsync(terminal: ITerminal): Promise<AmazonS3Client> {\n if (!this.__s3Client) {\n let credentials: IAmazonS3Credentials | undefined = AmazonS3Client.tryDeserializeCredentials(\n this._environmentCredential\n );\n\n if (!credentials) {\n let cacheEntry: ICredentialCacheEntry | undefined;\n await CredentialCache.usingAsync(\n {\n supportEditing: false\n },\n (credentialsCache: CredentialCache) => {\n cacheEntry = credentialsCache.tryGetCacheEntry(this._credentialCacheId);\n }\n );\n\n if (cacheEntry) {\n const expirationTime: number | undefined = cacheEntry.expires?.getTime();\n if (expirationTime && expirationTime < Date.now()) {\n throw new Error(\n 'Cached Amazon S3 credentials have expired. ' +\n `Update the credentials by running \"rush ${RushConstants.updateCloudCredentialsCommandName}\".`\n );\n } else {\n credentials = AmazonS3Client.tryDeserializeCredentials(cacheEntry?.credential);\n }\n } else if (this._isCacheWriteAllowedByConfiguration) {\n throw new Error(\n \"An Amazon S3 credential hasn't been provided, or has expired. \" +\n `Update the credentials by running \"rush ${RushConstants.updateCloudCredentialsCommandName}\", ` +\n `or provide an <AccessKeyId>:<SecretAccessKey> pair in the ` +\n `${EnvironmentVariableNames.RUSH_BUILD_CACHE_CREDENTIAL} environment variable`\n );\n }\n }\n\n this.__s3Client = new AmazonS3Client(\n credentials,\n {\n ...this._options,\n // advanced options\n s3Endpoint: this._s3Endpoint\n },\n new WebClient(),\n terminal\n );\n }\n\n return this.__s3Client;\n }\n\n public async tryGetCacheEntryBufferByIdAsync(\n terminal: ITerminal,\n cacheId: string\n ): Promise<Buffer | undefined> {\n try {\n const client: AmazonS3Client = await this._getS3ClientAsync(terminal);\n return await client.getObjectAsync(this._s3Prefix ? `${this._s3Prefix}/${cacheId}` : cacheId);\n } catch (e) {\n terminal.writeWarningLine(`Error getting cache entry from S3: ${e}`);\n return undefined;\n }\n }\n\n public async trySetCacheEntryBufferAsync(\n terminal: ITerminal,\n cacheId: string,\n objectBuffer: Buffer\n ): Promise<boolean> {\n if (!this.isCacheWriteAllowed) {\n terminal.writeErrorLine('Writing to S3 cache is not allowed in the current configuration.');\n return false;\n }\n\n terminal.writeDebugLine('Uploading object with cacheId: ', cacheId);\n\n try {\n const client: AmazonS3Client = await this._getS3ClientAsync(terminal);\n await client.uploadObjectAsync(this._s3Prefix ? `${this._s3Prefix}/${cacheId}` : cacheId, objectBuffer);\n return true;\n } catch (e) {\n terminal.writeWarningLine(`Error uploading cache entry to S3: ${e}`);\n return false;\n }\n }\n\n public async updateCachedCredentialAsync(terminal: ITerminal, credential: string): Promise<void> {\n await CredentialCache.usingAsync(\n {\n supportEditing: true\n },\n async (credentialsCache: CredentialCache) => {\n credentialsCache.setCacheEntry(this._credentialCacheId, { credential });\n await credentialsCache.saveIfModifiedAsync();\n }\n );\n }\n\n public async updateCachedCredentialInteractiveAsync(terminal: ITerminal): Promise<void> {\n throw new Error(\n 'The interactive cloud credentials flow is not supported for Amazon S3.\\n' +\n 'Provide your credentials to rush using the --credential flag instead. Credentials must be ' +\n 'in the form of <ACCESS KEY ID>:<SECRET ACCESS KEY> or ' +\n '<ACCESS KEY ID>:<SECRET ACCESS KEY>:<SESSION TOKEN>.'\n );\n }\n\n public async deleteCachedCredentialsAsync(terminal: ITerminal): Promise<void> {\n await CredentialCache.usingAsync(\n {\n supportEditing: true\n },\n async (credentialsCache: CredentialCache) => {\n credentialsCache.deleteCacheEntry(this._credentialCacheId);\n await credentialsCache.saveIfModifiedAsync();\n }\n );\n }\n}\n"]}
@@ -5,7 +5,7 @@ import * as fetch from 'node-fetch';
5
5
  *
6
6
  * @public
7
7
  */
8
- export declare type WebClientResponse = fetch.Response;
8
+ export type WebClientResponse = fetch.Response;
9
9
  /**
10
10
  * For use with {@link WebClient}.
11
11
  *
@@ -1 +1 @@
1
- {"version":3,"file":"WebClient.d.ts","sourceRoot":"","sources":["../src/WebClient.ts"],"names":[],"mappings":";AAaA,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AAMpC;;;;GAIG;AACH,oBAAY,iBAAiB,GAAG,KAAK,CAAC,QAAQ,CAAC;AAE/C;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC,SAAS,CAAC,EA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AE,KAAK,GAAG,KAAK,CAAC;IACrB,OAAO,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC;CACzB;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAiB,SAAQ,oBAAoB;IAC5D,IAAI,EAAE,KAAK,GAAG,KAAK,CAAC;CACrB;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAiB,SAAQ,oBAAoB;IAC5D,IAAI,EAAE,KAAK,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,oBAAY,cAAc;IACxB,IAAI,IAAA;IACJ,MAAM,IAAA;IACN,OAAO,IAAA;CACR;AAED;;;;GAIG;AACH,qBAAa,SAAS;IACpB,SAAgB,eAAe,EAAE,KAAK,CAAC,OAAO,CAAuB;IAE9D,MAAM,EAAE,MAAM,GAAG,SAAS,CAAS;IACnC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAgE;IAE7F,KAAK,EAAE,cAAc,CAAyB;;WAIvC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,OAAO,GAAG,IAAI;IAMvE,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;IAOtD,UAAU,CACrB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,gBAAgB,GAAG,gBAAgB,GAC5C,OAAO,CAAC,iBAAiB,CAAC;CAsD9B"}
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.34.9"
8
+ "packageVersion": "7.35.1"
9
9
  }
10
10
  ]
11
11
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/rush-amazon-s3-build-cache-plugin",
3
- "version": "5.98.0",
3
+ "version": "5.99.0",
4
4
  "description": "Rush plugin for Amazon S3 cloud build cache",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,23 +14,23 @@
14
14
  "dependencies": {
15
15
  "https-proxy-agent": "~5.0.0",
16
16
  "node-fetch": "2.6.7",
17
- "@rushstack/node-core-library": "3.59.0",
18
- "@rushstack/rush-sdk": "5.98.0"
17
+ "@rushstack/node-core-library": "3.59.2",
18
+ "@rushstack/rush-sdk": "5.99.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/heft-jest": "1.0.1",
22
22
  "@types/node": "14.18.36",
23
23
  "@types/node-fetch": "2.6.2",
24
- "@microsoft/rush-lib": "5.98.0",
25
- "@rushstack/eslint-config": "3.2.0",
26
- "@rushstack/heft": "0.50.5",
27
- "@rushstack/heft-node-rig": "1.12.11"
24
+ "@microsoft/rush-lib": "5.99.0",
25
+ "@rushstack/eslint-config": "3.3.0",
26
+ "@rushstack/heft": "0.51.0",
27
+ "@rushstack/heft-node-rig": "2.0.0"
28
28
  },
29
29
  "scripts": {
30
30
  "build": "heft build --clean",
31
31
  "start": "heft test --clean --watch",
32
32
  "test": "heft test",
33
- "_phase:build": "heft build --clean",
34
- "_phase:test": "heft test --no-build"
33
+ "_phase:build": "heft run --only build -- --clean",
34
+ "_phase:test": "heft run --only test -- --clean"
35
35
  }
36
36
  }