wrangler 0.0.0-e9307365 → 0.0.0-e94b46ff7

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