Skip to content

Commit

Permalink
fix(@angular/cli): ng-add should resolve package.json
Browse files Browse the repository at this point in the history
ng-add checks if a specified collection is installed, and if not it'd
proceed to install the package. However, `isPackageInstalled` would, by
default, resolve the main field or the index of the package. Not all NPM
packages specify the main field or provide an index file. It should
be sufficient to just check the presence of `package.json` to detect
whether a package is installed or not.

For example, `ng add @angular/bazel` should not install the package if
it's already installed locally. `@angular/bazel` does not specify a main
field not an index file in its `package.json`.
  • Loading branch information
kyliau authored and Angular Builds committed Jan 30, 2019
1 parent bf228a0 commit fedda40
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/angular/cli/commands/add-impl.ts
Expand Up @@ -140,7 +140,11 @@ export class AddCommand extends SchematicCommand<AddCommandSchema> {

private isPackageInstalled(name: string): boolean {
try {
resolve(name, { checkLocal: true, basedir: this.workspace.root });
resolve(name, {
checkLocal: true,
basedir: this.workspace.root,
resolvePackageJson: true,
});

return true;
} catch (e) {
Expand Down

0 comments on commit fedda40

Please sign in to comment.