wrangler 0.0.0-e043479 → 0.0.0-e0a0509

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 (96) hide show
  1. package/README.md +27 -14
  2. package/bin/wrangler.js +13 -1
  3. package/miniflare-dist/index.mjs +4886 -0
  4. package/package.json +38 -25
  5. package/pages/functions/buildPlugin.ts +92 -0
  6. package/pages/functions/buildWorker.ts +80 -4
  7. package/pages/functions/filepath-routing.test.ts +136 -25
  8. package/pages/functions/filepath-routing.ts +14 -3
  9. package/pages/functions/routes.ts +6 -1
  10. package/pages/functions/template-plugin.ts +146 -0
  11. package/pages/functions/template-worker.ts +21 -8
  12. package/src/__tests__/config-cache.test.ts +36 -0
  13. package/src/__tests__/configuration.test.ts +1294 -355
  14. package/src/__tests__/dev.test.tsx +592 -12
  15. package/src/__tests__/guess-worker-format.test.ts +37 -18
  16. package/src/__tests__/helpers/mock-account-id.ts +4 -0
  17. package/src/__tests__/helpers/mock-cfetch.ts +8 -4
  18. package/src/__tests__/helpers/mock-console.ts +20 -3
  19. package/src/__tests__/helpers/mock-dialogs.ts +26 -1
  20. package/src/__tests__/helpers/mock-http-server.ts +46 -0
  21. package/src/__tests__/helpers/mock-istty.ts +27 -0
  22. package/src/__tests__/helpers/mock-kv.ts +9 -16
  23. package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
  24. package/src/__tests__/helpers/run-in-tmp.ts +10 -0
  25. package/src/__tests__/helpers/write-worker-source.ts +31 -0
  26. package/src/__tests__/https-options.test.ts +130 -0
  27. package/src/__tests__/index.test.ts +129 -753
  28. package/src/__tests__/init.test.ts +1516 -0
  29. package/src/__tests__/jest.setup.ts +13 -5
  30. package/src/__tests__/kv.test.ts +208 -174
  31. package/src/__tests__/logger.test.ts +115 -0
  32. package/src/__tests__/pages.test.ts +327 -0
  33. package/src/__tests__/parse.test.ts +4 -0
  34. package/src/__tests__/publish.test.ts +3313 -505
  35. package/src/__tests__/r2.test.ts +38 -26
  36. package/src/__tests__/route.test.ts +45 -0
  37. package/src/__tests__/secret.test.ts +55 -34
  38. package/src/__tests__/tail.test.ts +146 -20
  39. package/src/__tests__/user.test.ts +131 -0
  40. package/src/__tests__/whoami.test.tsx +26 -7
  41. package/src/bundle.ts +43 -7
  42. package/src/cfetch/internal.ts +9 -5
  43. package/src/cli.ts +5 -11
  44. package/src/config/README.md +7 -7
  45. package/src/config/config.ts +69 -105
  46. package/src/config/environment.ts +93 -4
  47. package/src/config/index.ts +15 -4
  48. package/src/config/validation-helpers.ts +228 -23
  49. package/src/config/validation.ts +559 -154
  50. package/src/config-cache.ts +45 -0
  51. package/src/{api/preview.ts → create-worker-preview.ts} +41 -13
  52. package/src/{api/form_data.ts → create-worker-upload-form.ts} +33 -10
  53. package/src/dev/dev-vars.ts +36 -0
  54. package/src/dev/dev.tsx +418 -0
  55. package/src/dev/local.tsx +312 -0
  56. package/src/dev/remote.tsx +213 -0
  57. package/src/dev/use-esbuild.ts +118 -0
  58. package/src/dialogs.tsx +16 -6
  59. package/src/entry.ts +222 -12
  60. package/src/environment-variables.ts +3 -1
  61. package/src/errors.ts +11 -0
  62. package/src/https-options.ts +123 -0
  63. package/src/index.tsx +878 -482
  64. package/src/inspect.ts +25 -11
  65. package/src/intl-polyfill.d.ts +139 -0
  66. package/src/{kv.tsx → kv.ts} +7 -27
  67. package/src/logger.ts +66 -0
  68. package/src/miniflare-cli/README.md +30 -0
  69. package/src/miniflare-cli/enum-keys.ts +17 -0
  70. package/src/miniflare-cli/index.ts +41 -0
  71. package/src/miniflare-cli/request-context.ts +40 -0
  72. package/src/module-collection.ts +94 -6
  73. package/src/open-in-browser.ts +18 -5
  74. package/src/package-manager.ts +9 -8
  75. package/src/pages.tsx +892 -62
  76. package/src/parse.ts +4 -2
  77. package/src/proxy.ts +128 -55
  78. package/src/publish.ts +305 -199
  79. package/src/selfsigned.d.ts +29 -0
  80. package/src/sites.tsx +88 -33
  81. package/src/tail/index.ts +2 -2
  82. package/src/tail/printing.ts +13 -8
  83. package/src/update-check.ts +19 -0
  84. package/src/user.tsx +244 -104
  85. package/src/whoami.tsx +2 -1
  86. package/src/{api/worker.ts → worker.ts} +15 -29
  87. package/templates/gitignore +171 -0
  88. package/templates/static-asset-facade.js +1 -1
  89. package/wrangler-dist/cli.js +23568 -50489
  90. package/src/__tests__/helpers/mock-user.ts +0 -27
  91. package/src/__tests__/logout.test.ts +0 -50
  92. package/src/__tests__/sentry.test.ts +0 -146
  93. package/src/dev.tsx +0 -960
  94. package/src/guess-worker-format.ts +0 -68
  95. package/src/reporting.ts +0 -115
  96. package/wrangler-dist/cli.js.map +0 -7
@@ -0,0 +1,131 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import fetchMock from "jest-fetch-mock";
5
+ import {
6
+ readAuthConfigFile,
7
+ requireAuth,
8
+ USER_AUTH_CONFIG_FILE,
9
+ writeAuthConfigFile,
10
+ } from "../user";
11
+ import { mockConsoleMethods } from "./helpers/mock-console";
12
+ import { useMockIsTTY } from "./helpers/mock-istty";
13
+ import { mockOAuthFlow } from "./helpers/mock-oauth-flow";
14
+ import { runInTempDir } from "./helpers/run-in-tmp";
15
+ import { runWrangler } from "./helpers/run-wrangler";
16
+ import type { Config } from "../config";
17
+ import type { UserAuthConfig } from "../user";
18
+
19
+ describe("User", () => {
20
+ runInTempDir({ homedir: "./home" });
21
+ const std = mockConsoleMethods();
22
+ const {
23
+ mockOAuthServerCallback,
24
+ mockGrantAccessToken,
25
+ mockGrantAuthorization,
26
+ mockRevokeAuthorization,
27
+ mockExchangeRefreshTokenForAccessToken,
28
+ } = mockOAuthFlow();
29
+
30
+ const { setIsTTY } = useMockIsTTY();
31
+
32
+ describe("login", () => {
33
+ it("should login a user when `wrangler login` is run", async () => {
34
+ mockOAuthServerCallback();
35
+ const accessTokenRequest = mockGrantAccessToken({ respondWith: "ok" });
36
+ mockGrantAuthorization({ respondWith: "success" });
37
+
38
+ await runWrangler("login");
39
+
40
+ expect(accessTokenRequest.actual.url).toEqual(
41
+ accessTokenRequest.expected.url
42
+ );
43
+ expect(accessTokenRequest.actual.method).toEqual(
44
+ accessTokenRequest.expected.method
45
+ );
46
+
47
+ expect(std.out).toMatchInlineSnapshot(`
48
+ "Attempting to login via OAuth...
49
+ Successfully logged in."
50
+ `);
51
+
52
+ expect(readAuthConfigFile()).toEqual<UserAuthConfig>({
53
+ api_token: undefined,
54
+ oauth_token: "test-access-token",
55
+ refresh_token: "test-refresh-token",
56
+ expiration_time: expect.any(String),
57
+ });
58
+ });
59
+ });
60
+
61
+ describe("logout", () => {
62
+ it("should exit with a message stating the user is not logged in", async () => {
63
+ await runWrangler("logout");
64
+ expect(std.out).toMatchInlineSnapshot(`"Not logged in, exiting..."`);
65
+ });
66
+
67
+ it("should logout user that has been properly logged in", async () => {
68
+ writeAuthConfigFile({
69
+ oauth_token: "some-oauth-tok",
70
+ refresh_token: "some-refresh-tok",
71
+ });
72
+ const outcome = mockRevokeAuthorization();
73
+
74
+ await runWrangler("logout");
75
+
76
+ expect(outcome.actual.url).toEqual(
77
+ "https://dash.cloudflare.com/oauth2/revoke"
78
+ );
79
+ expect(outcome.actual.method).toEqual("POST");
80
+
81
+ expect(std.out).toMatchInlineSnapshot(`"Successfully logged out."`);
82
+
83
+ // Make sure that we made the request to logout.
84
+ expect(fetchMock).toHaveBeenCalledTimes(1);
85
+
86
+ // Make sure that logout removed the config file containing the auth tokens.
87
+ const config = path.join(os.homedir(), USER_AUTH_CONFIG_FILE);
88
+ expect(fs.existsSync(config)).toBeFalsy();
89
+ });
90
+ });
91
+
92
+ // TODO: Improve OAuth mocking to handle `/token` endpoints from different calls
93
+ it("should handle errors for failed token refresh", async () => {
94
+ setIsTTY(false);
95
+ mockOAuthServerCallback();
96
+ writeAuthConfigFile({
97
+ oauth_token: "hunter2",
98
+ refresh_token: "Order 66",
99
+ });
100
+ mockGrantAuthorization({ respondWith: "success" });
101
+
102
+ mockExchangeRefreshTokenForAccessToken({
103
+ respondWith: "badResponse",
104
+ });
105
+
106
+ // Handles the requireAuth error throw from failed login that is unhandled due to directly calling it here
107
+ await expect(
108
+ requireAuth({} as Config)
109
+ ).rejects.toThrowErrorMatchingInlineSnapshot(
110
+ `"Did not login, quitting..."`
111
+ );
112
+ });
113
+
114
+ it("should confirm no error message when refresh is successful", async () => {
115
+ setIsTTY(false);
116
+ mockOAuthServerCallback();
117
+ writeAuthConfigFile({
118
+ oauth_token: "hunter2",
119
+ refresh_token: "Order 66",
120
+ });
121
+ mockGrantAuthorization({ respondWith: "success" });
122
+
123
+ mockExchangeRefreshTokenForAccessToken({
124
+ respondWith: "refreshSuccess",
125
+ });
126
+
127
+ // Handles the requireAuth error throw from failed login that is unhandled due to directly calling it here
128
+ await expect(requireAuth({} as Config)).rejects.toThrowError();
129
+ expect(std.err).toContain("");
130
+ });
131
+ });
@@ -1,30 +1,36 @@
1
1
  import { render } from "ink-testing-library";
2
2
  import React from "react";
3
- import { initialise } from "../user";
3
+ import { writeAuthConfigFile } from "../user";
4
4
  import { getUserInfo, WhoAmI } from "../whoami";
5
5
  import { setMockResponse } from "./helpers/mock-cfetch";
6
- import { writeUserConfig } from "./helpers/mock-user";
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
- writeUserConfig();
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
- writeUserConfig("some-oauth-token");
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
+ "▲ [WARNING] It looks like you have used Wrangler 1's \`config\` command to login with an API token.
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,11 +1,13 @@
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
- import makeModuleCollector from "./module-collection";
6
- import type { CfModule, CfScriptFormat } from "./api/worker";
7
+ import createModuleCollector from "./module-collection";
7
8
  import type { Config } from "./config";
8
9
  import type { Entry } from "./entry";
10
+ import type { CfModule } from "./worker";
9
11
 
10
12
  type BundleResult = {
11
13
  modules: CfModule[];
@@ -24,38 +26,72 @@ export async function bundleWorker(
24
26
  serveAssetsFromWorker: boolean;
25
27
  jsxFactory: string | undefined;
26
28
  jsxFragment: string | undefined;
27
- format: CfScriptFormat;
28
29
  rules: Config["rules"];
29
30
  watch?: esbuild.WatchMode;
31
+ tsconfig: string | undefined;
32
+ minify: boolean | undefined;
33
+ nodeCompat: boolean | undefined;
30
34
  }
31
35
  ): Promise<BundleResult> {
32
36
  const {
33
37
  serveAssetsFromWorker,
34
38
  jsxFactory,
35
39
  jsxFragment,
36
- format,
37
40
  rules,
38
41
  watch,
42
+ tsconfig,
43
+ minify,
44
+ nodeCompat,
39
45
  } = options;
40
- const moduleCollector = makeModuleCollector({ format, rules });
46
+ const entryDirectory = path.dirname(entry.file);
47
+ const moduleCollector = createModuleCollector({
48
+ wrangler1xlegacyModuleReferences: {
49
+ rootDirectory: entryDirectory,
50
+ fileNames: new Set(
51
+ fs
52
+ .readdirSync(entryDirectory, { withFileTypes: true })
53
+ .filter(
54
+ (dirEntry) =>
55
+ dirEntry.isFile() && dirEntry.name !== path.basename(entry.file)
56
+ )
57
+ .map((dirEnt) => dirEnt.name)
58
+ ),
59
+ },
60
+ format: entry.format,
61
+ rules,
62
+ });
41
63
  const result = await esbuild.build({
42
64
  ...getEntryPoint(entry.file, serveAssetsFromWorker),
43
65
  bundle: true,
44
66
  absWorkingDir: entry.directory,
45
67
  outdir: destination,
46
68
  external: ["__STATIC_CONTENT_MANIFEST"],
47
- format: "esm",
69
+ format: entry.format === "modules" ? "esm" : "iife",
70
+ target: "es2020",
48
71
  sourcemap: true,
72
+ minify,
49
73
  metafile: true,
50
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
+ }),
51
81
  loader: {
52
82
  ".js": "jsx",
53
83
  ".mjs": "jsx",
54
84
  ".cjs": "jsx",
55
85
  },
56
- plugins: [moduleCollector.plugin],
86
+ plugins: [
87
+ moduleCollector.plugin,
88
+ ...(nodeCompat
89
+ ? [NodeGlobalsPolyfills({ buffer: true }), NodeModulesPolyfills()]
90
+ : []),
91
+ ],
57
92
  ...(jsxFactory && { jsxFactory }),
58
93
  ...(jsxFragment && { jsxFragment }),
94
+ ...(tsconfig && { tsconfig }),
59
95
  watch,
60
96
  });
61
97
 
@@ -1,4 +1,4 @@
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
4
  import { getAPIToken, loginOrRefreshIfRequired } from "../user";
@@ -72,7 +72,11 @@ function truncate(text: string, maxLength: number): string {
72
72
  function cloneHeaders(
73
73
  headers: HeadersInit | undefined
74
74
  ): Record<string, string> {
75
- return { ...headers };
75
+ return headers instanceof Headers
76
+ ? Object.fromEntries(headers.entries())
77
+ : Array.isArray(headers)
78
+ ? Object.fromEntries(headers)
79
+ : { ...headers };
76
80
  }
77
81
 
78
82
  async function requireLoggedIn(): Promise<void> {
@@ -83,11 +87,11 @@ async function requireLoggedIn(): Promise<void> {
83
87
  }
84
88
 
85
89
  function requireApiToken(): string {
86
- const apiToken = getAPIToken();
87
- if (!apiToken) {
90
+ const authToken = getAPIToken();
91
+ if (!authToken) {
88
92
  throw new Error("No API token found.");
89
93
  }
90
- return apiToken;
94
+ return authToken;
91
95
  }
92
96
 
93
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 { reportError, initReporting } from "./reporting";
4
+ import { FatalError } from "./errors";
4
5
  import { main } from ".";
5
6
 
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(() => {
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
- process.exit(1);
11
+ const exitCode = (e instanceof FatalError && e.code) || 1;
12
+ process.exit(exitCode);
19
13
  });
@@ -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 top level environment.
29
+ In this case the `Environment`, here, corresponds to the "currently active" environment. This is specified by the `--env` command line argument.
30
+ If there is no argument passed then the currently active environment is the "top-level" environment.
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 also includes `DeprecatedConfigFields` and extends and contains the `RawEnvironment` 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 `console.warn()` messages,
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
@@ -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<Environment> & Environment;
23
+ export type Config = ConfigFields<DevConfig> & Environment;
24
24
 
25
- export type RawConfig = Partial<ConfigFields<RawEnvironment>> &
25
+ export type RawConfig = Partial<ConfigFields<RawDevConfig>> &
26
26
  RawEnvironment &
27
- DeprecatedConfigFields;
27
+ DeprecatedConfigFields &
28
+ EnvironmentMap;
28
29
 
29
- export interface ConfigFields<Env extends RawEnvironment> {
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,64 +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
-
98
- /**
99
- * Host to forward requests to, defaults to the zone of project
100
- */
101
- host?: string;
102
- };
44
+ dev: Dev;
103
45
 
104
46
  /**
105
47
  * A list of migrations that should be uploaded with your Worker.
@@ -195,25 +137,58 @@ export interface ConfigFields<Env extends RawEnvironment> {
195
137
  | undefined;
196
138
 
197
139
  /**
198
- * Configures a custom build step to be run by Wrangler when building your Worker.
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,
199
154
  *
200
- * Refer to the [custom builds documentation](https://developers.cloudflare.com/workers/cli-wrangler/configuration#build)
201
- * for more details.
155
+ * @default `localhost`
156
+ */
157
+ ip: string;
158
+
159
+ /**
160
+ * Port for the local dev server to listen on
202
161
  *
203
- * @default {}
162
+ * @default `8787`
204
163
  */
205
- build: {
206
- /** 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. */
207
- command?: string;
208
- /** The directory in which the command is executed. */
209
- cwd?: string;
210
- /** The directory to watch for changes while using wrangler dev, defaults to the current working directory */
211
- watch_dir?: string;
212
- /** Deprecated field previously used to configure the build and upload of the script. */
213
- upload?: DeprecatedUpload;
214
- };
164
+ port: number | undefined;
165
+
166
+ /**
167
+ * Protocol that local wrangler dev server listens to requests on.
168
+ *
169
+ * @default `http`
170
+ */
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: Config["route"];
215
188
  }
216
189
 
190
+ export type RawDevConfig = Partial<DevConfig>;
191
+
217
192
  export interface DeprecatedConfigFields {
218
193
  /**
219
194
  * The project "type". A holdover from wrangler 1.x.
@@ -232,39 +207,28 @@ export interface DeprecatedConfigFields {
232
207
  * @breaking
233
208
  */
234
209
  webpack_config?: string;
235
- }
236
210
 
237
- /**
238
- * Deprecated upload configuration.
239
- */
240
- export interface DeprecatedUpload {
241
211
  /**
242
- * The format of the Worker script.
243
- *
244
- * @deprecated We infer the format automatically now.
212
+ * Configuration only used by a standalone use of the miniflare binary.
213
+ * @deprecated
245
214
  */
246
- format?: "modules" | "service-worker";
215
+ miniflare?: unknown;
216
+ }
247
217
 
218
+ interface EnvironmentMap {
248
219
  /**
249
- * The directory you wish to upload your worker from,
250
- * relative to the wrangler.toml file.
220
+ * The `env` section defines overrides for the configuration for different environments.
251
221
  *
252
- * Defaults to the directory containing the wrangler.toml file.
222
+ * All environment fields can be specified at the top level of the config indicating the default environment settings.
253
223
  *
254
- * @deprecated
255
- * @breaking In wrangler 1, this defaults to ./dist, whereas in wrangler 2 it defaults to ./
256
- */
257
- dir?: string;
258
-
259
- /**
260
- * 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.
261
226
  *
262
- * @deprecated This will be replaced by a command line argument.
263
- */
264
- main?: string;
265
-
266
- /**
267
- * @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 `{}`
268
230
  */
269
- rules?: Environment["rules"];
231
+ env?: {
232
+ [envName: string]: RawEnvironment;
233
+ };
270
234
  }