wrangler 0.0.0-e2a26a0 → 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 (91) hide show
  1. package/README.md +3 -3
  2. package/bin/wrangler.js +10 -1
  3. package/miniflare-dist/index.mjs +79 -0
  4. package/miniflare-dist/index.mjs.map +7 -0
  5. package/package.json +24 -12
  6. package/pages/functions/filepath-routing.test.ts +212 -36
  7. package/pages/functions/filepath-routing.ts +69 -119
  8. package/pages/functions/routes.ts +8 -17
  9. package/pages/functions/template-worker.ts +3 -9
  10. package/src/__tests__/configuration.test.ts +2820 -0
  11. package/src/__tests__/dev.test.tsx +535 -65
  12. package/src/__tests__/guess-worker-format.test.ts +68 -0
  13. package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
  14. package/src/__tests__/helpers/mock-account-id.ts +26 -8
  15. package/src/__tests__/helpers/mock-bin.ts +4 -1
  16. package/src/__tests__/helpers/mock-cfetch.ts +5 -5
  17. package/src/__tests__/helpers/mock-console.ts +21 -7
  18. package/src/__tests__/helpers/mock-kv.ts +9 -16
  19. package/src/__tests__/helpers/mock-stdin.ts +103 -0
  20. package/src/__tests__/helpers/mock-web-socket.ts +29 -0
  21. package/src/__tests__/helpers/run-in-tmp.ts +3 -0
  22. package/src/__tests__/helpers/run-wrangler.ts +5 -3
  23. package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
  24. package/src/__tests__/https-options.test.ts +127 -0
  25. package/src/__tests__/index.test.ts +467 -27
  26. package/src/__tests__/jest.setup.ts +37 -5
  27. package/src/__tests__/kv.test.ts +442 -201
  28. package/src/__tests__/logout.test.ts +15 -13
  29. package/src/__tests__/package-manager.test.ts +2 -2
  30. package/src/__tests__/pages.test.ts +82 -0
  31. package/src/__tests__/parse.test.ts +322 -0
  32. package/src/__tests__/publish.test.ts +2717 -430
  33. package/src/__tests__/r2.test.ts +198 -0
  34. package/src/__tests__/route.test.ts +45 -0
  35. package/src/__tests__/secret.test.ts +301 -86
  36. package/src/__tests__/sentry.test.ts +146 -0
  37. package/src/__tests__/tail.test.ts +638 -0
  38. package/src/__tests__/whoami.test.tsx +21 -7
  39. package/src/bundle.ts +155 -0
  40. package/src/cfetch/index.ts +8 -6
  41. package/src/cfetch/internal.ts +60 -22
  42. package/src/cli.ts +10 -0
  43. package/src/config/README.md +107 -0
  44. package/src/config/config.ts +218 -0
  45. package/src/config/diagnostics.ts +80 -0
  46. package/src/config/environment.ts +371 -0
  47. package/src/config/index.ts +62 -0
  48. package/src/config/validation-helpers.ts +554 -0
  49. package/src/config/validation.ts +1232 -0
  50. package/src/{api/preview.ts → create-worker-preview.ts} +59 -21
  51. package/src/create-worker-upload-form.ts +217 -0
  52. package/src/dev/dev.tsx +392 -0
  53. package/src/dev/local.tsx +232 -0
  54. package/src/dev/remote.tsx +203 -0
  55. package/src/dev/use-esbuild.ts +104 -0
  56. package/src/entry.ts +240 -0
  57. package/src/environment-variables.ts +33 -0
  58. package/src/https-options.ts +122 -0
  59. package/src/index.tsx +1068 -780
  60. package/src/inspect.ts +25 -4
  61. package/src/intl-polyfill.d.ts +139 -0
  62. package/src/{kv.tsx → kv.ts} +95 -60
  63. package/src/miniflare-cli/README.md +30 -0
  64. package/src/miniflare-cli/enum-keys.ts +17 -0
  65. package/src/miniflare-cli/index.ts +37 -0
  66. package/src/module-collection.ts +226 -31
  67. package/src/open-in-browser.ts +25 -0
  68. package/src/package-manager.ts +21 -15
  69. package/src/pages.tsx +35 -20
  70. package/src/parse.ts +183 -0
  71. package/src/proxy.ts +115 -45
  72. package/src/publish.ts +268 -328
  73. package/src/r2.ts +50 -0
  74. package/src/reporting.ts +131 -0
  75. package/src/selfsigned.d.ts +29 -0
  76. package/src/sites.tsx +83 -43
  77. package/src/tail/filters.ts +279 -0
  78. package/src/tail/index.ts +299 -0
  79. package/src/tail/printing.ts +62 -0
  80. package/src/user.tsx +234 -126
  81. package/src/{api/worker.ts → worker.ts} +44 -36
  82. package/templates/new-worker.js +1 -1
  83. package/templates/new-worker.ts +1 -1
  84. package/templates/tsconfig.json +105 -0
  85. package/wrangler-dist/cli.js +131202 -114243
  86. package/wrangler-dist/cli.js.map +3 -3
  87. package/src/__tests__/helpers/mock-user.ts +0 -27
  88. package/src/api/form_data.ts +0 -134
  89. package/src/config.ts +0 -641
  90. package/src/dev.tsx +0 -834
  91. package/src/tail.tsx +0 -73
package/src/bundle.ts ADDED
@@ -0,0 +1,155 @@
1
+ import assert from "node:assert";
2
+ import * as fs from "node:fs";
3
+ import * as path from "node:path";
4
+ import * as esbuild from "esbuild";
5
+ import createModuleCollector from "./module-collection";
6
+ import type { Config } from "./config";
7
+ import type { Entry } from "./entry";
8
+ import type { CfModule } from "./worker";
9
+
10
+ type BundleResult = {
11
+ modules: CfModule[];
12
+ resolvedEntryPointPath: string;
13
+ bundleType: "esm" | "commonjs";
14
+ stop: (() => void) | undefined;
15
+ };
16
+
17
+ /**
18
+ * Generate a bundle for the worker identified by the arguments passed in.
19
+ */
20
+ export async function bundleWorker(
21
+ entry: Entry,
22
+ destination: string,
23
+ options: {
24
+ serveAssetsFromWorker: boolean;
25
+ jsxFactory: string | undefined;
26
+ jsxFragment: string | undefined;
27
+ rules: Config["rules"];
28
+ watch?: esbuild.WatchMode;
29
+ tsconfig: string | undefined;
30
+ }
31
+ ): Promise<BundleResult> {
32
+ const {
33
+ serveAssetsFromWorker,
34
+ jsxFactory,
35
+ jsxFragment,
36
+ rules,
37
+ watch,
38
+ tsconfig,
39
+ } = options;
40
+ const entryDirectory = path.dirname(entry.file);
41
+ const moduleCollector = createModuleCollector({
42
+ wrangler1xlegacyModuleReferences: {
43
+ rootDirectory: entryDirectory,
44
+ fileNames: new Set(
45
+ fs
46
+ .readdirSync(entryDirectory, { withFileTypes: true })
47
+ .filter(
48
+ (dirEntry) =>
49
+ dirEntry.isFile() && dirEntry.name !== path.basename(entry.file)
50
+ )
51
+ .map((dirEnt) => dirEnt.name)
52
+ ),
53
+ },
54
+ format: entry.format,
55
+ rules,
56
+ });
57
+ const result = await esbuild.build({
58
+ ...getEntryPoint(entry.file, serveAssetsFromWorker),
59
+ bundle: true,
60
+ absWorkingDir: entry.directory,
61
+ outdir: destination,
62
+ external: ["__STATIC_CONTENT_MANIFEST"],
63
+ format: "esm",
64
+ sourcemap: true,
65
+ metafile: true,
66
+ conditions: ["worker", "browser"],
67
+ ...(process.env.NODE_ENV && {
68
+ define: {
69
+ "process.env.NODE_ENV": `"${process.env.NODE_ENV}"`,
70
+ },
71
+ }),
72
+ loader: {
73
+ ".js": "jsx",
74
+ ".mjs": "jsx",
75
+ ".cjs": "jsx",
76
+ },
77
+ plugins: [moduleCollector.plugin],
78
+ ...(jsxFactory && { jsxFactory }),
79
+ ...(jsxFragment && { jsxFragment }),
80
+ ...(tsconfig && { tsconfig }),
81
+ watch,
82
+ });
83
+
84
+ const entryPointOutputs = Object.entries(result.metafile.outputs).filter(
85
+ ([_path, output]) => output.entryPoint !== undefined
86
+ );
87
+ assert(
88
+ entryPointOutputs.length > 0,
89
+ `Cannot find entry-point "${entry.file}" in generated bundle.` +
90
+ listEntryPoints(entryPointOutputs)
91
+ );
92
+ assert(
93
+ entryPointOutputs.length < 2,
94
+ "More than one entry-point found for generated bundle." +
95
+ listEntryPoints(entryPointOutputs)
96
+ );
97
+
98
+ const entryPointExports = entryPointOutputs[0][1].exports;
99
+ const bundleType = entryPointExports.length > 0 ? "esm" : "commonjs";
100
+
101
+ return {
102
+ modules: moduleCollector.modules,
103
+ resolvedEntryPointPath: path.resolve(
104
+ entry.directory,
105
+ entryPointOutputs[0][0]
106
+ ),
107
+ bundleType,
108
+ stop: result.stop,
109
+ };
110
+ }
111
+
112
+ type EntryPoint =
113
+ | { stdin: esbuild.StdinOptions; nodePaths: string[] }
114
+ | { entryPoints: string[] };
115
+
116
+ /**
117
+ * Create an object that describes the entry point for esbuild.
118
+ *
119
+ * If we are using the experimental asset handling, then the entry point is
120
+ * actually a shim worker that will either return an asset from a KV store,
121
+ * or delegate to the actual worker.
122
+ */
123
+ function getEntryPoint(
124
+ entryFile: string,
125
+ serveAssetsFromWorker: boolean
126
+ ): EntryPoint {
127
+ if (serveAssetsFromWorker) {
128
+ return {
129
+ stdin: {
130
+ contents: fs
131
+ .readFileSync(
132
+ path.join(__dirname, "../templates/static-asset-facade.js"),
133
+ "utf8"
134
+ )
135
+ .replace("__ENTRY_POINT__", entryFile),
136
+ sourcefile: "static-asset-facade.js",
137
+ resolveDir: path.dirname(entryFile),
138
+ },
139
+ nodePaths: [path.join(__dirname, "../vendor")],
140
+ };
141
+ } else {
142
+ return { entryPoints: [entryFile] };
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Generate a string that describes the entry-points that were identified by esbuild.
148
+ */
149
+ function listEntryPoints(
150
+ outputs: [string, ValueOf<esbuild.Metafile["outputs"]>][]
151
+ ): string {
152
+ return outputs.map(([_input, output]) => output.entryPoint).join("\n");
153
+ }
154
+
155
+ type ValueOf<T> = T[keyof T];
@@ -1,10 +1,11 @@
1
1
  import { URLSearchParams } from "node:url";
2
+ import { ParseError } from "../parse";
2
3
  import { fetchInternal } from "./internal";
3
4
  import type { RequestInit } from "undici";
4
5
 
5
6
  // Check out https://api.cloudflare.com/ for API docs.
6
7
 
7
- export { CF_API_BASE_URL } from "./internal";
8
+ export { getCloudflareAPIBaseURL as getCloudflareApiBaseUrl } from "./internal";
8
9
 
9
10
  export interface FetchError {
10
11
  code: number;
@@ -81,11 +82,12 @@ function throwFetchError(
81
82
  resource: string,
82
83
  response: FetchResult<unknown>
83
84
  ): never {
84
- response.messages.forEach((message) => console.warn(message));
85
- const errors = response.errors
86
- .map((error) => `${error.code}: ${error.message}`)
87
- .join("\n");
88
- const error = new Error(`Failed to fetch ${resource} - \n${errors}`);
85
+ const error = new ParseError({
86
+ text: "Received a bad response from the API",
87
+ notes: response.errors.map((err) => ({
88
+ text: err.code ? `${err.message} [code: ${err.code}]` : err.message,
89
+ })),
90
+ });
89
91
  // add the first error code directly to this error
90
92
  // so consumers can use it for specific behaviour
91
93
  const code = response.errors[0]?.code;
@@ -1,10 +1,19 @@
1
- import { fetch } from "undici";
1
+ import { fetch, Headers } from "undici";
2
+ import { getEnvironmentVariableFactory } from "../environment-variables";
3
+ import { ParseError, parseJSON } from "../parse";
4
+ import { reportError } from "../reporting";
2
5
  import { getAPIToken, loginOrRefreshIfRequired } from "../user";
3
6
  import type { URLSearchParams } from "node:url";
4
7
  import type { RequestInit, HeadersInit } from "undici";
5
8
 
6
- export const CF_API_BASE_URL =
7
- process.env.CF_API_BASE_URL || "https://api.cloudflare.com/client/v4";
9
+ /**
10
+ * Get the URL to use to access the Cloudflare API.
11
+ */
12
+ export const getCloudflareAPIBaseURL = getEnvironmentVariableFactory({
13
+ variableName: "CLOUDFLARE_API_BASE_URL",
14
+ deprecatedName: "CF_API_BASE_URL",
15
+ defaultValue: "https://api.cloudflare.com/client/v4",
16
+ });
8
17
 
9
18
  /**
10
19
  * Make a fetch request to the Cloudflare API.
@@ -26,24 +35,50 @@ export async function fetchInternal<ResponseType>(
26
35
  addAuthorizationHeader(headers, apiToken);
27
36
 
28
37
  const queryString = queryParams ? `?${queryParams.toString()}` : "";
29
- const response = await fetch(`${CF_API_BASE_URL}${resource}${queryString}`, {
30
- method: "GET",
31
- ...init,
32
- headers,
33
- });
38
+ const method = init.method ?? "GET";
39
+ const response = await fetch(
40
+ `${getCloudflareAPIBaseURL()}${resource}${queryString}`,
41
+ {
42
+ method,
43
+ ...init,
44
+ headers,
45
+ }
46
+ );
34
47
  const jsonText = await response.text();
35
48
  try {
36
- const json = JSON.parse(jsonText);
37
- return json as ResponseType;
38
- } catch (e) {
39
- throw new Error(
40
- `Failed to fetch ${resource} - ${response.status}: ${response.statusText}\nInvalid JSON response:\n${jsonText}`
41
- );
49
+ return parseJSON(jsonText) as ResponseType;
50
+ } catch (err) {
51
+ await reportError(err as Error);
52
+ throw new ParseError({
53
+ text: "Received a malformed response from the API",
54
+ notes: [
55
+ {
56
+ text: truncate(jsonText, 100),
57
+ },
58
+ {
59
+ text: `${method} ${resource} -> ${response.status} ${response.statusText}`,
60
+ },
61
+ ],
62
+ });
63
+ }
64
+ }
65
+
66
+ function truncate(text: string, maxLength: number): string {
67
+ const { length } = text;
68
+ if (length <= maxLength) {
69
+ return text;
42
70
  }
71
+ return `${text.substring(0, maxLength)}... (length = ${length})`;
43
72
  }
44
73
 
45
- function cloneHeaders(headers: HeadersInit | undefined): HeadersInit {
46
- return { ...headers };
74
+ function cloneHeaders(
75
+ headers: HeadersInit | undefined
76
+ ): Record<string, string> {
77
+ return headers instanceof Headers
78
+ ? Object.fromEntries(headers.entries())
79
+ : Array.isArray(headers)
80
+ ? Object.fromEntries(headers)
81
+ : { ...headers };
47
82
  }
48
83
 
49
84
  async function requireLoggedIn(): Promise<void> {
@@ -54,15 +89,18 @@ async function requireLoggedIn(): Promise<void> {
54
89
  }
55
90
 
56
91
  function requireApiToken(): string {
57
- const apiToken = getAPIToken();
58
- if (!apiToken) {
92
+ const authToken = getAPIToken();
93
+ if (!authToken) {
59
94
  throw new Error("No API token found.");
60
95
  }
61
- return apiToken;
96
+ return authToken;
62
97
  }
63
98
 
64
- function addAuthorizationHeader(headers: HeadersInit, apiToken: string): void {
65
- if (headers["Authorization"]) {
99
+ function addAuthorizationHeader(
100
+ headers: Record<string, string>,
101
+ apiToken: string
102
+ ): void {
103
+ if ("Authorization" in headers) {
66
104
  throw new Error(
67
105
  "The request already specifies an authorisation header - cannot add a new one."
68
106
  );
@@ -86,7 +124,7 @@ export async function fetchKVGetValue(
86
124
  await requireLoggedIn();
87
125
  const apiToken = requireApiToken();
88
126
  const headers = { Authorization: `Bearer ${apiToken}` };
89
- const resource = `${CF_API_BASE_URL}/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${key}`;
127
+ const resource = `${getCloudflareAPIBaseURL()}/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${key}`;
90
128
  const response = await fetch(resource, {
91
129
  method: "GET",
92
130
  headers,
package/src/cli.ts CHANGED
@@ -1,6 +1,16 @@
1
+ import process from "process";
1
2
  import { hideBin } from "yargs/helpers";
3
+ import { reportError, initReporting } from "./reporting";
2
4
  import { main } from ".";
3
5
 
6
+ try {
7
+ initReporting();
8
+ } catch (error) {}
9
+
10
+ process.on("uncaughtExceptionMonitor", async (err, origin) => {
11
+ await reportError(err, origin);
12
+ });
13
+
4
14
  main(hideBin(process.argv)).catch(() => {
5
15
  // The logging of any error that was thrown from `main()` is handled in the `yargs.fail()` handler.
6
16
  // Here we just want to ensure that the process exits with a non-zero code.
@@ -0,0 +1,107 @@
1
+ # Configuration validation
2
+
3
+ The files in this directory define and validate the configuration that is read from a `wrangler.toml` file.
4
+
5
+ The configuration for a Worker is complicated since we can define different "environments", and each environment can have its own configuration.
6
+ There is a default ("top-level") environment and then named environments that provide environment specific configuration.
7
+
8
+ This is further complicated by the fact that there are three kinds of environment configuration:
9
+
10
+ - **non-overridable**: these values are defined once in the top-level configuration, apply to all environments and cannot be overridden by an environment.
11
+ - **inheritable**: these values can be defined at the top-level but can also be overridden by environment specific values.
12
+ Named environments do not need to provide their own values, in which case they inherit the value from the top-level.
13
+ - **non-inheritable**: these values must be explicitly defined in each environment if they are defined at the top-level.
14
+ Named environments do not inherit such configuration and must provide their own values.
15
+
16
+ All configuration values in `wrangler.toml` are optional and will receive a default value if not defined.
17
+
18
+ ## Types
19
+
20
+ ### Environment
21
+
22
+ The fields that can be defined within the `env` containers are defined in the [`Environment`](./environment.ts) type.
23
+ This includes the `EnvironmentInheritable` and `EnvironmentNonInheritable` fields.
24
+
25
+ ### Config
26
+
27
+ The "non-overridable" types are defined in the [`ConfigFields`](./config.ts) type.
28
+ The `Config` type is the overall configuration, which consists of the `ConfigFields` and also an `Environment`.
29
+ In this case the `Environment`, here, corresponds to the "currently active" environment. This is specified by the `--env` command line argument.
30
+ If there is no argument passed then the currently active environment is the "top-level" environment.
31
+ The fields in `Config` and `Environment` are not generally optional and so you can expect they have been filled with suitable inherited or default values.
32
+ These types should be used when you are working with fields that should be passed to commands.
33
+
34
+ ### RawConfig
35
+
36
+ The `RawConfig` type is a version of `Config`, where all the fields are optional.
37
+ The `RawConfig` type includes `DeprecatedConfigFields` and `EnvironmentMap`.
38
+ It also extends the `RawEnvironment` type, which is a version of `Environment` where all the fields are optional.
39
+ These optional fields map to the actual fields found in the `wrangler.toml`.
40
+ These types should be used when you are working with raw configuration that is read or will be written to a `wrangler.toml`.
41
+
42
+ ## Validation
43
+
44
+ Validation is triggered by passing a `RawConfig` object, and the active environment name, to the `normalizeAndValidateConfig()` function.
45
+ This function will return:
46
+
47
+ - a `Config` object, where all the fields have suitable valid values
48
+ - a `Diagnostics` object, which contains any errors or warnings from the validation process
49
+
50
+ The field values may have been parsed directly from the `RawConfig`, inherited into a named environment from the top-level environment, or given a default value.
51
+ Generally, if there are any warnings they should be presented to the user via `console.warn()` messages,
52
+ and if there are any errors then an `Error` should be thrown describing these errors.
53
+
54
+ The `Diagnostics` object is hierarchical: each `Diagnostics` instance can contain a collection of child `Diagnostics` instance.
55
+ When checking for or rendering warnings and errors, the `Diagnostics` class will automatically traverse down to all its children.
56
+
57
+ ## Usage
58
+
59
+ The [high level API](./index.ts) for configuration processing consists of the `findWranglerToml()` and `readConfig()` functions.
60
+
61
+ ### readConfig()
62
+
63
+ The `readConfig()` function will find the nearest `wrangler.toml` file, load and parse it, then validate and normalize the values into a `Config` object.
64
+ Note that you should pass the current active environment name in as a parameter. The resulting `Config` object will contain only the fields appropriate to that environment.
65
+ If there are validation errors then it will throw a suitable error.
66
+
67
+ ## Changing configuration
68
+
69
+ ### Add a new configuration field
70
+
71
+ When a new field needs to be added to the `wrangler.toml` configuration you will need to add to the types and validation code in this directory.
72
+
73
+ Here are some steps that you should consider when doing this:
74
+
75
+ - add the new field to one of the interface:
76
+ - if the field is not overridable in an environment then add it to the `ConfigFields` interface.
77
+ - if the field can be inherited and overridden in a named environment then add it to the `EnvironmentInheritable` interface.
78
+ - if the field cannot be inherited and must be specified in each named environment then add it to the `EnvironmentNonInheritable` interface.
79
+ - if the field is experimental then add a call to the `experimental()` function:
80
+ - if the field is now in the `ConfigDeprecated` interface then add the call to the `normalizeAndValidateConfig()` function.
81
+ - if the field is now in the `EnvironmentDeprecated` interface then add the call to the `normalizeAndValidateEnvironment()` function.
82
+ - add validation and normalization to the interface
83
+ - if the field is in `ConfigFields` then add validation calls to `normalizeAndValidateConfig()` and assign the normalized value to the appropriate property in the `config` object.
84
+ - if the field is in `EnvironmentInheritable` then call `inheritable()` in `normalizeAndValidateEnvironment()` and assign the normalized value to the appropriate property in the `environment` object.
85
+ - if the field is in `EnvironmentNonInheritable` then call `notInheritable()` in `normalizeAndValidateEnvironment()` and assign the normalized value to the appropriate property in the `environment` object.
86
+ - update the tests in `configuration.test.ts`
87
+ - add to the `"should use defaults for empty configuration"` test to prove the correct default value is assigned
88
+ - if the field is in `ConfigFields` add tests to the `"top-level non-environment configuration"` block to check the validation and normalization of values
89
+ - if the field is in `EnvironmentInheritable` or `EnvironmentNonInheritable`
90
+ - add tests to the `"top-level environment configuration"` block to check the validation and normalization of values
91
+ - add tests to the `"named environment configuration"` block to check the inheritance of values
92
+
93
+ ### Remove a configuration field
94
+
95
+ We should not just remove a field from use, since users would not know that this field is no longer needed, nor how to migrate to any new usage.
96
+ Instead we should first deprecate it, and then then remove it in a future major release.
97
+
98
+ - move the field to a deprecation interface:
99
+ - if the field was originally in `ConfigFields` then move it to the `ConfigDeprecated` interface.
100
+ - if the field was originally in either `EnvironmentInheritable` or `EnvironmentNonInheritable` then move it to the `EnvironmentDeprecatedInterface`.
101
+ - remove the validation for the field
102
+ - the TypeScript compiler should indicate where there is now an unknown field, so that you can remove its validation and normalization from the code base.
103
+ - add a deprecation warning by calling `deprecated()`
104
+ - if the field is now in the `ConfigDeprecated` interface then add the call to the `normalizeAndValidateConfig()` function.
105
+ - if the field is now in the `EnvironmentDeprecated` interface then add the call to the `normalizeAndValidateEnvironment()` function.
106
+ - update the tests in `configuration.test.ts`
107
+ - Find tests where the field is mentioned and either remove them (e.g. validation) or update to show the deprecation message.
@@ -0,0 +1,218 @@
1
+ import type { Environment, RawEnvironment } from "./environment";
2
+
3
+ /**
4
+ * This is the static type definition for the configuration object.
5
+ *
6
+ * It reflects a normalized and validated version of the configuration that you can write in wrangler.toml,
7
+ * and optionally augment with arguments passed directly to wrangler.
8
+ *
9
+ * For more information about the configuration object, see the
10
+ * documentation at https://developers.cloudflare.com/workers/cli-wrangler/configuration
11
+ *
12
+ * Notes:
13
+ *
14
+ * - Fields that are only specified in `ConfigFields` and not `Environment` can only appear
15
+ * in the top level config and should not appear in any environments.
16
+ * - All top level fields in config and environments are optional in the wrangler.toml file.
17
+ *
18
+ * Legend for the annotations:
19
+ *
20
+ * - `@breaking`: the deprecation/optionality is a breaking change from wrangler 1.
21
+ * - `@todo`: there's more work to be done (with details attached).
22
+ */
23
+ export type Config = ConfigFields<DevConfig> & Environment;
24
+
25
+ export type RawConfig = Partial<ConfigFields<RawDevConfig>> &
26
+ RawEnvironment &
27
+ DeprecatedConfigFields &
28
+ EnvironmentMap;
29
+
30
+ export interface ConfigFields<Dev extends RawDevConfig> {
31
+ configPath: string | undefined;
32
+
33
+ /**
34
+ * A boolean to enable "legacy" style wrangler environments (from wrangler 1).
35
+ * These have been superseded by Services, but there may be projects that won't
36
+ * (or can't) use them. If you're using a legacy environment, you can set this
37
+ * to `true` to enable it.
38
+ */
39
+ legacy_env: boolean;
40
+
41
+ /**
42
+ * Options to configure the development server that your worker will use.
43
+ */
44
+ dev: Dev;
45
+
46
+ /**
47
+ * A list of migrations that should be uploaded with your Worker.
48
+ *
49
+ * These define changes in your Durable Object declarations.
50
+ *
51
+ * More details at https://developers.cloudflare.com/workers/learning/using-durable-objects#configuring-durable-object-classes-with-migrations
52
+ *
53
+ * @default `[]`
54
+ */
55
+ migrations: {
56
+ /** A unique identifier for this migration. */
57
+ tag: string;
58
+ /** The new Durable Objects being defined. */
59
+ new_classes?: string[];
60
+ /** The Durable Objects being renamed. */
61
+ renamed_classes?: {
62
+ from: string;
63
+ to: string;
64
+ }[];
65
+ /** The Durable Objects being removed. */
66
+ deleted_classes?: string[];
67
+ }[];
68
+
69
+ /**
70
+ * The definition of a Worker Site, a feature that lets you upload
71
+ * static assets with your Worker.
72
+ *
73
+ * More details at https://developers.cloudflare.com/workers/platform/sites
74
+ */
75
+ site:
76
+ | {
77
+ /**
78
+ * The directory containing your static assets.
79
+ *
80
+ * It must be a path relative to your wrangler.toml file.
81
+ * Example: bucket = "./public"
82
+ *
83
+ * If there is a `site` field then it must contain this `bucket` field.
84
+ */
85
+ bucket: string;
86
+
87
+ /**
88
+ * The location of your Worker script.
89
+ *
90
+ * @deprecated DO NOT use this (it's a holdover from wrangler 1.x). Either use the top level `main` field, or pass the path to your entry file as a command line argument.
91
+ * @breaking
92
+ */
93
+ "entry-point"?: string;
94
+
95
+ /**
96
+ * An exclusive list of .gitignore-style patterns that match file
97
+ * or directory names from your bucket location. Only matched
98
+ * items will be uploaded. Example: include = ["upload_dir"]
99
+ *
100
+ * @optional
101
+ * @default `[]`
102
+ */
103
+ include?: string[];
104
+
105
+ /**
106
+ * A list of .gitignore-style patterns that match files or
107
+ * directories in your bucket that should be excluded from
108
+ * uploads. Example: exclude = ["ignore_dir"]
109
+ *
110
+ * @optional
111
+ * @default `[]`
112
+ */
113
+ exclude?: string[];
114
+ }
115
+ | undefined;
116
+
117
+ /**
118
+ * A list of wasm modules that your worker should be bound to. This is
119
+ * the "legacy" way of binding to a wasm module. ES module workers should
120
+ * do proper module imports.
121
+ */
122
+ wasm_modules:
123
+ | {
124
+ [key: string]: string;
125
+ }
126
+ | undefined;
127
+
128
+ /**
129
+ * A list of text files that your worker should be bound to. This is
130
+ * the "legacy" way of binding to a text file. ES module workers should
131
+ * do proper module imports.
132
+ */
133
+ text_blobs:
134
+ | {
135
+ [key: string]: string;
136
+ }
137
+ | undefined;
138
+ }
139
+
140
+ export interface DevConfig {
141
+ /**
142
+ * IP address for the local dev server to listen on,
143
+ *
144
+ * @default `localhost`
145
+ * @todo this needs to be implemented
146
+ */
147
+ ip: string;
148
+
149
+ /**
150
+ * Port for the local dev server to listen on
151
+ *
152
+ * @default `8787`
153
+ */
154
+ port: number;
155
+
156
+ /**
157
+ * Protocol that local wrangler dev server listens to requests on.
158
+ *
159
+ * @default `http`
160
+ * @todo this needs to be implemented
161
+ */
162
+ local_protocol: "http" | "https";
163
+
164
+ /**
165
+ * Protocol that wrangler dev forwards requests on
166
+ *
167
+ * Setting this to `http` is not currently implemented.
168
+ * See https://github.com/cloudflare/wrangler2/issues/583
169
+ *
170
+ * @default `https`
171
+ */
172
+ upstream_protocol: "https" | "http";
173
+
174
+ /**
175
+ * Host to forward requests to, defaults to the zone of project
176
+ */
177
+ host: string | undefined;
178
+ }
179
+
180
+ export type RawDevConfig = Partial<DevConfig>;
181
+
182
+ export interface DeprecatedConfigFields {
183
+ /**
184
+ * The project "type". A holdover from wrangler 1.x.
185
+ * Valid values were "webpack", "javascript", and "rust".
186
+ *
187
+ * @deprecated DO NOT USE THIS. Most common features now work out of the box with wrangler, including modules, jsx, typescript, etc. If you need anything more, use a custom build.
188
+ * @breaking
189
+ */
190
+ type?: "webpack" | "javascript" | "rust";
191
+
192
+ /**
193
+ * Path to the webpack config to use when building your worker.
194
+ * A holdover from wrangler 1.x, used with `type: "webpack"`.
195
+ *
196
+ * @deprecated DO NOT USE THIS. Most common features now work out of the box with wrangler, including modules, jsx, typescript, etc. If you need anything more, use a custom build.
197
+ * @breaking
198
+ */
199
+ webpack_config?: string;
200
+ }
201
+
202
+ interface EnvironmentMap {
203
+ /**
204
+ * The `env` section defines overrides for the configuration for different environments.
205
+ *
206
+ * All environment fields can be specified at the top level of the config indicating the default environment settings.
207
+ *
208
+ * - Some fields are inherited and overridable in each environment.
209
+ * - But some are not inherited and must be explicitly specified in every environment, if they are specified at the top level.
210
+ *
211
+ * For more information, see the documentation at https://developers.cloudflare.com/workers/cli-wrangler/configuration#environments
212
+ *
213
+ * @default `{}`
214
+ */
215
+ env?: {
216
+ [envName: string]: RawEnvironment;
217
+ };
218
+ }