wrangler 2.0.8 → 2.0.12

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 (67) hide show
  1. package/kv-asset-handler.js +1 -0
  2. package/package.json +3 -1
  3. package/src/__tests__/configuration.test.ts +255 -142
  4. package/src/__tests__/dev.test.tsx +88 -58
  5. package/src/__tests__/index.test.ts +2 -1
  6. package/src/__tests__/init.test.ts +3 -0
  7. package/src/__tests__/kv.test.ts +23 -2
  8. package/src/__tests__/pages.test.ts +98 -1
  9. package/src/__tests__/publish.test.ts +514 -162
  10. package/src/__tests__/whoami.test.tsx +34 -0
  11. package/src/bundle.ts +9 -5
  12. package/src/cfetch/internal.ts +6 -9
  13. package/src/config/config.ts +1 -1
  14. package/src/config/environment.ts +1 -1
  15. package/src/config/validation-helpers.ts +10 -1
  16. package/src/config/validation.ts +22 -13
  17. package/src/create-worker-preview.ts +15 -15
  18. package/src/dev/dev.tsx +32 -56
  19. package/src/dev/local.tsx +10 -7
  20. package/src/dev/remote.tsx +30 -17
  21. package/src/dev/use-esbuild.ts +1 -4
  22. package/src/index.tsx +239 -244
  23. package/src/kv.ts +1 -1
  24. package/src/pages.tsx +295 -229
  25. package/src/parse.ts +21 -1
  26. package/src/proxy.ts +19 -6
  27. package/src/publish.ts +154 -16
  28. package/src/sites.tsx +49 -18
  29. package/src/user.tsx +12 -1
  30. package/src/whoami.tsx +3 -2
  31. package/src/worker.ts +2 -1
  32. package/src/zones.ts +73 -0
  33. package/templates/static-asset-facade.js +1 -5
  34. package/wrangler-dist/cli.js +73693 -73458
  35. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  36. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  37. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  38. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  39. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  40. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  41. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  42. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  43. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  44. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  45. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  46. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  47. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  48. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  49. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  50. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  51. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  52. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  53. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  54. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  55. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  56. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  57. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  58. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  59. package/vendor/wrangler-mime/LICENSE +0 -21
  60. package/vendor/wrangler-mime/Mime.js +0 -97
  61. package/vendor/wrangler-mime/README.md +0 -187
  62. package/vendor/wrangler-mime/cli.js +0 -46
  63. package/vendor/wrangler-mime/index.js +0 -4
  64. package/vendor/wrangler-mime/lite.js +0 -4
  65. package/vendor/wrangler-mime/package.json +0 -52
  66. package/vendor/wrangler-mime/types/other.js +0 -1
  67. 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": "2.0.8",
3
+ "version": "2.0.12",
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",
@@ -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: [],
@@ -438,6 +438,40 @@ describe("normalizeAndValidateConfig()", () => {
438
438
  expect(diagnostics.hasWarnings()).toBe(false);
439
439
  });
440
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
+
441
475
  it("should error on invalid `wasm_modules` paths", () => {
442
476
  const expectedConfig = {
443
477
  wasm_modules: {
@@ -845,171 +879,250 @@ describe("normalizeAndValidateConfig()", () => {
845
879
  `);
846
880
  });
847
881
 
848
- it("should error on invalid `name` value with spaces", () => {
849
- const expectedConfig: RawEnvironment = {
850
- name: "NCC 1701 D",
851
- } 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;
852
887
 
853
- const { config, diagnostics } = normalizeAndValidateConfig(
854
- expectedConfig,
855
- undefined,
856
- { env: undefined }
857
- );
888
+ const { config, diagnostics } = normalizeAndValidateConfig(
889
+ expectedConfig,
890
+ undefined,
891
+ { env: undefined }
892
+ );
858
893
 
859
- expect(config).toEqual(expect.objectContaining(expectedConfig));
860
- expect(diagnostics.hasWarnings()).toBe(false);
861
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
862
- "Processing wrangler configuration:
863
- - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"NCC 1701 D\\"."
864
- `);
865
- });
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
+ });
866
901
 
867
- it("should be valid `name` with underscores", () => {
868
- const expectedConfig: RawEnvironment = {
869
- name: "enterprise_nx_01",
870
- } 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;
871
906
 
872
- const { config, diagnostics } = normalizeAndValidateConfig(
873
- expectedConfig,
874
- undefined,
875
- { env: undefined }
876
- );
907
+ const { config, diagnostics } = normalizeAndValidateConfig(
908
+ expectedConfig,
909
+ undefined,
910
+ { env: undefined }
911
+ );
877
912
 
878
- expect(config).toEqual(expect.objectContaining(expectedConfig));
879
- expect(diagnostics.hasWarnings()).toBe(false);
880
- expect(diagnostics.hasErrors()).toBe(false);
881
- });
913
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
914
+ expect(diagnostics.hasWarnings()).toBe(false);
915
+ expect(diagnostics.hasErrors()).toBe(false);
916
+ });
882
917
 
883
- it("should error on invalid `name` value with special characters", () => {
884
- const expectedConfig: RawEnvironment = {
885
- name: "Thy'lek-Shran",
886
- } 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;
887
922
 
888
- const { config, diagnostics } = normalizeAndValidateConfig(
889
- expectedConfig,
890
- undefined,
891
- { env: undefined }
892
- );
923
+ const { config, diagnostics } = normalizeAndValidateConfig(
924
+ expectedConfig,
925
+ undefined,
926
+ { env: undefined }
927
+ );
893
928
 
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 \\"Thy'lek-Shran\\"."
899
- `);
900
- });
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
+ });
901
936
 
902
- it("should error on invalid `name` value with only special characters", () => {
903
- const expectedConfig: RawEnvironment = {
904
- name: "!@#$%^&*(()",
905
- } 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;
906
941
 
907
- const { config, diagnostics } = normalizeAndValidateConfig(
908
- expectedConfig,
909
- undefined,
910
- { env: undefined }
911
- );
942
+ const { config, diagnostics } = normalizeAndValidateConfig(
943
+ expectedConfig,
944
+ undefined,
945
+ { env: undefined }
946
+ );
912
947
 
913
- expect(config).toEqual(expect.objectContaining(expectedConfig));
914
- expect(diagnostics.hasWarnings()).toBe(false);
915
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
916
- "Processing wrangler configuration:
917
- - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"!@#$%^&*(()\\"."
918
- `);
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
+ });
919
955
  });
920
956
 
921
- it("should override build.upload config defaults with provided values and warn about deprecations", () => {
922
- const expectedConfig: RawEnvironment = {
923
- build: {
924
- upload: {
925
- dir: "src",
926
- format: "modules",
927
- main: "index.ts",
928
- 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
+ },
929
967
  },
930
- },
931
- };
968
+ };
932
969
 
933
- const { config, diagnostics } = normalizeAndValidateConfig(
934
- expectedConfig,
935
- path.resolve("project/wrangler.toml"),
936
- { env: undefined }
937
- );
970
+ const { config, diagnostics } = normalizeAndValidateConfig(
971
+ expectedConfig,
972
+ path.resolve("project/wrangler.toml"),
973
+ { env: undefined }
974
+ );
938
975
 
939
- expect(config.main).toEqual(path.resolve("project/src/index.ts"));
940
- expect(config.build.upload).toBeUndefined();
941
- expect(diagnostics.hasErrors()).toBe(false);
942
- expect(diagnostics.hasWarnings()).toBe(true);
943
- expect(normalizePath(diagnostics.renderWarnings()))
944
- .toMatchInlineSnapshot(`
945
- "Processing project/wrangler.toml configuration:
946
- - Deprecation: \\"build.upload.format\\":
947
- The format is inferred automatically from the code.
948
- - Deprecation: \\"build.upload.main\\":
949
- Delete the \`build.upload.main\` and \`build.upload.dir\` fields.
950
- Then add the top level \`main\` field to your configuration file:
951
- \`\`\`
952
- main = \\"src/index.ts\\"
953
- \`\`\`
954
- - Deprecation: \\"build.upload.dir\\":
955
- Use the top level \\"main\\" field or a command-line argument to specify the entry-point for the Worker.
956
- - 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:
957
- \`\`\`
958
- [[rules]]
959
- type = \\"Text\\"
960
- globs = [ \\"GLOB\\" ]
961
- fallthrough = true
962
- \`\`\`"
963
- `);
964
- });
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
+ });
965
1002
 
966
- it("should default custom build watch directories to src", () => {
967
- const expectedConfig: RawEnvironment = {
968
- build: {
969
- command: "execute some --build",
970
- },
971
- };
1003
+ it("should default custom build watch directories to src", () => {
1004
+ const expectedConfig: RawEnvironment = {
1005
+ build: {
1006
+ command: "execute some --build",
1007
+ },
1008
+ };
972
1009
 
973
- const { config, diagnostics } = normalizeAndValidateConfig(
974
- expectedConfig,
975
- undefined,
976
- { env: undefined }
977
- );
1010
+ const { config, diagnostics } = normalizeAndValidateConfig(
1011
+ expectedConfig,
1012
+ undefined,
1013
+ { env: undefined }
1014
+ );
978
1015
 
979
- expect(config.build).toEqual(
980
- expect.objectContaining({
981
- command: "execute some --build",
982
- watch_dir: "./src",
983
- })
984
- );
1016
+ expect(config.build).toEqual(
1017
+ expect.objectContaining({
1018
+ command: "execute some --build",
1019
+ watch_dir: "./src",
1020
+ })
1021
+ );
985
1022
 
986
- expect(diagnostics.hasErrors()).toBe(false);
987
- expect(diagnostics.hasWarnings()).toBe(false);
988
- });
1023
+ expect(diagnostics.hasErrors()).toBe(false);
1024
+ expect(diagnostics.hasWarnings()).toBe(false);
1025
+ });
989
1026
 
990
- it("should resolve custom build watch directories relative to wrangler.toml", async () => {
991
- const expectedConfig: RawEnvironment = {
992
- build: {
993
- command: "execute some --build",
994
- watch_dir: "some/path",
995
- },
996
- };
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
+ };
997
1034
 
998
- const { config, diagnostics } = normalizeAndValidateConfig(
999
- expectedConfig,
1000
- "project/wrangler.toml",
1001
- { env: undefined }
1002
- );
1035
+ const { config, diagnostics } = normalizeAndValidateConfig(
1036
+ expectedConfig,
1037
+ "project/wrangler.toml",
1038
+ { env: undefined }
1039
+ );
1003
1040
 
1004
- expect(config.build).toEqual(
1005
- expect.objectContaining({
1006
- command: "execute some --build",
1007
- watch_dir: path.normalize("project/some/path"),
1008
- })
1009
- );
1041
+ expect(config.build).toEqual(
1042
+ expect.objectContaining({
1043
+ command: "execute some --build",
1044
+ watch_dir: path.normalize("project/some/path"),
1045
+ })
1046
+ );
1010
1047
 
1011
- expect(diagnostics.hasErrors()).toBe(false);
1012
- 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
+ });
1013
1126
  });
1014
1127
 
1015
1128
  describe("durable_objects field", () => {