@rushstack/rush-http-build-cache-plugin 5.113.4 → 5.114.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.
Files changed (37) hide show
  1. package/.eslintrc.js +12 -0
  2. package/.rush/temp/operation/_phase_build/all.log +3 -2
  3. package/.rush/temp/operation/_phase_build/state.json +1 -1
  4. package/.rush/temp/operation/_phase_test/all.log +3 -3
  5. package/.rush/temp/operation/_phase_test/state.json +1 -1
  6. package/.rush/temp/{rushstack+rush-http-build-cache-plugin-_phase_build-0959f6ff3364a08451be32d25795047fc38a09fe.tar.log → rushstack+rush-http-build-cache-plugin-_phase_build-bdf30e460f994579fa5d5b8a382c75152ff42394.tar.log} +3 -2
  7. package/.rush/temp/{rushstack+rush-http-build-cache-plugin-_phase_build-0959f6ff3364a08451be32d25795047fc38a09fe.untar.log → rushstack+rush-http-build-cache-plugin-_phase_build-bdf30e460f994579fa5d5b8a382c75152ff42394.untar.log} +2 -2
  8. package/.rush/temp/{rushstack+rush-http-build-cache-plugin-_phase_test-aff7df502d985d6583980fce14fc03bc89c7ddcf.tar.log → rushstack+rush-http-build-cache-plugin-_phase_test-76e145455db25f136523ab72c2aaed644e2abb26.tar.log} +2 -2
  9. package/.rush/temp/{rushstack+rush-http-build-cache-plugin-_phase_test-aff7df502d985d6583980fce14fc03bc89c7ddcf.untar.log → rushstack+rush-http-build-cache-plugin-_phase_test-76e145455db25f136523ab72c2aaed644e2abb26.untar.log} +2 -2
  10. package/.rush/temp/shrinkwrap-deps.json +1 -1
  11. package/coverage/HttpBuildCacheProvider.ts.html +53 -26
  12. package/coverage/RushHttpBuildCachePlugin.ts.html +2 -2
  13. package/coverage/cobertura-coverage.xml +257 -245
  14. package/coverage/index.html +13 -13
  15. package/coverage/index.ts.html +14 -5
  16. package/coverage/junit.xml +4 -4
  17. package/lib/HttpBuildCacheProvider.d.ts +2 -2
  18. package/lib/HttpBuildCacheProvider.d.ts.map +1 -1
  19. package/lib/HttpBuildCacheProvider.js +2 -0
  20. package/lib/HttpBuildCacheProvider.js.map +1 -1
  21. package/lib/RushHttpBuildCachePlugin.js.map +1 -1
  22. package/lib/index.d.ts.map +1 -1
  23. package/lib/index.js +2 -0
  24. package/lib/index.js.map +1 -1
  25. package/lib/test/HttpBuildCacheProvider.test.js +3 -3
  26. package/lib/test/HttpBuildCacheProvider.test.js.map +1 -1
  27. package/package.json +7 -6
  28. package/rush-logs/rush-http-build-cache-plugin._phase_build.cache.log +4 -3
  29. package/rush-logs/rush-http-build-cache-plugin._phase_build.log +3 -2
  30. package/rush-logs/rush-http-build-cache-plugin._phase_test.cache.log +4 -4
  31. package/rush-logs/rush-http-build-cache-plugin._phase_test.log +3 -3
  32. package/src/HttpBuildCacheProvider.ts +29 -20
  33. package/src/RushHttpBuildCachePlugin.ts +1 -1
  34. package/src/index.ts +3 -0
  35. package/src/test/HttpBuildCacheProvider.test.ts +2 -2
  36. package/temp/build/lint/_eslint-it73M-Rx.json +21 -0
  37. package/temp/build/typescript/ts_l9Fw4VUO.json +1 -1
@@ -23,9 +23,9 @@
23
23
  <div class='clearfix'>
24
24
 
25
25
  <div class='fl pad1y space-right2'>
26
- <span class="strong">54.22% </span>
26
+ <span class="strong">53.93% </span>
27
27
  <span class="quiet">Statements</span>
28
- <span class='fraction'>276/509</span>
28
+ <span class='fraction'>281/521</span>
29
29
  </div>
30
30
 
31
31
 
@@ -44,9 +44,9 @@
44
44
 
45
45
 
46
46
  <div class='fl pad1y space-right2'>
47
- <span class="strong">54.22% </span>
47
+ <span class="strong">53.93% </span>
48
48
  <span class="quiet">Lines</span>
49
- <span class='fraction'>276/509</span>
49
+ <span class='fraction'>281/521</span>
50
50
  </div>
51
51
 
52
52
 
@@ -80,17 +80,17 @@
80
80
  </thead>
81
81
  <tbody><tr>
82
82
  <td class="file high" data-value="HttpBuildCacheProvider.ts"><a href="HttpBuildCacheProvider.ts.html">HttpBuildCacheProvider.ts</a></td>
83
- <td data-value="65.09" class="pic high">
84
- <div class="chart"><div class="cover-fill" style="width: 65%"></div><div class="cover-empty" style="width: 35%"></div></div>
83
+ <td data-value="64.89" class="pic high">
84
+ <div class="chart"><div class="cover-fill" style="width: 64%"></div><div class="cover-empty" style="width: 36%"></div></div>
85
85
  </td>
86
- <td data-value="65.09" class="pct high">65.09%</td>
87
- <td data-value="424" class="abs high">276/424</td>
86
+ <td data-value="64.89" class="pct high">64.89%</td>
87
+ <td data-value="433" class="abs high">281/433</td>
88
88
  <td data-value="55.17" class="pct high">55.17%</td>
89
89
  <td data-value="58" class="abs high">32/58</td>
90
90
  <td data-value="61.53" class="pct high">61.53%</td>
91
91
  <td data-value="13" class="abs high">8/13</td>
92
- <td data-value="65.09" class="pct high">65.09%</td>
93
- <td data-value="424" class="abs high">276/424</td>
92
+ <td data-value="64.89" class="pct high">64.89%</td>
93
+ <td data-value="433" class="abs high">281/433</td>
94
94
  </tr>
95
95
 
96
96
  <tr>
@@ -114,13 +114,13 @@
114
114
  <div class="chart"><div class="cover-fill" style="width: 0%"></div><div class="cover-empty" style="width: 100%"></div></div>
115
115
  </td>
116
116
  <td data-value="0" class="pct low">0%</td>
117
- <td data-value="4" class="abs low">0/4</td>
117
+ <td data-value="7" class="abs low">0/7</td>
118
118
  <td data-value="0" class="pct low">0%</td>
119
119
  <td data-value="1" class="abs low">0/1</td>
120
120
  <td data-value="0" class="pct low">0%</td>
121
121
  <td data-value="1" class="abs low">0/1</td>
122
122
  <td data-value="0" class="pct low">0%</td>
123
- <td data-value="4" class="abs low">0/4</td>
123
+ <td data-value="7" class="abs low">0/7</td>
124
124
  </tr>
125
125
 
126
126
  </tbody>
@@ -131,7 +131,7 @@
131
131
  <div class='footer quiet pad2 space-top1 center small'>
132
132
  Code coverage generated by
133
133
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
134
- at 2024-01-31T22:47:39.058Z
134
+ at 2024-02-19T21:52:46.098Z
135
135
  </div>
136
136
  <script src="prettify.js"></script>
137
137
  <script>
@@ -25,7 +25,7 @@
25
25
  <div class='fl pad1y space-right2'>
26
26
  <span class="strong">0% </span>
27
27
  <span class="quiet">Statements</span>
28
- <span class='fraction'>0/4</span>
28
+ <span class='fraction'>0/7</span>
29
29
  </div>
30
30
 
31
31
 
@@ -46,7 +46,7 @@
46
46
  <div class='fl pad1y space-right2'>
47
47
  <span class="strong">0% </span>
48
48
  <span class="quiet">Lines</span>
49
- <span class='fraction'>0/4</span>
49
+ <span class='fraction'>0/7</span>
50
50
  </div>
51
51
 
52
52
 
@@ -67,11 +67,20 @@
67
67
  <a name='L2'></a><a href='#L2'>2</a>
68
68
  <a name='L3'></a><a href='#L3'>3</a>
69
69
  <a name='L4'></a><a href='#L4'>4</a>
70
- <a name='L5'></a><a href='#L5'>5</a></td><td class="line-coverage quiet"><span class="cline-any cline-no">&nbsp;</span>
70
+ <a name='L5'></a><a href='#L5'>5</a>
71
+ <a name='L6'></a><a href='#L6'>6</a>
72
+ <a name='L7'></a><a href='#L7'>7</a>
73
+ <a name='L8'></a><a href='#L8'>8</a></td><td class="line-coverage quiet"><span class="cline-any cline-no">&nbsp;</span>
71
74
  <span class="cline-any cline-no">&nbsp;</span>
72
75
  <span class="cline-any cline-no">&nbsp;</span>
73
76
  <span class="cline-any cline-no">&nbsp;</span>
74
- <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js"><span class="cstat-no" title="statement not covered" >import { RushHttpBuildCachePlugin } from './RushHttpBuildCachePlugin';<span class="fstat-no" title="function not covered" ><span class="branch-0 cbranch-no" title="branch not covered" ></span></span></span>
77
+ <span class="cline-any cline-no">&nbsp;</span>
78
+ <span class="cline-any cline-no">&nbsp;</span>
79
+ <span class="cline-any cline-no">&nbsp;</span>
80
+ <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js"><span class="cstat-no" title="statement not covered" >// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.<span class="fstat-no" title="function not covered" ><span class="branch-0 cbranch-no" title="branch not covered" ></span></span></span>
81
+ <span class="cstat-no" title="statement not covered" >// See LICENSE in the project root for license information.</span>
82
+ <span class="cstat-no" title="statement not covered" ></span>
83
+ <span class="cstat-no" title="statement not covered" >import { RushHttpBuildCachePlugin } from './RushHttpBuildCachePlugin';</span>
75
84
  <span class="cstat-no" title="statement not covered" ></span>
76
85
  <span class="cstat-no" title="statement not covered" >export default RushHttpBuildCachePlugin;</span>
77
86
  <span class="cstat-no" title="statement not covered" >export { IHttpBuildCacheProviderOptions } from './HttpBuildCacheProvider';</span>
@@ -82,7 +91,7 @@
82
91
  <div class='footer quiet pad2 space-top1 center small'>
83
92
  Code coverage generated by
84
93
  <a href="https://istanbul.js.org/" target="_blank" rel="noopener noreferrer">istanbul</a>
85
- at 2024-01-31T22:47:39.058Z
94
+ at 2024-02-19T21:52:46.098Z
86
95
  </div>
87
96
  <script src="prettify.js"></script>
88
97
  <script>
@@ -1,9 +1,9 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <testsuites name="jest tests" tests="2" failures="0" errors="0" time="1.323">
3
- <testsuite name="HttpBuildCacheProvider" errors="0" failures="0" skipped="0" timestamp="2024-01-31T22:47:37" time="1.018" tests="2">
4
- <testcase classname="HttpBuildCacheProvider tryGetCacheEntryBufferByIdAsync &gt; " name="prints warning if read credentials are not available (lib/test/HttpBuildCacheProvider.test.js)" time="0.017">
2
+ <testsuites name="jest tests" tests="2" failures="0" errors="0" time="1.87">
3
+ <testsuite name="HttpBuildCacheProvider" errors="0" failures="0" skipped="0" timestamp="2024-02-19T21:52:43" time="1.559" tests="2">
4
+ <testcase classname="HttpBuildCacheProvider tryGetCacheEntryBufferByIdAsync &gt; " name="prints warning if read credentials are not available (lib/test/HttpBuildCacheProvider.test.js)" time="0.02">
5
5
  </testcase>
6
- <testcase classname="HttpBuildCacheProvider tryGetCacheEntryBufferByIdAsync &gt; " name="attempts up to 3 times to download a cache entry (lib/test/HttpBuildCacheProvider.test.js)" time="0.012">
6
+ <testcase classname="HttpBuildCacheProvider tryGetCacheEntryBufferByIdAsync &gt; " name="attempts up to 3 times to download a cache entry (lib/test/HttpBuildCacheProvider.test.js)" time="0.013">
7
7
  </testcase>
8
8
  </testsuite>
9
9
  </testsuites>
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
- import { ITerminal } from '@rushstack/node-core-library';
3
- import { ICloudBuildCacheProvider, RushSession } from '@rushstack/rush-sdk';
2
+ import type { ITerminal } from '@rushstack/terminal';
3
+ import { type ICloudBuildCacheProvider, type RushSession } from '@rushstack/rush-sdk';
4
4
  export interface IHttpBuildCacheTokenHandler {
5
5
  exec: string;
6
6
  args?: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"HttpBuildCacheProvider.d.ts","sourceRoot":"","sources":["../src/HttpBuildCacheProvider.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAqB,MAAM,8BAA8B,CAAC;AAC5E,OAAO,EACL,wBAAwB,EAGxB,WAAW,EAEZ,MAAM,qBAAqB,CAAC;AAiB7B,MAAM,WAAW,2BAA2B;IAC1C,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,8BAA8B;IAC7C,GAAG,EAAE,MAAM,CAAC;IACZ,YAAY,CAAC,EAAE,2BAA2B,CAAC;IAC3C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,mBAAmB,EAAE,OAAO,CAAC;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,MAAM,CAAC;CACxB;AAKD,qBAAa,sBAAuB,YAAW,wBAAwB;IACrE,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACr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AAE,WAAW;IAcvE,+BAA+B,CAC1C,QAAQ,EAAE,SAAS,EACnB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAmBjB,2BAA2B,CACtC,QAAQ,EAAE,SAAS,EACnB,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,OAAO,CAAC;IA0BN,2BAA2B,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAcnF,sCAAsC,CAAC,QAAQ,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAkC1E,4BAA4B,CAAC,QAAQ,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAY7E,OAAO,KAAK,kBAAkB,GAY7B;YAEa,KAAK;YAgFL,kBAAkB;YAgClB,2BAA2B;IAoBzC,OAAO,CAAC,eAAe;IA+CvB,OAAO,CAAC,cAAc;CA4CvB"}
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
2
4
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
5
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
6
  };
@@ -1 +1 @@
1
- {"version":3,"file":"HttpBuildCacheProvider.js","sourceRoot":"","sources":["../src/HttpBuildCacheProvider.ts"],"names":[],"mappings":";;;;;;AAAA,oEAA4E;AAC5E,kDAM6B;AAC7B,4DAAuD;AAEvD,IAAK,kBAIJ;AAJD,WAAK,kBAAkB;IACrB,mEAAQ,CAAA;IACR,mEAAQ,CAAA;IACR,2DAAI,CAAA;AACN,CAAC,EAJI,kBAAkB,KAAlB,kBAAkB,QAItB;AAED,IAAK,WAMJ;AAND,WAAK,WAAW;IACd,6CAAI,CAAA;IACJ,+DAAa,CAAA;IACb,mDAAO,CAAA;IACP,+CAAK,CAAA;IACL,iEAAc,CAAA;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ACzF,MAAM;YACR,CAAC;YAED,KAAK,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC;gBAC/B,QAAQ,CAAC,SAAS,CAAC,GAAG,OAAO,UAAU,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;gBAClF,MAAM;YACR,CAAC;YAED,KAAK,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;gBACtB,QAAQ,CAAC,cAAc,CAAC,GAAG,OAAO,UAAU,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC;gBACvF,MAAM;YACR,CAAC;YAED,KAAK,WAAW,CAAC,cAAc,CAAC,CAAC,CAAC;gBAChC,MAAM,IAAI,KAAK,CACb;oBACE,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,mBAAmB,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,GAAG;oBAC9E,mDAAmD;oBACnD,6FAA6F;oBAC7F,EAAE;oBACF,4BAA4B;oBAC5B,EAAE;oBACF,iDAAiD;oBACjD,EAAE;iBACH,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAxXD,wDAwXC","sourcesContent":["import { ITerminal, Executable, Async } from '@rushstack/node-core-library';\nimport {\n ICloudBuildCacheProvider,\n ICredentialCacheEntry,\n CredentialCache,\n RushSession,\n EnvironmentConfiguration\n} from '@rushstack/rush-sdk';\nimport fetch, { BodyInit, Response } from 'node-fetch';\n\nenum CredentialsOptions {\n Optional,\n Required,\n Omit\n}\n\nenum FailureType {\n None,\n Informational,\n Warning,\n Error,\n Authentication\n}\n\nexport interface IHttpBuildCacheTokenHandler {\n exec: string;\n args?: string[];\n}\n\n/**\n * @public\n */\nexport interface IHttpBuildCacheProviderOptions {\n url: string;\n tokenHandler?: IHttpBuildCacheTokenHandler;\n uploadMethod?: string;\n minHttpRetryDelayMs?: number;\n headers?: Record<string, string>;\n cacheKeyPrefix?: string;\n isCacheWriteAllowed: boolean;\n pluginName: string;\n rushJsonFolder: string;\n}\n\nconst MAX_HTTP_CACHE_ATTEMPTS: number = 3;\nconst DEFAULT_MIN_HTTP_RETRY_DELAY_MS = 2500;\n\nexport class HttpBuildCacheProvider implements ICloudBuildCacheProvider {\n private readonly _pluginName: string;\n private readonly _rushProjectRoot: string;\n private readonly _environmentCredential: string | undefined;\n private readonly _isCacheWriteAllowedByConfiguration: boolean;\n private readonly _url: URL;\n private readonly _uploadMethod: string;\n private readonly _headers: Record<string, string>;\n private readonly _cacheKeyPrefix: string;\n private readonly _tokenHandler: IHttpBuildCacheTokenHandler | undefined;\n private readonly _minHttpRetryDelayMs: number;\n private __credentialCacheId: string | undefined;\n\n public get isCacheWriteAllowed(): boolean {\n return EnvironmentConfiguration.buildCacheWriteAllowed ?? this._isCacheWriteAllowedByConfiguration;\n }\n\n public constructor(options: IHttpBuildCacheProviderOptions, rushSession: RushSession) {\n this._pluginName = options.pluginName;\n this._rushProjectRoot = options.rushJsonFolder;\n\n this._environmentCredential = EnvironmentConfiguration.buildCacheCredential;\n this._isCacheWriteAllowedByConfiguration = options.isCacheWriteAllowed;\n this._url = new URL(options.url.endsWith('/') ? options.url : options.url + '/');\n this._uploadMethod = options.uploadMethod ?? 'PUT';\n this._headers = options.headers ?? {};\n this._tokenHandler = options.tokenHandler;\n this._cacheKeyPrefix = options.cacheKeyPrefix ?? '';\n this._minHttpRetryDelayMs = options.minHttpRetryDelayMs ?? DEFAULT_MIN_HTTP_RETRY_DELAY_MS;\n }\n\n public async tryGetCacheEntryBufferByIdAsync(\n terminal: ITerminal,\n cacheId: string\n ): Promise<Buffer | undefined> {\n try {\n const result = await this._http({\n terminal: terminal,\n relUrl: `${this._cacheKeyPrefix}${cacheId}`,\n method: 'GET',\n body: undefined,\n warningText: 'Could not get cache entry',\n readBody: true,\n maxAttempts: MAX_HTTP_CACHE_ATTEMPTS\n });\n\n return Buffer.isBuffer(result) ? result : undefined;\n } catch (e) {\n terminal.writeWarningLine(`Error getting cache entry: ${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 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 result = await this._http({\n terminal: terminal,\n relUrl: `${this._cacheKeyPrefix}${cacheId}`,\n method: this._uploadMethod,\n body: objectBuffer,\n warningText: 'Could not write cache entry',\n readBody: false,\n maxAttempts: MAX_HTTP_CACHE_ATTEMPTS\n });\n\n return result !== false;\n } catch (e) {\n terminal.writeWarningLine(`Error uploading cache entry: ${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, {\n credential: credential\n });\n await credentialsCache.saveIfModifiedAsync();\n }\n );\n }\n\n public async updateCachedCredentialInteractiveAsync(terminal: ITerminal): Promise<void> {\n if (!this._tokenHandler) {\n throw new Error(\n `The interactive cloud credentials flow is not configured.\\n` +\n `Set the 'tokenHandler' setting in 'common/config/rush-plugins/${this._pluginName}.json' to a command that writes your credentials to standard output and exits with code 0 ` +\n `or provide your credentials to rush using the --credential flag instead. Credentials must be the ` +\n `'Authorization' header expected by ${this._url.href}`\n );\n }\n\n const cmd: string = `${this._tokenHandler.exec} ${(this._tokenHandler.args || []).join(' ')}`;\n terminal.writeVerboseLine(`Running '${cmd}' to get credentials`);\n const result = Executable.spawnSync(this._tokenHandler.exec, this._tokenHandler.args || [], {\n currentWorkingDirectory: this._rushProjectRoot\n });\n\n terminal.writeErrorLine(result.stderr);\n\n if (result.error) {\n throw new Error(`Could not obtain credentials. The command '${cmd}' failed.`);\n }\n\n const credential = result.stdout.trim();\n terminal.writeVerboseLine('Got credentials');\n\n await this.updateCachedCredentialAsync(terminal, credential);\n\n terminal.writeLine('Updated credentials cache');\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 private get _credentialCacheId(): string {\n if (!this.__credentialCacheId) {\n const cacheIdParts: string[] = [this._url.href];\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 _http(options: {\n terminal: ITerminal;\n relUrl: string;\n method: string;\n body: BodyInit | undefined;\n warningText: string;\n readBody: boolean;\n maxAttempts: number;\n credentialOptions?: CredentialsOptions;\n }): Promise<Buffer | boolean> {\n const { terminal, relUrl, method, body, warningText, readBody, credentialOptions } = options;\n const safeCredentialOptions = credentialOptions ?? CredentialsOptions.Optional;\n const credentials = await this._tryGetCredentials(safeCredentialOptions);\n const url = new URL(relUrl, this._url).href;\n\n const headers: Record<string, string> = {};\n if (typeof credentials === 'string') {\n headers.Authorization = credentials;\n }\n\n for (const [key, value] of Object.entries(this._headers)) {\n if (typeof value === 'string') {\n headers[key] = value;\n }\n }\n\n const bodyLength = (body as { length: number })?.length || 'unknown';\n\n terminal.writeDebugLine(`[http-build-cache] request: ${method} ${url} ${bodyLength} bytes`);\n\n const response = await fetch(url, {\n method: method,\n headers: headers,\n body: body,\n redirect: 'follow'\n });\n\n if (!response.ok) {\n const isNonCredentialResponse = response.status >= 500 && response.status < 600;\n\n if (\n !isNonCredentialResponse &&\n typeof credentials !== 'string' &&\n safeCredentialOptions === CredentialsOptions.Optional\n ) {\n // If we don't already have credentials yet, and we got a response from the server\n // that is a \"normal\" failure (4xx), then we assume that credentials are probably\n // required. Re-attempt the request, requiring credentials this time.\n //\n // This counts as part of the \"first attempt\", so it is not included in the max attempts\n return await this._http({ ...options, credentialOptions: CredentialsOptions.Required });\n }\n\n if (options.maxAttempts > 1) {\n // Pause a bit before retrying in case the server is busy\n // Add some random jitter to the retry so we can spread out load on the remote service\n // A proper solution might add exponential back off in case the retry count is high (10 or more)\n const factor = 1.0 + Math.random(); // A random number between 1.0 and 2.0\n const retryDelay = Math.floor(factor * this._minHttpRetryDelayMs);\n\n await Async.sleep(retryDelay);\n\n return await this._http({ ...options, maxAttempts: options.maxAttempts - 1 });\n }\n\n this._reportFailure(terminal, method, response, false, warningText);\n return false;\n }\n\n const result: Buffer | boolean = readBody ? Buffer.from(await response.arrayBuffer()) : true;\n\n terminal.writeDebugLine(\n `[http-build-cache] actual response: ${response.status} ${url} ${\n result === true ? 'true' : result.length\n } bytes`\n );\n\n return result;\n }\n\n private async _tryGetCredentials(options: CredentialsOptions.Required): Promise<string>;\n private async _tryGetCredentials(options: CredentialsOptions.Optional): Promise<string | undefined>;\n private async _tryGetCredentials(options: CredentialsOptions.Omit): Promise<undefined>;\n private async _tryGetCredentials(options: CredentialsOptions): Promise<string | undefined>;\n private async _tryGetCredentials(options: CredentialsOptions): Promise<string | undefined> {\n if (options === CredentialsOptions.Omit) {\n return;\n }\n\n let credentials: string | undefined = this._environmentCredential;\n\n if (credentials === undefined) {\n credentials = await this._tryGetCredentialsFromCache();\n }\n\n if (typeof credentials !== 'string' && options === CredentialsOptions.Required) {\n throw new Error(\n [\n `Credentials for ${this._url.href} have not been provided.`,\n `In CI, verify that RUSH_BUILD_CACHE_CREDENTIAL contains a valid Authorization header value.`,\n ``,\n `For local developers, run:`,\n ``,\n ` rush update-cloud-credentials --interactive`,\n ``\n ].join('\\n')\n );\n }\n\n return credentials;\n }\n\n private async _tryGetCredentialsFromCache(): Promise<string | undefined> {\n let cacheEntry: ICredentialCacheEntry | undefined;\n\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 return cacheEntry.credential;\n }\n }\n }\n\n private _getFailureType(requestMethod: string, response: Response, isRedirect: boolean): FailureType {\n if (response.ok) {\n return FailureType.None;\n }\n\n switch (response.status) {\n case 503: {\n // We select 503 specifically because this represents \"service unavailable\" and\n // \"rate limit throttle\" errors, which are transient issues.\n //\n // There are other 5xx errors, such as 501, that can occur if the request is\n // malformed, so as a general rule we want to let through other 5xx errors\n // so the user can troubleshoot.\n\n // Don't fail production builds with warnings for transient issues\n return FailureType.Informational;\n }\n\n case 401:\n case 403:\n case 407: {\n if (requestMethod === 'GET' && (isRedirect || response.redirected)) {\n // Cache misses for GET requests are not errors\n // This is a workaround behavior where a server can issue a redirect and we fail to authenticate at the new location.\n // We do not want to signal this as an authentication failure because the authorization header is not passed on to redirects.\n // i.e The authentication header was accepted for the first request and therefore subsequent failures\n // where it was not present should not be attributed to the header.\n // This scenario usually comes up with services that redirect to pre-signed URLS that don't actually exist.\n // Those services then usually treat the 404 as a 403 to prevent leaking information.\n return FailureType.None;\n }\n\n return FailureType.Authentication;\n }\n\n case 404: {\n if (requestMethod === 'GET') {\n // Cache misses for GET requests are not errors\n return FailureType.None;\n }\n }\n }\n\n // Let dev builds succeed, let Prod builds fail\n return FailureType.Warning;\n }\n\n private _reportFailure(\n terminal: ITerminal,\n requestMethod: string,\n response: Response,\n isRedirect: boolean,\n message: string\n ): void {\n switch (this._getFailureType(requestMethod, response, isRedirect)) {\n default: {\n terminal.writeErrorLine(`${message}: HTTP ${response.status}: ${response.statusText}`);\n break;\n }\n\n case FailureType.Warning: {\n terminal.writeWarningLine(`${message}: HTTP ${response.status}: ${response.statusText}`);\n break;\n }\n\n case FailureType.Informational: {\n terminal.writeLine(`${message}: HTTP ${response.status}: ${response.statusText}`);\n break;\n }\n\n case FailureType.None: {\n terminal.writeDebugLine(`${message}: HTTP ${response.status}: ${response.statusText}`);\n break;\n }\n\n case FailureType.Authentication: {\n throw new Error(\n [\n `${this._url.href} responded with ${response.status}: ${response.statusText}.`,\n `Credentials may be misconfigured or have expired.`,\n `In CI, verify that RUSH_BUILD_CACHE_CREDENTIAL contains a valid Authorization header value.`,\n ``,\n `For local developers, run:`,\n ``,\n ` rush update-cloud-credentials --interactive`,\n ``\n ].join('\\n')\n );\n }\n }\n }\n}\n"]}
1
+ {"version":3,"file":"HttpBuildCacheProvider.js","sourceRoot":"","sources":["../src/HttpBuildCacheProvider.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,oEAAiE;AAEjE,kDAM6B;AAC7B,4DAAiE;AAGjE,IAAK,kBAIJ;AAJD,WAAK,kBAAkB;IACrB,mEAAQ,CAAA;IACR,mEAAQ,CAAA;IACR,2DAAI,CAAA;AACN,CAAC,EAJI,kBAAkB,KAAlB,kBAAkB,QAItB;AAED,IAAK,WAMJ;AAND,WAAK,WAAW;IACd,6CAAI,CAAA;IACJ,+DAAa,CAAA;IACb,mDAAO,CAAA;IACP,+CAAK,CAAA;IACL,iEAAc,CAAA;AAChB,CAAC,EANI,WAAW,KAAX,WAAW,QAMf;AAsBD,MAAM,uBAAuB,GAAW,CAAC,CAAC;AAC1C,MAAM,+BAA+B,GAAW,IAAI,CAAC;AAErD,MAAa,sBAAsB;IAajC,IAAW,mBAAmB;;QAC5B,OAAO,MAAA,mCAAwB,CAAC,sBAAsB,mCAAI,IAAI,CAAC,mCAAmC,CAAC;IACrG,CAAC;IAED,YAAmB,OAAuC,EAAE,WAAwB;;QAClF,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;QACtC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC;QAE/C,IAAI,CAAC,sBAAsB,GAAG,mCAAwB,CAAC,oBAAoB,CAAC;QAC5E,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AK,CACb;oBACE,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,mBAAmB,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,GAAG;oBAC9E,mDAAmD;oBACnD,6FAA6F;oBAC7F,EAAE;oBACF,4BAA4B;oBAC5B,EAAE;oBACF,iDAAiD;oBACjD,EAAE;iBACH,CAAC,IAAI,CAAC,IAAI,CAAC,CACb,CAAC;YACJ,CAAC;QACH,CAAC;IACH,CAAC;CACF;AA5XD,wDA4XC","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 { Executable, Async } from '@rushstack/node-core-library';\nimport type { ITerminal } from '@rushstack/terminal';\nimport {\n type ICloudBuildCacheProvider,\n type ICredentialCacheEntry,\n CredentialCache,\n type RushSession,\n EnvironmentConfiguration\n} from '@rushstack/rush-sdk';\nimport fetch, { type BodyInit, type Response } from 'node-fetch';\nimport type { SpawnSyncReturns } from 'child_process';\n\nenum CredentialsOptions {\n Optional,\n Required,\n Omit\n}\n\nenum FailureType {\n None,\n Informational,\n Warning,\n Error,\n Authentication\n}\n\nexport interface IHttpBuildCacheTokenHandler {\n exec: string;\n args?: string[];\n}\n\n/**\n * @public\n */\nexport interface IHttpBuildCacheProviderOptions {\n url: string;\n tokenHandler?: IHttpBuildCacheTokenHandler;\n uploadMethod?: string;\n minHttpRetryDelayMs?: number;\n headers?: Record<string, string>;\n cacheKeyPrefix?: string;\n isCacheWriteAllowed: boolean;\n pluginName: string;\n rushJsonFolder: string;\n}\n\nconst MAX_HTTP_CACHE_ATTEMPTS: number = 3;\nconst DEFAULT_MIN_HTTP_RETRY_DELAY_MS: number = 2500;\n\nexport class HttpBuildCacheProvider implements ICloudBuildCacheProvider {\n private readonly _pluginName: string;\n private readonly _rushProjectRoot: string;\n private readonly _environmentCredential: string | undefined;\n private readonly _isCacheWriteAllowedByConfiguration: boolean;\n private readonly _url: URL;\n private readonly _uploadMethod: string;\n private readonly _headers: Record<string, string>;\n private readonly _cacheKeyPrefix: string;\n private readonly _tokenHandler: IHttpBuildCacheTokenHandler | undefined;\n private readonly _minHttpRetryDelayMs: number;\n private __credentialCacheId: string | undefined;\n\n public get isCacheWriteAllowed(): boolean {\n return EnvironmentConfiguration.buildCacheWriteAllowed ?? this._isCacheWriteAllowedByConfiguration;\n }\n\n public constructor(options: IHttpBuildCacheProviderOptions, rushSession: RushSession) {\n this._pluginName = options.pluginName;\n this._rushProjectRoot = options.rushJsonFolder;\n\n this._environmentCredential = EnvironmentConfiguration.buildCacheCredential;\n this._isCacheWriteAllowedByConfiguration = options.isCacheWriteAllowed;\n this._url = new URL(options.url.endsWith('/') ? options.url : options.url + '/');\n this._uploadMethod = options.uploadMethod ?? 'PUT';\n this._headers = options.headers ?? {};\n this._tokenHandler = options.tokenHandler;\n this._cacheKeyPrefix = options.cacheKeyPrefix ?? '';\n this._minHttpRetryDelayMs = options.minHttpRetryDelayMs ?? DEFAULT_MIN_HTTP_RETRY_DELAY_MS;\n }\n\n public async tryGetCacheEntryBufferByIdAsync(\n terminal: ITerminal,\n cacheId: string\n ): Promise<Buffer | undefined> {\n try {\n const result: boolean | Buffer = await this._http({\n terminal: terminal,\n relUrl: `${this._cacheKeyPrefix}${cacheId}`,\n method: 'GET',\n body: undefined,\n warningText: 'Could not get cache entry',\n readBody: true,\n maxAttempts: MAX_HTTP_CACHE_ATTEMPTS\n });\n\n return Buffer.isBuffer(result) ? result : undefined;\n } catch (e) {\n terminal.writeWarningLine(`Error getting cache entry: ${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 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 result: boolean | Buffer = await this._http({\n terminal: terminal,\n relUrl: `${this._cacheKeyPrefix}${cacheId}`,\n method: this._uploadMethod,\n body: objectBuffer,\n warningText: 'Could not write cache entry',\n readBody: false,\n maxAttempts: MAX_HTTP_CACHE_ATTEMPTS\n });\n\n return result !== false;\n } catch (e) {\n terminal.writeWarningLine(`Error uploading cache entry: ${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, {\n credential: credential\n });\n await credentialsCache.saveIfModifiedAsync();\n }\n );\n }\n\n public async updateCachedCredentialInteractiveAsync(terminal: ITerminal): Promise<void> {\n if (!this._tokenHandler) {\n throw new Error(\n `The interactive cloud credentials flow is not configured.\\n` +\n `Set the 'tokenHandler' setting in 'common/config/rush-plugins/${this._pluginName}.json' to a command that writes your credentials to standard output and exits with code 0 ` +\n `or provide your credentials to rush using the --credential flag instead. Credentials must be the ` +\n `'Authorization' header expected by ${this._url.href}`\n );\n }\n\n const cmd: string = `${this._tokenHandler.exec} ${(this._tokenHandler.args || []).join(' ')}`;\n terminal.writeVerboseLine(`Running '${cmd}' to get credentials`);\n const result: SpawnSyncReturns<string> = Executable.spawnSync(\n this._tokenHandler.exec,\n this._tokenHandler.args || [],\n {\n currentWorkingDirectory: this._rushProjectRoot\n }\n );\n\n terminal.writeErrorLine(result.stderr);\n\n if (result.error) {\n throw new Error(`Could not obtain credentials. The command '${cmd}' failed.`);\n }\n\n const credential: string = result.stdout.trim();\n terminal.writeVerboseLine('Got credentials');\n\n await this.updateCachedCredentialAsync(terminal, credential);\n\n terminal.writeLine('Updated credentials cache');\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 private get _credentialCacheId(): string {\n if (!this.__credentialCacheId) {\n const cacheIdParts: string[] = [this._url.href];\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 _http(options: {\n terminal: ITerminal;\n relUrl: string;\n method: string;\n body: BodyInit | undefined;\n warningText: string;\n readBody: boolean;\n maxAttempts: number;\n credentialOptions?: CredentialsOptions;\n }): Promise<Buffer | boolean> {\n const { terminal, relUrl, method, body, warningText, readBody, credentialOptions } = options;\n const safeCredentialOptions: CredentialsOptions = credentialOptions ?? CredentialsOptions.Optional;\n const credentials: string | undefined = await this._tryGetCredentials(safeCredentialOptions);\n const url: string = new URL(relUrl, this._url).href;\n\n const headers: Record<string, string> = {};\n if (typeof credentials === 'string') {\n headers.Authorization = credentials;\n }\n\n for (const [key, value] of Object.entries(this._headers)) {\n if (typeof value === 'string') {\n headers[key] = value;\n }\n }\n\n const bodyLength: number | 'unknown' = (body as { length: number })?.length || 'unknown';\n\n terminal.writeDebugLine(`[http-build-cache] request: ${method} ${url} ${bodyLength} bytes`);\n\n const response: Response = await fetch(url, {\n method: method,\n headers: headers,\n body: body,\n redirect: 'follow'\n });\n\n if (!response.ok) {\n const isNonCredentialResponse: boolean = response.status >= 500 && response.status < 600;\n\n if (\n !isNonCredentialResponse &&\n typeof credentials !== 'string' &&\n safeCredentialOptions === CredentialsOptions.Optional\n ) {\n // If we don't already have credentials yet, and we got a response from the server\n // that is a \"normal\" failure (4xx), then we assume that credentials are probably\n // required. Re-attempt the request, requiring credentials this time.\n //\n // This counts as part of the \"first attempt\", so it is not included in the max attempts\n return await this._http({ ...options, credentialOptions: CredentialsOptions.Required });\n }\n\n if (options.maxAttempts > 1) {\n // Pause a bit before retrying in case the server is busy\n // Add some random jitter to the retry so we can spread out load on the remote service\n // A proper solution might add exponential back off in case the retry count is high (10 or more)\n const factor: number = 1.0 + Math.random(); // A random number between 1.0 and 2.0\n const retryDelay: number = Math.floor(factor * this._minHttpRetryDelayMs);\n\n await Async.sleep(retryDelay);\n\n return await this._http({ ...options, maxAttempts: options.maxAttempts - 1 });\n }\n\n this._reportFailure(terminal, method, response, false, warningText);\n return false;\n }\n\n const result: Buffer | boolean = readBody ? Buffer.from(await response.arrayBuffer()) : true;\n\n terminal.writeDebugLine(\n `[http-build-cache] actual response: ${response.status} ${url} ${\n result === true ? 'true' : result.length\n } bytes`\n );\n\n return result;\n }\n\n private async _tryGetCredentials(options: CredentialsOptions.Required): Promise<string>;\n private async _tryGetCredentials(options: CredentialsOptions.Optional): Promise<string | undefined>;\n private async _tryGetCredentials(options: CredentialsOptions.Omit): Promise<undefined>;\n private async _tryGetCredentials(options: CredentialsOptions): Promise<string | undefined>;\n private async _tryGetCredentials(options: CredentialsOptions): Promise<string | undefined> {\n if (options === CredentialsOptions.Omit) {\n return;\n }\n\n let credentials: string | undefined = this._environmentCredential;\n\n if (credentials === undefined) {\n credentials = await this._tryGetCredentialsFromCache();\n }\n\n if (typeof credentials !== 'string' && options === CredentialsOptions.Required) {\n throw new Error(\n [\n `Credentials for ${this._url.href} have not been provided.`,\n `In CI, verify that RUSH_BUILD_CACHE_CREDENTIAL contains a valid Authorization header value.`,\n ``,\n `For local developers, run:`,\n ``,\n ` rush update-cloud-credentials --interactive`,\n ``\n ].join('\\n')\n );\n }\n\n return credentials;\n }\n\n private async _tryGetCredentialsFromCache(): Promise<string | undefined> {\n let cacheEntry: ICredentialCacheEntry | undefined;\n\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 return cacheEntry.credential;\n }\n }\n }\n\n private _getFailureType(requestMethod: string, response: Response, isRedirect: boolean): FailureType {\n if (response.ok) {\n return FailureType.None;\n }\n\n switch (response.status) {\n case 503: {\n // We select 503 specifically because this represents \"service unavailable\" and\n // \"rate limit throttle\" errors, which are transient issues.\n //\n // There are other 5xx errors, such as 501, that can occur if the request is\n // malformed, so as a general rule we want to let through other 5xx errors\n // so the user can troubleshoot.\n\n // Don't fail production builds with warnings for transient issues\n return FailureType.Informational;\n }\n\n case 401:\n case 403:\n case 407: {\n if (requestMethod === 'GET' && (isRedirect || response.redirected)) {\n // Cache misses for GET requests are not errors\n // This is a workaround behavior where a server can issue a redirect and we fail to authenticate at the new location.\n // We do not want to signal this as an authentication failure because the authorization header is not passed on to redirects.\n // i.e The authentication header was accepted for the first request and therefore subsequent failures\n // where it was not present should not be attributed to the header.\n // This scenario usually comes up with services that redirect to pre-signed URLS that don't actually exist.\n // Those services then usually treat the 404 as a 403 to prevent leaking information.\n return FailureType.None;\n }\n\n return FailureType.Authentication;\n }\n\n case 404: {\n if (requestMethod === 'GET') {\n // Cache misses for GET requests are not errors\n return FailureType.None;\n }\n }\n }\n\n // Let dev builds succeed, let Prod builds fail\n return FailureType.Warning;\n }\n\n private _reportFailure(\n terminal: ITerminal,\n requestMethod: string,\n response: Response,\n isRedirect: boolean,\n message: string\n ): void {\n switch (this._getFailureType(requestMethod, response, isRedirect)) {\n default: {\n terminal.writeErrorLine(`${message}: HTTP ${response.status}: ${response.statusText}`);\n break;\n }\n\n case FailureType.Warning: {\n terminal.writeWarningLine(`${message}: HTTP ${response.status}: ${response.statusText}`);\n break;\n }\n\n case FailureType.Informational: {\n terminal.writeLine(`${message}: HTTP ${response.status}: ${response.statusText}`);\n break;\n }\n\n case FailureType.None: {\n terminal.writeDebugLine(`${message}: HTTP ${response.status}: ${response.statusText}`);\n break;\n }\n\n case FailureType.Authentication: {\n throw new Error(\n [\n `${this._url.href} responded with ${response.status}: ${response.statusText}.`,\n `Credentials may be misconfigured or have expired.`,\n `In CI, verify that RUSH_BUILD_CACHE_CREDENTIAL contains a valid Authorization header value.`,\n ``,\n `For local developers, run:`,\n ``,\n ` rush update-cloud-credentials --interactive`,\n ``\n ].join('\\n')\n );\n }\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"RushHttpBuildCachePlugin.js","sourceRoot":"","sources":["../src/RushHttpBuildCachePlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAK3D,MAAM,WAAW,GAAW,sBAAsB,CAAC;AAyCnD;;GAEG;AACH,MAAa,wBAAwB;IAArC;QACkB,eAAU,GAAW,WAAW,CAAC;IA6BnD,CAAC;IA3BQ,KAAK,CAAC,WAAwB,EAAE,UAA6B;QAClE,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE;YACrD,WAAW,CAAC,sCAAsC,CAAC,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,EAAE;gBACpF,MAAM,MAAM,GACV,gBAGD,CAAC,iBAAiB,CAAC;gBAEpB,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,GAAG,MAAM,CAAC;gBAEjG,MAAM,OAAO,GAAmC;oBAC9C,UAAU,EAAE,IAAI,CAAC,UAAU;oBAC3B,cAAc,EAAE,UAAU,CAAC,cAAc;oBACzC,GAAG,EAAE,GAAG;oBACR,YAAY,EAAE,YAAY;oBAC1B,OAAO,EAAE,OAAO;oBAChB,YAAY,EAAE,YAAY;oBAC1B,cAAc,EAAE,cAAc;oBAC9B,mBAAmB,EAAE,CAAC,CAAC,mBAAmB;iBAC3C,CAAC;gBAEF,MAAM,EAAE,sBAAsB,EAAE,GAAG,wDAAa,0BAA0B,GAAC,CAAC;gBAC5E,OAAO,IAAI,sBAAsB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;YAC1D,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA9BD,4DA8BC","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 type { IRushPlugin, RushSession, RushConfiguration } from '@rushstack/rush-sdk';\nimport type { HttpBuildCacheProvider, IHttpBuildCacheProviderOptions } from './HttpBuildCacheProvider';\n\nconst PLUGIN_NAME: string = 'HttpBuildCachePlugin';\n\n/**\n * @public\n */\nexport interface IRushHttpBuildCachePluginConfig {\n /**\n * The URL of the server that stores the caches (e.g. \"https://build-caches.example.com\").\n */\n url: string;\n\n /**\n * The HTTP method to use when writing to the cache (defaults to PUT).\n */\n uploadMethod?: string;\n\n /**\n * An optional set of HTTP headers to pass to the cache server.\n */\n headers?: Record<string, string>;\n\n /**\n * An optional command that prints the endpoint's credentials to stdout. Provide the\n * command or script to execute and, optionally, any arguments to pass to the script.\n */\n tokenHandler?: {\n exec: string;\n args?: string[];\n };\n\n /**\n * Prefix for cache keys.\n */\n cacheKeyPrefix?: string;\n\n /**\n * If set to true, allow writing to the cache. Defaults to false.\n */\n isCacheWriteAllowed?: boolean;\n}\n\n/**\n * @public\n */\nexport class RushHttpBuildCachePlugin implements IRushPlugin {\n public readonly pluginName: string = PLUGIN_NAME;\n\n public apply(rushSession: RushSession, rushConfig: RushConfiguration): void {\n rushSession.hooks.initialize.tap(this.pluginName, () => {\n rushSession.registerCloudBuildCacheProviderFactory('http', async (buildCacheConfig) => {\n const config: IRushHttpBuildCachePluginConfig = (\n buildCacheConfig as typeof buildCacheConfig & {\n httpConfiguration: IRushHttpBuildCachePluginConfig;\n }\n ).httpConfiguration;\n\n const { url, uploadMethod, headers, tokenHandler, cacheKeyPrefix, isCacheWriteAllowed } = config;\n\n const options: IHttpBuildCacheProviderOptions = {\n pluginName: this.pluginName,\n rushJsonFolder: rushConfig.rushJsonFolder,\n url: url,\n uploadMethod: uploadMethod,\n headers: headers,\n tokenHandler: tokenHandler,\n cacheKeyPrefix: cacheKeyPrefix,\n isCacheWriteAllowed: !!isCacheWriteAllowed\n };\n\n const { HttpBuildCacheProvider } = await import('./HttpBuildCacheProvider');\n return new HttpBuildCacheProvider(options, rushSession);\n });\n });\n }\n}\n"]}
1
+ {"version":3,"file":"RushHttpBuildCachePlugin.js","sourceRoot":"","sources":["../src/RushHttpBuildCachePlugin.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;AAK3D,MAAM,WAAW,GAAW,sBAAsB,CAAC;AAyCnD;;GAEG;AACH,MAAa,wBAAwB;IAArC;QACkB,eAAU,GAAW,WAAW,CAAC;IA6BnD,CAAC;IA3BQ,KAAK,CAAC,WAAwB,EAAE,UAA6B;QAClE,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,EAAE;YACrD,WAAW,CAAC,sCAAsC,CAAC,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,EAAE;gBACpF,MAAM,MAAM,GACV,gBAGD,CAAC,iBAAiB,CAAC;gBAEpB,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,mBAAmB,EAAE,GAAG,MAAM,CAAC;gBAEjG,MAAM,OAAO,GAAmC;oBAC9C,UAAU,EAAE,IAAI,CAAC,UAAU;oBAC3B,cAAc,EAAE,UAAU,CAAC,cAAc;oBACzC,GAAG,EAAE,GAAG;oBACR,YAAY,EAAE,YAAY;oBAC1B,OAAO,EAAE,OAAO;oBAChB,YAAY,EAAE,YAAY;oBAC1B,cAAc,EAAE,cAAc;oBAC9B,mBAAmB,EAAE,CAAC,CAAC,mBAAmB;iBAC3C,CAAC;gBAEF,MAAM,EAAE,sBAAsB,EAAE,GAAG,wDAAa,0BAA0B,GAAC,CAAC;gBAC5E,OAAO,IAAI,sBAAsB,CAAC,OAAO,EAAE,WAAW,CAAC,CAAC;YAC1D,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AA9BD,4DA8BC","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 type { IRushPlugin, RushSession, RushConfiguration } from '@rushstack/rush-sdk';\nimport type { IHttpBuildCacheProviderOptions } from './HttpBuildCacheProvider';\n\nconst PLUGIN_NAME: string = 'HttpBuildCachePlugin';\n\n/**\n * @public\n */\nexport interface IRushHttpBuildCachePluginConfig {\n /**\n * The URL of the server that stores the caches (e.g. \"https://build-caches.example.com\").\n */\n url: string;\n\n /**\n * The HTTP method to use when writing to the cache (defaults to PUT).\n */\n uploadMethod?: string;\n\n /**\n * An optional set of HTTP headers to pass to the cache server.\n */\n headers?: Record<string, string>;\n\n /**\n * An optional command that prints the endpoint's credentials to stdout. Provide the\n * command or script to execute and, optionally, any arguments to pass to the script.\n */\n tokenHandler?: {\n exec: string;\n args?: string[];\n };\n\n /**\n * Prefix for cache keys.\n */\n cacheKeyPrefix?: string;\n\n /**\n * If set to true, allow writing to the cache. Defaults to false.\n */\n isCacheWriteAllowed?: boolean;\n}\n\n/**\n * @public\n */\nexport class RushHttpBuildCachePlugin implements IRushPlugin {\n public readonly pluginName: string = PLUGIN_NAME;\n\n public apply(rushSession: RushSession, rushConfig: RushConfiguration): void {\n rushSession.hooks.initialize.tap(this.pluginName, () => {\n rushSession.registerCloudBuildCacheProviderFactory('http', async (buildCacheConfig) => {\n const config: IRushHttpBuildCachePluginConfig = (\n buildCacheConfig as typeof buildCacheConfig & {\n httpConfiguration: IRushHttpBuildCachePluginConfig;\n }\n ).httpConfiguration;\n\n const { url, uploadMethod, headers, tokenHandler, cacheKeyPrefix, isCacheWriteAllowed } = config;\n\n const options: IHttpBuildCacheProviderOptions = {\n pluginName: this.pluginName,\n rushJsonFolder: rushConfig.rushJsonFolder,\n url: url,\n uploadMethod: uploadMethod,\n headers: headers,\n tokenHandler: tokenHandler,\n cacheKeyPrefix: cacheKeyPrefix,\n isCacheWriteAllowed: !!isCacheWriteAllowed\n };\n\n const { HttpBuildCacheProvider } = await import('./HttpBuildCacheProvider');\n return new HttpBuildCacheProvider(options, rushSession);\n });\n });\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,eAAe,wBAAwB,CAAC;AACxC,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAC;AAEtE,eAAe,wBAAwB,CAAC;AACxC,OAAO,EAAE,8BAA8B,EAAE,MAAM,0BAA0B,CAAC"}
package/lib/index.js CHANGED
@@ -1,4 +1,6 @@
1
1
  "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
2
4
  Object.defineProperty(exports, "__esModule", { value: true });
3
5
  const RushHttpBuildCachePlugin_1 = require("./RushHttpBuildCachePlugin");
4
6
  exports.default = RushHttpBuildCachePlugin_1.RushHttpBuildCachePlugin;
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,yEAAsE;AAEtE,kBAAe,mDAAwB,CAAC","sourcesContent":["import { RushHttpBuildCachePlugin } from './RushHttpBuildCachePlugin';\n\nexport default RushHttpBuildCachePlugin;\nexport { IHttpBuildCacheProviderOptions } from './HttpBuildCacheProvider';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;AAE3D,yEAAsE;AAEtE,kBAAe,mDAAwB,CAAC","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 { RushHttpBuildCachePlugin } from './RushHttpBuildCachePlugin';\n\nexport default RushHttpBuildCachePlugin;\nexport { IHttpBuildCacheProviderOptions } from './HttpBuildCacheProvider';\n"]}
@@ -30,7 +30,7 @@ jest.mock('node-fetch', function () {
30
30
  });
31
31
  const node_fetch_1 = __importStar(require("node-fetch"));
32
32
  const rush_sdk_1 = require("@rushstack/rush-sdk");
33
- const node_core_library_1 = require("@rushstack/node-core-library");
33
+ const terminal_1 = require("@rushstack/terminal");
34
34
  const HttpBuildCacheProvider_1 = require("../HttpBuildCacheProvider");
35
35
  const EXAMPLE_OPTIONS = {
36
36
  url: 'https://buildcache.example.acme.com',
@@ -48,8 +48,8 @@ describe('HttpBuildCacheProvider', () => {
48
48
  let terminalBuffer;
49
49
  let terminal;
50
50
  beforeEach(() => {
51
- terminalBuffer = new node_core_library_1.StringBufferTerminalProvider();
52
- terminal = new node_core_library_1.Terminal(terminalBuffer);
51
+ terminalBuffer = new terminal_1.StringBufferTerminalProvider();
52
+ terminal = new terminal_1.Terminal(terminalBuffer);
53
53
  });
54
54
  describe('tryGetCacheEntryBufferByIdAsync', () => {
55
55
  it('prints warning if read credentials are not available', async () => {
@@ -1 +1 @@
1
- {"version":3,"file":"HttpBuildCacheProvider.test.js","sourceRoot":"","sources":["../../src/test/HttpBuildCacheProvider.test.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;IACtB,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC;AACpE,CAAC,CAAC,CAAC;AAEH,yDAA6C;AAC7C,kDAA4E;AAC5E,oEAAsF;AAEtF,sEAAwG;AAExG,MAAM,eAAe,GAAmC;IACtD,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CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;YACvC,MAAM,CAAC,oBAAK,CAAC,CAAC,uBAAuB,CAAC,CAAC,EAAE,8CAA8C,EAAE;gBACvF,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,EAAE;gBACX,MAAM,EAAE,KAAK;gBACb,QAAQ,EAAE,QAAQ;aACnB,CAAC,CAAC;YACH,MAAM,CAAC,oBAAK,CAAC,CAAC,uBAAuB,CAAC,CAAC,EAAE,8CAA8C,EAAE;gBACvF,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,EAAE;gBACX,MAAM,EAAE,KAAK;gBACb,QAAQ,EAAE,QAAQ;aACnB,CAAC,CAAC;YACH,MAAM,CAAC,oBAAK,CAAC,CAAC,uBAAuB,CAAC,CAAC,EAAE,8CAA8C,EAAE;gBACvF,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,EAAE;gBACX,MAAM,EAAE,KAAK;gBACb,QAAQ,EAAE,QAAQ;aACnB,CAAC,CAAC;YACH,MAAM,CAAC,cAAc,CAAC,gBAAgB,EAAE,CAAC,CAAC,qBAAqB,CAC7D,sDAAsD,CACvD,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\njest.mock('node-fetch', function () {\n return Object.assign(jest.fn(), jest.requireActual('node-fetch'));\n});\n\nimport fetch, { Response } from 'node-fetch';\nimport { RushSession, EnvironmentConfiguration } from '@rushstack/rush-sdk';\nimport { StringBufferTerminalProvider, Terminal } from '@rushstack/node-core-library';\n\nimport { HttpBuildCacheProvider, type IHttpBuildCacheProviderOptions } from '../HttpBuildCacheProvider';\n\nconst EXAMPLE_OPTIONS: IHttpBuildCacheProviderOptions = {\n url: 'https://buildcache.example.acme.com',\n tokenHandler: {\n exec: 'node',\n args: ['tokenHandler.js']\n },\n uploadMethod: 'POST',\n isCacheWriteAllowed: false,\n pluginName: 'example-plugin',\n rushJsonFolder: '/repo',\n minHttpRetryDelayMs: 1\n};\n\ndescribe('HttpBuildCacheProvider', () => {\n let terminalBuffer: StringBufferTerminalProvider;\n let terminal!: Terminal;\n\n beforeEach(() => {\n terminalBuffer = new StringBufferTerminalProvider();\n terminal = new Terminal(terminalBuffer);\n });\n\n describe('tryGetCacheEntryBufferByIdAsync', () => {\n it('prints warning if read credentials are not available', async () => {\n jest.spyOn(EnvironmentConfiguration, 'buildCacheCredential', 'get').mockReturnValue(undefined);\n\n const session: RushSession = {} as RushSession;\n const provider = new HttpBuildCacheProvider(EXAMPLE_OPTIONS, session);\n\n mocked(fetch).mockResolvedValue(\n new Response('Unauthorized', {\n status: 401,\n statusText: 'Unauthorized'\n })\n );\n\n const result = await provider.tryGetCacheEntryBufferByIdAsync(terminal, 'some-key');\n expect(result).toBe(undefined);\n expect(fetch).toHaveBeenCalledTimes(1);\n expect(fetch).toHaveBeenNthCalledWith(1, 'https://buildcache.example.acme.com/some-key', {\n body: undefined,\n headers: {},\n method: 'GET',\n redirect: 'follow'\n });\n expect(terminalBuffer.getWarningOutput()).toMatchInlineSnapshot(\n `\"Error getting cache entry: Error: Credentials for https://buildcache.example.acme.com/ have not been provided.[n]In CI, verify that RUSH_BUILD_CACHE_CREDENTIAL contains a valid Authorization header value.[n][n]For local developers, run:[n][n] rush update-cloud-credentials --interactive[n][n]\"`\n );\n });\n\n it('attempts up to 3 times to download a cache entry', async () => {\n jest.spyOn(EnvironmentConfiguration, 'buildCacheCredential', 'get').mockReturnValue(undefined);\n\n const session: RushSession = {} as RushSession;\n const provider = new HttpBuildCacheProvider(EXAMPLE_OPTIONS, session);\n\n mocked(fetch).mockResolvedValueOnce(\n new Response('InternalServiceError', {\n status: 500,\n statusText: 'InternalServiceError'\n })\n );\n mocked(fetch).mockResolvedValueOnce(\n new Response('ServiceUnavailable', {\n status: 503,\n statusText: 'ServiceUnavailable'\n })\n );\n mocked(fetch).mockResolvedValueOnce(\n new Response('BadGateway', {\n status: 504,\n statusText: 'BadGateway'\n })\n );\n\n const result = await provider.tryGetCacheEntryBufferByIdAsync(terminal, 'some-key');\n expect(result).toBe(undefined);\n expect(fetch).toHaveBeenCalledTimes(3);\n expect(fetch).toHaveBeenNthCalledWith(1, 'https://buildcache.example.acme.com/some-key', {\n body: undefined,\n headers: {},\n method: 'GET',\n redirect: 'follow'\n });\n expect(fetch).toHaveBeenNthCalledWith(2, 'https://buildcache.example.acme.com/some-key', {\n body: undefined,\n headers: {},\n method: 'GET',\n redirect: 'follow'\n });\n expect(fetch).toHaveBeenNthCalledWith(3, 'https://buildcache.example.acme.com/some-key', {\n body: undefined,\n headers: {},\n method: 'GET',\n redirect: 'follow'\n });\n expect(terminalBuffer.getWarningOutput()).toMatchInlineSnapshot(\n `\"Could not get cache entry: HTTP 504: BadGateway[n]\"`\n );\n });\n });\n});\n"]}
1
+ {"version":3,"file":"HttpBuildCacheProvider.test.js","sourceRoot":"","sources":["../../src/test/HttpBuildCacheProvider.test.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;IACtB,OAAO,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,CAAC,CAAC;AACpE,CAAC,CAAC,CAAC;AAEH,yDAA6C;AAC7C,kDAAiF;AACjF,kDAA6E;AAE7E,sEAAwG;AAExG,MAAM,eAAe,GAAmC;IACtD,GAAG,EAAE,qCAAqC;IAC1C,YAAY,EAAE;QACZ,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,CAAC,iBAAiB,CAAC;KAC1B;IACD,YAAY,EAAE,MAAM;IACpB,mBAAmB,EAAE,KAAK;IAC1B,UAAU,EAAE,gBAAgB;IAC5B,cAAc,EAAE,OAAO;IACvB,mBAAmB,EAA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AAC;YACH,MAAM,CAAC,oBAAK,CAAC,CAAC,uBAAuB,CAAC,CAAC,EAAE,8CAA8C,EAAE;gBACvF,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,EAAE;gBACX,MAAM,EAAE,KAAK;gBACb,QAAQ,EAAE,QAAQ;aACnB,CAAC,CAAC;YACH,MAAM,CAAC,oBAAK,CAAC,CAAC,uBAAuB,CAAC,CAAC,EAAE,8CAA8C,EAAE;gBACvF,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,EAAE;gBACX,MAAM,EAAE,KAAK;gBACb,QAAQ,EAAE,QAAQ;aACnB,CAAC,CAAC;YACH,MAAM,CAAC,cAAc,CAAC,gBAAgB,EAAE,CAAC,CAAC,qBAAqB,CAC7D,sDAAsD,CACvD,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\njest.mock('node-fetch', function () {\n return Object.assign(jest.fn(), jest.requireActual('node-fetch'));\n});\n\nimport fetch, { Response } from 'node-fetch';\nimport { type RushSession, EnvironmentConfiguration } from '@rushstack/rush-sdk';\nimport { StringBufferTerminalProvider, Terminal } from '@rushstack/terminal';\n\nimport { HttpBuildCacheProvider, type IHttpBuildCacheProviderOptions } from '../HttpBuildCacheProvider';\n\nconst EXAMPLE_OPTIONS: IHttpBuildCacheProviderOptions = {\n url: 'https://buildcache.example.acme.com',\n tokenHandler: {\n exec: 'node',\n args: ['tokenHandler.js']\n },\n uploadMethod: 'POST',\n isCacheWriteAllowed: false,\n pluginName: 'example-plugin',\n rushJsonFolder: '/repo',\n minHttpRetryDelayMs: 1\n};\n\ndescribe('HttpBuildCacheProvider', () => {\n let terminalBuffer: StringBufferTerminalProvider;\n let terminal!: Terminal;\n\n beforeEach(() => {\n terminalBuffer = new StringBufferTerminalProvider();\n terminal = new Terminal(terminalBuffer);\n });\n\n describe('tryGetCacheEntryBufferByIdAsync', () => {\n it('prints warning if read credentials are not available', async () => {\n jest.spyOn(EnvironmentConfiguration, 'buildCacheCredential', 'get').mockReturnValue(undefined);\n\n const session: RushSession = {} as RushSession;\n const provider = new HttpBuildCacheProvider(EXAMPLE_OPTIONS, session);\n\n mocked(fetch).mockResolvedValue(\n new Response('Unauthorized', {\n status: 401,\n statusText: 'Unauthorized'\n })\n );\n\n const result = await provider.tryGetCacheEntryBufferByIdAsync(terminal, 'some-key');\n expect(result).toBe(undefined);\n expect(fetch).toHaveBeenCalledTimes(1);\n expect(fetch).toHaveBeenNthCalledWith(1, 'https://buildcache.example.acme.com/some-key', {\n body: undefined,\n headers: {},\n method: 'GET',\n redirect: 'follow'\n });\n expect(terminalBuffer.getWarningOutput()).toMatchInlineSnapshot(\n `\"Error getting cache entry: Error: Credentials for https://buildcache.example.acme.com/ have not been provided.[n]In CI, verify that RUSH_BUILD_CACHE_CREDENTIAL contains a valid Authorization header value.[n][n]For local developers, run:[n][n] rush update-cloud-credentials --interactive[n][n]\"`\n );\n });\n\n it('attempts up to 3 times to download a cache entry', async () => {\n jest.spyOn(EnvironmentConfiguration, 'buildCacheCredential', 'get').mockReturnValue(undefined);\n\n const session: RushSession = {} as RushSession;\n const provider = new HttpBuildCacheProvider(EXAMPLE_OPTIONS, session);\n\n mocked(fetch).mockResolvedValueOnce(\n new Response('InternalServiceError', {\n status: 500,\n statusText: 'InternalServiceError'\n })\n );\n mocked(fetch).mockResolvedValueOnce(\n new Response('ServiceUnavailable', {\n status: 503,\n statusText: 'ServiceUnavailable'\n })\n );\n mocked(fetch).mockResolvedValueOnce(\n new Response('BadGateway', {\n status: 504,\n statusText: 'BadGateway'\n })\n );\n\n const result = await provider.tryGetCacheEntryBufferByIdAsync(terminal, 'some-key');\n expect(result).toBe(undefined);\n expect(fetch).toHaveBeenCalledTimes(3);\n expect(fetch).toHaveBeenNthCalledWith(1, 'https://buildcache.example.acme.com/some-key', {\n body: undefined,\n headers: {},\n method: 'GET',\n redirect: 'follow'\n });\n expect(fetch).toHaveBeenNthCalledWith(2, 'https://buildcache.example.acme.com/some-key', {\n body: undefined,\n headers: {},\n method: 'GET',\n redirect: 'follow'\n });\n expect(fetch).toHaveBeenNthCalledWith(3, 'https://buildcache.example.acme.com/some-key', {\n body: undefined,\n headers: {},\n method: 'GET',\n redirect: 'follow'\n });\n expect(terminalBuffer.getWarningOutput()).toMatchInlineSnapshot(\n `\"Could not get cache entry: HTTP 504: BadGateway[n]\"`\n );\n });\n });\n});\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rushstack/rush-http-build-cache-plugin",
3
- "version": "5.113.4",
3
+ "version": "5.114.0",
4
4
  "description": "Rush plugin for generic HTTP cloud build cache",
5
5
  "repository": {
6
6
  "type": "git",
@@ -14,14 +14,15 @@
14
14
  "dependencies": {
15
15
  "https-proxy-agent": "~5.0.0",
16
16
  "node-fetch": "2.6.7",
17
- "@rushstack/node-core-library": "3.64.2",
18
- "@rushstack/rush-sdk": "5.113.4"
17
+ "@rushstack/node-core-library": "4.0.0",
18
+ "@rushstack/rush-sdk": "5.114.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@types/node-fetch": "2.6.2",
22
- "@microsoft/rush-lib": "5.113.4",
23
- "@rushstack/heft": "0.64.3",
24
- "local-node-rig": "1.0.0"
22
+ "@rushstack/heft": "0.64.8",
23
+ "@rushstack/terminal": "0.8.0",
24
+ "local-node-rig": "1.0.0",
25
+ "@microsoft/rush-lib": "5.114.0"
25
26
  },
26
27
  "scripts": {
27
28
  "build": "heft build --clean",
@@ -1,11 +1,12 @@
1
1
  Build cache hit.
2
- Cache key: rushstack+rush-http-build-cache-plugin-_phase_build-0959f6ff3364a08451be32d25795047fc38a09fe
2
+ Cache key: rushstack+rush-http-build-cache-plugin-_phase_build-bdf30e460f994579fa5d5b8a382c75152ff42394
3
3
  Clearing cached folders: dist, lib, lib-commonjs, temp, .heft
4
4
  Successfully restored output from the build cache.
5
5
  Restoring cached log file at /mnt/vss/_work/1/s/rush-plugins/rush-http-build-cache-plugin/.rush/temp/operation/_phase_build/all.log
6
6
  Invoking: heft run --only build -- --clean --production
7
7
  ---- build started ----
8
8
  [build:typescript] Using TypeScript version 5.3.3
9
+ [build:lint] Using ESLint version 8.7.0
9
10
  [build:typescript] Copied 1 folder or file and linked 0 files
10
- ---- build finished (6.312s) ----
11
- -------------------- Finished (6.331s) --------------------
11
+ ---- build finished (8.378s) ----
12
+ -------------------- Finished (8.405s) --------------------
@@ -1,6 +1,7 @@
1
1
  Invoking: heft run --only build -- --clean --production
2
2
  ---- build started ----
3
3
  [build:typescript] Using TypeScript version 5.3.3
4
+ [build:lint] Using ESLint version 8.7.0
4
5
  [build:typescript] Copied 1 folder or file and linked 0 files
5
- ---- build finished (6.312s) ----
6
- -------------------- Finished (6.331s) --------------------
6
+ ---- build finished (8.378s) ----
7
+ -------------------- Finished (8.405s) --------------------
@@ -1,5 +1,5 @@
1
1
  Build cache hit.
2
- Cache key: rushstack+rush-http-build-cache-plugin-_phase_test-aff7df502d985d6583980fce14fc03bc89c7ddcf
2
+ Cache key: rushstack+rush-http-build-cache-plugin-_phase_test-76e145455db25f136523ab72c2aaed644e2abb26
3
3
  Clearing cached folders: coverage
4
4
  Successfully restored output from the build cache.
5
5
  Restoring cached log file at /mnt/vss/_work/1/s/rush-plugins/rush-http-build-cache-plugin/.rush/temp/operation/_phase_test/all.log
@@ -10,11 +10,11 @@ The provided list of phases does not contain all phase dependencies. You may nee
10
10
  [test:jest]
11
11
  [test:jest] Run start. 1 test suite
12
12
  [test:jest] START lib/test/HttpBuildCacheProvider.test.js
13
- [test:jest] PASS lib/test/HttpBuildCacheProvider.test.js (duration: 1.018s, 2 passed, 0 failed)
13
+ [test:jest] PASS lib/test/HttpBuildCacheProvider.test.js (duration: 1.559s, 2 passed, 0 failed)
14
14
  [test:jest]
15
15
  [test:jest] Tests finished:
16
16
  [test:jest] Successes: 2
17
17
  [test:jest] Failures: 0
18
18
  [test:jest] Total: 2
19
- ---- test finished (2.649s) ----
20
- -------------------- Finished (2.657s) --------------------
19
+ ---- test finished (3.393s) ----
20
+ -------------------- Finished (3.401s) --------------------
@@ -5,11 +5,11 @@ The provided list of phases does not contain all phase dependencies. You may nee
5
5
  [test:jest]
6
6
  [test:jest] Run start. 1 test suite
7
7
  [test:jest] START lib/test/HttpBuildCacheProvider.test.js
8
- [test:jest] PASS lib/test/HttpBuildCacheProvider.test.js (duration: 1.018s, 2 passed, 0 failed)
8
+ [test:jest] PASS lib/test/HttpBuildCacheProvider.test.js (duration: 1.559s, 2 passed, 0 failed)
9
9
  [test:jest]
10
10
  [test:jest] Tests finished:
11
11
  [test:jest] Successes: 2
12
12
  [test:jest] Failures: 0
13
13
  [test:jest] Total: 2
14
- ---- test finished (2.649s) ----
15
- -------------------- Finished (2.657s) --------------------
14
+ ---- test finished (3.393s) ----
15
+ -------------------- Finished (3.401s) --------------------
@@ -1,12 +1,17 @@
1
- import { ITerminal, Executable, Async } from '@rushstack/node-core-library';
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 { Executable, Async } from '@rushstack/node-core-library';
5
+ import type { ITerminal } from '@rushstack/terminal';
2
6
  import {
3
- ICloudBuildCacheProvider,
4
- ICredentialCacheEntry,
7
+ type ICloudBuildCacheProvider,
8
+ type ICredentialCacheEntry,
5
9
  CredentialCache,
6
- RushSession,
10
+ type RushSession,
7
11
  EnvironmentConfiguration
8
12
  } from '@rushstack/rush-sdk';
9
- import fetch, { BodyInit, Response } from 'node-fetch';
13
+ import fetch, { type BodyInit, type Response } from 'node-fetch';
14
+ import type { SpawnSyncReturns } from 'child_process';
10
15
 
11
16
  enum CredentialsOptions {
12
17
  Optional,
@@ -43,7 +48,7 @@ export interface IHttpBuildCacheProviderOptions {
43
48
  }
44
49
 
45
50
  const MAX_HTTP_CACHE_ATTEMPTS: number = 3;
46
- const DEFAULT_MIN_HTTP_RETRY_DELAY_MS = 2500;
51
+ const DEFAULT_MIN_HTTP_RETRY_DELAY_MS: number = 2500;
47
52
 
48
53
  export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
49
54
  private readonly _pluginName: string;
@@ -81,7 +86,7 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
81
86
  cacheId: string
82
87
  ): Promise<Buffer | undefined> {
83
88
  try {
84
- const result = await this._http({
89
+ const result: boolean | Buffer = await this._http({
85
90
  terminal: terminal,
86
91
  relUrl: `${this._cacheKeyPrefix}${cacheId}`,
87
92
  method: 'GET',
@@ -111,7 +116,7 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
111
116
  terminal.writeDebugLine('Uploading object with cacheId: ', cacheId);
112
117
 
113
118
  try {
114
- const result = await this._http({
119
+ const result: boolean | Buffer = await this._http({
115
120
  terminal: terminal,
116
121
  relUrl: `${this._cacheKeyPrefix}${cacheId}`,
117
122
  method: this._uploadMethod,
@@ -154,9 +159,13 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
154
159
 
155
160
  const cmd: string = `${this._tokenHandler.exec} ${(this._tokenHandler.args || []).join(' ')}`;
156
161
  terminal.writeVerboseLine(`Running '${cmd}' to get credentials`);
157
- const result = Executable.spawnSync(this._tokenHandler.exec, this._tokenHandler.args || [], {
158
- currentWorkingDirectory: this._rushProjectRoot
159
- });
162
+ const result: SpawnSyncReturns<string> = Executable.spawnSync(
163
+ this._tokenHandler.exec,
164
+ this._tokenHandler.args || [],
165
+ {
166
+ currentWorkingDirectory: this._rushProjectRoot
167
+ }
168
+ );
160
169
 
161
170
  terminal.writeErrorLine(result.stderr);
162
171
 
@@ -164,7 +173,7 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
164
173
  throw new Error(`Could not obtain credentials. The command '${cmd}' failed.`);
165
174
  }
166
175
 
167
- const credential = result.stdout.trim();
176
+ const credential: string = result.stdout.trim();
168
177
  terminal.writeVerboseLine('Got credentials');
169
178
 
170
179
  await this.updateCachedCredentialAsync(terminal, credential);
@@ -209,9 +218,9 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
209
218
  credentialOptions?: CredentialsOptions;
210
219
  }): Promise<Buffer | boolean> {
211
220
  const { terminal, relUrl, method, body, warningText, readBody, credentialOptions } = options;
212
- const safeCredentialOptions = credentialOptions ?? CredentialsOptions.Optional;
213
- const credentials = await this._tryGetCredentials(safeCredentialOptions);
214
- const url = new URL(relUrl, this._url).href;
221
+ const safeCredentialOptions: CredentialsOptions = credentialOptions ?? CredentialsOptions.Optional;
222
+ const credentials: string | undefined = await this._tryGetCredentials(safeCredentialOptions);
223
+ const url: string = new URL(relUrl, this._url).href;
215
224
 
216
225
  const headers: Record<string, string> = {};
217
226
  if (typeof credentials === 'string') {
@@ -224,11 +233,11 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
224
233
  }
225
234
  }
226
235
 
227
- const bodyLength = (body as { length: number })?.length || 'unknown';
236
+ const bodyLength: number | 'unknown' = (body as { length: number })?.length || 'unknown';
228
237
 
229
238
  terminal.writeDebugLine(`[http-build-cache] request: ${method} ${url} ${bodyLength} bytes`);
230
239
 
231
- const response = await fetch(url, {
240
+ const response: Response = await fetch(url, {
232
241
  method: method,
233
242
  headers: headers,
234
243
  body: body,
@@ -236,7 +245,7 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
236
245
  });
237
246
 
238
247
  if (!response.ok) {
239
- const isNonCredentialResponse = response.status >= 500 && response.status < 600;
248
+ const isNonCredentialResponse: boolean = response.status >= 500 && response.status < 600;
240
249
 
241
250
  if (
242
251
  !isNonCredentialResponse &&
@@ -255,8 +264,8 @@ export class HttpBuildCacheProvider implements ICloudBuildCacheProvider {
255
264
  // Pause a bit before retrying in case the server is busy
256
265
  // Add some random jitter to the retry so we can spread out load on the remote service
257
266
  // A proper solution might add exponential back off in case the retry count is high (10 or more)
258
- const factor = 1.0 + Math.random(); // A random number between 1.0 and 2.0
259
- const retryDelay = Math.floor(factor * this._minHttpRetryDelayMs);
267
+ const factor: number = 1.0 + Math.random(); // A random number between 1.0 and 2.0
268
+ const retryDelay: number = Math.floor(factor * this._minHttpRetryDelayMs);
260
269
 
261
270
  await Async.sleep(retryDelay);
262
271