Skip to content

Commit 01e4fba

Browse files
authored
fix(ng-update): do not throw if project does not have dependencies (#18470)
The v9 hammerjs migration in some cases tries to remove `hammerjs` from the workspace `package.json`. It always assumes that there is a `dependencies` property. This is not always guaranteed because a project doesn't need to define this property. This change guards against this case and avoids a runtime migration exception. Fixes #18469.
1 parent aea79f0 commit 01e4fba

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/material/schematics/ng-update/upgrade-rules/hammer-gestures-v9/hammer-gestures-rule.ts

+2-3
Original file line numberDiff line numberDiff line change
@@ -853,9 +853,8 @@ export class HammerGesturesRule extends MigrationRule<null> {
853853

854854
const packageJson = JSON.parse(tree.read('/package.json')!.toString('utf8'));
855855

856-
// We do not handle the case where someone manually added "hammerjs"
857-
// to the dev dependencies.
858-
if (packageJson.dependencies[HAMMER_MODULE_SPECIFIER]) {
856+
// We do not handle the case where someone manually added "hammerjs" to the dev dependencies.
857+
if (packageJson.dependencies && packageJson.dependencies[HAMMER_MODULE_SPECIFIER]) {
859858
delete packageJson.dependencies[HAMMER_MODULE_SPECIFIER];
860859
tree.overwrite('/package.json', JSON.stringify(packageJson, null, 2));
861860
return true;

0 commit comments

Comments
 (0)