wrangler 0.0.0-e95bea2 → 0.0.0-ea8e701

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 (55) hide show
  1. package/README.md +3 -3
  2. package/bin/wrangler.js +10 -1
  3. package/miniflare-dist/index.mjs +79 -0
  4. package/miniflare-dist/index.mjs.map +7 -0
  5. package/package.json +7 -6
  6. package/pages/functions/filepath-routing.test.ts +125 -25
  7. package/pages/functions/filepath-routing.ts +6 -3
  8. package/src/__tests__/configuration.test.ts +826 -223
  9. package/src/__tests__/dev.test.tsx +145 -9
  10. package/src/__tests__/guess-worker-format.test.ts +26 -1
  11. package/src/__tests__/helpers/mock-account-id.ts +4 -0
  12. package/src/__tests__/helpers/mock-kv.ts +9 -16
  13. package/src/__tests__/helpers/mock-oauth-flow.ts +178 -0
  14. package/src/__tests__/helpers/run-in-tmp.ts +3 -0
  15. package/src/__tests__/index.test.ts +9 -13
  16. package/src/__tests__/jest.setup.ts +5 -0
  17. package/src/__tests__/kv.test.ts +43 -71
  18. package/src/__tests__/pages.test.ts +48 -10
  19. package/src/__tests__/publish.test.ts +1456 -327
  20. package/src/__tests__/r2.test.ts +4 -4
  21. package/src/__tests__/tail.test.ts +78 -4
  22. package/src/__tests__/user.test.ts +83 -0
  23. package/src/__tests__/whoami.test.tsx +16 -7
  24. package/src/bundle.ts +15 -2
  25. package/src/cfetch/internal.ts +9 -5
  26. package/src/config/README.md +6 -6
  27. package/src/config/config.ts +17 -78
  28. package/src/config/environment.ts +67 -1
  29. package/src/config/index.ts +13 -3
  30. package/src/config/validation-helpers.ts +177 -11
  31. package/src/config/validation.ts +305 -100
  32. package/src/dev/dev.tsx +76 -41
  33. package/src/dev/local.tsx +105 -114
  34. package/src/dev/remote.tsx +2 -0
  35. package/src/dev/use-esbuild.ts +4 -0
  36. package/src/entry.ts +103 -6
  37. package/src/index.tsx +251 -189
  38. package/src/intl-polyfill.d.ts +139 -0
  39. package/src/{kv/index.tsx → kv.ts} +8 -28
  40. package/src/miniflare-cli/README.md +30 -0
  41. package/src/miniflare-cli/enum-keys.ts +17 -0
  42. package/src/miniflare-cli/index.ts +37 -0
  43. package/src/module-collection.ts +58 -53
  44. package/src/pages.tsx +26 -10
  45. package/src/proxy.ts +5 -3
  46. package/src/publish.ts +17 -21
  47. package/src/sites.tsx +67 -25
  48. package/src/tail/index.ts +1 -1
  49. package/src/tail/printing.ts +2 -2
  50. package/src/user.tsx +161 -81
  51. package/wrangler-dist/cli.js +3418 -1437
  52. package/wrangler-dist/cli.js.map +3 -3
  53. package/src/__tests__/dev2.test.tsx +0 -152
  54. package/src/__tests__/helpers/mock-user.ts +0 -27
  55. package/src/__tests__/logout.test.ts +0 -50
@@ -61,7 +61,7 @@ describe("wrangler", () => {
61
61
  --legacy-env Use legacy environments [boolean]
62
62
 
63
63
  Options:
64
- --env Perform on a specific environment [string]
64
+ -e, --env Perform on a specific environment [string]
65
65
  --preview Interact with a preview namespace [boolean]
66
66
 
67
67
  Not enough non-option arguments: got 0, need at least 1"
@@ -72,7 +72,7 @@ describe("wrangler", () => {
72
72
  await expect(
73
73
  runWrangler("kv:namespace create abc def ghi")
74
74
  ).rejects.toThrowErrorMatchingInlineSnapshot(
75
- `"Unexpected additional positional arguments \\"def ghi\\"."`
75
+ `"Unknown arguments: def, ghi"`
76
76
  );
77
77
  expect(std.out).toMatchInlineSnapshot(`""`);
78
78
  expect(std.err).toMatchInlineSnapshot(`
@@ -90,10 +90,10 @@ describe("wrangler", () => {
90
90
  --legacy-env Use legacy environments [boolean]
91
91
 
92
92
  Options:
93
- --env Perform on a specific environment [string]
93
+ -e, --env Perform on a specific environment [string]
94
94
  --preview Interact with a preview namespace [boolean]
95
95
 
96
- Unexpected additional positional arguments \\"def ghi\\"."
96
+ Unknown arguments: def, ghi"
97
97
  `);
98
98
  });
99
99
 
@@ -120,7 +120,7 @@ describe("wrangler", () => {
120
120
  --legacy-env Use legacy environments [boolean]
121
121
 
122
122
  Options:
123
- --env Perform on a specific environment [string]
123
+ -e, --env Perform on a specific environment [string]
124
124
  --preview Interact with a preview namespace [boolean]
125
125
 
126
126
  The namespace binding name \\"abc-def\\" is invalid. It can only have alphanumeric and _ characters, and cannot begin with a number."
@@ -286,7 +286,7 @@ describe("wrangler", () => {
286
286
  Options:
287
287
  --binding The name of the namespace to delete [string]
288
288
  --namespace-id The id of the namespace to delete [string]
289
- --env Perform on a specific environment [string]
289
+ -e, --env Perform on a specific environment [string]
290
290
  --preview Interact with a preview namespace [boolean]
291
291
 
292
292
  Not able to delete namespace.
@@ -480,7 +480,7 @@ describe("wrangler", () => {
480
480
  Options:
481
481
  --binding The binding of the namespace to write to [string]
482
482
  --namespace-id The id of the namespace to write to [string]
483
- --env Perform on a specific environment [string]
483
+ -e, --env Perform on a specific environment [string]
484
484
  --preview Interact with a preview namespace [boolean]
485
485
  --ttl Time for which the entries should be visible [number]
486
486
  --expiration Time since the UNIX epoch after which the entry expires [number]
@@ -516,7 +516,7 @@ describe("wrangler", () => {
516
516
  Options:
517
517
  --binding The binding of the namespace to write to [string]
518
518
  --namespace-id The id of the namespace to write to [string]
519
- --env Perform on a specific environment [string]
519
+ -e, --env Perform on a specific environment [string]
520
520
  --preview Interact with a preview namespace [boolean]
521
521
  --ttl Time for which the entries should be visible [number]
522
522
  --expiration Time since the UNIX epoch after which the entry expires [number]
@@ -552,7 +552,7 @@ describe("wrangler", () => {
552
552
  Options:
553
553
  --binding The binding of the namespace to write to [string]
554
554
  --namespace-id The id of the namespace to write to [string]
555
- --env Perform on a specific environment [string]
555
+ -e, --env Perform on a specific environment [string]
556
556
  --preview Interact with a preview namespace [boolean]
557
557
  --ttl Time for which the entries should be visible [number]
558
558
  --expiration Time since the UNIX epoch after which the entry expires [number]
@@ -588,7 +588,7 @@ describe("wrangler", () => {
588
588
  Options:
589
589
  --binding The binding of the namespace to write to [string]
590
590
  --namespace-id The id of the namespace to write to [string]
591
- --env Perform on a specific environment [string]
591
+ -e, --env Perform on a specific environment [string]
592
592
  --preview Interact with a preview namespace [boolean]
593
593
  --ttl Time for which the entries should be visible [number]
594
594
  --expiration Time since the UNIX epoch after which the entry expires [number]
@@ -624,7 +624,7 @@ describe("wrangler", () => {
624
624
  Options:
625
625
  --binding The binding of the namespace to write to [string]
626
626
  --namespace-id The id of the namespace to write to [string]
627
- --env Perform on a specific environment [string]
627
+ -e, --env Perform on a specific environment [string]
628
628
  --preview Interact with a preview namespace [boolean]
629
629
  --ttl Time for which the entries should be visible [number]
630
630
  --expiration Time since the UNIX epoch after which the entry expires [number]
@@ -673,26 +673,26 @@ describe("wrangler", () => {
673
673
 
674
674
  describe("list", () => {
675
675
  it("should list the keys of a namespace specified by namespace-id", async () => {
676
- const keys = ["key-1", "key-2", "key-3"];
676
+ const keys = [
677
+ { name: "key-1" },
678
+ { name: "key-2", expiration: 123456789 },
679
+ { name: "key-3", expiration_ttl: 666 },
680
+ ];
677
681
  mockKeyListRequest("some-namespace-id", keys);
678
682
  await runWrangler("kv:key list --namespace-id some-namespace-id");
679
683
  expect(std.err).toMatchInlineSnapshot(`""`);
680
684
  expect(std.out).toMatchInlineSnapshot(`
681
685
  "[
682
686
  {
683
- \\"name\\": \\"key-1\\",
684
- \\"expiration\\": 123456789,
685
- \\"metadata\\": {}
687
+ \\"name\\": \\"key-1\\"
686
688
  },
687
689
  {
688
690
  \\"name\\": \\"key-2\\",
689
- \\"expiration\\": 123456789,
690
- \\"metadata\\": {}
691
+ \\"expiration\\": 123456789
691
692
  },
692
693
  {
693
694
  \\"name\\": \\"key-3\\",
694
- \\"expiration\\": 123456789,
695
- \\"metadata\\": {}
695
+ \\"expiration_ttl\\": 666
696
696
  }
697
697
  ]"
698
698
  `);
@@ -700,7 +700,7 @@ describe("wrangler", () => {
700
700
 
701
701
  it("should list the keys of a namespace specified by binding", async () => {
702
702
  writeWranglerConfig();
703
- const keys = ["key-1", "key-2", "key-3"];
703
+ const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
704
704
  mockKeyListRequest("bound-id", keys);
705
705
 
706
706
  await runWrangler("kv:key list --binding someBinding");
@@ -708,19 +708,13 @@ describe("wrangler", () => {
708
708
  expect(std.out).toMatchInlineSnapshot(`
709
709
  "[
710
710
  {
711
- \\"name\\": \\"key-1\\",
712
- \\"expiration\\": 123456789,
713
- \\"metadata\\": {}
711
+ \\"name\\": \\"key-1\\"
714
712
  },
715
713
  {
716
- \\"name\\": \\"key-2\\",
717
- \\"expiration\\": 123456789,
718
- \\"metadata\\": {}
714
+ \\"name\\": \\"key-2\\"
719
715
  },
720
716
  {
721
- \\"name\\": \\"key-3\\",
722
- \\"expiration\\": 123456789,
723
- \\"metadata\\": {}
717
+ \\"name\\": \\"key-3\\"
724
718
  }
725
719
  ]"
726
720
  `);
@@ -728,26 +722,20 @@ describe("wrangler", () => {
728
722
 
729
723
  it("should list the keys of a preview namespace specified by binding", async () => {
730
724
  writeWranglerConfig();
731
- const keys = ["key-1", "key-2", "key-3"];
725
+ const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
732
726
  mockKeyListRequest("preview-bound-id", keys);
733
727
  await runWrangler("kv:key list --binding someBinding --preview");
734
728
  expect(std.err).toMatchInlineSnapshot(`""`);
735
729
  expect(std.out).toMatchInlineSnapshot(`
736
730
  "[
737
731
  {
738
- \\"name\\": \\"key-1\\",
739
- \\"expiration\\": 123456789,
740
- \\"metadata\\": {}
732
+ \\"name\\": \\"key-1\\"
741
733
  },
742
734
  {
743
- \\"name\\": \\"key-2\\",
744
- \\"expiration\\": 123456789,
745
- \\"metadata\\": {}
735
+ \\"name\\": \\"key-2\\"
746
736
  },
747
737
  {
748
- \\"name\\": \\"key-3\\",
749
- \\"expiration\\": 123456789,
750
- \\"metadata\\": {}
738
+ \\"name\\": \\"key-3\\"
751
739
  }
752
740
  ]"
753
741
  `);
@@ -755,7 +743,7 @@ describe("wrangler", () => {
755
743
 
756
744
  it("should list the keys of a namespace specified by binding, in a given environment", async () => {
757
745
  writeWranglerConfig();
758
- const keys = ["key-1", "key-2", "key-3"];
746
+ const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
759
747
  mockKeyListRequest("env-bound-id", keys);
760
748
  await runWrangler(
761
749
  "kv:key list --binding someBinding --env some-environment"
@@ -764,19 +752,13 @@ describe("wrangler", () => {
764
752
  expect(std.out).toMatchInlineSnapshot(`
765
753
  "[
766
754
  {
767
- \\"name\\": \\"key-1\\",
768
- \\"expiration\\": 123456789,
769
- \\"metadata\\": {}
755
+ \\"name\\": \\"key-1\\"
770
756
  },
771
757
  {
772
- \\"name\\": \\"key-2\\",
773
- \\"expiration\\": 123456789,
774
- \\"metadata\\": {}
758
+ \\"name\\": \\"key-2\\"
775
759
  },
776
760
  {
777
- \\"name\\": \\"key-3\\",
778
- \\"expiration\\": 123456789,
779
- \\"metadata\\": {}
761
+ \\"name\\": \\"key-3\\"
780
762
  }
781
763
  ]"
782
764
  `);
@@ -784,7 +766,7 @@ describe("wrangler", () => {
784
766
 
785
767
  it("should list the keys of a preview namespace specified by binding, in a given environment", async () => {
786
768
  writeWranglerConfig();
787
- const keys = ["key-1", "key-2", "key-3"];
769
+ const keys = [{ name: "key-1" }, { name: "key-2" }, { name: "key-3" }];
788
770
  mockKeyListRequest("preview-env-bound-id", keys);
789
771
  await runWrangler(
790
772
  "kv:key list --binding someBinding --preview --env some-environment"
@@ -793,19 +775,13 @@ describe("wrangler", () => {
793
775
  expect(std.out).toMatchInlineSnapshot(`
794
776
  "[
795
777
  {
796
- \\"name\\": \\"key-1\\",
797
- \\"expiration\\": 123456789,
798
- \\"metadata\\": {}
778
+ \\"name\\": \\"key-1\\"
799
779
  },
800
780
  {
801
- \\"name\\": \\"key-2\\",
802
- \\"expiration\\": 123456789,
803
- \\"metadata\\": {}
781
+ \\"name\\": \\"key-2\\"
804
782
  },
805
783
  {
806
- \\"name\\": \\"key-3\\",
807
- \\"expiration\\": 123456789,
808
- \\"metadata\\": {}
784
+ \\"name\\": \\"key-3\\"
809
785
  }
810
786
  ]"
811
787
  `);
@@ -822,9 +798,9 @@ describe("wrangler", () => {
822
798
  describe(`cursor - ${blankCursorValue}`, () => {
823
799
  it("should make multiple requests for paginated results", async () => {
824
800
  // Create a lot of mock keys, so that the fetch requests will be paginated
825
- const keys: string[] = [];
801
+ const keys: NamespaceKeyInfo[] = [];
826
802
  for (let i = 0; i < 550; i++) {
827
- keys.push("key-" + i);
803
+ keys.push({ name: "key-" + i });
828
804
  }
829
805
  // Ask for the keys in pages of size 100.
830
806
  const requests = mockKeyListRequest(
@@ -833,13 +809,9 @@ describe("wrangler", () => {
833
809
  100,
834
810
  blankCursorValue
835
811
  );
836
- await runWrangler(
837
- "kv:key list --namespace-id some-namespace-id --limit 100"
838
- );
812
+ await runWrangler("kv:key list --namespace-id some-namespace-id");
839
813
  expect(std.err).toMatchInlineSnapshot(`""`);
840
- expect(
841
- JSON.parse(std.out).map((k: NamespaceKeyInfo) => k.name)
842
- ).toEqual(keys);
814
+ expect(JSON.parse(std.out)).toEqual(keys);
843
815
  expect(requests.count).toEqual(6);
844
816
  });
845
817
  });
@@ -915,7 +887,7 @@ describe("wrangler", () => {
915
887
  "my-value"
916
888
  );
917
889
  await runWrangler(
918
- "kv:key get my-key my-value --binding someBinding --env some-environment --preview false"
890
+ "kv:key get my-key --binding someBinding --env some-environment --preview false"
919
891
  );
920
892
  expect(std.out).toMatchInlineSnapshot(`"my-value"`);
921
893
  expect(std.err).toMatchInlineSnapshot(`""`);
@@ -945,7 +917,7 @@ describe("wrangler", () => {
945
917
  Options:
946
918
  --binding The name of the namespace to get from [string]
947
919
  --namespace-id The id of the namespace to get from [string]
948
- --env Perform on a specific environment [string]
920
+ -e, --env Perform on a specific environment [string]
949
921
  --preview Interact with a preview namespace [boolean] [default: false]
950
922
 
951
923
  Not enough non-option arguments: got 0, need at least 1"
@@ -976,7 +948,7 @@ describe("wrangler", () => {
976
948
  Options:
977
949
  --binding The name of the namespace to get from [string]
978
950
  --namespace-id The id of the namespace to get from [string]
979
- --env Perform on a specific environment [string]
951
+ -e, --env Perform on a specific environment [string]
980
952
  --preview Interact with a preview namespace [boolean] [default: false]
981
953
 
982
954
  Exactly one of the arguments binding and namespace-id is required"
@@ -1008,7 +980,7 @@ describe("wrangler", () => {
1008
980
  Options:
1009
981
  --binding The name of the namespace to get from [string]
1010
982
  --namespace-id The id of the namespace to get from [string]
1011
- --env Perform on a specific environment [string]
983
+ -e, --env Perform on a specific environment [string]
1012
984
  --preview Interact with a preview namespace [boolean] [default: false]
1013
985
 
1014
986
  Arguments binding and namespace-id are mutually exclusive"
@@ -1,3 +1,4 @@
1
+ import { execaSync } from "execa";
1
2
  import { getPackageManager } from "../package-manager";
2
3
  import { mockConsoleMethods } from "./helpers/mock-console";
3
4
  import { runInTempDir } from "./helpers/run-in-tmp";
@@ -23,22 +24,59 @@ describe("subcommand implicit help ran on imcomplete command execution", () => {
23
24
  function endEventLoop() {
24
25
  return new Promise((resolve) => setImmediate(resolve));
25
26
  }
26
- it("no subcommand for 'pages' should display a list of available subcommands", async () => {
27
+
28
+ it("should should display a list of available subcommands, for pages with no subcommand", async () => {
27
29
  await runWrangler("pages");
28
30
  await endEventLoop();
31
+
29
32
  expect(std.out).toMatchInlineSnapshot(`
30
- "wrangler pages
33
+ "wrangler pages
31
34
 
32
- ⚡️ Configure Cloudflare Pages
35
+ ⚡️ Configure Cloudflare Pages
33
36
 
34
- Commands:
35
- wrangler pages dev [directory] [-- command] 🧑‍💻 Develop your full-stack Pages application locally
37
+ Commands:
38
+ wrangler pages dev [directory] [-- command] 🧑‍💻 Develop your full-stack Pages application locally
36
39
 
37
- Flags:
38
- -c, --config Path to .toml configuration file [string]
39
- -h, --help Show help [boolean]
40
- -v, --version Show version number [boolean]
41
- --legacy-env Use legacy environments [boolean]"
40
+ Flags:
41
+ -c, --config Path to .toml configuration file [string]
42
+ -h, --help Show help [boolean]
43
+ -v, --version Show version number [boolean]
44
+ --legacy-env Use legacy environments [boolean]
45
+
46
+ 🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose"
42
47
  `);
43
48
  });
44
49
  });
50
+
51
+ describe("beta message for subcommands", () => {
52
+ const isWindows = process.platform === "win32";
53
+ it("should display for pages:dev", async () => {
54
+ try {
55
+ execaSync("npx", ["wrangler", "pages", "dev"], {
56
+ shell: isWindows,
57
+ env: { BROWSER: "none", ...process.env },
58
+ }).stderr;
59
+ } catch (e: unknown) {
60
+ expect(e).toMatchInlineSnapshot(`
61
+ [Error: Command failed with exit code 1: npx wrangler pages dev
62
+ 🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
63
+ Must specify a directory of static assets to serve or a command to run.]
64
+ `);
65
+ }
66
+ });
67
+
68
+ it("should display for pages:functions", async () => {
69
+ try {
70
+ execaSync("npx", ["wrangler", "pages", "functions"], {
71
+ shell: isWindows,
72
+ env: { BROWSER: "none", ...process.env },
73
+ }).stderr;
74
+ } catch (e: unknown) {
75
+ expect(e).toMatchInlineSnapshot(`
76
+ [Error: Command failed with exit code 1: npx wrangler pages functions
77
+ 🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
78
+ Must specify a directory of static assets to serve or a command to run.]
79
+ `);
80
+ }
81
+ });
82
+ });