wrangler 2.0.3 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/wrangler.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
- const { spawn } = require("node:child_process");
3
- const { join } = require("node:path");
2
+ const { spawn } = require("child_process");
3
+ const { join } = require("path");
4
4
  const semiver = require("semiver");
5
5
 
6
6
  const MIN_NODE_VERSION = "16.7.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "2.0.3",
3
+ "version": "2.0.7",
4
4
  "author": "wrangler@cloudflare.com",
5
5
  "description": "Command-line interface for all things Cloudflare Workers",
6
6
  "bin": {
@@ -75,6 +75,7 @@
75
75
  "find-up": "^6.3.0",
76
76
  "get-port": "^6.1.2",
77
77
  "glob-to-regexp": "0.4.1",
78
+ "http-terminator": "^3.2.0",
78
79
  "ignore": "^5.2.0",
79
80
  "ink": "^3.2.0",
80
81
  "ink-select-input": "^4.2.1",
@@ -86,6 +87,7 @@
86
87
  "jest-websocket-mock": "^2.3.0",
87
88
  "mime": "^3.0.0",
88
89
  "open": "^8.4.0",
90
+ "p-queue": "^7.2.0",
89
91
  "pretty-bytes": "^6.0.0",
90
92
  "prompts": "^2.4.2",
91
93
  "react": "^17.0.2",
@@ -96,7 +98,7 @@
96
98
  "timeago.js": "^4.0.2",
97
99
  "tmp-promise": "^3.0.3",
98
100
  "ts-dedent": "^2.2.0",
99
- "undici": "^4.15.1",
101
+ "undici": "^5.3.0",
100
102
  "update-check": "^1.5.4",
101
103
  "ws": "^8.5.0",
102
104
  "yargs": "^17.4.1"
@@ -131,7 +133,7 @@
131
133
  "testTimeout": 30000,
132
134
  "testRegex": ".*.(test|spec)\\.[jt]sx?$",
133
135
  "transformIgnorePatterns": [
134
- "node_modules/(?!find-up|locate-path|p-locate|p-limit|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream|get-port|supports-color|pretty-bytes)"
136
+ "node_modules/(?!find-up|locate-path|p-locate|p-limit|p-timeout|p-queue|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream|get-port|supports-color|pretty-bytes)"
135
137
  ],
136
138
  "moduleNameMapper": {
137
139
  "clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",
@@ -1,5 +1,7 @@
1
1
  import { access, lstat } from "node:fs/promises";
2
2
  import { dirname, relative, resolve } from "node:path";
3
+ import NodeGlobalsPolyfills from "@esbuild-plugins/node-globals-polyfill";
4
+ import NodeModulesPolyfills from "@esbuild-plugins/node-modules-polyfill";
3
5
  import { build } from "esbuild";
4
6
 
5
7
  type Options = {
@@ -8,6 +10,7 @@ type Options = {
8
10
  minify?: boolean;
9
11
  sourcemap?: boolean;
10
12
  watch?: boolean;
13
+ nodeCompat?: boolean;
11
14
  onEnd?: () => void;
12
15
  };
13
16
 
@@ -17,6 +20,7 @@ export function buildPlugin({
17
20
  minify = false,
18
21
  sourcemap = false,
19
22
  watch = false,
23
+ nodeCompat,
20
24
  onEnd = () => {},
21
25
  }: Options) {
22
26
  return build({
@@ -30,6 +34,7 @@ export function buildPlugin({
30
34
  sourcemap,
31
35
  watch,
32
36
  allowOverwrite: true,
37
+ define: { ...(nodeCompat ? { global: "globalThis" } : {}) },
33
38
  plugins: [
34
39
  {
35
40
  name: "wrangler notifier and monitor",
@@ -87,6 +92,14 @@ export function buildPlugin({
87
92
  }
88
93
  },
89
94
  },
95
+ ...(nodeCompat
96
+ ? [
97
+ NodeGlobalsPolyfills({
98
+ buffer: true,
99
+ }),
100
+ NodeModulesPolyfills(),
101
+ ]
102
+ : []),
90
103
  ],
91
104
  });
92
105
  }
@@ -1,5 +1,7 @@
1
1
  import { access, cp, lstat, rm } from "node:fs/promises";
2
2
  import { join, resolve } from "node:path";
3
+ import NodeGlobalsPolyfills from "@esbuild-plugins/node-globals-polyfill";
4
+ import NodeModulesPolyfills from "@esbuild-plugins/node-modules-polyfill";
3
5
  import { build } from "esbuild";
4
6
  import { nanoid } from "nanoid";
5
7
 
@@ -12,6 +14,7 @@ type Options = {
12
14
  watch?: boolean;
13
15
  onEnd?: () => void;
14
16
  buildOutputDirectory?: string;
17
+ nodeCompat?: boolean;
15
18
  };
16
19
 
17
20
  export function buildWorker({
@@ -23,6 +26,7 @@ export function buildWorker({
23
26
  watch = false,
24
27
  onEnd = () => {},
25
28
  buildOutputDirectory,
29
+ nodeCompat,
26
30
  }: Options) {
27
31
  return build({
28
32
  entryPoints: [resolve(__dirname, "../pages/functions/template-worker.ts")],
@@ -37,6 +41,7 @@ export function buildWorker({
37
41
  allowOverwrite: true,
38
42
  define: {
39
43
  __FALLBACK_SERVICE__: JSON.stringify(fallbackService),
44
+ ...(nodeCompat ? { global: "globalThis" } : {}),
40
45
  },
41
46
  plugins: [
42
47
  {
@@ -133,6 +138,14 @@ export function buildWorker({
133
138
  );
134
139
  },
135
140
  },
141
+ ...(nodeCompat
142
+ ? [
143
+ NodeGlobalsPolyfills({
144
+ buffer: true,
145
+ }),
146
+ NodeModulesPolyfills(),
147
+ ]
148
+ : []),
136
149
  ],
137
150
  });
138
151
  }
@@ -43,6 +43,7 @@ describe("normalizeAndValidateConfig()", () => {
43
43
  migrations: [],
44
44
  name: undefined,
45
45
  r2_buckets: [],
46
+ services: [],
46
47
  route: undefined,
47
48
  routes: undefined,
48
49
  rules: [],
@@ -620,6 +621,12 @@ describe("normalizeAndValidateConfig()", () => {
620
621
  class_name: "CLASS2",
621
622
  script_name: "SCRIPT2",
622
623
  },
624
+ {
625
+ name: "DO_BINDING_3",
626
+ class_name: "CLASS3",
627
+ script_name: "SCRIPT3",
628
+ environment: "ENV3",
629
+ },
623
630
  ],
624
631
  },
625
632
  kv_namespaces: [
@@ -638,6 +645,13 @@ describe("normalizeAndValidateConfig()", () => {
638
645
  preview_bucket_name: "R2_PREVIEW_2",
639
646
  },
640
647
  ],
648
+ services: [
649
+ {
650
+ binding: "SERVICE_BINDING_1",
651
+ service: "SERVICE_TYPE_1",
652
+ environment: "SERVICE_BINDING_ENVIRONMENT_1",
653
+ },
654
+ ],
641
655
  unsafe: {
642
656
  bindings: [
643
657
  { name: "UNSAFE_BINDING_1", type: "UNSAFE_TYPE_1" },
@@ -661,9 +675,11 @@ describe("normalizeAndValidateConfig()", () => {
661
675
  );
662
676
  expect(diagnostics.hasErrors()).toBe(false);
663
677
  expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
664
- "Processing wrangler configuration:
665
- - \\"unsafe\\" fields are experimental and may change or break at any time."
666
- `);
678
+ "Processing wrangler configuration:
679
+ - \\"unsafe\\" fields are experimental and may change or break at any time.
680
+ - \\"services\\" fields are experimental and may change or break at any time.
681
+ - In wrangler.toml, you have configured [durable_objects] exported by this Worker (CLASS1), but no [migrations] for them. This may not work as expected until you add a [migrations] section to your wrangler.toml. Refer to https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml for more details."
682
+ `);
667
683
  });
668
684
 
669
685
  it("should error on invalid environment values", () => {
@@ -717,8 +733,8 @@ describe("normalizeAndValidateConfig()", () => {
717
733
  expect(diagnostics.hasWarnings()).toBe(false);
718
734
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
719
735
  "Processing wrangler configuration:
720
- - Expected \\"route\\" to be either a string, or an object with shape { pattern, zone_id | zone_name }, but got 888.
721
- - Expected \\"routes\\" to be an array of either strings or objects with the shape { pattern, zone_id | zone_name }, but these weren't valid: [
736
+ - Expected \\"route\\" to be either a string, or an object with shape { pattern, custom_domain, zone_id | zone_name }, but got 888.
737
+ - Expected \\"routes\\" to be an array of either strings or objects with the shape { pattern, custom_domain, zone_id | zone_name }, but these weren't valid: [
722
738
  666,
723
739
  777,
724
740
  {
@@ -1106,13 +1122,29 @@ describe("normalizeAndValidateConfig()", () => {
1106
1122
  durable_objects: {
1107
1123
  bindings: [
1108
1124
  {},
1109
- { name: "VALID" },
1125
+ { name: "MISSING_CLASS" },
1110
1126
  { name: 1555, class_name: 1666 },
1111
1127
  {
1112
1128
  name: 1777,
1113
1129
  class_name: 1888,
1114
1130
  script_name: 1999,
1115
1131
  },
1132
+ {
1133
+ name: "SOMENAME",
1134
+ class_name: "SomeClass",
1135
+ environment: "staging",
1136
+ },
1137
+ {
1138
+ name: 1778,
1139
+ class_name: 1889,
1140
+ script_name: 1992,
1141
+ environment: 2111,
1142
+ },
1143
+ {
1144
+ name: 1772,
1145
+ class_name: 1883,
1146
+ environment: 2112,
1147
+ },
1116
1148
  ],
1117
1149
  },
1118
1150
  } as unknown as RawConfig,
@@ -1125,7 +1157,12 @@ describe("normalizeAndValidateConfig()", () => {
1125
1157
  durable_objects: { bindings: expect.anything },
1126
1158
  })
1127
1159
  );
1128
- expect(diagnostics.hasWarnings()).toBe(false);
1160
+ expect(diagnostics.hasWarnings()).toBe(true);
1161
+ expect(diagnostics.hasErrors()).toBe(true);
1162
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1163
+ "Processing wrangler configuration:
1164
+ - In wrangler.toml, you have configured [durable_objects] exported by this Worker ((unnamed), (unnamed), 1666, SomeClass, 1883), but no [migrations] for them. This may not work as expected until you add a [migrations] section to your wrangler.toml. Refer to https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml for more details."
1165
+ `);
1129
1166
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1130
1167
  "Processing wrangler configuration:
1131
1168
 
@@ -1133,7 +1170,7 @@ describe("normalizeAndValidateConfig()", () => {
1133
1170
  - binding should have a string \\"name\\" field.
1134
1171
  - binding should have a string \\"class_name\\" field.
1135
1172
 
1136
- - \\"durable_objects.bindings[1]\\": {\\"name\\":\\"VALID\\"}
1173
+ - \\"durable_objects.bindings[1]\\": {\\"name\\":\\"MISSING_CLASS\\"}
1137
1174
  - binding should have a string \\"class_name\\" field.
1138
1175
 
1139
1176
  - \\"durable_objects.bindings[2]\\": {\\"name\\":1555,\\"class_name\\":1666}
@@ -1143,7 +1180,22 @@ describe("normalizeAndValidateConfig()", () => {
1143
1180
  - \\"durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
1144
1181
  - binding should have a string \\"name\\" field.
1145
1182
  - binding should have a string \\"class_name\\" field.
1146
- - binding should, optionally, have a string \\"script_name\\" field."
1183
+ - the field \\"script_name\\", when present, should be a string.
1184
+
1185
+ - \\"durable_objects.bindings[4]\\": {\\"name\\":\\"SOMENAME\\",\\"class_name\\":\\"SomeClass\\",\\"environment\\":\\"staging\\"}
1186
+ - binding should have a \\"script_name\\" field if \\"environment\\" is present.
1187
+
1188
+ - \\"durable_objects.bindings[5]\\": {\\"name\\":1778,\\"class_name\\":1889,\\"script_name\\":1992,\\"environment\\":2111}
1189
+ - binding should have a string \\"name\\" field.
1190
+ - binding should have a string \\"class_name\\" field.
1191
+ - the field \\"script_name\\", when present, should be a string.
1192
+ - the field \\"environment\\", when present, should be a string.
1193
+
1194
+ - \\"durable_objects.bindings[6]\\": {\\"name\\":1772,\\"class_name\\":1883,\\"environment\\":2112}
1195
+ - binding should have a string \\"name\\" field.
1196
+ - binding should have a string \\"class_name\\" field.
1197
+ - the field \\"environment\\", when present, should be a string.
1198
+ - binding should have a \\"script_name\\" field if \\"environment\\" is present."
1147
1199
  `);
1148
1200
  });
1149
1201
  });
@@ -1358,6 +1410,151 @@ describe("normalizeAndValidateConfig()", () => {
1358
1410
  });
1359
1411
  });
1360
1412
 
1413
+ describe("services field", () => {
1414
+ it("should error if services is an object", () => {
1415
+ const { config, diagnostics } = normalizeAndValidateConfig(
1416
+ { services: {} } as unknown as RawConfig,
1417
+ undefined,
1418
+ { env: undefined }
1419
+ );
1420
+
1421
+ expect(config).toEqual(
1422
+ expect.not.objectContaining({ services: expect.anything })
1423
+ );
1424
+ expect(diagnostics.hasWarnings()).toBe(true);
1425
+ expect(diagnostics.hasErrors()).toBe(true);
1426
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1427
+ "Processing wrangler configuration:
1428
+ - \\"services\\" fields are experimental and may change or break at any time."
1429
+ `);
1430
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1431
+ "Processing wrangler configuration:
1432
+ - The field \\"services\\" should be an array but got {}."
1433
+ `);
1434
+ });
1435
+
1436
+ it("should error if services is a string", () => {
1437
+ const { config, diagnostics } = normalizeAndValidateConfig(
1438
+ { services: "BAD" } as unknown as RawConfig,
1439
+ undefined,
1440
+ { env: undefined }
1441
+ );
1442
+
1443
+ expect(config).toEqual(
1444
+ expect.not.objectContaining({ services: expect.anything })
1445
+ );
1446
+ expect(diagnostics.hasWarnings()).toBe(true);
1447
+ expect(diagnostics.hasErrors()).toBe(true);
1448
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1449
+ "Processing wrangler configuration:
1450
+ - \\"services\\" fields are experimental and may change or break at any time."
1451
+ `);
1452
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1453
+ "Processing wrangler configuration:
1454
+ - The field \\"services\\" should be an array but got \\"BAD\\"."
1455
+ `);
1456
+ });
1457
+
1458
+ it("should error if services is a number", () => {
1459
+ const { config, diagnostics } = normalizeAndValidateConfig(
1460
+ { services: 999 } as unknown as RawConfig,
1461
+ undefined,
1462
+ { env: undefined }
1463
+ );
1464
+
1465
+ expect(config).toEqual(
1466
+ expect.not.objectContaining({ services: expect.anything })
1467
+ );
1468
+ expect(diagnostics.hasWarnings()).toBe(true);
1469
+ expect(diagnostics.hasErrors()).toBe(true);
1470
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1471
+ "Processing wrangler configuration:
1472
+ - \\"services\\" fields are experimental and may change or break at any time."
1473
+ `);
1474
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1475
+ "Processing wrangler configuration:
1476
+ - The field \\"services\\" should be an array but got 999."
1477
+ `);
1478
+ });
1479
+
1480
+ it("should error if services is null", () => {
1481
+ const { config, diagnostics } = normalizeAndValidateConfig(
1482
+ { services: null } as unknown as RawConfig,
1483
+ undefined,
1484
+ { env: undefined }
1485
+ );
1486
+
1487
+ expect(config).toEqual(
1488
+ expect.not.objectContaining({ services: expect.anything })
1489
+ );
1490
+ expect(diagnostics.hasWarnings()).toBe(true);
1491
+ expect(diagnostics.hasErrors()).toBe(true);
1492
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1493
+ "Processing wrangler configuration:
1494
+ - \\"services\\" fields are experimental and may change or break at any time."
1495
+ `);
1496
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1497
+ "Processing wrangler configuration:
1498
+ - The field \\"services\\" should be an array but got null."
1499
+ `);
1500
+ });
1501
+
1502
+ it("should error if services bindings are not valid", () => {
1503
+ const { config, diagnostics } = normalizeAndValidateConfig(
1504
+ {
1505
+ services: [
1506
+ {},
1507
+ { binding: "SERVICE_BINDING_1" },
1508
+ { binding: 123, service: 456 },
1509
+ { binding: 123, service: 456, environment: 789 },
1510
+ { binding: "SERVICE_BINDING_1", service: 456, environment: 789 },
1511
+ {
1512
+ binding: 123,
1513
+ service: "SERVICE_BINDING_SERVICE_1",
1514
+ environment: 789,
1515
+ },
1516
+ {
1517
+ binding: 123,
1518
+ service: 456,
1519
+ environment: "SERVICE_BINDING_ENVIRONMENT_1",
1520
+ },
1521
+ ],
1522
+ } as unknown as RawConfig,
1523
+ undefined,
1524
+ { env: undefined }
1525
+ );
1526
+
1527
+ expect(config).toEqual(
1528
+ expect.not.objectContaining({
1529
+ services: { bindings: expect.anything },
1530
+ })
1531
+ );
1532
+ expect(diagnostics.hasWarnings()).toBe(true);
1533
+ expect(diagnostics.hasErrors()).toBe(true);
1534
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
1535
+ "Processing wrangler configuration:
1536
+ - \\"services\\" fields are experimental and may change or break at any time."
1537
+ `);
1538
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1539
+ "Processing wrangler configuration:
1540
+ - \\"services[0]\\" bindings should have a string \\"binding\\" field but got {}.
1541
+ - \\"services[0]\\" bindings should have a string \\"service\\" field but got {}.
1542
+ - \\"services[1]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":\\"SERVICE_BINDING_1\\"}.
1543
+ - \\"services[2]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456}.
1544
+ - \\"services[2]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":123,\\"service\\":456}.
1545
+ - \\"services[3]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":789}.
1546
+ - \\"services[3]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":789}.
1547
+ - \\"services[3]\\" bindings should have a string \\"environment\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":789}.
1548
+ - \\"services[4]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":\\"SERVICE_BINDING_1\\",\\"service\\":456,\\"environment\\":789}.
1549
+ - \\"services[4]\\" bindings should have a string \\"environment\\" field but got {\\"binding\\":\\"SERVICE_BINDING_1\\",\\"service\\":456,\\"environment\\":789}.
1550
+ - \\"services[5]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":\\"SERVICE_BINDING_SERVICE_1\\",\\"environment\\":789}.
1551
+ - \\"services[5]\\" bindings should have a string \\"environment\\" field but got {\\"binding\\":123,\\"service\\":\\"SERVICE_BINDING_SERVICE_1\\",\\"environment\\":789}.
1552
+ - \\"services[6]\\" bindings should have a string \\"binding\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":\\"SERVICE_BINDING_ENVIRONMENT_1\\"}.
1553
+ - \\"services[6]\\" bindings should have a string \\"service\\" field but got {\\"binding\\":123,\\"service\\":456,\\"environment\\":\\"SERVICE_BINDING_ENVIRONMENT_1\\"}."
1554
+ `);
1555
+ });
1556
+ });
1557
+
1361
1558
  describe("unsafe field", () => {
1362
1559
  it("should error if unsafe is an array", () => {
1363
1560
  const { config, diagnostics } = normalizeAndValidateConfig(
@@ -1622,14 +1819,7 @@ describe("normalizeAndValidateConfig()", () => {
1622
1819
  - Deprecation: \\"zone_id\\":
1623
1820
  This is unnecessary since we can deduce this from routes directly.
1624
1821
  - Deprecation: \\"experimental_services\\":
1625
- The \\"experimental_services\\" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
1626
- \`\`\`
1627
- [[unsafe.bindings]]
1628
- name = \\"mock-name\\"
1629
- type = \\"service\\"
1630
- service = \\"SERVICE\\"
1631
- environment = \\"ENV\\"
1632
- \`\`\`"
1822
+ The \\"experimental_services\\" field is no longer supported. Simply rename the [experimental_services] field to [services]."
1633
1823
  `);
1634
1824
  });
1635
1825
  });
@@ -2045,8 +2235,8 @@ describe("normalizeAndValidateConfig()", () => {
2045
2235
  "Processing wrangler configuration:
2046
2236
 
2047
2237
  - \\"env.ENV1\\" environment configuration
2048
- - Expected \\"route\\" to be either a string, or an object with shape { pattern, zone_id | zone_name }, but got 888.
2049
- - Expected \\"routes\\" to be an array of either strings or objects with the shape { pattern, zone_id | zone_name }, but these weren't valid: [
2238
+ - Expected \\"route\\" to be either a string, or an object with shape { pattern, custom_domain, zone_id | zone_name }, but got 888.
2239
+ - Expected \\"routes\\" to be an array of either strings or objects with the shape { pattern, custom_domain, zone_id | zone_name }, but these weren't valid: [
2050
2240
  666,
2051
2241
  777
2052
2242
  ].
@@ -2284,7 +2474,12 @@ describe("normalizeAndValidateConfig()", () => {
2284
2474
  durable_objects: { bindings: expect.anything },
2285
2475
  })
2286
2476
  );
2287
- expect(diagnostics.hasWarnings()).toBe(false);
2477
+ expect(diagnostics.hasWarnings()).toBe(true);
2478
+ expect(diagnostics.hasErrors()).toBe(true);
2479
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2480
+ "Processing wrangler configuration:
2481
+ - In wrangler.toml, you have configured [durable_objects] exported by this Worker ((unnamed), (unnamed), 1666), but no [migrations] for them. This may not work as expected until you add a [migrations] section to your wrangler.toml. Refer to https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml for more details."
2482
+ `);
2288
2483
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2289
2484
  "Processing wrangler configuration:
2290
2485
 
@@ -2304,7 +2499,7 @@ describe("normalizeAndValidateConfig()", () => {
2304
2499
  - \\"env.ENV1.durable_objects.bindings[3]\\": {\\"name\\":1777,\\"class_name\\":1888,\\"script_name\\":1999}
2305
2500
  - binding should have a string \\"name\\" field.
2306
2501
  - binding should have a string \\"class_name\\" field.
2307
- - binding should, optionally, have a string \\"script_name\\" field."
2502
+ - the field \\"script_name\\", when present, should be a string."
2308
2503
  `);
2309
2504
  });
2310
2505
  });
@@ -2869,14 +3064,7 @@ describe("normalizeAndValidateConfig()", () => {
2869
3064
  - Deprecation: \\"zone_id\\":
2870
3065
  This is unnecessary since we can deduce this from routes directly.
2871
3066
  - Deprecation: \\"experimental_services\\":
2872
- The \\"experimental_services\\" field is no longer supported. Instead, use [[unsafe.bindings]] to enable experimental features. Add this to your wrangler.toml:
2873
- \`\`\`
2874
- [[unsafe.bindings]]
2875
- name = \\"mock-name\\"
2876
- type = \\"service\\"
2877
- service = \\"SERVICE\\"
2878
- environment = \\"ENV\\"
2879
- \`\`\`"
3067
+ The \\"experimental_services\\" field is no longer supported. Simply rename the [experimental_services] field to [services]."
2880
3068
  `);
2881
3069
  });
2882
3070
  });
@@ -225,6 +225,32 @@ describe("wrangler dev", () => {
225
225
  );
226
226
  });
227
227
 
228
+ it("should strip leading `*` from given host when deducing a zone id", async () => {
229
+ writeWranglerToml({
230
+ main: "index.js",
231
+ route: "*some-host.com/some/path/*",
232
+ });
233
+ fs.writeFileSync("index.js", `export default {};`);
234
+ mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
235
+ await runWrangler("dev");
236
+ expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
237
+ "some-host.com"
238
+ );
239
+ });
240
+
241
+ it("should strip leading `*.` from given host when deducing a zone id", async () => {
242
+ writeWranglerToml({
243
+ main: "index.js",
244
+ route: "*.some-host.com/some/path/*",
245
+ });
246
+ fs.writeFileSync("index.js", `export default {};`);
247
+ mockGetZones("some-host.com", [{ id: "some-zone-id" }]);
248
+ await runWrangler("dev");
249
+ expect((Dev as jest.Mock).mock.calls[0][0].zone.host).toEqual(
250
+ "some-host.com"
251
+ );
252
+ });
253
+
228
254
  it("should, when provided, use a configured zone_id", async () => {
229
255
  writeWranglerToml({
230
256
  main: "index.js",
@@ -649,7 +675,7 @@ describe("wrangler dev", () => {
649
675
  });
650
676
 
651
677
  describe("durable_objects", () => {
652
- it("should warn if there is one or more remote Durable Object", async () => {
678
+ it("should warn if there are remote Durable Objects, or missing migrations for local Durable Objects", async () => {
653
679
  writeWranglerToml({
654
680
  main: "index.js",
655
681
  durable_objects: {
@@ -674,7 +700,16 @@ describe("wrangler dev", () => {
674
700
  expect((Dev as jest.Mock).mock.calls[0][0].ip).toEqual("localhost");
675
701
  expect(std.out).toMatchInlineSnapshot(`""`);
676
702
  expect(std.warn).toMatchInlineSnapshot(`
677
- "▲ [WARNING] WARNING: You have Durable Object bindings that are not defined locally in the worker being developed.
703
+ "▲ [WARNING] Processing wrangler.toml configuration:
704
+
705
+ - In wrangler.toml, you have configured [durable_objects] exported by this Worker (CLASS_1,
706
+ CLASS_3), but no [migrations] for them. This may not work as expected until you add a [migrations]
707
+ section to your wrangler.toml. Refer to
708
+ https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml
709
+ for more details.
710
+
711
+
712
+ ▲ [WARNING] WARNING: You have Durable Object bindings that are not defined locally in the worker being developed.
678
713
 
679
714
  Be aware that changes to the data stored in these Durable Objects will be permanent and affect the
680
715
  live instances.
@@ -748,7 +783,11 @@ describe("wrangler dev", () => {
748
783
  expect(std).toMatchInlineSnapshot(`
749
784
  Object {
750
785
  "debug": "",
751
- "err": "wrangler dev [script]
786
+ "err": "X [ERROR] Not enough arguments following: site
787
+
788
+ ",
789
+ "out": "
790
+ wrangler dev [script]
752
791
 
753
792
  👂 Start a local server for developing your worker
754
793
 
@@ -785,12 +824,7 @@ describe("wrangler dev", () => {
785
824
  --minify Minify the script [boolean]
786
825
  --node-compat Enable node.js compatibility [boolean]
787
826
  --experimental-enable-local-persistence Enable persistence for this session (only for local mode) [boolean]
788
- --inspect Enable dev tools [deprecated] [boolean]
789
- X [ERROR] Not enough arguments following: site
790
-
791
- ",
792
- "out": "
793
- ",
827
+ --inspect Enable dev tools [deprecated] [boolean]",
794
828
  "warn": "",
795
829
  }
796
830
  `);
@@ -813,6 +847,34 @@ describe("wrangler dev", () => {
813
847
  `);
814
848
  });
815
849
  });
850
+
851
+ describe("service bindings", () => {
852
+ it("should warn when using service bindings", async () => {
853
+ writeWranglerToml({
854
+ services: [
855
+ { binding: "WorkerA", service: "A" },
856
+ { binding: "WorkerB", service: "B", environment: "staging" },
857
+ ],
858
+ });
859
+ fs.writeFileSync("index.js", `export default {};`);
860
+ await runWrangler("dev index.js");
861
+ expect(std).toMatchInlineSnapshot(`
862
+ Object {
863
+ "debug": "",
864
+ "err": "",
865
+ "out": "",
866
+ "warn": "▲ [WARNING] Processing wrangler.toml configuration:
867
+
868
+ - \\"services\\" fields are experimental and may change or break at any time.
869
+
870
+
871
+ ▲ [WARNING] This worker is bound to live services: WorkerA (A), WorkerB (B@staging)
872
+
873
+ ",
874
+ }
875
+ `);
876
+ });
877
+ });
816
878
  });
817
879
 
818
880
  function mockGetZones(domain: string, zones: { id: string }[] = []) {