From fedda409ed50481d0b295dfd850ba49afbdc05e6 Mon Sep 17 00:00:00 2001 From: Keen Yee Liau Date: Mon, 28 Jan 2019 13:27:46 -0800 Subject: [PATCH] fix(@angular/cli): ng-add should resolve package.json 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`. --- packages/angular/cli/commands/add-impl.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/angular/cli/commands/add-impl.ts b/packages/angular/cli/commands/add-impl.ts index 1e915ec4460b..34c9b75b1fbc 100644 --- a/packages/angular/cli/commands/add-impl.ts +++ b/packages/angular/cli/commands/add-impl.ts @@ -140,7 +140,11 @@ export class AddCommand extends SchematicCommand { 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) {