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

Fixes #13067
This commit is contained in:
Tim Neutkens 2020-05-20 05:39:27 +02:00 committed by GitHub
parent 49990f558d
commit 4ba2b78729
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,8 +26,6 @@ const TELEMETRY_KEY_ID = `telemetry.anonymousId`
// See the `oneWayHash` function.
const TELEMETRY_KEY_SALT = `telemetry.salt`
const { NEXT_TELEMETRY_DISABLED, NEXT_TELEMETRY_DEBUG } = process.env
type TelemetryEvent = { eventName: string; payload: object }
type EventContext = {
anonymousId: string
@ -51,10 +49,16 @@ export class Telemetry {
private conf: Conf<any> | null
private sessionId: string
private rawProjectId: string
private NEXT_TELEMETRY_DISABLED: any
private NEXT_TELEMETRY_DEBUG: any
private queue: Set<Promise<RecordObject>>
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)
try {
@ -125,7 +129,7 @@ export class Telemetry {
}
private get isDisabled(): boolean {
if (!!NEXT_TELEMETRY_DISABLED || !this.conf) {
if (!!this.NEXT_TELEMETRY_DISABLED || !this.conf) {
return true
}
return this.conf.get(TELEMETRY_KEY_ENABLED, true) === false
@ -206,7 +210,7 @@ export class Telemetry {
return Promise.resolve()
}
if (NEXT_TELEMETRY_DEBUG) {
if (this.NEXT_TELEMETRY_DEBUG) {
// Print to standard error to simplify selecting the output
events.forEach(({ eventName, payload }) =>
console.error(