wrangler 2.11.0 → 2.12.0

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 (46) hide show
  1. package/bin/wrangler.js +1 -1
  2. package/package.json +2 -2
  3. package/src/__tests__/configuration.test.ts +235 -6
  4. package/src/__tests__/dev.test.tsx +16 -1
  5. package/src/__tests__/init.test.ts +8 -7
  6. package/src/__tests__/pages/functions-build.test.ts +51 -0
  7. package/src/__tests__/publish.test.ts +99 -4
  8. package/src/__tests__/test-old-node-version.js +3 -3
  9. package/src/__tests__/tsconfig.tsbuildinfo +1 -1
  10. package/src/__tests__/type-generation.test.ts +1 -0
  11. package/src/api/dev.ts +3 -3
  12. package/src/api/pages/publish.tsx +7 -0
  13. package/src/bundle.ts +21 -8
  14. package/src/config/environment.ts +9 -4
  15. package/src/config/index.ts +12 -2
  16. package/src/config/validation-helpers.ts +1 -1
  17. package/src/config/validation.ts +58 -4
  18. package/src/create-worker-upload-form.ts +10 -2
  19. package/src/dev/dev.tsx +4 -2
  20. package/src/dev/local.tsx +10 -1
  21. package/src/dev/start-server.ts +9 -4
  22. package/src/dev/use-esbuild.ts +9 -5
  23. package/src/dev/validate-dev-props.ts +9 -0
  24. package/src/dev.tsx +27 -10
  25. package/src/index.ts +1 -1
  26. package/src/init.ts +1 -0
  27. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -1
  28. package/src/pages/build.ts +25 -5
  29. package/src/pages/buildFunctions.ts +7 -4
  30. package/src/pages/dev.ts +17 -6
  31. package/src/pages/functions/buildPlugin.ts +10 -3
  32. package/src/pages/functions/buildWorker.ts +12 -6
  33. package/src/pages/functions/tsconfig.tsbuildinfo +1 -1
  34. package/src/paths.ts +1 -1
  35. package/src/publish/index.ts +1 -1
  36. package/src/publish/publish.ts +19 -8
  37. package/src/r2/helpers.ts +1 -0
  38. package/src/secret/index.ts +1 -1
  39. package/src/type-generation.ts +1 -1
  40. package/src/worker.ts +8 -1
  41. package/templates/d1-beta-facade.js +2 -2
  42. package/templates/middleware/middleware-miniflare3-json-error.ts +17 -5
  43. package/templates/pages-template-plugin.ts +7 -3
  44. package/templates/tsconfig.tsbuildinfo +1 -1
  45. package/wrangler-dist/cli.d.ts +8 -4
  46. package/wrangler-dist/cli.js +218 -70
package/bin/wrangler.js CHANGED
@@ -20,7 +20,7 @@ function runWrangler() {
20
20
  // Note Volta and nvm are also recommended in the official docs:
21
21
  // https://developers.cloudflare.com/workers/get-started/guide#2-install-the-workers-cli
22
22
  console.error(
23
- `Wrangler requires at least node.js v${MIN_NODE_VERSION}. You are using v${process.versions.node}. Please update your version of node.js.
23
+ `Wrangler requires at least Node.js v${MIN_NODE_VERSION}. You are using v${process.versions.node}. Please update your version of Node.js.
24
24
 
25
25
  Consider using a Node.js version manager such as https://volta.sh/ or https://github.com/nvm-sh/nvm.`
26
26
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wrangler",
3
- "version": "2.11.0",
3
+ "version": "2.12.0",
4
4
  "description": "Command-line interface for all things Cloudflare Workers",
5
5
  "keywords": [
6
6
  "wrangler",
@@ -118,7 +118,7 @@
118
118
  "@cloudflare/workers-types": "^4.20221111.1",
119
119
  "@iarna/toml": "^3.0.0",
120
120
  "@microsoft/api-extractor": "^7.28.3",
121
- "@miniflare/tre": "^3.0.0-next.10",
121
+ "@miniflare/tre": "3.0.0-next.12",
122
122
  "@types/better-sqlite3": "^7.6.0",
123
123
  "@types/busboy": "^1.5.0",
124
124
  "@types/command-exists": "^1.2.0",
@@ -65,7 +65,8 @@ describe("normalizeAndValidateConfig()", () => {
65
65
  crons: [],
66
66
  },
67
67
  unsafe: {
68
- bindings: [],
68
+ bindings: undefined,
69
+ metadata: undefined,
69
70
  },
70
71
  dispatch_namespaces: [],
71
72
  mtls_certificates: [],
@@ -935,6 +936,7 @@ describe("normalizeAndValidateConfig()", () => {
935
936
  extra: "UNSAFE_EXTRA_1",
936
937
  },
937
938
  ],
939
+ metadata: undefined,
938
940
  },
939
941
  no_bundle: true,
940
942
  minify: true,
@@ -2329,7 +2331,7 @@ describe("normalizeAndValidateConfig()", () => {
2329
2331
  `);
2330
2332
  });
2331
2333
 
2332
- it("should error if unsafe.bindings is not defined", () => {
2334
+ it("should error if neither unsafe.bindings nor unsafe.metadata are defined", () => {
2333
2335
  const { diagnostics } = normalizeAndValidateConfig(
2334
2336
  { unsafe: {} } as unknown as RawConfig,
2335
2337
  undefined,
@@ -2341,9 +2343,37 @@ describe("normalizeAndValidateConfig()", () => {
2341
2343
  - \\"unsafe\\" fields are experimental and may change or break at any time."
2342
2344
  `);
2343
2345
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2346
+ "Processing wrangler configuration:
2347
+ - The field \\"unsafe\\" should contain at least one of \\"bindings\\" or \\"metadata\\" properties but got {}."
2348
+ `);
2349
+ });
2350
+
2351
+ it("should not error if at least unsafe.bindings is defined", () => {
2352
+ const { diagnostics } = normalizeAndValidateConfig(
2353
+ { unsafe: { bindings: [] } } as unknown as RawConfig,
2354
+ undefined,
2355
+ { env: undefined }
2356
+ );
2357
+
2358
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2344
2359
  "Processing wrangler configuration:
2345
- - The field \\"unsafe\\" is missing the required \\"bindings\\" property."
2360
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
2346
2361
  `);
2362
+ expect(diagnostics.hasErrors()).toBe(false);
2363
+ });
2364
+
2365
+ it("should not error if at least unsafe.metadata is defined", () => {
2366
+ const { diagnostics } = normalizeAndValidateConfig(
2367
+ { unsafe: { metadata: {} } } as unknown as RawConfig,
2368
+ undefined,
2369
+ { env: undefined }
2370
+ );
2371
+
2372
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2373
+ "Processing wrangler configuration:
2374
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
2375
+ `);
2376
+ expect(diagnostics.hasErrors()).toBe(false);
2347
2377
  });
2348
2378
 
2349
2379
  it("should error if unsafe.bindings is an object", () => {
@@ -2453,6 +2483,74 @@ describe("normalizeAndValidateConfig()", () => {
2453
2483
  - binding should have a string \\"type\\" field."
2454
2484
  `);
2455
2485
  });
2486
+
2487
+ it("should error if unsafe.metadata is an array", () => {
2488
+ const { diagnostics } = normalizeAndValidateConfig(
2489
+ { unsafe: { metadata: [] } } as unknown as RawConfig,
2490
+ undefined,
2491
+ { env: undefined }
2492
+ );
2493
+
2494
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2495
+ "Processing wrangler configuration:
2496
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
2497
+ `);
2498
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2499
+ "Processing wrangler configuration:
2500
+ - The field \\"unsafe.metadata\\" should be an object but got []."
2501
+ `);
2502
+ });
2503
+
2504
+ it("should error if unsafe.metadata is a string", () => {
2505
+ const { diagnostics } = normalizeAndValidateConfig(
2506
+ { unsafe: { metadata: "BAD" } } as unknown as RawConfig,
2507
+ undefined,
2508
+ { env: undefined }
2509
+ );
2510
+
2511
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2512
+ "Processing wrangler configuration:
2513
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
2514
+ `);
2515
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2516
+ "Processing wrangler configuration:
2517
+ - The field \\"unsafe.metadata\\" should be an object but got \\"BAD\\"."
2518
+ `);
2519
+ });
2520
+
2521
+ it("should error if unsafe.metadata is a number", () => {
2522
+ const { diagnostics } = normalizeAndValidateConfig(
2523
+ { unsafe: { metadata: 999 } } as unknown as RawConfig,
2524
+ undefined,
2525
+ { env: undefined }
2526
+ );
2527
+
2528
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2529
+ "Processing wrangler configuration:
2530
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
2531
+ `);
2532
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2533
+ "Processing wrangler configuration:
2534
+ - The field \\"unsafe.metadata\\" should be an object but got 999."
2535
+ `);
2536
+ });
2537
+
2538
+ it("should error if unsafe.metadata is null", () => {
2539
+ const { diagnostics } = normalizeAndValidateConfig(
2540
+ { unsafe: { metadata: null } } as unknown as RawConfig,
2541
+ undefined,
2542
+ { env: undefined }
2543
+ );
2544
+
2545
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
2546
+ "Processing wrangler configuration:
2547
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
2548
+ `);
2549
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
2550
+ "Processing wrangler configuration:
2551
+ - The field \\"unsafe.metadata\\" should be an object but got null."
2552
+ `);
2553
+ });
2456
2554
  });
2457
2555
 
2458
2556
  describe("(deprecated)", () => {
@@ -2836,7 +2934,10 @@ describe("normalizeAndValidateConfig()", () => {
2836
2934
  const r2_buckets: RawConfig["r2_buckets"] = [];
2837
2935
  const analytics_engine_datasets: RawConfig["analytics_engine_datasets"] =
2838
2936
  [];
2839
- const unsafe: RawConfig["unsafe"] = { bindings: [] };
2937
+ const unsafe: RawConfig["unsafe"] = {
2938
+ bindings: undefined,
2939
+ metadata: undefined,
2940
+ };
2840
2941
  const rawConfig: RawConfig = {
2841
2942
  define,
2842
2943
  vars,
@@ -3784,7 +3885,7 @@ describe("normalizeAndValidateConfig()", () => {
3784
3885
  `);
3785
3886
  });
3786
3887
 
3787
- it("should error if unsafe.bindings is not defined", () => {
3888
+ it("should error if neither unsafe.bindings nor unsafe.metadata are defined", () => {
3788
3889
  const { diagnostics } = normalizeAndValidateConfig(
3789
3890
  { env: { ENV1: { unsafe: {} } } } as unknown as RawConfig,
3790
3891
  undefined,
@@ -3798,11 +3899,47 @@ describe("normalizeAndValidateConfig()", () => {
3798
3899
  - \\"unsafe\\" fields are experimental and may change or break at any time."
3799
3900
  `);
3800
3901
  expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
3902
+ "Processing wrangler configuration:
3903
+
3904
+ - \\"env.ENV1\\" environment configuration
3905
+ - The field \\"env.ENV1.unsafe\\" should contain at least one of \\"bindings\\" or \\"metadata\\" properties but got {}."
3906
+ `);
3907
+ });
3908
+
3909
+ it("should not error if at least unsafe.bindings is undefined", () => {
3910
+ const { diagnostics } = normalizeAndValidateConfig(
3911
+ {
3912
+ env: { ENV1: { unsafe: { bindings: [] } } },
3913
+ } as unknown as RawConfig,
3914
+ undefined,
3915
+ { env: "ENV1" }
3916
+ );
3917
+
3918
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
3919
+ "Processing wrangler configuration:
3920
+
3921
+ - \\"env.ENV1\\" environment configuration
3922
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
3923
+ `);
3924
+ expect(diagnostics.hasErrors()).toBe(false);
3925
+ });
3926
+
3927
+ it("should not error if at least unsafe.metadata is undefined", () => {
3928
+ const { diagnostics } = normalizeAndValidateConfig(
3929
+ {
3930
+ env: { ENV1: { unsafe: { metadata: {} } } },
3931
+ } as unknown as RawConfig,
3932
+ undefined,
3933
+ { env: "ENV1" }
3934
+ );
3935
+
3936
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
3801
3937
  "Processing wrangler configuration:
3802
3938
 
3803
3939
  - \\"env.ENV1\\" environment configuration
3804
- - The field \\"env.ENV1.unsafe\\" is missing the required \\"bindings\\" property."
3940
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
3805
3941
  `);
3942
+ expect(diagnostics.hasErrors()).toBe(false);
3806
3943
  });
3807
3944
 
3808
3945
  it("should error if unsafe.bindings is an object", () => {
@@ -3944,6 +4081,98 @@ describe("normalizeAndValidateConfig()", () => {
3944
4081
  - binding should have a string \\"type\\" field."
3945
4082
  `);
3946
4083
  });
4084
+
4085
+ it("should error if unsafe.metadata is an array", () => {
4086
+ const { diagnostics } = normalizeAndValidateConfig(
4087
+ {
4088
+ env: { ENV1: { unsafe: { metadata: [] } } },
4089
+ } as unknown as RawConfig,
4090
+ undefined,
4091
+ { env: "ENV1" }
4092
+ );
4093
+
4094
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
4095
+ "Processing wrangler configuration:
4096
+
4097
+ - \\"env.ENV1\\" environment configuration
4098
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
4099
+ `);
4100
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
4101
+ "Processing wrangler configuration:
4102
+
4103
+ - \\"env.ENV1\\" environment configuration
4104
+ - The field \\"env.ENV1.unsafe.metadata\\" should be an object but got []."
4105
+ `);
4106
+ });
4107
+
4108
+ it("should error if unsafe.metadata is a string", () => {
4109
+ const { diagnostics } = normalizeAndValidateConfig(
4110
+ {
4111
+ env: { ENV1: { unsafe: { metadata: "BAD" } } },
4112
+ } as unknown as RawConfig,
4113
+ undefined,
4114
+ { env: "ENV1" }
4115
+ );
4116
+
4117
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
4118
+ "Processing wrangler configuration:
4119
+
4120
+ - \\"env.ENV1\\" environment configuration
4121
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
4122
+ `);
4123
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
4124
+ "Processing wrangler configuration:
4125
+
4126
+ - \\"env.ENV1\\" environment configuration
4127
+ - The field \\"env.ENV1.unsafe.metadata\\" should be an object but got \\"BAD\\"."
4128
+ `);
4129
+ });
4130
+
4131
+ it("should error if unsafe.metadata is a number", () => {
4132
+ const { diagnostics } = normalizeAndValidateConfig(
4133
+ {
4134
+ env: { ENV1: { unsafe: { metadata: 999 } } },
4135
+ } as unknown as RawConfig,
4136
+ undefined,
4137
+ { env: "ENV1" }
4138
+ );
4139
+
4140
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
4141
+ "Processing wrangler configuration:
4142
+
4143
+ - \\"env.ENV1\\" environment configuration
4144
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
4145
+ `);
4146
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
4147
+ "Processing wrangler configuration:
4148
+
4149
+ - \\"env.ENV1\\" environment configuration
4150
+ - The field \\"env.ENV1.unsafe.metadata\\" should be an object but got 999."
4151
+ `);
4152
+ });
4153
+
4154
+ it("should error if unsafe.metadata is null", () => {
4155
+ const { diagnostics } = normalizeAndValidateConfig(
4156
+ {
4157
+ env: { ENV1: { unsafe: { metadata: null } } },
4158
+ } as unknown as RawConfig,
4159
+ undefined,
4160
+ { env: "ENV1" }
4161
+ );
4162
+
4163
+ expect(diagnostics.renderWarnings()).toMatchInlineSnapshot(`
4164
+ "Processing wrangler configuration:
4165
+
4166
+ - \\"env.ENV1\\" environment configuration
4167
+ - \\"unsafe\\" fields are experimental and may change or break at any time."
4168
+ `);
4169
+ expect(diagnostics.renderErrors()).toMatchInlineSnapshot(`
4170
+ "Processing wrangler configuration:
4171
+
4172
+ - \\"env.ENV1\\" environment configuration
4173
+ - The field \\"env.ENV1.unsafe.metadata\\" should be an object but got null."
4174
+ `);
4175
+ });
3947
4176
  });
3948
4177
 
3949
4178
  describe("(deprecated)", () => {
@@ -1251,7 +1251,7 @@ describe("wrangler dev", () => {
1251
1251
  --experimental-local Run on my machine using the Cloudflare Workers runtime [boolean] [default: false]
1252
1252
  --experimental-local-remote-kv Read/write KV data from/to real namespaces on the Cloudflare network [boolean] [default: false]
1253
1253
  --minify Minify the script [boolean]
1254
- --node-compat Enable node.js compatibility [boolean]
1254
+ --node-compat Enable Node.js compatibility [boolean]
1255
1255
  --persist Enable persistence for local mode, using default path: .wrangler/state [boolean]
1256
1256
  --persist-to Specify directory to use for local persistence (implies --persist) [string]
1257
1257
  --live-reload Auto reload HTML pages when change is detected in local mode [boolean]
@@ -1566,6 +1566,21 @@ describe("wrangler dev", () => {
1566
1566
  `);
1567
1567
  });
1568
1568
  });
1569
+
1570
+ describe("`nodejs_compat` compatibility flag", () => {
1571
+ it("should conflict with the --node-compat option", async () => {
1572
+ writeWranglerToml();
1573
+ fs.writeFileSync("index.js", `export default {};`);
1574
+
1575
+ await expect(
1576
+ runWrangler(
1577
+ "dev index.js --compatibility-flag=nodejs_compat --node-compat"
1578
+ )
1579
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
1580
+ `"The \`nodejs_compat\` compatibility flag cannot be used in conjunction with the legacy \`--node-compat\` flag. If you want to use the Workers runtime Node.js compatibility features, please remove the \`--node-compat\` argument from your CLI command or \`node_compat = true\` from your config file."`
1581
+ );
1582
+ });
1583
+ });
1569
1584
  });
1570
1585
 
1571
1586
  function mockGetZones(domain: string, zones: { id: string }[] = []) {
@@ -2719,17 +2719,18 @@ describe("init", () => {
2719
2719
  DATA_BLOB_ONE = \\"DATA_BLOB_ONE\\"
2720
2720
  DATA_BLOB_TWO = \\"DATA_BLOB_TWO\\"
2721
2721
 
2722
- [[unsafe.bindings]]
2723
- type = \\"some unsafe thing\\"
2724
- name = \\"UNSAFE_BINDING_ONE\\"
2722
+ [unsafe]
2723
+ [[unsafe.bindings]]
2724
+ type = \\"some unsafe thing\\"
2725
+ name = \\"UNSAFE_BINDING_ONE\\"
2725
2726
 
2726
2727
  [unsafe.bindings.data.some]
2727
2728
  unsafe = \\"thing\\"
2728
2729
 
2729
- [[unsafe.bindings]]
2730
- type = \\"another unsafe thing\\"
2731
- name = \\"UNSAFE_BINDING_TWO\\"
2732
- data = 1_337
2730
+ [[unsafe.bindings]]
2731
+ type = \\"another unsafe thing\\"
2732
+ name = \\"UNSAFE_BINDING_TWO\\"
2733
+ data = 1_337
2733
2734
  "
2734
2735
  `);
2735
2736
  expect(std.out).toContain("cd isolinear-optical-chip");
@@ -399,4 +399,55 @@ export default {
399
399
 
400
400
  expect(std.err).toMatchInlineSnapshot(`""`);
401
401
  });
402
+
403
+ it("should leave Node.js imports when the `nodejs_compat` compatibility flag is set", async () => {
404
+ mkdirSync("functions");
405
+ writeFileSync(
406
+ "functions/hello.js",
407
+ `
408
+ import { AsyncLocalStorage } from 'node:async_hooks';
409
+
410
+ export async function onRequest() {
411
+ console.log(AsyncLocalStorage);
412
+ return new Response("Hello from Pages Functions");
413
+ }
414
+ `
415
+ );
416
+
417
+ await runWrangler(
418
+ `pages functions build --outfile=public/_worker.js --compatibility-flag=nodejs_compat`
419
+ );
420
+
421
+ expect(existsSync("public/_worker.js")).toBe(true);
422
+ expect(std.out).toMatchInlineSnapshot(`
423
+ "🚧 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/workers-sdk/issues/new/choose
424
+ ✨ Compiled Worker successfully"
425
+ `);
426
+
427
+ expect(readFileSync("public/_worker.js", "utf-8")).toContain(
428
+ `import { AsyncLocalStorage } from "node:async_hooks";`
429
+ );
430
+ });
431
+
432
+ it("should error at Node.js imports when the `nodejs_compat` compatibility flag is not set", async () => {
433
+ mkdirSync("functions");
434
+ writeFileSync(
435
+ "functions/hello.js",
436
+ `
437
+ import { AsyncLocalStorage } from 'node:async_hooks';
438
+
439
+ export async function onRequest() {
440
+ console.log(AsyncLocalStorage);
441
+ return new Response("Hello from Pages Functions");
442
+ }
443
+ `
444
+ );
445
+
446
+ await expect(
447
+ runWrangler(`pages functions build --outfile=public/_worker.js`)
448
+ ).rejects.toThrowErrorMatchingInlineSnapshot(`
449
+ "Build failed with 1 error:
450
+ hello.js:2:36: ERROR: Could not resolve \\"node:async_hooks\\""
451
+ `);
452
+ });
402
453
  });
@@ -4559,6 +4559,10 @@ addEventListener('fetch', event => {});`
4559
4559
  data: 1337,
4560
4560
  },
4561
4561
  ],
4562
+ metadata: {
4563
+ extra_data: "interesting value",
4564
+ more_data: "dubious value",
4565
+ },
4562
4566
  },
4563
4567
  vars: {
4564
4568
  ENV_VAR_ONE: 123,
@@ -4603,6 +4607,10 @@ addEventListener('fetch', event => {});`
4603
4607
 
4604
4608
  mockUploadWorkerRequest({
4605
4609
  expectedType: "sw",
4610
+ expectedUnsafeMetaData: {
4611
+ extra_data: "interesting value",
4612
+ more_data: "dubious value",
4613
+ },
4606
4614
  expectedBindings: [
4607
4615
  { json: 123, name: "ENV_VAR_ONE", type: "json" },
4608
4616
  {
@@ -4726,6 +4734,9 @@ addEventListener('fetch', event => {});`
4726
4734
  - Wasm Modules:
4727
4735
  - WASM_MODULE_ONE: some_wasm.wasm
4728
4736
  - WASM_MODULE_TWO: more_wasm.wasm
4737
+ - Unsafe Metadata:
4738
+ - extra_data: interesting value
4739
+ - more_data: dubious value
4729
4740
  Uploaded test-name (TIMINGS)
4730
4741
  Published test-name (TIMINGS)
4731
4742
  https://test-name.test-sub-domain.workers.dev
@@ -4794,6 +4805,7 @@ addEventListener('fetch', event => {});`
4794
4805
  data: 1337,
4795
4806
  },
4796
4807
  ],
4808
+ metadata: undefined,
4797
4809
  },
4798
4810
  vars: {
4799
4811
  ENV_VAR_ONE: 123,
@@ -4907,6 +4919,7 @@ addEventListener('fetch', event => {});`
4907
4919
  data: 1337,
4908
4920
  },
4909
4921
  ],
4922
+ metadata: undefined,
4910
4923
  },
4911
4924
  // text_blobs, vars, wasm_modules and data_blobs are fine because they're object literals,
4912
4925
  // and by definition cannot have two keys of the same name
@@ -5055,6 +5068,7 @@ addEventListener('fetch', event => {});`
5055
5068
  data: null,
5056
5069
  },
5057
5070
  ],
5071
+ metadata: undefined,
5058
5072
  },
5059
5073
  vars: {
5060
5074
  ENV_VAR_ONE: 123,
@@ -5992,6 +6006,7 @@ addEventListener('fetch', event => {});`
5992
6006
  param: "binding-param",
5993
6007
  },
5994
6008
  ],
6009
+ metadata: undefined,
5995
6010
  },
5996
6011
  });
5997
6012
  writeWorkerSource();
@@ -6036,6 +6051,7 @@ addEventListener('fetch', event => {});`
6036
6051
  text: "text",
6037
6052
  },
6038
6053
  ],
6054
+ metadata: undefined,
6039
6055
  },
6040
6056
  });
6041
6057
  writeWorkerSource();
@@ -6658,7 +6674,7 @@ export default{
6658
6674
  "err": "",
6659
6675
  "out": "Total Upload: xx KiB / gzip: xx KiB
6660
6676
  --dry-run: exiting now.",
6661
- "warn": "▲ [WARNING] Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.
6677
+ "warn": "▲ [WARNING] Enabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.
6662
6678
 
6663
6679
  ",
6664
6680
  }
@@ -6705,7 +6721,7 @@ export default{
6705
6721
  "err": "",
6706
6722
  "out": "Total Upload: xx KiB / gzip: xx KiB
6707
6723
  --dry-run: exiting now.",
6708
- "warn": "▲ [WARNING] Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.
6724
+ "warn": "▲ [WARNING] Enabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.
6709
6725
 
6710
6726
  ",
6711
6727
  }
@@ -6713,6 +6729,78 @@ export default{
6713
6729
  });
6714
6730
  });
6715
6731
 
6732
+ describe("`nodejs_compat` compatibility flag", () => {
6733
+ it('when absent, should error on any "external" `node:*` imports', async () => {
6734
+ writeWranglerToml();
6735
+ fs.writeFileSync(
6736
+ "index.js",
6737
+ `
6738
+ import AsyncHooks from 'node:async_hooks';
6739
+ console.log(AsyncHooks);
6740
+ export default {}
6741
+ `
6742
+ );
6743
+ let err: esbuild.BuildFailure | undefined;
6744
+ try {
6745
+ await runWrangler("publish index.js --dry-run"); // expecting this to throw, as node compatibility isn't enabled
6746
+ } catch (e) {
6747
+ err = e as esbuild.BuildFailure;
6748
+ }
6749
+ expect(
6750
+ esbuild.formatMessagesSync(err?.errors ?? [], { kind: "error" }).join()
6751
+ ).toMatch(/Could not resolve "node:async_hooks"/);
6752
+ });
6753
+
6754
+ it('when present, should support any "external" `node:*` imports', async () => {
6755
+ writeWranglerToml();
6756
+ fs.writeFileSync(
6757
+ "index.js",
6758
+ `
6759
+ import AsyncHooks from 'node:async_hooks';
6760
+ console.log(AsyncHooks);
6761
+ export default {}
6762
+ `
6763
+ );
6764
+
6765
+ await runWrangler(
6766
+ "publish index.js --dry-run --outdir=dist --compatibility-flag=nodejs_compat"
6767
+ );
6768
+
6769
+ expect(std).toMatchInlineSnapshot(`
6770
+ Object {
6771
+ "debug": "",
6772
+ "err": "",
6773
+ "out": "Total Upload: xx KiB / gzip: xx KiB
6774
+ --dry-run: exiting now.",
6775
+ "warn": "",
6776
+ }
6777
+ `);
6778
+ expect(fs.readFileSync("dist/index.js", { encoding: "utf-8" })).toContain(
6779
+ `import AsyncHooks from "node:async_hooks";`
6780
+ );
6781
+ });
6782
+
6783
+ it("should conflict with the --node-compat option", async () => {
6784
+ writeWranglerToml();
6785
+ fs.writeFileSync(
6786
+ "index.js",
6787
+ `
6788
+ import AsyncHooks from 'node:async_hooks';
6789
+ console.log(AsyncHooks);
6790
+ export default {}
6791
+ `
6792
+ );
6793
+
6794
+ await expect(
6795
+ runWrangler(
6796
+ "publish index.js --dry-run --outdir=dist --compatibility-flag=nodejs_compat --node-compat"
6797
+ )
6798
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
6799
+ `"The \`nodejs_compat\` compatibility flag cannot be used in conjunction with the legacy \`--node-compat\` flag. If you want to use the Workers runtime Node.js compatibility features, please remove the \`--node-compat\` argument from your CLI command or \`node_compat = true\` from your config file."`
6800
+ );
6801
+ });
6802
+ });
6803
+
6716
6804
  describe("bundle reporter", () => {
6717
6805
  it("should print the bundle size", async () => {
6718
6806
  fs.writeFileSync(
@@ -7125,7 +7213,7 @@ export default{
7125
7213
  "publish index.js --no-bundle --node-compat --dry-run --outdir dist"
7126
7214
  );
7127
7215
  expect(std.warn).toMatchInlineSnapshot(`
7128
- "▲ [WARNING] Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.
7216
+ "▲ [WARNING] Enabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.
7129
7217
 
7130
7218
 
7131
7219
  ▲ [WARNING] \`--node-compat\` and \`--no-bundle\` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process.
@@ -7145,7 +7233,7 @@ export default{
7145
7233
  fs.writeFileSync("index.js", scriptContent);
7146
7234
  await runWrangler("publish index.js --dry-run --outdir dist");
7147
7235
  expect(std.warn).toMatchInlineSnapshot(`
7148
- "▲ [WARNING] Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.
7236
+ "▲ [WARNING] Enabling Node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.
7149
7237
 
7150
7238
 
7151
7239
  ▲ [WARNING] \`--node-compat\` and \`--no-bundle\` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process.
@@ -7475,6 +7563,7 @@ function mockUploadWorkerRequest(
7475
7563
  expectedCompatibilityDate?: string;
7476
7564
  expectedCompatibilityFlags?: string[];
7477
7565
  expectedMigrations?: CfWorkerInit["migrations"];
7566
+ expectedUnsafeMetaData?: Record<string, string>;
7478
7567
  env?: string;
7479
7568
  legacyEnv?: boolean;
7480
7569
  sendScriptIds?: boolean;
@@ -7494,6 +7583,7 @@ function mockUploadWorkerRequest(
7494
7583
  env = undefined,
7495
7584
  legacyEnv = false,
7496
7585
  expectedMigrations,
7586
+ expectedUnsafeMetaData,
7497
7587
  sendScriptIds,
7498
7588
  keepVars,
7499
7589
  } = options;
@@ -7563,6 +7653,11 @@ function mockUploadWorkerRequest(
7563
7653
  if ("expectedMigrations" in options) {
7564
7654
  expect(metadata.migrations).toEqual(expectedMigrations);
7565
7655
  }
7656
+ if (expectedUnsafeMetaData !== undefined) {
7657
+ Object.keys(expectedUnsafeMetaData).forEach((key) => {
7658
+ expect(metadata[key]).toEqual(expectedUnsafeMetaData[key]);
7659
+ });
7660
+ }
7566
7661
  for (const [name, content] of Object.entries(expectedModules)) {
7567
7662
  expect(formBody.get(name)).toEqual(content);
7568
7663
  }
@@ -1,4 +1,4 @@
1
- // this test has to be run with a version of node.js older than 16.13 to pass
1
+ // this test has to be run with a version of Node.js older than 16.13 to pass
2
2
 
3
3
  const { spawn } = require("child_process");
4
4
  const path = require("path");
@@ -11,7 +11,7 @@ const wranglerProcess = spawn(
11
11
  { stdio: "pipe" }
12
12
  );
13
13
 
14
- const messageToMatch = "Wrangler requires at least node.js v16.13.0";
14
+ const messageToMatch = "Wrangler requires at least Node.js v16.13.0";
15
15
 
16
16
  wranglerProcess.once("exit", (code) => {
17
17
  try {
@@ -25,7 +25,7 @@ wranglerProcess.once("exit", (code) => {
25
25
  } catch (err) {
26
26
  console.error("Error:", err);
27
27
  throw new Error(
28
- "This test has to be run with a version of node.js under 16.13 to pass"
28
+ "This test has to be run with a version of Node.js under 16.13 to pass"
29
29
  );
30
30
  }
31
31
  });