Angular-cli: docs(ng-add): docs don't mention that the library will be installed in the project of the CWD

Created on 11 Aug 2019  路  6Comments  路  Source: angular/angular-cli

Reproduction

Steps to reproduce:

  1. ng new tmp and respond to prompts
  2. cd tmp/
  3. ng g app web-app and respond to prompts
  4. Edit workspace (angular.json) to change "defaultProject": "tmp" to "defaultProject": "web-app"

    1. ng add @angular/material and respond to prompts

Expected Behavior

The ng add docs state

Adds the npm package for a published library to your workspace, and configures your default app project to use that library,

The default app project is the value of defaultProject in angular.json.

Thus it is expected to add Angular Material to the default project, web-app.

Actual Behavior

Skipping installation: Package already installed
? Choose a prebuilt theme name, or "custom" for a custom theme: Custom
? Set up HammerJS for gesture recognition? Yes
? Set up browser animations for Angular Material? Yes
UPDATE package.json (1473 bytes)
UPDATE src/main.ts (391 bytes)
UPDATE src/app/app.module.ts (423 bytes)
UPDATE src/styles.scss (1418 bytes)
UPDATE src/index.html (484 bytes)

As you can see, it configured the initial app project in the workspace ("tmp") for Angular Material instead of the default project ("web-app").

Environment

Angular CLI: 8.2.1
Node: 10.15.3
OS: darwin x64
Angular: 8.2.1
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.802.1
@angular-devkit/build-angular      0.802.1
@angular-devkit/build-ng-packagr   0.802.1
@angular-devkit/build-optimizer    0.802.1
@angular-devkit/build-webpack      0.802.1
@angular-devkit/core               8.2.1
@angular-devkit/schematics         8.2.1
@angular/cdk                       8.1.2
@angular/material                  8.1.2
@ngtools/webpack                   8.2.1
@schematics/angular                8.2.1
@schematics/update                 0.802.1
ng-packagr                         5.4.3
rxjs                               6.4.0
typescript                         3.5.3
webpack                            4.38.0

Ran into this while reviewing PR https://github.com/angular/components/pull/16654.

angulacli low confusing docs

Most helpful comment

@Splaktar I investigated this and it looks like we are not doing anything magical for retrieving the project name.

We leverage the CLI's projectName provider which apparently determines the current project based on path and falls back to the defaultProjectName property if nothing could be found by path.

Problem is that the ng add command is executed in the workspace root which is also the project root of the tmp project --> so by path the current project is tmp. The issue would not appear if both projects (tmp and web-app) are under a projects/ folder.

So I think this is actually a CLI issue and it might be best to move that over? thoughts?

https://github.com/angular/angular-cli/blob/d0f2cc3b688848fb9e0f8d90a3c9b10344731725/packages/angular/cli/models/schematic-command.ts#L271-L294

All 6 comments

@Splaktar I investigated this and it looks like we are not doing anything magical for retrieving the project name.

We leverage the CLI's projectName provider which apparently determines the current project based on path and falls back to the defaultProjectName property if nothing could be found by path.

Problem is that the ng add command is executed in the workspace root which is also the project root of the tmp project --> so by path the current project is tmp. The issue would not appear if both projects (tmp and web-app) are under a projects/ folder.

So I think this is actually a CLI issue and it might be best to move that over? thoughts?

https://github.com/angular/angular-cli/blob/d0f2cc3b688848fb9e0f8d90a3c9b10344731725/packages/angular/cli/models/schematic-command.ts#L271-L294

Yeah, that code doesn't seem to match up with docs that I linked above.

@alan-agius4 is this a CLI docs issue (and should be transferred to angular/angular) or a CLI issue (and go to angular/angular-cli)?

@Splaktar, what @devversion explained is correct and we use the current working directory to determine the project. Hence what you are seeing is the expected behaviour.

The docs highlighted above needs to be fixed, these docs are in the CLI repo, so probably makes sense to transfer this to the CLI.

_I don鈥檛 seem to have permissions to transfer issues from the components repo._

@alan-agius4 thank you for the clarification!

@jbogarthyde the following, from the ng add docs needs to be changed

Adds the npm package for a published library to your workspace, and configures your default app project to use that library,

to something like:

Adds the npm package for a published library to your workspace, and configures the project related to your current directory, or your default project, to use that library,

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JanStureNielsen picture JanStureNielsen  路  3Comments

ericel picture ericel  路  3Comments

NCC1701M picture NCC1701M  路  3Comments

hartjo picture hartjo  路  3Comments

gotschmarcel picture gotschmarcel  路  3Comments