wrangler 0.0.0-e978986 → 0.0.0-e981d0be5

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 (187) hide show
  1. package/README.md +46 -36
  2. package/bin/wrangler.js +82 -69
  3. package/config-schema.json +2278 -0
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +131 -102
  6. package/templates/__tests__/pages-dev-util.test.ts +128 -0
  7. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  8. package/templates/__tests__/tsconfig.json +8 -0
  9. package/templates/checked-fetch.js +30 -0
  10. package/templates/facade.d.ts +19 -0
  11. package/templates/gitignore +2 -3
  12. package/templates/init-tests/test-jest-new-worker.js +23 -0
  13. package/templates/init-tests/test-vitest-new-worker.js +24 -0
  14. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  15. package/templates/middleware/common.ts +67 -0
  16. package/templates/middleware/loader-modules.ts +134 -0
  17. package/templates/middleware/loader-sw.ts +229 -0
  18. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  19. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  20. package/templates/middleware/middleware-mock-analytics-engine.d.ts +3 -0
  21. package/templates/middleware/middleware-mock-analytics-engine.ts +30 -0
  22. package/templates/middleware/middleware-patch-console-prefix.d.ts +3 -0
  23. package/templates/middleware/middleware-patch-console-prefix.ts +21 -0
  24. package/templates/middleware/middleware-pretty-error.ts +40 -0
  25. package/templates/middleware/middleware-scheduled.ts +29 -0
  26. package/templates/modules-watch-stub.js +4 -0
  27. package/templates/new-worker-scheduled.js +4 -4
  28. package/templates/new-worker-scheduled.ts +17 -17
  29. package/templates/new-worker.js +3 -3
  30. package/templates/new-worker.ts +19 -16
  31. package/templates/no-op-worker.js +10 -0
  32. package/templates/pages-dev-pipeline.ts +33 -0
  33. package/templates/pages-dev-util.ts +55 -0
  34. package/templates/pages-shim.ts +9 -0
  35. package/templates/pages-template-plugin.ts +190 -0
  36. package/templates/pages-template-worker.ts +198 -0
  37. package/templates/startDevWorker/InspectorProxyWorker.ts +679 -0
  38. package/templates/startDevWorker/ProxyWorker.ts +336 -0
  39. package/templates/tsconfig-sanity.ts +11 -0
  40. package/templates/tsconfig.init.json +22 -0
  41. package/templates/tsconfig.json +13 -103
  42. package/templates/tsconfig.tsbuildinfo +1 -0
  43. package/wrangler-dist/InspectorProxyWorker.js +471 -0
  44. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  45. package/wrangler-dist/ProxyWorker.js +238 -0
  46. package/wrangler-dist/ProxyWorker.js.map +6 -0
  47. package/wrangler-dist/cli.d.ts +26693 -0
  48. package/wrangler-dist/cli.js +148246 -120054
  49. package/Cloudflare_CA.pem +0 -18
  50. package/import_meta_url.js +0 -3
  51. package/miniflare-config-stubs/.env.empty +0 -0
  52. package/miniflare-config-stubs/package.empty.json +0 -1
  53. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  54. package/miniflare-dist/index.mjs +0 -4886
  55. package/pages/functions/buildPlugin.ts +0 -105
  56. package/pages/functions/buildWorker.ts +0 -151
  57. package/pages/functions/filepath-routing.test.ts +0 -234
  58. package/pages/functions/filepath-routing.ts +0 -189
  59. package/pages/functions/identifiers.ts +0 -78
  60. package/pages/functions/routes.ts +0 -156
  61. package/pages/functions/template-plugin.ts +0 -147
  62. package/pages/functions/template-worker.ts +0 -143
  63. package/src/__tests__/config-cache.test.ts +0 -36
  64. package/src/__tests__/configuration.test.ts +0 -3374
  65. package/src/__tests__/dev.test.tsx +0 -980
  66. package/src/__tests__/guess-worker-format.test.ts +0 -85
  67. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  68. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  69. package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
  70. package/src/__tests__/helpers/mock-account-id.ts +0 -48
  71. package/src/__tests__/helpers/mock-bin.ts +0 -36
  72. package/src/__tests__/helpers/mock-cfetch.ts +0 -211
  73. package/src/__tests__/helpers/mock-console.ts +0 -87
  74. package/src/__tests__/helpers/mock-dialogs.ts +0 -130
  75. package/src/__tests__/helpers/mock-http-server.ts +0 -46
  76. package/src/__tests__/helpers/mock-istty.ts +0 -27
  77. package/src/__tests__/helpers/mock-kv.ts +0 -33
  78. package/src/__tests__/helpers/mock-oauth-flow.ts +0 -255
  79. package/src/__tests__/helpers/mock-stdin.ts +0 -103
  80. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  81. package/src/__tests__/helpers/run-in-tmp.ts +0 -39
  82. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  83. package/src/__tests__/helpers/write-worker-source.ts +0 -31
  84. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  85. package/src/__tests__/https-options.test.ts +0 -130
  86. package/src/__tests__/index.test.ts +0 -256
  87. package/src/__tests__/init.test.ts +0 -1567
  88. package/src/__tests__/jest.setup.ts +0 -77
  89. package/src/__tests__/kv.test.ts +0 -1481
  90. package/src/__tests__/logger.test.ts +0 -115
  91. package/src/__tests__/package-manager.test.ts +0 -353
  92. package/src/__tests__/pages.test.ts +0 -657
  93. package/src/__tests__/parse.test.ts +0 -330
  94. package/src/__tests__/publish.test.ts +0 -5468
  95. package/src/__tests__/r2.test.ts +0 -233
  96. package/src/__tests__/route.test.ts +0 -45
  97. package/src/__tests__/secret.test.ts +0 -481
  98. package/src/__tests__/tail.test.ts +0 -690
  99. package/src/__tests__/user.test.ts +0 -131
  100. package/src/__tests__/whoami.test.tsx +0 -105
  101. package/src/abort.d.ts +0 -3
  102. package/src/bundle.ts +0 -200
  103. package/src/cfetch/index.ts +0 -121
  104. package/src/cfetch/internal.ts +0 -145
  105. package/src/cli.ts +0 -13
  106. package/src/config/README.md +0 -107
  107. package/src/config/config.ts +0 -234
  108. package/src/config/diagnostics.ts +0 -80
  109. package/src/config/environment.ts +0 -420
  110. package/src/config/index.ts +0 -225
  111. package/src/config/validation-helpers.ts +0 -575
  112. package/src/config/validation.ts +0 -1539
  113. package/src/config-cache.ts +0 -45
  114. package/src/create-worker-preview.ts +0 -185
  115. package/src/create-worker-upload-form.ts +0 -254
  116. package/src/dev/dev-vars.ts +0 -36
  117. package/src/dev/dev.tsx +0 -419
  118. package/src/dev/local.tsx +0 -318
  119. package/src/dev/remote.tsx +0 -227
  120. package/src/dev/use-esbuild.ts +0 -118
  121. package/src/dialogs.tsx +0 -135
  122. package/src/durable.ts +0 -102
  123. package/src/entry.ts +0 -322
  124. package/src/environment-variables.ts +0 -35
  125. package/src/errors.ts +0 -11
  126. package/src/https-options.ts +0 -123
  127. package/src/index.tsx +0 -2848
  128. package/src/inspect.ts +0 -662
  129. package/src/intl-polyfill.d.ts +0 -139
  130. package/src/kv.ts +0 -408
  131. package/src/logger.ts +0 -66
  132. package/src/miniflare-cli/README.md +0 -30
  133. package/src/miniflare-cli/enum-keys.ts +0 -17
  134. package/src/miniflare-cli/index.ts +0 -41
  135. package/src/miniflare-cli/request-context.ts +0 -40
  136. package/src/module-collection.ts +0 -258
  137. package/src/open-in-browser.ts +0 -19
  138. package/src/package-manager.ts +0 -174
  139. package/src/pages.tsx +0 -2027
  140. package/src/parse.ts +0 -202
  141. package/src/paths.ts +0 -26
  142. package/src/proxy.ts +0 -465
  143. package/src/publish.ts +0 -583
  144. package/src/r2.ts +0 -50
  145. package/src/selfsigned.d.ts +0 -29
  146. package/src/sites.tsx +0 -295
  147. package/src/tail/filters.ts +0 -279
  148. package/src/tail/index.ts +0 -299
  149. package/src/tail/printing.ts +0 -67
  150. package/src/update-check.ts +0 -19
  151. package/src/user.tsx +0 -1203
  152. package/src/whoami.tsx +0 -70
  153. package/src/worker.ts +0 -180
  154. package/templates/static-asset-facade.js +0 -47
  155. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  156. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  157. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  158. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  159. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  160. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  161. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  162. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  163. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  164. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  165. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  166. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  167. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  168. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  169. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  170. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  171. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  172. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  173. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  174. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  175. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  176. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  177. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  178. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  179. package/vendor/wrangler-mime/LICENSE +0 -21
  180. package/vendor/wrangler-mime/Mime.js +0 -97
  181. package/vendor/wrangler-mime/README.md +0 -187
  182. package/vendor/wrangler-mime/cli.js +0 -46
  183. package/vendor/wrangler-mime/index.js +0 -4
  184. package/vendor/wrangler-mime/lite.js +0 -4
  185. package/vendor/wrangler-mime/package.json +0 -52
  186. package/vendor/wrangler-mime/types/other.js +0 -1
  187. package/vendor/wrangler-mime/types/standard.js +0 -1
@@ -1,420 +0,0 @@
1
- /**
2
- * The `Environment` interface declares all the configuration fields that
3
- * can be specified for an environment.
4
- *
5
- * This could be the top-level default environment, or a specific named environment.
6
- */
7
- export interface Environment
8
- extends EnvironmentInheritable,
9
- EnvironmentNonInheritable {}
10
-
11
- export type SimpleRoute = string;
12
- export type ZoneIdRoute = {
13
- pattern: string;
14
- zone_id: string;
15
- custom_domain?: boolean;
16
- };
17
- export type ZoneNameRoute = {
18
- pattern: string;
19
- zone_name: string;
20
- custom_domain?: boolean;
21
- };
22
- export type CustomDomainRoute = { pattern: string; custom_domain: boolean };
23
- export type Route =
24
- | SimpleRoute
25
- | ZoneIdRoute
26
- | ZoneNameRoute
27
- | CustomDomainRoute;
28
-
29
- /**
30
- * The `EnvironmentInheritable` interface declares all the configuration fields for an environment
31
- * that can be inherited (and overridden) from the top-level environment.
32
- */
33
- interface EnvironmentInheritable {
34
- /**
35
- * The name of your worker. Alphanumeric + dashes only.
36
- *
37
- * @inheritable
38
- */
39
- name: string | undefined;
40
-
41
- /**
42
- * This is the ID of the account associated with your zone.
43
- * You might have more than one account, so make sure to use
44
- * the ID of the account associated with the zone/route you
45
- * provide, if you provide one. It can also be specified through
46
- * the CLOUDFLARE_ACCOUNT_ID environment variable.
47
- *
48
- * @inheritable
49
- */
50
- account_id: string | undefined;
51
-
52
- /**
53
- * A date in the form yyyy-mm-dd, which will be used to determine
54
- * which version of the Workers runtime is used.
55
- *
56
- * More details at https://developers.cloudflare.com/workers/platform/compatibility-dates
57
- *
58
- * @inheritable
59
- */
60
- compatibility_date: string | undefined;
61
-
62
- /**
63
- * A list of flags that enable features from upcoming features of
64
- * the Workers runtime, usually used together with compatibility_flags.
65
- *
66
- * More details at https://developers.cloudflare.com/workers/platform/compatibility-dates
67
- *
68
- * @inheritable
69
- */
70
- compatibility_flags: string[];
71
-
72
- /**
73
- * The entrypoint/path to the JavaScript file that will be executed.
74
- */
75
- main: string | undefined;
76
-
77
- /**
78
- * Whether we use <name>.<subdomain>.workers.dev to
79
- * test and deploy your worker.
80
- *
81
- * @default `true` (This is a breaking change from wrangler 1)
82
- * @breaking
83
- * @inheritable
84
- */
85
- workers_dev: boolean | undefined;
86
-
87
- /**
88
- * A list of routes that your worker should be published to.
89
- * Only one of `routes` or `route` is required.
90
- *
91
- * Only required when workers_dev is false, and there's no scheduled worker (see `triggers`)
92
- *
93
- * @inheritable
94
- */
95
- routes: Route[] | undefined;
96
-
97
- /**
98
- * A route that your worker should be published to. Literally
99
- * the same as routes, but only one.
100
- * Only one of `routes` or `route` is required.
101
- *
102
- * Only required when workers_dev is false, and there's no scheduled worker
103
- *
104
- * @inheritable
105
- */
106
- route: Route | undefined;
107
-
108
- /**
109
- * Path to a custom tsconfig
110
- */
111
- tsconfig: string | undefined;
112
-
113
- /**
114
- * The function to use to replace jsx syntax.
115
- *
116
- * @default `"React.createElement"`
117
- * @inheritable
118
- */
119
- jsx_factory: string;
120
-
121
- /**
122
- * The function to use to replace jsx fragment syntax.
123
- *
124
- * @default `"React.Fragment"`
125
- * @inheritable
126
- */
127
- jsx_fragment: string;
128
-
129
- /**
130
- * "Cron" definitions to trigger a worker's "scheduled" function.
131
- *
132
- * Lets you call workers periodically, much like a cron job.
133
- *
134
- * More details here https://developers.cloudflare.com/workers/platform/cron-triggers
135
- *
136
- * @default `{crons:[]}`
137
- * @inheritable
138
- */
139
- triggers: { crons: string[] };
140
-
141
- /**
142
- * Specifies the Usage Model for your Worker. There are two options -
143
- * [bundled](https://developers.cloudflare.com/workers/platform/limits#bundled-usage-model) and
144
- * [unbound](https://developers.cloudflare.com/workers/platform/limits#unbound-usage-model).
145
- * For newly created Workers, if the Usage Model is omitted
146
- * it will be set to the [default Usage Model set on the account](https://dash.cloudflare.com/?account=workers/default-usage-model).
147
- * For existing Workers, if the Usage Model is omitted, it will be
148
- * set to the Usage Model configured in the dashboard for that Worker.
149
- *
150
- * @inheritable
151
- */
152
- usage_model: "bundled" | "unbound" | undefined;
153
-
154
- /**
155
- * An ordered list of rules that define which modules to import,
156
- * and what type to import them as. You will need to specify rules
157
- * to use Text, Data, and CompiledWasm modules, or when you wish to
158
- * have a .js file be treated as an ESModule instead of CommonJS.
159
- *
160
- * @inheritable
161
- */
162
- rules: Rule[];
163
-
164
- /**
165
- * Configures a custom build step to be run by Wrangler when building your Worker.
166
- *
167
- * Refer to the [custom builds documentation](https://developers.cloudflare.com/workers/cli-wrangler/configuration#build)
168
- * for more details.
169
- *
170
- * @default {}
171
- */
172
- build: {
173
- /** The command used to build your Worker. On Linux and macOS, the command is executed in the `sh` shell and the `cmd` shell for Windows. The `&&` and `||` shell operators may be used. */
174
- command?: string;
175
- /** The directory in which the command is executed. */
176
- cwd?: string;
177
- /** The directory to watch for changes while using wrangler dev, defaults to the current working directory */
178
- watch_dir?: string;
179
- /**
180
- * Deprecated field previously used to configure the build and upload of the script.
181
- * @deprecated
182
- */
183
- upload?: DeprecatedUpload;
184
- };
185
-
186
- /**
187
- * Minify the script before uploading.
188
- * @inheritable
189
- */
190
- minify: boolean | undefined;
191
-
192
- /**
193
- * Add polyfills for node builtin modules and globals
194
- */
195
- node_compat: boolean | undefined;
196
-
197
- /**
198
- * TODO: remove this as it has been deprecated.
199
- *
200
- * This is just here for now because the `route` commands use it.
201
- * So we need to include it in this type so it is available.
202
- */
203
- zone_id?: string;
204
- }
205
-
206
- /**
207
- * The `EnvironmentNonInheritable` interface declares all the configuration fields for an environment
208
- * that cannot be inherited from the top-level environment, and must be defined specifically.
209
- *
210
- * If any of these fields are defined at the top-level then they should also be specifically defined
211
- * for each named environment.
212
- */
213
- interface EnvironmentNonInheritable {
214
- /**
215
- * A map of environment variables to set when deploying your worker.
216
- *
217
- * NOTE: This field is not automatically inherited from the top level environment,
218
- * and so must be specified in every named environment.
219
- *
220
- * @default `{}`
221
- * @nonInheritable
222
- */
223
- vars: { [key: string]: unknown };
224
-
225
- /**
226
- * A list of durable objects that your worker should be bound to.
227
- *
228
- * For more information about Durable Objects, see the documentation at
229
- * https://developers.cloudflare.com/workers/learning/using-durable-objects
230
- *
231
- * NOTE: This field is not automatically inherited from the top level environment,
232
- * and so must be specified in every named environment.
233
- *
234
- * @default `{bindings:[]}`
235
- * @nonInheritable
236
- */
237
- durable_objects: {
238
- bindings: {
239
- /** The name of the binding used to refer to the Durable Object */
240
- name: string;
241
- /** The exported class name of the Durable Object */
242
- class_name: string;
243
- /** The script where the Durable Object is defined (if it's external to this worker) */
244
- script_name?: string;
245
- /** The service environment of the script_name to bind to */
246
- environment?: string;
247
- }[];
248
- };
249
-
250
- /**
251
- * These specify any Workers KV Namespaces you want to
252
- * access from inside your Worker.
253
- *
254
- * To learn more about KV Namespaces,
255
- * see the documentation at https://developers.cloudflare.com/workers/learning/how-kv-works
256
- *
257
- * NOTE: This field is not automatically inherited from the top level environment,
258
- * and so must be specified in every named environment.
259
- *
260
- * @default `[]`
261
- * @nonInheritable
262
- */
263
- kv_namespaces: {
264
- /** The binding name used to refer to the KV Namespace */
265
- binding: string;
266
- /** The ID of the KV namespace */
267
- id: string;
268
- /** The ID of the KV namespace used during `wrangler dev` */
269
- preview_id?: string;
270
- }[];
271
-
272
- /**
273
- * Specifies R2 buckets that are bound to this Worker environment.
274
- *
275
- * NOTE: This field is not automatically inherited from the top level environment,
276
- * and so must be specified in every named environment.
277
- *
278
- * @default `[]`
279
- * @nonInheritable
280
- */
281
- r2_buckets: {
282
- /** The binding name used to refer to the R2 bucket in the worker. */
283
- binding: string;
284
- /** The name of this R2 bucket at the edge. */
285
- bucket_name: string;
286
- /** The preview name of this R2 bucket at the edge. */
287
- preview_bucket_name?: string;
288
- }[];
289
-
290
- /**
291
- * Specifies service bindings (worker-to-worker) that are bound to this Worker environment.
292
- *
293
- * NOTE: This field is not automatically inherited from the top level environment,
294
- * and so must be specified in every named environment.
295
- *
296
- * @default `[]`
297
- * @nonInheritable
298
- */
299
- services: {
300
- /** The binding name used to refer to the bound service. */
301
- binding: string;
302
- /** The name of the service. */
303
- service: string;
304
- /** The environment of the service (e.g. production, staging, etc). */
305
- environment?: string;
306
- }[];
307
-
308
- /**
309
- * "Unsafe" tables for features that aren't directly supported by wrangler.
310
- *
311
- * NOTE: This field is not automatically inherited from the top level environment,
312
- * and so must be specified in every named environment.
313
- *
314
- * @default `{ bindings: [] }`
315
- * @nonInheritable
316
- */
317
- unsafe: {
318
- /**
319
- * A set of bindings that should be put into a Worker's upload metadata without changes. These
320
- * can be used to implement bindings for features that haven't released and aren't supported
321
- * directly by wrangler or miniflare.
322
- *
323
- * @default []
324
- */
325
- bindings: {
326
- name: string;
327
- type: string;
328
- [key: string]: unknown;
329
- }[];
330
- };
331
- }
332
-
333
- /**
334
- * The environment configuration properties that have been deprecated.
335
- */
336
- interface EnvironmentDeprecated {
337
- /**
338
- * The zone ID of the zone you want to deploy to. You can find this
339
- * in your domain page on the dashboard.
340
- *
341
- * @deprecated This is unnecessary since we can deduce this from routes directly.
342
- */
343
- zone_id?: string;
344
-
345
- /**
346
- * A list of services that your worker should be bound to.
347
- *
348
- * @default `[]`
349
- * @deprecated DO NOT USE. We'd added this to test the new service binding system, but the proper way to test experimental features is to use `unsafe.bindings` configuration.
350
- */
351
- experimental_services?: {
352
- /** The binding name used to refer to the Service */
353
- name: string;
354
- /** The name of the Service being bound */
355
- service: string;
356
- /** The Service's environment */
357
- environment: string;
358
- }[];
359
- }
360
-
361
- /**
362
- * Deprecated upload configuration.
363
- */
364
- export interface DeprecatedUpload {
365
- /**
366
- * The format of the Worker script.
367
- *
368
- * @deprecated We infer the format automatically now.
369
- */
370
- format?: "modules" | "service-worker";
371
-
372
- /**
373
- * The directory you wish to upload your worker from,
374
- * relative to the wrangler.toml file.
375
- *
376
- * Defaults to the directory containing the wrangler.toml file.
377
- *
378
- * @deprecated
379
- */
380
- dir?: string;
381
-
382
- /**
383
- * The path to the Worker script, relative to `upload.dir`.
384
- *
385
- * @deprecated This will be replaced by a command line argument.
386
- */
387
- main?: string;
388
-
389
- /**
390
- * @deprecated This is now defined at the top level `rules` field.
391
- */
392
- rules?: Environment["rules"];
393
- }
394
-
395
- /**
396
- * The raw environment configuration that we read from the config file.
397
- *
398
- * All the properties are optional, and will be replaced with defaults in the configuration that
399
- * is used in the rest of the codebase.
400
- */
401
- export type RawEnvironment = Partial<Environment> & EnvironmentDeprecated;
402
-
403
- /**
404
- * A bundling resolver rule, defining the modules type for paths that match the specified globs.
405
- */
406
- export type Rule = {
407
- type: ConfigModuleRuleType;
408
- globs: string[];
409
- fallthrough?: boolean;
410
- };
411
-
412
- /**
413
- * The possible types for a `Rule`.
414
- */
415
- export type ConfigModuleRuleType =
416
- | "ESModule"
417
- | "CommonJS"
418
- | "CompiledWasm"
419
- | "Text"
420
- | "Data";
@@ -1,225 +0,0 @@
1
- import { findUpSync } from "find-up";
2
- import { logger } from "../logger";
3
- import { parseTOML, readFileSync } from "../parse";
4
- import { normalizeAndValidateConfig } from "./validation";
5
- import type { CfWorkerInit } from "../worker";
6
- import type { Config, RawConfig } from "./config";
7
-
8
- export type {
9
- Config,
10
- RawConfig,
11
- ConfigFields,
12
- DevConfig,
13
- RawDevConfig,
14
- } from "./config";
15
- export type {
16
- Environment,
17
- RawEnvironment,
18
- ConfigModuleRuleType,
19
- } from "./environment";
20
-
21
- /**
22
- * Get the Wrangler configuration; read it from the give `configPath` if available.
23
- */
24
- export function readConfig(
25
- configPath: string | undefined,
26
- args: unknown
27
- ): Config {
28
- let rawConfig: RawConfig = {};
29
- if (!configPath) {
30
- configPath = findWranglerToml();
31
- }
32
-
33
- // Load the configuration from disk if available
34
- if (configPath) {
35
- rawConfig = parseTOML(readFileSync(configPath), configPath);
36
- }
37
-
38
- // Process the top-level configuration.
39
- const { config, diagnostics } = normalizeAndValidateConfig(
40
- rawConfig,
41
- configPath,
42
- args
43
- );
44
-
45
- if (diagnostics.hasWarnings()) {
46
- logger.warn(diagnostics.renderWarnings());
47
- }
48
- if (diagnostics.hasErrors()) {
49
- throw new Error(diagnostics.renderErrors());
50
- }
51
-
52
- return config;
53
- }
54
-
55
- /**
56
- * Find the wrangler.toml file by searching up the file-system
57
- * from the current working directory.
58
- */
59
- export function findWranglerToml(
60
- referencePath: string = process.cwd()
61
- ): string | undefined {
62
- const configPath = findUpSync("wrangler.toml", { cwd: referencePath });
63
- return configPath;
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
- }