nx 19.6.2 → 19.7.0-beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. package/package.json +12 -12
  2. package/src/daemon/client/client.d.ts +3 -6
  3. package/src/daemon/client/client.js +5 -4
  4. package/src/daemon/message-types/task-history.d.ts +9 -9
  5. package/src/daemon/message-types/task-history.js +7 -7
  6. package/src/daemon/server/handle-task-history.d.ts +9 -0
  7. package/src/daemon/server/handle-task-history.js +28 -0
  8. package/src/daemon/server/server.js +4 -5
  9. package/src/hasher/hash-task.js +36 -1
  10. package/src/native/index.d.ts +45 -4
  11. package/src/native/native-bindings.js +4 -0
  12. package/src/native/nx.wasi-browser.js +50 -36
  13. package/src/native/nx.wasi.cjs +48 -36
  14. package/src/native/nx.wasm32-wasi.wasm +0 -0
  15. package/src/nx-cloud/update-manager.d.ts +2 -0
  16. package/src/tasks-runner/cache.d.ts +21 -2
  17. package/src/tasks-runner/cache.js +117 -25
  18. package/src/tasks-runner/default-tasks-runner.d.ts +6 -0
  19. package/src/tasks-runner/default-tasks-runner.js +34 -1
  20. package/src/tasks-runner/life-cycles/task-history-life-cycle-old.d.ts +9 -0
  21. package/src/tasks-runner/life-cycles/task-history-life-cycle-old.js +54 -0
  22. package/src/tasks-runner/life-cycles/task-history-life-cycle.d.ts +1 -0
  23. package/src/tasks-runner/life-cycles/task-history-life-cycle.js +19 -21
  24. package/src/tasks-runner/run-command.js +3 -1
  25. package/src/tasks-runner/task-orchestrator.js +10 -1
  26. package/src/utils/cache-directory.d.ts +1 -0
  27. package/src/utils/cache-directory.js +7 -3
  28. package/src/utils/db-connection.d.ts +2 -0
  29. package/src/utils/db-connection.js +11 -0
  30. package/src/utils/legacy-task-history.d.ts +8 -0
  31. package/src/utils/legacy-task-history.js +87 -0
  32. package/src/utils/task-history.d.ts +6 -8
  33. package/src/utils/task-history.js +16 -88
  34. package/src/utils/workspace-context.js +1 -1
  35. package/src/daemon/server/handle-get-task-history.d.ts +0 -4
  36. package/src/daemon/server/handle-get-task-history.js +0 -11
  37. package/src/daemon/server/handle-write-task-runs-to-history.d.ts +0 -5
  38. package/src/daemon/server/handle-write-task-runs-to-history.js +0 -11
@@ -1,97 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.taskHistoryFile = void 0;
4
- exports.getHistoryForHashes = getHistoryForHashes;
5
- exports.writeTaskRunsToHistory = writeTaskRunsToHistory;
6
- const fs_1 = require("fs");
7
- const path_1 = require("path");
3
+ exports.TaskHistory = void 0;
8
4
  const client_1 = require("../daemon/client/client");
9
5
  const is_on_daemon_1 = require("../daemon/is-on-daemon");
10
- const cache_directory_1 = require("./cache-directory");
11
- const taskRunKeys = [
12
- 'project',
13
- 'target',
14
- 'configuration',
15
- 'hash',
16
- 'code',
17
- 'status',
18
- 'start',
19
- 'end',
20
- ];
21
- let taskHistory = undefined;
22
- let taskHashToIndicesMap = new Map();
23
- async function getHistoryForHashes(hashes) {
24
- if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
25
- if (taskHistory === undefined) {
26
- loadTaskHistoryFromDisk();
6
+ const native_1 = require("../native");
7
+ const db_connection_1 = require("./db-connection");
8
+ class TaskHistory {
9
+ constructor() {
10
+ this.taskHistory = new native_1.NxTaskHistory((0, db_connection_1.getDbConnection)());
11
+ }
12
+ async getFlakyTasks(hashes) {
13
+ if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
14
+ return this.taskHistory.getFlakyTasks(hashes);
27
15
  }
28
- const result = {};
29
- for (let hash of hashes) {
30
- const indices = taskHashToIndicesMap.get(hash);
31
- if (!indices) {
32
- result[hash] = [];
33
- }
34
- else {
35
- result[hash] = indices.map((index) => taskHistory[index]);
36
- }
37
- }
38
- return result;
16
+ return await client_1.daemonClient.getFlakyTasks(hashes);
39
17
  }
40
- return await client_1.daemonClient.getTaskHistoryForHashes(hashes);
41
- }
42
- async function writeTaskRunsToHistory(taskRuns) {
43
- if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
44
- if (taskHistory === undefined) {
45
- loadTaskHistoryFromDisk();
46
- }
47
- const serializedLines = [];
48
- for (let taskRun of taskRuns) {
49
- const serializedLine = taskRunKeys.map((key) => taskRun[key]).join(',');
50
- serializedLines.push(serializedLine);
51
- recordTaskRunInMemory(taskRun);
52
- }
53
- if (!(0, fs_1.existsSync)(exports.taskHistoryFile)) {
54
- (0, fs_1.writeFileSync)(exports.taskHistoryFile, `${taskRunKeys.join(',')}\n`);
18
+ async recordTaskRuns(taskRuns) {
19
+ if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
20
+ return this.taskHistory.recordTaskRuns(taskRuns);
55
21
  }
56
- (0, fs_1.appendFileSync)(exports.taskHistoryFile, serializedLines.join('\n') + '\n');
57
- }
58
- else {
59
- await client_1.daemonClient.writeTaskRunsToHistory(taskRuns);
60
- }
61
- }
62
- exports.taskHistoryFile = (0, path_1.join)(cache_directory_1.workspaceDataDirectory, 'task-history.csv');
63
- function loadTaskHistoryFromDisk() {
64
- taskHashToIndicesMap.clear();
65
- taskHistory = [];
66
- if (!(0, fs_1.existsSync)(exports.taskHistoryFile)) {
67
- return;
68
- }
69
- const fileContent = (0, fs_1.readFileSync)(exports.taskHistoryFile, 'utf8');
70
- if (!fileContent) {
71
- return;
72
- }
73
- const lines = fileContent.split('\n');
74
- // if there are no lines or just the header, return
75
- if (lines.length <= 1) {
76
- return;
77
- }
78
- const contentLines = lines.slice(1).filter((l) => l.trim() !== '');
79
- // read the values from csv format where each header is a key and the value is the value
80
- for (let line of contentLines) {
81
- const values = line.trim().split(',');
82
- const run = {};
83
- taskRunKeys.forEach((header, index) => {
84
- run[header] = values[index];
85
- });
86
- recordTaskRunInMemory(run);
87
- }
88
- }
89
- function recordTaskRunInMemory(taskRun) {
90
- const index = taskHistory.push(taskRun) - 1;
91
- if (taskHashToIndicesMap.has(taskRun.hash)) {
92
- taskHashToIndicesMap.get(taskRun.hash).push(index);
93
- }
94
- else {
95
- taskHashToIndicesMap.set(taskRun.hash, [index]);
22
+ return client_1.daemonClient.recordTaskRuns(taskRuns);
96
23
  }
97
24
  }
25
+ exports.TaskHistory = TaskHistory;
@@ -19,7 +19,7 @@ let workspaceContext;
19
19
  function setupWorkspaceContext(workspaceRoot) {
20
20
  const { WorkspaceContext } = require('../native');
21
21
  perf_hooks_1.performance.mark('workspace-context');
22
- workspaceContext = new WorkspaceContext(workspaceRoot, (0, cache_directory_1.cacheDirectoryForWorkspace)(workspaceRoot));
22
+ workspaceContext = new WorkspaceContext(workspaceRoot, (0, cache_directory_1.workspaceDataDirectoryForWorkspace)(workspaceRoot));
23
23
  perf_hooks_1.performance.mark('workspace-context:end');
24
24
  perf_hooks_1.performance.measure('workspace context init', 'workspace-context', 'workspace-context:end');
25
25
  }
@@ -1,4 +0,0 @@
1
- export declare function handleGetTaskHistoryForHashes(hashes: string[]): Promise<{
2
- response: string;
3
- description: string;
4
- }>;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleGetTaskHistoryForHashes = handleGetTaskHistoryForHashes;
4
- const task_history_1 = require("../../utils/task-history");
5
- async function handleGetTaskHistoryForHashes(hashes) {
6
- const history = await (0, task_history_1.getHistoryForHashes)(hashes);
7
- return {
8
- response: JSON.stringify(history),
9
- description: 'handleGetTaskHistoryForHashes',
10
- };
11
- }
@@ -1,5 +0,0 @@
1
- import { TaskRun } from '../../utils/task-history';
2
- export declare function handleWriteTaskRunsToHistory(taskRuns: TaskRun[]): Promise<{
3
- response: string;
4
- description: string;
5
- }>;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.handleWriteTaskRunsToHistory = handleWriteTaskRunsToHistory;
4
- const task_history_1 = require("../../utils/task-history");
5
- async function handleWriteTaskRunsToHistory(taskRuns) {
6
- await (0, task_history_1.writeTaskRunsToHistory)(taskRuns);
7
- return {
8
- response: 'true',
9
- description: 'handleWriteTaskRunsToHistory',
10
- };
11
- }