File tree Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Expand file tree Collapse file tree 2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ import { File, FormData } from "undici";
99import { vi } from "vitest" ;
1010import { version as wranglerVersion } from "../../package.json" ;
1111import { downloadWorker } from "../init" ;
12+ import { writeMetricsConfig } from "../metrics/metrics-config" ;
1213import { getPackageManager } from "../package-manager" ;
1314import { mockAccountId , mockApiToken } from "./helpers/mock-account-id" ;
1415import { mockConsoleMethods } from "./helpers/mock-console" ;
@@ -149,6 +150,27 @@ describe("init", () => {
149150 ) ;
150151 } ) ;
151152 } ) ;
153+
154+ test ( "if telemetry is disabled in wrangler, then disable for c3 too" , async ( ) => {
155+ writeMetricsConfig ( {
156+ permission : {
157+ enabled : false ,
158+ date : new Date ( 2024 , 11 , 11 ) ,
159+ } ,
160+ } ) ;
161+ await runWrangler ( "init" ) ;
162+
163+ expect ( execa ) . toHaveBeenCalledWith (
164+ "mockpm" ,
165+ [ "create" , "cloudflare@^2.5.0" ] ,
166+ {
167+ env : {
168+ CREATE_CLOUDFLARE_TELEMETRY_DISABLED : "1" ,
169+ } ,
170+ stdio : "inherit" ,
171+ }
172+ ) ;
173+ } ) ;
152174 } ) ;
153175
154176 describe ( "deprecated behavior is retained with --no-delegate-c3" , ( ) => {
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import { getC3CommandFromEnv } from "./environment-variables/misc-variables";
1515import { CommandLineArgsError , FatalError , UserError } from "./errors" ;
1616import { getGitVersioon , initializeGit , isInsideGitRepo } from "./git-client" ;
1717import { logger } from "./logger" ;
18+ import { readMetricsConfig } from "./metrics/metrics-config" ;
1819import { getPackageManager } from "./package-manager" ;
1920import { parsePackageJSON , parseTOML , readFileSync } from "./parse" ;
2021import { getBasePath } from "./paths" ;
@@ -279,8 +280,14 @@ export async function initHandler(args: InitArgs) {
279280 ) ;
280281 logger . log ( `🌀 Running ${ replacementC3Command } ...` ) ;
281282
283+ // if telemetry is disabled in wrangler, prevent c3 from sending metrics too
284+ const metricsConfig = readMetricsConfig ( ) ;
285+
282286 await execa ( packageManager . type , c3Arguments , {
283287 stdio : "inherit" ,
288+ ...( metricsConfig . permission ?. enabled === false && {
289+ env : { CREATE_CLOUDFLARE_TELEMETRY_DISABLED : "1" } ,
290+ } ) ,
284291 } ) ;
285292
286293 return ;
You can’t perform that action at this time.
0 commit comments