wrangler 0.0.0-e3cab74 → 0.0.0-e3d46ab3

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 (158) hide show
  1. package/README.md +47 -16
  2. package/bin/wrangler.js +95 -32
  3. package/config-schema.json +2939 -0
  4. package/kv-asset-handler.js +1 -0
  5. package/package.json +135 -84
  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 +19 -0
  11. package/templates/gitignore +167 -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 +134 -0
  17. package/templates/middleware/loader-sw.ts +229 -0
  18. package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
  19. package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
  20. package/templates/middleware/middleware-pretty-error.ts +40 -0
  21. package/templates/middleware/middleware-scheduled.ts +15 -0
  22. package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
  23. package/templates/middleware/middleware-serve-static-assets.ts +56 -0
  24. package/templates/modules-watch-stub.js +4 -0
  25. package/templates/new-worker-scheduled.js +17 -0
  26. package/templates/new-worker-scheduled.ts +32 -0
  27. package/templates/new-worker.js +3 -3
  28. package/templates/new-worker.ts +22 -4
  29. package/templates/no-op-worker.js +10 -0
  30. package/templates/pages-dev-pipeline.ts +32 -0
  31. package/templates/pages-dev-util.ts +55 -0
  32. package/templates/pages-shim.ts +9 -0
  33. package/templates/pages-template-plugin.ts +190 -0
  34. package/templates/pages-template-worker.ts +198 -0
  35. package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
  36. package/templates/startDevWorker/ProxyWorker.ts +334 -0
  37. package/templates/tsconfig-sanity.ts +11 -0
  38. package/templates/tsconfig.init.json +105 -0
  39. package/templates/tsconfig.json +6 -103
  40. package/wrangler-dist/InspectorProxyWorker.js +464 -0
  41. package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
  42. package/wrangler-dist/ProxyWorker.js +240 -0
  43. package/wrangler-dist/ProxyWorker.js.map +6 -0
  44. package/wrangler-dist/cli.d.ts +24056 -0
  45. package/wrangler-dist/cli.js +199391 -131806
  46. package/wrangler-dist/wasm-sync.wasm +0 -0
  47. package/import_meta_url.js +0 -3
  48. package/miniflare-config-stubs/.env.empty +0 -0
  49. package/miniflare-config-stubs/package.empty.json +0 -1
  50. package/miniflare-config-stubs/wrangler.empty.toml +0 -0
  51. package/pages/functions/buildWorker.ts +0 -62
  52. package/pages/functions/filepath-routing.test.ts +0 -123
  53. package/pages/functions/filepath-routing.ts +0 -178
  54. package/pages/functions/identifiers.ts +0 -78
  55. package/pages/functions/routes.ts +0 -151
  56. package/pages/functions/template-worker.ts +0 -130
  57. package/src/__tests__/configuration.test.ts +0 -2185
  58. package/src/__tests__/dev.test.tsx +0 -113
  59. package/src/__tests__/guess-worker-format.test.ts +0 -66
  60. package/src/__tests__/helpers/clipboardy-mock.js +0 -4
  61. package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
  62. package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
  63. package/src/__tests__/helpers/mock-account-id.ts +0 -30
  64. package/src/__tests__/helpers/mock-bin.ts +0 -36
  65. package/src/__tests__/helpers/mock-cfetch.ts +0 -207
  66. package/src/__tests__/helpers/mock-console.ts +0 -62
  67. package/src/__tests__/helpers/mock-dialogs.ts +0 -65
  68. package/src/__tests__/helpers/mock-kv.ts +0 -40
  69. package/src/__tests__/helpers/mock-user.ts +0 -27
  70. package/src/__tests__/helpers/mock-web-socket.ts +0 -29
  71. package/src/__tests__/helpers/run-in-tmp.ts +0 -29
  72. package/src/__tests__/helpers/run-wrangler.ts +0 -16
  73. package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
  74. package/src/__tests__/index.test.ts +0 -866
  75. package/src/__tests__/jest.setup.ts +0 -57
  76. package/src/__tests__/kv.test.ts +0 -1141
  77. package/src/__tests__/logout.test.ts +0 -50
  78. package/src/__tests__/package-manager.test.ts +0 -206
  79. package/src/__tests__/parse.test.ts +0 -322
  80. package/src/__tests__/publish.test.ts +0 -2406
  81. package/src/__tests__/r2.test.ts +0 -198
  82. package/src/__tests__/secret.test.ts +0 -326
  83. package/src/__tests__/sentry.test.ts +0 -146
  84. package/src/__tests__/tail.test.ts +0 -564
  85. package/src/__tests__/whoami.test.tsx +0 -86
  86. package/src/api/form_data.ts +0 -217
  87. package/src/api/preview.ts +0 -147
  88. package/src/api/worker.ts +0 -186
  89. package/src/bundle.ts +0 -133
  90. package/src/cfetch/index.ts +0 -104
  91. package/src/cfetch/internal.ts +0 -133
  92. package/src/cli.ts +0 -19
  93. package/src/config/README.md +0 -107
  94. package/src/config/config.ts +0 -265
  95. package/src/config/diagnostics.ts +0 -80
  96. package/src/config/environment.ts +0 -305
  97. package/src/config/index.ts +0 -52
  98. package/src/config/validation-helpers.ts +0 -370
  99. package/src/config/validation.ts +0 -1017
  100. package/src/dev.tsx +0 -961
  101. package/src/dialogs.tsx +0 -77
  102. package/src/entry.ts +0 -57
  103. package/src/environment-variables.ts +0 -33
  104. package/src/guess-worker-format.ts +0 -68
  105. package/src/index.tsx +0 -2327
  106. package/src/inspect.ts +0 -609
  107. package/src/kv.tsx +0 -275
  108. package/src/module-collection.ts +0 -170
  109. package/src/open-in-browser.ts +0 -13
  110. package/src/package-manager.ts +0 -126
  111. package/src/pages.tsx +0 -1045
  112. package/src/parse.ts +0 -183
  113. package/src/paths.ts +0 -26
  114. package/src/proxy.ts +0 -376
  115. package/src/publish.ts +0 -368
  116. package/src/r2.ts +0 -50
  117. package/src/reporting.ts +0 -115
  118. package/src/sites.tsx +0 -241
  119. package/src/tail/filters.ts +0 -279
  120. package/src/tail/index.ts +0 -299
  121. package/src/tail/printing.ts +0 -62
  122. package/src/user.tsx +0 -1049
  123. package/src/whoami.tsx +0 -69
  124. package/templates/static-asset-facade.js +0 -47
  125. package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
  126. package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
  127. package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
  128. package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
  129. package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
  130. package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
  131. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
  132. package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
  133. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
  134. package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
  135. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
  136. package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
  137. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
  138. package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
  139. package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
  140. package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
  141. package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
  142. package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
  143. package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
  144. package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
  145. package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
  146. package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
  147. package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
  148. package/vendor/wrangler-mime/CHANGELOG.md +0 -289
  149. package/vendor/wrangler-mime/LICENSE +0 -21
  150. package/vendor/wrangler-mime/Mime.js +0 -97
  151. package/vendor/wrangler-mime/README.md +0 -187
  152. package/vendor/wrangler-mime/cli.js +0 -46
  153. package/vendor/wrangler-mime/index.js +0 -4
  154. package/vendor/wrangler-mime/lite.js +0 -4
  155. package/vendor/wrangler-mime/package.json +0 -52
  156. package/vendor/wrangler-mime/types/other.js +0 -1
  157. package/vendor/wrangler-mime/types/standard.js +0 -1
  158. package/wrangler-dist/cli.js.map +0 -7
@@ -1,104 +0,0 @@
1
- import { URLSearchParams } from "node:url";
2
- import { ParseError } from "../parse";
3
- import { fetchInternal } from "./internal";
4
- import type { RequestInit } from "undici";
5
-
6
- // Check out https://api.cloudflare.com/ for API docs.
7
-
8
- export { getCloudflareAPIBaseURL as getCloudflareApiBaseUrl } from "./internal";
9
-
10
- export interface FetchError {
11
- code: number;
12
- message: string;
13
- }
14
- export interface FetchResult<ResponseType = unknown> {
15
- success: boolean;
16
- result: ResponseType;
17
- errors: FetchError[];
18
- messages: string[];
19
- result_info?: unknown;
20
- }
21
-
22
- export { fetchKVGetValue } from "./internal";
23
-
24
- /**
25
- * Make a fetch request, and extract the `result` from the JSON response.
26
- */
27
- export async function fetchResult<ResponseType>(
28
- resource: string,
29
- init: RequestInit = {},
30
- queryParams?: URLSearchParams
31
- ): Promise<ResponseType> {
32
- const json = await fetchInternal<FetchResult<ResponseType>>(
33
- resource,
34
- init,
35
- queryParams
36
- );
37
- if (json.success) {
38
- return json.result;
39
- } else {
40
- throwFetchError(resource, json);
41
- }
42
- }
43
-
44
- /**
45
- * Make a fetch request for a list of values,
46
- * extracting the `result` from the JSON response,
47
- * and repeating the request if the results are paginated.
48
- */
49
- export async function fetchListResult<ResponseType>(
50
- resource: string,
51
- init: RequestInit = {},
52
- queryParams?: URLSearchParams
53
- ): Promise<ResponseType[]> {
54
- const results: ResponseType[] = [];
55
- let getMoreResults = true;
56
- let cursor: string | undefined;
57
- while (getMoreResults) {
58
- if (cursor) {
59
- queryParams = new URLSearchParams(queryParams);
60
- queryParams.set("cursor", cursor);
61
- }
62
- const json = await fetchInternal<FetchResult<ResponseType[]>>(
63
- resource,
64
- init,
65
- queryParams
66
- );
67
- if (json.success) {
68
- results.push(...json.result);
69
- if (hasCursor(json.result_info)) {
70
- cursor = json.result_info?.cursor;
71
- } else {
72
- getMoreResults = false;
73
- }
74
- } else {
75
- throwFetchError(resource, json);
76
- }
77
- }
78
- return results;
79
- }
80
-
81
- function throwFetchError(
82
- resource: string,
83
- response: FetchResult<unknown>
84
- ): never {
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
- });
91
- // add the first error code directly to this error
92
- // so consumers can use it for specific behaviour
93
- const code = response.errors[0]?.code;
94
- if (code) {
95
- //@ts-expect-error non-standard property on Error
96
- error.code = code;
97
- }
98
- throw error;
99
- }
100
-
101
- function hasCursor(result_info: unknown): result_info is { cursor: string } {
102
- const cursor = (result_info as { cursor: string } | undefined)?.cursor;
103
- return cursor !== undefined && cursor !== null && cursor !== "";
104
- }
@@ -1,133 +0,0 @@
1
- import { fetch } from "undici";
2
- import { getEnvironmentVariableFactory } from "../environment-variables";
3
- import { ParseError, parseJSON } from "../parse";
4
- import { getAPIToken, loginOrRefreshIfRequired } from "../user";
5
- import type { URLSearchParams } from "node:url";
6
- import type { RequestInit, HeadersInit } from "undici";
7
-
8
- /**
9
- * Get the URL to use to access the Cloudflare API.
10
- */
11
- export const getCloudflareAPIBaseURL = getEnvironmentVariableFactory({
12
- variableName: "CLOUDFLARE_API_BASE_URL",
13
- deprecatedName: "CF_API_BASE_URL",
14
- defaultValue: "https://api.cloudflare.com/client/v4",
15
- });
16
-
17
- /**
18
- * Make a fetch request to the Cloudflare API.
19
- *
20
- * This function handles acquiring the API token and logging the caller in, as necessary.
21
- *
22
- * Check out https://api.cloudflare.com/ for API docs.
23
- *
24
- * This function should not be used directly, instead use the functions in `cfetch/index.ts`.
25
- */
26
- export async function fetchInternal<ResponseType>(
27
- resource: string,
28
- init: RequestInit = {},
29
- queryParams?: URLSearchParams
30
- ): Promise<ResponseType> {
31
- await requireLoggedIn();
32
- const apiToken = requireApiToken();
33
- const headers = cloneHeaders(init.headers);
34
- addAuthorizationHeader(headers, apiToken);
35
-
36
- const queryString = queryParams ? `?${queryParams.toString()}` : "";
37
- const method = init.method ?? "GET";
38
- const response = await fetch(
39
- `${getCloudflareAPIBaseURL()}${resource}${queryString}`,
40
- {
41
- method,
42
- ...init,
43
- headers,
44
- }
45
- );
46
- const jsonText = await response.text();
47
- try {
48
- return parseJSON(jsonText) as ResponseType;
49
- } catch (err) {
50
- throw new ParseError({
51
- text: "Received a malformed response from the API",
52
- notes: [
53
- {
54
- text: truncate(jsonText, 100),
55
- },
56
- {
57
- text: `${method} ${resource} -> ${response.status} ${response.statusText}`,
58
- },
59
- ],
60
- });
61
- }
62
- }
63
-
64
- function truncate(text: string, maxLength: number): string {
65
- const { length } = text;
66
- if (length <= maxLength) {
67
- return text;
68
- }
69
- return `${text.substring(0, maxLength)}... (length = ${length})`;
70
- }
71
-
72
- function cloneHeaders(
73
- headers: HeadersInit | undefined
74
- ): Record<string, string> {
75
- return { ...headers };
76
- }
77
-
78
- async function requireLoggedIn(): Promise<void> {
79
- const loggedIn = await loginOrRefreshIfRequired();
80
- if (!loggedIn) {
81
- throw new Error("Not logged in.");
82
- }
83
- }
84
-
85
- function requireApiToken(): string {
86
- const apiToken = getAPIToken();
87
- if (!apiToken) {
88
- throw new Error("No API token found.");
89
- }
90
- return apiToken;
91
- }
92
-
93
- function addAuthorizationHeader(
94
- headers: Record<string, string>,
95
- apiToken: string
96
- ): void {
97
- if ("Authorization" in headers) {
98
- throw new Error(
99
- "The request already specifies an authorisation header - cannot add a new one."
100
- );
101
- }
102
- headers["Authorization"] = `Bearer ${apiToken}`;
103
- }
104
-
105
- /**
106
- * The implementation for fetching a kv value from the cloudflare API.
107
- * We special-case this one call, because it's the only API call that
108
- * doesn't return json. We inline the implementation and try not to share
109
- * any code with the other calls. We should push back on any new APIs that
110
- * try to introduce non-"standard" response structures.
111
- */
112
-
113
- export async function fetchKVGetValue(
114
- accountId: string,
115
- namespaceId: string,
116
- key: string
117
- ): Promise<string> {
118
- await requireLoggedIn();
119
- const apiToken = requireApiToken();
120
- const headers = { Authorization: `Bearer ${apiToken}` };
121
- const resource = `${getCloudflareAPIBaseURL()}/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${key}`;
122
- const response = await fetch(resource, {
123
- method: "GET",
124
- headers,
125
- });
126
- if (response.ok) {
127
- return await response.text();
128
- } else {
129
- throw new Error(
130
- `Failed to fetch ${resource} - ${response.status}: ${response.statusText});`
131
- );
132
- }
133
- }
package/src/cli.ts DELETED
@@ -1,19 +0,0 @@
1
- import process from "process";
2
- import { hideBin } from "yargs/helpers";
3
- import { reportError, initReporting } from "./reporting";
4
- import { main } from ".";
5
-
6
- try {
7
- initReporting();
8
- } catch (error) {}
9
-
10
- process.on("uncaughtExceptionMonitor", async (err, origin) => {
11
- await reportError(err, origin);
12
- });
13
-
14
- main(hideBin(process.argv)).catch(() => {
15
- // The logging of any error that was thrown from `main()` is handled in the `yargs.fail()` handler.
16
- // Here we just want to ensure that the process exits with a non-zero code.
17
- // We don't want to do this inside the `main()` function, since that would kill the process when running our tests.
18
- process.exit(1);
19
- });
@@ -1,107 +0,0 @@
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
- Notably this also contains a property called `env` which is the container for the named environment configuration.
29
-
30
- The `Config` type is the overall configuration, which consists of the `ConfigFields` and also an `Environment`.
31
- In this case the `Environment`, here, corresponds to the top level environment.
32
- 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.
33
- These types should be used when you are working with fields that should be passed to commands.
34
-
35
- ### RawConfig
36
-
37
- The `RawConfig` type is a version of `Config`, where all the fields are optional.
38
- The `RawConfig` type also includes `DeprecatedConfigFields` and extends and contains the `RawEnvironment` type,
39
- which is a version of `Environment` where all the fields are optional.
40
- These optional fields map to the actual fields found in the `wrangler.toml`.
41
- These types should be used when you are working with raw configuration that is read or will be written to a `wrangler.toml`.
42
-
43
- ## Validation
44
-
45
- Validation is triggered by passing a `RawConfig` object to the `normalizeAndValidateConfig()` function.
46
- This function will return:
47
-
48
- - a `Config` object, where all the fields have suitable valid values
49
- - a `Diagnostics` object, which contains any errors or warnings from the validation process
50
-
51
- 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.
52
- Generally, if there are any warnings they should be presented to the user via `console.warn()` messages,
53
- and if there are any errors then an `Error` should be thrown describing these errors.
54
-
55
- The `Diagnostics` object is hierarchical: each `Diagnostics` instance can contain a collection of child `Diagnostics` instance.
56
- When checking for or rendering warnings and errors, the `Diagnostics` class will automatically traverse down to all its children.
57
-
58
- ## Usage
59
-
60
- The [high level API](./index.ts) for configuration processing consists of the `findWranglerToml()` and `readConfig()` functions.
61
-
62
- ### readConfig()
63
-
64
- The `readConfig()` function will find the nearest `wrangler.toml` file, load and parse it, then validate and normalize the values into a `Config` object.
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.
@@ -1,265 +0,0 @@
1
- import type { Environment, RawEnvironment } from "./environment";
2
-
3
- /**
4
- * This is the static type definition for the configuration object.
5
- *
6
- * It reflects 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<Environment> & Environment;
24
-
25
- export type RawConfig = Partial<ConfigFields<RawEnvironment>> &
26
- RawEnvironment &
27
- DeprecatedConfigFields;
28
-
29
- export interface ConfigFields<Env extends RawEnvironment> {
30
- configPath: string | undefined;
31
-
32
- /**
33
- * The entrypoint/path to the JavaScript file that will be executed.
34
- */
35
- main: string | undefined;
36
-
37
- /**
38
- * A boolean to enable "legacy" style wrangler environments (from wrangler 1).
39
- * These have been superseded by Services, but there may be projects that won't
40
- * (or can't) use them. If you're using a legacy environment, you can set this
41
- * to `true` to enable it.
42
- */
43
- legacy_env: boolean;
44
-
45
- /**
46
- * The `env` section defines overrides for the configuration for different environments.
47
- *
48
- * All environment fields can be specified at the top level of the config indicating the default environment settings.
49
- *
50
- * - Some fields are inherited and overridable in each environment.
51
- * - But some are not inherited and must be explicitly specified in every environment, if they are specified at the top level.
52
- *
53
- * For more information, see the documentation at https://developers.cloudflare.com/workers/cli-wrangler/configuration#environments
54
- *
55
- * @default `{}`
56
- */
57
- env: {
58
- [envName: string]: Env;
59
- };
60
-
61
- /**
62
- * Options to configure the development server that your worker will use.
63
- *
64
- * @default `{}`
65
- */
66
- dev: {
67
- /**
68
- * IP address for the local dev server to listen on,
69
- *
70
- * @default `127.0.0.1`
71
- * @todo this needs to be implemented
72
- */
73
- ip?: string;
74
-
75
- /**
76
- * Port for the local dev server to listen on
77
- *
78
- * @default `8787`
79
- */
80
- port?: number;
81
-
82
- /**
83
- * Protocol that local wrangler dev server listens to requests on.
84
- *
85
- * @default `http`
86
- * @todo this needs to be implemented
87
- */
88
- local_protocol?: string;
89
-
90
- /**
91
- * Protocol that wrangler dev forwards requests on
92
- *
93
- * @default `https`
94
- * @todo this needs to be implemented
95
- */
96
- upstream_protocol?: string;
97
- };
98
-
99
- /**
100
- * A list of migrations that should be uploaded with your Worker.
101
- *
102
- * These define changes in your Durable Object declarations.
103
- *
104
- * More details at https://developers.cloudflare.com/workers/learning/using-durable-objects#configuring-durable-object-classes-with-migrations
105
- *
106
- * @default `[]`
107
- */
108
- migrations: {
109
- /** A unique identifier for this migration. */
110
- tag: string;
111
- /** The new Durable Objects being defined. */
112
- new_classes?: string[];
113
- /** The Durable Objects being renamed. */
114
- renamed_classes?: {
115
- from: string;
116
- to: string;
117
- }[];
118
- /** The Durable Objects being removed. */
119
- deleted_classes?: string[];
120
- }[];
121
-
122
- /**
123
- * The definition of a Worker Site, a feature that lets you upload
124
- * static assets with your Worker.
125
- *
126
- * More details at https://developers.cloudflare.com/workers/platform/sites
127
- */
128
- site:
129
- | {
130
- /**
131
- * The directory containing your static assets.
132
- *
133
- * It must be a path relative to your wrangler.toml file.
134
- * Example: bucket = "./public"
135
- *
136
- * If there is a `site` field then it must contain this `bucket` field.
137
- */
138
- bucket: string;
139
-
140
- /**
141
- * The location of your Worker script.
142
- *
143
- * @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.
144
- * @breaking
145
- */
146
- "entry-point"?: string;
147
-
148
- /**
149
- * An exclusive list of .gitignore-style patterns that match file
150
- * or directory names from your bucket location. Only matched
151
- * items will be uploaded. Example: include = ["upload_dir"]
152
- *
153
- * @optional
154
- * @default `[]`
155
- */
156
- include?: string[];
157
-
158
- /**
159
- * A list of .gitignore-style patterns that match files or
160
- * directories in your bucket that should be excluded from
161
- * uploads. Example: exclude = ["ignore_dir"]
162
- *
163
- * @optional
164
- * @default `[]`
165
- */
166
- exclude?: string[];
167
- }
168
- | undefined;
169
-
170
- /**
171
- * A list of wasm modules that your worker should be bound to. This is
172
- * the "legacy" way of binding to a wasm module. ES module workers should
173
- * do proper module imports.
174
- */
175
- wasm_modules:
176
- | {
177
- [key: string]: string;
178
- }
179
- | undefined;
180
-
181
- /**
182
- * A list of text files that your worker should be bound to. This is
183
- * the "legacy" way of binding to a text file. ES module workers should
184
- * do proper module imports.
185
- */
186
- text_blobs:
187
- | {
188
- [key: string]: string;
189
- }
190
- | undefined;
191
-
192
- /**
193
- * Configures a custom build step to be run by Wrangler when building your Worker.
194
- *
195
- * Refer to the [custom builds documentation](https://developers.cloudflare.com/workers/cli-wrangler/configuration#build)
196
- * for more details.
197
- *
198
- * @default {}
199
- */
200
- build: {
201
- /** The command used to build your Worker. On Linux and macOS, the command is executed in the `sh` shell and the `cmd` shell for Windows. The `&&` and `||` shell operators may be used. */
202
- command?: string;
203
- /** The directory in which the command is executed. */
204
- cwd?: string;
205
- /** The directory to watch for changes while using wrangler dev, defaults to the current working directory */
206
- watch_dir?: string;
207
- /** Deprecated field previously used to configure the build and upload of the script. */
208
- upload?: DeprecatedUpload;
209
- };
210
- }
211
-
212
- export interface DeprecatedConfigFields {
213
- /**
214
- * The project "type". A holdover from wrangler 1.x.
215
- * Valid values were "webpack", "javascript", and "rust".
216
- *
217
- * @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.
218
- * @breaking
219
- */
220
- type?: "webpack" | "javascript" | "rust";
221
-
222
- /**
223
- * Path to the webpack config to use when building your worker.
224
- * A holdover from wrangler 1.x, used with `type: "webpack"`.
225
- *
226
- * @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.
227
- * @breaking
228
- */
229
- webpack_config?: string;
230
- }
231
-
232
- /**
233
- * Deprecated upload configuration.
234
- */
235
- export interface DeprecatedUpload {
236
- /**
237
- * The format of the Worker script.
238
- *
239
- * @deprecated We infer the format automatically now.
240
- */
241
- format?: "modules" | "service-worker";
242
-
243
- /**
244
- * The directory you wish to upload your worker from,
245
- * relative to the wrangler.toml file.
246
- *
247
- * Defaults to the directory containing the wrangler.toml file.
248
- *
249
- * @deprecated
250
- * @breaking In wrangler 1, this defaults to ./dist, whereas in wrangler 2 it defaults to ./
251
- */
252
- dir?: string;
253
-
254
- /**
255
- * The path to the Worker script, relative to `upload.dir`.
256
- *
257
- * @deprecated This will be replaced by a command line argument.
258
- */
259
- main?: string;
260
-
261
- /**
262
- * @deprecated This is now defined at the top level `rules` field.
263
- */
264
- rules?: Environment["rules"];
265
- }