nx 19.6.1 → 19.7.0-beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. package/README.md +1 -1
  2. package/package.json +12 -12
  3. package/src/command-line/add/add.js +1 -5
  4. package/src/command-line/add/command-object.js +1 -5
  5. package/src/command-line/affected/affected.js +0 -3
  6. package/src/command-line/exec/exec.js +0 -3
  7. package/src/command-line/generate/command-object.js +2 -5
  8. package/src/command-line/generate/generate.js +4 -8
  9. package/src/command-line/import/command-object.js +1 -1
  10. package/src/command-line/import/utils/prepare-source-repo.js +2 -2
  11. package/src/command-line/migrate/command-object.js +3 -2
  12. package/src/command-line/migrate/migrate.js +0 -3
  13. package/src/command-line/release/changelog.js +0 -3
  14. package/src/command-line/release/command-object.js +1 -5
  15. package/src/command-line/release/plan-check.js +0 -3
  16. package/src/command-line/release/plan.js +0 -3
  17. package/src/command-line/release/publish.js +0 -6
  18. package/src/command-line/release/release.js +0 -3
  19. package/src/command-line/release/version.js +0 -3
  20. package/src/command-line/repair/command-object.js +2 -4
  21. package/src/command-line/repair/repair.js +2 -6
  22. package/src/command-line/run/run-one.js +0 -3
  23. package/src/command-line/show/command-object.js +2 -2
  24. package/src/command-line/sync/command-object.js +3 -8
  25. package/src/command-line/sync/sync.js +1 -5
  26. package/src/command-line/watch/command-object.js +1 -1
  27. package/src/command-line/watch/watch.js +0 -3
  28. package/src/command-line/yargs-utils/shared-options.js +3 -3
  29. package/src/core/graph/main.js +1 -1
  30. package/src/daemon/client/client.d.ts +3 -6
  31. package/src/daemon/client/client.js +5 -4
  32. package/src/daemon/message-types/task-history.d.ts +9 -9
  33. package/src/daemon/message-types/task-history.js +7 -7
  34. package/src/daemon/server/handle-task-history.d.ts +9 -0
  35. package/src/daemon/server/handle-task-history.js +28 -0
  36. package/src/daemon/server/server.js +4 -5
  37. package/src/hasher/hash-task.js +36 -1
  38. package/src/native/assert-supported-platform.js +1 -1
  39. package/src/native/index.d.ts +45 -4
  40. package/src/native/native-bindings.js +4 -0
  41. package/src/native/nx.wasi-browser.js +50 -36
  42. package/src/native/nx.wasi.cjs +48 -36
  43. package/src/native/nx.wasm32-wasi.wasm +0 -0
  44. package/src/nx-cloud/update-manager.d.ts +2 -0
  45. package/src/nx-cloud/utilities/url-shorten.js +1 -1
  46. package/src/plugins/js/package-json/create-package-json.d.ts +1 -0
  47. package/src/plugins/js/package-json/create-package-json.js +1 -1
  48. package/src/tasks-runner/cache.d.ts +21 -2
  49. package/src/tasks-runner/cache.js +118 -26
  50. package/src/tasks-runner/default-tasks-runner.d.ts +6 -0
  51. package/src/tasks-runner/default-tasks-runner.js +31 -1
  52. package/src/tasks-runner/life-cycles/task-history-life-cycle-old.d.ts +9 -0
  53. package/src/tasks-runner/life-cycles/task-history-life-cycle-old.js +54 -0
  54. package/src/tasks-runner/life-cycles/task-history-life-cycle.d.ts +1 -0
  55. package/src/tasks-runner/life-cycles/task-history-life-cycle.js +19 -21
  56. package/src/tasks-runner/run-command.js +3 -1
  57. package/src/tasks-runner/task-orchestrator.js +10 -1
  58. package/src/utils/cache-directory.d.ts +1 -0
  59. package/src/utils/cache-directory.js +7 -3
  60. package/src/utils/db-connection.d.ts +2 -0
  61. package/src/utils/db-connection.js +11 -0
  62. package/src/utils/git-utils.js +1 -1
  63. package/src/utils/legacy-task-history.d.ts +8 -0
  64. package/src/utils/legacy-task-history.js +87 -0
  65. package/src/utils/logger.js +1 -1
  66. package/src/utils/task-history.d.ts +6 -8
  67. package/src/utils/task-history.js +16 -88
  68. package/src/utils/workspace-context.js +1 -1
  69. package/src/daemon/server/handle-get-task-history.d.ts +0 -4
  70. package/src/daemon/server/handle-get-task-history.js +0 -11
  71. package/src/daemon/server/handle-write-task-runs-to-history.d.ts +0 -5
  72. 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
- }