wrangler 0.0.0-e6733a3 → 0.0.0-e88a54e
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/bin/wrangler.js +2 -2
- package/miniflare-dist/index.mjs +79 -0
- package/miniflare-dist/index.mjs.map +7 -0
- package/package.json +35 -16
- package/pages/functions/buildWorker.ts +1 -1
- package/pages/functions/filepath-routing.test.ts +212 -28
- package/pages/functions/filepath-routing.ts +91 -131
- package/pages/functions/routes.ts +11 -18
- package/pages/functions/template-worker.ts +19 -33
- package/src/__tests__/configuration.test.ts +2796 -0
- package/src/__tests__/dev.test.tsx +488 -58
- package/src/__tests__/dev2.test.tsx +154 -0
- package/src/__tests__/guess-worker-format.test.ts +58 -0
- package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
- package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
- package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +48 -0
- package/src/__tests__/helpers/mock-bin.ts +36 -0
- package/src/__tests__/{mock-cfetch.ts → helpers/mock-cfetch.ts} +55 -19
- package/src/__tests__/helpers/mock-console.ts +70 -0
- package/src/__tests__/{mock-dialogs.ts → helpers/mock-dialogs.ts} +1 -1
- package/src/__tests__/helpers/mock-kv.ts +33 -0
- 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 +32 -0
- package/src/__tests__/helpers/run-wrangler.ts +16 -0
- 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 +779 -75
- package/src/__tests__/jest.setup.ts +53 -6
- package/src/__tests__/kv.test.ts +738 -454
- package/src/__tests__/logout.test.ts +52 -0
- package/src/__tests__/package-manager.test.ts +206 -0
- package/src/__tests__/pages.test.ts +44 -0
- package/src/__tests__/parse.test.ts +322 -0
- package/src/__tests__/publish.test.ts +2704 -0
- package/src/__tests__/r2.test.ts +198 -0
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +425 -0
- package/src/__tests__/sentry.test.ts +146 -0
- package/src/__tests__/tail.test.ts +564 -0
- package/src/__tests__/whoami.test.tsx +100 -0
- package/src/bundle.ts +142 -0
- package/src/cfetch/index.ts +21 -19
- package/src/cfetch/internal.ts +94 -24
- 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 +366 -0
- package/src/config/index.ts +62 -0
- package/src/config/validation-helpers.ts +486 -0
- package/src/config/validation.ts +1090 -0
- package/src/{api/preview.ts → create-worker-preview.ts} +61 -23
- package/src/create-worker-upload-form.ts +217 -0
- package/src/dev/dev.tsx +364 -0
- package/src/dev/local.tsx +232 -0
- package/src/dev/remote.tsx +203 -0
- package/src/dev/use-esbuild.ts +100 -0
- package/src/dialogs.tsx +2 -2
- package/src/entry.ts +208 -0
- package/src/environment-variables.ts +33 -0
- package/src/https-options.ts +122 -0
- package/src/index.tsx +1198 -799
- package/src/inspect.ts +159 -66
- package/src/{kv.tsx → kv.ts} +117 -65
- 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 +229 -35
- package/src/open-in-browser.ts +25 -0
- package/src/package-manager.ts +126 -0
- package/src/pages.tsx +58 -42
- package/src/parse.ts +183 -0
- package/src/paths.ts +26 -0
- package/src/proxy.ts +224 -78
- package/src/publish.ts +281 -292
- package/src/r2.ts +50 -0
- package/src/reporting.ts +131 -0
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +224 -58
- 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 +273 -180
- package/src/whoami.tsx +69 -0
- package/src/{api/worker.ts → worker.ts} +45 -37
- package/templates/new-worker.js +15 -0
- package/templates/new-worker.ts +15 -0
- package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.js +130612 -112486
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/run-in-tmp.ts +0 -19
- package/src/__tests__/run-wrangler.ts +0 -32
- package/src/api/form_data.ts +0 -131
- package/src/config.ts +0 -487
- package/src/dev.tsx +0 -771
- package/src/tail.tsx +0 -73
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
3
|
import { isValidIdentifier, normalizeIdentifier } from "./identifiers";
|
|
4
|
+
import type { UrlPath } from "../../src/paths";
|
|
4
5
|
|
|
5
6
|
export const HTTP_METHODS = [
|
|
6
7
|
"HEAD",
|
|
@@ -19,22 +20,20 @@ export function isHTTPMethod(
|
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
export type RoutesCollection = Array<{
|
|
22
|
-
routePath:
|
|
23
|
-
|
|
23
|
+
routePath: UrlPath;
|
|
24
|
+
method?: HTTPMethod;
|
|
24
25
|
modules: string[];
|
|
25
26
|
middlewares: string[];
|
|
26
27
|
}>;
|
|
27
28
|
|
|
28
29
|
export type Config = {
|
|
29
|
-
routes?:
|
|
30
|
+
routes?: RouteConfig[];
|
|
30
31
|
schedules?: unknown;
|
|
31
32
|
};
|
|
32
33
|
|
|
33
|
-
export type RoutesConfig = {
|
|
34
|
-
[route: string]: RouteConfig;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
34
|
export type RouteConfig = {
|
|
35
|
+
routePath: UrlPath;
|
|
36
|
+
method?: HTTPMethod;
|
|
38
37
|
middleware?: string | string[];
|
|
39
38
|
module?: string | string[];
|
|
40
39
|
};
|
|
@@ -114,16 +113,10 @@ export function parseConfig(config: Config, baseDir: string) {
|
|
|
114
113
|
});
|
|
115
114
|
}
|
|
116
115
|
|
|
117
|
-
for (const
|
|
118
|
-
let [_methods, routePath] = route.split(" ");
|
|
119
|
-
if (!routePath) {
|
|
120
|
-
routePath = _methods;
|
|
121
|
-
_methods = "";
|
|
122
|
-
}
|
|
123
|
-
|
|
116
|
+
for (const { routePath, method, ...props } of config.routes ?? []) {
|
|
124
117
|
routes.push({
|
|
125
118
|
routePath,
|
|
126
|
-
|
|
119
|
+
method,
|
|
127
120
|
middlewares: parseModuleIdentifiers(props.middleware),
|
|
128
121
|
modules: parseModuleIdentifiers(props.module),
|
|
129
122
|
});
|
|
@@ -148,7 +141,7 @@ export const routes = [
|
|
|
148
141
|
.map(
|
|
149
142
|
(route) => ` {
|
|
150
143
|
routePath: "${route.routePath}",
|
|
151
|
-
|
|
144
|
+
method: "${route.method}",
|
|
152
145
|
middlewares: [${route.middlewares.join(", ")}],
|
|
153
146
|
modules: [${route.modules.join(", ")}],
|
|
154
147
|
},`
|
|
@@ -22,7 +22,7 @@ declare type PagesFunction<
|
|
|
22
22
|
|
|
23
23
|
type RouteHandler = {
|
|
24
24
|
routePath: string;
|
|
25
|
-
|
|
25
|
+
method?: HTTPMethod;
|
|
26
26
|
modules: PagesFunction[];
|
|
27
27
|
middlewares: PagesFunction[];
|
|
28
28
|
};
|
|
@@ -33,25 +33,21 @@ declare const routes: RouteHandler[];
|
|
|
33
33
|
declare const __FALLBACK_SERVICE__: string;
|
|
34
34
|
|
|
35
35
|
// expect an ASSETS fetcher binding pointing to the asset-server stage
|
|
36
|
-
type
|
|
37
|
-
[name: string]:
|
|
38
|
-
ASSETS: { fetch
|
|
36
|
+
type FetchEnv = {
|
|
37
|
+
[name: string]: { fetch: typeof fetch };
|
|
38
|
+
ASSETS: { fetch: typeof fetch };
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
type WorkerContext = {
|
|
42
42
|
waitUntil: (promise: Promise<unknown>) => void;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
function* executeRequest(request: Request, env: Env) {
|
|
45
|
+
function* executeRequest(request: Request, _env: FetchEnv) {
|
|
47
46
|
const requestPath = new URL(request.url).pathname;
|
|
48
47
|
|
|
49
48
|
// First, iterate through the routes (backwards) and execute "middlewares" on partial route matches
|
|
50
49
|
for (const route of [...routes].reverse()) {
|
|
51
|
-
if (
|
|
52
|
-
route.methods.length &&
|
|
53
|
-
!route.methods.includes(request.method as HTTPMethod)
|
|
54
|
-
) {
|
|
50
|
+
if (route.method && route.method !== request.method) {
|
|
55
51
|
continue;
|
|
56
52
|
}
|
|
57
53
|
|
|
@@ -69,10 +65,7 @@ function* executeRequest(request: Request, env: Env) {
|
|
|
69
65
|
|
|
70
66
|
// Then look for the first exact route match and execute its "modules"
|
|
71
67
|
for (const route of routes) {
|
|
72
|
-
if (
|
|
73
|
-
route.methods.length &&
|
|
74
|
-
!route.methods.includes(request.method as HTTPMethod)
|
|
75
|
-
) {
|
|
68
|
+
if (route.method && route.method !== request.method) {
|
|
76
69
|
continue;
|
|
77
70
|
}
|
|
78
71
|
|
|
@@ -88,20 +81,10 @@ function* executeRequest(request: Request, env: Env) {
|
|
|
88
81
|
break;
|
|
89
82
|
}
|
|
90
83
|
}
|
|
91
|
-
|
|
92
|
-
// Finally, yield to the fallback service (`env.ASSETS.fetch` in Pages' case)
|
|
93
|
-
return {
|
|
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),
|
|
99
|
-
params: {} as Params,
|
|
100
|
-
};
|
|
101
84
|
}
|
|
102
85
|
|
|
103
86
|
export default {
|
|
104
|
-
async fetch(request: Request, env:
|
|
87
|
+
async fetch(request: Request, env: FetchEnv, workerContext: WorkerContext) {
|
|
105
88
|
const handlerIterator = executeRequest(request, env);
|
|
106
89
|
const data = {}; // arbitrary data the user can set between functions
|
|
107
90
|
const next = async (input?: RequestInfo, init?: RequestInit) => {
|
|
@@ -109,14 +92,11 @@ export default {
|
|
|
109
92
|
request = new Request(input, init);
|
|
110
93
|
}
|
|
111
94
|
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
string,
|
|
118
|
-
Record<string, unknown>
|
|
119
|
-
> = {
|
|
95
|
+
const result = handlerIterator.next();
|
|
96
|
+
// Note we can't use `!result.done` because this doesn't narrow to the correct type
|
|
97
|
+
if (result.done == false) {
|
|
98
|
+
const { handler, params } = result.value;
|
|
99
|
+
const context = {
|
|
120
100
|
request: new Request(request.clone()),
|
|
121
101
|
next,
|
|
122
102
|
params,
|
|
@@ -132,6 +112,12 @@ export default {
|
|
|
132
112
|
[101, 204, 205, 304].includes(response.status) ? null : response.body,
|
|
133
113
|
response
|
|
134
114
|
);
|
|
115
|
+
} else if (__FALLBACK_SERVICE__) {
|
|
116
|
+
// There are no more handlers so finish with the fallback service (`env.ASSETS.fetch` in Pages' case)
|
|
117
|
+
return env[__FALLBACK_SERVICE__].fetch(request);
|
|
118
|
+
} else {
|
|
119
|
+
// There was not fallback service so actually make the request to the origin.
|
|
120
|
+
return fetch(request);
|
|
135
121
|
}
|
|
136
122
|
};
|
|
137
123
|
|