wrangler 0.0.0-ea8f8d7 → 0.0.0-eb22835

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 (78) hide show
  1. package/kv-asset-handler.js +1 -0
  2. package/package.json +4 -2
  3. package/src/__tests__/configuration.test.ts +354 -199
  4. package/src/__tests__/dev.test.tsx +176 -65
  5. package/src/__tests__/helpers/mock-dialogs.ts +41 -1
  6. package/src/__tests__/index.test.ts +2 -1
  7. package/src/__tests__/init.test.ts +175 -95
  8. package/src/__tests__/jest.setup.ts +30 -0
  9. package/src/__tests__/kv.test.ts +8 -8
  10. package/src/__tests__/package-manager.test.ts +154 -7
  11. package/src/__tests__/pages.test.ts +115 -18
  12. package/src/__tests__/publish.test.ts +528 -175
  13. package/src/__tests__/secret.test.ts +4 -4
  14. package/src/__tests__/user.test.ts +1 -0
  15. package/src/__tests__/whoami.test.tsx +34 -0
  16. package/src/bundle.ts +9 -5
  17. package/src/cfetch/internal.ts +12 -9
  18. package/src/config/config.ts +1 -1
  19. package/src/config/environment.ts +1 -1
  20. package/src/config/validation-helpers.ts +10 -1
  21. package/src/config/validation.ts +40 -22
  22. package/src/create-worker-preview.ts +15 -15
  23. package/src/dev/dev.tsx +32 -59
  24. package/src/dev/local.tsx +10 -7
  25. package/src/dev/remote.tsx +30 -17
  26. package/src/dev/use-esbuild.ts +1 -4
  27. package/src/dialogs.tsx +48 -0
  28. package/src/generate-auth-url.ts +33 -0
  29. package/src/generate-random-state.ts +16 -0
  30. package/src/index.tsx +301 -232
  31. package/src/open-in-browser.ts +1 -3
  32. package/src/package-manager.ts +50 -3
  33. package/src/pages.tsx +298 -229
  34. package/src/parse.ts +2 -1
  35. package/src/proxy.ts +19 -6
  36. package/src/publish.ts +154 -16
  37. package/src/sites.tsx +49 -18
  38. package/src/user.tsx +24 -25
  39. package/src/whoami.tsx +3 -2
  40. package/src/worker.ts +2 -1
  41. package/src/zones.ts +73 -0
  42. package/templates/new-worker-scheduled.js +17 -0
  43. package/templates/new-worker-scheduled.ts +32 -0
  44. package/templates/static-asset-facade.js +2 -6
  45. package/wrangler-dist/cli.js +73874 -73485
  46. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  47. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  48. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  49. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  50. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  51. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  52. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  53. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  54. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  55. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  56. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  57. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  58. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  59. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  60. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  61. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  62. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  63. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  64. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  65. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  66. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  67. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  68. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  69. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  70. package/vendor/wrangler-mime/LICENSE +0 -21
  71. package/vendor/wrangler-mime/Mime.js +0 -97
  72. package/vendor/wrangler-mime/README.md +0 -187
  73. package/vendor/wrangler-mime/cli.js +0 -46
  74. package/vendor/wrangler-mime/index.js +0 -4
  75. package/vendor/wrangler-mime/lite.js +0 -4
  76. package/vendor/wrangler-mime/package.json +0 -52
  77. package/vendor/wrangler-mime/types/other.js +0 -1
  78. package/vendor/wrangler-mime/types/standard.js +0 -1
@@ -0,0 +1 @@
1
+ export * from "@cloudflare/kv-asset-handler";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "0.0.0-ea8f8d7",
3
+ "version": "0.0.0-eb22835",
4
4
  "author": "wrangler@cloudflare.com",
5
5
  "description": "Command-line interface for all things Cloudflare Workers",
6
6
  "bin": {
@@ -36,6 +36,7 @@
36
36
  "cli"
37
37
  ],
38
38
  "dependencies": {
39
+ "@cloudflare/kv-asset-handler": "^0.2.0",
39
40
  "@esbuild-plugins/node-globals-polyfill": "^0.1.1",
40
41
  "@esbuild-plugins/node-modules-polyfill": "^0.1.4",
41
42
  "blake3-wasm": "^2.1.5",
@@ -98,7 +99,7 @@
98
99
  "timeago.js": "^4.0.2",
99
100
  "tmp-promise": "^3.0.3",
100
101
  "ts-dedent": "^2.2.0",
101
- "undici": "^5.3.0",
102
+ "undici": "^5.5.1",
102
103
  "update-check": "^1.5.4",
103
104
  "ws": "^8.5.0",
104
105
  "yargs": "^17.4.1"
@@ -113,6 +114,7 @@
113
114
  "templates",
114
115
  "vendor",
115
116
  "import_meta_url.js",
117
+ "kv-asset-handler.js",
116
118
  "Cloudflare_CA.pem"
117
119
  ],
118
120
  "scripts": {
@@ -19,7 +19,7 @@ describe("normalizeAndValidateConfig()", () => {
19
19
  build: {
20
20
  command: undefined,
21
21
  cwd: undefined,
22
- watch_dir: undefined,
22
+ watch_dir: "./src",
23
23
  },
24
24
  compatibility_date: undefined,
25
25
  compatibility_flags: [],
@@ -165,68 +165,110 @@ describe("normalizeAndValidateConfig()", () => {
165
165
  `);
166
166
  });
167
167
 
168
- it("should override `migrations` config defaults with provided values", () => {
169
- const expectedConfig: RawConfig = {
170
- migrations: [
171
- {
172
- tag: "TAG",
173
- new_classes: ["CLASS_1", "CLASS_2"],
174
- renamed_classes: [
175
- {
176
- from: "FROM_CLASS",
177
- to: "TO_CLASS",
178
- },
179
- ],
180
- deleted_classes: ["CLASS_3", "CLASS_4"],
181
- },
182
- ],
183
- };
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
+ };
184
185
 
185
- const { config, diagnostics } = normalizeAndValidateConfig(
186
- expectedConfig,
187
- undefined,
188
- { env: undefined }
189
- );
186
+ const { config, diagnostics } = normalizeAndValidateConfig(
187
+ expectedConfig,
188
+ undefined,
189
+ { env: undefined }
190
+ );
190
191
 
191
- expect(config).toEqual(expect.objectContaining(expectedConfig));
192
- expect(diagnostics.hasErrors()).toBe(false);
193
- expect(diagnostics.hasWarnings()).toBe(false);
194
- });
192
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
193
+ expect(diagnostics.hasErrors()).toBe(false);
194
+ expect(diagnostics.hasWarnings()).toBe(false);
195
+ });
195
196
 
196
- it("should error on invalid `migrations` values", () => {
197
- const expectedConfig = {
198
- migrations: [
199
- {
200
- tag: 111,
201
- new_classes: [222, 333],
202
- renamed_classes: [
203
- {
204
- from: 444,
205
- to: 555,
206
- },
207
- ],
208
- deleted_classes: [666, 777],
209
- },
210
- ],
211
- };
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
+ };
212
213
 
213
- const { config, diagnostics } = normalizeAndValidateConfig(
214
- expectedConfig as unknown as RawConfig,
215
- undefined,
216
- { env: undefined }
217
- );
214
+ const { config, diagnostics } = normalizeAndValidateConfig(
215
+ expectedConfig as unknown as RawConfig,
216
+ undefined,
217
+ { env: undefined }
218
+ );
218
219
 
219
- expect(config).toEqual(expect.objectContaining(expectedConfig));
220
- expect(diagnostics.hasWarnings()).toBe(false);
221
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
222
- "Processing wrangler configuration:
223
- - Expected \\"migrations[0].tag\\" to be of type string but got 111.
224
- - Expected \\"migrations[0].new_classes.[0]\\" to be of type string but got 222.
225
- - Expected \\"migrations[0].new_classes.[1]\\" to be of type string but got 333.
226
- - Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
227
- - Expected \\"migrations[0].deleted_classes.[0]\\" to be of type string but got 666.
228
- - Expected \\"migrations[0].deleted_classes.[1]\\" to be of type string but got 777."
229
- `);
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
+ });
230
272
  });
231
273
 
232
274
  describe("site", () => {
@@ -396,6 +438,40 @@ describe("normalizeAndValidateConfig()", () => {
396
438
  expect(diagnostics.hasWarnings()).toBe(false);
397
439
  });
398
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
+
399
475
  it("should error on invalid `wasm_modules` paths", () => {
400
476
  const expectedConfig = {
401
477
  wasm_modules: {
@@ -803,171 +879,250 @@ describe("normalizeAndValidateConfig()", () => {
803
879
  `);
804
880
  });
805
881
 
806
- it("should error on invalid `name` value with spaces", () => {
807
- const expectedConfig: RawEnvironment = {
808
- name: "NCC 1701 D",
809
- } as unknown as RawEnvironment;
882
+ describe("name", () => {
883
+ it("should error on invalid `name` value with spaces", () => {
884
+ const expectedConfig: RawEnvironment = {
885
+ name: "NCC 1701 D",
886
+ } as unknown as RawEnvironment;
810
887
 
811
- const { config, diagnostics } = normalizeAndValidateConfig(
812
- expectedConfig,
813
- undefined,
814
- { env: undefined }
815
- );
888
+ const { config, diagnostics } = normalizeAndValidateConfig(
889
+ expectedConfig,
890
+ undefined,
891
+ { env: undefined }
892
+ );
816
893
 
817
- expect(config).toEqual(expect.objectContaining(expectedConfig));
818
- expect(diagnostics.hasWarnings()).toBe(false);
819
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
820
- "Processing wrangler configuration:
821
- - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"NCC 1701 D\\"."
822
- `);
823
- });
894
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
895
+ expect(diagnostics.hasWarnings()).toBe(false);
896
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
897
+ "Processing wrangler configuration:
898
+ - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"NCC 1701 D\\"."
899
+ `);
900
+ });
824
901
 
825
- it("should be valid `name` with underscores", () => {
826
- const expectedConfig: RawEnvironment = {
827
- name: "enterprise_nx_01",
828
- } as unknown as RawEnvironment;
902
+ it("should be valid `name` with underscores", () => {
903
+ const expectedConfig: RawEnvironment = {
904
+ name: "enterprise_nx_01",
905
+ } as unknown as RawEnvironment;
829
906
 
830
- const { config, diagnostics } = normalizeAndValidateConfig(
831
- expectedConfig,
832
- undefined,
833
- { env: undefined }
834
- );
907
+ const { config, diagnostics } = normalizeAndValidateConfig(
908
+ expectedConfig,
909
+ undefined,
910
+ { env: undefined }
911
+ );
835
912
 
836
- expect(config).toEqual(expect.objectContaining(expectedConfig));
837
- expect(diagnostics.hasWarnings()).toBe(false);
838
- expect(diagnostics.hasErrors()).toBe(false);
839
- });
913
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
914
+ expect(diagnostics.hasWarnings()).toBe(false);
915
+ expect(diagnostics.hasErrors()).toBe(false);
916
+ });
840
917
 
841
- it("should error on invalid `name` value with special characters", () => {
842
- const expectedConfig: RawEnvironment = {
843
- name: "Thy'lek-Shran",
844
- } as unknown as RawEnvironment;
918
+ it("should error on invalid `name` value with special characters", () => {
919
+ const expectedConfig: RawEnvironment = {
920
+ name: "Thy'lek-Shran",
921
+ } as unknown as RawEnvironment;
845
922
 
846
- const { config, diagnostics } = normalizeAndValidateConfig(
847
- expectedConfig,
848
- undefined,
849
- { env: undefined }
850
- );
923
+ const { config, diagnostics } = normalizeAndValidateConfig(
924
+ expectedConfig,
925
+ undefined,
926
+ { env: undefined }
927
+ );
851
928
 
852
- expect(config).toEqual(expect.objectContaining(expectedConfig));
853
- expect(diagnostics.hasWarnings()).toBe(false);
854
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
855
- "Processing wrangler configuration:
856
- - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"Thy'lek-Shran\\"."
857
- `);
858
- });
929
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
930
+ expect(diagnostics.hasWarnings()).toBe(false);
931
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
932
+ "Processing wrangler configuration:
933
+ - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"Thy'lek-Shran\\"."
934
+ `);
935
+ });
859
936
 
860
- it("should error on invalid `name` value with only special characters", () => {
861
- const expectedConfig: RawEnvironment = {
862
- name: "!@#$%^&*(()",
863
- } as unknown as RawEnvironment;
937
+ it("should error on invalid `name` value with only special characters", () => {
938
+ const expectedConfig: RawEnvironment = {
939
+ name: "!@#$%^&*(()",
940
+ } as unknown as RawEnvironment;
864
941
 
865
- const { config, diagnostics } = normalizeAndValidateConfig(
866
- expectedConfig,
867
- undefined,
868
- { env: undefined }
869
- );
942
+ const { config, diagnostics } = normalizeAndValidateConfig(
943
+ expectedConfig,
944
+ undefined,
945
+ { env: undefined }
946
+ );
870
947
 
871
- expect(config).toEqual(expect.objectContaining(expectedConfig));
872
- expect(diagnostics.hasWarnings()).toBe(false);
873
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
874
- "Processing wrangler configuration:
875
- - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"!@#$%^&*(()\\"."
876
- `);
948
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
949
+ expect(diagnostics.hasWarnings()).toBe(false);
950
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
951
+ "Processing wrangler configuration:
952
+ - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"!@#$%^&*(()\\"."
953
+ `);
954
+ });
877
955
  });
878
956
 
879
- it("should override build.upload config defaults with provided values and warn about deprecations", () => {
880
- const expectedConfig: RawEnvironment = {
881
- build: {
882
- upload: {
883
- dir: "src",
884
- format: "modules",
885
- main: "index.ts",
886
- rules: [{ type: "Text", globs: ["GLOB"], fallthrough: true }],
957
+ describe("build", () => {
958
+ it("should override build.upload config defaults with provided values and warn about deprecations", () => {
959
+ const expectedConfig: RawEnvironment = {
960
+ build: {
961
+ upload: {
962
+ dir: "src",
963
+ format: "modules",
964
+ main: "index.ts",
965
+ rules: [{ type: "Text", globs: ["GLOB"], fallthrough: true }],
966
+ },
887
967
  },
888
- },
889
- };
968
+ };
890
969
 
891
- const { config, diagnostics } = normalizeAndValidateConfig(
892
- expectedConfig,
893
- path.resolve("project/wrangler.toml"),
894
- { env: undefined }
895
- );
970
+ const { config, diagnostics } = normalizeAndValidateConfig(
971
+ expectedConfig,
972
+ path.resolve("project/wrangler.toml"),
973
+ { env: undefined }
974
+ );
896
975
 
897
- expect(config.main).toEqual(path.resolve("project/src/index.ts"));
898
- expect(config.build.upload).toBeUndefined();
899
- expect(diagnostics.hasErrors()).toBe(false);
900
- expect(diagnostics.hasWarnings()).toBe(true);
901
- expect(normalizePath(diagnostics.renderWarnings()))
902
- .toMatchInlineSnapshot(`
903
- "Processing project/wrangler.toml configuration:
904
- - Deprecation: \\"build.upload.format\\":
905
- The format is inferred automatically from the code.
906
- - Deprecation: \\"build.upload.main\\":
907
- Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
908
- Then add the top level \`main\` field to your configuration file:
909
- \`\`\`
910
- main = \\"src/index.ts\\"
911
- \`\`\`
912
- - Deprecation: \\"build.upload.dir\\":
913
- Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the Worker.
914
- - Deprecation: The \`build.upload.rules\` config field is no longer used, the rules should be specified via the \`rules\` config field. Delete the \`build.upload\` field from the configuration file, and add this:
915
- \`\`\`
916
- [[rules]]
917
- type = \\"Text\\"
918
- globs = [ \\"GLOB\\" ]
919
- fallthrough = true
920
- \`\`\`"
921
- `);
922
- });
976
+ expect(config.main).toEqual(path.resolve("project/src/index.ts"));
977
+ expect(config.build.upload).toBeUndefined();
978
+ expect(diagnostics.hasErrors()).toBe(false);
979
+ expect(diagnostics.hasWarnings()).toBe(true);
980
+ expect(normalizePath(diagnostics.renderWarnings()))
981
+ .toMatchInlineSnapshot(`
982
+ "Processing project/wrangler.toml configuration:
983
+ - Deprecation: \\"build.upload.format\\":
984
+ The format is inferred automatically from the code.
985
+ - Deprecation: \\"build.upload.main\\":
986
+ Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
987
+ Then add the top level \`main\` field to your configuration file:
988
+ \`\`\`
989
+ main = \\"src/index.ts\\"
990
+ \`\`\`
991
+ - Deprecation: \\"build.upload.dir\\":
992
+ Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the Worker.
993
+ - Deprecation: The \`build.upload.rules\` config field is no longer used, the rules should be specified via the \`rules\` config field. Delete the \`build.upload\` field from the configuration file, and add this:
994
+ \`\`\`
995
+ [[rules]]
996
+ type = \\"Text\\"
997
+ globs = [ \\"GLOB\\" ]
998
+ fallthrough = true
999
+ \`\`\`"
1000
+ `);
1001
+ });
923
1002
 
924
- it("should default custom build watch directories to src", () => {
925
- const expectedConfig: RawEnvironment = {
926
- build: {
927
- command: "execute some --build",
928
- },
929
- };
1003
+ it("should default custom build watch directories to src", () => {
1004
+ const expectedConfig: RawEnvironment = {
1005
+ build: {
1006
+ command: "execute some --build",
1007
+ },
1008
+ };
930
1009
 
931
- const { config, diagnostics } = normalizeAndValidateConfig(
932
- expectedConfig,
933
- undefined,
934
- { env: undefined }
935
- );
1010
+ const { config, diagnostics } = normalizeAndValidateConfig(
1011
+ expectedConfig,
1012
+ undefined,
1013
+ { env: undefined }
1014
+ );
936
1015
 
937
- expect(config.build).toEqual(
938
- expect.objectContaining({
939
- command: "execute some --build",
940
- watch_dir: "./src",
941
- })
942
- );
1016
+ expect(config.build).toEqual(
1017
+ expect.objectContaining({
1018
+ command: "execute some --build",
1019
+ watch_dir: "./src",
1020
+ })
1021
+ );
943
1022
 
944
- expect(diagnostics.hasErrors()).toBe(false);
945
- expect(diagnostics.hasWarnings()).toBe(false);
946
- });
1023
+ expect(diagnostics.hasErrors()).toBe(false);
1024
+ expect(diagnostics.hasWarnings()).toBe(false);
1025
+ });
947
1026
 
948
- it("should resolve custom build watch directories relative to wrangler.toml", async () => {
949
- const expectedConfig: RawEnvironment = {
950
- build: {
951
- command: "execute some --build",
952
- watch_dir: "some/path",
953
- },
954
- };
1027
+ it("should resolve custom build watch directories relative to wrangler.toml", async () => {
1028
+ const expectedConfig: RawEnvironment = {
1029
+ build: {
1030
+ command: "execute some --build",
1031
+ watch_dir: "some/path",
1032
+ },
1033
+ };
955
1034
 
956
- const { config, diagnostics } = normalizeAndValidateConfig(
957
- expectedConfig,
958
- "project/wrangler.toml",
959
- { env: undefined }
960
- );
1035
+ const { config, diagnostics } = normalizeAndValidateConfig(
1036
+ expectedConfig,
1037
+ "project/wrangler.toml",
1038
+ { env: undefined }
1039
+ );
961
1040
 
962
- expect(config.build).toEqual(
963
- expect.objectContaining({
964
- command: "execute some --build",
965
- watch_dir: path.normalize("project/some/path"),
966
- })
967
- );
1041
+ expect(config.build).toEqual(
1042
+ expect.objectContaining({
1043
+ command: "execute some --build",
1044
+ watch_dir: path.normalize("project/some/path"),
1045
+ })
1046
+ );
968
1047
 
969
- expect(diagnostics.hasErrors()).toBe(false);
970
- expect(diagnostics.hasWarnings()).toBe(false);
1048
+ expect(diagnostics.hasErrors()).toBe(false);
1049
+ expect(diagnostics.hasWarnings()).toBe(false);
1050
+ });
1051
+
1052
+ it("should allow watch_dir to be an array of paths", () => {
1053
+ const expectedConfig: RawEnvironment = {
1054
+ build: {
1055
+ command: "execute some --build",
1056
+ watch_dir: ["some/path/a", "some/path/b", "some/path/c"],
1057
+ },
1058
+ };
1059
+
1060
+ const { config, diagnostics } = normalizeAndValidateConfig(
1061
+ expectedConfig,
1062
+ "project/wrangler.toml",
1063
+ { env: undefined }
1064
+ );
1065
+
1066
+ expect(config.build).toEqual(
1067
+ expect.objectContaining({
1068
+ command: "execute some --build",
1069
+ watch_dir: [
1070
+ path.normalize("project/some/path/a"),
1071
+ path.normalize("project/some/path/b"),
1072
+ path.normalize("project/some/path/c"),
1073
+ ],
1074
+ })
1075
+ );
1076
+
1077
+ expect(diagnostics.hasErrors()).toBe(false);
1078
+ expect(diagnostics.hasWarnings()).toBe(false);
1079
+ });
1080
+
1081
+ it("should error when the watch_dir array isn't an array of strings", () => {
1082
+ const expectedConfig: RawEnvironment = {
1083
+ build: {
1084
+ command: "execute some --build",
1085
+ watch_dir: [
1086
+ "some/path/a",
1087
+ "some/path/b",
1088
+ // @ts-expect-error intentionally bad "paths"
1089
+ 123,
1090
+ "some/path/c",
1091
+ // @ts-expect-error intentionally bad "paths"
1092
+ false,
1093
+ ],
1094
+ },
1095
+ };
1096
+
1097
+ const { config, diagnostics } = normalizeAndValidateConfig(
1098
+ expectedConfig,
1099
+ "project/wrangler.toml",
1100
+ { env: undefined }
1101
+ );
1102
+
1103
+ expect(config.build).toEqual(
1104
+ expect.objectContaining({
1105
+ command: "execute some --build",
1106
+ watch_dir: [
1107
+ path.normalize("project/some/path/a"),
1108
+ path.normalize("project/some/path/b"),
1109
+ path.normalize("project/123"),
1110
+ path.normalize("project/some/path/c"),
1111
+ path.normalize("project/false"),
1112
+ ],
1113
+ })
1114
+ );
1115
+
1116
+ expect(diagnostics.hasWarnings()).toBe(false);
1117
+ expect(diagnostics.hasErrors()).toBe(true);
1118
+
1119
+ expect(normalizePath(diagnostics.renderErrors()))
1120
+ .toMatchInlineSnapshot(`
1121
+ "Processing project/wrangler.toml configuration:
1122
+ - Expected \\"build.watch_dir.[2]\\" to be of type string but got 123.
1123
+ - Expected \\"build.watch_dir.[4]\\" to be of type string but got false."
1124
+ `);
1125
+ });
971
1126
  });
972
1127
 
973
1128
  describe("durable_objects field", () => {