wrangler 0.0.0-e22f9d7 → 0.0.0-e2b7352

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 (100) hide show
  1. package/README.md +3 -3
  2. package/bin/wrangler.js +12 -3
  3. package/miniflare-dist/index.mjs +79 -0
  4. package/miniflare-dist/index.mjs.map +7 -0
  5. package/package.json +33 -16
  6. package/pages/functions/buildWorker.ts +1 -1
  7. package/pages/functions/filepath-routing.test.ts +212 -28
  8. package/pages/functions/filepath-routing.ts +91 -131
  9. package/pages/functions/routes.ts +11 -18
  10. package/pages/functions/template-worker.ts +19 -33
  11. package/src/__tests__/configuration.test.ts +2820 -0
  12. package/src/__tests__/dev.test.tsx +535 -61
  13. package/src/__tests__/guess-worker-format.test.ts +68 -0
  14. package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
  15. package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
  16. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  17. package/src/__tests__/helpers/mock-account-id.ts +48 -0
  18. package/src/__tests__/helpers/mock-bin.ts +36 -0
  19. package/src/__tests__/{mock-cfetch.ts → helpers/mock-cfetch.ts} +52 -16
  20. package/src/__tests__/helpers/mock-console.ts +70 -0
  21. package/src/__tests__/{mock-dialogs.ts → helpers/mock-dialogs.ts} +1 -1
  22. package/src/__tests__/helpers/mock-kv.ts +33 -0
  23. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  24. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  25. package/src/__tests__/helpers/run-in-tmp.ts +32 -0
  26. package/src/__tests__/helpers/run-wrangler.ts +16 -0
  27. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  28. package/src/__tests__/https-options.test.ts +127 -0
  29. package/src/__tests__/index.test.ts +773 -77
  30. package/src/__tests__/jest.setup.ts +53 -6
  31. package/src/__tests__/kv.test.ts +725 -456
  32. package/src/__tests__/logout.test.ts +52 -0
  33. package/src/__tests__/package-manager.test.ts +206 -0
  34. package/src/__tests__/pages.test.ts +82 -0
  35. package/src/__tests__/parse.test.ts +322 -0
  36. package/src/__tests__/publish.test.ts +3509 -0
  37. package/src/__tests__/r2.test.ts +198 -0
  38. package/src/__tests__/route.test.ts +45 -0
  39. package/src/__tests__/secret.test.ts +425 -0
  40. package/src/__tests__/sentry.test.ts +146 -0
  41. package/src/__tests__/tail.test.ts +638 -0
  42. package/src/__tests__/whoami.test.tsx +100 -0
  43. package/src/bundle.ts +155 -0
  44. package/src/cfetch/index.ts +21 -19
  45. package/src/cfetch/internal.ts +92 -22
  46. package/src/cli.ts +10 -0
  47. package/src/config/README.md +107 -0
  48. package/src/config/config.ts +218 -0
  49. package/src/config/diagnostics.ts +80 -0
  50. package/src/config/environment.ts +371 -0
  51. package/src/config/index.ts +62 -0
  52. package/src/config/validation-helpers.ts +554 -0
  53. package/src/config/validation.ts +1232 -0
  54. package/src/{api/preview.ts → create-worker-preview.ts} +61 -23
  55. package/src/create-worker-upload-form.ts +217 -0
  56. package/src/dev/dev.tsx +392 -0
  57. package/src/dev/local.tsx +232 -0
  58. package/src/dev/remote.tsx +203 -0
  59. package/src/dev/use-esbuild.ts +104 -0
  60. package/src/dialogs.tsx +2 -2
  61. package/src/entry.ts +240 -0
  62. package/src/environment-variables.ts +33 -0
  63. package/src/https-options.ts +122 -0
  64. package/src/index.tsx +1218 -803
  65. package/src/inspect.ts +103 -25
  66. package/src/intl-polyfill.d.ts +139 -0
  67. package/src/{kv.tsx → kv.ts} +104 -61
  68. package/src/miniflare-cli/README.md +30 -0
  69. package/src/miniflare-cli/enum-keys.ts +17 -0
  70. package/src/miniflare-cli/index.ts +37 -0
  71. package/src/module-collection.ts +229 -35
  72. package/src/open-in-browser.ts +25 -0
  73. package/src/package-manager.ts +126 -0
  74. package/src/pages.tsx +74 -44
  75. package/src/parse.ts +183 -0
  76. package/src/paths.ts +26 -0
  77. package/src/proxy.ts +177 -39
  78. package/src/publish.ts +286 -300
  79. package/src/r2.ts +50 -0
  80. package/src/reporting.ts +131 -0
  81. package/src/selfsigned.d.ts +29 -0
  82. package/src/sites.tsx +224 -62
  83. package/src/tail/filters.ts +279 -0
  84. package/src/tail/index.ts +299 -0
  85. package/src/tail/printing.ts +62 -0
  86. package/src/user.tsx +278 -178
  87. package/src/whoami.tsx +69 -0
  88. package/src/{api/worker.ts → worker.ts} +45 -37
  89. package/templates/new-worker.js +15 -0
  90. package/templates/new-worker.ts +15 -0
  91. package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
  92. package/templates/tsconfig.json +105 -0
  93. package/wrangler-dist/cli.js +130377 -112126
  94. package/wrangler-dist/cli.js.map +3 -3
  95. package/src/__tests__/run-in-tmp.ts +0 -19
  96. package/src/__tests__/run-wrangler.ts +0 -32
  97. package/src/api/form_data.ts +0 -131
  98. package/src/config.ts +0 -487
  99. package/src/dev.tsx +0 -784
  100. package/src/tail.tsx +0 -73
@@ -0,0 +1,146 @@
1
+ import * as fs from "node:fs";
2
+ import * as fsp from "node:fs/promises";
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import * as TOML from "@iarna/toml";
6
+ import * as Sentry from "@sentry/node";
7
+ import prompts from "prompts";
8
+
9
+ import { mockConsoleMethods } from "./helpers/mock-console";
10
+ import { runInTempDir } from "./helpers/run-in-tmp";
11
+ import { runWrangler } from "./helpers/run-wrangler";
12
+ const { reportError } = jest.requireActual("../reporting");
13
+
14
+ describe("Error Reporting", () => {
15
+ runInTempDir({ homedir: "./home" });
16
+ mockConsoleMethods();
17
+ const reportingTOMLPath = ".wrangler/config/reporting.toml";
18
+
19
+ const originalTTY = process.stdout.isTTY;
20
+ beforeEach(() => {
21
+ jest.mock("@sentry/node");
22
+ jest.spyOn(Sentry, "captureException");
23
+ process.stdout.isTTY = true;
24
+ });
25
+
26
+ afterEach(() => {
27
+ jest.unmock("@sentry/node");
28
+ jest.clearAllMocks();
29
+ process.stdout.isTTY = originalTTY;
30
+ });
31
+
32
+ it("should confirm user will allow error reporting usage", async () => {
33
+ jest.spyOn(prompts, "prompt").mockResolvedValue({ sentryDecision: true });
34
+
35
+ await reportError(new Error("test error"), "testFalse");
36
+
37
+ const { error_tracking_opt, error_tracking_opt_date } = TOML.parse(
38
+ await fsp.readFile(path.join(os.homedir(), reportingTOMLPath), "utf-8")
39
+ );
40
+
41
+ expect(error_tracking_opt).toBe(true);
42
+ expect(error_tracking_opt_date).toBeTruthy();
43
+
44
+ expect(Sentry.captureException).toHaveBeenCalledWith(
45
+ new Error("test error")
46
+ );
47
+ });
48
+
49
+ it("should confirm user will disallow error reporting usage", async () => {
50
+ jest.spyOn(prompts, "prompt").mockResolvedValue({ sentryDecision: false });
51
+ await reportError(new Error("test error"), "testFalse");
52
+
53
+ const { error_tracking_opt, error_tracking_opt_date } = TOML.parse(
54
+ await fsp.readFile(path.join(os.homedir(), reportingTOMLPath), "utf-8")
55
+ );
56
+
57
+ expect(error_tracking_opt).toBe(false);
58
+ expect(error_tracking_opt_date).toBeTruthy();
59
+
60
+ expect(Sentry.captureException).not.toHaveBeenCalledWith(
61
+ new Error("test error"),
62
+ "testFalse"
63
+ );
64
+ });
65
+
66
+ it("should confirm user will allow 'once' error reporting usage", async () => {
67
+ jest.spyOn(prompts, "prompt").mockResolvedValue({ sentryDecision: "once" });
68
+ await runWrangler();
69
+ await reportError(new Error("test error"), "testFalse");
70
+
71
+ expect(fs.existsSync(path.join(os.homedir(), reportingTOMLPath))).toBe(
72
+ false
73
+ );
74
+
75
+ expect(Sentry.captureException).not.toHaveBeenCalledWith(
76
+ new Error("test error"),
77
+ "testFalse"
78
+ );
79
+ });
80
+
81
+ it("should not prompt w/ subsequent Errors after user disallows error reporting", async () => {
82
+ jest.spyOn(prompts, "prompt").mockResolvedValue({ sentryDecision: false });
83
+ await reportError(new Error("test error"), "testFalse");
84
+
85
+ expect(Sentry.captureException).not.toHaveBeenCalledWith(
86
+ new Error("test error"),
87
+ "testFalse"
88
+ );
89
+
90
+ await reportError(new Error("second test error"), "testFalse");
91
+ expect(Sentry.captureException).not.toHaveBeenCalledWith(
92
+ new Error("second test error"),
93
+ "testFalse"
94
+ );
95
+ });
96
+
97
+ it("should not prompt w/ subsequent Errors after user Always allows error reporting", async () => {
98
+ jest.spyOn(prompts, "prompt").mockResolvedValue({ sentryDecision: true });
99
+ await reportError(new Error("test error"), "testFalse");
100
+
101
+ expect(Sentry.captureException).toHaveBeenCalledWith(
102
+ new Error("test error")
103
+ );
104
+
105
+ await reportError(new Error("second test error"), "testFalse");
106
+ expect(Sentry.captureException).toHaveBeenCalledWith(
107
+ new Error("second test error")
108
+ );
109
+ });
110
+
111
+ it("should prompt w/ subsequent Errors after user allows error reporting once", async () => {
112
+ const promptSpy = jest
113
+ .spyOn(prompts, "prompt")
114
+ .mockResolvedValue({ sentryDecision: "once" });
115
+ await reportError(new Error("test error"), "testFalse");
116
+
117
+ expect(Sentry.captureException).toHaveBeenCalledWith(
118
+ new Error("test error")
119
+ );
120
+
121
+ await reportError(new Error("second test error"), "testFalse");
122
+ expect(Sentry.captureException).toHaveBeenCalledWith(
123
+ new Error("second test error")
124
+ );
125
+
126
+ expect(promptSpy).toBeCalledTimes(2);
127
+ });
128
+
129
+ it("should not prompt in non-TTY environment", async () => {
130
+ process.stdout.isTTY = false;
131
+
132
+ await reportError(new Error("test error"), "testFalse");
133
+
134
+ const { error_tracking_opt, error_tracking_opt_date } = TOML.parse(
135
+ await fsp.readFile(path.join(os.homedir(), reportingTOMLPath), "utf-8")
136
+ );
137
+
138
+ expect(error_tracking_opt).toBe(false);
139
+ expect(error_tracking_opt_date).toBeTruthy();
140
+
141
+ expect(Sentry.captureException).not.toHaveBeenCalledWith(
142
+ new Error("test error")
143
+ );
144
+ process.stdout.isTTY = originalTTY;
145
+ });
146
+ });