@nrwl/nx-cloud 14.6.2 → 14.7.0-beta.1

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.
@@ -1 +1,36 @@
1
- const a0_0x2b7b=['apiAxiosInstance','../../utilities/axios','warn','value','throw','ErrorReporterApi','__esModule','axiosMultipleTries','reportError','message','__awaiter','next','apply','/nx-cloud/report-client-error','post','then'];(function(_0x176d82,_0x2b7b35){const _0x224de9=function(_0x94f897){while(--_0x94f897){_0x176d82['push'](_0x176d82['shift']());}};_0x224de9(++_0x2b7b35);}(a0_0x2b7b,0xc6));const a0_0x224d=function(_0x176d82,_0x2b7b35){_0x176d82=_0x176d82-0x0;let _0x224de9=a0_0x2b7b[_0x176d82];return _0x224de9;};'use strict';var __awaiter=this&&this[a0_0x224d('0x4')]||function(_0x457eb0,_0x16f82a,_0x5e07ee,_0x136c73){function _0xe0b766(_0x51839){return _0x51839 instanceof _0x5e07ee?_0x51839:new _0x5e07ee(function(_0xfe2366){_0xfe2366(_0x51839);});}return new(_0x5e07ee||(_0x5e07ee=Promise))(function(_0x114e0d,_0x631bec){function _0x41d503(_0xa8fb64){try{_0xcd4f14(_0x136c73[a0_0x224d('0x5')](_0xa8fb64));}catch(_0x4780ee){_0x631bec(_0x4780ee);}}function _0xb7332e(_0x3b068f){try{_0xcd4f14(_0x136c73[a0_0x224d('0xe')](_0x3b068f));}catch(_0xb8d38d){_0x631bec(_0xb8d38d);}}function _0xcd4f14(_0x429401){_0x429401['done']?_0x114e0d(_0x429401[a0_0x224d('0xd')]):_0xe0b766(_0x429401[a0_0x224d('0xd')])[a0_0x224d('0x9')](_0x41d503,_0xb7332e);}_0xcd4f14((_0x136c73=_0x136c73[a0_0x224d('0x6')](_0x457eb0,_0x16f82a||[]))[a0_0x224d('0x5')]());});};Object['defineProperty'](exports,a0_0x224d('0x0'),{'value':!![]});exports[a0_0x224d('0xf')]=void 0x0;const axios_1=require(a0_0x224d('0xb'));const {output}=require('../../utilities/nx-imports');class ErrorReporterApi{constructor(_0x232591){this['apiAxiosInstance']=(0x0,axios_1['createApiAxiosInstance'])(_0x232591);}[a0_0x224d('0x2')](_0x595e98){return __awaiter(this,void 0x0,void 0x0,function*(){try{yield(0x0,axios_1[a0_0x224d('0x1')])(()=>this[a0_0x224d('0xa')][a0_0x224d('0x8')](a0_0x224d('0x7'),{'message':_0x595e98}));}catch(_0x468fdc){output[a0_0x224d('0xc')]({'title':'Unable\x20to\x20record\x20the\x20following\x20error:\x20\x27'+_0x595e98+'\x27','bodyLines':[_0x468fdc[a0_0x224d('0x3')]]});}});}}exports[a0_0x224d('0xf')]=ErrorReporterApi;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.ErrorReporterApi = void 0;
13
+ const axios_1 = require("../../utilities/axios");
14
+ const { output } = require('../../utilities/nx-imports');
15
+ class ErrorReporterApi {
16
+ constructor(options) {
17
+ this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
18
+ }
19
+ reportError(message) {
20
+ return __awaiter(this, void 0, void 0, function* () {
21
+ try {
22
+ yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/report-client-error', {
23
+ message,
24
+ }));
25
+ }
26
+ catch (e) {
27
+ output.warn({
28
+ title: `Unable to record the following error: '${message}'`,
29
+ bodyLines: [e.message],
30
+ });
31
+ }
32
+ });
33
+ }
34
+ }
35
+ exports.ErrorReporterApi = ErrorReporterApi;
36
+ //# sourceMappingURL=error-reporter.api.js.map
@@ -1 +1,68 @@
1
- const a1_0x35f4=['defineProperty','recordMetric','RunGroupApi','/nx-cloud/executions/complete-run-group','RUNNER_FAILURE_PERF_ENTRY','exit','../../utilities/nx-imports','throw','done','/nx-cloud/executions/create-run-group','next','post','__esModule','mapRespToPerfEntry','__awaiter','response','axiosMultipleTries','createMetricRecorder','../../utilities/axios','createRunGroup','apply','createApiAxiosInstance','error','value','completeRunGroup','axiosException'];(function(_0x329ec2,_0x35f4a5){const _0x15c6f2=function(_0x71af94){while(--_0x71af94){_0x329ec2['push'](_0x329ec2['shift']());}};_0x15c6f2(++_0x35f4a5);}(a1_0x35f4,0x138));const a1_0x15c6=function(_0x329ec2,_0x35f4a5){_0x329ec2=_0x329ec2-0x0;let _0x15c6f2=a1_0x35f4[_0x329ec2];return _0x15c6f2;};'use strict';var __awaiter=this&&this[a1_0x15c6('0xe')]||function(_0x27fa6b,_0x42093f,_0x752c12,_0x58759f){function _0x20b3e7(_0x3a36a6){return _0x3a36a6 instanceof _0x752c12?_0x3a36a6:new _0x752c12(function(_0x30825c){_0x30825c(_0x3a36a6);});}return new(_0x752c12||(_0x752c12=Promise))(function(_0x103bf5,_0x598730){function _0x385a00(_0x18b681){try{_0x293ab3(_0x58759f[a1_0x15c6('0xa')](_0x18b681));}catch(_0x3354c0){_0x598730(_0x3354c0);}}function _0x4ba1d(_0x5211e3){try{_0x293ab3(_0x58759f[a1_0x15c6('0x7')](_0x5211e3));}catch(_0x1d1cc7){_0x598730(_0x1d1cc7);}}function _0x293ab3(_0x5d1a52){_0x5d1a52[a1_0x15c6('0x8')]?_0x103bf5(_0x5d1a52[a1_0x15c6('0x17')]):_0x20b3e7(_0x5d1a52['value'])['then'](_0x385a00,_0x4ba1d);}_0x293ab3((_0x58759f=_0x58759f[a1_0x15c6('0x14')](_0x27fa6b,_0x42093f||[]))[a1_0x15c6('0xa')]());});};Object[a1_0x15c6('0x0')](exports,a1_0x15c6('0xc'),{'value':!![]});exports['RunGroupApi']=void 0x0;const axios_1=require(a1_0x15c6('0x12'));const metric_logger_1=require('../../utilities/metric-logger');const {output}=require(a1_0x15c6('0x6'));class RunGroupApi{constructor(_0x59acb0){this['apiAxiosInstance']=(0x0,axios_1[a1_0x15c6('0x15')])(_0x59acb0);}['createRunGroup'](_0x827895,_0x5d51f3,_0x8453ee,_0x32c53b,_0x1bf68e){var _0x35e341;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x5ce758=(0x0,metric_logger_1[a1_0x15c6('0x11')])('createRunGroup');try{const _0x23db10=yield(0x0,axios_1[a1_0x15c6('0x10')])(()=>this['apiAxiosInstance'][a1_0x15c6('0xb')](a1_0x15c6('0x9'),{'branch':_0x827895,'runGroup':_0x5d51f3,'stopAgentsOnFailure':_0x8453ee,'agentCount':_0x32c53b,'stopAgentsAfter':_0x1bf68e}));_0x5ce758[a1_0x15c6('0x1')]((0x0,metric_logger_1[a1_0x15c6('0xd')])(_0x23db10));}catch(_0x297727){_0x5ce758['recordMetric'](((_0x35e341=_0x297727===null||_0x297727===void 0x0?void 0x0:_0x297727[a1_0x15c6('0x19')])===null||_0x35e341===void 0x0?void 0x0:_0x35e341[a1_0x15c6('0xf')])?(0x0,metric_logger_1['mapRespToPerfEntry'])(_0x297727[a1_0x15c6('0x19')][a1_0x15c6('0xf')]):metric_logger_1[a1_0x15c6('0x4')]);output[a1_0x15c6('0x16')]({'title':_0x297727['message']});process['exit'](0x1);}});}[a1_0x15c6('0x18')](_0x1f6717){var _0x2efe8e;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x54347e=(0x0,metric_logger_1[a1_0x15c6('0x11')])(a1_0x15c6('0x13'));try{const _0x34eb37=yield(0x0,axios_1[a1_0x15c6('0x10')])(()=>this['apiAxiosInstance'][a1_0x15c6('0xb')](a1_0x15c6('0x3'),{'runGroup':_0x1f6717}));_0x54347e[a1_0x15c6('0x1')]((0x0,metric_logger_1[a1_0x15c6('0xd')])(_0x34eb37));}catch(_0x5f3f73){_0x54347e[a1_0x15c6('0x1')](((_0x2efe8e=_0x5f3f73===null||_0x5f3f73===void 0x0?void 0x0:_0x5f3f73['axiosException'])===null||_0x2efe8e===void 0x0?void 0x0:_0x2efe8e[a1_0x15c6('0xf')])?(0x0,metric_logger_1[a1_0x15c6('0xd')])(_0x5f3f73['axiosException'][a1_0x15c6('0xf')]):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);output['error']({'title':_0x5f3f73['message']});process[a1_0x15c6('0x5')](0x1);}});}}exports[a1_0x15c6('0x2')]=RunGroupApi;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RunGroupApi = void 0;
13
+ const axios_1 = require("../../utilities/axios");
14
+ const metric_logger_1 = require("../../utilities/metric-logger");
15
+ const { output } = require('../../utilities/nx-imports');
16
+ class RunGroupApi {
17
+ constructor(options) {
18
+ this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
19
+ }
20
+ createRunGroup(branch, runGroup, stopAgentsOnFailure, agentCount, stopAgentsAfter) {
21
+ var _a;
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const recorder = (0, metric_logger_1.createMetricRecorder)('createRunGroup');
24
+ try {
25
+ const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/create-run-group', {
26
+ branch,
27
+ runGroup,
28
+ stopAgentsOnFailure,
29
+ agentCount,
30
+ stopAgentsAfter,
31
+ }));
32
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
33
+ }
34
+ catch (e) {
35
+ recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
36
+ ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
37
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
38
+ output.error({
39
+ title: e.message,
40
+ });
41
+ process.exit(1);
42
+ }
43
+ });
44
+ }
45
+ completeRunGroup(runGroup) {
46
+ var _a;
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const recorder = (0, metric_logger_1.createMetricRecorder)('createRunGroup');
49
+ try {
50
+ const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
51
+ runGroup: runGroup,
52
+ }));
53
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
54
+ }
55
+ catch (e) {
56
+ recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
57
+ ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
58
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
59
+ output.error({
60
+ title: e.message,
61
+ });
62
+ process.exit(1);
63
+ }
64
+ });
65
+ }
66
+ }
67
+ exports.RunGroupApi = RunGroupApi;
68
+ //# sourceMappingURL=run-group.api.js.map
@@ -1 +1,156 @@
1
- const a0_0x1927=['implicitDeps','taskId','outputObfuscator','../../../utilities/environment','length','collectTerminalOutput','runContext','code','startTask','terminalOutput','getTerminalOutput','keys','startsWith','skipNxCache','local-cache','../../../utilities/nx-imports','local-cache-hit','node_modules','obfuscate','readFileSync','../../../utilities/serializer-overrides','tasks','runtime','forEach','slice','task','target','MAX_CHARACTERS_FAILED_TASK','indexOf','toISOString','params','scheduleTask','cache-miss','remote-cache-hit','.cache','Cannot\x20find\x20task\x20','remote-cache','MAX_CHARACTERS_CACHED_TASK','hash','project','NX_CLOUD_UNLIMITED_OUTPUT','serializeOverrides','join','CloudEnabledLifeCycle','nodes','readTerminalOutputFile','updateStartedTask','terminalOutputs','defineProperty','status','path','statuses','cacheableOperations','toString','scheduledTasks','cacheStatus','MAX_CHARACTERS_SUCCESSFUL_TASK','local-cache-kept-existing','cleanUpHashDetails','cacheDirectory','find','__esModule'];(function(_0x286e73,_0x19275d){const _0x271157=function(_0x3c1ba6){while(--_0x3c1ba6){_0x286e73['push'](_0x286e73['shift']());}};_0x271157(++_0x19275d);}(a0_0x1927,0x6e));const a0_0x2711=function(_0x286e73,_0x19275d){_0x286e73=_0x286e73-0x0;let _0x271157=a0_0x1927[_0x286e73];return _0x271157;};'use strict';Object[a0_0x2711('0x0')](exports,a0_0x2711('0xd'),{'value':!![]});exports[a0_0x2711('0x39')]=void 0x0;const path=require(a0_0x2711('0x2'));const path_1=require(a0_0x2711('0x2'));const fs_1=require('fs');const environment_1=require(a0_0x2711('0x11'));const serializer_overrides_1=require(a0_0x2711('0x22'));const {workspaceRoot}=require(a0_0x2711('0x1d'));class CloudEnabledLifeCycle{constructor(_0x5d1a0c,_0x32e8de,_0x1aabf6,_0x45f967,_0x5e0c14,_0x4eebca,_0x2bb3e9){this['runContext']=_0x5d1a0c;this[a0_0x2711('0xb')]=_0x32e8de;this[a0_0x2711('0x1b')]=_0x1aabf6;this[a0_0x2711('0x13')]=_0x45f967;this[a0_0x2711('0x4')]=_0x5e0c14;this[a0_0x2711('0x10')]=_0x4eebca;this['tasks']=_0x2bb3e9;}[a0_0x2711('0x2d')](_0x5261af){this[a0_0x2711('0x14')][a0_0x2711('0x6')]['push'](_0x5261af);}[a0_0x2711('0x16')](_0x5ca8f1){this['tasks']['push']({'taskId':_0x5ca8f1['id'],'startTime':new Date()[a0_0x2711('0x2b')](),'target':_0x5ca8f1[a0_0x2711('0x28')][a0_0x2711('0x28')],'projectName':_0x5ca8f1['target'][a0_0x2711('0x35')],'hash':_0x5ca8f1[a0_0x2711('0x34')],'hashDetails':this['cleanUpHashDetails'](_0x5ca8f1['hashDetails']),'params':(0x0,serializer_overrides_1[a0_0x2711('0x37')])(_0x5ca8f1)});}['endTask'](_0x9f8e8a,_0x478ec8){let _0x416f9f;if(this[a0_0x2711('0x14')]['statuses'][_0x9f8e8a[a0_0x2711('0x34')]]){_0x416f9f=this[a0_0x2711('0x14')]['statuses'][_0x9f8e8a[a0_0x2711('0x34')]];}else{if(this[a0_0x2711('0x4')][a0_0x2711('0x2a')](_0x9f8e8a[a0_0x2711('0x28')][a0_0x2711('0x28')])>-0x1&&!this[a0_0x2711('0x1b')]){_0x416f9f=a0_0x2711('0x1e');}else{_0x416f9f=a0_0x2711('0x2e');}}this[a0_0x2711('0x3c')](_0x9f8e8a,_0x478ec8,_0x416f9f);}['endTasks'](_0x244c99){for(let _0x101f0d of _0x244c99){let _0x111c84;const _0x579835=_0x101f0d[a0_0x2711('0x1')]===a0_0x2711('0x32');const _0x1c222f=_0x101f0d[a0_0x2711('0x1')]==='cache';const _0x2b950e=_0x101f0d['status']===a0_0x2711('0x1c')||_0x101f0d[a0_0x2711('0x1')]===a0_0x2711('0x9')||_0x1c222f;if(this[a0_0x2711('0x14')][a0_0x2711('0x3')][_0x101f0d[a0_0x2711('0x27')]['hash']]){_0x111c84=this['runContext'][a0_0x2711('0x3')][_0x101f0d[a0_0x2711('0x27')][a0_0x2711('0x34')]];}else if(_0x579835){_0x111c84=a0_0x2711('0x2f');}else if(_0x2b950e){_0x111c84='local-cache-hit';}else{if(this['cacheableOperations'][a0_0x2711('0x2a')](_0x101f0d[a0_0x2711('0x27')][a0_0x2711('0x28')][a0_0x2711('0x28')])>-0x1&&!this[a0_0x2711('0x1b')]){_0x111c84=a0_0x2711('0x1e');}else{_0x111c84=a0_0x2711('0x2e');}}this[a0_0x2711('0x3c')](_0x101f0d[a0_0x2711('0x27')],_0x101f0d[a0_0x2711('0x15')],_0x111c84);}}['endCommand'](){}['updateStartedTask'](_0x3bb94f,_0x2311c4,_0x54a21b){const _0x2be9ba=this[a0_0x2711('0x23')][a0_0x2711('0xc')](_0x16c803=>_0x16c803[a0_0x2711('0xf')]===_0x3bb94f['id']);if(!_0x2be9ba){throw new Error(a0_0x2711('0x31')+_0x3bb94f['id']);}_0x2be9ba['endTime']=new Date()[a0_0x2711('0x2b')]();_0x2be9ba['status']=_0x2311c4;_0x2be9ba['params']=this[a0_0x2711('0x10')]['obfuscate'](_0x2be9ba[a0_0x2711('0x2c')]);_0x2be9ba[a0_0x2711('0x7')]=_0x54a21b;if(this[a0_0x2711('0x13')]){_0x2be9ba[a0_0x2711('0x17')]=this['getTerminalOutput'](_0x3bb94f[a0_0x2711('0x34')],_0x2be9ba[a0_0x2711('0x7')],_0x2311c4);}}[a0_0x2711('0x18')](_0x48fabf,_0x447632,_0x4fb2fd){let _0x3e1713;if(this[a0_0x2711('0xb')]){if(this[a0_0x2711('0xb')][a0_0x2711('0x1a')]('./')){_0x3e1713=(0x0,path_1[a0_0x2711('0x38')])(workspaceRoot,this[a0_0x2711('0xb')]);}else{_0x3e1713=this[a0_0x2711('0xb')];}}else{_0x3e1713=(0x0,path_1[a0_0x2711('0x38')])(workspaceRoot,a0_0x2711('0x1f'),a0_0x2711('0x30'),'nx');}try{const _0x3b4615=this[a0_0x2711('0x3b')](_0x3e1713,_0x48fabf);const _0x304ebe=this[a0_0x2711('0x10')][a0_0x2711('0x20')](_0x3b4615);if(environment_1[a0_0x2711('0x36')])return _0x304ebe;const _0x343648=_0x447632===a0_0x2711('0x2e')?_0x4fb2fd===0x0?CloudEnabledLifeCycle[a0_0x2711('0x8')]:CloudEnabledLifeCycle[a0_0x2711('0x29')]:CloudEnabledLifeCycle[a0_0x2711('0x33')];return _0x304ebe[a0_0x2711('0x12')]>_0x343648?'TRUNCATED\x0a\x0a'+_0x304ebe[a0_0x2711('0x26')](_0x304ebe[a0_0x2711('0x12')]-_0x343648):_0x304ebe;}catch(_0x4ac6a4){return'';}}[a0_0x2711('0xa')](_0x16d7ef){const _0x1febb7={};Object[a0_0x2711('0x19')](_0x16d7ef[a0_0x2711('0x3a')])['filter'](_0x27486b=>!_0x27486b[a0_0x2711('0x1a')]('npm:'))[a0_0x2711('0x25')](_0x5d1011=>{_0x1febb7[_0x5d1011]=_0x16d7ef[a0_0x2711('0x3a')][_0x5d1011];});return{'nodes':_0x1febb7,'runtime':_0x16d7ef[a0_0x2711('0x24')],'implicitDeps':_0x16d7ef[a0_0x2711('0xe')]};}[a0_0x2711('0x3b')](_0x21da43,_0x249dee){try{return(0x0,fs_1['readFileSync'])(path[a0_0x2711('0x38')](_0x21da43,a0_0x2711('0x3d'),_0x249dee))[a0_0x2711('0x5')]();}catch(_0x589727){try{return(0x0,fs_1[a0_0x2711('0x21')])(path[a0_0x2711('0x38')](_0x21da43,_0x249dee,a0_0x2711('0x17')))[a0_0x2711('0x5')]();}catch(_0x1b8463){return'';}}}}exports[a0_0x2711('0x39')]=CloudEnabledLifeCycle;CloudEnabledLifeCycle[a0_0x2711('0x29')]=0x30d40;CloudEnabledLifeCycle[a0_0x2711('0x8')]=0x4e20;CloudEnabledLifeCycle[a0_0x2711('0x33')]=0x4e20;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CloudEnabledLifeCycle = void 0;
4
+ const path = require("path");
5
+ const path_1 = require("path");
6
+ const fs_1 = require("fs");
7
+ const environment_1 = require("../../../utilities/environment");
8
+ const serializer_overrides_1 = require("../../../utilities/serializer-overrides");
9
+ const { workspaceRoot } = require('../../../utilities/nx-imports');
10
+ class CloudEnabledLifeCycle {
11
+ constructor(runContext, cacheDirectory, skipNxCache, collectTerminalOutput, cacheableOperations, outputObfuscator, tasks) {
12
+ this.runContext = runContext;
13
+ this.cacheDirectory = cacheDirectory;
14
+ this.skipNxCache = skipNxCache;
15
+ this.collectTerminalOutput = collectTerminalOutput;
16
+ this.cacheableOperations = cacheableOperations;
17
+ this.outputObfuscator = outputObfuscator;
18
+ this.tasks = tasks;
19
+ }
20
+ scheduleTask(task) {
21
+ this.runContext.scheduledTasks.push(task);
22
+ }
23
+ startTask(task) {
24
+ this.tasks.push({
25
+ taskId: task.id,
26
+ startTime: new Date().toISOString(),
27
+ target: task.target.target,
28
+ projectName: task.target.project,
29
+ hash: task.hash,
30
+ hashDetails: this.cleanUpHashDetails(task.hashDetails),
31
+ params: (0, serializer_overrides_1.serializeOverrides)(task),
32
+ });
33
+ }
34
+ // Used for older version for Nx. Remove in Dec 2022
35
+ endTask(task, code) {
36
+ let cacheStatus;
37
+ if (this.runContext.statuses[task.hash]) {
38
+ cacheStatus = this.runContext.statuses[task.hash];
39
+ }
40
+ else {
41
+ if (this.cacheableOperations.indexOf(task.target.target) > -1 &&
42
+ !this.skipNxCache) {
43
+ cacheStatus = 'local-cache-hit';
44
+ }
45
+ else {
46
+ cacheStatus = 'cache-miss';
47
+ }
48
+ }
49
+ this.updateStartedTask(task, code, cacheStatus);
50
+ }
51
+ endTasks(tasks) {
52
+ for (let t of tasks) {
53
+ let cacheStatus;
54
+ const taskIsRemoteCacheHit = t.status === 'remote-cache';
55
+ const taskIsLocalCacheHitPreNx135 = t.status === 'cache';
56
+ const taskIsLocalCacheHit = t.status === 'local-cache' ||
57
+ t.status === 'local-cache-kept-existing' ||
58
+ taskIsLocalCacheHitPreNx135;
59
+ if (this.runContext.statuses[t.task.hash]) {
60
+ cacheStatus = this.runContext.statuses[t.task.hash];
61
+ }
62
+ else if (taskIsRemoteCacheHit) {
63
+ cacheStatus = 'remote-cache-hit';
64
+ }
65
+ else if (taskIsLocalCacheHit) {
66
+ cacheStatus = 'local-cache-hit';
67
+ }
68
+ else {
69
+ if (this.cacheableOperations.indexOf(t.task.target.target) > -1 &&
70
+ !this.skipNxCache) {
71
+ cacheStatus = 'local-cache-hit';
72
+ }
73
+ else {
74
+ cacheStatus = 'cache-miss';
75
+ }
76
+ }
77
+ this.updateStartedTask(t.task, t.code, cacheStatus);
78
+ }
79
+ }
80
+ endCommand() { }
81
+ updateStartedTask(task, code, cacheStatus) {
82
+ const startedTask = this.tasks.find((t) => t.taskId === task.id);
83
+ if (!startedTask) {
84
+ throw new Error(`Cannot find task ${task.id}`);
85
+ }
86
+ startedTask.endTime = new Date().toISOString();
87
+ startedTask.status = code;
88
+ startedTask.params = this.outputObfuscator.obfuscate(startedTask.params);
89
+ startedTask.cacheStatus = cacheStatus;
90
+ if (this.collectTerminalOutput) {
91
+ startedTask.terminalOutput = this.getTerminalOutput(task.hash, startedTask.cacheStatus, code);
92
+ }
93
+ }
94
+ getTerminalOutput(hash, cacheStatus, code) {
95
+ let dir;
96
+ if (this.cacheDirectory) {
97
+ if (this.cacheDirectory.startsWith('./')) {
98
+ dir = (0, path_1.join)(workspaceRoot, this.cacheDirectory);
99
+ }
100
+ else {
101
+ dir = this.cacheDirectory;
102
+ }
103
+ }
104
+ else {
105
+ dir = (0, path_1.join)(workspaceRoot, 'node_modules', '.cache', 'nx');
106
+ }
107
+ try {
108
+ const taskOutput = this.readTerminalOutputFile(dir, hash);
109
+ const taskOutputSanitized = this.outputObfuscator.obfuscate(taskOutput);
110
+ if (environment_1.NX_CLOUD_UNLIMITED_OUTPUT)
111
+ return taskOutputSanitized;
112
+ const maxCharacters = cacheStatus === 'cache-miss'
113
+ ? code === 0
114
+ ? CloudEnabledLifeCycle.MAX_CHARACTERS_SUCCESSFUL_TASK
115
+ : CloudEnabledLifeCycle.MAX_CHARACTERS_FAILED_TASK
116
+ : CloudEnabledLifeCycle.MAX_CHARACTERS_CACHED_TASK;
117
+ return taskOutputSanitized.length > maxCharacters
118
+ ? `TRUNCATED\n\n${taskOutputSanitized.slice(taskOutputSanitized.length - maxCharacters)}`
119
+ : taskOutputSanitized;
120
+ }
121
+ catch (e) {
122
+ return '';
123
+ }
124
+ }
125
+ cleanUpHashDetails(hashDetails) {
126
+ const nodes = {};
127
+ Object.keys(hashDetails.nodes)
128
+ .filter((k) => !k.startsWith('npm:'))
129
+ .forEach((k) => {
130
+ nodes[k] = hashDetails.nodes[k];
131
+ });
132
+ return {
133
+ nodes,
134
+ runtime: hashDetails.runtime,
135
+ implicitDeps: hashDetails.implicitDeps,
136
+ };
137
+ }
138
+ readTerminalOutputFile(dir, hash) {
139
+ try {
140
+ return (0, fs_1.readFileSync)(path.join(dir, 'terminalOutputs', hash)).toString();
141
+ }
142
+ catch (_a) {
143
+ try {
144
+ return (0, fs_1.readFileSync)(path.join(dir, hash, 'terminalOutput')).toString();
145
+ }
146
+ catch (_b) {
147
+ return '';
148
+ }
149
+ }
150
+ }
151
+ }
152
+ exports.CloudEnabledLifeCycle = CloudEnabledLifeCycle;
153
+ CloudEnabledLifeCycle.MAX_CHARACTERS_FAILED_TASK = 200000;
154
+ CloudEnabledLifeCycle.MAX_CHARACTERS_SUCCESSFUL_TASK = 20000;
155
+ CloudEnabledLifeCycle.MAX_CHARACTERS_CACHED_TASK = 20000;
156
+ //# sourceMappingURL=cloud-enabled-life-cycle.js.map
@@ -1 +1,288 @@
1
- const a1_0x3b45=['__esModule','CloudEnabledLifeCycle','taskId','../../../utilities/nx-imports','lifeCycle','./node_modules/.cache/nx','CloudRunApi','env','pathExists','ACCESS_TOKEN','../../terminal-output/end-of-run-message','defineProperty','then','cacheableOperations','../../api/error-reporter.api','apply','skipNxCache','@nrwl/nx-cloud/lib/daemon/process-run-end','uploads','.nx.app','scan','requests','printMessages','throw','value','tasks-hashes-','stringify','getMachineInfo','FileStorage','endsWith','waitForStoreRequestsToComplete','error','localhost','./cloud-remote-cache','maskedProperties','./cloud-enabled-life-cycle','runUrl','assign','next','indexOf','join','all','NX_CLOUD_DISTRIBUTED_EXECUTION_ID','submitRunMetrics','enabled','cachePath','complete','Executed\x20tasks\x20with\x20hashes:\x20','generateUniqueLinkId','EndOfRunMessage','subscribe','message','../../../utilities/metric-logger','rxjs/internal/Subject','obfuscate','../../terminal-output/output-obfuscator','encryptionKey','ErrorReporterApi','MessageReporter','__awaiter','OutputObfuscator','./cloud-run.api','cacheDirectory','https://nx.app','VERBOSE_LOGGING','push','anyErrors','Nx\x20Cloud\x20wasn\x27t\x20able\x20to\x20store\x20artifacts.','toString','api.nrwl.io','fs-extra','../../file-storage/file-storage','daemon','../../file-storage/e2e-encryption','CloudRemoteCache','toISOString','Nx\x20Cloud\x20Problems','url','.commit','cloudEnabledTasksRunner','getBranch','printCacheHitsMessage','done','map','parseCommand','extractGitSha'];(function(_0x55aef5,_0x3b45ac){const _0x17aa86=function(_0x455f4b){while(--_0x455f4b){_0x55aef5['push'](_0x55aef5['shift']());}};_0x17aa86(++_0x3b45ac);}(a1_0x3b45,0x1cc));const a1_0x17aa=function(_0x55aef5,_0x3b45ac){_0x55aef5=_0x55aef5-0x0;let _0x17aa86=a1_0x3b45[_0x55aef5];return _0x17aa86;};'use strict';var __awaiter=this&&this[a1_0x17aa('0x1d')]||function(_0x4512b3,_0x31beb4,_0x2bad60,_0x3dfae2){function _0x53a145(_0x71fedd){return _0x71fedd instanceof _0x2bad60?_0x71fedd:new _0x2bad60(function(_0x458dd1){_0x458dd1(_0x71fedd);});}return new(_0x2bad60||(_0x2bad60=Promise))(function(_0x4b8e48,_0x18e4fc){function _0x340d0e(_0x2ee5fe){try{_0x2cf5c2(_0x3dfae2[a1_0x17aa('0x8')](_0x2ee5fe));}catch(_0x2ae99e){_0x18e4fc(_0x2ae99e);}}function _0x288bc1(_0x15fcdb){try{_0x2cf5c2(_0x3dfae2[a1_0x17aa('0x4f')](_0x15fcdb));}catch(_0x1c0f4e){_0x18e4fc(_0x1c0f4e);}}function _0x2cf5c2(_0x37dd72){_0x37dd72[a1_0x17aa('0x34')]?_0x4b8e48(_0x37dd72['value']):_0x53a145(_0x37dd72[a1_0x17aa('0x50')])[a1_0x17aa('0x44')](_0x340d0e,_0x288bc1);}_0x2cf5c2((_0x3dfae2=_0x3dfae2[a1_0x17aa('0x47')](_0x4512b3,_0x31beb4||[]))[a1_0x17aa('0x8')]());});};Object[a1_0x17aa('0x43')](exports,a1_0x17aa('0x38'),{'value':!![]});exports[a1_0x17aa('0x31')]=void 0x0;const message_reporter_1=require('../../terminal-output/message-reporter');const end_of_run_message_1=require(a1_0x17aa('0x42'));const output_obfuscator_1=require(a1_0x17aa('0x19'));const cloud_enabled_life_cycle_1=require(a1_0x17aa('0x5'));const file_storage_1=require(a1_0x17aa('0x29'));const e2e_encryption_1=require(a1_0x17aa('0x2b'));const environment_1=require('../../../utilities/environment');const cloud_remote_cache_1=require(a1_0x17aa('0x3'));const cloud_run_api_1=require(a1_0x17aa('0x1f'));const fs_1=require('fs');const path=require('path');const metric_logger_1=require(a1_0x17aa('0x16'));const error_reporter_api_1=require(a1_0x17aa('0x46'));const path_1=require('path');const fs_extra_1=require(a1_0x17aa('0x28'));const id_generator_1=require('./id-generator');const {tasksRunner,output,Cache}=require(a1_0x17aa('0x3b'));function createApi(_0x24470f,_0x32f535,_0x4bc29c){const _0x737d0=(0x0,environment_1[a1_0x17aa('0x53')])(_0x32f535);return new cloud_run_api_1[(a1_0x17aa('0x3e'))](_0x24470f,_0x4bc29c,_0x32f535,_0x737d0);}function storeTaskHashes(_0x25575e,_0x1c42c5,_0x505373){const _0x3a6c12=JSON[a1_0x17aa('0x52')](_0x25575e[a1_0x17aa('0x35')](_0xceeafb=>({'taskId':_0xceeafb[a1_0x17aa('0x3a')],'hash':_0xceeafb['hash']})));if(environment_1[a1_0x17aa('0x22')]){output['note']({'title':a1_0x17aa('0x11')+_0x3a6c12});}(0x0,fs_1['writeFileSync'])(path[a1_0x17aa('0xa')](_0x1c42c5,a1_0x17aa('0x51')+_0x505373),_0x3a6c12);}function onComplete({daemon,lifeCycle,options,remoteCache,api,outputObfuscator,runStartTime,messages,endOfRunMessage,taskExecutions,versionOfNxBefore133,inner,encryptionKey,fileStorage,uploadInCurrentProcess,runContext}){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x1bb485=new Date()[a1_0x17aa('0x2d')]();const _0x5b6005=(0x0,environment_1[a1_0x17aa('0x32')])();const _0x2a7da9={'command':outputObfuscator[a1_0x17aa('0x18')]((0x0,environment_1[a1_0x17aa('0x36')])()),'startTime':runStartTime,'endTime':_0x1bb485,'distributedExecutionId':environment_1[a1_0x17aa('0xc')],'branch':_0x5b6005,'scan':!![],'runGroup':(0x0,environment_1['getRunGroup'])(),'sha':_0x5b6005?(0x0,environment_1[a1_0x17aa('0x37')])():undefined,'inner':inner};if(uploadInCurrentProcess){if(environment_1['AGENT_RUNNING_IN_DISTRIBUTED_EXECUTION']){storeTaskHashes(taskExecutions,options[a1_0x17aa('0x20')]||a1_0x17aa('0x3d'),environment_1[a1_0x17aa('0xc')]);}try{yield remoteCache[a1_0x17aa('0x0')]();}catch(_0x1f47a7){output[a1_0x17aa('0x1')]({'title':a1_0x17aa('0x25')});messages[a1_0x17aa('0x4e')]();process['exit'](environment_1['DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE']);}try{yield api['endRun'](_0x2a7da9,taskExecutions);}catch(_0x8dda4e){output[a1_0x17aa('0x1')]({'title':'Nx\x20Cloud\x20wasn\x27t\x20able\x20to\x20record\x20its\x20run.'});messages[a1_0x17aa('0x4e')]();process['exit'](environment_1['DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE']);}yield(0x0,metric_logger_1[a1_0x17aa('0xd')])(options);}else{try{const _0x38fd71=environment_1[a1_0x17aa('0x41')]?environment_1['ACCESS_TOKEN']:options['accessToken'];const _0x195b79=(0x0,id_generator_1[a1_0x17aa('0x12')])();yield daemon['processInBackground'](a1_0x17aa('0x49'),{'encryptionKey':encryptionKey,'runnerOptions':Object[a1_0x17aa('0x7')](Object[a1_0x17aa('0x7')]({},options),{'accessToken':_0x38fd71}),'uploads':fileStorage[a1_0x17aa('0x4a')],'runEnd':{'runData':_0x2a7da9,'taskExecutions':taskExecutions,'linkId':_0x195b79}});runContext[a1_0x17aa('0x6')]=(options[a1_0x17aa('0x2f')]||a1_0x17aa('0x21'))+'/runs/'+_0x195b79;}catch(_0x16fac6){output['warn']({'title':a1_0x17aa('0x2e'),'bodyLines':[_0x16fac6[a1_0x17aa('0x15')]||_0x16fac6[a1_0x17aa('0x26')]()]});}}if(versionOfNxBefore133){setTimeout(()=>{messages['printMessages']();if(!messages['anyErrors']&&!inner){endOfRunMessage[a1_0x17aa('0x33')]();}},0x0);}else{messages[a1_0x17aa('0x4e')]();if(!messages[a1_0x17aa('0x24')]&&!inner){endOfRunMessage[a1_0x17aa('0x33')]();}}});}function createLifeCycle(_0x345939,_0x52b459,_0x282fae,_0x4e8927){const _0x150249=new cloud_enabled_life_cycle_1[(a1_0x17aa('0x39'))](_0x345939,_0x52b459[a1_0x17aa('0x20')],!!_0x52b459[a1_0x17aa('0x48')],_0x52b459[a1_0x17aa('0x4c')]===undefined?!![]:_0x52b459[a1_0x17aa('0x4c')],_0x52b459[a1_0x17aa('0x45')]||[],_0x282fae,_0x4e8927);try{const {CompositeLifeCycle}=require(a1_0x17aa('0x3b'));if(!CompositeLifeCycle)return _0x150249;return new CompositeLifeCycle([_0x52b459[a1_0x17aa('0x3c')],_0x150249]);}catch(_0x5b3f31){return _0x150249;}}function fetchUrlsForKnownHashesUpfront(_0x514e56,_0x10c73c,_0x29878b,_0x25cfee){return __awaiter(this,void 0x0,void 0x0,function*(){let _0x30fa2e=_0x29878b[a1_0x17aa('0x35')](_0x133393=>_0x133393['hash'])['filter'](_0x51fcce=>!!_0x51fcce);const _0x405baf=new Cache(_0x25cfee);if(!_0x25cfee[a1_0x17aa('0x48')]){const _0x385140=yield Promise[a1_0x17aa('0xb')](_0x30fa2e[a1_0x17aa('0x35')](_0x505bf7=>{const _0x29f272=(0x0,path_1[a1_0x17aa('0xa')])(_0x405baf[a1_0x17aa('0xf')],_0x505bf7+a1_0x17aa('0x30'));return(0x0,fs_extra_1[a1_0x17aa('0x40')])(_0x29f272);}));const _0x14a8e5=[];for(let _0x4e5b79=0x0;_0x4e5b79<_0x385140['length'];++_0x4e5b79){if(_0x385140[_0x4e5b79]){_0x14a8e5[a1_0x17aa('0x23')](_0x30fa2e[_0x4e5b79]);}}_0x30fa2e=_0x14a8e5;}if(_0x30fa2e['length']>0x0){const _0x113e06=_0x514e56['startRun'](environment_1['NX_CLOUD_DISTRIBUTED_EXECUTION_ID'],_0x30fa2e);for(const _0x1d28f0 of _0x30fa2e){_0x10c73c[a1_0x17aa('0x4d')][_0x1d28f0]=_0x113e06;}}});}function isConnectedToPrivateCloud(_0x48b6f2){if(!_0x48b6f2[a1_0x17aa('0x2f')])return![];if(_0x48b6f2[a1_0x17aa('0x2f')][a1_0x17aa('0x55')](a1_0x17aa('0x27')))return![];if(_0x48b6f2[a1_0x17aa('0x2f')]['endsWith'](a1_0x17aa('0x4b')))return![];if(_0x48b6f2['url'][a1_0x17aa('0x9')](a1_0x17aa('0x2'))>-0x1)return![];return!![];}function cloudEnabledTasksRunner(_0x44496b,_0x52156f,_0x5b3ea9,_0x17a583=![]){var _0x5ec162;const _0x48fc6f={'statuses':{},'scheduledTasks':[],'requests':{},'allTasks':_0x44496b};const _0xdd7645=_0x52156f[a1_0x17aa('0x3c')]===undefined;const _0x68185a=[];const _0x470f05=new message_reporter_1[(a1_0x17aa('0x1c'))](_0x52156f);const _0x38ce85=createApi(_0x470f05,_0x52156f,_0x48fc6f);const _0xca0099=new end_of_run_message_1[(a1_0x17aa('0x13'))](_0x48fc6f,_0x68185a);const _0x428f92=new output_obfuscator_1[(a1_0x17aa('0x1e'))](_0x52156f[a1_0x17aa('0x4')]);const _0x38cc62=new Date()[a1_0x17aa('0x2d')]();const _0x19bc3e=createLifeCycle(_0x48fc6f,_0x52156f,_0x428f92,_0x68185a);const _0x434d5b=environment_1['ENCRYPTION_KEY']||_0x52156f[a1_0x17aa('0x1a')];const _0x4473b0=new e2e_encryption_1['E2EEncryption'](_0x434d5b);const _0x336859=new error_reporter_api_1[(a1_0x17aa('0x1b'))](_0x52156f);const _0x1582dc=!!environment_1['AGENT_RUNNING_IN_DISTRIBUTED_EXECUTION']||!((_0x5ec162=_0x5b3ea9[a1_0x17aa('0x2a')])===null||_0x5ec162===void 0x0?void 0x0:_0x5ec162[a1_0x17aa('0xe')]())||isConnectedToPrivateCloud(_0x52156f);const _0x3d881=new file_storage_1[(a1_0x17aa('0x54'))](_0x4473b0,_0x336859,![],_0x1582dc);const _0x43932b=new cloud_remote_cache_1[(a1_0x17aa('0x2c'))](_0x470f05,_0x38ce85,_0x48fc6f,_0x3d881);fetchUrlsForKnownHashesUpfront(_0x38ce85,_0x48fc6f,_0x44496b,_0x52156f);delete process[a1_0x17aa('0x3f')][a1_0x17aa('0xc')];const _0x176b9b=tasksRunner(_0x44496b,Object[a1_0x17aa('0x7')](Object[a1_0x17aa('0x7')]({},_0x52156f),{'remoteCache':_0x43932b,'lifeCycle':_0x19bc3e}),_0x5b3ea9);if(_0x176b9b[a1_0x17aa('0x14')]){const {Subject}=require(a1_0x17aa('0x17'));const _0x258a3b=new Subject();_0x176b9b['subscribe']({'next':_0x188140=>_0x258a3b[a1_0x17aa('0x8')](_0x188140),'error':_0x2361b2=>_0x258a3b[a1_0x17aa('0x1')](_0x2361b2),'complete':()=>__awaiter(this,void 0x0,void 0x0,function*(){yield onComplete({'daemon':_0x5b3ea9[a1_0x17aa('0x2a')],'lifeCycle':_0x19bc3e,'options':_0x52156f,'remoteCache':_0x43932b,'api':_0x38ce85,'outputObfuscator':_0x428f92,'runStartTime':_0x38cc62,'messages':_0x470f05,'endOfRunMessage':_0xca0099,'taskExecutions':_0x68185a,'versionOfNxBefore133':_0xdd7645,'inner':_0x17a583,'encryptionKey':_0x434d5b,'fileStorage':_0x3d881,'uploadInCurrentProcess':_0x1582dc,'runContext':_0x48fc6f});_0x258a3b[a1_0x17aa('0x10')]();})});return _0x258a3b;}else{return _0x176b9b[a1_0x17aa('0x44')](_0x3aa2bc=>__awaiter(this,void 0x0,void 0x0,function*(){yield onComplete({'daemon':_0x5b3ea9[a1_0x17aa('0x2a')],'lifeCycle':_0x19bc3e,'options':_0x52156f,'remoteCache':_0x43932b,'api':_0x38ce85,'outputObfuscator':_0x428f92,'runStartTime':_0x38cc62,'messages':_0x470f05,'endOfRunMessage':_0xca0099,'taskExecutions':_0x68185a,'versionOfNxBefore133':_0xdd7645,'inner':_0x17a583,'encryptionKey':_0x434d5b,'fileStorage':_0x3d881,'uploadInCurrentProcess':_0x1582dc,'runContext':_0x48fc6f});return _0x3aa2bc;}))['catch'](_0x359435=>__awaiter(this,void 0x0,void 0x0,function*(){yield onComplete({'daemon':_0x5b3ea9[a1_0x17aa('0x2a')],'lifeCycle':_0x19bc3e,'options':_0x52156f,'remoteCache':_0x43932b,'api':_0x38ce85,'outputObfuscator':_0x428f92,'runStartTime':_0x38cc62,'messages':_0x470f05,'endOfRunMessage':_0xca0099,'taskExecutions':_0x68185a,'versionOfNxBefore133':_0xdd7645,'inner':_0x17a583,'encryptionKey':_0x434d5b,'fileStorage':_0x3d881,'uploadInCurrentProcess':_0x1582dc,'runContext':_0x48fc6f});throw _0x359435;}));}}exports[a1_0x17aa('0x31')]=cloudEnabledTasksRunner;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.cloudEnabledTasksRunner = void 0;
13
+ const message_reporter_1 = require("../../terminal-output/message-reporter");
14
+ const end_of_run_message_1 = require("../../terminal-output/end-of-run-message");
15
+ const output_obfuscator_1 = require("../../terminal-output/output-obfuscator");
16
+ const cloud_enabled_life_cycle_1 = require("./cloud-enabled-life-cycle");
17
+ const file_storage_1 = require("../../file-storage/file-storage");
18
+ const e2e_encryption_1 = require("../../file-storage/e2e-encryption");
19
+ const environment_1 = require("../../../utilities/environment");
20
+ const cloud_remote_cache_1 = require("./cloud-remote-cache");
21
+ const cloud_run_api_1 = require("./cloud-run.api");
22
+ const fs_1 = require("fs");
23
+ const path = require("path");
24
+ const metric_logger_1 = require("../../../utilities/metric-logger");
25
+ const error_reporter_api_1 = require("../../api/error-reporter.api");
26
+ const path_1 = require("path");
27
+ const fs_extra_1 = require("fs-extra");
28
+ const id_generator_1 = require("./id-generator");
29
+ const { tasksRunner, output, Cache } = require('../../../utilities/nx-imports');
30
+ function createApi(errors, options, runContext) {
31
+ const machineInfo = (0, environment_1.getMachineInfo)(options);
32
+ return new cloud_run_api_1.CloudRunApi(errors, runContext, options, machineInfo);
33
+ }
34
+ function storeTaskHashes(taskExecutions, directory, distributedExecutionId) {
35
+ const hashes = JSON.stringify(taskExecutions.map((t) => ({
36
+ taskId: t.taskId,
37
+ hash: t.hash,
38
+ })));
39
+ if (environment_1.VERBOSE_LOGGING) {
40
+ output.note({
41
+ title: `Executed tasks with hashes: ${hashes}`,
42
+ });
43
+ }
44
+ (0, fs_1.writeFileSync)(path.join(directory, `tasks-hashes-${distributedExecutionId}`), hashes);
45
+ }
46
+ function onComplete({ daemon, lifeCycle, options, remoteCache, api, outputObfuscator, runStartTime, messages, endOfRunMessage, taskExecutions, versionOfNxBefore133, inner, encryptionKey, fileStorage, uploadInCurrentProcess, runContext, }) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const runEndTime = new Date().toISOString();
49
+ const branch = (0, environment_1.getBranch)();
50
+ const runData = {
51
+ command: outputObfuscator.obfuscate((0, environment_1.parseCommand)()),
52
+ startTime: runStartTime,
53
+ endTime: runEndTime,
54
+ distributedExecutionId: environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_ID,
55
+ branch: branch,
56
+ scan: true,
57
+ runGroup: (0, environment_1.getRunGroup)(),
58
+ // only set sha if branch is set because we invoke a separate process,
59
+ // which adds a few millis
60
+ sha: branch ? (0, environment_1.extractGitSha)() : undefined,
61
+ inner: inner,
62
+ };
63
+ if (uploadInCurrentProcess) {
64
+ if (environment_1.AGENT_RUNNING_IN_DISTRIBUTED_EXECUTION) {
65
+ storeTaskHashes(taskExecutions, options.cacheDirectory || './node_modules/.cache/nx', environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_ID);
66
+ }
67
+ try {
68
+ yield remoteCache.waitForStoreRequestsToComplete();
69
+ }
70
+ catch (e) {
71
+ output.error({
72
+ title: `Nx Cloud wasn't able to store artifacts.`,
73
+ });
74
+ messages.printMessages();
75
+ process.exit(environment_1.DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE);
76
+ }
77
+ try {
78
+ yield api.endRun(runData, taskExecutions);
79
+ }
80
+ catch (e) {
81
+ output.error({
82
+ title: `Nx Cloud wasn't able to record its run.`,
83
+ });
84
+ messages.printMessages();
85
+ process.exit(environment_1.DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE);
86
+ }
87
+ yield (0, metric_logger_1.submitRunMetrics)(options);
88
+ }
89
+ else {
90
+ try {
91
+ const accessToken = environment_1.ACCESS_TOKEN ? environment_1.ACCESS_TOKEN : options.accessToken;
92
+ const linkId = (0, id_generator_1.generateUniqueLinkId)();
93
+ yield daemon.processInBackground('@nrwl/nx-cloud/lib/daemon/process-run-end', {
94
+ encryptionKey,
95
+ runnerOptions: Object.assign(Object.assign({}, options), { accessToken }),
96
+ uploads: fileStorage.uploads,
97
+ runEnd: {
98
+ runData,
99
+ taskExecutions,
100
+ linkId,
101
+ },
102
+ });
103
+ runContext.runUrl = `${options.url || 'https://nx.app'}/runs/${linkId}`;
104
+ }
105
+ catch (e) {
106
+ output.warn({
107
+ title: `Nx Cloud Problems`,
108
+ bodyLines: [e.message || e.toString()],
109
+ });
110
+ }
111
+ }
112
+ // this workaround is required because prior to Nx 13.3 we printed
113
+ // the end message after the runner completes, so we need to wait for the
114
+ // message to appear in the right place
115
+ if (versionOfNxBefore133) {
116
+ setTimeout(() => {
117
+ messages.printMessages();
118
+ if (!messages.anyErrors && !inner) {
119
+ endOfRunMessage.printCacheHitsMessage();
120
+ }
121
+ }, 0);
122
+ }
123
+ else {
124
+ messages.printMessages();
125
+ if (!messages.anyErrors && !inner) {
126
+ endOfRunMessage.printCacheHitsMessage();
127
+ }
128
+ }
129
+ });
130
+ }
131
+ function createLifeCycle(runContext, options, outputObfuscator, tasks) {
132
+ const cloudEnabledLifeCycle = new cloud_enabled_life_cycle_1.CloudEnabledLifeCycle(runContext, options.cacheDirectory, !!options.skipNxCache, options.scan === undefined ? true : options.scan, options.cacheableOperations || [], outputObfuscator, tasks);
133
+ try {
134
+ const { CompositeLifeCycle } = require('../../../utilities/nx-imports');
135
+ if (!CompositeLifeCycle)
136
+ return cloudEnabledLifeCycle;
137
+ return new CompositeLifeCycle([options.lifeCycle, cloudEnabledLifeCycle]);
138
+ }
139
+ catch (e) {
140
+ return cloudEnabledLifeCycle;
141
+ }
142
+ }
143
+ function fetchUrlsForKnownHashesUpfront(api, runContext, tasks, options) {
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ let hashes = tasks.map((t) => t.hash).filter((h) => !!h);
146
+ const c = new Cache(options);
147
+ if (!options.skipNxCache) {
148
+ // filter out the urls that don't have artifact stored locally
149
+ const promises = yield Promise.all(hashes.map((hash) => {
150
+ const tdCommit = (0, path_1.join)(c.cachePath, `${hash}.commit`);
151
+ return (0, fs_extra_1.pathExists)(tdCommit);
152
+ }));
153
+ const missingHashes = [];
154
+ for (let i = 0; i < promises.length; ++i) {
155
+ if (promises[i]) {
156
+ missingHashes.push(hashes[i]);
157
+ }
158
+ }
159
+ hashes = missingHashes;
160
+ }
161
+ if (hashes.length > 0) {
162
+ const startRunRequest = api.startRun(environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_ID, hashes);
163
+ for (const hash of hashes) {
164
+ runContext.requests[hash] = startRunRequest;
165
+ }
166
+ }
167
+ });
168
+ }
169
+ function isConnectedToPrivateCloud(options) {
170
+ if (!options.url)
171
+ return false;
172
+ if (options.url.endsWith('api.nrwl.io'))
173
+ return false;
174
+ if (options.url.endsWith('.nx.app'))
175
+ return false;
176
+ if (options.url.indexOf('localhost') > -1)
177
+ return false;
178
+ return true;
179
+ }
180
+ function cloudEnabledTasksRunner(tasks, options, context, inner = false) {
181
+ var _a;
182
+ const runContext = {
183
+ statuses: {},
184
+ scheduledTasks: [],
185
+ requests: {},
186
+ allTasks: tasks,
187
+ };
188
+ const versionOfNxBefore133 = options.lifeCycle === undefined;
189
+ const taskExecutions = [];
190
+ const messages = new message_reporter_1.MessageReporter(options);
191
+ const api = createApi(messages, options, runContext);
192
+ const endOfRunMessage = new end_of_run_message_1.EndOfRunMessage(runContext, taskExecutions);
193
+ const outputObfuscator = new output_obfuscator_1.OutputObfuscator(options.maskedProperties);
194
+ const runStartTime = new Date().toISOString();
195
+ const lifeCycle = createLifeCycle(runContext, options, outputObfuscator, taskExecutions);
196
+ const encryptionKey = environment_1.ENCRYPTION_KEY || options.encryptionKey;
197
+ const encryption = new e2e_encryption_1.E2EEncryption(encryptionKey);
198
+ const errorApi = new error_reporter_api_1.ErrorReporterApi(options);
199
+ const uploadInCurrentProcess = !!environment_1.AGENT_RUNNING_IN_DISTRIBUTED_EXECUTION ||
200
+ !((_a = context.daemon) === null || _a === void 0 ? void 0 : _a.enabled()) ||
201
+ isConnectedToPrivateCloud(options);
202
+ const fileStorage = new file_storage_1.FileStorage(encryption, errorApi, false, uploadInCurrentProcess);
203
+ const remoteCache = new cloud_remote_cache_1.CloudRemoteCache(messages, api, runContext, fileStorage);
204
+ // we don't await for it cause this step is optional
205
+ fetchUrlsForKnownHashesUpfront(api, runContext, tasks, options);
206
+ // have to reset it so we don't capture inner tasks
207
+ delete process.env.NX_CLOUD_DISTRIBUTED_EXECUTION_ID;
208
+ const res = tasksRunner(tasks, Object.assign(Object.assign({}, options), { remoteCache, lifeCycle }), context);
209
+ // observable -> legacy
210
+ if (res.subscribe) {
211
+ const { Subject } = require('rxjs/internal/Subject');
212
+ const wrappedRes = new Subject();
213
+ res.subscribe({
214
+ next: (value) => wrappedRes.next(value),
215
+ error: (err) => wrappedRes.error(err),
216
+ complete: () => __awaiter(this, void 0, void 0, function* () {
217
+ yield onComplete({
218
+ daemon: context.daemon,
219
+ lifeCycle,
220
+ options,
221
+ remoteCache,
222
+ api,
223
+ outputObfuscator,
224
+ runStartTime,
225
+ messages,
226
+ endOfRunMessage,
227
+ taskExecutions,
228
+ versionOfNxBefore133,
229
+ inner,
230
+ encryptionKey,
231
+ fileStorage,
232
+ uploadInCurrentProcess,
233
+ runContext,
234
+ });
235
+ wrappedRes.complete();
236
+ }),
237
+ });
238
+ return wrappedRes;
239
+ // promise
240
+ }
241
+ else {
242
+ return res
243
+ .then((r) => __awaiter(this, void 0, void 0, function* () {
244
+ yield onComplete({
245
+ daemon: context.daemon,
246
+ lifeCycle,
247
+ options,
248
+ remoteCache,
249
+ api,
250
+ outputObfuscator,
251
+ runStartTime,
252
+ messages,
253
+ endOfRunMessage,
254
+ taskExecutions,
255
+ versionOfNxBefore133,
256
+ inner,
257
+ encryptionKey,
258
+ fileStorage,
259
+ uploadInCurrentProcess,
260
+ runContext,
261
+ });
262
+ return r;
263
+ }))
264
+ .catch((e) => __awaiter(this, void 0, void 0, function* () {
265
+ yield onComplete({
266
+ daemon: context.daemon,
267
+ lifeCycle,
268
+ options,
269
+ remoteCache,
270
+ api,
271
+ outputObfuscator,
272
+ runStartTime,
273
+ messages,
274
+ endOfRunMessage,
275
+ taskExecutions,
276
+ versionOfNxBefore133,
277
+ inner,
278
+ encryptionKey,
279
+ fileStorage,
280
+ uploadInCurrentProcess,
281
+ runContext,
282
+ });
283
+ throw e;
284
+ }));
285
+ }
286
+ }
287
+ exports.cloudEnabledTasksRunner = cloudEnabledTasksRunner;
288
+ //# sourceMappingURL=cloud-enabled.runner.js.map