nx 19.8.0-canary.20240917-5b34ea5 → 19.8.0-canary.20240919-7f4a877

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.
Files changed (57) hide show
  1. package/bin/nx-cloud.js +0 -0
  2. package/package.json +17 -17
  3. package/schemas/nx-schema.json +2 -2
  4. package/src/command-line/activate-powerpack/activate-powerpack.d.ts +2 -0
  5. package/src/command-line/activate-powerpack/activate-powerpack.js +32 -0
  6. package/src/command-line/activate-powerpack/command-object.d.ts +6 -0
  7. package/src/command-line/activate-powerpack/command-object.js +26 -0
  8. package/src/command-line/add/command-object.d.ts +1 -1
  9. package/src/command-line/format/format.js +24 -7
  10. package/src/command-line/import/import.js +9 -4
  11. package/src/command-line/import/utils/prepare-source-repo.js +7 -35
  12. package/src/command-line/init/init-v2.d.ts +1 -1
  13. package/src/command-line/init/init-v2.js +10 -4
  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/release/command-object.d.ts +2 -2
  18. package/src/command-line/release/config/config.js +8 -2
  19. package/src/command-line/release/utils/git.d.ts +2 -2
  20. package/src/command-line/release/utils/git.js +12 -2
  21. package/src/command-line/release/utils/shared.d.ts +1 -1
  22. package/src/command-line/release/version.js +4 -0
  23. package/src/command-line/report/report.d.ts +3 -0
  24. package/src/command-line/report/report.js +27 -1
  25. package/src/config/nx-json.d.ts +13 -5
  26. package/src/core/graph/main.js +1 -1
  27. package/src/native/index.d.ts +2 -1
  28. package/src/native/nx.wasm32-wasi.wasm +0 -0
  29. package/src/tasks-runner/cache.d.ts +5 -1
  30. package/src/tasks-runner/cache.js +51 -5
  31. package/src/tasks-runner/init-tasks-runner.d.ts +1 -1
  32. package/src/tasks-runner/init-tasks-runner.js +5 -3
  33. package/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.d.ts +0 -2
  34. package/src/tasks-runner/life-cycles/invoke-runner-terminal-output-life-cycle.js +0 -5
  35. package/src/tasks-runner/life-cycles/static-run-many-terminal-output-life-cycle.d.ts +2 -6
  36. package/src/tasks-runner/life-cycles/static-run-one-terminal-output-life-cycle.d.ts +2 -6
  37. package/src/tasks-runner/life-cycles/store-run-information-life-cycle.d.ts +2 -7
  38. package/src/tasks-runner/life-cycles/task-profiling-life-cycle.d.ts +2 -7
  39. package/src/tasks-runner/life-cycles/task-results-life-cycle.d.ts +6 -0
  40. package/src/tasks-runner/life-cycles/task-results-life-cycle.js +17 -0
  41. package/src/tasks-runner/life-cycles/task-timings-life-cycle.d.ts +2 -7
  42. package/src/tasks-runner/run-command.d.ts +12 -2
  43. package/src/tasks-runner/run-command.js +52 -59
  44. package/src/tasks-runner/task-orchestrator.d.ts +0 -1
  45. package/src/tasks-runner/task-orchestrator.js +5 -7
  46. package/src/utils/db-connection.d.ts +4 -1
  47. package/src/utils/db-connection.js +15 -4
  48. package/src/utils/git-utils.d.ts +4 -2
  49. package/src/utils/git-utils.index-filter.d.ts +0 -0
  50. package/src/utils/git-utils.index-filter.js +20 -0
  51. package/src/utils/git-utils.js +48 -13
  52. package/src/utils/git-utils.tree-filter.d.ts +11 -0
  53. package/src/utils/git-utils.tree-filter.js +43 -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
@@ -35,6 +35,7 @@ export declare class NxCache {
35
35
  getTaskOutputsPath(hash: string): string
36
36
  copyFilesFromCache(cachedResult: CachedResult, outputs: Array<string>): void
37
37
  removeOldCacheRecords(): void
38
+ checkCacheFsInSync(): boolean
38
39
  }
39
40
 
40
41
  export declare class NxTaskHistory {
@@ -96,7 +97,7 @@ export interface CachedResult {
96
97
  outputsPath: string
97
98
  }
98
99
 
99
- export declare export function connectToNxDb(cacheDir: string, nxVersion: string): ExternalObject<Connection>
100
+ export declare export function connectToNxDb(cacheDir: string, nxVersion: string, dbName?: string | undefined | null): ExternalObject<Connection>
100
101
 
101
102
  export declare export function copy(src: string, dest: string): void
102
103
 
Binary file
@@ -16,10 +16,10 @@ export declare class DbCache {
16
16
  private cache;
17
17
  private remoteCache;
18
18
  private remoteCachePromise;
19
- setup(): Promise<void>;
20
19
  constructor(options: {
21
20
  nxCloudRemoteCache: RemoteCache;
22
21
  });
22
+ init(): Promise<void>;
23
23
  get(task: Task): Promise<CachedResult | null>;
24
24
  private applyRemoteCacheResults;
25
25
  put(task: Task, terminalOutput: string | null, outputs: string[], code: number): Promise<void>;
@@ -28,6 +28,10 @@ export declare class DbCache {
28
28
  temporaryOutputPath(task: Task): string;
29
29
  private getRemoteCache;
30
30
  private _getRemoteCache;
31
+ private getPowerpackS3Cache;
32
+ private getPowerpackSharedCache;
33
+ private resolvePackage;
34
+ private assertCacheIsValid;
31
35
  }
32
36
  /**
33
37
  * @deprecated Use the {@link DbCache} class instead. This will be removed in Nx 21.
@@ -16,6 +16,7 @@ const nx_cloud_utils_1 = require("../utils/nx-cloud-utils");
16
16
  const nx_json_1 = require("../config/nx-json");
17
17
  const update_manager_1 = require("../nx-cloud/update-manager");
18
18
  const get_cloud_options_1 = require("../nx-cloud/utilities/get-cloud-options");
19
+ const is_ci_1 = require("../utils/is-ci");
19
20
  function getCache(options) {
20
21
  return process.env.NX_DISABLE_DB !== 'true' &&
21
22
  process.env.NX_DB_CACHE === 'true'
@@ -28,13 +29,17 @@ function getCache(options) {
28
29
  : new Cache(options);
29
30
  }
30
31
  class DbCache {
31
- async setup() {
32
- this.remoteCache = await this.getRemoteCache();
33
- }
34
32
  constructor(options) {
35
33
  this.options = options;
36
34
  this.cache = new native_1.NxCache(workspace_root_1.workspaceRoot, cache_directory_1.cacheDir, (0, db_connection_1.getDbConnection)());
37
35
  }
36
+ async init() {
37
+ // This should be cheap because we've already loaded
38
+ this.remoteCache = await this.getRemoteCache();
39
+ if (!this.remoteCache) {
40
+ this.assertCacheIsValid();
41
+ }
42
+ }
38
43
  async get(task) {
39
44
  const res = this.cache.get(task.hash);
40
45
  if (res) {
@@ -43,7 +48,6 @@ class DbCache {
43
48
  remote: false,
44
49
  };
45
50
  }
46
- await this.setup();
47
51
  if (this.remoteCache) {
48
52
  // didn't find it locally but we have a remote cache
49
53
  // attempt remote cache
@@ -67,9 +71,9 @@ class DbCache {
67
71
  return this.cache.applyRemoteCacheResults(hash, res);
68
72
  }
69
73
  async put(task, terminalOutput, outputs, code) {
74
+ await this.assertCacheIsValid();
70
75
  return tryAndRetry(async () => {
71
76
  this.cache.put(task.hash, terminalOutput, outputs, code);
72
- await this.setup();
73
77
  if (this.remoteCache) {
74
78
  await this.remoteCache.store(task.hash, this.cache.cacheDirectory, terminalOutput, code);
75
79
  }
@@ -105,9 +109,51 @@ class DbCache {
105
109
  }
106
110
  }
107
111
  else {
112
+ return ((await this.getPowerpackS3Cache()) ??
113
+ (await this.getPowerpackSharedCache()) ??
114
+ null);
115
+ }
116
+ }
117
+ async getPowerpackS3Cache() {
118
+ try {
119
+ const { getRemoteCache } = await Promise.resolve(`${this.resolvePackage('@nx/powerpack-s3-cache')}`).then(s => require(s));
120
+ return getRemoteCache();
121
+ }
122
+ catch {
108
123
  return null;
109
124
  }
110
125
  }
126
+ async getPowerpackSharedCache() {
127
+ try {
128
+ const { getRemoteCache } = await Promise.resolve(`${this.resolvePackage('@nx/powerpack-shared-cache')}`).then(s => require(s));
129
+ return getRemoteCache();
130
+ }
131
+ catch {
132
+ return null;
133
+ }
134
+ }
135
+ resolvePackage(pkg) {
136
+ return require.resolve(pkg, {
137
+ paths: [process.cwd(), workspace_root_1.workspaceRoot, __dirname],
138
+ });
139
+ }
140
+ assertCacheIsValid() {
141
+ // User has customized the cache directory - this could be because they
142
+ // are using a shared cache in the custom directory. The db cache is not
143
+ // stored in the cache directory, and is keyed by machine ID so they would
144
+ // hit issues. If we detect this, we can create a fallback db cache in the
145
+ // custom directory, and check if the entries are there when the main db
146
+ // cache misses.
147
+ if ((0, is_ci_1.isCI)() && !this.cache.checkCacheFsInSync()) {
148
+ const warning = [
149
+ `Nx found unrecognized artifacts in the cache directory and will not be able to use them.`,
150
+ `Nx can only restore artifacts it has metadata about.`,
151
+ `Read about this warning and how to address it here: https://nx.dev/troubleshooting/unknown-local-cache`,
152
+ ``,
153
+ ].join('\n');
154
+ console.warn(warning);
155
+ }
156
+ }
111
157
  }
112
158
  exports.DbCache = DbCache;
113
159
  /**
@@ -6,7 +6,7 @@ export declare function initTasksRunner(nxArgs: NxArgs): Promise<{
6
6
  tasks: Task[];
7
7
  parallel: number;
8
8
  }) => Promise<{
9
- status: number;
9
+ status: NodeJS.Process["exitCode"];
10
10
  taskGraph: TaskGraph;
11
11
  taskResults: Record<string, TaskResult>;
12
12
  }>;
@@ -39,7 +39,7 @@ async function initTasksRunner(nxArgs) {
39
39
  return acc;
40
40
  }, {}),
41
41
  };
42
- const status = await (0, run_command_1.invokeTasksRunner)({
42
+ const taskResults = await (0, run_command_1.invokeTasksRunner)({
43
43
  tasks: opts.tasks,
44
44
  projectGraph,
45
45
  taskGraph,
@@ -50,9 +50,11 @@ async function initTasksRunner(nxArgs) {
50
50
  initiatingProject: null,
51
51
  });
52
52
  return {
53
- status,
53
+ status: Object.values(taskResults).some((taskResult) => taskResult.status === 'failure' || taskResult.status === 'skipped')
54
+ ? 1
55
+ : 0,
54
56
  taskGraph,
55
- taskResults: lifeCycle.getTaskResults(),
57
+ taskResults,
56
58
  };
57
59
  },
58
60
  };
@@ -5,11 +5,9 @@ export declare class InvokeRunnerTerminalOutputLifeCycle implements LifeCycle {
5
5
  private readonly tasks;
6
6
  failedTasks: Task[];
7
7
  cachedTasks: Task[];
8
- private taskResults;
9
8
  constructor(tasks: Task[]);
10
9
  startCommand(): void;
11
10
  endCommand(): void;
12
11
  endTasks(taskResults: TaskResult[]): void;
13
12
  printTaskTerminalOutput(task: Task, cacheStatus: TaskStatus, terminalOutput: string): void;
14
- getTaskResults(): Record<string, TaskResult>;
15
13
  }
@@ -8,7 +8,6 @@ class InvokeRunnerTerminalOutputLifeCycle {
8
8
  this.tasks = tasks;
9
9
  this.failedTasks = [];
10
10
  this.cachedTasks = [];
11
- this.taskResults = {};
12
11
  }
13
12
  startCommand() {
14
13
  output_1.output.log({
@@ -46,7 +45,6 @@ class InvokeRunnerTerminalOutputLifeCycle {
46
45
  }
47
46
  endTasks(taskResults) {
48
47
  for (let t of taskResults) {
49
- this.taskResults[t.task.id] = t;
50
48
  if (t.status === 'failure') {
51
49
  this.failedTasks.push(t.task);
52
50
  }
@@ -65,8 +63,5 @@ class InvokeRunnerTerminalOutputLifeCycle {
65
63
  const args = (0, utils_1.getPrintableCommandArgsForTask)(task);
66
64
  output_1.output.logCommandOutput(args.join(' '), cacheStatus, terminalOutput);
67
65
  }
68
- getTaskResults() {
69
- return this.taskResults;
70
- }
71
66
  }
72
67
  exports.InvokeRunnerTerminalOutputLifeCycle = InvokeRunnerTerminalOutputLifeCycle;
@@ -1,5 +1,5 @@
1
1
  import { TaskStatus } from '../tasks-runner';
2
- import type { LifeCycle } from '../life-cycle';
2
+ import type { LifeCycle, TaskResult } from '../life-cycle';
3
3
  import { Task } from '../../config/task-graph';
4
4
  /**
5
5
  * The following life cycle's outputs are static, meaning no previous content
@@ -24,10 +24,6 @@ export declare class StaticRunManyTerminalOutputLifeCycle implements LifeCycle {
24
24
  startCommand(): void;
25
25
  endCommand(): void;
26
26
  private skippedTasks;
27
- endTasks(taskResults: {
28
- task: Task;
29
- status: TaskStatus;
30
- code: number;
31
- }[]): void;
27
+ endTasks(taskResults: TaskResult[]): void;
32
28
  printTaskTerminalOutput(task: Task, cacheStatus: TaskStatus, terminalOutput: string): void;
33
29
  }
@@ -1,5 +1,5 @@
1
1
  import { TaskStatus } from '../tasks-runner';
2
- import type { LifeCycle } from '../life-cycle';
2
+ import type { LifeCycle, TaskResult } from '../life-cycle';
3
3
  import { Task } from '../../config/task-graph';
4
4
  /**
5
5
  * The following life cycle's outputs are static, meaning no previous content
@@ -23,10 +23,6 @@ export declare class StaticRunOneTerminalOutputLifeCycle implements LifeCycle {
23
23
  });
24
24
  startCommand(): void;
25
25
  endCommand(): void;
26
- endTasks(taskResults: {
27
- task: Task;
28
- status: TaskStatus;
29
- code: number;
30
- }[]): void;
26
+ endTasks(taskResults: TaskResult[]): void;
31
27
  printTaskTerminalOutput(task: Task, status: TaskStatus, terminalOutput: string): void;
32
28
  }
@@ -1,6 +1,5 @@
1
- import { LifeCycle } from '../../tasks-runner/life-cycle';
1
+ import { LifeCycle, TaskResult } from '../../tasks-runner/life-cycle';
2
2
  import { Task } from '../../config/task-graph';
3
- import { TaskStatus } from '../../tasks-runner/tasks-runner';
4
3
  export declare class StoreRunInformationLifeCycle implements LifeCycle {
5
4
  private readonly command;
6
5
  private readonly storeFile;
@@ -10,11 +9,7 @@ export declare class StoreRunInformationLifeCycle implements LifeCycle {
10
9
  private taskResults;
11
10
  constructor(command?: string, storeFile?: typeof storeFileFunction, now?: () => string);
12
11
  startTasks(tasks: Task[]): void;
13
- endTasks(taskResults: Array<{
14
- task: Task;
15
- status: TaskStatus;
16
- code: number;
17
- }>): void;
12
+ endTasks(taskResults: TaskResult[]): void;
18
13
  startCommand(): void;
19
14
  endCommand(): any;
20
15
  }
@@ -1,5 +1,4 @@
1
- import { LifeCycle, TaskMetadata } from '../life-cycle';
2
- import { TaskStatus } from '../tasks-runner';
1
+ import { LifeCycle, TaskMetadata, TaskResult } from '../life-cycle';
3
2
  import { Task } from '../../config/task-graph';
4
3
  export declare class TaskProfilingLifeCycle implements LifeCycle {
5
4
  private timings;
@@ -8,11 +7,7 @@ export declare class TaskProfilingLifeCycle implements LifeCycle {
8
7
  private registeredGroups;
9
8
  constructor(_profileFile: string);
10
9
  startTasks(tasks: Task[], { groupId }: TaskMetadata): void;
11
- endTasks(taskResults: Array<{
12
- task: Task;
13
- status: TaskStatus;
14
- code: number;
15
- }>, metadata: TaskMetadata): void;
10
+ endTasks(taskResults: TaskResult[], metadata: TaskMetadata): void;
16
11
  endCommand(): void;
17
12
  private recordTaskCompletions;
18
13
  private registerGroup;
@@ -0,0 +1,6 @@
1
+ import type { LifeCycle, TaskResult } from '../life-cycle';
2
+ export declare class TaskResultsLifeCycle implements LifeCycle {
3
+ private taskResults;
4
+ endTasks(taskResults: TaskResult[]): void;
5
+ getTaskResults(): Record<string, TaskResult>;
6
+ }
@@ -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
  }
@@ -40,7 +40,6 @@ export declare class TaskOrchestrator {
40
40
  private runTaskInForkedProcess;
41
41
  private preRunSteps;
42
42
  private postRunSteps;
43
- private scheduleNextTasks;
44
43
  private complete;
45
44
  private pipeOutputCapture;
46
45
  private shouldCacheTaskResult;
@@ -40,13 +40,14 @@ class TaskOrchestrator {
40
40
  this.bailed = false;
41
41
  }
42
42
  async run() {
43
- // Init the ForkedProcessTaskRunner
43
+ // Init the ForkedProcessTaskRunner, TasksSchedule, and Cache
44
44
  await Promise.all([
45
45
  this.forkedProcessTaskRunner.init(),
46
46
  this.tasksSchedule.init(),
47
+ 'init' in this.cache ? this.cache.init() : null,
47
48
  ]);
48
49
  // initial scheduling
49
- await this.scheduleNextTasks();
50
+ await this.tasksSchedule.scheduleNextTasks();
50
51
  perf_hooks_1.performance.mark('task-execution:start');
51
52
  const threads = [];
52
53
  process.stdout.setMaxListeners(this.options.parallel + events_1.defaultMaxListeners);
@@ -68,6 +69,7 @@ class TaskOrchestrator {
68
69
  }
69
70
  const doNotSkipCache = this.options.skipNxCache === false ||
70
71
  this.options.skipNxCache === undefined;
72
+ this.processAllScheduledTasks();
71
73
  const batch = this.tasksSchedule.nextBatch();
72
74
  if (batch) {
73
75
  const groupId = this.closeGroup();
@@ -376,15 +378,11 @@ class TaskOrchestrator {
376
378
  status,
377
379
  };
378
380
  }));
379
- await this.scheduleNextTasks();
381
+ await this.tasksSchedule.scheduleNextTasks();
380
382
  // release blocked threads
381
383
  this.waitingForTasks.forEach((f) => f(null));
382
384
  this.waitingForTasks.length = 0;
383
385
  }
384
- async scheduleNextTasks() {
385
- await this.tasksSchedule.scheduleNextTasks();
386
- this.processAllScheduledTasks();
387
- }
388
386
  complete(taskResults) {
389
387
  this.tasksSchedule.complete(taskResults.map(({ taskId }) => taskId));
390
388
  for (const { taskId, status } of taskResults) {
@@ -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[]>;
@@ -25,10 +26,11 @@ export declare class GitRepository {
25
26
  deleteGitRemote(name: string): Promise<string>;
26
27
  addGitRemote(name: string, url: string): Promise<string>;
27
28
  hasFilterRepoInstalled(): Promise<boolean>;
28
- filterRepo(subdirectory: string): Promise<string>;
29
- filterBranch(subdirectory: string, branchName: string): Promise<string>;
29
+ filterRepo(source: string, destination: string): Promise<void>;
30
+ filterBranch(source: string, destination: string, branchName: string): Promise<void>;
30
31
  private execAsync;
31
32
  private quotePath;
33
+ private quoteArg;
32
34
  }
33
35
  /**
34
36
  * This is currently duplicated in Nx Console. Please let @MaxKless know if you make changes here.
File without changes