wrangler 2.0.7 → 2.0.11

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/README.md CHANGED
@@ -24,7 +24,7 @@ npx wrangler init my-worker
24
24
  # try it out
25
25
  cd my-worker && npm run start
26
26
  # and then publish it
27
- npm run publish
27
+ npm run deploy
28
28
  ```
29
29
 
30
30
  ## Installation:
package/bin/wrangler.js CHANGED
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  const { spawn } = require("child_process");
3
- const { join } = require("path");
3
+ const path = require("path");
4
+ const fs = require("fs");
5
+ const os = require("os");
4
6
  const semiver = require("semiver");
5
7
 
6
8
  const MIN_NODE_VERSION = "16.7.0";
@@ -25,13 +27,23 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
25
27
  // TODO:
26
28
  // - should we log a warning here?
27
29
  // - maybe we can generate a certificate that concatenates with ours?
28
- // - is there a security concern/should we cleanup after we exit?
29
30
  //
30
31
  // I do think it'll be rare that someone wants to add a cert AND
31
32
  // use cloudflare WARP, but let's wait till the situation actually
32
33
  // arises before we do anything about it
33
34
  } else {
34
- pathToCACerts = join(__dirname, "../Cloudflare_CA.pem");
35
+ const osTempDir = os.tmpdir();
36
+ const certDir = path.join(osTempDir, "wrangler-cert");
37
+ const certPath = path.join(certDir, "Cloudflare_CA.pem");
38
+ // copy cert to the system temp dir if needed
39
+ if (!fs.existsSync(certPath)) {
40
+ fs.mkdirSync(certDir, { recursive: true });
41
+ fs.writeFileSync(
42
+ certPath,
43
+ fs.readFileSync(path.join(__dirname, "../Cloudflare_CA.pem"), "utf-8")
44
+ );
45
+ }
46
+ pathToCACerts = certPath;
35
47
  }
36
48
 
37
49
  wranglerProcess = spawn(
@@ -43,7 +55,7 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
43
55
  "--no-warnings",
44
56
  "--experimental-vm-modules",
45
57
  ...process.execArgv,
46
- join(__dirname, "../wrangler-dist/cli.js"),
58
+ path.join(__dirname, "../wrangler-dist/cli.js"),
47
59
  ...process.argv.slice(2),
48
60
  ],
49
61
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "2.0.7",
3
+ "version": "2.0.11",
4
4
  "author": "wrangler@cloudflare.com",
5
5
  "description": "Command-line interface for all things Cloudflare Workers",
6
6
  "bin": {
@@ -40,7 +40,7 @@
40
40
  "@esbuild-plugins/node-modules-polyfill": "^0.1.4",
41
41
  "blake3-wasm": "^2.1.5",
42
42
  "esbuild": "0.14.34",
43
- "miniflare": "2.4.0",
43
+ "miniflare": "^2.5.0",
44
44
  "nanoid": "^3.3.3",
45
45
  "path-to-regexp": "^6.2.0",
46
46
  "selfsigned": "^2.0.1",
@@ -61,6 +61,8 @@ describe("normalizeAndValidateConfig()", () => {
61
61
  data_blobs: undefined,
62
62
  workers_dev: undefined,
63
63
  zone_id: undefined,
64
+ minify: undefined,
65
+ node_compat: undefined,
64
66
  });
65
67
  expect(diagnostics.hasErrors()).toBe(false);
66
68
  expect(diagnostics.hasWarnings()).toBe(false);
@@ -163,68 +165,110 @@ describe("normalizeAndValidateConfig()", () => {
163
165
  `);
164
166
  });
165
167
 
166
- it("should override `migrations` config defaults with provided values", () => {
167
- const expectedConfig: RawConfig = {
168
- migrations: [
169
- {
170
- tag: "TAG",
171
- new_classes: ["CLASS_1", "CLASS_2"],
172
- renamed_classes: [
173
- {
174
- from: "FROM_CLASS",
175
- to: "TO_CLASS",
176
- },
177
- ],
178
- deleted_classes: ["CLASS_3", "CLASS_4"],
179
- },
180
- ],
181
- };
168
+ describe("migrations", () => {
169
+ it("should override `migrations` config defaults with provided values", () => {
170
+ const expectedConfig: RawConfig = {
171
+ migrations: [
172
+ {
173
+ tag: "TAG",
174
+ new_classes: ["CLASS_1", "CLASS_2"],
175
+ renamed_classes: [
176
+ {
177
+ from: "FROM_CLASS",
178
+ to: "TO_CLASS",
179
+ },
180
+ ],
181
+ deleted_classes: ["CLASS_3", "CLASS_4"],
182
+ },
183
+ ],
184
+ };
182
185
 
183
- const { config, diagnostics } = normalizeAndValidateConfig(
184
- expectedConfig,
185
- undefined,
186
- { env: undefined }
187
- );
186
+ const { config, diagnostics } = normalizeAndValidateConfig(
187
+ expectedConfig,
188
+ undefined,
189
+ { env: undefined }
190
+ );
188
191
 
189
- expect(config).toEqual(expect.objectContaining(expectedConfig));
190
- expect(diagnostics.hasErrors()).toBe(false);
191
- expect(diagnostics.hasWarnings()).toBe(false);
192
- });
192
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
193
+ expect(diagnostics.hasErrors()).toBe(false);
194
+ expect(diagnostics.hasWarnings()).toBe(false);
195
+ });
193
196
 
194
- it("should error on invalid `migrations` values", () => {
195
- const expectedConfig = {
196
- migrations: [
197
- {
198
- tag: 111,
199
- new_classes: [222, 333],
200
- renamed_classes: [
201
- {
202
- from: 444,
203
- to: 555,
204
- },
205
- ],
206
- deleted_classes: [666, 777],
207
- },
208
- ],
209
- };
197
+ it("should error on invalid `migrations` values", () => {
198
+ const expectedConfig = {
199
+ migrations: [
200
+ {
201
+ tag: 111,
202
+ new_classes: [222, 333],
203
+ renamed_classes: [
204
+ {
205
+ from: 444,
206
+ to: 555,
207
+ },
208
+ ],
209
+ deleted_classes: [666, 777],
210
+ },
211
+ ],
212
+ };
210
213
 
211
- const { config, diagnostics } = normalizeAndValidateConfig(
212
- expectedConfig as unknown as RawConfig,
213
- undefined,
214
- { env: undefined }
215
- );
214
+ const { config, diagnostics } = normalizeAndValidateConfig(
215
+ expectedConfig as unknown as RawConfig,
216
+ undefined,
217
+ { env: undefined }
218
+ );
216
219
 
217
- expect(config).toEqual(expect.objectContaining(expectedConfig));
218
- expect(diagnostics.hasWarnings()).toBe(false);
219
- expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
220
- "Processing wrangler configuration:
221
- - Expected \\"migrations[0].tag\\" to be of type string but got 111.
222
- - Expected \\"migrations[0].new_classes.[0]\\" to be of type string but got 222.
223
- - Expected \\"migrations[0].new_classes.[1]\\" to be of type string but got 333.
224
- - Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
225
- - Expected \\"migrations[0].deleted_classes.[0]\\" to be of type string but got 666.
226
- - Expected \\"migrations[0].deleted_classes.[1]\\" to be of type string but got 777."
227
- `);
220
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
221
+ expect(diagnostics.hasWarnings()).toBe(false);
222
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
223
+ "Processing wrangler configuration:
224
+ - Expected \\"migrations[0].tag\\" to be of type string but got 111.
225
+ - Expected \\"migrations[0].new_classes.[0]\\" to be of type string but got 222.
226
+ - Expected \\"migrations[0].new_classes.[1]\\" to be of type string but got 333.
227
+ - Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":444,\\"to\\":555}].
228
+ - Expected \\"migrations[0].deleted_classes.[0]\\" to be of type string but got 666.
229
+ - Expected \\"migrations[0].deleted_classes.[1]\\" to be of type string but got 777."
230
+ `);
231
+ });
232
+
233
+ it("should warn/error on unexpected fields on `migrations`", async () => {
234
+ const expectedConfig = {
235
+ migrations: [
236
+ {
237
+ tag: "TAG",
238
+ new_classes: ["CLASS_1", "CLASS_2"],
239
+ renamed_classes: [
240
+ {
241
+ from: "FROM_CLASS",
242
+ to: "TO_CLASS",
243
+ },
244
+ {
245
+ a: "something",
246
+ b: "someone",
247
+ },
248
+ ],
249
+ deleted_classes: ["CLASS_3", "CLASS_4"],
250
+ unrecognized_field: "FOO",
251
+ },
252
+ ],
253
+ };
254
+
255
+ const { config, diagnostics } = normalizeAndValidateConfig(
256
+ expectedConfig as unknown as RawConfig,
257
+ undefined,
258
+ { env: undefined }
259
+ );
260
+
261
+ expect(config).toEqual(expect.objectContaining(expectedConfig));
262
+ expect(diagnostics.hasErrors()).toBe(true);
263
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
264
+ "Processing wrangler configuration:
265
+ - Unexpected fields found in migrations field: \\"unrecognized_field\\""
266
+ `);
267
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
268
+ "Processing wrangler configuration:
269
+ - Expected \\"migrations[0].renamed_classes\\" to be an array of \\"{from: string, to: string}\\" objects but got [{\\"from\\":\\"FROM_CLASS\\",\\"to\\":\\"TO_CLASS\\"},{\\"a\\":\\"something\\",\\"b\\":\\"someone\\"}]."
270
+ `);
271
+ });
228
272
  });
229
273
 
230
274
  describe("site", () => {
@@ -394,6 +438,40 @@ describe("normalizeAndValidateConfig()", () => {
394
438
  expect(diagnostics.hasWarnings()).toBe(false);
395
439
  });
396
440
 
441
+ it("should warn on unexpected fields on `triggers`", async () => {
442
+ const expectedConfig: RawConfig = {
443
+ triggers: {
444
+ crons: ["1 * * * *"],
445
+ // @ts-expect-error we're purposely adding a field
446
+ // that doesn't belong here
447
+ someOtherfield: 123,
448
+ },
449
+ };
450
+
451
+ const { config, diagnostics } = normalizeAndValidateConfig(
452
+ expectedConfig,
453
+ "project/wrangler.toml",
454
+ { env: undefined }
455
+ );
456
+
457
+ expect(config).toEqual(
458
+ expect.objectContaining({
459
+ triggers: {
460
+ crons: ["1 * * * *"],
461
+ someOtherfield: 123,
462
+ },
463
+ })
464
+ );
465
+ expect(diagnostics.hasErrors()).toBe(false);
466
+ expect(diagnostics.hasWarnings()).toBe(true);
467
+
468
+ expect(normalizePath(diagnostics.renderWarnings()))
469
+ .toMatchInlineSnapshot(`
470
+ "Processing project/wrangler.toml configuration:
471
+ - Unexpected fields found in triggers field: \\"someOtherfield\\""
472
+ `);
473
+ });
474
+
397
475
  it("should error on invalid `wasm_modules` paths", () => {
398
476
  const expectedConfig = {
399
477
  wasm_modules: {
@@ -662,6 +740,8 @@ describe("normalizeAndValidateConfig()", () => {
662
740
  },
663
741
  ],
664
742
  },
743
+ minify: true,
744
+ node_compat: true,
665
745
  };
666
746
 
667
747
  const { config, diagnostics } = normalizeAndValidateConfig(
@@ -678,7 +758,15 @@ describe("normalizeAndValidateConfig()", () => {
678
758
  "Processing wrangler configuration:
679
759
  - \\"unsafe\\" fields are experimental and may change or break at any time.
680
760
  - \\"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."
761
+ - 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. Add this configuration to your wrangler.toml:
762
+
763
+ \`\`\`
764
+ [[migrations]]
765
+ tag = \\"v1\\" # Should be unique for each entry
766
+ new_classes = [\\"CLASS1\\"]
767
+ \`\`\`
768
+
769
+ Refer to https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml for more details."
682
770
  `);
683
771
  });
684
772
 
@@ -721,6 +809,8 @@ describe("normalizeAndValidateConfig()", () => {
721
809
  cwd: 1555,
722
810
  watch_dir: 1666,
723
811
  },
812
+ minify: "INVALID",
813
+ node_compat: "INVALID",
724
814
  } as unknown as RawEnvironment;
725
815
 
726
816
  const { config, diagnostics } = normalizeAndValidateConfig(
@@ -783,7 +873,9 @@ describe("normalizeAndValidateConfig()", () => {
783
873
  - Expected \\"tsconfig\\" to be of type string but got true.
784
874
  - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got 111.
785
875
  - Expected \\"main\\" to be of type string but got 1333.
786
- - Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\"."
876
+ - Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\".
877
+ - Expected \\"minify\\" to be of type boolean but got \\"INVALID\\".
878
+ - Expected \\"node_compat\\" to be of type boolean but got \\"INVALID\\"."
787
879
  `);
788
880
  });
789
881
 
@@ -1157,12 +1249,9 @@ describe("normalizeAndValidateConfig()", () => {
1157
1249
  durable_objects: { bindings: expect.anything },
1158
1250
  })
1159
1251
  );
1160
- expect(diagnostics.hasWarnings()).toBe(true);
1252
+ expect(diagnostics.hasWarnings()).toBe(false);
1253
+
1161
1254
  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
- `);
1166
1255
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
1167
1256
  "Processing wrangler configuration:
1168
1257
 
@@ -1912,6 +2001,8 @@ describe("normalizeAndValidateConfig()", () => {
1912
2001
  cwd: "CWD",
1913
2002
  watch_dir: "WATCH_DIR",
1914
2003
  },
2004
+ minify: true,
2005
+ node_compat: true,
1915
2006
  };
1916
2007
 
1917
2008
  const { config, diagnostics } = normalizeAndValidateConfig(
@@ -1952,6 +2043,8 @@ describe("normalizeAndValidateConfig()", () => {
1952
2043
  cwd: "ENV_CWD",
1953
2044
  watch_dir: "ENV_WATCH_DIR",
1954
2045
  },
2046
+ minify: false,
2047
+ node_compat: false,
1955
2048
  };
1956
2049
  const rawConfig: RawConfig = {
1957
2050
  name: "mock-name",
@@ -1971,6 +2064,8 @@ describe("normalizeAndValidateConfig()", () => {
1971
2064
  cwd: "CWD",
1972
2065
  watch_dir: "WATCH_DIR",
1973
2066
  },
2067
+ minify: true,
2068
+ node_compat: true,
1974
2069
  env: {
1975
2070
  ENV1: rawEnv,
1976
2071
  },
@@ -2221,6 +2316,8 @@ describe("normalizeAndValidateConfig()", () => {
2221
2316
  cwd: 1555,
2222
2317
  watch_dir: 1666,
2223
2318
  },
2319
+ minify: "INVALID",
2320
+ node_compat: "INVALID",
2224
2321
  } as unknown as RawEnvironment;
2225
2322
 
2226
2323
  const { config, diagnostics } = normalizeAndValidateConfig(
@@ -2253,7 +2350,9 @@ describe("normalizeAndValidateConfig()", () => {
2253
2350
  - Expected \\"tsconfig\\" to be of type string but got 123.
2254
2351
  - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got 111.
2255
2352
  - Expected \\"main\\" to be of type string but got 1333.
2256
- - Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\"."
2353
+ - Expected \\"usage_model\\" field to be one of [\\"bundled\\",\\"unbound\\"] but got \\"INVALID\\".
2354
+ - Expected \\"minify\\" to be of type boolean but got \\"INVALID\\".
2355
+ - Expected \\"node_compat\\" to be of type boolean but got \\"INVALID\\"."
2257
2356
  `);
2258
2357
  });
2259
2358
 
@@ -2474,12 +2573,8 @@ describe("normalizeAndValidateConfig()", () => {
2474
2573
  durable_objects: { bindings: expect.anything },
2475
2574
  })
2476
2575
  );
2477
- expect(diagnostics.hasWarnings()).toBe(true);
2576
+ expect(diagnostics.hasWarnings()).toBe(false);
2478
2577
  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
- `);
2483
2578
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2484
2579
  "Processing wrangler configuration:
2485
2580