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
@@ -1,26 +1,6 @@
1
1
  import { rest } from "msw";
2
2
 
3
- export type DeploymentListRes = {
4
- versions: {
5
- version_id: string;
6
- version_number: string;
7
- metadata: {
8
- author_id: string;
9
- author_email: string;
10
- source: "api" | "dash" | "wrangler" | "terraform" | "other";
11
- created_on: string;
12
- modified_on: string;
13
- };
14
- preview: {
15
- active: boolean;
16
- url: string;
17
- };
18
- resources: {
19
- script: string;
20
- bindings: unknown[];
21
- };
22
- }[];
23
- };
3
+ import type { DeploymentListRes } from "../../../../deployments";
24
4
 
25
5
  export const mswSuccessDeployments = [
26
6
  rest.get(
@@ -33,10 +13,25 @@ export const mswSuccessDeployments = [
33
13
  errors: [],
34
14
  messages: [],
35
15
  result: {
36
- versions: [
16
+ latest: {
17
+ id: "Galaxy-Class",
18
+ number: "1701-E",
19
+ metadata: {
20
+ author_id: "Picard-Gamma-6-0-7-3",
21
+ author_email: "Jean-Luc-Picard@federation.org",
22
+ source: "wrangler",
23
+ created_on: "2021-01-01T00:00:00.000000Z",
24
+ modified_on: "2021-01-01T00:00:00.000000Z",
25
+ },
26
+ resources: {
27
+ script: "MOCK-TAG",
28
+ bindings: [],
29
+ },
30
+ },
31
+ items: [
37
32
  {
38
- version_id: "Galaxy-Class",
39
- version_number: "1701-E",
33
+ id: "Galaxy-Class",
34
+ number: "1701-E",
40
35
  metadata: {
41
36
  author_id: "Picard-Gamma-6-0-7-3",
42
37
  author_email: "Jean-Luc-Picard@federation.org",
@@ -44,18 +39,10 @@ export const mswSuccessDeployments = [
44
39
  created_on: "2021-01-01T00:00:00.000000Z",
45
40
  modified_on: "2021-01-01T00:00:00.000000Z",
46
41
  },
47
- preview: {
48
- active: true,
49
- url: "https://example.com",
50
- },
51
- resources: {
52
- script: "script.js",
53
- bindings: [],
54
- },
55
42
  },
56
43
  {
57
- version_id: "Intrepid-Class",
58
- version_number: "NCC-74656",
44
+ id: "Intrepid-Class",
45
+ number: "NCC-74656",
59
46
  metadata: {
60
47
  author_id: "Kathryn-Jane-Gamma-6-0-7-3",
61
48
  author_email: "Kathryn-Janeway@federation.org",
@@ -63,17 +50,9 @@ export const mswSuccessDeployments = [
63
50
  created_on: "2021-02-02T00:00:00.000000Z",
64
51
  modified_on: "2021-02-02T00:00:00.000000Z",
65
52
  },
66
- preview: {
67
- active: true,
68
- url: "https://example.com",
69
- },
70
- resources: {
71
- script: "script.js",
72
- bindings: [],
73
- },
74
53
  },
75
54
  ],
76
- },
55
+ } as DeploymentListRes,
77
56
  })
78
57
  )
79
58
  ),
@@ -0,0 +1,22 @@
1
+ import { rest } from "msw";
2
+
3
+ export default [
4
+ rest.get("*/zones", ({ url: { searchParams } }, res, context) => {
5
+ return res(
6
+ context.status(200),
7
+ context.json({
8
+ success: true,
9
+ errors: [],
10
+ messages: [],
11
+ result:
12
+ searchParams.get("name") === "exists.com"
13
+ ? [
14
+ {
15
+ id: "exists-com",
16
+ },
17
+ ]
18
+ : [],
19
+ })
20
+ );
21
+ }),
22
+ ];
@@ -1,10 +1,12 @@
1
1
  import { setupServer } from "msw/node";
2
+ import { default as mswAccessHandlers } from "./handlers/access";
2
3
  import { mswSuccessDeployments } from "./handlers/deployments";
3
4
  import { mswSuccessNamespacesHandlers } from "./handlers/namespaces";
4
5
  import { mswSuccessOauthHandlers } from "./handlers/oauth";
5
6
  import { mswSuccessR2handlers } from "./handlers/r2";
6
7
  import { default as mswSucessScriptHandlers } from "./handlers/script";
7
8
  import { mswSuccessUserHandlers } from "./handlers/user";
9
+ import { default as mswZoneHandlers } from "./handlers/zones";
8
10
  export const msw = setupServer();
9
11
 
10
12
  export {
@@ -13,5 +15,7 @@ export {
13
15
  mswSuccessOauthHandlers,
14
16
  mswSuccessNamespacesHandlers,
15
17
  mswSucessScriptHandlers,
18
+ mswZoneHandlers,
16
19
  mswSuccessDeployments,
20
+ mswAccessHandlers,
17
21
  };
@@ -42,6 +42,7 @@ describe("wrangler", () => {
42
42
  wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
43
43
  wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
44
44
  wrangler pages ⚡️ Configure Cloudflare Pages
45
+ wrangler queues 🆀 Configure Workers Queues
45
46
  wrangler r2 📦 Interact with an R2 store
46
47
  wrangler dispatch-namespace 📦 Interact with a dispatch namespace
47
48
  wrangler d1 🗄 Interact with a D1 database
@@ -53,6 +54,7 @@ describe("wrangler", () => {
53
54
 
54
55
  Flags:
55
56
  -c, --config Path to .toml configuration file [string]
57
+ -e, --env Environment to use for operations and .env files [string]
56
58
  -h, --help Show help [boolean]
57
59
  -v, --version Show version number [boolean]"
58
60
  `);
@@ -85,6 +87,7 @@ describe("wrangler", () => {
85
87
  wrangler kv:key 🔑 Individually manage Workers KV key-value pairs
86
88
  wrangler kv:bulk 💪 Interact with multiple Workers KV key-value pairs at once
87
89
  wrangler pages ⚡️ Configure Cloudflare Pages
90
+ wrangler queues 🆀 Configure Workers Queues
88
91
  wrangler r2 📦 Interact with an R2 store
89
92
  wrangler dispatch-namespace 📦 Interact with a dispatch namespace
90
93
  wrangler d1 🗄 Interact with a D1 database
@@ -96,6 +99,7 @@ describe("wrangler", () => {
96
99
 
97
100
  Flags:
98
101
  -c, --config Path to .toml configuration file [string]
102
+ -e, --env Environment to use for operations and .env files [string]
99
103
  -h, --help Show help [boolean]
100
104
  -v, --version Show version number [boolean]"
101
105
  `);
@@ -142,6 +146,7 @@ describe("wrangler", () => {
142
146
 
143
147
  Flags:
144
148
  -c, --config Path to .toml configuration file [string]
149
+ -e, --env Environment to use for operations and .env files [string]
145
150
  -h, --help Show help [boolean]
146
151
  -v, --version Show version number [boolean]"
147
152
  `);
@@ -151,60 +156,63 @@ describe("wrangler", () => {
151
156
  await runWrangler("kv:namespace");
152
157
  await endEventLoop();
153
158
  expect(std.out).toMatchInlineSnapshot(`
154
- "wrangler kv:namespace
159
+ "wrangler kv:namespace
155
160
 
156
- 🗂️ Interact with your Workers KV Namespaces
161
+ 🗂️ Interact with your Workers KV Namespaces
157
162
 
158
- Commands:
159
- wrangler kv:namespace create <namespace> Create a new namespace
160
- wrangler kv:namespace list Outputs a list of all KV namespaces associated with your account id.
161
- wrangler kv:namespace delete Deletes a given namespace.
163
+ Commands:
164
+ wrangler kv:namespace create <namespace> Create a new namespace
165
+ wrangler kv:namespace list Outputs a list of all KV namespaces associated with your account id.
166
+ wrangler kv:namespace delete Deletes a given namespace.
162
167
 
163
- Flags:
164
- -c, --config Path to .toml configuration file [string]
165
- -h, --help Show help [boolean]
166
- -v, --version Show version number [boolean]"
167
- `);
168
+ Flags:
169
+ -c, --config Path to .toml configuration file [string]
170
+ -e, --env Environment to use for operations and .env files [string]
171
+ -h, --help Show help [boolean]
172
+ -v, --version Show version number [boolean]"
173
+ `);
168
174
  });
169
175
 
170
176
  it("no subcommand 'kv:key' should display a list of available subcommands", async () => {
171
177
  await runWrangler("kv:key");
172
178
  await endEventLoop();
173
179
  expect(std.out).toMatchInlineSnapshot(`
174
- "wrangler kv:key
180
+ "wrangler kv:key
175
181
 
176
- 🔑 Individually manage Workers KV key-value pairs
182
+ 🔑 Individually manage Workers KV key-value pairs
177
183
 
178
- Commands:
179
- wrangler kv:key put <key> [value] Writes a single key/value pair to the given namespace.
180
- wrangler kv:key list Outputs a list of all keys in a given namespace.
181
- wrangler kv:key get <key> Reads a single value by key from the given namespace.
182
- wrangler kv:key delete <key> Removes a single key value pair from the given namespace.
184
+ Commands:
185
+ wrangler kv:key put <key> [value] Writes a single key/value pair to the given namespace.
186
+ wrangler kv:key list Outputs a list of all keys in a given namespace.
187
+ wrangler kv:key get <key> Reads a single value by key from the given namespace.
188
+ wrangler kv:key delete <key> Removes a single key value pair from the given namespace.
183
189
 
184
- Flags:
185
- -c, --config Path to .toml configuration file [string]
186
- -h, --help Show help [boolean]
187
- -v, --version Show version number [boolean]"
188
- `);
190
+ Flags:
191
+ -c, --config Path to .toml configuration file [string]
192
+ -e, --env Environment to use for operations and .env files [string]
193
+ -h, --help Show help [boolean]
194
+ -v, --version Show version number [boolean]"
195
+ `);
189
196
  });
190
197
 
191
198
  it("no subcommand 'kv:bulk' should display a list of available subcommands", async () => {
192
199
  await runWrangler("kv:bulk");
193
200
  await endEventLoop();
194
201
  expect(std.out).toMatchInlineSnapshot(`
195
- "wrangler kv:bulk
202
+ "wrangler kv:bulk
196
203
 
197
- 💪 Interact with multiple Workers KV key-value pairs at once
204
+ 💪 Interact with multiple Workers KV key-value pairs at once
198
205
 
199
- Commands:
200
- wrangler kv:bulk put <filename> Upload multiple key-value pairs to a namespace
201
- wrangler kv:bulk delete <filename> Delete multiple key-value pairs from a namespace
206
+ Commands:
207
+ wrangler kv:bulk put <filename> Upload multiple key-value pairs to a namespace
208
+ wrangler kv:bulk delete <filename> Delete multiple key-value pairs from a namespace
202
209
 
203
- Flags:
204
- -c, --config Path to .toml configuration file [string]
205
- -h, --help Show help [boolean]
206
- -v, --version Show version number [boolean]"
207
- `);
210
+ Flags:
211
+ -c, --config Path to .toml configuration file [string]
212
+ -e, --env Environment to use for operations and .env files [string]
213
+ -h, --help Show help [boolean]
214
+ -v, --version Show version number [boolean]"
215
+ `);
208
216
  });
209
217
 
210
218
  it("no subcommand 'r2' should display a list of available subcommands", async () => {
@@ -221,6 +229,7 @@ describe("wrangler", () => {
221
229
 
222
230
  Flags:
223
231
  -c, --config Path to .toml configuration file [string]
232
+ -e, --env Environment to use for operations and .env files [string]
224
233
  -h, --help Show help [boolean]
225
234
  -v, --version Show version number [boolean]"
226
235
  `);
@@ -2087,8 +2087,8 @@ describe("init", () => {
2087
2087
  },
2088
2088
  {
2089
2089
  type: "plain_text",
2090
- name: "ANOTHER",
2091
- text: "thing",
2090
+ name: "ANOTHER-NAME",
2091
+ text: "thing-TEXT",
2092
2092
  },
2093
2093
  {
2094
2094
  type: "durable_object_namespace",
@@ -2218,8 +2218,7 @@ describe("init", () => {
2218
2218
  },
2219
2219
  usage_model: "bundled",
2220
2220
  vars: {
2221
- name: "ANOTHER",
2222
- text: "thing",
2221
+ "ANOTHER-NAME": "thing-TEXT",
2223
2222
  },
2224
2223
  env: {
2225
2224
  test: {},
@@ -2380,6 +2379,8 @@ describe("init", () => {
2380
2379
  "init isolinear-optical-chip --from-dash memory-crystal"
2381
2380
  );
2382
2381
 
2382
+ expect(std.out).toContain("cd isolinear-optical-chip");
2383
+
2383
2384
  checkFiles({
2384
2385
  items: {
2385
2386
  "isolinear-optical-chip/src/index.js": false,
@@ -2433,6 +2434,89 @@ describe("init", () => {
2433
2434
 
2434
2435
  await runWrangler("init --from-dash isolinear-optical-chip");
2435
2436
 
2437
+ expect(fs.readFileSync("./isolinear-optical-chip/wrangler.toml", "utf8"))
2438
+ .toMatchInlineSnapshot(`
2439
+ "name = \\"isolinear-optical-chip\\"
2440
+ main = \\"src/index.ts\\"
2441
+ compatibility_date = \\"1987-9-27\\"
2442
+ route = \\"delta.quadrant\\"
2443
+ usage_model = \\"bundled\\"
2444
+
2445
+ [[migrations]]
2446
+ tag = \\"some-migration-tag\\"
2447
+ new_classes = [ \\"Durability\\" ]
2448
+
2449
+ [triggers]
2450
+ crons = [ \\"0 0 0 * * *\\" ]
2451
+
2452
+ [env]
2453
+ test = { }
2454
+ staging = { }
2455
+
2456
+ [vars]
2457
+ ANOTHER-NAME = \\"thing-TEXT\\"
2458
+
2459
+ [[durable_objects.bindings]]
2460
+ name = \\"DURABLE_TEST\\"
2461
+ class_name = \\"Durability\\"
2462
+ script_name = \\"another-durable-object-worker\\"
2463
+ environment = \\"production\\"
2464
+
2465
+ [[kv_namespaces]]
2466
+ id = \\"some-namespace-id\\"
2467
+ binding = \\"kv_testing\\"
2468
+
2469
+ [[r2_buckets]]
2470
+ binding = \\"test-bucket\\"
2471
+ bucket_name = \\"test-bucket\\"
2472
+
2473
+ [[services]]
2474
+ binding = \\"website\\"
2475
+ service = \\"website\\"
2476
+ environment = \\"production\\"
2477
+
2478
+ [[dispatch_namespaces]]
2479
+ binding = \\"name-namespace-mock\\"
2480
+ namespace = \\"namespace-mock\\"
2481
+
2482
+ [logfwdr]
2483
+ schema = \\"\\"
2484
+
2485
+ [[logfwdr.bindings]]
2486
+ name = \\"httplogs\\"
2487
+ destination = \\"httplogs\\"
2488
+
2489
+ [[logfwdr.bindings]]
2490
+ name = \\"trace\\"
2491
+ destination = \\"trace\\"
2492
+
2493
+ [wasm_modules]
2494
+ WASM_MODULE_ONE = \\"./some_wasm.wasm\\"
2495
+ WASM_MODULE_TWO = \\"./more_wasm.wasm\\"
2496
+
2497
+ [text_blobs]
2498
+ TEXT_BLOB_ONE = \\"./my-entire-app-depends-on-this.cfg\\"
2499
+ TEXT_BLOB_TWO = \\"./the-entirety-of-human-knowledge.txt\\"
2500
+
2501
+ [data_blobs]
2502
+ DATA_BLOB_ONE = \\"DATA_BLOB_ONE\\"
2503
+ DATA_BLOB_TWO = \\"DATA_BLOB_TWO\\"
2504
+
2505
+ [[unsafe.bindings]]
2506
+ type = \\"some unsafe thing\\"
2507
+ name = \\"UNSAFE_BINDING_ONE\\"
2508
+
2509
+ [unsafe.bindings.data.some]
2510
+ unsafe = \\"thing\\"
2511
+
2512
+ [[unsafe.bindings]]
2513
+ type = \\"another unsafe thing\\"
2514
+ name = \\"UNSAFE_BINDING_TWO\\"
2515
+ data = 1_337
2516
+ "
2517
+ `);
2518
+ expect(std.out).toContain("cd isolinear-optical-chip");
2519
+
2436
2520
  checkFiles({
2437
2521
  items: {
2438
2522
  "isolinear-optical-chip/src/index.js": false,
@@ -39,6 +39,17 @@ jest.mock("get-port", () => {
39
39
  };
40
40
  });
41
41
 
42
+ jest.mock("child_process", () => {
43
+ return {
44
+ __esModule: true,
45
+ ...jest.requireActual("child_process"),
46
+ spawnSync: jest.fn().mockImplementation(async (binary, ...args) => {
47
+ if (binary === "cloudflared") return { error: true };
48
+ return jest.requireActual("child_process").spawnSync(binary, ...args);
49
+ }),
50
+ };
51
+ });
52
+
42
53
  jest.mock("ws", () => {
43
54
  return {
44
55
  __esModule: true,