Unverified Commit 4ba2b787 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Read process.env after loading .env files (#13087)

Fixes #13067
parent 49990f55
...@@ -26,8 +26,6 @@ const TELEMETRY_KEY_ID = `telemetry.anonymousId` ...@@ -26,8 +26,6 @@ const TELEMETRY_KEY_ID = `telemetry.anonymousId`
// See the `oneWayHash` function. // See the `oneWayHash` function.
const TELEMETRY_KEY_SALT = `telemetry.salt` const TELEMETRY_KEY_SALT = `telemetry.salt`
const { NEXT_TELEMETRY_DISABLED, NEXT_TELEMETRY_DEBUG } = process.env
type TelemetryEvent = { eventName: string; payload: object } type TelemetryEvent = { eventName: string; payload: object }
type EventContext = { type EventContext = {
anonymousId: string anonymousId: string
...@@ -51,10 +49,16 @@ export class Telemetry { ...@@ -51,10 +49,16 @@ export class Telemetry {
private conf: Conf<any> | null private conf: Conf<any> | null
private sessionId: string private sessionId: string
private rawProjectId: string private rawProjectId: string
private NEXT_TELEMETRY_DISABLED: any
private NEXT_TELEMETRY_DEBUG: any
private queue: Set<Promise<RecordObject>> private queue: Set<Promise<RecordObject>>
constructor({ distDir }: { distDir: string }) { constructor({ distDir }: { distDir: string }) {
// Read in the constructor so that .env can be loaded before reading
const { NEXT_TELEMETRY_DISABLED, NEXT_TELEMETRY_DEBUG } = process.env
this.NEXT_TELEMETRY_DISABLED = NEXT_TELEMETRY_DISABLED
this.NEXT_TELEMETRY_DEBUG = NEXT_TELEMETRY_DEBUG
const storageDirectory = getStorageDirectory(distDir) const storageDirectory = getStorageDirectory(distDir)
try { try {
...@@ -125,7 +129,7 @@ export class Telemetry { ...@@ -125,7 +129,7 @@ export class Telemetry {
} }
private get isDisabled(): boolean { private get isDisabled(): boolean {
if (!!NEXT_TELEMETRY_DISABLED || !this.conf) { if (!!this.NEXT_TELEMETRY_DISABLED || !this.conf) {
return true return true
} }
return this.conf.get(TELEMETRY_KEY_ENABLED, true) === false return this.conf.get(TELEMETRY_KEY_ENABLED, true) === false
...@@ -206,7 +210,7 @@ export class Telemetry { ...@@ -206,7 +210,7 @@ export class Telemetry {
return Promise.resolve() return Promise.resolve()
} }
if (NEXT_TELEMETRY_DEBUG) { if (this.NEXT_TELEMETRY_DEBUG) {
// Print to standard error to simplify selecting the output // Print to standard error to simplify selecting the output
events.forEach(({ eventName, payload }) => events.forEach(({ eventName, payload }) =>
console.error( console.error(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment