wrangler 0.0.0-e2b7352 → 0.0.0-e305903a

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