wrangler 0.0.0-e2f9bb2 → 0.0.0-e3278fa

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 (90) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +3 -1
  3. package/bin/wrangler.js +36 -4
  4. package/package.json +12 -7
  5. package/pages/functions/buildPlugin.ts +13 -0
  6. package/pages/functions/buildWorker.ts +14 -1
  7. package/pages/functions/template-plugin.ts +3 -2
  8. package/src/__tests__/configuration.test.ts +370 -87
  9. package/src/__tests__/dev.test.tsx +298 -77
  10. package/src/__tests__/helpers/mock-dialogs.ts +43 -2
  11. package/src/__tests__/index.test.ts +79 -72
  12. package/src/__tests__/init.test.ts +718 -123
  13. package/src/__tests__/jest.setup.ts +8 -0
  14. package/src/__tests__/kv.test.ts +173 -146
  15. package/src/__tests__/package-manager.test.ts +154 -7
  16. package/src/__tests__/pages.test.ts +478 -53
  17. package/src/__tests__/parse.test.ts +8 -0
  18. package/src/__tests__/publish.test.ts +1094 -215
  19. package/src/__tests__/r2.test.ts +55 -36
  20. package/src/__tests__/secret.test.ts +39 -4
  21. package/src/__tests__/whoami.test.tsx +34 -0
  22. package/src/abort.d.ts +3 -0
  23. package/src/bundle.ts +34 -6
  24. package/src/cfetch/index.ts +21 -4
  25. package/src/cfetch/internal.ts +23 -18
  26. package/src/config/config.ts +2 -2
  27. package/src/config/environment.ts +40 -14
  28. package/src/config/index.ts +162 -0
  29. package/src/config/validation-helpers.ts +10 -1
  30. package/src/config/validation.ts +180 -65
  31. package/src/create-worker-preview.ts +32 -22
  32. package/src/create-worker-upload-form.ts +22 -8
  33. package/src/dev/dev.tsx +12 -18
  34. package/src/dev/local.tsx +10 -0
  35. package/src/dev/remote.tsx +40 -16
  36. package/src/dialogs.tsx +48 -0
  37. package/src/durable.ts +102 -0
  38. package/src/entry.ts +64 -9
  39. package/src/index.tsx +548 -317
  40. package/src/inspect.ts +39 -0
  41. package/src/kv.ts +114 -25
  42. package/src/open-in-browser.ts +5 -12
  43. package/src/package-manager.ts +50 -3
  44. package/src/pages.tsx +434 -207
  45. package/src/parse.ts +23 -4
  46. package/src/proxy.ts +59 -35
  47. package/src/publish.ts +374 -127
  48. package/src/sites.tsx +61 -28
  49. package/src/user.tsx +23 -2
  50. package/src/whoami.tsx +3 -2
  51. package/src/worker.ts +10 -1
  52. package/src/zones.ts +73 -0
  53. package/templates/new-worker-scheduled.js +17 -0
  54. package/templates/new-worker-scheduled.ts +32 -0
  55. package/templates/new-worker.ts +16 -1
  56. package/templates/static-asset-facade.js +0 -4
  57. package/wrangler-dist/cli.js +96965 -83414
  58. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  59. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  60. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  61. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  62. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  63. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  64. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  65. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  66. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  67. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  68. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  69. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  70. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  71. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  72. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  73. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  74. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  75. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  76. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  77. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  78. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  79. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  80. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  81. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  82. package/vendor/wrangler-mime/LICENSE +0 -21
  83. package/vendor/wrangler-mime/Mime.js +0 -97
  84. package/vendor/wrangler-mime/README.md +0 -187
  85. package/vendor/wrangler-mime/cli.js +0 -46
  86. package/vendor/wrangler-mime/index.js +0 -4
  87. package/vendor/wrangler-mime/lite.js +0 -4
  88. package/vendor/wrangler-mime/package.json +0 -52
  89. package/vendor/wrangler-mime/types/other.js +0 -1
  90. package/vendor/wrangler-mime/types/standard.js +0 -1
@@ -27,7 +27,7 @@ describe("normalizeAndValidateConfig()", () => {
27
27
  dev: {
28
28
  ip: "localhost",
29
29
  local_protocol: "http",
30
- port: 8787,
30
+ port: undefined, // the default of 8787 is set at runtime
31
31
  upstream_protocol: "https",
32
32
  host: undefined,
33
33
  },
@@ -43,6 +43,7 @@ describe("normalizeAndValidateConfig()", () => {
43
43
  migrations: [],
44
44
  name: undefined,
45
45
  r2_buckets: [],
46
+ services: [],
46
47
  route: undefined,
47
48
  routes: undefined,
48
49
  rules: [],
@@ -60,6 +61,8 @@ describe("normalizeAndValidateConfig()", () => {
60
61
  data_blobs: undefined,
61
62
  workers_dev: undefined,
62
63
  zone_id: undefined,
64
+ minify: undefined,
65
+ node_compat: undefined,
63
66
  });
64
67
  expect(diagnostics.hasErrors()).toBe(false);
65
68
  expect(diagnostics.hasWarnings()).toBe(false);
@@ -162,68 +165,110 @@ describe("normalizeAndValidateConfig()", () => {
162
165
  `);
163
166
  });
164
167
 
165
- it("should override `migrations` config defaults with provided values", () => {
166
- const expectedConfig: RawConfig = {
167
- migrations: [
168
- {
169
- tag: "TAG",
170
- new_classes: ["CLASS_1", "CLASS_2"],
171
- renamed_classes: [
172
- {
173
- from: "FROM_CLASS",
174
- to: "TO_CLASS",
175
- },
176
- ],
177
- deleted_classes: ["CLASS_3", "CLASS_4"],
178
- },
179
- ],
180
- };
168
+ describe("migrations", () => {
169
+ it("should override `migrations` config defaults with provided values", () => {
170
+ const expectedConfig: RawConfig = {
171
+ migrations: [
172
+ {
173
+ tag: "TAG",
174
+ new_classes: ["CLASS_1", "CLASS_2"],
175
+ renamed_classes: [
176
+ {
177
+ from: "FROM_CLASS",
178
+ to: "TO_CLASS",
179
+ },
180
+ ],
181
+ deleted_classes: ["CLASS_3", "CLASS_4"],
182
+ },
183
+ ],
184
+ };
181
185
 
182
- const { config, diagnostics } = normalizeAndValidateConfig(
183
- expectedConfig,
184
- undefined,
185
- { env: undefined }
186
- );
186
+ const { config, diagnostics } = normalizeAndValidateConfig(
187
+ expectedConfig,
188
+ undefined,
189
+ { env: undefined }
190
+ );
187
191
 
188
- expect(config).toEqual(expect.objectContaining(expectedConfig));
189
- expect(diagnostics.hasErrors()).toBe(false);
190
- expect(diagnostics.hasWarnings()).toBe(false);
191
- });
192
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
193
+ expect(diagnostics.hasErrors()).toBe(false);
194
+ expect(diagnostics.hasWarnings()).toBe(false);
195
+ });
192
196
 
193
- it("should error on invalid `migrations` values", () => {
194
- const expectedConfig = {
195
- migrations: [
196
- {
197
- tag: 111,
198
- new_classes: [222, 333],
199
- renamed_classes: [
200
- {
201
- from: 444,
202
- to: 555,
203
- },
204
- ],
205
- deleted_classes: [666, 777],
206
- },
207
- ],
208
- };
197
+ it("should error on invalid `migrations` values", () => {
198
+ const expectedConfig = {
199
+ migrations: [
200
+ {
201
+ tag: 111,
202
+ new_classes: [222, 333],
203
+ renamed_classes: [
204
+ {
205
+ from: 444,
206
+ to: 555,
207
+ },
208
+ ],
209
+ deleted_classes: [666, 777],
210
+ },
211
+ ],
212
+ };
209
213
 
210
- const { config, diagnostics } = normalizeAndValidateConfig(
211
- expectedConfig as unknown as RawConfig,
212
- undefined,
213
- { env: undefined }
214
- );
214
+ const { config, diagnostics } = normalizeAndValidateConfig(
215
+ expectedConfig as unknown as RawConfig,
216
+ undefined,
217
+ { env: undefined }
218
+ );
215
219
 
216
- expect(config).toEqual(expect.objectContaining(expectedConfig));
217
- expect(diagnostics.hasWarnings()).toBe(false);
218
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
219
- "Processing wrangler configuration:
220
- - Expected \\"migrations[0].tag\\" to be of type string but got 111.
221
- - Expected \\"migrations[0].new_classes.[0]\\" to be of type string but got 222.
222
- - Expected \\"migrations[0].new_classes.[1]\\" to be of type string but got 333.
223
- - Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
224
- - Expected \\"migrations[0].deleted_classes.[0]\\" to be of type string but got 666.
225
- - Expected \\"migrations[0].deleted_classes.[1]\\" to be of type string but got 777."
226
- `);
220
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
221
+ expect(diagnostics.hasWarnings()).toBe(false);
222
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
223
+ "Processing wrangler configuration:
224
+ - Expected \\"migrations[0].tag\\" to be of type string but got 111.
225
+ - Expected \\"migrations[0].new_classes.[0]\\" to be of type string but got 222.
226
+ - Expected \\"migrations[0].new_classes.[1]\\" to be of type string but got 333.
227
+ - Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
228
+ - Expected \\"migrations[0].deleted_classes.[0]\\" to be of type string but got 666.
229
+ - Expected \\"migrations[0].deleted_classes.[1]\\" to be of type string but got 777."
230
+ `);
231
+ });
232
+
233
+ it("should warn/error on unexpected fields on `migrations`", async () => {
234
+ const expectedConfig = {
235
+ migrations: [
236
+ {
237
+ tag: "TAG",
238
+ new_classes: ["CLASS_1", "CLASS_2"],
239
+ renamed_classes: [
240
+ {
241
+ from: "FROM_CLASS",
242
+ to: "TO_CLASS",
243
+ },
244
+ {
245
+ a: "something",
246
+ b: "someone",
247
+ },
248
+ ],
249
+ deleted_classes: ["CLASS_3", "CLASS_4"],
250
+ unrecognized_field: "FOO",
251
+ },
252
+ ],
253
+ };
254
+
255
+ const { config, diagnostics } = normalizeAndValidateConfig(
256
+ expectedConfig as unknown as RawConfig,
257
+ undefined,
258
+ { env: undefined }
259
+ );
260
+
261
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
262
+ expect(diagnostics.hasErrors()).toBe(true);
263
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
264
+ "Processing wrangler configuration:
265
+ - Unexpected fields found in migrations field: \\"unrecognized_field\\""
266
+ `);
267
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
268
+ "Processing wrangler configuration:
269
+ - Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":\\"FROM_CLASS\\",\\"to\\":\\"TO_CLASS\\"},{\\"a\\":\\"something\\",\\"b\\":\\"someone\\"}]."
270
+ `);
271
+ });
227
272
  });
228
273
 
229
274
  describe("site", () => {
@@ -393,6 +438,40 @@ describe("normalizeAndValidateConfig()", () => {
393
438
  expect(diagnostics.hasWarnings()).toBe(false);
394
439
  });
395
440
 
441
+ it("should warn on unexpected fields on `triggers`", async () => {
442
+ const expectedConfig: RawConfig = {
443
+ triggers: {
444
+ crons: ["1 * * * *"],
445
+ // @ts-expect-error we're purposely adding a field
446
+ // that doesn't belong here
447
+ someOtherfield: 123,
448
+ },
449
+ };
450
+
451
+ const { config, diagnostics } = normalizeAndValidateConfig(
452
+ expectedConfig,
453
+ "project/wrangler.toml",
454
+ { env: undefined }
455
+ );
456
+
457
+ expect(config).toEqual(
458
+ expect.objectContaining({
459
+ triggers: {
460
+ crons: ["1 * * * *"],
461
+ someOtherfield: 123,
462
+ },
463
+ })
464
+ );
465
+ expect(diagnostics.hasErrors()).toBe(false);
466
+ expect(diagnostics.hasWarnings()).toBe(true);
467
+
468
+ expect(normalizePath(diagnostics.renderWarnings()))
469
+ .toMatchInlineSnapshot(`
470
+ "Processing project/wrangler.toml configuration:
471
+ - Unexpected fields found in triggers field: \\"someOtherfield\\""
472
+ `);
473
+ });
474
+
396
475
  it("should error on invalid `wasm_modules` paths", () => {
397
476
  const expectedConfig = {
398
477
  wasm_modules: {
@@ -620,6 +699,12 @@ describe("normalizeAndValidateConfig()", () => {
620
699
  class_name: "CLASS2",
621
700
  script_name: "SCRIPT2",
622
701
  },
702
+ {
703
+ name: "DO_BINDING_3",
704
+ class_name: "CLASS3",
705
+ script_name: "SCRIPT3",
706
+ environment: "ENV3",
707
+ },
623
708
  ],
624
709
  },
625
710
  kv_namespaces: [
@@ -638,6 +723,13 @@ describe("normalizeAndValidateConfig()", () => {
638
723
  preview_bucket_name: "R2_PREVIEW_2",
639
724
  },
640
725
  ],
726
+ services: [
727
+ {
728
+ binding: "SERVICE_BINDING_1",
729
+ service: "SERVICE_TYPE_1",
730
+ environment: "SERVICE_BINDING_ENVIRONMENT_1",
731
+ },
732
+ ],
641
733
  unsafe: {
642
734
  bindings: [
643
735
  { name: "UNSAFE_BINDING_1", type: "UNSAFE_TYPE_1" },
@@ -648,6 +740,8 @@ describe("normalizeAndValidateConfig()", () => {
648
740
  },
649
741
  ],
650
742
  },
743
+ minify: true,
744
+ node_compat: true,
651
745
  };
652
746
 
653
747
  const { config, diagnostics } = normalizeAndValidateConfig(
@@ -661,9 +755,19 @@ describe("normalizeAndValidateConfig()", () => {
661
755
  );
662
756
  expect(diagnostics.hasErrors()).toBe(false);
663
757
  expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
664
- "Processing wrangler configuration:
665
- - \\"unsafe\\" fields are experimental and may change or break at any time."
666
- `);
758
+ "Processing wrangler configuration:
759
+ - \\"unsafe\\" fields are experimental and may change or break at any time.
760
+ - \\"services\\" fields are experimental and may change or break at any time.
761
+ - In wrangler.toml, you have configured [durable_objects] exported by this Worker (CLASS1), but no [migrations] for them. This may not work as expected until you add a [migrations] section to your wrangler.toml. Add this configuration to your wrangler.toml:
762
+
763
+ \`\`\`
764
+ [[migrations]]
765
+ tag = \\"v1\\" # Should be unique for each entry
766
+ new_classes = [\\"CLASS1\\"]
767
+ \`\`\`
768
+
769
+ Refer to https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml for more details."
770
+ `);
667
771
  });
668
772
 
669
773
  it("should error on invalid environment values", () => {
@@ -705,6 +809,8 @@ describe("normalizeAndValidateConfig()", () => {
705
809
  cwd: 1555,
706
810
  watch_dir: 1666,
707
811
  },
812
+ minify: "INVALID",
813
+ node_compat: "INVALID",
708
814
  } as unknown as RawEnvironment;
709
815
 
710
816
  const { config, diagnostics } = normalizeAndValidateConfig(
@@ -717,8 +823,8 @@ describe("normalizeAndValidateConfig()", () => {
717
823
  expect(diagnostics.hasWarnings()).toBe(false);
718
824
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
719
825
  "Processing wrangler configuration:
720
- - Expected \\"route\\" to be either a string, or an object with shape { pattern, zone_id | zone_name }, but got 888.
721
- - Expected \\"routes\\" to be an array of either strings or objects with the shape { pattern, zone_id | zone_name }, but these weren't valid: [
826
+ - Expected \\"route\\" to be either a string, or an object with shape { pattern, custom_domain, zone_id | zone_name }, but got 888.
827
+ - Expected \\"routes\\" to be an array of either strings or objects with the shape { pattern, custom_domain, zone_id | zone_name }, but these weren't valid: [
722
828
  666,
723
829
  777,
724
830
  {
@@ -767,7 +873,9 @@ describe("normalizeAndValidateConfig()", () => {
767
873
  - Expected \\"tsconfig\\" to be of type string but got true.
768
874
  - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got 111.
769
875
  - Expected \\"main\\" to be of type string but got 1333.
770
- - Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\"."
876
+ - Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\".
877
+ - Expected \\"minify\\" to be of type boolean but got \\"INVALID\\".
878
+ - Expected \\"node_compat\\" to be of type boolean but got \\"INVALID\\"."
771
879
  `);
772
880
  });
773
881
 
@@ -1106,13 +1214,29 @@ describe("normalizeAndValidateConfig()", () => {
1106
1214
  durable_objects: {
1107
1215
  bindings: [
1108
1216
  {},
1109
- { name: "VALID" },
1217
+ { name: "MISSING_CLASS" },
1110
1218
  { name: 1555, class_name: 1666 },
1111
1219
  {
1112
1220
  name: 1777,
1113
1221
  class_name: 1888,
1114
1222
  script_name: 1999,
1115
1223
  },
1224
+ {
1225
+ name: "SOMENAME",
1226
+ class_name: "SomeClass",
1227
+ environment: "staging",
1228
+ },
1229
+ {
1230
+ name: 1778,
1231
+ class_name: 1889,
1232
+ script_name: 1992,
1233
+ environment: 2111,
1234
+ },
1235
+ {
1236
+ name: 1772,
1237
+ class_name: 1883,
1238
+ environment: 2112,
1239
+ },
1116
1240
  ],
1117
1241
  },
1118
1242
  } as unknown as RawConfig,
@@ -1126,6 +1250,8 @@ describe("normalizeAndValidateConfig()", () => {
1126
1250
  })
1127
1251
  );
1128
1252
  expect(diagnostics.hasWarnings()).toBe(false);
1253
+
1254
+ expect(diagnostics.hasErrors()).toBe(true);
1129
1255
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1130
1256
  "Processing wrangler configuration:
1131
1257
 
@@ -1133,7 +1259,7 @@ describe("normalizeAndValidateConfig()", () => {
1133
1259
  - binding should have a string \\"name\\" field.
1134
1260
  - binding should have a string \\"class_name\\" field.
1135
1261
 
1136
- - \\"durable_objects.bindings[1]\\": {\\"name\\":\\"VALID\\"}
1262
+ - \\"durable_objects.bindings[1]\\": {\\"name\\":\\"MISSING_CLASS\\"}
1137
1263
  - binding should have a string \\"class_name\\" field.
1138
1264
 
1139
1265
  - \\"durable_objects.bindings[2]\\": {\\"name\\":1555,\\"class_name\\":1666}
@@ -1143,7 +1269,22 @@ describe("normalizeAndValidateConfig()", () => {
1143
1269
  - \\"durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
1144
1270
  - binding should have a string \\"name\\" field.
1145
1271
  - binding should have a string \\"class_name\\" field.
1146
- - binding should, optionally, have a string \\"script_name\\" field."
1272
+ - the field \\"script_name\\", when present, should be a string.
1273
+
1274
+ - \\"durable_objects.bindings[4]\\": {\\"name\\":\\"SOMENAME\\",\\"class_name\\":\\"SomeClass\\",\\"environment\\":\\"staging\\"}
1275
+ - binding should have a \\"script_name\\" field if \\"environment\\" is present.
1276
+
1277
+ - \\"durable_objects.bindings[5]\\": {\\"name\\":1778,\\"class_name\\":1889,\\"script_name\\":1992,\\"environment\\":2111}
1278
+ - binding should have a string \\"name\\" field.
1279
+ - binding should have a string \\"class_name\\" field.
1280
+ - the field \\"script_name\\", when present, should be a string.
1281
+ - the field \\"environment\\", when present, should be a string.
1282
+
1283
+ - \\"durable_objects.bindings[6]\\": {\\"name\\":1772,\\"class_name\\":1883,\\"environment\\":2112}
1284
+ - binding should have a string \\"name\\" field.
1285
+ - binding should have a string \\"class_name\\" field.
1286
+ - the field \\"environment\\", when present, should be a string.
1287
+ - binding should have a \\"script_name\\" field if \\"environment\\" is present."
1147
1288
  `);
1148
1289
  });
1149
1290
  });
@@ -1358,6 +1499,151 @@ describe("normalizeAndValidateConfig()", () => {
1358
1499
  });
1359
1500
  });
1360
1501
 
1502
+ describe("services field", () => {
1503
+ it("should error if services is an object", () => {
1504
+ const { config, diagnostics } = normalizeAndValidateConfig(
1505
+ { services: {} } as unknown as RawConfig,
1506
+ undefined,
1507
+ { env: undefined }
1508
+ );
1509
+
1510
+ expect(config).toEqual(
1511
+ expect.not.objectContaining({ services: expect.anything })
1512
+ );
1513
+ expect(diagnostics.hasWarnings()).toBe(true);
1514
+ expect(diagnostics.hasErrors()).toBe(true);
1515
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1516
+ "Processing wrangler configuration:
1517
+ - \\"services\\" fields are experimental and may change or break at any time."
1518
+ `);
1519
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1520
+ "Processing wrangler configuration:
1521
+ - The field \\"services\\" should be an array but got {}."
1522
+ `);
1523
+ });
1524
+
1525
+ it("should error if services is a string", () => {
1526
+ const { config, diagnostics } = normalizeAndValidateConfig(
1527
+ { services: "BAD" } as unknown as RawConfig,
1528
+ undefined,
1529
+ { env: undefined }
1530
+ );
1531
+
1532
+ expect(config).toEqual(
1533
+ expect.not.objectContaining({ services: expect.anything })
1534
+ );
1535
+ expect(diagnostics.hasWarnings()).toBe(true);
1536
+ expect(diagnostics.hasErrors()).toBe(true);
1537
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1538
+ "Processing wrangler configuration:
1539
+ - \\"services\\" fields are experimental and may change or break at any time."
1540
+ `);
1541
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1542
+ "Processing wrangler configuration:
1543
+ - The field \\"services\\" should be an array but got \\"BAD\\"."
1544
+ `);
1545
+ });
1546
+
1547
+ it("should error if services is a number", () => {
1548
+ const { config, diagnostics } = normalizeAndValidateConfig(
1549
+ { services: 999 } as unknown as RawConfig,
1550
+ undefined,
1551
+ { env: undefined }
1552
+ );
1553
+
1554
+ expect(config).toEqual(
1555
+ expect.not.objectContaining({ services: expect.anything })
1556
+ );
1557
+ expect(diagnostics.hasWarnings()).toBe(true);
1558
+ expect(diagnostics.hasErrors()).toBe(true);
1559
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1560
+ "Processing wrangler configuration:
1561
+ - \\"services\\" fields are experimental and may change or break at any time."
1562
+ `);
1563
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1564
+ "Processing wrangler configuration:
1565
+ - The field \\"services\\" should be an array but got 999."
1566
+ `);
1567
+ });
1568
+
1569
+ it("should error if services is null", () => {
1570
+ const { config, diagnostics } = normalizeAndValidateConfig(
1571
+ { services: null } as unknown as RawConfig,
1572
+ undefined,
1573
+ { env: undefined }
1574
+ );
1575
+
1576
+ expect(config).toEqual(
1577
+ expect.not.objectContaining({ services: expect.anything })
1578
+ );
1579
+ expect(diagnostics.hasWarnings()).toBe(true);
1580
+ expect(diagnostics.hasErrors()).toBe(true);
1581
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1582
+ "Processing wrangler configuration:
1583
+ - \\"services\\" fields are experimental and may change or break at any time."
1584
+ `);
1585
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1586
+ "Processing wrangler configuration:
1587
+ - The field \\"services\\" should be an array but got null."
1588
+ `);
1589
+ });
1590
+
1591
+ it("should error if services bindings are not valid", () => {
1592
+ const { config, diagnostics } = normalizeAndValidateConfig(
1593
+ {
1594
+ services: [
1595
+ {},
1596
+ { binding: "SERVICE_BINDING_1" },
1597
+ { binding: 123, service: 456 },
1598
+ { binding: 123, service: 456, environment: 789 },
1599
+ { binding: "SERVICE_BINDING_1", service: 456, environment: 789 },
1600
+ {
1601
+ binding: 123,
1602
+ service: "SERVICE_BINDING_SERVICE_1",
1603
+ environment: 789,
1604
+ },
1605
+ {
1606
+ binding: 123,
1607
+ service: 456,
1608
+ environment: "SERVICE_BINDING_ENVIRONMENT_1",
1609
+ },
1610
+ ],
1611
+ } as unknown as RawConfig,
1612
+ undefined,
1613
+ { env: undefined }
1614
+ );
1615
+
1616
+ expect(config).toEqual(
1617
+ expect.not.objectContaining({
1618
+ services: { bindings: expect.anything },
1619
+ })
1620
+ );
1621
+ expect(diagnostics.hasWarnings()).toBe(true);
1622
+ expect(diagnostics.hasErrors()).toBe(true);
1623
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1624
+ "Processing wrangler configuration:
1625
+ - \\"services\\" fields are experimental and may change or break at any time."
1626
+ `);
1627
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1628
+ "Processing wrangler configuration:
1629
+ - \\"services[0]\\" bindings should have a string \\"binding\\" field but got {}.
1630
+ - \\"services[0]\\" bindings should have a string \\"service\\" field but got {}.
1631
+ - \\"services[1]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":\\"SERVICE_BINDING_1\\"}.
1632
+ - \\"services[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456}.
1633
+ - \\"services[2]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":123,\\"service\\":456}.
1634
+ - \\"services[3]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":789}.
1635
+ - \\"services[3]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":789}.
1636
+ - \\"services[3]\\" bindings should have a string \\"environment\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":789}.
1637
+ - \\"services[4]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":\\"SERVICE_BINDING_1\\",\\"service\\":456,\\"environment\\":789}.
1638
+ - \\"services[4]\\" bindings should have a string \\"environment\\" field but got {\\"binding\\":\\"SERVICE_BINDING_1\\",\\"service\\":456,\\"environment\\":789}.
1639
+ - \\"services[5]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":\\"SERVICE_BINDING_SERVICE_1\\",\\"environment\\":789}.
1640
+ - \\"services[5]\\" bindings should have a string \\"environment\\" field but got {\\"binding\\":123,\\"service\\":\\"SERVICE_BINDING_SERVICE_1\\",\\"environment\\":789}.
1641
+ - \\"services[6]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":\\"SERVICE_BINDING_ENVIRONMENT_1\\"}.
1642
+ - \\"services[6]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":\\"SERVICE_BINDING_ENVIRONMENT_1\\"}."
1643
+ `);
1644
+ });
1645
+ });
1646
+
1361
1647
  describe("unsafe field", () => {
1362
1648
  it("should error if unsafe is an array", () => {
1363
1649
  const { config, diagnostics } = normalizeAndValidateConfig(
@@ -1622,14 +1908,7 @@ describe("normalizeAndValidateConfig()", () => {
1622
1908
  - Deprecation: \\"zone_id\\":
1623
1909
  This is unnecessary since we can deduce this from routes directly.
1624
1910
  - Deprecation: \\"experimental_services\\":
1625
- The \\"experimental_services\\" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
1626
- \`\`\`
1627
- [[unsafe.bindings]]
1628
- name = \\"mock-name\\"
1629
- type = \\"service\\"
1630
- service = \\"SERVICE\\"
1631
- environment = \\"ENV\\"
1632
- \`\`\`"
1911
+ The \\"experimental_services\\" field is no longer supported. Simply rename the [experimental_services] field to [services]."
1633
1912
  `);
1634
1913
  });
1635
1914
  });
@@ -1722,6 +2001,8 @@ describe("normalizeAndValidateConfig()", () => {
1722
2001
  cwd: "CWD",
1723
2002
  watch_dir: "WATCH_DIR",
1724
2003
  },
2004
+ minify: true,
2005
+ node_compat: true,
1725
2006
  };
1726
2007
 
1727
2008
  const { config, diagnostics } = normalizeAndValidateConfig(
@@ -1762,6 +2043,8 @@ describe("normalizeAndValidateConfig()", () => {
1762
2043
  cwd: "ENV_CWD",
1763
2044
  watch_dir: "ENV_WATCH_DIR",
1764
2045
  },
2046
+ minify: false,
2047
+ node_compat: false,
1765
2048
  };
1766
2049
  const rawConfig: RawConfig = {
1767
2050
  name: "mock-name",
@@ -1781,6 +2064,8 @@ describe("normalizeAndValidateConfig()", () => {
1781
2064
  cwd: "CWD",
1782
2065
  watch_dir: "WATCH_DIR",
1783
2066
  },
2067
+ minify: true,
2068
+ node_compat: true,
1784
2069
  env: {
1785
2070
  ENV1: rawEnv,
1786
2071
  },
@@ -2031,6 +2316,8 @@ describe("normalizeAndValidateConfig()", () => {
2031
2316
  cwd: 1555,
2032
2317
  watch_dir: 1666,
2033
2318
  },
2319
+ minify: "INVALID",
2320
+ node_compat: "INVALID",
2034
2321
  } as unknown as RawEnvironment;
2035
2322
 
2036
2323
  const { config, diagnostics } = normalizeAndValidateConfig(
@@ -2045,8 +2332,8 @@ describe("normalizeAndValidateConfig()", () => {
2045
2332
  "Processing wrangler configuration:
2046
2333
 
2047
2334
  - \\"env.ENV1\\" environment configuration
2048
- - Expected \\"route\\" to be either a string, or an object with shape { pattern, zone_id | zone_name }, but got 888.
2049
- - Expected \\"routes\\" to be an array of either strings or objects with the shape { pattern, zone_id | zone_name }, but these weren't valid: [
2335
+ - Expected \\"route\\" to be either a string, or an object with shape { pattern, custom_domain, zone_id | zone_name }, but got 888.
2336
+ - Expected \\"routes\\" to be an array of either strings or objects with the shape { pattern, custom_domain, zone_id | zone_name }, but these weren't valid: [
2050
2337
  666,
2051
2338
  777
2052
2339
  ].
@@ -2063,7 +2350,9 @@ describe("normalizeAndValidateConfig()", () => {
2063
2350
  - Expected \\"tsconfig\\" to be of type string but got 123.
2064
2351
  - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got 111.
2065
2352
  - Expected \\"main\\" to be of type string but got 1333.
2066
- - Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\"."
2353
+ - Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\".
2354
+ - Expected \\"minify\\" to be of type boolean but got \\"INVALID\\".
2355
+ - Expected \\"node_compat\\" to be of type boolean but got \\"INVALID\\"."
2067
2356
  `);
2068
2357
  });
2069
2358
 
@@ -2285,6 +2574,7 @@ describe("normalizeAndValidateConfig()", () => {
2285
2574
  })
2286
2575
  );
2287
2576
  expect(diagnostics.hasWarnings()).toBe(false);
2577
+ expect(diagnostics.hasErrors()).toBe(true);
2288
2578
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2289
2579
  "Processing wrangler configuration:
2290
2580
 
@@ -2304,7 +2594,7 @@ describe("normalizeAndValidateConfig()", () => {
2304
2594
  - \\"env.ENV1.durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
2305
2595
  - binding should have a string \\"name\\" field.
2306
2596
  - binding should have a string \\"class_name\\" field.
2307
- - binding should, optionally, have a string \\"script_name\\" field."
2597
+ - the field \\"script_name\\", when present, should be a string."
2308
2598
  `);
2309
2599
  });
2310
2600
  });
@@ -2869,14 +3159,7 @@ describe("normalizeAndValidateConfig()", () => {
2869
3159
  - Deprecation: \\"zone_id\\":
2870
3160
  This is unnecessary since we can deduce this from routes directly.
2871
3161
  - Deprecation: \\"experimental_services\\":
2872
- The \\"experimental_services\\" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
2873
- \`\`\`
2874
- [[unsafe.bindings]]
2875
- name = \\"mock-name\\"
2876
- type = \\"service\\"
2877
- service = \\"SERVICE\\"
2878
- environment = \\"ENV\\"
2879
- \`\`\`"
3162
+ The \\"experimental_services\\" field is no longer supported. Simply rename the [experimental_services] field to [services]."
2880
3163
  `);
2881
3164
  });
2882
3165
  });