wrangler 0.0.0-e151223 → 0.0.0-e1e2ee5c

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 (209) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +33 -14
  3. package/bin/wrangler.js +160 -28
  4. package/kv-asset-handler.js +1 -0
  5. package/miniflare-dist/index.mjs +5354 -0
  6. package/package.json +166 -127
  7. package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
  8. package/src/__tests__/config-cache.test.ts +42 -0
  9. package/src/__tests__/configuration.test.ts +3950 -0
  10. package/src/__tests__/dev.test.tsx +1199 -67
  11. package/src/__tests__/guess-worker-format.test.ts +85 -0
  12. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  13. package/src/__tests__/helpers/mock-account-id.ts +36 -18
  14. package/src/__tests__/helpers/mock-bin.ts +36 -0
  15. package/src/__tests__/helpers/mock-cfetch.ts +118 -80
  16. package/src/__tests__/helpers/mock-console.ts +70 -29
  17. package/src/__tests__/helpers/mock-dialogs.ts +121 -33
  18. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  19. package/src/__tests__/helpers/mock-istty.ts +74 -0
  20. package/src/__tests__/helpers/mock-kv.ts +28 -35
  21. package/src/__tests__/helpers/mock-oauth-flow.ts +250 -0
  22. package/src/__tests__/helpers/mock-process.ts +39 -0
  23. package/src/__tests__/helpers/mock-stdin.ts +108 -0
  24. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  25. package/src/__tests__/helpers/run-in-tmp.ts +29 -20
  26. package/src/__tests__/helpers/run-wrangler.ts +8 -6
  27. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  28. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  29. package/src/__tests__/https-options.test.ts +163 -0
  30. package/src/__tests__/index.test.ts +255 -399
  31. package/src/__tests__/init.test.ts +1992 -0
  32. package/src/__tests__/jest.setup.ts +102 -16
  33. package/src/__tests__/kv.test.ts +1400 -878
  34. package/src/__tests__/logger.test.ts +141 -0
  35. package/src/__tests__/metrics.test.ts +445 -0
  36. package/src/__tests__/package-manager.test.ts +353 -0
  37. package/src/__tests__/pages.test.ts +1261 -0
  38. package/src/__tests__/parse.test.ts +330 -0
  39. package/src/__tests__/publish.test.ts +6633 -1184
  40. package/src/__tests__/pubsub.test.ts +367 -0
  41. package/src/__tests__/r2.test.ts +233 -0
  42. package/src/__tests__/route.test.ts +45 -0
  43. package/src/__tests__/secret.test.ts +484 -202
  44. package/src/__tests__/tail.test.ts +698 -0
  45. package/src/__tests__/test-old-node-version.js +31 -0
  46. package/src/__tests__/user.test.ts +143 -0
  47. package/src/__tests__/version.test.ts +35 -0
  48. package/src/__tests__/whoami.test.tsx +219 -75
  49. package/src/__tests__/worker-namespace.test.ts +327 -0
  50. package/src/abort.d.ts +3 -0
  51. package/src/api/dev.ts +86 -0
  52. package/src/api/index.ts +1 -0
  53. package/src/bundle-reporter.tsx +29 -0
  54. package/src/bundle.ts +236 -0
  55. package/src/cfetch/index.ts +86 -76
  56. package/src/cfetch/internal.ts +122 -45
  57. package/src/cli.ts +24 -6
  58. package/src/config/README.md +107 -0
  59. package/src/config/config.ts +251 -0
  60. package/src/config/diagnostics.ts +80 -0
  61. package/src/config/environment.ts +453 -0
  62. package/src/config/index.ts +238 -0
  63. package/src/config/validation-helpers.ts +584 -0
  64. package/src/config/validation.ts +1754 -0
  65. package/src/config-cache.ts +84 -0
  66. package/src/create-worker-preview.ts +255 -0
  67. package/src/create-worker-upload-form.ts +263 -0
  68. package/src/dev/dev-vars.ts +36 -0
  69. package/src/dev/dev.tsx +452 -0
  70. package/src/dev/local.tsx +373 -0
  71. package/src/dev/remote.tsx +386 -0
  72. package/src/dev/use-esbuild.ts +150 -0
  73. package/src/dev.tsx +579 -820
  74. package/src/dialogs.tsx +115 -57
  75. package/src/durable.ts +102 -0
  76. package/src/entry.ts +328 -0
  77. package/src/environment-variables.ts +35 -0
  78. package/src/errors.ts +11 -0
  79. package/src/faye-websocket.d.ts +6 -0
  80. package/src/generate.ts +33 -0
  81. package/src/git-client.ts +42 -0
  82. package/src/global-wrangler-config-path.ts +26 -0
  83. package/src/https-options.ts +127 -0
  84. package/src/index.tsx +1969 -2024
  85. package/src/init.ts +549 -0
  86. package/src/inspect.ts +603 -537
  87. package/src/intl-polyfill.d.ts +139 -0
  88. package/src/is-interactive.ts +12 -0
  89. package/src/kv.ts +430 -0
  90. package/src/logger.ts +73 -0
  91. package/src/metrics/index.ts +4 -0
  92. package/src/metrics/is-ci.ts +14 -0
  93. package/src/metrics/metrics-config.ts +239 -0
  94. package/src/metrics/metrics-dispatcher.ts +95 -0
  95. package/src/metrics/send-event.ts +92 -0
  96. package/src/miniflare-cli/README.md +30 -0
  97. package/src/miniflare-cli/assets.ts +543 -0
  98. package/src/miniflare-cli/enum-keys.ts +17 -0
  99. package/src/miniflare-cli/index.ts +85 -0
  100. package/src/miniflare-cli/request-context.ts +40 -0
  101. package/src/module-collection.ts +244 -49
  102. package/src/open-in-browser.ts +17 -0
  103. package/src/package-manager.ts +219 -0
  104. package/src/pages/build.tsx +204 -0
  105. package/src/pages/constants.ts +7 -0
  106. package/src/pages/deployments.tsx +106 -0
  107. package/src/pages/dev.tsx +401 -0
  108. package/src/pages/functions/buildPlugin.ts +105 -0
  109. package/src/pages/functions/buildWorker.ts +151 -0
  110. package/src/pages/functions/filepath-routing.test.ts +234 -0
  111. package/src/pages/functions/filepath-routing.ts +189 -0
  112. package/src/pages/functions/identifiers.ts +78 -0
  113. package/src/pages/functions/routes.ts +151 -0
  114. package/src/pages/index.tsx +84 -0
  115. package/src/pages/projects.tsx +163 -0
  116. package/src/pages/publish.tsx +338 -0
  117. package/src/pages/types.ts +40 -0
  118. package/src/pages/upload.tsx +396 -0
  119. package/src/pages/utils.ts +12 -0
  120. package/src/parse.ts +286 -0
  121. package/src/paths.ts +6 -6
  122. package/src/preview.ts +31 -0
  123. package/src/proxy.ts +417 -311
  124. package/src/publish.ts +774 -391
  125. package/src/pubsub/index.ts +286 -0
  126. package/src/pubsub/pubsub-commands.tsx +623 -0
  127. package/src/r2.ts +50 -0
  128. package/src/selfsigned.d.ts +29 -0
  129. package/src/sites.tsx +291 -159
  130. package/src/tail/filters.ts +279 -0
  131. package/src/tail/index.ts +299 -0
  132. package/src/tail/printing.ts +67 -0
  133. package/src/update-check.ts +19 -0
  134. package/src/user/choose-account.tsx +69 -0
  135. package/src/user/env-vars.ts +46 -0
  136. package/src/user/generate-auth-url.ts +33 -0
  137. package/src/user/generate-random-state.ts +16 -0
  138. package/src/user/index.ts +3 -0
  139. package/src/user/user.tsx +1171 -0
  140. package/src/whoami.tsx +63 -41
  141. package/src/worker-namespace.ts +206 -0
  142. package/src/worker.ts +191 -0
  143. package/src/zones.ts +76 -0
  144. package/templates/checked-fetch.js +17 -0
  145. package/templates/gitignore +171 -0
  146. package/templates/new-worker-scheduled.js +17 -0
  147. package/templates/new-worker-scheduled.ts +32 -0
  148. package/templates/new-worker.js +15 -0
  149. package/templates/new-worker.ts +30 -0
  150. package/templates/no-op-worker.js +10 -0
  151. package/templates/pages-shim.ts +9 -0
  152. package/templates/pages-template-plugin.ts +155 -0
  153. package/templates/pages-template-worker.ts +161 -0
  154. package/templates/static-asset-facade.js +49 -0
  155. package/templates/tsconfig.json +105 -0
  156. package/wrangler-dist/cli.d.ts +327 -0
  157. package/wrangler-dist/cli.js +78107 -79324
  158. package/pages/functions/buildWorker.ts +0 -62
  159. package/pages/functions/filepath-routing.test.ts +0 -47
  160. package/pages/functions/filepath-routing.ts +0 -231
  161. package/pages/functions/identifiers.ts +0 -78
  162. package/pages/functions/routes.ts +0 -160
  163. package/pages/functions/template-worker.ts +0 -136
  164. package/src/__tests__/helpers/mock-user.ts +0 -27
  165. package/src/__tests__/logout.test.ts +0 -50
  166. package/src/api/form_data.ts +0 -134
  167. package/src/api/preview.ts +0 -128
  168. package/src/api/worker.ts +0 -155
  169. package/src/config.ts +0 -641
  170. package/src/kv.tsx +0 -276
  171. package/src/npm-installer.ts +0 -20
  172. package/src/pages.tsx +0 -1045
  173. package/src/tail.tsx +0 -73
  174. package/src/user.tsx +0 -1019
  175. package/static-asset-facade.js +0 -47
  176. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  177. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  178. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  179. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  180. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  181. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  182. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  183. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  184. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  185. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  186. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  187. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  188. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  189. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  190. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  191. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  192. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  193. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  194. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  195. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  196. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  197. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  198. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  199. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  200. package/vendor/wrangler-mime/LICENSE +0 -21
  201. package/vendor/wrangler-mime/Mime.js +0 -97
  202. package/vendor/wrangler-mime/README.md +0 -187
  203. package/vendor/wrangler-mime/cli.js +0 -46
  204. package/vendor/wrangler-mime/index.js +0 -4
  205. package/vendor/wrangler-mime/lite.js +0 -4
  206. package/vendor/wrangler-mime/package.json +0 -52
  207. package/vendor/wrangler-mime/types/other.js +0 -1
  208. package/vendor/wrangler-mime/types/standard.js +0 -1
  209. package/wrangler-dist/cli.js.map +0 -7
package/src/kv.tsx DELETED
@@ -1,276 +0,0 @@
1
- import { URLSearchParams } from "node:url";
2
- import { fetchListResult, fetchResult } from "./cfetch";
3
- import type { Config } from "./config";
4
-
5
- type KvArgs = {
6
- binding?: string;
7
- "namespace-id"?: string;
8
- env?: string;
9
- preview?: boolean;
10
- config?: Config;
11
- };
12
-
13
- /**
14
- * Create a new namespace under the given `accountId` with the given `title`.
15
- *
16
- * @returns the generated id of the created namespace.
17
- */
18
- export async function createNamespace(
19
- accountId: string,
20
- title: string
21
- ): Promise<string> {
22
- const response = await fetchResult<{ id: string }>(
23
- `/accounts/${accountId}/storage/kv/namespaces`,
24
- {
25
- method: "POST",
26
- headers: {
27
- "Content-Type": "application/json",
28
- },
29
- body: JSON.stringify({
30
- title,
31
- }),
32
- }
33
- );
34
-
35
- return response.id;
36
- }
37
-
38
- /**
39
- * The information about a namespace that is returned from `listNamespaces()`.
40
- */
41
- export interface KVNamespaceInfo {
42
- id: string;
43
- title: string;
44
- supports_url_encoding?: boolean;
45
- }
46
-
47
- /**
48
- * Fetch a list of all the namespaces under the given `accountId`.
49
- */
50
- export async function listNamespaces(
51
- accountId: string
52
- ): Promise<KVNamespaceInfo[]> {
53
- const pageSize = 100;
54
- let page = 1;
55
- const results: KVNamespaceInfo[] = [];
56
- while (results.length % pageSize === 0) {
57
- const json = await fetchResult<KVNamespaceInfo[]>(
58
- `/accounts/${accountId}/storage/kv/namespaces`,
59
- {},
60
- new URLSearchParams({
61
- per_page: pageSize.toString(),
62
- order: "title",
63
- direction: "asc",
64
- page: page.toString(),
65
- })
66
- );
67
- page++;
68
- results.push(...json);
69
- if (json.length < pageSize) {
70
- break;
71
- }
72
- }
73
- return results;
74
- }
75
-
76
- export interface NamespaceKeyInfo {
77
- name: string;
78
- expiration?: number;
79
- metadata?: { [key: string]: unknown };
80
- }
81
-
82
- export async function listNamespaceKeys(
83
- accountId: string,
84
- namespaceId: string,
85
- prefix = ""
86
- ) {
87
- return await fetchListResult<NamespaceKeyInfo>(
88
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/keys`,
89
- {},
90
- new URLSearchParams({ prefix })
91
- );
92
- }
93
-
94
- export async function putKeyValue(
95
- accountId: string,
96
- namespaceId: string,
97
- key: string,
98
- value: string,
99
- args?: { expiration?: number; expiration_ttl?: number }
100
- ) {
101
- let searchParams: URLSearchParams | undefined;
102
- if (args) {
103
- searchParams = new URLSearchParams();
104
- if (args.expiration) {
105
- searchParams.set("expiration", `${args.expiration}`);
106
- }
107
- if (args.expiration_ttl) {
108
- searchParams.set("expiration_ttl", `${args.expiration_ttl}`);
109
- }
110
- }
111
- return await fetchResult(
112
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${key}`,
113
- { method: "PUT", body: value },
114
- searchParams
115
- );
116
- }
117
-
118
- export async function putBulkKeyValue(
119
- accountId: string,
120
- namespaceId: string,
121
- keyvalueStr: string
122
- ) {
123
- return await fetchResult(
124
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/bulk`,
125
- {
126
- method: "PUT",
127
- body: keyvalueStr,
128
- headers: { "Content-Type": "application/json" },
129
- }
130
- );
131
- }
132
-
133
- export async function deleteBulkKeyValue(
134
- accountId: string,
135
- namespaceId: string,
136
- keyStr: string
137
- ) {
138
- return await fetchResult(
139
- `/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/bulk`,
140
- {
141
- method: "DELETE",
142
- body: keyStr,
143
- headers: { "Content-Type": "application/json" },
144
- }
145
- );
146
- }
147
-
148
- export function getNamespaceId({
149
- preview,
150
- binding,
151
- config,
152
- "namespace-id": namespaceId,
153
- env,
154
- }: KvArgs): string {
155
- // nice
156
- if (namespaceId) {
157
- return namespaceId;
158
- }
159
-
160
- // begin pre-flight checks
161
-
162
- // `--binding` is only valid if there's a wrangler configuration file.
163
- if (binding && !config) {
164
- throw new Error("--binding specified, but no config file was found.");
165
- }
166
-
167
- // there's no config. abort here
168
- if (!config) {
169
- throw new Error(
170
- "Failed to find a config file.\n" +
171
- "Either use --namespace-id to upload directly or create a configuration file with a binding."
172
- );
173
- }
174
-
175
- // they want to use an environment, actually
176
- if (env) {
177
- if (!config.env || !config.env[env]) {
178
- throw new Error(
179
- `Failed to find environment "${env}" in configuration file!`
180
- );
181
- }
182
-
183
- // TODO: either a bespoke arg type for this function to avoid `undefined`s or an `EnvOrConfig` type
184
- return getNamespaceId({
185
- binding,
186
- "namespace-id": namespaceId,
187
- env: undefined,
188
- preview,
189
- config: {
190
- env: undefined,
191
- build: undefined,
192
- name: undefined,
193
- account_id: undefined,
194
- ...config.env[env],
195
- },
196
- });
197
- }
198
-
199
- // there's no KV namespaces
200
- if (!config.kv_namespaces || config.kv_namespaces.length === 0) {
201
- throw new Error(
202
- "No KV Namespaces configured! Either use --namespace-id to upload directly or add a KV namespace to your wrangler config file."
203
- );
204
- }
205
-
206
- const namespace = config.kv_namespaces.find((ns) => ns.binding === binding);
207
-
208
- // we couldn't find a namespace with that binding
209
- if (!namespace) {
210
- throw new Error(
211
- `A namespace with binding name "${binding}" was not found in the configured "kv_namespaces".`
212
- );
213
- }
214
-
215
- // end pre-flight checks
216
-
217
- // we're in preview mode, `--preview true` or `--preview` was passed
218
- if (preview && namespace.preview_id) {
219
- namespaceId = namespace.preview_id;
220
- // We don't want to execute code below if preview is set to true, so we just return. Otherwise we will get errors!
221
- return namespaceId;
222
- } else if (preview) {
223
- throw new Error(
224
- `No preview ID found for ${binding}. Add one to your wrangler config file to use a separate namespace for previewing your worker.`
225
- );
226
- }
227
-
228
- // either `--preview false`, or preview wasn't passed
229
- // TODO: should we care? or should we just treat false and undefined the same
230
- const previewIsDefined = typeof preview !== "undefined";
231
-
232
- // --preview false was passed
233
- if (previewIsDefined && namespace.id) {
234
- namespaceId = namespace.id;
235
- // We don't want to execute code below if preview is set to true, so we just return. Otherwise we can get error!
236
- return namespaceId;
237
- } else if (previewIsDefined) {
238
- throw new Error(
239
- `No namespace ID found for ${binding}. Add one to your wrangler config file to use a separate namespace for previewing your worker.`
240
- );
241
- }
242
-
243
- // `--preview` wasn't passed
244
- const bindingHasOnlyOneId =
245
- (namespace.id && !namespace.preview_id) ||
246
- (!namespace.id && namespace.preview_id);
247
- if (bindingHasOnlyOneId) {
248
- namespaceId = namespace.id || namespace.preview_id;
249
- } else {
250
- throw new Error(
251
- `${binding} has both a namespace ID and a preview ID. Specify "--preview" or "--preview false" to avoid writing data to the wrong namespace.`
252
- );
253
- }
254
-
255
- // shouldn't happen. we should be able to prove this with strong typing.
256
- // TODO: when we add strongly typed commands, rewrite these checks so they're exhaustive
257
- if (!namespaceId) {
258
- throw Error(
259
- "Something went wrong trying to determine which namespace to upload to.\n" +
260
- "Please create a github issue with the command you just ran along with your wrangler configuration."
261
- );
262
- }
263
-
264
- return namespaceId;
265
- }
266
-
267
- /**
268
- * KV namespace binding names must be valid JS identifiers.
269
- */
270
- export function isValidNamespaceBinding(
271
- binding: string | undefined
272
- ): binding is string {
273
- return (
274
- typeof binding === "string" && /^[a-zA-Z_][a-zA-Z0-9_]*$/.test(binding)
275
- );
276
- }
@@ -1,20 +0,0 @@
1
- import { execa } from "execa";
2
-
3
- /**
4
- * Helpers for running npm commands
5
- */
6
- export const npm = {
7
- /** Add and install a new devDependency into the local package.json. */
8
- async addDevDeps(...packages: string[]): Promise<void> {
9
- await execa("npm", ["install", ...packages, "--save-dev"], {
10
- stdio: "inherit",
11
- });
12
- },
13
-
14
- /** Install all the dependencies in the local package.json. */
15
- async install(): Promise<void> {
16
- await execa("npm", ["install"], {
17
- stdio: "inherit",
18
- });
19
- },
20
- };