wrangler 0.0.0-ece06ea → 0.0.0-ed4f2ef

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/README.md +3 -3
  2. package/bin/wrangler.js +12 -3
  3. package/miniflare-dist/index.mjs +79 -0
  4. package/miniflare-dist/index.mjs.map +7 -0
  5. package/package.json +49 -22
  6. package/pages/functions/buildWorker.ts +62 -0
  7. package/pages/functions/filepath-routing.test.ts +223 -0
  8. package/pages/functions/filepath-routing.ts +181 -0
  9. package/pages/functions/identifiers.ts +78 -0
  10. package/pages/functions/routes.ts +151 -0
  11. package/pages/functions/template-worker.ts +130 -0
  12. package/src/__tests__/configuration.test.ts +2874 -0
  13. package/src/__tests__/dev.test.tsx +588 -0
  14. package/src/__tests__/guess-worker-format.test.ts +83 -0
  15. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  16. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  17. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  18. package/src/__tests__/helpers/mock-account-id.ts +48 -0
  19. package/src/__tests__/helpers/mock-bin.ts +36 -0
  20. package/src/__tests__/helpers/mock-cfetch.ts +207 -0
  21. package/src/__tests__/helpers/mock-console.ts +70 -0
  22. package/src/__tests__/helpers/mock-dialogs.ts +65 -0
  23. package/src/__tests__/helpers/mock-kv.ts +33 -0
  24. package/src/__tests__/helpers/mock-oauth-flow.ts +178 -0
  25. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  26. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  27. package/src/__tests__/helpers/run-in-tmp.ts +32 -0
  28. package/src/__tests__/helpers/run-wrangler.ts +16 -0
  29. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  30. package/src/__tests__/https-options.test.ts +127 -0
  31. package/src/__tests__/index.test.ts +953 -119
  32. package/src/__tests__/jest.setup.ts +74 -0
  33. package/src/__tests__/kv.test.ts +1380 -0
  34. package/src/__tests__/package-manager.test.ts +206 -0
  35. package/src/__tests__/pages.test.ts +180 -0
  36. package/src/__tests__/parse.test.ts +322 -0
  37. package/src/__tests__/publish.test.ts +3946 -0
  38. package/src/__tests__/r2.test.ts +198 -0
  39. package/src/__tests__/route.test.ts +45 -0
  40. package/src/__tests__/secret.test.ts +425 -0
  41. package/src/__tests__/sentry.test.ts +146 -0
  42. package/src/__tests__/tail.test.ts +638 -0
  43. package/src/__tests__/user.test.ts +83 -0
  44. package/src/__tests__/whoami.test.tsx +95 -0
  45. package/src/bundle.ts +155 -0
  46. package/src/cfetch/index.ts +104 -0
  47. package/src/cfetch/internal.ts +139 -0
  48. package/src/cli.ts +18 -7
  49. package/src/config/README.md +107 -0
  50. package/src/config/config.ts +229 -0
  51. package/src/config/diagnostics.ts +80 -0
  52. package/src/config/environment.ts +371 -0
  53. package/src/config/index.ts +62 -0
  54. package/src/config/validation-helpers.ts +557 -0
  55. package/src/config/validation.ts +1240 -0
  56. package/src/create-worker-preview.ts +173 -0
  57. package/src/create-worker-upload-form.ts +240 -0
  58. package/src/dev/dev.tsx +413 -0
  59. package/src/dev/local.tsx +287 -0
  60. package/src/dev/remote.tsx +209 -0
  61. package/src/dev/use-esbuild.ts +109 -0
  62. package/src/dialogs.tsx +6 -14
  63. package/src/entry.ts +256 -0
  64. package/src/environment-variables.ts +33 -0
  65. package/src/errors.ts +11 -0
  66. package/src/https-options.ts +122 -0
  67. package/src/index.tsx +1503 -959
  68. package/src/inspect.ts +624 -0
  69. package/src/intl-polyfill.d.ts +139 -0
  70. package/src/kv.ts +319 -0
  71. package/src/miniflare-cli/README.md +30 -0
  72. package/src/miniflare-cli/enum-keys.ts +17 -0
  73. package/src/miniflare-cli/index.ts +38 -0
  74. package/src/module-collection.ts +257 -0
  75. package/src/open-in-browser.ts +25 -0
  76. package/src/package-manager.ts +126 -0
  77. package/src/pages.tsx +1074 -212
  78. package/src/parse.ts +183 -0
  79. package/src/paths.ts +26 -0
  80. package/src/proxy.ts +455 -0
  81. package/src/publish.ts +326 -295
  82. package/src/r2.ts +50 -0
  83. package/src/reporting.ts +131 -0
  84. package/src/selfsigned.d.ts +29 -0
  85. package/src/sites.tsx +224 -59
  86. package/src/tail/filters.ts +279 -0
  87. package/src/tail/index.ts +299 -0
  88. package/src/tail/printing.ts +62 -0
  89. package/src/user.tsx +340 -203
  90. package/src/whoami.tsx +69 -0
  91. package/src/worker.ts +172 -0
  92. package/templates/new-worker.js +15 -0
  93. package/templates/new-worker.ts +15 -0
  94. package/{static-asset-facade.js → templates/static-asset-facade.js} +1 -1
  95. package/templates/tsconfig.json +105 -0
  96. package/wrangler-dist/cli.js +136988 -131174
  97. package/wrangler-dist/cli.js.map +3 -3
  98. package/src/__tests__/fixtures/init/.gitkeep +0 -0
  99. package/src/__tests__/mock-cfetch.js +0 -46
  100. package/src/api/form_data.ts +0 -158
  101. package/src/api/inspect.ts +0 -441
  102. package/src/api/preview.ts +0 -123
  103. package/src/api/worker.ts +0 -161
  104. package/src/cfetch.ts +0 -72
  105. package/src/config.ts +0 -124
  106. package/src/dev.tsx +0 -736
  107. package/src/kv.tsx +0 -211
  108. package/src/tail.tsx +0 -71
  109. package/src/util/fetch.ts +0 -74
@@ -0,0 +1,1240 @@
1
+ import path from "node:path";
2
+ import TOML from "@iarna/toml";
3
+ import { Diagnostics } from "./diagnostics";
4
+ import {
5
+ deprecated,
6
+ experimental,
7
+ hasProperty,
8
+ inheritable,
9
+ isBoolean,
10
+ isObjectWith,
11
+ isOneOf,
12
+ isOptionalProperty,
13
+ isRequiredProperty,
14
+ isString,
15
+ isStringArray,
16
+ validateAdditionalProperties,
17
+ notInheritable,
18
+ validateOptionalProperty,
19
+ validateOptionalTypedArray,
20
+ validateRequiredProperty,
21
+ validateTypedArray,
22
+ all,
23
+ isMutuallyExclusiveWith,
24
+ inheritableInLegacyEnvironments,
25
+ appendEnvName,
26
+ getBindingNames,
27
+ } from "./validation-helpers";
28
+ import type { Config, DevConfig, RawConfig, RawDevConfig } from "./config";
29
+ import type {
30
+ RawEnvironment,
31
+ DeprecatedUpload,
32
+ Environment,
33
+ Rule,
34
+ } from "./environment";
35
+ import type { ValidatorFn } from "./validation-helpers";
36
+
37
+ const ENGLISH = new Intl.ListFormat("en");
38
+
39
+ /**
40
+ * Validate the given `rawConfig` object that was loaded from `configPath`.
41
+ *
42
+ * The configuration is normalized, which includes using default values for missing field,
43
+ * and copying over inheritable fields into named environments.
44
+ *
45
+ * Any errors or warnings from the validation are available in the returned `diagnostics` object.
46
+ */
47
+ export function normalizeAndValidateConfig(
48
+ rawConfig: RawConfig,
49
+ configPath: string | undefined,
50
+ args: unknown
51
+ ): {
52
+ config: Config;
53
+ diagnostics: Diagnostics;
54
+ } {
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
+ data_blobs: normalizeAndValidateModulePaths(
186
+ diagnostics,
187
+ configPath,
188
+ "data_blobs",
189
+ rawConfig.data_blobs
190
+ ),
191
+ };
192
+
193
+ validateBindingsHaveUniqueNames(diagnostics, config);
194
+
195
+ validateAdditionalProperties(
196
+ diagnostics,
197
+ "top-level",
198
+ Object.keys(rawConfig),
199
+ [...Object.keys(config), "env", "miniflare"]
200
+ );
201
+
202
+ return { config, diagnostics };
203
+ }
204
+
205
+ /**
206
+ * Validate the `build` configuration and return the normalized values.
207
+ */
208
+ function normalizeAndValidateBuild(
209
+ diagnostics: Diagnostics,
210
+ rawEnv: RawEnvironment,
211
+ rawBuild: Config["build"],
212
+ configPath: string | undefined
213
+ ): Config["build"] & { deprecatedUpload: DeprecatedUpload } {
214
+ const { command, cwd, watch_dir, upload, ...rest } = rawBuild;
215
+ const deprecatedUpload: DeprecatedUpload = { ...upload };
216
+ validateAdditionalProperties(diagnostics, "build", Object.keys(rest), []);
217
+
218
+ validateOptionalProperty(diagnostics, "build", "command", command, "string");
219
+ validateOptionalProperty(diagnostics, "build", "cwd", cwd, "string");
220
+ validateOptionalProperty(
221
+ diagnostics,
222
+ "build",
223
+ "watch_dir",
224
+ watch_dir,
225
+ "string"
226
+ );
227
+
228
+ deprecated(
229
+ diagnostics,
230
+ rawEnv,
231
+ "build.upload.format",
232
+ "The format is inferred automatically from the code.",
233
+ true
234
+ );
235
+
236
+ if (rawEnv.main !== undefined && rawBuild.upload?.main) {
237
+ diagnostics.errors.push(
238
+ `Don't define both the \`main\` and \`build.upload.main\` fields in your configuration.\n` +
239
+ `They serve the same purpose: to point to the entry-point of your worker.\n` +
240
+ `Delete the \`build.upload.main\` and \`build.upload.dir\` field from your config.`
241
+ );
242
+ } else {
243
+ deprecated(
244
+ diagnostics,
245
+ rawEnv,
246
+ "build.upload.main",
247
+ `Delete the \`build.upload.main\` and \`build.upload.dir\` fields.\n` +
248
+ `Then add the top level \`main\` field to your configuration file:\n` +
249
+ `\`\`\`\n` +
250
+ `main = "${path.join(
251
+ rawBuild.upload?.dir ?? "./dist",
252
+ rawBuild.upload?.main ?? "."
253
+ )}"\n` +
254
+ `\`\`\``,
255
+ true
256
+ );
257
+
258
+ deprecated(
259
+ diagnostics,
260
+ rawEnv,
261
+ "build.upload.dir",
262
+ `Use the top level "main" field or a command-line argument to specify the entry-point for the Worker.`,
263
+ true
264
+ );
265
+ }
266
+
267
+ return {
268
+ command,
269
+ watch_dir:
270
+ // - `watch_dir` only matters when `command` is defined, so we apply
271
+ // a default only when `command` is defined
272
+ // - `configPath` will always be defined since `build` can only
273
+ // be configured in `wrangler.toml`, but who knows, that may
274
+ // change in the future, so we do a check anyway
275
+ command
276
+ ? configPath
277
+ ? path.relative(
278
+ process.cwd(),
279
+ path.join(path.dirname(configPath), watch_dir || "./src")
280
+ )
281
+ : watch_dir || "./src"
282
+ : watch_dir,
283
+ cwd,
284
+ deprecatedUpload,
285
+ };
286
+ }
287
+
288
+ /**
289
+ * Validate the `main` field and return the normalized values.
290
+ */
291
+ function normalizeAndValidateMainField(
292
+ configPath: string | undefined,
293
+ rawMain: string | undefined,
294
+ deprecatedUpload: DeprecatedUpload | undefined
295
+ ): string | undefined {
296
+ const configDir = path.dirname(configPath ?? "wrangler.toml");
297
+ if (rawMain !== undefined) {
298
+ if (typeof rawMain === "string") {
299
+ const directory = path.resolve(configDir);
300
+ return path.resolve(directory, rawMain);
301
+ } else {
302
+ return rawMain;
303
+ }
304
+ } else if (deprecatedUpload?.main !== undefined) {
305
+ const directory = path.resolve(
306
+ configDir,
307
+ deprecatedUpload?.dir || "./dist"
308
+ );
309
+ return path.resolve(directory, deprecatedUpload.main);
310
+ } else {
311
+ return;
312
+ }
313
+ }
314
+
315
+ /**
316
+ * Validate the `dev` configuration and return the normalized values.
317
+ */
318
+ function normalizeAndValidateDev(
319
+ diagnostics: Diagnostics,
320
+ rawDev: RawDevConfig
321
+ ): DevConfig {
322
+ const {
323
+ ip = "localhost",
324
+ port = 8787,
325
+ local_protocol = "http",
326
+ upstream_protocol = "https",
327
+ host,
328
+ ...rest
329
+ } = rawDev;
330
+ validateAdditionalProperties(diagnostics, "dev", Object.keys(rest), []);
331
+
332
+ validateOptionalProperty(diagnostics, "dev", "ip", ip, "string");
333
+ validateOptionalProperty(diagnostics, "dev", "port", port, "number");
334
+ validateOptionalProperty(
335
+ diagnostics,
336
+ "dev",
337
+ "local_protocol",
338
+ local_protocol,
339
+ "string",
340
+ ["http", "https"]
341
+ );
342
+ validateOptionalProperty(
343
+ diagnostics,
344
+ "dev",
345
+ "upstream_protocol",
346
+ upstream_protocol,
347
+ "string",
348
+ ["http", "https"]
349
+ );
350
+ validateOptionalProperty(diagnostics, "dev", "host", host, "string");
351
+ return { ip, port, local_protocol, upstream_protocol, host };
352
+ }
353
+
354
+ /**
355
+ * Validate the `migrations` configuration and return the normalized values.
356
+ */
357
+ function normalizeAndValidateMigrations(
358
+ diagnostics: Diagnostics,
359
+ rawMigrations: Config["migrations"]
360
+ ): Config["migrations"] {
361
+ if (!Array.isArray(rawMigrations)) {
362
+ diagnostics.errors.push(
363
+ `The optional "migrations" field should be an array, but got ${JSON.stringify(
364
+ rawMigrations
365
+ )}`
366
+ );
367
+ return [];
368
+ } else {
369
+ for (let i = 0; i < rawMigrations.length; i++) {
370
+ const migration = rawMigrations[i];
371
+ validateRequiredProperty(
372
+ diagnostics,
373
+ `migrations[${i}]`,
374
+ `tag`,
375
+ migration.tag,
376
+ "string"
377
+ );
378
+ validateOptionalTypedArray(
379
+ diagnostics,
380
+ `migrations[${i}].new_classes`,
381
+ migration.new_classes,
382
+ "string"
383
+ );
384
+ if (migration.renamed_classes !== undefined) {
385
+ if (!Array.isArray(migration.renamed_classes)) {
386
+ diagnostics.errors.push(
387
+ `Expected "migrations[${i}].renamed_classes" to be an array of "{from: string, to: string}" objects but got ${JSON.stringify(
388
+ migration.renamed_classes
389
+ )}.`
390
+ );
391
+ } else if (
392
+ migration.renamed_classes.some(
393
+ (c) =>
394
+ typeof c !== "object" ||
395
+ !isRequiredProperty(c, "from", "string") ||
396
+ !isRequiredProperty(c, "to", "string")
397
+ )
398
+ ) {
399
+ diagnostics.errors.push(
400
+ `Expected "migrations[${i}].renamed_classes" to be an array of "{from: string, to: string}" objects but got ${JSON.stringify(
401
+ migration.renamed_classes
402
+ )}.`
403
+ );
404
+ }
405
+ }
406
+ validateOptionalTypedArray(
407
+ diagnostics,
408
+ `migrations[${i}].deleted_classes`,
409
+ migration.deleted_classes,
410
+ "string"
411
+ );
412
+ }
413
+ return rawMigrations;
414
+ }
415
+ }
416
+
417
+ /**
418
+ * Validate the `site` configuration and return the normalized values.
419
+ */
420
+ function normalizeAndValidateSite(
421
+ diagnostics: Diagnostics,
422
+ rawSite: Config["site"]
423
+ ): Config["site"] {
424
+ if (rawSite !== undefined) {
425
+ const { bucket, include = [], exclude = [], ...rest } = rawSite;
426
+ validateAdditionalProperties(diagnostics, "site", Object.keys(rest), []);
427
+ validateRequiredProperty(diagnostics, "site", "bucket", bucket, "string");
428
+ validateTypedArray(diagnostics, "sites.include", include, "string");
429
+ validateTypedArray(diagnostics, "sites.exclude", exclude, "string");
430
+ return { bucket, include, exclude };
431
+ }
432
+ return undefined;
433
+ }
434
+
435
+ /**
436
+ * Map the paths of the `wasm_modules`, `text_blobs` or `data_blobs` configuration to be relative to the current working directory.
437
+ */
438
+ function normalizeAndValidateModulePaths(
439
+ diagnostics: Diagnostics,
440
+ configPath: string | undefined,
441
+ field: "wasm_modules" | "text_blobs" | "data_blobs",
442
+ rawMapping: Record<string, string> | undefined
443
+ ): Record<string, string> | undefined {
444
+ if (rawMapping === undefined) {
445
+ return undefined;
446
+ }
447
+ const mapping: Record<string, string> = {};
448
+ // Rewrite paths to be relative to the cwd, rather than the config path.
449
+ for (const [name, filePath] of Object.entries(rawMapping)) {
450
+ if (isString(diagnostics, `${field}['${name}']`, filePath, undefined)) {
451
+ if (configPath) {
452
+ mapping[name] = configPath
453
+ ? path.relative(
454
+ process.cwd(),
455
+ path.join(path.dirname(configPath), filePath)
456
+ )
457
+ : filePath;
458
+ }
459
+ }
460
+ }
461
+ return mapping;
462
+ }
463
+
464
+ /**
465
+ * Validate top-level environment configuration and return the normalized values.
466
+ */
467
+ function normalizeAndValidateEnvironment(
468
+ diagnostics: Diagnostics,
469
+ configPath: string | undefined,
470
+ topLevelEnv: RawEnvironment
471
+ ): Environment;
472
+ /**
473
+ * Validate the named environment configuration and return the normalized values.
474
+ */
475
+ function normalizeAndValidateEnvironment(
476
+ diagnostics: Diagnostics,
477
+ configPath: string | undefined,
478
+ rawEnv: RawEnvironment,
479
+ envName: string,
480
+ topLevelEnv: Environment,
481
+ isLegacyEnv: boolean,
482
+ rawConfig: RawConfig
483
+ ): Environment;
484
+ function normalizeAndValidateEnvironment(
485
+ diagnostics: Diagnostics,
486
+ configPath: string | undefined,
487
+ rawEnv: RawEnvironment,
488
+ envName = "top level",
489
+ topLevelEnv?: Environment | undefined,
490
+ isLegacyEnv?: boolean,
491
+ rawConfig?: RawConfig | undefined
492
+ ): Environment {
493
+ deprecated(
494
+ diagnostics,
495
+ rawEnv,
496
+ "zone_id",
497
+ "This is unnecessary since we can deduce this from routes directly.",
498
+ false // We need to leave this in-place for the moment since `route` commands might use it.
499
+ );
500
+
501
+ // The field "experimental_services" doesn't exist anymore in the config, but we still want to error about any older usage.
502
+ // TODO: remove this before GA.
503
+ deprecated(
504
+ diagnostics,
505
+ rawEnv,
506
+ "experimental_services",
507
+ `The "experimental_services" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:\n` +
508
+ "```\n" +
509
+ TOML.stringify({
510
+ unsafe: {
511
+ bindings: (rawEnv?.experimental_services || []).map(
512
+ (serviceDefinition) => {
513
+ return {
514
+ name: serviceDefinition.name,
515
+ type: "service",
516
+ service: serviceDefinition.service,
517
+ environment: serviceDefinition.environment,
518
+ };
519
+ }
520
+ ),
521
+ },
522
+ }) +
523
+ "```",
524
+ true
525
+ );
526
+
527
+ experimental(diagnostics, rawEnv, "unsafe");
528
+
529
+ const route = inheritable(
530
+ diagnostics,
531
+ topLevelEnv,
532
+ rawEnv,
533
+ "route",
534
+ isString,
535
+ undefined
536
+ );
537
+ const routes = inheritable(
538
+ diagnostics,
539
+ topLevelEnv,
540
+ rawEnv,
541
+ "routes",
542
+ all(isStringArray, isMutuallyExclusiveWith(rawEnv, "route")),
543
+ undefined
544
+ );
545
+ const workers_dev = inheritable(
546
+ diagnostics,
547
+ topLevelEnv,
548
+ rawEnv,
549
+ "workers_dev",
550
+ isBoolean,
551
+ undefined
552
+ );
553
+
554
+ const { deprecatedUpload, ...build } = normalizeAndValidateBuild(
555
+ diagnostics,
556
+ rawEnv,
557
+ rawEnv.build ?? topLevelEnv?.build ?? {},
558
+ configPath
559
+ );
560
+
561
+ const environment: Environment = {
562
+ // Inherited fields
563
+ account_id: inheritable(
564
+ diagnostics,
565
+ topLevelEnv,
566
+ rawEnv,
567
+ "account_id",
568
+ isString,
569
+ undefined
570
+ ),
571
+ compatibility_date: inheritable(
572
+ diagnostics,
573
+ topLevelEnv,
574
+ rawEnv,
575
+ "compatibility_date",
576
+ isString,
577
+ undefined
578
+ ),
579
+ compatibility_flags: inheritable(
580
+ diagnostics,
581
+ topLevelEnv,
582
+ rawEnv,
583
+ "compatibility_flags",
584
+ isStringArray,
585
+ []
586
+ ),
587
+ jsx_factory: inheritable(
588
+ diagnostics,
589
+ topLevelEnv,
590
+ rawEnv,
591
+ "jsx_factory",
592
+ isString,
593
+ "React.createElement"
594
+ ),
595
+ jsx_fragment: inheritable(
596
+ diagnostics,
597
+ topLevelEnv,
598
+ rawEnv,
599
+ "jsx_fragment",
600
+ isString,
601
+ "React.Fragment"
602
+ ),
603
+ tsconfig: validateAndNormalizeTsconfig(
604
+ diagnostics,
605
+ topLevelEnv,
606
+ rawEnv,
607
+ configPath
608
+ ),
609
+ rules: validateAndNormalizeRules(
610
+ diagnostics,
611
+ topLevelEnv,
612
+ rawEnv,
613
+ deprecatedUpload?.rules,
614
+ envName
615
+ ),
616
+ name: inheritableInLegacyEnvironments(
617
+ diagnostics,
618
+ isLegacyEnv,
619
+ topLevelEnv,
620
+ rawEnv,
621
+ "name",
622
+ isString,
623
+ appendEnvName(envName),
624
+ undefined
625
+ ),
626
+ main: normalizeAndValidateMainField(
627
+ configPath,
628
+ inheritable(
629
+ diagnostics,
630
+ topLevelEnv,
631
+ rawEnv,
632
+ "main",
633
+ isString,
634
+ undefined
635
+ ),
636
+ deprecatedUpload
637
+ ),
638
+ route,
639
+ routes,
640
+ triggers: inheritable(
641
+ diagnostics,
642
+ topLevelEnv,
643
+ rawEnv,
644
+ "triggers",
645
+ isObjectWith("crons"),
646
+ { crons: [] }
647
+ ),
648
+ usage_model: inheritable(
649
+ diagnostics,
650
+ topLevelEnv,
651
+ rawEnv,
652
+ "usage_model",
653
+ isOneOf("bundled", "unbound"),
654
+ undefined
655
+ ),
656
+ build,
657
+ workers_dev,
658
+ // Not inherited fields
659
+ vars: notInheritable(
660
+ diagnostics,
661
+ topLevelEnv,
662
+ rawConfig,
663
+ rawEnv,
664
+ envName,
665
+ "vars",
666
+ validateVars(envName),
667
+ {}
668
+ ),
669
+ durable_objects: notInheritable(
670
+ diagnostics,
671
+ topLevelEnv,
672
+ rawConfig,
673
+ rawEnv,
674
+ envName,
675
+ "durable_objects",
676
+ validateBindingsProperty(envName, validateDurableObjectBinding),
677
+ {
678
+ bindings: [],
679
+ }
680
+ ),
681
+ kv_namespaces: notInheritable(
682
+ diagnostics,
683
+ topLevelEnv,
684
+ rawConfig,
685
+ rawEnv,
686
+ envName,
687
+ "kv_namespaces",
688
+ validateBindingArray(envName, validateKVBinding),
689
+ []
690
+ ),
691
+ r2_buckets: notInheritable(
692
+ diagnostics,
693
+ topLevelEnv,
694
+ rawConfig,
695
+ rawEnv,
696
+ envName,
697
+ "r2_buckets",
698
+ validateBindingArray(envName, validateR2Binding),
699
+ []
700
+ ),
701
+ unsafe: notInheritable(
702
+ diagnostics,
703
+ topLevelEnv,
704
+ rawConfig,
705
+ rawEnv,
706
+ envName,
707
+ "unsafe",
708
+ validateBindingsProperty(envName, validateUnsafeBinding),
709
+ {
710
+ bindings: [],
711
+ }
712
+ ),
713
+ zone_id: rawEnv.zone_id,
714
+ };
715
+
716
+ return environment;
717
+ }
718
+
719
+ function validateAndNormalizeTsconfig(
720
+ diagnostics: Diagnostics,
721
+ topLevelEnv: Environment | undefined,
722
+ rawEnv: RawEnvironment,
723
+ configPath: string | undefined
724
+ ) {
725
+ const tsconfig = inheritable(
726
+ diagnostics,
727
+ topLevelEnv,
728
+ rawEnv,
729
+ "tsconfig",
730
+ isString,
731
+ undefined
732
+ );
733
+
734
+ return configPath && tsconfig
735
+ ? path.relative(
736
+ process.cwd(),
737
+ path.join(path.dirname(configPath), tsconfig)
738
+ )
739
+ : tsconfig;
740
+ }
741
+
742
+ const validateAndNormalizeRules = (
743
+ diagnostics: Diagnostics,
744
+ topLevelEnv: Environment | undefined,
745
+ rawEnv: RawEnvironment,
746
+ deprecatedRules: Rule[] | undefined,
747
+ envName: string
748
+ ): Rule[] => {
749
+ if (topLevelEnv === undefined) {
750
+ // Only create errors/warnings for the top-level environment
751
+ if (rawEnv.rules && deprecatedRules) {
752
+ diagnostics.errors.push(
753
+ `You cannot configure both [rules] and [build.upload.rules] in your wrangler.toml. Delete the \`build.upload\` section.`
754
+ );
755
+ } else if (deprecatedRules) {
756
+ diagnostics.warnings.push(
757
+ `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` +
758
+ "```\n" +
759
+ TOML.stringify({ rules: deprecatedRules }) +
760
+ "```"
761
+ );
762
+ }
763
+ }
764
+
765
+ return inheritable(
766
+ diagnostics,
767
+ topLevelEnv,
768
+ rawEnv,
769
+ "rules",
770
+ validateRules(envName),
771
+ deprecatedRules ?? []
772
+ );
773
+ };
774
+
775
+ const validateRules =
776
+ (envName: string): ValidatorFn =>
777
+ (diagnostics, field, envValue, config) => {
778
+ if (!envValue) {
779
+ return true;
780
+ }
781
+ const fieldPath =
782
+ config === undefined ? `${field}` : `env.${envName}.${field}`;
783
+ if (!Array.isArray(envValue)) {
784
+ diagnostics.errors.push(
785
+ `The field "${fieldPath}" should be an array but got ${JSON.stringify(
786
+ envValue
787
+ )}.`
788
+ );
789
+ return false;
790
+ }
791
+
792
+ let isValid = true;
793
+ for (let i = 0; i < envValue.length; i++) {
794
+ isValid =
795
+ validateRule(diagnostics, `${fieldPath}[${i}]`, envValue[i], config) &&
796
+ isValid;
797
+ }
798
+ return isValid;
799
+ };
800
+
801
+ const validateRule: ValidatorFn = (diagnostics, field, value) => {
802
+ if (typeof value !== "object" || value === null) {
803
+ diagnostics.errors.push(
804
+ `"${field}" should be an object but got ${JSON.stringify(value)}.`
805
+ );
806
+ return false;
807
+ }
808
+ // Rules must have a type string and glob string array, and optionally a fallthrough boolean.
809
+ let isValid = true;
810
+ const rule = value as Rule;
811
+
812
+ if (
813
+ !isRequiredProperty(rule, "type", "string", [
814
+ "ESModule",
815
+ "CommonJS",
816
+ "CompiledWasm",
817
+ "Text",
818
+ "Data",
819
+ ])
820
+ ) {
821
+ diagnostics.errors.push(
822
+ `bindings should have a string "type" field, which contains one of "ESModule", "CommonJS", "CompiledWasm", "Text", or "Data".`
823
+ );
824
+ isValid = false;
825
+ }
826
+
827
+ isValid =
828
+ validateTypedArray(diagnostics, `${field}.globs`, rule.globs, "string") &&
829
+ isValid;
830
+
831
+ if (!isOptionalProperty(rule, "fallthrough", "boolean")) {
832
+ diagnostics.errors.push(
833
+ `binding should, optionally, have a boolean "fallthrough" field.`
834
+ );
835
+ isValid = false;
836
+ }
837
+
838
+ return isValid;
839
+ };
840
+
841
+ const validateVars =
842
+ (envName: string): ValidatorFn =>
843
+ (diagnostics, field, value, config) => {
844
+ let isValid = true;
845
+ const fieldPath =
846
+ config === undefined ? `${field}` : `env.${envName}.${field}`;
847
+ const configVars = Object.keys(config?.vars ?? {});
848
+ // If there are no top level vars then there is nothing to do here.
849
+ if (configVars.length > 0) {
850
+ if (typeof value !== "object" || value === null) {
851
+ diagnostics.errors.push(
852
+ `The field "${fieldPath}" should be an object but got ${JSON.stringify(
853
+ value
854
+ )}.\n`
855
+ );
856
+ isValid = false;
857
+ } else {
858
+ for (const varName of configVars) {
859
+ if (!(varName in value)) {
860
+ diagnostics.warnings.push(
861
+ `"vars.${varName}" exists at the top level, but not on "${fieldPath}".\n` +
862
+ `This is not what you probably want, since "vars" configuration is not inherited by environments.\n` +
863
+ `Please add "vars.${varName}" to "env.${envName}".`
864
+ );
865
+ }
866
+ }
867
+ }
868
+ }
869
+ return isValid;
870
+ };
871
+
872
+ const validateBindingsProperty =
873
+ (envName: string, validateBinding: ValidatorFn): ValidatorFn =>
874
+ (diagnostics, field, value, config) => {
875
+ let isValid = true;
876
+ const fieldPath =
877
+ config === undefined ? `${field}` : `env.${envName}.${field}`;
878
+
879
+ if (value !== undefined) {
880
+ // Check the validity of the `value` as a bindings container.
881
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
882
+ diagnostics.errors.push(
883
+ `The field "${fieldPath}" should be an object but got ${JSON.stringify(
884
+ value
885
+ )}.`
886
+ );
887
+ isValid = false;
888
+ } else if (!hasProperty(value, "bindings")) {
889
+ diagnostics.errors.push(
890
+ `The field "${fieldPath}" is missing the required "bindings" property.`
891
+ );
892
+ isValid = false;
893
+ } else if (!Array.isArray(value.bindings)) {
894
+ diagnostics.errors.push(
895
+ `The field "${fieldPath}.bindings" should be an array but got ${JSON.stringify(
896
+ value.bindings
897
+ )}.`
898
+ );
899
+ isValid = false;
900
+ } else {
901
+ for (let i = 0; i < value.bindings.length; i++) {
902
+ const binding = value.bindings[i];
903
+ const bindingDiagnostics = new Diagnostics(
904
+ `"${fieldPath}.bindings[${i}]": ${JSON.stringify(binding)}`
905
+ );
906
+ isValid =
907
+ validateBinding(
908
+ bindingDiagnostics,
909
+ `${fieldPath}.bindings[${i}]`,
910
+ binding,
911
+ config
912
+ ) && isValid;
913
+ diagnostics.addChild(bindingDiagnostics);
914
+ }
915
+ }
916
+
917
+ const configBindingNames = getBindingNames(
918
+ config?.[field as keyof Environment]
919
+ );
920
+ if (isValid && configBindingNames.length > 0) {
921
+ // If there are top level bindings then check that they all appear in the environment.
922
+ const envBindingNames = new Set(getBindingNames(value));
923
+ const missingBindings = configBindingNames.filter(
924
+ (name) => !envBindingNames.has(name)
925
+ );
926
+ if (missingBindings.length > 0) {
927
+ diagnostics.warnings.push(
928
+ `The following bindings are at the top level, but not on "env.${envName}".\n` +
929
+ `This is not what you probably want, since "${field}" configuration is not inherited by environments.\n` +
930
+ `Please add a binding for each to "${fieldPath}.bindings".` +
931
+ missingBindings.map((name) => `- ${name}`).join("\n")
932
+ );
933
+ }
934
+ }
935
+ }
936
+ return isValid;
937
+ };
938
+
939
+ /**
940
+ * Check that the given field is a valid "durable_object" binding object.
941
+ */
942
+ const validateDurableObjectBinding: ValidatorFn = (
943
+ diagnostics,
944
+ field,
945
+ value
946
+ ) => {
947
+ if (typeof value !== "object" || value === null) {
948
+ diagnostics.errors.push(
949
+ `Expected "${field}" to be an object but got ${JSON.stringify(value)}`
950
+ );
951
+ return false;
952
+ }
953
+
954
+ // Durable Object bindings must have a name and class_name, and optionally a script_name.
955
+ let isValid = true;
956
+ if (!isRequiredProperty(value, "name", "string")) {
957
+ diagnostics.errors.push(`binding should have a string "name" field.`);
958
+ isValid = false;
959
+ }
960
+ if (!isRequiredProperty(value, "class_name", "string")) {
961
+ diagnostics.errors.push(`binding should have a string "class_name" field.`);
962
+ isValid = false;
963
+ }
964
+ if (!isOptionalProperty(value, "script_name", "string")) {
965
+ diagnostics.errors.push(
966
+ `binding should, optionally, have a string "script_name" field.`
967
+ );
968
+ isValid = false;
969
+ }
970
+
971
+ return isValid;
972
+ };
973
+
974
+ /**
975
+ * Check that the given field is a valid "unsafe" binding object.
976
+ *
977
+ * TODO: further validation of known unsafe bindings.
978
+ */
979
+ const validateUnsafeBinding: ValidatorFn = (diagnostics, field, value) => {
980
+ if (typeof value !== "object" || value === null) {
981
+ diagnostics.errors.push(
982
+ `Expected ${field} to be an object but got ${JSON.stringify(value)}.`
983
+ );
984
+ return false;
985
+ }
986
+
987
+ let isValid = true;
988
+ // Unsafe bindings must have a name and type.
989
+ if (!isRequiredProperty(value, "name", "string")) {
990
+ diagnostics.errors.push(`binding should have a string "name" field.`);
991
+ isValid = false;
992
+ }
993
+ if (isRequiredProperty(value, "type", "string")) {
994
+ const safeBindings = [
995
+ "plain_text",
996
+ "json",
997
+ "kv_namespace",
998
+ "durable_object_namespace",
999
+ ];
1000
+
1001
+ if (safeBindings.includes(value.type)) {
1002
+ diagnostics.warnings.push(
1003
+ `The binding type "${value.type}" is directly supported by wrangler.\n` +
1004
+ `Consider migrating this unsafe binding to a format for '${value.type}' bindings that is supported by wrangler for optimal support.\n` +
1005
+ "For more details, see https://developers.cloudflare.com/workers/cli-wrangler/configuration"
1006
+ );
1007
+ }
1008
+ } else {
1009
+ diagnostics.errors.push(`binding should have a string "type" field.`);
1010
+ isValid = false;
1011
+ }
1012
+ return isValid;
1013
+ };
1014
+
1015
+ /**
1016
+ * Check that the given environment field is a valid array of bindings.
1017
+ */
1018
+ const validateBindingArray =
1019
+ (envName: string, validateBinding: ValidatorFn): ValidatorFn =>
1020
+ (diagnostics, field, envValue, config) => {
1021
+ if (envValue === undefined) {
1022
+ return true;
1023
+ }
1024
+
1025
+ const fieldPath =
1026
+ config === undefined ? `${field}` : `env.${envName}.${field}`;
1027
+ if (!Array.isArray(envValue)) {
1028
+ diagnostics.errors.push(
1029
+ `The field "${fieldPath}" should be an array but got ${JSON.stringify(
1030
+ envValue
1031
+ )}.`
1032
+ );
1033
+ return false;
1034
+ }
1035
+
1036
+ let isValid = true;
1037
+ for (let i = 0; i < envValue.length; i++) {
1038
+ isValid =
1039
+ validateBinding(
1040
+ diagnostics,
1041
+ `${fieldPath}[${i}]`,
1042
+ envValue[i],
1043
+ config
1044
+ ) && isValid;
1045
+ }
1046
+ const configValue = config?.[field as keyof Environment] as {
1047
+ binding: unknown;
1048
+ }[];
1049
+ if (Array.isArray(configValue)) {
1050
+ const configBindingNames = configValue.map((value) => value.binding);
1051
+ // If there are no top level bindings then there is nothing to do here.
1052
+ if (configBindingNames.length > 0) {
1053
+ const envBindingNames = new Set(envValue.map((value) => value.binding));
1054
+ for (const configBindingName of configBindingNames) {
1055
+ if (!envBindingNames.has(configBindingName)) {
1056
+ diagnostics.warnings.push(
1057
+ `There is a ${field} binding with name "${configBindingName}" at the top level, but not on "env.${envName}".\n` +
1058
+ `This is not what you probably want, since "${field}" configuration is not inherited by environments.\n` +
1059
+ `Please add a binding for "${configBindingName}" to "env.${envName}.${field}.bindings".`
1060
+ );
1061
+ }
1062
+ }
1063
+ }
1064
+ }
1065
+ return isValid;
1066
+ };
1067
+
1068
+ const validateKVBinding: ValidatorFn = (diagnostics, field, value) => {
1069
+ if (typeof value !== "object" || value === null) {
1070
+ diagnostics.errors.push(
1071
+ `"kv_namespaces" bindings should be objects, but got ${JSON.stringify(
1072
+ value
1073
+ )}`
1074
+ );
1075
+ return false;
1076
+ }
1077
+ let isValid = true;
1078
+ // KV bindings must have a binding and id.
1079
+ if (!isRequiredProperty(value, "binding", "string")) {
1080
+ diagnostics.errors.push(
1081
+ `"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
1082
+ value
1083
+ )}.`
1084
+ );
1085
+ isValid = false;
1086
+ }
1087
+ if (!isRequiredProperty(value, "id", "string")) {
1088
+ diagnostics.errors.push(
1089
+ `"${field}" bindings should have a string "id" field but got ${JSON.stringify(
1090
+ value
1091
+ )}.`
1092
+ );
1093
+ isValid = false;
1094
+ }
1095
+ if (!isOptionalProperty(value, "preview_id", "string")) {
1096
+ diagnostics.errors.push(
1097
+ `"${field}" bindings should, optionally, have a string "preview_id" field but got ${JSON.stringify(
1098
+ value
1099
+ )}.`
1100
+ );
1101
+ isValid = false;
1102
+ }
1103
+ return isValid;
1104
+ };
1105
+
1106
+ const validateR2Binding: ValidatorFn = (diagnostics, field, value) => {
1107
+ if (typeof value !== "object" || value === null) {
1108
+ diagnostics.errors.push(
1109
+ `"kv_namespaces" bindings should be objects, but got ${JSON.stringify(
1110
+ value
1111
+ )}`
1112
+ );
1113
+ return false;
1114
+ }
1115
+ let isValid = true;
1116
+ // R2 bindings must have a binding and bucket_name.
1117
+ if (!isRequiredProperty(value, "binding", "string")) {
1118
+ diagnostics.errors.push(
1119
+ `"${field}" bindings should have a string "binding" field but got ${JSON.stringify(
1120
+ value
1121
+ )}.`
1122
+ );
1123
+ isValid = false;
1124
+ }
1125
+ if (!isRequiredProperty(value, "bucket_name", "string")) {
1126
+ diagnostics.errors.push(
1127
+ `"${field}" bindings should have a string "bucket_name" field but got ${JSON.stringify(
1128
+ value
1129
+ )}.`
1130
+ );
1131
+ isValid = false;
1132
+ }
1133
+ if (!isOptionalProperty(value, "preview_bucket_name", "string")) {
1134
+ diagnostics.errors.push(
1135
+ `"${field}" bindings should, optionally, have a string "preview_bucket_name" field but got ${JSON.stringify(
1136
+ value
1137
+ )}.`
1138
+ );
1139
+ isValid = false;
1140
+ }
1141
+ return isValid;
1142
+ };
1143
+
1144
+ /**
1145
+ * Check that bindings whose names might conflict, don't.
1146
+ *
1147
+ * We don't want to have, for example, a KV namespace named "DATA"
1148
+ * and a Durable Object also named "DATA". Then it would be ambiguous
1149
+ * what exactly would live at `env.DATA` (or in the case of service-workers,
1150
+ * the `DATA` global).
1151
+ */
1152
+ const validateBindingsHaveUniqueNames = (
1153
+ diagnostics: Diagnostics,
1154
+ {
1155
+ durable_objects,
1156
+ kv_namespaces,
1157
+ r2_buckets,
1158
+ text_blobs,
1159
+ unsafe,
1160
+ vars,
1161
+ wasm_modules,
1162
+ data_blobs,
1163
+ }: Partial<Config>
1164
+ ): boolean => {
1165
+ let hasDuplicates = false;
1166
+
1167
+ const bindingsGroupedByType = {
1168
+ "Durable Object": getBindingNames(durable_objects),
1169
+ "KV Namespace": getBindingNames(kv_namespaces),
1170
+ "R2 Bucket": getBindingNames(r2_buckets),
1171
+ "Text Blob": getBindingNames(text_blobs),
1172
+ Unsafe: getBindingNames(unsafe),
1173
+ "Environment Variable": getBindingNames(vars),
1174
+ "WASM Module": getBindingNames(wasm_modules),
1175
+ "Data Blob": getBindingNames(data_blobs),
1176
+ } as Record<string, string[]>;
1177
+
1178
+ const bindingsGroupedByName: Record<string, string[]> = {};
1179
+
1180
+ for (const bindingType in bindingsGroupedByType) {
1181
+ const bindingNames = bindingsGroupedByType[bindingType];
1182
+
1183
+ for (const bindingName of bindingNames) {
1184
+ if (!(bindingName in bindingsGroupedByName)) {
1185
+ bindingsGroupedByName[bindingName] = [];
1186
+ }
1187
+
1188
+ bindingsGroupedByName[bindingName].push(bindingType);
1189
+ }
1190
+ }
1191
+
1192
+ for (const bindingName in bindingsGroupedByName) {
1193
+ const bindingTypes = bindingsGroupedByName[bindingName];
1194
+ if (bindingTypes.length < 2) {
1195
+ // there's only one (or zero) binding(s) with this name, which is fine, actually
1196
+ continue;
1197
+ }
1198
+
1199
+ hasDuplicates = true;
1200
+
1201
+ // there's two types of duplicates we want to look for:
1202
+ // - bindings with the same name of the same type (e.g. two Durable Objects both named "OBJ")
1203
+ // - bindings with the same name of different types (a KV namespace and DO both named "DATA")
1204
+
1205
+ const sameType = bindingTypes
1206
+ // filter once to find duplicate binding types
1207
+ .filter((type, i) => bindingTypes.indexOf(type) !== i)
1208
+ // filter twice to only get _unique_ duplicate binding types
1209
+ .filter(
1210
+ (type, i, duplicateBindingTypes) =>
1211
+ duplicateBindingTypes.indexOf(type) === i
1212
+ );
1213
+
1214
+ const differentTypes = bindingTypes.filter(
1215
+ (type, i) => bindingTypes.indexOf(type) === i
1216
+ );
1217
+
1218
+ if (differentTypes.length > 1) {
1219
+ // we have multiple different types using the same name
1220
+ diagnostics.errors.push(
1221
+ `${bindingName} assigned to ${ENGLISH.format(differentTypes)} bindings.`
1222
+ );
1223
+ }
1224
+
1225
+ sameType.forEach((bindingType) => {
1226
+ diagnostics.errors.push(
1227
+ `${bindingName} assigned to multiple ${bindingType} bindings.`
1228
+ );
1229
+ });
1230
+ }
1231
+
1232
+ if (hasDuplicates) {
1233
+ const problem =
1234
+ "Bindings must have unique names, so that they can all be referenced in the worker.";
1235
+ const resolution = "Please change your bindings to have unique names.";
1236
+ diagnostics.errors.push(`${problem}\n${resolution}`);
1237
+ }
1238
+
1239
+ return !hasDuplicates;
1240
+ };