nx 19.8.0-canary.20240912-b6140d4 → 19.8.0-canary.20240914-dc821ab
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +12 -12
- package/src/command-line/add/add.js +2 -2
- package/src/command-line/affected/command-object.js +6 -6
- package/src/command-line/deprecated/command-objects.js +3 -3
- package/src/command-line/generate/generate.js +2 -1
- package/src/command-line/generate/generator-utils.d.ts +2 -1
- package/src/command-line/import/command-object.js +3 -3
- package/src/command-line/init/init-v2.js +5 -1
- package/src/command-line/login/login.js +2 -2
- package/src/command-line/logout/logout.js +2 -2
- package/src/command-line/migrate/migrate.js +2 -2
- package/src/command-line/new/new.js +2 -1
- package/src/command-line/release/changelog.js +2 -2
- package/src/command-line/release/plan-check.js +2 -2
- package/src/command-line/release/plan.js +2 -2
- package/src/command-line/release/publish.js +2 -2
- package/src/command-line/release/release.js +2 -2
- package/src/command-line/release/version.js +2 -1
- package/src/command-line/repair/repair.js +2 -2
- package/src/command-line/run/command-object.js +3 -3
- package/src/command-line/run/run.js +3 -2
- package/src/command-line/run-many/command-object.js +2 -2
- package/src/command-line/show/command-object.js +3 -3
- package/src/command-line/sync/command-object.js +2 -2
- package/src/command-line/sync/sync.js +2 -2
- package/src/core/graph/main.js +1 -1
- package/src/core/graph/styles.css +1 -1
- package/src/daemon/client/client.d.ts +2 -1
- package/src/daemon/client/client.js +7 -0
- package/src/daemon/message-types/task-history.d.ts +9 -3
- package/src/daemon/message-types/task-history.js +10 -2
- package/src/daemon/server/handle-task-history.d.ts +5 -1
- package/src/daemon/server/handle-task-history.js +11 -9
- package/src/daemon/server/server.js +5 -2
- package/src/native/index.d.ts +1 -0
- package/src/native/nx.wasi.cjs +20 -20
- package/src/native/nx.wasm32-wasi.wasm +0 -0
- package/src/nx-cloud/generators/connect-to-nx-cloud/connect-to-nx-cloud.js +0 -1
- package/src/nx-cloud/utilities/get-cloud-options.d.ts +1 -0
- package/src/nx-cloud/utilities/get-cloud-options.js +4 -0
- package/src/nx-cloud/utilities/is-workspace-claimed.d.ts +1 -1
- package/src/nx-cloud/utilities/is-workspace-claimed.js +6 -5
- package/src/nx-cloud/utilities/onboarding.js +2 -2
- package/src/plugins/js/utils/register.js +7 -0
- package/src/project-graph/error-types.d.ts +1 -1
- package/src/project-graph/error-types.js +19 -5
- package/src/tasks-runner/life-cycles/task-history-life-cycle.js +1 -1
- package/src/tasks-runner/run-command.js +2 -2
- package/src/tasks-runner/task-orchestrator.js +4 -1
- package/src/tasks-runner/tasks-schedule.d.ts +3 -0
- package/src/tasks-runner/tasks-schedule.js +22 -4
- package/src/utils/handle-errors.d.ts +1 -0
- package/src/utils/handle-errors.js +71 -0
- package/src/utils/nx-cloud-utils.d.ts +0 -1
- package/src/utils/nx-cloud-utils.js +0 -10
- package/src/utils/params.d.ts +0 -1
- package/src/utils/params.js +0 -50
- package/src/utils/plugins/plugin-capabilities.js +4 -1
- package/src/utils/task-history.d.ts +12 -1
- package/src/utils/task-history.js +23 -0
@@ -4,6 +4,7 @@ exports.TasksSchedule = void 0;
|
|
4
4
|
const utils_1 = require("./utils");
|
5
5
|
const project_graph_utils_1 = require("../utils/project-graph-utils");
|
6
6
|
const operators_1 = require("../project-graph/operators");
|
7
|
+
const task_history_1 = require("../utils/task-history");
|
7
8
|
class TasksSchedule {
|
8
9
|
constructor(projectGraph, taskGraph, options) {
|
9
10
|
this.projectGraph = projectGraph;
|
@@ -12,12 +13,16 @@ class TasksSchedule {
|
|
12
13
|
this.notScheduledTaskGraph = this.taskGraph;
|
13
14
|
this.reverseTaskDeps = (0, utils_1.calculateReverseDeps)(this.taskGraph);
|
14
15
|
this.reverseProjectGraph = (0, operators_1.reverse)(this.projectGraph);
|
16
|
+
this.taskHistory = (0, task_history_1.getTaskHistory)();
|
15
17
|
this.scheduledBatches = [];
|
16
18
|
this.scheduledTasks = [];
|
17
19
|
this.runningTasks = new Set();
|
18
20
|
this.completedTasks = new Set();
|
19
21
|
this.scheduleRequestsExecutionChain = Promise.resolve();
|
20
22
|
}
|
23
|
+
async init() {
|
24
|
+
this.estimatedTaskTimings = await this.taskHistory.getEstimatedTaskTimings(Object.values(this.taskGraph.tasks).map((t) => t.target));
|
25
|
+
}
|
21
26
|
async scheduleNextTasks() {
|
22
27
|
this.scheduleRequestsExecutionChain =
|
23
28
|
this.scheduleRequestsExecutionChain.then(() => this.scheduleTasks());
|
@@ -81,10 +86,23 @@ class TasksSchedule {
|
|
81
86
|
// Most likely tasks with no dependencies such as test
|
82
87
|
const project1 = this.taskGraph.tasks[taskId1].target.project;
|
83
88
|
const project2 = this.taskGraph.tasks[taskId2].target.project;
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
89
|
+
const project1NodeDependencies = (0, project_graph_utils_1.findAllProjectNodeDependencies)(project1, this.reverseProjectGraph).length;
|
90
|
+
const project2NodeDependencies = (0, project_graph_utils_1.findAllProjectNodeDependencies)(project2, this.reverseProjectGraph).length;
|
91
|
+
const dependenciesDiff = project2NodeDependencies - project1NodeDependencies;
|
92
|
+
if (dependenciesDiff !== 0) {
|
93
|
+
return dependenciesDiff;
|
94
|
+
}
|
95
|
+
const task1Timing = this.estimatedTaskTimings[taskId1];
|
96
|
+
if (!task1Timing) {
|
97
|
+
// if no timing or 0, put task1 at beginning
|
98
|
+
return -1;
|
99
|
+
}
|
100
|
+
const task2Timing = this.estimatedTaskTimings[taskId2];
|
101
|
+
if (!task2Timing) {
|
102
|
+
// if no timing or 0, put task2 at beginning
|
103
|
+
return 1;
|
104
|
+
}
|
105
|
+
return task2Timing - task1Timing;
|
88
106
|
});
|
89
107
|
this.runningTasks.add(taskId);
|
90
108
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function handleErrors(isVerbose: boolean, fn: Function): Promise<number>;
|
@@ -0,0 +1,71 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.handleErrors = handleErrors;
|
4
|
+
const client_1 = require("../daemon/client/client");
|
5
|
+
const logger_1 = require("./logger");
|
6
|
+
const output_1 = require("./output");
|
7
|
+
async function handleErrors(isVerbose, fn) {
|
8
|
+
try {
|
9
|
+
const result = await fn();
|
10
|
+
if (typeof result === 'number') {
|
11
|
+
return result;
|
12
|
+
}
|
13
|
+
return 0;
|
14
|
+
}
|
15
|
+
catch (err) {
|
16
|
+
err ||= new Error('Unknown error caught');
|
17
|
+
if (err.constructor.name === 'UnsuccessfulWorkflowExecution') {
|
18
|
+
logger_1.logger.error('The generator workflow failed. See above.');
|
19
|
+
}
|
20
|
+
else if (err.name === 'ProjectGraphError') {
|
21
|
+
const projectGraphError = err;
|
22
|
+
let title = projectGraphError.message;
|
23
|
+
if (projectGraphError.cause &&
|
24
|
+
typeof projectGraphError.cause === 'object' &&
|
25
|
+
'message' in projectGraphError.cause) {
|
26
|
+
title += ' ' + projectGraphError.cause.message + '.';
|
27
|
+
}
|
28
|
+
if (isVerbose) {
|
29
|
+
title += ' See errors below.';
|
30
|
+
}
|
31
|
+
const bodyLines = isVerbose
|
32
|
+
? formatErrorStackAndCause(projectGraphError)
|
33
|
+
: ['Pass --verbose to see the stacktraces.'];
|
34
|
+
output_1.output.error({
|
35
|
+
title,
|
36
|
+
bodyLines: bodyLines,
|
37
|
+
});
|
38
|
+
}
|
39
|
+
else {
|
40
|
+
const lines = (err.message ? err.message : err.toString()).split('\n');
|
41
|
+
const bodyLines = lines.slice(1);
|
42
|
+
if (isVerbose) {
|
43
|
+
bodyLines.push(...formatErrorStackAndCause(err));
|
44
|
+
}
|
45
|
+
else if (err.stack) {
|
46
|
+
bodyLines.push('Pass --verbose to see the stacktrace.');
|
47
|
+
}
|
48
|
+
output_1.output.error({
|
49
|
+
title: lines[0],
|
50
|
+
bodyLines,
|
51
|
+
});
|
52
|
+
}
|
53
|
+
if (client_1.daemonClient.enabled()) {
|
54
|
+
client_1.daemonClient.reset();
|
55
|
+
}
|
56
|
+
return 1;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
function formatErrorStackAndCause(error) {
|
60
|
+
return [
|
61
|
+
error.stack || error.message,
|
62
|
+
...(error.cause && typeof error.cause === 'object'
|
63
|
+
? [
|
64
|
+
'Caused by:',
|
65
|
+
'stack' in error.cause
|
66
|
+
? error.cause.stack.toString()
|
67
|
+
: error.cause.toString(),
|
68
|
+
]
|
69
|
+
: []),
|
70
|
+
];
|
71
|
+
}
|
@@ -1,4 +1,3 @@
|
|
1
1
|
import { NxJsonConfiguration } from '../config/nx-json';
|
2
2
|
export declare function isNxCloudUsed(nxJson: NxJsonConfiguration): boolean;
|
3
3
|
export declare function getNxCloudUrl(nxJson: NxJsonConfiguration): string;
|
4
|
-
export declare function getNxCloudToken(nxJson: NxJsonConfiguration): string;
|
@@ -2,7 +2,6 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.isNxCloudUsed = isNxCloudUsed;
|
4
4
|
exports.getNxCloudUrl = getNxCloudUrl;
|
5
|
-
exports.getNxCloudToken = getNxCloudToken;
|
6
5
|
function isNxCloudUsed(nxJson) {
|
7
6
|
return (!!process.env.NX_CLOUD_ACCESS_TOKEN ||
|
8
7
|
!!nxJson.nxCloudAccessToken ||
|
@@ -17,12 +16,3 @@ function getNxCloudUrl(nxJson) {
|
|
17
16
|
throw new Error('nx-cloud runner not found in nx.json');
|
18
17
|
return cloudRunner?.options?.url ?? nxJson.nxCloudUrl ?? 'https://nx.app';
|
19
18
|
}
|
20
|
-
function getNxCloudToken(nxJson) {
|
21
|
-
const cloudRunner = Object.values(nxJson.tasksRunnerOptions ?? {}).find((r) => r.runner == '@nrwl/nx-cloud' || r.runner == 'nx-cloud');
|
22
|
-
if (!cloudRunner &&
|
23
|
-
!(nxJson.nxCloudAccessToken || process.env.NX_CLOUD_ACCESS_TOKEN))
|
24
|
-
throw new Error('nx-cloud runner not found in nx.json');
|
25
|
-
return (process.env.NX_CLOUD_ACCESS_TOKEN ??
|
26
|
-
cloudRunner?.options.accessToken ??
|
27
|
-
nxJson.nxCloudAccessToken);
|
28
|
-
}
|
package/src/utils/params.d.ts
CHANGED
@@ -79,7 +79,6 @@ export type Options = {
|
|
79
79
|
'--'?: Unmatched[];
|
80
80
|
[k: string]: string | number | boolean | string[] | Unmatched[] | undefined;
|
81
81
|
};
|
82
|
-
export declare function handleErrors(isVerbose: boolean, fn: Function): Promise<number>;
|
83
82
|
export declare function convertToCamelCase(parsed: {
|
84
83
|
[k: string]: any;
|
85
84
|
}, schema: Schema): Options;
|
package/src/utils/params.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.SchemaError = void 0;
|
4
|
-
exports.handleErrors = handleErrors;
|
5
4
|
exports.convertToCamelCase = convertToCamelCase;
|
6
5
|
exports.coerceTypesInOptions = coerceTypesInOptions;
|
7
6
|
exports.convertAliases = convertAliases;
|
@@ -15,55 +14,6 @@ exports.warnDeprecations = warnDeprecations;
|
|
15
14
|
exports.convertSmartDefaultsIntoNamedParams = convertSmartDefaultsIntoNamedParams;
|
16
15
|
exports.getPromptsForSchema = getPromptsForSchema;
|
17
16
|
const logger_1 = require("./logger");
|
18
|
-
const output_1 = require("./output");
|
19
|
-
const client_1 = require("../daemon/client/client");
|
20
|
-
async function handleErrors(isVerbose, fn) {
|
21
|
-
try {
|
22
|
-
const result = await fn();
|
23
|
-
if (typeof result === 'number') {
|
24
|
-
return result;
|
25
|
-
}
|
26
|
-
return 0;
|
27
|
-
}
|
28
|
-
catch (err) {
|
29
|
-
err ||= new Error('Unknown error caught');
|
30
|
-
if (err.constructor.name === 'UnsuccessfulWorkflowExecution') {
|
31
|
-
logger_1.logger.error('The generator workflow failed. See above.');
|
32
|
-
}
|
33
|
-
else if (err.name === 'ProjectGraphError') {
|
34
|
-
const projectGraphError = err;
|
35
|
-
let title = projectGraphError.message;
|
36
|
-
if (isVerbose) {
|
37
|
-
title += ' See errors below.';
|
38
|
-
}
|
39
|
-
const bodyLines = isVerbose
|
40
|
-
? [projectGraphError.stack]
|
41
|
-
: ['Pass --verbose to see the stacktraces.'];
|
42
|
-
output_1.output.error({
|
43
|
-
title,
|
44
|
-
bodyLines: bodyLines,
|
45
|
-
});
|
46
|
-
}
|
47
|
-
else {
|
48
|
-
const lines = (err.message ? err.message : err.toString()).split('\n');
|
49
|
-
const bodyLines = lines.slice(1);
|
50
|
-
if (err.stack && !isVerbose) {
|
51
|
-
bodyLines.push('Pass --verbose to see the stacktrace.');
|
52
|
-
}
|
53
|
-
output_1.output.error({
|
54
|
-
title: lines[0],
|
55
|
-
bodyLines,
|
56
|
-
});
|
57
|
-
if (err.stack && isVerbose) {
|
58
|
-
logger_1.logger.info(err.stack);
|
59
|
-
}
|
60
|
-
}
|
61
|
-
if (client_1.daemonClient.enabled()) {
|
62
|
-
client_1.daemonClient.reset();
|
63
|
-
}
|
64
|
-
return 1;
|
65
|
-
}
|
66
|
-
}
|
67
17
|
function camelCase(input) {
|
68
18
|
if (input.indexOf('-') > 1) {
|
69
19
|
return input
|
@@ -41,10 +41,13 @@ async function getPluginCapabilities(workspaceRoot, pluginName, projects, includ
|
|
41
41
|
projectGraphExtension: pluginModule &&
|
42
42
|
('processProjectGraph' in pluginModule ||
|
43
43
|
'createNodes' in pluginModule ||
|
44
|
+
'createNodesV2' in pluginModule ||
|
45
|
+
'createMetadata' in pluginModule ||
|
44
46
|
'createDependencies' in pluginModule),
|
45
47
|
projectInference: pluginModule &&
|
46
48
|
('projectFilePatterns' in pluginModule ||
|
47
|
-
'createNodes' in pluginModule
|
49
|
+
'createNodes' in pluginModule ||
|
50
|
+
'createNodesV2' in pluginModule),
|
48
51
|
};
|
49
52
|
}
|
50
53
|
catch {
|
@@ -1,6 +1,17 @@
|
|
1
|
-
import { NxTaskHistory, TaskRun } from '../native';
|
1
|
+
import { NxTaskHistory, TaskRun, TaskTarget } from '../native';
|
2
2
|
export declare class TaskHistory {
|
3
3
|
taskHistory: NxTaskHistory;
|
4
|
+
/**
|
5
|
+
* This function returns estimated timings per task
|
6
|
+
* @param targets
|
7
|
+
* @returns a map where key is task id (project:target:configuration), value is average time of historical runs
|
8
|
+
*/
|
9
|
+
getEstimatedTaskTimings(targets: TaskTarget[]): Promise<Record<string, number>>;
|
4
10
|
getFlakyTasks(hashes: string[]): Promise<string[]>;
|
5
11
|
recordTaskRuns(taskRuns: TaskRun[]): Promise<void>;
|
6
12
|
}
|
13
|
+
/**
|
14
|
+
* This function returns the singleton instance of TaskHistory
|
15
|
+
* @returns singleton instance of TaskHistory
|
16
|
+
*/
|
17
|
+
export declare function getTaskHistory(): TaskHistory;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.TaskHistory = void 0;
|
4
|
+
exports.getTaskHistory = getTaskHistory;
|
4
5
|
const client_1 = require("../daemon/client/client");
|
5
6
|
const is_on_daemon_1 = require("../daemon/is-on-daemon");
|
6
7
|
const native_1 = require("../native");
|
@@ -9,6 +10,17 @@ class TaskHistory {
|
|
9
10
|
constructor() {
|
10
11
|
this.taskHistory = new native_1.NxTaskHistory((0, db_connection_1.getDbConnection)());
|
11
12
|
}
|
13
|
+
/**
|
14
|
+
* This function returns estimated timings per task
|
15
|
+
* @param targets
|
16
|
+
* @returns a map where key is task id (project:target:configuration), value is average time of historical runs
|
17
|
+
*/
|
18
|
+
async getEstimatedTaskTimings(targets) {
|
19
|
+
if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
|
20
|
+
return this.taskHistory.getEstimatedTaskTimings(targets);
|
21
|
+
}
|
22
|
+
return await client_1.daemonClient.getEstimatedTaskTimings(targets);
|
23
|
+
}
|
12
24
|
async getFlakyTasks(hashes) {
|
13
25
|
if ((0, is_on_daemon_1.isOnDaemon)() || !client_1.daemonClient.enabled()) {
|
14
26
|
return this.taskHistory.getFlakyTasks(hashes);
|
@@ -23,3 +35,14 @@ class TaskHistory {
|
|
23
35
|
}
|
24
36
|
}
|
25
37
|
exports.TaskHistory = TaskHistory;
|
38
|
+
let taskHistory;
|
39
|
+
/**
|
40
|
+
* This function returns the singleton instance of TaskHistory
|
41
|
+
* @returns singleton instance of TaskHistory
|
42
|
+
*/
|
43
|
+
function getTaskHistory() {
|
44
|
+
if (!taskHistory) {
|
45
|
+
taskHistory = new TaskHistory();
|
46
|
+
}
|
47
|
+
return taskHistory;
|
48
|
+
}
|