wrangler 0.0.0-e2a26a0 → 0.0.0-e2b7352
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.
- package/README.md +3 -3
- package/bin/wrangler.js +10 -1
- package/miniflare-dist/index.mjs +79 -0
- package/miniflare-dist/index.mjs.map +7 -0
- package/package.json +24 -12
- package/pages/functions/filepath-routing.test.ts +212 -36
- package/pages/functions/filepath-routing.ts +69 -119
- package/pages/functions/routes.ts +8 -17
- package/pages/functions/template-worker.ts +3 -9
- package/src/__tests__/configuration.test.ts +2820 -0
- package/src/__tests__/dev.test.tsx +535 -65
- package/src/__tests__/guess-worker-format.test.ts +68 -0
- package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +26 -8
- package/src/__tests__/helpers/mock-bin.ts +4 -1
- package/src/__tests__/helpers/mock-cfetch.ts +5 -5
- package/src/__tests__/helpers/mock-console.ts +21 -7
- package/src/__tests__/helpers/mock-kv.ts +9 -16
- package/src/__tests__/helpers/mock-stdin.ts +103 -0
- package/src/__tests__/helpers/mock-web-socket.ts +29 -0
- package/src/__tests__/helpers/run-in-tmp.ts +3 -0
- package/src/__tests__/helpers/run-wrangler.ts +5 -3
- package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
- package/src/__tests__/https-options.test.ts +127 -0
- package/src/__tests__/index.test.ts +467 -27
- package/src/__tests__/jest.setup.ts +37 -5
- package/src/__tests__/kv.test.ts +442 -201
- package/src/__tests__/logout.test.ts +15 -13
- package/src/__tests__/package-manager.test.ts +2 -2
- package/src/__tests__/pages.test.ts +82 -0
- package/src/__tests__/parse.test.ts +322 -0
- package/src/__tests__/publish.test.ts +2717 -430
- package/src/__tests__/r2.test.ts +198 -0
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +301 -86
- package/src/__tests__/sentry.test.ts +146 -0
- package/src/__tests__/tail.test.ts +638 -0
- package/src/__tests__/whoami.test.tsx +21 -7
- package/src/bundle.ts +155 -0
- package/src/cfetch/index.ts +8 -6
- package/src/cfetch/internal.ts +60 -22
- package/src/cli.ts +10 -0
- package/src/config/README.md +107 -0
- package/src/config/config.ts +218 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +371 -0
- package/src/config/index.ts +62 -0
- package/src/config/validation-helpers.ts +554 -0
- package/src/config/validation.ts +1232 -0
- package/src/{api/preview.ts → create-worker-preview.ts} +59 -21
- package/src/create-worker-upload-form.ts +217 -0
- package/src/dev/dev.tsx +392 -0
- package/src/dev/local.tsx +232 -0
- package/src/dev/remote.tsx +203 -0
- package/src/dev/use-esbuild.ts +104 -0
- package/src/entry.ts +240 -0
- package/src/environment-variables.ts +33 -0
- package/src/https-options.ts +122 -0
- package/src/index.tsx +1068 -780
- package/src/inspect.ts +25 -4
- package/src/intl-polyfill.d.ts +139 -0
- package/src/{kv.tsx → kv.ts} +95 -60
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +37 -0
- package/src/module-collection.ts +226 -31
- package/src/open-in-browser.ts +25 -0
- package/src/package-manager.ts +21 -15
- package/src/pages.tsx +35 -20
- package/src/parse.ts +183 -0
- package/src/proxy.ts +115 -45
- package/src/publish.ts +268 -328
- package/src/r2.ts +50 -0
- package/src/reporting.ts +131 -0
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +83 -43
- package/src/tail/filters.ts +279 -0
- package/src/tail/index.ts +299 -0
- package/src/tail/printing.ts +62 -0
- package/src/user.tsx +234 -126
- package/src/{api/worker.ts → worker.ts} +44 -36
- package/templates/new-worker.js +1 -1
- package/templates/new-worker.ts +1 -1
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.js +131202 -114243
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/api/form_data.ts +0 -134
- package/src/config.ts +0 -641
- package/src/dev.tsx +0 -834
- 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
|
+
`"Unknown 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
|
+
Unknown 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
|
+
`"Unknown 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
|
+
Unknown 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
|
+
});
|