wrangler 0.0.0-ece06ea → 0.0.0-ed4f2ef
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 +3 -3
- package/bin/wrangler.js +12 -3
- package/miniflare-dist/index.mjs +79 -0
- package/miniflare-dist/index.mjs.map +7 -0
- package/package.json +49 -22
- package/pages/functions/buildWorker.ts +62 -0
- package/pages/functions/filepath-routing.test.ts +223 -0
- package/pages/functions/filepath-routing.ts +181 -0
- package/pages/functions/identifiers.ts +78 -0
- package/pages/functions/routes.ts +151 -0
- package/pages/functions/template-worker.ts +130 -0
- package/src/__tests__/configuration.test.ts +2874 -0
- package/src/__tests__/dev.test.tsx +588 -0
- package/src/__tests__/guess-worker-format.test.ts +83 -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__/helpers/mock-cfetch.ts +207 -0
- package/src/__tests__/helpers/mock-console.ts +70 -0
- package/src/__tests__/helpers/mock-dialogs.ts +65 -0
- package/src/__tests__/helpers/mock-kv.ts +33 -0
- package/src/__tests__/helpers/mock-oauth-flow.ts +178 -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 +953 -119
- package/src/__tests__/jest.setup.ts +74 -0
- package/src/__tests__/kv.test.ts +1380 -0
- package/src/__tests__/package-manager.test.ts +206 -0
- package/src/__tests__/pages.test.ts +180 -0
- package/src/__tests__/parse.test.ts +322 -0
- package/src/__tests__/publish.test.ts +3946 -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 +638 -0
- package/src/__tests__/user.test.ts +83 -0
- package/src/__tests__/whoami.test.tsx +95 -0
- package/src/bundle.ts +155 -0
- package/src/cfetch/index.ts +104 -0
- package/src/cfetch/internal.ts +139 -0
- package/src/cli.ts +18 -7
- package/src/config/README.md +107 -0
- package/src/config/config.ts +229 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +371 -0
- package/src/config/index.ts +62 -0
- package/src/config/validation-helpers.ts +557 -0
- package/src/config/validation.ts +1240 -0
- package/src/create-worker-preview.ts +173 -0
- package/src/create-worker-upload-form.ts +240 -0
- package/src/dev/dev.tsx +413 -0
- package/src/dev/local.tsx +287 -0
- package/src/dev/remote.tsx +209 -0
- package/src/dev/use-esbuild.ts +109 -0
- package/src/dialogs.tsx +6 -14
- package/src/entry.ts +256 -0
- package/src/environment-variables.ts +33 -0
- package/src/errors.ts +11 -0
- package/src/https-options.ts +122 -0
- package/src/index.tsx +1503 -959
- package/src/inspect.ts +624 -0
- package/src/intl-polyfill.d.ts +139 -0
- package/src/kv.ts +319 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +38 -0
- package/src/module-collection.ts +257 -0
- package/src/open-in-browser.ts +25 -0
- package/src/package-manager.ts +126 -0
- package/src/pages.tsx +1074 -212
- package/src/parse.ts +183 -0
- package/src/paths.ts +26 -0
- package/src/proxy.ts +455 -0
- package/src/publish.ts +326 -295
- package/src/r2.ts +50 -0
- package/src/reporting.ts +131 -0
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +224 -59
- 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 +340 -203
- package/src/whoami.tsx +69 -0
- package/src/worker.ts +172 -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} +1 -1
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.js +136988 -131174
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/fixtures/init/.gitkeep +0 -0
- package/src/__tests__/mock-cfetch.js +0 -46
- package/src/api/form_data.ts +0 -158
- package/src/api/inspect.ts +0 -441
- package/src/api/preview.ts +0 -123
- package/src/api/worker.ts +0 -161
- package/src/cfetch.ts +0 -72
- package/src/config.ts +0 -124
- package/src/dev.tsx +0 -736
- package/src/kv.tsx +0 -211
- package/src/tail.tsx +0 -71
- package/src/util/fetch.ts +0 -74
|
@@ -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
|
+
The `Config` type is the overall configuration, which consists of the `ConfigFields` and also an `Environment`.
|
|
29
|
+
In this case the `Environment`, here, corresponds to the "currently active" environment. This is specified by the `--env` command line argument.
|
|
30
|
+
If there is no argument passed then the currently active environment is the "top-level" environment.
|
|
31
|
+
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.
|
|
32
|
+
These types should be used when you are working with fields that should be passed to commands.
|
|
33
|
+
|
|
34
|
+
### RawConfig
|
|
35
|
+
|
|
36
|
+
The `RawConfig` type is a version of `Config`, where all the fields are optional.
|
|
37
|
+
The `RawConfig` type includes `DeprecatedConfigFields` and `EnvironmentMap`.
|
|
38
|
+
It also extends the `RawEnvironment` type, which is a version of `Environment` where all the fields are optional.
|
|
39
|
+
These optional fields map to the actual fields found in the `wrangler.toml`.
|
|
40
|
+
These types should be used when you are working with raw configuration that is read or will be written to a `wrangler.toml`.
|
|
41
|
+
|
|
42
|
+
## Validation
|
|
43
|
+
|
|
44
|
+
Validation is triggered by passing a `RawConfig` object, and the active environment name, to the `normalizeAndValidateConfig()` function.
|
|
45
|
+
This function will return:
|
|
46
|
+
|
|
47
|
+
- a `Config` object, where all the fields have suitable valid values
|
|
48
|
+
- a `Diagnostics` object, which contains any errors or warnings from the validation process
|
|
49
|
+
|
|
50
|
+
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.
|
|
51
|
+
Generally, if there are any warnings they should be presented to the user via `console.warn()` messages,
|
|
52
|
+
and if there are any errors then an `Error` should be thrown describing these errors.
|
|
53
|
+
|
|
54
|
+
The `Diagnostics` object is hierarchical: each `Diagnostics` instance can contain a collection of child `Diagnostics` instance.
|
|
55
|
+
When checking for or rendering warnings and errors, the `Diagnostics` class will automatically traverse down to all its children.
|
|
56
|
+
|
|
57
|
+
## Usage
|
|
58
|
+
|
|
59
|
+
The [high level API](./index.ts) for configuration processing consists of the `findWranglerToml()` and `readConfig()` functions.
|
|
60
|
+
|
|
61
|
+
### readConfig()
|
|
62
|
+
|
|
63
|
+
The `readConfig()` function will find the nearest `wrangler.toml` file, load and parse it, then validate and normalize the values into a `Config` object.
|
|
64
|
+
Note that you should pass the current active environment name in as a parameter. The resulting `Config` object will contain only the fields appropriate to that environment.
|
|
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,229 @@
|
|
|
1
|
+
import type { Environment, RawEnvironment } from "./environment";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* This is the static type definition for the configuration object.
|
|
5
|
+
*
|
|
6
|
+
* It reflects a normalized and validated version of 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<DevConfig> & Environment;
|
|
24
|
+
|
|
25
|
+
export type RawConfig = Partial<ConfigFields<RawDevConfig>> &
|
|
26
|
+
RawEnvironment &
|
|
27
|
+
DeprecatedConfigFields &
|
|
28
|
+
EnvironmentMap;
|
|
29
|
+
|
|
30
|
+
export interface ConfigFields<Dev extends RawDevConfig> {
|
|
31
|
+
configPath: string | undefined;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A boolean to enable "legacy" style wrangler environments (from wrangler 1).
|
|
35
|
+
* These have been superseded by Services, but there may be projects that won't
|
|
36
|
+
* (or can't) use them. If you're using a legacy environment, you can set this
|
|
37
|
+
* to `true` to enable it.
|
|
38
|
+
*/
|
|
39
|
+
legacy_env: boolean;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Options to configure the development server that your worker will use.
|
|
43
|
+
*/
|
|
44
|
+
dev: Dev;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* A list of migrations that should be uploaded with your Worker.
|
|
48
|
+
*
|
|
49
|
+
* These define changes in your Durable Object declarations.
|
|
50
|
+
*
|
|
51
|
+
* More details at https://developers.cloudflare.com/workers/learning/using-durable-objects#configuring-durable-object-classes-with-migrations
|
|
52
|
+
*
|
|
53
|
+
* @default `[]`
|
|
54
|
+
*/
|
|
55
|
+
migrations: {
|
|
56
|
+
/** A unique identifier for this migration. */
|
|
57
|
+
tag: string;
|
|
58
|
+
/** The new Durable Objects being defined. */
|
|
59
|
+
new_classes?: string[];
|
|
60
|
+
/** The Durable Objects being renamed. */
|
|
61
|
+
renamed_classes?: {
|
|
62
|
+
from: string;
|
|
63
|
+
to: string;
|
|
64
|
+
}[];
|
|
65
|
+
/** The Durable Objects being removed. */
|
|
66
|
+
deleted_classes?: string[];
|
|
67
|
+
}[];
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* The definition of a Worker Site, a feature that lets you upload
|
|
71
|
+
* static assets with your Worker.
|
|
72
|
+
*
|
|
73
|
+
* More details at https://developers.cloudflare.com/workers/platform/sites
|
|
74
|
+
*/
|
|
75
|
+
site:
|
|
76
|
+
| {
|
|
77
|
+
/**
|
|
78
|
+
* The directory containing your static assets.
|
|
79
|
+
*
|
|
80
|
+
* It must be a path relative to your wrangler.toml file.
|
|
81
|
+
* Example: bucket = "./public"
|
|
82
|
+
*
|
|
83
|
+
* If there is a `site` field then it must contain this `bucket` field.
|
|
84
|
+
*/
|
|
85
|
+
bucket: string;
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The location of your Worker script.
|
|
89
|
+
*
|
|
90
|
+
* @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.
|
|
91
|
+
* @breaking
|
|
92
|
+
*/
|
|
93
|
+
"entry-point"?: string;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* An exclusive list of .gitignore-style patterns that match file
|
|
97
|
+
* or directory names from your bucket location. Only matched
|
|
98
|
+
* items will be uploaded. Example: include = ["upload_dir"]
|
|
99
|
+
*
|
|
100
|
+
* @optional
|
|
101
|
+
* @default `[]`
|
|
102
|
+
*/
|
|
103
|
+
include?: string[];
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* A list of .gitignore-style patterns that match files or
|
|
107
|
+
* directories in your bucket that should be excluded from
|
|
108
|
+
* uploads. Example: exclude = ["ignore_dir"]
|
|
109
|
+
*
|
|
110
|
+
* @optional
|
|
111
|
+
* @default `[]`
|
|
112
|
+
*/
|
|
113
|
+
exclude?: string[];
|
|
114
|
+
}
|
|
115
|
+
| undefined;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* A list of wasm modules that your worker should be bound to. This is
|
|
119
|
+
* the "legacy" way of binding to a wasm module. ES module workers should
|
|
120
|
+
* do proper module imports.
|
|
121
|
+
*/
|
|
122
|
+
wasm_modules:
|
|
123
|
+
| {
|
|
124
|
+
[key: string]: string;
|
|
125
|
+
}
|
|
126
|
+
| undefined;
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* A list of text files that your worker should be bound to. This is
|
|
130
|
+
* the "legacy" way of binding to a text file. ES module workers should
|
|
131
|
+
* do proper module imports.
|
|
132
|
+
*/
|
|
133
|
+
text_blobs:
|
|
134
|
+
| {
|
|
135
|
+
[key: string]: string;
|
|
136
|
+
}
|
|
137
|
+
| undefined;
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* A list of data files that your worker should be bound to. This is
|
|
141
|
+
* the "legacy" way of binding to a data file. ES module workers should
|
|
142
|
+
* do proper module imports.
|
|
143
|
+
*/
|
|
144
|
+
data_blobs:
|
|
145
|
+
| {
|
|
146
|
+
[key: string]: string;
|
|
147
|
+
}
|
|
148
|
+
| undefined;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface DevConfig {
|
|
152
|
+
/**
|
|
153
|
+
* IP address for the local dev server to listen on,
|
|
154
|
+
*
|
|
155
|
+
* @default `localhost`
|
|
156
|
+
* @todo this needs to be implemented
|
|
157
|
+
*/
|
|
158
|
+
ip: string;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Port for the local dev server to listen on
|
|
162
|
+
*
|
|
163
|
+
* @default `8787`
|
|
164
|
+
*/
|
|
165
|
+
port: number;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Protocol that local wrangler dev server listens to requests on.
|
|
169
|
+
*
|
|
170
|
+
* @default `http`
|
|
171
|
+
* @todo this needs to be implemented
|
|
172
|
+
*/
|
|
173
|
+
local_protocol: "http" | "https";
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Protocol that wrangler dev forwards requests on
|
|
177
|
+
*
|
|
178
|
+
* Setting this to `http` is not currently implemented.
|
|
179
|
+
* See https://github.com/cloudflare/wrangler2/issues/583
|
|
180
|
+
*
|
|
181
|
+
* @default `https`
|
|
182
|
+
*/
|
|
183
|
+
upstream_protocol: "https" | "http";
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Host to forward requests to, defaults to the zone of project
|
|
187
|
+
*/
|
|
188
|
+
host: string | undefined;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export type RawDevConfig = Partial<DevConfig>;
|
|
192
|
+
|
|
193
|
+
export interface DeprecatedConfigFields {
|
|
194
|
+
/**
|
|
195
|
+
* The project "type". A holdover from wrangler 1.x.
|
|
196
|
+
* Valid values were "webpack", "javascript", and "rust".
|
|
197
|
+
*
|
|
198
|
+
* @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.
|
|
199
|
+
* @breaking
|
|
200
|
+
*/
|
|
201
|
+
type?: "webpack" | "javascript" | "rust";
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Path to the webpack config to use when building your worker.
|
|
205
|
+
* A holdover from wrangler 1.x, used with `type: "webpack"`.
|
|
206
|
+
*
|
|
207
|
+
* @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.
|
|
208
|
+
* @breaking
|
|
209
|
+
*/
|
|
210
|
+
webpack_config?: string;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
interface EnvironmentMap {
|
|
214
|
+
/**
|
|
215
|
+
* The `env` section defines overrides for the configuration for different environments.
|
|
216
|
+
*
|
|
217
|
+
* All environment fields can be specified at the top level of the config indicating the default environment settings.
|
|
218
|
+
*
|
|
219
|
+
* - Some fields are inherited and overridable in each environment.
|
|
220
|
+
* - But some are not inherited and must be explicitly specified in every environment, if they are specified at the top level.
|
|
221
|
+
*
|
|
222
|
+
* For more information, see the documentation at https://developers.cloudflare.com/workers/cli-wrangler/configuration#environments
|
|
223
|
+
*
|
|
224
|
+
* @default `{}`
|
|
225
|
+
*/
|
|
226
|
+
env?: {
|
|
227
|
+
[envName: string]: RawEnvironment;
|
|
228
|
+
};
|
|
229
|
+
}
|
|
@@ -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
|
+
}
|