Skip to content

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

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

Closed
Splaktar opened this issue Aug 10, 2019 · 6 comments · Fixed by #15377
Closed
Assignees
Labels
area: @angular/cli area: docs Related to the documentation freq1: low Only reported by a handful of users who observe it rarely severity1: confusing
Milestone

Comments

@Splaktar
Copy link
Contributor

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"
  5. 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 angular/components#16654.

@devversion devversion self-assigned this Aug 15, 2019
@devversion
Copy link
Member

devversion commented Aug 15, 2019

@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?

const getProjectName = () => {
if (this._workspace) {
const projectNames = getProjectsByPath(this._workspace, process.cwd(), this.workspace.root);
if (projectNames.length === 1) {
return projectNames[0];
} else {
if (projectNames.length > 1) {
this.logger.warn(tags.oneLine`
Two or more projects are using identical roots.
Unable to determine project using current working directory.
Using default workspace project instead.
`);
}
const defaultProjectName = this._workspace.extensions['defaultProject'];
if (typeof defaultProjectName === 'string' && defaultProjectName) {
return defaultProjectName;
}
}
}
return undefined;
};

@Splaktar
Copy link
Contributor Author

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)?

@alan-agius4
Copy link
Collaborator

alan-agius4 commented Aug 15, 2019

@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’t seem to have permissions to transfer issues from the components repo.

@devversion devversion transferred this issue from angular/components Aug 15, 2019
@ngbot ngbot bot modified the milestone: Backlog Aug 16, 2019
@alan-agius4 alan-agius4 added freq1: low Only reported by a handful of users who observe it rarely type: bug/fix and removed type: bug/fix labels Aug 16, 2019
@Splaktar
Copy link
Contributor Author

@alan-agius4 thank you for the clarification!

@Splaktar
Copy link
Contributor Author

@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,

@Splaktar Splaktar changed the title schematic(add): does not respect workspace's defaultProject docs(ng-add): docs don't mention that the library will be installed in the project of the CWD Aug 16, 2019
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @angular/cli area: docs Related to the documentation freq1: low Only reported by a handful of users who observe it rarely severity1: confusing
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants