feat(nx-plugin): update executor generator to have context (#16982)

Co-authored-by: Craigory Coppola <craigorycoppola@gmail.com>
This commit is contained in:
Michal Jez 2024-06-04 17:49:50 -04:00 committed by GitHub
parent a1c26d51ab
commit 6d2e7cd2cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 89 additions and 25 deletions

View File

@ -0,0 +1,26 @@
# Type alias: AsyncIteratorExecutor\<T\>
Ƭ **AsyncIteratorExecutor**\<`T`\>: (`options`: `T`, `context`: [`ExecutorContext`](../../devkit/documents/ExecutorContext)) => `AsyncIterableIterator`\<\{ `success`: `boolean` }\>
An executor implementation that returns an async iterator
#### Type parameters
| Name | Type |
| :--- | :---- |
| `T` | `any` |
#### Type declaration
▸ (`options`, `context`): `AsyncIterableIterator`\<\{ `success`: `boolean` }\>
##### Parameters
| Name | Type |
| :-------- | :---------------------------------------------------------- |
| `options` | `T` |
| `context` | [`ExecutorContext`](../../devkit/documents/ExecutorContext) |
##### Returns
`AsyncIterableIterator`\<\{ `success`: `boolean` }\>

View File

@ -1,6 +1,6 @@
# Type alias: Executor\<T\> # Type alias: Executor\<T\>
Ƭ **Executor**\<`T`\>: (`options`: `T`, `context`: [`ExecutorContext`](../../devkit/documents/ExecutorContext)) => `Promise`\<\{ `success`: `boolean` }\> \| `AsyncIterableIterator`\<\{ `success`: `boolean` }\> Ƭ **Executor**\<`T`\>: [`PromiseExecutor`](../../devkit/documents/PromiseExecutor)\<`T`\> \| [`AsyncIteratorExecutor`](../../devkit/documents/AsyncIteratorExecutor)\<`T`\>
Implementation of a target of a project Implementation of a target of a project
@ -9,18 +9,3 @@ Implementation of a target of a project
| Name | Type | | Name | Type |
| :--- | :---- | | :--- | :---- |
| `T` | `any` | | `T` | `any` |
#### Type declaration
▸ (`options`, `context`): `Promise`\<\{ `success`: `boolean` }\> \| `AsyncIterableIterator`\<\{ `success`: `boolean` }\>
##### Parameters
| Name | Type |
| :-------- | :---------------------------------------------------------- |
| `options` | `T` |
| `context` | [`ExecutorContext`](../../devkit/documents/ExecutorContext) |
##### Returns
`Promise`\<\{ `success`: `boolean` }\> \| `AsyncIterableIterator`\<\{ `success`: `boolean` }\>

View File

@ -0,0 +1,26 @@
# Type alias: PromiseExecutor\<T\>
Ƭ **PromiseExecutor**\<`T`\>: (`options`: `T`, `context`: [`ExecutorContext`](../../devkit/documents/ExecutorContext)) => `Promise`\<\{ `success`: `boolean` }\>
An executor implementation that returns a promise
#### Type parameters
| Name | Type |
| :--- | :---- |
| `T` | `any` |
#### Type declaration
▸ (`options`, `context`): `Promise`\<\{ `success`: `boolean` }\>
##### Parameters
| Name | Type |
| :-------- | :---------------------------------------------------------- |
| `options` | `T` |
| `context` | [`ExecutorContext`](../../devkit/documents/ExecutorContext) |
##### Returns
`Promise`\<\{ `success`: `boolean` }\>

View File

@ -65,6 +65,7 @@ It only uses language primitives and immutable objects
### Type Aliases ### Type Aliases
- [AsyncIteratorExecutor](../../devkit/documents/AsyncIteratorExecutor)
- [CreateDependencies](../../devkit/documents/CreateDependencies) - [CreateDependencies](../../devkit/documents/CreateDependencies)
- [CreateMetadata](../../devkit/documents/CreateMetadata) - [CreateMetadata](../../devkit/documents/CreateMetadata)
- [CreateMetadataContext](../../devkit/documents/CreateMetadataContext) - [CreateMetadataContext](../../devkit/documents/CreateMetadataContext)
@ -91,6 +92,7 @@ It only uses language primitives and immutable objects
- [ProjectTargetConfigurator](../../devkit/documents/ProjectTargetConfigurator) - [ProjectTargetConfigurator](../../devkit/documents/ProjectTargetConfigurator)
- [ProjectType](../../devkit/documents/ProjectType) - [ProjectType](../../devkit/documents/ProjectType)
- [ProjectsMetadata](../../devkit/documents/ProjectsMetadata) - [ProjectsMetadata](../../devkit/documents/ProjectsMetadata)
- [PromiseExecutor](../../devkit/documents/PromiseExecutor)
- [RawProjectGraphDependency](../../devkit/documents/RawProjectGraphDependency) - [RawProjectGraphDependency](../../devkit/documents/RawProjectGraphDependency)
- [StaticDependency](../../devkit/documents/StaticDependency) - [StaticDependency](../../devkit/documents/StaticDependency)
- [StringChange](../../devkit/documents/StringChange) - [StringChange](../../devkit/documents/StringChange)

View File

@ -65,6 +65,7 @@ It only uses language primitives and immutable objects
### Type Aliases ### Type Aliases
- [AsyncIteratorExecutor](../../devkit/documents/AsyncIteratorExecutor)
- [CreateDependencies](../../devkit/documents/CreateDependencies) - [CreateDependencies](../../devkit/documents/CreateDependencies)
- [CreateMetadata](../../devkit/documents/CreateMetadata) - [CreateMetadata](../../devkit/documents/CreateMetadata)
- [CreateMetadataContext](../../devkit/documents/CreateMetadataContext) - [CreateMetadataContext](../../devkit/documents/CreateMetadataContext)
@ -91,6 +92,7 @@ It only uses language primitives and immutable objects
- [ProjectTargetConfigurator](../../devkit/documents/ProjectTargetConfigurator) - [ProjectTargetConfigurator](../../devkit/documents/ProjectTargetConfigurator)
- [ProjectType](../../devkit/documents/ProjectType) - [ProjectType](../../devkit/documents/ProjectType)
- [ProjectsMetadata](../../devkit/documents/ProjectsMetadata) - [ProjectsMetadata](../../devkit/documents/ProjectsMetadata)
- [PromiseExecutor](../../devkit/documents/PromiseExecutor)
- [RawProjectGraphDependency](../../devkit/documents/RawProjectGraphDependency) - [RawProjectGraphDependency](../../devkit/documents/RawProjectGraphDependency)
- [StaticDependency](../../devkit/documents/StaticDependency) - [StaticDependency](../../devkit/documents/StaticDependency)
- [StringChange](../../devkit/documents/StringChange) - [StringChange](../../devkit/documents/StringChange)

View File

@ -106,17 +106,31 @@ export interface ExecutorConfig {
} }
/** /**
* Implementation of a target of a project * An executor implementation that returns a promise
*/ */
export type Executor<T = any> = ( export type PromiseExecutor<T = any> = (
/** /**
* Options that users configure or pass via the command line * Options that users configure or pass via the command line
*/ */
options: T, options: T,
context: ExecutorContext context: ExecutorContext
) => ) => Promise<{ success: boolean }>;
| Promise<{ success: boolean }>
| AsyncIterableIterator<{ success: boolean }>; /**
* An executor implementation that returns an async iterator
*/
export type AsyncIteratorExecutor<T = any> = (
/**
* Options that users configure or pass via the command line
*/
options: T,
context: ExecutorContext
) => AsyncIterableIterator<{ success: boolean }>;
/**
* Implementation of a target of a project
*/
export type Executor<T = any> = PromiseExecutor<T> | AsyncIteratorExecutor<T>;
export interface HasherContext { export interface HasherContext {
hasher: TaskHasher; hasher: TaskHasher;

View File

@ -27,6 +27,8 @@ export type {
export type { export type {
Generator, Generator,
GeneratorCallback, GeneratorCallback,
PromiseExecutor,
AsyncIteratorExecutor,
Executor, Executor,
ExecutorContext, ExecutorContext,
TaskGraphExecutor, TaskGraphExecutor,

View File

@ -1,11 +1,18 @@
import { ExecutorContext } from '@nx/devkit';
import { <%= className %>ExecutorSchema } from './schema'; import { <%= className %>ExecutorSchema } from './schema';
import executor from './executor'; import executor from './executor';
const options: <%= className %>ExecutorSchema = {}; const options: <%= className %>ExecutorSchema = {};
const context: ExecutorContext = {
root: '',
cwd: process.cwd(),
isVerbose: false,
};
describe('<%= className %> Executor', () => { describe('<%= className %> Executor', () => {
it('can run', async () => { it('can run', async () => {
const output = await executor(options); const output = await executor(options, context);
expect(output.success).toBe(true); expect(output.success).toBe(true);
}); });
}); });

View File

@ -1,11 +1,11 @@
import { PromiseExecutor } from "@nx/devkit";
import { <%= className %>ExecutorSchema } from './schema'; import { <%= className %>ExecutorSchema } from './schema';
export default async function runExecutor( const runExecutor: PromiseExecutor<<%= className %>ExecutorSchema> = async (options) => {
options: <%= className %>ExecutorSchema,
) {
console.log('Executor ran for <%= className %>', options); console.log('Executor ran for <%= className %>', options);
return { return {
success: true success: true
}; };
} }
export default runExecutor;