Skip to content

Commit fedda40

Browse files
Keen Yee LiauAngular Builds
authored andcommitted
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`.
1 parent bf228a0 commit fedda40

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/angular/cli/commands/add-impl.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,11 @@ export class AddCommand extends SchematicCommand<AddCommandSchema> {
140140

141141
private isPackageInstalled(name: string): boolean {
142142
try {
143-
resolve(name, { checkLocal: true, basedir: this.workspace.root });
143+
resolve(name, {
144+
checkLocal: true,
145+
basedir: this.workspace.root,
146+
resolvePackageJson: true,
147+
});
144148

145149
return true;
146150
} catch (e) {

0 commit comments

Comments
 (0)