Generator Nx21 + Workspace + Project References #31266
-
Hello everyone, I am currently migrating one of our legacy NX Monorepos (v16) to a new clean NX 21 Monorepo setup, with the latest workspace and references configuration. While experimenting with the provided generators, I’ve noticed that each time I generate a publishable library, it automatically adds the following entry to my
My question is: Does @nx/devkit provide any utilities or best practices for managing this new workspace resolution format in yarn.lock when generating sharable libraries from custom generators? Alternatively, does anyone have an example of how to handle this in the recommended NX way? Any guidance would be greatly appreciated! 🙏 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
After reviewing the source code of some of the provided generators, I was able to identify the function that handles this and gain a better understanding of how it works: It seems that we don’t actually need an extra function for this. In our custom generator, we can simply add the library to the package.json's
It looks like I’ve answered my own question 😅 I won’t delete it, though, as it might be helpful to others who find themselves in a similar situation. |
Beta Was this translation helpful? Give feedback.
After reviewing the source code of some of the provided generators, I was able to identify the function that handles this and gain a better understanding of how it works:
https://github.com/nrwl/nx/blob/master/packages/js/src/generators/library/library.ts#L116C3-L116C70
It seems that we don’t actually need an extra function for this. In our custom generator, we can simply add the library to the package.json's
workspaces
property via updateJson (provided by @nx/devkit). Finally, at the end of the generator, we can execute the following to create the correct reference in the .lock file:It looks like I’ve answered my own question 😅 I won’t …