wrangler 0.0.0-e3cab74 → 0.0.0-e452a04

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 (47) hide show
  1. package/package.json +6 -4
  2. package/src/__tests__/configuration.test.ts +141 -109
  3. package/src/__tests__/dev.test.tsx +375 -83
  4. package/src/__tests__/dev2.test.tsx +152 -0
  5. package/src/__tests__/guess-worker-format.test.ts +9 -17
  6. package/src/__tests__/helpers/mock-account-id.ts +18 -4
  7. package/src/__tests__/helpers/mock-cfetch.ts +3 -3
  8. package/src/__tests__/helpers/mock-console.ts +17 -9
  9. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  10. package/src/__tests__/https-options.test.ts +127 -0
  11. package/src/__tests__/index.test.ts +125 -0
  12. package/src/__tests__/jest.setup.ts +16 -4
  13. package/src/__tests__/kv.test.ts +321 -54
  14. package/src/__tests__/pages.test.ts +44 -0
  15. package/src/__tests__/publish.test.ts +299 -453
  16. package/src/__tests__/route.test.ts +45 -0
  17. package/src/__tests__/secret.test.ts +167 -68
  18. package/src/bundle.ts +20 -11
  19. package/src/cfetch/internal.ts +2 -0
  20. package/src/config/config.ts +53 -39
  21. package/src/config/validation-helpers.ts +30 -12
  22. package/src/config/validation.ts +49 -39
  23. package/src/{api/preview.ts → create-worker-preview.ts} +39 -20
  24. package/src/{api/form_data.ts → create-worker-upload-form.ts} +1 -1
  25. package/src/dev/dev.tsx +357 -0
  26. package/src/dev/local.tsx +241 -0
  27. package/src/dev/remote.tsx +201 -0
  28. package/src/dev/use-esbuild.ts +100 -0
  29. package/src/entry.ts +111 -9
  30. package/src/https-options.ts +122 -0
  31. package/src/index.tsx +447 -445
  32. package/src/inspect.ts +9 -1
  33. package/src/{kv.tsx → kv/index.tsx} +92 -28
  34. package/src/module-collection.ts +85 -2
  35. package/src/open-in-browser.ts +14 -2
  36. package/src/pages.tsx +1 -1
  37. package/src/proxy.ts +102 -40
  38. package/src/publish.ts +37 -53
  39. package/src/reporting.ts +25 -9
  40. package/src/selfsigned.d.ts +29 -0
  41. package/src/sites.tsx +3 -6
  42. package/src/user.tsx +21 -5
  43. package/src/{api/worker.ts → worker.ts} +1 -24
  44. package/wrangler-dist/cli.js +2815 -2690
  45. package/wrangler-dist/cli.js.map +3 -3
  46. package/src/dev.tsx +0 -961
  47. package/src/guess-worker-format.ts +0 -68
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "0.0.0-e3cab74",
3
+ "version": "0.0.0-e452a04",
4
4
  "author": "wrangler@cloudflare.com",
5
5
  "description": "Command-line interface for all things Cloudflare Workers",
6
6
  "bin": {
@@ -39,6 +39,7 @@
39
39
  "esbuild": "0.14.23",
40
40
  "miniflare": "2.3.0",
41
41
  "path-to-regexp": "^6.2.0",
42
+ "selfsigned": "^2.0.0",
42
43
  "semiver": "^1.1.0",
43
44
  "xxhash-wasm": "^1.0.1"
44
45
  },
@@ -46,17 +47,16 @@
46
47
  "fsevents": "~2.3.2"
47
48
  },
48
49
  "devDependencies": {
49
- "@babel/types": "^7.16.0",
50
50
  "@iarna/toml": "^2.2.5",
51
51
  "@sentry/cli": "^1.71.0",
52
52
  "@sentry/integrations": "^6.17.6",
53
53
  "@sentry/node": "^6.17.6",
54
54
  "@types/command-exists": "^1.2.0",
55
- "@types/estree": "^0.0.50",
56
55
  "@types/glob-to-regexp": "0.4.1",
57
56
  "@types/mime": "^2.0.3",
58
57
  "@types/prompts": "^2.0.14",
59
58
  "@types/react": "^17.0.37",
59
+ "@types/react-test-renderer": "^17.0.1",
60
60
  "@types/serve-static": "^1.13.10",
61
61
  "@types/signal-exit": "^3.0.1",
62
62
  "@types/ws": "^8.2.1",
@@ -84,6 +84,7 @@
84
84
  "open": "^8.4.0",
85
85
  "prompts": "^2.4.2",
86
86
  "react": "^17.0.2",
87
+ "react-test-renderer": "^17.0.2",
87
88
  "react-error-boundary": "^3.1.4",
88
89
  "serve-static": "^1.14.1",
89
90
  "signal-exit": "^3.0.6",
@@ -123,7 +124,8 @@
123
124
  "node_modules/(?!find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream|get-port)"
124
125
  ],
125
126
  "moduleNameMapper": {
126
- "clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js"
127
+ "clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",
128
+ "miniflare/cli": "<rootDir>/../../node_modules/miniflare/dist/src/cli.js"
127
129
  },
128
130
  "transform": {
129
131
  "^.+\\.c?(t|j)sx?$": [
@@ -21,6 +21,7 @@ describe("normalizeAndValidateConfig()", () => {
21
21
  local_protocol: "http",
22
22
  port: 8787,
23
23
  upstream_protocol: "https",
24
+ host: undefined,
24
25
  },
25
26
  durable_objects: {
26
27
  bindings: [],
@@ -64,8 +65,8 @@ describe("normalizeAndValidateConfig()", () => {
64
65
  dev: {
65
66
  ip: "255.255.255.255",
66
67
  port: 9999,
67
- local_protocol: "HTTPS",
68
- upstream_protocol: "HTTP",
68
+ local_protocol: "https",
69
+ upstream_protocol: "http",
69
70
  },
70
71
  build: {
71
72
  command: "COMMAND",
@@ -94,8 +95,8 @@ describe("normalizeAndValidateConfig()", () => {
94
95
  dev: {
95
96
  ip: 222,
96
97
  port: "FOO",
97
- local_protocol: 333,
98
- upstream_protocol: 444,
98
+ local_protocol: "wss",
99
+ upstream_protocol: "ws",
99
100
  },
100
101
  build: {
101
102
  command: 555,
@@ -114,17 +115,17 @@ describe("normalizeAndValidateConfig()", () => {
114
115
  );
115
116
  expect(diagnostics.hasWarnings()).toBe(false);
116
117
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
117
- "Processing wrangler configuration:
118
- - ERROR: \\"build.command\\" should be of type string but got 555.
119
- - ERROR: \\"build.cwd\\" should be of type string but got 666.
120
- - ERROR: \\"build.watch_dir\\" should be of type string but got 777.
121
- - ERROR: \\"legacy_env\\" should be of type boolean but got \\"FOO\\".
122
- - ERROR: \\"main\\" should be a string but got 111
123
- - ERROR: \\"dev.ip\\" should be of type string but got 222.
124
- - ERROR: \\"dev.port\\" should be of type number but got \\"FOO\\".
125
- - ERROR: \\"dev.local_protocol\\" should be of type string but got 333.
126
- - ERROR: \\"dev.upstream_protocol\\" should be of type string but got 444."
127
- `);
118
+ "Processing wrangler configuration:
119
+ - Expected \\"build.command\\" to be of type string but got 555.
120
+ - Expected \\"build.cwd\\" to be of type string but got 666.
121
+ - Expected \\"build.watch_dir\\" to be of type string but got 777.
122
+ - Expected \\"legacy_env\\" to be of type boolean but got \\"FOO\\".
123
+ - Expected \\"main\\" to be a string but got 111
124
+ - Expected \\"dev.ip\\" to be of type string but got 222.
125
+ - Expected \\"dev.port\\" to be of type number but got \\"FOO\\".
126
+ - Expected \\"dev.local_protocol\\" field to be one of [\\"http\\",\\"https\\"] but got \\"wss\\".
127
+ - Expected \\"dev.upstream_protocol\\" field to be one of [\\"http\\",\\"https\\"] but got \\"ws\\"."
128
+ `);
128
129
  });
129
130
 
130
131
  it("should warn on and remove unexpected top level fields", () => {
@@ -243,84 +244,115 @@ describe("normalizeAndValidateConfig()", () => {
243
244
  expect(config).toEqual(expect.objectContaining(expectedConfig));
244
245
  expect(diagnostics.hasWarnings()).toBe(false);
245
246
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
246
- "Processing wrangler configuration:
247
- - ERROR: \\"migrations[0].tag\\" should be of type string but got 111.
248
- - ERROR: \\"migrations[0].new_classes.[0]\\" should be of type string but got 222.
249
- - ERROR: \\"migrations[0].new_classes.[1]\\" should be of type string but got 333.
250
- - \\"migrations[0].renamed_classes\\" should be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
251
- - ERROR: \\"migrations[0].deleted_classes.[0]\\" should be of type string but got 666.
252
- - ERROR: \\"migrations[0].deleted_classes.[1]\\" should be of type string but got 777."
253
- `);
247
+ "Processing wrangler configuration:
248
+ - Expected \\"migrations[0].tag\\" to be of type string but got 111.
249
+ - Expected \\"migrations[0].new_classes.[0]\\" to be of type string but got 222.
250
+ - Expected \\"migrations[0].new_classes.[1]\\" to be of type string but got 333.
251
+ - Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
252
+ - Expected \\"migrations[0].deleted_classes.[0]\\" to be of type string but got 666.
253
+ - Expected \\"migrations[0].deleted_classes.[1]\\" to be of type string but got 777."
254
+ `);
254
255
  });
255
256
 
256
- it("should override `site` config defaults with provided values", () => {
257
- const expectedConfig: RawConfig = {
258
- site: {
259
- bucket: "BUCKET",
260
- "entry-point": "ENTRY_POINT",
261
- include: ["INCLUDE_1", "INCLUDE_2"],
262
- exclude: ["EXCLUDE_1", "EXCLUDE_2"],
263
- },
264
- };
257
+ describe("site", () => {
258
+ it("should override `site` config defaults with provided values", () => {
259
+ const expectedConfig: RawConfig = {
260
+ site: {
261
+ bucket: "BUCKET",
262
+ include: ["INCLUDE_1", "INCLUDE_2"],
263
+ exclude: ["EXCLUDE_1", "EXCLUDE_2"],
264
+ },
265
+ };
265
266
 
266
- const { config, diagnostics } = normalizeAndValidateConfig(
267
- expectedConfig,
268
- undefined
269
- );
267
+ const { config, diagnostics } = normalizeAndValidateConfig(
268
+ expectedConfig,
269
+ undefined
270
+ );
270
271
 
271
- expect(config).toEqual(expect.objectContaining(expectedConfig));
272
- expect(diagnostics.hasErrors()).toBe(false);
273
- expect(diagnostics.hasWarnings()).toBe(false);
274
- });
272
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
273
+ expect(diagnostics.hasErrors()).toBe(false);
274
+ expect(diagnostics.hasWarnings()).toBe(false);
275
+ });
275
276
 
276
- it("should error if `site` config is missing `bucket`", () => {
277
- const expectedConfig: RawConfig = {
278
- site: {
279
- "entry-point": "ENTRY_POINT",
280
- include: ["INCLUDE_1", "INCLUDE_2"],
281
- exclude: ["EXCLUDE_1", "EXCLUDE_2"],
282
- },
283
- } as RawConfig;
277
+ it("should error if `site` config is missing `bucket`", () => {
278
+ const expectedConfig: RawConfig = {
279
+ // @ts-expect-error we're intentionally passing an invalid configuration here
280
+ site: {
281
+ include: ["INCLUDE_1", "INCLUDE_2"],
282
+ exclude: ["EXCLUDE_1", "EXCLUDE_2"],
283
+ },
284
+ };
284
285
 
285
- const { config, diagnostics } = normalizeAndValidateConfig(
286
- expectedConfig,
287
- undefined
288
- );
286
+ const { config, diagnostics } = normalizeAndValidateConfig(
287
+ expectedConfig,
288
+ undefined
289
+ );
289
290
 
290
- expect(config).toEqual(expect.objectContaining(expectedConfig));
291
- expect(diagnostics.hasErrors()).toBe(true);
292
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
293
- "Processing wrangler configuration:
294
- - ERROR: \\"site.bucket\\" is a required field."
295
- `);
296
- expect(diagnostics.hasWarnings()).toBe(false);
297
- });
291
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
292
+ expect(diagnostics.hasErrors()).toBe(true);
293
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
294
+ "Processing wrangler configuration:
295
+ - \\"site.bucket\\" is a required field."
296
+ `);
297
+ expect(diagnostics.hasWarnings()).toBe(false);
298
+ });
298
299
 
299
- it("should error on invalid `site` values", () => {
300
- const expectedConfig = {
301
- site: {
302
- bucket: "BUCKET",
303
- "entry-point": 111,
304
- include: [222, 333],
305
- exclude: [444, 555],
306
- },
307
- };
300
+ it("should error on invalid `site` values", () => {
301
+ const expectedConfig = {
302
+ site: {
303
+ bucket: "BUCKET",
304
+ include: [222, 333],
305
+ exclude: [444, 555],
306
+ },
307
+ };
308
308
 
309
- const { config, diagnostics } = normalizeAndValidateConfig(
310
- expectedConfig as unknown as RawConfig,
311
- undefined
312
- );
309
+ const { config, diagnostics } = normalizeAndValidateConfig(
310
+ expectedConfig as unknown as RawConfig,
311
+ undefined
312
+ );
313
313
 
314
- expect(config).toEqual(expect.objectContaining(expectedConfig));
315
- expect(diagnostics.hasWarnings()).toBe(false);
316
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
314
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
315
+ expect(diagnostics.hasWarnings()).toBe(false);
316
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
317
+ "Processing wrangler configuration:
318
+ - Expected \\"sites.include.[0]\\" to be of type string but got 222.
319
+ - Expected \\"sites.include.[1]\\" to be of type string but got 333.
320
+ - Expected \\"sites.exclude.[0]\\" to be of type string but got 444.
321
+ - Expected \\"sites.exclude.[1]\\" to be of type string but got 555."
322
+ `);
323
+ });
324
+
325
+ it("should error with a deprecation warning if entry-point is defined", async () => {
326
+ const { config, diagnostics } = normalizeAndValidateConfig(
327
+ {
328
+ site: {
329
+ bucket: "some/path",
330
+ "entry-point": "some/other/script.js",
331
+ },
332
+ } as unknown as RawConfig,
333
+ undefined
334
+ );
335
+
336
+ expect(config.site).toMatchInlineSnapshot(`
337
+ Object {
338
+ "bucket": "some/path",
339
+ "exclude": Array [],
340
+ "include": Array [],
341
+ }
342
+ `);
343
+ expect(diagnostics.hasWarnings()).toBe(true);
344
+ expect(diagnostics.hasErrors()).toBe(true);
345
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
317
346
  "Processing wrangler configuration:
318
- - ERROR: \\"site.entry_point\\" should be of type string but got 111.
319
- - ERROR: \\"sites.include.[0]\\" should be of type string but got 222.
320
- - ERROR: \\"sites.include.[1]\\" should be of type string but got 333.
321
- - ERROR: \\"sites.exclude.[0]\\" should be of type string but got 444.
322
- - ERROR: \\"sites.exclude.[1]\\" should be of type string but got 555."
347
+ - Unexpected fields found in site field: \\"entry-point\\""
323
348
  `);
349
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
350
+ "Processing wrangler configuration:
351
+ - DEPRECATION: \\"site.entry-point\\":
352
+ The \`site.entry-point\` config field is no longer used.
353
+ The entry-point should be specified via the command line or the \`main\` config field."
354
+ `);
355
+ });
324
356
  });
325
357
 
326
358
  it("should map `wasm_module` paths from relative to the config path to relative to the cwd", () => {
@@ -559,7 +591,7 @@ describe("normalizeAndValidateConfig()", () => {
559
591
  - Expected \\"jsx_factory\\" field to be a string but got 999.
560
592
  - Expected \\"jsx_fragment\\" field to be a string but got 1000.
561
593
  - Expected \\"name\\" field to be a string but got 111.
562
- - Expected \\"usage_model\\" field to be on of bundled,unbound but got \\"INVALID\\"."
594
+ - Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\"."
563
595
  `);
564
596
  });
565
597
 
@@ -745,20 +777,20 @@ describe("normalizeAndValidateConfig()", () => {
745
777
  "Processing wrangler configuration:
746
778
 
747
779
  - \\"durable_objects.bindings[0]\\": {}
748
- - ERROR: bindings should have a string \\"name\\" field.
749
- - ERROR: should have a string \\"class_name\\" field.
780
+ - binding should have a string \\"name\\" field.
781
+ - binding should have a string \\"class_name\\" field.
750
782
 
751
783
  - \\"durable_objects.bindings[1]\\": {\\"name\\":\\"VALID\\"}
752
- - ERROR: should have a string \\"class_name\\" field.
784
+ - binding should have a string \\"class_name\\" field.
753
785
 
754
786
  - \\"durable_objects.bindings[2]\\": {\\"name\\":1555,\\"class_name\\":1666}
755
- - ERROR: bindings should have a string \\"name\\" field.
756
- - ERROR: should have a string \\"class_name\\" field.
787
+ - binding should have a string \\"name\\" field.
788
+ - binding should have a string \\"class_name\\" field.
757
789
 
758
790
  - \\"durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
759
- - ERROR: bindings should have a string \\"name\\" field.
760
- - ERROR: should have a string \\"class_name\\" field.
761
- - ERROR: should, optionally, have a string \\"script_name\\" field."
791
+ - binding should have a string \\"name\\" field.
792
+ - binding should have a string \\"class_name\\" field.
793
+ - binding should, optionally, have a string \\"script_name\\" field."
762
794
  `);
763
795
  });
764
796
  });
@@ -1175,15 +1207,15 @@ describe("normalizeAndValidateConfig()", () => {
1175
1207
  "Processing wrangler configuration:
1176
1208
 
1177
1209
  - \\"unsafe.bindings[0]\\": {}
1178
- - ERROR: should have a string \\"name\\" field.
1179
- - ERROR: should have a string \\"type\\" field.
1210
+ - binding should have a string \\"name\\" field.
1211
+ - binding should have a string \\"type\\" field.
1180
1212
 
1181
1213
  - \\"unsafe.bindings[1]\\": {\\"name\\":\\"UNSAFE_BINDING_1\\"}
1182
- - ERROR: should have a string \\"type\\" field.
1214
+ - binding should have a string \\"type\\" field.
1183
1215
 
1184
1216
  - \\"unsafe.bindings[2]\\": {\\"name\\":2666,\\"type\\":2777}
1185
- - ERROR: should have a string \\"name\\" field.
1186
- - ERROR: should have a string \\"type\\" field."
1217
+ - binding should have a string \\"name\\" field.
1218
+ - binding should have a string \\"type\\" field."
1187
1219
  `);
1188
1220
  });
1189
1221
  });
@@ -1389,7 +1421,7 @@ describe("normalizeAndValidateConfig()", () => {
1389
1421
  - Expected \\"jsx_factory\\" field to be a string but got 999.
1390
1422
  - Expected \\"jsx_fragment\\" field to be a string but got 1000.
1391
1423
  - Expected \\"name\\" field to be a string but got 111.
1392
- - Expected \\"usage_model\\" field to be on of bundled,unbound but got \\"INVALID\\"."
1424
+ - Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\"."
1393
1425
  `);
1394
1426
  });
1395
1427
 
@@ -1607,20 +1639,20 @@ describe("normalizeAndValidateConfig()", () => {
1607
1639
  - \\"env.ENV1\\" environment configuration
1608
1640
 
1609
1641
  - \\"env.ENV1.durable_objects.bindings[0]\\": {}
1610
- - ERROR: bindings should have a string \\"name\\" field.
1611
- - ERROR: should have a string \\"class_name\\" field.
1642
+ - binding should have a string \\"name\\" field.
1643
+ - binding should have a string \\"class_name\\" field.
1612
1644
 
1613
1645
  - \\"env.ENV1.durable_objects.bindings[1]\\": {\\"name\\":\\"VALID\\"}
1614
- - ERROR: should have a string \\"class_name\\" field.
1646
+ - binding should have a string \\"class_name\\" field.
1615
1647
 
1616
1648
  - \\"env.ENV1.durable_objects.bindings[2]\\": {\\"name\\":1555,\\"class_name\\":1666}
1617
- - ERROR: bindings should have a string \\"name\\" field.
1618
- - ERROR: should have a string \\"class_name\\" field.
1649
+ - binding should have a string \\"name\\" field.
1650
+ - binding should have a string \\"class_name\\" field.
1619
1651
 
1620
1652
  - \\"env.ENV1.durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
1621
- - ERROR: bindings should have a string \\"name\\" field.
1622
- - ERROR: should have a string \\"class_name\\" field.
1623
- - ERROR: should, optionally, have a string \\"script_name\\" field."
1653
+ - binding should have a string \\"name\\" field.
1654
+ - binding should have a string \\"class_name\\" field.
1655
+ - binding should, optionally, have a string \\"script_name\\" field."
1624
1656
  `);
1625
1657
  });
1626
1658
  });
@@ -2117,15 +2149,15 @@ describe("normalizeAndValidateConfig()", () => {
2117
2149
  - \\"env.ENV1\\" environment configuration
2118
2150
 
2119
2151
  - \\"env.ENV1.unsafe.bindings[0]\\": {}
2120
- - ERROR: should have a string \\"name\\" field.
2121
- - ERROR: should have a string \\"type\\" field.
2152
+ - binding should have a string \\"name\\" field.
2153
+ - binding should have a string \\"type\\" field.
2122
2154
 
2123
2155
  - \\"env.ENV1.unsafe.bindings[1]\\": {\\"name\\":\\"UNSAFE_BINDING_1\\"}
2124
- - ERROR: should have a string \\"type\\" field.
2156
+ - binding should have a string \\"type\\" field.
2125
2157
 
2126
2158
  - \\"env.ENV1.unsafe.bindings[2]\\": {\\"name\\":2666,\\"type\\":2777}
2127
- - ERROR: should have a string \\"name\\" field.
2128
- - ERROR: should have a string \\"type\\" field."
2159
+ - binding should have a string \\"name\\" field.
2160
+ - binding should have a string \\"type\\" field."
2129
2161
  `);
2130
2162
  });
2131
2163
  });