wrangler 0.0.0-e4ef867c → 0.0.0-e57758f8
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 +1 -1
- package/bin/wrangler.js +5 -0
- package/config-schema.json +2939 -0
- package/package.json +217 -195
- package/templates/facade.d.ts +7 -5
- package/templates/gitignore +0 -5
- package/templates/init-tests/test-vitest-new-worker.js +1 -1
- package/templates/init-tests/test-vitest-new-worker.ts +1 -1
- package/templates/middleware/loader-modules.ts +93 -97
- package/templates/middleware/loader-sw.ts +4 -3
- package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
- package/templates/middleware/middleware-serve-static-assets.ts +5 -5
- package/templates/modules-watch-stub.js +4 -0
- package/templates/pages-dev-pipeline.ts +2 -1
- package/templates/startDevWorker/InspectorProxyWorker.ts +661 -0
- package/templates/startDevWorker/ProxyWorker.ts +331 -0
- package/wrangler-dist/InspectorProxyWorker.js +464 -0
- package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
- package/wrangler-dist/ProxyWorker.js +240 -0
- package/wrangler-dist/ProxyWorker.js.map +6 -0
- package/wrangler-dist/cli.d.ts +22463 -158
- package/wrangler-dist/cli.js +146091 -88862
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/templates/middleware/middleware-d1-beta.d.ts +0 -3
- package/templates/middleware/middleware-d1-beta.ts +0 -244
- package/templates/middleware/middleware-multiworker-dev.d.ts +0 -4
- package/templates/middleware/middleware-multiworker-dev.ts +0 -59
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import worker from "__ENTRY_POINT__";
|
|
15
|
-
|
|
16
|
-
// We need to preserve all of the exports from the worker
|
|
1
|
+
// This loads all middlewares exposed on the middleware object and then starts
|
|
2
|
+
// the invocation chain. The big idea is that we can add these to the middleware
|
|
3
|
+
// export dynamically through wrangler, or we can potentially let users directly
|
|
4
|
+
// add them as a sort of "plugin" system.
|
|
5
|
+
|
|
6
|
+
import ENTRY from "__ENTRY_POINT__";
|
|
7
|
+
import { __facade_invoke__, __facade_register__, Dispatcher } from "./common";
|
|
8
|
+
import type {
|
|
9
|
+
WithMiddleware,
|
|
10
|
+
WorkerEntrypointConstructor,
|
|
11
|
+
} from "__ENTRY_POINT__";
|
|
12
|
+
|
|
13
|
+
// Preserve all the exports from the worker
|
|
17
14
|
export * from "__ENTRY_POINT__";
|
|
18
15
|
|
|
19
16
|
class __Facade_ScheduledController__ implements ScheduledController {
|
|
20
|
-
#noRetry: ScheduledController["noRetry"];
|
|
17
|
+
readonly #noRetry: ScheduledController["noRetry"];
|
|
21
18
|
|
|
22
19
|
constructor(
|
|
23
20
|
readonly scheduledTime: number,
|
|
@@ -36,71 +33,33 @@ class __Facade_ScheduledController__ implements ScheduledController {
|
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
35
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
function getMaskedEnv(rawEnv: unknown) {
|
|
50
|
-
let env = rawEnv as Record<string, unknown>;
|
|
51
|
-
if (worker.envWrappers && worker.envWrappers.length > 0) {
|
|
52
|
-
for (const wrapFn of worker.envWrappers) {
|
|
53
|
-
env = wrapFn(env);
|
|
54
|
-
}
|
|
36
|
+
function wrapExportedHandler(
|
|
37
|
+
worker: WithMiddleware<ExportedHandler>
|
|
38
|
+
): ExportedHandler {
|
|
39
|
+
// If we don't have any middleware defined, just return the handler as is
|
|
40
|
+
if (worker.middleware === undefined || worker.middleware.length === 0) {
|
|
41
|
+
return worker;
|
|
42
|
+
}
|
|
43
|
+
// Otherwise, register all middleware once
|
|
44
|
+
for (const middleware of worker.middleware) {
|
|
45
|
+
__facade_register__(middleware);
|
|
55
46
|
}
|
|
56
|
-
return env;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* This type is here to cause a type error if a new export handler is added to
|
|
61
|
-
* `ExportHandler` without it being included in the `facade` below.
|
|
62
|
-
*/
|
|
63
|
-
type MissingExportHandlers = Omit<
|
|
64
|
-
Required<ExportedHandler>,
|
|
65
|
-
"tail" | "trace" | "scheduled" | "queue" | "test" | "email" | "fetch"
|
|
66
|
-
>;
|
|
67
|
-
|
|
68
|
-
let registeredMiddleware = false;
|
|
69
|
-
|
|
70
|
-
const facade: ExportedHandler<unknown> & MissingExportHandlers = {
|
|
71
|
-
...(worker.tail && {
|
|
72
|
-
tail: maskHandlerEnv(worker.tail),
|
|
73
|
-
}),
|
|
74
|
-
...(worker.trace && {
|
|
75
|
-
trace: maskHandlerEnv(worker.trace),
|
|
76
|
-
}),
|
|
77
|
-
...(worker.scheduled && {
|
|
78
|
-
scheduled: maskHandlerEnv(worker.scheduled),
|
|
79
|
-
}),
|
|
80
|
-
...(worker.queue && {
|
|
81
|
-
queue: maskHandlerEnv(worker.queue),
|
|
82
|
-
}),
|
|
83
|
-
...(worker.test && {
|
|
84
|
-
test: maskHandlerEnv(worker.test),
|
|
85
|
-
}),
|
|
86
|
-
...(worker.email && {
|
|
87
|
-
email: maskHandlerEnv(worker.email),
|
|
88
|
-
}),
|
|
89
47
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
}
|
|
48
|
+
const fetchDispatcher: ExportedHandlerFetchHandler = function (
|
|
49
|
+
request,
|
|
50
|
+
env,
|
|
51
|
+
ctx
|
|
52
|
+
) {
|
|
53
|
+
if (worker.fetch === undefined) {
|
|
54
|
+
throw new Error("Handler does not export a fetch() function.");
|
|
55
|
+
}
|
|
56
|
+
return worker.fetch(request, env, ctx);
|
|
57
|
+
};
|
|
102
58
|
|
|
103
|
-
|
|
59
|
+
return {
|
|
60
|
+
...worker,
|
|
61
|
+
fetch(request, env, ctx) {
|
|
62
|
+
const dispatcher: Dispatcher = function (type, init) {
|
|
104
63
|
if (type === "scheduled" && worker.scheduled !== undefined) {
|
|
105
64
|
const controller = new __Facade_ScheduledController__(
|
|
106
65
|
Date.now(),
|
|
@@ -110,28 +69,65 @@ const facade: ExportedHandler<unknown> & MissingExportHandlers = {
|
|
|
110
69
|
return worker.scheduled(controller, env, ctx);
|
|
111
70
|
}
|
|
112
71
|
};
|
|
72
|
+
return __facade_invoke__(request, env, ctx, dispatcher, fetchDispatcher);
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function wrapWorkerEntrypoint(
|
|
78
|
+
klass: WithMiddleware<WorkerEntrypointConstructor>
|
|
79
|
+
): WorkerEntrypointConstructor {
|
|
80
|
+
// If we don't have any middleware defined, just return the handler as is
|
|
81
|
+
if (klass.middleware === undefined || klass.middleware.length === 0) {
|
|
82
|
+
return klass;
|
|
83
|
+
}
|
|
84
|
+
// Otherwise, register all middleware once
|
|
85
|
+
for (const middleware of klass.middleware) {
|
|
86
|
+
__facade_register__(middleware);
|
|
87
|
+
}
|
|
113
88
|
|
|
89
|
+
// `extend`ing `klass` here so other RPC methods remain callable
|
|
90
|
+
return class extends klass {
|
|
91
|
+
#fetchDispatcher: ExportedHandlerFetchHandler<Record<string, unknown>> = (
|
|
92
|
+
request,
|
|
93
|
+
env,
|
|
94
|
+
ctx
|
|
95
|
+
) => {
|
|
96
|
+
this.env = env;
|
|
97
|
+
this.ctx = ctx;
|
|
98
|
+
if (super.fetch === undefined) {
|
|
99
|
+
throw new Error("Entrypoint class does not define a fetch() function.");
|
|
100
|
+
}
|
|
101
|
+
return super.fetch(request);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
#dispatcher: Dispatcher = (type, init) => {
|
|
105
|
+
if (type === "scheduled" && super.scheduled !== undefined) {
|
|
106
|
+
const controller = new __Facade_ScheduledController__(
|
|
107
|
+
Date.now(),
|
|
108
|
+
init.cron ?? "",
|
|
109
|
+
() => {}
|
|
110
|
+
);
|
|
111
|
+
return super.scheduled(controller);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
fetch(request: Request<unknown, IncomingRequestCfProperties>) {
|
|
114
116
|
return __facade_invoke__(
|
|
115
117
|
request,
|
|
116
|
-
env,
|
|
117
|
-
ctx,
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
this.env,
|
|
119
|
+
this.ctx,
|
|
120
|
+
this.#dispatcher,
|
|
121
|
+
this.#fetchDispatcher
|
|
120
122
|
);
|
|
121
|
-
} else {
|
|
122
|
-
// We didn't have any middleware so we can skip the invocation chain,
|
|
123
|
-
// and just call the fetch handler directly
|
|
124
|
-
|
|
125
|
-
// We "don't care" if this is undefined as we want to have the same behavior
|
|
126
|
-
// as if the worker completely bypassed middleware.
|
|
127
|
-
return __facade_modules_fetch__(request, env, ctx);
|
|
128
123
|
}
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
type HandlerFn<D, R> = (data: D, env: unknown, ctx: ExecutionContext) => R;
|
|
133
|
-
function maskHandlerEnv<D, R>(handler: HandlerFn<D, R>): HandlerFn<D, R> {
|
|
134
|
-
return (data, env, ctx) => handler(data, getMaskedEnv(env), ctx);
|
|
124
|
+
};
|
|
135
125
|
}
|
|
136
126
|
|
|
137
|
-
|
|
127
|
+
let WRAPPED_ENTRY: ExportedHandler | WorkerEntrypointConstructor | undefined;
|
|
128
|
+
if (typeof ENTRY === "object") {
|
|
129
|
+
WRAPPED_ENTRY = wrapExportedHandler(ENTRY);
|
|
130
|
+
} else if (typeof ENTRY === "function") {
|
|
131
|
+
WRAPPED_ENTRY = wrapWorkerEntrypoint(ENTRY);
|
|
132
|
+
}
|
|
133
|
+
export default WRAPPED_ENTRY;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
+
__facade_invoke__,
|
|
3
|
+
__facade_register__,
|
|
4
|
+
__facade_registerInternal__,
|
|
2
5
|
Awaitable,
|
|
3
6
|
Dispatcher,
|
|
4
7
|
IncomingRequest,
|
|
5
8
|
Middleware,
|
|
6
|
-
__facade_invoke__,
|
|
7
|
-
__facade_register__,
|
|
8
|
-
__facade_registerInternal__,
|
|
9
9
|
} from "./common";
|
|
10
|
+
|
|
10
11
|
export { __facade_register__, __facade_registerInternal__ };
|
|
11
12
|
|
|
12
13
|
// Miniflare 2's `EventTarget` follows the spec and doesn't allow exceptions to
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Middleware } from "./common";
|
|
2
|
+
|
|
3
|
+
const drainBody: Middleware = async (request, env, _ctx, middlewareCtx) => {
|
|
4
|
+
try {
|
|
5
|
+
return await middlewareCtx.next(request, env);
|
|
6
|
+
} finally {
|
|
7
|
+
try {
|
|
8
|
+
if (request.body !== null && !request.bodyUsed) {
|
|
9
|
+
const reader = request.body.getReader();
|
|
10
|
+
while (!(await reader.read()).done) {}
|
|
11
|
+
}
|
|
12
|
+
} catch (e) {
|
|
13
|
+
console.error("Failed to drain the unused request body.", e);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default drainBody;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/// <reference path="middleware-serve-static-assets.d.ts"/>
|
|
2
2
|
|
|
3
|
+
import manifest from "__STATIC_CONTENT_MANIFEST";
|
|
3
4
|
import {
|
|
4
5
|
getAssetFromKV,
|
|
5
|
-
NotFoundError,
|
|
6
6
|
MethodNotAllowedError,
|
|
7
|
+
NotFoundError,
|
|
7
8
|
serveSinglePageApp,
|
|
8
9
|
} from "@cloudflare/kv-asset-handler";
|
|
10
|
+
import { cacheControl, spaMode } from "config:middleware/serve-static-assets";
|
|
11
|
+
import type { Middleware } from "./common";
|
|
9
12
|
import type { Options } from "@cloudflare/kv-asset-handler";
|
|
10
|
-
import { spaMode, cacheControl } from "config:middleware/serve-static-assets";
|
|
11
13
|
import type * as kvAssetHandler from "@cloudflare/kv-asset-handler";
|
|
12
|
-
import manifest from "__STATIC_CONTENT_MANIFEST";
|
|
13
|
-
const ASSET_MANIFEST = JSON.parse(manifest);
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
const ASSET_MANIFEST = JSON.parse(manifest);
|
|
16
16
|
|
|
17
17
|
const staticAssets: Middleware = async (request, env, _ctx, middlewareCtx) => {
|
|
18
18
|
let options: Partial<Options> = {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// @ts-ignore entry point will get replaced
|
|
2
2
|
import worker from "__ENTRY_POINT__";
|
|
3
|
+
import { isRoutingRuleMatch } from "./pages-dev-util";
|
|
4
|
+
|
|
3
5
|
// @ts-ignore entry point will get replaced
|
|
4
6
|
export * from "__ENTRY_POINT__";
|
|
5
|
-
import { isRoutingRuleMatch } from "./pages-dev-util";
|
|
6
7
|
|
|
7
8
|
// @ts-ignore routes are injected
|
|
8
9
|
const routes = __ROUTES__;
|