-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent Behavior of @schematics/angular
With/Without @nx/angular
#22625
Comments
Inconsistent Behavior of @schematics/angular With/Without @nx/angular #22625 nrwl/nx#22625
Thanks for reporting this! Currently, the Regarding the "unexpected" dependencies added by the generators, some of them are actually required by the
Thanks for bringing it up and for being explicit about the things you think are wrong. There are some things that are immediately actionable, and we'll work on them. Also, note that you can provide the |
Thank you very much for the detailed response! I understand that currently the precense of Besides, I think this is more likely a bug instead of some inconsistent behavior for the following reasons:
Thanks for your clearification on the dependencies. However I'm still confused about several points:
Overall, my point is that a package should not be added as a dependency of the user workspace, if it is not directly referenced/used from the user workspace. I guess the reason Nx adds them as user dependencies is to make sure the same instance of the dependency is used by multiple plugins, but I believe peer dependencies can solve that too. I would really appreciate a clearification on this. The extraneous dependencies have been especially annoying to me, and it disallows me to remove unused dependencies since I don't know which are implicitly used by Nx. |
Revise: They are already listed as peer dependencies. I'm confused why it is still required to add them as user workspace dependencies even though they will be installed by npm automatically. However, it is not the most important point. The point is that In summary, I suspect that there are two bugs:
I'll be happy to help if they are confirmed as bugs. Let me know if I can help with anything. |
Thanks again for the feedback! This is valuable to us. Please see below.
There are three reasons our generators install dependencies:
Long story short, while the implementation is currently not the best and we'll look into change it when we have some time, the end result will still be the same: you need to install Angular is a bit special because there are no I agree the current implementation is weird/wrong because, as you stated, if you only have the This is why when creating a new workspace or using our automated conversion ( I agree with your suggestion that this should be clearly stated in the docs. We'll review the docs and amend as needed.
Yeah, there was an issue with the |
Thanks for your response! It is very helpful!
I do agree that generators should add dependencies, and also agree with your first two points. For the third point:
I totally understand that you have experienced such issue before, and figured that the solution is to install the peer dependencies at the root. However, I believe this issue no longer exists with the current peer dependency resolution strategy. If
My proposal is that Nx generators should add ONLY direct dependencies that will be directly referenced/used from the user workspace, and should NOT add dependencies of dependencies to the user workspace, such as
I am confused. Does it mean the current support for Angular schematics without Before we discuss the schematics support in Nx, I need to first point out that using packages implicitly (require the presence of a package) seems to be a bad design to me. If a package is used, the package name should be somehow referenced (unless it is an optional peer dependency that doesn't affect the package's behavior unless explicitly configured). In order to distinguish and remove extraneous dependencies, developers usually perform a global search of the package name, and can tell a package being extraneous if no references to the package is found. However, as Nx is implicitly using a lot of packages without listing their names, developers can no longer tell which package is extraneous and which is not, since they'll never know what is needed by Nx and what is not, without looking into the source of each Nx plugin. This also applies to how Nx currently automatically discover generators/plugins from Back to the topic of Angular schematics support in Nx. First of all, I think the support for Angular schematics should be an inseparable part of Nx's core functionalities. Angular schematics are actually designed to be framework-agnostic at first, which is why they use If you really decide to separate the support of schematics, I have another proposal: Extract the schematics support from
I have migrated to
By looking at its name, I expect
|
Ideally, yes. In practice, a lot of folks end up running I understand your reasoning, and it's not wrong. I'm not saying otherwise, but one thing to keep in mind is that our generators (like any code-generation tool out there) are opinionated. We're trying to make sure what we generate works in most scenarios. That's what we believe is the best to cover a broader range of setups. There's always going to be things we generate in a way that folks might agree or not. The beauty of Nx is that it's highly extensible, so you can create your own generators that better fit your conventions or preferences. As mentioned before, the escape hatch for this particular issue is to run the generators with
You uncovered another issue, which I addressed on #22777. We released the change in Nx 18.3.0. Could you please try again with the latest version and let me know if it works? 🙏🏻
That's correct. The core of Nx should only know how to run generators and executors written with the Nx DevKit. Running other tool artifacts (e.g., Angular DevKit schematics and builders) should be enabled by a plugin. The core of Nx is meant to be technology agnostic, and support for specific technologies (e.g., Angular DevKit) should be enabled by plugins. This is explained in our docs. We can definitely be more explicit about it in the docs (I think I mentioned it already), but there's nothing in the docs explicitly stating that "Nx Core" supports Angular schematics. There's also nothing explicitly stating that a specific plugin is needed for it. So, we'll make sure to improve that.
I can see your point about the explicitness of registering a plugin, though I think it's a gray area. We've internally evaluated this in the past and decided on simplicity and less configuration. It's very common in plugin architecture to enable things by adding/installing plugins. You don't necessarily need to register them. For example, you don't register plugins in VSCode. You just install them, and they augment the VSCode core functionality. A separate story is to want to control and be able to enable/disable functionalities. For example, you can enable/disable VSCode plugin functionalities through the options they expose to do so. Nx plugins don't currently offer a way to do so because we don't think it is needed for the most part:
Having to explicitly enable them in order to use them seems like an extra burden and configuration. Installing the plugin means you want to use its functionality. How much of its functionality you use is up to you. Some things are effectively enabled/disabled through configuration (e.g., project graph plugins that infer tasks from tool configurations). That's the case with features that change Nx core behavior. You have the option to enable/disable them.
We have to disagree here. The Angular DevKit (what powers the schematics) is not the same as the Nx DevKit. Nx is not tied to Angular in any sense (it used to be that way when it started as an Angular extension, but that hasn't been the case for a long time now). The fact you can use the Angular DevKit to write schematics for any tool doesn't mean that Nx should support it out of the box. There are other technology-agnostic generation tools out there, and that doesn't mean the core of Nx must support them. Looking at https://nx.dev/getting-started/why-nx#how-does-nx-work, the
The final package where we plan to move the Angular DevKit support is TBD. I mentioned As explained before, we have different opinions about needing to explicitly register plugins to use generators or other capabilities. We don't plan to do that any time soon. |
I want to separate bugs that we need to address from feature requests that we need to discuss more. To that extent, I want to focus this issue on the wrong behavior of Could you please retry running the generators with I'd be happy to continue the rest of the discussion on a separate GH Discussion. Any and all feedback is welcome to try to improve the tool. Please, create a separate GH Discussion (or multiple if you feel like it) to discuss the rest of the features we've discussed here (or others) you'd like Nx to support. You can of course link back to this issue if you need to reference anything. |
Hey @leosvelperez I appreciate the the update! I'd like to keep this issue open until Angular schematics support are completely extracted, or this behavior is expliclty documented. |
I see why Nx installs the dev deps by default, as long as Speaking of explicitly listing plugins, I do agree that the current approach is pretty convenient, and I myself is not even sure what could be a better design, so no feature requests on that. However, I do think it could be a good idea to allow the developer to explicitly list all the plugins that they want to nx to discover generators from. I prefer to use the shorthands such as A proposal is to have an optional "generatorsFrom": "@schematics/angular" Finally, I would strongly recommend to have a separated package for schematics support, unless the previous I'll create dedicated issues for each of the feature requests above, but I'm not sure if the Nx team would like a public discussion for Angular schematics, and I think the Nx team should creates such a discussion. |
Thanks for confirming! I created a PR to update our documentation by explicitly mentioning in a few places that the Once again, thanks for all the feedback! As advised before, please feel free to create Feature Requests (GH Discussions) for any new feature or behavior you think Nx should support. You don't need to wait for the team to create a discussion on anything you think should be discussed. Try to keep each feature request focused on a single feature to improve the discussion around it. |
@leosvelperez Unsurprisingly, opening feature requests as GH Discussions won't receive any feedback, which is why I planned to create tickets instead. The following feature requests have been there for weeks. I don't know if the Nx team is even aware of their existences. |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
I am migrating a Angular CLI monorepo library collection project to NX. I decided to keep using
@schematics/angular
and thus removed@nx/angular
because it is too opinionated and introduces too many things that I do not need. The workspace works mostly good, except of when generating new libraries:When generating a new library (or application) with
nx g @schematics/angular:library
, theproject.json
configuration of all my other libraries are all unexpectedly updated, with all the inferred targets andtargetDefaults
options mandatorily added into theproject.json
files.The output of the command does not show updates on the
project.json
files:But they're indeed modified:
However, when trying to reproducing this issue within a new repository generated with Angular CLI and then migrated to Nx, everything worked as expected. I eventually figured out that it caused by the removal of the
@nx/angular
package. Once the@nx/angular
package is installed back, theproject.json
files stay intacted when generating new libraries/applications with@schematics/angular
.Expected Behavior
Nx does not have a direct dependency on
@nx/angular
, and also the documentation did not mention that@nx/angular
have to be installed to use@schematics/angular
. Therefore, I believe the behavior of@schematics/angular
should remain consistent with or without@nx/angular
, which is thatproject.json
files should not be mandatorily updated.One other thing that I am quite confused about is that why the Nx generators force the installation of so many dev dependencies that seems extraneous to me.
Examples:
@angular-devkit/{core,schematics}
and@nx/workspace
are added, but I don't see any usage of these dependencies.@nx/angular
, mandatorily installed dependencies includepostcss
,postcss-url
,autoprefixer
,@swc/{core,helpers}
,@swc-node/register
,@angular-devkit/{core,schematics}
, and even@angular/language-service
?? I can't find any direct or indirect usage of these dependencies, and was quite annoyed by their repetitive occurrence.If they're somehow used in the plugins, I expect to at least read about their importance in the plugin documentation. I would like to get a clearification on this too.
GitHub Repo
https://github.com/TheNightmareX/nx-angular-schematics-demo
Steps to Reproduce
npm install
npm run reproduce
projects/ng-cli-lib/project.json
, and you'll find it unexpectedly updatedNx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
OS: WSL2 - Ubuntu
The text was updated successfully, but these errors were encountered: