wrangler 0.0.0-e6c9c5c0 → 0.0.0-e6e1daba

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 (126) hide show
  1. package/README.md +3 -3
  2. package/miniflare-dist/index.mjs +22 -18
  3. package/package.json +12 -12
  4. package/src/__tests__/configuration.test.ts +70 -0
  5. package/src/__tests__/d1/d1.test.ts +13 -58
  6. package/src/__tests__/d1/execute.test.ts +64 -0
  7. package/src/__tests__/d1/migrate.test.ts +155 -0
  8. package/src/__tests__/deployments.test.ts +40 -16
  9. package/src/__tests__/dev.test.tsx +8 -7
  10. package/src/__tests__/generate.test.ts +1 -1
  11. package/src/__tests__/guess-worker-format.test.ts +35 -0
  12. package/src/__tests__/helpers/end-event-loop.ts +6 -0
  13. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
  14. package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
  15. package/src/__tests__/helpers/msw/handlers/deployments.ts +40 -16
  16. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
  17. package/src/__tests__/index.test.ts +38 -32
  18. package/src/__tests__/init.test.ts +1 -1
  19. package/src/__tests__/kv.test.ts +63 -52
  20. package/src/__tests__/middleware.test.ts +65 -0
  21. package/src/__tests__/mtls-certificates.test.ts +585 -0
  22. package/src/__tests__/pages/deployment-list.test.ts +78 -0
  23. package/src/__tests__/pages/functions-build.test.ts +402 -0
  24. package/src/__tests__/pages/pages.test.ts +81 -0
  25. package/src/__tests__/pages/project-create.test.ts +63 -0
  26. package/src/__tests__/pages/project-list.test.ts +108 -0
  27. package/src/__tests__/pages/project-upload.test.ts +481 -0
  28. package/src/__tests__/pages/publish.test.ts +2745 -0
  29. package/src/__tests__/parse.test.ts +106 -0
  30. package/src/__tests__/publish.test.ts +80 -30
  31. package/src/__tests__/pubsub.test.ts +15 -12
  32. package/src/__tests__/queues.test.ts +37 -30
  33. package/src/__tests__/r2.test.ts +25 -20
  34. package/src/__tests__/secret.test.ts +4 -4
  35. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  36. package/src/__tests__/user.test.ts +1 -1
  37. package/src/__tests__/whoami.test.tsx +1 -1
  38. package/src/__tests__/worker-namespace.test.ts +26 -21
  39. package/src/api/dev.ts +80 -11
  40. package/src/api/index.ts +8 -0
  41. package/src/api/mtls-certificate.ts +148 -0
  42. package/src/api/pages/create-worker-bundle-contents.ts +75 -0
  43. package/src/api/pages/publish.tsx +59 -12
  44. package/src/bundle.ts +9 -7
  45. package/src/config/config.ts +14 -7
  46. package/src/config/environment.ts +9 -2
  47. package/src/config/index.ts +37 -20
  48. package/src/config/validation.ts +50 -3
  49. package/src/create-worker-preview.ts +19 -8
  50. package/src/create-worker-upload-form.ts +9 -0
  51. package/src/d1/backups.tsx +20 -24
  52. package/src/d1/create.tsx +6 -5
  53. package/src/d1/delete.ts +7 -10
  54. package/src/d1/execute.tsx +174 -143
  55. package/src/d1/index.ts +5 -6
  56. package/src/d1/list.tsx +21 -9
  57. package/src/d1/migrations/apply.tsx +42 -33
  58. package/src/d1/migrations/create.tsx +16 -17
  59. package/src/d1/migrations/helpers.ts +63 -38
  60. package/src/d1/migrations/list.tsx +37 -24
  61. package/src/d1/migrations/options.ts +7 -2
  62. package/src/d1/options.ts +3 -3
  63. package/src/d1/types.ts +1 -0
  64. package/src/d1/utils.ts +2 -1
  65. package/src/delete.ts +5 -8
  66. package/src/deployments.ts +62 -39
  67. package/src/deprecated/index.ts +7 -8
  68. package/src/dev/dev.tsx +1 -15
  69. package/src/dev/local.tsx +5 -6
  70. package/src/dev/remote.tsx +2 -2
  71. package/src/dev.tsx +51 -86
  72. package/src/dispatch-namespace.ts +20 -16
  73. package/src/docs/index.ts +7 -8
  74. package/src/entry.ts +1 -2
  75. package/src/generate/index.ts +6 -8
  76. package/src/index.ts +37 -26
  77. package/src/init.ts +5 -7
  78. package/src/inspect.ts +16 -1
  79. package/src/kv/index.ts +15 -17
  80. package/src/miniflare-cli/assets.ts +9 -8
  81. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  82. package/src/mtls-certificate/cli.ts +155 -0
  83. package/src/pages/build.ts +109 -27
  84. package/src/pages/buildFunctions.ts +32 -31
  85. package/src/pages/deployment-tails.ts +7 -10
  86. package/src/pages/deployments.tsx +6 -4
  87. package/src/pages/dev.ts +19 -19
  88. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  89. package/src/pages/functions.ts +8 -4
  90. package/src/pages/index.ts +3 -3
  91. package/src/pages/projects.tsx +7 -12
  92. package/src/pages/publish.tsx +18 -5
  93. package/src/pages/types.ts +5 -0
  94. package/src/pages/upload.tsx +6 -4
  95. package/src/pages/utils.ts +1 -1
  96. package/src/parse.ts +23 -1
  97. package/src/publish/index.ts +19 -15
  98. package/src/publish/publish.ts +5 -4
  99. package/src/pubsub/pubsub-commands.ts +18 -19
  100. package/src/queues/cli/commands/consumer/add.ts +18 -24
  101. package/src/queues/cli/commands/consumer/index.ts +3 -6
  102. package/src/queues/cli/commands/consumer/remove.ts +11 -18
  103. package/src/queues/cli/commands/create.ts +8 -8
  104. package/src/queues/cli/commands/delete.ts +8 -8
  105. package/src/queues/cli/commands/index.ts +3 -4
  106. package/src/queues/cli/commands/list.ts +8 -8
  107. package/src/r2/helpers.ts +1 -0
  108. package/src/r2/index.ts +28 -28
  109. package/src/secret/index.ts +10 -14
  110. package/src/sites.ts +1 -1
  111. package/src/tail/filters.ts +1 -1
  112. package/src/tail/index.ts +6 -8
  113. package/src/user/user.ts +4 -3
  114. package/src/worker.ts +6 -0
  115. package/src/yargs-types.ts +18 -5
  116. package/templates/checked-fetch.js +9 -1
  117. package/templates/format-dev-errors.ts +1 -0
  118. package/templates/new-worker.ts +3 -0
  119. package/templates/pages-template-plugin.ts +7 -3
  120. package/templates/serve-static-assets.ts +1 -0
  121. package/templates/service-bindings-module-facade.js +1 -0
  122. package/templates/tsconfig.init.json +1 -1
  123. package/templates/tsconfig.tsbuildinfo +1 -1
  124. package/wrangler-dist/cli.d.ts +596 -3
  125. package/wrangler-dist/cli.js +14276 -6748
  126. package/src/__tests__/pages.test.ts +0 -2898
@@ -63,10 +63,11 @@ describe("wrangler", () => {
63
63
  namespace The name of the new namespace [string] [required]
64
64
 
65
65
  Flags:
66
- -c, --config Path to .toml configuration file [string]
67
- -e, --env Environment to use for operations and .env files [string]
68
- -h, --help Show help [boolean]
69
- -v, --version Show version number [boolean]
66
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
67
+ -c, --config Path to .toml configuration file [string]
68
+ -e, --env Environment to use for operations and .env files [string]
69
+ -h, --help Show help [boolean]
70
+ -v, --version Show version number [boolean]
70
71
 
71
72
  Options:
72
73
  --preview Interact with a preview namespace [boolean]"
@@ -94,10 +95,11 @@ describe("wrangler", () => {
94
95
  namespace The name of the new namespace [string] [required]
95
96
 
96
97
  Flags:
97
- -c, --config Path to .toml configuration file [string]
98
- -e, --env Environment to use for operations and .env files [string]
99
- -h, --help Show help [boolean]
100
- -v, --version Show version number [boolean]
98
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
99
+ -c, --config Path to .toml configuration file [string]
100
+ -e, --env Environment to use for operations and .env files [string]
101
+ -h, --help Show help [boolean]
102
+ -v, --version Show version number [boolean]
101
103
 
102
104
  Options:
103
105
  --preview Interact with a preview namespace [boolean]"
@@ -126,10 +128,11 @@ describe("wrangler", () => {
126
128
  namespace The name of the new namespace [string] [required]
127
129
 
128
130
  Flags:
129
- -c, --config Path to .toml configuration file [string]
130
- -e, --env Environment to use for operations and .env files [string]
131
- -h, --help Show help [boolean]
132
- -v, --version Show version number [boolean]
131
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
132
+ -c, --config Path to .toml configuration file [string]
133
+ -e, --env Environment to use for operations and .env files [string]
134
+ -h, --help Show help [boolean]
135
+ -v, --version Show version number [boolean]
133
136
 
134
137
  Options:
135
138
  --preview Interact with a preview namespace [boolean]"
@@ -552,10 +555,11 @@ describe("wrangler", () => {
552
555
  value The value to write [string]
553
556
 
554
557
  Flags:
555
- -c, --config Path to .toml configuration file [string]
556
- -e, --env Environment to use for operations and .env files [string]
557
- -h, --help Show help [boolean]
558
- -v, --version Show version number [boolean]
558
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
559
+ -c, --config Path to .toml configuration file [string]
560
+ -e, --env Environment to use for operations and .env files [string]
561
+ -h, --help Show help [boolean]
562
+ -v, --version Show version number [boolean]
559
563
 
560
564
  Options:
561
565
  --binding The binding of the namespace to write to [string]
@@ -591,10 +595,11 @@ describe("wrangler", () => {
591
595
  value The value to write [string]
592
596
 
593
597
  Flags:
594
- -c, --config Path to .toml configuration file [string]
595
- -e, --env Environment to use for operations and .env files [string]
596
- -h, --help Show help [boolean]
597
- -v, --version Show version number [boolean]
598
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
599
+ -c, --config Path to .toml configuration file [string]
600
+ -e, --env Environment to use for operations and .env files [string]
601
+ -h, --help Show help [boolean]
602
+ -v, --version Show version number [boolean]
598
603
 
599
604
  Options:
600
605
  --binding The binding of the namespace to write to [string]
@@ -630,10 +635,11 @@ describe("wrangler", () => {
630
635
  value The value to write [string]
631
636
 
632
637
  Flags:
633
- -c, --config Path to .toml configuration file [string]
634
- -e, --env Environment to use for operations and .env files [string]
635
- -h, --help Show help [boolean]
636
- -v, --version Show version number [boolean]
638
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
639
+ -c, --config Path to .toml configuration file [string]
640
+ -e, --env Environment to use for operations and .env files [string]
641
+ -h, --help Show help [boolean]
642
+ -v, --version Show version number [boolean]
637
643
 
638
644
  Options:
639
645
  --binding The binding of the namespace to write to [string]
@@ -669,10 +675,11 @@ describe("wrangler", () => {
669
675
  value The value to write [string]
670
676
 
671
677
  Flags:
672
- -c, --config Path to .toml configuration file [string]
673
- -e, --env Environment to use for operations and .env files [string]
674
- -h, --help Show help [boolean]
675
- -v, --version Show version number [boolean]
678
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
679
+ -c, --config Path to .toml configuration file [string]
680
+ -e, --env Environment to use for operations and .env files [string]
681
+ -h, --help Show help [boolean]
682
+ -v, --version Show version number [boolean]
676
683
 
677
684
  Options:
678
685
  --binding The binding of the namespace to write to [string]
@@ -708,10 +715,11 @@ describe("wrangler", () => {
708
715
  value The value to write [string]
709
716
 
710
717
  Flags:
711
- -c, --config Path to .toml configuration file [string]
712
- -e, --env Environment to use for operations and .env files [string]
713
- -h, --help Show help [boolean]
714
- -v, --version Show version number [boolean]
718
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
719
+ -c, --config Path to .toml configuration file [string]
720
+ -e, --env Environment to use for operations and .env files [string]
721
+ -h, --help Show help [boolean]
722
+ -v, --version Show version number [boolean]
715
723
 
716
724
  Options:
717
725
  --binding The binding of the namespace to write to [string]
@@ -739,7 +747,7 @@ describe("wrangler", () => {
739
747
 
740
748
  expect(std.out).toMatchInlineSnapshot(`
741
749
  "
742
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
750
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
743
751
  `);
744
752
  expect(std.err).toMatchInlineSnapshot(`
745
753
  "X [ERROR] A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
@@ -761,7 +769,7 @@ describe("wrangler", () => {
761
769
  );
762
770
  expect(std.out).toMatchInlineSnapshot(`
763
771
  "
764
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
772
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
765
773
  `);
766
774
  expect(std.err).toMatchInlineSnapshot(`
767
775
  "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.
@@ -932,7 +940,7 @@ describe("wrangler", () => {
932
940
  `);
933
941
  expect(std.out).toMatchInlineSnapshot(`
934
942
  "
935
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
943
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
936
944
  `);
937
945
  });
938
946
  });
@@ -1083,10 +1091,11 @@ describe("wrangler", () => {
1083
1091
  key The key value to get. [string] [required]
1084
1092
 
1085
1093
  Flags:
1086
- -c, --config Path to .toml configuration file [string]
1087
- -e, --env Environment to use for operations and .env files [string]
1088
- -h, --help Show help [boolean]
1089
- -v, --version Show version number [boolean]
1094
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
1095
+ -c, --config Path to .toml configuration file [string]
1096
+ -e, --env Environment to use for operations and .env files [string]
1097
+ -h, --help Show help [boolean]
1098
+ -v, --version Show version number [boolean]
1090
1099
 
1091
1100
  Options:
1092
1101
  --binding The name of the namespace to get from [string]
@@ -1117,10 +1126,11 @@ describe("wrangler", () => {
1117
1126
  key The key value to get. [string] [required]
1118
1127
 
1119
1128
  Flags:
1120
- -c, --config Path to .toml configuration file [string]
1121
- -e, --env Environment to use for operations and .env files [string]
1122
- -h, --help Show help [boolean]
1123
- -v, --version Show version number [boolean]
1129
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
1130
+ -c, --config Path to .toml configuration file [string]
1131
+ -e, --env Environment to use for operations and .env files [string]
1132
+ -h, --help Show help [boolean]
1133
+ -v, --version Show version number [boolean]
1124
1134
 
1125
1135
  Options:
1126
1136
  --binding The name of the namespace to get from [string]
@@ -1152,10 +1162,11 @@ describe("wrangler", () => {
1152
1162
  key The key value to get. [string] [required]
1153
1163
 
1154
1164
  Flags:
1155
- -c, --config Path to .toml configuration file [string]
1156
- -e, --env Environment to use for operations and .env files [string]
1157
- -h, --help Show help [boolean]
1158
- -v, --version Show version number [boolean]
1165
+ -j, --experimental-json-config Experimental: Support wrangler.json [boolean]
1166
+ -c, --config Path to .toml configuration file [string]
1167
+ -e, --env Environment to use for operations and .env files [string]
1168
+ -h, --help Show help [boolean]
1169
+ -v, --version Show version number [boolean]
1159
1170
 
1160
1171
  Options:
1161
1172
  --binding The name of the namespace to get from [string]
@@ -1179,7 +1190,7 @@ describe("wrangler", () => {
1179
1190
  );
1180
1191
  expect(std.out).toMatchInlineSnapshot(`
1181
1192
  "
1182
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1193
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
1183
1194
  `);
1184
1195
  expect(std.err).toMatchInlineSnapshot(`
1185
1196
  "X [ERROR] A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
@@ -1442,7 +1453,7 @@ describe("wrangler", () => {
1442
1453
  `);
1443
1454
  expect(std.out).toMatchInlineSnapshot(`
1444
1455
  "
1445
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1456
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
1446
1457
  `);
1447
1458
  expect(std.warn).toMatchInlineSnapshot(`""`);
1448
1459
  });
@@ -1504,7 +1515,7 @@ describe("wrangler", () => {
1504
1515
 
1505
1516
  expect(std.out).toMatchInlineSnapshot(`
1506
1517
  "
1507
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1518
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
1508
1519
  `);
1509
1520
  expect(std.warn).toMatchInlineSnapshot(`
1510
1521
  "â–² [WARNING] Unexpected key-value properties in \\"keys.json\\".
@@ -1646,7 +1657,7 @@ describe("wrangler", () => {
1646
1657
  `);
1647
1658
  expect(std.out).toMatchInlineSnapshot(`
1648
1659
  "
1649
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1660
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
1650
1661
  `);
1651
1662
  expect(std.warn).toMatchInlineSnapshot(`""`);
1652
1663
  });
@@ -1671,7 +1682,7 @@ describe("wrangler", () => {
1671
1682
  `);
1672
1683
  expect(std.out).toMatchInlineSnapshot(`
1673
1684
  "
1674
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1685
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/workers-sdk/issues/new/choose"
1675
1686
  `);
1676
1687
  expect(std.warn).toMatchInlineSnapshot(`""`);
1677
1688
  });
@@ -748,3 +748,68 @@ describe("unchanged functionality when wrapping with middleware", () => {
748
748
  });
749
749
  });
750
750
  });
751
+
752
+ describe("multiple middleware", () => {
753
+ it("should respond correctly with D1 databases, scheduled testing, and formatted dev errors", async () => {
754
+ // Kitchen sink test to check interaction between multiple middlewares
755
+ const scriptContent = `
756
+ export default {
757
+ async fetch(request, env, ctx) {
758
+ const { pathname } = new URL(request.url);
759
+ if (pathname === "/setup") {
760
+ await env.DB.exec("CREATE TABLE IF NOT EXISTS test (id INTEGER PRIMARY KEY, value TEXT);");
761
+ return new Response(null, { status: 204 });
762
+ } else if (pathname === "/query") {
763
+ const rows = await env.DB.prepare("SELECT * FROM test;").all();
764
+ return Response.json(rows.results);
765
+ }
766
+ throw new Error("Not found!");
767
+ },
768
+ async scheduled(controller, env, ctx) {
769
+ const stmt = await env.DB.prepare("INSERT INTO test (id, value) VALUES (?, ?)");
770
+ await stmt.bind(1, "one").run();
771
+ }
772
+ }
773
+ `;
774
+ fs.writeFileSync("index.js", scriptContent);
775
+
776
+ const originalFormatErrors = process.env.FORMAT_WRANGLER_ERRORS;
777
+ process.env.FORMAT_WRANGLER_ERRORS = "true";
778
+
779
+ const worker = await unstable_dev("index.js", {
780
+ experimental: {
781
+ disableExperimentalWarning: true,
782
+ disableDevRegistry: true,
783
+ testScheduled: true,
784
+ d1Databases: [
785
+ {
786
+ binding: "DB",
787
+ database_name: "db",
788
+ database_id: "00000000-0000-0000-0000-000000000000",
789
+ },
790
+ ],
791
+ },
792
+ });
793
+
794
+ try {
795
+ let res = await worker.fetch("http://localhost/setup");
796
+ expect(res.status).toBe(204);
797
+
798
+ res = await worker.fetch("http://localhost/__scheduled");
799
+ expect(res.status).toBe(200);
800
+ expect(await res.text()).toBe("Ran scheduled event");
801
+
802
+ res = await worker.fetch("http://localhost/query");
803
+ expect(res.status).toBe(200);
804
+ expect(await res.json()).toEqual([{ id: 1, value: "one" }]);
805
+
806
+ res = await worker.fetch("http://localhost/bad");
807
+ expect(res.status).toBe(500);
808
+ expect(res.headers.get("Content-Type")).toBe("text/html");
809
+ expect(await res.text()).toContain("Error: Not found!");
810
+ } finally {
811
+ process.env.FORMAT_WRANGLER_ERRORS = originalFormatErrors;
812
+ await worker.stop();
813
+ }
814
+ });
815
+ });