nx 19.7.4 → 19.8.0-beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. package/bin/nx-cloud.js +0 -0
  2. package/package.json +17 -17
  3. package/src/command-line/activate-powerpack/activate-powerpack.d.ts +2 -0
  4. package/src/command-line/activate-powerpack/activate-powerpack.js +32 -0
  5. package/src/command-line/activate-powerpack/command-object.d.ts +6 -0
  6. package/src/command-line/activate-powerpack/command-object.js +25 -0
  7. package/src/command-line/add/command-object.d.ts +1 -1
  8. package/src/command-line/format/format.js +24 -7
  9. package/src/command-line/generate/generator-utils.d.ts +2 -1
  10. package/src/command-line/import/command-object.js +1 -1
  11. package/src/command-line/import/import.js +6 -2
  12. package/src/command-line/init/init-v2.d.ts +1 -1
  13. package/src/command-line/init/init-v2.js +8 -2
  14. package/src/command-line/list/list.js +2 -0
  15. package/src/command-line/nx-commands.d.ts +1 -1
  16. package/src/command-line/nx-commands.js +77 -57
  17. package/src/command-line/report/report.d.ts +3 -0
  18. package/src/command-line/report/report.js +27 -1
  19. package/src/command-line/sync/command-object.js +2 -2
  20. package/src/core/graph/main.js +1 -1
  21. package/src/core/graph/styles.css +1 -1
  22. package/src/daemon/client/client.d.ts +2 -1
  23. package/src/daemon/client/client.js +7 -0
  24. package/src/daemon/message-types/task-history.d.ts +9 -3
  25. package/src/daemon/message-types/task-history.js +10 -2
  26. package/src/daemon/server/handle-task-history.d.ts +5 -1
  27. package/src/daemon/server/handle-task-history.js +11 -9
  28. package/src/daemon/server/server.js +5 -2
  29. package/src/native/index.d.ts +3 -1
  30. package/src/native/nx.wasm32-wasi.wasm +0 -0
  31. package/src/tasks-runner/cache.d.ts +5 -1
  32. package/src/tasks-runner/cache.js +51 -5
  33. package/src/tasks-runner/init-tasks-runner.d.ts +1 -1
  34. package/src/tasks-runner/init-tasks-runner.js +5 -3
  35. package/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.d.ts +0 -2
  36. package/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.js +0 -5
  37. package/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.d.ts +2 -6
  38. package/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.d.ts +2 -6
  39. package/src/tasks-runner/life-cycles/store-run-information-life-cycle.d.ts +2 -7
  40. package/src/tasks-runner/life-cycles/task-history-life-cycle.js +1 -1
  41. package/src/tasks-runner/life-cycles/task-profiling-life-cycle.d.ts +2 -7
  42. package/src/tasks-runner/life-cycles/task-results-life-cycle.d.ts +6 -0
  43. package/src/tasks-runner/life-cycles/task-results-life-cycle.js +17 -0
  44. package/src/tasks-runner/life-cycles/task-timings-life-cycle.d.ts +2 -7
  45. package/src/tasks-runner/run-command.d.ts +12 -2
  46. package/src/tasks-runner/run-command.js +52 -59
  47. package/src/tasks-runner/task-orchestrator.js +4 -1
  48. package/src/tasks-runner/tasks-schedule.d.ts +3 -0
  49. package/src/tasks-runner/tasks-schedule.js +26 -4
  50. package/src/utils/db-connection.d.ts +4 -1
  51. package/src/utils/db-connection.js +15 -4
  52. package/src/utils/git-utils.d.ts +1 -0
  53. package/src/utils/git-utils.js +4 -0
  54. package/src/utils/plugins/output.d.ts +1 -0
  55. package/src/utils/plugins/output.js +7 -0
  56. package/src/utils/powerpack.d.ts +5 -0
  57. package/src/utils/powerpack.js +38 -0
  58. package/src/utils/task-history.d.ts +12 -1
  59. package/src/utils/task-history.js +23 -0
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TaskResultsLifeCycle = void 0;
4
+ class TaskResultsLifeCycle {
5
+ constructor() {
6
+ this.taskResults = {};
7
+ }
8
+ endTasks(taskResults) {
9
+ for (let t of taskResults) {
10
+ this.taskResults[t.task.id] = t;
11
+ }
12
+ }
13
+ getTaskResults() {
14
+ return this.taskResults;
15
+ }
16
+ }
17
+ exports.TaskResultsLifeCycle = TaskResultsLifeCycle;
@@ -1,13 +1,8 @@
1
1
  import { Task } from '../../config/task-graph';
2
- import { LifeCycle } from '../life-cycle';
3
- import { TaskStatus } from '../tasks-runner';
2
+ import { LifeCycle, TaskResult } from '../life-cycle';
4
3
  export declare class TaskTimingsLifeCycle implements LifeCycle {
5
4
  private timings;
6
5
  startTasks(tasks: Task[]): void;
7
- endTasks(taskResults: Array<{
8
- task: Task;
9
- status: TaskStatus;
10
- code: number;
11
- }>): void;
6
+ endTasks(taskResults: TaskResult[]): void;
12
7
  endCommand(): void;
13
8
  }
@@ -3,7 +3,7 @@ import { ProjectGraph, ProjectGraphProjectNode } from '../config/project-graph';
3
3
  import { Task, TaskGraph } from '../config/task-graph';
4
4
  import { TargetDependencyConfig } from '../config/workspace-json-project-json';
5
5
  import { NxArgs } from '../utils/command-line-utils';
6
- import { LifeCycle } from './life-cycle';
6
+ import { LifeCycle, TaskResult } from './life-cycle';
7
7
  import { TasksRunner } from './tasks-runner';
8
8
  export declare function runCommand(projectsToRun: ProjectGraphProjectNode[], currentProjectGraph: ProjectGraph, { nxJson }: {
9
9
  nxJson: NxJsonConfiguration;
@@ -11,6 +11,14 @@ export declare function runCommand(projectsToRun: ProjectGraphProjectNode[], cur
11
11
  excludeTaskDependencies: boolean;
12
12
  loadDotEnvFiles: boolean;
13
13
  }): Promise<NodeJS.Process['exitCode']>;
14
+ export declare function runCommandForTasks(projectsToRun: ProjectGraphProjectNode[], currentProjectGraph: ProjectGraph, { nxJson }: {
15
+ nxJson: NxJsonConfiguration;
16
+ }, nxArgs: NxArgs, overrides: any, initiatingProject: string | null, extraTargetDependencies: Record<string, (TargetDependencyConfig | string)[]>, extraOptions: {
17
+ excludeTaskDependencies: boolean;
18
+ loadDotEnvFiles: boolean;
19
+ }): Promise<{
20
+ [id: string]: TaskResult;
21
+ }>;
14
22
  export declare function invokeTasksRunner({ tasks, projectGraph, taskGraph, lifeCycle, nxJson, nxArgs, loadDotEnvFiles, initiatingProject, }: {
15
23
  tasks: Task[];
16
24
  projectGraph: ProjectGraph;
@@ -20,7 +28,9 @@ export declare function invokeTasksRunner({ tasks, projectGraph, taskGraph, life
20
28
  nxArgs: NxArgs;
21
29
  loadDotEnvFiles: boolean;
22
30
  initiatingProject: string | null;
23
- }): Promise<1 | 0>;
31
+ }): Promise<{
32
+ [id: string]: TaskResult;
33
+ }>;
24
34
  export declare function getRunner(nxArgs: NxArgs, nxJson: NxJsonConfiguration): {
25
35
  tasksRunner: TasksRunner;
26
36
  runnerOptions: any;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.runCommand = runCommand;
4
+ exports.runCommandForTasks = runCommandForTasks;
4
5
  exports.invokeTasksRunner = invokeTasksRunner;
5
6
  exports.getRunner = getRunner;
6
7
  exports.getRunnerOptions = getRunnerOptions;
@@ -31,9 +32,11 @@ const task_history_life_cycle_1 = require("./life-cycles/task-history-life-cycle
31
32
  const task_history_life_cycle_old_1 = require("./life-cycles/task-history-life-cycle-old");
32
33
  const task_profiling_life_cycle_1 = require("./life-cycles/task-profiling-life-cycle");
33
34
  const task_timings_life_cycle_1 = require("./life-cycles/task-timings-life-cycle");
35
+ const task_results_life_cycle_1 = require("./life-cycles/task-results-life-cycle");
34
36
  const task_graph_utils_1 = require("./task-graph-utils");
35
37
  const utils_1 = require("./utils");
36
38
  const chalk = require("chalk");
39
+ const powerpack_1 = require("../utils/powerpack");
37
40
  async function getTerminalOutputLifeCycle(initiatingProject, projectNames, tasks, nxArgs, nxJson, overrides) {
38
41
  const { runnerOptions } = getRunner(nxArgs, nxJson);
39
42
  const isRunOne = initiatingProject != null;
@@ -99,25 +102,32 @@ function createTaskGraphAndRunValidations(projectGraph, extraTargetDependencies,
99
102
  }
100
103
  async function runCommand(projectsToRun, currentProjectGraph, { nxJson }, nxArgs, overrides, initiatingProject, extraTargetDependencies, extraOptions) {
101
104
  const status = await (0, handle_errors_1.handleErrors)(process.env.NX_VERBOSE_LOGGING === 'true', async () => {
102
- const projectNames = projectsToRun.map((t) => t.name);
103
- const { projectGraph, taskGraph } = await ensureWorkspaceIsInSyncAndGetGraphs(currentProjectGraph, nxJson, projectNames, nxArgs, overrides, extraTargetDependencies, extraOptions);
104
- const tasks = Object.values(taskGraph.tasks);
105
- const { lifeCycle, renderIsDone } = await getTerminalOutputLifeCycle(initiatingProject, projectNames, tasks, nxArgs, nxJson, overrides);
106
- const status = await invokeTasksRunner({
107
- tasks,
108
- projectGraph,
109
- taskGraph,
110
- lifeCycle,
111
- nxJson,
112
- nxArgs,
113
- loadDotEnvFiles: extraOptions.loadDotEnvFiles,
114
- initiatingProject,
115
- });
116
- await renderIsDone;
117
- return status;
105
+ const taskResults = await runCommandForTasks(projectsToRun, currentProjectGraph, { nxJson }, nxArgs, overrides, initiatingProject, extraTargetDependencies, extraOptions);
106
+ return Object.values(taskResults).some((taskResult) => taskResult.status === 'failure' || taskResult.status === 'skipped')
107
+ ? 1
108
+ : 0;
118
109
  });
119
110
  return status;
120
111
  }
112
+ async function runCommandForTasks(projectsToRun, currentProjectGraph, { nxJson }, nxArgs, overrides, initiatingProject, extraTargetDependencies, extraOptions) {
113
+ const projectNames = projectsToRun.map((t) => t.name);
114
+ const { projectGraph, taskGraph } = await ensureWorkspaceIsInSyncAndGetGraphs(currentProjectGraph, nxJson, projectNames, nxArgs, overrides, extraTargetDependencies, extraOptions);
115
+ const tasks = Object.values(taskGraph.tasks);
116
+ const { lifeCycle, renderIsDone } = await getTerminalOutputLifeCycle(initiatingProject, projectNames, tasks, nxArgs, nxJson, overrides);
117
+ const taskResults = await invokeTasksRunner({
118
+ tasks,
119
+ projectGraph,
120
+ taskGraph,
121
+ lifeCycle,
122
+ nxJson,
123
+ nxArgs,
124
+ loadDotEnvFiles: extraOptions.loadDotEnvFiles,
125
+ initiatingProject,
126
+ });
127
+ await renderIsDone;
128
+ await (0, powerpack_1.printPowerpackLicense)();
129
+ return taskResults;
130
+ }
121
131
  async function ensureWorkspaceIsInSyncAndGetGraphs(projectGraph, nxJson, projectNames, nxArgs, overrides, extraTargetDependencies, extraOptions) {
122
132
  let taskGraph = createTaskGraphAndRunValidations(projectGraph, extraTargetDependencies ?? {}, projectNames, nxArgs, overrides, extraOptions);
123
133
  if (nxArgs.skipSync) {
@@ -359,9 +369,14 @@ async function invokeTasksRunner({ tasks, projectGraph, taskGraph, lifeCycle, nx
359
369
  // to submit everything that is known in advance to Nx Cloud to run in
360
370
  // a distributed fashion
361
371
  await (0, hash_task_1.hashTasksThatDoNotDependOnOutputsOfOtherTasks)(hasher, projectGraph, taskGraph, nxJson);
362
- const promiseOrObservable = tasksRunner(tasks, {
372
+ const taskResultsLifecycle = new task_results_life_cycle_1.TaskResultsLifeCycle();
373
+ const compositedLifeCycle = new life_cycle_1.CompositeLifeCycle([
374
+ ...constructLifeCycles(lifeCycle),
375
+ taskResultsLifecycle,
376
+ ]);
377
+ let promiseOrObservable = tasksRunner(tasks, {
363
378
  ...runnerOptions,
364
- lifeCycle: new life_cycle_1.CompositeLifeCycle(constructLifeCycles(lifeCycle)),
379
+ lifeCycle: compositedLifeCycle,
365
380
  }, {
366
381
  initiatingProject: nxArgs.outputStyle === 'compact' ? null : initiatingProject,
367
382
  projectGraph,
@@ -418,15 +433,11 @@ async function invokeTasksRunner({ tasks, projectGraph, taskGraph, lifeCycle, nx
418
433
  },
419
434
  daemon: client_1.daemonClient,
420
435
  });
421
- let anyFailures;
422
436
  if (promiseOrObservable.subscribe) {
423
- anyFailures = await anyFailuresInObservable(promiseOrObservable);
424
- }
425
- else {
426
- // simply await the promise
427
- anyFailures = await anyFailuresInPromise(promiseOrObservable);
437
+ promiseOrObservable = convertObservableToPromise(promiseOrObservable);
428
438
  }
429
- return anyFailures ? 1 : 0;
439
+ await promiseOrObservable;
440
+ return taskResultsLifecycle.getTaskResults();
430
441
  }
431
442
  function constructLifeCycles(lifeCycle) {
432
443
  const lifeCycles = [];
@@ -445,41 +456,23 @@ function constructLifeCycles(lifeCycle) {
445
456
  }
446
457
  return lifeCycles;
447
458
  }
448
- function mergeTargetDependencies(defaults, deps) {
449
- const res = {};
450
- Object.keys(defaults ?? {}).forEach((k) => {
451
- res[k] = defaults[k].dependsOn;
452
- });
453
- if (deps) {
454
- Object.keys(deps).forEach((k) => {
455
- if (res[k]) {
456
- res[k] = [...res[k], deps[k]];
457
- }
458
- else {
459
- res[k] = deps[k];
460
- }
461
- });
462
- return res;
463
- }
464
- }
465
- async function anyFailuresInPromise(promise) {
466
- return Object.values(await promise).some((v) => v === 'failure' || v === 'skipped');
467
- }
468
- async function anyFailuresInObservable(obs) {
459
+ async function convertObservableToPromise(obs) {
469
460
  return await new Promise((res) => {
470
- let anyFailures = false;
471
- obs.subscribe((t) => {
472
- if (!t.success) {
473
- anyFailures = true;
474
- }
475
- }, (error) => {
476
- output_1.output.error({
477
- title: 'Unhandled error in task executor',
478
- });
479
- console.error(error);
480
- res(true);
481
- }, () => {
482
- res(anyFailures);
461
+ let tasksResults = {};
462
+ obs.subscribe({
463
+ next: (t) => {
464
+ tasksResults[t.task.id] = t.success ? 'success' : 'failure';
465
+ },
466
+ error: (error) => {
467
+ output_1.output.error({
468
+ title: 'Unhandled error in task executor',
469
+ });
470
+ console.error(error);
471
+ res(tasksResults);
472
+ },
473
+ complete: () => {
474
+ res(tasksResults);
475
+ },
483
476
  });
484
477
  });
485
478
  }
@@ -41,7 +41,10 @@ class TaskOrchestrator {
41
41
  }
42
42
  async run() {
43
43
  // Init the ForkedProcessTaskRunner
44
- await this.forkedProcessTaskRunner.init();
44
+ await Promise.all([
45
+ this.forkedProcessTaskRunner.init(),
46
+ this.tasksSchedule.init(),
47
+ ]);
45
48
  // initial scheduling
46
49
  await this.tasksSchedule.scheduleNextTasks();
47
50
  perf_hooks_1.performance.mark('task-execution:start');
@@ -12,12 +12,15 @@ export declare class TasksSchedule {
12
12
  private notScheduledTaskGraph;
13
13
  private reverseTaskDeps;
14
14
  private reverseProjectGraph;
15
+ private taskHistory;
15
16
  private scheduledBatches;
16
17
  private scheduledTasks;
17
18
  private runningTasks;
18
19
  private completedTasks;
19
20
  private scheduleRequestsExecutionChain;
21
+ private estimatedTaskTimings;
20
22
  constructor(projectGraph: ProjectGraph, taskGraph: TaskGraph, options: DefaultTasksRunnerOptions);
23
+ init(): Promise<void>;
21
24
  scheduleNextTasks(): Promise<void>;
22
25
  hasTasks(): boolean;
23
26
  complete(taskIds: string[]): void;
@@ -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,11 +13,19 @@ 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 = process.env.NX_DISABLE_DB !== 'true' ? (0, task_history_1.getTaskHistory)() : null;
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();
22
+ this.estimatedTaskTimings = {};
23
+ }
24
+ async init() {
25
+ if (this.taskHistory) {
26
+ this.estimatedTaskTimings =
27
+ await this.taskHistory.getEstimatedTaskTimings(Object.values(this.taskGraph.tasks).map((t) => t.target));
28
+ }
20
29
  }
21
30
  async scheduleNextTasks() {
22
31
  this.scheduleRequestsExecutionChain =
@@ -81,10 +90,23 @@ class TasksSchedule {
81
90
  // Most likely tasks with no dependencies such as test
82
91
  const project1 = this.taskGraph.tasks[taskId1].target.project;
83
92
  const project2 = this.taskGraph.tasks[taskId2].target.project;
84
- return ((0, project_graph_utils_1.findAllProjectNodeDependencies)(project2, this.reverseProjectGraph)
85
- .length -
86
- (0, project_graph_utils_1.findAllProjectNodeDependencies)(project1, this.reverseProjectGraph)
87
- .length);
93
+ const project1NodeDependencies = (0, project_graph_utils_1.findAllProjectNodeDependencies)(project1, this.reverseProjectGraph).length;
94
+ const project2NodeDependencies = (0, project_graph_utils_1.findAllProjectNodeDependencies)(project2, this.reverseProjectGraph).length;
95
+ const dependenciesDiff = project2NodeDependencies - project1NodeDependencies;
96
+ if (dependenciesDiff !== 0) {
97
+ return dependenciesDiff;
98
+ }
99
+ const task1Timing = this.estimatedTaskTimings[taskId1];
100
+ if (!task1Timing) {
101
+ // if no timing or 0, put task1 at beginning
102
+ return -1;
103
+ }
104
+ const task2Timing = this.estimatedTaskTimings[taskId2];
105
+ if (!task2Timing) {
106
+ // if no timing or 0, put task2 at beginning
107
+ return 1;
108
+ }
109
+ return task2Timing - task1Timing;
88
110
  });
89
111
  this.runningTasks.add(taskId);
90
112
  }
@@ -1,2 +1,5 @@
1
1
  import { ExternalObject } from '../native';
2
- export declare function getDbConnection(directory?: string): ExternalObject<any>;
2
+ export declare function getDbConnection(opts?: {
3
+ directory?: string;
4
+ dbName?: string;
5
+ }): ExternalObject<Connection>;
@@ -4,8 +4,19 @@ exports.getDbConnection = getDbConnection;
4
4
  const native_1 = require("../native");
5
5
  const cache_directory_1 = require("./cache-directory");
6
6
  const package_json_1 = require("../../package.json");
7
- let dbConnection;
8
- function getDbConnection(directory = cache_directory_1.workspaceDataDirectory) {
9
- dbConnection ??= (0, native_1.connectToNxDb)(directory, package_json_1.version);
10
- return dbConnection;
7
+ const dbConnectionMap = new Map();
8
+ function getDbConnection(opts = {}) {
9
+ opts.directory ??= cache_directory_1.workspaceDataDirectory;
10
+ const key = `${opts.directory}:${opts.dbName ?? 'default'}`;
11
+ const connection = getEntryOrSet(dbConnectionMap, key, () => (0, native_1.connectToNxDb)(opts.directory, package_json_1.version, opts.dbName));
12
+ return connection;
13
+ }
14
+ function getEntryOrSet(map, key, defaultValue) {
15
+ const existing = map.get(key);
16
+ if (existing) {
17
+ return existing;
18
+ }
19
+ const val = defaultValue();
20
+ map.set(key, val);
21
+ return val;
11
22
  }
@@ -7,6 +7,7 @@ export declare class GitRepository {
7
7
  root: string;
8
8
  constructor(directory: string);
9
9
  getGitRootPath(cwd: string): string;
10
+ hasUncommittedChanges(): Promise<boolean>;
10
11
  addFetchRemote(remoteName: string, branch: string): Promise<string>;
11
12
  showStat(): Promise<string>;
12
13
  listBranches(): Promise<string[]>;
@@ -40,6 +40,10 @@ class GitRepository {
40
40
  .toString()
41
41
  .trim();
42
42
  }
43
+ async hasUncommittedChanges() {
44
+ const data = await this.execAsync(`git status --porcelain`);
45
+ return data.trim() !== '';
46
+ }
43
47
  async addFetchRemote(remoteName, branch) {
44
48
  return await this.execAsync(`git config --add remote.${remoteName}.fetch "+refs/heads/${branch}:refs/remotes/${remoteName}/${branch}"`);
45
49
  }
@@ -2,4 +2,5 @@ import { ProjectConfiguration } from '../../config/workspace-json-project-json';
2
2
  import { PluginCapabilities } from './plugin-capabilities';
3
3
  export declare function listPlugins(plugins: Map<string, PluginCapabilities>, title: string): void;
4
4
  export declare function listAlsoAvailableCorePlugins(installedPlugins: Map<string, PluginCapabilities>): void;
5
+ export declare function listPowerpackPlugins(): void;
5
6
  export declare function listPluginCapabilities(pluginName: string, projects: Record<string, ProjectConfiguration>): Promise<void>;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.listPlugins = listPlugins;
4
4
  exports.listAlsoAvailableCorePlugins = listAlsoAvailableCorePlugins;
5
+ exports.listPowerpackPlugins = listPowerpackPlugins;
5
6
  exports.listPluginCapabilities = listPluginCapabilities;
6
7
  const chalk = require("chalk");
7
8
  const output_1 = require("../output");
@@ -45,6 +46,12 @@ function listAlsoAvailableCorePlugins(installedPlugins) {
45
46
  });
46
47
  }
47
48
  }
49
+ function listPowerpackPlugins() {
50
+ const powerpackLink = 'https://nx.dev/plugin-registry';
51
+ output_1.output.log({
52
+ title: `Available Powerpack Plugins: ${powerpackLink}`,
53
+ });
54
+ }
48
55
  async function listPluginCapabilities(pluginName, projects) {
49
56
  const plugin = await (0, plugin_capabilities_1.getPluginCapabilities)(workspace_root_1.workspaceRoot, pluginName, projects);
50
57
  if (!plugin) {
@@ -0,0 +1,5 @@
1
+ export declare function printPowerpackLicense(): Promise<void>;
2
+ export declare function getPowerpackLicenseInformation(): Promise<any>;
3
+ export declare class NxPowerpackNotInstalledError extends Error {
4
+ constructor(e: Error);
5
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NxPowerpackNotInstalledError = void 0;
4
+ exports.printPowerpackLicense = printPowerpackLicense;
5
+ exports.getPowerpackLicenseInformation = getPowerpackLicenseInformation;
6
+ const logger_1 = require("./logger");
7
+ const package_manager_1 = require("./package-manager");
8
+ const workspace_root_1 = require("./workspace-root");
9
+ async function printPowerpackLicense() {
10
+ try {
11
+ const { organizationName, seatCount, workspaceCount } = await getPowerpackLicenseInformation();
12
+ logger_1.logger.log(`Nx Powerpack Licensed to ${organizationName} for ${seatCount} user${seatCount > 1 ? '' : 's'} in ${workspaceCount} workspace${workspaceCount > 1 ? '' : 's'}`);
13
+ }
14
+ catch { }
15
+ }
16
+ async function getPowerpackLicenseInformation() {
17
+ try {
18
+ const { getPowerpackLicenseInformation } = (await Promise.resolve().then(() => require(
19
+ // @ts-ignore
20
+ '@nx/powerpack-license'
21
+ // TODO(@FrozenPandaz): Provide the right type here.
22
+ )));
23
+ // )) as typeof import('@nx/powerpack-license');
24
+ return getPowerpackLicenseInformation(workspace_root_1.workspaceRoot);
25
+ }
26
+ catch (e) {
27
+ if ('code' in e && e.code === 'ERR_MODULE_NOT_FOUND') {
28
+ throw new NxPowerpackNotInstalledError(e);
29
+ }
30
+ throw e;
31
+ }
32
+ }
33
+ class NxPowerpackNotInstalledError extends Error {
34
+ constructor(e) {
35
+ super(`The "@nx/powerpack-license" package is needed to use Nx Powerpack enabled features. Please install the @nx/powerpack-license with ${(0, package_manager_1.getPackageManagerCommand)().addDev} @nx/powerpack-license`, { cause: e });
36
+ }
37
+ }
38
+ exports.NxPowerpackNotInstalledError = NxPowerpackNotInstalledError;
@@ -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
+ }