wrangler 0.0.0-e043479 → 0.0.0-e0850ad1

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 (154) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +47 -16
  3. package/bin/wrangler.js +118 -32
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +148 -78
  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 +17 -0
  11. package/templates/gitignore +172 -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 +137 -0
  17. package/templates/middleware/loader-sw.ts +228 -0
  18. package/templates/middleware/middleware-d1-beta.d.ts +3 -0
  19. package/templates/middleware/middleware-miniflare3-json-error.ts +33 -0
  20. package/templates/middleware/middleware-multiworker-dev.d.ts +4 -0
  21. package/templates/middleware/middleware-multiworker-dev.ts +59 -0
  22. package/templates/middleware/middleware-pretty-error.ts +40 -0
  23. package/templates/middleware/middleware-scheduled.ts +15 -0
  24. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  25. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  26. package/templates/new-worker-scheduled.js +17 -0
  27. package/templates/new-worker-scheduled.ts +32 -0
  28. package/templates/new-worker.js +3 -3
  29. package/templates/new-worker.ts +22 -4
  30. package/templates/no-op-worker.js +10 -0
  31. package/templates/pages-dev-pipeline.ts +31 -0
  32. package/templates/pages-dev-util.ts +55 -0
  33. package/templates/pages-shim.ts +9 -0
  34. package/templates/pages-template-plugin.ts +190 -0
  35. package/templates/pages-template-worker.ts +198 -0
  36. package/templates/tsconfig-sanity.ts +11 -0
  37. package/templates/tsconfig.init.json +105 -0
  38. package/templates/tsconfig.json +6 -103
  39. package/wrangler-dist/cli.d.ts +1743 -0
  40. package/wrangler-dist/cli.js +142279 -130711
  41. package/wrangler-dist/wasm-sync.wasm +0 -0
  42. package/import_meta_url.js +0 -3
  43. package/miniflare-config-stubs/.env.empty +0 -0
  44. package/miniflare-config-stubs/package.empty.json +0 -1
  45. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  46. package/pages/functions/buildWorker.ts +0 -62
  47. package/pages/functions/filepath-routing.test.ts +0 -123
  48. package/pages/functions/filepath-routing.ts +0 -178
  49. package/pages/functions/identifiers.ts +0 -78
  50. package/pages/functions/routes.ts +0 -151
  51. package/pages/functions/template-worker.ts +0 -130
  52. package/src/__tests__/configuration.test.ts +0 -2186
  53. package/src/__tests__/dev.test.tsx +0 -247
  54. package/src/__tests__/guess-worker-format.test.ts +0 -66
  55. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  56. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  57. package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
  58. package/src/__tests__/helpers/mock-account-id.ts +0 -44
  59. package/src/__tests__/helpers/mock-bin.ts +0 -36
  60. package/src/__tests__/helpers/mock-cfetch.ts +0 -207
  61. package/src/__tests__/helpers/mock-console.ts +0 -70
  62. package/src/__tests__/helpers/mock-dialogs.ts +0 -65
  63. package/src/__tests__/helpers/mock-kv.ts +0 -40
  64. package/src/__tests__/helpers/mock-stdin.ts +0 -103
  65. package/src/__tests__/helpers/mock-user.ts +0 -27
  66. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  67. package/src/__tests__/helpers/run-in-tmp.ts +0 -29
  68. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  69. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  70. package/src/__tests__/index.test.ts +0 -866
  71. package/src/__tests__/jest.setup.ts +0 -69
  72. package/src/__tests__/kv.test.ts +0 -1408
  73. package/src/__tests__/logout.test.ts +0 -50
  74. package/src/__tests__/package-manager.test.ts +0 -206
  75. package/src/__tests__/parse.test.ts +0 -322
  76. package/src/__tests__/publish.test.ts +0 -2139
  77. package/src/__tests__/r2.test.ts +0 -198
  78. package/src/__tests__/secret.test.ts +0 -425
  79. package/src/__tests__/sentry.test.ts +0 -146
  80. package/src/__tests__/tail.test.ts +0 -564
  81. package/src/__tests__/whoami.test.tsx +0 -86
  82. package/src/api/form_data.ts +0 -217
  83. package/src/api/preview.ts +0 -147
  84. package/src/api/worker.ts +0 -186
  85. package/src/bundle.ts +0 -133
  86. package/src/cfetch/index.ts +0 -104
  87. package/src/cfetch/internal.ts +0 -133
  88. package/src/cli.ts +0 -19
  89. package/src/config/README.md +0 -107
  90. package/src/config/config.ts +0 -270
  91. package/src/config/diagnostics.ts +0 -80
  92. package/src/config/environment.ts +0 -305
  93. package/src/config/index.ts +0 -52
  94. package/src/config/validation-helpers.ts +0 -370
  95. package/src/config/validation.ts +0 -1019
  96. package/src/dev.tsx +0 -960
  97. package/src/dialogs.tsx +0 -77
  98. package/src/entry.ts +0 -57
  99. package/src/environment-variables.ts +0 -33
  100. package/src/guess-worker-format.ts +0 -68
  101. package/src/index.tsx +0 -2302
  102. package/src/inspect.ts +0 -609
  103. package/src/kv.tsx +0 -339
  104. package/src/module-collection.ts +0 -170
  105. package/src/open-in-browser.ts +0 -13
  106. package/src/package-manager.ts +0 -126
  107. package/src/pages.tsx +0 -1045
  108. package/src/parse.ts +0 -183
  109. package/src/paths.ts +0 -26
  110. package/src/proxy.ts +0 -376
  111. package/src/publish.ts +0 -363
  112. package/src/r2.ts +0 -50
  113. package/src/reporting.ts +0 -115
  114. package/src/sites.tsx +0 -238
  115. package/src/tail/filters.ts +0 -279
  116. package/src/tail/index.ts +0 -299
  117. package/src/tail/printing.ts +0 -62
  118. package/src/user.tsx +0 -1063
  119. package/src/whoami.tsx +0 -69
  120. package/templates/static-asset-facade.js +0 -47
  121. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  122. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  123. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  124. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  125. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  126. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  127. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  128. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  129. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  130. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  131. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  132. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  133. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  134. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  135. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  136. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  137. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  138. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  139. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  140. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  141. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  142. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  143. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  144. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  145. package/vendor/wrangler-mime/LICENSE +0 -21
  146. package/vendor/wrangler-mime/Mime.js +0 -97
  147. package/vendor/wrangler-mime/README.md +0 -187
  148. package/vendor/wrangler-mime/cli.js +0 -46
  149. package/vendor/wrangler-mime/index.js +0 -4
  150. package/vendor/wrangler-mime/lite.js +0 -4
  151. package/vendor/wrangler-mime/package.json +0 -52
  152. package/vendor/wrangler-mime/types/other.js +0 -1
  153. package/vendor/wrangler-mime/types/standard.js +0 -1
  154. 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
- };