Skip to content

Commit 8d8a710

Browse files
committed
fix(@angular/cli): handle missing package manager during analytics initialization
Wrap getVersion() call in try-catch to prevent a crash during analytics setup when the package manager is not available.
1 parent 7fbc715 commit 8d8a710

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

packages/angular/cli/src/command-builder/command-module.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,21 @@ export abstract class CommandModule<T extends {} = {}> implements CommandModuleI
153153
['version', 'update', 'analytics'].includes(this.commandName),
154154
);
155155

156-
return userId
157-
? new AnalyticsCollector(this.context.logger, userId, {
158-
name: this.context.packageManager.name,
159-
version: await this.context.packageManager.getVersion(),
160-
})
161-
: undefined;
156+
if (!userId) {
157+
return undefined;
158+
}
159+
160+
let version: string | undefined;
161+
try {
162+
version = await this.context.packageManager.getVersion();
163+
} catch {
164+
// Ignore errors if the package manager is not available.
165+
}
166+
167+
return new AnalyticsCollector(this.context.logger, userId, {
168+
name: this.context.packageManager.name,
169+
version,
170+
});
162171
}
163172

164173
/**

0 commit comments

Comments
 (0)