@nrwl/nx-cloud 15.3.5 → 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 (24) 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/id-generator.js +16 -1
  11. package/lib/core/runners/distributed-agent/distributed-agent.api.js +93 -1
  12. package/lib/core/runners/distributed-agent/distributed-agent.impl.js +157 -1
  13. package/lib/core/runners/distributed-agent/execute-tasks.js +114 -1
  14. package/lib/core/runners/distributed-agent/invoke-tasks-using-nx-imperative-api.js +58 -1
  15. package/lib/core/runners/distributed-agent/invoke-tasks-using-run-many.js +97 -1
  16. package/lib/core/runners/distributed-execution/distributed-execution.api.js +152 -1
  17. package/lib/core/runners/distributed-execution/distributed-execution.runner.js +118 -1
  18. package/lib/core/runners/distributed-execution/process-task.js +45 -1
  19. package/lib/core/runners/distributed-execution/process-tasks.js +67 -1
  20. package/lib/core/runners/distributed-execution/split-task-graph-into-stages.js +37 -1
  21. package/lib/core/runners/distributed-execution/task-graph-creator.js +100 -1
  22. package/lib/utilities/axios.js +8 -2
  23. package/lib/utilities/axios.js.map +1 -1
  24. package/package.json +1 -1
@@ -1 +1,157 @@
1
- const a6_0x4b3d=['This\x20can\x20also\x20be\x20a\x20false\x20positive\x20caused\x20by\x20agents\x20that\x20did\x20not\x20shut\x20down\x20correctly.','done','existsSync','If\x20you\x20believe\x20this\x20is\x20the\x20case,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22.','Duplicate\x20Agent\x20ID\x20Detected','default','tasksRunnerOptions','writeFileSync','../../../utilities/dte-artifact-storage','.lock','floor','Starting\x20an\x20agent\x20for\x20running\x20Nx\x20target(s)\x20[','SIGTERM','message','filter','../../../utilities/metric-logger','NX_AGENT_NAME','We\x20have\x20detected\x20other\x20agents\x20running\x20in\x20this\x20workspace.\x20This\x20can\x20cause\x20unexpected\x20behavior.','@nrwl/nx-cloud','cacheableOperations','__awaiter','env','defineProperty','__esModule','getCIExecutionEnv','value','ENCRYPTION_KEY','length','map','printCacheableTargetsError','trim','getNxCacheDirectory','CIRCLECI','DistributedAgentApi','some','FileStorage','apply','printRunGroupError','split','options','getCIExecutionId','Other\x20Nx\x20Cloud\x20Agents\x20Detected','../../error/print-cacheable-targets-error','getBranch','getRunGroup','ErrorReporterApi','then','../../api/error-reporter.api','dte-agent','../../../utilities/environment','End\x20all\x20currently\x20running\x20agents,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22,\x20and\x20try\x20again.','../../file-storage/e2e-encryption','CIRCLE_STAGE','throw','next','SIGINT','encryptionKey','canDetectRunGroup','Agent\x20','completeRunGroupWithError','invokeTasksUsingRunMany','toString','/nx.json','./invoke-tasks-using-nx-imperative-api','yargs-parser','Agent\x20was\x20terminated\x20via\x20SIGTERM','./execute-tasks','runner','targets','Agent\x20was\x20terminated\x20via\x20SIGINT','readdirSync','exit','note','warn','startAgent','CIRCLE_JOB','strip-json-comments','random','printInvalidRunnerError','/lockfiles','invokeTasksUsingNxImperativeApi','./invoke-tasks-using-run-many','mkdirSync','executeTasks','Critical\x20Error\x20in\x20Agent:\x20\x22','../../error/print-invalid-runner-error','readFileSync'];(function(_0xb498d7,_0x4b3d70){const _0x28ecea=function(_0x1e8bf1){while(--_0x1e8bf1){_0xb498d7['push'](_0xb498d7['shift']());}};_0x28ecea(++_0x4b3d70);}(a6_0x4b3d,0x93));const a6_0x28ec=function(_0xb498d7,_0x4b3d70){_0xb498d7=_0xb498d7-0x0;let _0x28ecea=a6_0x4b3d[_0xb498d7];return _0x28ecea;};'use strict';var __awaiter=this&&this[a6_0x28ec('0x2f')]||function(_0x102274,_0x3bd1a0,_0x5a856f,_0x1f2186){function _0x33f7a0(_0x508aae){return _0x508aae instanceof _0x5a856f?_0x508aae:new _0x5a856f(function(_0x309054){_0x309054(_0x508aae);});}return new(_0x5a856f||(_0x5a856f=Promise))(function(_0x51f6dc,_0x3ed71e){function _0xd183fb(_0x508f24){try{_0x4f3391(_0x1f2186[a6_0x28ec('0x51')](_0x508f24));}catch(_0x2e2108){_0x3ed71e(_0x2e2108);}}function _0x213f92(_0x1fa61a){try{_0x4f3391(_0x1f2186[a6_0x28ec('0x50')](_0x1fa61a));}catch(_0x18f6b2){_0x3ed71e(_0x18f6b2);}}function _0x4f3391(_0x25bc78){_0x25bc78[a6_0x28ec('0x1c')]?_0x51f6dc(_0x25bc78['value']):_0x33f7a0(_0x25bc78[a6_0x28ec('0x34')])[a6_0x28ec('0x49')](_0xd183fb,_0x213f92);}_0x4f3391((_0x1f2186=_0x1f2186[a6_0x28ec('0x3f')](_0x102274,_0x3bd1a0||[]))['next']());});};Object[a6_0x28ec('0x31')](exports,a6_0x28ec('0x32'),{'value':!![]});exports[a6_0x28ec('0xe')]=void 0x0;const fs_1=require('fs');const stripJsonComments=require(a6_0x28ec('0x10'));const yargsParser=require(a6_0x28ec('0x4'));const environment_1=require(a6_0x28ec('0x4c'));const metric_logger_1=require(a6_0x28ec('0x2a'));const print_cacheable_targets_error_1=require(a6_0x28ec('0x45'));const print_invalid_runner_error_1=require(a6_0x28ec('0x19'));const print_run_group_error_1=require('../../error/print-run-group-error');const distributed_agent_api_1=require('./distributed-agent.api');const execute_tasks_1=require(a6_0x28ec('0x6'));const dte_artifact_storage_1=require(a6_0x28ec('0x23'));const file_storage_1=require('../../file-storage/file-storage');const e2e_encryption_1=require(a6_0x28ec('0x4e'));const error_reporter_api_1=require(a6_0x28ec('0x4a'));const invoke_tasks_using_run_many_1=require(a6_0x28ec('0x15'));const invoke_tasks_using_nx_imperative_api_1=require(a6_0x28ec('0x3'));const {output,initTasksRunner,workspaceRoot}=require('../../../utilities/nx-imports');const args=yargsParser(process['argv'],{'array':[a6_0x28ec('0x8')],'default':{}});if(args['targets']&&args['targets'][a6_0x28ec('0x36')]===0x1){args['targets']=args[a6_0x28ec('0x8')][0x0][a6_0x28ec('0x41')](',')[a6_0x28ec('0x37')](_0x3732aa=>_0x3732aa[a6_0x28ec('0x39')]());}function startAgent(){return __awaiter(this,void 0x0,void 0x0,function*(){const _0xfc542d=(0x0,environment_1[a6_0x28ec('0x46')])();const _0x4c13f1=(0x0,environment_1[a6_0x28ec('0x47')])();const _0x4c49ce=(0x0,environment_1[a6_0x28ec('0x43')])();const _0x2369e8=(0x0,environment_1[a6_0x28ec('0x33')])();if(!(0x0,print_run_group_error_1[a6_0x28ec('0x54')])(_0x4c13f1,_0x4c49ce)){(0x0,print_run_group_error_1[a6_0x28ec('0x40')])();process[a6_0x28ec('0xb')](0x1);}if(args[a6_0x28ec('0x8')]&&args[a6_0x28ec('0x8')]['length']){output[a6_0x28ec('0xc')]({'title':a6_0x28ec('0x26')+args['targets']['join'](',\x20')+']'});}else{output[a6_0x28ec('0xc')]({'title':'Starting\x20an\x20agent\x20for\x20running\x20Nx\x20tasks'});}const _0x1409b8=JSON['parse'](stripJsonComments((0x0,fs_1[a6_0x28ec('0x1a')])(workspaceRoot+a6_0x28ec('0x2'))[a6_0x28ec('0x1')]()))[a6_0x28ec('0x21')][a6_0x28ec('0x20')];if(_0x1409b8[a6_0x28ec('0x7')]!==a6_0x28ec('0x2d')){(0x0,print_invalid_runner_error_1[a6_0x28ec('0x12')])();return process[a6_0x28ec('0xb')](0x1);}const _0x1cebe9=_0x1409b8[a6_0x28ec('0x42')];if(args['targets']&&args[a6_0x28ec('0x8')][a6_0x28ec('0x3d')](_0x5f15a0=>{var _0x2ddf8e;return!((_0x2ddf8e=_0x1cebe9[a6_0x28ec('0x2e')])===null||_0x2ddf8e===void 0x0?void 0x0:_0x2ddf8e['includes'](_0x5f15a0));})){const _0x3f8b38=args[a6_0x28ec('0x8')][a6_0x28ec('0x29')](_0x23a939=>{var _0x2381ec;return!((_0x2381ec=_0x1cebe9[a6_0x28ec('0x2e')])===null||_0x2381ec===void 0x0?void 0x0:_0x2381ec['includes'](_0x23a939));});(0x0,print_cacheable_targets_error_1[a6_0x28ec('0x38')])(_0x3f8b38);return process['exit'](0x1);}const _0x342e55=getAgentName();const _0x41f420=new distributed_agent_api_1[(a6_0x28ec('0x3c'))](_0x1cebe9,_0xfc542d,_0x4c13f1,_0x4c49ce,_0x2369e8,_0x342e55);createAgentLockfileAndSetUpListeners(_0x41f420,_0x1cebe9,_0x342e55);const _0x2486ce=new e2e_encryption_1['E2EEncryption'](environment_1[a6_0x28ec('0x35')]||_0x1cebe9[a6_0x28ec('0x53')]);const _0x3cedaf=new error_reporter_api_1[(a6_0x28ec('0x48'))](_0x1cebe9);const _0x116f6f=new dte_artifact_storage_1['DteArtifactStorage'](new file_storage_1[(a6_0x28ec('0x3e'))](_0x2486ce,_0x3cedaf,_0x1cebe9,a6_0x28ec('0x4b')),(0x0,environment_1[a6_0x28ec('0x3a')])(_0x1cebe9));const _0x3e84f9=initTasksRunner?yield(0x0,invoke_tasks_using_nx_imperative_api_1[a6_0x28ec('0x14')])(_0x1cebe9):yield(0x0,invoke_tasks_using_run_many_1[a6_0x28ec('0x0')])(_0x1cebe9);return(0x0,execute_tasks_1[a6_0x28ec('0x17')])(_0x342e55,_0x41f420,_0x116f6f,_0x3e84f9,args[a6_0x28ec('0x8')])[a6_0x28ec('0x49')](_0x313ad0=>__awaiter(this,void 0x0,void 0x0,function*(){yield(0x0,metric_logger_1['submitRunMetrics'])(_0x1cebe9);return _0x313ad0;}))['catch'](_0x22b569=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x41f420[a6_0x28ec('0x56')](a6_0x28ec('0x18')+_0x22b569[a6_0x28ec('0x28')]+'\x22');throw _0x22b569;}));});}exports[a6_0x28ec('0xe')]=startAgent;function getAgentName(){if(process[a6_0x28ec('0x30')]['NX_AGENT_NAME']!==undefined){return process[a6_0x28ec('0x30')][a6_0x28ec('0x2b')];}else if(process[a6_0x28ec('0x30')]['CIRCLECI']!==undefined&&process[a6_0x28ec('0x30')][a6_0x28ec('0x4f')]){return process[a6_0x28ec('0x30')][a6_0x28ec('0x4f')];}else if(process[a6_0x28ec('0x30')][a6_0x28ec('0x3b')]!==undefined&&process[a6_0x28ec('0x30')][a6_0x28ec('0xf')]){return process[a6_0x28ec('0x30')][a6_0x28ec('0xf')];}else{return a6_0x28ec('0x55')+Math[a6_0x28ec('0x25')](Math[a6_0x28ec('0x11')]()*0x186a0);}}function createAgentLockfileAndSetUpListeners(_0x1b18f4,_0xf6b334,_0x335c46){const _0x55973c=(0x0,environment_1[a6_0x28ec('0x3a')])(_0xf6b334);const _0x1b6544=_0x55973c+a6_0x28ec('0x13');const _0x1fe67f=_0x1b6544+'/'+_0x335c46+a6_0x28ec('0x24');if(!(0x0,fs_1[a6_0x28ec('0x1d')])(_0x1b6544)){(0x0,fs_1[a6_0x28ec('0x16')])(_0x1b6544,{'recursive':!![]});}const _0x4e03b=(0x0,fs_1[a6_0x28ec('0xa')])(_0x1b6544);if(_0x4e03b[a6_0x28ec('0x36')]){if(_0x4e03b['includes'](_0x335c46+'.lock')){output['error']({'title':a6_0x28ec('0x1f'),'bodyLines':['We\x20have\x20detected\x20another\x20agent\x20with\x20this\x20ID\x20running\x20in\x20this\x20workspace.\x20This\x20should\x20not\x20happen.','',a6_0x28ec('0x4d')]});process[a6_0x28ec('0xb')](0x1);}output[a6_0x28ec('0xd')]({'title':a6_0x28ec('0x44'),'bodyLines':[a6_0x28ec('0x2c'),'',a6_0x28ec('0x1b'),a6_0x28ec('0x1e')]});}(0x0,fs_1[a6_0x28ec('0x22')])(_0x1fe67f,'');process['on']('exit',_0x494194=>{cleanupAgentLockfile(_0x1fe67f,_0x494194);});process['on'](a6_0x28ec('0x27'),()=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x1b18f4[a6_0x28ec('0x56')](a6_0x28ec('0x5'));cleanupAgentLockfile(_0x1fe67f,0x1);}));process['on'](a6_0x28ec('0x52'),()=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x1b18f4[a6_0x28ec('0x56')](a6_0x28ec('0x9'));cleanupAgentLockfile(_0x1fe67f,0x1);}));}function cleanupAgentLockfile(_0x37bcd3,_0x5c0d7f){if((0x0,fs_1['existsSync'])(_0x37bcd3)){(0x0,fs_1['unlinkSync'])(_0x37bcd3);process[a6_0x28ec('0xb')](_0x5c0d7f);}}
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_0x161d=['../../../utilities/waiter','Waiter','exit','\x20seconds','RUN_GROUP_COMPLETED','Error:','executeTasks','status:\x20','executionId:\x20','completed','next','\x20downloading\x20artifacts\x20for\x20','No\x20new\x20messages\x20received\x20after\x20','map','NO_FURTHER_TASKS_TO_RUN','../../../utilities/environment','../../../utilities/nx-imports','\x20Hash:\x20','retryDuring:\x20','defineProperty','hash','createUnchangedValueTimeout','../../../utilities/create-unchanged-value-timeout','throw','status','\x20Url:\x20','tasks','url','note','completedTasks','__awaiter','maxParallel','length','number\x20of\x20tasks:\x20','value','criticalErrorMessage','Distributed\x20Execution\x20Terminated','reset','done','retryDuring','taskId','getTime','maxParallel:\x20','NO_MESSAGES_TIMEOUT','join','wait','executionId','VERBOSE_LOGGING','completedStatusCode'];(function(_0x190508,_0x161d5f){const _0x4b7aac=function(_0x44c702){while(--_0x44c702){_0x190508['push'](_0x190508['shift']());}};_0x4b7aac(++_0x161d5f);}(a7_0x161d,0xcd));const a7_0x4b7a=function(_0x190508,_0x161d5f){_0x190508=_0x190508-0x0;let _0x4b7aac=a7_0x161d[_0x190508];return _0x4b7aac;};'use strict';var __awaiter=this&&this[a7_0x4b7a('0x15')]||function(_0x20b739,_0xa3d779,_0x3b8799,_0x574f41){function _0x253400(_0x437468){return _0x437468 instanceof _0x3b8799?_0x437468:new _0x3b8799(function(_0x232802){_0x232802(_0x437468);});}return new(_0x3b8799||(_0x3b8799=Promise))(function(_0x4ff064,_0x132b38){function _0x5e33d5(_0x1d6ff3){try{_0x4d2737(_0x574f41['next'](_0x1d6ff3));}catch(_0x3cac32){_0x132b38(_0x3cac32);}}function _0x227966(_0x357fca){try{_0x4d2737(_0x574f41[a7_0x4b7a('0xe')](_0x357fca));}catch(_0x4ed34d){_0x132b38(_0x4ed34d);}}function _0x4d2737(_0x27d309){_0x27d309[a7_0x4b7a('0x1d')]?_0x4ff064(_0x27d309[a7_0x4b7a('0x19')]):_0x253400(_0x27d309['value'])['then'](_0x5e33d5,_0x227966);}_0x4d2737((_0x574f41=_0x574f41['apply'](_0x20b739,_0xa3d779||[]))[a7_0x4b7a('0x1')]());});};Object[a7_0x4b7a('0xa')](exports,'__esModule',{'value':!![]});exports[a7_0x4b7a('0x2e')]=void 0x0;const create_unchanged_value_timeout_1=require(a7_0x4b7a('0xd'));const environment_1=require(a7_0x4b7a('0x6'));const waiter_1=require(a7_0x4b7a('0x28'));const {output}=require(a7_0x4b7a('0x7'));function executeTasks(_0x2dd6ed,_0x3d9726,_0x396b00,_0xc7ebc6,_0x3b7ed4){return __awaiter(this,void 0x0,void 0x0,function*(){let _0x537076=0x0;let _0x107cb1=null;const _0x37be8a=(0x0,create_unchanged_value_timeout_1[a7_0x4b7a('0xc')])({'title':a7_0x4b7a('0x3')+environment_1[a7_0x4b7a('0x22')]/0x3e8+a7_0x4b7a('0x2b'),'timeout':environment_1[a7_0x4b7a('0x22')]});const _0x4dbe55=new waiter_1[(a7_0x4b7a('0x29'))]();let _0x1b7566=[];const _0xce0cd3=new Date();let _0x1cd852=![];const _0x5339ae={};while(!![]){if(environment_1['VERBOSE_LOGGING']){output[a7_0x4b7a('0x13')]({'title':_0x2dd6ed+'\x20fetching\x20tasks...'});}_0x107cb1=yield _0x3d9726['tasks'](_0x107cb1?_0x107cb1['executionId']:null,_0x537076,_0x1b7566,_0x3b7ed4);if(environment_1[a7_0x4b7a('0x26')]){output['note']({'title':_0x2dd6ed+'\x20received\x20an\x20API\x20Response','bodyLines':['completed:\x20'+_0x107cb1['completed'],a7_0x4b7a('0x2f')+_0x107cb1['status'],a7_0x4b7a('0x9')+_0x107cb1[a7_0x4b7a('0x1e')],a7_0x4b7a('0x30')+_0x107cb1[a7_0x4b7a('0x25')],a7_0x4b7a('0x18')+_0x107cb1[a7_0x4b7a('0x11')][a7_0x4b7a('0x17')],'error:\x20'+_0x107cb1[a7_0x4b7a('0x1a')],a7_0x4b7a('0x21')+_0x107cb1['maxParallel']]});}if(_0x107cb1[a7_0x4b7a('0x1a')]){output['error']({'title':a7_0x4b7a('0x1b'),'bodyLines':[a7_0x4b7a('0x2d'),_0x107cb1['criticalErrorMessage']]});process[a7_0x4b7a('0x2a')](0x0);}if((_0x107cb1===null||_0x107cb1===void 0x0?void 0x0:_0x107cb1[a7_0x4b7a('0x1e')])&&(_0x107cb1===null||_0x107cb1===void 0x0?void 0x0:_0x107cb1[a7_0x4b7a('0x1e')])!==0x0&&!_0x1cd852&&new Date()[a7_0x4b7a('0x20')]()-_0xce0cd3[a7_0x4b7a('0x20')]()>_0x107cb1[a7_0x4b7a('0x1e')]){yield _0x4dbe55[a7_0x4b7a('0x24')]();continue;}if((_0x107cb1===null||_0x107cb1===void 0x0?void 0x0:_0x107cb1['status'])!==undefined){if(_0x107cb1['status']===a7_0x4b7a('0x2c')||_0x107cb1[a7_0x4b7a('0xf')]===a7_0x4b7a('0x5')){return;}}else if(_0x107cb1[a7_0x4b7a('0x0')]){return;}_0x37be8a(_0x107cb1['tasks'][a7_0x4b7a('0x4')](_0x46efd6=>_0x46efd6['taskId'])[a7_0x4b7a('0x23')](''));if(!_0x107cb1['executionId']){if(environment_1['VERBOSE_LOGGING']){output[a7_0x4b7a('0x13')]({'title':_0x2dd6ed+'\x20waiting...'});}yield _0x4dbe55[a7_0x4b7a('0x24')]();_0x537076=0x0;_0x1b7566=[];continue;}_0x4dbe55[a7_0x4b7a('0x1c')]();_0x1cd852=!![];if(_0x107cb1['completedTasks']){for(const _0xa1e162 of _0x107cb1[a7_0x4b7a('0x14')]){if(_0x5339ae[_0xa1e162['taskId']])continue;output[a7_0x4b7a('0x13')]({'title':_0x2dd6ed+a7_0x4b7a('0x2')+_0xa1e162[a7_0x4b7a('0x1f')]+a7_0x4b7a('0x8')+_0xa1e162[a7_0x4b7a('0xb')]+a7_0x4b7a('0x10')+_0xa1e162[a7_0x4b7a('0x12')]});yield _0x396b00['retrieveAndExtract'](_0xa1e162[a7_0x4b7a('0xb')],_0xa1e162[a7_0x4b7a('0x12')]);_0x5339ae[_0xa1e162[a7_0x4b7a('0x1f')]]=!![];}}const _0x1c5731=yield _0xc7ebc6(_0x107cb1['executionId'],_0x107cb1['tasks'],_0x107cb1[a7_0x4b7a('0x16')]);for(const _0x2fe587 of _0x1c5731[a7_0x4b7a('0x14')]){_0x5339ae[_0x2fe587['taskId']]=!![];}_0x537076=_0x1c5731[a7_0x4b7a('0x27')];_0x1b7566=_0x1c5731[a7_0x4b7a('0x14')];}});}exports[a7_0x4b7a('0x2e')]=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_0x51a6=['NX_STREAM_OUTPUT','__esModule','status','NX_CLOUD_DISTRIBUTED_EXECUTION_ID','map','then','next','env','target','configuration','NX_CACHE_FAILURES','throw','hash','projectName','apply','values','tasks','defineProperty','invokeTasksUsingNxImperativeApi','yargs-parser','done','value','taskGraph','length'];(function(_0x1bb632,_0x51a6a3){const _0xe66f8b=function(_0x54492e){while(--_0x54492e){_0x1bb632['push'](_0x1bb632['shift']());}};_0xe66f8b(++_0x51a6a3);}(a8_0x51a6,0xd8));const a8_0xe66f=function(_0x1bb632,_0x51a6a3){_0x1bb632=_0x1bb632-0x0;let _0xe66f8b=a8_0x51a6[_0x1bb632];return _0xe66f8b;};'use strict';var __awaiter=this&&this['__awaiter']||function(_0x18968c,_0x9e284a,_0x2f739f,_0x5dee51){function _0x2a5653(_0xa52ad6){return _0xa52ad6 instanceof _0x2f739f?_0xa52ad6:new _0x2f739f(function(_0x12c9b1){_0x12c9b1(_0xa52ad6);});}return new(_0x2f739f||(_0x2f739f=Promise))(function(_0x39a83a,_0x439865){function _0x574610(_0x5bf365){try{_0x34869c(_0x5dee51[a8_0xe66f('0x6')](_0x5bf365));}catch(_0x4deaf3){_0x439865(_0x4deaf3);}}function _0x145634(_0x1c4467){try{_0x34869c(_0x5dee51[a8_0xe66f('0xb')](_0x1c4467));}catch(_0xb219f4){_0x439865(_0xb219f4);}}function _0x34869c(_0x3782e9){_0x3782e9[a8_0xe66f('0x14')]?_0x39a83a(_0x3782e9['value']):_0x2a5653(_0x3782e9[a8_0xe66f('0x15')])[a8_0xe66f('0x5')](_0x574610,_0x145634);}_0x34869c((_0x5dee51=_0x5dee51[a8_0xe66f('0xe')](_0x18968c,_0x9e284a||[]))['next']());});};Object[a8_0xe66f('0x11')](exports,a8_0xe66f('0x1'),{'value':!![]});exports['invokeTasksUsingNxImperativeApi']=void 0x0;const {initTasksRunner}=require('../../../utilities/nx-imports');const parser=require(a8_0xe66f('0x13'));const serializer_overrides_1=require('../../../utilities/serializer-overrides');function invokeTasksUsingNxImperativeApi(_0xedabc){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x26beef=yield initTasksRunner(_0xedabc);return(_0x4b762d,_0x56329c,_0x27d158)=>__awaiter(this,void 0x0,void 0x0,function*(){const _0x1c55bf=_0x56329c[a8_0xe66f('0x4')](_0x585dd3=>{const _0x14dc99=parser(_0x585dd3['params'],{'configuration':{'camel-case-expansion':![],'dot-notation':!![]}});const _0x437ae9=(0x0,serializer_overrides_1['unparse'])(_0x14dc99);if(_0x14dc99['_'][a8_0xe66f('0x17')]==0x0){delete _0x14dc99['_'];}return{'id':_0x585dd3['taskId'],'target':{'project':_0x585dd3[a8_0xe66f('0xd')],'target':_0x585dd3[a8_0xe66f('0x8')],'configuration':_0x585dd3[a8_0xe66f('0x9')]},'overrides':Object['assign'](Object['assign']({},_0x14dc99),{'__overrides_unparsed__':_0x437ae9})};});process['env'][a8_0xe66f('0xa')]='true';process['env'][a8_0xe66f('0x3')]=_0x4b762d;process[a8_0xe66f('0x7')][a8_0xe66f('0x0')]='true';process[a8_0xe66f('0x7')]['NX_PREFIX_OUTPUT']='true';const _0x405f57=yield _0x26beef['invoke']({'tasks':_0x1c55bf,'parallel':_0x27d158});const _0x60cb2a=Object[a8_0xe66f('0xf')](_0x405f57[a8_0xe66f('0x16')][a8_0xe66f('0x10')]);return{'completedTasks':_0x60cb2a[a8_0xe66f('0x4')](_0x2eda0c=>({'taskId':_0x2eda0c['id'],'hash':_0x2eda0c[a8_0xe66f('0xc')]})),'completedStatusCode':_0x405f57[a8_0xe66f('0x2')]};});});}exports[a8_0xe66f('0x12')]=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_0x358b=['--configuration=','value','configuration','note','status','/tasks-hashes-','params','defineProperty','apply','push','../../../utilities/nx-imports','../../../utilities/environment','true','projectName','assign','parse','projects','forEach','getNxCacheDirectory','length','find','npx\x20nx\x20run-many\x20--target=','VERBOSE_LOGGING','ignore','next','readFileSync','Command\x20execution\x20failed\x20(distributed\x20task\x20execution:\x20','unlinkSync','__esModule','__awaiter','target','throw','Executing:\x20\x27','inherit','then','invokeTasksUsingRunMany','join','child_process'];(function(_0x36fd05,_0x358b48){const _0x16779a=function(_0x358ff7){while(--_0x358ff7){_0x36fd05['push'](_0x36fd05['shift']());}};_0x16779a(++_0x358b48);}(a9_0x358b,0x14b));const a9_0x1677=function(_0x36fd05,_0x358b48){_0x36fd05=_0x36fd05-0x0;let _0x16779a=a9_0x358b[_0x36fd05];return _0x16779a;};'use strict';var __awaiter=this&&this[a9_0x1677('0x2')]||function(_0x39437e,_0x4e14ef,_0x232b29,_0x24aa9e){function _0x5e16a1(_0x12a430){return _0x12a430 instanceof _0x232b29?_0x12a430:new _0x232b29(function(_0x530833){_0x530833(_0x12a430);});}return new(_0x232b29||(_0x232b29=Promise))(function(_0x2c3417,_0x1ea63c){function _0x32c2d4(_0x5117f4){try{_0x1dcdbd(_0x24aa9e[a9_0x1677('0x23')](_0x5117f4));}catch(_0x584cfe){_0x1ea63c(_0x584cfe);}}function _0x426305(_0x5702bc){try{_0x1dcdbd(_0x24aa9e[a9_0x1677('0x4')](_0x5702bc));}catch(_0x21f43c){_0x1ea63c(_0x21f43c);}}function _0x1dcdbd(_0x35e698){_0x35e698['done']?_0x2c3417(_0x35e698[a9_0x1677('0xc')]):_0x5e16a1(_0x35e698[a9_0x1677('0xc')])[a9_0x1677('0x7')](_0x32c2d4,_0x426305);}_0x1dcdbd((_0x24aa9e=_0x24aa9e[a9_0x1677('0x13')](_0x39437e,_0x4e14ef||[]))['next']());});};Object[a9_0x1677('0x12')](exports,a9_0x1677('0x1'),{'value':!![]});exports[a9_0x1677('0x8')]=void 0x0;const environment_1=require(a9_0x1677('0x16'));const child_process_1=require(a9_0x1677('0xa'));const fs_1=require('fs');const {output}=require(a9_0x1677('0x15'));function invokeTasksUsingRunMany(_0x1cc6f3){return __awaiter(this,void 0x0,void 0x0,function*(){const _0xdcc24=completedTasksReader(_0x1cc6f3);return function _0x781be1(_0xcd63d0,_0x2b5b67,_0x26402f){return __awaiter(this,void 0x0,void 0x0,function*(){let _0xf1f199=0x0;const _0x5a0c10=[];for(const _0x352c8f of groupByTarget(_0x2b5b67)){const _0x39cf1f=_0x352c8f[a9_0x1677('0xd')]?a9_0x1677('0xb')+_0x352c8f[a9_0x1677('0xd')]:'';const _0x44cbe9=_0x26402f>0x1?'\x20--parallel\x20--max-parallel='+_0x26402f:'';const _0x23925a=a9_0x1677('0x20')+_0x352c8f[a9_0x1677('0x3')]+'\x20'+_0x39cf1f+'\x20--projects='+_0x352c8f[a9_0x1677('0x1b')][a9_0x1677('0x9')](',')+'\x20'+_0x352c8f[a9_0x1677('0x11')]+_0x44cbe9;if(environment_1[a9_0x1677('0x21')]){output[a9_0x1677('0xe')]({'title':a9_0x1677('0x5')+_0x23925a+'\x27'});}try{(0x0,child_process_1['execSync'])(_0x23925a,{'stdio':[a9_0x1677('0x22'),a9_0x1677('0x6'),a9_0x1677('0x6')],'env':Object[a9_0x1677('0x19')](Object[a9_0x1677('0x19')]({},process['env']),{'NX_CACHE_FAILURES':a9_0x1677('0x17'),'NX_CLOUD_DISTRIBUTED_EXECUTION_ID':_0xcd63d0,'NX_STREAM_OUTPUT':a9_0x1677('0x17'),'NX_PREFIX_OUTPUT':a9_0x1677('0x17')})});_0x5a0c10[a9_0x1677('0x14')](..._0xdcc24(_0xcd63d0));}catch(_0x2b84e6){if(_0x2b84e6[a9_0x1677('0xf')]===environment_1['DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE']){throw _0x2b84e6;}else{_0xf1f199=0x1;_0x5a0c10[a9_0x1677('0x14')](..._0xdcc24(_0xcd63d0));}}}return{'completedStatusCode':_0xf1f199,'completedTasks':_0x5a0c10};});};});}exports[a9_0x1677('0x8')]=invokeTasksUsingRunMany;function groupByTarget(_0x36df82){const _0x2811a5=[];_0x36df82[a9_0x1677('0x1c')](_0x51f009=>{const _0x6f00d6=_0x2811a5[a9_0x1677('0x1f')](_0x3bc9f4=>_0x3bc9f4[a9_0x1677('0x3')]===_0x51f009['target']&&_0x3bc9f4[a9_0x1677('0xd')]===_0x51f009['configuration']);if(_0x6f00d6){_0x6f00d6['projects'][a9_0x1677('0x14')](_0x51f009[a9_0x1677('0x18')]);}else{_0x2811a5[a9_0x1677('0x14')]({'target':_0x51f009[a9_0x1677('0x3')],'projects':[_0x51f009[a9_0x1677('0x18')]],'params':_0x51f009[a9_0x1677('0x11')],'configuration':_0x51f009['configuration']});}});return _0x2811a5;}function completedTasksReader(_0x1faf7a){const _0x44cf37=(0x0,environment_1[a9_0x1677('0x1d')])(_0x1faf7a);return _0x5a9c73=>{const _0x59f280=a9_0x1677('0x25')+_0x5a9c73+').\x20Tasks\x20hashes\x20haven\x27t\x20been\x20recorded.';let _0x11a216;try{const _0x3a19ab=_0x44cf37+a9_0x1677('0x10')+_0x5a9c73;_0x11a216=JSON[a9_0x1677('0x1a')]((0x0,fs_1[a9_0x1677('0x24')])(_0x3a19ab)['toString']());(0x0,fs_1[a9_0x1677('0x0')])(_0x3a19ab);}catch(_0x3f6dd0){throw new Error(_0x59f280);}if(_0x11a216[a9_0x1677('0x1e')]==0x0){throw new Error(_0x59f280);}return _0x11a216;};}
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