wrangler 2.0.18 → 2.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -94,6 +94,14 @@ export function normalizeAndValidateConfig(
94
94
  "boolean"
95
95
  );
96
96
 
97
+ validateOptionalProperty(
98
+ diagnostics,
99
+ "",
100
+ "send_metrics",
101
+ rawConfig.send_metrics,
102
+ "boolean"
103
+ );
104
+
97
105
  // TODO: set the default to false to turn on service environments as the default
98
106
  const isLegacyEnv =
99
107
  (args as { "legacy-env": boolean | undefined })["legacy-env"] ??
@@ -173,6 +181,7 @@ export function normalizeAndValidateConfig(
173
181
  const config: Config = {
174
182
  configPath,
175
183
  legacy_env: isLegacyEnv,
184
+ send_metrics: rawConfig.send_metrics,
176
185
  ...activeEnv,
177
186
  dev: normalizeAndValidateDev(diagnostics, rawConfig.dev ?? {}),
178
187
  migrations: normalizeAndValidateMigrations(
@@ -6,7 +6,7 @@ import { logger } from "./logger";
6
6
 
7
7
  let cacheMessageShown = false;
8
8
 
9
- let __cacheFolder: string | null;
9
+ let __cacheFolder: string | null | undefined;
10
10
  function getCacheFolder() {
11
11
  if (__cacheFolder || __cacheFolder === null) return __cacheFolder;
12
12
 
@@ -80,4 +80,5 @@ export function purgeConfigCaches() {
80
80
  if (cacheFolder) {
81
81
  rmSync(cacheFolder, { recursive: true, force: true });
82
82
  }
83
+ __cacheFolder = undefined;
83
84
  }
package/src/dev/dev.tsx CHANGED
@@ -55,7 +55,7 @@ export type DevProps = {
55
55
  zone: string | undefined;
56
56
  host: string | undefined;
57
57
  routes: Route[] | undefined;
58
- inspect: boolean | undefined;
58
+ inspect: boolean;
59
59
  logLevel: "none" | "error" | "log" | "warn" | "debug" | undefined;
60
60
  onReady: (() => void) | undefined;
61
61
  showInteractiveDevSession: boolean | undefined;
@@ -101,16 +101,17 @@ export function DevImplementation(props: DevProps): JSX.Element {
101
101
  }
102
102
 
103
103
  function InteractiveDevSession(props: DevProps) {
104
- const toggles = useHotkeys(
105
- {
104
+ const toggles = useHotkeys({
105
+ initial: {
106
106
  local: props.initialMode === "local",
107
107
  tunnel: false,
108
108
  },
109
- props.port,
110
- props.ip,
111
- props.inspectorPort,
112
- props.localProtocol
113
- );
109
+ port: props.port,
110
+ ip: props.ip,
111
+ inspectorPort: props.inspectorPort,
112
+ inspect: props.inspect,
113
+ localProtocol: props.localProtocol,
114
+ });
114
115
 
115
116
  useTunnel(toggles.tunnel);
116
117
 
@@ -120,8 +121,12 @@ function InteractiveDevSession(props: DevProps) {
120
121
  <Box borderStyle="round" paddingLeft={1} paddingRight={1}>
121
122
  <Text bold={true}>[b]</Text>
122
123
  <Text> open a browser, </Text>
123
- <Text bold={true}>[d]</Text>
124
- <Text> open Devtools, </Text>
124
+ {props.inspect ? (
125
+ <>
126
+ <Text bold={true}>[d]</Text>
127
+ <Text> open Devtools, </Text>
128
+ </>
129
+ ) : null}
125
130
  <Text bold={true}>[l]</Text>
126
131
  <Text> {toggles.local ? "turn off" : "turn on"} local mode, </Text>
127
132
  <Text bold={true}>[c]</Text>
@@ -193,6 +198,7 @@ function DevSession(props: DevSessionProps) {
193
198
  ip={props.ip}
194
199
  localProtocol={props.localProtocol}
195
200
  inspectorPort={props.inspectorPort}
201
+ inspect={props.inspect}
196
202
  compatibilityDate={props.compatibilityDate}
197
203
  compatibilityFlags={props.compatibilityFlags}
198
204
  usageModel={props.usageModel}
@@ -346,13 +352,15 @@ type useHotkeysInitialState = {
346
352
  local: boolean;
347
353
  tunnel: boolean;
348
354
  };
349
- function useHotkeys(
350
- initial: useHotkeysInitialState,
351
- port: number,
352
- ip: string,
353
- inspectorPort: number,
354
- localProtocol: "http" | "https"
355
- ) {
355
+ function useHotkeys(props: {
356
+ initial: useHotkeysInitialState;
357
+ port: number;
358
+ ip: string;
359
+ inspectorPort: number;
360
+ inspect: boolean;
361
+ localProtocol: "http" | "https";
362
+ }) {
363
+ const { initial, port, ip, inspectorPort, inspect, localProtocol } = props;
356
364
  // UGH, we should put port in context instead
357
365
  const [toggles, setToggles] = useState(initial);
358
366
  const { exit } = useApp();
@@ -377,7 +385,9 @@ function useHotkeys(
377
385
  }
378
386
  // toggle inspector
379
387
  case "d": {
380
- await openInspector(inspectorPort);
388
+ if (inspect) {
389
+ await openInspector(inspectorPort);
390
+ }
381
391
  break;
382
392
  }
383
393
  // toggle local
package/src/dev/local.tsx CHANGED
@@ -31,7 +31,7 @@ interface LocalProps {
31
31
  crons: Config["triggers"]["crons"];
32
32
  localProtocol: "http" | "https";
33
33
  localUpstream: string | undefined;
34
- inspect: boolean | undefined;
34
+ inspect: boolean;
35
35
  onReady: (() => void) | undefined;
36
36
  logLevel: "none" | "error" | "log" | "warn" | "debug" | undefined;
37
37
  }
@@ -195,9 +195,10 @@ function useLocalWorker({
195
195
  ),
196
196
  ...(localPersistencePath
197
197
  ? {
198
- kvPersist: path.join(localPersistencePath, "kv"),
199
- durableObjectsPersist: path.join(localPersistencePath, "do"),
200
198
  cachePersist: path.join(localPersistencePath, "cache"),
199
+ durableObjectsPersist: path.join(localPersistencePath, "do"),
200
+ kvPersist: path.join(localPersistencePath, "kv"),
201
+ r2Persist: path.join(localPersistencePath, "r2"),
201
202
  }
202
203
  : {
203
204
  // We mark these as true, so that they'll
@@ -205,9 +206,10 @@ function useLocalWorker({
205
206
  // This means they'll persist across a dev session,
206
207
  // even if we change source and reload,
207
208
  // and be deleted when the dev session ends
208
- durableObjectsPersist: true,
209
209
  cachePersist: true,
210
+ durableObjectsPersist: true,
210
211
  kvPersist: true,
212
+ r2Persist: true,
211
213
  }),
212
214
 
213
215
  sitePath: assetPaths?.assetDirectory
@@ -254,6 +256,7 @@ function useLocalWorker({
254
256
  {
255
257
  cwd: path.dirname(scriptPath),
256
258
  execArgv: nodeOptions,
259
+ stdio: "pipe",
257
260
  }
258
261
  ));
259
262
  child.on("message", (message) => {
@@ -42,6 +42,7 @@ export function Remote(props: {
42
42
  port: number;
43
43
  ip: string;
44
44
  localProtocol: "https" | "http";
45
+ inspect: boolean;
45
46
  inspectorPort: number;
46
47
  accountId: string | undefined;
47
48
  bindings: CfWorkerInit["bindings"];
@@ -91,7 +92,10 @@ export function Remote(props: {
91
92
  });
92
93
 
93
94
  useInspector({
94
- inspectorUrl: previewToken ? previewToken.inspectorUrl.href : undefined,
95
+ inspectorUrl:
96
+ props.inspect && previewToken
97
+ ? previewToken.inspectorUrl.href
98
+ : undefined,
95
99
  port: props.inspectorPort,
96
100
  logToTerminal: true,
97
101
  });
package/src/dev.tsx CHANGED
@@ -10,6 +10,7 @@ import { getVarsForDev } from "./dev/dev-vars";
10
10
 
11
11
  import { getEntry } from "./entry";
12
12
  import { logger } from "./logger";
13
+ import * as metrics from "./metrics";
13
14
  import { getAssetPaths, getSiteAssetPaths } from "./sites";
14
15
  import { getAccountFromCache } from "./user";
15
16
  import { getZoneIdFromHost, getZoneForRoute, getHostFromRoute } from "./zones";
@@ -264,6 +265,11 @@ export async function startDev(args: ArgumentsCamelCase<DevArgs>) {
264
265
  ((args.script &&
265
266
  findWranglerToml(path.dirname(args.script))) as ConfigPath);
266
267
  let config = readConfig(configPath, args);
268
+ await metrics.sendMetricsEvent(
269
+ "run dev",
270
+ { local: args.local },
271
+ { sendMetrics: config.send_metrics, offline: args.local }
272
+ );
267
273
 
268
274
  if (config.configPath) {
269
275
  watcher = watch(config.configPath, {
@@ -500,7 +506,7 @@ export async function startDev(args: ArgumentsCamelCase<DevArgs>) {
500
506
  crons={config.triggers.crons}
501
507
  logLevel={args.logLevel}
502
508
  onReady={args.onReady}
503
- inspect={args.inspect}
509
+ inspect={args.inspect ?? true}
504
510
  showInteractiveDevSession={args.showInteractiveDevSession}
505
511
  />
506
512
  );
package/src/index.tsx CHANGED
@@ -33,6 +33,7 @@ import {
33
33
  deleteKVKeyValue,
34
34
  } from "./kv";
35
35
  import { logger } from "./logger";
36
+ import * as metrics from "./metrics";
36
37
  import { pages } from "./pages";
37
38
  import {
38
39
  formatMessage,
@@ -500,6 +501,9 @@ function createCLIParser(argv: string[]) {
500
501
  (args.config as ConfigPath) ||
501
502
  (args.script && findWranglerToml(path.dirname(args.script)));
502
503
  const config = readConfig(configPath, args);
504
+ await metrics.sendMetricsEvent("deploy worker script", {
505
+ sendMetrics: config.send_metrics,
506
+ });
503
507
  const entry = await getEntry(args, config, "publish");
504
508
 
505
509
  if (args.public) {
@@ -640,6 +644,9 @@ function createCLIParser(argv: string[]) {
640
644
  await printWranglerBanner();
641
645
  }
642
646
  const config = readConfig(args.config as ConfigPath, args);
647
+ await metrics.sendMetricsEvent("begin log stream", {
648
+ sendMetrics: config.send_metrics,
649
+ });
643
650
 
644
651
  const scriptName = getLegacyScriptName(args, config);
645
652
 
@@ -685,6 +692,9 @@ function createCLIParser(argv: string[]) {
685
692
  onExit(async () => {
686
693
  tail.terminate();
687
694
  await deleteTail();
695
+ await metrics.sendMetricsEvent("end log stream", {
696
+ sendMetrics: config.send_metrics,
697
+ });
688
698
  });
689
699
 
690
700
  const printLog: (data: RawData) => void =
@@ -701,6 +711,9 @@ function createCLIParser(argv: string[]) {
701
711
  await setTimeout(100);
702
712
  break;
703
713
  case tail.CLOSED:
714
+ await metrics.sendMetricsEvent("end log stream", {
715
+ sendMetrics: config.send_metrics,
716
+ });
704
717
  throw new Error(
705
718
  `Connection to ${scriptDisplayName} closed unexpectedly.`
706
719
  );
@@ -714,6 +727,9 @@ function createCLIParser(argv: string[]) {
714
727
  tail.on("close", async () => {
715
728
  tail.terminate();
716
729
  await deleteTail();
730
+ await metrics.sendMetricsEvent("end log stream", {
731
+ sendMetrics: config.send_metrics,
732
+ });
717
733
  });
718
734
  }
719
735
  );
@@ -944,6 +960,9 @@ function createCLIParser(argv: string[]) {
944
960
 
945
961
  try {
946
962
  await submitSecret();
963
+ await metrics.sendMetricsEvent("create encrypted variable", {
964
+ sendMetrics: config.send_metrics,
965
+ });
947
966
  } catch (e) {
948
967
  if (isMissingWorkerError(e)) {
949
968
  // create a draft worker and try again
@@ -1016,6 +1035,9 @@ function createCLIParser(argv: string[]) {
1016
1035
  : `/accounts/${accountId}/workers/services/${scriptName}/environments/${args.env}/secrets`;
1017
1036
 
1018
1037
  await fetchResult(`${url}/${args.key}`, { method: "DELETE" });
1038
+ await metrics.sendMetricsEvent("delete encrypted variable", {
1039
+ sendMetrics: config.send_metrics,
1040
+ });
1019
1041
  logger.log(`✨ Success! Deleted secret ${args.key}`);
1020
1042
  }
1021
1043
  }
@@ -1056,6 +1078,9 @@ function createCLIParser(argv: string[]) {
1056
1078
  : `/accounts/${accountId}/workers/services/${scriptName}/environments/${args.env}/secrets`;
1057
1079
 
1058
1080
  logger.log(JSON.stringify(await fetchResult(url), null, " "));
1081
+ await metrics.sendMetricsEvent("list encrypted variables", {
1082
+ sendMetrics: config.send_metrics,
1083
+ });
1059
1084
  }
1060
1085
  );
1061
1086
  }
@@ -1117,6 +1142,9 @@ function createCLIParser(argv: string[]) {
1117
1142
 
1118
1143
  logger.log(`🌀 Creating namespace with title "${title}"`);
1119
1144
  const namespaceId = await createKVNamespace(accountId, title);
1145
+ await metrics.sendMetricsEvent("create kv namespace", {
1146
+ sendMetrics: config.send_metrics,
1147
+ });
1120
1148
 
1121
1149
  logger.log("✨ Success!");
1122
1150
  const envString = args.env ? ` under [env.${args.env}]` : "";
@@ -1145,6 +1173,9 @@ function createCLIParser(argv: string[]) {
1145
1173
  logger.log(
1146
1174
  JSON.stringify(await listKVNamespaces(accountId), null, " ")
1147
1175
  );
1176
+ await metrics.sendMetricsEvent("list kv namespaces", {
1177
+ sendMetrics: config.send_metrics,
1178
+ });
1148
1179
  }
1149
1180
  )
1150
1181
  .command(
@@ -1190,6 +1221,9 @@ function createCLIParser(argv: string[]) {
1190
1221
  const accountId = await requireAuth(config);
1191
1222
 
1192
1223
  await deleteKVNamespace(accountId, id);
1224
+ await metrics.sendMetricsEvent("delete kv namespace", {
1225
+ sendMetrics: config.send_metrics,
1226
+ });
1193
1227
 
1194
1228
  // TODO: recommend they remove it from wrangler.toml
1195
1229
 
@@ -1313,6 +1347,9 @@ function createCLIParser(argv: string[]) {
1313
1347
  expiration_ttl: ttl,
1314
1348
  metadata: metadata as KeyValue["metadata"],
1315
1349
  });
1350
+ await metrics.sendMetricsEvent("write kv key-value", {
1351
+ sendMetrics: config.send_metrics,
1352
+ });
1316
1353
  }
1317
1354
  )
1318
1355
  .command(
@@ -1362,6 +1399,9 @@ function createCLIParser(argv: string[]) {
1362
1399
  prefix
1363
1400
  );
1364
1401
  logger.log(JSON.stringify(results, undefined, 2));
1402
+ await metrics.sendMetricsEvent("list kv keys", {
1403
+ sendMetrics: config.send_metrics,
1404
+ });
1365
1405
  }
1366
1406
  )
1367
1407
  .command(
@@ -1422,6 +1462,9 @@ function createCLIParser(argv: string[]) {
1422
1462
  } else {
1423
1463
  process.stdout.write(bufferKVValue);
1424
1464
  }
1465
+ await metrics.sendMetricsEvent("read kv value", {
1466
+ sendMetrics: config.send_metrics,
1467
+ });
1425
1468
  }
1426
1469
  )
1427
1470
  .command(
@@ -1468,6 +1511,9 @@ function createCLIParser(argv: string[]) {
1468
1511
  const accountId = await requireAuth(config);
1469
1512
 
1470
1513
  await deleteKVKeyValue(accountId, namespaceId, key);
1514
+ await metrics.sendMetricsEvent("delete kv key-value", {
1515
+ sendMetrics: config.send_metrics,
1516
+ });
1471
1517
  }
1472
1518
  );
1473
1519
  }
@@ -1572,6 +1618,9 @@ function createCLIParser(argv: string[]) {
1572
1618
 
1573
1619
  const accountId = await requireAuth(config);
1574
1620
  await putKVBulkKeyValue(accountId, namespaceId, content);
1621
+ await metrics.sendMetricsEvent("write kv key-values (bulk)", {
1622
+ sendMetrics: config.send_metrics,
1623
+ });
1575
1624
 
1576
1625
  logger.log("Success!");
1577
1626
  }
@@ -1662,6 +1711,9 @@ function createCLIParser(argv: string[]) {
1662
1711
  const accountId = await requireAuth(config);
1663
1712
 
1664
1713
  await deleteKVBulkKeyValue(accountId, namespaceId, content);
1714
+ await metrics.sendMetricsEvent("delete kv key-values (bulk)", {
1715
+ sendMetrics: config.send_metrics,
1716
+ });
1665
1717
 
1666
1718
  logger.log("Success!");
1667
1719
  }
@@ -1701,6 +1753,9 @@ function createCLIParser(argv: string[]) {
1701
1753
  logger.log(`Creating bucket ${args.name}.`);
1702
1754
  await createR2Bucket(accountId, args.name);
1703
1755
  logger.log(`Created bucket ${args.name}.`);
1756
+ await metrics.sendMetricsEvent("create r2 bucket", {
1757
+ sendMetrics: config.send_metrics,
1758
+ });
1704
1759
  }
1705
1760
  );
1706
1761
 
@@ -1710,6 +1765,9 @@ function createCLIParser(argv: string[]) {
1710
1765
  const accountId = await requireAuth(config);
1711
1766
 
1712
1767
  logger.log(JSON.stringify(await listR2Buckets(accountId), null, 2));
1768
+ await metrics.sendMetricsEvent("list r2 buckets", {
1769
+ sendMetrics: config.send_metrics,
1770
+ });
1713
1771
  });
1714
1772
 
1715
1773
  r2BucketYargs.command(
@@ -1732,6 +1790,9 @@ function createCLIParser(argv: string[]) {
1732
1790
  logger.log(`Deleting bucket ${args.name}.`);
1733
1791
  await deleteR2Bucket(accountId, args.name);
1734
1792
  logger.log(`Deleted bucket ${args.name}.`);
1793
+ await metrics.sendMetricsEvent("delete r2 bucket", {
1794
+ sendMetrics: config.send_metrics,
1795
+ });
1735
1796
  }
1736
1797
  );
1737
1798
  return r2BucketYargs;
@@ -1800,6 +1861,10 @@ function createCLIParser(argv: string[]) {
1800
1861
  return;
1801
1862
  }
1802
1863
  await login();
1864
+ const config = readConfig(args.config as ConfigPath, args);
1865
+ await metrics.sendMetricsEvent("login user", {
1866
+ sendMetrics: config.send_metrics,
1867
+ });
1803
1868
 
1804
1869
  // TODO: would be nice if it optionally saved login
1805
1870
  // credentials inside node_modules/.cache or something
@@ -1816,6 +1881,10 @@ function createCLIParser(argv: string[]) {
1816
1881
  async () => {
1817
1882
  await printWranglerBanner();
1818
1883
  await logout();
1884
+ const config = readConfig(undefined, {});
1885
+ await metrics.sendMetricsEvent("logout user", {
1886
+ sendMetrics: config.send_metrics,
1887
+ });
1819
1888
  }
1820
1889
  );
1821
1890
 
@@ -1827,6 +1896,10 @@ function createCLIParser(argv: string[]) {
1827
1896
  async () => {
1828
1897
  await printWranglerBanner();
1829
1898
  await whoami();
1899
+ const config = readConfig(undefined, {});
1900
+ await metrics.sendMetricsEvent("view accounts", {
1901
+ sendMetrics: config.send_metrics,
1902
+ });
1830
1903
  }
1831
1904
  );
1832
1905
 
@@ -0,0 +1,4 @@
1
+ export { getMetricsDispatcher } from "./metrics-dispatcher";
2
+ export type { Properties } from "./metrics-dispatcher";
3
+ export { getMetricsConfig } from "./metrics-config";
4
+ export * from "./send-event";
@@ -0,0 +1,14 @@
1
+ import isCI from "is-ci";
2
+
3
+ /**
4
+ * Use this object to find out if we are currently running in a continuous integration environment.
5
+ *
6
+ * The isCI constant imported above cannot be easily mocked for testing.
7
+ * By wrapping this up in a method on an object, it results in clean and testable code.
8
+ */
9
+ export const CI = {
10
+ /** Is Wrangler currently running in a CI? */
11
+ isCI() {
12
+ return isCI;
13
+ },
14
+ };