wrangler 0.0.0-e043479 → 0.0.0-e0489587

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 (159) hide show
  1. package/README.md +47 -16
  2. package/bin/wrangler.js +95 -32
  3. package/config-schema.json +3059 -0
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +148 -89
  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 +170 -0
  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-pretty-error.ts +40 -0
  21. package/templates/middleware/middleware-scheduled.ts +15 -0
  22. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  23. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  24. package/templates/modules-watch-stub.js +4 -0
  25. package/templates/new-worker-scheduled.js +17 -0
  26. package/templates/new-worker-scheduled.ts +32 -0
  27. package/templates/new-worker.js +3 -3
  28. package/templates/new-worker.ts +22 -4
  29. package/templates/no-op-worker.js +10 -0
  30. package/templates/pages-dev-pipeline.ts +32 -0
  31. package/templates/pages-dev-util.ts +55 -0
  32. package/templates/pages-shim.ts +9 -0
  33. package/templates/pages-template-plugin.ts +190 -0
  34. package/templates/pages-template-worker.ts +198 -0
  35. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  36. package/templates/startDevWorker/ProxyWorker.ts +334 -0
  37. package/templates/tsconfig-sanity.ts +11 -0
  38. package/templates/tsconfig.init.json +105 -0
  39. package/templates/tsconfig.json +6 -103
  40. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  41. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  42. package/wrangler-dist/ProxyWorker.js +240 -0
  43. package/wrangler-dist/ProxyWorker.js.map +6 -0
  44. package/wrangler-dist/cli.d.ts +26375 -0
  45. package/wrangler-dist/cli.js +202160 -132057
  46. package/wrangler-dist/wasm-sync.wasm +0 -0
  47. package/import_meta_url.js +0 -3
  48. package/miniflare-config-stubs/.env.empty +0 -0
  49. package/miniflare-config-stubs/package.empty.json +0 -1
  50. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  51. package/pages/functions/buildWorker.ts +0 -62
  52. package/pages/functions/filepath-routing.test.ts +0 -123
  53. package/pages/functions/filepath-routing.ts +0 -178
  54. package/pages/functions/identifiers.ts +0 -78
  55. package/pages/functions/routes.ts +0 -151
  56. package/pages/functions/template-worker.ts +0 -130
  57. package/src/__tests__/configuration.test.ts +0 -2186
  58. package/src/__tests__/dev.test.tsx +0 -247
  59. package/src/__tests__/guess-worker-format.test.ts +0 -66
  60. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  61. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  62. package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
  63. package/src/__tests__/helpers/mock-account-id.ts +0 -44
  64. package/src/__tests__/helpers/mock-bin.ts +0 -36
  65. package/src/__tests__/helpers/mock-cfetch.ts +0 -207
  66. package/src/__tests__/helpers/mock-console.ts +0 -70
  67. package/src/__tests__/helpers/mock-dialogs.ts +0 -65
  68. package/src/__tests__/helpers/mock-kv.ts +0 -40
  69. package/src/__tests__/helpers/mock-stdin.ts +0 -103
  70. package/src/__tests__/helpers/mock-user.ts +0 -27
  71. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  72. package/src/__tests__/helpers/run-in-tmp.ts +0 -29
  73. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  74. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  75. package/src/__tests__/index.test.ts +0 -866
  76. package/src/__tests__/jest.setup.ts +0 -69
  77. package/src/__tests__/kv.test.ts +0 -1408
  78. package/src/__tests__/logout.test.ts +0 -50
  79. package/src/__tests__/package-manager.test.ts +0 -206
  80. package/src/__tests__/parse.test.ts +0 -322
  81. package/src/__tests__/publish.test.ts +0 -2139
  82. package/src/__tests__/r2.test.ts +0 -198
  83. package/src/__tests__/secret.test.ts +0 -425
  84. package/src/__tests__/sentry.test.ts +0 -146
  85. package/src/__tests__/tail.test.ts +0 -564
  86. package/src/__tests__/whoami.test.tsx +0 -86
  87. package/src/api/form_data.ts +0 -217
  88. package/src/api/preview.ts +0 -147
  89. package/src/api/worker.ts +0 -186
  90. package/src/bundle.ts +0 -133
  91. package/src/cfetch/index.ts +0 -104
  92. package/src/cfetch/internal.ts +0 -133
  93. package/src/cli.ts +0 -19
  94. package/src/config/README.md +0 -107
  95. package/src/config/config.ts +0 -270
  96. package/src/config/diagnostics.ts +0 -80
  97. package/src/config/environment.ts +0 -305
  98. package/src/config/index.ts +0 -52
  99. package/src/config/validation-helpers.ts +0 -370
  100. package/src/config/validation.ts +0 -1019
  101. package/src/dev.tsx +0 -960
  102. package/src/dialogs.tsx +0 -77
  103. package/src/entry.ts +0 -57
  104. package/src/environment-variables.ts +0 -33
  105. package/src/guess-worker-format.ts +0 -68
  106. package/src/index.tsx +0 -2302
  107. package/src/inspect.ts +0 -609
  108. package/src/kv.tsx +0 -339
  109. package/src/module-collection.ts +0 -170
  110. package/src/open-in-browser.ts +0 -13
  111. package/src/package-manager.ts +0 -126
  112. package/src/pages.tsx +0 -1045
  113. package/src/parse.ts +0 -183
  114. package/src/paths.ts +0 -26
  115. package/src/proxy.ts +0 -376
  116. package/src/publish.ts +0 -363
  117. package/src/r2.ts +0 -50
  118. package/src/reporting.ts +0 -115
  119. package/src/sites.tsx +0 -238
  120. package/src/tail/filters.ts +0 -279
  121. package/src/tail/index.ts +0 -299
  122. package/src/tail/printing.ts +0 -62
  123. package/src/user.tsx +0 -1063
  124. package/src/whoami.tsx +0 -69
  125. package/templates/static-asset-facade.js +0 -47
  126. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  127. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  128. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  129. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  130. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  131. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  132. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  133. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  134. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  135. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  136. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  137. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  138. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  139. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  140. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  141. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  142. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  143. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  144. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  145. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  146. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  147. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  148. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  149. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  150. package/vendor/wrangler-mime/LICENSE +0 -21
  151. package/vendor/wrangler-mime/Mime.js +0 -97
  152. package/vendor/wrangler-mime/README.md +0 -187
  153. package/vendor/wrangler-mime/cli.js +0 -46
  154. package/vendor/wrangler-mime/index.js +0 -4
  155. package/vendor/wrangler-mime/lite.js +0 -4
  156. package/vendor/wrangler-mime/package.json +0 -52
  157. package/vendor/wrangler-mime/types/other.js +0 -1
  158. package/vendor/wrangler-mime/types/standard.js +0 -1
  159. package/wrangler-dist/cli.js.map +0 -7
@@ -1,370 +0,0 @@
1
- import type { Config, RawConfig } from "./config";
2
- import type { Diagnostics } from "./diagnostics";
3
- import type { Environment, RawEnvironment } from "./environment";
4
-
5
- /**
6
- * Mark a field as deprecated.
7
- *
8
- * This function will add a diagnostics warning if the deprecated field is found in the `rawEnv`.
9
- * The `fieldPath` is a dot separated property path, e.g. `"build.upload.format"`.
10
- */
11
- export function deprecated<T extends object>(
12
- diagnostics: Diagnostics,
13
- config: T,
14
- fieldPath: DeepKeyOf<T>,
15
- message: string,
16
- remove: boolean
17
- ): void {
18
- const result = unwindPropertyPath(config, fieldPath);
19
- if (result !== undefined && result.field in result.container) {
20
- diagnostics.warnings.push(`DEPRECATION: "${fieldPath}":\n${message}`);
21
- if (remove) {
22
- delete (result.container as Record<string, unknown>)[result.field];
23
- }
24
- }
25
- }
26
-
27
- /**
28
- * Mark a field as experimental.
29
- *
30
- * This function will add a diagnostics warning if the experimental field is found in the `rawEnv`.
31
- * The `fieldPath` is a dot separated property path, e.g. `"build.upload.format"`.
32
- */
33
- export function experimental<T extends object>(
34
- diagnostics: Diagnostics,
35
- config: T,
36
- fieldPath: DeepKeyOf<T>
37
- ): void {
38
- const result = unwindPropertyPath(config, fieldPath);
39
- if (result !== undefined && result.field in result.container) {
40
- diagnostics.warnings.push(
41
- `"${fieldPath}" fields are experimental and may change or break at any time.`
42
- );
43
- }
44
- }
45
-
46
- /**
47
- * Get an inheritable environment field, after computing and validating its value.
48
- *
49
- * If the field is not defined in the given environment, then fallback to the value from the top-level config,
50
- * and then the `defaultValue`.
51
- */
52
- export function inheritable<K extends keyof Environment>(
53
- diagnostics: Diagnostics,
54
- config: Config | undefined,
55
- rawEnv: RawEnvironment,
56
- field: K,
57
- validate: ValidatorFn,
58
- defaultValue: Environment[K]
59
- ): Environment[K] {
60
- validate(diagnostics, field, rawEnv[field], config);
61
- return (rawEnv[field] as Environment[K]) ?? config?.[field] ?? defaultValue;
62
- }
63
-
64
- /**
65
- * Get a not inheritable environment field, after computing and validating its value.
66
- *
67
- * If the field is not defined in the given environment but it is defined in the top-level config,
68
- * then log a warning and return the `defaultValue`.
69
- */
70
- export function notInheritable<K extends keyof Environment>(
71
- diagnostics: Diagnostics,
72
- config: Config | undefined,
73
- rawConfig: RawConfig | undefined,
74
- rawEnv: RawEnvironment,
75
- envName: string,
76
- field: K,
77
- validate: ValidatorFn,
78
- defaultValue: Environment[K]
79
- ): Environment[K] {
80
- if (rawEnv[field] !== undefined) {
81
- validate(diagnostics, field, rawEnv[field], config);
82
- } else {
83
- if (rawConfig?.[field] !== undefined) {
84
- diagnostics.warnings.push(
85
- `"${field}" exists at the top level, but not on "env.${envName}".\n` +
86
- `This is not what you probably want, since "${field}" is not inherited by environments.\n` +
87
- `Please add "${field}" to "env.${envName}".`
88
- );
89
- }
90
- }
91
- return (rawEnv[field] as Environment[K]) ?? defaultValue;
92
- }
93
-
94
- // Idea taken from https://stackoverflow.com/a/66661477
95
- type DeepKeyOf<T> = (
96
- T extends object
97
- ? {
98
- [K in Exclude<keyof T, symbol>]: `${K}${DotPrefix<DeepKeyOf<T[K]>>}`;
99
- }[Exclude<keyof T, symbol>]
100
- : ""
101
- ) extends infer D
102
- ? Extract<D, string>
103
- : never;
104
-
105
- type DotPrefix<T extends string> = T extends "" ? "" : `.${T}`;
106
-
107
- /**
108
- * Return a container object and field name for the last property in a given property path.
109
- *
110
- * For example, given a path of `"build.upload.format"`) and a starting `root` object
111
- * this will return:
112
- *
113
- * ```
114
- * { container: root.build.upload, field: "format" }
115
- * ```
116
- */
117
- function unwindPropertyPath<T extends object>(
118
- root: T,
119
- path: DeepKeyOf<T>
120
- ): { container: object; field: string } | undefined {
121
- let container: object = root;
122
- const parts = (path as string).split(".");
123
- for (let i = 0; i < parts.length - 1; i++) {
124
- if (!hasProperty(container, parts[i])) {
125
- return;
126
- }
127
- container = container[parts[i]];
128
- }
129
- return { container, field: parts[parts.length - 1] };
130
- }
131
-
132
- /**
133
- * The type of a function that can be used to validate a configuration field.
134
- */
135
- export type ValidatorFn = (
136
- diagnostics: Diagnostics,
137
- field: string,
138
- value: unknown,
139
- config: Config | undefined
140
- ) => boolean;
141
-
142
- /**
143
- * Validate that the field is a string.
144
- */
145
- export const isString: ValidatorFn = (diagnostics, field, value) => {
146
- if (value !== undefined && typeof value !== "string") {
147
- diagnostics.errors.push(
148
- `Expected "${field}" field to be a string but got ${JSON.stringify(
149
- value
150
- )}.`
151
- );
152
- return false;
153
- }
154
- return true;
155
- };
156
-
157
- /**
158
- * Validate that the field is an array of strings.
159
- */
160
- export const isStringArray: ValidatorFn = (diagnostics, field, value) => {
161
- if (
162
- value !== undefined &&
163
- (!Array.isArray(value) || value.some((item) => typeof item !== "string"))
164
- ) {
165
- diagnostics.errors.push(
166
- `Expected "${field}" field to be an array of strings but got ${JSON.stringify(
167
- value
168
- )}.`
169
- );
170
- return false;
171
- }
172
- return true;
173
- };
174
-
175
- /**
176
- * Validate that the field is an object containing the given properties.
177
- */
178
- export const isObjectWith =
179
- (...properties: string[]): ValidatorFn =>
180
- (diagnostics, field, value) => {
181
- if (
182
- value !== undefined &&
183
- (typeof value !== "object" ||
184
- value === null ||
185
- !properties.every((prop) => prop in value))
186
- ) {
187
- diagnostics.errors.push(
188
- `Expected "${field}" field to be an object containing properties ${properties} but got ${JSON.stringify(
189
- value
190
- )}.`
191
- );
192
- return false;
193
- }
194
- return true;
195
- };
196
-
197
- /**
198
- * Validate that the field value is one of the given choices.
199
- */
200
- export const isOneOf =
201
- (...choices: unknown[]): ValidatorFn =>
202
- (diagnostics, field, value) => {
203
- if (value !== undefined && !choices.some((choice) => value === choice)) {
204
- diagnostics.errors.push(
205
- `Expected "${field}" field to be on of ${choices} but got ${JSON.stringify(
206
- value
207
- )}.`
208
- );
209
- return false;
210
- }
211
- return true;
212
- };
213
-
214
- /**
215
- * Validate that the field is a boolean.
216
- */
217
- export const isBoolean: ValidatorFn = (diagnostics, field, value) => {
218
- if (value !== undefined && typeof value !== "boolean") {
219
- diagnostics.errors.push(
220
- `Expected "${field}" field to be a boolean but got ${JSON.stringify(
221
- value
222
- )}.`
223
- );
224
- return false;
225
- }
226
- return true;
227
- };
228
-
229
- /**
230
- * Validate that the required field exists and has the expected type.
231
- */
232
- export const validateRequiredProperty = (
233
- diagnostics: Diagnostics,
234
- container: string,
235
- key: string,
236
- value: unknown,
237
- type: string
238
- ): boolean => {
239
- if (container) {
240
- container += ".";
241
- }
242
- if (value === undefined) {
243
- diagnostics.errors.push(`ERROR: "${container}${key}" is a required field.`);
244
- return false;
245
- } else if (typeof value !== type) {
246
- diagnostics.errors.push(
247
- `ERROR: "${container}${key}" should be of type ${type} but got ${JSON.stringify(
248
- value
249
- )}.`
250
- );
251
- return false;
252
- }
253
- return true;
254
- };
255
-
256
- /**
257
- * Validate that, if the optional field exists, then it has the expected type.
258
- */
259
- export const validateOptionalProperty = (
260
- diagnostics: Diagnostics,
261
- container: string,
262
- key: string,
263
- value: unknown,
264
- type: string
265
- ): boolean => {
266
- if (value !== undefined) {
267
- return validateRequiredProperty(diagnostics, container, key, value, type);
268
- }
269
- return true;
270
- };
271
-
272
- /**
273
- * Validate that the field is an array of elements of the given type.
274
- */
275
- export const validateTypedArray = (
276
- diagnostics: Diagnostics,
277
- container: string,
278
- value: unknown,
279
- type: string
280
- ): boolean => {
281
- let isValid = true;
282
- if (!Array.isArray(value)) {
283
- diagnostics.errors.push(
284
- `"${container}" should be an array of ${type}s but got ${JSON.stringify(
285
- value
286
- )}`
287
- );
288
- isValid = false;
289
- } else {
290
- for (let i = 0; i < value.length; i++) {
291
- isValid =
292
- validateRequiredProperty(
293
- diagnostics,
294
- container,
295
- `[${i}]`,
296
- value[i],
297
- type
298
- ) && isValid;
299
- }
300
- }
301
- return isValid;
302
- };
303
-
304
- /**
305
- * Validate that, if the optional field exists, it is an array of elements of the given type.
306
- */
307
- export const validateOptionalTypedArray = (
308
- diagnostics: Diagnostics,
309
- container: string,
310
- value: unknown,
311
- type: string
312
- ) => {
313
- if (value !== undefined) {
314
- return validateTypedArray(diagnostics, container, value, type);
315
- }
316
- return true;
317
- };
318
-
319
- /**
320
- * Test to see if `obj` has the required property `prop` of type `type`.
321
- */
322
- export const isRequiredProperty = <T extends object>(
323
- obj: object,
324
- prop: keyof T,
325
- type: string,
326
- choices?: unknown[]
327
- ): obj is T =>
328
- hasProperty<T>(obj, prop) &&
329
- typeof obj[prop] === type &&
330
- (choices === undefined || choices.includes(obj[prop]));
331
-
332
- /**
333
- * Test to see if `obj` has the optional property `prop` of type `type`.
334
- */
335
- export const isOptionalProperty = <T extends object>(
336
- obj: object,
337
- prop: keyof T,
338
- type: string
339
- ): obj is T => !hasProperty<T>(obj, prop) || typeof obj[prop] === type;
340
-
341
- /**
342
- * Test to see if `obj` has the property `prop`.
343
- */
344
- export const hasProperty = <T extends object>(
345
- obj: object,
346
- property: keyof T
347
- ): obj is T => property in obj;
348
-
349
- /**
350
- * Add warning messages about any properties in the given field that are not expected to be there.
351
- */
352
- export const validateAdditionalProperties = (
353
- diagnostics: Diagnostics,
354
- fieldPath: string,
355
- restProps: Iterable<string>,
356
- knownProps: Iterable<string>
357
- ): boolean => {
358
- const restPropSet = new Set(restProps);
359
- for (const knownProp of knownProps) {
360
- restPropSet.delete(knownProp);
361
- }
362
- if (restPropSet.size > 0) {
363
- const fields = Array.from(restPropSet.keys()).map((field) => `"${field}"`);
364
- diagnostics.warnings.push(
365
- `Unexpected fields found in ${fieldPath} field: ${fields}`
366
- );
367
- return false;
368
- }
369
- return true;
370
- };