createNodesV2— adds project nodes (and their targets) to the graph.createDependencies— adds dependency edges between projects.
Set
NX_DAEMON=false during plugin development. The Nx daemon caches plugin code, so changes won’t be reflected until the daemon restarts.Registering a plugin
Add the plugin to theplugins array in nx.json:
Adding nodes with createNodesV2
createNodesV2 is a tuple of [globPattern, asyncFunction]. Nx finds all files matching the glob and calls the function with the full list. Use createNodesFromFiles to process each file individually:
Adding inferred targets to existing projects
A common pattern is to check for the presence of a tool’s config file and add a target to the project if found:How project configurations are merged
When multiple plugins identify the same project (same root directory), Nx merges their configurations:Nx’s built-in plugins (which read
project.json and package.json) run after plugins listed in nx.json. A project.json file will overwrite any conflicting configuration added by your plugin.Passing options to a plugin
Options defined innx.json are forwarded as the options parameter:
Adding dependencies with createDependencies
createDependencies lets a plugin add dependency edges to the project graph. Export it from the same index.ts as createNodesV2:
CreateDependenciesContext provides:
projectsConfigurations— every project in the workspace.externalNodes— external npm packages in the graph.fileMap— all files in the workspace, indexed by project.filesToProcess— only files changed since the last invocation (use this for incremental analysis).nxJsonConfiguration— the contents ofnx.json.
Dependency types
- Static
- Dynamic
- Implicit
A static dependency is associated with a specific source file. Nx tracks which file defines the dependency and skips re-analysis when the file hasn’t changed.
Full createDependencies example
This plugin reads each project’spackage.json and creates static dependencies for any dependencies entries that resolve to other Nx projects:
Visualizing the project graph
After modifying your plugin, inspect the resulting graph:Testing project graph plugins
The fastest way to verify the computed graph isnx show project:
