Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): add pre and post run apis #29636

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/generated/devkit/NxPlugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

Ƭ **NxPlugin**: [`NxPluginV2`](../../devkit/documents/NxPluginV2)

A plugin for Nx
A plugin which enhances the behavior of Nx
4 changes: 3 additions & 1 deletion docs/generated/devkit/NxPluginV2.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Ƭ **NxPluginV2**\<`TOptions`\>: `Object`

A plugin for Nx which creates nodes and dependencies for the [ProjectGraph](../../devkit/documents/ProjectGraph)
A plugin which enhances the behavior of Nx

#### Type parameters

Expand All @@ -19,3 +19,5 @@ A plugin for Nx which creates nodes and dependencies for the [ProjectGraph](../.
| `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. |
| `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. |
| `name` | `string` | - |
| `postRun?` | [`PostRun`](../../devkit/documents/PostRun)\<`TOptions`\> | Provides a function to run after the Nx runs tasks |
| `preRun?` | [`PreRun`](../../devkit/documents/PreRun)\<`TOptions`\> | Provides a function to run before the Nx runs tasks |
24 changes: 24 additions & 0 deletions docs/generated/devkit/PostRun.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Type alias: PostRun\<TOptions\>

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

#### Type parameters

| Name | Type |
| :--------- | :-------- |
| `TOptions` | `unknown` |

#### Type declaration

▸ (`options`, `context`): `void` \| `Promise`\<`void`\>

##### Parameters

| Name | Type |
| :-------- | :-------------------------------------------------------- |
| `options` | `TOptions` \| `undefined` |
| `context` | [`PostRunContext`](../../devkit/documents/PostRunContext) |

##### Returns

`void` \| `Promise`\<`void`\>
11 changes: 11 additions & 0 deletions docs/generated/devkit/PostRunContext.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Type alias: PostRunContext

Ƭ **PostRunContext**: `Object`

#### Type declaration

| Name | Type |
| :-------------------- | :------------------------------------------------------------------ |
| `nxJsonConfiguration` | [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration) |
| `taskResults` | [`TaskResults`](../../devkit/documents/TaskResults) |
| `workspaceRoot` | `string` |
24 changes: 24 additions & 0 deletions docs/generated/devkit/PreRun.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Type alias: PreRun\<TOptions\>

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

#### Type parameters

| Name | Type |
| :--------- | :-------- |
| `TOptions` | `unknown` |

#### Type declaration

▸ (`options`, `context`): `void` \| `Promise`\<`void`\>

##### Parameters

| Name | Type |
| :-------- | :------------------------------------------------------ |
| `options` | `TOptions` \| `undefined` |
| `context` | [`PreRunContext`](../../devkit/documents/PreRunContext) |

##### Returns

`void` \| `Promise`\<`void`\>
10 changes: 10 additions & 0 deletions docs/generated/devkit/PreRunContext.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Type alias: PreRunContext

Ƭ **PreRunContext**: `Object`

#### Type declaration

| Name | Type |
| :-------------------- | :------------------------------------------------------------------ |
| `nxJsonConfiguration` | [`NxJsonConfiguration`](../../devkit/documents/NxJsonConfiguration) |
| `workspaceRoot` | `string` |
6 changes: 6 additions & 0 deletions docs/generated/devkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ It only uses language primitives and immutable objects
- [Task](../../devkit/documents/Task)
- [TaskGraph](../../devkit/documents/TaskGraph)
- [TaskHasher](../../devkit/documents/TaskHasher)
- [TaskResult](../../devkit/documents/TaskResult)
- [Tree](../../devkit/documents/Tree)
- [Workspace](../../devkit/documents/Workspace)

Expand Down Expand Up @@ -86,6 +87,10 @@ It only uses language primitives and immutable objects
- [NxPluginV2](../../devkit/documents/NxPluginV2)
- [PackageManager](../../devkit/documents/PackageManager)
- [PluginConfiguration](../../devkit/documents/PluginConfiguration)
- [PostRun](../../devkit/documents/PostRun)
- [PostRunContext](../../devkit/documents/PostRunContext)
- [PreRun](../../devkit/documents/PreRun)
- [PreRunContext](../../devkit/documents/PreRunContext)
- [ProjectType](../../devkit/documents/ProjectType)
- [ProjectsMetadata](../../devkit/documents/ProjectsMetadata)
- [PromiseExecutor](../../devkit/documents/PromiseExecutor)
Expand All @@ -94,6 +99,7 @@ It only uses language primitives and immutable objects
- [StringChange](../../devkit/documents/StringChange)
- [TargetDefaults](../../devkit/documents/TargetDefaults)
- [TaskGraphExecutor](../../devkit/documents/TaskGraphExecutor)
- [TaskResults](../../devkit/documents/TaskResults)
- [ToJSOptions](../../devkit/documents/ToJSOptions)
- [WorkspaceJsonConfiguration](../../devkit/documents/WorkspaceJsonConfiguration)

Expand Down
36 changes: 36 additions & 0 deletions docs/generated/devkit/TaskResult.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Interface: TaskResult

The result of a completed [Task](../../devkit/documents/Task)

## Table of contents

### Properties

- [code](../../devkit/documents/TaskResult#code): number
- [status](../../devkit/documents/TaskResult#status): TaskStatus
- [task](../../devkit/documents/TaskResult#task): Task
- [terminalOutput](../../devkit/documents/TaskResult#terminaloutput): string

## Properties

### code

• **code**: `number`

---

### status

• **status**: `TaskStatus`

---

### task

• **task**: [`Task`](../../devkit/documents/Task)

---

### terminalOutput

• `Optional` **terminalOutput**: `string`
5 changes: 5 additions & 0 deletions docs/generated/devkit/TaskResults.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Type alias: TaskResults

Ƭ **TaskResults**: `Record`\<`string`, [`TaskResult`](../../devkit/documents/TaskResult)\>

A map of [TaskResult](../../devkit/documents/TaskResult) keyed by the ID of the completed [Task](../../devkit/documents/Task)s
6 changes: 6 additions & 0 deletions docs/generated/packages/devkit/documents/nx_devkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ It only uses language primitives and immutable objects
- [Task](../../devkit/documents/Task)
- [TaskGraph](../../devkit/documents/TaskGraph)
- [TaskHasher](../../devkit/documents/TaskHasher)
- [TaskResult](../../devkit/documents/TaskResult)
- [Tree](../../devkit/documents/Tree)
- [Workspace](../../devkit/documents/Workspace)

Expand Down Expand Up @@ -86,6 +87,10 @@ It only uses language primitives and immutable objects
- [NxPluginV2](../../devkit/documents/NxPluginV2)
- [PackageManager](../../devkit/documents/PackageManager)
- [PluginConfiguration](../../devkit/documents/PluginConfiguration)
- [PostRun](../../devkit/documents/PostRun)
- [PostRunContext](../../devkit/documents/PostRunContext)
- [PreRun](../../devkit/documents/PreRun)
- [PreRunContext](../../devkit/documents/PreRunContext)
- [ProjectType](../../devkit/documents/ProjectType)
- [ProjectsMetadata](../../devkit/documents/ProjectsMetadata)
- [PromiseExecutor](../../devkit/documents/PromiseExecutor)
Expand All @@ -94,6 +99,7 @@ It only uses language primitives and immutable objects
- [StringChange](../../devkit/documents/StringChange)
- [TargetDefaults](../../devkit/documents/TargetDefaults)
- [TaskGraphExecutor](../../devkit/documents/TaskGraphExecutor)
- [TaskResults](../../devkit/documents/TaskResults)
- [ToJSOptions](../../devkit/documents/ToJSOptions)
- [WorkspaceJsonConfiguration](../../devkit/documents/WorkspaceJsonConfiguration)

Expand Down
14 changes: 14 additions & 0 deletions packages/nx/src/command-line/release/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ import {
import { deepMergeJson } from './config/deep-merge-json';
import { filterReleaseGroups } from './config/filter-release-groups';
import { printConfigAndExit } from './utils/print-config';
import { getPlugins } from '../../project-graph/plugins/get-plugins';
import { workspaceRoot } from '../../utils/workspace-root';
import { runPostRun, runPreRun } from '../../project-graph/plugins/run-hooks';

export interface PublishProjectsResult {
[projectName: string]: {
Expand Down Expand Up @@ -249,6 +252,12 @@ async function runPublishOnProjects(
].join('\n')}\n`
);
}
const plugins = await getPlugins();

await runPreRun(plugins, {
workspaceRoot,
nxJsonConfiguration: nxJson,
});

/**
* Run the relevant nx-release-publish executor on each of the selected projects.
Expand Down Expand Up @@ -276,6 +285,11 @@ async function runPublishOnProjects(
code: taskData.code,
};
}
await runPostRun(plugins, {
taskResults: commandResults,
workspaceRoot,
nxJsonConfiguration: nxJson,
});

return publishProjectsResult;
}
11 changes: 10 additions & 1 deletion packages/nx/src/devkit-exports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,26 @@ export type {
CreateMetadata,
CreateMetadataContext,
ProjectsMetadata,
PreRun,
PreRunContext,
PostRun,
PostRunContext,
} from './project-graph/plugins';

export { AggregateCreateNodesError } from './project-graph/error-types';

export { createNodesFromFiles } from './project-graph/plugins';

/**
* @category Workspace
* @category Tasks
*/
export type { Task, TaskGraph } from './config/task-graph';

/**
* @category Tasks
*/
export type { TaskResult, TaskResults } from './tasks-runner/life-cycle';

/**
* @category Workspace
*/
Expand Down
18 changes: 1 addition & 17 deletions packages/nx/src/project-graph/plugins/get-plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
cleanupPluginTSTranspiler,
pluginTranspilerIsRegistered,
} from './transpiler';
import { isIsolationEnabled } from './isolation/enabled';

/**
* Stuff for specified NX Plugins.
Expand Down Expand Up @@ -97,23 +98,6 @@ export function cleanupPlugins() {
* Stuff for generic loading
*/

function isIsolationEnabled() {
// Explicitly enabled, regardless of further conditions
if (process.env.NX_ISOLATE_PLUGINS === 'true') {
return true;
}
if (
// Explicitly disabled
process.env.NX_ISOLATE_PLUGINS === 'false' ||
// Isolation is disabled on WASM builds currently.
IS_WASM
) {
return false;
}
// Default value
return true;
}

const loadingMethod = isIsolationEnabled()
? loadNxPluginInIsolation
: loadNxPlugin;
Expand Down
18 changes: 18 additions & 0 deletions packages/nx/src/project-graph/plugins/isolation/enabled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IS_WASM } from 'nx/src/native';

export function isIsolationEnabled() {
// Explicitly enabled, regardless of further conditions
if (process.env.NX_ISOLATE_PLUGINS === 'true') {
return true;
}
if (
// Explicitly disabled
process.env.NX_ISOLATE_PLUGINS === 'false' ||
// Isolation is disabled on WASM builds currently.
IS_WASM
) {
return false;
}
// Default value
return true;
}
Loading
Loading