wrangler 2.6.2 → 2.7.0

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 (128) hide show
  1. package/bin/wrangler.js +9 -1
  2. package/miniflare-dist/index.mjs +1 -1
  3. package/package.json +12 -10
  4. package/src/__tests__/api-dev.test.ts +65 -36
  5. package/src/__tests__/api-devregistry.test.js +14 -6
  6. package/src/__tests__/configuration.test.ts +2 -31
  7. package/src/__tests__/{d1.test.ts → d1/d1.test.ts} +48 -5
  8. package/src/__tests__/d1/splitter.test.ts +255 -0
  9. package/src/__tests__/delete.test.ts +5 -2
  10. package/src/__tests__/deployments.test.ts +20 -6
  11. package/src/__tests__/dev.test.tsx +52 -19
  12. package/src/__tests__/generate.test.ts +7 -4
  13. package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
  14. package/src/__tests__/helpers/mock-cfetch.ts +2 -57
  15. package/src/__tests__/helpers/mock-dialogs.ts +70 -86
  16. package/src/__tests__/helpers/mock-oauth-flow.ts +64 -49
  17. package/src/__tests__/helpers/mock-process.ts +8 -13
  18. package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
  19. package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
  20. package/src/__tests__/index.test.ts +46 -44
  21. package/src/__tests__/init.test.ts +761 -537
  22. package/src/__tests__/jest.setup.ts +20 -24
  23. package/src/__tests__/kv.test.ts +286 -173
  24. package/src/__tests__/logout.test.ts +1 -1
  25. package/src/__tests__/metrics.test.ts +5 -7
  26. package/src/__tests__/middleware.scheduled.test.ts +40 -30
  27. package/src/__tests__/middleware.test.ts +144 -120
  28. package/src/__tests__/pages.test.ts +1617 -1161
  29. package/src/__tests__/publish.test.ts +174 -125
  30. package/src/__tests__/r2.test.ts +2 -2
  31. package/src/__tests__/secret.test.ts +183 -126
  32. package/src/__tests__/tail.test.ts +6 -0
  33. package/src/__tests__/tsconfig-sanity.ts +12 -0
  34. package/src/__tests__/tsconfig.json +8 -0
  35. package/src/__tests__/tsconfig.tsbuildinfo +1 -0
  36. package/src/__tests__/whoami.test.tsx +1 -96
  37. package/src/api/dev.ts +78 -41
  38. package/src/api/index.ts +1 -1
  39. package/src/{bundle-reporter.tsx → bundle-reporter.ts} +0 -0
  40. package/src/cfetch/index.ts +0 -2
  41. package/src/cfetch/internal.ts +6 -15
  42. package/src/cli.ts +2 -2
  43. package/src/config/validation.ts +1 -2
  44. package/src/create-worker-upload-form.ts +2 -2
  45. package/src/d1/{delete.tsx → delete.ts} +0 -0
  46. package/src/d1/execute.tsx +8 -37
  47. package/src/d1/migrations/apply.tsx +29 -19
  48. package/src/d1/migrations/{index.tsx → index.ts} +0 -0
  49. package/src/d1/splitter.ts +161 -0
  50. package/src/d1/{types.tsx → types.ts} +0 -0
  51. package/src/delete.ts +3 -8
  52. package/src/deployments.ts +6 -0
  53. package/src/deprecated/index.ts +2 -295
  54. package/src/dev/dev.tsx +2 -2
  55. package/src/dev/{get-local-persistence-path.tsx → get-local-persistence-path.ts} +0 -0
  56. package/src/dev/local.tsx +16 -4
  57. package/src/dev/remote.tsx +28 -1
  58. package/src/dev/start-server.ts +19 -11
  59. package/src/dev/use-esbuild.ts +1 -1
  60. package/src/{dev-registry.tsx → dev-registry.ts} +0 -0
  61. package/src/dev.tsx +21 -2
  62. package/src/dialogs.ts +136 -0
  63. package/src/dispatch-namespace.ts +1 -1
  64. package/src/docs/index.ts +3 -0
  65. package/src/environment-variables/factory.ts +88 -0
  66. package/src/environment-variables/misc-variables.ts +30 -0
  67. package/src/generate/index.ts +300 -0
  68. package/src/{index.tsx → index.ts} +10 -13
  69. package/src/init.ts +92 -52
  70. package/src/jest.d.ts +4 -0
  71. package/src/logger.ts +15 -3
  72. package/src/metrics/metrics-config.ts +1 -1
  73. package/src/miniflare-cli/assets.ts +4 -0
  74. package/src/miniflare-cli/index.ts +1 -5
  75. package/src/miniflare-cli/tsconfig.json +9 -0
  76. package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
  77. package/src/miniflare-cli/types.ts +11 -0
  78. package/src/pages/{build.tsx → build.ts} +0 -0
  79. package/src/pages/{deployment-tails.tsx → deployment-tails.ts} +0 -0
  80. package/src/pages/{dev.tsx → dev.ts} +53 -55
  81. package/src/pages/functions/buildWorker.ts +1 -1
  82. package/src/pages/functions/tsconfig.json +8 -0
  83. package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
  84. package/src/pages/{functions.tsx → functions.ts} +0 -0
  85. package/src/pages/{hash.tsx → hash.ts} +0 -0
  86. package/src/pages/{index.tsx → index.ts} +0 -0
  87. package/src/pages/projects.tsx +3 -5
  88. package/src/pages/publish.tsx +5 -4
  89. package/src/pages/upload.tsx +1 -1
  90. package/src/publish/publish.ts +9 -7
  91. package/src/pubsub/{pubsub-commands.tsx → pubsub-commands.ts} +1 -1
  92. package/src/secret/index.ts +1 -1
  93. package/src/{sites.tsx → sites.ts} +0 -0
  94. package/src/tail/index.ts +2 -3
  95. package/src/tsconfig-sanity.ts +16 -0
  96. package/src/user/access.ts +0 -1
  97. package/src/user/auth-variables.ts +113 -0
  98. package/src/user/choose-account.tsx +1 -31
  99. package/src/user/index.ts +0 -1
  100. package/src/user/{user.tsx → user.ts} +107 -73
  101. package/src/{whoami.tsx → whoami.ts} +37 -71
  102. package/templates/__tests__/tsconfig-sanity.ts +12 -0
  103. package/templates/__tests__/tsconfig.json +8 -0
  104. package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
  105. package/templates/d1-beta-facade.js +36 -0
  106. package/templates/facade.d.ts +14 -0
  107. package/templates/first-party-worker-module-facade.ts +4 -3
  108. package/templates/format-dev-errors.ts +7 -6
  109. package/templates/init-tests/test-jest-new-worker.js +3 -5
  110. package/templates/init-tests/test-vitest-new-worker.js +3 -5
  111. package/templates/init-tests/test-vitest-new-worker.ts +25 -0
  112. package/templates/middleware/loader-modules.ts +0 -2
  113. package/templates/middleware/loader-sw.ts +6 -0
  114. package/templates/pages-dev-pipeline.ts +4 -1
  115. package/templates/pages-shim.ts +4 -1
  116. package/templates/pages-template-plugin.ts +12 -7
  117. package/templates/serve-static-assets.ts +16 -14
  118. package/templates/tsconfig-sanity.ts +11 -0
  119. package/templates/tsconfig.init.json +106 -0
  120. package/templates/tsconfig.json +5 -103
  121. package/templates/tsconfig.tsbuildinfo +1 -0
  122. package/wrangler-dist/cli.d.ts +58 -60
  123. package/wrangler-dist/cli.js +34440 -55514
  124. package/wrangler-dist/wasm-sync.wasm +0 -0
  125. package/src/__tests__/dialogs.test.tsx +0 -40
  126. package/src/dialogs.tsx +0 -168
  127. package/src/environment-variables.ts +0 -50
  128. package/src/user/env-vars.ts +0 -46
Binary file
@@ -1,40 +0,0 @@
1
- jest.unmock("../dialogs");
2
- import { fromDashMessagePrompt } from "../dialogs";
3
- import { CI } from "../is-ci";
4
-
5
- describe("fromDashMessagePrompt", () => {
6
- it("should return undefined in CI when last deployed from api", async () => {
7
- //in CI
8
- jest.spyOn(CI, "isCI").mockReturnValue(true);
9
- const result = await fromDashMessagePrompt("api");
10
- expect(result).toBe(undefined);
11
- });
12
-
13
- it("should return undefined in CI when last deployed from wrangler", async () => {
14
- //in CI
15
- jest.spyOn(CI, "isCI").mockReturnValue(true);
16
- const result = await fromDashMessagePrompt("wrangler");
17
- expect(result).toBe(undefined);
18
- });
19
-
20
- it("should return true in CI when last deployed from dash", async () => {
21
- //in CI
22
- jest.spyOn(CI, "isCI").mockReturnValue(true);
23
- const result = await fromDashMessagePrompt("dash");
24
- expect(result).toBe(true);
25
- });
26
-
27
- it("should return undefined when last deployed from api", async () => {
28
- //not in CI
29
- jest.spyOn(CI, "isCI").mockReturnValue(false);
30
- const result = await fromDashMessagePrompt("api");
31
- expect(result).toBe(undefined);
32
- });
33
-
34
- it("should return undefined when last deployed from wrangler", async () => {
35
- //not in CI
36
- jest.spyOn(CI, "isCI").mockReturnValue(false);
37
- const result = await fromDashMessagePrompt("wrangler");
38
- expect(result).toBe(undefined);
39
- });
40
- });
package/src/dialogs.tsx DELETED
@@ -1,168 +0,0 @@
1
- import chalk from "chalk";
2
- import { Box, Text, useInput, render } from "ink";
3
- import SelectInput from "ink-select-input";
4
- import TextInput from "ink-text-input";
5
- import * as React from "react";
6
- import { useState } from "react";
7
-
8
- import { CI } from "./is-ci";
9
- import isInteractive from "./is-interactive";
10
- import { logger } from "./logger";
11
-
12
- type ConfirmProps = {
13
- text: string;
14
- onConfirm: (answer: boolean) => void;
15
- };
16
- function Confirm(props: ConfirmProps) {
17
- useInput((input: string, key) => {
18
- if (input === "y" || key.return === true) {
19
- props.onConfirm(true);
20
- } else if (input === "n") {
21
- props.onConfirm(false);
22
- } else {
23
- logger.warn("Unrecognised input:", input);
24
- }
25
- });
26
- return (
27
- <Box>
28
- <Text>
29
- {props.text} ({chalk.bold("y")}/n)
30
- </Text>
31
- </Box>
32
- );
33
- }
34
-
35
- export function confirm(
36
- text: string,
37
- beforeConfirm?: JSX.Element
38
- ): Promise<boolean> {
39
- return new Promise((resolve) => {
40
- const { unmount } = render(
41
- <Box flexDirection="column">
42
- {beforeConfirm}
43
- <Confirm
44
- text={text}
45
- onConfirm={(answer: boolean) => {
46
- unmount();
47
- resolve(answer);
48
- }}
49
- />
50
- </Box>
51
- );
52
- });
53
- }
54
-
55
- type PromptProps = {
56
- text: string;
57
- defaultValue?: string;
58
- type?: "text" | "password";
59
- onSubmit: (text: string) => void;
60
- };
61
-
62
- function Prompt(props: PromptProps) {
63
- const [value, setValue] = useState(props.defaultValue || "");
64
-
65
- return (
66
- <Box>
67
- <Text>{props.text} </Text>
68
- <Box>
69
- <TextInput
70
- mask={props.type === "password" ? "*" : undefined}
71
- value={value}
72
- onChange={setValue}
73
- onSubmit={props.onSubmit}
74
- />
75
- </Box>
76
- </Box>
77
- );
78
- }
79
-
80
- export async function prompt(
81
- text: string,
82
- type: "text" | "password" = "text",
83
- defaultValue?: string
84
- ): Promise<string> {
85
- return new Promise((resolve) => {
86
- const { unmount } = render(
87
- <Prompt
88
- text={text}
89
- defaultValue={defaultValue}
90
- type={type}
91
- onSubmit={(inputText) => {
92
- unmount();
93
- resolve(inputText);
94
- }}
95
- />
96
- );
97
- });
98
- }
99
-
100
- type SelectOption = {
101
- value: string;
102
- label: string;
103
- };
104
-
105
- type SelectProps = {
106
- text: string;
107
- options: SelectOption[];
108
- initialIndex: number;
109
- onSelect: (value: string) => void;
110
- };
111
-
112
- function Select(props: SelectProps) {
113
- return (
114
- <Box flexDirection="column">
115
- <Text>{props.text}</Text>
116
- <SelectInput
117
- initialIndex={props.initialIndex}
118
- items={props.options}
119
- onSelect={async (selected) => {
120
- props.onSelect(selected.value);
121
- }}
122
- />
123
- </Box>
124
- );
125
- }
126
-
127
- export function select(
128
- text: string,
129
- options: SelectOption[],
130
- initialIndex: number
131
- ): Promise<string> {
132
- return new Promise((resolve) => {
133
- const { unmount } = render(
134
- <Select
135
- text={text}
136
- options={options}
137
- initialIndex={initialIndex}
138
- onSelect={(option: string) => {
139
- unmount();
140
- resolve(option);
141
- }}
142
- />
143
- );
144
- });
145
- }
146
-
147
- export function logDim(msg: string) {
148
- console.log(chalk.gray(msg));
149
- }
150
-
151
- export async function fromDashMessagePrompt(
152
- deploySource: "dash" | "wrangler" | "api"
153
- ): Promise<boolean | void> {
154
- if (deploySource === "dash") {
155
- logger.warn(
156
- `You are about to publish a Workers Service that was last published via the Cloudflare Dashboard.\nEdits that have been made via the dashboard will be overridden by your local code and config.`
157
- );
158
-
159
- if (!isInteractive() || CI.isCI()) return true;
160
-
161
- return await confirm("Would you like to continue?");
162
- }
163
- }
164
- export async function tailDOLogPrompt(): Promise<boolean | void> {
165
- if (!isInteractive() || CI.isCI()) return true;
166
-
167
- return await confirm("Would you like to continue?");
168
- }
@@ -1,50 +0,0 @@
1
- import { logger } from "./logger";
2
-
3
- type VariableNames =
4
- | "CLOUDFLARE_ACCOUNT_ID"
5
- | "CLOUDFLARE_API_TOKEN"
6
- | "CLOUDFLARE_API_KEY"
7
- | "CLOUDFLARE_EMAIL"
8
- | "WRANGLER_SEND_METRICS"
9
- | "CLOUDFLARE_API_BASE_URL"
10
- | "WRANGLER_LOG";
11
-
12
- type DeprecatedNames =
13
- | "CF_ACCOUNT_ID"
14
- | "CF_API_TOKEN"
15
- | "CF_API_KEY"
16
- | "CF_EMAIL"
17
- | "CF_API_BASE_URL";
18
- /**
19
- * Create a function used to access an environment variable.
20
- *
21
- * This is not memoized to allow us to change the value at runtime, such as in testing.
22
- * A warning is shown if the client is using a deprecated version - but only once.
23
- */
24
- export function getEnvironmentVariableFactory({
25
- variableName,
26
- deprecatedName,
27
- defaultValue,
28
- }: {
29
- variableName: VariableNames;
30
- deprecatedName?: DeprecatedNames;
31
- defaultValue?: string;
32
- }) {
33
- let hasWarned = false;
34
- return () => {
35
- if (process.env[variableName]) {
36
- return process.env[variableName];
37
- } else if (deprecatedName && process.env[deprecatedName]) {
38
- if (!hasWarned) {
39
- // Only show the warning once.
40
- hasWarned = true;
41
- logger.warn(
42
- `Using "${deprecatedName}" environment variable. This is deprecated. Please use "${variableName}", instead.`
43
- );
44
- }
45
- return process.env[deprecatedName];
46
- } else {
47
- return defaultValue;
48
- }
49
- };
50
- }
@@ -1,46 +0,0 @@
1
- import { getEnvironmentVariableFactory } from "../environment-variables";
2
-
3
- export type ApiCredentials =
4
- | {
5
- apiToken: string;
6
- }
7
- | {
8
- authKey: string;
9
- authEmail: string;
10
- };
11
-
12
- const getCloudflareAPITokenFromEnv = getEnvironmentVariableFactory({
13
- variableName: "CLOUDFLARE_API_TOKEN",
14
- deprecatedName: "CF_API_TOKEN",
15
- });
16
- const getCloudflareGlobalAuthKeyFromEnv = getEnvironmentVariableFactory({
17
- variableName: "CLOUDFLARE_API_KEY",
18
- deprecatedName: "CF_API_KEY",
19
- });
20
- const getCloudflareGlobalAuthEmailFromEnv = getEnvironmentVariableFactory({
21
- variableName: "CLOUDFLARE_EMAIL",
22
- deprecatedName: "CF_EMAIL",
23
- });
24
-
25
- /**
26
- * Try to read an API token or Global Auth from the environment.
27
- */
28
- export function getAuthFromEnv(): ApiCredentials | undefined {
29
- const globalApiKey = getCloudflareGlobalAuthKeyFromEnv();
30
- const globalApiEmail = getCloudflareGlobalAuthEmailFromEnv();
31
- const apiToken = getCloudflareAPITokenFromEnv();
32
-
33
- if (globalApiKey && globalApiEmail) {
34
- return { authKey: globalApiKey, authEmail: globalApiEmail };
35
- } else if (apiToken) {
36
- return { apiToken };
37
- }
38
- }
39
-
40
- /**
41
- * Try to read the account ID from the environment.
42
- */
43
- export const getCloudflareAccountIdFromEnv = getEnvironmentVariableFactory({
44
- variableName: "CLOUDFLARE_ACCOUNT_ID",
45
- deprecatedName: "CF_ACCOUNT_ID",
46
- });