Socket
Socket
Sign inDemoInstall

nx-cloud

Package Overview
Dependencies
Maintainers
1
Versions
153
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nx-cloud - npm Package Compare versions

Comparing version 14.0.5 to 14.0.6-beta.1

lib/core/api/error-reporter.api.d.ts

66

lib/core/api/run-group.api.js

@@ -1,1 +0,65 @@

const a0_0x9bcf=['post','__esModule','../../utilities/axios','createRunGroup','RunGroupApi','apply','axiosException','/nx-cloud/executions/create-run-group','message','value','defineProperty','throw','next','completeRunGroup','../../utilities/nx-imports','RUNNER_FAILURE_PERF_ENTRY','response','axiosMultipleTries','exit','recordMetric','apiAxiosInstance','mapRespToPerfEntry','__awaiter','../../utilities/metric-logger','error','/nx-cloud/executions/complete-run-group','createApiAxiosInstance','then','createMetricRecorder'];(function(_0x56c574,_0x9bcfc8){const _0x354b09=function(_0x32994e){while(--_0x32994e){_0x56c574['push'](_0x56c574['shift']());}};_0x354b09(++_0x9bcfc8);}(a0_0x9bcf,0x1d0));const a0_0x354b=function(_0x56c574,_0x9bcfc8){_0x56c574=_0x56c574-0x0;let _0x354b09=a0_0x9bcf[_0x56c574];return _0x354b09;};'use strict';var __awaiter=this&&this[a0_0x354b('0x16')]||function(_0x357a34,_0x44852f,_0x3c94b6,_0x3d5e2e){function _0xe417b2(_0x20a8b3){return _0x20a8b3 instanceof _0x3c94b6?_0x20a8b3:new _0x3c94b6(function(_0x5dc4d3){_0x5dc4d3(_0x20a8b3);});}return new(_0x3c94b6||(_0x3c94b6=Promise))(function(_0x4ff18e,_0xc35589){function _0x33d838(_0x2bf9cc){try{_0x43fedd(_0x3d5e2e[a0_0x354b('0xc')](_0x2bf9cc));}catch(_0x1b8a36){_0xc35589(_0x1b8a36);}}function _0x2a84c1(_0x46f978){try{_0x43fedd(_0x3d5e2e[a0_0x354b('0xb')](_0x46f978));}catch(_0x55547c){_0xc35589(_0x55547c);}}function _0x43fedd(_0x1a1fc1){_0x1a1fc1['done']?_0x4ff18e(_0x1a1fc1[a0_0x354b('0x9')]):_0xe417b2(_0x1a1fc1[a0_0x354b('0x9')])[a0_0x354b('0x1b')](_0x33d838,_0x2a84c1);}_0x43fedd((_0x3d5e2e=_0x3d5e2e[a0_0x354b('0x5')](_0x357a34,_0x44852f||[]))[a0_0x354b('0xc')]());});};Object[a0_0x354b('0xa')](exports,a0_0x354b('0x1'),{'value':!![]});exports[a0_0x354b('0x4')]=void 0x0;const axios_1=require(a0_0x354b('0x2'));const metric_logger_1=require(a0_0x354b('0x17'));const {output}=require(a0_0x354b('0xe'));class RunGroupApi{constructor(_0xd152bd){this[a0_0x354b('0x14')]=(0x0,axios_1[a0_0x354b('0x1a')])(_0xd152bd);}['createRunGroup'](_0x225e34,_0x3a9cd8){var _0xfdc583;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x311f7d=(0x0,metric_logger_1[a0_0x354b('0x1c')])('createRunGroup');try{const _0x25428c=yield(0x0,axios_1[a0_0x354b('0x11')])(()=>this['apiAxiosInstance'][a0_0x354b('0x0')](a0_0x354b('0x7'),{'branch':_0x225e34,'runGroup':_0x3a9cd8}));_0x311f7d['recordMetric']((0x0,metric_logger_1[a0_0x354b('0x15')])(_0x25428c));}catch(_0x132e3d){_0x311f7d[a0_0x354b('0x13')](((_0xfdc583=_0x132e3d===null||_0x132e3d===void 0x0?void 0x0:_0x132e3d['axiosException'])===null||_0xfdc583===void 0x0?void 0x0:_0xfdc583[a0_0x354b('0x10')])?(0x0,metric_logger_1[a0_0x354b('0x15')])(_0x132e3d[a0_0x354b('0x6')][a0_0x354b('0x10')]):metric_logger_1[a0_0x354b('0xf')]);output[a0_0x354b('0x18')]({'title':_0x132e3d[a0_0x354b('0x8')]});process[a0_0x354b('0x12')](0x1);}});}[a0_0x354b('0xd')](_0x5eb01c){var _0x4622d7;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x424585=(0x0,metric_logger_1['createMetricRecorder'])(a0_0x354b('0x3'));try{const _0x146426=yield(0x0,axios_1[a0_0x354b('0x11')])(()=>this[a0_0x354b('0x14')][a0_0x354b('0x0')](a0_0x354b('0x19'),{'runGroup':_0x5eb01c}));_0x424585[a0_0x354b('0x13')]((0x0,metric_logger_1[a0_0x354b('0x15')])(_0x146426));}catch(_0x5a1af0){_0x424585['recordMetric'](((_0x4622d7=_0x5a1af0===null||_0x5a1af0===void 0x0?void 0x0:_0x5a1af0[a0_0x354b('0x6')])===null||_0x4622d7===void 0x0?void 0x0:_0x4622d7[a0_0x354b('0x10')])?(0x0,metric_logger_1['mapRespToPerfEntry'])(_0x5a1af0[a0_0x354b('0x6')][a0_0x354b('0x10')]):metric_logger_1[a0_0x354b('0xf')]);output[a0_0x354b('0x18')]({'title':_0x5a1af0[a0_0x354b('0x8')]});process[a0_0x354b('0x12')](0x1);}});}}exports[a0_0x354b('0x4')]=RunGroupApi;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RunGroupApi = void 0;
const axios_1 = require("../../utilities/axios");
const metric_logger_1 = require("../../utilities/metric-logger");
const { output } = require('../../utilities/nx-imports');
class RunGroupApi {
constructor(options) {
this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
}
createRunGroup(branch, runGroup) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const recorder = (0, metric_logger_1.createMetricRecorder)('createRunGroup');
try {
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/create-run-group', {
branch: branch,
runGroup: runGroup,
}));
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
}
catch (e) {
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
output.error({
title: e.message,
});
process.exit(1);
}
});
}
completeRunGroup(runGroup) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const recorder = (0, metric_logger_1.createMetricRecorder)('createRunGroup');
try {
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
runGroup: runGroup,
}));
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
}
catch (e) {
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
output.error({
title: e.message,
});
process.exit(1);
}
});
}
}
exports.RunGroupApi = RunGroupApi;
//# sourceMappingURL=run-group.api.js.map

5

lib/core/file-storage/file-storage.d.ts
import { E2EEncryption } from './e2e-encryption';
import { ErrorReporterApi } from '../api/error-reporter.api';
export declare class FileStorage {
private readonly encryption;
constructor(encryption: E2EEncryption);
private readonly errorReporter;
private readonly failWhenCannotDownloadArtifact;
constructor(encryption: E2EEncryption, errorReporter: ErrorReporterApi, failWhenCannotDownloadArtifact: boolean);
retrieve(hash: string, url: string, cacheDirectory: string): Promise<void>;

@@ -6,0 +9,0 @@ store(hash: string, url: string, cacheDirectory: string): Promise<any>;

@@ -23,4 +23,6 @@ "use strict";

class FileStorage {
constructor(encryption) {
constructor(encryption, errorReporter, failWhenCannotDownloadArtifact) {
this.encryption = encryption;
this.errorReporter = errorReporter;
this.failWhenCannotDownloadArtifact = failWhenCannotDownloadArtifact;
}

@@ -37,7 +39,23 @@ retrieve(hash, url, cacheDirectory) {

const commitFilePath = this.createCommitFilePath(hash, cacheDirectory);
yield this.downloadFile(url, tgz, commitFilePath);
this.createCommitFile(commitFilePath);
if (environment_1.VERBOSE_LOGGING) {
output.note({ title: `Nx Cloud: Downloaded ${hash}` });
try {
yield this.downloadFile(url, tgz, commitFilePath);
this.createCommitFile(commitFilePath);
if (environment_1.VERBOSE_LOGGING) {
output.note({ title: `Nx Cloud: Downloaded ${hash}` });
}
}
catch (e) {
const error = e.message || e.toString();
const errorMessage = `Failed to download or untar the cached artifacts for ${hash}. Error: ${error}`;
yield this.errorReporter.reportError(errorMessage);
if (this.failWhenCannotDownloadArtifact) {
throw e;
}
else {
output.warn({
title: errorMessage,
bodyLines: [`RETRIEVAL URL: ${url}`],
});
}
}
});

@@ -44,0 +62,0 @@ }

@@ -1,1 +0,141 @@

const a0_0x37cb=['local-cache','path','code','terminalOutputs','cache-miss','endTasks','cacheableOperations','CloudEnabledLifeCycle','cleanUpHashDetails','filter','status','scheduledTasks','runContext','slice','remote-cache','NX_CLOUD_UNLIMITED_OUTPUT','MAX_CHARACTERS_CACHED_TASK','../../../utilities/nx-imports','length','local-cache-kept-existing','endTime','params','obfuscate','find','statuses','join','cacheDirectory','../../../utilities/environment','keys','taskId','updateStartedTask','MAX_CHARACTERS_SUCCESSFUL_TASK','endTask','readTerminalOutputFile','TRUNCATED\x0a\x0a','MAX_CHARACTERS_FAILED_TASK','readFileSync','terminalOutput','tasks','scheduleTask','cacheStatus','hash','npm:','outputObfuscator','startTask','target','toString','skipNxCache','getTerminalOutput','defineProperty','push','collectTerminalOutput','node_modules','.cache','startsWith','toISOString','implicitDeps','local-cache-hit','configuration'];(function(_0x3e3c04,_0x37cb91){const _0x273adf=function(_0x106c2f){while(--_0x106c2f){_0x3e3c04['push'](_0x3e3c04['shift']());}};_0x273adf(++_0x37cb91);}(a0_0x37cb,0x169));const a0_0x273a=function(_0x3e3c04,_0x37cb91){_0x3e3c04=_0x3e3c04-0x0;let _0x273adf=a0_0x37cb[_0x3e3c04];return _0x273adf;};'use strict';Object[a0_0x273a('0x2a')](exports,'__esModule',{'value':!![]});exports[a0_0x273a('0x0')]=void 0x0;const path=require(a0_0x273a('0x35'));const path_1=require('path');const fs_1=require('fs');const environment_1=require(a0_0x273a('0x14'));const {workspaceRoot,unparse}=require(a0_0x273a('0xa'));class CloudEnabledLifeCycle{constructor(_0x5bb8d8,_0xf22322,_0xeca057,_0x4beeb7,_0x8bfcc0,_0x497312,_0xc31bb3){this['runContext']=_0x5bb8d8;this[a0_0x273a('0x13')]=_0xf22322;this[a0_0x273a('0x28')]=_0xeca057;this[a0_0x273a('0x2c')]=_0x4beeb7;this[a0_0x273a('0x3a')]=_0x8bfcc0;this['outputObfuscator']=_0x497312;this['tasks']=_0xc31bb3;}[a0_0x273a('0x20')](_0x9550e1){this['runContext'][a0_0x273a('0x4')][a0_0x273a('0x2b')](_0x9550e1);}[a0_0x273a('0x25')](_0x4719f1){const _0x4ba68d=Object['assign']({},_0x4719f1['overrides']||{});if(_0x4719f1[a0_0x273a('0x26')]['configuration']){_0x4ba68d[a0_0x273a('0x33')]=_0x4719f1[a0_0x273a('0x26')]['configuration'];}this['tasks'][a0_0x273a('0x2b')]({'taskId':_0x4719f1['id'],'startTime':new Date()[a0_0x273a('0x30')](),'target':_0x4719f1[a0_0x273a('0x26')][a0_0x273a('0x26')],'projectName':_0x4719f1[a0_0x273a('0x26')]['project'],'hash':_0x4719f1[a0_0x273a('0x22')],'hashDetails':this[a0_0x273a('0x1')](_0x4719f1['hashDetails']),'params':unparse(_0x4ba68d)[a0_0x273a('0x12')]('\x20')});}[a0_0x273a('0x19')](_0x1bed78,_0xebfa56){let _0xa64b6b;if(this[a0_0x273a('0x5')][a0_0x273a('0x11')][_0x1bed78[a0_0x273a('0x22')]]){_0xa64b6b=this[a0_0x273a('0x5')][a0_0x273a('0x11')][_0x1bed78[a0_0x273a('0x22')]];}else{if(this[a0_0x273a('0x3a')]['indexOf'](_0x1bed78[a0_0x273a('0x26')]['target'])>-0x1&&!this[a0_0x273a('0x28')]){_0xa64b6b='local-cache-hit';}else{_0xa64b6b='cache-miss';}}this[a0_0x273a('0x17')](_0x1bed78,_0xebfa56,_0xa64b6b);}[a0_0x273a('0x39')](_0x2c40ba){for(let _0x33e916 of _0x2c40ba){const _0x17c6b8=_0x33e916[a0_0x273a('0x3')]===a0_0x273a('0x7')?'remote-cache-hit':_0x33e916[a0_0x273a('0x3')]===a0_0x273a('0x34')||_0x33e916[a0_0x273a('0x3')]===a0_0x273a('0xc')?a0_0x273a('0x32'):a0_0x273a('0x38');this[a0_0x273a('0x17')](_0x33e916['task'],_0x33e916[a0_0x273a('0x36')],_0x17c6b8);}}['endCommand'](){}[a0_0x273a('0x17')](_0x465b13,_0x3f4e62,_0x27b95d){const _0x538177=this[a0_0x273a('0x1f')][a0_0x273a('0x10')](_0x959558=>_0x959558[a0_0x273a('0x16')]===_0x465b13['id']);if(!_0x538177){throw new Error('Cannot\x20find\x20task\x20'+_0x465b13['id']);}_0x538177[a0_0x273a('0xd')]=new Date()[a0_0x273a('0x30')]();_0x538177[a0_0x273a('0x3')]=_0x3f4e62;_0x538177[a0_0x273a('0xe')]=this[a0_0x273a('0x24')][a0_0x273a('0xf')](_0x538177[a0_0x273a('0xe')]);_0x538177[a0_0x273a('0x21')]=_0x27b95d;if(this[a0_0x273a('0x2c')]){_0x538177[a0_0x273a('0x1e')]=this[a0_0x273a('0x29')](_0x465b13['hash'],_0x538177[a0_0x273a('0x21')],_0x3f4e62);}}['getTerminalOutput'](_0xde8268,_0x3b6af1,_0x2418a2){let _0x555243;if(this[a0_0x273a('0x13')]){if(this[a0_0x273a('0x13')][a0_0x273a('0x2f')]('./')){_0x555243=(0x0,path_1[a0_0x273a('0x12')])(workspaceRoot,this[a0_0x273a('0x13')]);}else{_0x555243=this['cacheDirectory'];}}else{_0x555243=(0x0,path_1[a0_0x273a('0x12')])(workspaceRoot,a0_0x273a('0x2d'),a0_0x273a('0x2e'),'nx');}try{const _0x3eece4=this[a0_0x273a('0x1a')](_0x555243,_0xde8268);const _0x46ac63=this[a0_0x273a('0x24')][a0_0x273a('0xf')](_0x3eece4);if(environment_1[a0_0x273a('0x8')])return _0x46ac63;const _0x4022de=_0x3b6af1===a0_0x273a('0x38')?_0x2418a2===0x0?CloudEnabledLifeCycle[a0_0x273a('0x18')]:CloudEnabledLifeCycle[a0_0x273a('0x1c')]:CloudEnabledLifeCycle[a0_0x273a('0x9')];return _0x46ac63['length']>_0x4022de?a0_0x273a('0x1b')+_0x46ac63[a0_0x273a('0x6')](_0x46ac63[a0_0x273a('0xb')]-_0x4022de):_0x46ac63;}catch(_0x5ed29c){return'';}}[a0_0x273a('0x1')](_0xe298db){const _0x17941b={};Object[a0_0x273a('0x15')](_0xe298db['nodes'])[a0_0x273a('0x2')](_0x476ebf=>!_0x476ebf[a0_0x273a('0x2f')](a0_0x273a('0x23')))['forEach'](_0x21e62b=>{_0x17941b[_0x21e62b]=_0xe298db['nodes'][_0x21e62b];});return{'nodes':_0x17941b,'runtime':_0xe298db['runtime'],'implicitDeps':_0xe298db[a0_0x273a('0x31')]};}['readTerminalOutputFile'](_0x2d9ce8,_0x2ee5f0){try{return(0x0,fs_1[a0_0x273a('0x1d')])(path[a0_0x273a('0x12')](_0x2d9ce8,a0_0x273a('0x37'),_0x2ee5f0))[a0_0x273a('0x27')]();}catch(_0x2f0cc3){try{return(0x0,fs_1[a0_0x273a('0x1d')])(path['join'](_0x2d9ce8,_0x2ee5f0,a0_0x273a('0x1e')))['toString']();}catch(_0x42ef3a){return'';}}}}exports[a0_0x273a('0x0')]=CloudEnabledLifeCycle;CloudEnabledLifeCycle['MAX_CHARACTERS_FAILED_TASK']=0x30d40;CloudEnabledLifeCycle[a0_0x273a('0x18')]=0x4e20;CloudEnabledLifeCycle['MAX_CHARACTERS_CACHED_TASK']=0x4e20;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CloudEnabledLifeCycle = void 0;
const path = require("path");
const path_1 = require("path");
const fs_1 = require("fs");
const environment_1 = require("../../../utilities/environment");
const { workspaceRoot, unparse } = require('../../../utilities/nx-imports');
class CloudEnabledLifeCycle {
constructor(runContext, cacheDirectory, skipNxCache, collectTerminalOutput, cacheableOperations, outputObfuscator, tasks) {
this.runContext = runContext;
this.cacheDirectory = cacheDirectory;
this.skipNxCache = skipNxCache;
this.collectTerminalOutput = collectTerminalOutput;
this.cacheableOperations = cacheableOperations;
this.outputObfuscator = outputObfuscator;
this.tasks = tasks;
}
scheduleTask(task) {
this.runContext.scheduledTasks.push(task);
}
startTask(task) {
const overrides = Object.assign({}, (task.overrides || {}));
if (task.target.configuration) {
overrides['configuration'] = task.target.configuration;
}
this.tasks.push({
taskId: task.id,
startTime: new Date().toISOString(),
target: task.target.target,
projectName: task.target.project,
hash: task.hash,
hashDetails: this.cleanUpHashDetails(task.hashDetails),
params: unparse(overrides).join(' '),
});
}
// Used for older version for Nx. Remove in Dec 2022
endTask(task, code) {
let cacheStatus;
if (this.runContext.statuses[task.hash]) {
cacheStatus = this.runContext.statuses[task.hash];
}
else {
if (this.cacheableOperations.indexOf(task.target.target) > -1 &&
!this.skipNxCache) {
cacheStatus = 'local-cache-hit';
}
else {
cacheStatus = 'cache-miss';
}
}
this.updateStartedTask(task, code, cacheStatus);
}
endTasks(tasks) {
for (let t of tasks) {
const status = t.status === 'remote-cache'
? 'remote-cache-hit'
: t.status === 'local-cache' ||
t.status === 'local-cache-kept-existing'
? 'local-cache-hit'
: 'cache-miss';
this.updateStartedTask(t.task, t.code, status);
}
}
endCommand() { }
updateStartedTask(task, code, cacheStatus) {
const startedTask = this.tasks.find((t) => t.taskId === task.id);
if (!startedTask) {
throw new Error(`Cannot find task ${task.id}`);
}
startedTask.endTime = new Date().toISOString();
startedTask.status = code;
startedTask.params = this.outputObfuscator.obfuscate(startedTask.params);
startedTask.cacheStatus = cacheStatus;
if (this.collectTerminalOutput) {
startedTask.terminalOutput = this.getTerminalOutput(task.hash, startedTask.cacheStatus, code);
}
}
getTerminalOutput(hash, cacheStatus, code) {
let dir;
if (this.cacheDirectory) {
if (this.cacheDirectory.startsWith('./')) {
dir = (0, path_1.join)(workspaceRoot, this.cacheDirectory);
}
else {
dir = this.cacheDirectory;
}
}
else {
dir = (0, path_1.join)(workspaceRoot, 'node_modules', '.cache', 'nx');
}
try {
const taskOutput = this.readTerminalOutputFile(dir, hash);
const taskOutputSanitized = this.outputObfuscator.obfuscate(taskOutput);
if (environment_1.NX_CLOUD_UNLIMITED_OUTPUT)
return taskOutputSanitized;
const maxCharacters = cacheStatus === 'cache-miss'
? code === 0
? CloudEnabledLifeCycle.MAX_CHARACTERS_SUCCESSFUL_TASK
: CloudEnabledLifeCycle.MAX_CHARACTERS_FAILED_TASK
: CloudEnabledLifeCycle.MAX_CHARACTERS_CACHED_TASK;
return taskOutputSanitized.length > maxCharacters
? `TRUNCATED\n\n${taskOutputSanitized.slice(taskOutputSanitized.length - maxCharacters)}`
: taskOutputSanitized;
}
catch (e) {
return '';
}
}
cleanUpHashDetails(hashDetails) {
const nodes = {};
Object.keys(hashDetails.nodes)
.filter((k) => !k.startsWith('npm:'))
.forEach((k) => {
nodes[k] = hashDetails.nodes[k];
});
return {
nodes,
runtime: hashDetails.runtime,
implicitDeps: hashDetails.implicitDeps,
};
}
readTerminalOutputFile(dir, hash) {
try {
return (0, fs_1.readFileSync)(path.join(dir, 'terminalOutputs', hash)).toString();
}
catch (_a) {
try {
return (0, fs_1.readFileSync)(path.join(dir, hash, 'terminalOutput')).toString();
}
catch (_b) {
return '';
}
}
}
}
exports.CloudEnabledLifeCycle = CloudEnabledLifeCycle;
CloudEnabledLifeCycle.MAX_CHARACTERS_FAILED_TASK = 200000;
CloudEnabledLifeCycle.MAX_CHARACTERS_SUCCESSFUL_TASK = 20000;
CloudEnabledLifeCycle.MAX_CHARACTERS_CACHED_TASK = 20000;
//# sourceMappingURL=cloud-enabled-life-cycle.js.map

@@ -1,1 +0,169 @@

const a1_0x133c=['skipNxCache','getRunGroup','subscribe','requests','tasks-hashes-','error','../../file-storage/e2e-encryption','exit','done','../../terminal-output/output-obfuscator','map','defineProperty','../../../utilities/nx-imports','extractGitSha','encryptionKey','../../file-storage/file-storage','then','join','next','DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE','maskedProperties','getMachineInfo','../../../utilities/metric-logger','assign','throw','CloudRemoteCache','catch','env','ENCRYPTION_KEY','filter','../../terminal-output/end-of-run-message','complete','./node_modules/.cache/nx','forEach','toISOString','taskId','value','./cloud-run.api','path','parseCommand','OutputObfuscator','anyErrors','submitRunMetrics','Executed\x20tasks\x20with\x20hashes:\x20','cacheableOperations','Agent\x20wasn\x27t\x20able\x20to\x20store\x20artifacts','apply','E2EEncryption','waitForStoreRequestsToComplete','scan','NX_CLOUD_DISTRIBUTED_EXECUTION_ID','AGENT_RUNNING_IN_DISTRIBUTED_EXECUTION','getBranch','cacheDirectory','../../../utilities/environment','CloudEnabledLifeCycle','stringify','__esModule','obfuscate','./cloud-remote-cache','writeFileSync','Agent\x20wasn\x27t\x20able\x20to\x20record\x20its\x20run','__awaiter','cloudEnabledTasksRunner','note','printMessages','lifeCycle','CloudRunApi','MessageReporter','hash','./cloud-enabled-life-cycle'];(function(_0x779b6d,_0x133c46){const _0x2f3996=function(_0x367883){while(--_0x367883){_0x779b6d['push'](_0x779b6d['shift']());}};_0x2f3996(++_0x133c46);}(a1_0x133c,0x83));const a1_0x2f39=function(_0x779b6d,_0x133c46){_0x779b6d=_0x779b6d-0x0;let _0x2f3996=a1_0x133c[_0x779b6d];return _0x2f3996;};'use strict';var __awaiter=this&&this[a1_0x2f39('0x2')]||function(_0x5925f2,_0x5f284e,_0x5ae97b,_0x23211c){function _0x156500(_0x4916af){return _0x4916af instanceof _0x5ae97b?_0x4916af:new _0x5ae97b(function(_0x195980){_0x195980(_0x4916af);});}return new(_0x5ae97b||(_0x5ae97b=Promise))(function(_0x232faf,_0x1f6f40){function _0x23114c(_0x518e35){try{_0xea027d(_0x23211c['next'](_0x518e35));}catch(_0x348e94){_0x1f6f40(_0x348e94);}}function _0x845049(_0x27d322){try{_0xea027d(_0x23211c[a1_0x2f39('0x23')](_0x27d322));}catch(_0xdf17a1){_0x1f6f40(_0xdf17a1);}}function _0xea027d(_0x135ce8){_0x135ce8[a1_0x2f39('0x13')]?_0x232faf(_0x135ce8[a1_0x2f39('0x2f')]):_0x156500(_0x135ce8['value'])[a1_0x2f39('0x1b')](_0x23114c,_0x845049);}_0xea027d((_0x23211c=_0x23211c[a1_0x2f39('0x39')](_0x5925f2,_0x5f284e||[]))[a1_0x2f39('0x1d')]());});};Object[a1_0x2f39('0x16')](exports,a1_0x2f39('0x44'),{'value':!![]});exports[a1_0x2f39('0x3')]=void 0x0;const message_reporter_1=require('../../terminal-output/message-reporter');const end_of_run_message_1=require(a1_0x2f39('0x29'));const output_obfuscator_1=require(a1_0x2f39('0x14'));const cloud_enabled_life_cycle_1=require(a1_0x2f39('0xa'));const file_storage_1=require(a1_0x2f39('0x1a'));const e2e_encryption_1=require(a1_0x2f39('0x11'));const environment_1=require(a1_0x2f39('0x41'));const cloud_remote_cache_1=require(a1_0x2f39('0x46'));const cloud_run_api_1=require(a1_0x2f39('0x30'));const fs_1=require('fs');const path=require(a1_0x2f39('0x31'));const metric_logger_1=require(a1_0x2f39('0x21'));const {tasksRunner,output}=require(a1_0x2f39('0x17'));function createApi(_0x4ee2d8,_0x447779,_0x830492){const _0x5a5dfc=(0x0,environment_1[a1_0x2f39('0x20')])(_0x447779);return new cloud_run_api_1[(a1_0x2f39('0x7'))](_0x4ee2d8,_0x830492,_0x447779,_0x5a5dfc);}function storeTaskHashes(_0x32f7b4,_0x306dae,_0x45d79c){const _0x1b2f4d=JSON[a1_0x2f39('0x43')](_0x32f7b4[a1_0x2f39('0x15')](_0xc98a3d=>({'taskId':_0xc98a3d[a1_0x2f39('0x2e')],'hash':_0xc98a3d[a1_0x2f39('0x9')]})));if(environment_1['VERBOSE_LOGGING']){output[a1_0x2f39('0x4')]({'title':a1_0x2f39('0x36')+_0x1b2f4d});}(0x0,fs_1[a1_0x2f39('0x0')])(path[a1_0x2f39('0x1c')](_0x306dae,a1_0x2f39('0xf')+_0x45d79c),_0x1b2f4d);}function onComplete(_0x5d71af,_0x2c59d1,_0x176acb,_0x2ab55,_0x4c1c7e,_0xe7cb0e,_0x125006,_0x57275a,_0x46f589,_0x22561c,_0x247454){return __awaiter(this,void 0x0,void 0x0,function*(){const _0xf1171a=new Date()[a1_0x2f39('0x2d')]();if(environment_1['AGENT_RUNNING_IN_DISTRIBUTED_EXECUTION']){storeTaskHashes(_0x46f589,_0x2c59d1[a1_0x2f39('0x40')]||a1_0x2f39('0x2b'),environment_1[a1_0x2f39('0x3d')]);}const _0x18fa0b=(0x0,environment_1[a1_0x2f39('0x3f')])();const _0x8f7037=yield Promise['all']([_0x176acb[a1_0x2f39('0x3b')](),_0x2ab55['endRun']({'command':_0x4c1c7e[a1_0x2f39('0x45')]((0x0,environment_1[a1_0x2f39('0x32')])()),'startTime':_0xe7cb0e,'endTime':_0xf1171a,'distributedExecutionId':environment_1['NX_CLOUD_DISTRIBUTED_EXECUTION_ID'],'branch':_0x18fa0b,'scan':!![],'runGroup':(0x0,environment_1[a1_0x2f39('0xc')])(),'sha':_0x18fa0b?(0x0,environment_1[a1_0x2f39('0x18')])():undefined,'inner':_0x247454},_0x46f589)]);if(_0x22561c){setTimeout(()=>{_0x125006[a1_0x2f39('0x5')]();if(!_0x125006[a1_0x2f39('0x34')]&&!_0x247454){_0x57275a['printCacheHitsMessage']();}},0x0);}else{_0x125006['printMessages']();if(!_0x125006[a1_0x2f39('0x34')]&&!_0x247454){_0x57275a['printCacheHitsMessage']();}}if(environment_1[a1_0x2f39('0x3e')]){if(!_0x8f7037[0x0]){output[a1_0x2f39('0x10')]({'title':a1_0x2f39('0x38')});_0x125006[a1_0x2f39('0x5')]();process[a1_0x2f39('0x12')](environment_1['DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE']);}if(!_0x8f7037[0x1]){output['error']({'title':a1_0x2f39('0x1')});_0x125006[a1_0x2f39('0x5')]();process['exit'](environment_1[a1_0x2f39('0x1e')]);}}yield(0x0,metric_logger_1[a1_0x2f39('0x35')])(_0x2c59d1);});}function createLifeCycle(_0x7f6661,_0x2ab787,_0x64aef0,_0x3da38e){const _0x387d93=new cloud_enabled_life_cycle_1[(a1_0x2f39('0x42'))](_0x7f6661,_0x2ab787[a1_0x2f39('0x40')],!!_0x2ab787[a1_0x2f39('0xb')],_0x2ab787['scan']===undefined?!![]:_0x2ab787[a1_0x2f39('0x3c')],_0x2ab787[a1_0x2f39('0x37')]||[],_0x64aef0,_0x3da38e);try{const {CompositeLifeCycle}=require(a1_0x2f39('0x17'));if(!CompositeLifeCycle)return _0x387d93;return new CompositeLifeCycle([_0x2ab787[a1_0x2f39('0x6')],_0x387d93]);}catch(_0x192032){return _0x387d93;}}function cloudEnabledTasksRunner(_0x4f5306,_0x36f183,_0x11b9e0,_0xb8ca34=![]){const _0x8667b6={'statuses':{},'scheduledTasks':[],'requests':{},'allTasks':_0x4f5306};const _0x3cb205=_0x36f183[a1_0x2f39('0x6')]===undefined;const _0xd3c713=[];const _0x31a7dd=new message_reporter_1[(a1_0x2f39('0x8'))](_0x36f183);const _0x30e6af=createApi(_0x31a7dd,_0x36f183,_0x8667b6);const _0x3957c7=new end_of_run_message_1['EndOfRunMessage'](_0x8667b6,_0xd3c713);const _0xd52469=new output_obfuscator_1[(a1_0x2f39('0x33'))](_0x36f183[a1_0x2f39('0x1f')]);const _0x119b30=_0x4f5306[a1_0x2f39('0x15')](_0x532704=>_0x532704[a1_0x2f39('0x9')])[a1_0x2f39('0x28')](_0x3aa7b7=>!!_0x3aa7b7);const _0x4c1fd0=_0x30e6af['startRun'](environment_1[a1_0x2f39('0x3d')],_0x119b30);_0x119b30[a1_0x2f39('0x2c')](_0x156bdf=>{_0x8667b6[a1_0x2f39('0xe')][_0x156bdf]=_0x4c1fd0;});const _0x4df50e=new Date()[a1_0x2f39('0x2d')]();const _0x42149c=createLifeCycle(_0x8667b6,_0x36f183,_0xd52469,_0xd3c713);const _0x2e72e3=new e2e_encryption_1[(a1_0x2f39('0x3a'))](environment_1[a1_0x2f39('0x27')]||_0x36f183[a1_0x2f39('0x19')]);const _0xe3b86=new file_storage_1['FileStorage'](_0x2e72e3);const _0x42bc2d=new cloud_remote_cache_1[(a1_0x2f39('0x24'))](_0x31a7dd,_0x30e6af,_0x8667b6,_0xe3b86);delete process[a1_0x2f39('0x26')][a1_0x2f39('0x3d')];const _0x69823a=tasksRunner(_0x4f5306,Object[a1_0x2f39('0x22')](Object[a1_0x2f39('0x22')]({},_0x36f183),{'remoteCache':_0x42bc2d,'lifeCycle':_0x42149c}),_0x11b9e0);if(_0x69823a[a1_0x2f39('0xd')]){const {Subject}=require('rxjs/internal/Subject');const _0x1528f2=new Subject();_0x69823a[a1_0x2f39('0xd')]({'next':_0x193b1c=>_0x1528f2[a1_0x2f39('0x1d')](_0x193b1c),'error':_0x239fc1=>_0x1528f2[a1_0x2f39('0x10')](_0x239fc1),'complete':()=>__awaiter(this,void 0x0,void 0x0,function*(){yield onComplete(_0x42149c,_0x36f183,_0x42bc2d,_0x30e6af,_0xd52469,_0x4df50e,_0x31a7dd,_0x3957c7,_0xd3c713,_0x3cb205,_0xb8ca34);_0x1528f2[a1_0x2f39('0x2a')]();})});return _0x1528f2;}else{return _0x69823a['then'](_0x3d1910=>__awaiter(this,void 0x0,void 0x0,function*(){yield onComplete(_0x42149c,_0x36f183,_0x42bc2d,_0x30e6af,_0xd52469,_0x4df50e,_0x31a7dd,_0x3957c7,_0xd3c713,_0x3cb205,_0xb8ca34);return _0x3d1910;}))[a1_0x2f39('0x25')](_0x423827=>__awaiter(this,void 0x0,void 0x0,function*(){yield onComplete(_0x42149c,_0x36f183,_0x42bc2d,_0x30e6af,_0xd52469,_0x4df50e,_0x31a7dd,_0x3957c7,_0xd3c713,_0x3cb205,_0xb8ca34);throw _0x423827;}));}}exports['cloudEnabledTasksRunner']=cloudEnabledTasksRunner;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.cloudEnabledTasksRunner = void 0;
const message_reporter_1 = require("../../terminal-output/message-reporter");
const end_of_run_message_1 = require("../../terminal-output/end-of-run-message");
const output_obfuscator_1 = require("../../terminal-output/output-obfuscator");
const cloud_enabled_life_cycle_1 = require("./cloud-enabled-life-cycle");
const file_storage_1 = require("../../file-storage/file-storage");
const e2e_encryption_1 = require("../../file-storage/e2e-encryption");
const environment_1 = require("../../../utilities/environment");
const cloud_remote_cache_1 = require("./cloud-remote-cache");
const cloud_run_api_1 = require("./cloud-run.api");
const fs_1 = require("fs");
const path = require("path");
const metric_logger_1 = require("../../../utilities/metric-logger");
const error_reporter_api_1 = require("../../api/error-reporter.api");
const { tasksRunner, output } = require('../../../utilities/nx-imports');
function createApi(errors, options, runContext) {
const machineInfo = (0, environment_1.getMachineInfo)(options);
return new cloud_run_api_1.CloudRunApi(errors, runContext, options, machineInfo);
}
function storeTaskHashes(taskExecutions, directory, distributedExecutionId) {
const hashes = JSON.stringify(taskExecutions.map((t) => ({
taskId: t.taskId,
hash: t.hash,
})));
if (environment_1.VERBOSE_LOGGING) {
output.note({
title: `Executed tasks with hashes: ${hashes}`,
});
}
(0, fs_1.writeFileSync)(path.join(directory, `tasks-hashes-${distributedExecutionId}`), hashes);
}
function onComplete(lifeCycle, options, remoteCache, api, outputObfuscator, runStartTime, messages, endOfRunMessage, taskExecutions, versionOfNxBefore133, inner) {
return __awaiter(this, void 0, void 0, function* () {
const runEndTime = new Date().toISOString();
if (environment_1.AGENT_RUNNING_IN_DISTRIBUTED_EXECUTION) {
storeTaskHashes(taskExecutions, options.cacheDirectory || './node_modules/.cache/nx', environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_ID);
}
const branch = (0, environment_1.getBranch)();
const endRequest = yield Promise.all([
remoteCache.waitForStoreRequestsToComplete(),
api.endRun({
command: outputObfuscator.obfuscate((0, environment_1.parseCommand)()),
startTime: runStartTime,
endTime: runEndTime,
distributedExecutionId: environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_ID,
branch: branch,
scan: true,
runGroup: (0, environment_1.getRunGroup)(),
// only set sha if branch is set because we invoke a separate process,
// which adds a few millis
sha: branch ? (0, environment_1.extractGitSha)() : undefined,
inner: inner,
}, taskExecutions),
]);
// this workaround is required because prior to Nx 13.3 we printed
// the end message after the runner completes, so we need to wait for the
// message to appear in the right place
if (versionOfNxBefore133) {
setTimeout(() => {
messages.printMessages();
if (!messages.anyErrors && !inner) {
endOfRunMessage.printCacheHitsMessage();
}
}, 0);
}
else {
messages.printMessages();
if (!messages.anyErrors && !inner) {
endOfRunMessage.printCacheHitsMessage();
}
}
if (environment_1.AGENT_RUNNING_IN_DISTRIBUTED_EXECUTION) {
if (!endRequest[0]) {
output.error({
title: `Agent wasn't able to store artifacts`,
});
messages.printMessages();
process.exit(environment_1.DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE);
}
if (!endRequest[1]) {
output.error({
title: `Agent wasn't able to record its run`,
});
messages.printMessages();
process.exit(environment_1.DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE);
}
}
yield (0, metric_logger_1.submitRunMetrics)(options);
});
}
function createLifeCycle(runContext, options, outputObfuscator, tasks) {
const cloudEnabledLifeCycle = new cloud_enabled_life_cycle_1.CloudEnabledLifeCycle(runContext, options.cacheDirectory, !!options.skipNxCache, options.scan === undefined ? true : options.scan, options.cacheableOperations || [], outputObfuscator, tasks);
try {
const { CompositeLifeCycle } = require('../../../utilities/nx-imports');
if (!CompositeLifeCycle)
return cloudEnabledLifeCycle;
return new CompositeLifeCycle([options.lifeCycle, cloudEnabledLifeCycle]);
}
catch (e) {
return cloudEnabledLifeCycle;
}
}
function cloudEnabledTasksRunner(tasks, options, context, inner = false) {
const runContext = {
statuses: {},
scheduledTasks: [],
requests: {},
allTasks: tasks,
};
const versionOfNxBefore133 = options.lifeCycle === undefined;
const taskExecutions = [];
const messages = new message_reporter_1.MessageReporter(options);
const api = createApi(messages, options, runContext);
const endOfRunMessage = new end_of_run_message_1.EndOfRunMessage(runContext, taskExecutions);
const outputObfuscator = new output_obfuscator_1.OutputObfuscator(options.maskedProperties);
const hashes = tasks.map((t) => t.hash).filter((h) => !!h);
const startRunRequest = api.startRun(environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_ID, hashes);
hashes.forEach((hash) => {
runContext.requests[hash] = startRunRequest;
});
const runStartTime = new Date().toISOString();
const lifeCycle = createLifeCycle(runContext, options, outputObfuscator, taskExecutions);
const encryption = new e2e_encryption_1.E2EEncryption(environment_1.ENCRYPTION_KEY || options.encryptionKey);
const errorApi = new error_reporter_api_1.ErrorReporterApi(options);
const fileStorage = new file_storage_1.FileStorage(encryption, errorApi, false);
const remoteCache = new cloud_remote_cache_1.CloudRemoteCache(messages, api, runContext, fileStorage);
// have to reset it so we don't capture inner tasks
delete process.env.NX_CLOUD_DISTRIBUTED_EXECUTION_ID;
const res = tasksRunner(tasks, Object.assign(Object.assign({}, options), { remoteCache, lifeCycle }), context);
// observable -> legacy
if (res.subscribe) {
const { Subject } = require('rxjs/internal/Subject');
const wrappedRes = new Subject();
res.subscribe({
next: (value) => wrappedRes.next(value),
error: (err) => wrappedRes.error(err),
complete: () => __awaiter(this, void 0, void 0, function* () {
yield onComplete(lifeCycle, options, remoteCache, api, outputObfuscator, runStartTime, messages, endOfRunMessage, taskExecutions, versionOfNxBefore133, inner);
wrappedRes.complete();
}),
});
return wrappedRes;
// promise
}
else {
return res
.then((r) => __awaiter(this, void 0, void 0, function* () {
yield onComplete(lifeCycle, options, remoteCache, api, outputObfuscator, runStartTime, messages, endOfRunMessage, taskExecutions, versionOfNxBefore133, inner);
return r;
}))
.catch((e) => __awaiter(this, void 0, void 0, function* () {
yield onComplete(lifeCycle, options, remoteCache, api, outputObfuscator, runStartTime, messages, endOfRunMessage, taskExecutions, versionOfNxBefore133, inner);
throw e;
}));
}
}
exports.cloudEnabledTasksRunner = cloudEnabledTasksRunner;
//# sourceMappingURL=cloud-enabled.runner.js.map

@@ -1,1 +0,113 @@

const a2_0xbcfc=['NX_CLOUD_DISTRIBUTED_EXECUTION_ID','storeRequests','../../../utilities/nx-imports','apply','response','retrieve','remote-cache-hit','cacheError','then','scheduledTasks','cache-miss','__awaiter','CloudRemoteCache','put','__esModule','messages','runContext','requests','extractErrorMessage','fileStorage','next','get','note','.\x20Read\x20only\x20token\x20is\x20used.','resolve','store','forEach','api','done','hashUrls','throw','Nx\x20Cloud:\x20Skipping\x20storing\x20','value','defineProperty','push','VERBOSE_LOGGING','statuses','waitForStoreRequestsToComplete','storage','Nx\x20Cloud:\x20Cache\x20miss\x20','axiosException','hash'];(function(_0x4e123c,_0xbcfcaf){const _0x28ce01=function(_0x157de4){while(--_0x157de4){_0x4e123c['push'](_0x4e123c['shift']());}};_0x28ce01(++_0xbcfcaf);}(a2_0xbcfc,0x1ac));const a2_0x28ce=function(_0x4e123c,_0xbcfcaf){_0x4e123c=_0x4e123c-0x0;let _0x28ce01=a2_0xbcfc[_0x4e123c];return _0x28ce01;};'use strict';var __awaiter=this&&this[a2_0x28ce('0x3')]||function(_0xb83e21,_0x1bde6d,_0x4b9dc8,_0x4a4f76){function _0x43196a(_0x56c806){return _0x56c806 instanceof _0x4b9dc8?_0x56c806:new _0x4b9dc8(function(_0x4efa82){_0x4efa82(_0x56c806);});}return new(_0x4b9dc8||(_0x4b9dc8=Promise))(function(_0x40ee90,_0x268ee8){function _0x327fc1(_0x4c7dce){try{_0x530133(_0x4a4f76['next'](_0x4c7dce));}catch(_0x3d4daf){_0x268ee8(_0x3d4daf);}}function _0x29ee65(_0x555c18){try{_0x530133(_0x4a4f76[a2_0x28ce('0x16')](_0x555c18));}catch(_0x2e9f66){_0x268ee8(_0x2e9f66);}}function _0x530133(_0x509eb3){_0x509eb3[a2_0x28ce('0x14')]?_0x40ee90(_0x509eb3[a2_0x28ce('0x18')]):_0x43196a(_0x509eb3['value'])[a2_0x28ce('0x0')](_0x327fc1,_0x29ee65);}_0x530133((_0x4a4f76=_0x4a4f76[a2_0x28ce('0x25')](_0xb83e21,_0x1bde6d||[]))[a2_0x28ce('0xc')]());});};Object[a2_0x28ce('0x19')](exports,a2_0x28ce('0x6'),{'value':!![]});exports['CloudRemoteCache']=void 0x0;const environment_1=require('../../../utilities/environment');const {output}=require(a2_0x28ce('0x24'));class CloudRemoteCache{constructor(_0x1174f3,_0x4fcd0e,_0x29b00c,_0x57c615){this[a2_0x28ce('0x7')]=_0x1174f3;this[a2_0x28ce('0x13')]=_0x4fcd0e;this[a2_0x28ce('0x8')]=_0x29b00c;this[a2_0x28ce('0xb')]=_0x57c615;this[a2_0x28ce('0x23')]=[];}[a2_0x28ce('0x27')](_0x1ef2c5,_0xdc299){var _0xcd56d7;return __awaiter(this,void 0x0,void 0x0,function*(){if(this['messages'][a2_0x28ce('0x29')])return![];const _0x1c12a2=yield this[a2_0x28ce('0x15')](_0x1ef2c5);if(!_0x1c12a2||!_0x1c12a2[a2_0x28ce('0xd')]){if(environment_1[a2_0x28ce('0x1b')]){output['note']({'title':a2_0x28ce('0x1f')+_0x1ef2c5+'.'});}this[a2_0x28ce('0x8')][a2_0x28ce('0x1c')][_0x1ef2c5]=a2_0x28ce('0x2');return![];}try{yield this[a2_0x28ce('0xb')][a2_0x28ce('0x27')](_0x1ef2c5,_0x1c12a2[a2_0x28ce('0xd')],_0xdc299);this[a2_0x28ce('0x8')][a2_0x28ce('0x1c')][_0x1ef2c5]=a2_0x28ce('0x28');return!![];}catch(_0x427d51){const _0x2d009=(_0xcd56d7=_0x427d51[a2_0x28ce('0x20')])!==null&&_0xcd56d7!==void 0x0?_0xcd56d7:_0x427d51;if(_0x2d009[a2_0x28ce('0x26')]&&_0x2d009[a2_0x28ce('0x26')]['status']===0x194){if(environment_1['VERBOSE_LOGGING']){output[a2_0x28ce('0xe')]({'title':'Nx\x20Cloud:\x20Cache\x20miss\x20'+_0x1ef2c5+'.\x20Status\x20404.'});}}else{this['messages']['cacheError']=this[a2_0x28ce('0x7')][a2_0x28ce('0xa')](_0x2d009,a2_0x28ce('0x1e'));}this['runContext'][a2_0x28ce('0x1c')][_0x1ef2c5]='cache-miss';return![];}});}[a2_0x28ce('0x11')](_0x49504b,_0x5cff9e){return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a2_0x28ce('0x7')][a2_0x28ce('0x29')])return![];const _0x2118e0=Promise[a2_0x28ce('0x10')]()[a2_0x28ce('0x0')](()=>__awaiter(this,void 0x0,void 0x0,function*(){var _0xc83782;const _0x15faaf=yield this[a2_0x28ce('0x15')](_0x49504b);if(!_0x15faaf)return![];if(!_0x15faaf[a2_0x28ce('0x5')]){if(environment_1[a2_0x28ce('0x1b')]){output[a2_0x28ce('0xe')]({'title':a2_0x28ce('0x17')+_0x49504b+a2_0x28ce('0xf')});}return!![];}try{yield this[a2_0x28ce('0xb')][a2_0x28ce('0x11')](_0x49504b,_0x15faaf[a2_0x28ce('0x5')],_0x5cff9e);return!![];}catch(_0x10ff5c){const _0x3d1a89=(_0xc83782=_0x10ff5c[a2_0x28ce('0x20')])!==null&&_0xc83782!==void 0x0?_0xc83782:_0x10ff5c;this[a2_0x28ce('0x7')][a2_0x28ce('0x29')]=this['messages'][a2_0x28ce('0xa')](_0x3d1a89,a2_0x28ce('0x1e'));return![];}}));this[a2_0x28ce('0x23')]['push'](_0x2118e0);return _0x2118e0;});}[a2_0x28ce('0x15')](_0x4b9a2e){return __awaiter(this,void 0x0,void 0x0,function*(){if(_0x4b9a2e in this[a2_0x28ce('0x8')][a2_0x28ce('0x9')]){return(yield this[a2_0x28ce('0x8')][a2_0x28ce('0x9')][_0x4b9a2e])[_0x4b9a2e];}else{const _0x5bc060=this[a2_0x28ce('0x8')][a2_0x28ce('0x1')]['filter'](_0x1b0190=>!this[a2_0x28ce('0x8')]['requests'][_0x1b0190[a2_0x28ce('0x21')]])['map'](_0x4d9359=>_0x4d9359[a2_0x28ce('0x21')]);if(_0x5bc060['indexOf'](_0x4b9a2e)===-0x1){_0x5bc060[a2_0x28ce('0x1a')](_0x4b9a2e);}const _0x13bce5=this[a2_0x28ce('0x13')]['startRun'](environment_1[a2_0x28ce('0x22')],_0x5bc060);_0x5bc060[a2_0x28ce('0x12')](_0x5cb76c=>{this['runContext'][a2_0x28ce('0x9')][_0x5cb76c]=_0x13bce5;});return(yield _0x13bce5)[_0x4b9a2e];}});}[a2_0x28ce('0x1d')](){return Promise['all'](this[a2_0x28ce('0x23')])[a2_0x28ce('0x0')](_0x508b1b=>_0x508b1b['reduce']((_0x561855,_0x3ec7a0)=>_0x561855&&_0x3ec7a0,!![]));}}exports[a2_0x28ce('0x4')]=CloudRemoteCache;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CloudRemoteCache = void 0;
const environment_1 = require("../../../utilities/environment");
const { output } = require('../../../utilities/nx-imports');
class CloudRemoteCache {
constructor(messages, api, runContext, fileStorage) {
this.messages = messages;
this.api = api;
this.runContext = runContext;
this.fileStorage = fileStorage;
this.storeRequests = [];
}
retrieve(hash, cacheDirectory) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
if (this.messages.cacheError)
return false;
const hashUrls = yield this.hashUrls(hash);
if (!hashUrls || !hashUrls.get) {
if (environment_1.VERBOSE_LOGGING) {
output.note({ title: `Nx Cloud: Cache miss ${hash}.` });
}
this.runContext.statuses[hash] = 'cache-miss';
return false;
}
try {
yield this.fileStorage.retrieve(hash, hashUrls.get, cacheDirectory);
this.runContext.statuses[hash] = 'remote-cache-hit';
return true;
}
catch (ee) {
const e = (_a = ee.axiosException) !== null && _a !== void 0 ? _a : ee;
if (e.response && e.response.status === 404) {
if (environment_1.VERBOSE_LOGGING) {
output.note({ title: `Nx Cloud: Cache miss ${hash}. Status 404.` });
}
// cache miss. print nothing
}
else {
this.messages.cacheError = this.messages.extractErrorMessage(e, 'storage');
}
this.runContext.statuses[hash] = 'cache-miss';
return false;
}
});
}
store(hash, cacheDirectory) {
return __awaiter(this, void 0, void 0, function* () {
if (this.messages.cacheError)
return false;
const res = Promise.resolve().then(() => __awaiter(this, void 0, void 0, function* () {
var _a;
const hashUrls = yield this.hashUrls(hash);
if (!hashUrls)
return false;
if (!hashUrls.put) {
if (environment_1.VERBOSE_LOGGING) {
output.note({
title: `Nx Cloud: Skipping storing ${hash}. Read only token is used.`,
});
}
return true;
}
try {
yield this.fileStorage.store(hash, hashUrls.put, cacheDirectory);
return true;
}
catch (ee) {
const e = (_a = ee.axiosException) !== null && _a !== void 0 ? _a : ee;
this.messages.cacheError = this.messages.extractErrorMessage(e, 'storage');
return false;
}
}));
this.storeRequests.push(res);
return res;
});
}
hashUrls(hash) {
return __awaiter(this, void 0, void 0, function* () {
if (hash in this.runContext.requests) {
return (yield this.runContext.requests[hash])[hash];
}
else {
const scheduledTaskHashesWithoutRequests = this.runContext.scheduledTasks
.filter((t) => !this.runContext.requests[t.hash])
.map((t) => t.hash);
if (scheduledTaskHashesWithoutRequests.indexOf(hash) === -1) {
scheduledTaskHashesWithoutRequests.push(hash);
}
const request = this.api.startRun(environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_ID, scheduledTaskHashesWithoutRequests);
scheduledTaskHashesWithoutRequests.forEach((taskHash) => {
this.runContext.requests[taskHash] = request;
});
return (yield request)[hash];
}
});
}
waitForStoreRequestsToComplete() {
return Promise.all(this.storeRequests).then((r) => r.reduce((a, b) => a && b, true));
}
}
exports.CloudRemoteCache = CloudRemoteCache;
//# sourceMappingURL=cloud-remote-cache.js.map

@@ -15,4 +15,5 @@ import { RunContext } from '../../models/run-context.model';

startRun(distributedExecutionId: string | undefined, hashes: string[]): Promise<CacheUrls>;
private createReqBody;
endRun(run: RunData, tasks: TaskExecution[]): Promise<boolean>;
private nxCloudVersion;
}

@@ -1,1 +0,166 @@

const a3_0x4ce9=['nxCloudVersion','stack','throw','zlib','slice','VERBOSE_LOGGING','api','Nx\x20Cloud:\x20Unknown\x20Error\x20Occurred','RUNNER_FAILURE_PERF_ENTRY','headers','value','then','recordMetric','Run\x20completion\x20responded\x20with\x20`undefined`.','endRun','__esModule','../../../utilities/metric-logger','assign','Invalid\x20end\x20run\x20response:\x20','../../../utilities/nx-imports','createApiAxiosInstance','__awaiter','data','runContext','post','/nx-cloud/runs/end','startRun','CloudRunApi','runUrl','package.json','mapRespToPerfEntry','readFileSync','status','urls','parse','apiError','Run\x20Details:','extractErrorMessage','getBranch','devDependencies','from','...','terminalOutput','Stack\x20Trace:','error','response','application/octet-stream','defaults','stringify','success','createMetricRecorder','gzip','apply','apiAxiosInstance','getRunGroup','axiosMultipleTries','message','note','messages','/nx-cloud/runs/start','next','string','Invalid\x20end\x20run\x20response','promisify','axiosException','util','map'];(function(_0x4f085a,_0x4ce969){const _0x51d777=function(_0x1a1430){while(--_0x1a1430){_0x4f085a['push'](_0x4f085a['shift']());}};_0x51d777(++_0x4ce969);}(a3_0x4ce9,0x1b0));const a3_0x51d7=function(_0x4f085a,_0x4ce969){_0x4f085a=_0x4f085a-0x0;let _0x51d777=a3_0x4ce9[_0x4f085a];return _0x51d777;};'use strict';var __awaiter=this&&this[a3_0x51d7('0x3a')]||function(_0x25d966,_0x12a95b,_0x126472,_0x260d0d){function _0x73fd54(_0x309aa3){return _0x309aa3 instanceof _0x126472?_0x309aa3:new _0x126472(function(_0x33ee8b){_0x33ee8b(_0x309aa3);});}return new(_0x126472||(_0x126472=Promise))(function(_0x12879b,_0x448bc3){function _0x38cf69(_0x2fe3f9){try{_0x24b72e(_0x260d0d[a3_0x51d7('0x1e')](_0x2fe3f9));}catch(_0xf7933f){_0x448bc3(_0xf7933f);}}function _0xcf5417(_0x19f941){try{_0x24b72e(_0x260d0d[a3_0x51d7('0x27')](_0x19f941));}catch(_0x283fff){_0x448bc3(_0x283fff);}}function _0x24b72e(_0x487440){_0x487440['done']?_0x12879b(_0x487440[a3_0x51d7('0x2f')]):_0x73fd54(_0x487440[a3_0x51d7('0x2f')])[a3_0x51d7('0x30')](_0x38cf69,_0xcf5417);}_0x24b72e((_0x260d0d=_0x260d0d[a3_0x51d7('0x16')](_0x25d966,_0x12a95b||[]))[a3_0x51d7('0x1e')]());});};Object['defineProperty'](exports,a3_0x51d7('0x34'),{'value':!![]});exports['CloudRunApi']=void 0x0;const axios_1=require('../../../utilities/axios');const environment_1=require('../../../utilities/environment');const fs_1=require('fs');const zlib_1=require(a3_0x51d7('0x28'));const util_1=require(a3_0x51d7('0x23'));const metric_logger_1=require(a3_0x51d7('0x35'));const {output}=require(a3_0x51d7('0x38'));class CloudRunApi{constructor(_0x231d73,_0x21ca47,_0x29b868,_0x235ecb){this[a3_0x51d7('0x1c')]=_0x231d73;this['runContext']=_0x21ca47;this['machineInfo']=_0x235ecb;this[a3_0x51d7('0x17')]=(0x0,axios_1[a3_0x51d7('0x39')])(_0x29b868);}[a3_0x51d7('0x3f')](_0x345335,_0x504067){var _0x5231d0;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x2c7107=(0x0,metric_logger_1['createMetricRecorder'])(a3_0x51d7('0x3f'));try{const _0x3de1ec={'meta':{'nxCloudVersion':this[a3_0x51d7('0x25')]()},'branch':(0x0,environment_1[a3_0x51d7('0x8')])(),'runGroup':(0x0,environment_1[a3_0x51d7('0x18')])(),'distributedExecutionId':_0x345335,'hashes':_0x504067};if(environment_1[a3_0x51d7('0x2a')]){output['note']({'title':'RunStart','bodyLines':['\x0a'+JSON['stringify'](_0x3de1ec,null,0x2)]});}const _0x2f1acd=yield(0x0,axios_1['axiosMultipleTries'])(()=>this['apiAxiosInstance'][a3_0x51d7('0x3d')](a3_0x51d7('0x1d'),_0x3de1ec));_0x2c7107[a3_0x51d7('0x31')]((0x0,metric_logger_1['mapRespToPerfEntry'])(_0x2f1acd));if(_0x2f1acd['data']&&_0x2f1acd[a3_0x51d7('0x3b')]['message']){this[a3_0x51d7('0x1c')][a3_0x51d7('0x1a')]=_0x2f1acd[a3_0x51d7('0x3b')][a3_0x51d7('0x1a')];}if(!_0x2f1acd[a3_0x51d7('0x3b')]||!_0x2f1acd['data'][a3_0x51d7('0x3')]){this['messages'][a3_0x51d7('0x5')]='Invalid\x20Nx\x20Cloud\x20response:\x20'+JSON[a3_0x51d7('0x12')](_0x2f1acd[a3_0x51d7('0x3b')]);return{};}return _0x2f1acd[a3_0x51d7('0x3b')][a3_0x51d7('0x3')];}catch(_0x501033){_0x2c7107['recordMetric'](((_0x5231d0=_0x501033===null||_0x501033===void 0x0?void 0x0:_0x501033[a3_0x51d7('0x22')])===null||_0x5231d0===void 0x0?void 0x0:_0x5231d0[a3_0x51d7('0xf')])?(0x0,metric_logger_1[a3_0x51d7('0x0')])(_0x501033[a3_0x51d7('0x22')]['response']):metric_logger_1[a3_0x51d7('0x2d')]);this[a3_0x51d7('0x1c')][a3_0x51d7('0x5')]=this['messages'][a3_0x51d7('0x7')](_0x501033,a3_0x51d7('0x2b'));return{};}});}[a3_0x51d7('0x33')](_0x2f47ea,_0x59c5f1){var _0x18b15d,_0x1e0fff;return __awaiter(this,void 0x0,void 0x0,function*(){if(this[a3_0x51d7('0x1c')]['apiError'])return![];const _0x3c2e05={'meta':{'nxCloudVersion':this[a3_0x51d7('0x25')]()},'tasks':_0x59c5f1,'run':_0x2f47ea,'machineInfo':this['machineInfo']};const _0x9a4a9c=Buffer[a3_0x51d7('0xa')](JSON[a3_0x51d7('0x12')](_0x3c2e05));const _0x435ad3=yield(0x0,util_1[a3_0x51d7('0x21')])(zlib_1['gzip'])(_0x9a4a9c);const _0x15b753=(0x0,metric_logger_1[a3_0x51d7('0x14')])(a3_0x51d7('0x33'));try{if(environment_1[a3_0x51d7('0x2a')]){const _0x234d47=_0x59c5f1[a3_0x51d7('0x24')](_0x5ec8e1=>{return Object[a3_0x51d7('0x36')](Object[a3_0x51d7('0x36')]({},_0x5ec8e1),{'terminalOutput':_0x5ec8e1[a3_0x51d7('0xc')]?_0x5ec8e1[a3_0x51d7('0xc')][a3_0x51d7('0x29')](0x0,0x14)+a3_0x51d7('0xb'):undefined});});output[a3_0x51d7('0x1b')]({'title':'RunEnd.\x20Completed\x20tasks','bodyLines':['\x0a'+JSON['stringify'](_0x234d47,null,0x2)]});}const _0x6d8c8c=yield(0x0,axios_1[a3_0x51d7('0x19')])(()=>this[a3_0x51d7('0x17')][a3_0x51d7('0x3d')](a3_0x51d7('0x3e'),_0x435ad3,{'headers':Object[a3_0x51d7('0x36')](Object['assign']({},this[a3_0x51d7('0x17')][a3_0x51d7('0x11')][a3_0x51d7('0x2e')]),{'Content-Encoding':a3_0x51d7('0x15'),'Content-Type':a3_0x51d7('0x10')})}));if(_0x6d8c8c){_0x15b753['recordMetric']((0x0,metric_logger_1[a3_0x51d7('0x0')])(_0x6d8c8c));if(_0x6d8c8c[a3_0x51d7('0x3b')]&&_0x6d8c8c[a3_0x51d7('0x3b')][a3_0x51d7('0x41')]&&_0x6d8c8c[a3_0x51d7('0x3b')][a3_0x51d7('0x2')]===a3_0x51d7('0x13')){this[a3_0x51d7('0x3c')][a3_0x51d7('0x41')]=_0x6d8c8c[a3_0x51d7('0x3b')][a3_0x51d7('0x41')];return!![];}if(_0x6d8c8c[a3_0x51d7('0x3b')]&&_0x6d8c8c[a3_0x51d7('0x3b')][a3_0x51d7('0x2')]){this['messages'][a3_0x51d7('0x5')]=a3_0x51d7('0x37')+JSON[a3_0x51d7('0x12')](_0x6d8c8c[a3_0x51d7('0x3b')][a3_0x51d7('0x1a')]);}else if(_0x6d8c8c[a3_0x51d7('0x3b')]&&typeof _0x6d8c8c[a3_0x51d7('0x3b')]===a3_0x51d7('0x1f')){if(_0x6d8c8c[a3_0x51d7('0x3b')]!==a3_0x51d7('0x13')){this[a3_0x51d7('0x1c')]['apiError']=a3_0x51d7('0x37')+JSON['stringify'](_0x6d8c8c[a3_0x51d7('0x3b')]);}}else{this[a3_0x51d7('0x1c')][a3_0x51d7('0x5')]=a3_0x51d7('0x37')+JSON[a3_0x51d7('0x12')](_0x6d8c8c[a3_0x51d7('0x3b')]);}if(environment_1[a3_0x51d7('0x2a')]){output[a3_0x51d7('0x1b')]({'title':a3_0x51d7('0x20'),'bodyLines':[JSON[a3_0x51d7('0x12')](_0x6d8c8c['data'],null,0x2)]});}}else{output[a3_0x51d7('0xe')]({'title':a3_0x51d7('0x2c'),'bodyLines':[a3_0x51d7('0x32'),a3_0x51d7('0x6'),JSON[a3_0x51d7('0x12')](_0x2f47ea,null,0x2),a3_0x51d7('0xd'),JSON[a3_0x51d7('0x12')](new Error()[a3_0x51d7('0x26')],null,0x2)]});}return![];}catch(_0x450dbc){_0x15b753[a3_0x51d7('0x31')](((_0x18b15d=_0x450dbc===null||_0x450dbc===void 0x0?void 0x0:_0x450dbc[a3_0x51d7('0x22')])===null||_0x18b15d===void 0x0?void 0x0:_0x18b15d[a3_0x51d7('0xf')])?(0x0,metric_logger_1['mapRespToPerfEntry'])(_0x450dbc[a3_0x51d7('0x22')][a3_0x51d7('0xf')]):metric_logger_1[a3_0x51d7('0x2d')]);const _0x54bb8a=(_0x1e0fff=_0x450dbc[a3_0x51d7('0x22')])!==null&&_0x1e0fff!==void 0x0?_0x1e0fff:_0x450dbc;this[a3_0x51d7('0x1c')][a3_0x51d7('0x5')]=this[a3_0x51d7('0x1c')]['extractErrorMessage'](_0x54bb8a,a3_0x51d7('0x2b'));return![];}});}[a3_0x51d7('0x25')](){try{const _0x5ad8ab=JSON[a3_0x51d7('0x4')]((0x0,fs_1[a3_0x51d7('0x1')])(a3_0x51d7('0x42'))['toString']());return _0x5ad8ab[a3_0x51d7('0x9')]['@nrwl/nx-cloud'];}catch(_0x375b43){return'unknown';}}}exports[a3_0x51d7('0x40')]=CloudRunApi;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CloudRunApi = void 0;
const axios_1 = require("../../../utilities/axios");
const environment_1 = require("../../../utilities/environment");
const fs_1 = require("fs");
const zlib_1 = require("zlib");
const util_1 = require("util");
const metric_logger_1 = require("../../../utilities/metric-logger");
const { output } = require('../../../utilities/nx-imports');
class CloudRunApi {
constructor(messages, runContext, options, machineInfo) {
this.messages = messages;
this.runContext = runContext;
this.machineInfo = machineInfo;
this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
}
startRun(distributedExecutionId, hashes) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const recorder = (0, metric_logger_1.createMetricRecorder)('startRun');
try {
const request = {
meta: {
nxCloudVersion: this.nxCloudVersion(),
},
branch: (0, environment_1.getBranch)(),
runGroup: (0, environment_1.getRunGroup)(),
distributedExecutionId,
hashes,
};
if (environment_1.VERBOSE_LOGGING) {
output.note({
title: 'RunStart',
bodyLines: ['\n' + JSON.stringify(request, null, 2)],
});
}
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/runs/start', request));
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
if (resp.data && resp.data.message) {
this.messages.message = resp.data.message;
}
if (!resp.data || !resp.data.urls) {
this.messages.apiError = `Invalid Nx Cloud response: ${JSON.stringify(resp.data)}`;
return {};
}
return resp.data.urls;
}
catch (e) {
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
this.messages.apiError = this.messages.extractErrorMessage(e, 'api');
return {};
}
});
}
createReqBody(run, tasks) {
const uncompressedReqBody = {
meta: {
nxCloudVersion: this.nxCloudVersion(),
},
tasks,
run: run,
machineInfo: this.machineInfo,
};
return JSON.stringify(uncompressedReqBody);
}
endRun(run, tasks) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
// API is not working, don't make the end request
if (this.messages.apiError)
return false;
let uncompressedBodyString = this.createReqBody(run, tasks);
// if the req body is > 20mb, remove hashDetails
if (uncompressedBodyString.length > 20 * 1000 * 1000) {
uncompressedBodyString = this.createReqBody(run, tasks.map((t) => (Object.assign(Object.assign({}, t), { hashDetails: undefined }))));
}
const uncompressedBuffer = Buffer.from(uncompressedBodyString);
const compressedBuffer = yield (0, util_1.promisify)(zlib_1.gzip)(uncompressedBuffer);
const recorder = (0, metric_logger_1.createMetricRecorder)('endRun');
try {
if (environment_1.VERBOSE_LOGGING) {
const t = tasks.map((tt) => {
return Object.assign(Object.assign({}, tt), { terminalOutput: tt.terminalOutput
? `${tt.terminalOutput.slice(0, 20)}...`
: undefined });
});
output.note({
title: 'RunEnd. Completed tasks',
bodyLines: ['\n' + JSON.stringify(t, null, 2)],
});
}
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/runs/end', compressedBuffer, {
headers: Object.assign(Object.assign({}, this.apiAxiosInstance.defaults.headers), { 'Content-Encoding': 'gzip', 'Content-Type': 'application/octet-stream' }),
}));
if (resp) {
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
if (resp.data && resp.data.runUrl && resp.data.status === 'success') {
this.runContext.runUrl = resp.data.runUrl;
return true;
}
if (resp.data && resp.data.status) {
this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data.message)}`;
}
else if (resp.data && typeof resp.data === 'string') {
if (resp.data !== 'success') {
this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data)}`;
}
}
else {
this.messages.apiError = `Invalid end run response: ${JSON.stringify(resp.data)}`;
}
if (environment_1.VERBOSE_LOGGING) {
output.note({
title: 'Invalid end run response',
bodyLines: [JSON.stringify(resp.data, null, 2)],
});
}
}
else {
output.error({
title: 'Nx Cloud: Unknown Error Occurred',
bodyLines: [
'Run completion responded with `undefined`.',
'Run Details:',
JSON.stringify(run, null, 2),
'Stack Trace:',
JSON.stringify(new Error().stack, null, 2),
],
});
}
return false;
}
catch (ee) {
recorder.recordMetric(((_a = ee === null || ee === void 0 ? void 0 : ee.axiosException) === null || _a === void 0 ? void 0 : _a.response)
? (0, metric_logger_1.mapRespToPerfEntry)(ee.axiosException.response)
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
const e = (_b = ee.axiosException) !== null && _b !== void 0 ? _b : ee;
this.messages.apiError = this.messages.extractErrorMessage(e, 'api');
return false;
}
});
}
nxCloudVersion() {
try {
const v = JSON.parse((0, fs_1.readFileSync)(`package.json`).toString());
return v.devDependencies['@nrwl/nx-cloud'];
}
catch (e) {
return 'unknown';
}
}
}
exports.CloudRunApi = CloudRunApi;
//# sourceMappingURL=cloud-run.api.js.map

@@ -1,1 +0,79 @@

const a4_0x28bf=['completeRunGroupWithError','/nx-cloud/executions/complete-run-group','apiAxiosInstance','done','runGroup:\x20','error','../../../utilities/nx-imports','../../../utilities/metric-logger','note','completeRunGroup','createMetricRecorder','dtePollTasks','Completed\x20run\x20group\x20with\x20an\x20error','defineProperty','createApiAxiosInstance','__esModule','value','Completing\x20run\x20group\x20with\x20an\x20error','agentName','DistributedAgentApi','../../../utilities/environment','axiosException','runGroup','error:\x20','response','next','../../../utilities/axios','data','VERBOSE_LOGGING','axiosMultipleTries','RUNNER_FAILURE_PERF_ENTRY','__awaiter','mapRespToPerfEntry','then','recordMetric','apply'];(function(_0x4567c3,_0x28bf31){const _0x12d8d9=function(_0x3d58a9){while(--_0x3d58a9){_0x4567c3['push'](_0x4567c3['shift']());}};_0x12d8d9(++_0x28bf31);}(a4_0x28bf,0x187));const a4_0x12d8=function(_0x4567c3,_0x28bf31){_0x4567c3=_0x4567c3-0x0;let _0x12d8d9=a4_0x28bf[_0x4567c3];return _0x12d8d9;};'use strict';var __awaiter=this&&this[a4_0x12d8('0x0')]||function(_0x2aead8,_0x57ca5c,_0x2eecb4,_0x4989f0){function _0x3d0431(_0x795e5d){return _0x795e5d instanceof _0x2eecb4?_0x795e5d:new _0x2eecb4(function(_0x5d762f){_0x5d762f(_0x795e5d);});}return new(_0x2eecb4||(_0x2eecb4=Promise))(function(_0x35948b,_0x2d1c4c){function _0x43d21d(_0x1bd4f1){try{_0x55aa4d(_0x4989f0[a4_0x12d8('0x1e')](_0x1bd4f1));}catch(_0x1a6db5){_0x2d1c4c(_0x1a6db5);}}function _0x7b46a4(_0x547c8c){try{_0x55aa4d(_0x4989f0['throw'](_0x547c8c));}catch(_0x495bff){_0x2d1c4c(_0x495bff);}}function _0x55aa4d(_0x5c253f){_0x5c253f[a4_0x12d8('0x8')]?_0x35948b(_0x5c253f[a4_0x12d8('0x15')]):_0x3d0431(_0x5c253f[a4_0x12d8('0x15')])[a4_0x12d8('0x2')](_0x43d21d,_0x7b46a4);}_0x55aa4d((_0x4989f0=_0x4989f0[a4_0x12d8('0x4')](_0x2aead8,_0x57ca5c||[]))[a4_0x12d8('0x1e')]());});};Object[a4_0x12d8('0x12')](exports,a4_0x12d8('0x14'),{'value':!![]});exports['DistributedAgentApi']=void 0x0;const axios_1=require(a4_0x12d8('0x1f'));const environment_1=require(a4_0x12d8('0x19'));const metric_logger_1=require(a4_0x12d8('0xc'));const {output}=require(a4_0x12d8('0xb'));class DistributedAgentApi{constructor(_0x42ec5e,_0x553fbe,_0x4b356d){this[a4_0x12d8('0x1b')]=_0x553fbe;this['agentName']=_0x4b356d;this[a4_0x12d8('0x7')]=(0x0,axios_1[a4_0x12d8('0x13')])(_0x42ec5e);}['tasks'](_0x2c534f,_0x391c66,_0x4bae59){var _0x225f02;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x337822=(0x0,metric_logger_1[a4_0x12d8('0xf')])(a4_0x12d8('0x10'));try{const _0x5a94db=yield(0x0,axios_1['axiosMultipleTries'])(()=>this[a4_0x12d8('0x7')]['post']('/nx-cloud/executions/tasks',{'runGroup':this[a4_0x12d8('0x1b')],'agentName':this['agentName'],'executionId':_0x2c534f,'statusCode':_0x391c66,'completedTasks':_0x4bae59}));_0x337822[a4_0x12d8('0x3')]((0x0,metric_logger_1[a4_0x12d8('0x1')])(_0x5a94db));return _0x5a94db[a4_0x12d8('0x20')];}catch(_0x35c402){_0x337822[a4_0x12d8('0x3')](((_0x225f02=_0x35c402===null||_0x35c402===void 0x0?void 0x0:_0x35c402['axiosException'])===null||_0x225f02===void 0x0?void 0x0:_0x225f02['response'])?(0x0,metric_logger_1['mapRespToPerfEntry'])(_0x35c402['axiosException']['response']):metric_logger_1[a4_0x12d8('0x23')]);throw _0x35c402;}});}[a4_0x12d8('0x5')](_0x1e4b1d){var _0x372edd;return __awaiter(this,void 0x0,void 0x0,function*(){if(environment_1['VERBOSE_LOGGING']){output[a4_0x12d8('0xd')]({'title':a4_0x12d8('0x16'),'bodyLines':[a4_0x12d8('0x9')+this[a4_0x12d8('0x1b')],a4_0x12d8('0x1c')+_0x1e4b1d]});}const _0x2217b1=(0x0,metric_logger_1[a4_0x12d8('0xf')])(a4_0x12d8('0xe'));try{const _0x43f992=yield(0x0,axios_1[a4_0x12d8('0x22')])(()=>this[a4_0x12d8('0x7')]['post'](a4_0x12d8('0x6'),{'runGroup':this[a4_0x12d8('0x1b')],'agentName':this[a4_0x12d8('0x17')],'criticalErrorMessage':_0x1e4b1d}));if(environment_1[a4_0x12d8('0x21')]){output[a4_0x12d8('0xd')]({'title':a4_0x12d8('0x11')});}_0x2217b1[a4_0x12d8('0x3')]((0x0,metric_logger_1['mapRespToPerfEntry'])(_0x43f992));}catch(_0x4d51e0){_0x2217b1[a4_0x12d8('0x3')](((_0x372edd=_0x4d51e0===null||_0x4d51e0===void 0x0?void 0x0:_0x4d51e0[a4_0x12d8('0x1a')])===null||_0x372edd===void 0x0?void 0x0:_0x372edd[a4_0x12d8('0x1d')])?(0x0,metric_logger_1[a4_0x12d8('0x1')])(_0x4d51e0['axiosException'][a4_0x12d8('0x1d')]):metric_logger_1[a4_0x12d8('0x23')]);console[a4_0x12d8('0xa')](_0x4d51e0);}});}}exports[a4_0x12d8('0x18')]=DistributedAgentApi;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DistributedAgentApi = void 0;
const axios_1 = require("../../../utilities/axios");
const environment_1 = require("../../../utilities/environment");
const metric_logger_1 = require("../../../utilities/metric-logger");
const { output } = require('../../../utilities/nx-imports');
class DistributedAgentApi {
constructor(options, runGroup, agentName) {
this.runGroup = runGroup;
this.agentName = agentName;
this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
}
tasks(executionId, statusCode, completedTasks) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const recorder = (0, metric_logger_1.createMetricRecorder)('dtePollTasks');
try {
const res = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/tasks', {
runGroup: this.runGroup,
agentName: this.agentName,
executionId,
statusCode,
completedTasks,
}));
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(res));
return res.data;
}
catch (e) {
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
throw e;
}
});
}
completeRunGroupWithError(error) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
if (environment_1.VERBOSE_LOGGING) {
output.note({
title: 'Completing run group with an error',
bodyLines: [`runGroup: ${this.runGroup}`, `error: ${error}`],
});
}
const recorder = (0, metric_logger_1.createMetricRecorder)('completeRunGroup');
try {
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
runGroup: this.runGroup,
agentName: this.agentName,
criticalErrorMessage: error,
}));
if (environment_1.VERBOSE_LOGGING) {
output.note({
title: 'Completed run group with an error',
});
}
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
}
catch (e) {
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
console.error(e);
}
});
}
}
exports.DistributedAgentApi = DistributedAgentApi;
//# sourceMappingURL=distributed-agent.api.js.map

@@ -1,1 +0,240 @@

const a5_0x1e02=['../../error/print-run-group-error','random','VERBOSE_LOGGING','projectName','error:\x20','map','This\x20can\x20also\x20be\x20a\x20false\x20positive\x20caused\x20by\x20agents\x20that\x20did\x20not\x20shut\x20down\x20correctly.','SIGINT','.lock','completed:\x20','Executing:\x20\x27',').\x20Tasks\x20hashes\x20haven\x27t\x20been\x20recorded.','then','exit','printRunGroupError','taskId','completeRunGroupWithError','assign','length','tasks','NX_AGENT_NAME','retryDuring','API\x20Response','DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE','maxParallel','message','toString','next','Agent\x20','submitRunMetrics','status','./node_modules/.cache/nx','Other\x20Nx\x20Cloud\x20Agents\x20Detected','join','projects','catch','configuration','maxParallel:\x20','../../../utilities/metric-logger','existsSync','We\x20have\x20detected\x20another\x20agent\x20with\x20this\x20ID\x20running\x20in\x20this\x20workspace.\x20This\x20should\x20not\x20happen.','unlinkSync','./distributed-agent.api','includes','/lockfiles','find','Fetching\x20tasks...','Command\x20execution\x20failed\x20(distributed\x20task\x20execution:\x20','executionId','value','Starting\x20an\x20agent\x20for\x20running\x20Nx\x20tasks','CIRCLE_STAGE','retryDuring:\x20','../../../utilities/environment','mkdirSync','../../../utilities/waiter','../../../utilities/create-no-new-messages-timeout','createNoNewMessagesTimeout','inherit','reset','note','criticalErrorMessage','completed','Critical\x20Error\x20in\x20Agent:\x20\x22','writeFileSync','defineProperty','execSync','completedTasks','\x20--projects=','../../../utilities/nx-imports','done','\x20--parallel\x20--max-parallel=','__awaiter','Error:','npx\x20nx\x20run-many\x20--target=','/tasks-hashes-','readFileSync','startAgent','executionId:\x20','apply','End\x20all\x20currently\x20running\x20agents,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22,\x20and\x20try\x20again.','parse','child_process','wait','push','params','getTime','env','target','warn','Waiting...','number\x20of\x20tasks:\x20','cacheDirectory','error'];(function(_0x8b778f,_0x1e0222){const _0x561599=function(_0x31dfd3){while(--_0x31dfd3){_0x8b778f['push'](_0x8b778f['shift']());}};_0x561599(++_0x1e0222);}(a5_0x1e02,0x88));const a5_0x5615=function(_0x8b778f,_0x1e0222){_0x8b778f=_0x8b778f-0x0;let _0x561599=a5_0x1e02[_0x8b778f];return _0x561599;};'use strict';var __awaiter=this&&this[a5_0x5615('0x1e')]||function(_0x3ef85b,_0x3865ba,_0x105261,_0x5d48a6){function _0x1c05c5(_0x353019){return _0x353019 instanceof _0x105261?_0x353019:new _0x105261(function(_0x148109){_0x148109(_0x353019);});}return new(_0x105261||(_0x105261=Promise))(function(_0x527195,_0x2b212f){function _0x4f95df(_0x51b357){try{_0x328570(_0x5d48a6[a5_0x5615('0x4f')](_0x51b357));}catch(_0x39ee25){_0x2b212f(_0x39ee25);}}function _0xf1808c(_0x1249cc){try{_0x328570(_0x5d48a6['throw'](_0x1249cc));}catch(_0x568b15){_0x2b212f(_0x568b15);}}function _0x328570(_0x33e835){_0x33e835[a5_0x5615('0x1c')]?_0x527195(_0x33e835[a5_0x5615('0x7')]):_0x1c05c5(_0x33e835[a5_0x5615('0x7')])[a5_0x5615('0x40')](_0x4f95df,_0xf1808c);}_0x328570((_0x5d48a6=_0x5d48a6[a5_0x5615('0x25')](_0x3ef85b,_0x3865ba||[]))[a5_0x5615('0x4f')]());});};Object[a5_0x5615('0x17')](exports,'__esModule',{'value':!![]});exports[a5_0x5615('0x23')]=void 0x0;const child_process_1=require(a5_0x5615('0x28'));const stripJsonComments=require('strip-json-comments');const distributed_agent_api_1=require(a5_0x5615('0x0'));const waiter_1=require(a5_0x5615('0xd'));const environment_1=require(a5_0x5615('0xb'));const print_run_group_error_1=require(a5_0x5615('0x34'));const create_no_new_messages_timeout_1=require(a5_0x5615('0xe'));const fs_1=require('fs');const metric_logger_1=require(a5_0x5615('0x5a'));const {output,workspaceRoot}=require(a5_0x5615('0x1b'));function executeTasks(_0x15214f,_0x3ab6a4){return __awaiter(this,void 0x0,void 0x0,function*(){let _0x2fc04b=0x0;let _0x145b0c=null;const _0x2fd06a=(0x0,create_no_new_messages_timeout_1[a5_0x5615('0xf')])();const _0x14b7b3=new waiter_1['Waiter']();let _0x35121e=[];const _0x38db62=new Date();let _0xf775c8=![];while(!![]){if(environment_1[a5_0x5615('0x36')]){output[a5_0x5615('0x12')]({'title':a5_0x5615('0x4')});}_0x145b0c=yield _0x3ab6a4[a5_0x5615('0x47')](_0x145b0c?_0x145b0c[a5_0x5615('0x6')]:null,_0x2fc04b,_0x35121e);if(environment_1[a5_0x5615('0x36')]){output[a5_0x5615('0x12')]({'title':a5_0x5615('0x4a'),'bodyLines':[a5_0x5615('0x3d')+_0x145b0c[a5_0x5615('0x14')],a5_0x5615('0xa')+_0x145b0c['retryDuring'],a5_0x5615('0x24')+_0x145b0c[a5_0x5615('0x6')],a5_0x5615('0x31')+_0x145b0c['tasks'][a5_0x5615('0x46')],a5_0x5615('0x38')+_0x145b0c[a5_0x5615('0x13')],a5_0x5615('0x59')+_0x145b0c['maxParallel']]});}if(_0x145b0c[a5_0x5615('0x13')]){output[a5_0x5615('0x33')]({'title':'Distributed\x20Execution\x20Terminated','bodyLines':[a5_0x5615('0x1f'),_0x145b0c['criticalErrorMessage']]});process[a5_0x5615('0x41')](0x0);}if((_0x145b0c===null||_0x145b0c===void 0x0?void 0x0:_0x145b0c['retryDuring'])&&(_0x145b0c===null||_0x145b0c===void 0x0?void 0x0:_0x145b0c['retryDuring'])!==0x0&&!_0xf775c8&&new Date()[a5_0x5615('0x2c')]()-_0x38db62['getTime']()>_0x145b0c[a5_0x5615('0x49')]){yield _0x14b7b3[a5_0x5615('0x29')]();continue;}if(_0x145b0c['completed'])return;_0x2fd06a(_0x145b0c['tasks'][a5_0x5615('0x39')](_0x20e449=>_0x20e449[a5_0x5615('0x43')])[a5_0x5615('0x55')](''));if(!_0x145b0c[a5_0x5615('0x6')]){if(environment_1['VERBOSE_LOGGING']){output['note']({'title':a5_0x5615('0x30')});}yield _0x14b7b3[a5_0x5615('0x29')]();_0x2fc04b=0x0;_0x35121e=[];continue;}_0x14b7b3[a5_0x5615('0x11')]();_0xf775c8=!![];const _0x3bae23=invokeTasksUsingRunMany(_0x15214f,_0x145b0c['executionId'],_0x145b0c[a5_0x5615('0x47')],_0x145b0c[a5_0x5615('0x4c')]);_0x2fc04b=_0x3bae23['completedStatusCode'];_0x35121e=_0x3bae23[a5_0x5615('0x19')];}});}function readCompletedTasks(_0x12924b,_0x1fef34){const _0x1313a0=a5_0x5615('0x5')+_0x1fef34+a5_0x5615('0x3f');let _0x17e87e;try{const _0x536b9c=_0x12924b[a5_0x5615('0x32')]||a5_0x5615('0x53');const _0x4ce3a7=_0x536b9c+a5_0x5615('0x21')+_0x1fef34;_0x17e87e=JSON[a5_0x5615('0x27')]((0x0,fs_1[a5_0x5615('0x22')])(_0x4ce3a7)[a5_0x5615('0x4e')]());(0x0,fs_1[a5_0x5615('0x5d')])(_0x4ce3a7);}catch(_0xf1ef69){throw new Error(_0x1313a0);}if(_0x17e87e[a5_0x5615('0x46')]==0x0){throw new Error(_0x1313a0);}return _0x17e87e;}function invokeTasksUsingRunMany(_0x3df89d,_0x8f9f64,_0x5ec450,_0x30909b){let _0x2e933e=0x0;const _0x3d25a8=[];for(const _0x1025de of groupByTarget(_0x5ec450)){const _0x4c7221=_0x1025de[a5_0x5615('0x58')]?'--configuration='+_0x1025de[a5_0x5615('0x58')]:'';const _0x20e823=_0x30909b>0x1?a5_0x5615('0x1d')+_0x30909b:'';const _0x479bb7=a5_0x5615('0x20')+_0x1025de[a5_0x5615('0x2e')]+'\x20'+_0x4c7221+a5_0x5615('0x1a')+_0x1025de[a5_0x5615('0x56')][a5_0x5615('0x55')](',')+'\x20'+_0x1025de[a5_0x5615('0x2b')]+_0x20e823;if(environment_1[a5_0x5615('0x36')]){output['note']({'title':a5_0x5615('0x3e')+_0x479bb7+'\x27'});}try{(0x0,child_process_1[a5_0x5615('0x18')])(_0x479bb7,{'stdio':[a5_0x5615('0x10'),a5_0x5615('0x10'),a5_0x5615('0x10')],'env':Object[a5_0x5615('0x45')](Object[a5_0x5615('0x45')]({},process[a5_0x5615('0x2d')]),{'NX_CACHE_FAILURES':'true','NX_CLOUD_DISTRIBUTED_EXECUTION_ID':_0x8f9f64})});}catch(_0x52a377){if(_0x52a377[a5_0x5615('0x52')]===environment_1[a5_0x5615('0x4b')]){throw _0x52a377;}else{_0x2e933e=0x1;}}finally{_0x3d25a8[a5_0x5615('0x2a')](...readCompletedTasks(_0x3df89d,_0x8f9f64));}}return{'completedStatusCode':_0x2e933e,'completedTasks':_0x3d25a8};}function groupByTarget(_0x40e027){const _0x3fa765=[];_0x40e027['forEach'](_0x2c2686=>{const _0x2f1a0f=_0x3fa765[a5_0x5615('0x3')](_0xa146af=>_0xa146af[a5_0x5615('0x2e')]===_0x2c2686[a5_0x5615('0x2e')]&&_0xa146af[a5_0x5615('0x58')]===_0x2c2686['configuration']);if(_0x2f1a0f){_0x2f1a0f[a5_0x5615('0x56')][a5_0x5615('0x2a')](_0x2c2686[a5_0x5615('0x37')]);}else{_0x3fa765[a5_0x5615('0x2a')]({'target':_0x2c2686[a5_0x5615('0x2e')],'projects':[_0x2c2686['projectName']],'params':_0x2c2686['params'],'configuration':_0x2c2686[a5_0x5615('0x58')]});}});return _0x3fa765;}function getAgentName(){if(process[a5_0x5615('0x2d')][a5_0x5615('0x48')]!==undefined){return process[a5_0x5615('0x2d')][a5_0x5615('0x48')];}else if(process['env']['CIRCLECI']!==undefined){return process[a5_0x5615('0x2d')][a5_0x5615('0x9')];}else{return a5_0x5615('0x50')+Math['floor'](Math[a5_0x5615('0x35')]()*0x186a0);}}function createAgentLockfile(_0x4613b7,_0xdb6e63){const _0x49a195=_0x4613b7[a5_0x5615('0x32')]||'./node_modules/.cache/nx';const _0x4ed5ea=_0x49a195+a5_0x5615('0x2');const _0x5f3f12=_0x4ed5ea+'/'+_0xdb6e63+'.lock';if(!(0x0,fs_1['existsSync'])(_0x4ed5ea)){(0x0,fs_1[a5_0x5615('0xc')])(_0x4ed5ea,{'recursive':!![]});}const _0x2bcbca=(0x0,fs_1['readdirSync'])(_0x4ed5ea);if(_0x2bcbca['length']){if(_0x2bcbca[a5_0x5615('0x1')](_0xdb6e63+a5_0x5615('0x3c'))){output[a5_0x5615('0x33')]({'title':'Duplicate\x20Agent\x20ID\x20Detected','bodyLines':[a5_0x5615('0x5c'),'',a5_0x5615('0x26')]});process[a5_0x5615('0x41')](0x1);}output[a5_0x5615('0x2f')]({'title':a5_0x5615('0x54'),'bodyLines':['We\x20have\x20detected\x20other\x20agents\x20running\x20in\x20this\x20workspace.\x20This\x20can\x20cause\x20unexpected\x20behavior.','',a5_0x5615('0x3a'),'If\x20you\x20believe\x20this\x20is\x20the\x20case,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22.']});}(0x0,fs_1[a5_0x5615('0x16')])(_0x5f3f12,'');process['on'](a5_0x5615('0x41'),_0x8cc447=>cleanupAgentLockfile(_0x5f3f12,_0x8cc447));process['on'](a5_0x5615('0x3b'),()=>cleanupAgentLockfile(_0x5f3f12,0x0));}function cleanupAgentLockfile(_0x359fd8,_0x530b53){if((0x0,fs_1[a5_0x5615('0x5b')])(_0x359fd8)){(0x0,fs_1[a5_0x5615('0x5d')])(_0x359fd8);process[a5_0x5615('0x41')](_0x530b53);}}function startAgent(){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x8be062=(0x0,environment_1['getRunGroup'])();if(!_0x8be062){(0x0,print_run_group_error_1[a5_0x5615('0x42')])();return process['exit'](0x1);}output[a5_0x5615('0x12')]({'title':a5_0x5615('0x8')});const _0x8c0fc6=JSON[a5_0x5615('0x27')](stripJsonComments((0x0,fs_1['readFileSync'])(workspaceRoot+'/nx.json')[a5_0x5615('0x4e')]()))['tasksRunnerOptions']['default']['options'];const _0x4c7167=getAgentName();createAgentLockfile(_0x8c0fc6,_0x4c7167);const _0x20cfc6=new distributed_agent_api_1['DistributedAgentApi'](_0x8c0fc6,_0x8be062,_0x4c7167);return executeTasks(_0x8c0fc6,_0x20cfc6)['then'](_0x184a59=>__awaiter(this,void 0x0,void 0x0,function*(){yield(0x0,metric_logger_1[a5_0x5615('0x51')])(_0x8c0fc6);return _0x184a59;}))[a5_0x5615('0x57')](_0x21b484=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x20cfc6[a5_0x5615('0x44')](a5_0x5615('0x15')+_0x21b484[a5_0x5615('0x4d')]+'\x22');throw _0x21b484;}));});}exports[a5_0x5615('0x23')]=startAgent;
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.startAgent = void 0;
const child_process_1 = require("child_process");
const stripJsonComments = require("strip-json-comments");
const distributed_agent_api_1 = require("./distributed-agent.api");
const waiter_1 = require("../../../utilities/waiter");
const environment_1 = require("../../../utilities/environment");
const print_run_group_error_1 = require("../../error/print-run-group-error");
const create_no_new_messages_timeout_1 = require("../../../utilities/create-no-new-messages-timeout");
const fs_1 = require("fs");
const metric_logger_1 = require("../../../utilities/metric-logger");
const { output, workspaceRoot } = require('../../../utilities/nx-imports');
function executeTasks(options, api) {
return __awaiter(this, void 0, void 0, function* () {
let completedStatusCode = 0;
let apiResponse = null;
const failIfSameTasksIn30Mins = (0, create_no_new_messages_timeout_1.createNoNewMessagesTimeout)();
const waiter = new waiter_1.Waiter();
let completedTasks = [];
const startTime = new Date();
let executedAnyTasks = false;
while (true) {
if (environment_1.VERBOSE_LOGGING) {
output.note({
title: 'Fetching tasks...',
});
}
apiResponse = yield api.tasks(apiResponse ? apiResponse.executionId : null, completedStatusCode, completedTasks);
if (environment_1.VERBOSE_LOGGING) {
output.note({
title: 'API Response',
bodyLines: [
`completed: ${apiResponse.completed}`,
`retryDuring: ${apiResponse.retryDuring}`,
`executionId: ${apiResponse.executionId}`,
`number of tasks: ${apiResponse.tasks.length}`,
`error: ${apiResponse.criticalErrorMessage}`,
`maxParallel: ${apiResponse.maxParallel}`,
],
});
}
if (apiResponse.criticalErrorMessage) {
output.error({
title: 'Distributed Execution Terminated',
bodyLines: ['Error:', apiResponse.criticalErrorMessage],
});
process.exit(0);
}
// run group is completed but it might be a rerun
// we will try several times before going further and
// completed the response
// we only do it if we haven't executed any tasks
if ((apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.retryDuring) &&
(apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.retryDuring) !== 0 &&
!executedAnyTasks &&
new Date().getTime() - startTime.getTime() > apiResponse.retryDuring) {
yield waiter.wait();
continue;
}
if (apiResponse.completed)
return;
failIfSameTasksIn30Mins(apiResponse.tasks.map((t) => t.taskId).join(''));
if (!apiResponse.executionId) {
if (environment_1.VERBOSE_LOGGING) {
output.note({
title: 'Waiting...',
});
}
yield waiter.wait();
completedStatusCode = 0;
completedTasks = [];
continue;
}
waiter.reset();
executedAnyTasks = true;
const r = invokeTasksUsingRunMany(options, apiResponse.executionId, apiResponse.tasks, apiResponse.maxParallel);
completedStatusCode = r.completedStatusCode;
completedTasks = r.completedTasks;
}
});
}
function readCompletedTasks(options, distributedExecutionId) {
const errorMessage = `Command execution failed (distributed task execution: ${distributedExecutionId}). Tasks hashes haven\'t been recorded.`;
let completedTasks;
try {
const cacheDirectory = options.cacheDirectory || './node_modules/.cache/nx';
const taskHashesFile = `${cacheDirectory}/tasks-hashes-${distributedExecutionId}`;
completedTasks = JSON.parse((0, fs_1.readFileSync)(taskHashesFile).toString());
// remove it such that if the next command crashes we don't read an obsolete file
(0, fs_1.unlinkSync)(taskHashesFile);
}
catch (e) {
throw new Error(errorMessage);
}
if (completedTasks.length == 0) {
throw new Error(errorMessage);
}
return completedTasks;
}
function invokeTasksUsingRunMany(options, executionId, tasks, maxParallel) {
let completedStatusCode = 0;
const completedTasks = [];
for (const g of groupByTarget(tasks)) {
const config = g.configuration ? `--configuration=${g.configuration}` : ``;
const parallel = maxParallel > 1 ? ` --parallel --max-parallel=${maxParallel}` : ``;
// TODO use pnpx or yarn when needed
const command = `npx nx run-many --target=${g.target} ${config} --projects=${g.projects.join(',')} ${g.params}${parallel}`;
if (environment_1.VERBOSE_LOGGING) {
output.note({
title: `Executing: '${command}'`,
});
}
try {
(0, child_process_1.execSync)(command, {
stdio: ['inherit', 'inherit', 'inherit'],
env: Object.assign(Object.assign({}, process.env), { NX_CACHE_FAILURES: 'true', NX_CLOUD_DISTRIBUTED_EXECUTION_ID: executionId }),
});
}
catch (e) {
if (e.status === environment_1.DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE) {
throw e;
}
else {
completedStatusCode = 1;
}
}
finally {
completedTasks.push(...readCompletedTasks(options, executionId));
}
}
return { completedStatusCode, completedTasks };
}
function groupByTarget(tasks) {
const res = [];
tasks.forEach((t) => {
const r = res.find((rr) => rr.target === t.target && rr.configuration === t.configuration);
if (r) {
r.projects.push(t.projectName);
}
else {
res.push({
target: t.target,
projects: [t.projectName],
params: t.params,
configuration: t.configuration,
});
}
});
return res;
}
function getAgentName() {
if (process.env.NX_AGENT_NAME !== undefined) {
return process.env.NX_AGENT_NAME;
}
else if (process.env.CIRCLECI !== undefined) {
return process.env.CIRCLE_STAGE;
}
else {
return `Agent ${Math.floor(Math.random() * 100000)}`;
}
}
function createAgentLockfile(options, agentName) {
const cacheDirectory = options.cacheDirectory || './node_modules/.cache/nx';
const lockFileDirectory = `${cacheDirectory}/lockfiles`;
const lockFilePath = `${lockFileDirectory}/${agentName}.lock`;
if (!(0, fs_1.existsSync)(lockFileDirectory)) {
(0, fs_1.mkdirSync)(lockFileDirectory, { recursive: true });
}
// Check for other agents' lockfiles and warn if exist
const lockFiles = (0, fs_1.readdirSync)(lockFileDirectory);
if (lockFiles.length) {
// Check to make sure the current agent name is not in use (only 1/100000 ^ 2 chance of this)
if (lockFiles.includes(`${agentName}.lock`)) {
output.error({
title: 'Duplicate Agent ID Detected',
bodyLines: [
'We have detected another agent with this ID running in this workspace. This should not happen.',
'',
'End all currently running agents, run "npx nx-cloud clean-up-agents", and try again.',
],
});
process.exit(1);
}
output.warn({
title: 'Other Nx Cloud Agents Detected',
bodyLines: [
'We have detected other agents running in this workspace. This can cause unexpected behavior.',
'',
'This can also be a false positive caused by agents that did not shut down correctly.',
'If you believe this is the case, run "npx nx-cloud clean-up-agents".',
],
});
}
(0, fs_1.writeFileSync)(lockFilePath, '');
process.on('exit', (code) => cleanupAgentLockfile(lockFilePath, code));
process.on('SIGINT', () => cleanupAgentLockfile(lockFilePath, 0));
}
function cleanupAgentLockfile(lockFilePath, code) {
if ((0, fs_1.existsSync)(lockFilePath)) {
(0, fs_1.unlinkSync)(lockFilePath);
process.exit(code);
}
}
function startAgent() {
return __awaiter(this, void 0, void 0, function* () {
const runGroup = (0, environment_1.getRunGroup)();
if (!runGroup) {
(0, print_run_group_error_1.printRunGroupError)();
return process.exit(1);
}
output.note({
title: 'Starting an agent for running Nx tasks',
});
const options = JSON.parse(stripJsonComments((0, fs_1.readFileSync)(`${workspaceRoot}/nx.json`).toString())).tasksRunnerOptions.default.options;
const agentName = getAgentName();
createAgentLockfile(options, agentName);
const api = new distributed_agent_api_1.DistributedAgentApi(options, runGroup, agentName);
return executeTasks(options, api)
.then((res) => __awaiter(this, void 0, void 0, function* () {
yield (0, metric_logger_1.submitRunMetrics)(options);
return res;
}))
.catch((e) => __awaiter(this, void 0, void 0, function* () {
yield api.completeRunGroupWithError(`Critical Error in Agent: "${e.message}"`);
throw e;
}));
});
}
exports.startAgent = startAgent;
//# sourceMappingURL=distributed-agent.impl.js.map

@@ -1,1 +0,130 @@

const a6_0x29c3=['target','apply','value','join','status','../../../utilities/metric-logger','then','mapRespToPerfEntry','next','createMetricRecorder','/nx-cloud/executions/start','project','../../../utilities/nx-imports','stopAgentsOnFailure','axiosException','message','throw','dteStatus','data','Workspace\x20is\x20disabled.\x20Cannot\x20perform\x20distributed\x20task\x20executions.','defineProperty','apiAxiosInstance','recordMetric','RUNNER_FAILURE_PERF_ENTRY','NX_CLOUD_DISTRIBUTED_EXECUTION_STOP_AGENTS_ON_FAILURE','parseCommand','DistributedExecutionApi','/nx-cloud/executions/status','post','getBranch','completeRunGroup','response','map','maxParallel','NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT','axiosMultipleTries','done','__esModule','completeRunGroupWithError','error','true','__awaiter','parallel','exit','start'];(function(_0x3b8619,_0x29c3c7){const _0x4b8b2c=function(_0x279801){while(--_0x279801){_0x3b8619['push'](_0x3b8619['shift']());}};_0x4b8b2c(++_0x29c3c7);}(a6_0x29c3,0x15e));const a6_0x4b8b=function(_0x3b8619,_0x29c3c7){_0x3b8619=_0x3b8619-0x0;let _0x4b8b2c=a6_0x29c3[_0x3b8619];return _0x4b8b2c;};'use strict';var __awaiter=this&&this[a6_0x4b8b('0x6')]||function(_0x407b6d,_0x180953,_0x201a15,_0x53feb6){function _0xdbdea0(_0x37163e){return _0x37163e instanceof _0x201a15?_0x37163e:new _0x201a15(function(_0x1c830c){_0x1c830c(_0x37163e);});}return new(_0x201a15||(_0x201a15=Promise))(function(_0x449614,_0x8ece6){function _0x431e6d(_0x504b84){try{_0x287417(_0x53feb6[a6_0x4b8b('0x12')](_0x504b84));}catch(_0x497388){_0x8ece6(_0x497388);}}function _0x228921(_0x3245d3){try{_0x287417(_0x53feb6[a6_0x4b8b('0x1a')](_0x3245d3));}catch(_0x5db920){_0x8ece6(_0x5db920);}}function _0x287417(_0x1f815c){_0x1f815c[a6_0x4b8b('0x1')]?_0x449614(_0x1f815c[a6_0x4b8b('0xc')]):_0xdbdea0(_0x1f815c[a6_0x4b8b('0xc')])[a6_0x4b8b('0x10')](_0x431e6d,_0x228921);}_0x287417((_0x53feb6=_0x53feb6[a6_0x4b8b('0xb')](_0x407b6d,_0x180953||[]))[a6_0x4b8b('0x12')]());});};Object[a6_0x4b8b('0x1e')](exports,a6_0x4b8b('0x2'),{'value':!![]});exports['createStartRequest']=exports[a6_0x4b8b('0x24')]=void 0x0;const axios_1=require('../../../utilities/axios');const environment_1=require('../../../utilities/environment');const metric_logger_1=require(a6_0x4b8b('0xf'));const {output,unparse}=require(a6_0x4b8b('0x16'));class DistributedExecutionApi{constructor(_0x20fa9f){this['apiAxiosInstance']=(0x0,axios_1['createApiAxiosInstance'])(_0x20fa9f);}[a6_0x4b8b('0x9')](_0x46a09b){var _0x41e071;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x5189b5=(0x0,metric_logger_1[a6_0x4b8b('0x13')])('dteStart');let _0x3cad43;try{_0x3cad43=yield(0x0,axios_1[a6_0x4b8b('0x0')])(()=>this[a6_0x4b8b('0x1f')]['post'](a6_0x4b8b('0x14'),_0x46a09b));_0x5189b5[a6_0x4b8b('0x20')]((0x0,metric_logger_1[a6_0x4b8b('0x11')])(_0x3cad43));}catch(_0x1adb92){_0x5189b5[a6_0x4b8b('0x20')](((_0x41e071=_0x1adb92===null||_0x1adb92===void 0x0?void 0x0:_0x1adb92[a6_0x4b8b('0x18')])===null||_0x41e071===void 0x0?void 0x0:_0x41e071[a6_0x4b8b('0x29')])?(0x0,metric_logger_1[a6_0x4b8b('0x11')])(_0x1adb92['axiosException'][a6_0x4b8b('0x29')]):metric_logger_1[a6_0x4b8b('0x21')]);throw _0x1adb92;}if(!_0x3cad43[a6_0x4b8b('0x1c')]['enabled']){throw new Error(a6_0x4b8b('0x1d'));}if(_0x3cad43[a6_0x4b8b('0x1c')][a6_0x4b8b('0x4')]){throw new Error(_0x3cad43['data']['error']);}return _0x3cad43[a6_0x4b8b('0x1c')]['id'];});}[a6_0x4b8b('0xe')](_0x53c0ec){var _0x3bc9af;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x41edea=(0x0,metric_logger_1['createMetricRecorder'])(a6_0x4b8b('0x1b'));try{const _0xd0d28f=yield(0x0,axios_1[a6_0x4b8b('0x0')])(()=>this[a6_0x4b8b('0x1f')][a6_0x4b8b('0x26')](a6_0x4b8b('0x25'),{'id':_0x53c0ec}));_0x41edea[a6_0x4b8b('0x20')]((0x0,metric_logger_1['mapRespToPerfEntry'])(_0xd0d28f));return _0xd0d28f[a6_0x4b8b('0x1c')];}catch(_0x38cfa0){_0x41edea[a6_0x4b8b('0x20')](((_0x3bc9af=_0x38cfa0===null||_0x38cfa0===void 0x0?void 0x0:_0x38cfa0[a6_0x4b8b('0x18')])===null||_0x3bc9af===void 0x0?void 0x0:_0x3bc9af['response'])?(0x0,metric_logger_1[a6_0x4b8b('0x11')])(_0x38cfa0[a6_0x4b8b('0x18')]['response']):metric_logger_1[a6_0x4b8b('0x21')]);output[a6_0x4b8b('0x4')]({'title':_0x38cfa0[a6_0x4b8b('0x19')]});process[a6_0x4b8b('0x8')](0x1);}});}[a6_0x4b8b('0x3')](_0x3f8831,_0x17c509){var _0x14daba;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x6f0561=(0x0,metric_logger_1['createMetricRecorder'])(a6_0x4b8b('0x28'));try{const _0x2862b9=yield(0x0,axios_1[a6_0x4b8b('0x0')])(()=>this[a6_0x4b8b('0x1f')][a6_0x4b8b('0x26')]('/nx-cloud/executions/complete-run-group',{'runGroup':_0x3f8831,'criticalErrorMessage':_0x17c509}),0x3);_0x6f0561[a6_0x4b8b('0x20')]((0x0,metric_logger_1[a6_0x4b8b('0x11')])(_0x2862b9));}catch(_0xde1497){_0x6f0561[a6_0x4b8b('0x20')](((_0x14daba=_0xde1497===null||_0xde1497===void 0x0?void 0x0:_0xde1497[a6_0x4b8b('0x18')])===null||_0x14daba===void 0x0?void 0x0:_0x14daba[a6_0x4b8b('0x29')])?(0x0,metric_logger_1[a6_0x4b8b('0x11')])(_0xde1497[a6_0x4b8b('0x18')][a6_0x4b8b('0x29')]):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);}});}}exports[a6_0x4b8b('0x24')]=DistributedExecutionApi;function createStartRequest(_0x5b5f71,_0x3274de,_0x3956ca){const _0x531b87=_0x3274de['map'](_0x1609b7=>{return _0x1609b7[a6_0x4b8b('0x2a')](_0x3734e8=>{return{'taskId':_0x3734e8['id'],'hash':_0x3734e8['hash'],'projectName':_0x3734e8[a6_0x4b8b('0xa')][a6_0x4b8b('0x15')],'target':_0x3734e8[a6_0x4b8b('0xa')][a6_0x4b8b('0xa')],'configuration':_0x3734e8['target']['configuration']||null,'params':unparse(_0x3734e8['overrides'])[a6_0x4b8b('0xd')]('\x20')};});});const _0x270b9a={'command':(0x0,environment_1[a6_0x4b8b('0x23')])(),'branch':(0x0,environment_1[a6_0x4b8b('0x27')])(),'runGroup':_0x5b5f71,'tasks':_0x531b87,'maxParallel':calculateMaxParallel(_0x3956ca)};if(environment_1[a6_0x4b8b('0x2c')]){_0x270b9a['agentCount']=environment_1[a6_0x4b8b('0x2c')];}if(!environment_1[a6_0x4b8b('0x22')]){_0x270b9a[a6_0x4b8b('0x17')]=![];}return _0x270b9a;}exports['createStartRequest']=createStartRequest;function calculateMaxParallel(_0x496534){if(_0x496534[a6_0x4b8b('0x7')]==='false'||_0x496534[a6_0x4b8b('0x7')]===![]){return 0x1;}else if(_0x496534[a6_0x4b8b('0x7')]===a6_0x4b8b('0x5')||_0x496534[a6_0x4b8b('0x7')]===!![]){return Number(_0x496534[a6_0x4b8b('0x2b')]||0x3);}else if(_0x496534['parallel']===undefined){return _0x496534[a6_0x4b8b('0x2b')]?Number(_0x496534[a6_0x4b8b('0x2b')]):0x3;}else{return Number(_0x496534[a6_0x4b8b('0x7')])||0x3;}}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createStartRequest = exports.DistributedExecutionApi = void 0;
const axios_1 = require("../../../utilities/axios");
const environment_1 = require("../../../utilities/environment");
const metric_logger_1 = require("../../../utilities/metric-logger");
const { output, unparse } = require('../../../utilities/nx-imports');
class DistributedExecutionApi {
constructor(options) {
this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
}
start(params) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const recorder = (0, metric_logger_1.createMetricRecorder)('dteStart');
let resp;
try {
resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/start', params));
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
}
catch (e) {
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
throw e;
}
if (!resp.data.enabled) {
throw new Error(`Workspace is disabled. Cannot perform distributed task executions.`);
}
if (resp.data.error) {
throw new Error(resp.data.error);
}
return resp.data.id;
});
}
status(id) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const recorder = (0, metric_logger_1.createMetricRecorder)('dteStatus');
try {
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/status', {
id,
}));
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
return resp.data;
}
catch (e) {
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
output.error({
title: e.message,
});
process.exit(1);
}
});
}
completeRunGroupWithError(runGroup, error) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const recorder = (0, metric_logger_1.createMetricRecorder)('completeRunGroup');
try {
const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
runGroup: runGroup,
criticalErrorMessage: error,
}), 3);
recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
}
catch (e) {
recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
: metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
}
});
}
}
exports.DistributedExecutionApi = DistributedExecutionApi;
function createStartRequest(runGroup, task, options) {
const tasksToExecute = task.map((arr) => {
return arr.map((t) => {
return {
taskId: t.id,
hash: t.hash,
projectName: t.target.project,
target: t.target.target,
configuration: t.target.configuration || null,
params: unparse(t.overrides).join(' '),
};
});
});
const request = {
command: (0, environment_1.parseCommand)(),
branch: (0, environment_1.getBranch)(),
runGroup,
tasks: tasksToExecute,
maxParallel: calculateMaxParallel(options),
};
if (environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT) {
request.agentCount = environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT;
}
if (!environment_1.NX_CLOUD_DISTRIBUTED_EXECUTION_STOP_AGENTS_ON_FAILURE) {
request.stopAgentsOnFailure = false;
}
return request;
}
exports.createStartRequest = createStartRequest;
function calculateMaxParallel(options) {
if (options.parallel === 'false' || options.parallel === false) {
return 1;
}
else if (options.parallel === 'true' || options.parallel === true) {
return Number(options.maxParallel || 3);
}
else if (options.parallel === undefined) {
return options.maxParallel ? Number(options.maxParallel) : 3;
}
else {
return Number(options.parallel) || 3;
}
}
//# sourceMappingURL=distributed-execution.api.js.map

@@ -1,1 +0,309 @@

const a7_0x340b=['COMPLETED','push','criticalErrorMessage','createNoNewMessagesTimeout','roots','hash','completedTasks','axiosException','value','Found\x20unknown\x20task:\x20','VERBOSE_LOGGING','log','commandStatus','success','lifeCycle','submitRunMetrics','Error:','tasks','../../../utilities/nx-imports','wait','See\x20run\x20details\x20at\x20','next','note','Retrieving\x20artifacts\x20from\x20','Waiting...','targetDependencies','defaultTargetDependencies','addTaskDependencies','status','configuration','throw','reset','projectGraph','__awaiter','keys','projects','runUrl','splitTasksIntoStages','target','length','../../error/print-run-group-error','nxCloudDistributedTasksRunner','message','apply','build','logCommand','Successfully\x20completed\x20running\x20the\x20command.','copyFilesFromCache','terminalOutput','executionStatus','find','map','Starting\x20distributed\x20command\x20execution','../../../utilities/metric-logger','dependencies','cacheDirectory','then','../../../utilities/environment','filter','./distributed-execution.api','addTaskToGraph','Unable\x20to\x20complete\x20a\x20run.','addVerticalSeparator','size','findTask','parse','error','Command\x20execution\x20failed.','Extracting\x20artifacts','strip-json-comments','Main\x20job\x20terminated\x20with\x20an\x20error:\x20\x22','delete','project','assign','Waiter','ENCRYPTION_KEY','executionId:\x20','scheduleTask','TaskGraphCreator','taskId','start','number\x20of\x20completed\x20tasks:\x20','__esModule','printRunGroupError','/nx.json','DistributedExecutionApi','url','createStartRequest','startTask','has','completeRunGroupWithError','nodes','run','addDependencies','toString','indexOf','error:\x20','E2EEncryption','createTaskGraph','exit','overrides','endTask','Distributed\x20Execution\x20Terminated','../../file-storage/e2e-encryption','strictlyOrderedTargets','add'];(function(_0x12ed6d,_0x340b75){const _0x473c34=function(_0x32ac72){while(--_0x32ac72){_0x12ed6d['push'](_0x12ed6d['shift']());}};_0x473c34(++_0x340b75);}(a7_0x340b,0xb3));const a7_0x473c=function(_0x12ed6d,_0x340b75){_0x12ed6d=_0x12ed6d-0x0;let _0x473c34=a7_0x340b[_0x12ed6d];return _0x473c34;};'use strict';var __awaiter=this&&this[a7_0x473c('0x42')]||function(_0x276365,_0x2fee74,_0x5ab7d6,_0x45cadd){function _0x392d6e(_0x5c5df7){return _0x5c5df7 instanceof _0x5ab7d6?_0x5c5df7:new _0x5ab7d6(function(_0x2cc013){_0x2cc013(_0x5c5df7);});}return new(_0x5ab7d6||(_0x5ab7d6=Promise))(function(_0x485446,_0x3b4dad){function _0x1acd2e(_0xbdaf97){try{_0x9c1f72(_0x45cadd['next'](_0xbdaf97));}catch(_0x1e0bac){_0x3b4dad(_0x1e0bac);}}function _0x150449(_0x210431){try{_0x9c1f72(_0x45cadd[a7_0x473c('0x3f')](_0x210431));}catch(_0x288ef3){_0x3b4dad(_0x288ef3);}}function _0x9c1f72(_0x5ecfcb){_0x5ecfcb['done']?_0x485446(_0x5ecfcb['value']):_0x392d6e(_0x5ecfcb[a7_0x473c('0x29')])[a7_0x473c('0x59')](_0x1acd2e,_0x150449);}_0x9c1f72((_0x45cadd=_0x45cadd[a7_0x473c('0x4c')](_0x276365,_0x2fee74||[]))[a7_0x473c('0x36')]());});};Object['defineProperty'](exports,a7_0x473c('0x9'),{'value':!![]});exports[a7_0x473c('0x5')]=exports[a7_0x473c('0x4a')]=void 0x0;const stripJsonComments=require(a7_0x473c('0x66'));const fs_1=require('fs');const distributed_execution_api_1=require(a7_0x473c('0x5c'));const file_storage_1=require('../../file-storage/file-storage');const e2e_encryption_1=require(a7_0x473c('0x1e'));const waiter_1=require('../../../utilities/waiter');const environment_1=require(a7_0x473c('0x5a'));const print_run_group_error_1=require(a7_0x473c('0x49'));const create_no_new_messages_timeout_1=require('../../../utilities/create-no-new-messages-timeout');const metric_logger_1=require(a7_0x473c('0x56'));const {output,workspaceRoot,getDependencyConfigs,getOutputs,unparse,Cache}=require(a7_0x473c('0x33'));class NoopLifeCycle{[a7_0x473c('0x4')](_0x374dbe){}[a7_0x473c('0xf')](_0x4848f5){}[a7_0x473c('0x1c')](_0x75c481,_0x58675a){}}function runDistributedExecution(_0x46f9b4,_0x2b1503,_0x14893b,_0x326f6b,_0x5f4119,_0x508a16,_0x125c5d){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x54c2a3=JSON[a7_0x473c('0x62')](stripJsonComments((0x0,fs_1['readFileSync'])(workspaceRoot+a7_0x473c('0xb'))[a7_0x473c('0x15')]()));const _0x51a449=new TaskOrderer(_0x14893b[a7_0x473c('0x41')],getDefaultDependencyConfigs(_0x54c2a3,_0x2b1503))[a7_0x473c('0x46')](_0x125c5d);const _0x259311=yield _0x46f9b4[a7_0x473c('0x7')]((0x0,distributed_execution_api_1[a7_0x473c('0xe')])(_0x508a16,_0x51a449,_0x2b1503));return yield processTasks(_0x46f9b4,_0x326f6b,_0x5f4119,_0x2b1503,_0x259311,_0x125c5d,_0x14893b);});}function processTasks(_0x335fb8,_0x128238,_0xb05f43,_0x2110e8,_0x5ed40a,_0x2f3f82,_0x3350c9){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x32cab1={};const _0x3a2f0c=(0x0,create_no_new_messages_timeout_1[a7_0x473c('0x24')])();const _0x57903b=new waiter_1[(a7_0x473c('0x1'))]();while(!![]){if(environment_1['VERBOSE_LOGGING']){output[a7_0x473c('0x37')]({'title':a7_0x473c('0x39')});}yield _0x57903b[a7_0x473c('0x34')]();const _0x5d3168=yield _0x335fb8[a7_0x473c('0x3d')](_0x5ed40a);if(environment_1[a7_0x473c('0x2b')]){output[a7_0x473c('0x37')]({'title':'Status\x20update','bodyLines':[a7_0x473c('0x3')+_0x5ed40a,'executionStatus:\x20'+_0x5d3168[a7_0x473c('0x52')],a7_0x473c('0x8')+_0x5d3168['completedTasks']['length'],a7_0x473c('0x17')+_0x5d3168['criticalErrorMessage']]});}if(_0x5d3168['criticalErrorMessage']){output[a7_0x473c('0x63')]({'title':a7_0x473c('0x1d'),'bodyLines':[a7_0x473c('0x31'),_0x5d3168[a7_0x473c('0x23')]]});process[a7_0x473c('0x1a')](0x1);}_0x3a2f0c(_0x5d3168[a7_0x473c('0x27')][a7_0x473c('0x48')]);for(const _0x432195 of _0x5d3168[a7_0x473c('0x27')]){if(_0x32cab1[_0x432195[a7_0x473c('0x6')]])continue;yield processTask(_0x128238,_0xb05f43,_0x3350c9,_0x2110e8,_0x2f3f82,_0x432195);_0x57903b[a7_0x473c('0x40')]();_0x32cab1[_0x432195[a7_0x473c('0x6')]]=!![];}if(_0x5d3168['executionStatus']===a7_0x473c('0x21')){return{'commandStatus':_0x5d3168[a7_0x473c('0x2d')],'runUrl':_0x5d3168['runUrl']};}}});}function processTask(_0x4c010c,_0x538c3c,_0x53e1c7,_0x5f22fd,_0x1a02e1,_0x192c48){return __awaiter(this,void 0x0,void 0x0,function*(){if(environment_1['VERBOSE_LOGGING']){output['note']({'title':'Processing\x20task\x20'+_0x192c48['taskId']});}const _0x2604c6=_0x1a02e1[a7_0x473c('0x53')](_0x4a91ca=>_0x192c48[a7_0x473c('0x6')]===_0x4a91ca['id']);if(!_0x2604c6){throw new Error(a7_0x473c('0x2a')+_0x192c48['taskId']);}if(environment_1[a7_0x473c('0x2b')]){output[a7_0x473c('0x37')]({'title':a7_0x473c('0x38')+_0x192c48[a7_0x473c('0xd')]});}yield _0x4c010c['retrieve'](_0x192c48['hash'],_0x192c48['url'],_0x5f22fd[a7_0x473c('0x58')]||'./node_modules/.cache/nx');const _0x3a9d2b=yield _0x538c3c['get'](Object['assign'](Object[a7_0x473c('0x0')]({},_0x2604c6),{'hash':_0x192c48[a7_0x473c('0x26')]}));const _0x28acec=getOutputs(_0x53e1c7[a7_0x473c('0x41')][a7_0x473c('0x12')],_0x2604c6);if(environment_1[a7_0x473c('0x2b')]){output['note']({'title':a7_0x473c('0x65'),'bodyLines':_0x28acec});}yield _0x538c3c[a7_0x473c('0x50')](_0x192c48[a7_0x473c('0x26')],_0x3a9d2b,_0x28acec);output[a7_0x473c('0x4e')](getCommand(_0x2604c6));process['stdout']['write'](_0x3a9d2b[a7_0x473c('0x51')]);output[a7_0x473c('0x5f')]();});}function getCommand(_0x24b2c8){const _0x3e04bb=unparse(_0x24b2c8[a7_0x473c('0x1b')]||{});const _0x4d479b=_0x24b2c8[a7_0x473c('0x47')][a7_0x473c('0x3e')]?':'+_0x24b2c8[a7_0x473c('0x47')][a7_0x473c('0x3e')]:'';return['nx',a7_0x473c('0x13'),_0x24b2c8[a7_0x473c('0x47')][a7_0x473c('0x69')]+':'+_0x24b2c8[a7_0x473c('0x47')]['target']+_0x4d479b,..._0x3e04bb]['join']('\x20');}const nxCloudDistributedTasksRunner=(_0x54ec2e,_0x252c70,_0x20a840)=>__awaiter(void 0x0,void 0x0,void 0x0,function*(){if(environment_1[a7_0x473c('0x2b')]){output[a7_0x473c('0x37')]({'title':a7_0x473c('0x55')});}_0x252c70[a7_0x473c('0x2f')]=new NoopLifeCycle();const _0x596e84=(0x0,environment_1['getRunGroup'])();if(!_0x596e84){(0x0,print_run_group_error_1[a7_0x473c('0xa')])();return process[a7_0x473c('0x1a')](0x1);}const _0x5c3446=new e2e_encryption_1[(a7_0x473c('0x18'))](environment_1[a7_0x473c('0x2')]||_0x252c70['encryptionKey']);const _0x1878a8=new file_storage_1['FileStorage'](_0x5c3446);const _0x4188f0=new Cache(_0x252c70);const _0x32eaab=new distributed_execution_api_1[(a7_0x473c('0xc'))](_0x252c70);try{const _0x52f8c4=yield runDistributedExecution(_0x32eaab,_0x252c70,_0x20a840,_0x1878a8,_0x4188f0,_0x596e84,_0x54ec2e);if(_0x52f8c4[a7_0x473c('0x2d')]===0x0){output[a7_0x473c('0x2e')]({'title':a7_0x473c('0x4f'),'bodyLines':[a7_0x473c('0x35')+_0x52f8c4[a7_0x473c('0x45')]]});}else{output[a7_0x473c('0x63')]({'title':a7_0x473c('0x64'),'bodyLines':[a7_0x473c('0x35')+_0x52f8c4[a7_0x473c('0x45')]]});}yield(0x0,metric_logger_1[a7_0x473c('0x30')])(_0x252c70);process[a7_0x473c('0x1a')](_0x52f8c4[a7_0x473c('0x2d')]);}catch(_0x203526){output[a7_0x473c('0x63')]({'title':a7_0x473c('0x5e'),'bodyLines':[_0x203526[a7_0x473c('0x4b')]]});if(_0x203526[a7_0x473c('0x28')]){console[a7_0x473c('0x2c')](_0x203526[a7_0x473c('0x28')]);}else{console[a7_0x473c('0x2c')](_0x203526);}try{yield _0x32eaab[a7_0x473c('0x11')](_0x596e84,a7_0x473c('0x67')+_0x203526[a7_0x473c('0x4b')]+'\x22');}finally{process[a7_0x473c('0x1a')](0x1);}}});exports[a7_0x473c('0x4a')]=nxCloudDistributedTasksRunner;class TaskOrderer{constructor(_0x1ad6fc,_0x45141b){this[a7_0x473c('0x41')]=_0x1ad6fc;this[a7_0x473c('0x3b')]=_0x45141b;}[a7_0x473c('0x46')](_0x322e8c){if(_0x322e8c[a7_0x473c('0x48')]===0x0)return[];const _0x227ad0=[];const _0x2aa476=this[a7_0x473c('0x19')](_0x322e8c);const _0x398d0e=new Set(_0x322e8c[a7_0x473c('0x54')](_0x2f2a2f=>_0x2f2a2f['id']));let _0x3b6330=0x0;while(_0x398d0e[a7_0x473c('0x60')]>0x0){const _0x4f5b22=_0x227ad0[_0x3b6330]=[];for(const _0x57065b of _0x398d0e){let _0x3d0674=!![];for(const _0x39ebb8 of _0x2aa476[a7_0x473c('0x57')][_0x57065b]){if(_0x398d0e[a7_0x473c('0x10')](_0x39ebb8)){_0x3d0674=![];break;}}if(!_0x3d0674){continue;}const _0xbe1e7=_0x2aa476[a7_0x473c('0x32')][_0x57065b];_0x4f5b22['push'](_0xbe1e7);}for(const _0x50e006 of _0x4f5b22){_0x398d0e[a7_0x473c('0x68')](_0x50e006['id']);}_0x3b6330++;}return _0x227ad0;}['createTaskGraph'](_0x1a0440){const _0x1fdece=new TaskGraphCreator(this[a7_0x473c('0x41')],this[a7_0x473c('0x3b')]);return _0x1fdece[a7_0x473c('0x19')](_0x1a0440);}}class TaskGraphCreator{constructor(_0x1c6c94,_0x395fb9){this[a7_0x473c('0x41')]=_0x1c6c94;this[a7_0x473c('0x3b')]=_0x395fb9;}[a7_0x473c('0x19')](_0x7b0014){const _0x4dff03={'roots':[],'tasks':{},'dependencies':{}};for(const _0x3d48aa of _0x7b0014){this[a7_0x473c('0x5d')](_0x3d48aa,_0x4dff03);const _0x5c45a6=getDependencyConfigs(_0x3d48aa['target'],this['defaultTargetDependencies'],this['projectGraph']);if(!_0x5c45a6){continue;}this[a7_0x473c('0x3c')](_0x3d48aa,_0x5c45a6,_0x7b0014,_0x4dff03);}_0x4dff03[a7_0x473c('0x25')]=Object[a7_0x473c('0x43')](_0x4dff03['dependencies'])[a7_0x473c('0x5b')](_0x446df2=>_0x4dff03['dependencies'][_0x446df2][a7_0x473c('0x48')]===0x0);return _0x4dff03;}[a7_0x473c('0x3c')](_0x20ba9f,_0x5d72e6,_0x441022,_0x530cb9){for(const _0x567cd9 of _0x5d72e6){if(_0x567cd9['projects']==='self'){for(const _0x19457e of _0x441022){if(_0x19457e[a7_0x473c('0x47')][a7_0x473c('0x69')]===_0x20ba9f['target']['project']&&_0x19457e['target'][a7_0x473c('0x47')]===_0x567cd9[a7_0x473c('0x47')]){_0x530cb9[a7_0x473c('0x57')][_0x20ba9f['id']]['push'](_0x19457e['id']);}}}else if(_0x567cd9[a7_0x473c('0x44')]===a7_0x473c('0x57')){const _0x28b06e=new Set();this[a7_0x473c('0x14')](_0x20ba9f[a7_0x473c('0x47')][a7_0x473c('0x69')],_0x567cd9[a7_0x473c('0x47')],_0x441022,_0x530cb9,_0x20ba9f['id'],_0x28b06e);}}}[a7_0x473c('0x14')](_0x1526ea,_0x158282,_0xaac9f3,_0x58b985,_0x5331a9,_0x2c1986){_0x2c1986[a7_0x473c('0x20')](_0x1526ea);const _0x48a8ee=this['projectGraph'][a7_0x473c('0x57')][_0x1526ea];if(_0x48a8ee){const _0x1255e2=_0x48a8ee['map'](_0x44852d=>_0x44852d[a7_0x473c('0x47')]);for(const _0xb24f9d of _0x1255e2){if(_0x2c1986[a7_0x473c('0x10')](_0xb24f9d)){continue;}const _0x54d9cb=this[a7_0x473c('0x61')]({'project':_0xb24f9d,'target':_0x158282},_0xaac9f3);if(_0x54d9cb){if(_0x58b985[a7_0x473c('0x57')][_0x5331a9][a7_0x473c('0x16')](_0x54d9cb['id'])===-0x1){_0x58b985[a7_0x473c('0x57')][_0x5331a9][a7_0x473c('0x22')](_0x54d9cb['id']);}}else{this[a7_0x473c('0x14')](_0xb24f9d,_0x158282,_0xaac9f3,_0x58b985,_0x5331a9,_0x2c1986);}}}}['findTask']({project,target},_0x46417f){return _0x46417f[a7_0x473c('0x53')](_0xbfa14d=>_0xbfa14d[a7_0x473c('0x47')][a7_0x473c('0x69')]===project&&_0xbfa14d[a7_0x473c('0x47')][a7_0x473c('0x47')]===target);}[a7_0x473c('0x5d')](_0x19e59f,_0x55d12f){_0x55d12f[a7_0x473c('0x32')][_0x19e59f['id']]=_0x19e59f;_0x55d12f[a7_0x473c('0x57')][_0x19e59f['id']]=[];}}exports[a7_0x473c('0x5')]=TaskGraphCreator;function getDefaultDependencyConfigs(_0x5f3048,_0x2b6922){var _0x3812c9,_0x2c3c30;const _0x5a461c=(_0x3812c9=_0x5f3048[a7_0x473c('0x3a')])!==null&&_0x3812c9!==void 0x0?_0x3812c9:{};const _0x5e400f=_0x2b6922?(_0x2c3c30=_0x2b6922[a7_0x473c('0x1f')])!==null&&_0x2c3c30!==void 0x0?_0x2c3c30:[a7_0x473c('0x4d')]:[];for(const _0x1d9b16 of _0x5e400f){_0x5a461c[_0x1d9b16]=_0x5a461c[_0x1d9b16]||[];_0x5a461c[_0x1d9b16][a7_0x473c('0x22')]({'target':_0x1d9b16,'projects':a7_0x473c('0x57')});}return _0x5a461c;}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TaskGraphCreator = exports.nxCloudDistributedTasksRunner = void 0;
const stripJsonComments = require("strip-json-comments");
const fs_1 = require("fs");
const distributed_execution_api_1 = require("./distributed-execution.api");
const file_storage_1 = require("../../file-storage/file-storage");
const e2e_encryption_1 = require("../../file-storage/e2e-encryption");
const waiter_1 = require("../../../utilities/waiter");
const environment_1 = require("../../../utilities/environment");
const print_run_group_error_1 = require("../../error/print-run-group-error");
const create_no_new_messages_timeout_1 = require("../../../utilities/create-no-new-messages-timeout");
const metric_logger_1 = require("../../../utilities/metric-logger");
const error_reporter_api_1 = require("../../api/error-reporter.api");
const { output, workspaceRoot, getDependencyConfigs, getOutputs, unparse, Cache, } = require('../../../utilities/nx-imports');
class NoopLifeCycle {
scheduleTask(task) { }
startTask(task) { }
endTask(task, code) { }
}
function runDistributedExecution(api, options, context, fileStorage, cache, runGroup, tasks) {
return __awaiter(this, void 0, void 0, function* () {
const nxjson = JSON.parse(stripJsonComments((0, fs_1.readFileSync)(`${workspaceRoot}/nx.json`).toString()));
const stages = new TaskOrderer(context.projectGraph, getDefaultDependencyConfigs(nxjson, options)).splitTasksIntoStages(tasks);
const id = yield api.start((0, distributed_execution_api_1.createStartRequest)(runGroup, stages, options));
return yield processTasks(api, fileStorage, cache, options, id, tasks, context);
});
}
function processTasks(api, fileStorage, cache, options, executionId, tasks, context) {
return __awaiter(this, void 0, void 0, function* () {
const processedTasks = {};
const failIfNumberOfCompletedTasksDoesNotChangeIn30Mins = (0, create_no_new_messages_timeout_1.createNoNewMessagesTimeout)();
const waiter = new waiter_1.Waiter();
while (true) {
if (environment_1.VERBOSE_LOGGING) {
output.note({
title: 'Waiting...',
});
}
yield waiter.wait();
const r = yield api.status(executionId);
if (environment_1.VERBOSE_LOGGING) {
output.note({
title: `Status update`,
bodyLines: [
`executionId: ${executionId}`,
`executionStatus: ${r.executionStatus}`,
`number of completed tasks: ${r.completedTasks.length}`,
`error: ${r.criticalErrorMessage}`,
],
});
}
if (r.criticalErrorMessage) {
output.error({
title: 'Distributed Execution Terminated',
bodyLines: ['Error:', r.criticalErrorMessage],
});
process.exit(1);
}
failIfNumberOfCompletedTasksDoesNotChangeIn30Mins(r.completedTasks.length);
for (const t of r.completedTasks) {
if (processedTasks[t.taskId])
continue;
yield processTask(fileStorage, cache, context, options, tasks, t);
waiter.reset();
processedTasks[t.taskId] = true;
}
if (r.executionStatus === 'COMPLETED') {
return { commandStatus: r.commandStatus, runUrl: r.runUrl };
}
}
});
}
function processTask(fileStorage, cache, context, options, tasks, completedTask) {
return __awaiter(this, void 0, void 0, function* () {
if (environment_1.VERBOSE_LOGGING) {
output.note({
title: `Processing task ${completedTask.taskId}`,
});
}
const matchingTask = tasks.find((tt) => completedTask.taskId === tt.id);
if (!matchingTask) {
throw new Error(`Found unknown task: ${completedTask.taskId}`);
}
if (environment_1.VERBOSE_LOGGING) {
output.note({
title: `Retrieving artifacts from ${completedTask.url}`,
});
}
yield fileStorage.retrieve(completedTask.hash, completedTask.url, options.cacheDirectory || './node_modules/.cache/nx');
const cachedResult = yield cache.get(Object.assign(Object.assign({}, matchingTask), { hash: completedTask.hash }));
const outputs = getOutputs(context.projectGraph.nodes, matchingTask);
if (environment_1.VERBOSE_LOGGING) {
output.note({
title: `Extracting artifacts`,
bodyLines: outputs,
});
}
yield cache.copyFilesFromCache(completedTask.hash, cachedResult, outputs);
output.logCommand(getCommand(matchingTask));
process.stdout.write(cachedResult.terminalOutput);
output.addVerticalSeparator();
});
}
function getCommand(task) {
const args = unparse(task.overrides || {});
const config = task.target.configuration
? `:${task.target.configuration}`
: '';
return [
'nx',
'run',
`${task.target.project}:${task.target.target}${config}`,
...args,
].join(' ');
}
const nxCloudDistributedTasksRunner = (tasks, options, context) => __awaiter(void 0, void 0, void 0, function* () {
if (environment_1.VERBOSE_LOGGING) {
output.note({
title: 'Starting distributed command execution',
});
}
options.lifeCycle = new NoopLifeCycle();
const runGroup = (0, environment_1.getRunGroup)();
if (!runGroup) {
(0, print_run_group_error_1.printRunGroupError)();
return process.exit(1);
}
const encryption = new e2e_encryption_1.E2EEncryption(environment_1.ENCRYPTION_KEY || options.encryptionKey);
const errorReporter = new error_reporter_api_1.ErrorReporterApi(options);
const fileStorage = new file_storage_1.FileStorage(encryption, errorReporter, true);
const cache = new Cache(options);
const api = new distributed_execution_api_1.DistributedExecutionApi(options);
try {
const r = yield runDistributedExecution(api, options, context, fileStorage, cache, runGroup, tasks);
if (r.commandStatus === 0) {
output.success({
title: 'Successfully completed running the command.',
bodyLines: [`See run details at ${r.runUrl}`],
});
}
else {
output.error({
title: 'Command execution failed.',
bodyLines: [`See run details at ${r.runUrl}`],
});
}
yield (0, metric_logger_1.submitRunMetrics)(options);
process.exit(r.commandStatus);
}
catch (e) {
output.error({
title: 'Unable to complete a run.',
bodyLines: [e.message],
});
if (e.axiosException) {
console.log(e.axiosException);
}
else {
console.log(e);
}
try {
yield api.completeRunGroupWithError(runGroup, `Main job terminated with an error: "${e.message}"`);
}
finally {
process.exit(1);
}
}
});
exports.nxCloudDistributedTasksRunner = nxCloudDistributedTasksRunner;
class TaskOrderer {
constructor(projectGraph, defaultTargetDependencies) {
this.projectGraph = projectGraph;
this.defaultTargetDependencies = defaultTargetDependencies;
}
splitTasksIntoStages(tasks) {
if (tasks.length === 0)
return [];
const stages = [];
const taskGraph = this.createTaskGraph(tasks);
const notStagedTaskIds = new Set(tasks.map((t) => t.id));
let stageIndex = 0;
// Loop through tasks and try to stage them. As tasks are staged, they are removed from the loop
while (notStagedTaskIds.size > 0) {
const currentStage = (stages[stageIndex] = []);
for (const taskId of notStagedTaskIds) {
let ready = true;
for (const dependency of taskGraph.dependencies[taskId]) {
if (notStagedTaskIds.has(dependency)) {
// dependency has not been staged yet, this task is not ready to be staged.
ready = false;
break;
}
}
// Some dependency still has not been staged, skip it for now, it will be processed again
if (!ready) {
continue;
}
// All the dependencies have been staged, let's stage it.
const task = taskGraph.tasks[taskId];
currentStage.push(task);
}
// Remove the entire new stage of tasks from the list
for (const task of currentStage) {
notStagedTaskIds.delete(task.id);
}
stageIndex++;
}
return stages;
}
createTaskGraph(tasks) {
const t = new TaskGraphCreator(this.projectGraph, this.defaultTargetDependencies);
return t.createTaskGraph(tasks);
}
}
class TaskGraphCreator {
constructor(projectGraph, defaultTargetDependencies) {
this.projectGraph = projectGraph;
this.defaultTargetDependencies = defaultTargetDependencies;
}
createTaskGraph(tasks) {
const graph = {
roots: [],
tasks: {},
dependencies: {},
};
for (const task of tasks) {
this.addTaskToGraph(task, graph);
const dependencyConfigs = getDependencyConfigs(task.target, this.defaultTargetDependencies, this.projectGraph);
if (!dependencyConfigs) {
continue;
}
this.addTaskDependencies(task, dependencyConfigs, tasks, graph);
}
graph.roots = Object.keys(graph.dependencies).filter((k) => graph.dependencies[k].length === 0);
return graph;
}
addTaskDependencies(task, dependencyConfigs, tasks, graph) {
for (const dependencyConfig of dependencyConfigs) {
if (dependencyConfig.projects === 'self') {
for (const t of tasks) {
if (t.target.project === task.target.project &&
t.target.target === dependencyConfig.target) {
graph.dependencies[task.id].push(t.id);
}
}
}
else if (dependencyConfig.projects === 'dependencies') {
const seen = new Set();
this.addDependencies(task.target.project, dependencyConfig.target, tasks, graph, task.id, seen);
}
}
}
addDependencies(project, target, tasks, graph, taskId, seen) {
seen.add(project);
const dependencies = this.projectGraph.dependencies[project];
if (dependencies) {
const projectDependencies = dependencies.map((dependency) => dependency.target);
for (const projectDependency of projectDependencies) {
if (seen.has(projectDependency)) {
continue;
}
const dependency = this.findTask({ project: projectDependency, target }, tasks);
if (dependency) {
if (graph.dependencies[taskId].indexOf(dependency.id) === -1) {
graph.dependencies[taskId].push(dependency.id);
}
}
else {
this.addDependencies(projectDependency, target, tasks, graph, taskId, seen);
}
}
}
}
findTask({ project, target }, tasks) {
return tasks.find((t) => t.target.project === project && t.target.target === target);
}
addTaskToGraph(task, graph) {
graph.tasks[task.id] = task;
graph.dependencies[task.id] = [];
}
}
exports.TaskGraphCreator = TaskGraphCreator;
function getDefaultDependencyConfigs(nxJson, runnerOptions) {
var _a, _b;
const defaults = (_a = nxJson.targetDependencies) !== null && _a !== void 0 ? _a : {};
const strictlyOrderedTargets = runnerOptions
? (_b = runnerOptions.strictlyOrderedTargets) !== null && _b !== void 0 ? _b : ['build']
: [];
// Strictly Ordered Targets depend on their dependencies
for (const target of strictlyOrderedTargets) {
defaults[target] = defaults[target] || [];
defaults[target].push({
target,
projects: 'dependencies',
});
}
return defaults;
}
//# sourceMappingURL=distributed-execution.runner.js.map
{
"name": "nx-cloud",
"version": "14.0.5",
"version": "14.0.6-beta.1",
"description": "Nx Cloud plugin for Nx",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc