wrangler 2.0.5 → 2.0.8

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 (46) hide show
  1. package/README.md +1 -1
  2. package/bin/wrangler.js +16 -4
  3. package/package.json +6 -4
  4. package/pages/functions/buildPlugin.ts +13 -0
  5. package/pages/functions/buildWorker.ts +13 -0
  6. package/src/__tests__/configuration.test.ts +335 -86
  7. package/src/__tests__/dev.test.tsx +166 -15
  8. package/src/__tests__/helpers/mock-dialogs.ts +41 -1
  9. package/src/__tests__/index.test.ts +30 -16
  10. package/src/__tests__/init.test.ts +249 -131
  11. package/src/__tests__/kv.test.ts +101 -101
  12. package/src/__tests__/package-manager.test.ts +154 -7
  13. package/src/__tests__/pages.test.ts +369 -39
  14. package/src/__tests__/parse.test.ts +5 -1
  15. package/src/__tests__/publish.test.ts +556 -84
  16. package/src/__tests__/r2.test.ts +47 -24
  17. package/src/__tests__/secret.test.ts +39 -4
  18. package/src/abort.d.ts +3 -0
  19. package/src/bundle.ts +32 -1
  20. package/src/cfetch/index.ts +21 -4
  21. package/src/cfetch/internal.ts +14 -9
  22. package/src/config/environment.ts +40 -14
  23. package/src/config/index.ts +162 -0
  24. package/src/config/validation.ts +179 -64
  25. package/src/create-worker-preview.ts +17 -7
  26. package/src/create-worker-upload-form.ts +22 -8
  27. package/src/dev/dev.tsx +2 -4
  28. package/src/dev/local.tsx +6 -0
  29. package/src/dev/remote.tsx +15 -1
  30. package/src/dialogs.tsx +48 -0
  31. package/src/durable.ts +102 -0
  32. package/src/index.tsx +314 -144
  33. package/src/inspect.ts +39 -0
  34. package/src/kv.ts +77 -13
  35. package/src/open-in-browser.ts +5 -12
  36. package/src/package-manager.ts +50 -3
  37. package/src/pages.tsx +210 -65
  38. package/src/parse.ts +21 -4
  39. package/src/proxy.ts +38 -22
  40. package/src/publish.ts +227 -113
  41. package/src/sites.tsx +11 -9
  42. package/src/worker.ts +8 -0
  43. package/templates/new-worker-scheduled.js +17 -0
  44. package/templates/new-worker-scheduled.ts +32 -0
  45. package/templates/new-worker.ts +16 -1
  46. package/wrangler-dist/cli.js +35466 -22362
@@ -48,10 +48,7 @@ describe("wrangler", () => {
48
48
  );
49
49
  expect(std.out).toMatchInlineSnapshot(`
50
50
  "
51
- "
52
- `);
53
- expect(std.err).toMatchInlineSnapshot(`
54
- "wrangler kv:namespace create <namespace>
51
+ wrangler kv:namespace create <namespace>
55
52
 
56
53
  Create a new namespace
57
54
 
@@ -65,8 +62,10 @@ describe("wrangler", () => {
65
62
 
66
63
  Options:
67
64
  -e, --env Perform on a specific environment [string]
68
- --preview Interact with a preview namespace [boolean]
69
- X [ERROR] Not enough non-option arguments: got 0, need at least 1
65
+ --preview Interact with a preview namespace [boolean]"
66
+ `);
67
+ expect(std.err).toMatchInlineSnapshot(`
68
+ "X [ERROR] Not enough non-option arguments: got 0, need at least 1
70
69
 
71
70
  "
72
71
  `);
@@ -80,10 +79,7 @@ describe("wrangler", () => {
80
79
  );
81
80
  expect(std.out).toMatchInlineSnapshot(`
82
81
  "
83
- "
84
- `);
85
- expect(std.err).toMatchInlineSnapshot(`
86
- "wrangler kv:namespace create <namespace>
82
+ wrangler kv:namespace create <namespace>
87
83
 
88
84
  Create a new namespace
89
85
 
@@ -97,8 +93,10 @@ describe("wrangler", () => {
97
93
 
98
94
  Options:
99
95
  -e, --env Perform on a specific environment [string]
100
- --preview Interact with a preview namespace [boolean]
101
- X [ERROR] Unknown arguments: def, ghi
96
+ --preview Interact with a preview namespace [boolean]"
97
+ `);
98
+ expect(std.err).toMatchInlineSnapshot(`
99
+ "X [ERROR] Unknown arguments: def, ghi
102
100
 
103
101
  "
104
102
  `);
@@ -113,10 +111,7 @@ describe("wrangler", () => {
113
111
 
114
112
  expect(std.out).toMatchInlineSnapshot(`
115
113
  "
116
- "
117
- `);
118
- expect(std.err).toMatchInlineSnapshot(`
119
- "wrangler kv:namespace create <namespace>
114
+ wrangler kv:namespace create <namespace>
120
115
 
121
116
  Create a new namespace
122
117
 
@@ -130,8 +125,10 @@ describe("wrangler", () => {
130
125
 
131
126
  Options:
132
127
  -e, --env Perform on a specific environment [string]
133
- --preview Interact with a preview namespace [boolean]
134
- X [ERROR] The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number.
128
+ --preview Interact with a preview namespace [boolean]"
129
+ `);
130
+ expect(std.err).toMatchInlineSnapshot(`
131
+ "X [ERROR] The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number.
135
132
 
136
133
  "
137
134
  `);
@@ -283,21 +280,7 @@ describe("wrangler", () => {
283
280
  A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\"."
284
281
  `);
285
282
  expect(std.err).toMatchInlineSnapshot(`
286
- "wrangler kv:namespace delete
287
-
288
- Deletes a given namespace.
289
-
290
- Flags:
291
- -c, --config Path to .toml configuration file [string]
292
- -h, --help Show help [boolean]
293
- -v, --version Show version number [boolean]
294
-
295
- Options:
296
- --binding The name of the namespace to delete [string]
297
- --namespace-id The id of the namespace to delete [string]
298
- -e, --env Perform on a specific environment [string]
299
- --preview Interact with a preview namespace [boolean]
300
- X [ERROR] Not able to delete namespace.
283
+ "X [ERROR] Not able to delete namespace.
301
284
 
302
285
  A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
303
286
 
@@ -489,10 +472,7 @@ describe("wrangler", () => {
489
472
 
490
473
  expect(std.out).toMatchInlineSnapshot(`
491
474
  "
492
- "
493
- `);
494
- expect(std.err).toMatchInlineSnapshot(`
495
- "wrangler kv:key put <key> [value]
475
+ wrangler kv:key put <key> [value]
496
476
 
497
477
  Writes a single key/value pair to the given namespace.
498
478
 
@@ -512,8 +492,10 @@ describe("wrangler", () => {
512
492
  --preview Interact with a preview namespace [boolean]
513
493
  --ttl Time for which the entries should be visible [number]
514
494
  --expiration Time since the UNIX epoch after which the entry expires [number]
515
- --path Read value from the file at a given path [string]
516
- X [ERROR] Not enough non-option arguments: got 0, need at least 1
495
+ --path Read value from the file at a given path [string]"
496
+ `);
497
+ expect(std.err).toMatchInlineSnapshot(`
498
+ "X [ERROR] Not enough non-option arguments: got 0, need at least 1
517
499
 
518
500
  "
519
501
  `);
@@ -528,10 +510,7 @@ describe("wrangler", () => {
528
510
 
529
511
  expect(std.out).toMatchInlineSnapshot(`
530
512
  "
531
- "
532
- `);
533
- expect(std.err).toMatchInlineSnapshot(`
534
- "wrangler kv:key put <key> [value]
513
+ wrangler kv:key put <key> [value]
535
514
 
536
515
  Writes a single key/value pair to the given namespace.
537
516
 
@@ -551,8 +530,10 @@ describe("wrangler", () => {
551
530
  --preview Interact with a preview namespace [boolean]
552
531
  --ttl Time for which the entries should be visible [number]
553
532
  --expiration Time since the UNIX epoch after which the entry expires [number]
554
- --path Read value from the file at a given path [string]
555
- X [ERROR] Exactly one of the arguments binding and namespace-id is required
533
+ --path Read value from the file at a given path [string]"
534
+ `);
535
+ expect(std.err).toMatchInlineSnapshot(`
536
+ "X [ERROR] Exactly one of the arguments binding and namespace-id is required
556
537
 
557
538
  "
558
539
  `);
@@ -567,10 +548,7 @@ describe("wrangler", () => {
567
548
 
568
549
  expect(std.out).toMatchInlineSnapshot(`
569
550
  "
570
- "
571
- `);
572
- expect(std.err).toMatchInlineSnapshot(`
573
- "wrangler kv:key put <key> [value]
551
+ wrangler kv:key put <key> [value]
574
552
 
575
553
  Writes a single key/value pair to the given namespace.
576
554
 
@@ -590,8 +568,10 @@ describe("wrangler", () => {
590
568
  --preview Interact with a preview namespace [boolean]
591
569
  --ttl Time for which the entries should be visible [number]
592
570
  --expiration Time since the UNIX epoch after which the entry expires [number]
593
- --path Read value from the file at a given path [string]
594
- X [ERROR] Arguments binding and namespace-id are mutually exclusive
571
+ --path Read value from the file at a given path [string]"
572
+ `);
573
+ expect(std.err).toMatchInlineSnapshot(`
574
+ "X [ERROR] Arguments binding and namespace-id are mutually exclusive
595
575
 
596
576
  "
597
577
  `);
@@ -606,10 +586,7 @@ describe("wrangler", () => {
606
586
 
607
587
  expect(std.out).toMatchInlineSnapshot(`
608
588
  "
609
- "
610
- `);
611
- expect(std.err).toMatchInlineSnapshot(`
612
- "wrangler kv:key put <key> [value]
589
+ wrangler kv:key put <key> [value]
613
590
 
614
591
  Writes a single key/value pair to the given namespace.
615
592
 
@@ -629,8 +606,10 @@ describe("wrangler", () => {
629
606
  --preview Interact with a preview namespace [boolean]
630
607
  --ttl Time for which the entries should be visible [number]
631
608
  --expiration Time since the UNIX epoch after which the entry expires [number]
632
- --path Read value from the file at a given path [string]
633
- X [ERROR] Exactly one of the arguments value and path is required
609
+ --path Read value from the file at a given path [string]"
610
+ `);
611
+ expect(std.err).toMatchInlineSnapshot(`
612
+ "X [ERROR] Exactly one of the arguments value and path is required
634
613
 
635
614
  "
636
615
  `);
@@ -645,10 +624,7 @@ describe("wrangler", () => {
645
624
 
646
625
  expect(std.out).toMatchInlineSnapshot(`
647
626
  "
648
- "
649
- `);
650
- expect(std.err).toMatchInlineSnapshot(`
651
- "wrangler kv:key put <key> [value]
627
+ wrangler kv:key put <key> [value]
652
628
 
653
629
  Writes a single key/value pair to the given namespace.
654
630
 
@@ -668,8 +644,10 @@ describe("wrangler", () => {
668
644
  --preview Interact with a preview namespace [boolean]
669
645
  --ttl Time for which the entries should be visible [number]
670
646
  --expiration Time since the UNIX epoch after which the entry expires [number]
671
- --path Read value from the file at a given path [string]
672
- X [ERROR] Arguments value and path are mutually exclusive
647
+ --path Read value from the file at a given path [string]"
648
+ `);
649
+ expect(std.err).toMatchInlineSnapshot(`
650
+ "X [ERROR] Arguments value and path are mutually exclusive
673
651
 
674
652
  "
675
653
  `);
@@ -685,7 +663,7 @@ describe("wrangler", () => {
685
663
 
686
664
  expect(std.out).toMatchInlineSnapshot(`
687
665
  "
688
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
666
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
689
667
  `);
690
668
  expect(std.err).toMatchInlineSnapshot(`
691
669
  "X [ERROR] A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
@@ -707,7 +685,7 @@ describe("wrangler", () => {
707
685
  );
708
686
  expect(std.out).toMatchInlineSnapshot(`
709
687
  "
710
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
688
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
711
689
  `);
712
690
  expect(std.err).toMatchInlineSnapshot(`
713
691
  "X [ERROR] someBinding has both a namespace ID and a preview ID. Specify \\"--preview\\" or \\"--preview false\\" to avoid writing data to the wrong namespace.
@@ -878,7 +856,7 @@ describe("wrangler", () => {
878
856
  `);
879
857
  expect(std.out).toMatchInlineSnapshot(`
880
858
  "
881
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
859
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
882
860
  `);
883
861
  });
884
862
  });
@@ -965,10 +943,7 @@ describe("wrangler", () => {
965
943
  );
966
944
  expect(std.out).toMatchInlineSnapshot(`
967
945
  "
968
- "
969
- `);
970
- expect(std.err).toMatchInlineSnapshot(`
971
- "wrangler kv:key get <key>
946
+ wrangler kv:key get <key>
972
947
 
973
948
  Reads a single value by key from the given namespace.
974
949
 
@@ -984,8 +959,10 @@ describe("wrangler", () => {
984
959
  --binding The name of the namespace to get from [string]
985
960
  --namespace-id The id of the namespace to get from [string]
986
961
  -e, --env Perform on a specific environment [string]
987
- --preview Interact with a preview namespace [boolean] [default: false]
988
- X [ERROR] Not enough non-option arguments: got 0, need at least 1
962
+ --preview Interact with a preview namespace [boolean] [default: false]"
963
+ `);
964
+ expect(std.err).toMatchInlineSnapshot(`
965
+ "X [ERROR] Not enough non-option arguments: got 0, need at least 1
989
966
 
990
967
  "
991
968
  `);
@@ -999,10 +976,7 @@ describe("wrangler", () => {
999
976
  );
1000
977
  expect(std.out).toMatchInlineSnapshot(`
1001
978
  "
1002
- "
1003
- `);
1004
- expect(std.err).toMatchInlineSnapshot(`
1005
- "wrangler kv:key get <key>
979
+ wrangler kv:key get <key>
1006
980
 
1007
981
  Reads a single value by key from the given namespace.
1008
982
 
@@ -1018,8 +992,10 @@ describe("wrangler", () => {
1018
992
  --binding The name of the namespace to get from [string]
1019
993
  --namespace-id The id of the namespace to get from [string]
1020
994
  -e, --env Perform on a specific environment [string]
1021
- --preview Interact with a preview namespace [boolean] [default: false]
1022
- X [ERROR] Exactly one of the arguments binding and namespace-id is required
995
+ --preview Interact with a preview namespace [boolean] [default: false]"
996
+ `);
997
+ expect(std.err).toMatchInlineSnapshot(`
998
+ "X [ERROR] Exactly one of the arguments binding and namespace-id is required
1023
999
 
1024
1000
  "
1025
1001
  `);
@@ -1034,10 +1010,7 @@ describe("wrangler", () => {
1034
1010
 
1035
1011
  expect(std.out).toMatchInlineSnapshot(`
1036
1012
  "
1037
- "
1038
- `);
1039
- expect(std.err).toMatchInlineSnapshot(`
1040
- "wrangler kv:key get <key>
1013
+ wrangler kv:key get <key>
1041
1014
 
1042
1015
  Reads a single value by key from the given namespace.
1043
1016
 
@@ -1053,8 +1026,10 @@ describe("wrangler", () => {
1053
1026
  --binding The name of the namespace to get from [string]
1054
1027
  --namespace-id The id of the namespace to get from [string]
1055
1028
  -e, --env Perform on a specific environment [string]
1056
- --preview Interact with a preview namespace [boolean] [default: false]
1057
- X [ERROR] Arguments binding and namespace-id are mutually exclusive
1029
+ --preview Interact with a preview namespace [boolean] [default: false]"
1030
+ `);
1031
+ expect(std.err).toMatchInlineSnapshot(`
1032
+ "X [ERROR] Arguments binding and namespace-id are mutually exclusive
1058
1033
 
1059
1034
  "
1060
1035
  `);
@@ -1069,7 +1044,7 @@ describe("wrangler", () => {
1069
1044
  );
1070
1045
  expect(std.out).toMatchInlineSnapshot(`
1071
1046
  "
1072
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1047
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1073
1048
  `);
1074
1049
  expect(std.err).toMatchInlineSnapshot(`
1075
1050
  "X [ERROR] A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
@@ -1230,10 +1205,10 @@ describe("wrangler", () => {
1230
1205
  );
1231
1206
  expect(requests.count).toEqual(3);
1232
1207
  expect(std.out).toMatchInlineSnapshot(`
1233
- "Uploaded 0 of 12000.
1234
- Uploaded 5000 of 12000.
1235
- Uploaded 10000 of 12000.
1236
- Uploaded 12000 of 12000.
1208
+ "Uploaded 0% (0 out of 12,000)
1209
+ Uploaded 41% (5,000 out of 12,000)
1210
+ Uploaded 83% (10,000 out of 12,000)
1211
+ Uploaded 100% (12,000 out of 12,000)
1237
1212
  Success!"
1238
1213
  `);
1239
1214
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -1251,7 +1226,7 @@ describe("wrangler", () => {
1251
1226
  `);
1252
1227
  expect(std.out).toMatchInlineSnapshot(`
1253
1228
  "
1254
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1229
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1255
1230
  `);
1256
1231
  expect(std.warn).toMatchInlineSnapshot(`""`);
1257
1232
  });
@@ -1262,7 +1237,25 @@ describe("wrangler", () => {
1262
1237
  "a string",
1263
1238
  { key: "someKey" },
1264
1239
  { value: "someValue" },
1240
+ // add a valid object here to make sure it's not included
1241
+ { key: "someKey1", value: "someValue1" },
1242
+ // this one will only add a warning
1265
1243
  { key: "someKey1", value: "someValue1", invalid: true },
1244
+ // back to the invalid ones
1245
+ { key: 123, value: "somevalue" },
1246
+ { key: "somekey", value: 123 },
1247
+ { key: "someKey1", value: "someValue1", expiration: "string" },
1248
+ { key: "someKey1", value: "someValue1", expiration_ttl: "string" },
1249
+ {
1250
+ key: 123,
1251
+ value: {
1252
+ a: {
1253
+ nested: "object",
1254
+ },
1255
+ },
1256
+ },
1257
+ { key: "someKey1", value: "someValue1", metadata: 123 },
1258
+ { key: "someKey1", value: "someValue1", base64: "string" },
1266
1259
  ];
1267
1260
  writeFileSync("./keys.json", JSON.stringify(keyValues));
1268
1261
  await expect(
@@ -1280,20 +1273,27 @@ describe("wrangler", () => {
1280
1273
  base64?: boolean;
1281
1274
  }
1282
1275
 
1283
- The item at index 0 is type: \\"number\\" - 123
1284
- The item at index 1 is type: \\"string\\" - \\"a string\\"
1276
+ The item at index 0 is 123
1277
+ The item at index 1 is \\"a string\\"
1285
1278
  The item at index 2 is {\\"key\\":\\"someKey\\"}
1286
- The item at index 3 is {\\"value\\":\\"someValue\\"}"
1279
+ The item at index 3 is {\\"value\\":\\"someValue\\"}
1280
+ The item at index 6 is {\\"key\\":123,\\"value\\":\\"somevalue\\"}
1281
+ The item at index 7 is {\\"key\\":\\"somekey\\",\\"value\\":123}
1282
+ The item at index 8 is {\\"key\\":\\"someKey1\\",\\"value\\":\\"someValue1\\",\\"expiration\\":\\"string\\"}
1283
+ The item at index 9 is {\\"key\\":\\"someKey1\\",\\"value\\":\\"someValue1\\",\\"expiration_ttl\\":\\"string\\"}
1284
+ The item at index 10 is {\\"key\\":123,\\"value\\":{\\"a\\":{\\"nested\\":\\"object\\"}}}
1285
+ The item at index 11 is {\\"key\\":\\"someKey1\\",\\"value\\":\\"someValue1\\",\\"metadata\\":123}
1286
+ The item at index 12 is {\\"key\\":\\"someKey1\\",\\"value\\":\\"someValue1\\",\\"base64\\":\\"string\\"}"
1287
1287
  `);
1288
1288
 
1289
1289
  expect(std.out).toMatchInlineSnapshot(`
1290
1290
  "
1291
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1291
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1292
1292
  `);
1293
1293
  expect(std.warn).toMatchInlineSnapshot(`
1294
1294
  "â–² [WARNING] Unexpected key-value properties in \\"keys.json\\".
1295
1295
 
1296
- The item at index 4 contains unexpected properties: [\\"invalid\\"].
1296
+ The item at index 5 contains unexpected properties: [\\"invalid\\"].
1297
1297
 
1298
1298
  "
1299
1299
  `);
@@ -1358,10 +1358,10 @@ describe("wrangler", () => {
1358
1358
  );
1359
1359
  expect(requests.count).toEqual(3);
1360
1360
  expect(std.out).toMatchInlineSnapshot(`
1361
- "Deleted 0 of 12000.
1362
- Deleted 5000 of 12000.
1363
- Deleted 10000 of 12000.
1364
- Deleted 12000 of 12000.
1361
+ "Deleted 0% (0 out of 12,000)
1362
+ Deleted 41% (5,000 out of 12,000)
1363
+ Deleted 83% (10,000 out of 12,000)
1364
+ Deleted 100% (12,000 out of 12,000)
1365
1365
  Success!"
1366
1366
  `);
1367
1367
  expect(std.warn).toMatchInlineSnapshot(`""`);
@@ -1429,7 +1429,7 @@ describe("wrangler", () => {
1429
1429
  `);
1430
1430
  expect(std.out).toMatchInlineSnapshot(`
1431
1431
  "
1432
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1432
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1433
1433
  `);
1434
1434
  expect(std.warn).toMatchInlineSnapshot(`""`);
1435
1435
  });
@@ -1454,7 +1454,7 @@ describe("wrangler", () => {
1454
1454
  `);
1455
1455
  expect(std.out).toMatchInlineSnapshot(`
1456
1456
  "
1457
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1457
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1458
1458
  `);
1459
1459
  expect(std.warn).toMatchInlineSnapshot(`""`);
1460
1460
  });