wrangler 0.0.0-e151223 → 0.0.0-e29a241

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 (92) hide show
  1. package/miniflare-dist/index.mjs +79 -0
  2. package/miniflare-dist/index.mjs.map +7 -0
  3. package/package.json +29 -13
  4. package/pages/functions/filepath-routing.test.ts +212 -36
  5. package/pages/functions/filepath-routing.ts +69 -119
  6. package/pages/functions/routes.ts +8 -17
  7. package/pages/functions/template-worker.ts +3 -9
  8. package/src/__tests__/configuration.test.ts +2754 -0
  9. package/src/__tests__/dev.test.tsx +488 -63
  10. package/src/__tests__/dev2.test.tsx +154 -0
  11. package/src/__tests__/guess-worker-format.test.ts +58 -0
  12. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  13. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  14. package/src/__tests__/helpers/mock-account-id.ts +26 -8
  15. package/src/__tests__/helpers/mock-bin.ts +36 -0
  16. package/src/__tests__/helpers/mock-cfetch.ts +44 -10
  17. package/src/__tests__/helpers/mock-console.ts +21 -7
  18. package/src/__tests__/helpers/mock-kv.ts +9 -16
  19. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  20. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  21. package/src/__tests__/helpers/run-in-tmp.ts +3 -0
  22. package/src/__tests__/helpers/run-wrangler.ts +5 -3
  23. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  24. package/src/__tests__/https-options.test.ts +127 -0
  25. package/src/__tests__/index.test.ts +617 -32
  26. package/src/__tests__/jest.setup.ts +41 -6
  27. package/src/__tests__/kv.test.ts +455 -222
  28. package/src/__tests__/logout.test.ts +15 -13
  29. package/src/__tests__/package-manager.test.ts +206 -0
  30. package/src/__tests__/pages.test.ts +44 -0
  31. package/src/__tests__/parse.test.ts +322 -0
  32. package/src/__tests__/publish.test.ts +1919 -437
  33. package/src/__tests__/r2.test.ts +198 -0
  34. package/src/__tests__/route.test.ts +45 -0
  35. package/src/__tests__/secret.test.ts +301 -86
  36. package/src/__tests__/sentry.test.ts +146 -0
  37. package/src/__tests__/tail.test.ts +564 -0
  38. package/src/__tests__/whoami.test.tsx +21 -7
  39. package/src/bundle.ts +142 -0
  40. package/src/cfetch/index.ts +9 -16
  41. package/src/cfetch/internal.ts +89 -22
  42. package/src/cli.ts +10 -0
  43. package/src/config/README.md +107 -0
  44. package/src/config/config.ts +274 -0
  45. package/src/config/diagnostics.ts +80 -0
  46. package/src/config/environment.ts +310 -0
  47. package/src/config/index.ts +56 -0
  48. package/src/config/validation-helpers.ts +486 -0
  49. package/src/config/validation.ts +1096 -0
  50. package/src/{api/preview.ts → create-worker-preview.ts} +59 -21
  51. package/src/create-worker-upload-form.ts +217 -0
  52. package/src/dev/dev.tsx +364 -0
  53. package/src/dev/local.tsx +226 -0
  54. package/src/dev/remote.tsx +203 -0
  55. package/src/dev/use-esbuild.ts +100 -0
  56. package/src/entry.ts +208 -0
  57. package/src/environment-variables.ts +33 -0
  58. package/src/https-options.ts +122 -0
  59. package/src/index.tsx +1079 -766
  60. package/src/inspect.ts +25 -4
  61. package/src/{kv.tsx → kv.ts} +104 -61
  62. package/src/miniflare-cli/README.md +30 -0
  63. package/src/miniflare-cli/enum-keys.ts +17 -0
  64. package/src/miniflare-cli/index.ts +37 -0
  65. package/src/module-collection.ts +226 -31
  66. package/src/open-in-browser.ts +25 -0
  67. package/src/package-manager.ts +126 -0
  68. package/src/pages.tsx +11 -11
  69. package/src/parse.ts +183 -0
  70. package/src/proxy.ts +115 -45
  71. package/src/publish.ts +265 -328
  72. package/src/r2.ts +50 -0
  73. package/src/reporting.ts +131 -0
  74. package/src/selfsigned.d.ts +29 -0
  75. package/src/sites.tsx +83 -43
  76. package/src/tail/filters.ts +279 -0
  77. package/src/tail/index.ts +299 -0
  78. package/src/tail/printing.ts +62 -0
  79. package/src/user.tsx +223 -124
  80. package/src/{api/worker.ts → worker.ts} +44 -36
  81. package/templates/new-worker.js +15 -0
  82. package/templates/new-worker.ts +15 -0
  83. package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
  84. package/templates/tsconfig.json +105 -0
  85. package/wrangler-dist/cli.js +60837 -43876
  86. package/wrangler-dist/cli.js.map +3 -3
  87. package/src/__tests__/helpers/mock-user.ts +0 -27
  88. package/src/api/form_data.ts +0 -134
  89. package/src/config.ts +0 -641
  90. package/src/dev.tsx +0 -834
  91. package/src/npm-installer.ts +0 -20
  92. package/src/tail.tsx +0 -73
@@ -0,0 +1,198 @@
1
+ import { mockAccountId, mockApiToken } from "./helpers/mock-account-id";
2
+ import { setMockResponse, unsetAllMocks } from "./helpers/mock-cfetch";
3
+ import { mockConsoleMethods } from "./helpers/mock-console";
4
+ import { runInTempDir } from "./helpers/run-in-tmp";
5
+ import { runWrangler } from "./helpers/run-wrangler";
6
+ import type { R2BucketInfo } from "../r2";
7
+
8
+ describe("wrangler", () => {
9
+ mockAccountId();
10
+ mockApiToken();
11
+ runInTempDir();
12
+ const std = mockConsoleMethods();
13
+
14
+ afterEach(() => {
15
+ unsetAllMocks();
16
+ });
17
+
18
+ describe("r2", () => {
19
+ describe("bucket", () => {
20
+ describe("list", () => {
21
+ function mockListRequest(buckets: R2BucketInfo[]) {
22
+ const requests = { count: 0 };
23
+ setMockResponse(
24
+ "/accounts/:accountId/r2/buckets",
25
+ ([_url, accountId], init) => {
26
+ requests.count++;
27
+ expect(accountId).toEqual("some-account-id");
28
+ expect(init).toEqual({});
29
+ return { buckets };
30
+ }
31
+ );
32
+ return requests;
33
+ }
34
+
35
+ it("should list buckets", async () => {
36
+ const expectedBuckets: R2BucketInfo[] = [
37
+ { name: "bucket-1", creation_date: "01-01-2001" },
38
+ { name: "bucket-2", creation_date: "01-01-2001" },
39
+ ];
40
+ mockListRequest(expectedBuckets);
41
+ await runWrangler("r2 bucket list");
42
+
43
+ expect(std.err).toMatchInlineSnapshot(`""`);
44
+ const buckets = JSON.parse(std.out);
45
+ expect(buckets).toEqual(expectedBuckets);
46
+ });
47
+ });
48
+
49
+ describe("create", () => {
50
+ function mockCreateRequest(expectedBucketName: string) {
51
+ const requests = { count: 0 };
52
+ setMockResponse(
53
+ "/accounts/:accountId/r2/buckets/:bucketName",
54
+ "PUT",
55
+ ([_url, accountId, bucketName]) => {
56
+ expect(accountId).toEqual("some-account-id");
57
+ expect(bucketName).toEqual(expectedBucketName);
58
+ requests.count += 1;
59
+ }
60
+ );
61
+ return requests;
62
+ }
63
+
64
+ it("should error if no bucket name is given", async () => {
65
+ await expect(
66
+ runWrangler("r2 bucket create")
67
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
68
+ `"Not enough non-option arguments: got 0, need at least 1"`
69
+ );
70
+ expect(std.out).toMatchInlineSnapshot(`""`);
71
+ expect(std.err).toMatchInlineSnapshot(`
72
+ "wrangler r2 bucket create <name>
73
+
74
+ Create a new R2 bucket
75
+
76
+ Positionals:
77
+ name The name of the new bucket [string] [required]
78
+
79
+ Flags:
80
+ -c, --config Path to .toml configuration file [string]
81
+ -h, --help Show help [boolean]
82
+ -v, --version Show version number [boolean]
83
+ --legacy-env Use legacy environments [boolean]
84
+
85
+ Not enough non-option arguments: got 0, need at least 1"
86
+ `);
87
+ });
88
+
89
+ it("should error if the bucket to create contains spaces", async () => {
90
+ await expect(
91
+ runWrangler("r2 bucket create abc def ghi")
92
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
93
+ `"Unexpected additional positional arguments \\"def ghi\\"."`
94
+ );
95
+ expect(std.out).toMatchInlineSnapshot(`""`);
96
+ expect(std.err).toMatchInlineSnapshot(`
97
+ "wrangler r2 bucket create <name>
98
+
99
+ Create a new R2 bucket
100
+
101
+ Positionals:
102
+ name The name of the new bucket [string] [required]
103
+
104
+ Flags:
105
+ -c, --config Path to .toml configuration file [string]
106
+ -h, --help Show help [boolean]
107
+ -v, --version Show version number [boolean]
108
+ --legacy-env Use legacy environments [boolean]
109
+
110
+ Unexpected additional positional arguments \\"def ghi\\"."
111
+ `);
112
+ });
113
+
114
+ it("should create a bucket", async () => {
115
+ const requests = mockCreateRequest("testBucket");
116
+ await runWrangler("r2 bucket create testBucket");
117
+ expect(std.out).toMatchInlineSnapshot(`
118
+ "Creating bucket testBucket.
119
+ Created bucket testBucket."
120
+ `);
121
+ expect(requests.count).toEqual(1);
122
+ });
123
+ });
124
+
125
+ describe("delete", () => {
126
+ function mockDeleteRequest(expectedBucketName: string) {
127
+ const requests = { count: 0 };
128
+ setMockResponse(
129
+ "/accounts/:accountId/r2/buckets/:bucketName",
130
+ "DELETE",
131
+ ([_url, accountId, bucketName]) => {
132
+ expect(accountId).toEqual("some-account-id");
133
+ expect(bucketName).toEqual(expectedBucketName);
134
+ requests.count += 1;
135
+ }
136
+ );
137
+ return requests;
138
+ }
139
+
140
+ it("should error if no bucket name is given", async () => {
141
+ await expect(
142
+ runWrangler("r2 bucket delete")
143
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
144
+ `"Not enough non-option arguments: got 0, need at least 1"`
145
+ );
146
+ expect(std.out).toMatchInlineSnapshot(`""`);
147
+ expect(std.err).toMatchInlineSnapshot(`
148
+ "wrangler r2 bucket delete <name>
149
+
150
+ Delete an R2 bucket
151
+
152
+ Positionals:
153
+ name The name of the bucket to delete [string] [required]
154
+
155
+ Flags:
156
+ -c, --config Path to .toml configuration file [string]
157
+ -h, --help Show help [boolean]
158
+ -v, --version Show version number [boolean]
159
+ --legacy-env Use legacy environments [boolean]
160
+
161
+ Not enough non-option arguments: got 0, need at least 1"
162
+ `);
163
+ });
164
+
165
+ it("should error if the bucket name to delete contains spaces", async () => {
166
+ await expect(
167
+ runWrangler("r2 bucket delete abc def ghi")
168
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
169
+ `"Unexpected additional positional arguments \\"def ghi\\"."`
170
+ );
171
+ expect(std.out).toMatchInlineSnapshot(`""`);
172
+ expect(std.err).toMatchInlineSnapshot(`
173
+ "wrangler r2 bucket delete <name>
174
+
175
+ Delete an R2 bucket
176
+
177
+ Positionals:
178
+ name The name of the bucket to delete [string] [required]
179
+
180
+ Flags:
181
+ -c, --config Path to .toml configuration file [string]
182
+ -h, --help Show help [boolean]
183
+ -v, --version Show version number [boolean]
184
+ --legacy-env Use legacy environments [boolean]
185
+
186
+ Unexpected additional positional arguments \\"def ghi\\"."
187
+ `);
188
+ });
189
+
190
+ it("should delete a bucket specified by name", async () => {
191
+ const requests = mockDeleteRequest("some-bucket");
192
+ await runWrangler(`r2 bucket delete some-bucket`);
193
+ expect(requests.count).toEqual(1);
194
+ });
195
+ });
196
+ });
197
+ });
198
+ });
@@ -0,0 +1,45 @@
1
+ import { mockConsoleMethods } from "./helpers/mock-console";
2
+ import { runInTempDir } from "./helpers/run-in-tmp";
3
+ import { runWrangler } from "./helpers/run-wrangler";
4
+
5
+ describe("wrangler route", () => {
6
+ mockConsoleMethods();
7
+ runInTempDir();
8
+
9
+ it("shows a deprecation notice when `wrangler route` is run", async () => {
10
+ await expect(runWrangler("route")).rejects
11
+ .toThrowErrorMatchingInlineSnapshot(`
12
+ "DEPRECATION WARNING:
13
+ \`wrangler route\` has been deprecated.
14
+ Please use wrangler.toml and/or \`wrangler publish --routes\` to modify routes"
15
+ `);
16
+ });
17
+
18
+ it("shows a deprecation notice when `wrangler route delete` is run", async () => {
19
+ await expect(runWrangler("route delete")).rejects
20
+ .toThrowErrorMatchingInlineSnapshot(`
21
+ "DEPRECATION WARNING:
22
+ \`wrangler route delete\` has been deprecated.
23
+ Remove the unwanted route(s) from wrangler.toml and run \`wrangler publish\` to remove your worker from those routes."
24
+ `);
25
+ });
26
+
27
+ it("shows a deprecation notice when `wrangler route delete <id>` is run", async () => {
28
+ await expect(runWrangler("route delete some-zone-id")).rejects
29
+ .toThrowErrorMatchingInlineSnapshot(`
30
+ "DEPRECATION WARNING:
31
+ \`wrangler route delete\` has been deprecated.
32
+ Remove the unwanted route(s) from wrangler.toml and run \`wrangler publish\` to remove your worker from those routes."
33
+ `);
34
+ });
35
+
36
+ it("shows a deprecation notice when `wrangler route list` is run", async () => {
37
+ await expect(runWrangler("route list")).rejects
38
+ .toThrowErrorMatchingInlineSnapshot(`
39
+ "DEPRECATION WARNING:
40
+ \`wrangler route list\` has been deprecated.
41
+ Refer to wrangler.toml for a list of routes the worker will be deployed to upon publishing.
42
+ Refer to the Cloudflare Dashboard to see the routes this worker is currently running on."
43
+ `);
44
+ });
45
+ });