wrangler 0.0.0-ece06ea → 0.0.0-ed4f2ef

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