Skip to content

Commit fcaa02c

Browse files
authored
fix(wrangler): fix schema defaults (#7821)
1 parent d7adb50 commit fcaa02c

File tree

3 files changed

+58
-34
lines changed

3 files changed

+58
-34
lines changed

.changeset/dry-snakes-deliver.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"wrangler": patch
3+
---
4+
5+
fix(wrangler): fix wrangler config schema defaults
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
4+
describe("src/config/environment.ts", () => {
5+
// `@default` values must not be escaped in order to generate a valid schema.
6+
test("default values are not escaped", () => {
7+
const srcFile = path.join(__dirname, "../../config/environment.ts");
8+
const srcLines = fs.readFileSync(srcFile, "utf-8").split("\n");
9+
const hasEscapedDefaultRegex = /@default\s+`/;
10+
srcLines.forEach((line, lineNumber) => {
11+
const hasEscapedDefault = hasEscapedDefaultRegex.test(line);
12+
expect
13+
.soft(hasEscapedDefault, `On line ${lineNumber + 1}: "${line}"`)
14+
.toEqual(false);
15+
});
16+
});
17+
});

packages/wrangler/src/config/environment.ts

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ interface EnvironmentInheritable {
119119

120120
/**
121121
* A list of flags that enable features from upcoming features of
122-
* the Workers runtime, usually used together with compatibility_flags.
122+
* the Workers runtime, usually used together with compatibility_date.
123123
*
124-
* More details at https://developers.cloudflare.com/workers/platform/compatibility-dates
124+
* More details at https://developers.cloudflare.com/workers/platform/compatibility-flags
125125
*
126-
* @default `[]`
126+
* @default []
127127
* @inheritable
128128
*/
129129
compatibility_flags: string[];
@@ -162,23 +162,25 @@ interface EnvironmentInheritable {
162162
*/
163163
base_dir: string | undefined;
164164

165+
// Carmen according to our tests the default is undefined
166+
// warning: you must force "workers_dev: true" in tests to match expected behavior
165167
/**
166168
* Whether we use <name>.<subdomain>.workers.dev to
167169
* test and deploy your Worker.
168170
*
169-
* // Carmen according to our tests the default is undefined
170-
* // warning: you must force "workers_dev: true" in tests to match expected behavior
171-
* @default `true` (This is a breaking change from Wrangler v1)
171+
*
172+
* @default true
172173
* @breaking
173174
* @inheritable
174175
*/
176+
175177
workers_dev: boolean | undefined;
176178

177179
/**
178180
* Whether we use <version>-<name>.<subdomain>.workers.dev to
179181
* serve Preview URLs for your Worker.
180182
*
181-
* @default `true`
183+
* @default true
182184
* @inheritable
183185
*/
184186
preview_urls: boolean | undefined;
@@ -214,15 +216,15 @@ interface EnvironmentInheritable {
214216
/**
215217
* The function to use to replace jsx syntax.
216218
*
217-
* @default `"React.createElement"`
219+
* @default "React.createElement"
218220
* @inheritable
219221
*/
220222
jsx_factory: string;
221223

222224
/**
223225
* The function to use to replace jsx fragment syntax.
224226
*
225-
* @default `"React.Fragment"`
227+
* @default "React.Fragment"
226228
* @inheritable
227229
*/
228230
jsx_fragment: string;
@@ -246,7 +248,7 @@ interface EnvironmentInheritable {
246248
*
247249
* More details here https://developers.cloudflare.com/workers/platform/cron-triggers
248250
*
249-
* @default `{crons:[]}`
251+
* @default {crons:[]}
250252
* @inheritable
251253
*/
252254
triggers: { crons: string[] };
@@ -340,7 +342,7 @@ interface EnvironmentInheritable {
340342
/**
341343
* List of bindings that you will send to logfwdr
342344
*
343-
* @default `{bindings:[]}`
345+
* @default {bindings:[]}
344346
* @inheritable
345347
*/
346348
logfwdr: {
@@ -432,7 +434,7 @@ export interface EnvironmentNonInheritable {
432434
* NOTE: This field is not automatically inherited from the top level environment,
433435
* and so must be specified in every named environment.
434436
*
435-
* @default `{}`
437+
* @default {}
436438
* @nonInheritable
437439
*/
438440
define: Record<string, string>;
@@ -442,7 +444,7 @@ export interface EnvironmentNonInheritable {
442444
* NOTE: This field is not automatically inherited from the top level environment,
443445
* and so must be specified in every named environment.
444446
*
445-
* @default `{}`
447+
* @default {}
446448
* @nonInheritable
447449
*/
448450
vars: Record<string, string | Json>;
@@ -456,7 +458,7 @@ export interface EnvironmentNonInheritable {
456458
* NOTE: This field is not automatically inherited from the top level environment,
457459
* and so must be specified in every named environment.
458460
*
459-
* @default `{bindings:[]}`
461+
* @default {bindings:[]}
460462
* @nonInheritable
461463
*/
462464
durable_objects: {
@@ -469,7 +471,7 @@ export interface EnvironmentNonInheritable {
469471
* NOTE: This field is not automatically inherited from the top level environment,
470472
* and so must be specified in every named environment.
471473
*
472-
* @default `[]`
474+
* @default []
473475
* @nonInheritable
474476
*/
475477
workflows: WorkflowBinding[];
@@ -480,7 +482,7 @@ export interface EnvironmentNonInheritable {
480482
* NOTE: This field is not automatically inherited from the top level environment,
481483
* and so must be specified in every named environment.
482484
*
483-
* @default `{}`
485+
* @default {}
484486
* @nonInheritable
485487
*/
486488
cloudchamber: CloudchamberConfig;
@@ -495,7 +497,7 @@ export interface EnvironmentNonInheritable {
495497
* NOTE: This field is not automatically inherited from the top level environment,
496498
* and so must be specified in every named environment.
497499
*
498-
* @default `{}`
500+
* @default {}
499501
* @nonInheritable
500502
*/
501503
app: ContainerApp[];
@@ -511,7 +513,7 @@ export interface EnvironmentNonInheritable {
511513
* NOTE: This field is not automatically inherited from the top level environment,
512514
* and so must be specified in every named environment.
513515
*
514-
* @default `[]`
516+
* @default []
515517
* @nonInheritable
516518
*/
517519
kv_namespaces: {
@@ -529,7 +531,7 @@ export interface EnvironmentNonInheritable {
529531
* NOTE: This field is not automatically inherited from the top level environment,
530532
* and so must be specified in every named environment.
531533
*
532-
* @default `[]`
534+
* @default []
533535
* @nonInheritable
534536
*/
535537
send_email: {
@@ -547,7 +549,7 @@ export interface EnvironmentNonInheritable {
547549
* NOTE: This field is not automatically inherited from the top level environment,
548550
* and so must be specified in every named environment.
549551
*
550-
* @default `{consumers:[],producers:[]}`
552+
* @default {consumers:[],producers:[]}
551553
* @nonInheritable
552554
*/
553555
queues: {
@@ -600,7 +602,7 @@ export interface EnvironmentNonInheritable {
600602
* NOTE: This field is not automatically inherited from the top level environment,
601603
* and so must be specified in every named environment.
602604
*
603-
* @default `[]`
605+
* @default []
604606
* @nonInheritable
605607
*/
606608
r2_buckets: {
@@ -620,7 +622,7 @@ export interface EnvironmentNonInheritable {
620622
* NOTE: This field is not automatically inherited from the top level environment,
621623
* and so must be specified in every named environment.
622624
*
623-
* @default `[]`
625+
* @default []
624626
* @nonInheritable
625627
*/
626628
d1_databases: {
@@ -646,7 +648,7 @@ export interface EnvironmentNonInheritable {
646648
* NOTE: This field is not automatically inherited from the top level environment,
647649
* and so must be specified in every named environment.
648650
*
649-
* @default `[]`
651+
* @default []
650652
* @nonInheritable
651653
*/
652654
vectorize: {
@@ -662,7 +664,7 @@ export interface EnvironmentNonInheritable {
662664
* NOTE: This field is not automatically inherited from the top level environment,
663665
* and so must be specified in every named environment.
664666
*
665-
* @default `[]`
667+
* @default []
666668
* @nonInheritable
667669
*/
668670
hyperdrive: {
@@ -680,7 +682,7 @@ export interface EnvironmentNonInheritable {
680682
* NOTE: This field is not automatically inherited from the top level environment,
681683
* and so must be specified in every named environment.
682684
*
683-
* @default `[]`
685+
* @default []
684686
* @nonInheritable
685687
*/
686688
services:
@@ -702,7 +704,7 @@ export interface EnvironmentNonInheritable {
702704
* NOTE: This field is not automatically inherited from the top level environment,
703705
* and so must be specified in every named environment.
704706
*
705-
* @default `[]`
707+
* @default []
706708
* @nonInheritable
707709
*/
708710
analytics_engine_datasets: {
@@ -718,7 +720,7 @@ export interface EnvironmentNonInheritable {
718720
* NOTE: This field is not automatically inherited from the top level environment,
719721
* and so must be specified in every named environment.
720722
*
721-
* @default `{}`
723+
* @default {}
722724
* @nonInheritable
723725
*/
724726
browser:
@@ -733,7 +735,7 @@ export interface EnvironmentNonInheritable {
733735
* NOTE: This field is not automatically inherited from the top level environment,
734736
* and so must be specified in every named environment.
735737
*
736-
* @default `{}`
738+
* @default {}
737739
* @nonInheritable
738740
*/
739741
ai:
@@ -758,7 +760,7 @@ export interface EnvironmentNonInheritable {
758760
* NOTE: This field is not automatically inherited from the top level environment,
759761
* and so must be specified in every named environment.
760762
*
761-
* @default `{}`
763+
* @default {}
762764
* @nonInheritable
763765
*/
764766
unsafe: {
@@ -803,7 +805,7 @@ export interface EnvironmentNonInheritable {
803805
* NOTE: This field is not automatically inherited from the top level environment,
804806
* and so must be specified in every named environment.
805807
*
806-
* @default `[]`
808+
* @default []
807809
* @nonInheritable
808810
*/
809811
mtls_certificates: {
@@ -819,7 +821,7 @@ export interface EnvironmentNonInheritable {
819821
* NOTE: This field is not automatically inherited from the top level environment,
820822
* and so must be specified in every named environment.
821823
*
822-
* @default `[]`
824+
* @default []
823825
* @nonInheritable
824826
*/
825827
tail_consumers?: TailConsumer[];
@@ -830,7 +832,7 @@ export interface EnvironmentNonInheritable {
830832
* NOTE: This field is not automatically inherited from the top level environment,
831833
* and so must be specified in every named environment.
832834
*
833-
* @default `[]`
835+
* @default []
834836
* @nonInheritable
835837
*/
836838
dispatch_namespaces: {
@@ -848,7 +850,7 @@ export interface EnvironmentNonInheritable {
848850
* NOTE: This field is not automatically inherited from the top level environment,
849851
* and so must be specified in every named environment.
850852
*
851-
* @default `[]`
853+
* @default []
852854
* @nonInheritable
853855
*/
854856
pipelines: {
@@ -882,7 +884,7 @@ interface EnvironmentDeprecated {
882884
/**
883885
* A list of services that your Worker should be bound to.
884886
*
885-
* @default `[]`
887+
* @default []
886888
* @deprecated DO NOT USE. We'd added this to test the new service binding system, but the proper way to test experimental features is to use `unsafe.bindings` configuration.
887889
*/
888890
experimental_services?: {

0 commit comments

Comments
 (0)