wrangler 0.0.0-e5d3690 → 0.0.0-e5dbedd78
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 +49 -26
- package/bin/wrangler.js +88 -31
- package/config-schema.json +2278 -0
- package/kv-asset-handler.js +1 -0
- package/package.json +146 -92
- package/templates/__tests__/pages-dev-util.test.ts +128 -0
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/checked-fetch.js +30 -0
- package/templates/facade.d.ts +19 -0
- package/templates/gitignore +170 -0
- package/templates/init-tests/test-jest-new-worker.js +23 -0
- package/templates/init-tests/test-vitest-new-worker.js +24 -0
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/common.ts +67 -0
- package/templates/middleware/loader-modules.ts +134 -0
- package/templates/middleware/loader-sw.ts +229 -0
- package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
- package/templates/middleware/middleware-mock-analytics-engine.d.ts +3 -0
- package/templates/middleware/middleware-mock-analytics-engine.ts +30 -0
- package/templates/middleware/middleware-patch-console-prefix.d.ts +3 -0
- package/templates/middleware/middleware-patch-console-prefix.ts +21 -0
- package/templates/middleware/middleware-pretty-error.ts +40 -0
- package/templates/middleware/middleware-scheduled.ts +29 -0
- package/templates/modules-watch-stub.js +4 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.js +15 -0
- package/templates/new-worker.ts +33 -0
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-dev-pipeline.ts +33 -0
- package/templates/pages-dev-util.ts +55 -0
- package/templates/pages-shim.ts +9 -0
- package/templates/pages-template-plugin.ts +190 -0
- package/templates/pages-template-worker.ts +198 -0
- package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
- package/templates/startDevWorker/ProxyWorker.ts +336 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +22 -0
- package/templates/tsconfig.json +15 -0
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/InspectorProxyWorker.js +460 -0
- package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
- package/wrangler-dist/ProxyWorker.js +238 -0
- package/wrangler-dist/ProxyWorker.js.map +6 -0
- package/wrangler-dist/cli.d.ts +26693 -0
- package/wrangler-dist/cli.js +149006 -119006
- package/import_meta_url.js +0 -3
- package/miniflare-config-stubs/.env.empty +0 -0
- package/miniflare-config-stubs/package.empty.json +0 -1
- package/miniflare-config-stubs/wrangler.empty.toml +0 -0
- package/pages/functions/buildWorker.ts +0 -62
- package/pages/functions/filepath-routing.test.ts +0 -39
- package/pages/functions/filepath-routing.ts +0 -228
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -158
- package/pages/functions/template-worker.ts +0 -136
- package/src/__tests__/clipboardy-mock.js +0 -4
- package/src/__tests__/dev.test.tsx +0 -67
- package/src/__tests__/index.test.ts +0 -289
- package/src/__tests__/jest.setup.ts +0 -22
- package/src/__tests__/kv.test.ts +0 -1199
- package/src/__tests__/mock-cfetch.ts +0 -173
- package/src/__tests__/mock-dialogs.ts +0 -65
- package/src/__tests__/publish.test.ts +0 -672
- package/src/__tests__/run-in-tmp.ts +0 -19
- package/src/__tests__/run-wrangler.ts +0 -32
- package/src/__tests__/whoami.test.tsx +0 -130
- package/src/api/form_data.ts +0 -131
- package/src/api/preview.ts +0 -128
- package/src/api/worker.ts +0 -155
- package/src/cfetch/index.ts +0 -110
- package/src/cfetch/internal.ts +0 -71
- package/src/cli.ts +0 -9
- package/src/config.ts +0 -646
- package/src/dev.tsx +0 -779
- package/src/dialogs.tsx +0 -77
- package/src/index.tsx +0 -1975
- package/src/inspect.ts +0 -543
- package/src/kv.tsx +0 -276
- package/src/module-collection.ts +0 -64
- package/src/pages.tsx +0 -1040
- package/src/proxy.ts +0 -302
- package/src/publish.ts +0 -382
- package/src/sites.tsx +0 -243
- package/src/tail.tsx +0 -73
- package/src/user.tsx +0 -1019
- package/src/whoami.tsx +0 -69
- package/static-asset-facade.js +0 -47
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
- package/wrangler-dist/cli.js.map +0 -7
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import type { RequestInit } from "node-fetch";
|
|
2
|
-
import { URLSearchParams } from "node:url";
|
|
3
|
-
import { pathToRegexp } from "path-to-regexp";
|
|
4
|
-
import { CF_API_BASE_URL } from "../cfetch";
|
|
5
|
-
import type { FetchResult } from "../cfetch";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The signature of the function that will handle a mock request.
|
|
9
|
-
*/
|
|
10
|
-
export type MockHandler<ResponseType> = (
|
|
11
|
-
uri: RegExpExecArray,
|
|
12
|
-
init: RequestInit,
|
|
13
|
-
queryParams: URLSearchParams
|
|
14
|
-
) => ResponseType;
|
|
15
|
-
|
|
16
|
-
type RemoveMockFn = () => void;
|
|
17
|
-
|
|
18
|
-
interface MockFetch<ResponseType> {
|
|
19
|
-
regexp: RegExp;
|
|
20
|
-
method: string | undefined;
|
|
21
|
-
handler: MockHandler<ResponseType>;
|
|
22
|
-
}
|
|
23
|
-
const mocks: MockFetch<unknown>[] = [];
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* The mock implementation of `cfApi.fetch()`.
|
|
27
|
-
*
|
|
28
|
-
* This function will attempt to match the given request to one of the mock handlers configured by calls to `setMock`.
|
|
29
|
-
*
|
|
30
|
-
* Once found the handler will be used to generate a mock response.
|
|
31
|
-
*/
|
|
32
|
-
export async function mockFetchInternal(
|
|
33
|
-
resource: string,
|
|
34
|
-
init: RequestInit = {},
|
|
35
|
-
queryParams: URLSearchParams = new URLSearchParams()
|
|
36
|
-
) {
|
|
37
|
-
for (const { regexp, method, handler } of mocks) {
|
|
38
|
-
const resourcePath = new URL(resource, CF_API_BASE_URL).pathname;
|
|
39
|
-
const uri = regexp.exec(resourcePath);
|
|
40
|
-
// Do the resource path and (if specified) the HTTP method match?
|
|
41
|
-
if (uri !== null && (!method || method === (init.method ?? "GET"))) {
|
|
42
|
-
// The `resource` regular expression will extract the labelled groups from the URL.
|
|
43
|
-
// These are passed through to the `handler` call, to allow it to do additional checks or behaviour.
|
|
44
|
-
return handler(uri, init, queryParams); // TODO: should we have some kind of fallthrough system? we'll see.
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
throw new Error(
|
|
48
|
-
`no mocks found for ${init.method ?? "any HTTP"} request to ${resource}`
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Specify an expected resource path that is to be handled, resulting in a raw JSON response.
|
|
54
|
-
*
|
|
55
|
-
* @param resource The path of the resource to be matched.
|
|
56
|
-
* This can include wildcards whose value will be passed to the `handler`.
|
|
57
|
-
* @param handler The function that will generate the mock response for this request.
|
|
58
|
-
*/
|
|
59
|
-
export function setMockRawResponse<ResponseType>(
|
|
60
|
-
resource: string,
|
|
61
|
-
handler: MockHandler<ResponseType>
|
|
62
|
-
): RemoveMockFn;
|
|
63
|
-
/**
|
|
64
|
-
* Specify an expected resource path that is to be handled, resulting in a raw JSON response.
|
|
65
|
-
*
|
|
66
|
-
* @param resource The path of the resource to be matched.
|
|
67
|
-
* This can include wildcards whose value will be passed to the `handler`.
|
|
68
|
-
* @param method The HTTP method (e.g. GET, POST, etc) that the request must have to match this mock handler.
|
|
69
|
-
* @param handler The function that will generate the mock response for this request.
|
|
70
|
-
*/
|
|
71
|
-
export function setMockRawResponse<ResponseType>(
|
|
72
|
-
resource: string,
|
|
73
|
-
method: string,
|
|
74
|
-
handler: MockHandler<ResponseType>
|
|
75
|
-
): RemoveMockFn;
|
|
76
|
-
/**
|
|
77
|
-
* Specify an expected resource path that is to be handled, resulting in a raw JSON response.
|
|
78
|
-
*/
|
|
79
|
-
export function setMockRawResponse<ResponseType>(
|
|
80
|
-
resource: string,
|
|
81
|
-
...args: [string, MockHandler<ResponseType>] | [MockHandler<ResponseType>]
|
|
82
|
-
): RemoveMockFn {
|
|
83
|
-
const handler = args.pop() as MockHandler<ResponseType>;
|
|
84
|
-
const method = args.pop() as string;
|
|
85
|
-
const mock = {
|
|
86
|
-
resource,
|
|
87
|
-
method,
|
|
88
|
-
handler,
|
|
89
|
-
regexp: pathToRegexp(resource),
|
|
90
|
-
};
|
|
91
|
-
mocks.push(mock);
|
|
92
|
-
return () => {
|
|
93
|
-
const mockIndex = mocks.indexOf(mock);
|
|
94
|
-
if (mockIndex !== -1) {
|
|
95
|
-
mocks.splice(mockIndex, 1);
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Specify an expected resource path that is to be handled, resulting in a `FetchRequest`.
|
|
102
|
-
*
|
|
103
|
-
* The mock `handler` should return the `result`, which will then be wrapped in a `FetchRequest` object.
|
|
104
|
-
*
|
|
105
|
-
* @param resource The path of the resource to be matched.
|
|
106
|
-
* This can include wildcards whose value will be passed to the `handler`.
|
|
107
|
-
* @param handler The function that will generate the mock response for this request.
|
|
108
|
-
*/
|
|
109
|
-
export function setMockResponse<ResponseType>(
|
|
110
|
-
resource: string,
|
|
111
|
-
handler: MockHandler<ResponseType>
|
|
112
|
-
): RemoveMockFn;
|
|
113
|
-
/**
|
|
114
|
-
* Specify an expected resource path that is to be handled, resulting in a FetchRequest..
|
|
115
|
-
*
|
|
116
|
-
* @param resource The path of the resource to be matched.
|
|
117
|
-
* This can include wildcards whose value will be passed to the `handler`.
|
|
118
|
-
* @param method The HTTP method (e.g. GET, POST, etc) that the request must have to match this mock handler.
|
|
119
|
-
* @param handler The function that will generate the mock response for this request.
|
|
120
|
-
*/
|
|
121
|
-
export function setMockResponse<ResponseType>(
|
|
122
|
-
resource: string,
|
|
123
|
-
method: string,
|
|
124
|
-
handler: MockHandler<ResponseType>
|
|
125
|
-
): RemoveMockFn;
|
|
126
|
-
/**
|
|
127
|
-
* Specify an expected resource path that is to be handled, resulting in a FetchRequest.
|
|
128
|
-
*/
|
|
129
|
-
export function setMockResponse<ResponseType>(
|
|
130
|
-
resource: string,
|
|
131
|
-
...args: [string, MockHandler<ResponseType>] | [MockHandler<ResponseType>]
|
|
132
|
-
): RemoveMockFn {
|
|
133
|
-
const handler = args.pop() as MockHandler<ResponseType>;
|
|
134
|
-
const method = args.pop() as string;
|
|
135
|
-
return setMockRawResponse(resource, method, (...handlerArgs) =>
|
|
136
|
-
createFetchResult(handler(...handlerArgs))
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* A helper to make it easier to create `FetchResult` objects in tests.
|
|
142
|
-
*/
|
|
143
|
-
export function createFetchResult<ResponseType>(
|
|
144
|
-
result: ResponseType,
|
|
145
|
-
success = true,
|
|
146
|
-
errors = [],
|
|
147
|
-
messages = [],
|
|
148
|
-
result_info?: unknown
|
|
149
|
-
): FetchResult<ResponseType> {
|
|
150
|
-
return result_info
|
|
151
|
-
? {
|
|
152
|
-
result,
|
|
153
|
-
success,
|
|
154
|
-
errors,
|
|
155
|
-
messages,
|
|
156
|
-
result_info,
|
|
157
|
-
}
|
|
158
|
-
: {
|
|
159
|
-
result,
|
|
160
|
-
success,
|
|
161
|
-
errors,
|
|
162
|
-
messages,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Remove all the configured mock handlers.
|
|
168
|
-
*
|
|
169
|
-
* This should be called in an `afterEach()` block to ensure that mock handlers do not leak between tests.
|
|
170
|
-
*/
|
|
171
|
-
export function unsetAllMocks() {
|
|
172
|
-
mocks.length = 0;
|
|
173
|
-
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { confirm, prompt } from "../dialogs";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* The expected values for a confirmation request.
|
|
5
|
-
*/
|
|
6
|
-
export interface ConfirmExpectation {
|
|
7
|
-
/** The text expected to be seen in the confirmation dialog. */
|
|
8
|
-
text: string;
|
|
9
|
-
/** The mock response send back from the confirmation dialog. */
|
|
10
|
-
result: boolean;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Mock the implementation of `confirm()` that will respond with configured results
|
|
15
|
-
* for configured confirmation text messages.
|
|
16
|
-
*
|
|
17
|
-
* If there is a call to `confirm()` that does not match any of the expectations
|
|
18
|
-
* then an error is thrown.
|
|
19
|
-
*/
|
|
20
|
-
export function mockConfirm(...expectations: ConfirmExpectation[]) {
|
|
21
|
-
(confirm as jest.Mock).mockImplementation((text: string) => {
|
|
22
|
-
for (const { text: expectedText, result } of expectations) {
|
|
23
|
-
if (text === expectedText) {
|
|
24
|
-
return Promise.resolve(result);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
throw new Error(`Unexpected confirmation message: ${text}`);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* The expected values for a prompt request.
|
|
33
|
-
*/
|
|
34
|
-
export interface PromptExpectation {
|
|
35
|
-
/** The text expected to be seen in the prompt dialog. */
|
|
36
|
-
text: string;
|
|
37
|
-
/** The type of the prompt. */
|
|
38
|
-
type: "text" | "password";
|
|
39
|
-
/** The mock response send back from the prompt dialog. */
|
|
40
|
-
result: string;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Mock the implementation of `prompt()` that will respond with configured results
|
|
45
|
-
* for configured prompt text messages.
|
|
46
|
-
*
|
|
47
|
-
* If there is a call to `prompt()` that does not match any of the expectations
|
|
48
|
-
* then an error is thrown.
|
|
49
|
-
*/
|
|
50
|
-
export function mockPrompt(...expectations: PromptExpectation[]) {
|
|
51
|
-
(prompt as jest.Mock).mockImplementation(
|
|
52
|
-
(text: string, type: "text" | "password") => {
|
|
53
|
-
for (const {
|
|
54
|
-
text: expectedText,
|
|
55
|
-
type: expectedType,
|
|
56
|
-
result,
|
|
57
|
-
} of expectations) {
|
|
58
|
-
if (text === expectedText && type == expectedType) {
|
|
59
|
-
return Promise.resolve(result);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
throw new Error(`Unexpected confirmation message: ${text}`);
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
}
|