@nrwl/nx-cloud 13.2.1 → 13.3.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.
package/bin/nx-cloud.js CHANGED
@@ -5,6 +5,7 @@ const distributed_agent_impl_1 = require("../lib/core/runners/distributed-agent/
5
5
  const start_ci_run_1 = require("../lib/core/commands/start-ci-run");
6
6
  const stop_all_agents_1 = require("../lib/core/commands/stop-all-agents");
7
7
  const clean_up_agents_1 = require("../lib/core/commands/clean-up-agents");
8
+ const record_output_1 = require("../lib/core/commands/record-output");
8
9
  const command = process.argv[2];
9
10
  if (command === 'start-agent') {
10
11
  (0, distributed_agent_impl_1.startAgent)().catch((e) => {
@@ -30,6 +31,12 @@ else if (command === 'clean-up-agents') {
30
31
  process.exit(1);
31
32
  });
32
33
  }
34
+ else if (command === 'record') {
35
+ (0, record_output_1.runCommandAndStoreInCloud)().catch((e) => {
36
+ console.error(e);
37
+ process.exit(1);
38
+ });
39
+ }
33
40
  else {
34
41
  console.log('Pass start-agent, stop-all-agents, or clean-up-agents');
35
42
  }
@@ -1 +1 @@
1
- {"version":3,"file":"nx-cloud.js","sourceRoot":"","sources":["../../../../../libs/nx-packages/nx-cloud/bin/nx-cloud.ts"],"names":[],"mappings":";;;AAEA,yGAA0F;AAC1F,oEAA+D;AAC/D,0EAAqE;AACrE,0EAAqE;AAErE,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAEhC,IAAI,OAAO,KAAK,aAAa,EAAE;IAC7B,IAAA,mCAAU,GAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACvB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ;KAAM,IAAI,OAAO,KAAK,iBAAiB,EAAE;IACxC,IAAA,+BAAa,GAAE,CAAC,KAA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KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QAC1B,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ;KAAM,IAAI,OAAO,KAAK,cAAc,EAAE;IACrC,IAAA,yBAAU,GAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACvB,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ;KAAM,IAAI,OAAO,KAAK,iBAAiB,EAAE;IACxC,IAAA,+BAAa,GAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QAC1B,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ;KAAM,IAAI,OAAO,KAAK,QAAQ,EAAE;IAC/B,IAAA,yCAAyB,GAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;QACtC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC,CAAC,CAAC;CACJ;KAAM;IACL,OAAO,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;CACtE"}
@@ -1 +1,65 @@
1
- const a0_0x1a13=['recordMetric','value','__awaiter','exit','defineProperty','axiosMultipleTries','axiosException','message','createRunGroup','createMetricRecorder','apply','throw','mapRespToPerfEntry','next','../../utilities/nx-imports','completeRunGroup','/nx-cloud/executions/create-run-group','__esModule','../../utilities/metric-logger','response','apiAxiosInstance','/nx-cloud/executions/complete-run-group','RunGroupApi','post','createApiAxiosInstance'];(function(_0x17f825,_0x1a1397){const _0x4b2d90=function(_0x3c3ecb){while(--_0x3c3ecb){_0x17f825['push'](_0x17f825['shift']());}};_0x4b2d90(++_0x1a1397);}(a0_0x1a13,0xc8));const a0_0x4b2d=function(_0x17f825,_0x1a1397){_0x17f825=_0x17f825-0x0;let _0x4b2d90=a0_0x1a13[_0x17f825];return _0x4b2d90;};'use strict';var __awaiter=this&&this[a0_0x4b2d('0x2')]||function(_0x2338d2,_0x402c74,_0x1d4481,_0x1602e2){function _0x221966(_0x13e42c){return _0x13e42c instanceof _0x1d4481?_0x13e42c:new _0x1d4481(function(_0x51580b){_0x51580b(_0x13e42c);});}return new(_0x1d4481||(_0x1d4481=Promise))(function(_0x122596,_0x2f46e8){function _0x255101(_0x1c5bbf){try{_0x5858bd(_0x1602e2[a0_0x4b2d('0xd')](_0x1c5bbf));}catch(_0x454119){_0x2f46e8(_0x454119);}}function _0x54c56e(_0x477902){try{_0x5858bd(_0x1602e2[a0_0x4b2d('0xb')](_0x477902));}catch(_0x485983){_0x2f46e8(_0x485983);}}function _0x5858bd(_0x331bd4){_0x331bd4['done']?_0x122596(_0x331bd4[a0_0x4b2d('0x1')]):_0x221966(_0x331bd4[a0_0x4b2d('0x1')])['then'](_0x255101,_0x54c56e);}_0x5858bd((_0x1602e2=_0x1602e2[a0_0x4b2d('0xa')](_0x2338d2,_0x402c74||[]))[a0_0x4b2d('0xd')]());});};Object[a0_0x4b2d('0x4')](exports,a0_0x4b2d('0x11'),{'value':!![]});exports[a0_0x4b2d('0x16')]=void 0x0;const axios_1=require('../../utilities/axios');const metric_logger_1=require(a0_0x4b2d('0x12'));const {output}=require(a0_0x4b2d('0xe'));class RunGroupApi{constructor(_0xab9bdd){this[a0_0x4b2d('0x14')]=(0x0,axios_1[a0_0x4b2d('0x18')])(_0xab9bdd);}[a0_0x4b2d('0x8')](_0x28c98b,_0x13f03e){var _0x40c94e;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x668199=(0x0,metric_logger_1[a0_0x4b2d('0x9')])(a0_0x4b2d('0x8'));try{const _0x43a4de=yield(0x0,axios_1['axiosMultipleTries'])(()=>this[a0_0x4b2d('0x14')][a0_0x4b2d('0x17')](a0_0x4b2d('0x10'),{'branch':_0x28c98b,'runGroup':_0x13f03e}));_0x668199[a0_0x4b2d('0x0')]((0x0,metric_logger_1['mapRespToPerfEntry'])(_0x43a4de));}catch(_0x24594d){_0x668199[a0_0x4b2d('0x0')](((_0x40c94e=_0x24594d===null||_0x24594d===void 0x0?void 0x0:_0x24594d[a0_0x4b2d('0x6')])===null||_0x40c94e===void 0x0?void 0x0:_0x40c94e['response'])?(0x0,metric_logger_1[a0_0x4b2d('0xc')])(_0x24594d[a0_0x4b2d('0x6')][a0_0x4b2d('0x13')]):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);output['error']({'title':_0x24594d['message']});process[a0_0x4b2d('0x3')](0x1);}});}[a0_0x4b2d('0xf')](_0xc9c895){var _0x2c35b6;return __awaiter(this,void 0x0,void 0x0,function*(){const _0x184a20=(0x0,metric_logger_1['createMetricRecorder'])(a0_0x4b2d('0x8'));try{const _0x1d6c53=yield(0x0,axios_1[a0_0x4b2d('0x5')])(()=>this[a0_0x4b2d('0x14')][a0_0x4b2d('0x17')](a0_0x4b2d('0x15'),{'runGroup':_0xc9c895}));_0x184a20['recordMetric']((0x0,metric_logger_1[a0_0x4b2d('0xc')])(_0x1d6c53));}catch(_0x656f8b){_0x184a20[a0_0x4b2d('0x0')](((_0x2c35b6=_0x656f8b===null||_0x656f8b===void 0x0?void 0x0:_0x656f8b[a0_0x4b2d('0x6')])===null||_0x2c35b6===void 0x0?void 0x0:_0x2c35b6[a0_0x4b2d('0x13')])?(0x0,metric_logger_1[a0_0x4b2d('0xc')])(_0x656f8b['axiosException'][a0_0x4b2d('0x13')]):metric_logger_1['RUNNER_FAILURE_PERF_ENTRY']);output['error']({'title':_0x656f8b[a0_0x4b2d('0x7')]});process[a0_0x4b2d('0x3')](0x1);}});}}exports[a0_0x4b2d('0x16')]=RunGroupApi;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.RunGroupApi = void 0;
13
+ const axios_1 = require("../../utilities/axios");
14
+ const metric_logger_1 = require("../../utilities/metric-logger");
15
+ const { output } = require('../../utilities/nx-imports');
16
+ class RunGroupApi {
17
+ constructor(options) {
18
+ this.apiAxiosInstance = (0, axios_1.createApiAxiosInstance)(options);
19
+ }
20
+ createRunGroup(branch, runGroup) {
21
+ var _a;
22
+ return __awaiter(this, void 0, void 0, function* () {
23
+ const recorder = (0, metric_logger_1.createMetricRecorder)('createRunGroup');
24
+ try {
25
+ const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/create-run-group', {
26
+ branch: branch,
27
+ runGroup: runGroup,
28
+ }));
29
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
30
+ }
31
+ catch (e) {
32
+ recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
33
+ ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
34
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
35
+ output.error({
36
+ title: e.message,
37
+ });
38
+ process.exit(1);
39
+ }
40
+ });
41
+ }
42
+ completeRunGroup(runGroup) {
43
+ var _a;
44
+ return __awaiter(this, void 0, void 0, function* () {
45
+ const recorder = (0, metric_logger_1.createMetricRecorder)('createRunGroup');
46
+ try {
47
+ const resp = yield (0, axios_1.axiosMultipleTries)(() => this.apiAxiosInstance.post('/nx-cloud/executions/complete-run-group', {
48
+ runGroup: runGroup,
49
+ }));
50
+ recorder.recordMetric((0, metric_logger_1.mapRespToPerfEntry)(resp));
51
+ }
52
+ catch (e) {
53
+ recorder.recordMetric(((_a = e === null || e === void 0 ? void 0 : e.axiosException) === null || _a === void 0 ? void 0 : _a.response)
54
+ ? (0, metric_logger_1.mapRespToPerfEntry)(e.axiosException.response)
55
+ : metric_logger_1.RUNNER_FAILURE_PERF_ENTRY);
56
+ output.error({
57
+ title: e.message,
58
+ });
59
+ process.exit(1);
60
+ }
61
+ });
62
+ }
63
+ }
64
+ exports.RunGroupApi = RunGroupApi;
65
+ //# sourceMappingURL=run-group.api.js.map
@@ -0,0 +1,16 @@
1
+ export declare function runCommandAndStoreInCloud(): Promise<void>;
2
+ /**
3
+ * https://github.com/nrwl/nx/blob/master/packages/nx/src/utils/find-workspace-root.ts
4
+ * Recursive function that walks back up the directory
5
+ * tree to try and find a workspace file.
6
+ *
7
+ * @param dir Directory to start searching with
8
+ */
9
+ export declare function findWorkspaceRoot(dir: string): WorkspaceTypeAndRoot | null;
10
+ /**
11
+ * https://github.com/nrwl/nx/blob/master/packages/nx/src/utils/find-workspace-root.ts
12
+ */
13
+ export interface WorkspaceTypeAndRoot {
14
+ type: 'nx' | 'angular';
15
+ dir: string;
16
+ }
@@ -0,0 +1,200 @@
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.findWorkspaceRoot = exports.runCommandAndStoreInCloud = void 0;
13
+ const cp = require("child_process");
14
+ const fs_1 = require("fs");
15
+ const path = require("path");
16
+ const environment_1 = require("../../utilities/environment");
17
+ const axios_1 = require("../../utilities/axios");
18
+ const util_1 = require("util");
19
+ const zlib_1 = require("zlib");
20
+ const output_obfuscator_1 = require("../terminal-output/output-obfuscator");
21
+ const print_message_1 = require("../../utilities/print-message");
22
+ const { output } = require('../../utilities/nx-imports');
23
+ const MAX_CHARACTERS_OUTPUT_CAPTURE = 200000;
24
+ function runCommandAndStoreInCloud() {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const taskRunnerOptions = getTaskRunnerOptions();
27
+ const axios = (0, axios_1.createApiAxiosInstance)(taskRunnerOptions);
28
+ const outputObfuscator = new output_obfuscator_1.OutputObfuscator(taskRunnerOptions.maskedProperties);
29
+ const branch = (0, environment_1.getBranch)();
30
+ const runGroup = (0, environment_1.getRunGroup)();
31
+ let userCommandAndArgs;
32
+ const commandStartIndex = process.argv.findIndex((arg) => arg === 'record');
33
+ if (commandStartIndex < process.argv.length - 1) {
34
+ userCommandAndArgs = process.argv.slice(commandStartIndex + 1);
35
+ }
36
+ else {
37
+ console.log('Invalid command. Use `nx-cloud record [my command] [my arg1] [my arg...]`');
38
+ process.exit(1);
39
+ }
40
+ const [userCommand, ...userArgs] = userCommandAndArgs;
41
+ const startRecordRunRequest = {
42
+ branch,
43
+ runGroup,
44
+ hashes: [],
45
+ };
46
+ yield (0, axios_1.axiosMultipleTries)(() => axios.post('/nx-cloud/runs/start', startRecordRunRequest));
47
+ const startTime = new Date().toISOString();
48
+ const { statusCode, terminalOutput } = yield spawnUserCommandAndCaptureOutput(userCommand, userArgs);
49
+ const endTime = new Date().toISOString();
50
+ const endRecordOutputRunParams = {
51
+ statusCode,
52
+ terminalOutput,
53
+ userCommandAndArgsString: userCommandAndArgs.join(' '),
54
+ startTime,
55
+ endTime,
56
+ branch,
57
+ runGroup,
58
+ };
59
+ yield endRecordOutputRun(axios, outputObfuscator, taskRunnerOptions, endRecordOutputRunParams);
60
+ });
61
+ }
62
+ exports.runCommandAndStoreInCloud = runCommandAndStoreInCloud;
63
+ function getTaskRunnerOptions() {
64
+ var _a, _b, _c;
65
+ const workspaceRoot = findWorkspaceRoot(process.cwd());
66
+ if (workspaceRoot == null) {
67
+ throw new Error('Unable to locate task runner options.');
68
+ }
69
+ else {
70
+ const taskRunnerOptions = (_c = (_b = (_a = require(`${workspaceRoot.dir}/nx.json`)) === null || _a === void 0 ? void 0 : _a.tasksRunnerOptions) === null || _b === void 0 ? void 0 : _b.default) === null || _c === void 0 ? void 0 : _c.options;
71
+ return taskRunnerOptions;
72
+ }
73
+ }
74
+ function splitUserCommandAndArgs(userCommandAndArgs) {
75
+ const userCommand = userCommandAndArgs[0];
76
+ let userArgs = [];
77
+ if (userCommandAndArgs.length > 1) {
78
+ userArgs = userCommandAndArgs.slice(1);
79
+ }
80
+ return { userCommand, userArgs };
81
+ }
82
+ function spawnUserCommandAndCaptureOutput(command, args) {
83
+ return new Promise((res, rej) => {
84
+ try {
85
+ const userCommandProcess = cp.spawn(command, args, {
86
+ stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
87
+ });
88
+ const outLines = [];
89
+ userCommandProcess.stdout.on('data', (chunk) => {
90
+ process.stdout.write(chunk);
91
+ outLines.push(chunk.toString());
92
+ });
93
+ userCommandProcess.stderr.on('data', (chunk) => {
94
+ process.stderr.write(chunk);
95
+ outLines.push(chunk.toString());
96
+ });
97
+ userCommandProcess.on('exit', (exitCode, exitSignal) => {
98
+ const statusCode = exitCode !== null && exitCode !== void 0 ? exitCode : signalToCode(exitSignal || '');
99
+ const joinedOutput = outLines.join('');
100
+ res({
101
+ statusCode,
102
+ terminalOutput: joinedOutput,
103
+ });
104
+ });
105
+ }
106
+ catch (e) {
107
+ rej(e);
108
+ }
109
+ });
110
+ }
111
+ function createTaskDefinitionFromUserCommand(outputObfuscator, params) {
112
+ const sanitizedOutput = outputObfuscator.obfuscate(params.terminalOutput);
113
+ const truncatedOutput = sanitizedOutput.length > MAX_CHARACTERS_OUTPUT_CAPTURE
114
+ ? `TRUNCATED\n\n${sanitizedOutput.slice(sanitizedOutput.length - MAX_CHARACTERS_OUTPUT_CAPTURE)}`
115
+ : sanitizedOutput;
116
+ return {
117
+ taskId: 'nx-cloud-tasks-runner:record-command',
118
+ target: 'record-command',
119
+ projectName: 'nx-cloud-tasks-runner',
120
+ hash: '',
121
+ startTime: params.startTime,
122
+ endTime: params.endTime,
123
+ hashDetails: {},
124
+ params: params.userCommandAndArgsString,
125
+ cacheStatus: 'n/a',
126
+ status: params.statusCode,
127
+ terminalOutput: truncatedOutput,
128
+ };
129
+ }
130
+ function endRecordOutputRun(axios, obfuscator, taskRunnerOptions, params) {
131
+ return __awaiter(this, void 0, void 0, function* () {
132
+ const commandWithPrefix = `nx-cloud record -- ${params.userCommandAndArgsString}`;
133
+ const endRunReq = {
134
+ meta: {
135
+ nxCloudVersion: '0.0.0',
136
+ },
137
+ tasks: [createTaskDefinitionFromUserCommand(obfuscator, params)],
138
+ run: {
139
+ command: commandWithPrefix,
140
+ startTime: params.startTime,
141
+ endTime: params.endTime,
142
+ branch: params.branch,
143
+ scan: true,
144
+ runGroup: params.runGroup,
145
+ // only set sha if branch is set because we invoke a separate process,
146
+ // which adds a few millis
147
+ sha: params.branch ? (0, environment_1.extractGitSha)() : undefined,
148
+ },
149
+ machineInfo: (0, environment_1.getMachineInfo)(taskRunnerOptions),
150
+ };
151
+ const uncompressedBuffer = Buffer.from(JSON.stringify(endRunReq));
152
+ const compressedBuffer = yield (0, util_1.promisify)(zlib_1.gzip)(uncompressedBuffer);
153
+ const endRunResp = yield (0, axios_1.axiosMultipleTries)(() => axios.post('/nx-cloud/runs/end', compressedBuffer, {
154
+ headers: Object.assign(Object.assign({}, axios.defaults.headers), { 'Content-Encoding': 'gzip', 'Content-Type': 'application/octet-stream' }),
155
+ }));
156
+ printRecordOutputRunEndMessage(endRunResp.data.runUrl);
157
+ });
158
+ }
159
+ function printRecordOutputRunEndMessage(runUrl) {
160
+ output.addVerticalSeparator();
161
+ output.note({ title: 'Nx Cloud: Successfully recorded command output' });
162
+ (0, print_message_1.printMessage)(`You can view or share your output by visiting ${runUrl}`);
163
+ }
164
+ // Everything from here down is ripped from the nx package
165
+ // You probably don't want to adjust this manually
166
+ /**
167
+ * https://github.com/nrwl/nx/blob/master/packages/nx/src/utils/find-workspace-root.ts
168
+ * Recursive function that walks back up the directory
169
+ * tree to try and find a workspace file.
170
+ *
171
+ * @param dir Directory to start searching with
172
+ */
173
+ function findWorkspaceRoot(dir) {
174
+ if ((0, fs_1.existsSync)(path.join(dir, 'angular.json'))) {
175
+ return { type: 'angular', dir };
176
+ }
177
+ if ((0, fs_1.existsSync)(path.join(dir, 'nx.json'))) {
178
+ return { type: 'nx', dir };
179
+ }
180
+ if (path.dirname(dir) === dir) {
181
+ return null;
182
+ }
183
+ return findWorkspaceRoot(path.dirname(dir));
184
+ }
185
+ exports.findWorkspaceRoot = findWorkspaceRoot;
186
+ /**
187
+ * https://github.com/nrwl/nx/blob/master/packages/nx/src/tasks-runner/forked-process-task-runner.ts
188
+ *
189
+ * @param signal
190
+ */
191
+ function signalToCode(signal) {
192
+ if (signal === 'SIGHUP')
193
+ return 128 + 1;
194
+ if (signal === 'SIGINT')
195
+ return 128 + 2;
196
+ if (signal === 'SIGTERM')
197
+ return 128 + 15;
198
+ return 128;
199
+ }
200
+ //# sourceMappingURL=record-output.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record-output.js","sourceRoot":"","sources":["../../../../../../../libs/nx-packages/nx-cloud/lib/core/commands/record-output.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,oCAAoC;AACpC,2BAAgC;AAChC,6BAA6B;AAC7B,6DAKqC;AAErC,iDAG+B;AAC/B,+BAAiC;AACjC,+BAA4B;AAE5B,4EAAwE;AACx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AO,CAAC,GAAG,CAAC,KAAK,GAAG,EAAE;QAC7B,OAAO,IAAI,CAAC;KACb;IAED,OAAO,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;AAC9C,CAAC;AAdD,8CAcC;AAUD;;;;GAIG;AACH,SAAS,YAAY,CAAC,MAAc;IAClC,IAAI,MAAM,KAAK,QAAQ;QAAE,OAAO,GAAG,GAAG,CAAC,CAAC;IACxC,IAAI,MAAM,KAAK,QAAQ;QAAE,OAAO,GAAG,GAAG,CAAC,CAAC;IACxC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,GAAG,GAAG,EAAE,CAAC;IAC1C,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -1 +1,138 @@
1
- const a0_0x47d9=['configuration','assign','runtime','toISOString','statuses','cleanUpHashDetails','CloudEnabledLifeCycle','endCommand','status','MAX_CHARACTERS_SUCCESSFUL_TASK','remote-cache-hit','cacheStatus','MAX_CHARACTERS_CACHED_TASK','MAX_CHARACTERS_FAILED_TASK','taskId','readTerminalOutputFile','hashDetails','project','slice','updateStartedTask','getTerminalOutput','keys','local-cache-hit','join','tasks','nodes','filter','readFileSync','push','local-cache-kept-existing','local-cache','outputObfuscator','endTasks','terminalOutputs','overrides','cache-miss','target','toString','forEach','__esModule','collectTerminalOutput','defineProperty','cacheDirectory','startsWith','hash','obfuscate','length','scheduledTasks','terminalOutput','cacheableOperations','runContext','skipNxCache','endTask','startTask','path','remote-cache','find','node_modules','indexOf','.cache'];(function(_0x10c6de,_0x47d9f3){const _0x46b8de=function(_0x229dff){while(--_0x229dff){_0x10c6de['push'](_0x10c6de['shift']());}};_0x46b8de(++_0x47d9f3);}(a0_0x47d9,0xaa));const a0_0x46b8=function(_0x10c6de,_0x47d9f3){_0x10c6de=_0x10c6de-0x0;let _0x46b8de=a0_0x47d9[_0x10c6de];return _0x46b8de;};'use strict';Object[a0_0x46b8('0x33')](exports,a0_0x46b8('0x31'),{'value':!![]});exports[a0_0x46b8('0x10')]=void 0x0;const path=require(a0_0x46b8('0x4'));const path_1=require(a0_0x46b8('0x4'));const fs_1=require('fs');const {appRootPath,unparse}=require('../../../utilities/nx-imports');class CloudEnabledLifeCycle{constructor(_0x4a182d,_0x486429,_0x3ec134,_0x3178ea,_0xb393d2,_0xa3095e,_0x1356c6){this['runContext']=_0x4a182d;this[a0_0x46b8('0x34')]=_0x486429;this[a0_0x46b8('0x1')]=_0x3ec134;this[a0_0x46b8('0x32')]=_0x3178ea;this['cacheableOperations']=_0xb393d2;this[a0_0x46b8('0x29')]=_0xa3095e;this[a0_0x46b8('0x22')]=_0x1356c6;}['scheduleTask'](_0x5da31c){this['runContext'][a0_0x46b8('0x39')][a0_0x46b8('0x26')](_0x5da31c);}[a0_0x46b8('0x3')](_0x3d1ba5){const _0x14e1b2=Object[a0_0x46b8('0xb')]({},_0x3d1ba5[a0_0x46b8('0x2c')]||{});if(_0x3d1ba5[a0_0x46b8('0x2e')][a0_0x46b8('0xa')]){_0x14e1b2[a0_0x46b8('0xa')]=_0x3d1ba5['target'][a0_0x46b8('0xa')];}this[a0_0x46b8('0x22')][a0_0x46b8('0x26')]({'taskId':_0x3d1ba5['id'],'startTime':new Date()[a0_0x46b8('0xd')](),'target':_0x3d1ba5[a0_0x46b8('0x2e')][a0_0x46b8('0x2e')],'projectName':_0x3d1ba5['target'][a0_0x46b8('0x1b')],'hash':_0x3d1ba5[a0_0x46b8('0x36')],'hashDetails':this['cleanUpHashDetails'](_0x3d1ba5[a0_0x46b8('0x1a')]),'params':unparse(_0x14e1b2)[a0_0x46b8('0x21')]('\x20')});}[a0_0x46b8('0x2')](_0x3d8c13,_0x347740){let _0xd2c0d7;if(this[a0_0x46b8('0x0')][a0_0x46b8('0xe')][_0x3d8c13[a0_0x46b8('0x36')]]){_0xd2c0d7=this[a0_0x46b8('0x0')]['statuses'][_0x3d8c13['hash']];}else{if(this[a0_0x46b8('0x3b')][a0_0x46b8('0x8')](_0x3d8c13['target']['target'])>-0x1&&!this[a0_0x46b8('0x1')]){_0xd2c0d7=a0_0x46b8('0x20');}else{_0xd2c0d7=a0_0x46b8('0x2d');}}this[a0_0x46b8('0x1d')](_0x3d8c13,_0x347740,_0xd2c0d7);}[a0_0x46b8('0x2a')](_0x38e005){for(let _0x505404 of _0x38e005){const _0x507ac9=_0x505404[a0_0x46b8('0x12')]===a0_0x46b8('0x5')?a0_0x46b8('0x14'):_0x505404['status']===a0_0x46b8('0x28')||_0x505404[a0_0x46b8('0x12')]===a0_0x46b8('0x27')?a0_0x46b8('0x20'):a0_0x46b8('0x2d');this['updateStartedTask'](_0x505404['task'],_0x505404['code'],_0x507ac9);}}[a0_0x46b8('0x11')](){}['updateStartedTask'](_0x232b2d,_0xf60ebe,_0x31d594){const _0x246378=this['tasks'][a0_0x46b8('0x6')](_0x5a4dc2=>_0x5a4dc2[a0_0x46b8('0x18')]===_0x232b2d['id']);if(!_0x246378){throw new Error('Cannot\x20find\x20task\x20'+_0x232b2d['id']);}_0x246378['endTime']=new Date()['toISOString']();_0x246378['status']=_0xf60ebe;_0x246378['params']=this['outputObfuscator'][a0_0x46b8('0x37')](_0x246378['params']);_0x246378[a0_0x46b8('0x15')]=_0x31d594;if(this[a0_0x46b8('0x32')]){_0x246378['terminalOutput']=this[a0_0x46b8('0x1e')](_0x232b2d[a0_0x46b8('0x36')],_0x246378[a0_0x46b8('0x15')],_0xf60ebe);}}[a0_0x46b8('0x1e')](_0x3dd733,_0x35d48f,_0x55cbfe){let _0x3f194a;if(this[a0_0x46b8('0x34')]){if(this[a0_0x46b8('0x34')][a0_0x46b8('0x35')]('./')){_0x3f194a=(0x0,path_1['join'])(appRootPath,this['cacheDirectory']);}else{_0x3f194a=this[a0_0x46b8('0x34')];}}else{_0x3f194a=(0x0,path_1['join'])(appRootPath,a0_0x46b8('0x7'),a0_0x46b8('0x9'),'nx');}try{const _0x516e3d=this[a0_0x46b8('0x19')](_0x3f194a,_0x3dd733);const _0x2bfe71=this[a0_0x46b8('0x29')]['obfuscate'](_0x516e3d);const _0x2551ae=_0x35d48f===a0_0x46b8('0x2d')?_0x55cbfe===0x0?CloudEnabledLifeCycle[a0_0x46b8('0x13')]:CloudEnabledLifeCycle[a0_0x46b8('0x17')]:CloudEnabledLifeCycle[a0_0x46b8('0x16')];return _0x2bfe71[a0_0x46b8('0x38')]>_0x2551ae?'TRUNCATED\x0a\x0a'+_0x2bfe71[a0_0x46b8('0x1c')](_0x2bfe71[a0_0x46b8('0x38')]-_0x2551ae):_0x2bfe71;}catch(_0x4a96e3){return'';}}[a0_0x46b8('0xf')](_0x479359){const _0x3f47da={};Object[a0_0x46b8('0x1f')](_0x479359[a0_0x46b8('0x23')])[a0_0x46b8('0x24')](_0x37185c=>!_0x37185c[a0_0x46b8('0x35')]('npm:'))[a0_0x46b8('0x30')](_0x2dc5c4=>{_0x3f47da[_0x2dc5c4]=_0x479359[a0_0x46b8('0x23')][_0x2dc5c4];});return{'nodes':_0x3f47da,'runtime':_0x479359[a0_0x46b8('0xc')],'implicitDeps':_0x479359['implicitDeps']};}[a0_0x46b8('0x19')](_0x31c26a,_0x254dc0){try{return(0x0,fs_1[a0_0x46b8('0x25')])(path[a0_0x46b8('0x21')](_0x31c26a,a0_0x46b8('0x2b'),_0x254dc0))[a0_0x46b8('0x2f')]();}catch(_0x5ca910){try{return(0x0,fs_1[a0_0x46b8('0x25')])(path[a0_0x46b8('0x21')](_0x31c26a,_0x254dc0,a0_0x46b8('0x3a')))['toString']();}catch(_0x351acc){return'';}}}}exports[a0_0x46b8('0x10')]=CloudEnabledLifeCycle;CloudEnabledLifeCycle['MAX_CHARACTERS_FAILED_TASK']=0x30d40;CloudEnabledLifeCycle[a0_0x46b8('0x13')]=0x4e20;CloudEnabledLifeCycle[a0_0x46b8('0x16')]=0x1388;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CloudEnabledLifeCycle = void 0;
4
+ const path = require("path");
5
+ const path_1 = require("path");
6
+ const fs_1 = require("fs");
7
+ const { appRootPath, unparse } = require('../../../utilities/nx-imports');
8
+ class CloudEnabledLifeCycle {
9
+ constructor(runContext, cacheDirectory, skipNxCache, collectTerminalOutput, cacheableOperations, outputObfuscator, tasks) {
10
+ this.runContext = runContext;
11
+ this.cacheDirectory = cacheDirectory;
12
+ this.skipNxCache = skipNxCache;
13
+ this.collectTerminalOutput = collectTerminalOutput;
14
+ this.cacheableOperations = cacheableOperations;
15
+ this.outputObfuscator = outputObfuscator;
16
+ this.tasks = tasks;
17
+ }
18
+ scheduleTask(task) {
19
+ this.runContext.scheduledTasks.push(task);
20
+ }
21
+ startTask(task) {
22
+ const overrides = Object.assign({}, (task.overrides || {}));
23
+ if (task.target.configuration) {
24
+ overrides['configuration'] = task.target.configuration;
25
+ }
26
+ this.tasks.push({
27
+ taskId: task.id,
28
+ startTime: new Date().toISOString(),
29
+ target: task.target.target,
30
+ projectName: task.target.project,
31
+ hash: task.hash,
32
+ hashDetails: this.cleanUpHashDetails(task.hashDetails),
33
+ params: unparse(overrides).join(' '),
34
+ });
35
+ }
36
+ // Used for older version for Nx. Remove in Dec 2022
37
+ endTask(task, code) {
38
+ let cacheStatus;
39
+ if (this.runContext.statuses[task.hash]) {
40
+ cacheStatus = this.runContext.statuses[task.hash];
41
+ }
42
+ else {
43
+ if (this.cacheableOperations.indexOf(task.target.target) > -1 &&
44
+ !this.skipNxCache) {
45
+ cacheStatus = 'local-cache-hit';
46
+ }
47
+ else {
48
+ cacheStatus = 'cache-miss';
49
+ }
50
+ }
51
+ this.updateStartedTask(task, code, cacheStatus);
52
+ }
53
+ endTasks(tasks) {
54
+ for (let t of tasks) {
55
+ const status = t.status === 'remote-cache'
56
+ ? 'remote-cache-hit'
57
+ : t.status === 'local-cache' ||
58
+ t.status === 'local-cache-kept-existing'
59
+ ? 'local-cache-hit'
60
+ : 'cache-miss';
61
+ this.updateStartedTask(t.task, t.code, status);
62
+ }
63
+ }
64
+ endCommand() { }
65
+ updateStartedTask(task, code, cacheStatus) {
66
+ const startedTask = this.tasks.find((t) => t.taskId === task.id);
67
+ if (!startedTask) {
68
+ throw new Error(`Cannot find task ${task.id}`);
69
+ }
70
+ startedTask.endTime = new Date().toISOString();
71
+ startedTask.status = code;
72
+ startedTask.params = this.outputObfuscator.obfuscate(startedTask.params);
73
+ startedTask.cacheStatus = cacheStatus;
74
+ if (this.collectTerminalOutput) {
75
+ startedTask.terminalOutput = this.getTerminalOutput(task.hash, startedTask.cacheStatus, code);
76
+ }
77
+ }
78
+ getTerminalOutput(hash, cacheStatus, code) {
79
+ let dir;
80
+ if (this.cacheDirectory) {
81
+ if (this.cacheDirectory.startsWith('./')) {
82
+ dir = (0, path_1.join)(appRootPath, this.cacheDirectory);
83
+ }
84
+ else {
85
+ dir = this.cacheDirectory;
86
+ }
87
+ }
88
+ else {
89
+ dir = (0, path_1.join)(appRootPath, 'node_modules', '.cache', 'nx');
90
+ }
91
+ try {
92
+ const taskOutput = this.readTerminalOutputFile(dir, hash);
93
+ const taskOutputSanitized = this.outputObfuscator.obfuscate(taskOutput);
94
+ const maxCharacters = cacheStatus === 'cache-miss'
95
+ ? code === 0
96
+ ? CloudEnabledLifeCycle.MAX_CHARACTERS_SUCCESSFUL_TASK
97
+ : CloudEnabledLifeCycle.MAX_CHARACTERS_FAILED_TASK
98
+ : CloudEnabledLifeCycle.MAX_CHARACTERS_CACHED_TASK;
99
+ return taskOutputSanitized.length > maxCharacters
100
+ ? `TRUNCATED\n\n${taskOutputSanitized.slice(taskOutputSanitized.length - maxCharacters)}`
101
+ : taskOutputSanitized;
102
+ }
103
+ catch (e) {
104
+ return '';
105
+ }
106
+ }
107
+ cleanUpHashDetails(hashDetails) {
108
+ const nodes = {};
109
+ Object.keys(hashDetails.nodes)
110
+ .filter((k) => !k.startsWith('npm:'))
111
+ .forEach((k) => {
112
+ nodes[k] = hashDetails.nodes[k];
113
+ });
114
+ return {
115
+ nodes,
116
+ runtime: hashDetails.runtime,
117
+ implicitDeps: hashDetails.implicitDeps,
118
+ };
119
+ }
120
+ readTerminalOutputFile(dir, hash) {
121
+ try {
122
+ return (0, fs_1.readFileSync)(path.join(dir, 'terminalOutputs', hash)).toString();
123
+ }
124
+ catch (_a) {
125
+ try {
126
+ return (0, fs_1.readFileSync)(path.join(dir, hash, 'terminalOutput')).toString();
127
+ }
128
+ catch (_b) {
129
+ return '';
130
+ }
131
+ }
132
+ }
133
+ }
134
+ exports.CloudEnabledLifeCycle = CloudEnabledLifeCycle;
135
+ CloudEnabledLifeCycle.MAX_CHARACTERS_FAILED_TASK = 200000;
136
+ CloudEnabledLifeCycle.MAX_CHARACTERS_SUCCESSFUL_TASK = 20000;
137
+ CloudEnabledLifeCycle.MAX_CHARACTERS_CACHED_TASK = 5000;
138
+ //# sourceMappingURL=cloud-enabled-life-cycle.js.map