wrangler 0.0.0-e95bea2 → 0.0.0-ea8e701
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 +3 -3
- package/bin/wrangler.js +10 -1
- package/miniflare-dist/index.mjs +79 -0
- package/miniflare-dist/index.mjs.map +7 -0
- package/package.json +7 -6
- package/pages/functions/filepath-routing.test.ts +125 -25
- package/pages/functions/filepath-routing.ts +6 -3
- package/src/__tests__/configuration.test.ts +826 -223
- package/src/__tests__/dev.test.tsx +145 -9
- package/src/__tests__/guess-worker-format.test.ts +26 -1
- package/src/__tests__/helpers/mock-account-id.ts +4 -0
- package/src/__tests__/helpers/mock-kv.ts +9 -16
- package/src/__tests__/helpers/mock-oauth-flow.ts +178 -0
- package/src/__tests__/helpers/run-in-tmp.ts +3 -0
- package/src/__tests__/index.test.ts +9 -13
- package/src/__tests__/jest.setup.ts +5 -0
- package/src/__tests__/kv.test.ts +43 -71
- package/src/__tests__/pages.test.ts +48 -10
- package/src/__tests__/publish.test.ts +1456 -327
- package/src/__tests__/r2.test.ts +4 -4
- package/src/__tests__/tail.test.ts +78 -4
- package/src/__tests__/user.test.ts +83 -0
- package/src/__tests__/whoami.test.tsx +16 -7
- package/src/bundle.ts +15 -2
- package/src/cfetch/internal.ts +9 -5
- package/src/config/README.md +6 -6
- package/src/config/config.ts +17 -78
- package/src/config/environment.ts +67 -1
- package/src/config/index.ts +13 -3
- package/src/config/validation-helpers.ts +177 -11
- package/src/config/validation.ts +305 -100
- package/src/dev/dev.tsx +76 -41
- package/src/dev/local.tsx +105 -114
- package/src/dev/remote.tsx +2 -0
- package/src/dev/use-esbuild.ts +4 -0
- package/src/entry.ts +103 -6
- package/src/index.tsx +251 -189
- package/src/intl-polyfill.d.ts +139 -0
- package/src/{kv/index.tsx → kv.ts} +8 -28
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +37 -0
- package/src/module-collection.ts +58 -53
- package/src/pages.tsx +26 -10
- package/src/proxy.ts +5 -3
- package/src/publish.ts +17 -21
- package/src/sites.tsx +67 -25
- package/src/tail/index.ts +1 -1
- package/src/tail/printing.ts +2 -2
- package/src/user.tsx +161 -81
- package/wrangler-dist/cli.js +3418 -1437
- package/wrangler-dist/cli.js.map +3 -3
- 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__/r2.test.ts
CHANGED
|
@@ -90,7 +90,7 @@ describe("wrangler", () => {
|
|
|
90
90
|
await expect(
|
|
91
91
|
runWrangler("r2 bucket create abc def ghi")
|
|
92
92
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
93
|
-
`"
|
|
93
|
+
`"Unknown arguments: def, ghi"`
|
|
94
94
|
);
|
|
95
95
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
96
96
|
expect(std.err).toMatchInlineSnapshot(`
|
|
@@ -107,7 +107,7 @@ describe("wrangler", () => {
|
|
|
107
107
|
-v, --version Show version number [boolean]
|
|
108
108
|
--legacy-env Use legacy environments [boolean]
|
|
109
109
|
|
|
110
|
-
|
|
110
|
+
Unknown arguments: def, ghi"
|
|
111
111
|
`);
|
|
112
112
|
});
|
|
113
113
|
|
|
@@ -166,7 +166,7 @@ describe("wrangler", () => {
|
|
|
166
166
|
await expect(
|
|
167
167
|
runWrangler("r2 bucket delete abc def ghi")
|
|
168
168
|
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
169
|
-
`"
|
|
169
|
+
`"Unknown arguments: def, ghi"`
|
|
170
170
|
);
|
|
171
171
|
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
172
172
|
expect(std.err).toMatchInlineSnapshot(`
|
|
@@ -183,7 +183,7 @@ describe("wrangler", () => {
|
|
|
183
183
|
-v, --version Show version number [boolean]
|
|
184
184
|
--legacy-env Use legacy environments [boolean]
|
|
185
185
|
|
|
186
|
-
|
|
186
|
+
Unknown arguments: def, ghi"
|
|
187
187
|
`);
|
|
188
188
|
});
|
|
189
189
|
|
|
@@ -134,7 +134,7 @@ describe("tail", () => {
|
|
|
134
134
|
|
|
135
135
|
it("sends header filters without a query", async () => {
|
|
136
136
|
const api = mockWebsocketAPIs();
|
|
137
|
-
await runWrangler("tail test-worker --header X-CUSTOM-HEADER
|
|
137
|
+
await runWrangler("tail test-worker --header X-CUSTOM-HEADER");
|
|
138
138
|
await expect(api.nextMessageJson()).resolves.toHaveProperty("filters", [
|
|
139
139
|
{ header: { key: "X-CUSTOM-HEADER" } },
|
|
140
140
|
]);
|
|
@@ -142,9 +142,7 @@ describe("tail", () => {
|
|
|
142
142
|
|
|
143
143
|
it("sends header filters with a query", async () => {
|
|
144
144
|
const api = mockWebsocketAPIs();
|
|
145
|
-
await runWrangler(
|
|
146
|
-
"tail test-worker --header X-CUSTOM-HEADER:some-value "
|
|
147
|
-
);
|
|
145
|
+
await runWrangler("tail test-worker --header X-CUSTOM-HEADER:some-value");
|
|
148
146
|
await expect(api.nextMessageJson()).resolves.toHaveProperty("filters", [
|
|
149
147
|
{ header: { key: "X-CUSTOM-HEADER", query: "some-value" } },
|
|
150
148
|
]);
|
|
@@ -268,6 +266,82 @@ describe("tail", () => {
|
|
|
268
266
|
`);
|
|
269
267
|
});
|
|
270
268
|
|
|
269
|
+
it("defaults to logging in pretty format", async () => {
|
|
270
|
+
// the same test as the one before, but without the --format flag
|
|
271
|
+
const api = mockWebsocketAPIs();
|
|
272
|
+
await runWrangler("tail test-worker");
|
|
273
|
+
|
|
274
|
+
const event = generateMockRequestEvent();
|
|
275
|
+
const message = generateMockEventMessage({ event });
|
|
276
|
+
const serializedMessage = serialize(message);
|
|
277
|
+
|
|
278
|
+
api.ws.send(serializedMessage);
|
|
279
|
+
expect(
|
|
280
|
+
std.out
|
|
281
|
+
.replace(
|
|
282
|
+
new Date(mockEventTimestamp).toLocaleString(),
|
|
283
|
+
"[mock event timestamp]"
|
|
284
|
+
)
|
|
285
|
+
.replace(
|
|
286
|
+
mockTailExpiration.toLocaleString(),
|
|
287
|
+
"[mock expiration date]"
|
|
288
|
+
)
|
|
289
|
+
).toMatchInlineSnapshot(`
|
|
290
|
+
"successfully created tail, expires at [mock expiration date]
|
|
291
|
+
Connected to test-worker, waiting for logs...
|
|
292
|
+
GET https://example.org/ - Ok @ [mock event timestamp]"
|
|
293
|
+
`);
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
it("logs console messages and exceptions", async () => {
|
|
297
|
+
const api = mockWebsocketAPIs();
|
|
298
|
+
await runWrangler("tail test-worker");
|
|
299
|
+
|
|
300
|
+
const event = generateMockRequestEvent();
|
|
301
|
+
const message = generateMockEventMessage({
|
|
302
|
+
event,
|
|
303
|
+
logs: [
|
|
304
|
+
{ message: ["some string"], level: "log", timestamp: 1234561 },
|
|
305
|
+
{
|
|
306
|
+
message: [{ complex: "object" }],
|
|
307
|
+
level: "log",
|
|
308
|
+
timestamp: 1234562,
|
|
309
|
+
},
|
|
310
|
+
{ message: [1234], level: "error", timestamp: 1234563 },
|
|
311
|
+
],
|
|
312
|
+
exceptions: [
|
|
313
|
+
{ name: "Error", message: "some error", timestamp: 1234564 },
|
|
314
|
+
{ name: "Error", message: { complex: "error" }, timestamp: 1234564 },
|
|
315
|
+
],
|
|
316
|
+
});
|
|
317
|
+
const serializedMessage = serialize(message);
|
|
318
|
+
|
|
319
|
+
api.ws.send(serializedMessage);
|
|
320
|
+
expect(
|
|
321
|
+
std.out
|
|
322
|
+
.replace(
|
|
323
|
+
new Date(mockEventTimestamp).toLocaleString(),
|
|
324
|
+
"[mock event timestamp]"
|
|
325
|
+
)
|
|
326
|
+
.replace(
|
|
327
|
+
mockTailExpiration.toLocaleString(),
|
|
328
|
+
"[mock expiration date]"
|
|
329
|
+
)
|
|
330
|
+
).toMatchInlineSnapshot(`
|
|
331
|
+
"successfully created tail, expires at [mock expiration date]
|
|
332
|
+
Connected to test-worker, waiting for logs...
|
|
333
|
+
GET https://example.org/ - Ok @ [mock event timestamp]
|
|
334
|
+
(log) some string
|
|
335
|
+
(log) { complex: 'object' }
|
|
336
|
+
(error) 1234"
|
|
337
|
+
`);
|
|
338
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
339
|
+
" Error: some error
|
|
340
|
+
Error: { complex: 'error' }"
|
|
341
|
+
`);
|
|
342
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
343
|
+
});
|
|
344
|
+
|
|
271
345
|
it("logs scheduled messages in pretty format", async () => {
|
|
272
346
|
const api = mockWebsocketAPIs();
|
|
273
347
|
await runWrangler("tail test-worker --format pretty");
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
+
USER_AUTH_CONFIG_FILE,
|
|
8
|
+
writeAuthConfigFile,
|
|
9
|
+
} from "../user";
|
|
10
|
+
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
11
|
+
import { mockOAuthFlow } from "./helpers/mock-oauth-flow";
|
|
12
|
+
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
13
|
+
import { runWrangler } from "./helpers/run-wrangler";
|
|
14
|
+
import type { UserAuthConfig } from "../user";
|
|
15
|
+
|
|
16
|
+
describe("wrangler", () => {
|
|
17
|
+
runInTempDir({ homedir: "./home" });
|
|
18
|
+
const std = mockConsoleMethods();
|
|
19
|
+
const {
|
|
20
|
+
mockGrantAccessToken,
|
|
21
|
+
mockGrantAuthorization,
|
|
22
|
+
mockRevokeAuthorization,
|
|
23
|
+
} = mockOAuthFlow();
|
|
24
|
+
|
|
25
|
+
describe("login", () => {
|
|
26
|
+
it("should should log in a user when `wrangler login` is run", async () => {
|
|
27
|
+
const accessTokenRequest = mockGrantAccessToken({ respondWith: "ok" });
|
|
28
|
+
mockGrantAuthorization({ respondWith: "success" });
|
|
29
|
+
|
|
30
|
+
await runWrangler("login");
|
|
31
|
+
|
|
32
|
+
expect(accessTokenRequest.actual.url).toEqual(
|
|
33
|
+
accessTokenRequest.expected.url
|
|
34
|
+
);
|
|
35
|
+
expect(accessTokenRequest.actual.method).toEqual(
|
|
36
|
+
accessTokenRequest.expected.method
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
expect(std.out).toMatchInlineSnapshot(`
|
|
40
|
+
"Attempting to login via OAuth...
|
|
41
|
+
Successfully logged in."
|
|
42
|
+
`);
|
|
43
|
+
|
|
44
|
+
expect(readAuthConfigFile()).toEqual<UserAuthConfig>({
|
|
45
|
+
api_token: undefined,
|
|
46
|
+
oauth_token: "test-access-token",
|
|
47
|
+
refresh_token: "test-refresh-token",
|
|
48
|
+
expiration_time: expect.any(String),
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("logout", () => {
|
|
54
|
+
it("should exit with a message stating the user is not logged in", async () => {
|
|
55
|
+
await runWrangler("logout");
|
|
56
|
+
expect(std.out).toMatchInlineSnapshot(`"Not logged in, exiting..."`);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("should logout user that has been properly logged in", async () => {
|
|
60
|
+
writeAuthConfigFile({
|
|
61
|
+
oauth_token: "some-oauth-tok",
|
|
62
|
+
refresh_token: "some-refresh-tok",
|
|
63
|
+
});
|
|
64
|
+
const outcome = mockRevokeAuthorization();
|
|
65
|
+
|
|
66
|
+
await runWrangler("logout");
|
|
67
|
+
|
|
68
|
+
expect(outcome.actual.url).toEqual(
|
|
69
|
+
"https://dash.cloudflare.com/oauth2/revoke"
|
|
70
|
+
);
|
|
71
|
+
expect(outcome.actual.method).toEqual("POST");
|
|
72
|
+
|
|
73
|
+
expect(std.out).toMatchInlineSnapshot(`"Successfully logged out."`);
|
|
74
|
+
|
|
75
|
+
// Make sure that we made the request to logout.
|
|
76
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
77
|
+
|
|
78
|
+
// Make sure that logout removed the config file containing the auth tokens.
|
|
79
|
+
const config = path.join(os.homedir(), USER_AUTH_CONFIG_FILE);
|
|
80
|
+
expect(fs.existsSync(config)).toBeFalsy();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -1,30 +1,30 @@
|
|
|
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
7
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
8
8
|
import type { UserInfo } from "../whoami";
|
|
9
9
|
|
|
10
10
|
describe("getUserInfo()", () => {
|
|
11
11
|
runInTempDir({ homedir: "./home" });
|
|
12
|
+
const std = mockConsoleMethods();
|
|
12
13
|
|
|
13
14
|
it("should return undefined if there is no config file", async () => {
|
|
14
|
-
await initialise();
|
|
15
15
|
const userInfo = await getUserInfo();
|
|
16
16
|
expect(userInfo).toBeUndefined();
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
it("should return undefined if there is an empty config file", async () => {
|
|
20
|
-
|
|
21
|
-
await initialise();
|
|
20
|
+
writeAuthConfigFile({});
|
|
22
21
|
const userInfo = await getUserInfo();
|
|
23
22
|
expect(userInfo).toBeUndefined();
|
|
24
23
|
});
|
|
25
24
|
|
|
26
25
|
it("should return the user's email and accounts if authenticated via config token", async () => {
|
|
27
|
-
|
|
26
|
+
writeAuthConfigFile({ oauth_token: "some-oauth-token" });
|
|
27
|
+
|
|
28
28
|
setMockResponse("/user", () => {
|
|
29
29
|
return { email: "user@example.com" };
|
|
30
30
|
});
|
|
@@ -36,7 +36,6 @@ describe("getUserInfo()", () => {
|
|
|
36
36
|
];
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
await initialise();
|
|
40
39
|
const userInfo = await getUserInfo();
|
|
41
40
|
|
|
42
41
|
expect(userInfo).toEqual({
|
|
@@ -50,6 +49,16 @@ describe("getUserInfo()", () => {
|
|
|
50
49
|
],
|
|
51
50
|
});
|
|
52
51
|
});
|
|
52
|
+
|
|
53
|
+
it("should display a warning message if the config file contains a legacy api_token field", async () => {
|
|
54
|
+
writeAuthConfigFile({ api_token: "API_TOKEN" });
|
|
55
|
+
await getUserInfo();
|
|
56
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
57
|
+
"It looks like you have used Wrangler 1's \`config\` command to login with an API token.
|
|
58
|
+
This is no longer supported in the current version of Wrangler.
|
|
59
|
+
If you wish to authenticate via an API token then please set the \`CLOUDFLARE_API_TOKEN\` environment variable."
|
|
60
|
+
`);
|
|
61
|
+
});
|
|
53
62
|
});
|
|
54
63
|
|
|
55
64
|
describe("WhoAmI component", () => {
|
package/src/bundle.ts
CHANGED
|
@@ -26,10 +26,17 @@ export async function bundleWorker(
|
|
|
26
26
|
jsxFragment: string | undefined;
|
|
27
27
|
rules: Config["rules"];
|
|
28
28
|
watch?: esbuild.WatchMode;
|
|
29
|
+
tsconfig: string | undefined;
|
|
29
30
|
}
|
|
30
31
|
): Promise<BundleResult> {
|
|
31
|
-
const {
|
|
32
|
-
|
|
32
|
+
const {
|
|
33
|
+
serveAssetsFromWorker,
|
|
34
|
+
jsxFactory,
|
|
35
|
+
jsxFragment,
|
|
36
|
+
rules,
|
|
37
|
+
watch,
|
|
38
|
+
tsconfig,
|
|
39
|
+
} = options;
|
|
33
40
|
const entryDirectory = path.dirname(entry.file);
|
|
34
41
|
const moduleCollector = createModuleCollector({
|
|
35
42
|
wrangler1xlegacyModuleReferences: {
|
|
@@ -57,6 +64,11 @@ export async function bundleWorker(
|
|
|
57
64
|
sourcemap: true,
|
|
58
65
|
metafile: true,
|
|
59
66
|
conditions: ["worker", "browser"],
|
|
67
|
+
...(process.env.NODE_ENV && {
|
|
68
|
+
define: {
|
|
69
|
+
"process.env.NODE_ENV": `"${process.env.NODE_ENV}"`,
|
|
70
|
+
},
|
|
71
|
+
}),
|
|
60
72
|
loader: {
|
|
61
73
|
".js": "jsx",
|
|
62
74
|
".mjs": "jsx",
|
|
@@ -65,6 +77,7 @@ export async function bundleWorker(
|
|
|
65
77
|
plugins: [moduleCollector.plugin],
|
|
66
78
|
...(jsxFactory && { jsxFactory }),
|
|
67
79
|
...(jsxFragment && { jsxFragment }),
|
|
80
|
+
...(tsconfig && { tsconfig }),
|
|
68
81
|
watch,
|
|
69
82
|
});
|
|
70
83
|
|
package/src/cfetch/internal.ts
CHANGED
|
@@ -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 { reportError } from "../reporting";
|
|
@@ -74,7 +74,11 @@ function truncate(text: string, maxLength: number): string {
|
|
|
74
74
|
function cloneHeaders(
|
|
75
75
|
headers: HeadersInit | undefined
|
|
76
76
|
): Record<string, string> {
|
|
77
|
-
return
|
|
77
|
+
return headers instanceof Headers
|
|
78
|
+
? Object.fromEntries(headers.entries())
|
|
79
|
+
: Array.isArray(headers)
|
|
80
|
+
? Object.fromEntries(headers)
|
|
81
|
+
: { ...headers };
|
|
78
82
|
}
|
|
79
83
|
|
|
80
84
|
async function requireLoggedIn(): Promise<void> {
|
|
@@ -85,11 +89,11 @@ async function requireLoggedIn(): Promise<void> {
|
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
function requireApiToken(): string {
|
|
88
|
-
const
|
|
89
|
-
if (!
|
|
92
|
+
const authToken = getAPIToken();
|
|
93
|
+
if (!authToken) {
|
|
90
94
|
throw new Error("No API token found.");
|
|
91
95
|
}
|
|
92
|
-
return
|
|
96
|
+
return authToken;
|
|
93
97
|
}
|
|
94
98
|
|
|
95
99
|
function addAuthorizationHeader(
|
package/src/config/README.md
CHANGED
|
@@ -25,24 +25,23 @@ 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
|
|
@@ -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
|
*/
|
|
@@ -158,35 +135,13 @@ export interface ConfigFields<
|
|
|
158
135
|
[key: string]: string;
|
|
159
136
|
}
|
|
160
137
|
| undefined;
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Configures a custom build step to be run by Wrangler when building your Worker.
|
|
164
|
-
*
|
|
165
|
-
* Refer to the [custom builds documentation](https://developers.cloudflare.com/workers/cli-wrangler/configuration#build)
|
|
166
|
-
* for more details.
|
|
167
|
-
*
|
|
168
|
-
* @default {}
|
|
169
|
-
*/
|
|
170
|
-
build: {
|
|
171
|
-
/** 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. */
|
|
172
|
-
command?: string;
|
|
173
|
-
/** The directory in which the command is executed. */
|
|
174
|
-
cwd?: string;
|
|
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
|
-
};
|
|
183
138
|
}
|
|
184
139
|
|
|
185
140
|
export interface DevConfig {
|
|
186
141
|
/**
|
|
187
142
|
* IP address for the local dev server to listen on,
|
|
188
143
|
*
|
|
189
|
-
* @default `
|
|
144
|
+
* @default `localhost`
|
|
190
145
|
* @todo this needs to be implemented
|
|
191
146
|
*/
|
|
192
147
|
ip: string;
|
|
@@ -244,36 +199,20 @@ export interface DeprecatedConfigFields {
|
|
|
244
199
|
webpack_config?: string;
|
|
245
200
|
}
|
|
246
201
|
|
|
247
|
-
|
|
248
|
-
* Deprecated upload configuration.
|
|
249
|
-
*/
|
|
250
|
-
export interface DeprecatedUpload {
|
|
202
|
+
interface EnvironmentMap {
|
|
251
203
|
/**
|
|
252
|
-
* The
|
|
204
|
+
* The `env` section defines overrides for the configuration for different environments.
|
|
253
205
|
*
|
|
254
|
-
*
|
|
255
|
-
*/
|
|
256
|
-
format?: "modules" | "service-worker";
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* The directory you wish to upload your worker from,
|
|
260
|
-
* relative to the wrangler.toml file.
|
|
206
|
+
* All environment fields can be specified at the top level of the config indicating the default environment settings.
|
|
261
207
|
*
|
|
262
|
-
*
|
|
208
|
+
* - Some fields are inherited and overridable in each environment.
|
|
209
|
+
* - But some are not inherited and must be explicitly specified in every environment, if they are specified at the top level.
|
|
263
210
|
*
|
|
264
|
-
*
|
|
265
|
-
*/
|
|
266
|
-
dir?: string;
|
|
267
|
-
|
|
268
|
-
/**
|
|
269
|
-
* The path to the Worker script, relative to `upload.dir`.
|
|
211
|
+
* For more information, see the documentation at https://developers.cloudflare.com/workers/cli-wrangler/configuration#environments
|
|
270
212
|
*
|
|
271
|
-
* @
|
|
272
|
-
*/
|
|
273
|
-
main?: string;
|
|
274
|
-
|
|
275
|
-
/**
|
|
276
|
-
* @deprecated This is now defined at the top level `rules` field.
|
|
213
|
+
* @default `{}`
|
|
277
214
|
*/
|
|
278
|
-
|
|
215
|
+
env?: {
|
|
216
|
+
[envName: string]: RawEnvironment;
|
|
217
|
+
};
|
|
279
218
|
}
|
|
@@ -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.
|
|
@@ -82,6 +87,11 @@ interface EnvironmentInheritable {
|
|
|
82
87
|
*/
|
|
83
88
|
route: string | undefined;
|
|
84
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Path to a custom tsconfig
|
|
92
|
+
*/
|
|
93
|
+
tsconfig: string | undefined;
|
|
94
|
+
|
|
85
95
|
/**
|
|
86
96
|
* The function to use to replace jsx syntax.
|
|
87
97
|
*
|
|
@@ -133,6 +143,28 @@ interface EnvironmentInheritable {
|
|
|
133
143
|
*/
|
|
134
144
|
rules: Rule[];
|
|
135
145
|
|
|
146
|
+
/**
|
|
147
|
+
* Configures a custom build step to be run by Wrangler when building your Worker.
|
|
148
|
+
*
|
|
149
|
+
* Refer to the [custom builds documentation](https://developers.cloudflare.com/workers/cli-wrangler/configuration#build)
|
|
150
|
+
* for more details.
|
|
151
|
+
*
|
|
152
|
+
* @default {}
|
|
153
|
+
*/
|
|
154
|
+
build: {
|
|
155
|
+
/** 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. */
|
|
156
|
+
command?: string;
|
|
157
|
+
/** The directory in which the command is executed. */
|
|
158
|
+
cwd?: string;
|
|
159
|
+
/** The directory to watch for changes while using wrangler dev, defaults to the current working directory */
|
|
160
|
+
watch_dir?: string;
|
|
161
|
+
/**
|
|
162
|
+
* Deprecated field previously used to configure the build and upload of the script.
|
|
163
|
+
* @deprecated
|
|
164
|
+
*/
|
|
165
|
+
upload?: DeprecatedUpload;
|
|
166
|
+
};
|
|
167
|
+
|
|
136
168
|
/**
|
|
137
169
|
* TODO: remove this as it has been deprecated.
|
|
138
170
|
*
|
|
@@ -277,6 +309,40 @@ interface EnvironmentDeprecated {
|
|
|
277
309
|
}[];
|
|
278
310
|
}
|
|
279
311
|
|
|
312
|
+
/**
|
|
313
|
+
* Deprecated upload configuration.
|
|
314
|
+
*/
|
|
315
|
+
export interface DeprecatedUpload {
|
|
316
|
+
/**
|
|
317
|
+
* The format of the Worker script.
|
|
318
|
+
*
|
|
319
|
+
* @deprecated We infer the format automatically now.
|
|
320
|
+
*/
|
|
321
|
+
format?: "modules" | "service-worker";
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* The directory you wish to upload your worker from,
|
|
325
|
+
* relative to the wrangler.toml file.
|
|
326
|
+
*
|
|
327
|
+
* Defaults to the directory containing the wrangler.toml file.
|
|
328
|
+
*
|
|
329
|
+
* @deprecated
|
|
330
|
+
*/
|
|
331
|
+
dir?: string;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* The path to the Worker script, relative to `upload.dir`.
|
|
335
|
+
*
|
|
336
|
+
* @deprecated This will be replaced by a command line argument.
|
|
337
|
+
*/
|
|
338
|
+
main?: string;
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* @deprecated This is now defined at the top level `rules` field.
|
|
342
|
+
*/
|
|
343
|
+
rules?: Environment["rules"];
|
|
344
|
+
}
|
|
345
|
+
|
|
280
346
|
/**
|
|
281
347
|
* The raw environment configuration that we read from the config file.
|
|
282
348
|
*
|
package/src/config/index.ts
CHANGED
|
@@ -3,7 +3,13 @@ import { parseTOML, readFileSync } from "../parse";
|
|
|
3
3
|
import { normalizeAndValidateConfig } from "./validation";
|
|
4
4
|
import type { Config, RawConfig } from "./config";
|
|
5
5
|
|
|
6
|
-
export type {
|
|
6
|
+
export type {
|
|
7
|
+
Config,
|
|
8
|
+
RawConfig,
|
|
9
|
+
ConfigFields,
|
|
10
|
+
DevConfig,
|
|
11
|
+
RawDevConfig,
|
|
12
|
+
} from "./config";
|
|
7
13
|
export type {
|
|
8
14
|
Environment,
|
|
9
15
|
RawEnvironment,
|
|
@@ -13,7 +19,10 @@ export type {
|
|
|
13
19
|
/**
|
|
14
20
|
* Get the Wrangler configuration; read it from the give `configPath` if available.
|
|
15
21
|
*/
|
|
16
|
-
export function readConfig(
|
|
22
|
+
export function readConfig(
|
|
23
|
+
configPath: string | undefined,
|
|
24
|
+
args: unknown
|
|
25
|
+
): Config {
|
|
17
26
|
let rawConfig: RawConfig = {};
|
|
18
27
|
if (!configPath) {
|
|
19
28
|
configPath = findWranglerToml();
|
|
@@ -27,7 +36,8 @@ export function readConfig(configPath?: string): Config {
|
|
|
27
36
|
// Process the top-level configuration.
|
|
28
37
|
const { config, diagnostics } = normalizeAndValidateConfig(
|
|
29
38
|
rawConfig,
|
|
30
|
-
configPath
|
|
39
|
+
configPath,
|
|
40
|
+
args
|
|
31
41
|
);
|
|
32
42
|
|
|
33
43
|
if (diagnostics.hasWarnings()) {
|