Skip to content

Commit e5a8190

Browse files
committed
add config type
1 parent 0e93043 commit e5a8190

File tree

6 files changed

+33
-1
lines changed

6 files changed

+33
-1
lines changed

packages/wrangler/src/__tests__/metrics.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { UserError } from "../errors";
66
import { CI } from "../is-ci";
77
import { logger } from "../logger";
88
import {
9+
getConfigFileType,
910
getNodeVersion,
1011
getOS,
1112
getOSVersion,
@@ -58,6 +59,7 @@ describe("metrics", () => {
5859
vi.mocked(getOSVersion).mockReturnValue("mock os version");
5960
vi.mocked(getNodeVersion).mockReturnValue("1.1.1");
6061
vi.mocked(getPlatform).mockReturnValue("mock platform");
62+
vi.mocked(getConfigFileType).mockReturnValue("toml");
6163
vi.useFakeTimers({
6264
now: new Date(2024, 11, 12),
6365
});
@@ -245,6 +247,7 @@ describe("metrics", () => {
245247
osVersion: "mock os version",
246248
nodeVersion: "1.1.1",
247249
isFirstUsage: false,
250+
configFileType: "toml",
248251
isCI: false,
249252
isInteractive: true,
250253
};

packages/wrangler/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,10 @@ export async function main(argv: string[]): Promise<void> {
690690
// key to fetch) or flags
691691

692692
try {
693-
const { rawConfig } = parseConfig(args.config, args, false);
693+
const { rawConfig, configPath } = parseConfig(args.config, args, false);
694694
dispatcher = getMetricsDispatcher({
695695
sendMetrics: rawConfig.send_metrics,
696+
configPath,
696697
});
697698
} catch (e) {
698699
// If we can't parse the config, we can't send metrics

packages/wrangler/src/metrics/helpers.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,20 @@ export function getOSVersion() {
3838
export function getNodeVersion() {
3939
return process.version;
4040
}
41+
42+
export function getConfigFileType(configPath: string | undefined) {
43+
if (configPath === undefined) {
44+
return "none";
45+
}
46+
if (configPath.endsWith(".toml")) {
47+
return "toml";
48+
}
49+
if (configPath.endsWith(".json")) {
50+
return "json";
51+
}
52+
if (configPath.endsWith(".jsonc")) {
53+
return "jsonc";
54+
}
55+
/** shouldn't ever get here */
56+
return "invalid";
57+
}

packages/wrangler/src/metrics/metrics-config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export interface MetricsConfigOptions {
2323
* Otherwise, infer the enabled value from the user configuration.
2424
*/
2525
sendMetrics?: boolean;
26+
/**
27+
* Path to wrangler configuration file, if it exists. Used for configFileType property
28+
*/
29+
configPath?: string | undefined;
2630
}
2731

2832
/**

packages/wrangler/src/metrics/metrics-dispatcher.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import _isInteractive from "../is-interactive";
44
import { logger } from "../logger";
55
import { CI } from "./../is-ci";
66
import {
7+
getConfigFileType,
78
getNodeVersion,
89
getOS,
910
getOSVersion,
@@ -35,6 +36,7 @@ export function getMetricsDispatcher(options: MetricsConfigOptions) {
3536
const isCI = CI.isCI();
3637
const isInteractive = _isInteractive();
3738
const amplitude_session_id = Date.now();
39+
const configFileType = getConfigFileType(options.configPath);
3840
let amplitude_event_id = 0;
3941
/** We redact strings in arg values, unless they are named here */
4042
const allowList = {
@@ -95,6 +97,7 @@ export function getMetricsDispatcher(options: MetricsConfigOptions) {
9597
nodeVersion,
9698
packageManager,
9799
isFirstUsage,
100+
configFileType,
98101
isCI,
99102
isInteractive,
100103
argsUsed,

packages/wrangler/src/metrics/send-event.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ export type CommonEventProperties = {
138138
* Whether this is the first time the user has used the wrangler client.
139139
*/
140140
isFirstUsage: boolean;
141+
/**
142+
* What format is the configuration file?
143+
*/
144+
configFileType: "toml" | "json" | "jsonc" | "none" | "invalid";
141145

142146
amplitude_session_id: number;
143147
amplitude_event_id: number;

0 commit comments

Comments
 (0)