wrangler 2.0.12 → 2.0.16
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 +7 -1
- package/bin/wrangler.js +111 -57
- package/miniflare-dist/index.mjs +9 -2
- package/package.json +156 -154
- package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
- package/src/__tests__/config-cache.test.ts +30 -24
- package/src/__tests__/configuration.test.ts +3935 -3476
- package/src/__tests__/dev.test.tsx +1128 -979
- package/src/__tests__/guess-worker-format.test.ts +68 -68
- package/src/__tests__/helpers/cmd-shim.d.ts +6 -6
- package/src/__tests__/helpers/faye-websocket.d.ts +4 -4
- package/src/__tests__/helpers/mock-account-id.ts +24 -24
- package/src/__tests__/helpers/mock-bin.ts +20 -20
- package/src/__tests__/helpers/mock-cfetch.ts +92 -92
- package/src/__tests__/helpers/mock-console.ts +49 -39
- package/src/__tests__/helpers/mock-dialogs.ts +94 -71
- package/src/__tests__/helpers/mock-http-server.ts +30 -30
- package/src/__tests__/helpers/mock-istty.ts +65 -18
- package/src/__tests__/helpers/mock-kv.ts +26 -26
- package/src/__tests__/helpers/mock-oauth-flow.ts +223 -228
- package/src/__tests__/helpers/mock-process.ts +39 -0
- package/src/__tests__/helpers/mock-stdin.ts +82 -77
- package/src/__tests__/helpers/mock-web-socket.ts +21 -21
- package/src/__tests__/helpers/run-in-tmp.ts +27 -27
- package/src/__tests__/helpers/run-wrangler.ts +8 -8
- package/src/__tests__/helpers/write-worker-source.ts +16 -16
- package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
- package/src/__tests__/https-options.test.ts +104 -104
- package/src/__tests__/index.test.ts +239 -234
- package/src/__tests__/init.test.ts +1605 -1250
- package/src/__tests__/jest.setup.ts +63 -33
- package/src/__tests__/kv.test.ts +1128 -1011
- package/src/__tests__/logger.test.ts +100 -74
- package/src/__tests__/package-manager.test.ts +303 -303
- package/src/__tests__/pages.test.ts +1152 -652
- package/src/__tests__/parse.test.ts +252 -252
- package/src/__tests__/publish.test.ts +6371 -5622
- package/src/__tests__/pubsub.test.ts +367 -0
- package/src/__tests__/r2.test.ts +133 -133
- package/src/__tests__/route.test.ts +18 -18
- package/src/__tests__/secret.test.ts +382 -377
- package/src/__tests__/tail.test.ts +530 -530
- package/src/__tests__/user.test.ts +123 -111
- package/src/__tests__/whoami.test.tsx +198 -117
- package/src/__tests__/worker-namespace.test.ts +327 -0
- package/src/abort.d.ts +1 -1
- package/src/api/dev.ts +49 -0
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +29 -0
- package/src/bundle.ts +157 -149
- package/src/cfetch/index.ts +80 -80
- package/src/cfetch/internal.ts +90 -83
- package/src/cli.ts +21 -7
- package/src/config/config.ts +204 -195
- package/src/config/diagnostics.ts +61 -61
- package/src/config/environment.ts +390 -357
- package/src/config/index.ts +206 -193
- package/src/config/validation-helpers.ts +366 -366
- package/src/config/validation.ts +1573 -1376
- package/src/config-cache.ts +79 -41
- package/src/create-worker-preview.ts +206 -136
- package/src/create-worker-upload-form.ts +247 -238
- package/src/dev/dev-vars.ts +13 -13
- package/src/dev/dev.tsx +329 -307
- package/src/dev/local.tsx +304 -275
- package/src/dev/remote.tsx +366 -224
- package/src/dev/use-esbuild.ts +126 -91
- package/src/dev.tsx +538 -0
- package/src/dialogs.tsx +97 -97
- package/src/durable.ts +87 -87
- package/src/entry.ts +234 -228
- package/src/environment-variables.ts +23 -23
- package/src/errors.ts +6 -6
- package/src/generate.ts +33 -0
- package/src/git-client.ts +42 -0
- package/src/https-options.ts +79 -79
- package/src/index.tsx +1775 -2763
- package/src/init.ts +549 -0
- package/src/inspect.ts +593 -593
- package/src/intl-polyfill.d.ts +123 -123
- package/src/is-interactive.ts +12 -0
- package/src/kv.ts +277 -277
- package/src/logger.ts +46 -39
- package/src/miniflare-cli/enum-keys.ts +8 -8
- package/src/miniflare-cli/index.ts +42 -31
- package/src/miniflare-cli/request-context.ts +18 -18
- package/src/module-collection.ts +212 -212
- package/src/open-in-browser.ts +4 -6
- package/src/package-manager.ts +123 -123
- package/src/pages/build.tsx +202 -0
- package/src/pages/constants.ts +7 -0
- package/src/pages/deployments.tsx +101 -0
- package/src/pages/dev.tsx +964 -0
- package/src/pages/functions/buildPlugin.ts +105 -0
- package/src/pages/functions/buildWorker.ts +151 -0
- package/{pages → src/pages}/functions/filepath-routing.test.ts +113 -113
- package/src/pages/functions/filepath-routing.ts +189 -0
- package/src/pages/functions/identifiers.ts +78 -0
- package/src/pages/functions/routes.ts +151 -0
- package/src/pages/index.tsx +84 -0
- package/src/pages/projects.tsx +157 -0
- package/src/pages/publish.tsx +335 -0
- package/src/pages/types.ts +40 -0
- package/src/pages/upload.tsx +384 -0
- package/src/pages/utils.ts +12 -0
- package/src/parse.ts +202 -138
- package/src/paths.ts +6 -6
- package/src/preview.ts +31 -0
- package/src/proxy.ts +400 -402
- package/src/publish.ts +667 -621
- package/src/pubsub/index.ts +286 -0
- package/src/pubsub/pubsub-commands.tsx +577 -0
- package/src/r2.ts +19 -19
- package/src/selfsigned.d.ts +23 -23
- package/src/sites.tsx +271 -225
- package/src/tail/filters.ts +108 -108
- package/src/tail/index.ts +217 -217
- package/src/tail/printing.ts +45 -45
- package/src/update-check.ts +11 -11
- package/src/user/choose-account.tsx +60 -0
- package/src/user/env-vars.ts +46 -0
- package/src/user/generate-auth-url.ts +33 -0
- package/src/user/generate-random-state.ts +16 -0
- package/src/user/index.ts +3 -0
- package/src/user/user.tsx +1161 -0
- package/src/whoami.tsx +61 -42
- package/src/worker-namespace.ts +190 -0
- package/src/worker.ts +110 -100
- package/src/zones.ts +39 -36
- package/templates/checked-fetch.js +17 -0
- package/templates/new-worker-scheduled.js +3 -3
- package/templates/new-worker-scheduled.ts +15 -15
- package/templates/new-worker.js +3 -3
- package/templates/new-worker.ts +15 -15
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-template-plugin.ts +155 -0
- package/templates/pages-template-worker.ts +161 -0
- package/templates/static-asset-facade.js +31 -31
- package/templates/tsconfig.json +95 -95
- package/wrangler-dist/cli.js +55383 -54138
- package/pages/functions/buildPlugin.ts +0 -105
- package/pages/functions/buildWorker.ts +0 -151
- package/pages/functions/filepath-routing.ts +0 -189
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -156
- package/pages/functions/template-plugin.ts +0 -147
- package/pages/functions/template-worker.ts +0 -143
- package/src/pages.tsx +0 -2093
- package/src/user.tsx +0 -1214
package/src/config/validation.ts
CHANGED
|
@@ -2,36 +2,36 @@ import path from "node:path";
|
|
|
2
2
|
import TOML from "@iarna/toml";
|
|
3
3
|
import { Diagnostics } from "./diagnostics";
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
5
|
+
deprecated,
|
|
6
|
+
experimental,
|
|
7
|
+
hasProperty,
|
|
8
|
+
inheritable,
|
|
9
|
+
isBoolean,
|
|
10
|
+
isObjectWith,
|
|
11
|
+
isOneOf,
|
|
12
|
+
isOptionalProperty,
|
|
13
|
+
isRequiredProperty,
|
|
14
|
+
isString,
|
|
15
|
+
isStringArray,
|
|
16
|
+
validateAdditionalProperties,
|
|
17
|
+
notInheritable,
|
|
18
|
+
validateOptionalProperty,
|
|
19
|
+
validateOptionalTypedArray,
|
|
20
|
+
validateRequiredProperty,
|
|
21
|
+
validateTypedArray,
|
|
22
|
+
all,
|
|
23
|
+
isMutuallyExclusiveWith,
|
|
24
|
+
inheritableInLegacyEnvironments,
|
|
25
|
+
appendEnvName,
|
|
26
|
+
getBindingNames,
|
|
27
|
+
isValidName,
|
|
28
28
|
} from "./validation-helpers";
|
|
29
29
|
import type { Config, DevConfig, RawConfig, RawDevConfig } from "./config";
|
|
30
30
|
import type {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
RawEnvironment,
|
|
32
|
+
DeprecatedUpload,
|
|
33
|
+
Environment,
|
|
34
|
+
Rule,
|
|
35
35
|
} from "./environment";
|
|
36
36
|
import type { ValidatorFn } from "./validation-helpers";
|
|
37
37
|
|
|
@@ -46,558 +46,590 @@ const ENGLISH = new Intl.ListFormat("en");
|
|
|
46
46
|
* Any errors or warnings from the validation are available in the returned `diagnostics` object.
|
|
47
47
|
*/
|
|
48
48
|
export function normalizeAndValidateConfig(
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
rawConfig: RawConfig,
|
|
50
|
+
configPath: string | undefined,
|
|
51
|
+
args: unknown
|
|
52
52
|
): {
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
config: Config;
|
|
54
|
+
diagnostics: Diagnostics;
|
|
55
55
|
} {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
56
|
+
const diagnostics = new Diagnostics(
|
|
57
|
+
`Processing ${
|
|
58
|
+
configPath ? path.relative(process.cwd(), configPath) : "wrangler"
|
|
59
|
+
} configuration:`
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
deprecated(
|
|
63
|
+
diagnostics,
|
|
64
|
+
rawConfig,
|
|
65
|
+
"miniflare",
|
|
66
|
+
"Wrangler does not use configuration in the `miniflare` section. Unless you are using Miniflare directly you can remove this section.",
|
|
67
|
+
true,
|
|
68
|
+
"😶 Ignored"
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
deprecated(
|
|
72
|
+
diagnostics,
|
|
73
|
+
rawConfig,
|
|
74
|
+
"type",
|
|
75
|
+
"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.",
|
|
76
|
+
true,
|
|
77
|
+
"😶 Ignored"
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
deprecated(
|
|
81
|
+
diagnostics,
|
|
82
|
+
rawConfig,
|
|
83
|
+
"webpack_config",
|
|
84
|
+
"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.",
|
|
85
|
+
true,
|
|
86
|
+
"😶 Ignored"
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
validateOptionalProperty(
|
|
90
|
+
diagnostics,
|
|
91
|
+
"",
|
|
92
|
+
"legacy_env",
|
|
93
|
+
rawConfig.legacy_env,
|
|
94
|
+
"boolean"
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
// TODO: set the default to false to turn on service environments as the default
|
|
98
|
+
const isLegacyEnv =
|
|
99
|
+
(args as { "legacy-env": boolean | undefined })["legacy-env"] ??
|
|
100
|
+
rawConfig.legacy_env ??
|
|
101
|
+
true;
|
|
102
|
+
|
|
103
|
+
// TODO: remove this once service environments goes GA.
|
|
104
|
+
if (!isLegacyEnv) {
|
|
105
|
+
diagnostics.warnings.push(
|
|
106
|
+
"Experimental: Service environments are in beta, and their behaviour is guaranteed to change in the future. DO NOT USE IN PRODUCTION."
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const topLevelEnv = normalizeAndValidateEnvironment(
|
|
111
|
+
diagnostics,
|
|
112
|
+
configPath,
|
|
113
|
+
rawConfig
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
//TODO: find a better way to define the type of Args that can be passed to the normalizeAndValidateConfig()
|
|
117
|
+
const envName = (args as { env: string | undefined }).env;
|
|
118
|
+
|
|
119
|
+
let activeEnv = topLevelEnv;
|
|
120
|
+
if (envName !== undefined) {
|
|
121
|
+
const envDiagnostics = new Diagnostics(
|
|
122
|
+
`"env.${envName}" environment configuration`
|
|
123
|
+
);
|
|
124
|
+
const rawEnv = rawConfig.env?.[envName];
|
|
125
|
+
if (rawEnv !== undefined) {
|
|
126
|
+
activeEnv = normalizeAndValidateEnvironment(
|
|
127
|
+
envDiagnostics,
|
|
128
|
+
configPath,
|
|
129
|
+
rawEnv,
|
|
130
|
+
envName,
|
|
131
|
+
topLevelEnv,
|
|
132
|
+
isLegacyEnv,
|
|
133
|
+
rawConfig
|
|
134
|
+
);
|
|
135
|
+
diagnostics.addChild(envDiagnostics);
|
|
136
|
+
} else {
|
|
137
|
+
// An environment was specified, but no configuration for it was found.
|
|
138
|
+
// To cover any legacy environment cases, where the `envName` is used,
|
|
139
|
+
// Let's create a fake active environment with the specified `envName`.
|
|
140
|
+
activeEnv = normalizeAndValidateEnvironment(
|
|
141
|
+
envDiagnostics,
|
|
142
|
+
configPath,
|
|
143
|
+
{},
|
|
144
|
+
envName,
|
|
145
|
+
topLevelEnv,
|
|
146
|
+
isLegacyEnv,
|
|
147
|
+
rawConfig
|
|
148
|
+
);
|
|
149
|
+
const envNames = rawConfig.env
|
|
150
|
+
? `The available configured environment names are: ${JSON.stringify(
|
|
151
|
+
Object.keys(rawConfig.env)
|
|
152
|
+
)}\n`
|
|
153
|
+
: "";
|
|
154
|
+
const message =
|
|
155
|
+
`No environment found in configuration with name "${envName}".\n` +
|
|
156
|
+
`Before using \`--env=${envName}\` there should be an equivalent environment section in the configuration.\n` +
|
|
157
|
+
`${envNames}\n` +
|
|
158
|
+
`Consider adding an environment configuration section to the wrangler.toml file:\n` +
|
|
159
|
+
"```\n[env." +
|
|
160
|
+
envName +
|
|
161
|
+
"]\n```\n";
|
|
162
|
+
|
|
163
|
+
if (envNames.length > 0) {
|
|
164
|
+
diagnostics.errors.push(message);
|
|
165
|
+
} else {
|
|
166
|
+
// Only warn (rather than error) if there are not actually any environments configured in wrangler.toml.
|
|
167
|
+
diagnostics.warnings.push(message);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// Process the top-level default environment configuration.
|
|
173
|
+
const config: Config = {
|
|
174
|
+
configPath,
|
|
175
|
+
legacy_env: isLegacyEnv,
|
|
176
|
+
...activeEnv,
|
|
177
|
+
dev: normalizeAndValidateDev(diagnostics, rawConfig.dev ?? {}),
|
|
178
|
+
migrations: normalizeAndValidateMigrations(
|
|
179
|
+
diagnostics,
|
|
180
|
+
rawConfig.migrations ?? [],
|
|
181
|
+
activeEnv.durable_objects
|
|
182
|
+
),
|
|
183
|
+
site: normalizeAndValidateSite(
|
|
184
|
+
diagnostics,
|
|
185
|
+
configPath,
|
|
186
|
+
rawConfig,
|
|
187
|
+
activeEnv.main
|
|
188
|
+
),
|
|
189
|
+
assets: normalizeAndValidateAssets(diagnostics, configPath, rawConfig),
|
|
190
|
+
wasm_modules: normalizeAndValidateModulePaths(
|
|
191
|
+
diagnostics,
|
|
192
|
+
configPath,
|
|
193
|
+
"wasm_modules",
|
|
194
|
+
rawConfig.wasm_modules
|
|
195
|
+
),
|
|
196
|
+
text_blobs: normalizeAndValidateModulePaths(
|
|
197
|
+
diagnostics,
|
|
198
|
+
configPath,
|
|
199
|
+
"text_blobs",
|
|
200
|
+
rawConfig.text_blobs
|
|
201
|
+
),
|
|
202
|
+
data_blobs: normalizeAndValidateModulePaths(
|
|
203
|
+
diagnostics,
|
|
204
|
+
configPath,
|
|
205
|
+
"data_blobs",
|
|
206
|
+
rawConfig.data_blobs
|
|
207
|
+
),
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
validateBindingsHaveUniqueNames(diagnostics, config);
|
|
211
|
+
|
|
212
|
+
validateAdditionalProperties(
|
|
213
|
+
diagnostics,
|
|
214
|
+
"top-level",
|
|
215
|
+
Object.keys(rawConfig),
|
|
216
|
+
[...Object.keys(config), "env"]
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
experimental(diagnostics, rawConfig, "assets");
|
|
220
|
+
|
|
221
|
+
return { config, diagnostics };
|
|
219
222
|
}
|
|
220
223
|
|
|
221
224
|
/**
|
|
222
225
|
* Validate the `build` configuration and return the normalized values.
|
|
223
226
|
*/
|
|
224
227
|
function normalizeAndValidateBuild(
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
228
|
+
diagnostics: Diagnostics,
|
|
229
|
+
rawEnv: RawEnvironment,
|
|
230
|
+
rawBuild: Config["build"],
|
|
231
|
+
configPath: string | undefined
|
|
229
232
|
): Config["build"] & { deprecatedUpload: DeprecatedUpload } {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
233
|
+
const { command, cwd, watch_dir = "./src", upload, ...rest } = rawBuild;
|
|
234
|
+
const deprecatedUpload: DeprecatedUpload = { ...upload };
|
|
235
|
+
validateAdditionalProperties(diagnostics, "build", Object.keys(rest), []);
|
|
236
|
+
|
|
237
|
+
validateOptionalProperty(diagnostics, "build", "command", command, "string");
|
|
238
|
+
validateOptionalProperty(diagnostics, "build", "cwd", cwd, "string");
|
|
239
|
+
if (Array.isArray(watch_dir)) {
|
|
240
|
+
validateTypedArray(diagnostics, "build.watch_dir", watch_dir, "string");
|
|
241
|
+
} else {
|
|
242
|
+
validateOptionalProperty(
|
|
243
|
+
diagnostics,
|
|
244
|
+
"build",
|
|
245
|
+
"watch_dir",
|
|
246
|
+
watch_dir,
|
|
247
|
+
"string"
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
deprecated(
|
|
252
|
+
diagnostics,
|
|
253
|
+
rawEnv,
|
|
254
|
+
"build.upload.format",
|
|
255
|
+
"The format is inferred automatically from the code.",
|
|
256
|
+
true
|
|
257
|
+
);
|
|
258
|
+
|
|
259
|
+
if (rawEnv.main !== undefined && rawBuild.upload?.main) {
|
|
260
|
+
diagnostics.errors.push(
|
|
261
|
+
`Don't define both the \`main\` and \`build.upload.main\` fields in your configuration.\n` +
|
|
262
|
+
`They serve the same purpose: to point to the entry-point of your worker.\n` +
|
|
263
|
+
`Delete the \`build.upload.main\` and \`build.upload.dir\` field from your config.`
|
|
264
|
+
);
|
|
265
|
+
} else {
|
|
266
|
+
deprecated(
|
|
267
|
+
diagnostics,
|
|
268
|
+
rawEnv,
|
|
269
|
+
"build.upload.main",
|
|
270
|
+
`Delete the \`build.upload.main\` and \`build.upload.dir\` fields.\n` +
|
|
271
|
+
`Then add the top level \`main\` field to your configuration file:\n` +
|
|
272
|
+
`\`\`\`\n` +
|
|
273
|
+
`main = "${path.join(
|
|
274
|
+
rawBuild.upload?.dir ?? "./dist",
|
|
275
|
+
rawBuild.upload?.main ?? "."
|
|
276
|
+
)}"\n` +
|
|
277
|
+
`\`\`\``,
|
|
278
|
+
true
|
|
279
|
+
);
|
|
280
|
+
|
|
281
|
+
deprecated(
|
|
282
|
+
diagnostics,
|
|
283
|
+
rawEnv,
|
|
284
|
+
"build.upload.dir",
|
|
285
|
+
`Use the top level "main" field or a command-line argument to specify the entry-point for the Worker.`,
|
|
286
|
+
true
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return {
|
|
291
|
+
command,
|
|
292
|
+
watch_dir:
|
|
293
|
+
// - `watch_dir` only matters when `command` is defined, so we apply
|
|
294
|
+
// a default only when `command` is defined
|
|
295
|
+
// - `configPath` will always be defined since `build` can only
|
|
296
|
+
// be configured in `wrangler.toml`, but who knows, that may
|
|
297
|
+
// change in the future, so we do a check anyway
|
|
298
|
+
command && configPath
|
|
299
|
+
? Array.isArray(watch_dir)
|
|
300
|
+
? watch_dir.map((dir) =>
|
|
301
|
+
path.relative(
|
|
302
|
+
process.cwd(),
|
|
303
|
+
path.join(path.dirname(configPath), `${dir}`)
|
|
304
|
+
)
|
|
305
|
+
)
|
|
306
|
+
: path.relative(
|
|
307
|
+
process.cwd(),
|
|
308
|
+
path.join(path.dirname(configPath), `${watch_dir}`)
|
|
309
|
+
)
|
|
310
|
+
: watch_dir,
|
|
311
|
+
cwd,
|
|
312
|
+
deprecatedUpload,
|
|
313
|
+
};
|
|
311
314
|
}
|
|
312
315
|
|
|
313
316
|
/**
|
|
314
317
|
* Validate the `main` field and return the normalized values.
|
|
315
318
|
*/
|
|
316
319
|
function normalizeAndValidateMainField(
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
+
configPath: string | undefined,
|
|
321
|
+
rawMain: string | undefined,
|
|
322
|
+
deprecatedUpload: DeprecatedUpload | undefined
|
|
320
323
|
): string | undefined {
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
324
|
+
const configDir = path.dirname(configPath ?? "wrangler.toml");
|
|
325
|
+
if (rawMain !== undefined) {
|
|
326
|
+
if (typeof rawMain === "string") {
|
|
327
|
+
const directory = path.resolve(configDir);
|
|
328
|
+
return path.resolve(directory, rawMain);
|
|
329
|
+
} else {
|
|
330
|
+
return rawMain;
|
|
331
|
+
}
|
|
332
|
+
} else if (deprecatedUpload?.main !== undefined) {
|
|
333
|
+
const directory = path.resolve(
|
|
334
|
+
configDir,
|
|
335
|
+
deprecatedUpload?.dir || "./dist"
|
|
336
|
+
);
|
|
337
|
+
return path.resolve(directory, deprecatedUpload.main);
|
|
338
|
+
} else {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
338
341
|
}
|
|
339
342
|
|
|
340
343
|
/**
|
|
341
344
|
* Validate the `dev` configuration and return the normalized values.
|
|
342
345
|
*/
|
|
343
346
|
function normalizeAndValidateDev(
|
|
344
|
-
|
|
345
|
-
|
|
347
|
+
diagnostics: Diagnostics,
|
|
348
|
+
rawDev: RawDevConfig
|
|
346
349
|
): DevConfig {
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
350
|
+
const {
|
|
351
|
+
ip = "localhost",
|
|
352
|
+
port,
|
|
353
|
+
local_protocol = "http",
|
|
354
|
+
upstream_protocol = "https",
|
|
355
|
+
host,
|
|
356
|
+
...rest
|
|
357
|
+
} = rawDev;
|
|
358
|
+
validateAdditionalProperties(diagnostics, "dev", Object.keys(rest), []);
|
|
359
|
+
|
|
360
|
+
validateOptionalProperty(diagnostics, "dev", "ip", ip, "string");
|
|
361
|
+
validateOptionalProperty(diagnostics, "dev", "port", port, "number");
|
|
362
|
+
validateOptionalProperty(
|
|
363
|
+
diagnostics,
|
|
364
|
+
"dev",
|
|
365
|
+
"local_protocol",
|
|
366
|
+
local_protocol,
|
|
367
|
+
"string",
|
|
368
|
+
["http", "https"]
|
|
369
|
+
);
|
|
370
|
+
validateOptionalProperty(
|
|
371
|
+
diagnostics,
|
|
372
|
+
"dev",
|
|
373
|
+
"upstream_protocol",
|
|
374
|
+
upstream_protocol,
|
|
375
|
+
"string",
|
|
376
|
+
["http", "https"]
|
|
377
|
+
);
|
|
378
|
+
validateOptionalProperty(diagnostics, "dev", "host", host, "string");
|
|
379
|
+
return { ip, port, local_protocol, upstream_protocol, host };
|
|
377
380
|
}
|
|
378
381
|
|
|
379
382
|
/**
|
|
380
383
|
* Validate the `migrations` configuration and return the normalized values.
|
|
381
384
|
*/
|
|
382
385
|
function normalizeAndValidateMigrations(
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
+
diagnostics: Diagnostics,
|
|
387
|
+
rawMigrations: Config["migrations"],
|
|
388
|
+
durableObjects: Config["durable_objects"]
|
|
386
389
|
): Config["migrations"] {
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
390
|
+
if (!Array.isArray(rawMigrations)) {
|
|
391
|
+
diagnostics.errors.push(
|
|
392
|
+
`The optional "migrations" field should be an array, but got ${JSON.stringify(
|
|
393
|
+
rawMigrations
|
|
394
|
+
)}`
|
|
395
|
+
);
|
|
396
|
+
return [];
|
|
397
|
+
} else {
|
|
398
|
+
for (let i = 0; i < rawMigrations.length; i++) {
|
|
399
|
+
const { tag, new_classes, renamed_classes, deleted_classes, ...rest } =
|
|
400
|
+
rawMigrations[i];
|
|
401
|
+
|
|
402
|
+
validateAdditionalProperties(
|
|
403
|
+
diagnostics,
|
|
404
|
+
"migrations",
|
|
405
|
+
Object.keys(rest),
|
|
406
|
+
[]
|
|
407
|
+
);
|
|
408
|
+
|
|
409
|
+
validateRequiredProperty(
|
|
410
|
+
diagnostics,
|
|
411
|
+
`migrations[${i}]`,
|
|
412
|
+
`tag`,
|
|
413
|
+
tag,
|
|
414
|
+
"string"
|
|
415
|
+
);
|
|
416
|
+
validateOptionalTypedArray(
|
|
417
|
+
diagnostics,
|
|
418
|
+
`migrations[${i}].new_classes`,
|
|
419
|
+
new_classes,
|
|
420
|
+
"string"
|
|
421
|
+
);
|
|
422
|
+
if (renamed_classes !== undefined) {
|
|
423
|
+
if (!Array.isArray(renamed_classes)) {
|
|
424
|
+
diagnostics.errors.push(
|
|
425
|
+
`Expected "migrations[${i}].renamed_classes" to be an array of "{from: string, to: string}" objects but got ${JSON.stringify(
|
|
426
|
+
renamed_classes
|
|
427
|
+
)}.`
|
|
428
|
+
);
|
|
429
|
+
} else if (
|
|
430
|
+
renamed_classes.some(
|
|
431
|
+
(c) =>
|
|
432
|
+
typeof c !== "object" ||
|
|
433
|
+
!isRequiredProperty(c, "from", "string") ||
|
|
434
|
+
!isRequiredProperty(c, "to", "string")
|
|
435
|
+
)
|
|
436
|
+
) {
|
|
437
|
+
diagnostics.errors.push(
|
|
438
|
+
`Expected "migrations[${i}].renamed_classes" to be an array of "{from: string, to: string}" objects but got ${JSON.stringify(
|
|
439
|
+
renamed_classes
|
|
440
|
+
)}.`
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
validateOptionalTypedArray(
|
|
445
|
+
diagnostics,
|
|
446
|
+
`migrations[${i}].deleted_classes`,
|
|
447
|
+
deleted_classes,
|
|
448
|
+
"string"
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
if (
|
|
453
|
+
Array.isArray(durableObjects?.bindings) &&
|
|
454
|
+
durableObjects.bindings.length > 0
|
|
455
|
+
) {
|
|
456
|
+
// intrinsic [durable_objects] implies [migrations]
|
|
457
|
+
const exportedDurableObjects = (durableObjects.bindings || []).filter(
|
|
458
|
+
(binding) => !binding.script_name
|
|
459
|
+
);
|
|
460
|
+
if (exportedDurableObjects.length > 0 && rawMigrations.length === 0) {
|
|
461
|
+
if (
|
|
462
|
+
!exportedDurableObjects.some(
|
|
463
|
+
(exportedDurableObject) =>
|
|
464
|
+
typeof exportedDurableObject.class_name !== "string"
|
|
465
|
+
)
|
|
466
|
+
) {
|
|
467
|
+
const durableObjectClassnames = exportedDurableObjects.map(
|
|
468
|
+
(durable) => durable.class_name
|
|
469
|
+
);
|
|
470
|
+
|
|
471
|
+
diagnostics.warnings.push(
|
|
472
|
+
`In wrangler.toml, you have configured [durable_objects] exported by this Worker (${durableObjectClassnames.join(
|
|
473
|
+
", "
|
|
474
|
+
)}), but no [migrations] for them. This may not work as expected until you add a [migrations] section to your wrangler.toml. Add this configuration to your wrangler.toml:
|
|
472
475
|
|
|
473
476
|
\`\`\`
|
|
474
477
|
[[migrations]]
|
|
475
478
|
tag = "v1" # Should be unique for each entry
|
|
476
479
|
new_classes = [${durableObjectClassnames
|
|
477
|
-
|
|
478
|
-
|
|
480
|
+
.map((name) => `"${name}"`)
|
|
481
|
+
.join(", ")}]
|
|
479
482
|
\`\`\`
|
|
480
483
|
|
|
481
484
|
Refer to https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml for more details.`
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
486
489
|
|
|
487
|
-
|
|
488
|
-
|
|
490
|
+
return rawMigrations;
|
|
491
|
+
}
|
|
489
492
|
}
|
|
490
493
|
|
|
491
494
|
/**
|
|
492
495
|
* Validate the `site` configuration and return the normalized values.
|
|
493
496
|
*/
|
|
494
497
|
function normalizeAndValidateSite(
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
498
|
+
diagnostics: Diagnostics,
|
|
499
|
+
configPath: string | undefined,
|
|
500
|
+
rawConfig: RawConfig,
|
|
501
|
+
mainEntryPoint: string | undefined
|
|
499
502
|
): Config["site"] {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
503
|
+
if (rawConfig?.site !== undefined) {
|
|
504
|
+
const { bucket, include = [], exclude = [], ...rest } = rawConfig.site;
|
|
505
|
+
|
|
506
|
+
validateAdditionalProperties(diagnostics, "site", Object.keys(rest), [
|
|
507
|
+
"entry-point",
|
|
508
|
+
]);
|
|
509
|
+
validateRequiredProperty(diagnostics, "site", "bucket", bucket, "string");
|
|
510
|
+
validateTypedArray(diagnostics, "sites.include", include, "string");
|
|
511
|
+
validateTypedArray(diagnostics, "sites.exclude", exclude, "string");
|
|
512
|
+
validateOptionalProperty(
|
|
513
|
+
diagnostics,
|
|
514
|
+
"site",
|
|
515
|
+
"entry-point",
|
|
516
|
+
rawConfig.site["entry-point"],
|
|
517
|
+
"string"
|
|
518
|
+
);
|
|
519
|
+
|
|
520
|
+
deprecated(
|
|
521
|
+
diagnostics,
|
|
522
|
+
rawConfig,
|
|
523
|
+
`site.entry-point`,
|
|
524
|
+
`Delete the \`site.entry-point\` field, then add the top level \`main\` field to your configuration file:\n` +
|
|
525
|
+
`\`\`\`\n` +
|
|
526
|
+
`main = "${path.join(
|
|
527
|
+
String(rawConfig.site["entry-point"]) || "workers-site",
|
|
528
|
+
path.extname(String(rawConfig.site["entry-point"]) || "workers-site")
|
|
529
|
+
? ""
|
|
530
|
+
: "index.js"
|
|
531
|
+
)}"\n` +
|
|
532
|
+
`\`\`\``,
|
|
533
|
+
false,
|
|
534
|
+
undefined,
|
|
535
|
+
"warning"
|
|
536
|
+
);
|
|
537
|
+
|
|
538
|
+
let siteEntryPoint = rawConfig.site["entry-point"];
|
|
539
|
+
|
|
540
|
+
if (!mainEntryPoint && !siteEntryPoint) {
|
|
541
|
+
// this means that we're defaulting to "workers-site"
|
|
542
|
+
// so let's add the deprecation warning
|
|
543
|
+
diagnostics.warnings.push(
|
|
544
|
+
`Because you've defined a [site] configuration, we're defaulting to "workers-site" for the deprecated \`site.entry-point\`field.\n` +
|
|
545
|
+
`Add the top level \`main\` field to your configuration file:\n` +
|
|
546
|
+
`\`\`\`\n` +
|
|
547
|
+
`main = "workers-site/index.js"\n` +
|
|
548
|
+
`\`\`\``
|
|
549
|
+
);
|
|
550
|
+
siteEntryPoint = "workers-site";
|
|
551
|
+
} else if (mainEntryPoint && siteEntryPoint) {
|
|
552
|
+
diagnostics.errors.push(
|
|
553
|
+
`Don't define both the \`main\` and \`site.entry-point\` fields in your configuration.\n` +
|
|
554
|
+
`They serve the same purpose: to point to the entry-point of your worker.\n` +
|
|
555
|
+
`Delete the deprecated \`site.entry-point\` field from your config.`
|
|
556
|
+
);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
if (configPath && siteEntryPoint) {
|
|
560
|
+
// rewrite the path to be relative to the working directory
|
|
561
|
+
siteEntryPoint = path.relative(
|
|
562
|
+
process.cwd(),
|
|
563
|
+
path.join(path.dirname(configPath), siteEntryPoint)
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
return {
|
|
568
|
+
bucket,
|
|
569
|
+
"entry-point": siteEntryPoint,
|
|
570
|
+
include,
|
|
571
|
+
exclude,
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
return undefined;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* Validate the `assets` configuration and return normalized values.
|
|
579
|
+
*/
|
|
580
|
+
function normalizeAndValidateAssets(
|
|
581
|
+
diagnostics: Diagnostics,
|
|
582
|
+
configPath: string | undefined,
|
|
583
|
+
rawConfig: RawConfig
|
|
584
|
+
) {
|
|
585
|
+
if (
|
|
586
|
+
typeof rawConfig?.assets === "string" ||
|
|
587
|
+
rawConfig?.assets === undefined
|
|
588
|
+
) {
|
|
589
|
+
return rawConfig?.assets;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
const { bucket, include = [], exclude = [], ...rest } = rawConfig.assets;
|
|
593
|
+
|
|
594
|
+
validateAdditionalProperties(diagnostics, "assets", Object.keys(rest), []);
|
|
595
|
+
validateRequiredProperty(diagnostics, "assets", "bucket", bucket, "string");
|
|
596
|
+
validateTypedArray(diagnostics, "assets.include", include, "string");
|
|
597
|
+
validateTypedArray(diagnostics, "assets.exclude", exclude, "string");
|
|
598
|
+
|
|
599
|
+
return {
|
|
600
|
+
bucket,
|
|
601
|
+
include,
|
|
602
|
+
exclude,
|
|
603
|
+
};
|
|
572
604
|
}
|
|
573
605
|
|
|
574
606
|
/**
|
|
575
607
|
* Map the paths of the `wasm_modules`, `text_blobs` or `data_blobs` configuration to be relative to the current working directory.
|
|
576
608
|
*/
|
|
577
609
|
function normalizeAndValidateModulePaths(
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
610
|
+
diagnostics: Diagnostics,
|
|
611
|
+
configPath: string | undefined,
|
|
612
|
+
field: "wasm_modules" | "text_blobs" | "data_blobs",
|
|
613
|
+
rawMapping: Record<string, string> | undefined
|
|
582
614
|
): Record<string, string> | undefined {
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
615
|
+
if (rawMapping === undefined) {
|
|
616
|
+
return undefined;
|
|
617
|
+
}
|
|
618
|
+
const mapping: Record<string, string> = {};
|
|
619
|
+
// Rewrite paths to be relative to the cwd, rather than the config path.
|
|
620
|
+
for (const [name, filePath] of Object.entries(rawMapping)) {
|
|
621
|
+
if (isString(diagnostics, `${field}['${name}']`, filePath, undefined)) {
|
|
622
|
+
if (configPath) {
|
|
623
|
+
mapping[name] = configPath
|
|
624
|
+
? path.relative(
|
|
625
|
+
process.cwd(),
|
|
626
|
+
path.join(path.dirname(configPath), filePath)
|
|
627
|
+
)
|
|
628
|
+
: filePath;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
return mapping;
|
|
601
633
|
}
|
|
602
634
|
|
|
603
635
|
/**
|
|
@@ -605,638 +637,768 @@ function normalizeAndValidateModulePaths(
|
|
|
605
637
|
* or an object that looks like {pattern: string, zone_id: string }
|
|
606
638
|
*/
|
|
607
639
|
function isValidRouteValue(item: unknown): boolean {
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
640
|
+
if (!item) {
|
|
641
|
+
return false;
|
|
642
|
+
}
|
|
643
|
+
if (typeof item === "string") {
|
|
644
|
+
return true;
|
|
645
|
+
}
|
|
646
|
+
if (typeof item === "object") {
|
|
647
|
+
if (!hasProperty(item, "pattern") || typeof item.pattern !== "string") {
|
|
648
|
+
return false;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
const otherKeys = Object.keys(item).length - 1; // minus one to subtract "pattern"
|
|
652
|
+
|
|
653
|
+
const hasZoneId =
|
|
654
|
+
hasProperty(item, "zone_id") && typeof item.zone_id === "string";
|
|
655
|
+
const hasZoneName =
|
|
656
|
+
hasProperty(item, "zone_name") && typeof item.zone_name === "string";
|
|
657
|
+
const hasCustomDomainFlag =
|
|
658
|
+
hasProperty(item, "custom_domain") &&
|
|
659
|
+
typeof item.custom_domain === "boolean";
|
|
660
|
+
|
|
661
|
+
if (otherKeys === 2 && hasCustomDomainFlag && (hasZoneId || hasZoneName)) {
|
|
662
|
+
return true;
|
|
663
|
+
} else if (
|
|
664
|
+
otherKeys === 1 &&
|
|
665
|
+
(hasZoneId || hasZoneName || hasCustomDomainFlag)
|
|
666
|
+
) {
|
|
667
|
+
return true;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return false;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* If account_id has been passed as an empty string, normalise it to undefined.
|
|
675
|
+
* This is to workaround older wrangler1-era templates that have account_id = '',
|
|
676
|
+
* which isn't a valid value anyway
|
|
677
|
+
*/
|
|
678
|
+
function mutateEmptyStringAccountIDValue(
|
|
679
|
+
diagnostics: Diagnostics,
|
|
680
|
+
rawEnv: RawEnvironment
|
|
681
|
+
) {
|
|
682
|
+
if (rawEnv.account_id === "") {
|
|
683
|
+
diagnostics.warnings.push(
|
|
684
|
+
`The "account_id" field in your configuration is an empty string and will be ignored.\n` +
|
|
685
|
+
`Please remove the "account_id" field from your configuration.`
|
|
686
|
+
);
|
|
687
|
+
rawEnv.account_id = undefined;
|
|
688
|
+
}
|
|
689
|
+
return rawEnv;
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
/**
|
|
693
|
+
* Normalize empty string to `undefined` by mutating rawEnv.route value.
|
|
694
|
+
* As part of backward compatibility with Wrangler1 converting empty string to `undefined`
|
|
695
|
+
*/
|
|
696
|
+
function mutateEmptyStringRouteValue(
|
|
697
|
+
diagnostics: Diagnostics,
|
|
698
|
+
rawEnv: RawEnvironment
|
|
699
|
+
): RawEnvironment {
|
|
700
|
+
if (rawEnv["route"] === "") {
|
|
701
|
+
diagnostics.warnings.push(
|
|
702
|
+
`The "route" field in your configuration is an empty string and will be ignored.\n` +
|
|
703
|
+
`Please remove the "route" field from your configuration.`
|
|
704
|
+
);
|
|
705
|
+
rawEnv["route"] = undefined;
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
return rawEnv;
|
|
639
709
|
}
|
|
640
710
|
|
|
641
711
|
/**
|
|
642
712
|
* Validate that the field is a route.
|
|
643
713
|
*/
|
|
644
714
|
const isRoute: ValidatorFn = (diagnostics, field, value) => {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
715
|
+
if (value !== undefined && !isValidRouteValue(value)) {
|
|
716
|
+
diagnostics.errors.push(
|
|
717
|
+
`Expected "${field}" to be either a string, or an object with shape { pattern, custom_domain, zone_id | zone_name }, but got ${JSON.stringify(
|
|
718
|
+
value
|
|
719
|
+
)}.`
|
|
720
|
+
);
|
|
721
|
+
return false;
|
|
722
|
+
}
|
|
723
|
+
return true;
|
|
654
724
|
};
|
|
655
725
|
|
|
656
726
|
/**
|
|
657
727
|
* Validate that the field is an array of routes.
|
|
658
728
|
*/
|
|
659
729
|
const isRouteArray: ValidatorFn = (diagnostics, field, value) => {
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
730
|
+
if (value === undefined) {
|
|
731
|
+
return true;
|
|
732
|
+
}
|
|
733
|
+
if (!Array.isArray(value)) {
|
|
734
|
+
diagnostics.errors.push(
|
|
735
|
+
`Expected "${field}" to be an array but got ${JSON.stringify(value)}.`
|
|
736
|
+
);
|
|
737
|
+
return false;
|
|
738
|
+
}
|
|
739
|
+
const invalidRoutes = [];
|
|
740
|
+
for (const item of value) {
|
|
741
|
+
if (!isValidRouteValue(item)) {
|
|
742
|
+
invalidRoutes.push(item);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
if (invalidRoutes.length > 0) {
|
|
746
|
+
diagnostics.errors.push(
|
|
747
|
+
`Expected "${field}" to be an array of either strings or objects with the shape { pattern, custom_domain, zone_id | zone_name }, but these weren't valid: ${JSON.stringify(
|
|
748
|
+
invalidRoutes,
|
|
749
|
+
null,
|
|
750
|
+
2
|
|
751
|
+
)}.`
|
|
752
|
+
);
|
|
753
|
+
}
|
|
754
|
+
return invalidRoutes.length === 0;
|
|
685
755
|
};
|
|
686
756
|
|
|
687
|
-
function
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
757
|
+
function normalizeAndValidateRoute(
|
|
758
|
+
diagnostics: Diagnostics,
|
|
759
|
+
topLevelEnv: Environment | undefined,
|
|
760
|
+
rawEnv: RawEnvironment
|
|
691
761
|
): Config["route"] {
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
762
|
+
return inheritable(
|
|
763
|
+
diagnostics,
|
|
764
|
+
topLevelEnv,
|
|
765
|
+
mutateEmptyStringRouteValue(diagnostics, rawEnv),
|
|
766
|
+
"route",
|
|
767
|
+
isRoute,
|
|
768
|
+
undefined
|
|
769
|
+
);
|
|
700
770
|
}
|
|
701
771
|
|
|
702
772
|
function validateRoutes(
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
773
|
+
diagnostics: Diagnostics,
|
|
774
|
+
topLevelEnv: Environment | undefined,
|
|
775
|
+
rawEnv: RawEnvironment
|
|
706
776
|
): Config["routes"] {
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
777
|
+
return inheritable(
|
|
778
|
+
diagnostics,
|
|
779
|
+
topLevelEnv,
|
|
780
|
+
rawEnv,
|
|
781
|
+
"routes",
|
|
782
|
+
all(isRouteArray, isMutuallyExclusiveWith(rawEnv, "route")),
|
|
783
|
+
undefined
|
|
784
|
+
);
|
|
715
785
|
}
|
|
716
786
|
|
|
717
787
|
/**
|
|
718
788
|
* Validate top-level environment configuration and return the normalized values.
|
|
719
789
|
*/
|
|
720
790
|
function normalizeAndValidateEnvironment(
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
791
|
+
diagnostics: Diagnostics,
|
|
792
|
+
configPath: string | undefined,
|
|
793
|
+
topLevelEnv: RawEnvironment
|
|
724
794
|
): Environment;
|
|
725
795
|
/**
|
|
726
796
|
* Validate the named environment configuration and return the normalized values.
|
|
727
797
|
*/
|
|
728
798
|
function normalizeAndValidateEnvironment(
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
799
|
+
diagnostics: Diagnostics,
|
|
800
|
+
configPath: string | undefined,
|
|
801
|
+
rawEnv: RawEnvironment,
|
|
802
|
+
envName: string,
|
|
803
|
+
topLevelEnv: Environment,
|
|
804
|
+
isLegacyEnv: boolean,
|
|
805
|
+
rawConfig: RawConfig
|
|
736
806
|
): Environment;
|
|
737
807
|
function normalizeAndValidateEnvironment(
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
808
|
+
diagnostics: Diagnostics,
|
|
809
|
+
configPath: string | undefined,
|
|
810
|
+
rawEnv: RawEnvironment,
|
|
811
|
+
envName = "top level",
|
|
812
|
+
topLevelEnv?: Environment | undefined,
|
|
813
|
+
isLegacyEnv?: boolean,
|
|
814
|
+
rawConfig?: RawConfig | undefined
|
|
745
815
|
): Environment {
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
816
|
+
deprecated(
|
|
817
|
+
diagnostics,
|
|
818
|
+
rawEnv,
|
|
819
|
+
"zone_id",
|
|
820
|
+
"This is unnecessary since we can deduce this from routes directly.",
|
|
821
|
+
false // We need to leave this in-place for the moment since `route` commands might use it.
|
|
822
|
+
);
|
|
823
|
+
|
|
824
|
+
// The field "experimental_services" doesn't exist anymore in the config, but we still want to error about any older usage.
|
|
825
|
+
deprecated(
|
|
826
|
+
diagnostics,
|
|
827
|
+
rawEnv,
|
|
828
|
+
"experimental_services",
|
|
829
|
+
`The "experimental_services" field is no longer supported. Simply rename the [experimental_services] field to [services].`,
|
|
830
|
+
true
|
|
831
|
+
);
|
|
832
|
+
|
|
833
|
+
experimental(diagnostics, rawEnv, "unsafe");
|
|
834
|
+
experimental(diagnostics, rawEnv, "services");
|
|
835
|
+
experimental(diagnostics, rawEnv, "worker_namespaces");
|
|
836
|
+
|
|
837
|
+
const route = normalizeAndValidateRoute(diagnostics, topLevelEnv, rawEnv);
|
|
838
|
+
|
|
839
|
+
const account_id = inheritableInLegacyEnvironments(
|
|
840
|
+
diagnostics,
|
|
841
|
+
isLegacyEnv,
|
|
842
|
+
topLevelEnv,
|
|
843
|
+
mutateEmptyStringAccountIDValue(diagnostics, rawEnv),
|
|
844
|
+
"account_id",
|
|
845
|
+
isString,
|
|
846
|
+
undefined,
|
|
847
|
+
undefined
|
|
848
|
+
);
|
|
849
|
+
|
|
850
|
+
const routes = validateRoutes(diagnostics, topLevelEnv, rawEnv);
|
|
851
|
+
|
|
852
|
+
const workers_dev = inheritable(
|
|
853
|
+
diagnostics,
|
|
854
|
+
topLevelEnv,
|
|
855
|
+
rawEnv,
|
|
856
|
+
"workers_dev",
|
|
857
|
+
isBoolean,
|
|
858
|
+
undefined
|
|
859
|
+
);
|
|
860
|
+
|
|
861
|
+
const { deprecatedUpload, ...build } = normalizeAndValidateBuild(
|
|
862
|
+
diagnostics,
|
|
863
|
+
rawEnv,
|
|
864
|
+
rawEnv.build ?? topLevelEnv?.build ?? {},
|
|
865
|
+
configPath
|
|
866
|
+
);
|
|
867
|
+
|
|
868
|
+
const environment: Environment = {
|
|
869
|
+
// Inherited fields
|
|
870
|
+
account_id,
|
|
871
|
+
compatibility_date: inheritable(
|
|
872
|
+
diagnostics,
|
|
873
|
+
topLevelEnv,
|
|
874
|
+
rawEnv,
|
|
875
|
+
"compatibility_date",
|
|
876
|
+
isString,
|
|
877
|
+
undefined
|
|
878
|
+
),
|
|
879
|
+
compatibility_flags: inheritable(
|
|
880
|
+
diagnostics,
|
|
881
|
+
topLevelEnv,
|
|
882
|
+
rawEnv,
|
|
883
|
+
"compatibility_flags",
|
|
884
|
+
isStringArray,
|
|
885
|
+
[]
|
|
886
|
+
),
|
|
887
|
+
jsx_factory: inheritable(
|
|
888
|
+
diagnostics,
|
|
889
|
+
topLevelEnv,
|
|
890
|
+
rawEnv,
|
|
891
|
+
"jsx_factory",
|
|
892
|
+
isString,
|
|
893
|
+
"React.createElement"
|
|
894
|
+
),
|
|
895
|
+
jsx_fragment: inheritable(
|
|
896
|
+
diagnostics,
|
|
897
|
+
topLevelEnv,
|
|
898
|
+
rawEnv,
|
|
899
|
+
"jsx_fragment",
|
|
900
|
+
isString,
|
|
901
|
+
"React.Fragment"
|
|
902
|
+
),
|
|
903
|
+
tsconfig: validateAndNormalizeTsconfig(
|
|
904
|
+
diagnostics,
|
|
905
|
+
topLevelEnv,
|
|
906
|
+
rawEnv,
|
|
907
|
+
configPath
|
|
908
|
+
),
|
|
909
|
+
rules: validateAndNormalizeRules(
|
|
910
|
+
diagnostics,
|
|
911
|
+
topLevelEnv,
|
|
912
|
+
rawEnv,
|
|
913
|
+
deprecatedUpload?.rules,
|
|
914
|
+
envName
|
|
915
|
+
),
|
|
916
|
+
name: inheritableInLegacyEnvironments(
|
|
917
|
+
diagnostics,
|
|
918
|
+
isLegacyEnv,
|
|
919
|
+
topLevelEnv,
|
|
920
|
+
rawEnv,
|
|
921
|
+
"name",
|
|
922
|
+
isValidName,
|
|
923
|
+
appendEnvName(envName),
|
|
924
|
+
undefined
|
|
925
|
+
),
|
|
926
|
+
main: normalizeAndValidateMainField(
|
|
927
|
+
configPath,
|
|
928
|
+
inheritable(
|
|
929
|
+
diagnostics,
|
|
930
|
+
topLevelEnv,
|
|
931
|
+
rawEnv,
|
|
932
|
+
"main",
|
|
933
|
+
isString,
|
|
934
|
+
undefined
|
|
935
|
+
),
|
|
936
|
+
deprecatedUpload
|
|
937
|
+
),
|
|
938
|
+
route,
|
|
939
|
+
routes,
|
|
940
|
+
triggers: inheritable(
|
|
941
|
+
diagnostics,
|
|
942
|
+
topLevelEnv,
|
|
943
|
+
rawEnv,
|
|
944
|
+
"triggers",
|
|
945
|
+
isObjectWith("crons"),
|
|
946
|
+
{ crons: [] }
|
|
947
|
+
),
|
|
948
|
+
usage_model: inheritable(
|
|
949
|
+
diagnostics,
|
|
950
|
+
topLevelEnv,
|
|
951
|
+
rawEnv,
|
|
952
|
+
"usage_model",
|
|
953
|
+
isOneOf("bundled", "unbound"),
|
|
954
|
+
undefined
|
|
955
|
+
),
|
|
956
|
+
build,
|
|
957
|
+
workers_dev,
|
|
958
|
+
// Not inherited fields
|
|
959
|
+
vars: notInheritable(
|
|
960
|
+
diagnostics,
|
|
961
|
+
topLevelEnv,
|
|
962
|
+
rawConfig,
|
|
963
|
+
rawEnv,
|
|
964
|
+
envName,
|
|
965
|
+
"vars",
|
|
966
|
+
validateVars(envName),
|
|
967
|
+
{}
|
|
968
|
+
),
|
|
969
|
+
define: notInheritable(
|
|
970
|
+
diagnostics,
|
|
971
|
+
topLevelEnv,
|
|
972
|
+
rawConfig,
|
|
973
|
+
rawEnv,
|
|
974
|
+
envName,
|
|
975
|
+
"define",
|
|
976
|
+
validateDefines(envName),
|
|
977
|
+
{}
|
|
978
|
+
),
|
|
979
|
+
durable_objects: notInheritable(
|
|
980
|
+
diagnostics,
|
|
981
|
+
topLevelEnv,
|
|
982
|
+
rawConfig,
|
|
983
|
+
rawEnv,
|
|
984
|
+
envName,
|
|
985
|
+
"durable_objects",
|
|
986
|
+
validateBindingsProperty(envName, validateDurableObjectBinding),
|
|
987
|
+
{
|
|
988
|
+
bindings: [],
|
|
989
|
+
}
|
|
990
|
+
),
|
|
991
|
+
kv_namespaces: notInheritable(
|
|
992
|
+
diagnostics,
|
|
993
|
+
topLevelEnv,
|
|
994
|
+
rawConfig,
|
|
995
|
+
rawEnv,
|
|
996
|
+
envName,
|
|
997
|
+
"kv_namespaces",
|
|
998
|
+
validateBindingArray(envName, validateKVBinding),
|
|
999
|
+
[]
|
|
1000
|
+
),
|
|
1001
|
+
r2_buckets: notInheritable(
|
|
1002
|
+
diagnostics,
|
|
1003
|
+
topLevelEnv,
|
|
1004
|
+
rawConfig,
|
|
1005
|
+
rawEnv,
|
|
1006
|
+
envName,
|
|
1007
|
+
"r2_buckets",
|
|
1008
|
+
validateBindingArray(envName, validateR2Binding),
|
|
1009
|
+
[]
|
|
1010
|
+
),
|
|
1011
|
+
services: notInheritable(
|
|
1012
|
+
diagnostics,
|
|
1013
|
+
topLevelEnv,
|
|
1014
|
+
rawConfig,
|
|
1015
|
+
rawEnv,
|
|
1016
|
+
envName,
|
|
1017
|
+
"services",
|
|
1018
|
+
validateBindingArray(envName, validateServiceBinding),
|
|
1019
|
+
[]
|
|
1020
|
+
),
|
|
1021
|
+
worker_namespaces: notInheritable(
|
|
1022
|
+
diagnostics,
|
|
1023
|
+
topLevelEnv,
|
|
1024
|
+
rawConfig,
|
|
1025
|
+
rawEnv,
|
|
1026
|
+
envName,
|
|
1027
|
+
"worker_namespaces",
|
|
1028
|
+
validateBindingArray(envName, validateWorkerNamespaceBinding),
|
|
1029
|
+
[]
|
|
1030
|
+
),
|
|
1031
|
+
unsafe: notInheritable(
|
|
1032
|
+
diagnostics,
|
|
1033
|
+
topLevelEnv,
|
|
1034
|
+
rawConfig,
|
|
1035
|
+
rawEnv,
|
|
1036
|
+
envName,
|
|
1037
|
+
"unsafe",
|
|
1038
|
+
validateBindingsProperty(envName, validateUnsafeBinding),
|
|
1039
|
+
{
|
|
1040
|
+
bindings: [],
|
|
1041
|
+
}
|
|
1042
|
+
),
|
|
1043
|
+
zone_id: rawEnv.zone_id,
|
|
1044
|
+
no_bundle: inheritable(
|
|
1045
|
+
diagnostics,
|
|
1046
|
+
topLevelEnv,
|
|
1047
|
+
rawEnv,
|
|
1048
|
+
"no_bundle",
|
|
1049
|
+
isBoolean,
|
|
1050
|
+
undefined
|
|
1051
|
+
),
|
|
1052
|
+
minify: inheritable(
|
|
1053
|
+
diagnostics,
|
|
1054
|
+
topLevelEnv,
|
|
1055
|
+
rawEnv,
|
|
1056
|
+
"minify",
|
|
1057
|
+
isBoolean,
|
|
1058
|
+
undefined
|
|
1059
|
+
),
|
|
1060
|
+
node_compat: inheritable(
|
|
1061
|
+
diagnostics,
|
|
1062
|
+
topLevelEnv,
|
|
1063
|
+
rawEnv,
|
|
1064
|
+
"node_compat",
|
|
1065
|
+
isBoolean,
|
|
1066
|
+
undefined
|
|
1067
|
+
),
|
|
1068
|
+
};
|
|
1069
|
+
|
|
1070
|
+
return environment;
|
|
971
1071
|
}
|
|
972
1072
|
|
|
973
1073
|
function validateAndNormalizeTsconfig(
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
1074
|
+
diagnostics: Diagnostics,
|
|
1075
|
+
topLevelEnv: Environment | undefined,
|
|
1076
|
+
rawEnv: RawEnvironment,
|
|
1077
|
+
configPath: string | undefined
|
|
978
1078
|
) {
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1079
|
+
const tsconfig = inheritable(
|
|
1080
|
+
diagnostics,
|
|
1081
|
+
topLevelEnv,
|
|
1082
|
+
rawEnv,
|
|
1083
|
+
"tsconfig",
|
|
1084
|
+
isString,
|
|
1085
|
+
undefined
|
|
1086
|
+
);
|
|
1087
|
+
|
|
1088
|
+
return configPath && tsconfig
|
|
1089
|
+
? path.relative(
|
|
1090
|
+
process.cwd(),
|
|
1091
|
+
path.join(path.dirname(configPath), tsconfig)
|
|
1092
|
+
)
|
|
1093
|
+
: tsconfig;
|
|
994
1094
|
}
|
|
995
1095
|
|
|
996
1096
|
const validateAndNormalizeRules = (
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1097
|
+
diagnostics: Diagnostics,
|
|
1098
|
+
topLevelEnv: Environment | undefined,
|
|
1099
|
+
rawEnv: RawEnvironment,
|
|
1100
|
+
deprecatedRules: Rule[] | undefined,
|
|
1101
|
+
envName: string
|
|
1002
1102
|
): Rule[] => {
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1103
|
+
if (topLevelEnv === undefined) {
|
|
1104
|
+
// Only create errors/warnings for the top-level environment
|
|
1105
|
+
if (rawEnv.rules && deprecatedRules) {
|
|
1106
|
+
diagnostics.errors.push(
|
|
1107
|
+
`You cannot configure both [rules] and [build.upload.rules] in your wrangler.toml. Delete the \`build.upload\` section.`
|
|
1108
|
+
);
|
|
1109
|
+
} else if (deprecatedRules) {
|
|
1110
|
+
diagnostics.warnings.push(
|
|
1111
|
+
`Deprecation: The \`build.upload.rules\` config field is no longer used, the rules should be specified via the \`rules\` config field. Delete the \`build.upload\` field from the configuration file, and add this:\n` +
|
|
1112
|
+
"```\n" +
|
|
1113
|
+
TOML.stringify({ rules: deprecatedRules }) +
|
|
1114
|
+
"```"
|
|
1115
|
+
);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
|
|
1119
|
+
return inheritable(
|
|
1120
|
+
diagnostics,
|
|
1121
|
+
topLevelEnv,
|
|
1122
|
+
rawEnv,
|
|
1123
|
+
"rules",
|
|
1124
|
+
validateRules(envName),
|
|
1125
|
+
deprecatedRules ?? []
|
|
1126
|
+
);
|
|
1027
1127
|
};
|
|
1028
1128
|
|
|
1029
1129
|
const validateRules =
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1130
|
+
(envName: string): ValidatorFn =>
|
|
1131
|
+
(diagnostics, field, envValue, config) => {
|
|
1132
|
+
if (!envValue) {
|
|
1133
|
+
return true;
|
|
1134
|
+
}
|
|
1135
|
+
const fieldPath =
|
|
1136
|
+
config === undefined ? `${field}` : `env.${envName}.${field}`;
|
|
1137
|
+
if (!Array.isArray(envValue)) {
|
|
1138
|
+
diagnostics.errors.push(
|
|
1139
|
+
`The field "${fieldPath}" should be an array but got ${JSON.stringify(
|
|
1140
|
+
envValue
|
|
1141
|
+
)}.`
|
|
1142
|
+
);
|
|
1143
|
+
return false;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
let isValid = true;
|
|
1147
|
+
for (let i = 0; i < envValue.length; i++) {
|
|
1148
|
+
isValid =
|
|
1149
|
+
validateRule(diagnostics, `${fieldPath}[${i}]`, envValue[i], config) &&
|
|
1150
|
+
isValid;
|
|
1151
|
+
}
|
|
1152
|
+
return isValid;
|
|
1153
|
+
};
|
|
1054
1154
|
|
|
1055
1155
|
const validateRule: ValidatorFn = (diagnostics, field, value) => {
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1156
|
+
if (typeof value !== "object" || value === null) {
|
|
1157
|
+
diagnostics.errors.push(
|
|
1158
|
+
`"${field}" should be an object but got ${JSON.stringify(value)}.`
|
|
1159
|
+
);
|
|
1160
|
+
return false;
|
|
1161
|
+
}
|
|
1162
|
+
// Rules must have a type string and glob string array, and optionally a fallthrough boolean.
|
|
1163
|
+
let isValid = true;
|
|
1164
|
+
const rule = value as Rule;
|
|
1165
|
+
|
|
1166
|
+
if (
|
|
1167
|
+
!isRequiredProperty(rule, "type", "string", [
|
|
1168
|
+
"ESModule",
|
|
1169
|
+
"CommonJS",
|
|
1170
|
+
"CompiledWasm",
|
|
1171
|
+
"Text",
|
|
1172
|
+
"Data",
|
|
1173
|
+
])
|
|
1174
|
+
) {
|
|
1175
|
+
diagnostics.errors.push(
|
|
1176
|
+
`bindings should have a string "type" field, which contains one of "ESModule", "CommonJS", "CompiledWasm", "Text", or "Data".`
|
|
1177
|
+
);
|
|
1178
|
+
isValid = false;
|
|
1179
|
+
}
|
|
1180
|
+
|
|
1181
|
+
isValid =
|
|
1182
|
+
validateTypedArray(diagnostics, `${field}.globs`, rule.globs, "string") &&
|
|
1183
|
+
isValid;
|
|
1184
|
+
|
|
1185
|
+
if (!isOptionalProperty(rule, "fallthrough", "boolean")) {
|
|
1186
|
+
diagnostics.errors.push(
|
|
1187
|
+
`the field "fallthrough", when present, should be a boolean.`
|
|
1188
|
+
);
|
|
1189
|
+
isValid = false;
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
return isValid;
|
|
1093
1193
|
};
|
|
1094
1194
|
|
|
1195
|
+
const validateDefines =
|
|
1196
|
+
(envName: string): ValidatorFn =>
|
|
1197
|
+
(diagnostics, field, value, config) => {
|
|
1198
|
+
let isValid = true;
|
|
1199
|
+
const fieldPath =
|
|
1200
|
+
config === undefined ? `${field}` : `env.${envName}.${field}`;
|
|
1201
|
+
|
|
1202
|
+
if (typeof value === "object" && value !== null) {
|
|
1203
|
+
for (const varName in value) {
|
|
1204
|
+
// some casting here to appease typescript
|
|
1205
|
+
// even though the value might not match the type
|
|
1206
|
+
if (typeof (value as Record<string, string>)[varName] !== "string") {
|
|
1207
|
+
diagnostics.errors.push(
|
|
1208
|
+
`The field "${fieldPath}.${varName}" should be a string but got ${JSON.stringify(
|
|
1209
|
+
(value as Record<string, string>)[varName]
|
|
1210
|
+
)}.`
|
|
1211
|
+
);
|
|
1212
|
+
isValid = false;
|
|
1213
|
+
}
|
|
1214
|
+
}
|
|
1215
|
+
} else {
|
|
1216
|
+
if (value !== undefined) {
|
|
1217
|
+
diagnostics.errors.push(
|
|
1218
|
+
`The field "${fieldPath}" should be an object but got ${JSON.stringify(
|
|
1219
|
+
value
|
|
1220
|
+
)}.\n`
|
|
1221
|
+
);
|
|
1222
|
+
isValid = false;
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
const configDefines = Object.keys(config?.define ?? {});
|
|
1227
|
+
|
|
1228
|
+
// If there are no top level vars then there is nothing to do here.
|
|
1229
|
+
if (configDefines.length > 0) {
|
|
1230
|
+
if (typeof value === "object" && value !== null) {
|
|
1231
|
+
const configEnvDefines = config === undefined ? [] : Object.keys(value);
|
|
1232
|
+
|
|
1233
|
+
for (const varName of configDefines) {
|
|
1234
|
+
if (!(varName in value)) {
|
|
1235
|
+
diagnostics.warnings.push(
|
|
1236
|
+
`"define.${varName}" exists at the top level, but not on "${fieldPath}".\n` +
|
|
1237
|
+
`This is not what you probably want, since "define" configuration is not inherited by environments.\n` +
|
|
1238
|
+
`Please add "define.${varName}" to "env.${envName}".`
|
|
1239
|
+
);
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
for (const varName of configEnvDefines) {
|
|
1243
|
+
if (!configDefines.includes(varName)) {
|
|
1244
|
+
diagnostics.warnings.push(
|
|
1245
|
+
`"${varName}" exists on "env.${envName}", but not on the top level.\n` +
|
|
1246
|
+
`This is not what you probably want, since "define" configuration within environments can only override existing top level "define" configuration\n` +
|
|
1247
|
+
`Please remove "${fieldPath}.${varName}", or add "define.${varName}".`
|
|
1248
|
+
);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
|
|
1254
|
+
return isValid;
|
|
1255
|
+
};
|
|
1256
|
+
|
|
1095
1257
|
const validateVars =
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1258
|
+
(envName: string): ValidatorFn =>
|
|
1259
|
+
(diagnostics, field, value, config) => {
|
|
1260
|
+
let isValid = true;
|
|
1261
|
+
const fieldPath =
|
|
1262
|
+
config === undefined ? `${field}` : `env.${envName}.${field}`;
|
|
1263
|
+
const configVars = Object.keys(config?.vars ?? {});
|
|
1264
|
+
// If there are no top level vars then there is nothing to do here.
|
|
1265
|
+
if (configVars.length > 0) {
|
|
1266
|
+
if (typeof value !== "object" || value === null) {
|
|
1267
|
+
diagnostics.errors.push(
|
|
1268
|
+
`The field "${fieldPath}" should be an object but got ${JSON.stringify(
|
|
1269
|
+
value
|
|
1270
|
+
)}.\n`
|
|
1271
|
+
);
|
|
1272
|
+
isValid = false;
|
|
1273
|
+
} else {
|
|
1274
|
+
for (const varName of configVars) {
|
|
1275
|
+
if (!(varName in value)) {
|
|
1276
|
+
diagnostics.warnings.push(
|
|
1277
|
+
`"vars.${varName}" exists at the top level, but not on "${fieldPath}".\n` +
|
|
1278
|
+
`This is not what you probably want, since "vars" configuration is not inherited by environments.\n` +
|
|
1279
|
+
`Please add "vars.${varName}" to "env.${envName}".`
|
|
1280
|
+
);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
return isValid;
|
|
1286
|
+
};
|
|
1125
1287
|
|
|
1126
1288
|
const validateBindingsProperty =
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1289
|
+
(envName: string, validateBinding: ValidatorFn): ValidatorFn =>
|
|
1290
|
+
(diagnostics, field, value, config) => {
|
|
1291
|
+
let isValid = true;
|
|
1292
|
+
const fieldPath =
|
|
1293
|
+
config === undefined ? `${field}` : `env.${envName}.${field}`;
|
|
1294
|
+
|
|
1295
|
+
if (value !== undefined) {
|
|
1296
|
+
// Check the validity of the `value` as a bindings container.
|
|
1297
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
1298
|
+
diagnostics.errors.push(
|
|
1299
|
+
`The field "${fieldPath}" should be an object but got ${JSON.stringify(
|
|
1300
|
+
value
|
|
1301
|
+
)}.`
|
|
1302
|
+
);
|
|
1303
|
+
isValid = false;
|
|
1304
|
+
} else if (!hasProperty(value, "bindings")) {
|
|
1305
|
+
diagnostics.errors.push(
|
|
1306
|
+
`The field "${fieldPath}" is missing the required "bindings" property.`
|
|
1307
|
+
);
|
|
1308
|
+
isValid = false;
|
|
1309
|
+
} else if (!Array.isArray(value.bindings)) {
|
|
1310
|
+
diagnostics.errors.push(
|
|
1311
|
+
`The field "${fieldPath}.bindings" should be an array but got ${JSON.stringify(
|
|
1312
|
+
value.bindings
|
|
1313
|
+
)}.`
|
|
1314
|
+
);
|
|
1315
|
+
isValid = false;
|
|
1316
|
+
} else {
|
|
1317
|
+
for (let i = 0; i < value.bindings.length; i++) {
|
|
1318
|
+
const binding = value.bindings[i];
|
|
1319
|
+
const bindingDiagnostics = new Diagnostics(
|
|
1320
|
+
`"${fieldPath}.bindings[${i}]": ${JSON.stringify(binding)}`
|
|
1321
|
+
);
|
|
1322
|
+
isValid =
|
|
1323
|
+
validateBinding(
|
|
1324
|
+
bindingDiagnostics,
|
|
1325
|
+
`${fieldPath}.bindings[${i}]`,
|
|
1326
|
+
binding,
|
|
1327
|
+
config
|
|
1328
|
+
) && isValid;
|
|
1329
|
+
diagnostics.addChild(bindingDiagnostics);
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
const configBindingNames = getBindingNames(
|
|
1334
|
+
config?.[field as keyof Environment]
|
|
1335
|
+
);
|
|
1336
|
+
if (isValid && configBindingNames.length > 0) {
|
|
1337
|
+
// If there are top level bindings then check that they all appear in the environment.
|
|
1338
|
+
const envBindingNames = new Set(getBindingNames(value));
|
|
1339
|
+
const missingBindings = configBindingNames.filter(
|
|
1340
|
+
(name) => !envBindingNames.has(name)
|
|
1341
|
+
);
|
|
1342
|
+
if (missingBindings.length > 0) {
|
|
1343
|
+
diagnostics.warnings.push(
|
|
1344
|
+
`The following bindings are at the top level, but not on "env.${envName}".\n` +
|
|
1345
|
+
`This is not what you probably want, since "${field}" configuration is not inherited by environments.\n` +
|
|
1346
|
+
`Please add a binding for each to "${fieldPath}.bindings":\n` +
|
|
1347
|
+
missingBindings.map((name) => `- ${name}`).join("\n")
|
|
1348
|
+
);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
return isValid;
|
|
1353
|
+
};
|
|
1192
1354
|
|
|
1193
1355
|
/**
|
|
1194
1356
|
* Check that the given field is a valid "durable_object" binding object.
|
|
1195
1357
|
*/
|
|
1196
1358
|
const validateDurableObjectBinding: ValidatorFn = (
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1359
|
+
diagnostics,
|
|
1360
|
+
field,
|
|
1361
|
+
value
|
|
1200
1362
|
) => {
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1363
|
+
if (typeof value !== "object" || value === null) {
|
|
1364
|
+
diagnostics.errors.push(
|
|
1365
|
+
`Expected "${field}" to be an object but got ${JSON.stringify(value)}`
|
|
1366
|
+
);
|
|
1367
|
+
return false;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
// Durable Object bindings must have a name and class_name, and optionally a script_name and an environment.
|
|
1371
|
+
let isValid = true;
|
|
1372
|
+
if (!isRequiredProperty(value, "name", "string")) {
|
|
1373
|
+
diagnostics.errors.push(`binding should have a string "name" field.`);
|
|
1374
|
+
isValid = false;
|
|
1375
|
+
}
|
|
1376
|
+
if (!isRequiredProperty(value, "class_name", "string")) {
|
|
1377
|
+
diagnostics.errors.push(`binding should have a string "class_name" field.`);
|
|
1378
|
+
isValid = false;
|
|
1379
|
+
}
|
|
1380
|
+
if (!isOptionalProperty(value, "script_name", "string")) {
|
|
1381
|
+
diagnostics.errors.push(
|
|
1382
|
+
`the field "script_name", when present, should be a string.`
|
|
1383
|
+
);
|
|
1384
|
+
isValid = false;
|
|
1385
|
+
}
|
|
1386
|
+
// environment requires a script_name
|
|
1387
|
+
if (!isOptionalProperty(value, "environment", "string")) {
|
|
1388
|
+
diagnostics.errors.push(
|
|
1389
|
+
`the field "environment", when present, should be a string.`
|
|
1390
|
+
);
|
|
1391
|
+
isValid = false;
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
if ("environment" in value && !("script_name" in value)) {
|
|
1395
|
+
diagnostics.errors.push(
|
|
1396
|
+
`binding should have a "script_name" field if "environment" is present.`
|
|
1397
|
+
);
|
|
1398
|
+
isValid = false;
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
return isValid;
|
|
1240
1402
|
};
|
|
1241
1403
|
|
|
1242
1404
|
/**
|
|
@@ -1245,173 +1407,173 @@ const validateDurableObjectBinding: ValidatorFn = (
|
|
|
1245
1407
|
* TODO: further validation of known unsafe bindings.
|
|
1246
1408
|
*/
|
|
1247
1409
|
const validateUnsafeBinding: ValidatorFn = (diagnostics, field, value) => {
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1410
|
+
if (typeof value !== "object" || value === null) {
|
|
1411
|
+
diagnostics.errors.push(
|
|
1412
|
+
`Expected ${field} to be an object but got ${JSON.stringify(value)}.`
|
|
1413
|
+
);
|
|
1414
|
+
return false;
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
let isValid = true;
|
|
1418
|
+
// Unsafe bindings must have a name and type.
|
|
1419
|
+
if (!isRequiredProperty(value, "name", "string")) {
|
|
1420
|
+
diagnostics.errors.push(`binding should have a string "name" field.`);
|
|
1421
|
+
isValid = false;
|
|
1422
|
+
}
|
|
1423
|
+
if (isRequiredProperty(value, "type", "string")) {
|
|
1424
|
+
const safeBindings = [
|
|
1425
|
+
"plain_text",
|
|
1426
|
+
"json",
|
|
1427
|
+
"wasm_module",
|
|
1428
|
+
"data_blob",
|
|
1429
|
+
"text_blob",
|
|
1430
|
+
"kv_namespace",
|
|
1431
|
+
"durable_object_namespace",
|
|
1432
|
+
"r2_bucket",
|
|
1433
|
+
"service",
|
|
1434
|
+
];
|
|
1435
|
+
|
|
1436
|
+
if (safeBindings.includes(value.type)) {
|
|
1437
|
+
diagnostics.warnings.push(
|
|
1438
|
+
`The binding type "${value.type}" is directly supported by wrangler.\n` +
|
|
1439
|
+
`Consider migrating this unsafe binding to a format for '${value.type}' bindings that is supported by wrangler for optimal support.\n` +
|
|
1440
|
+
"For more details, see https://developers.cloudflare.com/workers/cli-wrangler/configuration"
|
|
1441
|
+
);
|
|
1442
|
+
}
|
|
1443
|
+
} else {
|
|
1444
|
+
diagnostics.errors.push(`binding should have a string "type" field.`);
|
|
1445
|
+
isValid = false;
|
|
1446
|
+
}
|
|
1447
|
+
return isValid;
|
|
1286
1448
|
};
|
|
1287
1449
|
|
|
1288
1450
|
/**
|
|
1289
1451
|
* Check that the given environment field is a valid array of bindings.
|
|
1290
1452
|
*/
|
|
1291
1453
|
const validateBindingArray =
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1454
|
+
(envName: string, validateBinding: ValidatorFn): ValidatorFn =>
|
|
1455
|
+
(diagnostics, field, envValue, config) => {
|
|
1456
|
+
if (envValue === undefined) {
|
|
1457
|
+
return true;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
const fieldPath =
|
|
1461
|
+
config === undefined ? `${field}` : `env.${envName}.${field}`;
|
|
1462
|
+
if (!Array.isArray(envValue)) {
|
|
1463
|
+
diagnostics.errors.push(
|
|
1464
|
+
`The field "${fieldPath}" should be an array but got ${JSON.stringify(
|
|
1465
|
+
envValue
|
|
1466
|
+
)}.`
|
|
1467
|
+
);
|
|
1468
|
+
return false;
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
let isValid = true;
|
|
1472
|
+
for (let i = 0; i < envValue.length; i++) {
|
|
1473
|
+
isValid =
|
|
1474
|
+
validateBinding(
|
|
1475
|
+
diagnostics,
|
|
1476
|
+
`${fieldPath}[${i}]`,
|
|
1477
|
+
envValue[i],
|
|
1478
|
+
config
|
|
1479
|
+
) && isValid;
|
|
1480
|
+
}
|
|
1481
|
+
const configValue = config?.[field as keyof Environment] as {
|
|
1482
|
+
binding: unknown;
|
|
1483
|
+
}[];
|
|
1484
|
+
if (Array.isArray(configValue)) {
|
|
1485
|
+
const configBindingNames = configValue.map((value) => value.binding);
|
|
1486
|
+
// If there are no top level bindings then there is nothing to do here.
|
|
1487
|
+
if (configBindingNames.length > 0) {
|
|
1488
|
+
const envBindingNames = new Set(envValue.map((value) => value.binding));
|
|
1489
|
+
for (const configBindingName of configBindingNames) {
|
|
1490
|
+
if (!envBindingNames.has(configBindingName)) {
|
|
1491
|
+
diagnostics.warnings.push(
|
|
1492
|
+
`There is a ${field} binding with name "${configBindingName}" at the top level, but not on "env.${envName}".\n` +
|
|
1493
|
+
`This is not what you probably want, since "${field}" configuration is not inherited by environments.\n` +
|
|
1494
|
+
`Please add a binding for "${configBindingName}" to "env.${envName}.${field}.bindings".`
|
|
1495
|
+
);
|
|
1496
|
+
}
|
|
1497
|
+
}
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
return isValid;
|
|
1501
|
+
};
|
|
1340
1502
|
|
|
1341
1503
|
const validateKVBinding: ValidatorFn = (diagnostics, field, value) => {
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1504
|
+
if (typeof value !== "object" || value === null) {
|
|
1505
|
+
diagnostics.errors.push(
|
|
1506
|
+
`"kv_namespaces" bindings should be objects, but got ${JSON.stringify(
|
|
1507
|
+
value
|
|
1508
|
+
)}`
|
|
1509
|
+
);
|
|
1510
|
+
return false;
|
|
1511
|
+
}
|
|
1512
|
+
let isValid = true;
|
|
1513
|
+
// KV bindings must have a binding and id.
|
|
1514
|
+
if (!isRequiredProperty(value, "binding", "string")) {
|
|
1515
|
+
diagnostics.errors.push(
|
|
1516
|
+
`"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
|
|
1517
|
+
value
|
|
1518
|
+
)}.`
|
|
1519
|
+
);
|
|
1520
|
+
isValid = false;
|
|
1521
|
+
}
|
|
1522
|
+
if (!isRequiredProperty(value, "id", "string")) {
|
|
1523
|
+
diagnostics.errors.push(
|
|
1524
|
+
`"${field}" bindings should have a string "id" field but got ${JSON.stringify(
|
|
1525
|
+
value
|
|
1526
|
+
)}.`
|
|
1527
|
+
);
|
|
1528
|
+
isValid = false;
|
|
1529
|
+
}
|
|
1530
|
+
if (!isOptionalProperty(value, "preview_id", "string")) {
|
|
1531
|
+
diagnostics.errors.push(
|
|
1532
|
+
`"${field}" bindings should, optionally, have a string "preview_id" field but got ${JSON.stringify(
|
|
1533
|
+
value
|
|
1534
|
+
)}.`
|
|
1535
|
+
);
|
|
1536
|
+
isValid = false;
|
|
1537
|
+
}
|
|
1538
|
+
return isValid;
|
|
1377
1539
|
};
|
|
1378
1540
|
|
|
1379
1541
|
const validateR2Binding: ValidatorFn = (diagnostics, field, value) => {
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1542
|
+
if (typeof value !== "object" || value === null) {
|
|
1543
|
+
diagnostics.errors.push(
|
|
1544
|
+
`"r2_buckets" bindings should be objects, but got ${JSON.stringify(
|
|
1545
|
+
value
|
|
1546
|
+
)}`
|
|
1547
|
+
);
|
|
1548
|
+
return false;
|
|
1549
|
+
}
|
|
1550
|
+
let isValid = true;
|
|
1551
|
+
// R2 bindings must have a binding and bucket_name.
|
|
1552
|
+
if (!isRequiredProperty(value, "binding", "string")) {
|
|
1553
|
+
diagnostics.errors.push(
|
|
1554
|
+
`"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
|
|
1555
|
+
value
|
|
1556
|
+
)}.`
|
|
1557
|
+
);
|
|
1558
|
+
isValid = false;
|
|
1559
|
+
}
|
|
1560
|
+
if (!isRequiredProperty(value, "bucket_name", "string")) {
|
|
1561
|
+
diagnostics.errors.push(
|
|
1562
|
+
`"${field}" bindings should have a string "bucket_name" field but got ${JSON.stringify(
|
|
1563
|
+
value
|
|
1564
|
+
)}.`
|
|
1565
|
+
);
|
|
1566
|
+
isValid = false;
|
|
1567
|
+
}
|
|
1568
|
+
if (!isOptionalProperty(value, "preview_bucket_name", "string")) {
|
|
1569
|
+
diagnostics.errors.push(
|
|
1570
|
+
`"${field}" bindings should, optionally, have a string "preview_bucket_name" field but got ${JSON.stringify(
|
|
1571
|
+
value
|
|
1572
|
+
)}.`
|
|
1573
|
+
);
|
|
1574
|
+
isValid = false;
|
|
1575
|
+
}
|
|
1576
|
+
return isValid;
|
|
1415
1577
|
};
|
|
1416
1578
|
|
|
1417
1579
|
/**
|
|
@@ -1423,126 +1585,161 @@ const validateR2Binding: ValidatorFn = (diagnostics, field, value) => {
|
|
|
1423
1585
|
* the `DATA` global).
|
|
1424
1586
|
*/
|
|
1425
1587
|
const validateBindingsHaveUniqueNames = (
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1588
|
+
diagnostics: Diagnostics,
|
|
1589
|
+
{
|
|
1590
|
+
durable_objects,
|
|
1591
|
+
kv_namespaces,
|
|
1592
|
+
r2_buckets,
|
|
1593
|
+
text_blobs,
|
|
1594
|
+
unsafe,
|
|
1595
|
+
vars,
|
|
1596
|
+
define,
|
|
1597
|
+
wasm_modules,
|
|
1598
|
+
data_blobs,
|
|
1599
|
+
}: Partial<Config>
|
|
1437
1600
|
): boolean => {
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1601
|
+
let hasDuplicates = false;
|
|
1602
|
+
|
|
1603
|
+
const bindingsGroupedByType = {
|
|
1604
|
+
"Durable Object": getBindingNames(durable_objects),
|
|
1605
|
+
"KV Namespace": getBindingNames(kv_namespaces),
|
|
1606
|
+
"R2 Bucket": getBindingNames(r2_buckets),
|
|
1607
|
+
"Text Blob": getBindingNames(text_blobs),
|
|
1608
|
+
Unsafe: getBindingNames(unsafe),
|
|
1609
|
+
"Environment Variable": getBindingNames(vars),
|
|
1610
|
+
Definition: getBindingNames(define),
|
|
1611
|
+
"WASM Module": getBindingNames(wasm_modules),
|
|
1612
|
+
"Data Blob": getBindingNames(data_blobs),
|
|
1613
|
+
} as Record<string, string[]>;
|
|
1614
|
+
|
|
1615
|
+
const bindingsGroupedByName: Record<string, string[]> = {};
|
|
1616
|
+
|
|
1617
|
+
for (const bindingType in bindingsGroupedByType) {
|
|
1618
|
+
const bindingNames = bindingsGroupedByType[bindingType];
|
|
1619
|
+
|
|
1620
|
+
for (const bindingName of bindingNames) {
|
|
1621
|
+
if (!(bindingName in bindingsGroupedByName)) {
|
|
1622
|
+
bindingsGroupedByName[bindingName] = [];
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
bindingsGroupedByName[bindingName].push(bindingType);
|
|
1626
|
+
}
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
for (const bindingName in bindingsGroupedByName) {
|
|
1630
|
+
const bindingTypes = bindingsGroupedByName[bindingName];
|
|
1631
|
+
if (bindingTypes.length < 2) {
|
|
1632
|
+
// there's only one (or zero) binding(s) with this name, which is fine, actually
|
|
1633
|
+
continue;
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
hasDuplicates = true;
|
|
1637
|
+
|
|
1638
|
+
// there's two types of duplicates we want to look for:
|
|
1639
|
+
// - bindings with the same name of the same type (e.g. two Durable Objects both named "OBJ")
|
|
1640
|
+
// - bindings with the same name of different types (a KV namespace and DO both named "DATA")
|
|
1641
|
+
|
|
1642
|
+
const sameType = bindingTypes
|
|
1643
|
+
// filter once to find duplicate binding types
|
|
1644
|
+
.filter((type, i) => bindingTypes.indexOf(type) !== i)
|
|
1645
|
+
// filter twice to only get _unique_ duplicate binding types
|
|
1646
|
+
.filter(
|
|
1647
|
+
(type, i, duplicateBindingTypes) =>
|
|
1648
|
+
duplicateBindingTypes.indexOf(type) === i
|
|
1649
|
+
);
|
|
1650
|
+
|
|
1651
|
+
const differentTypes = bindingTypes.filter(
|
|
1652
|
+
(type, i) => bindingTypes.indexOf(type) === i
|
|
1653
|
+
);
|
|
1654
|
+
|
|
1655
|
+
if (differentTypes.length > 1) {
|
|
1656
|
+
// we have multiple different types using the same name
|
|
1657
|
+
diagnostics.errors.push(
|
|
1658
|
+
`${bindingName} assigned to ${ENGLISH.format(differentTypes)} bindings.`
|
|
1659
|
+
);
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
sameType.forEach((bindingType) => {
|
|
1663
|
+
diagnostics.errors.push(
|
|
1664
|
+
`${bindingName} assigned to multiple ${bindingType} bindings.`
|
|
1665
|
+
);
|
|
1666
|
+
});
|
|
1667
|
+
}
|
|
1668
|
+
|
|
1669
|
+
if (hasDuplicates) {
|
|
1670
|
+
const problem =
|
|
1671
|
+
"Bindings must have unique names, so that they can all be referenced in the worker.";
|
|
1672
|
+
const resolution = "Please change your bindings to have unique names.";
|
|
1673
|
+
diagnostics.errors.push(`${problem}\n${resolution}`);
|
|
1674
|
+
}
|
|
1675
|
+
|
|
1676
|
+
return !hasDuplicates;
|
|
1513
1677
|
};
|
|
1678
|
+
|
|
1514
1679
|
const validateServiceBinding: ValidatorFn = (diagnostics, field, value) => {
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1680
|
+
if (typeof value !== "object" || value === null) {
|
|
1681
|
+
diagnostics.errors.push(
|
|
1682
|
+
`"services" bindings should be objects, but got ${JSON.stringify(value)}`
|
|
1683
|
+
);
|
|
1684
|
+
return false;
|
|
1685
|
+
}
|
|
1686
|
+
let isValid = true;
|
|
1687
|
+
// Service bindings must have a binding, service, and environment.
|
|
1688
|
+
if (!isRequiredProperty(value, "binding", "string")) {
|
|
1689
|
+
diagnostics.errors.push(
|
|
1690
|
+
`"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
|
|
1691
|
+
value
|
|
1692
|
+
)}.`
|
|
1693
|
+
);
|
|
1694
|
+
isValid = false;
|
|
1695
|
+
}
|
|
1696
|
+
if (!isRequiredProperty(value, "service", "string")) {
|
|
1697
|
+
diagnostics.errors.push(
|
|
1698
|
+
`"${field}" bindings should have a string "service" field but got ${JSON.stringify(
|
|
1699
|
+
value
|
|
1700
|
+
)}.`
|
|
1701
|
+
);
|
|
1702
|
+
isValid = false;
|
|
1703
|
+
}
|
|
1704
|
+
if (!isOptionalProperty(value, "environment", "string")) {
|
|
1705
|
+
diagnostics.errors.push(
|
|
1706
|
+
`"${field}" bindings should have a string "environment" field but got ${JSON.stringify(
|
|
1707
|
+
value
|
|
1708
|
+
)}.`
|
|
1709
|
+
);
|
|
1710
|
+
isValid = false;
|
|
1711
|
+
}
|
|
1712
|
+
return isValid;
|
|
1713
|
+
};
|
|
1714
|
+
|
|
1715
|
+
const validateWorkerNamespaceBinding: ValidatorFn = (
|
|
1716
|
+
diagnostics,
|
|
1717
|
+
field,
|
|
1718
|
+
value
|
|
1719
|
+
) => {
|
|
1720
|
+
if (typeof value !== "object" || value === null) {
|
|
1721
|
+
diagnostics.errors.push(
|
|
1722
|
+
`"${field}" binding should be objects, but got ${JSON.stringify(value)}`
|
|
1723
|
+
);
|
|
1724
|
+
return false;
|
|
1725
|
+
}
|
|
1726
|
+
let isValid = true;
|
|
1727
|
+
// Worker namespace bindings must have a binding, and a namespace.
|
|
1728
|
+
if (!isRequiredProperty(value, "binding", "string")) {
|
|
1729
|
+
diagnostics.errors.push(
|
|
1730
|
+
`"${field}" should have a string "binding" field but got ${JSON.stringify(
|
|
1731
|
+
value
|
|
1732
|
+
)}.`
|
|
1733
|
+
);
|
|
1734
|
+
isValid = false;
|
|
1735
|
+
}
|
|
1736
|
+
if (!isRequiredProperty(value, "namespace", "string")) {
|
|
1737
|
+
diagnostics.errors.push(
|
|
1738
|
+
`"${field}" should have a string "namespace" field but got ${JSON.stringify(
|
|
1739
|
+
value
|
|
1740
|
+
)}.`
|
|
1741
|
+
);
|
|
1742
|
+
isValid = false;
|
|
1743
|
+
}
|
|
1744
|
+
return isValid;
|
|
1548
1745
|
};
|