wrangler 2.9.0 → 2.10.0

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 (82) hide show
  1. package/README.md +3 -3
  2. package/miniflare-dist/index.mjs +2 -15
  3. package/package.json +9 -9
  4. package/src/__tests__/configuration.test.ts +70 -0
  5. package/src/__tests__/d1/d1.test.ts +3 -6
  6. package/src/__tests__/d1/execute.test.ts +64 -0
  7. package/src/__tests__/d1/migrate.test.ts +107 -0
  8. package/src/__tests__/deployments.test.ts +40 -16
  9. package/src/__tests__/dev.test.tsx +3 -3
  10. package/src/__tests__/generate.test.ts +1 -1
  11. package/src/__tests__/helpers/end-event-loop.ts +6 -0
  12. package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
  13. package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
  14. package/src/__tests__/helpers/msw/handlers/deployments.ts +40 -16
  15. package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -0
  16. package/src/__tests__/index.test.ts +3 -4
  17. package/src/__tests__/init.test.ts +1 -1
  18. package/src/__tests__/kv.test.ts +8 -8
  19. package/src/__tests__/middleware.test.ts +65 -0
  20. package/src/__tests__/mtls-certificates.test.ts +585 -0
  21. package/src/__tests__/pages/deployment-list.test.ts +78 -0
  22. package/src/__tests__/pages/functions-build.test.ts +402 -0
  23. package/src/__tests__/pages/pages.test.ts +81 -0
  24. package/src/__tests__/pages/project-create.test.ts +63 -0
  25. package/src/__tests__/pages/project-list.test.ts +108 -0
  26. package/src/__tests__/pages/project-upload.test.ts +481 -0
  27. package/src/__tests__/pages/publish.test.ts +2745 -0
  28. package/src/__tests__/publish.test.ts +58 -27
  29. package/src/__tests__/queues.test.ts +2 -2
  30. package/src/__tests__/secret.test.ts +4 -4
  31. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  32. package/src/__tests__/user.test.ts +1 -1
  33. package/src/__tests__/whoami.test.tsx +1 -1
  34. package/src/__tests__/worker-namespace.test.ts +1 -1
  35. package/src/api/index.ts +8 -0
  36. package/src/api/mtls-certificate.ts +148 -0
  37. package/src/api/pages/create-worker-bundle-contents.ts +75 -0
  38. package/src/api/pages/publish.tsx +52 -8
  39. package/src/bundle.ts +6 -5
  40. package/src/config/config.ts +7 -7
  41. package/src/config/environment.ts +9 -2
  42. package/src/config/index.ts +13 -0
  43. package/src/config/validation.ts +50 -3
  44. package/src/create-worker-upload-form.ts +9 -0
  45. package/src/d1/execute.tsx +124 -91
  46. package/src/d1/migrations/apply.tsx +36 -29
  47. package/src/d1/migrations/create.tsx +10 -8
  48. package/src/d1/migrations/helpers.ts +63 -38
  49. package/src/d1/migrations/list.tsx +31 -20
  50. package/src/d1/migrations/options.ts +6 -1
  51. package/src/d1/types.ts +1 -0
  52. package/src/d1/utils.ts +2 -1
  53. package/src/deployments.ts +62 -39
  54. package/src/dev/dev.tsx +1 -15
  55. package/src/dev/remote.tsx +2 -2
  56. package/src/dev.tsx +9 -6
  57. package/src/generate/index.ts +1 -1
  58. package/src/index.ts +15 -5
  59. package/src/miniflare-cli/assets.ts +1 -1
  60. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  61. package/src/mtls-certificate/cli.ts +155 -0
  62. package/src/pages/build.ts +103 -23
  63. package/src/pages/buildFunctions.ts +32 -31
  64. package/src/pages/dev.ts +4 -2
  65. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  66. package/src/pages/publish.tsx +12 -1
  67. package/src/pages/utils.ts +1 -1
  68. package/src/publish/publish.ts +3 -2
  69. package/src/secret/index.ts +1 -0
  70. package/src/sites.ts +1 -1
  71. package/src/tail/filters.ts +1 -1
  72. package/src/user/user.ts +4 -3
  73. package/src/worker.ts +6 -0
  74. package/templates/format-dev-errors.ts +1 -0
  75. package/templates/new-worker.ts +3 -0
  76. package/templates/serve-static-assets.ts +1 -0
  77. package/templates/service-bindings-module-facade.js +1 -0
  78. package/templates/tsconfig.init.json +1 -1
  79. package/templates/tsconfig.tsbuildinfo +1 -1
  80. package/wrangler-dist/cli.d.ts +82 -2
  81. package/wrangler-dist/cli.js +1726 -1616
  82. package/src/__tests__/pages.test.ts +0 -2905
@@ -0,0 +1,28 @@
1
+ export type PatternReplacementPair = [string | RegExp, string];
2
+
3
+ /**
4
+ * Sometimes, we might need to test strings that contain dynamic |
5
+ * random | generated data (such as file hashes, IDs, etc.).
6
+ *
7
+ * This helper function replaces the dynamic parts of such strings with
8
+ * static values, thus enabling us to properly test the contents of the
9
+ * string.
10
+ *
11
+ * see https://jestjs.io/docs/snapshot-testing#property-matchers
12
+ */
13
+ export function replaceRandomWithConstantData(
14
+ stringWithRandomData: string,
15
+ patternReplacementPairs: Array<PatternReplacementPair>
16
+ ) {
17
+ let stringWithConstantData = stringWithRandomData;
18
+
19
+ patternReplacementPairs.forEach(
20
+ (pair) =>
21
+ (stringWithConstantData = stringWithConstantData.replace(
22
+ pair[0], // pattern
23
+ pair[1] // replacement
24
+ ))
25
+ );
26
+
27
+ return stringWithConstantData;
28
+ }
@@ -1,4 +1,5 @@
1
1
  import { getPackageManager } from "../package-manager";
2
+ import { endEventLoop } from "./helpers/end-event-loop";
2
3
  import { mockConsoleMethods } from "./helpers/mock-console";
3
4
  import { runInTempDir } from "./helpers/run-in-tmp";
4
5
  import { runWrangler } from "./helpers/run-wrangler";
@@ -49,6 +50,7 @@ describe("wrangler", () => {
49
50
  wrangler dispatch-namespace 📦 Interact with a dispatch namespace
50
51
  wrangler d1 🗄 Interact with a D1 database
51
52
  wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
53
+ wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
52
54
  wrangler login 🔓 Login to Cloudflare
53
55
  wrangler logout 🚪 Logout from Cloudflare
54
56
  wrangler whoami 🕵️ Retrieve your user info and test your auth config
@@ -98,6 +100,7 @@ describe("wrangler", () => {
98
100
  wrangler dispatch-namespace 📦 Interact with a dispatch namespace
99
101
  wrangler d1 🗄 Interact with a D1 database
100
102
  wrangler pubsub 📮 Interact and manage Pub/Sub Brokers
103
+ wrangler mtls-certificate 🪪 Manage certificates used for mTLS connections
101
104
  wrangler login 🔓 Login to Cloudflare
102
105
  wrangler logout 🚪 Logout from Cloudflare
103
106
  wrangler whoami 🕵️ Retrieve your user info and test your auth config
@@ -269,7 +272,3 @@ describe("wrangler", () => {
269
272
  `);
270
273
  });
271
274
  });
272
-
273
- function endEventLoop() {
274
- return new Promise((resolve) => setImmediate(resolve));
275
- }
@@ -1392,7 +1392,7 @@ describe("init", () => {
1392
1392
  contents: {
1393
1393
  config: {
1394
1394
  compilerOptions: expect.objectContaining({
1395
- types: ["@cloudflare/workers-types", "jest"],
1395
+ types: ["@cloudflare/workers-types", "vitest"],
1396
1396
  }),
1397
1397
  },
1398
1398
  error: undefined,
@@ -747,7 +747,7 @@ describe("wrangler", () => {
747
747
 
748
748
  expect(std.out).toMatchInlineSnapshot(`
749
749
  "
750
- 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"
751
751
  `);
752
752
  expect(std.err).toMatchInlineSnapshot(`
753
753
  "X [ERROR] A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
@@ -769,7 +769,7 @@ describe("wrangler", () => {
769
769
  );
770
770
  expect(std.out).toMatchInlineSnapshot(`
771
771
  "
772
- 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"
773
773
  `);
774
774
  expect(std.err).toMatchInlineSnapshot(`
775
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.
@@ -940,7 +940,7 @@ describe("wrangler", () => {
940
940
  `);
941
941
  expect(std.out).toMatchInlineSnapshot(`
942
942
  "
943
- 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"
944
944
  `);
945
945
  });
946
946
  });
@@ -1190,7 +1190,7 @@ describe("wrangler", () => {
1190
1190
  );
1191
1191
  expect(std.out).toMatchInlineSnapshot(`
1192
1192
  "
1193
- 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"
1194
1194
  `);
1195
1195
  expect(std.err).toMatchInlineSnapshot(`
1196
1196
  "X [ERROR] A namespace with binding name \\"otherBinding\\" was not found in the configured \\"kv_namespaces\\".
@@ -1453,7 +1453,7 @@ describe("wrangler", () => {
1453
1453
  `);
1454
1454
  expect(std.out).toMatchInlineSnapshot(`
1455
1455
  "
1456
- 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"
1457
1457
  `);
1458
1458
  expect(std.warn).toMatchInlineSnapshot(`""`);
1459
1459
  });
@@ -1515,7 +1515,7 @@ describe("wrangler", () => {
1515
1515
 
1516
1516
  expect(std.out).toMatchInlineSnapshot(`
1517
1517
  "
1518
- 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"
1519
1519
  `);
1520
1520
  expect(std.warn).toMatchInlineSnapshot(`
1521
1521
  "▲ [WARNING] Unexpected key-value properties in \\"keys.json\\".
@@ -1657,7 +1657,7 @@ describe("wrangler", () => {
1657
1657
  `);
1658
1658
  expect(std.out).toMatchInlineSnapshot(`
1659
1659
  "
1660
- 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"
1661
1661
  `);
1662
1662
  expect(std.warn).toMatchInlineSnapshot(`""`);
1663
1663
  });
@@ -1682,7 +1682,7 @@ describe("wrangler", () => {
1682
1682
  `);
1683
1683
  expect(std.out).toMatchInlineSnapshot(`
1684
1684
  "
1685
- 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"
1686
1686
  `);
1687
1687
  expect(std.warn).toMatchInlineSnapshot(`""`);
1688
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
+ });