nx/docs/generated/devkit/NxPluginV2.md
Jason Jean 4a9508b368
feat(core): add pre and post run apis (#29636)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

There is no specific API for running things before and after tasks run.

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

This PR adds an API akin to npm's `preinstall` and `postinstall`.

Plugins can now specify `preTasksExecution` and `postTasksExecution`
functions which run before and after Nx runs tasks respectively.

```ts
import type { PreTasksExecutionContext, PostTasksExecutionContext } from '@nx/devkit';

interface PluginOptions {
  field: any;
}

export function preTasksExecution(options: PluginOptions, context: PreTasksExecutionContext) {
  console.log('prerun')
}

export function postTasksExecution(options: PluginOptions, context: PostTasksExecutionContext) {
  console.log('postrun', context.taskResults)
}
```

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #
2025-01-27 12:09:43 -05:00

3.7 KiB

Type alias: NxPluginV2<TOptions>

Ƭ NxPluginV2<TOptions>: Object

A plugin which enhances the behavior of Nx

Type parameters

Name Type
TOptions unknown

Type declaration

Name Type Description
createDependencies? CreateDependencies<TOptions> Provides a function to analyze files to create dependencies for the ProjectGraph
createMetadata? CreateMetadata<TOptions> Provides a function to create metadata for the ProjectGraph
createNodes? 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<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 -
postTasksExecution? PostTasksExecution<TOptions> Provides a function to run after the Nx runs tasks
preTasksExecution? PreTasksExecution<TOptions> Provides a function to run before the Nx runs tasks