wrangler 2.1.14 → 2.2.0

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.
Files changed (75) hide show
  1. package/miniflare-dist/index.mjs +3 -1
  2. package/package.json +2 -1
  3. package/src/__tests__/access.test.ts +25 -0
  4. package/src/__tests__/api-dev.test.ts +1 -1
  5. package/src/__tests__/api-devregistry.test.js +2 -2
  6. package/src/__tests__/configuration.test.ts +119 -2
  7. package/src/__tests__/d1.test.ts +2 -0
  8. package/src/__tests__/deployments.test.ts +22 -22
  9. package/src/__tests__/dev.test.tsx +167 -15
  10. package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
  11. package/src/__tests__/helpers/msw/handlers/deployments.ts +22 -43
  12. package/src/__tests__/helpers/msw/handlers/zones.ts +22 -0
  13. package/src/__tests__/helpers/msw/index.ts +4 -0
  14. package/src/__tests__/index.test.ts +42 -33
  15. package/src/__tests__/init.test.ts +88 -4
  16. package/src/__tests__/jest.setup.ts +11 -0
  17. package/src/__tests__/kv.test.ts +400 -400
  18. package/src/__tests__/pages.test.ts +140 -28
  19. package/src/__tests__/publish.test.ts +1161 -647
  20. package/src/__tests__/pubsub.test.ts +3 -0
  21. package/src/__tests__/queues.test.ts +371 -0
  22. package/src/__tests__/r2.test.ts +57 -52
  23. package/src/__tests__/worker-namespace.test.ts +15 -10
  24. package/src/bundle-reporter.tsx +41 -2
  25. package/src/bundle.ts +59 -30
  26. package/src/cli.ts +0 -1
  27. package/src/config/environment.ts +50 -0
  28. package/src/config/index.ts +41 -0
  29. package/src/config/validation.ts +173 -0
  30. package/src/create-worker-preview.ts +10 -3
  31. package/src/create-worker-upload-form.ts +12 -0
  32. package/src/d1/backups.tsx +11 -5
  33. package/src/d1/execute.tsx +52 -47
  34. package/src/d1/index.ts +2 -1
  35. package/src/delete.ts +7 -10
  36. package/src/deployments.ts +73 -0
  37. package/src/deprecated/index.ts +9 -24
  38. package/src/dev/dev-vars.ts +11 -8
  39. package/src/dev/dev.tsx +12 -0
  40. package/src/dev/local.tsx +26 -0
  41. package/src/dev/remote.tsx +2 -0
  42. package/src/dev/start-server.ts +7 -0
  43. package/src/dev/use-esbuild.ts +12 -5
  44. package/src/dev.tsx +12 -9
  45. package/src/dispatch-namespace.ts +4 -3
  46. package/src/index.tsx +61 -45
  47. package/src/init.ts +4 -4
  48. package/src/inspect.ts +21 -1
  49. package/src/is-interactive.ts +4 -0
  50. package/src/kv/index.ts +5 -54
  51. package/src/logger.ts +12 -0
  52. package/src/pages/constants.ts +2 -0
  53. package/src/pages/upload.tsx +42 -15
  54. package/src/proxy.ts +38 -6
  55. package/src/publish/index.ts +11 -8
  56. package/src/publish/publish.ts +151 -30
  57. package/src/pubsub/pubsub-commands.tsx +3 -2
  58. package/src/queues/cli/commands/consumer/add.ts +71 -0
  59. package/src/queues/cli/commands/consumer/index.ts +22 -0
  60. package/src/queues/cli/commands/consumer/remove.ts +38 -0
  61. package/src/queues/cli/commands/create.ts +25 -0
  62. package/src/queues/cli/commands/delete.ts +26 -0
  63. package/src/queues/cli/commands/index.ts +33 -0
  64. package/src/queues/cli/commands/list.ts +25 -0
  65. package/src/queues/client.ts +135 -0
  66. package/src/secret/index.ts +14 -39
  67. package/src/tail/index.ts +5 -8
  68. package/src/user/access.ts +69 -0
  69. package/src/worker.ts +7 -0
  70. package/src/yargs-types.ts +15 -2
  71. package/src/zones.ts +31 -5
  72. package/templates/pages-template-plugin.ts +4 -0
  73. package/templates/pages-template-worker.ts +21 -4
  74. package/wrangler-dist/cli.d.ts +42 -0
  75. package/wrangler-dist/cli.js +4559 -3228
@@ -38,6 +38,7 @@ describe("wrangler", () => {
38
38
 
39
39
  Flags:
40
40
  -c, --config Path to .toml configuration file [string]
41
+ -e, --env Environment to use for operations and .env files [string]
41
42
  -h, --help Show help [boolean]
42
43
  -v, --version Show version number [boolean]
43
44
 
@@ -68,6 +69,7 @@ describe("wrangler", () => {
68
69
 
69
70
  Flags:
70
71
  -c, --config Path to .toml configuration file [string]
72
+ -e, --env Environment to use for operations and .env files [string]
71
73
  -h, --help Show help [boolean]
72
74
  -v, --version Show version number [boolean]
73
75
 
@@ -158,6 +160,7 @@ describe("wrangler", () => {
158
160
 
159
161
  Flags:
160
162
  -c, --config Path to .toml configuration file [string]
163
+ -e, --env Environment to use for operations and .env files [string]
161
164
  -h, --help Show help [boolean]
162
165
  -v, --version Show version number [boolean]
163
166
 
@@ -0,0 +1,371 @@
1
+ import { type QueueResponse, type PostConsumerBody } from "../queues/client";
2
+ import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
3
+ import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
4
+ import { mockConsoleMethods } from "./helpers/mock-console";
5
+ import { runInTempDir } from "./helpers/run-in-tmp";
6
+ import { runWrangler } from "./helpers/run-wrangler";
7
+
8
+ describe("wrangler", () => {
9
+ mockAccountId();
10
+ mockApiToken();
11
+ runInTempDir();
12
+ const std = mockConsoleMethods();
13
+
14
+ afterEach(() => {
15
+ unsetAllMocks();
16
+ });
17
+
18
+ describe("queues", () => {
19
+ it("should show the correct help text", async () => {
20
+ await runWrangler("queues --help");
21
+ expect(std.err).toMatchInlineSnapshot(`""`);
22
+ expect(std.out).toMatchInlineSnapshot(`
23
+ "wrangler queues
24
+
25
+ 🆀 Configure Workers Queues
26
+
27
+ Commands:
28
+ wrangler queues list List Queues
29
+ wrangler queues create <name> Create a Queue
30
+ wrangler queues delete <name> Delete a Queue
31
+ wrangler queues consumer Configure Queue Consumers
32
+
33
+ Flags:
34
+ -c, --config Path to .toml configuration file [string]
35
+ -e, --env Environment to use for operations and .env files [string]
36
+ -h, --help Show help [boolean]
37
+ -v, --version Show version number [boolean]"
38
+ `);
39
+ });
40
+
41
+ describe("list", () => {
42
+ function mockListRequest(queues: QueueResponse[], page: number) {
43
+ const requests = { count: 0 };
44
+ setMockResponse(
45
+ "/accounts/:accountId/workers/queues",
46
+ ([_url, accountId], init, params) => {
47
+ requests.count++;
48
+ expect(params.get("page")).toEqual((page || 1).toString());
49
+ expect(accountId).toEqual("some-account-id");
50
+ expect(init).toEqual({});
51
+ return queues;
52
+ }
53
+ );
54
+ return requests;
55
+ }
56
+
57
+ it("should show the correct help text", async () => {
58
+ await runWrangler("queues list --help");
59
+ expect(std.err).toMatchInlineSnapshot(`""`);
60
+ expect(std.out).toMatchInlineSnapshot(`
61
+ "wrangler queues list
62
+
63
+ List Queues
64
+
65
+ Flags:
66
+ -c, --config Path to .toml configuration file [string]
67
+ -e, --env Environment to use for operations and .env files [string]
68
+ -h, --help Show help [boolean]
69
+ -v, --version Show version number [boolean]
70
+
71
+ Options:
72
+ --page Page number for pagination [number]"
73
+ `);
74
+ });
75
+
76
+ it("should list queues on page 1 with no --page", async () => {
77
+ const expectedQueues: QueueResponse[] = [
78
+ {
79
+ queue_name: "queue-1",
80
+ created_on: "01-01-2001",
81
+ modified_on: "01-01-2001",
82
+ },
83
+ {
84
+ queue_name: "queue-2",
85
+ created_on: "01-01-2001",
86
+ modified_on: "01-01-2001",
87
+ },
88
+ ];
89
+ const expectedPage = 1;
90
+ mockListRequest(expectedQueues, expectedPage);
91
+ await runWrangler("queues list");
92
+
93
+ expect(std.err).toMatchInlineSnapshot(`""`);
94
+ const buckets = JSON.parse(std.out);
95
+ expect(buckets).toEqual(expectedQueues);
96
+ });
97
+
98
+ it("should list queues using --page=2", async () => {
99
+ const expectedQueues: QueueResponse[] = [
100
+ {
101
+ queue_name: "queue-100",
102
+ created_on: "01-01-2001",
103
+ modified_on: "01-01-2001",
104
+ },
105
+ ];
106
+ const expectedPage = 2;
107
+ mockListRequest(expectedQueues, expectedPage);
108
+ await runWrangler("queues list --page=2");
109
+
110
+ expect(std.err).toMatchInlineSnapshot(`""`);
111
+ const buckets = JSON.parse(std.out);
112
+ expect(buckets).toEqual(expectedQueues);
113
+ });
114
+ });
115
+
116
+ describe("create", () => {
117
+ function mockCreateRequest(expectedQueueName: string) {
118
+ const requests = { count: 0 };
119
+ setMockResponse(
120
+ "/accounts/:accountId/workers/queues",
121
+ "POST",
122
+ ([_url, accountId], { body }) => {
123
+ expect(accountId).toEqual("some-account-id");
124
+ const queueName = JSON.parse(body as string).queue_name;
125
+ expect(queueName).toEqual(expectedQueueName);
126
+ requests.count += 1;
127
+ }
128
+ );
129
+ return requests;
130
+ }
131
+
132
+ it("should show the correct help text", async () => {
133
+ await runWrangler("queues create --help");
134
+ expect(std.err).toMatchInlineSnapshot(`""`);
135
+ expect(std.out).toMatchInlineSnapshot(`
136
+ "wrangler queues create <name>
137
+
138
+ Create a Queue
139
+
140
+ Positionals:
141
+ name The name of the queue [string] [required]
142
+
143
+ Flags:
144
+ -c, --config Path to .toml configuration file [string]
145
+ -e, --env Environment to use for operations and .env files [string]
146
+ -h, --help Show help [boolean]
147
+ -v, --version Show version number [boolean]"
148
+ `);
149
+ });
150
+
151
+ it("should create a queue", async () => {
152
+ const requests = mockCreateRequest("testQueue");
153
+ await runWrangler("queues create testQueue");
154
+ expect(std.out).toMatchInlineSnapshot(`
155
+ "Creating queue testQueue.
156
+ Created queue testQueue."
157
+ `);
158
+ expect(requests.count).toEqual(1);
159
+ });
160
+ });
161
+
162
+ describe("delete", () => {
163
+ function mockDeleteRequest(expectedQueueName: string) {
164
+ const requests = { count: 0 };
165
+ setMockResponse(
166
+ `/accounts/:accountId/workers/queues/${expectedQueueName}`,
167
+ "DELETE",
168
+ ([_url, accountId]) => {
169
+ expect(accountId).toEqual("some-account-id");
170
+ requests.count += 1;
171
+ }
172
+ );
173
+ return requests;
174
+ }
175
+
176
+ it("should show the correct help text", async () => {
177
+ await runWrangler("queues delete --help");
178
+ expect(std.err).toMatchInlineSnapshot(`""`);
179
+ expect(std.out).toMatchInlineSnapshot(`
180
+ "wrangler queues delete <name>
181
+
182
+ Delete a Queue
183
+
184
+ Positionals:
185
+ name The name of the queue [string] [required]
186
+
187
+ Flags:
188
+ -c, --config Path to .toml configuration file [string]
189
+ -e, --env Environment to use for operations and .env files [string]
190
+ -h, --help Show help [boolean]
191
+ -v, --version Show version number [boolean]"
192
+ `);
193
+ });
194
+
195
+ it("should delete a queue", async () => {
196
+ const requests = mockDeleteRequest("testQueue");
197
+ await runWrangler("queues delete testQueue");
198
+ expect(std.out).toMatchInlineSnapshot(`
199
+ "Deleting queue testQueue.
200
+ Deleted queue testQueue."
201
+ `);
202
+ expect(requests.count).toEqual(1);
203
+ });
204
+ });
205
+
206
+ describe("consumers", () => {
207
+ it("should show the correct help text", async () => {
208
+ await runWrangler("queues consumer --help");
209
+
210
+ expect(std.err).toMatchInlineSnapshot(`""`);
211
+ expect(std.out).toMatchInlineSnapshot(`
212
+ "wrangler queues consumer
213
+
214
+ Configure Queue Consumers
215
+
216
+ Commands:
217
+ wrangler queues consumer add <queue-name> <script-name> Add a Queue Consumer
218
+ wrangler queues consumer remove <queue-name> <script-name> Remove a Queue Consumer
219
+
220
+ Flags:
221
+ -c, --config Path to .toml configuration file [string]
222
+ -e, --env Environment to use for operations and .env files [string]
223
+ -h, --help Show help [boolean]
224
+ -v, --version Show version number [boolean]"
225
+ `);
226
+ });
227
+
228
+ describe("add", () => {
229
+ function mockPostRequest(
230
+ expectedQueueName: string,
231
+ expectedBody: PostConsumerBody
232
+ ) {
233
+ const requests = { count: 0 };
234
+ setMockResponse(
235
+ `/accounts/:accountId/workers/queues/${expectedQueueName}/consumers`,
236
+ "POST",
237
+ ([_url, accountId], { body }) => {
238
+ expect(accountId).toEqual("some-account-id");
239
+ expect(JSON.parse(body as string)).toEqual(expectedBody);
240
+ requests.count += 1;
241
+ }
242
+ );
243
+ return requests;
244
+ }
245
+
246
+ it("should show the correct help text", async () => {
247
+ await runWrangler("queues consumer add --help");
248
+ expect(std.err).toMatchInlineSnapshot(`""`);
249
+ expect(std.out).toMatchInlineSnapshot(`
250
+ "wrangler queues consumer add <queue-name> <script-name>
251
+
252
+ Add a Queue Consumer
253
+
254
+ Positionals:
255
+ queue-name Name of the queue to configure [string] [required]
256
+ script-name Name of the consumer script [string] [required]
257
+
258
+ Flags:
259
+ -c, --config Path to .toml configuration file [string]
260
+ -e, --env Environment to use for operations and .env files [string]
261
+ -h, --help Show help [boolean]
262
+ -v, --version Show version number [boolean]
263
+
264
+ Options:
265
+ --batch-size Maximum number of messages per batch [number]
266
+ --batch-timeout Maximum number of seconds to wait to fill a batch with messages [number]
267
+ --message-retries Maximum number of retries for each message [number]
268
+ --dead-letter-queue Queue to send messages that failed to be consumed [string]"
269
+ `);
270
+ });
271
+
272
+ it("should add a consumer using defaults", async () => {
273
+ const expectedBody: PostConsumerBody = {
274
+ script_name: "testScript",
275
+ environment_name: "",
276
+ settings: {
277
+ batch_size: undefined,
278
+ max_retries: undefined,
279
+ max_wait_time_ms: undefined,
280
+ },
281
+ dead_letter_queue: undefined,
282
+ };
283
+ mockPostRequest("testQueue", expectedBody);
284
+ await runWrangler("queues consumer add testQueue testScript");
285
+ expect(std.out).toMatchInlineSnapshot(`
286
+ "Adding consumer to queue testQueue.
287
+ Added consumer to queue testQueue."
288
+ `);
289
+ });
290
+
291
+ it("should add a consumer using custom values", async () => {
292
+ const expectedBody: PostConsumerBody = {
293
+ script_name: "testScript",
294
+ environment_name: "myEnv",
295
+ settings: {
296
+ batch_size: 20,
297
+ max_retries: 3,
298
+ max_wait_time_ms: 10 * 1000,
299
+ },
300
+ dead_letter_queue: "myDLQ",
301
+ };
302
+ mockPostRequest("testQueue", expectedBody);
303
+
304
+ await runWrangler(
305
+ "queues consumer add testQueue testScript --env myEnv --batch-size 20 --batch-timeout 10 --message-retries 3 --dead-letter-queue myDLQ"
306
+ );
307
+ expect(std.out).toMatchInlineSnapshot(`
308
+ "Adding consumer to queue testQueue.
309
+ Added consumer to queue testQueue."
310
+ `);
311
+ });
312
+ });
313
+
314
+ describe("delete", () => {
315
+ function mockDeleteRequest(
316
+ expectedQueueName: string,
317
+ expectedScriptName: string,
318
+ expectedEnvName?: string
319
+ ) {
320
+ let resource = `/accounts/:accountId/workers/queues/${expectedQueueName}/consumers/${expectedScriptName}`;
321
+ if (expectedEnvName !== undefined) {
322
+ resource += `/environments/${expectedEnvName}`;
323
+ }
324
+ setMockResponse(resource, "DELETE", ([_url, accountId]) => {
325
+ expect(accountId).toEqual("some-account-id");
326
+ });
327
+ }
328
+
329
+ it("should show the correct help text", async () => {
330
+ await runWrangler("queues consumer remove --help");
331
+ expect(std.err).toMatchInlineSnapshot(`""`);
332
+ expect(std.out).toMatchInlineSnapshot(`
333
+ "wrangler queues consumer remove <queue-name> <script-name>
334
+
335
+ Remove a Queue Consumer
336
+
337
+ Positionals:
338
+ queue-name Name of the queue to configure [string] [required]
339
+ script-name Name of the consumer script [string] [required]
340
+
341
+ Flags:
342
+ -c, --config Path to .toml configuration file [string]
343
+ -e, --env Environment to use for operations and .env files [string]
344
+ -h, --help Show help [boolean]
345
+ -v, --version Show version number [boolean]"
346
+ `);
347
+ });
348
+
349
+ it("should delete a consumer with no --env", async () => {
350
+ mockDeleteRequest("testQueue", "testScript");
351
+ await runWrangler("queues consumer remove testQueue testScript");
352
+ expect(std.out).toMatchInlineSnapshot(`
353
+ "Removing consumer from queue testQueue.
354
+ Removed consumer from queue testQueue."
355
+ `);
356
+ });
357
+
358
+ it("should delete a consumer with --env", async () => {
359
+ mockDeleteRequest("testQueue", "testScript", "myEnv");
360
+ await runWrangler(
361
+ "queues consumer remove testQueue testScript --env myEnv"
362
+ );
363
+ expect(std.out).toMatchInlineSnapshot(`
364
+ "Removing consumer from queue testQueue.
365
+ Removed consumer from queue testQueue."
366
+ `);
367
+ });
368
+ });
369
+ });
370
+ });
371
+ });
@@ -26,21 +26,22 @@ describe("r2", () => {
26
26
  "
27
27
  `);
28
28
  expect(std.out).toMatchInlineSnapshot(`
29
- "
30
- wrangler r2 bucket
29
+ "
30
+ wrangler r2 bucket
31
31
 
32
- Manage R2 buckets
32
+ Manage R2 buckets
33
33
 
34
- Commands:
35
- wrangler r2 bucket create <name> Create a new R2 bucket
36
- wrangler r2 bucket list List R2 buckets
37
- wrangler r2 bucket delete <name> Delete an R2 bucket
34
+ Commands:
35
+ wrangler r2 bucket create <name> Create a new R2 bucket
36
+ wrangler r2 bucket list List R2 buckets
37
+ wrangler r2 bucket delete <name> Delete an R2 bucket
38
38
 
39
- Flags:
40
- -c, --config Path to .toml configuration file [string]
41
- -h, --help Show help [boolean]
42
- -v, --version Show version number [boolean]"
43
- `);
39
+ Flags:
40
+ -c, --config Path to .toml configuration file [string]
41
+ -e, --env Environment to use for operations and .env files [string]
42
+ -h, --help Show help [boolean]
43
+ -v, --version Show version number [boolean]"
44
+ `);
44
45
  });
45
46
 
46
47
  describe("list", () => {
@@ -95,19 +96,20 @@ describe("r2", () => {
95
96
  `"Not enough non-option arguments: got 0, need at least 1"`
96
97
  );
97
98
  expect(std.out).toMatchInlineSnapshot(`
98
- "
99
- wrangler r2 bucket create <name>
99
+ "
100
+ wrangler r2 bucket create <name>
100
101
 
101
- Create a new R2 bucket
102
+ Create a new R2 bucket
102
103
 
103
- Positionals:
104
- name The name of the new bucket [string] [required]
104
+ Positionals:
105
+ name The name of the new bucket [string] [required]
105
106
 
106
- Flags:
107
- -c, --config Path to .toml configuration file [string]
108
- -h, --help Show help [boolean]
109
- -v, --version Show version number [boolean]"
110
- `);
107
+ Flags:
108
+ -c, --config Path to .toml configuration file [string]
109
+ -e, --env Environment to use for operations and .env files [string]
110
+ -h, --help Show help [boolean]
111
+ -v, --version Show version number [boolean]"
112
+ `);
111
113
  expect(std.err).toMatchInlineSnapshot(`
112
114
  "X [ERROR] Not enough non-option arguments: got 0, need at least 1
113
115
 
@@ -122,19 +124,20 @@ describe("r2", () => {
122
124
  `"Unknown arguments: def, ghi"`
123
125
  );
124
126
  expect(std.out).toMatchInlineSnapshot(`
125
- "
126
- wrangler r2 bucket create <name>
127
+ "
128
+ wrangler r2 bucket create <name>
127
129
 
128
- Create a new R2 bucket
130
+ Create a new R2 bucket
129
131
 
130
- Positionals:
131
- name The name of the new bucket [string] [required]
132
+ Positionals:
133
+ name The name of the new bucket [string] [required]
132
134
 
133
- Flags:
134
- -c, --config Path to .toml configuration file [string]
135
- -h, --help Show help [boolean]
136
- -v, --version Show version number [boolean]"
137
- `);
135
+ Flags:
136
+ -c, --config Path to .toml configuration file [string]
137
+ -e, --env Environment to use for operations and .env files [string]
138
+ -h, --help Show help [boolean]
139
+ -v, --version Show version number [boolean]"
140
+ `);
138
141
  expect(std.err).toMatchInlineSnapshot(`
139
142
  "X [ERROR] Unknown arguments: def, ghi
140
143
 
@@ -178,19 +181,20 @@ describe("r2", () => {
178
181
  `"Not enough non-option arguments: got 0, need at least 1"`
179
182
  );
180
183
  expect(std.out).toMatchInlineSnapshot(`
181
- "
182
- wrangler r2 bucket delete <name>
184
+ "
185
+ wrangler r2 bucket delete <name>
183
186
 
184
- Delete an R2 bucket
187
+ Delete an R2 bucket
185
188
 
186
- Positionals:
187
- name The name of the bucket to delete [string] [required]
189
+ Positionals:
190
+ name The name of the bucket to delete [string] [required]
188
191
 
189
- Flags:
190
- -c, --config Path to .toml configuration file [string]
191
- -h, --help Show help [boolean]
192
- -v, --version Show version number [boolean]"
193
- `);
192
+ Flags:
193
+ -c, --config Path to .toml configuration file [string]
194
+ -e, --env Environment to use for operations and .env files [string]
195
+ -h, --help Show help [boolean]
196
+ -v, --version Show version number [boolean]"
197
+ `);
194
198
  expect(std.err).toMatchInlineSnapshot(`
195
199
  "X [ERROR] Not enough non-option arguments: got 0, need at least 1
196
200
 
@@ -205,19 +209,20 @@ describe("r2", () => {
205
209
  `"Unknown arguments: def, ghi"`
206
210
  );
207
211
  expect(std.out).toMatchInlineSnapshot(`
208
- "
209
- wrangler r2 bucket delete <name>
212
+ "
213
+ wrangler r2 bucket delete <name>
210
214
 
211
- Delete an R2 bucket
215
+ Delete an R2 bucket
212
216
 
213
- Positionals:
214
- name The name of the bucket to delete [string] [required]
217
+ Positionals:
218
+ name The name of the bucket to delete [string] [required]
215
219
 
216
- Flags:
217
- -c, --config Path to .toml configuration file [string]
218
- -h, --help Show help [boolean]
219
- -v, --version Show version number [boolean]"
220
- `);
220
+ Flags:
221
+ -c, --config Path to .toml configuration file [string]
222
+ -e, --env Environment to use for operations and .env files [string]
223
+ -h, --help Show help [boolean]
224
+ -v, --version Show version number [boolean]"
225
+ `);
221
226
  expect(std.err).toMatchInlineSnapshot(`
222
227
  "X [ERROR] Unknown arguments: def, ghi
223
228
 
@@ -36,6 +36,7 @@ describe("dispatch-namespace", () => {
36
36
 
37
37
  Flags:
38
38
  -c, --config Path to .toml configuration file [string]
39
+ -e, --env Environment to use for operations and .env files [string]
39
40
  -h, --help Show help [boolean]
40
41
  -v, --version Show version number [boolean]",
41
42
  "warn": "",
@@ -87,6 +88,7 @@ describe("dispatch-namespace", () => {
87
88
 
88
89
  Flags:
89
90
  -c, --config Path to .toml configuration file [string]
91
+ -e, --env Environment to use for operations and .env files [string]
90
92
  -h, --help Show help [boolean]
91
93
  -v, --version Show version number [boolean]"
92
94
  `);
@@ -135,6 +137,7 @@ describe("dispatch-namespace", () => {
135
137
 
136
138
  Flags:
137
139
  -c, --config Path to .toml configuration file [string]
140
+ -e, --env Environment to use for operations and .env files [string]
138
141
  -h, --help Show help [boolean]
139
142
  -v, --version Show version number [boolean]"
140
143
  `);
@@ -183,19 +186,20 @@ describe("dispatch-namespace", () => {
183
186
  );
184
187
 
185
188
  expect(std.out).toMatchInlineSnapshot(`
186
- "
187
- wrangler dispatch-namespace get <name>
189
+ "
190
+ wrangler dispatch-namespace get <name>
188
191
 
189
- Get information about a dispatch namespace
192
+ Get information about a dispatch namespace
190
193
 
191
- Positionals:
192
- name Name of the dispatch namespace [string] [required]
194
+ Positionals:
195
+ name Name of the dispatch namespace [string] [required]
193
196
 
194
- Flags:
195
- -c, --config Path to .toml configuration file [string]
196
- -h, --help Show help [boolean]
197
- -v, --version Show version number [boolean]"
198
- `);
197
+ Flags:
198
+ -c, --config Path to .toml configuration file [string]
199
+ -e, --env Environment to use for operations and .env files [string]
200
+ -h, --help Show help [boolean]
201
+ -v, --version Show version number [boolean]"
202
+ `);
199
203
  });
200
204
 
201
205
  it("should attempt to get info for the given namespace", async () => {
@@ -302,6 +306,7 @@ describe("dispatch-namespace", () => {
302
306
 
303
307
  Flags:
304
308
  -c, --config Path to .toml configuration file [string]
309
+ -e, --env Environment to use for operations and .env files [string]
305
310
  -h, --help Show help [boolean]
306
311
  -v, --version Show version number [boolean]"
307
312
  `);
@@ -2,6 +2,10 @@ import { Blob } from "node:buffer";
2
2
  import { gzipSync } from "node:zlib";
3
3
  import { logger } from "./logger";
4
4
  import type { CfModule } from "./worker";
5
+ import type { Metafile } from "esbuild";
6
+
7
+ const ONE_KIB_BYTES = 1024;
8
+ const ONE_MIB_BYTES = ONE_KIB_BYTES * 1024;
5
9
 
6
10
  async function getSize(modules: CfModule[]) {
7
11
  const gzipSize = gzipSync(
@@ -21,9 +25,44 @@ export async function printBundleSize(
21
25
  ) {
22
26
  const { size, gzipSize } = await getSize([...modules, main]);
23
27
 
24
- const bundleReport = `${(size / 1024).toFixed(2)} KiB / gzip: ${(
25
- gzipSize / 1024
28
+ const bundleReport = `${(size / ONE_KIB_BYTES).toFixed(2)} KiB / gzip: ${(
29
+ gzipSize / ONE_KIB_BYTES
26
30
  ).toFixed(2)} KiB`;
27
31
 
28
32
  logger.log(`Total Upload: ${bundleReport}`);
33
+
34
+ if (gzipSize > ONE_MIB_BYTES && !process.env.NO_SCRIPT_SIZE_WARNING) {
35
+ logger.warn(
36
+ "We recommend keeping your script less than 1MiB (1024 KiB) after gzip. Exceeding past this can affect cold start time"
37
+ );
38
+ }
39
+ }
40
+
41
+ export function printOffendingDependencies(
42
+ dependencies: Metafile["outputs"][string]["inputs"]
43
+ ) {
44
+ const warning: string[] = [];
45
+
46
+ const dependenciesSorted = Object.entries(dependencies);
47
+ dependenciesSorted.sort(
48
+ ([_adep, aData], [_bdep, bData]) =>
49
+ bData.bytesInOutput - aData.bytesInOutput
50
+ );
51
+ const topLargest = dependenciesSorted.slice(0, 5);
52
+
53
+ if (topLargest.length > 0) {
54
+ warning.push(
55
+ `Here are the ${topLargest.length} largest dependencies included in your script:`
56
+ );
57
+
58
+ for (const [dep, data] of topLargest) {
59
+ warning.push(
60
+ `- ${dep} - ${(data.bytesInOutput / ONE_KIB_BYTES).toFixed(2)} KiB`
61
+ );
62
+ }
63
+
64
+ warning.push("If these are unnecessary, consider removing them");
65
+
66
+ logger.warn(warning.join("\n"));
67
+ }
29
68
  }