wrangler 0.0.0-e95bea2 → 0.0.0-e95e5a0
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/README.md +25 -14
- package/bin/wrangler.js +13 -1
- package/miniflare-dist/index.mjs +4886 -0
- package/package.json +33 -25
- package/pages/functions/buildPlugin.ts +92 -0
- package/pages/functions/buildWorker.ts +80 -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 +146 -0
- package/pages/functions/template-worker.ts +21 -8
- package/src/__tests__/config-cache.test.ts +36 -0
- package/src/__tests__/configuration.test.ts +1179 -271
- package/src/__tests__/dev.test.tsx +382 -25
- package/src/__tests__/guess-worker-format.test.ts +28 -1
- package/src/__tests__/helpers/mock-account-id.ts +4 -0
- package/src/__tests__/helpers/mock-cfetch.ts +5 -1
- package/src/__tests__/helpers/mock-console.ts +20 -3
- package/src/__tests__/helpers/mock-dialogs.ts +26 -1
- 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/run-in-tmp.ts +10 -0
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/https-options.test.ts +5 -2
- package/src/__tests__/index.test.ts +27 -769
- package/src/__tests__/init.test.ts +1516 -0
- package/src/__tests__/jest.setup.ts +4 -4
- package/src/__tests__/kv.test.ts +172 -126
- package/src/__tests__/logger.test.ts +115 -0
- package/src/__tests__/pages.test.ts +311 -26
- package/src/__tests__/publish.test.ts +2946 -524
- package/src/__tests__/r2.test.ts +26 -10
- package/src/__tests__/route.test.ts +4 -4
- package/src/__tests__/secret.test.ts +55 -34
- package/src/__tests__/tail.test.ts +146 -20
- package/src/__tests__/user.test.ts +131 -0
- package/src/__tests__/whoami.test.tsx +26 -7
- package/src/bundle.ts +30 -3
- package/src/cfetch/internal.ts +9 -7
- package/src/cli.ts +5 -11
- package/src/config/README.md +7 -7
- package/src/config/config.ts +33 -78
- package/src/config/environment.ts +93 -4
- package/src/config/index.ts +15 -4
- package/src/config/validation-helpers.ts +202 -15
- package/src/config/validation.ts +530 -133
- package/src/config-cache.ts +45 -0
- package/src/create-worker-preview.ts +22 -13
- package/src/create-worker-upload-form.ts +32 -9
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +136 -75
- package/src/dev/local.tsx +196 -125
- package/src/dev/remote.tsx +25 -13
- package/src/dev/use-esbuild.ts +23 -5
- package/src/dialogs.tsx +16 -6
- package/src/entry.ts +119 -11
- package/src/environment-variables.ts +3 -1
- package/src/errors.ts +11 -0
- package/src/https-options.ts +3 -2
- package/src/index.tsx +739 -400
- package/src/inspect.ts +17 -11
- package/src/intl-polyfill.d.ts +139 -0
- package/src/{kv/index.tsx → kv.ts} +8 -28
- 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 +63 -58
- package/src/open-in-browser.ts +5 -4
- package/src/package-manager.ts +9 -8
- package/src/pages.tsx +883 -62
- package/src/parse.ts +1 -1
- package/src/proxy.ts +32 -21
- package/src/publish.ts +276 -161
- package/src/sites.tsx +88 -33
- 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 +231 -103
- package/src/whoami.tsx +2 -1
- package/src/worker.ts +15 -6
- package/templates/gitignore +171 -0
- package/templates/static-asset-facade.js +1 -1
- package/wrangler-dist/cli.js +22087 -49340
- package/src/__tests__/dev2.test.tsx +0 -152
- 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/reporting.ts +0 -131
- package/wrangler-dist/cli.js.map +0 -7
|
@@ -1,30 +1,36 @@
|
|
|
1
1
|
import { render } from "ink-testing-library";
|
|
2
2
|
import React from "react";
|
|
3
|
-
import {
|
|
3
|
+
import { writeAuthConfigFile } from "../user";
|
|
4
4
|
import { getUserInfo, WhoAmI } from "../whoami";
|
|
5
5
|
import { setMockResponse } from "./helpers/mock-cfetch";
|
|
6
|
-
import {
|
|
6
|
+
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
7
|
+
import { useMockIsTTY } from "./helpers/mock-istty";
|
|
7
8
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
8
9
|
import type { UserInfo } from "../whoami";
|
|
9
10
|
|
|
10
11
|
describe("getUserInfo()", () => {
|
|
11
12
|
runInTempDir({ homedir: "./home" });
|
|
13
|
+
const std = mockConsoleMethods();
|
|
14
|
+
const { setIsTTY } = useMockIsTTY();
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
setIsTTY(true);
|
|
18
|
+
});
|
|
12
19
|
|
|
13
20
|
it("should return undefined if there is no config file", async () => {
|
|
14
|
-
await initialise();
|
|
15
21
|
const userInfo = await getUserInfo();
|
|
16
22
|
expect(userInfo).toBeUndefined();
|
|
17
23
|
});
|
|
18
24
|
|
|
19
25
|
it("should return undefined if there is an empty config file", async () => {
|
|
20
|
-
|
|
21
|
-
await initialise();
|
|
26
|
+
writeAuthConfigFile({});
|
|
22
27
|
const userInfo = await getUserInfo();
|
|
23
28
|
expect(userInfo).toBeUndefined();
|
|
24
29
|
});
|
|
25
30
|
|
|
26
31
|
it("should return the user's email and accounts if authenticated via config token", async () => {
|
|
27
|
-
|
|
32
|
+
writeAuthConfigFile({ oauth_token: "some-oauth-token" });
|
|
33
|
+
|
|
28
34
|
setMockResponse("/user", () => {
|
|
29
35
|
return { email: "user@example.com" };
|
|
30
36
|
});
|
|
@@ -36,7 +42,6 @@ describe("getUserInfo()", () => {
|
|
|
36
42
|
];
|
|
37
43
|
});
|
|
38
44
|
|
|
39
|
-
await initialise();
|
|
40
45
|
const userInfo = await getUserInfo();
|
|
41
46
|
|
|
42
47
|
expect(userInfo).toEqual({
|
|
@@ -50,6 +55,20 @@ describe("getUserInfo()", () => {
|
|
|
50
55
|
],
|
|
51
56
|
});
|
|
52
57
|
});
|
|
58
|
+
|
|
59
|
+
it("should display a warning message if the config file contains a legacy api_token field", async () => {
|
|
60
|
+
writeAuthConfigFile({ api_token: "API_TOKEN" });
|
|
61
|
+
await getUserInfo();
|
|
62
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
63
|
+
"[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mIt looks like you have used Wrangler 1's \`config\` command to login with an API token.[0m
|
|
64
|
+
|
|
65
|
+
This is no longer supported in the current version of Wrangler.
|
|
66
|
+
If you wish to authenticate via an API token then please set the \`CLOUDFLARE_API_TOKEN\`
|
|
67
|
+
environment variable.
|
|
68
|
+
|
|
69
|
+
"
|
|
70
|
+
`);
|
|
71
|
+
});
|
|
53
72
|
});
|
|
54
73
|
|
|
55
74
|
describe("WhoAmI component", () => {
|
package/src/bundle.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
2
|
import * as fs from "node:fs";
|
|
3
3
|
import * as path from "node:path";
|
|
4
|
+
import NodeGlobalsPolyfills from "@esbuild-plugins/node-globals-polyfill";
|
|
5
|
+
import NodeModulesPolyfills from "@esbuild-plugins/node-modules-polyfill";
|
|
4
6
|
import * as esbuild from "esbuild";
|
|
5
7
|
import createModuleCollector from "./module-collection";
|
|
6
8
|
import type { Config } from "./config";
|
|
@@ -26,10 +28,21 @@ export async function bundleWorker(
|
|
|
26
28
|
jsxFragment: string | undefined;
|
|
27
29
|
rules: Config["rules"];
|
|
28
30
|
watch?: esbuild.WatchMode;
|
|
31
|
+
tsconfig: string | undefined;
|
|
32
|
+
minify: boolean | undefined;
|
|
33
|
+
nodeCompat: boolean | undefined;
|
|
29
34
|
}
|
|
30
35
|
): Promise<BundleResult> {
|
|
31
|
-
const {
|
|
32
|
-
|
|
36
|
+
const {
|
|
37
|
+
serveAssetsFromWorker,
|
|
38
|
+
jsxFactory,
|
|
39
|
+
jsxFragment,
|
|
40
|
+
rules,
|
|
41
|
+
watch,
|
|
42
|
+
tsconfig,
|
|
43
|
+
minify,
|
|
44
|
+
nodeCompat,
|
|
45
|
+
} = options;
|
|
33
46
|
const entryDirectory = path.dirname(entry.file);
|
|
34
47
|
const moduleCollector = createModuleCollector({
|
|
35
48
|
wrangler1xlegacyModuleReferences: {
|
|
@@ -54,17 +67,31 @@ export async function bundleWorker(
|
|
|
54
67
|
outdir: destination,
|
|
55
68
|
external: ["__STATIC_CONTENT_MANIFEST"],
|
|
56
69
|
format: "esm",
|
|
70
|
+
target: "es2020",
|
|
57
71
|
sourcemap: true,
|
|
72
|
+
minify,
|
|
58
73
|
metafile: true,
|
|
59
74
|
conditions: ["worker", "browser"],
|
|
75
|
+
...(process.env.NODE_ENV && {
|
|
76
|
+
define: {
|
|
77
|
+
"process.env.NODE_ENV": `"${process.env.NODE_ENV}"`,
|
|
78
|
+
...(nodeCompat ? { global: "globalThis" } : {}),
|
|
79
|
+
},
|
|
80
|
+
}),
|
|
60
81
|
loader: {
|
|
61
82
|
".js": "jsx",
|
|
62
83
|
".mjs": "jsx",
|
|
63
84
|
".cjs": "jsx",
|
|
64
85
|
},
|
|
65
|
-
plugins: [
|
|
86
|
+
plugins: [
|
|
87
|
+
moduleCollector.plugin,
|
|
88
|
+
...(nodeCompat
|
|
89
|
+
? [NodeGlobalsPolyfills({ buffer: true }), NodeModulesPolyfills()]
|
|
90
|
+
: []),
|
|
91
|
+
],
|
|
66
92
|
...(jsxFactory && { jsxFactory }),
|
|
67
93
|
...(jsxFragment && { jsxFragment }),
|
|
94
|
+
...(tsconfig && { tsconfig }),
|
|
68
95
|
watch,
|
|
69
96
|
});
|
|
70
97
|
|
package/src/cfetch/internal.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { fetch } from "undici";
|
|
1
|
+
import { fetch, Headers } from "undici";
|
|
2
2
|
import { getEnvironmentVariableFactory } from "../environment-variables";
|
|
3
3
|
import { ParseError, parseJSON } from "../parse";
|
|
4
|
-
import { reportError } from "../reporting";
|
|
5
4
|
import { getAPIToken, loginOrRefreshIfRequired } from "../user";
|
|
6
5
|
import type { URLSearchParams } from "node:url";
|
|
7
6
|
import type { RequestInit, HeadersInit } from "undici";
|
|
@@ -48,7 +47,6 @@ export async function fetchInternal<ResponseType>(
|
|
|
48
47
|
try {
|
|
49
48
|
return parseJSON(jsonText) as ResponseType;
|
|
50
49
|
} catch (err) {
|
|
51
|
-
await reportError(err as Error);
|
|
52
50
|
throw new ParseError({
|
|
53
51
|
text: "Received a malformed response from the API",
|
|
54
52
|
notes: [
|
|
@@ -74,7 +72,11 @@ function truncate(text: string, maxLength: number): string {
|
|
|
74
72
|
function cloneHeaders(
|
|
75
73
|
headers: HeadersInit | undefined
|
|
76
74
|
): Record<string, string> {
|
|
77
|
-
return
|
|
75
|
+
return headers instanceof Headers
|
|
76
|
+
? Object.fromEntries(headers.entries())
|
|
77
|
+
: Array.isArray(headers)
|
|
78
|
+
? Object.fromEntries(headers)
|
|
79
|
+
: { ...headers };
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
async function requireLoggedIn(): Promise<void> {
|
|
@@ -85,11 +87,11 @@ async function requireLoggedIn(): Promise<void> {
|
|
|
85
87
|
}
|
|
86
88
|
|
|
87
89
|
function requireApiToken(): string {
|
|
88
|
-
const
|
|
89
|
-
if (!
|
|
90
|
+
const authToken = getAPIToken();
|
|
91
|
+
if (!authToken) {
|
|
90
92
|
throw new Error("No API token found.");
|
|
91
93
|
}
|
|
92
|
-
return
|
|
94
|
+
return authToken;
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
function addAuthorizationHeader(
|
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,23 +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
|
-
Env extends RawEnvironment,
|
|
31
|
-
Dev extends RawDevConfig
|
|
32
|
-
> {
|
|
30
|
+
export interface ConfigFields<Dev extends RawDevConfig> {
|
|
33
31
|
configPath: string | undefined;
|
|
34
32
|
|
|
35
|
-
/**
|
|
36
|
-
* The entrypoint/path to the JavaScript file that will be executed.
|
|
37
|
-
*/
|
|
38
|
-
main: string | undefined;
|
|
39
|
-
|
|
40
33
|
/**
|
|
41
34
|
* A boolean to enable "legacy" style wrangler environments (from wrangler 1).
|
|
42
35
|
* These have been superseded by Services, but there may be projects that won't
|
|
@@ -45,22 +38,6 @@ export interface ConfigFields<
|
|
|
45
38
|
*/
|
|
46
39
|
legacy_env: boolean;
|
|
47
40
|
|
|
48
|
-
/**
|
|
49
|
-
* The `env` section defines overrides for the configuration for different environments.
|
|
50
|
-
*
|
|
51
|
-
* All environment fields can be specified at the top level of the config indicating the default environment settings.
|
|
52
|
-
*
|
|
53
|
-
* - Some fields are inherited and overridable in each environment.
|
|
54
|
-
* - But some are not inherited and must be explicitly specified in every environment, if they are specified at the top level.
|
|
55
|
-
*
|
|
56
|
-
* For more information, see the documentation at https://developers.cloudflare.com/workers/cli-wrangler/configuration#environments
|
|
57
|
-
*
|
|
58
|
-
* @default `{}`
|
|
59
|
-
*/
|
|
60
|
-
env: {
|
|
61
|
-
[envName: string]: Env;
|
|
62
|
-
};
|
|
63
|
-
|
|
64
41
|
/**
|
|
65
42
|
* Options to configure the development server that your worker will use.
|
|
66
43
|
*/
|
|
@@ -160,34 +137,22 @@ export interface ConfigFields<
|
|
|
160
137
|
| undefined;
|
|
161
138
|
|
|
162
139
|
/**
|
|
163
|
-
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
* for more details.
|
|
167
|
-
*
|
|
168
|
-
* @default {}
|
|
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.
|
|
169
143
|
*/
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
/** The directory to watch for changes while using wrangler dev, defaults to the current working directory */
|
|
176
|
-
watch_dir?: string;
|
|
177
|
-
/**
|
|
178
|
-
* Deprecated field previously used to configure the build and upload of the script.
|
|
179
|
-
* @deprecated
|
|
180
|
-
*/
|
|
181
|
-
upload?: DeprecatedUpload;
|
|
182
|
-
};
|
|
144
|
+
data_blobs:
|
|
145
|
+
| {
|
|
146
|
+
[key: string]: string;
|
|
147
|
+
}
|
|
148
|
+
| undefined;
|
|
183
149
|
}
|
|
184
150
|
|
|
185
151
|
export interface DevConfig {
|
|
186
152
|
/**
|
|
187
153
|
* IP address for the local dev server to listen on,
|
|
188
154
|
*
|
|
189
|
-
* @default `
|
|
190
|
-
* @todo this needs to be implemented
|
|
155
|
+
* @default `localhost`
|
|
191
156
|
*/
|
|
192
157
|
ip: string;
|
|
193
158
|
|
|
@@ -202,7 +167,6 @@ export interface DevConfig {
|
|
|
202
167
|
* Protocol that local wrangler dev server listens to requests on.
|
|
203
168
|
*
|
|
204
169
|
* @default `http`
|
|
205
|
-
* @todo this needs to be implemented
|
|
206
170
|
*/
|
|
207
171
|
local_protocol: "http" | "https";
|
|
208
172
|
|
|
@@ -213,13 +177,14 @@ export interface DevConfig {
|
|
|
213
177
|
* See https://github.com/cloudflare/wrangler2/issues/583
|
|
214
178
|
*
|
|
215
179
|
* @default `https`
|
|
180
|
+
* @todo this needs to be implemented https://github.com/cloudflare/wrangler2/issues/583
|
|
216
181
|
*/
|
|
217
182
|
upstream_protocol: "https" | "http";
|
|
218
183
|
|
|
219
184
|
/**
|
|
220
|
-
* Host to forward requests to, defaults to the
|
|
185
|
+
* Host to forward requests to, defaults to the host of the first route of project
|
|
221
186
|
*/
|
|
222
|
-
host:
|
|
187
|
+
host: Config["route"];
|
|
223
188
|
}
|
|
224
189
|
|
|
225
190
|
export type RawDevConfig = Partial<DevConfig>;
|
|
@@ -242,38 +207,28 @@ export interface DeprecatedConfigFields {
|
|
|
242
207
|
* @breaking
|
|
243
208
|
*/
|
|
244
209
|
webpack_config?: string;
|
|
245
|
-
}
|
|
246
210
|
|
|
247
|
-
/**
|
|
248
|
-
* Deprecated upload configuration.
|
|
249
|
-
*/
|
|
250
|
-
export interface DeprecatedUpload {
|
|
251
211
|
/**
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
* @deprecated We infer the format automatically now.
|
|
212
|
+
* Configuration only used by a standalone use of the miniflare binary.
|
|
213
|
+
* @deprecated
|
|
255
214
|
*/
|
|
256
|
-
|
|
215
|
+
miniflare?: unknown;
|
|
216
|
+
}
|
|
257
217
|
|
|
218
|
+
interface EnvironmentMap {
|
|
258
219
|
/**
|
|
259
|
-
* The
|
|
260
|
-
* relative to the wrangler.toml file.
|
|
220
|
+
* The `env` section defines overrides for the configuration for different environments.
|
|
261
221
|
*
|
|
262
|
-
*
|
|
222
|
+
* All environment fields can be specified at the top level of the config indicating the default environment settings.
|
|
263
223
|
*
|
|
264
|
-
*
|
|
265
|
-
|
|
266
|
-
dir?: string;
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* 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.
|
|
270
226
|
*
|
|
271
|
-
*
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* @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 `{}`
|
|
277
230
|
*/
|
|
278
|
-
|
|
231
|
+
env?: {
|
|
232
|
+
[envName: string]: RawEnvironment;
|
|
233
|
+
};
|
|
279
234
|
}
|
|
@@ -51,6 +51,11 @@ interface EnvironmentInheritable {
|
|
|
51
51
|
*/
|
|
52
52
|
compatibility_flags: string[];
|
|
53
53
|
|
|
54
|
+
/**
|
|
55
|
+
* The entrypoint/path to the JavaScript file that will be executed.
|
|
56
|
+
*/
|
|
57
|
+
main: string | undefined;
|
|
58
|
+
|
|
54
59
|
/**
|
|
55
60
|
* Whether we use <name>.<subdomain>.workers.dev to
|
|
56
61
|
* test and deploy your worker.
|
|
@@ -59,7 +64,7 @@ interface EnvironmentInheritable {
|
|
|
59
64
|
* @breaking
|
|
60
65
|
* @inheritable
|
|
61
66
|
*/
|
|
62
|
-
workers_dev: boolean;
|
|
67
|
+
workers_dev: boolean | undefined;
|
|
63
68
|
|
|
64
69
|
/**
|
|
65
70
|
* A list of routes that your worker should be published to.
|
|
@@ -69,7 +74,13 @@ interface EnvironmentInheritable {
|
|
|
69
74
|
*
|
|
70
75
|
* @inheritable
|
|
71
76
|
*/
|
|
72
|
-
routes:
|
|
77
|
+
routes:
|
|
78
|
+
| (
|
|
79
|
+
| string
|
|
80
|
+
| { pattern: string; zone_id: string }
|
|
81
|
+
| { pattern: string; zone_name: string }
|
|
82
|
+
)[]
|
|
83
|
+
| undefined;
|
|
73
84
|
|
|
74
85
|
/**
|
|
75
86
|
* A route that your worker should be published to. Literally
|
|
@@ -80,7 +91,18 @@ interface EnvironmentInheritable {
|
|
|
80
91
|
*
|
|
81
92
|
* @inheritable
|
|
82
93
|
*/
|
|
83
|
-
route:
|
|
94
|
+
route:
|
|
95
|
+
| (
|
|
96
|
+
| string
|
|
97
|
+
| { pattern: string; zone_id: string }
|
|
98
|
+
| { pattern: string; zone_name: string }
|
|
99
|
+
)
|
|
100
|
+
| undefined;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Path to a custom tsconfig
|
|
104
|
+
*/
|
|
105
|
+
tsconfig: string | undefined;
|
|
84
106
|
|
|
85
107
|
/**
|
|
86
108
|
* The function to use to replace jsx syntax.
|
|
@@ -121,7 +143,7 @@ interface EnvironmentInheritable {
|
|
|
121
143
|
*
|
|
122
144
|
* @inheritable
|
|
123
145
|
*/
|
|
124
|
-
usage_model:
|
|
146
|
+
usage_model: "bundled" | "unbound" | undefined;
|
|
125
147
|
|
|
126
148
|
/**
|
|
127
149
|
* An ordered list of rules that define which modules to import,
|
|
@@ -133,6 +155,39 @@ interface EnvironmentInheritable {
|
|
|
133
155
|
*/
|
|
134
156
|
rules: Rule[];
|
|
135
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Configures a custom build step to be run by Wrangler when building your Worker.
|
|
160
|
+
*
|
|
161
|
+
* Refer to the [custom builds documentation](https://developers.cloudflare.com/workers/cli-wrangler/configuration#build)
|
|
162
|
+
* for more details.
|
|
163
|
+
*
|
|
164
|
+
* @default {}
|
|
165
|
+
*/
|
|
166
|
+
build: {
|
|
167
|
+
/** 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. */
|
|
168
|
+
command?: string;
|
|
169
|
+
/** The directory in which the command is executed. */
|
|
170
|
+
cwd?: string;
|
|
171
|
+
/** The directory to watch for changes while using wrangler dev, defaults to the current working directory */
|
|
172
|
+
watch_dir?: string;
|
|
173
|
+
/**
|
|
174
|
+
* Deprecated field previously used to configure the build and upload of the script.
|
|
175
|
+
* @deprecated
|
|
176
|
+
*/
|
|
177
|
+
upload?: DeprecatedUpload;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Minify the script before uploading.
|
|
182
|
+
* @inheritable
|
|
183
|
+
*/
|
|
184
|
+
minify: boolean | undefined;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Add polyfills for node builtin modules and globals
|
|
188
|
+
*/
|
|
189
|
+
node_compat: boolean | undefined;
|
|
190
|
+
|
|
136
191
|
/**
|
|
137
192
|
* TODO: remove this as it has been deprecated.
|
|
138
193
|
*
|
|
@@ -277,6 +332,40 @@ interface EnvironmentDeprecated {
|
|
|
277
332
|
}[];
|
|
278
333
|
}
|
|
279
334
|
|
|
335
|
+
/**
|
|
336
|
+
* Deprecated upload configuration.
|
|
337
|
+
*/
|
|
338
|
+
export interface DeprecatedUpload {
|
|
339
|
+
/**
|
|
340
|
+
* The format of the Worker script.
|
|
341
|
+
*
|
|
342
|
+
* @deprecated We infer the format automatically now.
|
|
343
|
+
*/
|
|
344
|
+
format?: "modules" | "service-worker";
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* The directory you wish to upload your worker from,
|
|
348
|
+
* relative to the wrangler.toml file.
|
|
349
|
+
*
|
|
350
|
+
* Defaults to the directory containing the wrangler.toml file.
|
|
351
|
+
*
|
|
352
|
+
* @deprecated
|
|
353
|
+
*/
|
|
354
|
+
dir?: string;
|
|
355
|
+
|
|
356
|
+
/**
|
|
357
|
+
* The path to the Worker script, relative to `upload.dir`.
|
|
358
|
+
*
|
|
359
|
+
* @deprecated This will be replaced by a command line argument.
|
|
360
|
+
*/
|
|
361
|
+
main?: string;
|
|
362
|
+
|
|
363
|
+
/**
|
|
364
|
+
* @deprecated This is now defined at the top level `rules` field.
|
|
365
|
+
*/
|
|
366
|
+
rules?: Environment["rules"];
|
|
367
|
+
}
|
|
368
|
+
|
|
280
369
|
/**
|
|
281
370
|
* The raw environment configuration that we read from the config file.
|
|
282
371
|
*
|
package/src/config/index.ts
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { findUpSync } from "find-up";
|
|
2
|
+
import { logger } from "../logger";
|
|
2
3
|
import { parseTOML, readFileSync } from "../parse";
|
|
3
4
|
import { normalizeAndValidateConfig } from "./validation";
|
|
4
5
|
import type { Config, RawConfig } from "./config";
|
|
5
6
|
|
|
6
|
-
export type {
|
|
7
|
+
export type {
|
|
8
|
+
Config,
|
|
9
|
+
RawConfig,
|
|
10
|
+
ConfigFields,
|
|
11
|
+
DevConfig,
|
|
12
|
+
RawDevConfig,
|
|
13
|
+
} from "./config";
|
|
7
14
|
export type {
|
|
8
15
|
Environment,
|
|
9
16
|
RawEnvironment,
|
|
@@ -13,7 +20,10 @@ export type {
|
|
|
13
20
|
/**
|
|
14
21
|
* Get the Wrangler configuration; read it from the give `configPath` if available.
|
|
15
22
|
*/
|
|
16
|
-
export function readConfig(
|
|
23
|
+
export function readConfig(
|
|
24
|
+
configPath: string | undefined,
|
|
25
|
+
args: unknown
|
|
26
|
+
): Config {
|
|
17
27
|
let rawConfig: RawConfig = {};
|
|
18
28
|
if (!configPath) {
|
|
19
29
|
configPath = findWranglerToml();
|
|
@@ -27,11 +37,12 @@ export function readConfig(configPath?: string): Config {
|
|
|
27
37
|
// Process the top-level configuration.
|
|
28
38
|
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
29
39
|
rawConfig,
|
|
30
|
-
configPath
|
|
40
|
+
configPath,
|
|
41
|
+
args
|
|
31
42
|
);
|
|
32
43
|
|
|
33
44
|
if (diagnostics.hasWarnings()) {
|
|
34
|
-
|
|
45
|
+
logger.warn(diagnostics.renderWarnings());
|
|
35
46
|
}
|
|
36
47
|
if (diagnostics.hasErrors()) {
|
|
37
48
|
throw new Error(diagnostics.renderErrors());
|