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
package/src/publish.ts DELETED
@@ -1,363 +0,0 @@
1
- import assert from "node:assert";
2
- import { readFileSync } from "node:fs";
3
- import path from "node:path";
4
- import { URLSearchParams } from "node:url";
5
- import { execaCommand } from "execa";
6
- import tmp from "tmp-promise";
7
- import { toFormData } from "./api/form_data";
8
- import { bundleWorker } from "./bundle";
9
- import { fetchResult } from "./cfetch";
10
- import { fileExists } from "./entry";
11
- import guessWorkerFormat from "./guess-worker-format";
12
- import { syncAssets } from "./sites";
13
- import type { CfScriptFormat, CfWorkerInit } from "./api/worker";
14
- import type { Config } from "./config";
15
- import type { AssetPaths } from "./sites";
16
-
17
- type Props = {
18
- config: Config;
19
- accountId: string;
20
- format: CfScriptFormat | undefined;
21
- entry: { file: string; directory: string };
22
- rules: Config["rules"];
23
- name: string | undefined;
24
- env: string | undefined;
25
- compatibilityDate: string | undefined;
26
- compatibilityFlags: string[] | undefined;
27
- assetPaths: AssetPaths | undefined;
28
- triggers: (string | number)[] | undefined;
29
- routes: (string | number)[] | undefined;
30
- legacyEnv: boolean | undefined;
31
- jsxFactory: undefined | string;
32
- jsxFragment: undefined | string;
33
- experimentalPublic: boolean;
34
- };
35
-
36
- function sleep(ms: number) {
37
- return new Promise((resolve) => setTimeout(resolve, ms));
38
- }
39
-
40
- export default async function publish(props: Props): Promise<void> {
41
- // TODO: warn if git/hg has uncommitted changes
42
- const { config, accountId } = props;
43
-
44
- // TODO: should we automatically fallback to top level config if there is no matching environment??
45
- const envRootObj = (props.env && config.env[props.env]) || config;
46
-
47
- assert(
48
- envRootObj.compatibility_date || props.compatibilityDate,
49
- "A compatibility_date is required when publishing. Add one to your wrangler.toml file, or pass it in your terminal as --compatibility_date. See https://developers.cloudflare.com/workers/platform/compatibility-dates for more information."
50
- );
51
-
52
- const triggers = props.triggers || envRootObj.triggers?.crons;
53
- const routes =
54
- props.routes ??
55
- envRootObj.routes ??
56
- (envRootObj.route ? [envRootObj.route] : []) ??
57
- [];
58
-
59
- const { workers_dev: deployToWorkersDev } = config;
60
-
61
- const jsxFactory = props.jsxFactory || envRootObj.jsx_factory;
62
- const jsxFragment = props.jsxFragment || envRootObj.jsx_fragment;
63
-
64
- const scriptName = props.name;
65
- assert(
66
- scriptName,
67
- 'You need to provide a name when publishing a worker. Either pass it as a cli arg with `--name <name>` or in your config file as `name = "<name>"`'
68
- );
69
-
70
- if (config.site?.["entry-point"]) {
71
- console.warn(
72
- "Deprecation notice: The `site.entry-point` config field is no longer used.\n" +
73
- "The entry-point should be specified via the command line (e.g. `wrangler publish path/to/script`) or the `main` config field.\n" +
74
- "Please remove the `site.entry-point` field from the `wrangler.toml` file."
75
- );
76
- }
77
-
78
- assert(
79
- !config.site || config.site.bucket,
80
- "A [site] definition requires a `bucket` field with a path to the site's public directory."
81
- );
82
-
83
- const destination = await tmp.dir({ unsafeCleanup: true });
84
- try {
85
- const envName = props.env ?? "production";
86
-
87
- if (config.build.command) {
88
- // TODO: add a deprecation message here?
89
- console.log("running:", config.build.command);
90
- await execaCommand(config.build.command, {
91
- shell: true,
92
- stdout: "inherit",
93
- stderr: "inherit",
94
- timeout: 1000 * 30,
95
- ...(config.build.cwd && { cwd: config.build.cwd }),
96
- });
97
-
98
- if (fileExists(props.entry.file) === false) {
99
- throw new Error(
100
- `Could not resolve "${path.relative(
101
- process.cwd(),
102
- props.entry.file
103
- )}".`
104
- );
105
- }
106
- }
107
-
108
- const format = await guessWorkerFormat(props.entry, props.format);
109
-
110
- if (props.experimentalPublic && format === "service-worker") {
111
- // TODO: check config too
112
- throw new Error(
113
- "You cannot publish in the service worker format with a public directory."
114
- );
115
- }
116
-
117
- if (config.wasm_modules && format === "modules") {
118
- throw new Error(
119
- "You cannot configure [wasm_modules] with an ES module worker. Instead, import the .wasm module directly in your code"
120
- );
121
- }
122
-
123
- if (config.text_blobs && format === "modules") {
124
- throw new Error(
125
- "You cannot configure [text_blobs] with an ES module worker. Instead, import the file directly in your code, and optionally configure `[build.upload.rules]` in your wrangler.toml"
126
- );
127
- }
128
-
129
- const { modules, resolvedEntryPointPath, bundleType } = await bundleWorker(
130
- props.entry,
131
- destination.path,
132
- {
133
- serveAssetsFromWorker: props.experimentalPublic,
134
- jsxFactory,
135
- jsxFragment,
136
- format,
137
- rules: props.rules,
138
- }
139
- );
140
-
141
- const content = readFileSync(resolvedEntryPointPath, {
142
- encoding: "utf-8",
143
- });
144
-
145
- // if config.migrations
146
- // get current migration tag
147
- let migrations;
148
- if (config.migrations.length > 0) {
149
- const scripts = await fetchResult<
150
- { id: string; migration_tag: string }[]
151
- >(`/accounts/${accountId}/workers/scripts`);
152
- const script = scripts.find(({ id }) => id === scriptName);
153
- if (script?.migration_tag) {
154
- // was already published once
155
- const foundIndex = config.migrations.findIndex(
156
- (migration) => migration.tag === script.migration_tag
157
- );
158
- if (foundIndex === -1) {
159
- console.warn(
160
- `The published script ${scriptName} has a migration tag "${script.migration_tag}, which was not found in wrangler.toml. You may have already deleted it. Applying all available migrations to the script...`
161
- );
162
- migrations = {
163
- old_tag: script.migration_tag,
164
- new_tag: config.migrations[config.migrations.length - 1].tag,
165
- steps: config.migrations.map(({ tag: _tag, ...rest }) => rest),
166
- };
167
- } else {
168
- migrations = {
169
- old_tag: script.migration_tag,
170
- new_tag: config.migrations[config.migrations.length - 1].tag,
171
- steps: config.migrations
172
- .slice(foundIndex + 1)
173
- .map(({ tag: _tag, ...rest }) => rest),
174
- };
175
- }
176
- } else {
177
- migrations = {
178
- new_tag: config.migrations[config.migrations.length - 1].tag,
179
- steps: config.migrations.map(({ tag: _tag, ...rest }) => rest),
180
- };
181
- }
182
- }
183
-
184
- const assets = await syncAssets(
185
- accountId,
186
- // When we're using the newer service environments, we wouldn't
187
- // have added the env name on to the script name. However, we must
188
- // include it in the kv namespace name regardless (since there's no
189
- // concept of service environments for kv namespaces yet).
190
- scriptName + (!props.legacyEnv && props.env ? `-${props.env}` : ""),
191
- props.assetPaths,
192
- false
193
- );
194
-
195
- const bindings: CfWorkerInit["bindings"] = {
196
- kv_namespaces: (envRootObj.kv_namespaces || []).concat(
197
- assets.namespace
198
- ? { binding: "__STATIC_CONTENT", id: assets.namespace }
199
- : []
200
- ),
201
- vars: envRootObj.vars,
202
- wasm_modules: config.wasm_modules,
203
- text_blobs: {
204
- ...config.text_blobs,
205
- ...(assets.manifest &&
206
- format === "service-worker" && {
207
- __STATIC_CONTENT_MANIFEST: "__STATIC_CONTENT_MANIFEST",
208
- }),
209
- },
210
- durable_objects: envRootObj.durable_objects,
211
- r2_buckets: envRootObj.r2_buckets,
212
- unsafe: envRootObj.unsafe?.bindings,
213
- };
214
-
215
- if (assets.manifest) {
216
- modules.push({
217
- name: "__STATIC_CONTENT_MANIFEST",
218
- content: JSON.stringify(assets.manifest),
219
- type: "text",
220
- });
221
- }
222
-
223
- const worker: CfWorkerInit = {
224
- name: scriptName,
225
- main: {
226
- name: path.basename(resolvedEntryPointPath),
227
- content: content,
228
- type: bundleType,
229
- },
230
- bindings,
231
- migrations,
232
- modules,
233
- compatibility_date: config.compatibility_date,
234
- compatibility_flags: config.compatibility_flags,
235
- usage_model: config.usage_model,
236
- };
237
-
238
- const start = Date.now();
239
- const notProd = !props.legacyEnv && props.env;
240
- const workerName = notProd ? `${scriptName} (${envName})` : scriptName;
241
- const workerUrl = notProd
242
- ? `/accounts/${accountId}/workers/services/${scriptName}/environments/${envName}`
243
- : `/accounts/${accountId}/workers/scripts/${scriptName}`;
244
-
245
- // Upload the script so it has time to propagate.
246
- const { available_on_subdomain } = await fetchResult(
247
- workerUrl,
248
- {
249
- method: "PUT",
250
- body: toFormData(worker),
251
- },
252
- new URLSearchParams({ available_on_subdomain: "true" })
253
- );
254
-
255
- const uploadMs = Date.now() - start;
256
- console.log("Uploaded", workerName, formatTime(uploadMs));
257
- const deployments: Promise<string[]>[] = [];
258
-
259
- if (deployToWorkersDev) {
260
- // Deploy to a subdomain of `workers.dev`
261
- const userSubdomain = (
262
- await fetchResult<{ subdomain: string }>(
263
- `/accounts/${accountId}/workers/subdomain`
264
- )
265
- ).subdomain;
266
- const scriptURL =
267
- props.legacyEnv || !props.env
268
- ? `${scriptName}.${userSubdomain}.workers.dev`
269
- : `${envName}.${scriptName}.${userSubdomain}.workers.dev`;
270
- if (!available_on_subdomain) {
271
- // Enable the `workers.dev` subdomain.
272
- deployments.push(
273
- fetchResult(`${workerUrl}/subdomain`, {
274
- method: "POST",
275
- body: JSON.stringify({ enabled: true }),
276
- headers: {
277
- "Content-Type": "application/json",
278
- },
279
- })
280
- .then(() => [scriptURL])
281
- // Add a delay when the subdomain is first created.
282
- // This is to prevent an issue where a negative cache-hit
283
- // causes the subdomain to be unavailable for 30 seconds.
284
- // This is a temporary measure until we fix this on the edge.
285
- .then(async (url) => {
286
- await sleep(3000);
287
- return url;
288
- })
289
- );
290
- } else {
291
- deployments.push(Promise.resolve([scriptURL]));
292
- }
293
- } else {
294
- // Disable the workers.dev deployment
295
- await fetchResult(`${workerUrl}/subdomain`, {
296
- method: "POST",
297
- body: JSON.stringify({ enabled: false }),
298
- headers: {
299
- "Content-Type": "application/json",
300
- },
301
- });
302
- }
303
-
304
- // Update routing table for the script.
305
- if (routes.length > 0) {
306
- deployments.push(
307
- fetchResult(`${workerUrl}/routes`, {
308
- // TODO: PATCH will not delete previous routes on this script,
309
- // whereas PUT will. We need to decide on the default behaviour
310
- // and how to configure it.
311
- method: "PUT",
312
- body: JSON.stringify(routes.map((pattern) => ({ pattern }))),
313
- headers: {
314
- "Content-Type": "application/json",
315
- },
316
- }).then(() => {
317
- if (routes.length > 10) {
318
- return routes
319
- .slice(0, 9)
320
- .map(String)
321
- .concat([`...and ${routes.length - 10} more routes`]);
322
- }
323
- return routes.map(String);
324
- })
325
- );
326
- }
327
-
328
- // Configure any schedules for the script.
329
- // TODO: rename this to `schedules`?
330
- if (triggers && triggers.length) {
331
- deployments.push(
332
- fetchResult(`${workerUrl}/schedules`, {
333
- // TODO: Unlike routes, this endpoint does not support PATCH.
334
- // So technically, this will override any previous schedules.
335
- // We should change the endpoint to support PATCH.
336
- method: "PUT",
337
- body: JSON.stringify(triggers.map((cron) => ({ cron }))),
338
- headers: {
339
- "Content-Type": "application/json",
340
- },
341
- }).then(() => triggers.map(String))
342
- );
343
- }
344
-
345
- const targets = await Promise.all(deployments);
346
- const deployMs = Date.now() - start - uploadMs;
347
-
348
- if (deployments.length > 0) {
349
- console.log("Published", workerName, formatTime(deployMs));
350
- for (const target of targets.flat()) {
351
- console.log(" ", target);
352
- }
353
- } else {
354
- console.log("No publish targets for", workerName, formatTime(deployMs));
355
- }
356
- } finally {
357
- await destination.cleanup();
358
- }
359
- }
360
-
361
- function formatTime(duration: number) {
362
- return `(${(duration / 1000).toFixed(2)} sec)`;
363
- }
package/src/r2.ts DELETED
@@ -1,50 +0,0 @@
1
- import { fetchResult } from "./cfetch";
2
-
3
- /**
4
- * Information about a bucket, returned from `listR2Buckets()`.
5
- */
6
- export interface R2BucketInfo {
7
- name: string;
8
- creation_date: string;
9
- }
10
-
11
- /**
12
- * Fetch a list of all the buckets under the given `accountId`.
13
- */
14
- export async function listR2Buckets(
15
- accountId: string
16
- ): Promise<R2BucketInfo[]> {
17
- const results = await fetchResult<{
18
- buckets: R2BucketInfo[];
19
- }>(`/accounts/${accountId}/r2/buckets`);
20
- return results.buckets;
21
- }
22
-
23
- /**
24
- * Create a bucket with the given `bucketName` within the account given by `accountId`.
25
- *
26
- * A 400 is returned if the account already owns a bucket with this name.
27
- * A bucket must be explicitly deleted to be replaced.
28
- */
29
- export async function createR2Bucket(
30
- accountId: string,
31
- bucketName: string
32
- ): Promise<void> {
33
- return await fetchResult<void>(
34
- `/accounts/${accountId}/r2/buckets/${bucketName}`,
35
- { method: "PUT" }
36
- );
37
- }
38
-
39
- /**
40
- * Delete a bucket with the given name
41
- */
42
- export async function deleteR2Bucket(
43
- accountId: string,
44
- bucketName: string
45
- ): Promise<void> {
46
- return await fetchResult<void>(
47
- `/accounts/${accountId}/r2/buckets/${bucketName}`,
48
- { method: "DELETE" }
49
- );
50
- }
package/src/reporting.ts DELETED
@@ -1,115 +0,0 @@
1
- import { appendFile, readFile } from "fs/promises";
2
- import * as fs from "node:fs";
3
- import os from "node:os";
4
- import path from "path/posix";
5
- import TOML from "@iarna/toml";
6
- import { RewriteFrames } from "@sentry/integrations";
7
- import {
8
- captureException,
9
- getCurrentHub,
10
- startTransaction,
11
- init,
12
- Integrations,
13
- setContext,
14
- } from "@sentry/node";
15
- import { execaSync } from "execa";
16
- import prompts from "prompts";
17
- import * as pkj from "../package.json";
18
-
19
- export function initReporting() {
20
- init({
21
- release: `${pkj.name}@${pkj.version}`,
22
- initialScope: {
23
- tags: { [pkj.name]: pkj.version },
24
- },
25
- dsn: "https://5089b76bf8a64a9c949bf5c2b5e8003c@o51786.ingest.sentry.io/6190959",
26
- tracesSampleRate: 1.0,
27
- integrations: [
28
- new RewriteFrames({
29
- root: "",
30
- prefix: "/",
31
- }),
32
- new Integrations.Http({ tracing: true }),
33
- ],
34
- });
35
-
36
- setContext("System Information", {
37
- OS: process.platform,
38
- node: process.version,
39
- npm: execaSync("npm", ["--version"]).stdout,
40
- wrangler: pkj.version,
41
- });
42
- }
43
-
44
- async function appendReportingDecision(userInput: "true" | "false") {
45
- const homePath = path.join(os.homedir(), ".wrangler/config/");
46
- fs.mkdirSync(homePath, { recursive: true });
47
- await appendFile(
48
- path.join(homePath, "reporting.toml"),
49
- `error_tracking_opt = ${userInput} # Sentry \nerror_tracking_opt_date = ${new Date().toISOString()} # Sentry Date Decision \n`,
50
- { encoding: "utf-8" }
51
- );
52
- }
53
-
54
- function exceptionTransaction(error: Error, origin = "") {
55
- const transaction = startTransaction({
56
- op: origin,
57
- name: error.name,
58
- });
59
- captureException(error);
60
- transaction.finish();
61
- }
62
-
63
- export async function reportError(err: Error, origin = "") {
64
- if (!process.stdout.isTTY) return await appendReportingDecision("false");
65
-
66
- const errorTrackingOpt = await reportingPermission();
67
-
68
- if (errorTrackingOpt === undefined) {
69
- const userInput = await prompts.prompt({
70
- type: "select",
71
- name: "sentryDecision",
72
- message: "Would you like to submit a report when an error occurs?",
73
- choices: [
74
- { title: "Always", value: true },
75
- { title: "Yes", value: "once" },
76
- { title: "No", value: false },
77
- ],
78
- initial: 2,
79
- });
80
-
81
- if (userInput.sentryDecision === "once") {
82
- exceptionTransaction(err, origin);
83
- return;
84
- }
85
-
86
- userInput.sentryDecision
87
- ? await appendReportingDecision("true")
88
- : await appendReportingDecision("false");
89
- }
90
-
91
- if (!errorTrackingOpt) {
92
- const sentryClient = getCurrentHub().getClient();
93
- if (sentryClient !== undefined) sentryClient.getOptions().enabled = false;
94
- }
95
-
96
- exceptionTransaction(err, origin);
97
- }
98
-
99
- async function reportingPermission() {
100
- if (
101
- !fs.existsSync(path.join(os.homedir(), ".wrangler/config/reporting.toml"))
102
- )
103
- return undefined;
104
-
105
- const reportingTOML = TOML.parse(
106
- await readFile(path.join(os.homedir(), ".wrangler/config/reporting.toml"), {
107
- encoding: "utf-8",
108
- })
109
- );
110
- const { error_tracking_opt } = reportingTOML as {
111
- error_tracking_opt: string | undefined;
112
- };
113
-
114
- return error_tracking_opt;
115
- }