wrangler 0.0.0-e3cab74 → 0.0.0-e3ce82b

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 (139) hide show
  1. package/Cloudflare_CA.pem +18 -0
  2. package/README.md +27 -14
  3. package/bin/wrangler.js +49 -5
  4. package/miniflare-dist/index.mjs +4886 -0
  5. package/package.json +43 -28
  6. package/pages/functions/buildPlugin.ts +105 -0
  7. package/pages/functions/buildWorker.ts +93 -4
  8. package/pages/functions/filepath-routing.test.ts +136 -25
  9. package/pages/functions/filepath-routing.ts +14 -3
  10. package/pages/functions/routes.ts +6 -1
  11. package/pages/functions/template-plugin.ts +147 -0
  12. package/pages/functions/template-worker.ts +21 -8
  13. package/src/__tests__/config-cache.test.ts +36 -0
  14. package/src/__tests__/configuration.test.ts +1713 -411
  15. package/src/__tests__/dev.test.tsx +954 -84
  16. package/src/__tests__/guess-worker-format.test.ts +37 -18
  17. package/src/__tests__/helpers/mock-account-id.ts +22 -4
  18. package/src/__tests__/helpers/mock-cfetch.ts +8 -4
  19. package/src/__tests__/helpers/mock-console.ts +35 -10
  20. package/src/__tests__/helpers/mock-dialogs.ts +67 -2
  21. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  22. package/src/__tests__/helpers/mock-istty.ts +27 -0
  23. package/src/__tests__/helpers/mock-kv.ts +9 -16
  24. package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
  25. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  26. package/src/__tests__/helpers/run-in-tmp.ts +10 -0
  27. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  28. package/src/__tests__/https-options.test.ts +130 -0
  29. package/src/__tests__/index.test.ts +138 -747
  30. package/src/__tests__/init.test.ts +1637 -0
  31. package/src/__tests__/jest.setup.ts +28 -8
  32. package/src/__tests__/kv.test.ts +598 -258
  33. package/src/__tests__/logger.test.ts +115 -0
  34. package/src/__tests__/package-manager.test.ts +154 -7
  35. package/src/__tests__/pages.test.ts +754 -0
  36. package/src/__tests__/parse.test.ts +8 -0
  37. package/src/__tests__/publish.test.ts +4374 -1025
  38. package/src/__tests__/r2.test.ts +69 -34
  39. package/src/__tests__/route.test.ts +45 -0
  40. package/src/__tests__/secret.test.ts +228 -73
  41. package/src/__tests__/tail.test.ts +146 -20
  42. package/src/__tests__/user.test.ts +131 -0
  43. package/src/__tests__/whoami.test.tsx +60 -7
  44. package/src/abort.d.ts +3 -0
  45. package/src/bundle.ts +75 -11
  46. package/src/cfetch/index.ts +21 -4
  47. package/src/cfetch/internal.ts +29 -20
  48. package/src/cli.ts +5 -11
  49. package/src/config/README.md +7 -7
  50. package/src/config/config.ts +69 -100
  51. package/src/config/environment.ts +119 -4
  52. package/src/config/index.ts +177 -4
  53. package/src/config/validation-helpers.ts +237 -23
  54. package/src/config/validation.ts +722 -191
  55. package/src/config-cache.ts +45 -0
  56. package/src/{api/preview.ts → create-worker-preview.ts} +65 -27
  57. package/src/{api/form_data.ts → create-worker-upload-form.ts} +55 -18
  58. package/src/dev/dev-vars.ts +36 -0
  59. package/src/dev/dev.tsx +401 -0
  60. package/src/dev/local.tsx +322 -0
  61. package/src/dev/remote.tsx +237 -0
  62. package/src/dev/use-esbuild.ts +118 -0
  63. package/src/dialogs.tsx +64 -6
  64. package/src/durable.ts +102 -0
  65. package/src/entry.ts +279 -14
  66. package/src/environment-variables.ts +3 -1
  67. package/src/errors.ts +11 -0
  68. package/src/https-options.ts +123 -0
  69. package/src/index.tsx +1386 -867
  70. package/src/inspect.ts +64 -11
  71. package/src/intl-polyfill.d.ts +139 -0
  72. package/src/{kv.tsx → kv.ts} +195 -62
  73. package/src/logger.ts +66 -0
  74. package/src/miniflare-cli/README.md +30 -0
  75. package/src/miniflare-cli/enum-keys.ts +17 -0
  76. package/src/miniflare-cli/index.ts +41 -0
  77. package/src/miniflare-cli/request-context.ts +40 -0
  78. package/src/module-collection.ts +94 -6
  79. package/src/open-in-browser.ts +9 -3
  80. package/src/package-manager.ts +59 -11
  81. package/src/pages.tsx +1123 -75
  82. package/src/parse.ts +26 -6
  83. package/src/proxy.ts +159 -57
  84. package/src/publish.ts +581 -228
  85. package/src/selfsigned.d.ts +29 -0
  86. package/src/sites.tsx +130 -45
  87. package/src/tail/index.ts +2 -2
  88. package/src/tail/printing.ts +13 -8
  89. package/src/update-check.ts +19 -0
  90. package/src/user.tsx +275 -110
  91. package/src/whoami.tsx +5 -3
  92. package/src/{api/worker.ts → worker.ts} +24 -29
  93. package/src/zones.ts +73 -0
  94. package/templates/gitignore +171 -0
  95. package/templates/new-worker-scheduled.js +17 -0
  96. package/templates/new-worker-scheduled.ts +32 -0
  97. package/templates/new-worker.ts +16 -1
  98. package/templates/static-asset-facade.js +1 -5
  99. package/wrangler-dist/cli.js +104803 -118375
  100. package/src/__tests__/helpers/mock-user.ts +0 -27
  101. package/src/__tests__/logout.test.ts +0 -50
  102. package/src/__tests__/sentry.test.ts +0 -146
  103. package/src/dev.tsx +0 -961
  104. package/src/guess-worker-format.ts +0 -68
  105. package/src/reporting.ts +0 -115
  106. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  107. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  108. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  109. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  110. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  111. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  112. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  113. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  114. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  115. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  116. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  117. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  118. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  119. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  120. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  121. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  122. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  123. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  124. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  125. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  126. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  127. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  128. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  129. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  130. package/vendor/wrangler-mime/LICENSE +0 -21
  131. package/vendor/wrangler-mime/Mime.js +0 -97
  132. package/vendor/wrangler-mime/README.md +0 -187
  133. package/vendor/wrangler-mime/cli.js +0 -46
  134. package/vendor/wrangler-mime/index.js +0 -4
  135. package/vendor/wrangler-mime/lite.js +0 -4
  136. package/vendor/wrangler-mime/package.json +0 -52
  137. package/vendor/wrangler-mime/types/other.js +0 -1
  138. package/vendor/wrangler-mime/types/standard.js +0 -1
  139. package/wrangler-dist/cli.js.map +0 -7
@@ -1,27 +0,0 @@
1
- import { mkdirSync, writeFileSync } from "node:fs";
2
- import os from "node:os";
3
- import path from "node:path";
4
-
5
- export function writeUserConfig(
6
- oauth_token?: string,
7
- refresh_token?: string,
8
- expiration_time?: string
9
- ) {
10
- const lines: string[] = [];
11
- if (oauth_token) {
12
- lines.push(`oauth_token = "${oauth_token}"`);
13
- }
14
- if (refresh_token) {
15
- lines.push(`refresh_token = "${refresh_token}"`);
16
- }
17
- if (expiration_time) {
18
- lines.push(`expiration_time = "${expiration_time}"`);
19
- }
20
- const configPath = path.join(os.homedir(), ".wrangler/config");
21
- mkdirSync(configPath, { recursive: true });
22
- writeFileSync(
23
- path.join(configPath, "default.toml"),
24
- lines.join("\n"),
25
- "utf-8"
26
- );
27
- }
@@ -1,50 +0,0 @@
1
- import { existsSync } from "node:fs";
2
- import os from "node:os";
3
- import path from "node:path";
4
- import fetchMock from "jest-fetch-mock";
5
- import { initialise } from "../user";
6
- import { mockConsoleMethods } from "./helpers/mock-console";
7
- import { writeUserConfig } from "./helpers/mock-user";
8
- import { runInTempDir } from "./helpers/run-in-tmp";
9
- import { runWrangler } from "./helpers/run-wrangler";
10
-
11
- describe("wrangler", () => {
12
- runInTempDir({ homedir: "./home" });
13
- const std = mockConsoleMethods();
14
-
15
- describe("logout", () => {
16
- it("should exit with a message stating the user is not logged in", async () => {
17
- await initialise();
18
- await runWrangler("logout");
19
- expect(std.out).toMatchInlineSnapshot(`"Not logged in, exiting..."`);
20
- });
21
-
22
- it("should logout user that has been properly logged in", async () => {
23
- writeUserConfig("some-oauth-tok", "some-refresh-tok");
24
-
25
- // Mock out the response for a request to revoke the auth tokens,
26
- // checking the form of the request is as expected.
27
- fetchMock.mockResponseOnce(async (req) => {
28
- expect(req.url).toEqual("https://dash.cloudflare.com/oauth2/revoke");
29
- expect(req.method).toEqual("POST");
30
- return "";
31
- });
32
-
33
- await initialise();
34
- await runWrangler("logout");
35
-
36
- expect(std.out).toMatchInlineSnapshot(`
37
- "💁 Wrangler is configured with an OAuth token. The token has been successfully revoked
38
- Removing ./home/.wrangler/config/default.toml.. success!"
39
- `);
40
-
41
- // Make sure that we made the request to logout.
42
- expect(fetchMock).toHaveBeenCalledTimes(1);
43
-
44
- // Make sure that logout removed the config file containing the auth tokens.
45
- expect(
46
- existsSync(path.join(os.homedir(), ".wrangler/config/default.toml"))
47
- ).toBe(false);
48
- });
49
- });
50
- });
@@ -1,146 +0,0 @@
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
- });