wrangler 0.0.0-e1c615f → 0.0.0-e3cab74

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 (85) hide show
  1. package/bin/wrangler.js +2 -2
  2. package/package.json +28 -13
  3. package/pages/functions/buildWorker.ts +6 -1
  4. package/pages/functions/filepath-routing.test.ts +112 -28
  5. package/pages/functions/filepath-routing.ts +88 -131
  6. package/pages/functions/routes.ts +11 -18
  7. package/pages/functions/template-worker.ts +21 -28
  8. package/src/__tests__/configuration.test.ts +2185 -0
  9. package/src/__tests__/dev.test.tsx +56 -9
  10. package/src/__tests__/guess-worker-format.test.ts +66 -0
  11. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  12. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  13. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  14. package/src/__tests__/helpers/mock-account-id.ts +30 -0
  15. package/src/__tests__/helpers/mock-bin.ts +36 -0
  16. package/src/__tests__/{mock-cfetch.ts → helpers/mock-cfetch.ts} +53 -17
  17. package/src/__tests__/helpers/mock-console.ts +62 -0
  18. package/src/__tests__/{mock-dialogs.ts → helpers/mock-dialogs.ts} +1 -1
  19. package/src/__tests__/helpers/mock-kv.ts +40 -0
  20. package/src/__tests__/helpers/mock-user.ts +27 -0
  21. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  22. package/src/__tests__/helpers/run-in-tmp.ts +29 -0
  23. package/src/__tests__/helpers/run-wrangler.ts +16 -0
  24. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  25. package/src/__tests__/index.test.ts +655 -76
  26. package/src/__tests__/jest.setup.ts +37 -2
  27. package/src/__tests__/kv.test.ts +441 -398
  28. package/src/__tests__/logout.test.ts +50 -0
  29. package/src/__tests__/package-manager.test.ts +206 -0
  30. package/src/__tests__/parse.test.ts +322 -0
  31. package/src/__tests__/publish.test.ts +2406 -0
  32. package/src/__tests__/r2.test.ts +198 -0
  33. package/src/__tests__/secret.test.ts +326 -0
  34. package/src/__tests__/sentry.test.ts +146 -0
  35. package/src/__tests__/tail.test.ts +564 -0
  36. package/src/__tests__/whoami.test.tsx +86 -0
  37. package/src/api/form_data.ts +112 -26
  38. package/src/api/preview.ts +34 -15
  39. package/src/api/worker.ts +58 -27
  40. package/src/bundle.ts +133 -0
  41. package/src/cfetch/index.ts +21 -19
  42. package/src/cfetch/internal.ts +85 -21
  43. package/src/cli.ts +10 -0
  44. package/src/config/README.md +107 -0
  45. package/src/config/config.ts +265 -0
  46. package/src/config/diagnostics.ts +80 -0
  47. package/src/config/environment.ts +305 -0
  48. package/src/config/index.ts +52 -0
  49. package/src/config/validation-helpers.ts +370 -0
  50. package/src/config/validation.ts +1017 -0
  51. package/src/dev.tsx +455 -368
  52. package/src/dialogs.tsx +2 -2
  53. package/src/entry.ts +57 -0
  54. package/src/environment-variables.ts +33 -0
  55. package/src/guess-worker-format.ts +68 -0
  56. package/src/index.tsx +1044 -646
  57. package/src/inspect.ts +609 -0
  58. package/src/kv.tsx +47 -39
  59. package/src/module-collection.ts +142 -36
  60. package/src/open-in-browser.ts +13 -0
  61. package/src/package-manager.ts +126 -0
  62. package/src/pages.tsx +139 -62
  63. package/src/parse.ts +183 -0
  64. package/src/paths.ts +26 -0
  65. package/src/proxy.ts +350 -77
  66. package/src/publish.ts +307 -289
  67. package/src/r2.ts +50 -0
  68. package/src/reporting.ts +115 -0
  69. package/src/sites.tsx +183 -56
  70. package/src/tail/filters.ts +279 -0
  71. package/src/tail/index.ts +299 -0
  72. package/src/tail/printing.ts +62 -0
  73. package/src/user.tsx +137 -110
  74. package/src/whoami.tsx +69 -0
  75. package/templates/new-worker.js +15 -0
  76. package/templates/new-worker.ts +15 -0
  77. package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
  78. package/templates/tsconfig.json +105 -0
  79. package/wrangler-dist/cli.js +127861 -111486
  80. package/wrangler-dist/cli.js.map +3 -3
  81. package/src/__tests__/run-in-tmp.ts +0 -19
  82. package/src/__tests__/run-wrangler.ts +0 -32
  83. package/src/api/inspect.ts +0 -430
  84. package/src/config.ts +0 -131
  85. package/src/tail.tsx +0 -73
@@ -0,0 +1,305 @@
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
+ /**
12
+ * The `EnvironmentInheritable` interface declares all the configuration fields for an environment
13
+ * that can be inherited (and overridden) from the top-level environment.
14
+ */
15
+ interface EnvironmentInheritable {
16
+ /**
17
+ * The name of your worker. Alphanumeric + dashes only.
18
+ *
19
+ * @inheritable
20
+ */
21
+ name: string | undefined;
22
+
23
+ /**
24
+ * This is the ID of the account associated with your zone.
25
+ * You might have more than one account, so make sure to use
26
+ * the ID of the account associated with the zone/route you
27
+ * provide, if you provide one. It can also be specified through
28
+ * the CLOUDFLARE_ACCOUNT_ID environment variable.
29
+ *
30
+ * @inheritable
31
+ */
32
+ account_id: string | undefined;
33
+
34
+ /**
35
+ * A date in the form yyyy-mm-dd, which will be used to determine
36
+ * which version of the Workers runtime is used.
37
+ *
38
+ * More details at https://developers.cloudflare.com/workers/platform/compatibility-dates
39
+ *
40
+ * @inheritable
41
+ */
42
+ compatibility_date: string | undefined;
43
+
44
+ /**
45
+ * A list of flags that enable features from upcoming features of
46
+ * the Workers runtime, usually used together with compatibility_flags.
47
+ *
48
+ * More details at https://developers.cloudflare.com/workers/platform/compatibility-dates
49
+ *
50
+ * @inheritable
51
+ */
52
+ compatibility_flags: string[];
53
+
54
+ /**
55
+ * Whether we use <name>.<subdomain>.workers.dev to
56
+ * test and deploy your worker.
57
+ *
58
+ * @default `true` (This is a breaking change from wrangler 1)
59
+ * @breaking
60
+ * @inheritable
61
+ */
62
+ workers_dev: boolean;
63
+
64
+ /**
65
+ * A list of routes that your worker should be published to.
66
+ * Only one of `routes` or `route` is required.
67
+ *
68
+ * Only required when workers_dev is false, and there's no scheduled worker (see `triggers`)
69
+ *
70
+ * @inheritable
71
+ */
72
+ routes: string[] | undefined;
73
+
74
+ /**
75
+ * A route that your worker should be published to. Literally
76
+ * the same as routes, but only one.
77
+ * Only one of `routes` or `route` is required.
78
+ *
79
+ * Only required when workers_dev is false, and there's no scheduled worker
80
+ *
81
+ * @inheritable
82
+ */
83
+ route: string | undefined;
84
+
85
+ /**
86
+ * The function to use to replace jsx syntax.
87
+ *
88
+ * @default `"React.createElement"`
89
+ * @inheritable
90
+ */
91
+ jsx_factory: string;
92
+
93
+ /**
94
+ * The function to use to replace jsx fragment syntax.
95
+ *
96
+ * @default `"React.Fragment"`
97
+ * @inheritable
98
+ */
99
+ jsx_fragment: string;
100
+
101
+ /**
102
+ * "Cron" definitions to trigger a worker's "scheduled" function.
103
+ *
104
+ * Lets you call workers periodically, much like a cron job.
105
+ *
106
+ * More details here https://developers.cloudflare.com/workers/platform/cron-triggers
107
+ *
108
+ * @default `{crons:[]}`
109
+ * @inheritable
110
+ */
111
+ triggers: { crons: string[] };
112
+
113
+ /**
114
+ * Specifies the Usage Model for your Worker. There are two options -
115
+ * [bundled](https://developers.cloudflare.com/workers/platform/limits#bundled-usage-model) and
116
+ * [unbound](https://developers.cloudflare.com/workers/platform/limits#unbound-usage-model).
117
+ * For newly created Workers, if the Usage Model is omitted
118
+ * it will be set to the [default Usage Model set on the account](https://dash.cloudflare.com/?account=workers/default-usage-model).
119
+ * For existing Workers, if the Usage Model is omitted, it will be
120
+ * set to the Usage Model configured in the dashboard for that Worker.
121
+ *
122
+ * @inheritable
123
+ */
124
+ usage_model: undefined | "bundled" | "unbound";
125
+
126
+ /**
127
+ * An ordered list of rules that define which modules to import,
128
+ * and what type to import them as. You will need to specify rules
129
+ * to use Text, Data, and CompiledWasm modules, or when you wish to
130
+ * have a .js file be treated as an ESModule instead of CommonJS.
131
+ *
132
+ * @inheritable
133
+ */
134
+ rules: Rule[];
135
+
136
+ /**
137
+ * TODO: remove this as it has been deprecated.
138
+ *
139
+ * This is just here for now because the `route` commands use it.
140
+ * So we need to include it in this type so it is available.
141
+ */
142
+ zone_id?: string;
143
+ }
144
+
145
+ /**
146
+ * The `EnvironmentNonInheritable` interface declares all the configuration fields for an environment
147
+ * that cannot be inherited from the top-level environment, and must be defined specifically.
148
+ *
149
+ * If any of these fields are defined at the top-level then they should also be specifically defined
150
+ * for each named environment.
151
+ */
152
+ interface EnvironmentNonInheritable {
153
+ /**
154
+ * A map of environment variables to set when deploying your worker.
155
+ *
156
+ * NOTE: This field is not automatically inherited from the top level environment,
157
+ * and so must be specified in every named environment.
158
+ *
159
+ * @default `{}`
160
+ * @nonInheritable
161
+ */
162
+ vars: { [key: string]: unknown };
163
+
164
+ /**
165
+ * A list of durable objects that your worker should be bound to.
166
+ *
167
+ * For more information about Durable Objects, see the documentation at
168
+ * https://developers.cloudflare.com/workers/learning/using-durable-objects
169
+ *
170
+ * NOTE: This field is not automatically inherited from the top level environment,
171
+ * and so must be specified in every named environment.
172
+ *
173
+ * @default `{bindings:[]}`
174
+ * @nonInheritable
175
+ */
176
+ durable_objects: {
177
+ bindings: {
178
+ /** The name of the binding used to refer to the Durable Object */
179
+ name: string;
180
+ /** The exported class name of the Durable Object */
181
+ class_name: string;
182
+ /** The script where the Durable Object is defined (if it's external to this worker) */
183
+ script_name?: string;
184
+ }[];
185
+ };
186
+
187
+ /**
188
+ * These specify any Workers KV Namespaces you want to
189
+ * access from inside your Worker.
190
+ *
191
+ * To learn more about KV Namespaces,
192
+ * see the documentation at https://developers.cloudflare.com/workers/learning/how-kv-works
193
+ *
194
+ * NOTE: This field is not automatically inherited from the top level environment,
195
+ * and so must be specified in every named environment.
196
+ *
197
+ * @default `[]`
198
+ * @nonInheritable
199
+ */
200
+ kv_namespaces: {
201
+ /** The binding name used to refer to the KV Namespace */
202
+ binding: string;
203
+ /** The ID of the KV namespace */
204
+ id: string;
205
+ /** The ID of the KV namespace used during `wrangler dev` */
206
+ preview_id?: string;
207
+ }[];
208
+
209
+ /**
210
+ * Specifies R2 buckets that are bound to this Worker environment.
211
+ *
212
+ * NOTE: This field is not automatically inherited from the top level environment,
213
+ * and so must be specified in every named environment.
214
+ *
215
+ * @default `[]`
216
+ * @nonInheritable
217
+ */
218
+ r2_buckets: {
219
+ /** The binding name used to refer to the R2 bucket in the worker. */
220
+ binding: string;
221
+ /** The name of this R2 bucket at the edge. */
222
+ bucket_name: string;
223
+ /** The preview name of this R2 bucket at the edge. */
224
+ preview_bucket_name?: string;
225
+ }[];
226
+
227
+ /**
228
+ * "Unsafe" tables for features that aren't directly supported by wrangler.
229
+ *
230
+ * NOTE: This field is not automatically inherited from the top level environment,
231
+ * and so must be specified in every named environment.
232
+ *
233
+ * @default `{ bindings: [] }`
234
+ * @nonInheritable
235
+ */
236
+ unsafe: {
237
+ /**
238
+ * A set of bindings that should be put into a Worker's upload metadata without changes. These
239
+ * can be used to implement bindings for features that haven't released and aren't supported
240
+ * directly by wrangler or miniflare.
241
+ *
242
+ * @default []
243
+ */
244
+ bindings: {
245
+ name: string;
246
+ type: string;
247
+ [key: string]: unknown;
248
+ }[];
249
+ };
250
+ }
251
+
252
+ /**
253
+ * The environment configuration properties that have been deprecated.
254
+ */
255
+ interface EnvironmentDeprecated {
256
+ /**
257
+ * The zone ID of the zone you want to deploy to. You can find this
258
+ * in your domain page on the dashboard.
259
+ *
260
+ * @deprecated This is unnecessary since we can deduce this from routes directly.
261
+ */
262
+ zone_id?: string;
263
+
264
+ /**
265
+ * A list of services that your worker should be bound to.
266
+ *
267
+ * @default `[]`
268
+ * @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.
269
+ */
270
+ experimental_services?: {
271
+ /** The binding name used to refer to the Service */
272
+ name: string;
273
+ /** The name of the Service being bound */
274
+ service: string;
275
+ /** The Service's environment */
276
+ environment: string;
277
+ }[];
278
+ }
279
+
280
+ /**
281
+ * The raw environment configuration that we read from the config file.
282
+ *
283
+ * All the properties are optional, and will be replaced with defaults in the configuration that
284
+ * is used in the rest of the codebase.
285
+ */
286
+ export type RawEnvironment = Partial<Environment> & EnvironmentDeprecated;
287
+
288
+ /**
289
+ * A bundling resolver rule, defining the modules type for paths that match the specified globs.
290
+ */
291
+ export type Rule = {
292
+ type: ConfigModuleRuleType;
293
+ globs: string[];
294
+ fallthrough?: boolean;
295
+ };
296
+
297
+ /**
298
+ * The possible types for a `Rule`.
299
+ */
300
+ export type ConfigModuleRuleType =
301
+ | "ESModule"
302
+ | "CommonJS"
303
+ | "CompiledWasm"
304
+ | "Text"
305
+ | "Data";
@@ -0,0 +1,52 @@
1
+ import { findUpSync } from "find-up";
2
+ import { parseTOML, readFileSync } from "../parse";
3
+ import { normalizeAndValidateConfig } from "./validation";
4
+ import type { Config, RawConfig } from "./config";
5
+
6
+ export type { Config, RawConfig } from "./config";
7
+ export type {
8
+ Environment,
9
+ RawEnvironment,
10
+ ConfigModuleRuleType,
11
+ } from "./environment";
12
+
13
+ /**
14
+ * Get the Wrangler configuration; read it from the give `configPath` if available.
15
+ */
16
+ export function readConfig(configPath?: string): Config {
17
+ let rawConfig: RawConfig = {};
18
+ if (!configPath) {
19
+ configPath = findWranglerToml();
20
+ }
21
+
22
+ // Load the configuration from disk if available
23
+ if (configPath) {
24
+ rawConfig = parseTOML(readFileSync(configPath), configPath);
25
+ }
26
+
27
+ // Process the top-level configuration.
28
+ const { config, diagnostics } = normalizeAndValidateConfig(
29
+ rawConfig,
30
+ configPath
31
+ );
32
+
33
+ if (diagnostics.hasWarnings()) {
34
+ console.warn(diagnostics.renderWarnings());
35
+ }
36
+ if (diagnostics.hasErrors()) {
37
+ throw new Error(diagnostics.renderErrors());
38
+ }
39
+
40
+ return config;
41
+ }
42
+
43
+ /**
44
+ * Find the wrangler.toml file by searching up the file-system
45
+ * from the current working directory.
46
+ */
47
+ export function findWranglerToml(
48
+ referencePath: string = process.cwd()
49
+ ): string | undefined {
50
+ const configPath = findUpSync("wrangler.toml", { cwd: referencePath });
51
+ return configPath;
52
+ }