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.
- package/Cloudflare_CA.pem +18 -0
- package/README.md +27 -14
- package/bin/wrangler.js +49 -5
- package/miniflare-dist/index.mjs +4886 -0
- package/package.json +43 -28
- package/pages/functions/buildPlugin.ts +105 -0
- package/pages/functions/buildWorker.ts +93 -4
- package/pages/functions/filepath-routing.test.ts +136 -25
- package/pages/functions/filepath-routing.ts +14 -3
- package/pages/functions/routes.ts +6 -1
- package/pages/functions/template-plugin.ts +147 -0
- package/pages/functions/template-worker.ts +21 -8
- package/src/__tests__/config-cache.test.ts +36 -0
- package/src/__tests__/configuration.test.ts +1713 -411
- package/src/__tests__/dev.test.tsx +954 -84
- package/src/__tests__/guess-worker-format.test.ts +37 -18
- package/src/__tests__/helpers/mock-account-id.ts +22 -4
- package/src/__tests__/helpers/mock-cfetch.ts +8 -4
- package/src/__tests__/helpers/mock-console.ts +35 -10
- package/src/__tests__/helpers/mock-dialogs.ts +67 -2
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +27 -0
- package/src/__tests__/helpers/mock-kv.ts +9 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
- package/src/__tests__/helpers/mock-stdin.ts +103 -0
- package/src/__tests__/helpers/run-in-tmp.ts +10 -0
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/https-options.test.ts +130 -0
- package/src/__tests__/index.test.ts +138 -747
- package/src/__tests__/init.test.ts +1637 -0
- package/src/__tests__/jest.setup.ts +28 -8
- package/src/__tests__/kv.test.ts +598 -258
- package/src/__tests__/logger.test.ts +115 -0
- package/src/__tests__/package-manager.test.ts +154 -7
- package/src/__tests__/pages.test.ts +754 -0
- package/src/__tests__/parse.test.ts +8 -0
- package/src/__tests__/publish.test.ts +4374 -1025
- package/src/__tests__/r2.test.ts +69 -34
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +228 -73
- package/src/__tests__/tail.test.ts +146 -20
- package/src/__tests__/user.test.ts +131 -0
- package/src/__tests__/whoami.test.tsx +60 -7
- package/src/abort.d.ts +3 -0
- package/src/bundle.ts +75 -11
- package/src/cfetch/index.ts +21 -4
- package/src/cfetch/internal.ts +29 -20
- package/src/cli.ts +5 -11
- package/src/config/README.md +7 -7
- package/src/config/config.ts +69 -100
- package/src/config/environment.ts +119 -4
- package/src/config/index.ts +177 -4
- package/src/config/validation-helpers.ts +237 -23
- package/src/config/validation.ts +722 -191
- package/src/config-cache.ts +45 -0
- package/src/{api/preview.ts → create-worker-preview.ts} +65 -27
- package/src/{api/form_data.ts → create-worker-upload-form.ts} +55 -18
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +401 -0
- package/src/dev/local.tsx +322 -0
- package/src/dev/remote.tsx +237 -0
- package/src/dev/use-esbuild.ts +118 -0
- package/src/dialogs.tsx +64 -6
- package/src/durable.ts +102 -0
- package/src/entry.ts +279 -14
- package/src/environment-variables.ts +3 -1
- package/src/errors.ts +11 -0
- package/src/https-options.ts +123 -0
- package/src/index.tsx +1386 -867
- package/src/inspect.ts +64 -11
- package/src/intl-polyfill.d.ts +139 -0
- package/src/{kv.tsx → kv.ts} +195 -62
- package/src/logger.ts +66 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +41 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +94 -6
- package/src/open-in-browser.ts +9 -3
- package/src/package-manager.ts +59 -11
- package/src/pages.tsx +1123 -75
- package/src/parse.ts +26 -6
- package/src/proxy.ts +159 -57
- package/src/publish.ts +581 -228
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +130 -45
- package/src/tail/index.ts +2 -2
- package/src/tail/printing.ts +13 -8
- package/src/update-check.ts +19 -0
- package/src/user.tsx +275 -110
- package/src/whoami.tsx +5 -3
- package/src/{api/worker.ts → worker.ts} +24 -29
- package/src/zones.ts +73 -0
- package/templates/gitignore +171 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.ts +16 -1
- package/templates/static-asset-facade.js +1 -5
- package/wrangler-dist/cli.js +104803 -118375
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/__tests__/logout.test.ts +0 -50
- package/src/__tests__/sentry.test.ts +0 -146
- package/src/dev.tsx +0 -961
- package/src/guess-worker-format.ts +0 -68
- package/src/reporting.ts +0 -115
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
- package/wrangler-dist/cli.js.map +0 -7
package/src/cfetch/internal.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { fetch, Headers } from "undici";
|
|
3
|
+
import { version as wranglerVersion } from "../../package.json";
|
|
2
4
|
import { getEnvironmentVariableFactory } from "../environment-variables";
|
|
3
5
|
import { ParseError, parseJSON } from "../parse";
|
|
4
|
-
import {
|
|
6
|
+
import { loginOrRefreshIfRequired, requireApiToken } from "../user";
|
|
5
7
|
import type { URLSearchParams } from "node:url";
|
|
6
8
|
import type { RequestInit, HeadersInit } from "undici";
|
|
7
9
|
|
|
@@ -26,12 +28,18 @@ export const getCloudflareAPIBaseURL = getEnvironmentVariableFactory({
|
|
|
26
28
|
export async function fetchInternal<ResponseType>(
|
|
27
29
|
resource: string,
|
|
28
30
|
init: RequestInit = {},
|
|
29
|
-
queryParams?: URLSearchParams
|
|
31
|
+
queryParams?: URLSearchParams,
|
|
32
|
+
abortSignal?: AbortSignal
|
|
30
33
|
): Promise<ResponseType> {
|
|
34
|
+
assert(
|
|
35
|
+
resource.startsWith("/"),
|
|
36
|
+
`CF API fetch - resource path must start with a "/" but got "${resource}"`
|
|
37
|
+
);
|
|
31
38
|
await requireLoggedIn();
|
|
32
39
|
const apiToken = requireApiToken();
|
|
33
40
|
const headers = cloneHeaders(init.headers);
|
|
34
|
-
|
|
41
|
+
addAuthorizationHeaderIfUnspecified(headers, apiToken);
|
|
42
|
+
addUserAgent(headers);
|
|
35
43
|
|
|
36
44
|
const queryString = queryParams ? `?${queryParams.toString()}` : "";
|
|
37
45
|
const method = init.method ?? "GET";
|
|
@@ -41,11 +49,12 @@ export async function fetchInternal<ResponseType>(
|
|
|
41
49
|
method,
|
|
42
50
|
...init,
|
|
43
51
|
headers,
|
|
52
|
+
signal: abortSignal,
|
|
44
53
|
}
|
|
45
54
|
);
|
|
46
55
|
const jsonText = await response.text();
|
|
47
56
|
try {
|
|
48
|
-
return parseJSON(jsonText)
|
|
57
|
+
return parseJSON<ResponseType>(jsonText);
|
|
49
58
|
} catch (err) {
|
|
50
59
|
throw new ParseError({
|
|
51
60
|
text: "Received a malformed response from the API",
|
|
@@ -72,7 +81,11 @@ function truncate(text: string, maxLength: number): string {
|
|
|
72
81
|
function cloneHeaders(
|
|
73
82
|
headers: HeadersInit | undefined
|
|
74
83
|
): Record<string, string> {
|
|
75
|
-
return
|
|
84
|
+
return headers instanceof Headers
|
|
85
|
+
? Object.fromEntries(headers.entries())
|
|
86
|
+
: Array.isArray(headers)
|
|
87
|
+
? Object.fromEntries(headers)
|
|
88
|
+
: { ...headers };
|
|
76
89
|
}
|
|
77
90
|
|
|
78
91
|
async function requireLoggedIn(): Promise<void> {
|
|
@@ -82,24 +95,17 @@ async function requireLoggedIn(): Promise<void> {
|
|
|
82
95
|
}
|
|
83
96
|
}
|
|
84
97
|
|
|
85
|
-
function
|
|
86
|
-
const apiToken = getAPIToken();
|
|
87
|
-
if (!apiToken) {
|
|
88
|
-
throw new Error("No API token found.");
|
|
89
|
-
}
|
|
90
|
-
return apiToken;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function addAuthorizationHeader(
|
|
98
|
+
function addAuthorizationHeaderIfUnspecified(
|
|
94
99
|
headers: Record<string, string>,
|
|
95
100
|
apiToken: string
|
|
96
101
|
): void {
|
|
97
|
-
if ("Authorization" in headers) {
|
|
98
|
-
|
|
99
|
-
"The request already specifies an authorisation header - cannot add a new one."
|
|
100
|
-
);
|
|
102
|
+
if (!("Authorization" in headers)) {
|
|
103
|
+
headers["Authorization"] = `Bearer ${apiToken}`;
|
|
101
104
|
}
|
|
102
|
-
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function addUserAgent(headers: Record<string, string>): void {
|
|
108
|
+
headers["User-Agent"] = `wrangler/${wranglerVersion}`;
|
|
103
109
|
}
|
|
104
110
|
|
|
105
111
|
/**
|
|
@@ -108,6 +114,9 @@ function addAuthorizationHeader(
|
|
|
108
114
|
* doesn't return json. We inline the implementation and try not to share
|
|
109
115
|
* any code with the other calls. We should push back on any new APIs that
|
|
110
116
|
* try to introduce non-"standard" response structures.
|
|
117
|
+
*
|
|
118
|
+
* Note: any calls to fetchKVGetValue must call encodeURIComponent on key
|
|
119
|
+
* before passing it
|
|
111
120
|
*/
|
|
112
121
|
|
|
113
122
|
export async function fetchKVGetValue(
|
package/src/cli.ts
CHANGED
|
@@ -1,19 +1,13 @@
|
|
|
1
|
+
import "dotenv/config"; // Grab locally specified env params from a `.env` file.
|
|
1
2
|
import process from "process";
|
|
2
3
|
import { hideBin } from "yargs/helpers";
|
|
3
|
-
import {
|
|
4
|
+
import { FatalError } from "./errors";
|
|
4
5
|
import { main } from ".";
|
|
5
6
|
|
|
6
|
-
|
|
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(() => {
|
|
7
|
+
main(hideBin(process.argv)).catch((e) => {
|
|
15
8
|
// The logging of any error that was thrown from `main()` is handled in the `yargs.fail()` handler.
|
|
16
9
|
// Here we just want to ensure that the process exits with a non-zero code.
|
|
17
10
|
// We don't want to do this inside the `main()` function, since that would kill the process when running our tests.
|
|
18
|
-
|
|
11
|
+
const exitCode = (e instanceof FatalError && e.code) || 1;
|
|
12
|
+
process.exit(exitCode);
|
|
19
13
|
});
|
package/src/config/README.md
CHANGED
|
@@ -25,31 +25,30 @@ This includes the `EnvironmentInheritable` and `EnvironmentNonInheritable` field
|
|
|
25
25
|
### Config
|
|
26
26
|
|
|
27
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
28
|
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
|
|
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.
|
|
32
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.
|
|
33
32
|
These types should be used when you are working with fields that should be passed to commands.
|
|
34
33
|
|
|
35
34
|
### RawConfig
|
|
36
35
|
|
|
37
36
|
The `RawConfig` type is a version of `Config`, where all the fields are optional.
|
|
38
|
-
The `RawConfig` type
|
|
39
|
-
which is a version of `Environment` 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.
|
|
40
39
|
These optional fields map to the actual fields found in the `wrangler.toml`.
|
|
41
40
|
These types should be used when you are working with raw configuration that is read or will be written to a `wrangler.toml`.
|
|
42
41
|
|
|
43
42
|
## Validation
|
|
44
43
|
|
|
45
|
-
Validation is triggered by passing a `RawConfig` object to the `normalizeAndValidateConfig()` function.
|
|
44
|
+
Validation is triggered by passing a `RawConfig` object, and the active environment name, to the `normalizeAndValidateConfig()` function.
|
|
46
45
|
This function will return:
|
|
47
46
|
|
|
48
47
|
- a `Config` object, where all the fields have suitable valid values
|
|
49
48
|
- a `Diagnostics` object, which contains any errors or warnings from the validation process
|
|
50
49
|
|
|
51
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.
|
|
52
|
-
Generally, if there are any warnings they should be presented to the user via `
|
|
51
|
+
Generally, if there are any warnings they should be presented to the user via `logger.warn()` messages,
|
|
53
52
|
and if there are any errors then an `Error` should be thrown describing these errors.
|
|
54
53
|
|
|
55
54
|
The `Diagnostics` object is hierarchical: each `Diagnostics` instance can contain a collection of child `Diagnostics` instance.
|
|
@@ -62,6 +61,7 @@ The [high level API](./index.ts) for configuration processing consists of the `f
|
|
|
62
61
|
### readConfig()
|
|
63
62
|
|
|
64
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
65
|
If there are validation errors then it will throw a suitable error.
|
|
66
66
|
|
|
67
67
|
## Changing configuration
|
package/src/config/config.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Environment, RawEnvironment } from "./environment";
|
|
|
3
3
|
/**
|
|
4
4
|
* This is the static type definition for the configuration object.
|
|
5
5
|
*
|
|
6
|
-
* It reflects the configuration that you can write in wrangler.toml,
|
|
6
|
+
* It reflects a normalized and validated version of the configuration that you can write in wrangler.toml,
|
|
7
7
|
* and optionally augment with arguments passed directly to wrangler.
|
|
8
8
|
*
|
|
9
9
|
* For more information about the configuration object, see the
|
|
@@ -20,20 +20,16 @@ import type { Environment, RawEnvironment } from "./environment";
|
|
|
20
20
|
* - `@breaking`: the deprecation/optionality is a breaking change from wrangler 1.
|
|
21
21
|
* - `@todo`: there's more work to be done (with details attached).
|
|
22
22
|
*/
|
|
23
|
-
export type Config = ConfigFields<
|
|
23
|
+
export type Config = ConfigFields<DevConfig> & Environment;
|
|
24
24
|
|
|
25
|
-
export type RawConfig = Partial<ConfigFields<
|
|
25
|
+
export type RawConfig = Partial<ConfigFields<RawDevConfig>> &
|
|
26
26
|
RawEnvironment &
|
|
27
|
-
DeprecatedConfigFields
|
|
27
|
+
DeprecatedConfigFields &
|
|
28
|
+
EnvironmentMap;
|
|
28
29
|
|
|
29
|
-
export interface ConfigFields<
|
|
30
|
+
export interface ConfigFields<Dev extends RawDevConfig> {
|
|
30
31
|
configPath: string | undefined;
|
|
31
32
|
|
|
32
|
-
/**
|
|
33
|
-
* The entrypoint/path to the JavaScript file that will be executed.
|
|
34
|
-
*/
|
|
35
|
-
main: string | undefined;
|
|
36
|
-
|
|
37
33
|
/**
|
|
38
34
|
* A boolean to enable "legacy" style wrangler environments (from wrangler 1).
|
|
39
35
|
* These have been superseded by Services, but there may be projects that won't
|
|
@@ -42,59 +38,10 @@ export interface ConfigFields<Env extends RawEnvironment> {
|
|
|
42
38
|
*/
|
|
43
39
|
legacy_env: boolean;
|
|
44
40
|
|
|
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
41
|
/**
|
|
62
42
|
* Options to configure the development server that your worker will use.
|
|
63
|
-
*
|
|
64
|
-
* @default `{}`
|
|
65
43
|
*/
|
|
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
|
-
};
|
|
44
|
+
dev: Dev;
|
|
98
45
|
|
|
99
46
|
/**
|
|
100
47
|
* A list of migrations that should be uploaded with your Worker.
|
|
@@ -190,25 +137,58 @@ export interface ConfigFields<Env extends RawEnvironment> {
|
|
|
190
137
|
| undefined;
|
|
191
138
|
|
|
192
139
|
/**
|
|
193
|
-
*
|
|
140
|
+
* A list of data files that your worker should be bound to. This is
|
|
141
|
+
* the "legacy" way of binding to a data file. ES module workers should
|
|
142
|
+
* do proper module imports.
|
|
143
|
+
*/
|
|
144
|
+
data_blobs:
|
|
145
|
+
| {
|
|
146
|
+
[key: string]: string;
|
|
147
|
+
}
|
|
148
|
+
| undefined;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export interface DevConfig {
|
|
152
|
+
/**
|
|
153
|
+
* IP address for the local dev server to listen on,
|
|
154
|
+
*
|
|
155
|
+
* @default `localhost`
|
|
156
|
+
*/
|
|
157
|
+
ip: string;
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Port for the local dev server to listen on
|
|
194
161
|
*
|
|
195
|
-
*
|
|
196
|
-
|
|
162
|
+
* @default `8787`
|
|
163
|
+
*/
|
|
164
|
+
port: number | undefined;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Protocol that local wrangler dev server listens to requests on.
|
|
197
168
|
*
|
|
198
|
-
* @default
|
|
169
|
+
* @default `http`
|
|
199
170
|
*/
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
171
|
+
local_protocol: "http" | "https";
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Protocol that wrangler dev forwards requests on
|
|
175
|
+
*
|
|
176
|
+
* Setting this to `http` is not currently implemented.
|
|
177
|
+
* See https://github.com/cloudflare/wrangler2/issues/583
|
|
178
|
+
*
|
|
179
|
+
* @default `https`
|
|
180
|
+
* @todo this needs to be implemented https://github.com/cloudflare/wrangler2/issues/583
|
|
181
|
+
*/
|
|
182
|
+
upstream_protocol: "https" | "http";
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Host to forward requests to, defaults to the host of the first route of project
|
|
186
|
+
*/
|
|
187
|
+
host: string | undefined;
|
|
210
188
|
}
|
|
211
189
|
|
|
190
|
+
export type RawDevConfig = Partial<DevConfig>;
|
|
191
|
+
|
|
212
192
|
export interface DeprecatedConfigFields {
|
|
213
193
|
/**
|
|
214
194
|
* The project "type". A holdover from wrangler 1.x.
|
|
@@ -227,39 +207,28 @@ export interface DeprecatedConfigFields {
|
|
|
227
207
|
* @breaking
|
|
228
208
|
*/
|
|
229
209
|
webpack_config?: string;
|
|
230
|
-
}
|
|
231
210
|
|
|
232
|
-
/**
|
|
233
|
-
* Deprecated upload configuration.
|
|
234
|
-
*/
|
|
235
|
-
export interface DeprecatedUpload {
|
|
236
211
|
/**
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
* @deprecated We infer the format automatically now.
|
|
212
|
+
* Configuration only used by a standalone use of the miniflare binary.
|
|
213
|
+
* @deprecated
|
|
240
214
|
*/
|
|
241
|
-
|
|
215
|
+
miniflare?: unknown;
|
|
216
|
+
}
|
|
242
217
|
|
|
218
|
+
interface EnvironmentMap {
|
|
243
219
|
/**
|
|
244
|
-
* The
|
|
245
|
-
* relative to the wrangler.toml file.
|
|
220
|
+
* The `env` section defines overrides for the configuration for different environments.
|
|
246
221
|
*
|
|
247
|
-
*
|
|
222
|
+
* All environment fields can be specified at the top level of the config indicating the default environment settings.
|
|
248
223
|
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*/
|
|
252
|
-
dir?: string;
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* The path to the Worker script, relative to `upload.dir`.
|
|
224
|
+
* - Some fields are inherited and overridable in each environment.
|
|
225
|
+
* - But some are not inherited and must be explicitly specified in every environment, if they are specified at the top level.
|
|
256
226
|
*
|
|
257
|
-
*
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* @deprecated This is now defined at the top level `rules` field.
|
|
227
|
+
* For more information, see the documentation at https://developers.cloudflare.com/workers/cli-wrangler/configuration#environments
|
|
228
|
+
*
|
|
229
|
+
* @default `{}`
|
|
263
230
|
*/
|
|
264
|
-
|
|
231
|
+
env?: {
|
|
232
|
+
[envName: string]: RawEnvironment;
|
|
233
|
+
};
|
|
265
234
|
}
|
|
@@ -8,6 +8,24 @@ export interface Environment
|
|
|
8
8
|
extends EnvironmentInheritable,
|
|
9
9
|
EnvironmentNonInheritable {}
|
|
10
10
|
|
|
11
|
+
export type SimpleRoute = string;
|
|
12
|
+
export type ZoneIdRoute = {
|
|
13
|
+
pattern: string;
|
|
14
|
+
zone_id: string;
|
|
15
|
+
custom_domain?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type ZoneNameRoute = {
|
|
18
|
+
pattern: string;
|
|
19
|
+
zone_name: string;
|
|
20
|
+
custom_domain?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export type CustomDomainRoute = { pattern: string; custom_domain: boolean };
|
|
23
|
+
export type Route =
|
|
24
|
+
| SimpleRoute
|
|
25
|
+
| ZoneIdRoute
|
|
26
|
+
| ZoneNameRoute
|
|
27
|
+
| CustomDomainRoute;
|
|
28
|
+
|
|
11
29
|
/**
|
|
12
30
|
* The `EnvironmentInheritable` interface declares all the configuration fields for an environment
|
|
13
31
|
* that can be inherited (and overridden) from the top-level environment.
|
|
@@ -51,6 +69,11 @@ interface EnvironmentInheritable {
|
|
|
51
69
|
*/
|
|
52
70
|
compatibility_flags: string[];
|
|
53
71
|
|
|
72
|
+
/**
|
|
73
|
+
* The entrypoint/path to the JavaScript file that will be executed.
|
|
74
|
+
*/
|
|
75
|
+
main: string | undefined;
|
|
76
|
+
|
|
54
77
|
/**
|
|
55
78
|
* Whether we use <name>.<subdomain>.workers.dev to
|
|
56
79
|
* test and deploy your worker.
|
|
@@ -59,7 +82,7 @@ interface EnvironmentInheritable {
|
|
|
59
82
|
* @breaking
|
|
60
83
|
* @inheritable
|
|
61
84
|
*/
|
|
62
|
-
workers_dev: boolean;
|
|
85
|
+
workers_dev: boolean | undefined;
|
|
63
86
|
|
|
64
87
|
/**
|
|
65
88
|
* A list of routes that your worker should be published to.
|
|
@@ -69,7 +92,7 @@ interface EnvironmentInheritable {
|
|
|
69
92
|
*
|
|
70
93
|
* @inheritable
|
|
71
94
|
*/
|
|
72
|
-
routes:
|
|
95
|
+
routes: Route[] | undefined;
|
|
73
96
|
|
|
74
97
|
/**
|
|
75
98
|
* A route that your worker should be published to. Literally
|
|
@@ -80,7 +103,12 @@ interface EnvironmentInheritable {
|
|
|
80
103
|
*
|
|
81
104
|
* @inheritable
|
|
82
105
|
*/
|
|
83
|
-
route:
|
|
106
|
+
route: Route | undefined;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Path to a custom tsconfig
|
|
110
|
+
*/
|
|
111
|
+
tsconfig: string | undefined;
|
|
84
112
|
|
|
85
113
|
/**
|
|
86
114
|
* The function to use to replace jsx syntax.
|
|
@@ -121,7 +149,7 @@ interface EnvironmentInheritable {
|
|
|
121
149
|
*
|
|
122
150
|
* @inheritable
|
|
123
151
|
*/
|
|
124
|
-
usage_model:
|
|
152
|
+
usage_model: "bundled" | "unbound" | undefined;
|
|
125
153
|
|
|
126
154
|
/**
|
|
127
155
|
* An ordered list of rules that define which modules to import,
|
|
@@ -133,6 +161,39 @@ interface EnvironmentInheritable {
|
|
|
133
161
|
*/
|
|
134
162
|
rules: Rule[];
|
|
135
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Configures a custom build step to be run by Wrangler when building your Worker.
|
|
166
|
+
*
|
|
167
|
+
* Refer to the [custom builds documentation](https://developers.cloudflare.com/workers/cli-wrangler/configuration#build)
|
|
168
|
+
* for more details.
|
|
169
|
+
*
|
|
170
|
+
* @default {}
|
|
171
|
+
*/
|
|
172
|
+
build: {
|
|
173
|
+
/** 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. */
|
|
174
|
+
command?: string;
|
|
175
|
+
/** The directory in which the command is executed. */
|
|
176
|
+
cwd?: string;
|
|
177
|
+
/** The directory to watch for changes while using wrangler dev, defaults to the current working directory */
|
|
178
|
+
watch_dir?: string | string[];
|
|
179
|
+
/**
|
|
180
|
+
* Deprecated field previously used to configure the build and upload of the script.
|
|
181
|
+
* @deprecated
|
|
182
|
+
*/
|
|
183
|
+
upload?: DeprecatedUpload;
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Minify the script before uploading.
|
|
188
|
+
* @inheritable
|
|
189
|
+
*/
|
|
190
|
+
minify: boolean | undefined;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Add polyfills for node builtin modules and globals
|
|
194
|
+
*/
|
|
195
|
+
node_compat: boolean | undefined;
|
|
196
|
+
|
|
136
197
|
/**
|
|
137
198
|
* TODO: remove this as it has been deprecated.
|
|
138
199
|
*
|
|
@@ -181,6 +242,8 @@ interface EnvironmentNonInheritable {
|
|
|
181
242
|
class_name: string;
|
|
182
243
|
/** The script where the Durable Object is defined (if it's external to this worker) */
|
|
183
244
|
script_name?: string;
|
|
245
|
+
/** The service environment of the script_name to bind to */
|
|
246
|
+
environment?: string;
|
|
184
247
|
}[];
|
|
185
248
|
};
|
|
186
249
|
|
|
@@ -224,6 +287,24 @@ interface EnvironmentNonInheritable {
|
|
|
224
287
|
preview_bucket_name?: string;
|
|
225
288
|
}[];
|
|
226
289
|
|
|
290
|
+
/**
|
|
291
|
+
* Specifies service bindings (worker-to-worker) that are bound to this Worker environment.
|
|
292
|
+
*
|
|
293
|
+
* NOTE: This field is not automatically inherited from the top level environment,
|
|
294
|
+
* and so must be specified in every named environment.
|
|
295
|
+
*
|
|
296
|
+
* @default `[]`
|
|
297
|
+
* @nonInheritable
|
|
298
|
+
*/
|
|
299
|
+
services: {
|
|
300
|
+
/** The binding name used to refer to the bound service. */
|
|
301
|
+
binding: string;
|
|
302
|
+
/** The name of the service. */
|
|
303
|
+
service: string;
|
|
304
|
+
/** The environment of the service (e.g. production, staging, etc). */
|
|
305
|
+
environment?: string;
|
|
306
|
+
}[];
|
|
307
|
+
|
|
227
308
|
/**
|
|
228
309
|
* "Unsafe" tables for features that aren't directly supported by wrangler.
|
|
229
310
|
*
|
|
@@ -277,6 +358,40 @@ interface EnvironmentDeprecated {
|
|
|
277
358
|
}[];
|
|
278
359
|
}
|
|
279
360
|
|
|
361
|
+
/**
|
|
362
|
+
* Deprecated upload configuration.
|
|
363
|
+
*/
|
|
364
|
+
export interface DeprecatedUpload {
|
|
365
|
+
/**
|
|
366
|
+
* The format of the Worker script.
|
|
367
|
+
*
|
|
368
|
+
* @deprecated We infer the format automatically now.
|
|
369
|
+
*/
|
|
370
|
+
format?: "modules" | "service-worker";
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* The directory you wish to upload your worker from,
|
|
374
|
+
* relative to the wrangler.toml file.
|
|
375
|
+
*
|
|
376
|
+
* Defaults to the directory containing the wrangler.toml file.
|
|
377
|
+
*
|
|
378
|
+
* @deprecated
|
|
379
|
+
*/
|
|
380
|
+
dir?: string;
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* The path to the Worker script, relative to `upload.dir`.
|
|
384
|
+
*
|
|
385
|
+
* @deprecated This will be replaced by a command line argument.
|
|
386
|
+
*/
|
|
387
|
+
main?: string;
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* @deprecated This is now defined at the top level `rules` field.
|
|
391
|
+
*/
|
|
392
|
+
rules?: Environment["rules"];
|
|
393
|
+
}
|
|
394
|
+
|
|
280
395
|
/**
|
|
281
396
|
* The raw environment configuration that we read from the config file.
|
|
282
397
|
*
|