wrangler 2.0.6 → 2.0.9

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/README.md +1 -1
  2. package/bin/wrangler.js +16 -4
  3. package/package.json +6 -4
  4. package/pages/functions/buildPlugin.ts +13 -0
  5. package/pages/functions/buildWorker.ts +13 -0
  6. package/src/__tests__/configuration.test.ts +132 -60
  7. package/src/__tests__/dev.test.tsx +168 -67
  8. package/src/__tests__/helpers/mock-dialogs.ts +41 -1
  9. package/src/__tests__/index.test.ts +25 -10
  10. package/src/__tests__/init.test.ts +252 -131
  11. package/src/__tests__/kv.test.ts +16 -16
  12. package/src/__tests__/package-manager.test.ts +154 -7
  13. package/src/__tests__/pages.test.ts +442 -38
  14. package/src/__tests__/parse.test.ts +5 -1
  15. package/src/__tests__/publish.test.ts +377 -84
  16. package/src/__tests__/secret.test.ts +4 -4
  17. package/src/__tests__/whoami.test.tsx +34 -0
  18. package/src/abort.d.ts +3 -0
  19. package/src/cfetch/index.ts +21 -4
  20. package/src/cfetch/internal.ts +20 -18
  21. package/src/config/config.ts +1 -1
  22. package/src/config/index.ts +162 -0
  23. package/src/config/validation.ts +77 -29
  24. package/src/create-worker-preview.ts +32 -22
  25. package/src/dev/dev.tsx +6 -16
  26. package/src/dev/remote.tsx +40 -16
  27. package/src/dialogs.tsx +48 -0
  28. package/src/durable.ts +102 -0
  29. package/src/index.tsx +291 -207
  30. package/src/inspect.ts +39 -0
  31. package/src/kv.ts +74 -25
  32. package/src/open-in-browser.ts +5 -12
  33. package/src/package-manager.ts +50 -3
  34. package/src/pages.tsx +218 -61
  35. package/src/parse.ts +21 -4
  36. package/src/proxy.ts +38 -22
  37. package/src/publish.ts +166 -108
  38. package/src/sites.tsx +8 -8
  39. package/src/user.tsx +12 -1
  40. package/src/whoami.tsx +3 -2
  41. package/src/worker.ts +2 -1
  42. package/src/zones.ts +73 -0
  43. package/templates/new-worker-scheduled.js +17 -0
  44. package/templates/new-worker-scheduled.ts +32 -0
  45. package/templates/new-worker.ts +16 -1
  46. package/wrangler-dist/cli.js +33066 -20052
@@ -471,7 +471,10 @@ describe("publish", () => {
471
471
  mockSubDomainRequest();
472
472
  await runWrangler("publish ./some-path/worker/index.js");
473
473
  expect(std.out).toMatchInlineSnapshot(`
474
- "Uploaded test-name (TIMINGS)
474
+ "Your worker has access to the following bindings:
475
+ - Vars:
476
+ - xyz: \\"123\\"
477
+ Uploaded test-name (TIMINGS)
475
478
  Published test-name (TIMINGS)
476
479
  test-name.test-sub-domain.workers.dev"
477
480
  `);
@@ -646,8 +649,85 @@ describe("publish", () => {
646
649
  await runWrangler("publish ./index --env dev --legacy-env false");
647
650
  });
648
651
 
652
+ it("should fallback to the Wrangler 1 zone-based API if the bulk-routes API fails", async () => {
653
+ writeWranglerToml({
654
+ routes: ["example.com/some-route/*"],
655
+ });
656
+ writeWorkerSource();
657
+ mockUpdateWorkerRequest({ enabled: false });
658
+ mockUploadWorkerRequest({ expectedType: "esm" });
659
+ // Simulate the bulk-routes API failing with a not authorized error.
660
+ mockUnauthorizedPublishRoutesRequest();
661
+ // Simulate that the worker has already been deployed to another route in this zone.
662
+ mockCollectKnownRoutesRequest([
663
+ {
664
+ pattern: "foo.example.com/other-route",
665
+ script: "test-name",
666
+ },
667
+ ]);
668
+ mockGetZoneFromHostRequest("example.com", "some-zone-id");
669
+ mockPublishRoutesFallbackRequest({
670
+ pattern: "example.com/some-route/*",
671
+ script: "test-name",
672
+ });
673
+ await runWrangler("publish ./index");
674
+
675
+ expect(std.err).toMatchInlineSnapshot(`""`);
676
+ expect(std.warn).toMatchInlineSnapshot(`
677
+ "▲ [WARNING] The current authentication token does not have 'All Zones' permissions.
678
+
679
+ Falling back to using the zone-based API endpoint to update each route individually.
680
+ Note that there is no access to routes associated with zones that the API token does not have
681
+ permission for.
682
+ Existing routes for this Worker in such zones will not be deleted.
683
+
684
+
685
+ ▲ [WARNING] Previously deployed routes:
686
+
687
+ The following routes were already associated with this worker, and have not been deleted:
688
+ - \\"foo.example.com/other-route\\"
689
+ If these routes are not wanted then you can remove them in the dashboard.
690
+
691
+ "
692
+ `);
693
+ expect(std.out).toMatchInlineSnapshot(`
694
+ "Uploaded test-name (TIMINGS)
695
+ Published test-name (TIMINGS)
696
+ example.com/some-route/*"
697
+ `);
698
+ });
699
+
700
+ it("should error if the bulk-routes API fails and trying to push to a non-production environment", async () => {
701
+ writeWranglerToml({
702
+ routes: ["example.com/some-route/*"],
703
+ legacy_env: false,
704
+ });
705
+ writeWorkerSource();
706
+ mockUpdateWorkerRequest({ env: "staging", enabled: false });
707
+ mockUploadWorkerRequest({ env: "staging", expectedType: "esm" });
708
+ // Simulate the bulk-routes API failing with a not authorized error.
709
+ mockUnauthorizedPublishRoutesRequest({ env: "staging" });
710
+ // Simulate that the worker has already been deployed to another route in this zone.
711
+ mockCollectKnownRoutesRequest([
712
+ {
713
+ pattern: "foo.example.com/other-route",
714
+ script: "test-name",
715
+ },
716
+ ]);
717
+ mockGetZoneFromHostRequest("example.com", "some-zone-id");
718
+ mockPublishRoutesFallbackRequest({
719
+ pattern: "example.com/some-route/*",
720
+ script: "test-name",
721
+ });
722
+ await expect(runWrangler("publish ./index --env=staging")).rejects
723
+ .toThrowErrorMatchingInlineSnapshot(`
724
+ "Service environments combined with an API token that doesn't have 'All Zones' permissions is not supported.
725
+ Either turn off service environments by setting \`legacy_env = true\`, creating an API token with 'All Zones' permissions, or logging in via OAuth"
726
+ `);
727
+ });
728
+
649
729
  describe("custom domains", () => {
650
- it("should publish routes marked with 'custom_domain' as seperate custom domains", async () => {
730
+ it("should publish routes marked with 'custom_domain' as separate custom domains", async () => {
651
731
  writeWranglerToml({
652
732
  routes: [{ pattern: "api.example.com", custom_domain: true }],
653
733
  });
@@ -1118,7 +1198,7 @@ addEventListener('fetch', event => {});`
1118
1198
 
1119
1199
  expect(std.out).toMatchInlineSnapshot(`
1120
1200
  "
1121
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1201
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1122
1202
  `);
1123
1203
  expect(std.err).toMatchInlineSnapshot(`
1124
1204
  "X [ERROR] Processing wrangler.toml configuration:
@@ -1276,7 +1356,7 @@ addEventListener('fetch', event => {});`
1276
1356
 
1277
1357
  expect(std.out).toMatchInlineSnapshot(`
1278
1358
  "
1279
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
1359
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1280
1360
  `);
1281
1361
  expect(std.err).toMatchInlineSnapshot(`
1282
1362
  "X [ERROR] Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler publish path/to/script\`) or the \`main\` config field.
@@ -1324,6 +1404,56 @@ addEventListener('fetch', event => {});`
1324
1404
  expect(std.err).toMatchInlineSnapshot(`""`);
1325
1405
  });
1326
1406
 
1407
+ it("should not contain backslash for assets with nested directories", async () => {
1408
+ const assets = [
1409
+ { filePath: "assets/subdir/file-1.txt", content: "Content of file-1" },
1410
+ { filePath: "assets/subdir/file-2.txt", content: "Content of file-2" },
1411
+ ];
1412
+ const kvNamespace = {
1413
+ title: "__test-name-workers_sites_assets",
1414
+ id: "__test-name-workers_sites_assets-id",
1415
+ };
1416
+ writeWranglerToml({
1417
+ main: "./index.js",
1418
+ site: {
1419
+ bucket: "assets",
1420
+ },
1421
+ });
1422
+ writeWorkerSource();
1423
+ writeAssets(assets);
1424
+ mockUploadWorkerRequest({
1425
+ expectedBindings: [
1426
+ {
1427
+ name: "__STATIC_CONTENT",
1428
+ namespace_id: "__test-name-workers_sites_assets-id",
1429
+ type: "kv_namespace",
1430
+ },
1431
+ ],
1432
+ expectedModules: {
1433
+ __STATIC_CONTENT_MANIFEST:
1434
+ '{"subdir/file-1.txt":"assets/subdir/file-1.2ca234f380.txt","subdir/file-2.txt":"assets/subdir/file-2.5938485188.txt"}',
1435
+ },
1436
+ });
1437
+ mockSubDomainRequest();
1438
+ mockListKVNamespacesRequest(kvNamespace);
1439
+ mockKeyListRequest(kvNamespace.id, []);
1440
+ mockUploadAssetsToKVRequest(kvNamespace.id, assets);
1441
+
1442
+ await runWrangler("publish");
1443
+
1444
+ expect(std.out).toMatchInlineSnapshot(`
1445
+ "Reading assets/subdir/file-1.txt...
1446
+ Uploading as assets/subdir/file-1.2ca234f380.txt...
1447
+ Reading assets/subdir/file-2.txt...
1448
+ Uploading as assets/subdir/file-2.5938485188.txt...
1449
+ ↗️ Done syncing assets
1450
+ Uploaded test-name (TIMINGS)
1451
+ Published test-name (TIMINGS)
1452
+ test-name.test-sub-domain.workers.dev"
1453
+ `);
1454
+ expect(std.err).toMatchInlineSnapshot(`""`);
1455
+ });
1456
+
1327
1457
  it("when using a service-worker type, it should add an asset manifest as a text_blob, and bind to a namespace", async () => {
1328
1458
  const assets = [
1329
1459
  { filePath: "assets/file-1.txt", content: "Content of file-1" },
@@ -1937,7 +2067,7 @@ addEventListener('fetch', event => {});`
1937
2067
  "Reading assets/large-file.txt...
1938
2068
  Uploading as assets/large-file.0ea0637a45.txt...
1939
2069
 
1940
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
2070
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1941
2071
  `);
1942
2072
  expect(std.err).toMatchInlineSnapshot(`
1943
2073
  "X [ERROR] File assets/too-large-file.txt is too big, it should be under 25 MiB. See https://developers.cloudflare.com/workers/platform/limits#kv-limits
@@ -1977,7 +2107,7 @@ addEventListener('fetch', event => {});`
1977
2107
  expect(std.out).toMatchInlineSnapshot(`
1978
2108
  "Reading assets/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/file.txt...
1979
2109
 
1980
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
2110
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
1981
2111
  `);
1982
2112
  expect(std.err).toMatchInlineSnapshot(`
1983
2113
  "X [ERROR] The asset path key \\"assets/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/folder/file.3da0d0cd12.txt\\" exceeds the maximum key size limit of 512. See https://developers.cloudflare.com/workers/platform/limits#kv-limits\\",
@@ -2688,7 +2818,7 @@ addEventListener('fetch', event => {});`
2688
2818
  expect(std.out).toMatchInlineSnapshot(`
2689
2819
  "Running custom build: node -e \\"console.log('custom build');\\"
2690
2820
 
2691
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
2821
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
2692
2822
  `);
2693
2823
  expect(std.err).toMatchInlineSnapshot(`
2694
2824
  "X [ERROR] The expected output file at \\"index.js\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
@@ -2727,7 +2857,7 @@ addEventListener('fetch', event => {});`
2727
2857
  expect(std.out).toMatchInlineSnapshot(`
2728
2858
  "Running custom build: node -e \\"console.log('custom build');\\"
2729
2859
 
2730
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
2860
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
2731
2861
  `);
2732
2862
  expect(std.err).toMatchInlineSnapshot(`
2733
2863
  "X [ERROR] The expected output file at \\".\\" was not found after running custom build: node -e \\"console.log('custom build');\\".
@@ -2829,13 +2959,30 @@ addEventListener('fetch', event => {});`
2829
2959
  mockUploadWorkerRequest();
2830
2960
  await runWrangler("publish index.js");
2831
2961
  expect(std.out).toMatchInlineSnapshot(`
2832
- "Uploaded test-name (TIMINGS)
2962
+ "Your worker has access to the following bindings:
2963
+ - Durable Objects:
2964
+ - SOMENAME: SomeClass
2965
+ Uploaded test-name (TIMINGS)
2833
2966
  Published test-name (TIMINGS)
2834
2967
  test-name.test-sub-domain.workers.dev"
2835
2968
  `);
2836
2969
  expect(std.err).toMatchInlineSnapshot(`""`);
2837
2970
  expect(std.warn).toMatchInlineSnapshot(`
2838
- "▲ [WARNING] In wrangler.toml, you have configured [durable_objects] exported by this Worker (SomeClass), 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.
2971
+ "▲ [WARNING] Processing wrangler.toml configuration:
2972
+
2973
+ - In wrangler.toml, you have configured [durable_objects] exported by this Worker (SomeClass),
2974
+ but no [migrations] for them. This may not work as expected until you add a [migrations] section
2975
+ to your wrangler.toml. Add this configuration to your wrangler.toml:
2976
+
2977
+ \`\`\`
2978
+ [[migrations]]
2979
+ tag = \\"v1\\" # Should be unique for each entry
2980
+ new_classes = [\\"SomeClass\\"]
2981
+ \`\`\`
2982
+
2983
+ Refer to
2984
+ https://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml
2985
+ for more details.
2839
2986
 
2840
2987
  "
2841
2988
  `);
@@ -2861,7 +3008,10 @@ addEventListener('fetch', event => {});`
2861
3008
  mockUploadWorkerRequest();
2862
3009
  await runWrangler("publish index.js");
2863
3010
  expect(std.out).toMatchInlineSnapshot(`
2864
- "Uploaded test-name (TIMINGS)
3011
+ "Your worker has access to the following bindings:
3012
+ - Durable Objects:
3013
+ - SOMENAME: SomeClass (defined in some-script)
3014
+ Uploaded test-name (TIMINGS)
2865
3015
  Published test-name (TIMINGS)
2866
3016
  test-name.test-sub-domain.workers.dev"
2867
3017
  `);
@@ -2900,7 +3050,11 @@ addEventListener('fetch', event => {});`
2900
3050
 
2901
3051
  await runWrangler("publish index.js");
2902
3052
  expect(std.out).toMatchInlineSnapshot(`
2903
- "Uploaded test-name (TIMINGS)
3053
+ "Your worker has access to the following bindings:
3054
+ - Durable Objects:
3055
+ - SOMENAME: SomeClass
3056
+ - SOMEOTHERNAME: SomeOtherClass
3057
+ Uploaded test-name (TIMINGS)
2904
3058
  Published test-name (TIMINGS)
2905
3059
  test-name.test-sub-domain.workers.dev"
2906
3060
  `);
@@ -2946,7 +3100,11 @@ addEventListener('fetch', event => {});`
2946
3100
  Object {
2947
3101
  "debug": "",
2948
3102
  "err": "",
2949
- "out": "Uploaded test-name (TIMINGS)
3103
+ "out": "Your worker has access to the following bindings:
3104
+ - Durable Objects:
3105
+ - SOMENAME: SomeClass
3106
+ - SOMEOTHERNAME: SomeOtherClass
3107
+ Uploaded test-name (TIMINGS)
2950
3108
  Published test-name (TIMINGS)
2951
3109
  test-name.test-sub-domain.workers.dev",
2952
3110
  "warn": "",
@@ -2985,7 +3143,11 @@ addEventListener('fetch', event => {});`
2985
3143
  Object {
2986
3144
  "debug": "",
2987
3145
  "err": "",
2988
- "out": "Uploaded test-name (TIMINGS)
3146
+ "out": "Your worker has access to the following bindings:
3147
+ - Durable Objects:
3148
+ - SOMENAME: SomeClass
3149
+ - SOMEOTHERNAME: SomeOtherClass
3150
+ Uploaded test-name (TIMINGS)
2989
3151
  Published test-name (TIMINGS)
2990
3152
  test-name.test-sub-domain.workers.dev",
2991
3153
  "warn": "",
@@ -3026,7 +3188,11 @@ addEventListener('fetch', event => {});`
3026
3188
 
3027
3189
  await runWrangler("publish index.js --legacy-env false");
3028
3190
  expect(std.out).toMatchInlineSnapshot(`
3029
- "Uploaded test-name (TIMINGS)
3191
+ "Your worker has access to the following bindings:
3192
+ - Durable Objects:
3193
+ - SOMENAME: SomeClass
3194
+ - SOMEOTHERNAME: SomeOtherClass
3195
+ Uploaded test-name (TIMINGS)
3030
3196
  Published test-name (TIMINGS)
3031
3197
  test-name.test-sub-domain.workers.dev"
3032
3198
  `);
@@ -3084,7 +3250,11 @@ addEventListener('fetch', event => {});`
3084
3250
 
3085
3251
  await runWrangler("publish index.js --legacy-env false --env xyz");
3086
3252
  expect(std.out).toMatchInlineSnapshot(`
3087
- "Uploaded test-name (xyz) (TIMINGS)
3253
+ "Your worker has access to the following bindings:
3254
+ - Durable Objects:
3255
+ - SOMENAME: SomeClass
3256
+ - SOMEOTHERNAME: SomeOtherClass
3257
+ Uploaded test-name (xyz) (TIMINGS)
3088
3258
  Published test-name (xyz) (TIMINGS)
3089
3259
  xyz.test-name.test-sub-domain.workers.dev"
3090
3260
  `);
@@ -3138,7 +3308,11 @@ addEventListener('fetch', event => {});`
3138
3308
  Object {
3139
3309
  "debug": "",
3140
3310
  "err": "",
3141
- "out": "Uploaded test-name (TIMINGS)
3311
+ "out": "Your worker has access to the following bindings:
3312
+ - Durable Objects:
3313
+ - SOMENAME: SomeClass
3314
+ - SOMEOTHERNAME: SomeOtherClass
3315
+ Uploaded test-name (TIMINGS)
3142
3316
  Published test-name (TIMINGS)
3143
3317
  test-name.test-sub-domain.workers.dev",
3144
3318
  "warn": "▲ [WARNING] Processing wrangler.toml configuration:
@@ -3202,7 +3376,11 @@ addEventListener('fetch', event => {});`
3202
3376
  Object {
3203
3377
  "debug": "",
3204
3378
  "err": "",
3205
- "out": "Uploaded test-name (xyz) (TIMINGS)
3379
+ "out": "Your worker has access to the following bindings:
3380
+ - Durable Objects:
3381
+ - SOMENAME: SomeClass
3382
+ - SOMEOTHERNAME: SomeOtherClass
3383
+ Uploaded test-name (xyz) (TIMINGS)
3206
3384
  Published test-name (xyz) (TIMINGS)
3207
3385
  xyz.test-name.test-sub-domain.workers.dev",
3208
3386
  "warn": "▲ [WARNING] Processing wrangler.toml configuration:
@@ -3366,7 +3544,32 @@ addEventListener('fetch', event => {});`
3366
3544
 
3367
3545
  await expect(runWrangler("publish index.js")).resolves.toBeUndefined();
3368
3546
  expect(std.out).toMatchInlineSnapshot(`
3369
- "Uploaded test-name (TIMINGS)
3547
+ "Your worker has access to the following bindings:
3548
+ - Data Blobs:
3549
+ - DATA_BLOB_ONE: some-data-blob.bin
3550
+ - DATA_BLOB_TWO: more-data-blob.bin
3551
+ - Durable Objects:
3552
+ - DURABLE_OBJECT_ONE: SomeDurableObject (defined in some-durable-object-worker)
3553
+ - DURABLE_OBJECT_TWO: AnotherDurableObject (defined in another-durable-object-worker) - staging
3554
+ - KV Namespaces:
3555
+ - KV_NAMESPACE_ONE: kv-ns-one-id
3556
+ - KV_NAMESPACE_TWO: kv-ns-two-id
3557
+ - R2 Buckets:
3558
+ - R2_BUCKET_ONE: r2-bucket-one-name
3559
+ - R2_BUCKET_TWO: r2-bucket-two-name
3560
+ - Text Blobs:
3561
+ - TEXT_BLOB_ONE: my-entire-app-depends-on-this.cfg
3562
+ - TEXT_BLOB_TWO: the-entirety-of-human-knowledge.txt
3563
+ - Unsafe:
3564
+ - some unsafe thing: UNSAFE_BINDING_ONE
3565
+ - another unsafe thing: UNSAFE_BINDING_TWO
3566
+ - Vars:
3567
+ - ENV_VAR_ONE: \\"123\\"
3568
+ - ENV_VAR_TWO: \\"Hello, I'm an environment variable\\"
3569
+ - Wasm Modules:
3570
+ - WASM_MODULE_ONE: some_wasm.wasm
3571
+ - WASM_MODULE_TWO: more_wasm.wasm
3572
+ Uploaded test-name (TIMINGS)
3370
3573
  Published test-name (TIMINGS)
3371
3574
  test-name.test-sub-domain.workers.dev"
3372
3575
  `);
@@ -3463,7 +3666,7 @@ addEventListener('fetch', event => {});`
3463
3666
  `);
3464
3667
  expect(std.out).toMatchInlineSnapshot(`
3465
3668
  "
3466
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
3669
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
3467
3670
  `);
3468
3671
  expect(std.err).toMatchInlineSnapshot(`
3469
3672
  "X [ERROR] Processing wrangler.toml configuration:
@@ -3562,7 +3765,7 @@ addEventListener('fetch', event => {});`
3562
3765
  `);
3563
3766
  expect(std.out).toMatchInlineSnapshot(`
3564
3767
  "
3565
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
3768
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
3566
3769
  `);
3567
3770
  expect(std.err).toMatchInlineSnapshot(`
3568
3771
  "X [ERROR] Processing wrangler.toml configuration:
@@ -3696,7 +3899,7 @@ addEventListener('fetch', event => {});`
3696
3899
  `);
3697
3900
  expect(std.out).toMatchInlineSnapshot(`
3698
3901
  "
3699
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
3902
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
3700
3903
  `);
3701
3904
  expect(std.err).toMatchInlineSnapshot(`
3702
3905
  "X [ERROR] Processing wrangler.toml configuration:
@@ -3742,10 +3945,13 @@ addEventListener('fetch', event => {});`
3742
3945
  mockSubDomainRequest();
3743
3946
  await runWrangler("publish index.js");
3744
3947
  expect(std.out).toMatchInlineSnapshot(`
3745
- "Uploaded test-name (TIMINGS)
3746
- Published test-name (TIMINGS)
3747
- test-name.test-sub-domain.workers.dev"
3748
- `);
3948
+ "Your worker has access to the following bindings:
3949
+ - Wasm Modules:
3950
+ - TESTWASMNAME: path/to/test.wasm
3951
+ Uploaded test-name (TIMINGS)
3952
+ Published test-name (TIMINGS)
3953
+ test-name.test-sub-domain.workers.dev"
3954
+ `);
3749
3955
  expect(std.err).toMatchInlineSnapshot(`""`);
3750
3956
  expect(std.warn).toMatchInlineSnapshot(`""`);
3751
3957
  });
@@ -3767,7 +3973,7 @@ addEventListener('fetch', event => {});`
3767
3973
  );
3768
3974
  expect(std.out).toMatchInlineSnapshot(`
3769
3975
  "
3770
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
3976
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
3771
3977
  `);
3772
3978
  expect(std.err).toMatchInlineSnapshot(`
3773
3979
  "X [ERROR] You cannot configure [wasm_modules] with an ES module worker. Instead, import the .wasm module directly in your code
@@ -3808,10 +4014,13 @@ addEventListener('fetch', event => {});`
3808
4014
  mockSubDomainRequest();
3809
4015
  await runWrangler("publish index.js --config ./path/to/wrangler.toml");
3810
4016
  expect(std.out).toMatchInlineSnapshot(`
3811
- "Uploaded test-name (TIMINGS)
3812
- Published test-name (TIMINGS)
3813
- test-name.test-sub-domain.workers.dev"
3814
- `);
4017
+ "Your worker has access to the following bindings:
4018
+ - Wasm Modules:
4019
+ - TESTWASMNAME: path/to/and/the/path/to/test.wasm
4020
+ Uploaded test-name (TIMINGS)
4021
+ Published test-name (TIMINGS)
4022
+ test-name.test-sub-domain.workers.dev"
4023
+ `);
3815
4024
  expect(std.err).toMatchInlineSnapshot(`""`);
3816
4025
  expect(std.warn).toMatchInlineSnapshot(`""`);
3817
4026
  });
@@ -3873,10 +4082,13 @@ addEventListener('fetch', event => {});`
3873
4082
  mockSubDomainRequest();
3874
4083
  await runWrangler("publish index.js");
3875
4084
  expect(std.out).toMatchInlineSnapshot(`
3876
- "Uploaded test-name (TIMINGS)
3877
- Published test-name (TIMINGS)
3878
- test-name.test-sub-domain.workers.dev"
3879
- `);
4085
+ "Your worker has access to the following bindings:
4086
+ - Text Blobs:
4087
+ - TESTTEXTBLOBNAME: path/to/text.file
4088
+ Uploaded test-name (TIMINGS)
4089
+ Published test-name (TIMINGS)
4090
+ test-name.test-sub-domain.workers.dev"
4091
+ `);
3880
4092
  expect(std.err).toMatchInlineSnapshot(`""`);
3881
4093
  expect(std.warn).toMatchInlineSnapshot(`""`);
3882
4094
  });
@@ -3898,7 +4110,7 @@ addEventListener('fetch', event => {});`
3898
4110
  );
3899
4111
  expect(std.out).toMatchInlineSnapshot(`
3900
4112
  "
3901
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
4113
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
3902
4114
  `);
3903
4115
  expect(std.err).toMatchInlineSnapshot(`
3904
4116
  "X [ERROR] You cannot configure [text_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[rules]\` in your wrangler.toml
@@ -3943,10 +4155,13 @@ addEventListener('fetch', event => {});`
3943
4155
  mockSubDomainRequest();
3944
4156
  await runWrangler("publish index.js --config ./path/to/wrangler.toml");
3945
4157
  expect(std.out).toMatchInlineSnapshot(`
3946
- "Uploaded test-name (TIMINGS)
3947
- Published test-name (TIMINGS)
3948
- test-name.test-sub-domain.workers.dev"
3949
- `);
4158
+ "Your worker has access to the following bindings:
4159
+ - Text Blobs:
4160
+ - TESTTEXTBLOBNAME: path/to/and/the/path/to/text.file
4161
+ Uploaded test-name (TIMINGS)
4162
+ Published test-name (TIMINGS)
4163
+ test-name.test-sub-domain.workers.dev"
4164
+ `);
3950
4165
  expect(std.err).toMatchInlineSnapshot(`""`);
3951
4166
  expect(std.warn).toMatchInlineSnapshot(`""`);
3952
4167
  });
@@ -3976,10 +4191,13 @@ addEventListener('fetch', event => {});`
3976
4191
  mockSubDomainRequest();
3977
4192
  await runWrangler("publish index.js");
3978
4193
  expect(std.out).toMatchInlineSnapshot(`
3979
- "Uploaded test-name (TIMINGS)
3980
- Published test-name (TIMINGS)
3981
- test-name.test-sub-domain.workers.dev"
3982
- `);
4194
+ "Your worker has access to the following bindings:
4195
+ - Data Blobs:
4196
+ - TESTDATABLOBNAME: path/to/data.bin
4197
+ Uploaded test-name (TIMINGS)
4198
+ Published test-name (TIMINGS)
4199
+ test-name.test-sub-domain.workers.dev"
4200
+ `);
3983
4201
  expect(std.err).toMatchInlineSnapshot(`""`);
3984
4202
  expect(std.warn).toMatchInlineSnapshot(`""`);
3985
4203
  });
@@ -4001,7 +4219,7 @@ addEventListener('fetch', event => {});`
4001
4219
  );
4002
4220
  expect(std.out).toMatchInlineSnapshot(`
4003
4221
  "
4004
- If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
4222
+ If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose"
4005
4223
  `);
4006
4224
  expect(std.err).toMatchInlineSnapshot(`
4007
4225
  "X [ERROR] You cannot configure [data_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure \`[rules]\` in your wrangler.toml
@@ -4046,10 +4264,13 @@ addEventListener('fetch', event => {});`
4046
4264
  mockSubDomainRequest();
4047
4265
  await runWrangler("publish index.js --config ./path/to/wrangler.toml");
4048
4266
  expect(std.out).toMatchInlineSnapshot(`
4049
- "Uploaded test-name (TIMINGS)
4050
- Published test-name (TIMINGS)
4051
- test-name.test-sub-domain.workers.dev"
4052
- `);
4267
+ "Your worker has access to the following bindings:
4268
+ - Data Blobs:
4269
+ - TESTDATABLOBNAME: path/to/and/the/path/to/data.bin
4270
+ Uploaded test-name (TIMINGS)
4271
+ Published test-name (TIMINGS)
4272
+ test-name.test-sub-domain.workers.dev"
4273
+ `);
4053
4274
  expect(std.err).toMatchInlineSnapshot(`""`);
4054
4275
  expect(std.warn).toMatchInlineSnapshot(`""`);
4055
4276
  });
@@ -4080,10 +4301,15 @@ addEventListener('fetch', event => {});`
4080
4301
 
4081
4302
  await runWrangler("publish index.js");
4082
4303
  expect(std.out).toMatchInlineSnapshot(`
4083
- "Uploaded test-name (TIMINGS)
4084
- Published test-name (TIMINGS)
4085
- test-name.test-sub-domain.workers.dev"
4086
- `);
4304
+ "Your worker has access to the following bindings:
4305
+ - Vars:
4306
+ - text: \\"plain ol' string\\"
4307
+ - count: \\"1\\"
4308
+ - complex: \\"[object Object]\\"
4309
+ Uploaded test-name (TIMINGS)
4310
+ Published test-name (TIMINGS)
4311
+ test-name.test-sub-domain.workers.dev"
4312
+ `);
4087
4313
  expect(std.err).toMatchInlineSnapshot(`""`);
4088
4314
  expect(std.warn).toMatchInlineSnapshot(`""`);
4089
4315
  });
@@ -4104,10 +4330,13 @@ addEventListener('fetch', event => {});`
4104
4330
 
4105
4331
  await runWrangler("publish index.js");
4106
4332
  expect(std.out).toMatchInlineSnapshot(`
4107
- "Uploaded test-name (TIMINGS)
4108
- Published test-name (TIMINGS)
4109
- test-name.test-sub-domain.workers.dev"
4110
- `);
4333
+ "Your worker has access to the following bindings:
4334
+ - R2 Buckets:
4335
+ - FOO: foo-bucket
4336
+ Uploaded test-name (TIMINGS)
4337
+ Published test-name (TIMINGS)
4338
+ test-name.test-sub-domain.workers.dev"
4339
+ `);
4111
4340
  expect(std.err).toMatchInlineSnapshot(`""`);
4112
4341
  expect(std.warn).toMatchInlineSnapshot(`""`);
4113
4342
  });
@@ -4146,10 +4375,13 @@ addEventListener('fetch', event => {});`
4146
4375
 
4147
4376
  await runWrangler("publish index.js");
4148
4377
  expect(std.out).toMatchInlineSnapshot(`
4149
- "Uploaded test-name (TIMINGS)
4150
- Published test-name (TIMINGS)
4151
- test-name.test-sub-domain.workers.dev"
4152
- `);
4378
+ "Your worker has access to the following bindings:
4379
+ - Durable Objects:
4380
+ - EXAMPLE_DO_BINDING: ExampleDurableObject
4381
+ Uploaded test-name (TIMINGS)
4382
+ Published test-name (TIMINGS)
4383
+ test-name.test-sub-domain.workers.dev"
4384
+ `);
4153
4385
  expect(std.err).toMatchInlineSnapshot(`""`);
4154
4386
  expect(std.warn).toMatchInlineSnapshot(`""`);
4155
4387
  });
@@ -4182,10 +4414,13 @@ addEventListener('fetch', event => {});`
4182
4414
 
4183
4415
  await runWrangler("publish index.js");
4184
4416
  expect(std.out).toMatchInlineSnapshot(`
4185
- "Uploaded test-name (TIMINGS)
4186
- Published test-name (TIMINGS)
4187
- test-name.test-sub-domain.workers.dev"
4188
- `);
4417
+ "Your worker has access to the following bindings:
4418
+ - Durable Objects:
4419
+ - EXAMPLE_DO_BINDING: ExampleDurableObject (defined in example-do-binding-worker)
4420
+ Uploaded test-name (TIMINGS)
4421
+ Published test-name (TIMINGS)
4422
+ test-name.test-sub-domain.workers.dev"
4423
+ `);
4189
4424
  expect(std.err).toMatchInlineSnapshot(`""`);
4190
4425
  expect(std.warn).toMatchInlineSnapshot(`""`);
4191
4426
  });
@@ -4223,10 +4458,13 @@ addEventListener('fetch', event => {});`
4223
4458
 
4224
4459
  await runWrangler("publish index.js");
4225
4460
  expect(std.out).toMatchInlineSnapshot(`
4226
- "Uploaded test-name (TIMINGS)
4227
- Published test-name (TIMINGS)
4228
- test-name.test-sub-domain.workers.dev"
4229
- `);
4461
+ "Your worker has access to the following bindings:
4462
+ - Durable Objects:
4463
+ - EXAMPLE_DO_BINDING: ExampleDurableObject
4464
+ Uploaded test-name (TIMINGS)
4465
+ Published test-name (TIMINGS)
4466
+ test-name.test-sub-domain.workers.dev"
4467
+ `);
4230
4468
  expect(std.err).toMatchInlineSnapshot(`""`);
4231
4469
  expect(std.warn).toMatchInlineSnapshot(`""`);
4232
4470
  });
@@ -4282,10 +4520,13 @@ addEventListener('fetch', event => {});`
4282
4520
 
4283
4521
  await runWrangler("publish index.js");
4284
4522
  expect(std.out).toMatchInlineSnapshot(`
4285
- "Uploaded test-name (TIMINGS)
4286
- Published test-name (TIMINGS)
4287
- test-name.test-sub-domain.workers.dev"
4288
- `);
4523
+ "Your worker has access to the following bindings:
4524
+ - Services:
4525
+ - FOO: foo-service - production
4526
+ Uploaded test-name (TIMINGS)
4527
+ Published test-name (TIMINGS)
4528
+ test-name.test-sub-domain.workers.dev"
4529
+ `);
4289
4530
  expect(std.err).toMatchInlineSnapshot(`""`);
4290
4531
  expect(std.warn).toMatchInlineSnapshot(`
4291
4532
  "▲ [WARNING] Processing wrangler.toml configuration:
@@ -4324,10 +4565,13 @@ addEventListener('fetch', event => {});`
4324
4565
 
4325
4566
  await runWrangler("publish index.js");
4326
4567
  expect(std.out).toMatchInlineSnapshot(`
4327
- "Uploaded test-name (TIMINGS)
4328
- Published test-name (TIMINGS)
4329
- test-name.test-sub-domain.workers.dev"
4330
- `);
4568
+ "Your worker has access to the following bindings:
4569
+ - Unsafe:
4570
+ - binding-type: my-binding
4571
+ Uploaded test-name (TIMINGS)
4572
+ Published test-name (TIMINGS)
4573
+ test-name.test-sub-domain.workers.dev"
4574
+ `);
4331
4575
  expect(std.err).toMatchInlineSnapshot(`""`);
4332
4576
  expect(std.warn).toMatchInlineSnapshot(`
4333
4577
  "▲ [WARNING] Processing wrangler.toml configuration:
@@ -4363,10 +4607,13 @@ addEventListener('fetch', event => {});`
4363
4607
 
4364
4608
  await runWrangler("publish index.js");
4365
4609
  expect(std.out).toMatchInlineSnapshot(`
4366
- "Uploaded test-name (TIMINGS)
4367
- Published test-name (TIMINGS)
4368
- test-name.test-sub-domain.workers.dev"
4369
- `);
4610
+ "Your worker has access to the following bindings:
4611
+ - Unsafe:
4612
+ - plain_text: my-binding
4613
+ Uploaded test-name (TIMINGS)
4614
+ Published test-name (TIMINGS)
4615
+ test-name.test-sub-domain.workers.dev"
4616
+ `);
4370
4617
  expect(std.err).toMatchInlineSnapshot(`""`);
4371
4618
  expect(std.warn).toMatchInlineSnapshot(`
4372
4619
  "▲ [WARNING] Processing wrangler.toml configuration:
@@ -4814,7 +5061,10 @@ addEventListener('fetch', event => {});`
4814
5061
  Object {
4815
5062
  "debug": "",
4816
5063
  "err": "",
4817
- "out": "--dry-run: exiting now.",
5064
+ "out": "Your worker has access to the following bindings:
5065
+ - Durable Objects:
5066
+ - NAME: SomeClass
5067
+ --dry-run: exiting now.",
4818
5068
  "warn": "",
4819
5069
  }
4820
5070
  `);
@@ -4831,7 +5081,7 @@ addEventListener('fetch', event => {});`
4831
5081
  "debug": "",
4832
5082
  "err": "",
4833
5083
  "out": "--dry-run: exiting now.",
4834
- "warn": "▲ [WARNING] Enabling node.js compatibility mode for builtins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.
5084
+ "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.
4835
5085
 
4836
5086
  ",
4837
5087
  }
@@ -4875,7 +5125,7 @@ addEventListener('fetch', event => {});`
4875
5125
  "debug": "",
4876
5126
  "err": "",
4877
5127
  "out": "--dry-run: exiting now.",
4878
- "warn": "▲ [WARNING] Enabling node.js compatibility mode for builtins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.
5128
+ "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.
4879
5129
 
4880
5130
  ",
4881
5131
  }
@@ -5053,6 +5303,49 @@ function mockPublishRoutesRequest({
5053
5303
  );
5054
5304
  }
5055
5305
 
5306
+ function mockUnauthorizedPublishRoutesRequest({
5307
+ env = undefined,
5308
+ legacyEnv = false,
5309
+ }: {
5310
+ env?: string | undefined;
5311
+ legacyEnv?: boolean | undefined;
5312
+ } = {}) {
5313
+ const servicesOrScripts = env && !legacyEnv ? "services" : "scripts";
5314
+ const environment = env && !legacyEnv ? "/environments/:envName" : "";
5315
+
5316
+ setMockRawResponse(
5317
+ `/accounts/:accountId/workers/${servicesOrScripts}/:scriptName${environment}/routes`,
5318
+ "PUT",
5319
+ () =>
5320
+ createFetchResult(null, false, [
5321
+ { message: "Authentication error", code: 10000 },
5322
+ ])
5323
+ );
5324
+ }
5325
+
5326
+ function mockCollectKnownRoutesRequest(
5327
+ routes: { pattern: string; script: string }[]
5328
+ ) {
5329
+ setMockResponse(`/zones/:zoneId/workers/routes`, "GET", () => routes);
5330
+ }
5331
+
5332
+ function mockGetZoneFromHostRequest(host: string, zone: string) {
5333
+ setMockResponse("/zones", (_uri, _init, queryParams) => {
5334
+ expect(queryParams.get("name")).toEqual(host);
5335
+ return [{ id: zone }];
5336
+ });
5337
+ }
5338
+
5339
+ function mockPublishRoutesFallbackRequest(route: {
5340
+ pattern: string;
5341
+ script: string;
5342
+ }) {
5343
+ setMockResponse(`/zones/:zoneId/workers/routes`, "POST", (_url, { body }) => {
5344
+ expect(JSON.parse(body as string)).toEqual(route);
5345
+ return route.pattern;
5346
+ });
5347
+ }
5348
+
5056
5349
  function mockPublishCustomDomainsRequest({
5057
5350
  publishFlags,
5058
5351
  domains = [],