wrangler 0.0.0-e2f9bb2 → 0.0.0-e322475

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 (103) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +3 -1
  3. package/bin/wrangler.js +36 -4
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +15 -7
  6. package/pages/functions/buildPlugin.ts +13 -0
  7. package/pages/functions/buildWorker.ts +14 -1
  8. package/pages/functions/template-plugin.ts +3 -2
  9. package/src/__tests__/configuration.test.ts +652 -229
  10. package/src/__tests__/dev.test.tsx +372 -79
  11. package/src/__tests__/helpers/mock-cfetch.ts +2 -2
  12. package/src/__tests__/helpers/mock-console.ts +11 -1
  13. package/src/__tests__/helpers/mock-dialogs.ts +75 -11
  14. package/src/__tests__/helpers/mock-process.ts +24 -0
  15. package/src/__tests__/index.test.ts +81 -72
  16. package/src/__tests__/init.test.ts +1360 -410
  17. package/src/__tests__/jest.setup.ts +38 -0
  18. package/src/__tests__/kv.test.ts +218 -152
  19. package/src/__tests__/logger.test.ts +26 -0
  20. package/src/__tests__/package-manager.test.ts +154 -7
  21. package/src/__tests__/pages.test.ts +478 -53
  22. package/src/__tests__/parse.test.ts +8 -0
  23. package/src/__tests__/publish.test.ts +1614 -333
  24. package/src/__tests__/r2.test.ts +55 -36
  25. package/src/__tests__/secret.test.ts +39 -4
  26. package/src/__tests__/user.test.ts +1 -0
  27. package/src/__tests__/whoami.test.tsx +34 -0
  28. package/src/abort.d.ts +3 -0
  29. package/src/bundle-reporter.tsx +29 -0
  30. package/src/bundle.ts +42 -7
  31. package/src/cfetch/index.ts +21 -4
  32. package/src/cfetch/internal.ts +25 -20
  33. package/src/config/config.ts +11 -2
  34. package/src/config/environment.ts +41 -15
  35. package/src/config/index.ts +162 -0
  36. package/src/config/validation-helpers.ts +10 -1
  37. package/src/config/validation.ts +234 -78
  38. package/src/create-worker-preview.ts +32 -22
  39. package/src/create-worker-upload-form.ts +22 -8
  40. package/src/dev/dev.tsx +48 -67
  41. package/src/dev/local.tsx +16 -7
  42. package/src/dev/remote.tsx +57 -21
  43. package/src/dev/use-esbuild.ts +1 -7
  44. package/src/dialogs.tsx +48 -0
  45. package/src/durable.ts +102 -0
  46. package/src/entry.ts +71 -10
  47. package/src/generate-auth-url.ts +33 -0
  48. package/src/generate-random-state.ts +16 -0
  49. package/src/git-client.ts +42 -0
  50. package/src/index.tsx +619 -338
  51. package/src/inspect.ts +39 -0
  52. package/src/kv.ts +116 -27
  53. package/src/logger.ts +8 -1
  54. package/src/open-in-browser.ts +3 -12
  55. package/src/package-manager.ts +50 -3
  56. package/src/pages.tsx +434 -207
  57. package/src/parse.ts +44 -5
  58. package/src/proxy.ts +66 -44
  59. package/src/publish.ts +407 -137
  60. package/src/sites.tsx +103 -28
  61. package/src/user.tsx +35 -26
  62. package/src/whoami.tsx +3 -2
  63. package/src/worker.ts +10 -1
  64. package/src/zones.ts +73 -0
  65. package/templates/new-worker-scheduled.js +17 -0
  66. package/templates/new-worker-scheduled.ts +32 -0
  67. package/templates/new-worker.ts +16 -1
  68. package/templates/no-op-worker.js +10 -0
  69. package/templates/static-asset-facade.js +2 -6
  70. package/wrangler-dist/cli.js +46122 -32396
  71. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  72. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  73. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  74. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  75. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  76. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  77. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  78. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  79. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  80. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  81. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  82. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  83. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  84. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  85. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  86. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  87. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  88. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  89. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  90. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  91. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  92. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  93. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  94. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  95. package/vendor/wrangler-mime/LICENSE +0 -21
  96. package/vendor/wrangler-mime/Mime.js +0 -97
  97. package/vendor/wrangler-mime/README.md +0 -187
  98. package/vendor/wrangler-mime/cli.js +0 -46
  99. package/vendor/wrangler-mime/index.js +0 -4
  100. package/vendor/wrangler-mime/lite.js +0 -4
  101. package/vendor/wrangler-mime/package.json +0 -52
  102. package/vendor/wrangler-mime/types/other.js +0 -1
  103. package/vendor/wrangler-mime/types/standard.js +0 -1
@@ -8,6 +8,24 @@ export interface Environment
8
8
  extends EnvironmentInheritable,
9
9
  EnvironmentNonInheritable {}
10
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
+
11
29
  /**
12
30
  * The `EnvironmentInheritable` interface declares all the configuration fields for an environment
13
31
  * that can be inherited (and overridden) from the top-level environment.
@@ -74,13 +92,7 @@ interface EnvironmentInheritable {
74
92
  *
75
93
  * @inheritable
76
94
  */
77
- routes:
78
- | (
79
- | string
80
- | { pattern: string; zone_id: string }
81
- | { pattern: string; zone_name: string }
82
- )[]
83
- | undefined;
95
+ routes: Route[] | undefined;
84
96
 
85
97
  /**
86
98
  * A route that your worker should be published to. Literally
@@ -91,13 +103,7 @@ interface EnvironmentInheritable {
91
103
  *
92
104
  * @inheritable
93
105
  */
94
- route:
95
- | (
96
- | string
97
- | { pattern: string; zone_id: string }
98
- | { pattern: string; zone_name: string }
99
- )
100
- | undefined;
106
+ route: Route | undefined;
101
107
 
102
108
  /**
103
109
  * Path to a custom tsconfig
@@ -169,7 +175,7 @@ interface EnvironmentInheritable {
169
175
  /** The directory in which the command is executed. */
170
176
  cwd?: string;
171
177
  /** The directory to watch for changes while using wrangler dev, defaults to the current working directory */
172
- watch_dir?: string;
178
+ watch_dir?: string | string[];
173
179
  /**
174
180
  * Deprecated field previously used to configure the build and upload of the script.
175
181
  * @deprecated
@@ -236,6 +242,8 @@ interface EnvironmentNonInheritable {
236
242
  class_name: string;
237
243
  /** The script where the Durable Object is defined (if it's external to this worker) */
238
244
  script_name?: string;
245
+ /** The service environment of the script_name to bind to */
246
+ environment?: string;
239
247
  }[];
240
248
  };
241
249
 
@@ -279,6 +287,24 @@ interface EnvironmentNonInheritable {
279
287
  preview_bucket_name?: string;
280
288
  }[];
281
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
+
282
308
  /**
283
309
  * "Unsafe" tables for features that aren't directly supported by wrangler.
284
310
  *
@@ -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
+ }
@@ -277,12 +277,21 @@ export const isObjectWith =
277
277
  !properties.every((prop) => prop in value))
278
278
  ) {
279
279
  diagnostics.errors.push(
280
- `Expected "${field}" to be of type object, containing properties ${properties}, but got ${JSON.stringify(
280
+ `Expected "${field}" to be of type object, containing only properties ${properties}, but got ${JSON.stringify(
281
281
  value
282
282
  )}.`
283
283
  );
284
284
  return false;
285
285
  }
286
+ // it's an object with the field as desired,
287
+ // but let's also check for unexpected fields
288
+ if (value !== undefined) {
289
+ const restFields = Object.keys(value).filter(
290
+ (key) => !properties.includes(key)
291
+ );
292
+ validateAdditionalProperties(diagnostics, field, restFields, []);
293
+ }
294
+
286
295
  return true;
287
296
  };
288
297