From 0617258165954e3ab0a8d11cf80f882732bed039 Mon Sep 17 00:00:00 2001 From: rosen-vladimirov Date: Tue, 27 Nov 2018 16:25:26 +0200 Subject: [PATCH] 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. --- lib/services/analytics/analytics-service.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/services/analytics/analytics-service.ts b/lib/services/analytics/analytics-service.ts index 3ea2036cdb..d054658c28 100644 --- a/lib/services/analytics/analytics-service.ts +++ b/lib/services/analytics/analytics-service.ts @@ -147,12 +147,10 @@ export class AnalyticsService implements IAnalyticsService, IDisposable { @cache() private getAnalyticsBroker(): Promise { return new Promise((resolve, reject) => { + const brokerProcessArgs = this.getBrokerProcessArgs(); + const broker = this.$childProcess.spawn(process.execPath, - [ - path.join(__dirname, "analytics-broker-process.js"), - this.$staticConfig.PATH_TO_BOOTSTRAP, - this.$options.analyticsLogFile // TODO: Check if passing path with space or quotes will work - ], + brokerProcessArgs, { stdio: ["ignore", "ignore", "ignore", "ipc"], detached: true @@ -200,6 +198,19 @@ export class AnalyticsService implements IAnalyticsService, IDisposable { }); } + private getBrokerProcessArgs(): string[] { + const brokerProcessArgs = [ + path.join(__dirname, "analytics-broker-process.js"), + this.$staticConfig.PATH_TO_BOOTSTRAP, + ]; + + if (this.$options.analyticsLogFile) { + brokerProcessArgs.push(this.$options.analyticsLogFile); + } + + return brokerProcessArgs; + } + private async sendInfoForTracking(trackingInfo: ITrackingInformation, settingName: string): Promise { await this.initAnalyticsStatuses();