File tree Expand file tree Collapse file tree 5 files changed +34
-12
lines changed Expand file tree Collapse file tree 5 files changed +34
-12
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,27 @@ type DeprecatedNames =
4646
4747type ElementType < A > = A extends readonly ( infer T ) [ ] ? T : never ;
4848
49+ export function getBooleanEnvironmentVariableFactory ( options : {
50+ variableName : VariableNames ;
51+ } ) : ( ) => boolean | undefined ;
52+ export function getBooleanEnvironmentVariableFactory ( options : {
53+ variableName : VariableNames ;
54+ defaultValue : boolean | ( ( ) => boolean ) ;
55+ } ) : ( ) => boolean ;
56+ export function getBooleanEnvironmentVariableFactory ( options : {
57+ variableName : VariableNames ;
58+ defaultValue ?: boolean | ( ( ) => boolean ) ;
59+ } ) : ( ) => boolean | undefined {
60+ return ( ) => {
61+ if ( options . variableName in process . env ) {
62+ return process . env [ options . variableName ] ?. toLowerCase ( ) === "true" ;
63+ }
64+ return typeof options . defaultValue === "function"
65+ ? options . defaultValue ( )
66+ : options . defaultValue ;
67+ } ;
68+ }
69+
4970/**
5071 * Create a function used to access an environment variable. It may return undefined if the variable is not set.
5172 *
Original file line number Diff line number Diff line change @@ -2,7 +2,10 @@ import path from "node:path";
22import { dedent } from "ts-dedent" ;
33import { UserError } from "../errors" ;
44import { getGlobalWranglerConfigPath } from "../global-wrangler-config-path" ;
5- import { getEnvironmentVariableFactory } from "./factory" ;
5+ import {
6+ getBooleanEnvironmentVariableFactory ,
7+ getEnvironmentVariableFactory ,
8+ } from "./factory" ;
69import type { Config } from "../config" ;
710
811/**
@@ -37,7 +40,8 @@ export const getC3CommandFromEnv = getEnvironmentVariableFactory({
3740/**
3841 * `WRANGLER_SEND_METRICS` can override whether we attempt to send metrics information to Sparrow.
3942 */
40- export const getWranglerSendMetricsFromEnv = getEnvironmentVariableFactory ( {
43+ export const getWranglerSendMetricsFromEnv =
44+ getBooleanEnvironmentVariableFactory ( {
4145 variableName : "WRANGLER_SEND_METRICS" ,
4246} ) ;
4347
@@ -139,10 +143,10 @@ function getStagingSubdomain(): string {
139143 *
140144 * By default we do, since debug logs could be added to GitHub issues and shouldn't include sensitive information.
141145 */
142- export const getSanitizeLogs = getEnvironmentVariableFactory ( {
146+ export const getSanitizeLogs = getBooleanEnvironmentVariableFactory ( {
143147 variableName : "WRANGLER_LOG_SANITIZE" ,
144148 defaultValue ( ) {
145- return " true" ;
149+ return true ;
146150 } ,
147151} ) ;
148152
Original file line number Diff line number Diff line change @@ -104,13 +104,13 @@ export class Logger {
104104
105105 debug = ( ...args : unknown [ ] ) => this . doLog ( "debug" , args ) ;
106106 debugWithSanitization = ( label : string , ...args : unknown [ ] ) => {
107- if ( getSanitizeLogs ( ) === "false" ) {
108- this . doLog ( "debug" , [ label , ...args ] ) ;
109- } else {
107+ if ( getSanitizeLogs ( ) ) {
110108 this . doLog ( "debug" , [
111109 label ,
112110 "omitted; set WRANGLER_LOG_SANITIZE=false to include sanitized data" ,
113111 ] ) ;
112+ } else {
113+ this . doLog ( "debug" , [ label , ...args ] ) ;
114114 }
115115 } ;
116116 info = ( ...args : unknown [ ] ) => this . doLog ( "info" , args ) ;
Original file line number Diff line number Diff line change @@ -61,10 +61,7 @@ export const telemetryStatusCommand = createCommand({
6161 const savedConfig = readMetricsConfig ( ) ;
6262 const sendMetricsEnv = getWranglerSendMetricsFromEnv ( ) ;
6363 if ( config . send_metrics !== undefined || sendMetricsEnv !== undefined ) {
64- const resolvedPermission =
65- sendMetricsEnv !== undefined
66- ? sendMetricsEnv === "true"
67- : config . send_metrics ;
64+ const resolvedPermission = sendMetricsEnv ?? config . send_metrics ;
6865 logger . log (
6966 `Status: ${ resolvedPermission ? chalk . green ( "Enabled" ) : chalk . red ( "Disabled" ) } (set by ${ sendMetricsEnv !== undefined ? "environment variable" : "wrangler.toml" } )\n`
7067 ) ;
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ export function getMetricsConfig({
6666 const sendMetricsEnv = getWranglerSendMetricsFromEnv ( ) ;
6767 if ( sendMetricsEnv !== undefined ) {
6868 return {
69- enabled : sendMetricsEnv . toLowerCase ( ) === "true" ,
69+ enabled : sendMetricsEnv ,
7070 deviceId,
7171 } ;
7272 }
You can’t perform that action at this time.
0 commit comments