docs(core): fix references to createNodes v1 (#29400)

This commit is contained in:
Isaac Mann 2024-12-18 08:15:04 -05:00 committed by GitHub
parent 5f77d65554
commit 6051e6e208
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,7 +6,7 @@ One of the best features of Nx the ability to construct the project graph automa
Project graph plugins are able to add new nodes or dependencies to the project graph. This allows you to extend the project graph with new projects and dependencies. The API is defined by two exported members, which are described below:
- [createNodes](#adding-new-nodes-to-the-project-graph): This tuple allows a plugin to tell Nx information about projects that are identified by a given file.
- [createNodesV2](#adding-new-nodes-to-the-project-graph): This tuple allows a plugin to tell Nx information about projects that are identified by a given file.
- [createDependencies](#adding-new-dependencies-to-the-project-graph): This function allows a plugin to tell Nx about dependencies between projects.
## Adding Plugins to Workspace
@ -295,7 +295,7 @@ Breaking down this example, we can see that it follows this flow:
## Accepting Plugin Options
When looking at `createNodes`, and `createDependencies` you may notice a parameter called `options`. This is the first parameter for `createDependencies` or the second parameter for `createDependencies`.
When looking at `createNodesV2`, and `createDependencies` you may notice a parameter called `options`. This is the first parameter for `createDependencies` or the second parameter for `createDependencies`.
By default, its typed as unknown. This is because it belongs to the plugin author. The `CreateNodes`, `CreateDependencies`, and `NxPluginV2` types all accept a generic parameter that allows you to specify the type of the options.
@ -319,20 +319,29 @@ As an example, the below `nx.json` file specifies a plugin called `my-plugin` an
`my-plugin` could then consume these options to add a tag to each project it detected:
```typescript
import { createNodesFromFiles } from '@nx/devkit';
import { dirname } from 'path';
type MyPluginOptions = { tagName: string };
export const createNodes: CreateNodes<MyPluginOptions> = [
'**/project.json',
(fileName, opts, ctx) => {
const root = dirname(fileName);
export const createNodesV2: CreateNodesV2<MyPluginOptions> = [
'**/tsconfig.json',
async (configFiles, options, context) => {
return await createNodesFromFiles(
(configFile, options, context) =>
const root = dirname(configFile);
return {
projects: {
[root]: {
tags: opts.tagName ? [opts.tagName] : [],
tags: options.tagName ? [options.tagName] : [],
},
},
};
configFiles,
options,
context
);
},
];
```