wrangler 0.0.0-e1c615f → 0.0.0-e3cab74
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/package.json +28 -13
- package/pages/functions/buildWorker.ts +6 -1
- package/pages/functions/filepath-routing.test.ts +112 -28
- package/pages/functions/filepath-routing.ts +88 -131
- package/pages/functions/routes.ts +11 -18
- package/pages/functions/template-worker.ts +21 -28
- package/src/__tests__/configuration.test.ts +2185 -0
- package/src/__tests__/dev.test.tsx +56 -9
- package/src/__tests__/guess-worker-format.test.ts +66 -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 +30 -0
- package/src/__tests__/helpers/mock-bin.ts +36 -0
- package/src/__tests__/{mock-cfetch.ts → helpers/mock-cfetch.ts} +53 -17
- package/src/__tests__/helpers/mock-console.ts +62 -0
- package/src/__tests__/{mock-dialogs.ts → helpers/mock-dialogs.ts} +1 -1
- package/src/__tests__/helpers/mock-kv.ts +40 -0
- package/src/__tests__/helpers/mock-user.ts +27 -0
- package/src/__tests__/helpers/mock-web-socket.ts +29 -0
- package/src/__tests__/helpers/run-in-tmp.ts +29 -0
- package/src/__tests__/helpers/run-wrangler.ts +16 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
- package/src/__tests__/index.test.ts +655 -76
- package/src/__tests__/jest.setup.ts +37 -2
- package/src/__tests__/kv.test.ts +441 -398
- package/src/__tests__/logout.test.ts +50 -0
- package/src/__tests__/package-manager.test.ts +206 -0
- package/src/__tests__/parse.test.ts +322 -0
- package/src/__tests__/publish.test.ts +2406 -0
- package/src/__tests__/r2.test.ts +198 -0
- package/src/__tests__/secret.test.ts +326 -0
- package/src/__tests__/sentry.test.ts +146 -0
- package/src/__tests__/tail.test.ts +564 -0
- package/src/__tests__/whoami.test.tsx +86 -0
- package/src/api/form_data.ts +112 -26
- package/src/api/preview.ts +34 -15
- package/src/api/worker.ts +58 -27
- package/src/bundle.ts +133 -0
- package/src/cfetch/index.ts +21 -19
- package/src/cfetch/internal.ts +85 -21
- package/src/cli.ts +10 -0
- package/src/config/README.md +107 -0
- package/src/config/config.ts +265 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +305 -0
- package/src/config/index.ts +52 -0
- package/src/config/validation-helpers.ts +370 -0
- package/src/config/validation.ts +1017 -0
- package/src/dev.tsx +455 -368
- package/src/dialogs.tsx +2 -2
- package/src/entry.ts +57 -0
- package/src/environment-variables.ts +33 -0
- package/src/guess-worker-format.ts +68 -0
- package/src/index.tsx +1044 -646
- package/src/inspect.ts +609 -0
- package/src/kv.tsx +47 -39
- package/src/module-collection.ts +142 -36
- package/src/open-in-browser.ts +13 -0
- package/src/package-manager.ts +126 -0
- package/src/pages.tsx +139 -62
- package/src/parse.ts +183 -0
- package/src/paths.ts +26 -0
- package/src/proxy.ts +350 -77
- package/src/publish.ts +307 -289
- package/src/r2.ts +50 -0
- package/src/reporting.ts +115 -0
- package/src/sites.tsx +183 -56
- 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 +137 -110
- package/src/whoami.tsx +69 -0
- 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 +127861 -111486
- 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/inspect.ts +0 -430
- package/src/config.ts +0 -131
- package/src/tail.tsx +0 -73
package/src/cfetch/internal.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import fetch from "
|
|
2
|
-
import
|
|
1
|
+
import { fetch } from "undici";
|
|
2
|
+
import { getEnvironmentVariableFactory } from "../environment-variables";
|
|
3
|
+
import { ParseError, parseJSON } from "../parse";
|
|
3
4
|
import { getAPIToken, loginOrRefreshIfRequired } from "../user";
|
|
5
|
+
import type { URLSearchParams } from "node:url";
|
|
6
|
+
import type { RequestInit, HeadersInit } from "undici";
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Get the URL to use to access the Cloudflare API.
|
|
10
|
+
*/
|
|
11
|
+
export const getCloudflareAPIBaseURL = getEnvironmentVariableFactory({
|
|
12
|
+
variableName: "CLOUDFLARE_API_BASE_URL",
|
|
13
|
+
deprecatedName: "CF_API_BASE_URL",
|
|
14
|
+
defaultValue: "https://api.cloudflare.com/client/v4",
|
|
15
|
+
});
|
|
7
16
|
|
|
8
17
|
/**
|
|
9
18
|
* Make a fetch request to the Cloudflare API.
|
|
@@ -25,19 +34,45 @@ export async function fetchInternal<ResponseType>(
|
|
|
25
34
|
addAuthorizationHeader(headers, apiToken);
|
|
26
35
|
|
|
27
36
|
const queryString = queryParams ? `?${queryParams.toString()}` : "";
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
37
|
+
const method = init.method ?? "GET";
|
|
38
|
+
const response = await fetch(
|
|
39
|
+
`${getCloudflareAPIBaseURL()}${resource}${queryString}`,
|
|
40
|
+
{
|
|
41
|
+
method,
|
|
42
|
+
...init,
|
|
43
|
+
headers,
|
|
44
|
+
}
|
|
45
|
+
);
|
|
46
|
+
const jsonText = await response.text();
|
|
47
|
+
try {
|
|
48
|
+
return parseJSON(jsonText) as ResponseType;
|
|
49
|
+
} catch (err) {
|
|
50
|
+
throw new ParseError({
|
|
51
|
+
text: "Received a malformed response from the API",
|
|
52
|
+
notes: [
|
|
53
|
+
{
|
|
54
|
+
text: truncate(jsonText, 100),
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
text: `${method} ${resource} -> ${response.status} ${response.statusText}`,
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
33
63
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
`Failed to fetch ${resource} - ${response.status}: ${response.statusText}`
|
|
39
|
-
);
|
|
64
|
+
function truncate(text: string, maxLength: number): string {
|
|
65
|
+
const { length } = text;
|
|
66
|
+
if (length <= maxLength) {
|
|
67
|
+
return text;
|
|
40
68
|
}
|
|
69
|
+
return `${text.substring(0, maxLength)}... (length = ${length})`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function cloneHeaders(
|
|
73
|
+
headers: HeadersInit | undefined
|
|
74
|
+
): Record<string, string> {
|
|
75
|
+
return { ...headers };
|
|
41
76
|
}
|
|
42
77
|
|
|
43
78
|
async function requireLoggedIn(): Promise<void> {
|
|
@@ -55,15 +90,44 @@ function requireApiToken(): string {
|
|
|
55
90
|
return apiToken;
|
|
56
91
|
}
|
|
57
92
|
|
|
58
|
-
function
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (headers["Authorization"]) {
|
|
93
|
+
function addAuthorizationHeader(
|
|
94
|
+
headers: Record<string, string>,
|
|
95
|
+
apiToken: string
|
|
96
|
+
): void {
|
|
97
|
+
if ("Authorization" in headers) {
|
|
64
98
|
throw new Error(
|
|
65
99
|
"The request already specifies an authorisation header - cannot add a new one."
|
|
66
100
|
);
|
|
67
101
|
}
|
|
68
102
|
headers["Authorization"] = `Bearer ${apiToken}`;
|
|
69
103
|
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* The implementation for fetching a kv value from the cloudflare API.
|
|
107
|
+
* We special-case this one call, because it's the only API call that
|
|
108
|
+
* doesn't return json. We inline the implementation and try not to share
|
|
109
|
+
* any code with the other calls. We should push back on any new APIs that
|
|
110
|
+
* try to introduce non-"standard" response structures.
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
export async function fetchKVGetValue(
|
|
114
|
+
accountId: string,
|
|
115
|
+
namespaceId: string,
|
|
116
|
+
key: string
|
|
117
|
+
): Promise<string> {
|
|
118
|
+
await requireLoggedIn();
|
|
119
|
+
const apiToken = requireApiToken();
|
|
120
|
+
const headers = { Authorization: `Bearer ${apiToken}` };
|
|
121
|
+
const resource = `${getCloudflareAPIBaseURL()}/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${key}`;
|
|
122
|
+
const response = await fetch(resource, {
|
|
123
|
+
method: "GET",
|
|
124
|
+
headers,
|
|
125
|
+
});
|
|
126
|
+
if (response.ok) {
|
|
127
|
+
return await response.text();
|
|
128
|
+
} else {
|
|
129
|
+
throw new Error(
|
|
130
|
+
`Failed to fetch ${resource} - ${response.status}: ${response.statusText});`
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
}
|
package/src/cli.ts
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
+
import process from "process";
|
|
1
2
|
import { hideBin } from "yargs/helpers";
|
|
3
|
+
import { reportError, initReporting } from "./reporting";
|
|
2
4
|
import { main } from ".";
|
|
3
5
|
|
|
6
|
+
try {
|
|
7
|
+
initReporting();
|
|
8
|
+
} catch (error) {}
|
|
9
|
+
|
|
10
|
+
process.on("uncaughtExceptionMonitor", async (err, origin) => {
|
|
11
|
+
await reportError(err, origin);
|
|
12
|
+
});
|
|
13
|
+
|
|
4
14
|
main(hideBin(process.argv)).catch(() => {
|
|
5
15
|
// The logging of any error that was thrown from `main()` is handled in the `yargs.fail()` handler.
|
|
6
16
|
// Here we just want to ensure that the process exits with a non-zero code.
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# Configuration validation
|
|
2
|
+
|
|
3
|
+
The files in this directory define and validate the configuration that is read from a `wrangler.toml` file.
|
|
4
|
+
|
|
5
|
+
The configuration for a Worker is complicated since we can define different "environments", and each environment can have its own configuration.
|
|
6
|
+
There is a default ("top-level") environment and then named environments that provide environment specific configuration.
|
|
7
|
+
|
|
8
|
+
This is further complicated by the fact that there are three kinds of environment configuration:
|
|
9
|
+
|
|
10
|
+
- **non-overridable**: these values are defined once in the top-level configuration, apply to all environments and cannot be overridden by an environment.
|
|
11
|
+
- **inheritable**: these values can be defined at the top-level but can also be overridden by environment specific values.
|
|
12
|
+
Named environments do not need to provide their own values, in which case they inherit the value from the top-level.
|
|
13
|
+
- **non-inheritable**: these values must be explicitly defined in each environment if they are defined at the top-level.
|
|
14
|
+
Named environments do not inherit such configuration and must provide their own values.
|
|
15
|
+
|
|
16
|
+
All configuration values in `wrangler.toml` are optional and will receive a default value if not defined.
|
|
17
|
+
|
|
18
|
+
## Types
|
|
19
|
+
|
|
20
|
+
### Environment
|
|
21
|
+
|
|
22
|
+
The fields that can be defined within the `env` containers are defined in the [`Environment`](./environment.ts) type.
|
|
23
|
+
This includes the `EnvironmentInheritable` and `EnvironmentNonInheritable` fields.
|
|
24
|
+
|
|
25
|
+
### Config
|
|
26
|
+
|
|
27
|
+
The "non-overridable" types are defined in the [`ConfigFields`](./config.ts) type.
|
|
28
|
+
Notably this also contains a property called `env` which is the container for the named environment configuration.
|
|
29
|
+
|
|
30
|
+
The `Config` type is the overall configuration, which consists of the `ConfigFields` and also an `Environment`.
|
|
31
|
+
In this case the `Environment`, here, corresponds to the top level environment.
|
|
32
|
+
The fields in `Config` and `Environment` are not generally optional and so you can expect they have been filled with suitable inherited or default values.
|
|
33
|
+
These types should be used when you are working with fields that should be passed to commands.
|
|
34
|
+
|
|
35
|
+
### RawConfig
|
|
36
|
+
|
|
37
|
+
The `RawConfig` type is a version of `Config`, where all the fields are optional.
|
|
38
|
+
The `RawConfig` type also includes `DeprecatedConfigFields` and extends and contains the `RawEnvironment` type,
|
|
39
|
+
which is a version of `Environment` where all the fields are optional.
|
|
40
|
+
These optional fields map to the actual fields found in the `wrangler.toml`.
|
|
41
|
+
These types should be used when you are working with raw configuration that is read or will be written to a `wrangler.toml`.
|
|
42
|
+
|
|
43
|
+
## Validation
|
|
44
|
+
|
|
45
|
+
Validation is triggered by passing a `RawConfig` object to the `normalizeAndValidateConfig()` function.
|
|
46
|
+
This function will return:
|
|
47
|
+
|
|
48
|
+
- a `Config` object, where all the fields have suitable valid values
|
|
49
|
+
- a `Diagnostics` object, which contains any errors or warnings from the validation process
|
|
50
|
+
|
|
51
|
+
The field values may have been parsed directly from the `RawConfig`, inherited into a named environment from the top-level environment, or given a default value.
|
|
52
|
+
Generally, if there are any warnings they should be presented to the user via `console.warn()` messages,
|
|
53
|
+
and if there are any errors then an `Error` should be thrown describing these errors.
|
|
54
|
+
|
|
55
|
+
The `Diagnostics` object is hierarchical: each `Diagnostics` instance can contain a collection of child `Diagnostics` instance.
|
|
56
|
+
When checking for or rendering warnings and errors, the `Diagnostics` class will automatically traverse down to all its children.
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
The [high level API](./index.ts) for configuration processing consists of the `findWranglerToml()` and `readConfig()` functions.
|
|
61
|
+
|
|
62
|
+
### readConfig()
|
|
63
|
+
|
|
64
|
+
The `readConfig()` function will find the nearest `wrangler.toml` file, load and parse it, then validate and normalize the values into a `Config` object.
|
|
65
|
+
If there are validation errors then it will throw a suitable error.
|
|
66
|
+
|
|
67
|
+
## Changing configuration
|
|
68
|
+
|
|
69
|
+
### Add a new configuration field
|
|
70
|
+
|
|
71
|
+
When a new field needs to be added to the `wrangler.toml` configuration you will need to add to the types and validation code in this directory.
|
|
72
|
+
|
|
73
|
+
Here are some steps that you should consider when doing this:
|
|
74
|
+
|
|
75
|
+
- add the new field to one of the interface:
|
|
76
|
+
- if the field is not overridable in an environment then add it to the `ConfigFields` interface.
|
|
77
|
+
- if the field can be inherited and overridden in a named environment then add it to the `EnvironmentInheritable` interface.
|
|
78
|
+
- if the field cannot be inherited and must be specified in each named environment then add it to the `EnvironmentNonInheritable` interface.
|
|
79
|
+
- if the field is experimental then add a call to the `experimental()` function:
|
|
80
|
+
- if the field is now in the `ConfigDeprecated` interface then add the call to the `normalizeAndValidateConfig()` function.
|
|
81
|
+
- if the field is now in the `EnvironmentDeprecated` interface then add the call to the `normalizeAndValidateEnvironment()` function.
|
|
82
|
+
- add validation and normalization to the interface
|
|
83
|
+
- if the field is in `ConfigFields` then add validation calls to `normalizeAndValidateConfig()` and assign the normalized value to the appropriate property in the `config` object.
|
|
84
|
+
- if the field is in `EnvironmentInheritable` then call `inheritable()` in `normalizeAndValidateEnvironment()` and assign the normalized value to the appropriate property in the `environment` object.
|
|
85
|
+
- if the field is in `EnvironmentNonInheritable` then call `notInheritable()` in `normalizeAndValidateEnvironment()` and assign the normalized value to the appropriate property in the `environment` object.
|
|
86
|
+
- update the tests in `configuration.test.ts`
|
|
87
|
+
- add to the `"should use defaults for empty configuration"` test to prove the correct default value is assigned
|
|
88
|
+
- if the field is in `ConfigFields` add tests to the `"top-level non-environment configuration"` block to check the validation and normalization of values
|
|
89
|
+
- if the field is in `EnvironmentInheritable` or `EnvironmentNonInheritable`
|
|
90
|
+
- add tests to the `"top-level environment configuration"` block to check the validation and normalization of values
|
|
91
|
+
- add tests to the `"named environment configuration"` block to check the inheritance of values
|
|
92
|
+
|
|
93
|
+
### Remove a configuration field
|
|
94
|
+
|
|
95
|
+
We should not just remove a field from use, since users would not know that this field is no longer needed, nor how to migrate to any new usage.
|
|
96
|
+
Instead we should first deprecate it, and then then remove it in a future major release.
|
|
97
|
+
|
|
98
|
+
- move the field to a deprecation interface:
|
|
99
|
+
- if the field was originally in `ConfigFields` then move it to the `ConfigDeprecated` interface.
|
|
100
|
+
- if the field was originally in either `EnvironmentInheritable` or `EnvironmentNonInheritable` then move it to the `EnvironmentDeprecatedInterface`.
|
|
101
|
+
- remove the validation for the field
|
|
102
|
+
- the TypeScript compiler should indicate where there is now an unknown field, so that you can remove its validation and normalization from the code base.
|
|
103
|
+
- add a deprecation warning by calling `deprecated()`
|
|
104
|
+
- if the field is now in the `ConfigDeprecated` interface then add the call to the `normalizeAndValidateConfig()` function.
|
|
105
|
+
- if the field is now in the `EnvironmentDeprecated` interface then add the call to the `normalizeAndValidateEnvironment()` function.
|
|
106
|
+
- update the tests in `configuration.test.ts`
|
|
107
|
+
- Find tests where the field is mentioned and either remove them (e.g. validation) or update to show the deprecation message.
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import type { Environment, RawEnvironment } from "./environment";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This is the static type definition for the configuration object.
|
|
5
|
+
*
|
|
6
|
+
* It reflects the configuration that you can write in wrangler.toml,
|
|
7
|
+
* and optionally augment with arguments passed directly to wrangler.
|
|
8
|
+
*
|
|
9
|
+
* For more information about the configuration object, see the
|
|
10
|
+
* documentation at https://developers.cloudflare.com/workers/cli-wrangler/configuration
|
|
11
|
+
*
|
|
12
|
+
* Notes:
|
|
13
|
+
*
|
|
14
|
+
* - Fields that are only specified in `ConfigFields` and not `Environment` can only appear
|
|
15
|
+
* in the top level config and should not appear in any environments.
|
|
16
|
+
* - All top level fields in config and environments are optional in the wrangler.toml file.
|
|
17
|
+
*
|
|
18
|
+
* Legend for the annotations:
|
|
19
|
+
*
|
|
20
|
+
* - `@breaking`: the deprecation/optionality is a breaking change from wrangler 1.
|
|
21
|
+
* - `@todo`: there's more work to be done (with details attached).
|
|
22
|
+
*/
|
|
23
|
+
export type Config = ConfigFields<Environment> & Environment;
|
|
24
|
+
|
|
25
|
+
export type RawConfig = Partial<ConfigFields<RawEnvironment>> &
|
|
26
|
+
RawEnvironment &
|
|
27
|
+
DeprecatedConfigFields;
|
|
28
|
+
|
|
29
|
+
export interface ConfigFields<Env extends RawEnvironment> {
|
|
30
|
+
configPath: string | undefined;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The entrypoint/path to the JavaScript file that will be executed.
|
|
34
|
+
*/
|
|
35
|
+
main: string | undefined;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A boolean to enable "legacy" style wrangler environments (from wrangler 1).
|
|
39
|
+
* These have been superseded by Services, but there may be projects that won't
|
|
40
|
+
* (or can't) use them. If you're using a legacy environment, you can set this
|
|
41
|
+
* to `true` to enable it.
|
|
42
|
+
*/
|
|
43
|
+
legacy_env: boolean;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The `env` section defines overrides for the configuration for different environments.
|
|
47
|
+
*
|
|
48
|
+
* All environment fields can be specified at the top level of the config indicating the default environment settings.
|
|
49
|
+
*
|
|
50
|
+
* - Some fields are inherited and overridable in each environment.
|
|
51
|
+
* - But some are not inherited and must be explicitly specified in every environment, if they are specified at the top level.
|
|
52
|
+
*
|
|
53
|
+
* For more information, see the documentation at https://developers.cloudflare.com/workers/cli-wrangler/configuration#environments
|
|
54
|
+
*
|
|
55
|
+
* @default `{}`
|
|
56
|
+
*/
|
|
57
|
+
env: {
|
|
58
|
+
[envName: string]: Env;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Options to configure the development server that your worker will use.
|
|
63
|
+
*
|
|
64
|
+
* @default `{}`
|
|
65
|
+
*/
|
|
66
|
+
dev: {
|
|
67
|
+
/**
|
|
68
|
+
* IP address for the local dev server to listen on,
|
|
69
|
+
*
|
|
70
|
+
* @default `127.0.0.1`
|
|
71
|
+
* @todo this needs to be implemented
|
|
72
|
+
*/
|
|
73
|
+
ip?: string;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Port for the local dev server to listen on
|
|
77
|
+
*
|
|
78
|
+
* @default `8787`
|
|
79
|
+
*/
|
|
80
|
+
port?: number;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Protocol that local wrangler dev server listens to requests on.
|
|
84
|
+
*
|
|
85
|
+
* @default `http`
|
|
86
|
+
* @todo this needs to be implemented
|
|
87
|
+
*/
|
|
88
|
+
local_protocol?: string;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Protocol that wrangler dev forwards requests on
|
|
92
|
+
*
|
|
93
|
+
* @default `https`
|
|
94
|
+
* @todo this needs to be implemented
|
|
95
|
+
*/
|
|
96
|
+
upstream_protocol?: string;
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* A list of migrations that should be uploaded with your Worker.
|
|
101
|
+
*
|
|
102
|
+
* These define changes in your Durable Object declarations.
|
|
103
|
+
*
|
|
104
|
+
* More details at https://developers.cloudflare.com/workers/learning/using-durable-objects#configuring-durable-object-classes-with-migrations
|
|
105
|
+
*
|
|
106
|
+
* @default `[]`
|
|
107
|
+
*/
|
|
108
|
+
migrations: {
|
|
109
|
+
/** A unique identifier for this migration. */
|
|
110
|
+
tag: string;
|
|
111
|
+
/** The new Durable Objects being defined. */
|
|
112
|
+
new_classes?: string[];
|
|
113
|
+
/** The Durable Objects being renamed. */
|
|
114
|
+
renamed_classes?: {
|
|
115
|
+
from: string;
|
|
116
|
+
to: string;
|
|
117
|
+
}[];
|
|
118
|
+
/** The Durable Objects being removed. */
|
|
119
|
+
deleted_classes?: string[];
|
|
120
|
+
}[];
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* The definition of a Worker Site, a feature that lets you upload
|
|
124
|
+
* static assets with your Worker.
|
|
125
|
+
*
|
|
126
|
+
* More details at https://developers.cloudflare.com/workers/platform/sites
|
|
127
|
+
*/
|
|
128
|
+
site:
|
|
129
|
+
| {
|
|
130
|
+
/**
|
|
131
|
+
* The directory containing your static assets.
|
|
132
|
+
*
|
|
133
|
+
* It must be a path relative to your wrangler.toml file.
|
|
134
|
+
* Example: bucket = "./public"
|
|
135
|
+
*
|
|
136
|
+
* If there is a `site` field then it must contain this `bucket` field.
|
|
137
|
+
*/
|
|
138
|
+
bucket: string;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The location of your Worker script.
|
|
142
|
+
*
|
|
143
|
+
* @deprecated DO NOT use this (it's a holdover from wrangler 1.x). Either use the top level `main` field, or pass the path to your entry file as a command line argument.
|
|
144
|
+
* @breaking
|
|
145
|
+
*/
|
|
146
|
+
"entry-point"?: string;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* An exclusive list of .gitignore-style patterns that match file
|
|
150
|
+
* or directory names from your bucket location. Only matched
|
|
151
|
+
* items will be uploaded. Example: include = ["upload_dir"]
|
|
152
|
+
*
|
|
153
|
+
* @optional
|
|
154
|
+
* @default `[]`
|
|
155
|
+
*/
|
|
156
|
+
include?: string[];
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* A list of .gitignore-style patterns that match files or
|
|
160
|
+
* directories in your bucket that should be excluded from
|
|
161
|
+
* uploads. Example: exclude = ["ignore_dir"]
|
|
162
|
+
*
|
|
163
|
+
* @optional
|
|
164
|
+
* @default `[]`
|
|
165
|
+
*/
|
|
166
|
+
exclude?: string[];
|
|
167
|
+
}
|
|
168
|
+
| undefined;
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* A list of wasm modules that your worker should be bound to. This is
|
|
172
|
+
* the "legacy" way of binding to a wasm module. ES module workers should
|
|
173
|
+
* do proper module imports.
|
|
174
|
+
*/
|
|
175
|
+
wasm_modules:
|
|
176
|
+
| {
|
|
177
|
+
[key: string]: string;
|
|
178
|
+
}
|
|
179
|
+
| undefined;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* A list of text files that your worker should be bound to. This is
|
|
183
|
+
* the "legacy" way of binding to a text file. ES module workers should
|
|
184
|
+
* do proper module imports.
|
|
185
|
+
*/
|
|
186
|
+
text_blobs:
|
|
187
|
+
| {
|
|
188
|
+
[key: string]: string;
|
|
189
|
+
}
|
|
190
|
+
| undefined;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Configures a custom build step to be run by Wrangler when building your Worker.
|
|
194
|
+
*
|
|
195
|
+
* Refer to the [custom builds documentation](https://developers.cloudflare.com/workers/cli-wrangler/configuration#build)
|
|
196
|
+
* for more details.
|
|
197
|
+
*
|
|
198
|
+
* @default {}
|
|
199
|
+
*/
|
|
200
|
+
build: {
|
|
201
|
+
/** 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. */
|
|
202
|
+
command?: string;
|
|
203
|
+
/** The directory in which the command is executed. */
|
|
204
|
+
cwd?: string;
|
|
205
|
+
/** The directory to watch for changes while using wrangler dev, defaults to the current working directory */
|
|
206
|
+
watch_dir?: string;
|
|
207
|
+
/** Deprecated field previously used to configure the build and upload of the script. */
|
|
208
|
+
upload?: DeprecatedUpload;
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export interface DeprecatedConfigFields {
|
|
213
|
+
/**
|
|
214
|
+
* The project "type". A holdover from wrangler 1.x.
|
|
215
|
+
* Valid values were "webpack", "javascript", and "rust".
|
|
216
|
+
*
|
|
217
|
+
* @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.
|
|
218
|
+
* @breaking
|
|
219
|
+
*/
|
|
220
|
+
type?: "webpack" | "javascript" | "rust";
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Path to the webpack config to use when building your worker.
|
|
224
|
+
* A holdover from wrangler 1.x, used with `type: "webpack"`.
|
|
225
|
+
*
|
|
226
|
+
* @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.
|
|
227
|
+
* @breaking
|
|
228
|
+
*/
|
|
229
|
+
webpack_config?: string;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Deprecated upload configuration.
|
|
234
|
+
*/
|
|
235
|
+
export interface DeprecatedUpload {
|
|
236
|
+
/**
|
|
237
|
+
* The format of the Worker script.
|
|
238
|
+
*
|
|
239
|
+
* @deprecated We infer the format automatically now.
|
|
240
|
+
*/
|
|
241
|
+
format?: "modules" | "service-worker";
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* The directory you wish to upload your worker from,
|
|
245
|
+
* relative to the wrangler.toml file.
|
|
246
|
+
*
|
|
247
|
+
* Defaults to the directory containing the wrangler.toml file.
|
|
248
|
+
*
|
|
249
|
+
* @deprecated
|
|
250
|
+
* @breaking In wrangler 1, this defaults to ./dist, whereas in wrangler 2 it defaults to ./
|
|
251
|
+
*/
|
|
252
|
+
dir?: string;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* The path to the Worker script, relative to `upload.dir`.
|
|
256
|
+
*
|
|
257
|
+
* @deprecated This will be replaced by a command line argument.
|
|
258
|
+
*/
|
|
259
|
+
main?: string;
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* @deprecated This is now defined at the top level `rules` field.
|
|
263
|
+
*/
|
|
264
|
+
rules?: Environment["rules"];
|
|
265
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostic errors and warnings.
|
|
3
|
+
*
|
|
4
|
+
* The structure is a tree, where each node can contain zero or more errors, warnings and child diagnostics objects.
|
|
5
|
+
* You can check whether the overall tree has errors or warnings, and you can render a string representation of the errors or warnings.
|
|
6
|
+
*/
|
|
7
|
+
export class Diagnostics {
|
|
8
|
+
errors: string[] = [];
|
|
9
|
+
warnings: string[] = [];
|
|
10
|
+
children: Diagnostics[] = [];
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Create a new Diagnostics object.
|
|
14
|
+
* @param description A general description of this collection of messages.
|
|
15
|
+
*/
|
|
16
|
+
constructor(public description: string) {}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Merge the given `diagnostics` into this as a child.
|
|
20
|
+
*/
|
|
21
|
+
addChild(diagnostics: Diagnostics): void {
|
|
22
|
+
if (diagnostics.hasErrors() || diagnostics.hasWarnings()) {
|
|
23
|
+
this.children.push(diagnostics);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Does this or any of its children have errors. */
|
|
28
|
+
hasErrors(): boolean {
|
|
29
|
+
if (this.errors.length > 0) {
|
|
30
|
+
return true;
|
|
31
|
+
} else {
|
|
32
|
+
return this.children.some((child) => child.hasErrors());
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Render the errors of this and all its children. */
|
|
37
|
+
renderErrors(): string {
|
|
38
|
+
return this.render("errors");
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Does this or any of its children have warnings. */
|
|
42
|
+
hasWarnings(): boolean {
|
|
43
|
+
if (this.warnings.length > 0) {
|
|
44
|
+
return true;
|
|
45
|
+
} else {
|
|
46
|
+
return this.children.some((child) => child.hasWarnings());
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Render the warnings of this and all its children. */
|
|
51
|
+
renderWarnings(): string {
|
|
52
|
+
return this.render("warnings");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private render(field: "errors" | "warnings"): string {
|
|
56
|
+
const hasMethod = field === "errors" ? "hasErrors" : "hasWarnings";
|
|
57
|
+
return indentText(
|
|
58
|
+
`${this.description}\n` +
|
|
59
|
+
// Output all the fields (errors or warnings) at this level
|
|
60
|
+
this[field].map((message) => `- ${indentText(message)}`).join("\n") +
|
|
61
|
+
// Output all the child diagnostics at the next level
|
|
62
|
+
this.children
|
|
63
|
+
.map((child) =>
|
|
64
|
+
child[hasMethod]() ? "\n- " + child.render(field) : ""
|
|
65
|
+
)
|
|
66
|
+
.filter((output) => output !== "")
|
|
67
|
+
.join("\n")
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Indent all the but the first line by two spaces. */
|
|
73
|
+
function indentText(str: string): string {
|
|
74
|
+
return str
|
|
75
|
+
.split("\n")
|
|
76
|
+
.map((line, index) =>
|
|
77
|
+
(index === 0 ? line : ` ${line}`).replace(/^\s*$/, "")
|
|
78
|
+
)
|
|
79
|
+
.join("\n");
|
|
80
|
+
}
|