wrangler 0.0.8 → 0.0.10
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/package.json +2 -2
- package/src/__tests__/dev.test.tsx +3 -2
- package/src/__tests__/kv.test.ts +24 -11
- package/src/__tests__/mock-cfetch.ts +4 -4
- package/src/api/form_data.ts +1 -1
- package/src/cfetch/internal.ts +4 -4
- package/src/config.ts +475 -119
- package/src/dev.tsx +52 -37
- package/src/index.tsx +2 -2
- package/src/inspect.ts +59 -44
- package/src/kv.tsx +18 -9
- package/src/proxy.ts +59 -51
- package/src/publish.ts +29 -23
- package/src/sites.tsx +5 -1
- package/src/user.tsx +10 -8
- package/wrangler-dist/cli.js +29591 -29559
- package/wrangler-dist/cli.js.map +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.10",
|
|
4
4
|
"author": "wrangler@cloudflare.com",
|
|
5
5
|
"description": "Command-line interface for all things Cloudflare Workers",
|
|
6
6
|
"bin": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"esbuild": "0.14.1",
|
|
40
|
-
"miniflare": "2.
|
|
40
|
+
"miniflare": "2.2.0",
|
|
41
41
|
"path-to-regexp": "^6.2.0",
|
|
42
42
|
"semiver": "^1.1.0"
|
|
43
43
|
},
|
|
@@ -15,9 +15,10 @@ describe("Dev component", () => {
|
|
|
15
15
|
accountId: "some-account-id",
|
|
16
16
|
public: "some/public/path",
|
|
17
17
|
});
|
|
18
|
-
expect(lastFrame()).
|
|
18
|
+
expect(lastFrame().split("\n").slice(0, 2).join("\n"))
|
|
19
|
+
.toMatchInlineSnapshot(`
|
|
19
20
|
"Something went wrong:
|
|
20
|
-
You cannot use the service worker format with a \`public\` directory."
|
|
21
|
+
Error: You cannot use the service worker format with a \`public\` directory."
|
|
21
22
|
`);
|
|
22
23
|
});
|
|
23
24
|
});
|
package/src/__tests__/kv.test.ts
CHANGED
|
@@ -8,6 +8,11 @@ import {
|
|
|
8
8
|
import { runWrangler } from "./run-wrangler";
|
|
9
9
|
import { runInTempDir } from "./run-in-tmp";
|
|
10
10
|
|
|
11
|
+
interface KVNamespaceInfo {
|
|
12
|
+
title: string;
|
|
13
|
+
id: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
11
16
|
describe("wrangler", () => {
|
|
12
17
|
runInTempDir();
|
|
13
18
|
|
|
@@ -196,30 +201,30 @@ describe("wrangler", () => {
|
|
|
196
201
|
}
|
|
197
202
|
|
|
198
203
|
it("should list namespaces", async () => {
|
|
199
|
-
const
|
|
204
|
+
const kvNamespaces: KVNamespaceInfo[] = [
|
|
200
205
|
{ title: "title-1", id: "id-1" },
|
|
201
206
|
{ title: "title-2", id: "id-2" },
|
|
202
207
|
];
|
|
203
|
-
mockListRequest(
|
|
208
|
+
mockListRequest(kvNamespaces);
|
|
204
209
|
const { error, stdout, stderr } = await runWrangler(
|
|
205
210
|
"kv:namespace list"
|
|
206
211
|
);
|
|
207
212
|
expect(error).toMatchInlineSnapshot(`undefined`);
|
|
208
213
|
expect(stderr).toMatchInlineSnapshot(`""`);
|
|
209
214
|
const namespaces = JSON.parse(stdout);
|
|
210
|
-
expect(namespaces).toEqual(
|
|
215
|
+
expect(namespaces).toEqual(kvNamespaces);
|
|
211
216
|
});
|
|
212
217
|
|
|
213
218
|
it("should make multiple requests for paginated results", async () => {
|
|
214
219
|
// Create a lot of mock namespaces, so that the fetch requests will be paginated
|
|
215
|
-
const
|
|
220
|
+
const kvNamespaces: KVNamespaceInfo[] = [];
|
|
216
221
|
for (let i = 0; i < 550; i++) {
|
|
217
|
-
|
|
222
|
+
kvNamespaces.push({ title: "title-" + i, id: "id-" + i });
|
|
218
223
|
}
|
|
219
|
-
const requests = mockListRequest(
|
|
224
|
+
const requests = mockListRequest(kvNamespaces);
|
|
220
225
|
const { stdout } = await runWrangler("kv:namespace list");
|
|
221
226
|
const namespaces = JSON.parse(stdout);
|
|
222
|
-
expect(namespaces).toEqual(
|
|
227
|
+
expect(namespaces).toEqual(kvNamespaces);
|
|
223
228
|
expect(requests.count).toEqual(6);
|
|
224
229
|
});
|
|
225
230
|
});
|
|
@@ -335,8 +340,16 @@ describe("wrangler", () => {
|
|
|
335
340
|
expect(namespaceId).toEqual(expectedNamespaceId);
|
|
336
341
|
expect(key).toEqual(expectedKey);
|
|
337
342
|
expect(body).toEqual(expectedValue);
|
|
338
|
-
|
|
339
|
-
|
|
343
|
+
if (expiration !== undefined) {
|
|
344
|
+
expect(query.get("expiration")).toEqual(`${expiration}`);
|
|
345
|
+
} else {
|
|
346
|
+
expect(query.has("expiration")).toBe(false);
|
|
347
|
+
}
|
|
348
|
+
if (expirationTtl) {
|
|
349
|
+
expect(query.get("expiration_ttl")).toEqual(`${expirationTtl}`);
|
|
350
|
+
} else {
|
|
351
|
+
expect(query.has("expiration_ttl")).toBe(false);
|
|
352
|
+
}
|
|
340
353
|
return null;
|
|
341
354
|
}
|
|
342
355
|
);
|
|
@@ -681,7 +694,7 @@ describe("wrangler", () => {
|
|
|
681
694
|
if (expectedKeys.length <= keysPerRequest) {
|
|
682
695
|
return createFetchResult(expectedKeys);
|
|
683
696
|
} else {
|
|
684
|
-
const start = parseInt(query.get("cursor")) || 0;
|
|
697
|
+
const start = parseInt(query.get("cursor") ?? "0") || 0;
|
|
685
698
|
const end = start + keysPerRequest;
|
|
686
699
|
const cursor = end < expectedKeys.length ? end : undefined;
|
|
687
700
|
return createFetchResult(
|
|
@@ -778,7 +791,7 @@ describe("wrangler", () => {
|
|
|
778
791
|
|
|
779
792
|
it("should make multiple requests for paginated results", async () => {
|
|
780
793
|
// Create a lot of mock keys, so that the fetch requests will be paginated
|
|
781
|
-
const keys = [];
|
|
794
|
+
const keys: string[] = [];
|
|
782
795
|
for (let i = 0; i < 550; i++) {
|
|
783
796
|
keys.push("key-" + i);
|
|
784
797
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { RequestInit } from "node-fetch";
|
|
2
|
-
import
|
|
2
|
+
import { URLSearchParams } from "node:url";
|
|
3
3
|
import { pathToRegexp } from "path-to-regexp";
|
|
4
4
|
import { CF_API_BASE_URL } from "../cfetch";
|
|
5
5
|
import type { FetchResult } from "../cfetch";
|
|
@@ -9,8 +9,8 @@ import type { FetchResult } from "../cfetch";
|
|
|
9
9
|
*/
|
|
10
10
|
export type MockHandler<ResponseType> = (
|
|
11
11
|
uri: RegExpExecArray,
|
|
12
|
-
init
|
|
13
|
-
queryParams
|
|
12
|
+
init: RequestInit,
|
|
13
|
+
queryParams: URLSearchParams
|
|
14
14
|
) => ResponseType;
|
|
15
15
|
|
|
16
16
|
type RemoveMockFn = () => void;
|
|
@@ -32,7 +32,7 @@ const mocks: MockFetch<unknown>[] = [];
|
|
|
32
32
|
export async function mockFetchInternal(
|
|
33
33
|
resource: string,
|
|
34
34
|
init: RequestInit = {},
|
|
35
|
-
queryParams
|
|
35
|
+
queryParams: URLSearchParams = new URLSearchParams()
|
|
36
36
|
) {
|
|
37
37
|
for (const { regexp, method, handler } of mocks) {
|
|
38
38
|
const resourcePath = new URL(resource, CF_API_BASE_URL).pathname;
|
package/src/api/form_data.ts
CHANGED
|
@@ -23,7 +23,7 @@ export function toMimeType(type: CfModuleType): string {
|
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
function toModule(module: CfModule, entryType
|
|
26
|
+
function toModule(module: CfModule, entryType: CfModuleType): Blob {
|
|
27
27
|
const { type: moduleType, content } = module;
|
|
28
28
|
const type = toMimeType(moduleType ?? entryType);
|
|
29
29
|
|
package/src/cfetch/internal.ts
CHANGED
|
@@ -40,6 +40,10 @@ export async function fetchInternal<ResponseType>(
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
function cloneHeaders(headers: HeadersInit): HeadersInit {
|
|
44
|
+
return { ...headers };
|
|
45
|
+
}
|
|
46
|
+
|
|
43
47
|
async function requireLoggedIn(): Promise<void> {
|
|
44
48
|
const loggedIn = await loginOrRefreshIfRequired();
|
|
45
49
|
if (!loggedIn) {
|
|
@@ -55,10 +59,6 @@ function requireApiToken(): string {
|
|
|
55
59
|
return apiToken;
|
|
56
60
|
}
|
|
57
61
|
|
|
58
|
-
function cloneHeaders(headers: HeadersInit): HeadersInit {
|
|
59
|
-
return { ...headers };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
62
|
function addAuthorizationHeader(headers: HeadersInit, apiToken: string): void {
|
|
63
63
|
if (headers["Authorization"]) {
|
|
64
64
|
throw new Error(
|