Replies: 2 comments 5 replies
-
I agree that an Nx project shouldn't be hard-linked to the existence of a For splitting the
So I personally don't think that's going to happen |
Beta Was this translation helpful? Give feedback.
4 replies
-
The second link is broken. Is it that one? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey hey,
I am opening this discussion because after exploring the code of Nx plugins, some reflections came to my mind about the design of the Project Crystal.
Current situation in a nutshell
Today, we can consider that if you want to modify the Project Graph, you can do it via Nx plugin by using:
createNodes
createDependencies
If we focus on
createNodes
, we can see that it serves two responsibilities:For example, we can see plugins that are:
@nx/jest/plugin
which only adds a targettest
if you have thejest.config.*
filenx/core/project-json
that will create an Nx Project if you have aproject.json
fileWe also know that the order of plugins matters because a config generated by one plugin can be overridden by another plugin.
A simplified example of the plugins execution today looks like:
But my explanation is wrong!
In fact, it is not possible for a plugin like
@nx/jest/plugin
to add thetest
target if it is not linked to an Nx Project. So the@nx/jest/plugin
is also responsible for Identifying projects!This is why many plugins are first testing if the path is related to a project by checking the existence of the
project.json
.Reflections
Why is the definition of an Nx Project still linked to a
project.json
file?My first reaction was to use the function
readProjectsConfigurationFromProjectGraph
instead of checking the existence of theproject.json
. Or to provide the list of projects in the context options of my plugin.In fact, maybe a previous plugin Identified Projects in a different way. Based on project structure for example.
But it cannot work because all plugins are run in parallel and then the results are merged in order. The execution is already done.
Why don't we split responsibilities?
For example, we could have a plugin
nx/core/project-json
that is only responsible for Identifying Project and another pluginnx/core/merge-project-json-targets
that is only responsible for adding targets.We could maybe also have three entry points in our plugin called in order:
createNodes
createDependencies
createTargets
But I don't think it's a breaking change and going back to the Nx Plugin v1 in a way :)
Why the plugin functions responsible of target generations are not exposed in the
@nx/devkit
?In that way, we could create a new plugin like
@org/jest
and just extend the@nx/devkit
What do you think?
Beta Was this translation helpful? Give feedback.
All reactions