diff --git a/packages/cli/src/analytics.ts b/packages/cli/src/analytics.ts index 0628e598bb..7fcdd24e02 100644 --- a/packages/cli/src/analytics.ts +++ b/packages/cli/src/analytics.ts @@ -36,15 +36,18 @@ export default class AnalyticsCommand { http: typeof deps.HTTP + initialize: Promise; + constructor(config: Interfaces.Config) { this.config = config this.http = deps.HTTP.create({ headers: {'user-agent': config.userAgent}, }) + this.initialize = this.init() } async record(opts: RecordOpts) { - await this.init() + await this.initialize const plugin = opts.Command.plugin if (!plugin) { debug('no plugin found for analytics') diff --git a/packages/cli/src/hooks/postrun/performance_analytics.ts b/packages/cli/src/hooks/postrun/performance_analytics.ts index 97f925d62d..df3da4ff54 100644 --- a/packages/cli/src/hooks/postrun/performance_analytics.ts +++ b/packages/cli/src/hooks/postrun/performance_analytics.ts @@ -12,6 +12,7 @@ const performance_analytics: Hook<'postrun'> = async function () { const cmdStartTime = global.cliTelemetry.commandRunDuration global.cliTelemetry.commandRunDuration = telemetry.computeDuration(cmdStartTime) global.cliTelemetry.lifecycleHookCompletion.postrun = true + await Reflect.get(globalThis, 'recordPromise') } export default performance_analytics diff --git a/packages/cli/src/hooks/prerun/analytics.ts b/packages/cli/src/hooks/prerun/analytics.ts index 50a585bf7b..9a2d20e35e 100644 --- a/packages/cli/src/hooks/prerun/analytics.ts +++ b/packages/cli/src/hooks/prerun/analytics.ts @@ -12,7 +12,7 @@ const analytics: Hook<'prerun'> = async function (options) { global.cliTelemetry = telemetry.setupTelemetry(this.config, options) const analytics = new Analytics(this.config) - await analytics.record(options) + Reflect.set(globalThis, 'recordPromise', analytics.record(options)) } export default analytics