Skip to content

Commit 8a3f6a6

Browse files
committed
chore(core): update API to pre/post tasks execution and for it to run via the daemon
1 parent e3c31b7 commit 8a3f6a6

File tree

21 files changed

+324
-164
lines changed

21 files changed

+324
-164
lines changed

docs/generated/devkit/NxPluginV2.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ A plugin which enhances the behavior of Nx
1919
| `createNodes?` | [`CreateNodes`](../../devkit/documents/CreateNodes)\<`TOptions`\> | Provides a file pattern and function that retrieves configuration info from those files. e.g. { '**/\*.csproj': buildProjectsFromCsProjFile } **`Deprecated`\*\* Use createNodesV2 instead. In Nx 21 support for calling createNodes with a single file for the first argument will be removed. |
2020
| `createNodesV2?` | [`CreateNodesV2`](../../devkit/documents/CreateNodesV2)\<`TOptions`\> | Provides a file pattern and function that retrieves configuration info from those files. e.g. { '\*_/_.csproj': buildProjectsFromCsProjFiles } In Nx 21 createNodes will be replaced with this property. In Nx 22, this property will be removed. |
2121
| `name` | `string` | - |
22-
| `postRun?` | [`PostRun`](../../devkit/documents/PostRun)\<`TOptions`\> | Provides a function to run after the Nx runs tasks |
23-
| `preRun?` | [`PreRun`](../../devkit/documents/PreRun)\<`TOptions`\> | Provides a function to run before the Nx runs tasks |
22+
| `postTasksExecution?` | [`PostTasksExecution`](../../devkit/documents/PostTasksExecution)\<`TOptions`\> | Provides a function to run after the Nx runs tasks |
23+
| `preTasksExecution?` | [`PreTasksExecution`](../../devkit/documents/PreTasksExecution)\<`TOptions`\> | Provides a function to run before the Nx runs tasks |

docs/generated/devkit/PreRun.md renamed to docs/generated/devkit/PostTasksExecution.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Type alias: PreRun\<TOptions\>
1+
# Type alias: PostTasksExecution\<TOptions\>
22

3-
Ƭ **PreRun**\<`TOptions`\>: (`options`: `TOptions` \| `undefined`, `context`: [`PreRunContext`](../../devkit/documents/PreRunContext)) => `void` \| `Promise`\<`void`\>
3+
Ƭ **PostTasksExecution**\<`TOptions`\>: (`options`: `TOptions` \| `undefined`, `context`: [`PostTasksExecutionContext`](../../devkit/documents/PostTasksExecutionContext)) => `void` \| `Promise`\<`void`\>
44

55
#### Type parameters
66

@@ -14,10 +14,10 @@
1414

1515
##### Parameters
1616

17-
| Name | Type |
18-
| :-------- | :------------------------------------------------------ |
19-
| `options` | `TOptions` \| `undefined` |
20-
| `context` | [`PreRunContext`](../../devkit/documents/PreRunContext) |
17+
| Name | Type |
18+
| :-------- | :------------------------------------------------------------------------------ |
19+
| `options` | `TOptions` \| `undefined` |
20+
| `context` | [`PostTasksExecutionContext`](../../devkit/documents/PostTasksExecutionContext) |
2121

2222
##### Returns
2323

docs/generated/devkit/PostRunContext.md renamed to docs/generated/devkit/PostTasksExecutionContext.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Type alias: PostRunContext
1+
# Type alias: PostTasksExecutionContext
22

3-
Ƭ **PostRunContext**: `Object`
3+
Ƭ **PostTasksExecutionContext**: `Object`
44

55
#### Type declaration
66

docs/generated/devkit/PostRun.md renamed to docs/generated/devkit/PreTasksExecution.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Type alias: PostRun\<TOptions\>
1+
# Type alias: PreTasksExecution\<TOptions\>
22

3-
Ƭ **PostRun**\<`TOptions`\>: (`options`: `TOptions` \| `undefined`, `context`: [`PostRunContext`](../../devkit/documents/PostRunContext)) => `void` \| `Promise`\<`void`\>
3+
Ƭ **PreTasksExecution**\<`TOptions`\>: (`options`: `TOptions` \| `undefined`, `context`: [`PreTasksExecutionContext`](../../devkit/documents/PreTasksExecutionContext)) => `void` \| `Promise`\<`void`\>
44

55
#### Type parameters
66

@@ -14,10 +14,10 @@
1414

1515
##### Parameters
1616

17-
| Name | Type |
18-
| :-------- | :-------------------------------------------------------- |
19-
| `options` | `TOptions` \| `undefined` |
20-
| `context` | [`PostRunContext`](../../devkit/documents/PostRunContext) |
17+
| Name | Type |
18+
| :-------- | :---------------------------------------------------------------------------- |
19+
| `options` | `TOptions` \| `undefined` |
20+
| `context` | [`PreTasksExecutionContext`](../../devkit/documents/PreTasksExecutionContext) |
2121

2222
##### Returns
2323

docs/generated/devkit/PreRunContext.md renamed to docs/generated/devkit/PreTasksExecutionContext.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Type alias: PreRunContext
1+
# Type alias: PreTasksExecutionContext
22

3-
Ƭ **PreRunContext**: `Object`
3+
Ƭ **PreTasksExecutionContext**: `Object`
44

55
#### Type declaration
66

docs/generated/devkit/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ It only uses language primitives and immutable objects
8787
- [NxPluginV2](../../devkit/documents/NxPluginV2)
8888
- [PackageManager](../../devkit/documents/PackageManager)
8989
- [PluginConfiguration](../../devkit/documents/PluginConfiguration)
90-
- [PostRun](../../devkit/documents/PostRun)
91-
- [PostRunContext](../../devkit/documents/PostRunContext)
92-
- [PreRun](../../devkit/documents/PreRun)
93-
- [PreRunContext](../../devkit/documents/PreRunContext)
90+
- [PostTasksExecution](../../devkit/documents/PostTasksExecution)
91+
- [PostTasksExecutionContext](../../devkit/documents/PostTasksExecutionContext)
92+
- [PreTasksExecution](../../devkit/documents/PreTasksExecution)
93+
- [PreTasksExecutionContext](../../devkit/documents/PreTasksExecutionContext)
9494
- [ProjectType](../../devkit/documents/ProjectType)
9595
- [ProjectsMetadata](../../devkit/documents/ProjectsMetadata)
9696
- [PromiseExecutor](../../devkit/documents/PromiseExecutor)

docs/generated/packages/devkit/documents/nx_devkit.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,10 @@ It only uses language primitives and immutable objects
8787
- [NxPluginV2](../../devkit/documents/NxPluginV2)
8888
- [PackageManager](../../devkit/documents/PackageManager)
8989
- [PluginConfiguration](../../devkit/documents/PluginConfiguration)
90-
- [PostRun](../../devkit/documents/PostRun)
91-
- [PostRunContext](../../devkit/documents/PostRunContext)
92-
- [PreRun](../../devkit/documents/PreRun)
93-
- [PreRunContext](../../devkit/documents/PreRunContext)
90+
- [PostTasksExecution](../../devkit/documents/PostTasksExecution)
91+
- [PostTasksExecutionContext](../../devkit/documents/PostTasksExecutionContext)
92+
- [PreTasksExecution](../../devkit/documents/PreTasksExecution)
93+
- [PreTasksExecutionContext](../../devkit/documents/PreTasksExecutionContext)
9494
- [ProjectType](../../devkit/documents/ProjectType)
9595
- [ProjectsMetadata](../../devkit/documents/ProjectsMetadata)
9696
- [PromiseExecutor](../../devkit/documents/PromiseExecutor)

packages/nx/src/command-line/release/publish.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ import {
2626
import { deepMergeJson } from './config/deep-merge-json';
2727
import { filterReleaseGroups } from './config/filter-release-groups';
2828
import { printConfigAndExit } from './utils/print-config';
29-
import { getPlugins } from '../../project-graph/plugins/get-plugins';
3029
import { workspaceRoot } from '../../utils/workspace-root';
31-
import { runPostRun, runPreRun } from '../../project-graph/plugins/run-hooks';
30+
import {
31+
runPostTasksExecution,
32+
runPreTasksExecution,
33+
} from '../../project-graph/plugins/tasks-execution-hooks';
3234

3335
export interface PublishProjectsResult {
3436
[projectName: string]: {
@@ -252,9 +254,7 @@ async function runPublishOnProjects(
252254
].join('\n')}\n`
253255
);
254256
}
255-
const plugins = await getPlugins();
256-
257-
await runPreRun(plugins, {
257+
await runPreTasksExecution({
258258
workspaceRoot,
259259
nxJsonConfiguration: nxJson,
260260
});
@@ -285,7 +285,7 @@ async function runPublishOnProjects(
285285
code: taskData.code,
286286
};
287287
}
288-
await runPostRun(plugins, {
288+
await runPostTasksExecution({
289289
taskResults: commandResults,
290290
workspaceRoot,
291291
nxJsonConfiguration: nxJson,

packages/nx/src/daemon/client/client.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ import {
7878
type HandleFlushSyncGeneratorChangesToDiskMessage,
7979
} from '../message-types/flush-sync-generator-changes-to-disk';
8080
import { DelayedSpinner } from '../../utils/delayed-spinner';
81+
import {
82+
PostTasksExecutionContext,
83+
PreTasksExecutionContext,
84+
} from '../../project-graph/plugins/public-api';
85+
import {
86+
HandlePostTasksExecutionMessage,
87+
HandlePreTasksExecutionMessage,
88+
POST_TASKS_EXECUTION,
89+
PRE_TASKS_EXECUTION,
90+
} from '../message-types/run-tasks-execution-hooks';
8191

8292
const DAEMON_ENV_SETTINGS = {
8393
NX_PROJECT_GLOB_CACHE: 'false',
@@ -435,6 +445,26 @@ export class DaemonClient {
435445
return this.sendToDaemonViaQueue(message);
436446
}
437447

448+
async runPreTasksExecution(
449+
context: PreTasksExecutionContext
450+
): Promise<NodeJS.ProcessEnv[]> {
451+
const message: HandlePreTasksExecutionMessage = {
452+
type: PRE_TASKS_EXECUTION,
453+
context,
454+
};
455+
return this.sendToDaemonViaQueue(message);
456+
}
457+
458+
async runPostTasksExecution(
459+
context: PostTasksExecutionContext
460+
): Promise<void> {
461+
const message: HandlePostTasksExecutionMessage = {
462+
type: POST_TASKS_EXECUTION,
463+
context,
464+
};
465+
return this.sendToDaemonViaQueue(message);
466+
}
467+
438468
async isServerAvailable(): Promise<boolean> {
439469
return new Promise((resolve) => {
440470
try {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import type {
2+
PostTasksExecutionContext,
3+
PreTasksExecutionContext,
4+
} from '../../project-graph/plugins';
5+
6+
export const PRE_TASKS_EXECUTION = 'PRE_TASKS_EXECUTION' as const;
7+
export const POST_TASKS_EXECUTION = 'POST_TASKS_EXECUTION' as const;
8+
9+
export type HandlePreTasksExecutionMessage = {
10+
type: typeof PRE_TASKS_EXECUTION;
11+
context: PreTasksExecutionContext;
12+
};
13+
export type HandlePostTasksExecutionMessage = {
14+
type: typeof POST_TASKS_EXECUTION;
15+
context: PostTasksExecutionContext;
16+
};
17+
18+
export function isHandlePreTasksExecutionMessage(
19+
message: unknown
20+
): message is HandlePreTasksExecutionMessage {
21+
return (
22+
typeof message === 'object' &&
23+
message !== null &&
24+
'type' in message &&
25+
message['type'] === PRE_TASKS_EXECUTION
26+
);
27+
}
28+
29+
export function isHandlePostTasksExecutionMessage(
30+
message: unknown
31+
): message is HandlePostTasksExecutionMessage {
32+
return (
33+
typeof message === 'object' &&
34+
message !== null &&
35+
'type' in message &&
36+
message['type'] === POST_TASKS_EXECUTION
37+
);
38+
}

0 commit comments

Comments
 (0)