wrangler 0.0.0-e6733a3 → 0.0.0-e6ada079
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.
Potentially problematic release.
This version of wrangler might be problematic. Click here for more details.
- package/README.md +47 -16
- package/bin/wrangler.js +94 -31
- package/config-schema.json +3100 -0
- package/kv-asset-handler.js +1 -0
- package/package.json +154 -82
- 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-pretty-error.ts +40 -0
- package/templates/middleware/middleware-scheduled.ts +15 -0
- package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
- package/templates/middleware/middleware-serve-static-assets.ts +56 -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 +32 -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 +334 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +22 -0
- package/templates/tsconfig.json +8 -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 +26391 -0
- package/wrangler-dist/cli.js +204293 -116652
- package/wrangler-dist/wasm-sync.wasm +0 -0
- 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 -221
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -158
- package/pages/functions/template-worker.ts +0 -144
- package/src/__tests__/clipboardy-mock.js +0 -4
- package/src/__tests__/dev.test.tsx +0 -66
- package/src/__tests__/index.test.ts +0 -287
- package/src/__tests__/jest.setup.ts +0 -22
- package/src/__tests__/kv.test.ts +0 -1098
- package/src/__tests__/mock-cfetch.ts +0 -171
- package/src/__tests__/mock-dialogs.ts +0 -65
- 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/api/preview.ts +0 -128
- package/src/api/worker.ts +0 -155
- package/src/cfetch/index.ts +0 -102
- package/src/cfetch/internal.ts +0 -69
- package/src/cli.ts +0 -9
- package/src/config.ts +0 -487
- package/src/dev.tsx +0 -771
- package/src/dialogs.tsx +0 -77
- package/src/index.tsx +0 -1974
- package/src/inspect.ts +0 -524
- package/src/kv.tsx +0 -267
- package/src/module-collection.ts +0 -64
- package/src/pages.tsx +0 -1031
- package/src/proxy.ts +0 -294
- package/src/publish.ts +0 -358
- package/src/sites.tsx +0 -114
- package/src/tail.tsx +0 -73
- package/src/user.tsx +0 -1025
- 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
package/src/cfetch/index.ts
DELETED
@@ -1,102 +0,0 @@
|
|
1
|
-
import type { RequestInit } from "node-fetch";
|
2
|
-
import { URLSearchParams } from "url";
|
3
|
-
import { fetchInternal } from "./internal";
|
4
|
-
|
5
|
-
// Check out https://api.cloudflare.com/ for API docs.
|
6
|
-
|
7
|
-
export { CF_API_BASE_URL } from "./internal";
|
8
|
-
|
9
|
-
export interface FetchError {
|
10
|
-
code: number;
|
11
|
-
message: string;
|
12
|
-
}
|
13
|
-
export interface FetchResult<ResponseType = unknown> {
|
14
|
-
success: boolean;
|
15
|
-
result: ResponseType;
|
16
|
-
errors: FetchError[];
|
17
|
-
messages: string[];
|
18
|
-
result_info?: unknown;
|
19
|
-
}
|
20
|
-
|
21
|
-
/**
|
22
|
-
* Make a fetch request for a raw JSON value.
|
23
|
-
*/
|
24
|
-
export async function fetchRaw<ResponseType>(
|
25
|
-
resource: string,
|
26
|
-
init: RequestInit = {},
|
27
|
-
queryParams?: URLSearchParams
|
28
|
-
): Promise<ResponseType> {
|
29
|
-
return fetchInternal<ResponseType>(resource, init, queryParams);
|
30
|
-
}
|
31
|
-
|
32
|
-
/**
|
33
|
-
* Make a fetch request, and extract the `result` from the JSON response.
|
34
|
-
*/
|
35
|
-
export async function fetchResult<ResponseType>(
|
36
|
-
resource: string,
|
37
|
-
init: RequestInit = {},
|
38
|
-
queryParams?: URLSearchParams
|
39
|
-
): Promise<ResponseType> {
|
40
|
-
const json = await fetchInternal<FetchResult<ResponseType>>(
|
41
|
-
resource,
|
42
|
-
init,
|
43
|
-
queryParams
|
44
|
-
);
|
45
|
-
if (json.success) {
|
46
|
-
return json.result;
|
47
|
-
} else {
|
48
|
-
throwFetchError(resource, json);
|
49
|
-
}
|
50
|
-
}
|
51
|
-
|
52
|
-
/**
|
53
|
-
* Make a fetch request for a list of values,
|
54
|
-
* extracting the `result` from the JSON response,
|
55
|
-
* and repeating the request if the results are paginated.
|
56
|
-
*/
|
57
|
-
export async function fetchListResult<ResponseType>(
|
58
|
-
resource: string,
|
59
|
-
init: RequestInit = {},
|
60
|
-
queryParams?: URLSearchParams
|
61
|
-
): Promise<ResponseType[]> {
|
62
|
-
const results: ResponseType[] = [];
|
63
|
-
let getMoreResults = true;
|
64
|
-
let cursor: string | undefined;
|
65
|
-
while (getMoreResults) {
|
66
|
-
if (cursor) {
|
67
|
-
queryParams = new URLSearchParams(queryParams);
|
68
|
-
queryParams.set("cursor", cursor);
|
69
|
-
}
|
70
|
-
const json = await fetchInternal<FetchResult<ResponseType[]>>(
|
71
|
-
resource,
|
72
|
-
init,
|
73
|
-
queryParams
|
74
|
-
);
|
75
|
-
if (json.success) {
|
76
|
-
results.push(...json.result);
|
77
|
-
if (hasCursor(json.result_info)) {
|
78
|
-
cursor = json.result_info?.cursor;
|
79
|
-
} else {
|
80
|
-
getMoreResults = false;
|
81
|
-
}
|
82
|
-
} else {
|
83
|
-
throwFetchError(resource, json);
|
84
|
-
}
|
85
|
-
}
|
86
|
-
return results;
|
87
|
-
}
|
88
|
-
|
89
|
-
function throwFetchError(
|
90
|
-
resource: string,
|
91
|
-
response: FetchResult<unknown>
|
92
|
-
): never {
|
93
|
-
response.messages.forEach((message) => console.warn(message));
|
94
|
-
const errors = response.errors
|
95
|
-
.map((error) => `${error.code}: ${error.message}`)
|
96
|
-
.join("\n");
|
97
|
-
throw new Error(`Failed to fetch ${resource} - ${errors}`);
|
98
|
-
}
|
99
|
-
|
100
|
-
function hasCursor(result_info: unknown): result_info is { cursor: string } {
|
101
|
-
return (result_info as { cursor } | undefined)?.cursor !== undefined;
|
102
|
-
}
|
package/src/cfetch/internal.ts
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
import fetch from "node-fetch";
|
2
|
-
import type { RequestInit, HeadersInit } from "node-fetch";
|
3
|
-
import { getAPIToken, loginOrRefreshIfRequired } from "../user";
|
4
|
-
|
5
|
-
export const CF_API_BASE_URL =
|
6
|
-
process.env.CF_API_BASE_URL || "https://api.cloudflare.com/client/v4";
|
7
|
-
|
8
|
-
/**
|
9
|
-
* Make a fetch request to the Cloudflare API.
|
10
|
-
*
|
11
|
-
* This function handles acquiring the API token and logging the caller in, as necessary.
|
12
|
-
*
|
13
|
-
* Check out https://api.cloudflare.com/ for API docs.
|
14
|
-
*
|
15
|
-
* This function should not be used directly, instead use the functions in `cfetch/index.ts`.
|
16
|
-
*/
|
17
|
-
export async function fetchInternal<ResponseType>(
|
18
|
-
resource: string,
|
19
|
-
init: RequestInit = {},
|
20
|
-
queryParams?: URLSearchParams
|
21
|
-
): Promise<ResponseType> {
|
22
|
-
await requireLoggedIn();
|
23
|
-
const apiToken = requireApiToken();
|
24
|
-
const headers = cloneHeaders(init.headers);
|
25
|
-
addAuthorizationHeader(headers, apiToken);
|
26
|
-
|
27
|
-
const queryString = queryParams ? `?${queryParams.toString()}` : "";
|
28
|
-
const response = await fetch(`${CF_API_BASE_URL}${resource}${queryString}`, {
|
29
|
-
method: "GET",
|
30
|
-
...init,
|
31
|
-
headers,
|
32
|
-
});
|
33
|
-
|
34
|
-
if (response.ok) {
|
35
|
-
return (await response.json()) as ResponseType;
|
36
|
-
} else {
|
37
|
-
throw new Error(
|
38
|
-
`Failed to fetch ${resource} - ${response.status}: ${response.statusText}`
|
39
|
-
);
|
40
|
-
}
|
41
|
-
}
|
42
|
-
|
43
|
-
async function requireLoggedIn(): Promise<void> {
|
44
|
-
const loggedIn = await loginOrRefreshIfRequired();
|
45
|
-
if (!loggedIn) {
|
46
|
-
throw new Error("Not logged in.");
|
47
|
-
}
|
48
|
-
}
|
49
|
-
|
50
|
-
function requireApiToken(): string {
|
51
|
-
const apiToken = getAPIToken();
|
52
|
-
if (!apiToken) {
|
53
|
-
throw new Error("No API token found.");
|
54
|
-
}
|
55
|
-
return apiToken;
|
56
|
-
}
|
57
|
-
|
58
|
-
function cloneHeaders(headers: HeadersInit): HeadersInit {
|
59
|
-
return { ...headers };
|
60
|
-
}
|
61
|
-
|
62
|
-
function addAuthorizationHeader(headers: HeadersInit, apiToken: string): void {
|
63
|
-
if (headers["Authorization"]) {
|
64
|
-
throw new Error(
|
65
|
-
"The request already specifies an authorisation header - cannot add a new one."
|
66
|
-
);
|
67
|
-
}
|
68
|
-
headers["Authorization"] = `Bearer ${apiToken}`;
|
69
|
-
}
|
package/src/cli.ts
DELETED
@@ -1,9 +0,0 @@
|
|
1
|
-
import { hideBin } from "yargs/helpers";
|
2
|
-
import { main } from ".";
|
3
|
-
|
4
|
-
main(hideBin(process.argv)).catch(() => {
|
5
|
-
// The logging of any error that was thrown from `main()` is handled in the `yargs.fail()` handler.
|
6
|
-
// Here we just want to ensure that the process exits with a non-zero code.
|
7
|
-
// We don't want to do this inside the `main()` function, since that would kill the process when running our tests.
|
8
|
-
process.exit(1);
|
9
|
-
});
|
package/src/config.ts
DELETED
@@ -1,487 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* This is the static type definition for the configuration object.
|
3
|
-
* It reflects the configuration that you can write in wrangler.toml,
|
4
|
-
* and optionally augment with arguments passed directly to wrangler.
|
5
|
-
* The type definition doesn't fully reflect the constraints applied
|
6
|
-
* to the configuration, but it is a good starting point. Later, we
|
7
|
-
* also defined a validator function that will validate the configuration
|
8
|
-
* with the same rules as the type definition, as well as the extra
|
9
|
-
* constraints. The type definition is good for asserting correctness
|
10
|
-
* in the wrangler codebase, whereas the validator function is useful
|
11
|
-
* for signalling errors in the configuration to a user of wrangler.
|
12
|
-
*
|
13
|
-
* For more information about the configuration object, see the
|
14
|
-
* documentation at https://developers.cloudflare.com/workers/cli-wrangler/configuration
|
15
|
-
*
|
16
|
-
* Legend for the annotations:
|
17
|
-
*
|
18
|
-
* *:optional means providing a value isn't mandatory
|
19
|
-
* *:deprecated means the field itself isn't necessary anymore in wrangler.toml
|
20
|
-
* *:breaking means the deprecation/optionality is a breaking change from wrangler 1
|
21
|
-
* *:todo means there's more work to be done (with details attached)
|
22
|
-
* *:inherited means the field is copied to all environments
|
23
|
-
*/
|
24
|
-
export type Config = {
|
25
|
-
/**
|
26
|
-
* The name of your worker. Alphanumeric + dashes only.
|
27
|
-
*
|
28
|
-
* @optional
|
29
|
-
* @inherited
|
30
|
-
*/
|
31
|
-
name?: string;
|
32
|
-
|
33
|
-
/**
|
34
|
-
* The entrypoint/path to the JavaScript file that will be executed.
|
35
|
-
*
|
36
|
-
* @optional
|
37
|
-
* @inherited
|
38
|
-
* @todo this needs to be implemented!
|
39
|
-
*/
|
40
|
-
entry?: string;
|
41
|
-
|
42
|
-
/**
|
43
|
-
* This is the ID of the account associated with your zone.
|
44
|
-
* You might have more than one account, so make sure to use
|
45
|
-
* the ID of the account associated with the zone/route you
|
46
|
-
* provide, if you provide one. It can also be specified through
|
47
|
-
* the CF_ACCOUNT_ID environment variable.
|
48
|
-
*
|
49
|
-
* @optional
|
50
|
-
* @inherited
|
51
|
-
*/
|
52
|
-
account_id?: string;
|
53
|
-
|
54
|
-
/**
|
55
|
-
* The project "type". A holdover from wrangler 1.x.
|
56
|
-
* Valid values were "webpack", "javascript", and "rust".
|
57
|
-
*
|
58
|
-
* @deprecated DO NOT USE THIS. Most common features now work out of the box with wrangler, including modules, jsx, typescript, etc. If you need anything more, use a custom build.
|
59
|
-
* @optional
|
60
|
-
* @inherited
|
61
|
-
* @breaking
|
62
|
-
*/
|
63
|
-
type?: "webpack" | "javascript" | "rust";
|
64
|
-
|
65
|
-
/**
|
66
|
-
* A date in the form yyyy-mm-dd, which will be used to determine
|
67
|
-
* which version of the Workers runtime is used. More details at
|
68
|
-
* https://developers.cloudflare.com/workers/platform/compatibility-dates
|
69
|
-
* @optional true for `dev`, false for `publish`
|
70
|
-
* @inherited
|
71
|
-
*/
|
72
|
-
compatibility_date?: string;
|
73
|
-
|
74
|
-
/**
|
75
|
-
* A list of flags that enable features from upcoming features of
|
76
|
-
* the Workers runtime, usually used together with compatibility_flags.
|
77
|
-
* More details at
|
78
|
-
* https://developers.cloudflare.com/workers/platform/compatibility-dates
|
79
|
-
*
|
80
|
-
* @optional
|
81
|
-
* @inherited
|
82
|
-
* @todo This could be an enum!
|
83
|
-
*/
|
84
|
-
compatibility_flags?: string[];
|
85
|
-
|
86
|
-
/**
|
87
|
-
* Whether we use <name>.<subdomain>.workers.dev to
|
88
|
-
* test and deploy your worker.
|
89
|
-
*
|
90
|
-
* @default `true` (This is a breaking change from wrangler 1)
|
91
|
-
* @optional
|
92
|
-
* @inherited
|
93
|
-
* @breaking
|
94
|
-
*/
|
95
|
-
workers_dev?: boolean;
|
96
|
-
|
97
|
-
/**
|
98
|
-
* The zone ID of the zone you want to deploy to. You can find this
|
99
|
-
* in your domain page on the dashboard.
|
100
|
-
*
|
101
|
-
* @deprecated This is unnecessary since we can deduce this from routes directly.
|
102
|
-
* @optional
|
103
|
-
* @inherited
|
104
|
-
*/
|
105
|
-
zone_id?: string;
|
106
|
-
|
107
|
-
/**
|
108
|
-
* A list of routes that your worker should be deployed to.
|
109
|
-
* Only one of `routes` or `route` is required.
|
110
|
-
*
|
111
|
-
* @optional false only when workers_dev is false, and there's no scheduled worker
|
112
|
-
* @inherited
|
113
|
-
*/
|
114
|
-
routes?: string[];
|
115
|
-
|
116
|
-
/**
|
117
|
-
* A route that your worker should be deployed to. Literally
|
118
|
-
* the same as routes, but only one.
|
119
|
-
* Only one of `routes` or `route` is required.
|
120
|
-
*
|
121
|
-
* @optional false only when workers_dev is false, and there's no scheduled worker
|
122
|
-
* @inherited
|
123
|
-
*/
|
124
|
-
route?: string;
|
125
|
-
|
126
|
-
/**
|
127
|
-
* Path to the webpack config to use when building your worker.
|
128
|
-
* A holdover from wrangler 1.x, used with `type: "webpack"`.
|
129
|
-
*
|
130
|
-
* @deprecated DO NOT USE THIS. Most common features now work out of the box with wrangler, including modules, jsx, typescript, etc. If you need anything more, use a custom build.
|
131
|
-
* @inherited
|
132
|
-
* @breaking
|
133
|
-
*/
|
134
|
-
webpack_config?: string;
|
135
|
-
|
136
|
-
/**
|
137
|
-
* The function to use to replace jsx syntax.
|
138
|
-
*
|
139
|
-
* @default `"React.createElement"`
|
140
|
-
* @optional
|
141
|
-
* @inherited
|
142
|
-
*/
|
143
|
-
jsx_factory?: string;
|
144
|
-
|
145
|
-
/**
|
146
|
-
* The function to use to replace jsx fragment syntax.
|
147
|
-
*
|
148
|
-
* @default `"React.Fragment"`
|
149
|
-
* @optional
|
150
|
-
* @inherited
|
151
|
-
*/
|
152
|
-
jsx_fragment?: string;
|
153
|
-
|
154
|
-
/**
|
155
|
-
* A map of environment variables to set when deploying your worker.
|
156
|
-
* Of note, they can only be strings. Which is unfortunate, really.
|
157
|
-
* (TODO: verify that they can only be strings?)
|
158
|
-
* NB: these are not inherited, and HAVE to be duplicated across all environments.
|
159
|
-
*
|
160
|
-
* @default `{}`
|
161
|
-
* @optional
|
162
|
-
* @inherited false
|
163
|
-
*/
|
164
|
-
vars?: { [key: string]: string };
|
165
|
-
|
166
|
-
/**
|
167
|
-
* A list of durable objects that your worker should be bound to.
|
168
|
-
* For more information about Durable Objects, see the documentation at
|
169
|
-
* https://developers.cloudflare.com/workers/learning/using-durable-objects
|
170
|
-
* NB: these are not inherited, and HAVE to be duplicated across all environments.
|
171
|
-
*
|
172
|
-
* @default `{ bindings: [] }`
|
173
|
-
* @optional
|
174
|
-
* @inherited false
|
175
|
-
*/
|
176
|
-
durable_objects?: {
|
177
|
-
bindings: {
|
178
|
-
/** The name of the binding used to refer to the Durable Object */
|
179
|
-
name: string;
|
180
|
-
/** The exported class name of the Durable Object */
|
181
|
-
class_name: string;
|
182
|
-
/** The script where the Durable Object is defined (if it's external to this worker) */
|
183
|
-
script_name?: string;
|
184
|
-
}[];
|
185
|
-
};
|
186
|
-
|
187
|
-
/**
|
188
|
-
* These specify any Workers KV Namespaces you want to
|
189
|
-
* access from inside your Worker. To learn more about KV Namespaces,
|
190
|
-
* see the documentation at https://developers.cloudflare.com/workers/learning/how-kv-works
|
191
|
-
* NB: these are not inherited, and HAVE to be duplicated across all environments.
|
192
|
-
*
|
193
|
-
* @default `[]`
|
194
|
-
* @optional
|
195
|
-
* @inherited false
|
196
|
-
*/
|
197
|
-
kv_namespaces?: {
|
198
|
-
/** The binding name used to refer to the KV Namespace */
|
199
|
-
binding: string;
|
200
|
-
/** The ID of the KV namespace */
|
201
|
-
id: string;
|
202
|
-
/** The ID of the KV namespace used during `wrangler dev` */
|
203
|
-
preview_id?: string;
|
204
|
-
}[];
|
205
|
-
|
206
|
-
/**
|
207
|
-
* A list of services that your worker should be bound to.
|
208
|
-
* NB: these are not inherited, and HAVE to be duplicated across all environments.
|
209
|
-
*
|
210
|
-
* @default `[]`
|
211
|
-
* @optional
|
212
|
-
* @inherited false
|
213
|
-
*/
|
214
|
-
experimental_services?: {
|
215
|
-
/** The binding name used to refer to the Service */
|
216
|
-
name: string;
|
217
|
-
/** The name of the Service being bound */
|
218
|
-
service: string;
|
219
|
-
/** The Service's environment */
|
220
|
-
environment: string;
|
221
|
-
}[];
|
222
|
-
|
223
|
-
/**
|
224
|
-
* A list of migrations that should be uploaded with your Worker.
|
225
|
-
* These define changes in your Durable Object declarations.
|
226
|
-
* More details at https://developers.cloudflare.com/workers/learning/using-durable-objects#configuring-durable-object-classes-with-migrations
|
227
|
-
* NB: these ARE inherited, and SHOULD NOT be duplicated across all environments.
|
228
|
-
*
|
229
|
-
* @default `[]`
|
230
|
-
* @optional
|
231
|
-
* @inherited true
|
232
|
-
*/
|
233
|
-
migrations?: {
|
234
|
-
/** A unique identifier for this migration. */
|
235
|
-
tag: string;
|
236
|
-
/** The new Durable Objects being defined. */
|
237
|
-
new_classes?: string[];
|
238
|
-
/** The Durable Objects being renamed. */
|
239
|
-
renamed_classes?: {
|
240
|
-
from: string;
|
241
|
-
to: string;
|
242
|
-
}[];
|
243
|
-
/** The Durable Objects being removed. */
|
244
|
-
deleted_classes?: string[];
|
245
|
-
}[];
|
246
|
-
|
247
|
-
/**
|
248
|
-
* The definition of a Worker Site, a feature that lets you upload
|
249
|
-
* static assets with your Worker.
|
250
|
-
* More details at https://developers.cloudflare.com/workers/platform/sites
|
251
|
-
* NB: This IS inherited, and SHOULD NOT be duplicated across all environments.
|
252
|
-
*
|
253
|
-
* @default `undefined`
|
254
|
-
* @optional
|
255
|
-
* @inherited true
|
256
|
-
*/
|
257
|
-
site?: {
|
258
|
-
/**
|
259
|
-
* The directory containing your static assets. It must be
|
260
|
-
* a path relative to your wrangler.toml file.
|
261
|
-
* Example: bucket = "./public"
|
262
|
-
*
|
263
|
-
* optional false
|
264
|
-
*/
|
265
|
-
bucket: string;
|
266
|
-
|
267
|
-
/**
|
268
|
-
* The location of your Worker script.
|
269
|
-
*
|
270
|
-
* @deprecated DO NOT use this (it's a holdover from wrangler 1.x). Either use the top level `entry` field, or pass the path to your entry file as a command line argument.
|
271
|
-
* @todo we should use a top level "entry" property instead
|
272
|
-
* @breaking
|
273
|
-
*/
|
274
|
-
"entry-point": string;
|
275
|
-
|
276
|
-
/**
|
277
|
-
* An exclusive list of .gitignore-style patterns that match file
|
278
|
-
* or directory names from your bucket location. Only matched
|
279
|
-
* items will be uploaded. Example: include = ["upload_dir"]
|
280
|
-
*
|
281
|
-
* @optional
|
282
|
-
* @default `[]`
|
283
|
-
* @todo this needs to be implemented!
|
284
|
-
*/
|
285
|
-
include?: string[];
|
286
|
-
|
287
|
-
/**
|
288
|
-
* A list of .gitignore-style patterns that match files or
|
289
|
-
* directories in your bucket that should be excluded from
|
290
|
-
* uploads. Example: exclude = ["ignore_dir"]
|
291
|
-
*
|
292
|
-
* @optional
|
293
|
-
* @default `[]`
|
294
|
-
* @todo this needs to be implemented!
|
295
|
-
*/
|
296
|
-
exclude?: string[];
|
297
|
-
};
|
298
|
-
|
299
|
-
/**
|
300
|
-
* "Cron" definitions to trigger a worker's "scheduled" function.
|
301
|
-
* Lets you call workers periodically, much like a cron job.
|
302
|
-
* More details here https://developers.cloudflare.com/workers/platform/cron-triggers
|
303
|
-
*
|
304
|
-
* @inherited
|
305
|
-
* @default `{ crons: [] }`
|
306
|
-
* @optional
|
307
|
-
* @todo can we use typescript for cron patterns?
|
308
|
-
*/
|
309
|
-
triggers?: { crons: string[] };
|
310
|
-
|
311
|
-
/**
|
312
|
-
* Options to configure the development server that your worker will use.
|
313
|
-
* NB: This is NOT inherited, and SHOULD NOT be duplicated across all environments.
|
314
|
-
*
|
315
|
-
* @default `{}`
|
316
|
-
* @optional
|
317
|
-
* @inherited false
|
318
|
-
*/
|
319
|
-
dev?: {
|
320
|
-
/**
|
321
|
-
* IP address for the local dev server to listen on,
|
322
|
-
*
|
323
|
-
* @default `127.0.0.1`
|
324
|
-
* @todo this needs to be implemented
|
325
|
-
*/
|
326
|
-
ip?: string;
|
327
|
-
|
328
|
-
/**
|
329
|
-
* Port for the local dev server to listen on
|
330
|
-
*
|
331
|
-
* @default `8787`
|
332
|
-
*/
|
333
|
-
port?: number;
|
334
|
-
|
335
|
-
/**
|
336
|
-
* Protocol that local wrangler dev server listens to requests on.
|
337
|
-
*
|
338
|
-
* @default `http`
|
339
|
-
* @todo this needs to be implemented
|
340
|
-
*/
|
341
|
-
local_protocol?: string;
|
342
|
-
|
343
|
-
/**
|
344
|
-
* Protocol that wrangler dev forwards requests on
|
345
|
-
*
|
346
|
-
* @default `https`
|
347
|
-
* @todo this needs to be implemented
|
348
|
-
*/
|
349
|
-
upstream_protocol?: string;
|
350
|
-
};
|
351
|
-
|
352
|
-
/**
|
353
|
-
* Specifies the Usage Model for your Worker. There are two options -
|
354
|
-
* [bundled](https://developers.cloudflare.com/workers/platform/limits#bundled-usage-model) and
|
355
|
-
* [unbound](https://developers.cloudflare.com/workers/platform/limits#unbound-usage-model).
|
356
|
-
* For newly created Workers, if the Usage Model is omitted
|
357
|
-
* it will be set to the [default Usage Model set on the account](https://dash.cloudflare.com/?account=workers/default-usage-model).
|
358
|
-
* For existing Workers, if the Usage Model is omitted, it will be
|
359
|
-
* set to the Usage Model configured in the dashboard for that Worker.
|
360
|
-
*/
|
361
|
-
usage_model?: undefined | "bundled" | "unbound";
|
362
|
-
|
363
|
-
/**
|
364
|
-
* Configures a custom build step to be run by Wrangler when
|
365
|
-
* building your Worker. Refer to the [custom builds documentation](https://developers.cloudflare.com/workers/cli-wrangler/configuration#build)
|
366
|
-
* for more details.
|
367
|
-
*
|
368
|
-
* @default `undefined`
|
369
|
-
* @optional
|
370
|
-
* @inherited false
|
371
|
-
*/
|
372
|
-
build?: {
|
373
|
-
/** The command used to build your Worker. On Linux and macOS, the command is executed in the `sh` shell and the `cmd` shell for Windows. The `&&` and `||` shell operators may be used. */
|
374
|
-
command?: string;
|
375
|
-
/** The directory in which the command is executed. */
|
376
|
-
cwd?: string;
|
377
|
-
/** The directory to watch for changes while using wrangler dev, defaults to the current working directory */
|
378
|
-
watch_dir?: string;
|
379
|
-
} & /**
|
380
|
-
* Much of the rest of this configuration isn't necessary anymore
|
381
|
-
* in wrangler2. We infer the format automatically, and we can pass
|
382
|
-
* the path to the script either in the CLI (or, @todo, as the top level
|
383
|
-
* `entry` property).
|
384
|
-
*/ (
|
385
|
-
| {
|
386
|
-
upload?: {
|
387
|
-
/**
|
388
|
-
* The format of the Worker script, must be "service-worker".
|
389
|
-
*
|
390
|
-
* @deprecated We infer the format automatically now.
|
391
|
-
*/
|
392
|
-
format: "service-worker";
|
393
|
-
|
394
|
-
/**
|
395
|
-
* The path to the Worker script. This should be replaced
|
396
|
-
* by the top level `entry' property.
|
397
|
-
*
|
398
|
-
* @deprecated This will be replaced by the top level `entry' property.
|
399
|
-
*/
|
400
|
-
main: string;
|
401
|
-
};
|
402
|
-
}
|
403
|
-
| {
|
404
|
-
/**
|
405
|
-
* When we use the module format, we only really
|
406
|
-
* need to specify the entry point. The format is deduced
|
407
|
-
* automatically in wrangler2.
|
408
|
-
*/
|
409
|
-
upload?: {
|
410
|
-
/**
|
411
|
-
* The format of the Worker script, must be "modules".
|
412
|
-
*
|
413
|
-
* @deprecated We infer the format automatically now.
|
414
|
-
*/
|
415
|
-
format: "modules";
|
416
|
-
|
417
|
-
/**
|
418
|
-
* The directory you wish to upload your modules from,
|
419
|
-
* defaults to the dist relative to the project root directory.
|
420
|
-
*
|
421
|
-
* @deprecated
|
422
|
-
* @breaking
|
423
|
-
*/
|
424
|
-
dir?: string;
|
425
|
-
|
426
|
-
/**
|
427
|
-
* The path to the Worker script. This should be replaced
|
428
|
-
* by the top level `entry' property.
|
429
|
-
*
|
430
|
-
* @deprecated This will be replaced by the top level `entry' property.
|
431
|
-
*/
|
432
|
-
main?: string;
|
433
|
-
|
434
|
-
/**
|
435
|
-
* An ordered list of rules that define which modules to import,
|
436
|
-
* and what type to import them as. You will need to specify rules
|
437
|
-
* to use Text, Data, and CompiledWasm modules, or when you wish to
|
438
|
-
* have a .js file be treated as an ESModule instead of CommonJS.
|
439
|
-
*
|
440
|
-
* @deprecated These are now inferred automatically for major file types, but you can still specify them manually.
|
441
|
-
* @todo this needs to be implemented!
|
442
|
-
* @breaking
|
443
|
-
*/
|
444
|
-
rules?: {
|
445
|
-
type: "ESModule" | "CommonJS" | "Text" | "Data" | "CompiledWasm";
|
446
|
-
globs: string[];
|
447
|
-
fallthrough?: boolean;
|
448
|
-
};
|
449
|
-
};
|
450
|
-
}
|
451
|
-
);
|
452
|
-
|
453
|
-
/**
|
454
|
-
* The `env` section defines overrides for the configuration for
|
455
|
-
* different environments. Most fields can be overridden, while
|
456
|
-
* some have to be specifically duplicated in every environment.
|
457
|
-
* For more information, see the documentation at https://developers.cloudflare.com/workers/cli-wrangler/configuration#environments
|
458
|
-
*/
|
459
|
-
env?: {
|
460
|
-
[envName: string]:
|
461
|
-
| undefined
|
462
|
-
| Omit<Config, "env" | "migrations" | "site" | "dev">;
|
463
|
-
};
|
464
|
-
};
|
465
|
-
|
466
|
-
type ValidationResults = (
|
467
|
-
| { key: string; info: string }
|
468
|
-
| { key: string; error: string }
|
469
|
-
| { key: string; warning: string }
|
470
|
-
)[];
|
471
|
-
|
472
|
-
/**
|
473
|
-
* We also define a validation function that manually validates
|
474
|
-
* every field in the configuration as per the type definitions,
|
475
|
-
* as well as extra constraints we apply to some fields, as well
|
476
|
-
* as some constraints on combinations of fields. This is useful for
|
477
|
-
* presenting errors and messages to the user. Eventually, we will
|
478
|
-
* combine this with some automatic config rewriting tools.
|
479
|
-
*
|
480
|
-
*/
|
481
|
-
export async function validateConfig(
|
482
|
-
_config: Partial<Config>
|
483
|
-
): Promise<ValidationResults> {
|
484
|
-
const results: ValidationResults = [];
|
485
|
-
|
486
|
-
return results;
|
487
|
-
}
|