@nrwl/nx-cloud 15.3.0 → 15.3.1-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 (22) 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/runners/cloud-enabled/cloud-enabled-life-cycle.js +93 -1
  4. package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js +320 -1
  5. package/lib/core/runners/cloud-enabled/cloud-enabled.runner.js.map +1 -1
  6. package/lib/core/runners/cloud-enabled/cloud-remote-cache.js +133 -1
  7. package/lib/core/runners/cloud-enabled/cloud-run.api.js +168 -1
  8. package/lib/core/runners/cloud-enabled/id-generator.js +16 -1
  9. package/lib/core/runners/distributed-agent/distributed-agent.api.js +93 -1
  10. package/lib/core/runners/distributed-agent/distributed-agent.impl.js +157 -1
  11. package/lib/core/runners/distributed-agent/execute-tasks.js +114 -1
  12. package/lib/core/runners/distributed-agent/invoke-tasks-using-nx-imperative-api.js +58 -1
  13. package/lib/core/runners/distributed-agent/invoke-tasks-using-run-many.js +97 -1
  14. package/lib/core/runners/distributed-execution/distributed-execution.api.js +152 -1
  15. package/lib/core/runners/distributed-execution/distributed-execution.runner.js +118 -1
  16. package/lib/core/runners/distributed-execution/process-task.js +45 -1
  17. package/lib/core/runners/distributed-execution/process-tasks.js +67 -1
  18. package/lib/core/runners/distributed-execution/split-task-graph-into-stages.js +37 -1
  19. package/lib/core/runners/distributed-execution/task-graph-creator.js +100 -1
  20. package/lib/daemon/process-run-end.js +1 -1
  21. package/lib/daemon/process-run-end.js.map +1 -1
  22. package/package.json +1 -1
@@ -1 +1,157 @@
1
- const a6_0x2b8e=['getCIExecutionEnv','getBranch','canDetectRunGroup','unlinkSync','map','Starting\x20an\x20agent\x20for\x20running\x20Nx\x20target(s)\x20[','exit','./invoke-tasks-using-run-many','If\x20you\x20believe\x20this\x20is\x20the\x20case,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22.','/lockfiles','CIRCLECI','../../error/print-invalid-runner-error','split','existsSync','../../../utilities/dte-artifact-storage','completeRunGroupWithError','This\x20can\x20also\x20be\x20a\x20false\x20positive\x20caused\x20by\x20agents\x20that\x20did\x20not\x20shut\x20down\x20correctly.','argv','executeTasks','DteArtifactStorage','default','../../../utilities/environment','printInvalidRunnerError','CIRCLE_JOB','Agent\x20was\x20terminated\x20via\x20SIGTERM','Agent\x20','We\x20have\x20detected\x20other\x20agents\x20running\x20in\x20this\x20workspace.\x20This\x20can\x20cause\x20unexpected\x20behavior.','value','getNxCacheDirectory','throw','filter','message','We\x20have\x20detected\x20another\x20agent\x20with\x20this\x20ID\x20running\x20in\x20this\x20workspace.\x20This\x20should\x20not\x20happen.','defineProperty','join','E2EEncryption','Starting\x20an\x20agent\x20for\x20running\x20Nx\x20tasks','runner','CIRCLE_STAGE','printCacheableTargetsError','length','encryptionKey','invokeTasksUsingRunMany','NX_AGENT_NAME','catch','yargs-parser','tasksRunnerOptions','../../error/print-run-group-error','warn','next','readdirSync','trim','some','./invoke-tasks-using-nx-imperative-api','env','then','targets','../../../utilities/metric-logger','toString','random','mkdirSync','../../error/print-cacheable-targets-error','printRunGroupError','cacheableOperations','End\x20all\x20currently\x20running\x20agents,\x20run\x20\x22npx\x20nx-cloud\x20clean-up-agents\x22,\x20and\x20try\x20again.','DistributedAgentApi','/nx.json','error','invokeTasksUsingNxImperativeApi','options','./distributed-agent.api','getRunGroup','ENCRYPTION_KEY','../../file-storage/e2e-encryption','SIGINT','writeFileSync','note','__esModule','submitRunMetrics','done','includes'];(function(_0x500fb5,_0x2b8e92){const _0x319dcb=function(_0x4ce839){while(--_0x4ce839){_0x500fb5['push'](_0x500fb5['shift']());}};_0x319dcb(++_0x2b8e92);}(a6_0x2b8e,0x1b4));const a6_0x319d=function(_0x500fb5,_0x2b8e92){_0x500fb5=_0x500fb5-0x0;let _0x319dcb=a6_0x2b8e[_0x500fb5];return _0x319dcb;};'use strict';var __awaiter=this&&this['__awaiter']||function(_0x1da0d9,_0x57575c,_0x2001cf,_0x4e55ef){function _0x4d9acd(_0x49fabf){return _0x49fabf instanceof _0x2001cf?_0x49fabf:new _0x2001cf(function(_0x516267){_0x516267(_0x49fabf);});}return new(_0x2001cf||(_0x2001cf=Promise))(function(_0x409fd6,_0x51c787){function _0x539df6(_0x438755){try{_0x3e763c(_0x4e55ef[a6_0x319d('0x12')](_0x438755));}catch(_0x595125){_0x51c787(_0x595125);}}function _0x10e7a3(_0xf5c346){try{_0x3e763c(_0x4e55ef[a6_0x319d('0x4f')](_0xf5c346));}catch(_0x94908b){_0x51c787(_0x94908b);}}function _0x3e763c(_0x37f889){_0x37f889[a6_0x319d('0x30')]?_0x409fd6(_0x37f889[a6_0x319d('0x4d')]):_0x4d9acd(_0x37f889['value'])[a6_0x319d('0x18')](_0x539df6,_0x10e7a3);}_0x3e763c((_0x4e55ef=_0x4e55ef['apply'](_0x1da0d9,_0x57575c||[]))[a6_0x319d('0x12')]());});};Object[a6_0x319d('0x2')](exports,a6_0x319d('0x2e'),{'value':!![]});exports['startAgent']=void 0x0;const fs_1=require('fs');const stripJsonComments=require('strip-json-comments');const yargsParser=require(a6_0x319d('0xe'));const environment_1=require(a6_0x319d('0x47'));const metric_logger_1=require(a6_0x319d('0x1a'));const print_cacheable_targets_error_1=require(a6_0x319d('0x1e'));const print_invalid_runner_error_1=require(a6_0x319d('0x3d'));const print_run_group_error_1=require(a6_0x319d('0x10'));const distributed_agent_api_1=require(a6_0x319d('0x27'));const execute_tasks_1=require('./execute-tasks');const dte_artifact_storage_1=require(a6_0x319d('0x40'));const file_storage_1=require('../../file-storage/file-storage');const e2e_encryption_1=require(a6_0x319d('0x2a'));const error_reporter_api_1=require('../../api/error-reporter.api');const invoke_tasks_using_run_many_1=require(a6_0x319d('0x39'));const invoke_tasks_using_nx_imperative_api_1=require(a6_0x319d('0x16'));const {output,initTasksRunner,workspaceRoot}=require('../../../utilities/nx-imports');const args=yargsParser(process[a6_0x319d('0x43')],{'array':['targets'],'default':{}});if(args['targets']&&args[a6_0x319d('0x19')][a6_0x319d('0x9')]===0x1){args[a6_0x319d('0x19')]=args[a6_0x319d('0x19')][0x0][a6_0x319d('0x3e')](',')[a6_0x319d('0x36')](_0x460f46=>_0x460f46[a6_0x319d('0x14')]());}function startAgent(){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x302b6d=(0x0,environment_1[a6_0x319d('0x33')])();const _0x2a2dea=(0x0,environment_1[a6_0x319d('0x28')])();const _0x255cdf=(0x0,environment_1['getCIExecutionId'])();const _0x3d2772=(0x0,environment_1[a6_0x319d('0x32')])();if(!(0x0,print_run_group_error_1[a6_0x319d('0x34')])(_0x2a2dea,_0x255cdf)){(0x0,print_run_group_error_1[a6_0x319d('0x1f')])();process[a6_0x319d('0x38')](0x1);}if(args[a6_0x319d('0x19')]&&args[a6_0x319d('0x19')][a6_0x319d('0x9')]){output[a6_0x319d('0x2d')]({'title':a6_0x319d('0x37')+args['targets'][a6_0x319d('0x3')](',\x20')+']'});}else{output['note']({'title':a6_0x319d('0x5')});}const _0xf1df55=JSON['parse'](stripJsonComments((0x0,fs_1['readFileSync'])(workspaceRoot+a6_0x319d('0x23'))[a6_0x319d('0x1b')]()))[a6_0x319d('0xf')][a6_0x319d('0x46')];if(_0xf1df55[a6_0x319d('0x6')]!=='@nrwl/nx-cloud'){(0x0,print_invalid_runner_error_1[a6_0x319d('0x48')])();return process['exit'](0x1);}const _0x44f400=_0xf1df55[a6_0x319d('0x26')];if(args[a6_0x319d('0x19')]&&args[a6_0x319d('0x19')][a6_0x319d('0x15')](_0x11f336=>{var _0x4c0b81;return!((_0x4c0b81=_0x44f400[a6_0x319d('0x20')])===null||_0x4c0b81===void 0x0?void 0x0:_0x4c0b81['includes'](_0x11f336));})){const _0x23d450=args[a6_0x319d('0x19')][a6_0x319d('0x50')](_0x557d18=>{var _0x75585d;return!((_0x75585d=_0x44f400[a6_0x319d('0x20')])===null||_0x75585d===void 0x0?void 0x0:_0x75585d[a6_0x319d('0x31')](_0x557d18));});(0x0,print_cacheable_targets_error_1[a6_0x319d('0x8')])(_0x23d450);return process[a6_0x319d('0x38')](0x1);}const _0x128f77=getAgentName();const _0x18b4b9=new distributed_agent_api_1[(a6_0x319d('0x22'))](_0x44f400,_0x302b6d,_0x2a2dea,_0x255cdf,_0x3d2772,_0x128f77);createAgentLockfileAndSetUpListeners(_0x18b4b9,_0x44f400,_0x128f77);const _0x1317a2=new e2e_encryption_1[(a6_0x319d('0x4'))](environment_1[a6_0x319d('0x29')]||_0x44f400[a6_0x319d('0xa')]);const _0x12bdd7=new error_reporter_api_1['ErrorReporterApi'](_0x44f400);const _0xbae200=new dte_artifact_storage_1[(a6_0x319d('0x45'))](new file_storage_1['FileStorage'](_0x1317a2,_0x12bdd7,_0x44f400,'dte-agent'),(0x0,environment_1['getNxCacheDirectory'])(_0x44f400));const _0x3faef6=initTasksRunner?yield(0x0,invoke_tasks_using_nx_imperative_api_1[a6_0x319d('0x25')])(_0x44f400):yield(0x0,invoke_tasks_using_run_many_1[a6_0x319d('0xb')])(_0x44f400);return(0x0,execute_tasks_1[a6_0x319d('0x44')])(_0x128f77,_0x18b4b9,_0xbae200,_0x3faef6,args[a6_0x319d('0x19')])[a6_0x319d('0x18')](_0x9b998b=>__awaiter(this,void 0x0,void 0x0,function*(){yield(0x0,metric_logger_1[a6_0x319d('0x2f')])(_0x44f400);return _0x9b998b;}))[a6_0x319d('0xd')](_0x54edb2=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x18b4b9[a6_0x319d('0x41')]('Critical\x20Error\x20in\x20Agent:\x20\x22'+_0x54edb2[a6_0x319d('0x0')]+'\x22');throw _0x54edb2;}));});}exports['startAgent']=startAgent;function getAgentName(){if(process['env'][a6_0x319d('0xc')]!==undefined){return process['env'][a6_0x319d('0xc')];}else if(process[a6_0x319d('0x17')]['CIRCLECI']!==undefined&&process[a6_0x319d('0x17')][a6_0x319d('0x7')]){return process[a6_0x319d('0x17')]['CIRCLE_STAGE'];}else if(process[a6_0x319d('0x17')][a6_0x319d('0x3c')]!==undefined&&process['env'][a6_0x319d('0x49')]){return process[a6_0x319d('0x17')][a6_0x319d('0x49')];}else{return a6_0x319d('0x4b')+Math['floor'](Math[a6_0x319d('0x1c')]()*0x186a0);}}function createAgentLockfileAndSetUpListeners(_0x3d122e,_0x26fa83,_0x1c1bfa){const _0x119955=(0x0,environment_1[a6_0x319d('0x4e')])(_0x26fa83);const _0xc4e8d5=_0x119955+a6_0x319d('0x3b');const _0x3a5699=_0xc4e8d5+'/'+_0x1c1bfa+'.lock';if(!(0x0,fs_1[a6_0x319d('0x3f')])(_0xc4e8d5)){(0x0,fs_1[a6_0x319d('0x1d')])(_0xc4e8d5,{'recursive':!![]});}const _0x484ca1=(0x0,fs_1[a6_0x319d('0x13')])(_0xc4e8d5);if(_0x484ca1[a6_0x319d('0x9')]){if(_0x484ca1['includes'](_0x1c1bfa+'.lock')){output[a6_0x319d('0x24')]({'title':'Duplicate\x20Agent\x20ID\x20Detected','bodyLines':[a6_0x319d('0x1'),'',a6_0x319d('0x21')]});process[a6_0x319d('0x38')](0x1);}output[a6_0x319d('0x11')]({'title':'Other\x20Nx\x20Cloud\x20Agents\x20Detected','bodyLines':[a6_0x319d('0x4c'),'',a6_0x319d('0x42'),a6_0x319d('0x3a')]});}(0x0,fs_1[a6_0x319d('0x2c')])(_0x3a5699,'');process['on']('exit',_0x9593a9=>{cleanupAgentLockfile(_0x3a5699,_0x9593a9);});process['on']('SIGTERM',()=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x3d122e[a6_0x319d('0x41')](a6_0x319d('0x4a'));cleanupAgentLockfile(_0x3a5699,0x1);}));process['on'](a6_0x319d('0x2b'),()=>__awaiter(this,void 0x0,void 0x0,function*(){yield _0x3d122e[a6_0x319d('0x41')]('Agent\x20was\x20terminated\x20via\x20SIGINT');cleanupAgentLockfile(_0x3a5699,0x1);}));}function cleanupAgentLockfile(_0x14f5fa,_0x378440){if((0x0,fs_1[a6_0x319d('0x3f')])(_0x14f5fa)){(0x0,fs_1[a6_0x319d('0x35')])(_0x14f5fa);process[a6_0x319d('0x38')](_0x378440);}}
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_0x38fd=['status:\x20','__awaiter','Distributed\x20Execution\x20Terminated','maxParallel:\x20','tasks','NO_FURTHER_TASKS_TO_RUN','RUN_GROUP_COMPLETED','criticalErrorMessage','__esModule','NO_MESSAGES_TIMEOUT','../../../utilities/nx-imports','retrieveAndExtract','taskId','getTime','\x20received\x20an\x20API\x20Response','error:\x20','url','retryDuring','executionId','join','Error:','note','\x20Url:\x20','\x20Hash:\x20','\x20seconds','completed','executionId:\x20','executeTasks','value','hash','retryDuring:\x20','\x20downloading\x20artifacts\x20for\x20','No\x20new\x20messages\x20received\x20after\x20','defineProperty','completedStatusCode','completedTasks','completed:\x20','number\x20of\x20tasks:\x20','wait','done','\x20waiting...','error','next','maxParallel','createUnchangedValueTimeout','\x20fetching\x20tasks...','throw','VERBOSE_LOGGING','../../../utilities/waiter','status','reset'];(function(_0xd4d44b,_0x38fd0d){const _0x4b59a5=function(_0x110355){while(--_0x110355){_0xd4d44b['push'](_0xd4d44b['shift']());}};_0x4b59a5(++_0x38fd0d);}(a7_0x38fd,0x9b));const a7_0x4b59=function(_0xd4d44b,_0x38fd0d){_0xd4d44b=_0xd4d44b-0x0;let _0x4b59a5=a7_0x38fd[_0xd4d44b];return _0x4b59a5;};'use strict';var __awaiter=this&&this[a7_0x4b59('0x32')]||function(_0x19a46d,_0x319f0b,_0x5d4591,_0x5a5a8f){function _0x531f15(_0x3c62ef){return _0x3c62ef instanceof _0x5d4591?_0x3c62ef:new _0x5d4591(function(_0x4cce05){_0x4cce05(_0x3c62ef);});}return new(_0x5d4591||(_0x5d4591=Promise))(function(_0x53b1a6,_0x5ce1b7){function _0x41e7e5(_0x3c6b7f){try{_0x2fdc17(_0x5a5a8f['next'](_0x3c6b7f));}catch(_0x29a4b4){_0x5ce1b7(_0x29a4b4);}}function _0x5794cf(_0x1712b8){try{_0x2fdc17(_0x5a5a8f[a7_0x4b59('0x2c')](_0x1712b8));}catch(_0x252b7b){_0x5ce1b7(_0x252b7b);}}function _0x2fdc17(_0x1292df){_0x1292df[a7_0x4b59('0x25')]?_0x53b1a6(_0x1292df[a7_0x4b59('0x1a')]):_0x531f15(_0x1292df[a7_0x4b59('0x1a')])['then'](_0x41e7e5,_0x5794cf);}_0x2fdc17((_0x5a5a8f=_0x5a5a8f['apply'](_0x19a46d,_0x319f0b||[]))[a7_0x4b59('0x28')]());});};Object[a7_0x4b59('0x1f')](exports,a7_0x4b59('0x6'),{'value':!![]});exports['executeTasks']=void 0x0;const create_unchanged_value_timeout_1=require('../../../utilities/create-unchanged-value-timeout');const environment_1=require('../../../utilities/environment');const waiter_1=require(a7_0x4b59('0x2e'));const {output}=require(a7_0x4b59('0x8'));function executeTasks(_0x58714e,_0x14f9f1,_0xf99bd1,_0x11e789,_0x334340){return __awaiter(this,void 0x0,void 0x0,function*(){let _0x3c37bd=0x0;let _0x83f5f=null;const _0x46807c=(0x0,create_unchanged_value_timeout_1[a7_0x4b59('0x2a')])({'title':a7_0x4b59('0x1e')+environment_1[a7_0x4b59('0x7')]/0x3e8+a7_0x4b59('0x16'),'timeout':environment_1[a7_0x4b59('0x7')]});const _0x272189=new waiter_1['Waiter']();let _0x2c9a92=[];const _0x4c5f13=new Date();let _0x36ae83=![];const _0x15e85d={};while(!![]){if(environment_1[a7_0x4b59('0x2d')]){output[a7_0x4b59('0x13')]({'title':_0x58714e+a7_0x4b59('0x2b')});}_0x83f5f=yield _0x14f9f1[a7_0x4b59('0x2')](_0x83f5f?_0x83f5f[a7_0x4b59('0x10')]:null,_0x3c37bd,_0x2c9a92,_0x334340);if(environment_1[a7_0x4b59('0x2d')]){output[a7_0x4b59('0x13')]({'title':_0x58714e+a7_0x4b59('0xc'),'bodyLines':[a7_0x4b59('0x22')+_0x83f5f[a7_0x4b59('0x17')],a7_0x4b59('0x31')+_0x83f5f[a7_0x4b59('0x2f')],a7_0x4b59('0x1c')+_0x83f5f[a7_0x4b59('0xf')],a7_0x4b59('0x18')+_0x83f5f['executionId'],a7_0x4b59('0x23')+_0x83f5f[a7_0x4b59('0x2')]['length'],a7_0x4b59('0xd')+_0x83f5f['criticalErrorMessage'],a7_0x4b59('0x1')+_0x83f5f[a7_0x4b59('0x29')]]});}if(_0x83f5f[a7_0x4b59('0x5')]){output[a7_0x4b59('0x27')]({'title':a7_0x4b59('0x0'),'bodyLines':[a7_0x4b59('0x12'),_0x83f5f[a7_0x4b59('0x5')]]});process['exit'](0x0);}if((_0x83f5f===null||_0x83f5f===void 0x0?void 0x0:_0x83f5f[a7_0x4b59('0xf')])&&(_0x83f5f===null||_0x83f5f===void 0x0?void 0x0:_0x83f5f['retryDuring'])!==0x0&&!_0x36ae83&&new Date()[a7_0x4b59('0xb')]()-_0x4c5f13[a7_0x4b59('0xb')]()>_0x83f5f[a7_0x4b59('0xf')]){yield _0x272189[a7_0x4b59('0x24')]();continue;}if((_0x83f5f===null||_0x83f5f===void 0x0?void 0x0:_0x83f5f[a7_0x4b59('0x2f')])!==undefined){if(_0x83f5f[a7_0x4b59('0x2f')]===a7_0x4b59('0x4')||_0x83f5f[a7_0x4b59('0x2f')]===a7_0x4b59('0x3')){return;}}else if(_0x83f5f[a7_0x4b59('0x17')]){return;}_0x46807c(_0x83f5f[a7_0x4b59('0x2')]['map'](_0xcc4d3d=>_0xcc4d3d[a7_0x4b59('0xa')])[a7_0x4b59('0x11')](''));if(!_0x83f5f['executionId']){if(environment_1[a7_0x4b59('0x2d')]){output[a7_0x4b59('0x13')]({'title':_0x58714e+a7_0x4b59('0x26')});}yield _0x272189[a7_0x4b59('0x24')]();_0x3c37bd=0x0;_0x2c9a92=[];continue;}_0x272189[a7_0x4b59('0x30')]();_0x36ae83=!![];if(_0x83f5f[a7_0x4b59('0x21')]){for(const _0xc5bc5c of _0x83f5f[a7_0x4b59('0x21')]){if(_0x15e85d[_0xc5bc5c['taskId']])continue;output[a7_0x4b59('0x13')]({'title':_0x58714e+a7_0x4b59('0x1d')+_0xc5bc5c['taskId']+a7_0x4b59('0x15')+_0xc5bc5c[a7_0x4b59('0x1b')]+a7_0x4b59('0x14')+_0xc5bc5c[a7_0x4b59('0xe')]});yield _0xf99bd1[a7_0x4b59('0x9')](_0xc5bc5c['hash'],_0xc5bc5c[a7_0x4b59('0xe')]);_0x15e85d[_0xc5bc5c['taskId']]=!![];}}const _0x3e970e=yield _0x11e789(_0x83f5f['executionId'],_0x83f5f[a7_0x4b59('0x2')],_0x83f5f[a7_0x4b59('0x29')]);for(const _0x2cc62c of _0x3e970e[a7_0x4b59('0x21')]){_0x15e85d[_0x2cc62c[a7_0x4b59('0xa')]]=!![];}_0x3c37bd=_0x3e970e[a7_0x4b59('0x20')];_0x2c9a92=_0x3e970e[a7_0x4b59('0x21')];}});}exports[a7_0x4b59('0x19')]=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_0xe255=['assign','invokeTasksUsingNxImperativeApi','length','__esModule','invoke','NX_CACHE_FAILURES','NX_CLOUD_DISTRIBUTED_EXECUTION_ID','hash','status','apply','defineProperty','taskGraph','next','true','done','target','params','__awaiter','then','value','tasks','configuration','map','env','../../../utilities/serializer-overrides','yargs-parser','values','taskId','NX_STREAM_OUTPUT','projectName'];(function(_0x829912,_0xe255a5){const _0x1ed8a2=function(_0xfeef3b){while(--_0xfeef3b){_0x829912['push'](_0x829912['shift']());}};_0x1ed8a2(++_0xe255a5);}(a8_0xe255,0x86));const a8_0x1ed8=function(_0x829912,_0xe255a5){_0x829912=_0x829912-0x0;let _0x1ed8a2=a8_0xe255[_0x829912];return _0x1ed8a2;};'use strict';var __awaiter=this&&this[a8_0x1ed8('0x3')]||function(_0x128758,_0x19b521,_0x31df02,_0x1d1e15){function _0xe45e96(_0x1c629b){return _0x1c629b instanceof _0x31df02?_0x1c629b:new _0x31df02(function(_0x2cca2d){_0x2cca2d(_0x1c629b);});}return new(_0x31df02||(_0x31df02=Promise))(function(_0x4abe03,_0x317d7f){function _0x377701(_0x5047f5){try{_0x452a0e(_0x1d1e15[a8_0x1ed8('0x1c')](_0x5047f5));}catch(_0x1c496e){_0x317d7f(_0x1c496e);}}function _0x1e8a47(_0x489cd2){try{_0x452a0e(_0x1d1e15['throw'](_0x489cd2));}catch(_0xcb882){_0x317d7f(_0xcb882);}}function _0x452a0e(_0x1b4557){_0x1b4557[a8_0x1ed8('0x0')]?_0x4abe03(_0x1b4557['value']):_0xe45e96(_0x1b4557[a8_0x1ed8('0x5')])[a8_0x1ed8('0x4')](_0x377701,_0x1e8a47);}_0x452a0e((_0x1d1e15=_0x1d1e15[a8_0x1ed8('0x19')](_0x128758,_0x19b521||[]))['next']());});};Object[a8_0x1ed8('0x1a')](exports,a8_0x1ed8('0x13'),{'value':!![]});exports[a8_0x1ed8('0x11')]=void 0x0;const {initTasksRunner}=require('../../../utilities/nx-imports');const parser=require(a8_0x1ed8('0xb'));const serializer_overrides_1=require(a8_0x1ed8('0xa'));function invokeTasksUsingNxImperativeApi(_0x1de099){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x2d510d=yield initTasksRunner(_0x1de099);return(_0x2b96b2,_0x3cb4ae,_0xd282ba)=>__awaiter(this,void 0x0,void 0x0,function*(){const _0x3267ea=_0x3cb4ae['map'](_0x44a525=>{const _0x302f06=parser(_0x44a525[a8_0x1ed8('0x2')],{'configuration':{'camel-case-expansion':![],'dot-notation':!![]}});const _0x5f3cef=(0x0,serializer_overrides_1['unparse'])(_0x302f06);if(_0x302f06['_'][a8_0x1ed8('0x12')]==0x0){delete _0x302f06['_'];}return{'id':_0x44a525[a8_0x1ed8('0xd')],'target':{'project':_0x44a525[a8_0x1ed8('0xf')],'target':_0x44a525[a8_0x1ed8('0x1')],'configuration':_0x44a525[a8_0x1ed8('0x7')]},'overrides':Object[a8_0x1ed8('0x10')](Object[a8_0x1ed8('0x10')]({},_0x302f06),{'__overrides_unparsed__':_0x5f3cef})};});process['env'][a8_0x1ed8('0x15')]=a8_0x1ed8('0x1d');process[a8_0x1ed8('0x9')][a8_0x1ed8('0x16')]=_0x2b96b2;process[a8_0x1ed8('0x9')][a8_0x1ed8('0xe')]='true';process[a8_0x1ed8('0x9')]['NX_PREFIX_OUTPUT']=a8_0x1ed8('0x1d');const _0x44e42b=yield _0x2d510d[a8_0x1ed8('0x14')]({'tasks':_0x3267ea,'parallel':_0xd282ba});const _0x4297dc=Object[a8_0x1ed8('0xc')](_0x44e42b[a8_0x1ed8('0x1b')][a8_0x1ed8('0x6')]);return{'completedTasks':_0x4297dc[a8_0x1ed8('0x8')](_0x19f3e4=>({'taskId':_0x19f3e4['id'],'hash':_0x19f3e4[a8_0x1ed8('0x17')]})),'completedStatusCode':_0x44e42b[a8_0x1ed8('0x18')]};});});}exports[a8_0x1ed8('0x11')]=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_0x5044=['Executing:\x20\x27','params','__awaiter','next','assign','note','parse','apply','env','status','inherit','join','child_process','then','projectName','target','execSync','length','projects','configuration','getNxCacheDirectory','done','/tasks-hashes-','VERBOSE_LOGGING','toString','../../../utilities/environment','\x20--projects=','__esModule','invokeTasksUsingRunMany','readFileSync','value','find',').\x20Tasks\x20hashes\x20haven\x27t\x20been\x20recorded.','--configuration=','unlinkSync','defineProperty','true','push'];(function(_0x43d3ae,_0x50444c){const _0xf7bb65=function(_0x2d74b6){while(--_0x2d74b6){_0x43d3ae['push'](_0x43d3ae['shift']());}};_0xf7bb65(++_0x50444c);}(a9_0x5044,0x181));const a9_0xf7bb=function(_0x43d3ae,_0x50444c){_0x43d3ae=_0x43d3ae-0x0;let _0xf7bb65=a9_0x5044[_0x43d3ae];return _0xf7bb65;};'use strict';var __awaiter=this&&this[a9_0xf7bb('0x23')]||function(_0x2cb813,_0x342d76,_0x3fec54,_0xc98f91){function _0x1298ce(_0x4af74e){return _0x4af74e instanceof _0x3fec54?_0x4af74e:new _0x3fec54(function(_0x15603b){_0x15603b(_0x4af74e);});}return new(_0x3fec54||(_0x3fec54=Promise))(function(_0x1ec683,_0x35e996){function _0x5e7f7a(_0x1b74bc){try{_0x5c8f13(_0xc98f91[a9_0xf7bb('0x24')](_0x1b74bc));}catch(_0x2446d2){_0x35e996(_0x2446d2);}}function _0xa548ac(_0x4e124c){try{_0x5c8f13(_0xc98f91['throw'](_0x4e124c));}catch(_0x32ba24){_0x35e996(_0x32ba24);}}function _0x5c8f13(_0x2cf9b5){_0x2cf9b5[a9_0xf7bb('0x10')]?_0x1ec683(_0x2cf9b5[a9_0xf7bb('0x19')]):_0x1298ce(_0x2cf9b5[a9_0xf7bb('0x19')])[a9_0xf7bb('0x8')](_0x5e7f7a,_0xa548ac);}_0x5c8f13((_0xc98f91=_0xc98f91[a9_0xf7bb('0x2')](_0x2cb813,_0x342d76||[]))['next']());});};Object[a9_0xf7bb('0x1e')](exports,a9_0xf7bb('0x16'),{'value':!![]});exports['invokeTasksUsingRunMany']=void 0x0;const environment_1=require(a9_0xf7bb('0x14'));const child_process_1=require(a9_0xf7bb('0x7'));const fs_1=require('fs');const {output}=require('../../../utilities/nx-imports');function invokeTasksUsingRunMany(_0x3ae860){return __awaiter(this,void 0x0,void 0x0,function*(){const _0x39b10e=completedTasksReader(_0x3ae860);return function _0x332d22(_0x25e2bf,_0x47fb6a,_0x3f97a8){return __awaiter(this,void 0x0,void 0x0,function*(){let _0x4b4514=0x0;const _0x34b28d=[];for(const _0x471dab of groupByTarget(_0x47fb6a)){const _0x149899=_0x471dab[a9_0xf7bb('0xe')]?a9_0xf7bb('0x1c')+_0x471dab[a9_0xf7bb('0xe')]:'';const _0x3e5604=_0x3f97a8>0x1?'\x20--parallel\x20--max-parallel='+_0x3f97a8:'';const _0x2f49fd='npx\x20nx\x20run-many\x20--target='+_0x471dab[a9_0xf7bb('0xa')]+'\x20'+_0x149899+a9_0xf7bb('0x15')+_0x471dab[a9_0xf7bb('0xd')][a9_0xf7bb('0x6')](',')+'\x20'+_0x471dab[a9_0xf7bb('0x22')]+_0x3e5604;if(environment_1[a9_0xf7bb('0x12')]){output[a9_0xf7bb('0x0')]({'title':a9_0xf7bb('0x21')+_0x2f49fd+'\x27'});}try{(0x0,child_process_1[a9_0xf7bb('0xb')])(_0x2f49fd,{'stdio':['ignore',a9_0xf7bb('0x5'),a9_0xf7bb('0x5')],'env':Object[a9_0xf7bb('0x25')](Object[a9_0xf7bb('0x25')]({},process[a9_0xf7bb('0x3')]),{'NX_CACHE_FAILURES':a9_0xf7bb('0x1f'),'NX_CLOUD_DISTRIBUTED_EXECUTION_ID':_0x25e2bf,'NX_STREAM_OUTPUT':a9_0xf7bb('0x1f'),'NX_PREFIX_OUTPUT':'true'})});_0x34b28d['push'](..._0x39b10e(_0x25e2bf));}catch(_0x1df2e2){if(_0x1df2e2[a9_0xf7bb('0x4')]===environment_1['DISTRIBUTED_TASK_EXECUTION_INTERNAL_ERROR_STATUS_CODE']){throw _0x1df2e2;}else{_0x4b4514=0x1;_0x34b28d['push'](..._0x39b10e(_0x25e2bf));}}}return{'completedStatusCode':_0x4b4514,'completedTasks':_0x34b28d};});};});}exports[a9_0xf7bb('0x17')]=invokeTasksUsingRunMany;function groupByTarget(_0x27b2f5){const _0x601eff=[];_0x27b2f5['forEach'](_0x575510=>{const _0x2c5ad1=_0x601eff[a9_0xf7bb('0x1a')](_0x4efa99=>_0x4efa99[a9_0xf7bb('0xa')]===_0x575510[a9_0xf7bb('0xa')]&&_0x4efa99[a9_0xf7bb('0xe')]===_0x575510[a9_0xf7bb('0xe')]);if(_0x2c5ad1){_0x2c5ad1[a9_0xf7bb('0xd')]['push'](_0x575510[a9_0xf7bb('0x9')]);}else{_0x601eff[a9_0xf7bb('0x20')]({'target':_0x575510[a9_0xf7bb('0xa')],'projects':[_0x575510[a9_0xf7bb('0x9')]],'params':_0x575510[a9_0xf7bb('0x22')],'configuration':_0x575510[a9_0xf7bb('0xe')]});}});return _0x601eff;}function completedTasksReader(_0x57713b){const _0x37bd45=(0x0,environment_1[a9_0xf7bb('0xf')])(_0x57713b);return _0x306ff6=>{const _0x1f8f85='Command\x20execution\x20failed\x20(distributed\x20task\x20execution:\x20'+_0x306ff6+a9_0xf7bb('0x1b');let _0x1b8b26;try{const _0x5630d3=_0x37bd45+a9_0xf7bb('0x11')+_0x306ff6;_0x1b8b26=JSON[a9_0xf7bb('0x1')]((0x0,fs_1[a9_0xf7bb('0x18')])(_0x5630d3)[a9_0xf7bb('0x13')]());(0x0,fs_1[a9_0xf7bb('0x1d')])(_0x5630d3);}catch(_0x2e8771){throw new Error(_0x1f8f85);}if(_0x1b8b26[a9_0xf7bb('0xc')]==0x0){throw new Error(_0x1f8f85);}return _0x1b8b26;};}
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