wrangler 0.0.0-e043479 → 0.0.0-e09abbc
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 +33 -14
- package/bin/wrangler.js +160 -28
- package/kv-asset-handler.js +1 -0
- package/miniflare-dist/index.mjs +5354 -0
- package/package.json +166 -136
- package/src/__tests__/config-cache-without-cache-dir.test.ts +38 -0
- package/src/__tests__/config-cache.test.ts +42 -0
- package/src/__tests__/configuration.test.ts +3942 -2178
- package/src/__tests__/dev.test.tsx +1191 -235
- package/src/__tests__/guess-worker-format.test.ts +76 -57
- package/src/__tests__/helpers/cmd-shim.d.ts +6 -6
- package/src/__tests__/helpers/mock-account-id.ts +26 -22
- package/src/__tests__/helpers/mock-bin.ts +20 -20
- package/src/__tests__/helpers/mock-cfetch.ts +96 -92
- package/src/__tests__/helpers/mock-console.ts +59 -32
- package/src/__tests__/helpers/mock-dialogs.ts +121 -33
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +74 -0
- package/src/__tests__/helpers/mock-kv.ts +28 -35
- package/src/__tests__/helpers/mock-oauth-flow.ts +250 -0
- package/src/__tests__/helpers/mock-process.ts +39 -0
- package/src/__tests__/helpers/mock-stdin.ts +82 -77
- package/src/__tests__/helpers/mock-web-socket.ts +21 -21
- package/src/__tests__/helpers/run-in-tmp.ts +29 -20
- package/src/__tests__/helpers/run-wrangler.ts +8 -8
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +9 -9
- package/src/__tests__/https-options.test.ts +163 -0
- package/src/__tests__/index.test.ts +246 -850
- package/src/__tests__/init.test.ts +1992 -0
- package/src/__tests__/jest.setup.ts +85 -34
- package/src/__tests__/kv.test.ts +1402 -1139
- package/src/__tests__/logger.test.ts +141 -0
- package/src/__tests__/metrics.test.ts +445 -0
- package/src/__tests__/package-manager.test.ts +312 -165
- package/src/__tests__/pages.test.ts +1261 -0
- package/src/__tests__/parse.test.ts +253 -245
- package/src/__tests__/publish.test.ts +6611 -2079
- package/src/__tests__/pubsub.test.ts +367 -0
- package/src/__tests__/r2.test.ts +184 -149
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +474 -407
- package/src/__tests__/tail.test.ts +565 -431
- package/src/__tests__/test-old-node-version.js +31 -0
- package/src/__tests__/user.test.ts +143 -0
- package/src/__tests__/whoami.test.tsx +219 -75
- package/src/__tests__/worker-namespace.test.ts +327 -0
- package/src/abort.d.ts +3 -0
- package/src/api/dev.ts +86 -0
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +29 -0
- package/src/bundle.ts +196 -93
- package/src/cfetch/index.ts +83 -66
- package/src/cfetch/internal.ts +100 -84
- package/src/cli.ts +22 -14
- package/src/config/README.md +7 -7
- package/src/config/config.ts +223 -242
- package/src/config/diagnostics.ts +61 -61
- package/src/config/environment.ts +404 -256
- package/src/config/index.ts +218 -32
- package/src/config/validation-helpers.ts +436 -222
- package/src/config/validation.ts +1642 -907
- package/src/config-cache.ts +84 -0
- package/src/create-worker-preview.ts +255 -0
- package/src/create-worker-upload-form.ts +263 -0
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +452 -0
- package/src/dev/local.tsx +373 -0
- package/src/dev/remote.tsx +386 -0
- package/src/dev/use-esbuild.ts +150 -0
- package/src/dev.tsx +576 -943
- package/src/dialogs.tsx +115 -57
- package/src/durable.ts +102 -0
- package/src/entry.ts +308 -37
- package/src/environment-variables.ts +25 -23
- package/src/errors.ts +11 -0
- package/src/faye-websocket.d.ts +6 -0
- package/src/generate.ts +33 -0
- package/src/git-client.ts +42 -0
- package/src/global-wrangler-config-path.ts +26 -0
- package/src/https-options.ts +127 -0
- package/src/index.tsx +1910 -2241
- package/src/init.ts +549 -0
- package/src/inspect.ts +603 -550
- package/src/intl-polyfill.d.ts +139 -0
- package/src/is-interactive.ts +12 -0
- package/src/kv.ts +430 -0
- package/src/logger.ts +73 -0
- package/src/metrics/index.ts +4 -0
- package/src/metrics/is-ci.ts +14 -0
- package/src/metrics/metrics-config.ts +239 -0
- package/src/metrics/metrics-dispatcher.ts +95 -0
- package/src/metrics/send-event.ts +92 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/assets.ts +543 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +85 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +234 -146
- package/src/open-in-browser.ts +10 -6
- package/src/package-manager.ts +183 -90
- package/src/pages/build.tsx +204 -0
- package/src/pages/constants.ts +7 -0
- package/src/pages/deployments.tsx +106 -0
- package/src/pages/dev.tsx +401 -0
- package/src/pages/functions/buildPlugin.ts +105 -0
- package/src/pages/functions/buildWorker.ts +151 -0
- package/src/pages/functions/filepath-routing.test.ts +234 -0
- package/src/pages/functions/filepath-routing.ts +189 -0
- package/src/pages/functions/identifiers.ts +78 -0
- package/src/pages/functions/routes.ts +151 -0
- package/src/pages/index.tsx +84 -0
- package/src/pages/projects.tsx +163 -0
- package/src/pages/publish.tsx +338 -0
- package/src/pages/types.ts +40 -0
- package/src/pages/upload.tsx +396 -0
- package/src/pages/utils.ts +12 -0
- package/src/parse.ts +224 -121
- package/src/paths.ts +6 -6
- package/src/preview.ts +31 -0
- package/src/proxy.ts +413 -313
- package/src/publish.ts +773 -343
- package/src/pubsub/index.ts +286 -0
- package/src/pubsub/pubsub-commands.tsx +623 -0
- package/src/r2.ts +19 -19
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +285 -151
- package/src/tail/filters.ts +108 -108
- package/src/tail/index.ts +217 -217
- package/src/tail/printing.ts +51 -46
- package/src/update-check.ts +19 -0
- package/src/user/choose-account.tsx +69 -0
- package/src/user/env-vars.ts +46 -0
- package/src/user/generate-auth-url.ts +33 -0
- package/src/user/generate-random-state.ts +16 -0
- package/src/user/index.ts +3 -0
- package/src/user/user.tsx +1171 -0
- package/src/whoami.tsx +63 -41
- package/src/worker-namespace.ts +206 -0
- package/src/worker.ts +191 -0
- package/src/zones.ts +76 -0
- package/templates/checked-fetch.js +17 -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.js +3 -3
- package/templates/new-worker.ts +18 -3
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-shim.ts +9 -0
- package/templates/pages-template-plugin.ts +155 -0
- package/templates/pages-template-worker.ts +161 -0
- package/templates/static-asset-facade.js +38 -36
- package/templates/tsconfig.json +95 -95
- package/wrangler-dist/cli.d.ts +327 -0
- package/wrangler-dist/cli.js +94947 -111199
- package/pages/functions/buildWorker.ts +0 -62
- package/pages/functions/filepath-routing.test.ts +0 -123
- package/pages/functions/filepath-routing.ts +0 -178
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -151
- package/pages/functions/template-worker.ts +0 -130
- package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
- 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/api/form_data.ts +0 -217
- package/src/api/preview.ts +0 -147
- package/src/api/worker.ts +0 -186
- package/src/guess-worker-format.ts +0 -68
- package/src/kv.tsx +0 -339
- package/src/pages.tsx +0 -1045
- package/src/reporting.ts +0 -115
- package/src/user.tsx +0 -1063
- 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,10 @@
|
|
|
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";
|
|
7
|
+
import type { ApiCredentials } from "../user";
|
|
5
8
|
import type { URLSearchParams } from "node:url";
|
|
6
9
|
import type { RequestInit, HeadersInit } from "undici";
|
|
7
10
|
|
|
@@ -9,9 +12,9 @@ import type { RequestInit, HeadersInit } from "undici";
|
|
|
9
12
|
* Get the URL to use to access the Cloudflare API.
|
|
10
13
|
*/
|
|
11
14
|
export const getCloudflareAPIBaseURL = getEnvironmentVariableFactory({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
variableName: "CLOUDFLARE_API_BASE_URL",
|
|
16
|
+
deprecatedName: "CF_API_BASE_URL",
|
|
17
|
+
defaultValue: "https://api.cloudflare.com/client/v4",
|
|
15
18
|
});
|
|
16
19
|
|
|
17
20
|
/**
|
|
@@ -24,82 +27,91 @@ export const getCloudflareAPIBaseURL = getEnvironmentVariableFactory({
|
|
|
24
27
|
* This function should not be used directly, instead use the functions in `cfetch/index.ts`.
|
|
25
28
|
*/
|
|
26
29
|
export async function fetchInternal<ResponseType>(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
resource: string,
|
|
31
|
+
init: RequestInit = {},
|
|
32
|
+
queryParams?: URLSearchParams,
|
|
33
|
+
abortSignal?: AbortSignal
|
|
30
34
|
): Promise<ResponseType> {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
assert(
|
|
36
|
+
resource.startsWith("/"),
|
|
37
|
+
`CF API fetch - resource path must start with a "/" but got "${resource}"`
|
|
38
|
+
);
|
|
39
|
+
await requireLoggedIn();
|
|
40
|
+
const apiToken = requireApiToken();
|
|
41
|
+
const headers = cloneHeaders(init.headers);
|
|
42
|
+
addAuthorizationHeaderIfUnspecified(headers, apiToken);
|
|
43
|
+
addUserAgent(headers);
|
|
35
44
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
45
|
+
const queryString = queryParams ? `?${queryParams.toString()}` : "";
|
|
46
|
+
const method = init.method ?? "GET";
|
|
47
|
+
const response = await fetch(
|
|
48
|
+
`${getCloudflareAPIBaseURL()}${resource}${queryString}`,
|
|
49
|
+
{
|
|
50
|
+
method,
|
|
51
|
+
...init,
|
|
52
|
+
headers,
|
|
53
|
+
signal: abortSignal,
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
const jsonText = await response.text();
|
|
57
|
+
try {
|
|
58
|
+
return parseJSON<ResponseType>(jsonText);
|
|
59
|
+
} catch (err) {
|
|
60
|
+
throw new ParseError({
|
|
61
|
+
text: "Received a malformed response from the API",
|
|
62
|
+
notes: [
|
|
63
|
+
{
|
|
64
|
+
text: truncate(jsonText, 100),
|
|
65
|
+
},
|
|
66
|
+
{
|
|
67
|
+
text: `${method} ${resource} -> ${response.status} ${response.statusText}`,
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
});
|
|
71
|
+
}
|
|
62
72
|
}
|
|
63
73
|
|
|
64
74
|
function truncate(text: string, maxLength: number): string {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
75
|
+
const { length } = text;
|
|
76
|
+
if (length <= maxLength) {
|
|
77
|
+
return text;
|
|
78
|
+
}
|
|
79
|
+
return `${text.substring(0, maxLength)}... (length = ${length})`;
|
|
70
80
|
}
|
|
71
81
|
|
|
72
82
|
function cloneHeaders(
|
|
73
|
-
|
|
83
|
+
headers: HeadersInit | undefined
|
|
74
84
|
): Record<string, string> {
|
|
75
|
-
|
|
85
|
+
return headers instanceof Headers
|
|
86
|
+
? Object.fromEntries(headers.entries())
|
|
87
|
+
: Array.isArray(headers)
|
|
88
|
+
? Object.fromEntries(headers)
|
|
89
|
+
: { ...headers };
|
|
76
90
|
}
|
|
77
91
|
|
|
78
92
|
async function requireLoggedIn(): Promise<void> {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
93
|
+
const loggedIn = await loginOrRefreshIfRequired();
|
|
94
|
+
if (!loggedIn) {
|
|
95
|
+
throw new Error("Not logged in.");
|
|
96
|
+
}
|
|
83
97
|
}
|
|
84
98
|
|
|
85
|
-
function
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
99
|
+
function addAuthorizationHeaderIfUnspecified(
|
|
100
|
+
headers: Record<string, string>,
|
|
101
|
+
auth: ApiCredentials
|
|
102
|
+
): void {
|
|
103
|
+
if (!("Authorization" in headers)) {
|
|
104
|
+
if ("apiToken" in auth) {
|
|
105
|
+
headers["Authorization"] = `Bearer ${auth.apiToken}`;
|
|
106
|
+
} else {
|
|
107
|
+
headers["X-Auth-Key"] = auth.authKey;
|
|
108
|
+
headers["X-Auth-Email"] = auth.authEmail;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
91
111
|
}
|
|
92
112
|
|
|
93
|
-
function
|
|
94
|
-
|
|
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}`;
|
|
113
|
+
function addUserAgent(headers: Record<string, string>): void {
|
|
114
|
+
headers["User-Agent"] = `wrangler/${wranglerVersion}`;
|
|
103
115
|
}
|
|
104
116
|
|
|
105
117
|
/**
|
|
@@ -108,26 +120,30 @@ function addAuthorizationHeader(
|
|
|
108
120
|
* doesn't return json. We inline the implementation and try not to share
|
|
109
121
|
* any code with the other calls. We should push back on any new APIs that
|
|
110
122
|
* try to introduce non-"standard" response structures.
|
|
123
|
+
*
|
|
124
|
+
* Note: any calls to fetchKVGetValue must call encodeURIComponent on key
|
|
125
|
+
* before passing it
|
|
111
126
|
*/
|
|
112
127
|
|
|
113
128
|
export async function fetchKVGetValue(
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
): Promise<
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
accountId: string,
|
|
130
|
+
namespaceId: string,
|
|
131
|
+
key: string
|
|
132
|
+
): Promise<ArrayBuffer> {
|
|
133
|
+
await requireLoggedIn();
|
|
134
|
+
const auth = requireApiToken();
|
|
135
|
+
const headers: Record<string, string> = {};
|
|
136
|
+
addAuthorizationHeaderIfUnspecified(headers, auth);
|
|
137
|
+
const resource = `${getCloudflareAPIBaseURL()}/accounts/${accountId}/storage/kv/namespaces/${namespaceId}/values/${key}`;
|
|
138
|
+
const response = await fetch(resource, {
|
|
139
|
+
method: "GET",
|
|
140
|
+
headers,
|
|
141
|
+
});
|
|
142
|
+
if (response.ok) {
|
|
143
|
+
return await response.arrayBuffer();
|
|
144
|
+
} else {
|
|
145
|
+
throw new Error(
|
|
146
|
+
`Failed to fetch ${resource} - ${response.status}: ${response.statusText});`
|
|
147
|
+
);
|
|
148
|
+
}
|
|
133
149
|
}
|
package/src/cli.ts
CHANGED
|
@@ -1,19 +1,27 @@
|
|
|
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 { unstable_dev } from "./api";
|
|
5
|
+
import { FatalError } from "./errors";
|
|
4
6
|
import { main } from ".";
|
|
5
7
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
/**
|
|
9
|
+
* The main entrypoint for the CLI.
|
|
10
|
+
* main only gets called when the script is run directly, not when it's imported as a module.
|
|
11
|
+
*/
|
|
12
|
+
if (typeof jest === "undefined" && require.main) {
|
|
13
|
+
main(hideBin(process.argv)).catch((e) => {
|
|
14
|
+
// The logging of any error that was thrown from `main()` is handled in the `yargs.fail()` handler.
|
|
15
|
+
// Here we just want to ensure that the process exits with a non-zero code.
|
|
16
|
+
// We don't want to do this inside the `main()` function, since that would kill the process when running our tests.
|
|
17
|
+
const exitCode = (e instanceof FatalError && e.code) || 1;
|
|
18
|
+
process.exit(exitCode);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
9
21
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
});
|
|
22
|
+
/**
|
|
23
|
+
* This is how we're exporting the API.
|
|
24
|
+
* It makes it possible to import wrangler from 'wrangler',
|
|
25
|
+
* and call wrangler.unstable_dev().
|
|
26
|
+
*/
|
|
27
|
+
export default { unstable_dev };
|
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
|