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.
- package/bin/wrangler.js +36 -5
- package/package.json +2 -2
- package/src/__tests__/configuration.test.ts +11 -7
- package/src/__tests__/dev.test.tsx +44 -0
- package/src/__tests__/helpers/run-in-tmp.ts +2 -2
- package/src/__tests__/metrics.test.ts +445 -0
- package/src/__tests__/test-old-node-version.js +31 -0
- package/src/config/config.ts +8 -0
- package/src/config/validation.ts +9 -0
- package/src/config-cache.ts +2 -1
- package/src/dev/dev.tsx +28 -18
- package/src/dev/local.tsx +7 -4
- package/src/dev/remote.tsx +5 -1
- package/src/dev.tsx +7 -1
- package/src/index.tsx +73 -0
- package/src/metrics/index.ts +4 -0
- package/src/metrics/is-ci.ts +14 -0
- package/src/metrics/metrics-config.ts +239 -0
- package/src/metrics/metrics-dispatcher.ts +95 -0
- package/src/metrics/send-event.ts +92 -0
- package/src/pages/build.tsx +2 -0
- package/src/pages/deployments.tsx +6 -1
- package/src/pages/dev.tsx +4 -0
- package/src/pages/projects.tsx +7 -1
- package/src/pages/publish.tsx +3 -0
- package/src/pages/upload.tsx +2 -2
- package/src/pubsub/pubsub-commands.tsx +46 -0
- package/src/user/user.tsx +2 -1
- package/src/whoami.tsx +2 -1
- package/src/worker-namespace.ts +16 -0
- package/wrangler-dist/cli.js +1619 -1002
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { readFileSync, mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { fetchResult } from "../cfetch";
|
|
6
|
+
import { getConfigCache, saveToConfigCache } from "../config-cache";
|
|
7
|
+
import { confirm } from "../dialogs";
|
|
8
|
+
import { getEnvironmentVariableFactory } from "../environment-variables";
|
|
9
|
+
import isInteractive from "../is-interactive";
|
|
10
|
+
import { logger } from "../logger";
|
|
11
|
+
import { getAPIToken } from "../user";
|
|
12
|
+
import { CI } from "./is-ci";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The date that the metrics being gathered was last updated in a way that would require
|
|
16
|
+
* the user to give their permission again.
|
|
17
|
+
*
|
|
18
|
+
* When reading from a config file, we check the recorded date in the config file against
|
|
19
|
+
* this one here. We ignore the permissions set in the the file if the recorded date is older.
|
|
20
|
+
* This allows us to prompt the user to re-opt-in when we make substantive changes to our metrics
|
|
21
|
+
* gathering.
|
|
22
|
+
*/
|
|
23
|
+
export const CURRENT_METRICS_DATE = new Date(2022, 6, 4);
|
|
24
|
+
export const USER_ID_CACHE_PATH = "user-id.json";
|
|
25
|
+
|
|
26
|
+
export const getWranglerSendMetricsFromEnv = getEnvironmentVariableFactory({
|
|
27
|
+
variableName: "WRANGLER_SEND_METRICS",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export interface MetricsConfigOptions {
|
|
31
|
+
/**
|
|
32
|
+
* Defines whether to send metrics to Cloudflare:
|
|
33
|
+
* If defined, then use this value for whether the dispatch is enabled.
|
|
34
|
+
* Otherwise, infer the enabled value from the user configuration.
|
|
35
|
+
*/
|
|
36
|
+
sendMetrics?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* When true, do not make any CF API requests.
|
|
39
|
+
*/
|
|
40
|
+
offline?: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The information needed to set up the MetricsDispatcher.
|
|
45
|
+
*/
|
|
46
|
+
export interface MetricsConfig {
|
|
47
|
+
/** True if usage tracking is enabled. */
|
|
48
|
+
enabled: boolean;
|
|
49
|
+
/** A UID that identifies this user and machine pair for Wrangler. */
|
|
50
|
+
deviceId: string;
|
|
51
|
+
/** The currently logged in user - undefined if not logged in. */
|
|
52
|
+
userId: string | undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Get hold of the permissions and device-id for metrics dispatch.
|
|
57
|
+
*
|
|
58
|
+
* The device-id is just a unique identifier sent along with events to help
|
|
59
|
+
* to collate metrics. Once generated, this id is cached in the metrics config file.
|
|
60
|
+
*
|
|
61
|
+
* The permissions define whether we can send metrics or not. They can come from a variety of places:
|
|
62
|
+
* - the `send_metrics` setting in `wrangler.toml`
|
|
63
|
+
* - a cached response from the current user
|
|
64
|
+
* - prompting the user to opt-in to metrics
|
|
65
|
+
*
|
|
66
|
+
* If the user was prompted to opt-in, then their response is cached in the metrics config file.
|
|
67
|
+
*
|
|
68
|
+
* If the current process is not interactive then we will cannot prompt the user and just assume
|
|
69
|
+
* we cannot send metrics if there is no cached or project-level preference available.
|
|
70
|
+
*/
|
|
71
|
+
export async function getMetricsConfig({
|
|
72
|
+
sendMetrics,
|
|
73
|
+
offline = false,
|
|
74
|
+
}: MetricsConfigOptions): Promise<MetricsConfig> {
|
|
75
|
+
const config = readMetricsConfig();
|
|
76
|
+
const deviceId = getDeviceId(config);
|
|
77
|
+
const userId = await getUserId(offline);
|
|
78
|
+
|
|
79
|
+
// If the WRANGLER_SEND_METRICS environment variable has been set use that
|
|
80
|
+
// and ignore everything else.
|
|
81
|
+
const sendMetricsEnv = getWranglerSendMetricsFromEnv();
|
|
82
|
+
if (sendMetricsEnv !== undefined) {
|
|
83
|
+
return {
|
|
84
|
+
enabled: sendMetricsEnv.toLowerCase() === "true",
|
|
85
|
+
deviceId,
|
|
86
|
+
userId,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// If the project is explicitly set the `send_metrics` options in `wrangler.toml`
|
|
91
|
+
// then use that and ignore any user preference.
|
|
92
|
+
if (sendMetrics !== undefined) {
|
|
93
|
+
return { enabled: sendMetrics, deviceId, userId };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Get the user preference from the metrics config.
|
|
97
|
+
const permission = config.permission;
|
|
98
|
+
if (permission !== undefined) {
|
|
99
|
+
if (new Date(permission.date) >= CURRENT_METRICS_DATE) {
|
|
100
|
+
return { enabled: permission.enabled, deviceId, userId };
|
|
101
|
+
} else if (permission.enabled) {
|
|
102
|
+
logger.log(
|
|
103
|
+
"Usage metrics tracking has changed since you last granted permission."
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// We couldn't get the metrics permission from the project-level nor the user-level config.
|
|
109
|
+
// If we are not interactive or in a CI build then just bail out.
|
|
110
|
+
if (!isInteractive() || CI.isCI()) {
|
|
111
|
+
return { enabled: false, deviceId, userId };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Otherwise, let's ask the user and store the result in the metrics config.
|
|
115
|
+
const enabled = await confirm(
|
|
116
|
+
"Would you like to help improve Wrangler by sending usage metrics to Cloudflare?"
|
|
117
|
+
);
|
|
118
|
+
logger.log(
|
|
119
|
+
`Your choice has been saved in the following file: ${path.relative(
|
|
120
|
+
process.cwd(),
|
|
121
|
+
getMetricsConfigPath()
|
|
122
|
+
)}.\n\n` +
|
|
123
|
+
" You can override the user level setting for a project in `wrangler.toml`:\n\n" +
|
|
124
|
+
" - to disable sending metrics for a project: `send_metrics = false`\n" +
|
|
125
|
+
" - to enable sending metrics for a project: `send_metrics = true`"
|
|
126
|
+
);
|
|
127
|
+
writeMetricsConfig({
|
|
128
|
+
permission: {
|
|
129
|
+
enabled,
|
|
130
|
+
date: CURRENT_METRICS_DATE,
|
|
131
|
+
},
|
|
132
|
+
deviceId,
|
|
133
|
+
});
|
|
134
|
+
return { enabled, deviceId, userId };
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Stringify and write the given info to the metrics config file.
|
|
139
|
+
*/
|
|
140
|
+
export function writeMetricsConfig(config: MetricsConfigFile) {
|
|
141
|
+
mkdirSync(path.dirname(getMetricsConfigPath()), { recursive: true });
|
|
142
|
+
writeFileSync(
|
|
143
|
+
getMetricsConfigPath(),
|
|
144
|
+
JSON.stringify(
|
|
145
|
+
config,
|
|
146
|
+
(_key, value) => (value instanceof Date ? value.toISOString() : value),
|
|
147
|
+
"\t"
|
|
148
|
+
)
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Read and parse the metrics config file.
|
|
154
|
+
*/
|
|
155
|
+
export function readMetricsConfig(): MetricsConfigFile {
|
|
156
|
+
try {
|
|
157
|
+
const config = readFileSync(getMetricsConfigPath(), "utf8");
|
|
158
|
+
return JSON.parse(config, (key, value) =>
|
|
159
|
+
key === "date" ? new Date(value) : value
|
|
160
|
+
);
|
|
161
|
+
} catch {
|
|
162
|
+
return {};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Get the path to the metrics config file.
|
|
168
|
+
*/
|
|
169
|
+
function getMetricsConfigPath(): string {
|
|
170
|
+
return path.resolve(os.homedir(), ".wrangler/config/metrics.json");
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The format of the metrics config file.
|
|
175
|
+
*/
|
|
176
|
+
export interface MetricsConfigFile {
|
|
177
|
+
permission?: {
|
|
178
|
+
/** True if Wrangler should send metrics to Cloudflare. */
|
|
179
|
+
enabled: boolean;
|
|
180
|
+
/** The date that this permission was set. */
|
|
181
|
+
date: Date;
|
|
182
|
+
};
|
|
183
|
+
/** A unique UUID that identifies this device for metrics purposes. */
|
|
184
|
+
deviceId?: string;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Returns an ID that uniquely identifies Wrangler on this device to help collate events.
|
|
189
|
+
*
|
|
190
|
+
* Once created this ID is stored in the metrics config file.
|
|
191
|
+
*/
|
|
192
|
+
function getDeviceId(config: MetricsConfigFile) {
|
|
193
|
+
// Get or create the deviceId.
|
|
194
|
+
const deviceId = config.deviceId ?? randomUUID();
|
|
195
|
+
if (config.deviceId === undefined) {
|
|
196
|
+
// We had to create a new deviceID so store it now.
|
|
197
|
+
writeMetricsConfig({ ...config, deviceId });
|
|
198
|
+
}
|
|
199
|
+
return deviceId;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Returns the ID of the current user, which will be sent with each event.
|
|
204
|
+
*
|
|
205
|
+
* The ID is retrieved from the CF API `/user` endpoint if the user is authenticated and then
|
|
206
|
+
* stored in the `node_modules/.cache`.
|
|
207
|
+
*
|
|
208
|
+
* If it is not possible to retrieve the ID (perhaps the user is not logged in) then we just use
|
|
209
|
+
* `undefined`.
|
|
210
|
+
*/
|
|
211
|
+
async function getUserId(offline: boolean) {
|
|
212
|
+
// Get the userId from the cache.
|
|
213
|
+
// If it has not been found in the cache and we are not offline then make an API call to get it.
|
|
214
|
+
// If we can't work in out then just use `anonymous`.
|
|
215
|
+
let userId = getConfigCache<{ userId: string }>(USER_ID_CACHE_PATH).userId;
|
|
216
|
+
if (userId === undefined && !offline) {
|
|
217
|
+
userId = await fetchUserId();
|
|
218
|
+
if (userId !== undefined) {
|
|
219
|
+
saveToConfigCache(USER_ID_CACHE_PATH, { userId });
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return userId;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Ask the Cloudflare API for the User ID of the current user.
|
|
227
|
+
*
|
|
228
|
+
* We will only do this if we are not "offline", e.g. not running `wrangler dev --local`.
|
|
229
|
+
* Quietly return undefined if anything goes wrong.
|
|
230
|
+
*/
|
|
231
|
+
async function fetchUserId(): Promise<string | undefined> {
|
|
232
|
+
try {
|
|
233
|
+
return getAPIToken()
|
|
234
|
+
? (await fetchResult<{ id: string }>("/user")).id
|
|
235
|
+
: undefined;
|
|
236
|
+
} catch (e) {
|
|
237
|
+
return undefined;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { fetch } from "undici";
|
|
2
|
+
import { version as wranglerVersion } from "../../package.json";
|
|
3
|
+
import { logger } from "../logger";
|
|
4
|
+
import { getMetricsConfig } from "./metrics-config";
|
|
5
|
+
import type { MetricsConfigOptions } from "./metrics-config";
|
|
6
|
+
|
|
7
|
+
// The SPARROW_SOURCE_KEY is provided at esbuild time as a `define` for production and beta
|
|
8
|
+
// releases. Otherwise it is left undefined, which automatically disables metrics requests.
|
|
9
|
+
declare const SPARROW_SOURCE_KEY: string;
|
|
10
|
+
const SPARROW_URL = "https://sparrow.cloudflare.com";
|
|
11
|
+
|
|
12
|
+
export async function getMetricsDispatcher(options: MetricsConfigOptions) {
|
|
13
|
+
return {
|
|
14
|
+
/**
|
|
15
|
+
* Dispatch a event to the analytics target.
|
|
16
|
+
*
|
|
17
|
+
* The event should follow these conventions
|
|
18
|
+
* - name is of the form `[action] [object]` (lower case)
|
|
19
|
+
* - additional properties are camelCased
|
|
20
|
+
*/
|
|
21
|
+
async sendEvent(name: string, properties: Properties = {}): Promise<void> {
|
|
22
|
+
await dispatch({ type: "event", name, properties });
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Dispatch a user profile information to the analytics target.
|
|
27
|
+
*
|
|
28
|
+
* This call can be used to inform the analytics target of relevant properties associated
|
|
29
|
+
* with the current user.
|
|
30
|
+
*/
|
|
31
|
+
async identify(properties: Properties): Promise<void> {
|
|
32
|
+
await dispatch({ type: "identify", name: "identify", properties });
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
async function dispatch(event: {
|
|
37
|
+
type: "identify" | "event";
|
|
38
|
+
name: string;
|
|
39
|
+
properties: Properties;
|
|
40
|
+
}): Promise<void> {
|
|
41
|
+
if (!SPARROW_SOURCE_KEY) {
|
|
42
|
+
logger.debug(
|
|
43
|
+
"Metrics dispatcher: Source Key not provided. Be sure to initialize before sending events.",
|
|
44
|
+
event
|
|
45
|
+
);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Lazily get the config for this dispatcher only when an event is being dispatched.
|
|
50
|
+
// We must await this since it might trigger user interaction that would break other UI
|
|
51
|
+
// in Wrangler if it was allowed to run in parallel.
|
|
52
|
+
const metricsConfig = await getMetricsConfig(options);
|
|
53
|
+
if (!metricsConfig.enabled) {
|
|
54
|
+
logger.debug(
|
|
55
|
+
`Metrics dispatcher: Dispatching disabled - would have sent ${JSON.stringify(
|
|
56
|
+
event
|
|
57
|
+
)}.`
|
|
58
|
+
);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
logger.debug(`Metrics dispatcher: Posting data ${JSON.stringify(event)}`);
|
|
63
|
+
const body = JSON.stringify({
|
|
64
|
+
deviceId: metricsConfig.deviceId,
|
|
65
|
+
userId: metricsConfig.userId,
|
|
66
|
+
event: event.name,
|
|
67
|
+
properties: {
|
|
68
|
+
category: "Workers",
|
|
69
|
+
wranglerVersion,
|
|
70
|
+
...event.properties,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Do not await this fetch call.
|
|
75
|
+
// Just fire-and-forget, otherwise we might slow down the rest of Wrangler.
|
|
76
|
+
fetch(`${SPARROW_URL}/api/v1/${event.type}`, {
|
|
77
|
+
method: "POST",
|
|
78
|
+
headers: {
|
|
79
|
+
Accept: "*/*",
|
|
80
|
+
"Content-Type": "application/json",
|
|
81
|
+
"Sparrow-Source-Key": SPARROW_SOURCE_KEY,
|
|
82
|
+
},
|
|
83
|
+
mode: "cors",
|
|
84
|
+
keepalive: true,
|
|
85
|
+
body,
|
|
86
|
+
}).catch((e) => {
|
|
87
|
+
logger.debug(
|
|
88
|
+
"Metrics dispatcher: Failed to send request:",
|
|
89
|
+
(e as Error).message
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type Properties = Record<string, unknown>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { logger } from "../logger";
|
|
2
|
+
import { getMetricsDispatcher } from "./metrics-dispatcher";
|
|
3
|
+
import type { MetricsConfigOptions } from "./metrics-config";
|
|
4
|
+
import type { Properties } from "./metrics-dispatcher";
|
|
5
|
+
|
|
6
|
+
/** These are event names used by this wrangler client. */
|
|
7
|
+
export type EventNames =
|
|
8
|
+
| "view accounts"
|
|
9
|
+
| "deploy worker script"
|
|
10
|
+
| "begin log stream"
|
|
11
|
+
| "end log stream"
|
|
12
|
+
| "create encrypted variable"
|
|
13
|
+
| "delete encrypted variable"
|
|
14
|
+
| "list encrypted variables"
|
|
15
|
+
| "create kv namespace"
|
|
16
|
+
| "list kv namespaces"
|
|
17
|
+
| "delete kv namespace"
|
|
18
|
+
| "write kv key-value"
|
|
19
|
+
| "list kv keys"
|
|
20
|
+
| "read kv value"
|
|
21
|
+
| "delete kv key-value"
|
|
22
|
+
| "write kv key-values (bulk)"
|
|
23
|
+
| "delete kv key-values (bulk)"
|
|
24
|
+
| "create r2 bucket"
|
|
25
|
+
| "list r2 buckets"
|
|
26
|
+
| "delete r2 bucket"
|
|
27
|
+
| "login user"
|
|
28
|
+
| "logout user"
|
|
29
|
+
| "create pubsub namespace"
|
|
30
|
+
| "list pubsub namespaces"
|
|
31
|
+
| "delete pubsub namespace"
|
|
32
|
+
| "view pubsub namespace"
|
|
33
|
+
| "create pubsub broker"
|
|
34
|
+
| "update pubsub broker"
|
|
35
|
+
| "list pubsub brokers"
|
|
36
|
+
| "delete pubsub broker"
|
|
37
|
+
| "view pubsub broker"
|
|
38
|
+
| "issue pubsub broker credentials"
|
|
39
|
+
| "revoke pubsub broker credentials"
|
|
40
|
+
| "unrevoke pubsub broker credentials"
|
|
41
|
+
| "list pubsub broker revoked credentials"
|
|
42
|
+
| "list pubsub broker public-keys"
|
|
43
|
+
| "list worker namespaces"
|
|
44
|
+
| "view worker namespace"
|
|
45
|
+
| "create worker namespace"
|
|
46
|
+
| "delete worker namespace"
|
|
47
|
+
| "rename worker namespace"
|
|
48
|
+
| "create pages project"
|
|
49
|
+
| "list pages projects"
|
|
50
|
+
| "deploy pages project"
|
|
51
|
+
| "list pages projects deployments"
|
|
52
|
+
| "build pages functions"
|
|
53
|
+
| "run dev"
|
|
54
|
+
| "run pages dev";
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Send a metrics event, with no extra properties, to Cloudflare, if usage tracking is enabled.
|
|
58
|
+
*
|
|
59
|
+
* This overload assumes that you do not want to configure analytics with options.
|
|
60
|
+
*/
|
|
61
|
+
export function sendMetricsEvent(event: EventNames): Promise<void>;
|
|
62
|
+
/**
|
|
63
|
+
* Send a metrics event, with no extra properties, to Cloudflare, if usage tracking is enabled.
|
|
64
|
+
*/
|
|
65
|
+
export function sendMetricsEvent(
|
|
66
|
+
event: EventNames,
|
|
67
|
+
options: MetricsConfigOptions
|
|
68
|
+
): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Send a metrics event to Cloudflare, if usage tracking is enabled.
|
|
71
|
+
*
|
|
72
|
+
* Generally you should pass the `send_metrics` property from the wrangler.toml config here,
|
|
73
|
+
* which would override any user permissions.
|
|
74
|
+
*/
|
|
75
|
+
export function sendMetricsEvent(
|
|
76
|
+
event: EventNames,
|
|
77
|
+
properties: Properties,
|
|
78
|
+
options: MetricsConfigOptions
|
|
79
|
+
): Promise<void>;
|
|
80
|
+
export async function sendMetricsEvent(
|
|
81
|
+
event: EventNames,
|
|
82
|
+
...args: [] | [MetricsConfigOptions] | [Properties, MetricsConfigOptions]
|
|
83
|
+
): Promise<void> {
|
|
84
|
+
try {
|
|
85
|
+
const options = args.pop() ?? {};
|
|
86
|
+
const properties = (args.pop() ?? {}) as Properties;
|
|
87
|
+
const metricsDispatcher = await getMetricsDispatcher(options);
|
|
88
|
+
await metricsDispatcher.sendEvent(event, properties);
|
|
89
|
+
} catch (err) {
|
|
90
|
+
logger.debug("Error sending metrics event", err);
|
|
91
|
+
}
|
|
92
|
+
}
|
package/src/pages/build.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import { writeFileSync } from "node:fs";
|
|
|
2
2
|
import { tmpdir } from "node:os";
|
|
3
3
|
import { dirname, join } from "node:path";
|
|
4
4
|
import { logger } from "../logger";
|
|
5
|
+
import * as metrics from "../metrics";
|
|
5
6
|
import { toUrlPath } from "../paths";
|
|
6
7
|
import { isInPagesCI } from "./constants";
|
|
7
8
|
import { buildPlugin } from "./functions/buildPlugin";
|
|
@@ -120,6 +121,7 @@ export const Handler = async ({
|
|
|
120
121
|
buildOutputDirectory,
|
|
121
122
|
nodeCompat,
|
|
122
123
|
});
|
|
124
|
+
await metrics.sendMetricsEvent("build pages functions");
|
|
123
125
|
};
|
|
124
126
|
|
|
125
127
|
export async function buildFunctions({
|
|
@@ -6,6 +6,7 @@ import { format as timeagoFormat } from "timeago.js";
|
|
|
6
6
|
import { fetchResult } from "../cfetch";
|
|
7
7
|
import { getConfigCache, saveToConfigCache } from "../config-cache";
|
|
8
8
|
import { FatalError } from "../errors";
|
|
9
|
+
import * as metrics from "../metrics";
|
|
9
10
|
import { requireAuth } from "../user";
|
|
10
11
|
import { PAGES_CONFIG_CACHE_FILENAME } from "./constants";
|
|
11
12
|
import { listProjects } from "./projects";
|
|
@@ -97,5 +98,9 @@ export async function ListHandler({
|
|
|
97
98
|
account_id: accountId,
|
|
98
99
|
});
|
|
99
100
|
|
|
100
|
-
render(<Table data={data}></Table>, {
|
|
101
|
+
const { unmount } = render(<Table data={data}></Table>, {
|
|
102
|
+
patchConsole: false,
|
|
103
|
+
});
|
|
104
|
+
unmount();
|
|
105
|
+
await metrics.sendMetricsEvent("list pages projects deployments");
|
|
101
106
|
}
|
package/src/pages/dev.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import { getType } from "mime";
|
|
|
8
8
|
import { getVarsForDev } from "../dev/dev-vars";
|
|
9
9
|
import { FatalError } from "../errors";
|
|
10
10
|
import { logger } from "../logger";
|
|
11
|
+
import * as metrics from "../metrics";
|
|
11
12
|
import { getRequestContextCheckOptions } from "../miniflare-cli/request-context";
|
|
12
13
|
import openInBrowser from "../open-in-browser";
|
|
13
14
|
import { buildFunctions } from "./build";
|
|
@@ -172,6 +173,7 @@ export const Handler = async ({
|
|
|
172
173
|
buildOutputDirectory: directory,
|
|
173
174
|
nodeCompat,
|
|
174
175
|
});
|
|
176
|
+
await metrics.sendMetricsEvent("build pages functions");
|
|
175
177
|
} catch {}
|
|
176
178
|
|
|
177
179
|
watch([functionsDirectory], {
|
|
@@ -187,6 +189,7 @@ export const Handler = async ({
|
|
|
187
189
|
buildOutputDirectory: directory,
|
|
188
190
|
nodeCompat,
|
|
189
191
|
});
|
|
192
|
+
await metrics.sendMetricsEvent("build pages functions");
|
|
190
193
|
});
|
|
191
194
|
|
|
192
195
|
miniflareArgs = {
|
|
@@ -318,6 +321,7 @@ export const Handler = async ({
|
|
|
318
321
|
// `startServer` might throw if user code contains errors
|
|
319
322
|
const server = await miniflare.startServer();
|
|
320
323
|
logger.log(`Serving at http://localhost:${port}/`);
|
|
324
|
+
await metrics.sendMetricsEvent("run pages dev");
|
|
321
325
|
|
|
322
326
|
if (process.env.BROWSER !== "none") {
|
|
323
327
|
await openInBrowser(`http://localhost:${port}/`);
|
package/src/pages/projects.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import { getConfigCache, saveToConfigCache } from "../config-cache";
|
|
|
8
8
|
import { prompt } from "../dialogs";
|
|
9
9
|
import { FatalError } from "../errors";
|
|
10
10
|
import { logger } from "../logger";
|
|
11
|
+
import * as metrics from "../metrics";
|
|
11
12
|
import { requireAuth } from "../user";
|
|
12
13
|
import { PAGES_CONFIG_CACHE_FILENAME } from "./constants";
|
|
13
14
|
import { pagesBetaWarning } from "./utils";
|
|
@@ -43,7 +44,11 @@ export async function ListHandler() {
|
|
|
43
44
|
account_id: accountId,
|
|
44
45
|
});
|
|
45
46
|
|
|
46
|
-
render(<Table data={data}></Table>, {
|
|
47
|
+
const { unmount } = render(<Table data={data}></Table>, {
|
|
48
|
+
patchConsole: false,
|
|
49
|
+
});
|
|
50
|
+
unmount();
|
|
51
|
+
await metrics.sendMetricsEvent("list pages projects");
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
export const listProjects = async ({
|
|
@@ -154,4 +159,5 @@ export async function CreateHandler({
|
|
|
154
159
|
logger.log(
|
|
155
160
|
`To deploy a folder of assets, run 'wrangler pages publish [directory]'.`
|
|
156
161
|
);
|
|
162
|
+
await metrics.sendMetricsEvent("create pages project");
|
|
157
163
|
}
|
package/src/pages/publish.tsx
CHANGED
|
@@ -12,6 +12,7 @@ import { getConfigCache, saveToConfigCache } from "../config-cache";
|
|
|
12
12
|
import { prompt } from "../dialogs";
|
|
13
13
|
import { FatalError } from "../errors";
|
|
14
14
|
import { logger } from "../logger";
|
|
15
|
+
import * as metrics from "../metrics";
|
|
15
16
|
import { requireAuth } from "../user";
|
|
16
17
|
import { buildFunctions } from "./build";
|
|
17
18
|
import { PAGES_CONFIG_CACHE_FILENAME } from "./constants";
|
|
@@ -193,6 +194,7 @@ export const Handler = async ({
|
|
|
193
194
|
});
|
|
194
195
|
|
|
195
196
|
logger.log(`✨ Successfully created the '${projectName}' project.`);
|
|
197
|
+
await metrics.sendMetricsEvent("create pages project");
|
|
196
198
|
break;
|
|
197
199
|
}
|
|
198
200
|
}
|
|
@@ -332,4 +334,5 @@ export const Handler = async ({
|
|
|
332
334
|
logger.log(
|
|
333
335
|
`✨ Deployment complete! Take a peek over at ${deploymentResponse.url}`
|
|
334
336
|
);
|
|
337
|
+
await metrics.sendMetricsEvent("deploy pages project");
|
|
335
338
|
};
|
package/src/pages/upload.tsx
CHANGED
|
@@ -282,9 +282,9 @@ export const upload = async (
|
|
|
282
282
|
});
|
|
283
283
|
} catch (e) {
|
|
284
284
|
if (attempts < MAX_UPLOAD_ATTEMPTS) {
|
|
285
|
-
//
|
|
285
|
+
// Exponential backoff, 1 second first time, then 2 second, then 4 second etc.
|
|
286
286
|
await new Promise((resolvePromise) =>
|
|
287
|
-
setTimeout(resolvePromise, attempts++ * 1000)
|
|
287
|
+
setTimeout(resolvePromise, Math.pow(2, attempts++) * 1000)
|
|
288
288
|
);
|
|
289
289
|
|
|
290
290
|
if ((e as { code: number }).code === 8000013) {
|