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
Docs on package.json vs project/foo/package.json (and their lockfiles) #43058
Comments
I had these same questions, and ran into the same SO post. Given the advice on SO and some apparently related issues with library dependencies in application builds, this is my take on the docs section on peer dependencies. Dependencies are touched on but their interpretation can vary based on perspective.
It's assumed this is referring to
I assume, but it's not immediately obvious that this is referring to the peer dependencies installed to the workspace of the consuming application which would enforce versions. I think that's because it's not clear whether or not those dependencies were bundled by the library build.
This is confusing, because the documentation states and the CLI places these in
I am experiencing problems, but I'm not sure if this is the one I'm referring to. Maybe it would be good clarify, because I already expected the library's peer dependencies to be pulled from the application's node_modules. Is there an edge case or different library setup that may or may not apply to me? [Edit] The first two sentences of Resolving UMD Module Identifiers will probably help a lot of people. However, I haven't seen it mentioned anywhere else in the libraries or ng-packagr docs. |
@AndrewKushnir what's the process to get this triaged? It would be great to see it added to the backlog. |
Description
The Creating Library guide is totally absent any information on package.json and dependencies.
Currently the library creation guide advocates creating a workspace for every library.
ng new my-workspace --create-application=false cd my-workspace ng generate library my-lib
This will give you two package.json files, and also two lockfiles
my-workspace/package.json
my-workspace/projects/my-lib/package.json
There is no information differentiating these two.
On StackOverflow there is advice to put in dependencies that people have to have to use your library in the
my-workspace/projects/my-lib/package.json
under the projects directory, and to put the dependencies that you need to develop the library in./package.json
, but this doesn't explicitly address how you can ever have one and not the other in tested functionality.More succiently, if a user needs a library to run the library in
my-workspace/projects/my-lib/package.json
won't the developer also need it inmy-workspace/package.json
so it can be available tong build
, andng test
? Do we have to manually keep these in sync? Is there ever a reason to have a dependency inmy-workspace/projects/my-lib/package.json
but not inmy-workspace/package.json
? Isnpm install --save
not useful for Angular libraries (it only adds to thepackage.json
in the toot of the repo and leaves the files in packages/ out of sync).My experience with this workspace structure leads me to believe a greater discussion should be had about whether or not this is even good idea. It's very confusing to have reputable tools like
@semantic-release
(which seem even semi-official) not even support multiple libraries in one workspace when the cli and docs make this sound like a routine practice. It also feels like the cli should be updated to make single-library-per-repo the default, and to restructure this such that there is only ever one package.json and one package in the default configuration.What is the affected URL?
https://angular.io/guide/creating-libraries
The text was updated successfully, but these errors were encountered: