wrangler 0.0.0-e1c615f → 0.0.0-e22f9d7
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 +3 -2
- package/pages/functions/buildWorker.ts +5 -0
- package/pages/functions/template-worker.ts +9 -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/api/worker.ts +6 -6
- package/src/cfetch/internal.ts +4 -4
- package/src/config.ts +475 -119
- package/src/dev.tsx +107 -197
- package/src/index.tsx +50 -5
- package/src/inspect.ts +539 -0
- package/src/kv.tsx +18 -9
- package/src/pages.tsx +98 -35
- package/src/proxy.ts +275 -76
- package/src/publish.ts +40 -26
- package/src/sites.tsx +5 -1
- package/src/user.tsx +22 -17
- package/wrangler-dist/cli.js +30051 -29836
- package/wrangler-dist/cli.js.map +3 -3
- package/src/api/inspect.ts +0 -430
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-e22f9d7",
|
|
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
|
},
|
|
@@ -59,6 +59,7 @@
|
|
|
59
59
|
"chokidar": "^3.5.2",
|
|
60
60
|
"clipboardy": "^3.0.0",
|
|
61
61
|
"command-exists": "^1.2.9",
|
|
62
|
+
"devtools-protocol": "^0.0.955664",
|
|
62
63
|
"execa": "^6.0.0",
|
|
63
64
|
"faye-websocket": "^0.11.4",
|
|
64
65
|
"finalhandler": "^1.1.2",
|
|
@@ -6,6 +6,7 @@ type Options = {
|
|
|
6
6
|
outfile: string;
|
|
7
7
|
minify?: boolean;
|
|
8
8
|
sourcemap?: boolean;
|
|
9
|
+
fallbackService?: string;
|
|
9
10
|
watch?: boolean;
|
|
10
11
|
onEnd?: () => void;
|
|
11
12
|
};
|
|
@@ -15,6 +16,7 @@ export function buildWorker({
|
|
|
15
16
|
outfile = "bundle.js",
|
|
16
17
|
minify = false,
|
|
17
18
|
sourcemap = false,
|
|
19
|
+
fallbackService = "ASSETS",
|
|
18
20
|
watch = false,
|
|
19
21
|
onEnd = () => {},
|
|
20
22
|
}: Options) {
|
|
@@ -31,6 +33,9 @@ export function buildWorker({
|
|
|
31
33
|
sourcemap,
|
|
32
34
|
watch,
|
|
33
35
|
allowOverwrite: true,
|
|
36
|
+
define: {
|
|
37
|
+
__FALLBACK_SERVICE__: JSON.stringify(fallbackService),
|
|
38
|
+
},
|
|
34
39
|
plugins: [
|
|
35
40
|
{
|
|
36
41
|
name: "wrangler notifier and monitor",
|
|
@@ -29,6 +29,8 @@ type RouteHandler = {
|
|
|
29
29
|
|
|
30
30
|
// inject `routes` via ESBuild
|
|
31
31
|
declare const routes: RouteHandler[];
|
|
32
|
+
// define `__FALLBACK_SERVICE__` via ESBuild
|
|
33
|
+
declare const __FALLBACK_SERVICE__: string;
|
|
32
34
|
|
|
33
35
|
// expect an ASSETS fetcher binding pointing to the asset-server stage
|
|
34
36
|
type Env = {
|
|
@@ -40,6 +42,7 @@ type WorkerContext = {
|
|
|
40
42
|
waitUntil: (promise: Promise<unknown>) => void;
|
|
41
43
|
};
|
|
42
44
|
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- `env` can be used by __FALLBACK_SERVICE_FETCH__
|
|
43
46
|
function* executeRequest(request: Request, env: Env) {
|
|
44
47
|
const requestPath = new URL(request.url).pathname;
|
|
45
48
|
|
|
@@ -86,9 +89,13 @@ function* executeRequest(request: Request, env: Env) {
|
|
|
86
89
|
}
|
|
87
90
|
}
|
|
88
91
|
|
|
89
|
-
// Finally, yield to the
|
|
92
|
+
// Finally, yield to the fallback service (`env.ASSETS.fetch` in Pages' case)
|
|
90
93
|
return {
|
|
91
|
-
handler: () =>
|
|
94
|
+
handler: () =>
|
|
95
|
+
__FALLBACK_SERVICE__
|
|
96
|
+
? // @ts-expect-error expecting __FALLBACK_SERVICE__ to be the name of a service binding, so fetch should be defined
|
|
97
|
+
env[__FALLBACK_SERVICE__].fetch(request)
|
|
98
|
+
: fetch(request),
|
|
92
99
|
params: {} as Params,
|
|
93
100
|
};
|
|
94
101
|
}
|
|
@@ -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/api/worker.ts
CHANGED
|
@@ -112,7 +112,7 @@ export interface CfWorkerInit {
|
|
|
112
112
|
/**
|
|
113
113
|
* The name of the worker.
|
|
114
114
|
*/
|
|
115
|
-
name: string |
|
|
115
|
+
name: string | undefined;
|
|
116
116
|
/**
|
|
117
117
|
* The entrypoint module.
|
|
118
118
|
*/
|
|
@@ -120,7 +120,7 @@ export interface CfWorkerInit {
|
|
|
120
120
|
/**
|
|
121
121
|
* The list of additional modules.
|
|
122
122
|
*/
|
|
123
|
-
modules:
|
|
123
|
+
modules: undefined | CfModule[];
|
|
124
124
|
/**
|
|
125
125
|
* All the bindings
|
|
126
126
|
*/
|
|
@@ -130,10 +130,10 @@ export interface CfWorkerInit {
|
|
|
130
130
|
vars?: CfVars;
|
|
131
131
|
services?: CfService[];
|
|
132
132
|
};
|
|
133
|
-
migrations:
|
|
134
|
-
compatibility_date: string |
|
|
135
|
-
compatibility_flags:
|
|
136
|
-
usage_model:
|
|
133
|
+
migrations: undefined | CfDurableObjectMigrations;
|
|
134
|
+
compatibility_date: string | undefined;
|
|
135
|
+
compatibility_flags: undefined | string[];
|
|
136
|
+
usage_model: undefined | "bundled" | "unbound";
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
/**
|
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(
|