wrangler 2.0.6 → 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/package.json +5 -3
- package/pages/functions/buildPlugin.ts +13 -0
- package/pages/functions/buildWorker.ts +13 -0
- package/src/__tests__/configuration.test.ts +14 -3
- package/src/__tests__/dev.test.tsx +11 -2
- package/src/__tests__/index.test.ts +25 -10
- package/src/__tests__/init.test.ts +61 -20
- package/src/__tests__/kv.test.ts +8 -8
- package/src/__tests__/pages.test.ts +339 -32
- package/src/__tests__/parse.test.ts +5 -1
- package/src/__tests__/publish.test.ts +184 -69
- package/src/abort.d.ts +3 -0
- package/src/cfetch/index.ts +4 -2
- package/src/cfetch/internal.ts +8 -9
- package/src/config/index.ts +162 -0
- package/src/config/validation.ts +24 -2
- package/src/create-worker-preview.ts +17 -7
- package/src/dev/dev.tsx +5 -4
- package/src/dev/remote.tsx +15 -1
- package/src/durable.ts +102 -0
- package/src/index.tsx +111 -41
- package/src/inspect.ts +39 -0
- package/src/kv.ts +74 -25
- package/src/open-in-browser.ts +5 -12
- package/src/pages.tsx +203 -61
- package/src/parse.ts +21 -4
- package/src/proxy.ts +38 -22
- package/src/publish.ts +18 -93
- package/src/sites.tsx +2 -7
- package/templates/new-worker.ts +16 -1
- package/wrangler-dist/cli.js +32779 -20005
|
@@ -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
|
-
"
|
|
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
|
`);
|
|
@@ -2829,13 +2832,22 @@ addEventListener('fetch', event => {});`
|
|
|
2829
2832
|
mockUploadWorkerRequest();
|
|
2830
2833
|
await runWrangler("publish index.js");
|
|
2831
2834
|
expect(std.out).toMatchInlineSnapshot(`
|
|
2832
|
-
"
|
|
2835
|
+
"Your worker has access to the following bindings:
|
|
2836
|
+
- Durable Objects:
|
|
2837
|
+
- SOMENAME: SomeClass
|
|
2838
|
+
Uploaded test-name (TIMINGS)
|
|
2833
2839
|
Published test-name (TIMINGS)
|
|
2834
2840
|
test-name.test-sub-domain.workers.dev"
|
|
2835
2841
|
`);
|
|
2836
2842
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
2837
2843
|
expect(std.warn).toMatchInlineSnapshot(`
|
|
2838
|
-
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [
|
|
2844
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mProcessing wrangler.toml configuration:[0m
|
|
2845
|
+
|
|
2846
|
+
- In wrangler.toml, you have configured [durable_objects] exported by this Worker (SomeClass),
|
|
2847
|
+
but no [migrations] for them. This may not work as expected until you add a [migrations] section
|
|
2848
|
+
to your wrangler.toml. Refer to
|
|
2849
|
+
[4mhttps://developers.cloudflare.com/workers/learning/using-durable-objects/#durable-object-migrations-in-wranglertoml[0m
|
|
2850
|
+
for more details.
|
|
2839
2851
|
|
|
2840
2852
|
"
|
|
2841
2853
|
`);
|
|
@@ -2861,7 +2873,10 @@ addEventListener('fetch', event => {});`
|
|
|
2861
2873
|
mockUploadWorkerRequest();
|
|
2862
2874
|
await runWrangler("publish index.js");
|
|
2863
2875
|
expect(std.out).toMatchInlineSnapshot(`
|
|
2864
|
-
"
|
|
2876
|
+
"Your worker has access to the following bindings:
|
|
2877
|
+
- Durable Objects:
|
|
2878
|
+
- SOMENAME: SomeClass (defined in some-script)
|
|
2879
|
+
Uploaded test-name (TIMINGS)
|
|
2865
2880
|
Published test-name (TIMINGS)
|
|
2866
2881
|
test-name.test-sub-domain.workers.dev"
|
|
2867
2882
|
`);
|
|
@@ -2900,7 +2915,11 @@ addEventListener('fetch', event => {});`
|
|
|
2900
2915
|
|
|
2901
2916
|
await runWrangler("publish index.js");
|
|
2902
2917
|
expect(std.out).toMatchInlineSnapshot(`
|
|
2903
|
-
"
|
|
2918
|
+
"Your worker has access to the following bindings:
|
|
2919
|
+
- Durable Objects:
|
|
2920
|
+
- SOMENAME: SomeClass
|
|
2921
|
+
- SOMEOTHERNAME: SomeOtherClass
|
|
2922
|
+
Uploaded test-name (TIMINGS)
|
|
2904
2923
|
Published test-name (TIMINGS)
|
|
2905
2924
|
test-name.test-sub-domain.workers.dev"
|
|
2906
2925
|
`);
|
|
@@ -2946,7 +2965,11 @@ addEventListener('fetch', event => {});`
|
|
|
2946
2965
|
Object {
|
|
2947
2966
|
"debug": "",
|
|
2948
2967
|
"err": "",
|
|
2949
|
-
"out": "
|
|
2968
|
+
"out": "Your worker has access to the following bindings:
|
|
2969
|
+
- Durable Objects:
|
|
2970
|
+
- SOMENAME: SomeClass
|
|
2971
|
+
- SOMEOTHERNAME: SomeOtherClass
|
|
2972
|
+
Uploaded test-name (TIMINGS)
|
|
2950
2973
|
Published test-name (TIMINGS)
|
|
2951
2974
|
test-name.test-sub-domain.workers.dev",
|
|
2952
2975
|
"warn": "",
|
|
@@ -2985,7 +3008,11 @@ addEventListener('fetch', event => {});`
|
|
|
2985
3008
|
Object {
|
|
2986
3009
|
"debug": "",
|
|
2987
3010
|
"err": "",
|
|
2988
|
-
"out": "
|
|
3011
|
+
"out": "Your worker has access to the following bindings:
|
|
3012
|
+
- Durable Objects:
|
|
3013
|
+
- SOMENAME: SomeClass
|
|
3014
|
+
- SOMEOTHERNAME: SomeOtherClass
|
|
3015
|
+
Uploaded test-name (TIMINGS)
|
|
2989
3016
|
Published test-name (TIMINGS)
|
|
2990
3017
|
test-name.test-sub-domain.workers.dev",
|
|
2991
3018
|
"warn": "",
|
|
@@ -3026,7 +3053,11 @@ addEventListener('fetch', event => {});`
|
|
|
3026
3053
|
|
|
3027
3054
|
await runWrangler("publish index.js --legacy-env false");
|
|
3028
3055
|
expect(std.out).toMatchInlineSnapshot(`
|
|
3029
|
-
"
|
|
3056
|
+
"Your worker has access to the following bindings:
|
|
3057
|
+
- Durable Objects:
|
|
3058
|
+
- SOMENAME: SomeClass
|
|
3059
|
+
- SOMEOTHERNAME: SomeOtherClass
|
|
3060
|
+
Uploaded test-name (TIMINGS)
|
|
3030
3061
|
Published test-name (TIMINGS)
|
|
3031
3062
|
test-name.test-sub-domain.workers.dev"
|
|
3032
3063
|
`);
|
|
@@ -3084,7 +3115,11 @@ addEventListener('fetch', event => {});`
|
|
|
3084
3115
|
|
|
3085
3116
|
await runWrangler("publish index.js --legacy-env false --env xyz");
|
|
3086
3117
|
expect(std.out).toMatchInlineSnapshot(`
|
|
3087
|
-
"
|
|
3118
|
+
"Your worker has access to the following bindings:
|
|
3119
|
+
- Durable Objects:
|
|
3120
|
+
- SOMENAME: SomeClass
|
|
3121
|
+
- SOMEOTHERNAME: SomeOtherClass
|
|
3122
|
+
Uploaded test-name (xyz) (TIMINGS)
|
|
3088
3123
|
Published test-name (xyz) (TIMINGS)
|
|
3089
3124
|
xyz.test-name.test-sub-domain.workers.dev"
|
|
3090
3125
|
`);
|
|
@@ -3138,7 +3173,11 @@ addEventListener('fetch', event => {});`
|
|
|
3138
3173
|
Object {
|
|
3139
3174
|
"debug": "",
|
|
3140
3175
|
"err": "",
|
|
3141
|
-
"out": "
|
|
3176
|
+
"out": "Your worker has access to the following bindings:
|
|
3177
|
+
- Durable Objects:
|
|
3178
|
+
- SOMENAME: SomeClass
|
|
3179
|
+
- SOMEOTHERNAME: SomeOtherClass
|
|
3180
|
+
Uploaded test-name (TIMINGS)
|
|
3142
3181
|
Published test-name (TIMINGS)
|
|
3143
3182
|
test-name.test-sub-domain.workers.dev",
|
|
3144
3183
|
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mProcessing wrangler.toml configuration:[0m
|
|
@@ -3202,7 +3241,11 @@ addEventListener('fetch', event => {});`
|
|
|
3202
3241
|
Object {
|
|
3203
3242
|
"debug": "",
|
|
3204
3243
|
"err": "",
|
|
3205
|
-
"out": "
|
|
3244
|
+
"out": "Your worker has access to the following bindings:
|
|
3245
|
+
- Durable Objects:
|
|
3246
|
+
- SOMENAME: SomeClass
|
|
3247
|
+
- SOMEOTHERNAME: SomeOtherClass
|
|
3248
|
+
Uploaded test-name (xyz) (TIMINGS)
|
|
3206
3249
|
Published test-name (xyz) (TIMINGS)
|
|
3207
3250
|
xyz.test-name.test-sub-domain.workers.dev",
|
|
3208
3251
|
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mProcessing wrangler.toml configuration:[0m
|
|
@@ -3366,7 +3409,32 @@ addEventListener('fetch', event => {});`
|
|
|
3366
3409
|
|
|
3367
3410
|
await expect(runWrangler("publish index.js")).resolves.toBeUndefined();
|
|
3368
3411
|
expect(std.out).toMatchInlineSnapshot(`
|
|
3369
|
-
"
|
|
3412
|
+
"Your worker has access to the following bindings:
|
|
3413
|
+
- Data Blobs:
|
|
3414
|
+
- DATA_BLOB_ONE: some-data-blob.bin
|
|
3415
|
+
- DATA_BLOB_TWO: more-data-blob.bin
|
|
3416
|
+
- Durable Objects:
|
|
3417
|
+
- DURABLE_OBJECT_ONE: SomeDurableObject (defined in some-durable-object-worker)
|
|
3418
|
+
- DURABLE_OBJECT_TWO: AnotherDurableObject (defined in another-durable-object-worker) - staging
|
|
3419
|
+
- KV Namespaces:
|
|
3420
|
+
- KV_NAMESPACE_ONE: kv-ns-one-id
|
|
3421
|
+
- KV_NAMESPACE_TWO: kv-ns-two-id
|
|
3422
|
+
- R2 Buckets:
|
|
3423
|
+
- R2_BUCKET_ONE: r2-bucket-one-name
|
|
3424
|
+
- R2_BUCKET_TWO: r2-bucket-two-name
|
|
3425
|
+
- Text Blobs:
|
|
3426
|
+
- TEXT_BLOB_ONE: my-entire-app-depends-on-this.cfg
|
|
3427
|
+
- TEXT_BLOB_TWO: the-entirety-of-human-knowledge.txt
|
|
3428
|
+
- Unsafe:
|
|
3429
|
+
- some unsafe thing: UNSAFE_BINDING_ONE
|
|
3430
|
+
- another unsafe thing: UNSAFE_BINDING_TWO
|
|
3431
|
+
- Vars:
|
|
3432
|
+
- ENV_VAR_ONE: \\"123\\"
|
|
3433
|
+
- ENV_VAR_TWO: \\"Hello, I'm an environment variable\\"
|
|
3434
|
+
- Wasm Modules:
|
|
3435
|
+
- WASM_MODULE_ONE: some_wasm.wasm
|
|
3436
|
+
- WASM_MODULE_TWO: more_wasm.wasm
|
|
3437
|
+
Uploaded test-name (TIMINGS)
|
|
3370
3438
|
Published test-name (TIMINGS)
|
|
3371
3439
|
test-name.test-sub-domain.workers.dev"
|
|
3372
3440
|
`);
|
|
@@ -3742,10 +3810,13 @@ addEventListener('fetch', event => {});`
|
|
|
3742
3810
|
mockSubDomainRequest();
|
|
3743
3811
|
await runWrangler("publish index.js");
|
|
3744
3812
|
expect(std.out).toMatchInlineSnapshot(`
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3813
|
+
"Your worker has access to the following bindings:
|
|
3814
|
+
- Wasm Modules:
|
|
3815
|
+
- TESTWASMNAME: path/to/test.wasm
|
|
3816
|
+
Uploaded test-name (TIMINGS)
|
|
3817
|
+
Published test-name (TIMINGS)
|
|
3818
|
+
test-name.test-sub-domain.workers.dev"
|
|
3819
|
+
`);
|
|
3749
3820
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
3750
3821
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
3751
3822
|
});
|
|
@@ -3808,10 +3879,13 @@ addEventListener('fetch', event => {});`
|
|
|
3808
3879
|
mockSubDomainRequest();
|
|
3809
3880
|
await runWrangler("publish index.js --config ./path/to/wrangler.toml");
|
|
3810
3881
|
expect(std.out).toMatchInlineSnapshot(`
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3882
|
+
"Your worker has access to the following bindings:
|
|
3883
|
+
- Wasm Modules:
|
|
3884
|
+
- TESTWASMNAME: path/to/and/the/path/to/test.wasm
|
|
3885
|
+
Uploaded test-name (TIMINGS)
|
|
3886
|
+
Published test-name (TIMINGS)
|
|
3887
|
+
test-name.test-sub-domain.workers.dev"
|
|
3888
|
+
`);
|
|
3815
3889
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
3816
3890
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
3817
3891
|
});
|
|
@@ -3873,10 +3947,13 @@ addEventListener('fetch', event => {});`
|
|
|
3873
3947
|
mockSubDomainRequest();
|
|
3874
3948
|
await runWrangler("publish index.js");
|
|
3875
3949
|
expect(std.out).toMatchInlineSnapshot(`
|
|
3876
|
-
|
|
3877
|
-
|
|
3878
|
-
|
|
3879
|
-
|
|
3950
|
+
"Your worker has access to the following bindings:
|
|
3951
|
+
- Text Blobs:
|
|
3952
|
+
- TESTTEXTBLOBNAME: path/to/text.file
|
|
3953
|
+
Uploaded test-name (TIMINGS)
|
|
3954
|
+
Published test-name (TIMINGS)
|
|
3955
|
+
test-name.test-sub-domain.workers.dev"
|
|
3956
|
+
`);
|
|
3880
3957
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
3881
3958
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
3882
3959
|
});
|
|
@@ -3943,10 +4020,13 @@ addEventListener('fetch', event => {});`
|
|
|
3943
4020
|
mockSubDomainRequest();
|
|
3944
4021
|
await runWrangler("publish index.js --config ./path/to/wrangler.toml");
|
|
3945
4022
|
expect(std.out).toMatchInlineSnapshot(`
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
4023
|
+
"Your worker has access to the following bindings:
|
|
4024
|
+
- Text Blobs:
|
|
4025
|
+
- TESTTEXTBLOBNAME: path/to/and/the/path/to/text.file
|
|
4026
|
+
Uploaded test-name (TIMINGS)
|
|
4027
|
+
Published test-name (TIMINGS)
|
|
4028
|
+
test-name.test-sub-domain.workers.dev"
|
|
4029
|
+
`);
|
|
3950
4030
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
3951
4031
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
3952
4032
|
});
|
|
@@ -3976,10 +4056,13 @@ addEventListener('fetch', event => {});`
|
|
|
3976
4056
|
mockSubDomainRequest();
|
|
3977
4057
|
await runWrangler("publish index.js");
|
|
3978
4058
|
expect(std.out).toMatchInlineSnapshot(`
|
|
3979
|
-
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
4059
|
+
"Your worker has access to the following bindings:
|
|
4060
|
+
- Data Blobs:
|
|
4061
|
+
- TESTDATABLOBNAME: path/to/data.bin
|
|
4062
|
+
Uploaded test-name (TIMINGS)
|
|
4063
|
+
Published test-name (TIMINGS)
|
|
4064
|
+
test-name.test-sub-domain.workers.dev"
|
|
4065
|
+
`);
|
|
3983
4066
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
3984
4067
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
3985
4068
|
});
|
|
@@ -4046,10 +4129,13 @@ addEventListener('fetch', event => {});`
|
|
|
4046
4129
|
mockSubDomainRequest();
|
|
4047
4130
|
await runWrangler("publish index.js --config ./path/to/wrangler.toml");
|
|
4048
4131
|
expect(std.out).toMatchInlineSnapshot(`
|
|
4049
|
-
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4132
|
+
"Your worker has access to the following bindings:
|
|
4133
|
+
- Data Blobs:
|
|
4134
|
+
- TESTDATABLOBNAME: path/to/and/the/path/to/data.bin
|
|
4135
|
+
Uploaded test-name (TIMINGS)
|
|
4136
|
+
Published test-name (TIMINGS)
|
|
4137
|
+
test-name.test-sub-domain.workers.dev"
|
|
4138
|
+
`);
|
|
4053
4139
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
4054
4140
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
4055
4141
|
});
|
|
@@ -4080,10 +4166,15 @@ addEventListener('fetch', event => {});`
|
|
|
4080
4166
|
|
|
4081
4167
|
await runWrangler("publish index.js");
|
|
4082
4168
|
expect(std.out).toMatchInlineSnapshot(`
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4169
|
+
"Your worker has access to the following bindings:
|
|
4170
|
+
- Vars:
|
|
4171
|
+
- text: \\"plain ol' string\\"
|
|
4172
|
+
- count: \\"1\\"
|
|
4173
|
+
- complex: \\"[object Object]\\"
|
|
4174
|
+
Uploaded test-name (TIMINGS)
|
|
4175
|
+
Published test-name (TIMINGS)
|
|
4176
|
+
test-name.test-sub-domain.workers.dev"
|
|
4177
|
+
`);
|
|
4087
4178
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
4088
4179
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
4089
4180
|
});
|
|
@@ -4104,10 +4195,13 @@ addEventListener('fetch', event => {});`
|
|
|
4104
4195
|
|
|
4105
4196
|
await runWrangler("publish index.js");
|
|
4106
4197
|
expect(std.out).toMatchInlineSnapshot(`
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4198
|
+
"Your worker has access to the following bindings:
|
|
4199
|
+
- R2 Buckets:
|
|
4200
|
+
- FOO: foo-bucket
|
|
4201
|
+
Uploaded test-name (TIMINGS)
|
|
4202
|
+
Published test-name (TIMINGS)
|
|
4203
|
+
test-name.test-sub-domain.workers.dev"
|
|
4204
|
+
`);
|
|
4111
4205
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
4112
4206
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
4113
4207
|
});
|
|
@@ -4146,10 +4240,13 @@ addEventListener('fetch', event => {});`
|
|
|
4146
4240
|
|
|
4147
4241
|
await runWrangler("publish index.js");
|
|
4148
4242
|
expect(std.out).toMatchInlineSnapshot(`
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4243
|
+
"Your worker has access to the following bindings:
|
|
4244
|
+
- Durable Objects:
|
|
4245
|
+
- EXAMPLE_DO_BINDING: ExampleDurableObject
|
|
4246
|
+
Uploaded test-name (TIMINGS)
|
|
4247
|
+
Published test-name (TIMINGS)
|
|
4248
|
+
test-name.test-sub-domain.workers.dev"
|
|
4249
|
+
`);
|
|
4153
4250
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
4154
4251
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
4155
4252
|
});
|
|
@@ -4182,10 +4279,13 @@ addEventListener('fetch', event => {});`
|
|
|
4182
4279
|
|
|
4183
4280
|
await runWrangler("publish index.js");
|
|
4184
4281
|
expect(std.out).toMatchInlineSnapshot(`
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4282
|
+
"Your worker has access to the following bindings:
|
|
4283
|
+
- Durable Objects:
|
|
4284
|
+
- EXAMPLE_DO_BINDING: ExampleDurableObject (defined in example-do-binding-worker)
|
|
4285
|
+
Uploaded test-name (TIMINGS)
|
|
4286
|
+
Published test-name (TIMINGS)
|
|
4287
|
+
test-name.test-sub-domain.workers.dev"
|
|
4288
|
+
`);
|
|
4189
4289
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
4190
4290
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
4191
4291
|
});
|
|
@@ -4223,10 +4323,13 @@ addEventListener('fetch', event => {});`
|
|
|
4223
4323
|
|
|
4224
4324
|
await runWrangler("publish index.js");
|
|
4225
4325
|
expect(std.out).toMatchInlineSnapshot(`
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4326
|
+
"Your worker has access to the following bindings:
|
|
4327
|
+
- Durable Objects:
|
|
4328
|
+
- EXAMPLE_DO_BINDING: ExampleDurableObject
|
|
4329
|
+
Uploaded test-name (TIMINGS)
|
|
4330
|
+
Published test-name (TIMINGS)
|
|
4331
|
+
test-name.test-sub-domain.workers.dev"
|
|
4332
|
+
`);
|
|
4230
4333
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
4231
4334
|
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
4232
4335
|
});
|
|
@@ -4282,10 +4385,13 @@ addEventListener('fetch', event => {});`
|
|
|
4282
4385
|
|
|
4283
4386
|
await runWrangler("publish index.js");
|
|
4284
4387
|
expect(std.out).toMatchInlineSnapshot(`
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4388
|
+
"Your worker has access to the following bindings:
|
|
4389
|
+
- Services:
|
|
4390
|
+
- FOO: foo-service - production
|
|
4391
|
+
Uploaded test-name (TIMINGS)
|
|
4392
|
+
Published test-name (TIMINGS)
|
|
4393
|
+
test-name.test-sub-domain.workers.dev"
|
|
4394
|
+
`);
|
|
4289
4395
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
4290
4396
|
expect(std.warn).toMatchInlineSnapshot(`
|
|
4291
4397
|
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mProcessing wrangler.toml configuration:[0m
|
|
@@ -4324,10 +4430,13 @@ addEventListener('fetch', event => {});`
|
|
|
4324
4430
|
|
|
4325
4431
|
await runWrangler("publish index.js");
|
|
4326
4432
|
expect(std.out).toMatchInlineSnapshot(`
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4433
|
+
"Your worker has access to the following bindings:
|
|
4434
|
+
- Unsafe:
|
|
4435
|
+
- binding-type: my-binding
|
|
4436
|
+
Uploaded test-name (TIMINGS)
|
|
4437
|
+
Published test-name (TIMINGS)
|
|
4438
|
+
test-name.test-sub-domain.workers.dev"
|
|
4439
|
+
`);
|
|
4331
4440
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
4332
4441
|
expect(std.warn).toMatchInlineSnapshot(`
|
|
4333
4442
|
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mProcessing wrangler.toml configuration:[0m
|
|
@@ -4363,10 +4472,13 @@ addEventListener('fetch', event => {});`
|
|
|
4363
4472
|
|
|
4364
4473
|
await runWrangler("publish index.js");
|
|
4365
4474
|
expect(std.out).toMatchInlineSnapshot(`
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4475
|
+
"Your worker has access to the following bindings:
|
|
4476
|
+
- Unsafe:
|
|
4477
|
+
- plain_text: my-binding
|
|
4478
|
+
Uploaded test-name (TIMINGS)
|
|
4479
|
+
Published test-name (TIMINGS)
|
|
4480
|
+
test-name.test-sub-domain.workers.dev"
|
|
4481
|
+
`);
|
|
4370
4482
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
4371
4483
|
expect(std.warn).toMatchInlineSnapshot(`
|
|
4372
4484
|
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mProcessing wrangler.toml configuration:[0m
|
|
@@ -4814,7 +4926,10 @@ addEventListener('fetch', event => {});`
|
|
|
4814
4926
|
Object {
|
|
4815
4927
|
"debug": "",
|
|
4816
4928
|
"err": "",
|
|
4817
|
-
"out": "
|
|
4929
|
+
"out": "Your worker has access to the following bindings:
|
|
4930
|
+
- Durable Objects:
|
|
4931
|
+
- NAME: SomeClass
|
|
4932
|
+
--dry-run: exiting now.",
|
|
4818
4933
|
"warn": "",
|
|
4819
4934
|
}
|
|
4820
4935
|
`);
|
package/src/abort.d.ts
ADDED
package/src/cfetch/index.ts
CHANGED
|
@@ -27,12 +27,14 @@ export { fetchKVGetValue } from "./internal";
|
|
|
27
27
|
export async function fetchResult<ResponseType>(
|
|
28
28
|
resource: string,
|
|
29
29
|
init: RequestInit = {},
|
|
30
|
-
queryParams?: URLSearchParams
|
|
30
|
+
queryParams?: URLSearchParams,
|
|
31
|
+
abortSignal?: AbortSignal
|
|
31
32
|
): Promise<ResponseType> {
|
|
32
33
|
const json = await fetchInternal<FetchResult<ResponseType>>(
|
|
33
34
|
resource,
|
|
34
35
|
init,
|
|
35
|
-
queryParams
|
|
36
|
+
queryParams,
|
|
37
|
+
abortSignal
|
|
36
38
|
);
|
|
37
39
|
if (json.success) {
|
|
38
40
|
return json.result;
|
package/src/cfetch/internal.ts
CHANGED
|
@@ -26,12 +26,13 @@ export const getCloudflareAPIBaseURL = getEnvironmentVariableFactory({
|
|
|
26
26
|
export async function fetchInternal<ResponseType>(
|
|
27
27
|
resource: string,
|
|
28
28
|
init: RequestInit = {},
|
|
29
|
-
queryParams?: URLSearchParams
|
|
29
|
+
queryParams?: URLSearchParams,
|
|
30
|
+
abortSignal?: AbortSignal
|
|
30
31
|
): Promise<ResponseType> {
|
|
31
32
|
await requireLoggedIn();
|
|
32
33
|
const apiToken = requireApiToken();
|
|
33
34
|
const headers = cloneHeaders(init.headers);
|
|
34
|
-
|
|
35
|
+
addAuthorizationHeaderIfUnspecified(headers, apiToken);
|
|
35
36
|
|
|
36
37
|
const queryString = queryParams ? `?${queryParams.toString()}` : "";
|
|
37
38
|
const method = init.method ?? "GET";
|
|
@@ -41,11 +42,12 @@ export async function fetchInternal<ResponseType>(
|
|
|
41
42
|
method,
|
|
42
43
|
...init,
|
|
43
44
|
headers,
|
|
45
|
+
signal: abortSignal,
|
|
44
46
|
}
|
|
45
47
|
);
|
|
46
48
|
const jsonText = await response.text();
|
|
47
49
|
try {
|
|
48
|
-
return parseJSON(jsonText)
|
|
50
|
+
return parseJSON<ResponseType>(jsonText);
|
|
49
51
|
} catch (err) {
|
|
50
52
|
throw new ParseError({
|
|
51
53
|
text: "Received a malformed response from the API",
|
|
@@ -94,16 +96,13 @@ function requireApiToken(): string {
|
|
|
94
96
|
return authToken;
|
|
95
97
|
}
|
|
96
98
|
|
|
97
|
-
function
|
|
99
|
+
function addAuthorizationHeaderIfUnspecified(
|
|
98
100
|
headers: Record<string, string>,
|
|
99
101
|
apiToken: string
|
|
100
102
|
): void {
|
|
101
|
-
if ("Authorization" in headers) {
|
|
102
|
-
|
|
103
|
-
"The request already specifies an authorisation header - cannot add a new one."
|
|
104
|
-
);
|
|
103
|
+
if (!("Authorization" in headers)) {
|
|
104
|
+
headers["Authorization"] = `Bearer ${apiToken}`;
|
|
105
105
|
}
|
|
106
|
-
headers["Authorization"] = `Bearer ${apiToken}`;
|
|
107
106
|
}
|
|
108
107
|
|
|
109
108
|
/**
|
package/src/config/index.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { findUpSync } from "find-up";
|
|
|
2
2
|
import { logger } from "../logger";
|
|
3
3
|
import { parseTOML, readFileSync } from "../parse";
|
|
4
4
|
import { normalizeAndValidateConfig } from "./validation";
|
|
5
|
+
import type { CfWorkerInit } from "../worker";
|
|
5
6
|
import type { Config, RawConfig } from "./config";
|
|
6
7
|
|
|
7
8
|
export type {
|
|
@@ -61,3 +62,164 @@ export function findWranglerToml(
|
|
|
61
62
|
const configPath = findUpSync("wrangler.toml", { cwd: referencePath });
|
|
62
63
|
return configPath;
|
|
63
64
|
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Print all the bindings a worker using a given config would have access to
|
|
68
|
+
*/
|
|
69
|
+
export function printBindings(bindings: CfWorkerInit["bindings"]) {
|
|
70
|
+
const truncate = (item: string | Record<string, unknown>) => {
|
|
71
|
+
const s = typeof item === "string" ? item : JSON.stringify(item);
|
|
72
|
+
const maxLength = 40;
|
|
73
|
+
if (s.length < maxLength) {
|
|
74
|
+
return s;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
return `${s.substring(0, maxLength - 3)}...`;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const output: { type: string; entries: { key: string; value: string }[] }[] =
|
|
81
|
+
[];
|
|
82
|
+
|
|
83
|
+
const {
|
|
84
|
+
data_blobs,
|
|
85
|
+
durable_objects,
|
|
86
|
+
kv_namespaces,
|
|
87
|
+
r2_buckets,
|
|
88
|
+
services,
|
|
89
|
+
text_blobs,
|
|
90
|
+
unsafe,
|
|
91
|
+
vars,
|
|
92
|
+
wasm_modules,
|
|
93
|
+
} = bindings;
|
|
94
|
+
|
|
95
|
+
if (data_blobs !== undefined && Object.keys(data_blobs).length > 0) {
|
|
96
|
+
output.push({
|
|
97
|
+
type: "Data Blobs",
|
|
98
|
+
entries: Object.entries(data_blobs).map(([key, value]) => ({
|
|
99
|
+
key,
|
|
100
|
+
value: truncate(value),
|
|
101
|
+
})),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (durable_objects !== undefined && durable_objects.bindings.length > 0) {
|
|
106
|
+
output.push({
|
|
107
|
+
type: "Durable Objects",
|
|
108
|
+
entries: durable_objects.bindings.map(
|
|
109
|
+
({ name, class_name, script_name, environment }) => {
|
|
110
|
+
let value = class_name;
|
|
111
|
+
if (script_name) {
|
|
112
|
+
value += ` (defined in ${script_name})`;
|
|
113
|
+
}
|
|
114
|
+
if (environment) {
|
|
115
|
+
value += ` - ${environment}`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
return {
|
|
119
|
+
key: name,
|
|
120
|
+
value,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (kv_namespaces !== undefined && kv_namespaces.length > 0) {
|
|
128
|
+
output.push({
|
|
129
|
+
type: "KV Namespaces",
|
|
130
|
+
entries: kv_namespaces.map(({ binding, id }) => {
|
|
131
|
+
return {
|
|
132
|
+
key: binding,
|
|
133
|
+
value: id,
|
|
134
|
+
};
|
|
135
|
+
}),
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (r2_buckets !== undefined && r2_buckets.length > 0) {
|
|
140
|
+
output.push({
|
|
141
|
+
type: "R2 Buckets",
|
|
142
|
+
entries: r2_buckets.map(({ binding, bucket_name }) => {
|
|
143
|
+
return {
|
|
144
|
+
key: binding,
|
|
145
|
+
value: bucket_name,
|
|
146
|
+
};
|
|
147
|
+
}),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (services !== undefined && services.length > 0) {
|
|
152
|
+
output.push({
|
|
153
|
+
type: "Services",
|
|
154
|
+
entries: services.map(({ binding, service, environment }) => {
|
|
155
|
+
let value = service;
|
|
156
|
+
if (environment) {
|
|
157
|
+
value += ` - ${environment}`;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
key: binding,
|
|
162
|
+
value,
|
|
163
|
+
};
|
|
164
|
+
}),
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
if (text_blobs !== undefined && Object.keys(text_blobs).length > 0) {
|
|
169
|
+
output.push({
|
|
170
|
+
type: "Text Blobs",
|
|
171
|
+
entries: Object.entries(text_blobs).map(([key, value]) => ({
|
|
172
|
+
key,
|
|
173
|
+
value: truncate(value),
|
|
174
|
+
})),
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (unsafe !== undefined && unsafe.length > 0) {
|
|
179
|
+
output.push({
|
|
180
|
+
type: "Unsafe",
|
|
181
|
+
entries: unsafe.map(({ name, type }) => ({
|
|
182
|
+
key: type,
|
|
183
|
+
value: name,
|
|
184
|
+
})),
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (vars !== undefined && Object.keys(vars).length > 0) {
|
|
189
|
+
output.push({
|
|
190
|
+
type: "Vars",
|
|
191
|
+
entries: Object.entries(vars).map(([key, value]) => ({
|
|
192
|
+
key,
|
|
193
|
+
value: `"${truncate(`${value}`)}"`,
|
|
194
|
+
})),
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (wasm_modules !== undefined && Object.keys(wasm_modules).length > 0) {
|
|
199
|
+
output.push({
|
|
200
|
+
type: "Wasm Modules",
|
|
201
|
+
entries: Object.entries(wasm_modules).map(([key, value]) => ({
|
|
202
|
+
key,
|
|
203
|
+
value: truncate(value),
|
|
204
|
+
})),
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (output.length === 0) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const message = [
|
|
213
|
+
`Your worker has access to the following bindings:`,
|
|
214
|
+
...output
|
|
215
|
+
.map((bindingGroup) => {
|
|
216
|
+
return [
|
|
217
|
+
`- ${bindingGroup.type}:`,
|
|
218
|
+
bindingGroup.entries.map(({ key, value }) => ` - ${key}: ${value}`),
|
|
219
|
+
];
|
|
220
|
+
})
|
|
221
|
+
.flat(2),
|
|
222
|
+
].join("\n");
|
|
223
|
+
|
|
224
|
+
logger.log(message);
|
|
225
|
+
}
|