@nrwl/nx-cloud 15.3.4 → 15.4.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/lib/core/api/error-reporter.api.js +36 -1
  2. package/lib/core/api/run-group.api.js +73 -1
  3. package/lib/core/file-storage/file-storage.js +4 -2
  4. package/lib/core/file-storage/file-storage.js.map +1 -1
  5. package/lib/core/models/cloud-task-runner-options.d.ts +1 -1
  6. package/lib/core/runners/cloud-enabled/cloud-enabled-life-cycle.js +93 -1
  7. package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js +320 -1
  8. package/lib/core/runners/cloud-enabled/cloud-remote-cache.js +133 -1
  9. package/lib/core/runners/cloud-enabled/cloud-run.api.js +174 -1
  10. package/lib/core/runners/cloud-enabled/cloud-run.api.js.map +1 -1
  11. package/lib/core/runners/cloud-enabled/id-generator.js +16 -1
  12. package/lib/core/runners/distributed-agent/distributed-agent.api.js +93 -1
  13. package/lib/core/runners/distributed-agent/distributed-agent.impl.js +157 -1
  14. package/lib/core/runners/distributed-agent/execute-tasks.js +114 -1
  15. package/lib/core/runners/distributed-agent/invoke-tasks-using-nx-imperative-api.js +58 -1
  16. package/lib/core/runners/distributed-agent/invoke-tasks-using-run-many.js +97 -1
  17. package/lib/core/runners/distributed-execution/distributed-execution.api.js +152 -1
  18. package/lib/core/runners/distributed-execution/distributed-execution.runner.js +118 -1
  19. package/lib/core/runners/distributed-execution/process-task.js +45 -1
  20. package/lib/core/runners/distributed-execution/process-tasks.js +67 -1
  21. package/lib/core/runners/distributed-execution/split-task-graph-into-stages.js +37 -1
  22. package/lib/core/runners/distributed-execution/task-graph-creator.js +100 -1
  23. package/lib/utilities/axios.js +8 -2
  24. package/lib/utilities/axios.js.map +1 -1
  25. package/lib/utilities/environment.d.ts +1 -1
  26. package/lib/utilities/environment.js +2 -0
  27. package/lib/utilities/environment.js.map +1 -1
  28. package/package.json +1 -1
@@ -1 +1,157 @@
1
- const a6_0x4d12=['CIRCLE_STAGE','canDetectRunGroup','FileStorage','.lock','Duplicate\x20Agent\x20ID\x20Detected','/lockfiles','parse','getBranch','invokeTasksUsingNxImperativeApi','toString','catch','writeFileSync','filter','getRunGroup','CIRCLE_JOB','map','This\x20can\x20also\x20be\x20a\x20false\x20positive\x20caused\x20by\x20agents\x20that\x20did\x20not\x20shut\x20down\x20correctly.','Other\x20Nx\x20Cloud\x20Agents\x20Detected','E2EEncryption','getCIExecutionId','exit','../../../utilities/nx-imports','../../../utilities/dte-artifact-storage','../../file-storage/file-storage','SIGINT','SIGTERM','executeTasks','We\x20have\x20detected\x20another\x20agent\x20with\x20this\x20ID\x20running\x20in\x20this\x20workspace.\x20This\x20should\x20not\x20happen.','throw','includes','join','invokeTasksUsingRunMany','existsSync','End\x20all\x20currently\x20running\x20agents,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22,\x20and\x20try\x20again.','split','../../../utilities/environment','__awaiter','../../error/print-invalid-runner-error','Critical\x20Error\x20in\x20Agent:\x20\x22','getNxCacheDirectory','startAgent','error','random','warn','unlinkSync','apply','env','../../error/print-cacheable-targets-error','yargs-parser','options','printRunGroupError','printCacheableTargetsError','./invoke-tasks-using-run-many','./invoke-tasks-using-nx-imperative-api','next','completeRunGroupWithError','then','length','message','value','We\x20have\x20detected\x20other\x20agents\x20running\x20in\x20this\x20workspace.\x20This\x20can\x20cause\x20unexpected\x20behavior.','mkdirSync','NX_AGENT_NAME','/nx.json','__esModule','note','some','runner','targets','DistributedAgentApi','cacheableOperations','argv','../../error/print-run-group-error','Agent\x20was\x20terminated\x20via\x20SIGINT','Agent\x20','dte-agent','done','Starting\x20an\x20agent\x20for\x20running\x20Nx\x20tasks'];(function(_0x59a327,_0x4d12cb){const _0x106470=function(_0x31aa1c){while(--_0x31aa1c){_0x59a327['push'](_0x59a327['shift']());}};_0x106470(++_0x4d12cb);}(a6_0x4d12,0x1dc));const a6_0x1064=function(_0x59a327,_0x4d12cb){_0x59a327=_0x59a327-0x0;let _0x106470=a6_0x4d12[_0x59a327];return _0x106470;};'use strict';var __awaiter=this&&this[a6_0x1064('0x1c')]||function(_0x3de4dd,_0xa201d5,_0x2a7b69,_0x36d515){function _0xf06f58(_0x306d03){return _0x306d03 instanceof _0x2a7b69?_0x306d03:new _0x2a7b69(function(_0x273ec2){_0x273ec2(_0x306d03);});}return new(_0x2a7b69||(_0x2a7b69=Promise))(function(_0x2388ad,_0x5ae366){function _0x3ffdb7(_0x5f4a78){try{_0x3ca02d(_0x36d515[a6_0x1064('0x2e')](_0x5f4a78));}catch(_0x340549){_0x5ae366(_0x340549);}}function _0x28969f(_0x5c9d26){try{_0x3ca02d(_0x36d515[a6_0x1064('0x14')](_0x5c9d26));}catch(_0x54ebaf){_0x5ae366(_0x54ebaf);}}function _0x3ca02d(_0x1201f0){_0x1201f0[a6_0x1064('0x44')]?_0x2388ad(_0x1201f0[a6_0x1064('0x33')]):_0xf06f58(_0x1201f0[a6_0x1064('0x33')])['then'](_0x3ffdb7,_0x28969f);}_0x3ca02d((_0x36d515=_0x36d515[a6_0x1064('0x25')](_0x3de4dd,_0xa201d5||[]))[a6_0x1064('0x2e')]());});};Object['defineProperty'](exports,a6_0x1064('0x38'),{'value':!![]});exports['startAgent']=void 0x0;const fs_1=require('fs');const stripJsonComments=require('strip-json-comments');const yargsParser=require(a6_0x1064('0x28'));const environment_1=require(a6_0x1064('0x1b'));const metric_logger_1=require('../../../utilities/metric-logger');const print_cacheable_targets_error_1=require(a6_0x1064('0x27'));const print_invalid_runner_error_1=require(a6_0x1064('0x1d'));const print_run_group_error_1=require(a6_0x1064('0x40'));const distributed_agent_api_1=require('./distributed-agent.api');const execute_tasks_1=require('./execute-tasks');const dte_artifact_storage_1=require(a6_0x1064('0xe'));const file_storage_1=require(a6_0x1064('0xf'));const e2e_encryption_1=require('../../file-storage/e2e-encryption');const error_reporter_api_1=require('../../api/error-reporter.api');const invoke_tasks_using_run_many_1=require(a6_0x1064('0x2c'));const invoke_tasks_using_nx_imperative_api_1=require(a6_0x1064('0x2d'));const {output,initTasksRunner,workspaceRoot}=require(a6_0x1064('0xd'));const args=yargsParser(process[a6_0x1064('0x3f')],{'array':[a6_0x1064('0x3c')],'default':{}});if(args['targets']&&args['targets']['length']===0x1){args['targets']=args[a6_0x1064('0x3c')][0x0][a6_0x1064('0x1a')](',')[a6_0x1064('0x7')](_0x22a602=>_0x22a602['trim']());}function startAgent(){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x61f48b=(0x0,environment_1[a6_0x1064('0x4d')])();const _0x4c9076=(0x0,environment_1[a6_0x1064('0x5')])();const _0xefd902=(0x0,environment_1[a6_0x1064('0xb')])();const _0x5a6635=(0x0,environment_1['getCIExecutionEnv'])();if(!(0x0,print_run_group_error_1[a6_0x1064('0x47')])(_0x4c9076,_0xefd902)){(0x0,print_run_group_error_1[a6_0x1064('0x2a')])();process[a6_0x1064('0xc')](0x1);}if(args[a6_0x1064('0x3c')]&&args[a6_0x1064('0x3c')][a6_0x1064('0x31')]){output[a6_0x1064('0x39')]({'title':'Starting\x20an\x20agent\x20for\x20running\x20Nx\x20target(s)\x20['+args[a6_0x1064('0x3c')][a6_0x1064('0x16')](',\x20')+']'});}else{output['note']({'title':a6_0x1064('0x45')});}const _0x543ba4=JSON[a6_0x1064('0x4c')](stripJsonComments((0x0,fs_1['readFileSync'])(workspaceRoot+a6_0x1064('0x37'))[a6_0x1064('0x1')]()))['tasksRunnerOptions']['default'];if(_0x543ba4[a6_0x1064('0x3b')]!=='@nrwl/nx-cloud'){(0x0,print_invalid_runner_error_1['printInvalidRunnerError'])();return process[a6_0x1064('0xc')](0x1);}const _0x1d94c6=_0x543ba4[a6_0x1064('0x29')];if(args[a6_0x1064('0x3c')]&&args[a6_0x1064('0x3c')][a6_0x1064('0x3a')](_0x221bf8=>{var _0x2837af;return!((_0x2837af=_0x1d94c6[a6_0x1064('0x3e')])===null||_0x2837af===void 0x0?void 0x0:_0x2837af['includes'](_0x221bf8));})){const _0x5e8154=args['targets'][a6_0x1064('0x4')](_0x427743=>{var _0x3c9777;return!((_0x3c9777=_0x1d94c6[a6_0x1064('0x3e')])===null||_0x3c9777===void 0x0?void 0x0:_0x3c9777[a6_0x1064('0x15')](_0x427743));});(0x0,print_cacheable_targets_error_1[a6_0x1064('0x2b')])(_0x5e8154);return process[a6_0x1064('0xc')](0x1);}const _0x30d707=getAgentName();const _0x18e3bc=new distributed_agent_api_1[(a6_0x1064('0x3d'))](_0x1d94c6,_0x61f48b,_0x4c9076,_0xefd902,_0x5a6635,_0x30d707);createAgentLockfileAndSetUpListeners(_0x18e3bc,_0x1d94c6,_0x30d707);const _0x1119ed=new e2e_encryption_1[(a6_0x1064('0xa'))](environment_1['ENCRYPTION_KEY']||_0x1d94c6['encryptionKey']);const _0x2160c6=new error_reporter_api_1['ErrorReporterApi'](_0x1d94c6);const _0x35130e=new dte_artifact_storage_1['DteArtifactStorage'](new file_storage_1[(a6_0x1064('0x48'))](_0x1119ed,_0x2160c6,_0x1d94c6,a6_0x1064('0x43')),(0x0,environment_1['getNxCacheDirectory'])(_0x1d94c6));const _0x154b50=initTasksRunner?yield(0x0,invoke_tasks_using_nx_imperative_api_1[a6_0x1064('0x0')])(_0x1d94c6):yield(0x0,invoke_tasks_using_run_many_1[a6_0x1064('0x17')])(_0x1d94c6);return(0x0,execute_tasks_1[a6_0x1064('0x12')])(_0x30d707,_0x18e3bc,_0x35130e,_0x154b50,args[a6_0x1064('0x3c')])[a6_0x1064('0x30')](_0x364d6f=>__awaiter(this,void 0x0,void 0x0,function*(){yield(0x0,metric_logger_1['submitRunMetrics'])(_0x1d94c6);return _0x364d6f;}))[a6_0x1064('0x2')](_0x718346=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x18e3bc[a6_0x1064('0x2f')](a6_0x1064('0x1e')+_0x718346[a6_0x1064('0x32')]+'\x22');throw _0x718346;}));});}exports[a6_0x1064('0x20')]=startAgent;function getAgentName(){if(process['env'][a6_0x1064('0x36')]!==undefined){return process[a6_0x1064('0x26')][a6_0x1064('0x36')];}else if(process[a6_0x1064('0x26')]['CIRCLECI']!==undefined&&process['env'][a6_0x1064('0x46')]){return process['env']['CIRCLE_STAGE'];}else if(process[a6_0x1064('0x26')]['CIRCLECI']!==undefined&&process[a6_0x1064('0x26')]['CIRCLE_JOB']){return process[a6_0x1064('0x26')][a6_0x1064('0x6')];}else{return a6_0x1064('0x42')+Math['floor'](Math[a6_0x1064('0x22')]()*0x186a0);}}function createAgentLockfileAndSetUpListeners(_0x2a888a,_0x51b161,_0x4487d8){const _0x48ee1e=(0x0,environment_1[a6_0x1064('0x1f')])(_0x51b161);const _0x35fd64=_0x48ee1e+a6_0x1064('0x4b');const _0x5b8eed=_0x35fd64+'/'+_0x4487d8+a6_0x1064('0x49');if(!(0x0,fs_1[a6_0x1064('0x18')])(_0x35fd64)){(0x0,fs_1[a6_0x1064('0x35')])(_0x35fd64,{'recursive':!![]});}const _0x49e834=(0x0,fs_1['readdirSync'])(_0x35fd64);if(_0x49e834[a6_0x1064('0x31')]){if(_0x49e834[a6_0x1064('0x15')](_0x4487d8+'.lock')){output[a6_0x1064('0x21')]({'title':a6_0x1064('0x4a'),'bodyLines':[a6_0x1064('0x13'),'',a6_0x1064('0x19')]});process[a6_0x1064('0xc')](0x1);}output[a6_0x1064('0x23')]({'title':a6_0x1064('0x9'),'bodyLines':[a6_0x1064('0x34'),'',a6_0x1064('0x8'),'If\x20you\x20believe\x20this\x20is\x20the\x20case,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22.']});}(0x0,fs_1[a6_0x1064('0x3')])(_0x5b8eed,'');process['on'](a6_0x1064('0xc'),_0x43efad=>{cleanupAgentLockfile(_0x5b8eed,_0x43efad);});process['on'](a6_0x1064('0x11'),()=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x2a888a[a6_0x1064('0x2f')]('Agent\x20was\x20terminated\x20via\x20SIGTERM');cleanupAgentLockfile(_0x5b8eed,0x1);}));process['on'](a6_0x1064('0x10'),()=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x2a888a['completeRunGroupWithError'](a6_0x1064('0x41'));cleanupAgentLockfile(_0x5b8eed,0x1);}));}function cleanupAgentLockfile(_0x14f6d9,_0xf296c){if((0x0,fs_1[a6_0x1064('0x18')])(_0x14f6d9)){(0x0,fs_1[a6_0x1064('0x24')])(_0x14f6d9);process[a6_0x1064('0xc')](_0xf296c);}}
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.startAgent = void 0;
13
+ const fs_1 = require("fs");
14
+ const stripJsonComments = require("strip-json-comments");
15
+ const yargsParser = require("yargs-parser");
16
+ const environment_1 = require("../../../utilities/environment");
17
+ const metric_logger_1 = require("../../../utilities/metric-logger");
18
+ const print_cacheable_targets_error_1 = require("../../error/print-cacheable-targets-error");
19
+ const print_invalid_runner_error_1 = require("../../error/print-invalid-runner-error");
20
+ const print_run_group_error_1 = require("../../error/print-run-group-error");
21
+ const distributed_agent_api_1 = require("./distributed-agent.api");
22
+ const execute_tasks_1 = require("./execute-tasks");
23
+ const dte_artifact_storage_1 = require("../../../utilities/dte-artifact-storage");
24
+ const file_storage_1 = require("../../file-storage/file-storage");
25
+ const e2e_encryption_1 = require("../../file-storage/e2e-encryption");
26
+ const error_reporter_api_1 = require("../../api/error-reporter.api");
27
+ const invoke_tasks_using_run_many_1 = require("./invoke-tasks-using-run-many");
28
+ const invoke_tasks_using_nx_imperative_api_1 = require("./invoke-tasks-using-nx-imperative-api");
29
+ const { output, initTasksRunner, workspaceRoot, } = require('../../../utilities/nx-imports');
30
+ const args = yargsParser(process.argv, {
31
+ array: ['targets'],
32
+ default: {},
33
+ });
34
+ // just in case someone passes the args with commas
35
+ // cf. https://github.com/yargs/yargs/issues/846
36
+ if (args.targets && args.targets.length === 1) {
37
+ args.targets = args.targets[0].split(',').map((x) => x.trim());
38
+ }
39
+ function startAgent() {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ const branch = (0, environment_1.getBranch)();
42
+ const runGroup = (0, environment_1.getRunGroup)();
43
+ const ciExecutionId = (0, environment_1.getCIExecutionId)();
44
+ const ciExecutionEnv = (0, environment_1.getCIExecutionEnv)();
45
+ if (!(0, print_run_group_error_1.canDetectRunGroup)(runGroup, ciExecutionId)) {
46
+ (0, print_run_group_error_1.printRunGroupError)();
47
+ process.exit(1);
48
+ }
49
+ if (args.targets && args.targets.length) {
50
+ output.note({
51
+ title: `Starting an agent for running Nx target(s) [${args.targets.join(', ')}]`,
52
+ });
53
+ }
54
+ else {
55
+ output.note({
56
+ title: 'Starting an agent for running Nx tasks',
57
+ });
58
+ }
59
+ const defaultRunnerConfig = JSON.parse(stripJsonComments((0, fs_1.readFileSync)(`${workspaceRoot}/nx.json`).toString())).tasksRunnerOptions.default;
60
+ if (defaultRunnerConfig.runner !== '@nrwl/nx-cloud') {
61
+ (0, print_invalid_runner_error_1.printInvalidRunnerError)();
62
+ return process.exit(1);
63
+ }
64
+ const options = defaultRunnerConfig.options;
65
+ if (args.targets &&
66
+ args.targets.some((target) => { var _a; return !((_a = options.cacheableOperations) === null || _a === void 0 ? void 0 : _a.includes(target)); })) {
67
+ const wrongTargets = args.targets.filter((target) => { var _a; return !((_a = options.cacheableOperations) === null || _a === void 0 ? void 0 : _a.includes(target)); });
68
+ (0, print_cacheable_targets_error_1.printCacheableTargetsError)(wrongTargets);
69
+ return process.exit(1);
70
+ }
71
+ const agentName = getAgentName();
72
+ const api = new distributed_agent_api_1.DistributedAgentApi(options, branch, runGroup, ciExecutionId, ciExecutionEnv, agentName);
73
+ createAgentLockfileAndSetUpListeners(api, options, agentName);
74
+ const encryption = new e2e_encryption_1.E2EEncryption(environment_1.ENCRYPTION_KEY || options.encryptionKey);
75
+ const errorReporter = new error_reporter_api_1.ErrorReporterApi(options);
76
+ const dteArtifactStorage = new dte_artifact_storage_1.DteArtifactStorage(new file_storage_1.FileStorage(encryption, errorReporter, options, 'dte-agent'), (0, environment_1.getNxCacheDirectory)(options));
77
+ const invokeTasks = initTasksRunner
78
+ ? yield (0, invoke_tasks_using_nx_imperative_api_1.invokeTasksUsingNxImperativeApi)(options)
79
+ : yield (0, invoke_tasks_using_run_many_1.invokeTasksUsingRunMany)(options);
80
+ return (0, execute_tasks_1.executeTasks)(agentName, api, dteArtifactStorage, invokeTasks, args.targets)
81
+ .then((res) => __awaiter(this, void 0, void 0, function* () {
82
+ yield (0, metric_logger_1.submitRunMetrics)(options);
83
+ return res;
84
+ }))
85
+ .catch((e) => __awaiter(this, void 0, void 0, function* () {
86
+ yield api.completeRunGroupWithError(`Critical Error in Agent: "${e.message}"`);
87
+ throw e;
88
+ }));
89
+ });
90
+ }
91
+ exports.startAgent = startAgent;
92
+ function getAgentName() {
93
+ if (process.env.NX_AGENT_NAME !== undefined) {
94
+ return process.env.NX_AGENT_NAME;
95
+ }
96
+ else if (process.env.CIRCLECI !== undefined && process.env.CIRCLE_STAGE) {
97
+ return process.env.CIRCLE_STAGE;
98
+ }
99
+ else if (process.env.CIRCLECI !== undefined && process.env.CIRCLE_JOB) {
100
+ return process.env.CIRCLE_JOB;
101
+ }
102
+ else {
103
+ return `Agent ${Math.floor(Math.random() * 100000)}`;
104
+ }
105
+ }
106
+ function createAgentLockfileAndSetUpListeners(api, options, agentName) {
107
+ const cacheDirectory = (0, environment_1.getNxCacheDirectory)(options);
108
+ const lockFileDirectory = `${cacheDirectory}/lockfiles`;
109
+ const lockFilePath = `${lockFileDirectory}/${agentName}.lock`;
110
+ if (!(0, fs_1.existsSync)(lockFileDirectory)) {
111
+ (0, fs_1.mkdirSync)(lockFileDirectory, { recursive: true });
112
+ }
113
+ // Check for other agents' lockfiles and warn if exist
114
+ const lockFiles = (0, fs_1.readdirSync)(lockFileDirectory);
115
+ if (lockFiles.length) {
116
+ // Check to make sure the current agent name is not in use (only 1/100000 ^ 2 chance of this)
117
+ if (lockFiles.includes(`${agentName}.lock`)) {
118
+ output.error({
119
+ title: 'Duplicate Agent ID Detected',
120
+ bodyLines: [
121
+ 'We have detected another agent with this ID running in this workspace. This should not happen.',
122
+ '',
123
+ 'End all currently running agents, run "npx nx-cloud clean-up-agents", and try again.',
124
+ ],
125
+ });
126
+ process.exit(1);
127
+ }
128
+ output.warn({
129
+ title: 'Other Nx Cloud Agents Detected',
130
+ bodyLines: [
131
+ 'We have detected other agents running in this workspace. This can cause unexpected behavior.',
132
+ '',
133
+ 'This can also be a false positive caused by agents that did not shut down correctly.',
134
+ 'If you believe this is the case, run "npx nx-cloud clean-up-agents".',
135
+ ],
136
+ });
137
+ }
138
+ (0, fs_1.writeFileSync)(lockFilePath, '');
139
+ process.on('exit', (code) => {
140
+ cleanupAgentLockfile(lockFilePath, code);
141
+ });
142
+ process.on('SIGTERM', () => __awaiter(this, void 0, void 0, function* () {
143
+ yield api.completeRunGroupWithError('Agent was terminated via SIGTERM');
144
+ cleanupAgentLockfile(lockFilePath, 1);
145
+ }));
146
+ process.on('SIGINT', () => __awaiter(this, void 0, void 0, function* () {
147
+ yield api.completeRunGroupWithError('Agent was terminated via SIGINT');
148
+ cleanupAgentLockfile(lockFilePath, 1);
149
+ }));
150
+ }
151
+ function cleanupAgentLockfile(lockFilePath, code) {
152
+ if ((0, fs_1.existsSync)(lockFilePath)) {
153
+ (0, fs_1.unlinkSync)(lockFilePath);
154
+ process.exit(code);
155
+ }
156
+ }
157
+ //# sourceMappingURL=distributed-agent.impl.js.map
@@ -1 +1,114 @@
1
- const a7_0x1a2c=['exit','url','defineProperty','completed','taskId','NO_FURTHER_TASKS_TO_RUN','note','maxParallel','error:\x20','join','No\x20new\x20messages\x20received\x20after\x20','Distributed\x20Execution\x20Terminated','completedStatusCode','retryDuring','executeTasks','__awaiter','\x20downloading\x20artifacts\x20for\x20','tasks','value','criticalErrorMessage','status:\x20','status','wait','createUnchangedValueTimeout','RUN_GROUP_COMPLETED','completedTasks','../../../utilities/nx-imports','\x20waiting...','number\x20of\x20tasks:\x20','executionId','executionId:\x20','map','VERBOSE_LOGGING','done','../../../utilities/environment','retrieveAndExtract','NO_MESSAGES_TIMEOUT','../../../utilities/create-unchanged-value-timeout','\x20Url:\x20','reset','\x20fetching\x20tasks...','then','length','next','\x20received\x20an\x20API\x20Response','completed:\x20','Error:','../../../utilities/waiter'];(function(_0x50a50d,_0x1a2cec){const _0x3dba43=function(_0x5e40ce){while(--_0x5e40ce){_0x50a50d['push'](_0x50a50d['shift']());}};_0x3dba43(++_0x1a2cec);}(a7_0x1a2c,0x1b7));const a7_0x3dba=function(_0x50a50d,_0x1a2cec){_0x50a50d=_0x50a50d-0x0;let _0x3dba43=a7_0x1a2c[_0x50a50d];return _0x3dba43;};'use strict';var __awaiter=this&&this[a7_0x3dba('0x8')]||function(_0x38a307,_0x264544,_0xa361ee,_0x503040){function _0x466847(_0x21fe8e){return _0x21fe8e instanceof _0xa361ee?_0x21fe8e:new _0xa361ee(function(_0x8383c2){_0x8383c2(_0x21fe8e);});}return new(_0xa361ee||(_0xa361ee=Promise))(function(_0x1fc469,_0x2afa59){function _0x2e0148(_0xd8ba){try{_0x5b6232(_0x503040['next'](_0xd8ba));}catch(_0xa702fa){_0x2afa59(_0xa702fa);}}function _0x5d731d(_0x4eea11){try{_0x5b6232(_0x503040['throw'](_0x4eea11));}catch(_0x262d43){_0x2afa59(_0x262d43);}}function _0x5b6232(_0x25f139){_0x25f139[a7_0x3dba('0x1a')]?_0x1fc469(_0x25f139[a7_0x3dba('0xb')]):_0x466847(_0x25f139[a7_0x3dba('0xb')])[a7_0x3dba('0x22')](_0x2e0148,_0x5d731d);}_0x5b6232((_0x503040=_0x503040['apply'](_0x38a307,_0x264544||[]))[a7_0x3dba('0x24')]());});};Object[a7_0x3dba('0x2b')](exports,'__esModule',{'value':!![]});exports[a7_0x3dba('0x7')]=void 0x0;const create_unchanged_value_timeout_1=require(a7_0x3dba('0x1e'));const environment_1=require(a7_0x3dba('0x1b'));const waiter_1=require(a7_0x3dba('0x28'));const {output}=require(a7_0x3dba('0x13'));function executeTasks(_0x158fbd,_0x125996,_0x5539f0,_0x49a551,_0x672899){return __awaiter(this,void 0x0,void 0x0,function*(){let _0x275c17=0x0;let _0x3e35b5=null;const _0xa0b0f9=(0x0,create_unchanged_value_timeout_1[a7_0x3dba('0x10')])({'title':a7_0x3dba('0x3')+environment_1['NO_MESSAGES_TIMEOUT']/0x3e8+'\x20seconds','timeout':environment_1[a7_0x3dba('0x1d')]});const _0x1683a5=new waiter_1['Waiter']();let _0x59a939=[];const _0x2af9a1=new Date();let _0x4dc9d3=![];const _0x473f54={};while(!![]){if(environment_1[a7_0x3dba('0x19')]){output[a7_0x3dba('0x2f')]({'title':_0x158fbd+a7_0x3dba('0x21')});}_0x3e35b5=yield _0x125996[a7_0x3dba('0xa')](_0x3e35b5?_0x3e35b5['executionId']:null,_0x275c17,_0x59a939,_0x672899);if(environment_1[a7_0x3dba('0x19')]){output[a7_0x3dba('0x2f')]({'title':_0x158fbd+a7_0x3dba('0x25'),'bodyLines':[a7_0x3dba('0x26')+_0x3e35b5['completed'],a7_0x3dba('0xd')+_0x3e35b5[a7_0x3dba('0xe')],'retryDuring:\x20'+_0x3e35b5[a7_0x3dba('0x6')],a7_0x3dba('0x17')+_0x3e35b5['executionId'],a7_0x3dba('0x15')+_0x3e35b5[a7_0x3dba('0xa')][a7_0x3dba('0x23')],a7_0x3dba('0x1')+_0x3e35b5[a7_0x3dba('0xc')],'maxParallel:\x20'+_0x3e35b5[a7_0x3dba('0x0')]]});}if(_0x3e35b5[a7_0x3dba('0xc')]){output['error']({'title':a7_0x3dba('0x4'),'bodyLines':[a7_0x3dba('0x27'),_0x3e35b5[a7_0x3dba('0xc')]]});process[a7_0x3dba('0x29')](0x0);}if((_0x3e35b5===null||_0x3e35b5===void 0x0?void 0x0:_0x3e35b5[a7_0x3dba('0x6')])&&(_0x3e35b5===null||_0x3e35b5===void 0x0?void 0x0:_0x3e35b5[a7_0x3dba('0x6')])!==0x0&&!_0x4dc9d3&&new Date()['getTime']()-_0x2af9a1['getTime']()>_0x3e35b5[a7_0x3dba('0x6')]){yield _0x1683a5[a7_0x3dba('0xf')]();continue;}if((_0x3e35b5===null||_0x3e35b5===void 0x0?void 0x0:_0x3e35b5[a7_0x3dba('0xe')])!==undefined){if(_0x3e35b5['status']===a7_0x3dba('0x11')||_0x3e35b5['status']===a7_0x3dba('0x2e')){return;}}else if(_0x3e35b5[a7_0x3dba('0x2c')]){return;}_0xa0b0f9(_0x3e35b5['tasks'][a7_0x3dba('0x18')](_0x31db59=>_0x31db59[a7_0x3dba('0x2d')])[a7_0x3dba('0x2')](''));if(!_0x3e35b5['executionId']){if(environment_1[a7_0x3dba('0x19')]){output[a7_0x3dba('0x2f')]({'title':_0x158fbd+a7_0x3dba('0x14')});}yield _0x1683a5['wait']();_0x275c17=0x0;_0x59a939=[];continue;}_0x1683a5[a7_0x3dba('0x20')]();_0x4dc9d3=!![];if(_0x3e35b5[a7_0x3dba('0x12')]){for(const _0xe129c0 of _0x3e35b5['completedTasks']){if(_0x473f54[_0xe129c0['taskId']])continue;output[a7_0x3dba('0x2f')]({'title':_0x158fbd+a7_0x3dba('0x9')+_0xe129c0['taskId']+'\x20Hash:\x20'+_0xe129c0['hash']+a7_0x3dba('0x1f')+_0xe129c0[a7_0x3dba('0x2a')]});yield _0x5539f0[a7_0x3dba('0x1c')](_0xe129c0['hash'],_0xe129c0[a7_0x3dba('0x2a')]);_0x473f54[_0xe129c0[a7_0x3dba('0x2d')]]=!![];}}const _0x4a19b1=yield _0x49a551(_0x3e35b5[a7_0x3dba('0x16')],_0x3e35b5[a7_0x3dba('0xa')],_0x3e35b5[a7_0x3dba('0x0')]);for(const _0x2928fe of _0x4a19b1[a7_0x3dba('0x12')]){_0x473f54[_0x2928fe['taskId']]=!![];}_0x275c17=_0x4a19b1[a7_0x3dba('0x5')];_0x59a939=_0x4a19b1['completedTasks'];}});}exports[a7_0x3dba('0x7')]=executeTasks;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.executeTasks = void 0;
13
+ const create_unchanged_value_timeout_1 = require("../../../utilities/create-unchanged-value-timeout");
14
+ const environment_1 = require("../../../utilities/environment");
15
+ const waiter_1 = require("../../../utilities/waiter");
16
+ const { output } = require('../../../utilities/nx-imports');
17
+ function executeTasks(agentName, api, dteArtifactStorage, invokeTasks, targets) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ let completedStatusCode = 0;
20
+ let apiResponse = null;
21
+ const failIfSameTasksAfterTimeout = (0, create_unchanged_value_timeout_1.createUnchangedValueTimeout)({
22
+ title: `No new messages received after ${environment_1.NO_MESSAGES_TIMEOUT / 1000} seconds`,
23
+ timeout: environment_1.NO_MESSAGES_TIMEOUT,
24
+ });
25
+ const waiter = new waiter_1.Waiter();
26
+ let completedTasks = [];
27
+ const startTime = new Date();
28
+ let executedAnyTasks = false;
29
+ const processedTasks = {};
30
+ while (true) {
31
+ if (environment_1.VERBOSE_LOGGING) {
32
+ output.note({
33
+ title: `${agentName} fetching tasks...`,
34
+ });
35
+ }
36
+ apiResponse = yield api.tasks(apiResponse ? apiResponse.executionId : null, completedStatusCode, completedTasks, targets);
37
+ if (environment_1.VERBOSE_LOGGING) {
38
+ output.note({
39
+ title: `${agentName} received an API Response`,
40
+ bodyLines: [
41
+ `completed: ${apiResponse.completed}`,
42
+ `status: ${apiResponse.status}`,
43
+ `retryDuring: ${apiResponse.retryDuring}`,
44
+ `executionId: ${apiResponse.executionId}`,
45
+ `number of tasks: ${apiResponse.tasks.length}`,
46
+ `error: ${apiResponse.criticalErrorMessage}`,
47
+ `maxParallel: ${apiResponse.maxParallel}`,
48
+ ],
49
+ });
50
+ }
51
+ if (apiResponse.criticalErrorMessage) {
52
+ output.error({
53
+ title: 'Distributed Execution Terminated',
54
+ bodyLines: ['Error:', apiResponse.criticalErrorMessage],
55
+ });
56
+ process.exit(0);
57
+ }
58
+ // run group is completed but it might be a rerun
59
+ // we will try several times before going further and
60
+ // completed the response
61
+ // we only do it if we haven't executed any tasks
62
+ if ((apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.retryDuring) &&
63
+ (apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.retryDuring) !== 0 &&
64
+ !executedAnyTasks &&
65
+ new Date().getTime() - startTime.getTime() > apiResponse.retryDuring) {
66
+ yield waiter.wait();
67
+ continue;
68
+ }
69
+ if ((apiResponse === null || apiResponse === void 0 ? void 0 : apiResponse.status) !== undefined) {
70
+ if (apiResponse.status === 'RUN_GROUP_COMPLETED' ||
71
+ apiResponse.status === 'NO_FURTHER_TASKS_TO_RUN') {
72
+ return;
73
+ }
74
+ }
75
+ else if (apiResponse.completed) {
76
+ return;
77
+ }
78
+ // if status is present that use the status instead of completed, otherwise use completed
79
+ failIfSameTasksAfterTimeout(apiResponse.tasks.map((t) => t.taskId).join(''));
80
+ if (!apiResponse.executionId) {
81
+ if (environment_1.VERBOSE_LOGGING) {
82
+ output.note({
83
+ title: `${agentName} waiting...`,
84
+ });
85
+ }
86
+ yield waiter.wait();
87
+ completedStatusCode = 0;
88
+ completedTasks = [];
89
+ continue;
90
+ }
91
+ waiter.reset();
92
+ executedAnyTasks = true;
93
+ if (apiResponse.completedTasks) {
94
+ for (const t of apiResponse.completedTasks) {
95
+ if (processedTasks[t.taskId])
96
+ continue;
97
+ output.note({
98
+ title: `${agentName} downloading artifacts for ${t.taskId} Hash: ${t.hash} Url: ${t.url}`,
99
+ });
100
+ yield dteArtifactStorage.retrieveAndExtract(t.hash, t.url);
101
+ processedTasks[t.taskId] = true;
102
+ }
103
+ }
104
+ const r = yield invokeTasks(apiResponse.executionId, apiResponse.tasks, apiResponse.maxParallel);
105
+ for (const t of r.completedTasks) {
106
+ processedTasks[t.taskId] = true;
107
+ }
108
+ completedStatusCode = r.completedStatusCode;
109
+ completedTasks = r.completedTasks;
110
+ }
111
+ });
112
+ }
113
+ exports.executeTasks = executeTasks;
114
+ //# sourceMappingURL=execute-tasks.js.map
@@ -1 +1,58 @@
1
- const a8_0x5db8=['invokeTasksUsingNxImperativeApi','done','unparse','hash','invoke','true','../../../utilities/nx-imports','values','throw','map','next','yargs-parser','NX_CLOUD_DISTRIBUTED_EXECUTION_ID','projectName','NX_STREAM_OUTPUT','params','NX_CACHE_FAILURES','__esModule','length','__awaiter','defineProperty','env','tasks','assign','target','taskId','configuration','status','taskGraph','value'];(function(_0x1a6a6,_0x5db829){const _0x3754ea=function(_0x162b22){while(--_0x162b22){_0x1a6a6['push'](_0x1a6a6['shift']());}};_0x3754ea(++_0x5db829);}(a8_0x5db8,0x64));const a8_0x3754=function(_0x1a6a6,_0x5db829){_0x1a6a6=_0x1a6a6-0x0;let _0x3754ea=a8_0x5db8[_0x1a6a6];return _0x3754ea;};'use strict';var __awaiter=this&&this[a8_0x3754('0x9')]||function(_0x4c6901,_0x67adfe,_0x372e5e,_0x15da2b){function _0xac354c(_0x28382e){return _0x28382e instanceof _0x372e5e?_0x28382e:new _0x372e5e(function(_0x56b010){_0x56b010(_0x28382e);});}return new(_0x372e5e||(_0x372e5e=Promise))(function(_0x5b1b0f,_0x528356){function _0xa67809(_0x4f57aa){try{_0x290faa(_0x15da2b['next'](_0x4f57aa));}catch(_0x16d91f){_0x528356(_0x16d91f);}}function _0x19ee67(_0x5f2c86){try{_0x290faa(_0x15da2b[a8_0x3754('0x1c')](_0x5f2c86));}catch(_0x54ccdd){_0x528356(_0x54ccdd);}}function _0x290faa(_0x29015a){_0x29015a[a8_0x3754('0x15')]?_0x5b1b0f(_0x29015a['value']):_0xac354c(_0x29015a[a8_0x3754('0x13')])['then'](_0xa67809,_0x19ee67);}_0x290faa((_0x15da2b=_0x15da2b['apply'](_0x4c6901,_0x67adfe||[]))[a8_0x3754('0x0')]());});};Object[a8_0x3754('0xa')](exports,a8_0x3754('0x7'),{'value':!![]});exports[a8_0x3754('0x14')]=void 0x0;const {initTasksRunner}=require(a8_0x3754('0x1a'));const parser=require(a8_0x3754('0x1'));const serializer_overrides_1=require('../../../utilities/serializer-overrides');function invokeTasksUsingNxImperativeApi(_0x545b66){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x3f13b7=yield initTasksRunner(_0x545b66);return(_0x2579a4,_0x1882fc,_0x4400ea)=>__awaiter(this,void 0x0,void 0x0,function*(){const _0x540123=_0x1882fc[a8_0x3754('0x1d')](_0x2f8549=>{const _0x2d7cd0=parser(_0x2f8549[a8_0x3754('0x5')],{'configuration':{'camel-case-expansion':![],'dot-notation':!![]}});const _0x10282e=(0x0,serializer_overrides_1[a8_0x3754('0x16')])(_0x2d7cd0);if(_0x2d7cd0['_'][a8_0x3754('0x8')]==0x0){delete _0x2d7cd0['_'];}return{'id':_0x2f8549[a8_0x3754('0xf')],'target':{'project':_0x2f8549[a8_0x3754('0x3')],'target':_0x2f8549[a8_0x3754('0xe')],'configuration':_0x2f8549[a8_0x3754('0x10')]},'overrides':Object[a8_0x3754('0xd')](Object[a8_0x3754('0xd')]({},_0x2d7cd0),{'__overrides_unparsed__':_0x10282e})};});process[a8_0x3754('0xb')][a8_0x3754('0x6')]=a8_0x3754('0x19');process[a8_0x3754('0xb')][a8_0x3754('0x2')]=_0x2579a4;process['env'][a8_0x3754('0x4')]=a8_0x3754('0x19');process[a8_0x3754('0xb')]['NX_PREFIX_OUTPUT']=a8_0x3754('0x19');const _0x400641=yield _0x3f13b7[a8_0x3754('0x18')]({'tasks':_0x540123,'parallel':_0x4400ea});const _0x53c882=Object[a8_0x3754('0x1b')](_0x400641[a8_0x3754('0x12')][a8_0x3754('0xc')]);return{'completedTasks':_0x53c882['map'](_0x398852=>({'taskId':_0x398852['id'],'hash':_0x398852[a8_0x3754('0x17')]})),'completedStatusCode':_0x400641[a8_0x3754('0x11')]};});});}exports['invokeTasksUsingNxImperativeApi']=invokeTasksUsingNxImperativeApi;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.invokeTasksUsingNxImperativeApi = void 0;
13
+ const { initTasksRunner } = require('../../../utilities/nx-imports');
14
+ const parser = require("yargs-parser");
15
+ const serializer_overrides_1 = require("../../../utilities/serializer-overrides");
16
+ function invokeTasksUsingNxImperativeApi(options) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ const tasksRunner = yield initTasksRunner(options);
19
+ return (executionId, tasksToExecute, parallel) => __awaiter(this, void 0, void 0, function* () {
20
+ const tasks = tasksToExecute.map((t) => {
21
+ const params = parser(t.params, {
22
+ configuration: {
23
+ 'camel-case-expansion': false,
24
+ 'dot-notation': true,
25
+ },
26
+ });
27
+ const unparsed = (0, serializer_overrides_1.unparse)(params);
28
+ if (params._.length == 0) {
29
+ delete params._;
30
+ }
31
+ return {
32
+ id: t.taskId,
33
+ target: {
34
+ project: t.projectName,
35
+ target: t.target,
36
+ configuration: t.configuration,
37
+ },
38
+ overrides: Object.assign(Object.assign({}, params), { __overrides_unparsed__: unparsed }),
39
+ };
40
+ });
41
+ process.env.NX_CACHE_FAILURES = 'true'; // this is only requires because of how we do uploads
42
+ process.env.NX_CLOUD_DISTRIBUTED_EXECUTION_ID = executionId;
43
+ process.env.NX_STREAM_OUTPUT = 'true';
44
+ process.env.NX_PREFIX_OUTPUT = 'true';
45
+ const r = yield tasksRunner.invoke({ tasks, parallel });
46
+ const completedTasks = Object.values(r.taskGraph.tasks);
47
+ return {
48
+ completedTasks: completedTasks.map((t) => ({
49
+ taskId: t.id,
50
+ hash: t.hash,
51
+ })),
52
+ completedStatusCode: r.status,
53
+ };
54
+ });
55
+ });
56
+ }
57
+ exports.invokeTasksUsingNxImperativeApi = invokeTasksUsingNxImperativeApi;
58
+ //# sourceMappingURL=invoke-tasks-using-nx-imperative-api.js.map
@@ -1 +1,97 @@
1
- const a9_0x3ba7=['then','assign','toString','note','Executing:\x20\x27','inherit','target','getNxCacheDirectory','true','push','done','execSync','length','next','unlinkSync','ignore','forEach','VERBOSE_LOGGING','throw','projectName','--configuration=','../../../utilities/nx-imports','invokeTasksUsingRunMany','__awaiter','DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE','npx\x20nx\x20run-many\x20--target=','configuration','join','/tasks-hashes-','child_process','__esModule','../../../utilities/environment','\x20--projects=','parse','projects','apply','params','readFileSync'];(function(_0x4ed579,_0x3ba7ce){const _0x66c2f6=function(_0x39e4b3){while(--_0x39e4b3){_0x4ed579['push'](_0x4ed579['shift']());}};_0x66c2f6(++_0x3ba7ce);}(a9_0x3ba7,0x1af));const a9_0x66c2=function(_0x4ed579,_0x3ba7ce){_0x4ed579=_0x4ed579-0x0;let _0x66c2f6=a9_0x3ba7[_0x4ed579];return _0x66c2f6;};'use strict';var __awaiter=this&&this[a9_0x66c2('0xa')]||function(_0x2e5397,_0x4adc49,_0x8a866,_0x5be9a3){function _0x364481(_0x7f6ca9){return _0x7f6ca9 instanceof _0x8a866?_0x7f6ca9:new _0x8a866(function(_0x4c75bd){_0x4c75bd(_0x7f6ca9);});}return new(_0x8a866||(_0x8a866=Promise))(function(_0x5149fb,_0x24d47c){function _0x24c15b(_0x427a11){try{_0x323ef4(_0x5be9a3[a9_0x66c2('0x0')](_0x427a11));}catch(_0x30c9c7){_0x24d47c(_0x30c9c7);}}function _0x10606a(_0x53b770){try{_0x323ef4(_0x5be9a3[a9_0x66c2('0x5')](_0x53b770));}catch(_0x3a7e81){_0x24d47c(_0x3a7e81);}}function _0x323ef4(_0x1ce51f){_0x1ce51f[a9_0x66c2('0x23')]?_0x5149fb(_0x1ce51f['value']):_0x364481(_0x1ce51f['value'])[a9_0x66c2('0x19')](_0x24c15b,_0x10606a);}_0x323ef4((_0x5be9a3=_0x5be9a3[a9_0x66c2('0x16')](_0x2e5397,_0x4adc49||[]))[a9_0x66c2('0x0')]());});};Object['defineProperty'](exports,a9_0x66c2('0x11'),{'value':!![]});exports[a9_0x66c2('0x9')]=void 0x0;const environment_1=require(a9_0x66c2('0x12'));const child_process_1=require(a9_0x66c2('0x10'));const fs_1=require('fs');const {output}=require(a9_0x66c2('0x8'));function invokeTasksUsingRunMany(_0x2b1f49){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x13fc8d=completedTasksReader(_0x2b1f49);return function _0x3b4154(_0x28718c,_0x42ff72,_0x4bfbf2){return __awaiter(this,void 0x0,void 0x0,function*(){let _0xf5d992=0x0;const _0x17d5cd=[];for(const _0x4b878e of groupByTarget(_0x42ff72)){const _0x39226a=_0x4b878e[a9_0x66c2('0xd')]?a9_0x66c2('0x7')+_0x4b878e[a9_0x66c2('0xd')]:'';const _0x5a57ac=_0x4bfbf2>0x1?'\x20--parallel\x20--max-parallel='+_0x4bfbf2:'';const _0x4027f0=a9_0x66c2('0xc')+_0x4b878e['target']+'\x20'+_0x39226a+a9_0x66c2('0x13')+_0x4b878e['projects'][a9_0x66c2('0xe')](',')+'\x20'+_0x4b878e[a9_0x66c2('0x17')]+_0x5a57ac;if(environment_1[a9_0x66c2('0x4')]){output[a9_0x66c2('0x1c')]({'title':a9_0x66c2('0x1d')+_0x4027f0+'\x27'});}try{(0x0,child_process_1[a9_0x66c2('0x24')])(_0x4027f0,{'stdio':[a9_0x66c2('0x2'),a9_0x66c2('0x1e'),a9_0x66c2('0x1e')],'env':Object[a9_0x66c2('0x1a')](Object[a9_0x66c2('0x1a')]({},process['env']),{'NX_CACHE_FAILURES':a9_0x66c2('0x21'),'NX_CLOUD_DISTRIBUTED_EXECUTION_ID':_0x28718c,'NX_STREAM_OUTPUT':a9_0x66c2('0x21'),'NX_PREFIX_OUTPUT':a9_0x66c2('0x21')})});_0x17d5cd[a9_0x66c2('0x22')](..._0x13fc8d(_0x28718c));}catch(_0x1a7aa4){if(_0x1a7aa4['status']===environment_1[a9_0x66c2('0xb')]){throw _0x1a7aa4;}else{_0xf5d992=0x1;_0x17d5cd[a9_0x66c2('0x22')](..._0x13fc8d(_0x28718c));}}}return{'completedStatusCode':_0xf5d992,'completedTasks':_0x17d5cd};});};});}exports[a9_0x66c2('0x9')]=invokeTasksUsingRunMany;function groupByTarget(_0x1a5ef2){const _0x3c55cc=[];_0x1a5ef2[a9_0x66c2('0x3')](_0x4c1921=>{const _0x113f2d=_0x3c55cc['find'](_0x3ddfa4=>_0x3ddfa4[a9_0x66c2('0x1f')]===_0x4c1921[a9_0x66c2('0x1f')]&&_0x3ddfa4[a9_0x66c2('0xd')]===_0x4c1921['configuration']);if(_0x113f2d){_0x113f2d[a9_0x66c2('0x15')][a9_0x66c2('0x22')](_0x4c1921[a9_0x66c2('0x6')]);}else{_0x3c55cc['push']({'target':_0x4c1921[a9_0x66c2('0x1f')],'projects':[_0x4c1921[a9_0x66c2('0x6')]],'params':_0x4c1921[a9_0x66c2('0x17')],'configuration':_0x4c1921[a9_0x66c2('0xd')]});}});return _0x3c55cc;}function completedTasksReader(_0x52fa06){const _0x3d1433=(0x0,environment_1[a9_0x66c2('0x20')])(_0x52fa06);return _0x28c941=>{const _0x48613d='Command\x20execution\x20failed\x20(distributed\x20task\x20execution:\x20'+_0x28c941+').\x20Tasks\x20hashes\x20haven\x27t\x20been\x20recorded.';let _0x1ae648;try{const _0x57fb84=_0x3d1433+a9_0x66c2('0xf')+_0x28c941;_0x1ae648=JSON[a9_0x66c2('0x14')]((0x0,fs_1[a9_0x66c2('0x18')])(_0x57fb84)[a9_0x66c2('0x1b')]());(0x0,fs_1[a9_0x66c2('0x1')])(_0x57fb84);}catch(_0x5856fc){throw new Error(_0x48613d);}if(_0x1ae648[a9_0x66c2('0x25')]==0x0){throw new Error(_0x48613d);}return _0x1ae648;};}
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.invokeTasksUsingRunMany = void 0;
13
+ const environment_1 = require("../../../utilities/environment");
14
+ const child_process_1 = require("child_process");
15
+ const fs_1 = require("fs");
16
+ const { output } = require('../../../utilities/nx-imports');
17
+ function invokeTasksUsingRunMany(options) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const readCompleted = completedTasksReader(options);
20
+ return function invokeTasksUsingRunMany(executionId, tasksToExecute, parallel) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ let completedStatusCode = 0;
23
+ const completedTasks = [];
24
+ for (const g of groupByTarget(tasksToExecute)) {
25
+ const config = g.configuration
26
+ ? `--configuration=${g.configuration}`
27
+ : ``;
28
+ const parallelStr = parallel > 1 ? ` --parallel --max-parallel=${parallel}` : ``;
29
+ // TODO use pnpx or yarn when needed
30
+ const command = `npx nx run-many --target=${g.target} ${config} --projects=${g.projects.join(',')} ${g.params}${parallelStr}`;
31
+ if (environment_1.VERBOSE_LOGGING) {
32
+ output.note({
33
+ title: `Executing: '${command}'`,
34
+ });
35
+ }
36
+ try {
37
+ (0, child_process_1.execSync)(command, {
38
+ stdio: ['ignore', 'inherit', 'inherit'],
39
+ env: Object.assign(Object.assign({}, process.env), { NX_CACHE_FAILURES: 'true', NX_CLOUD_DISTRIBUTED_EXECUTION_ID: executionId, NX_STREAM_OUTPUT: 'true', NX_PREFIX_OUTPUT: 'true' }),
40
+ });
41
+ completedTasks.push(...readCompleted(executionId));
42
+ }
43
+ catch (e) {
44
+ if (e.status === environment_1.DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE) {
45
+ throw e;
46
+ }
47
+ else {
48
+ completedStatusCode = 1;
49
+ completedTasks.push(...readCompleted(executionId));
50
+ }
51
+ }
52
+ }
53
+ return { completedStatusCode, completedTasks };
54
+ });
55
+ };
56
+ });
57
+ }
58
+ exports.invokeTasksUsingRunMany = invokeTasksUsingRunMany;
59
+ function groupByTarget(tasks) {
60
+ const res = [];
61
+ tasks.forEach((t) => {
62
+ const r = res.find((rr) => rr.target === t.target && rr.configuration === t.configuration);
63
+ if (r) {
64
+ r.projects.push(t.projectName);
65
+ }
66
+ else {
67
+ res.push({
68
+ target: t.target,
69
+ projects: [t.projectName],
70
+ params: t.params,
71
+ configuration: t.configuration,
72
+ });
73
+ }
74
+ });
75
+ return res;
76
+ }
77
+ function completedTasksReader(options) {
78
+ const cacheDirectory = (0, environment_1.getNxCacheDirectory)(options);
79
+ return (distributedExecutionId) => {
80
+ const errorMessage = `Command execution failed (distributed task execution: ${distributedExecutionId}). Tasks hashes haven\'t been recorded.`;
81
+ let completedTasks;
82
+ try {
83
+ const taskHashesFile = `${cacheDirectory}/tasks-hashes-${distributedExecutionId}`;
84
+ completedTasks = JSON.parse((0, fs_1.readFileSync)(taskHashesFile).toString());
85
+ // remove it such that if the next command crashes we don't read an obsolete file
86
+ (0, fs_1.unlinkSync)(taskHashesFile);
87
+ }
88
+ catch (e) {
89
+ throw new Error(errorMessage);
90
+ }
91
+ if (completedTasks.length == 0) {
92
+ throw new Error(errorMessage);
93
+ }
94
+ return completedTasks;
95
+ };
96
+ }
97
+ //# sourceMappingURL=invoke-tasks-using-run-many.js.map