Skip to content

Commit 0617258

Browse files
fix(analytics): undefined file is created on every command
When analytics are enabled, `undefined` file is created at the location where a command is executed. This is because the `$options.analyticsLoggingFile` is undefined, but we've set it as args to the spawned Analytics process. The value in the child process is the string "undefined", so that's why CLI always creates this file. Pass the path to file only when it is passed by user.
1 parent e2b55b2 commit 0617258

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

lib/services/analytics/analytics-service.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,10 @@ export class AnalyticsService implements IAnalyticsService, IDisposable {
147147
@cache()
148148
private getAnalyticsBroker(): Promise<ChildProcess> {
149149
return new Promise<ChildProcess>((resolve, reject) => {
150+
const brokerProcessArgs = this.getBrokerProcessArgs();
151+
150152
const broker = this.$childProcess.spawn(process.execPath,
151-
[
152-
path.join(__dirname, "analytics-broker-process.js"),
153-
this.$staticConfig.PATH_TO_BOOTSTRAP,
154-
this.$options.analyticsLogFile // TODO: Check if passing path with space or quotes will work
155-
],
153+
brokerProcessArgs,
156154
{
157155
stdio: ["ignore", "ignore", "ignore", "ipc"],
158156
detached: true
@@ -200,6 +198,19 @@ export class AnalyticsService implements IAnalyticsService, IDisposable {
200198
});
201199
}
202200

201+
private getBrokerProcessArgs(): string[] {
202+
const brokerProcessArgs = [
203+
path.join(__dirname, "analytics-broker-process.js"),
204+
this.$staticConfig.PATH_TO_BOOTSTRAP,
205+
];
206+
207+
if (this.$options.analyticsLogFile) {
208+
brokerProcessArgs.push(this.$options.analyticsLogFile);
209+
}
210+
211+
return brokerProcessArgs;
212+
}
213+
203214
private async sendInfoForTracking(trackingInfo: ITrackingInformation, settingName: string): Promise<void> {
204215
await this.initAnalyticsStatuses();
205216

0 commit comments

Comments
 (0)