wrangler 0.0.0-e3cab74 → 0.0.0-e452a35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cloudflare_CA.pem +18 -0
- package/README.md +27 -14
- package/bin/wrangler.js +49 -5
- package/miniflare-dist/index.mjs +4886 -0
- package/package.json +42 -28
- package/pages/functions/buildPlugin.ts +105 -0
- package/pages/functions/buildWorker.ts +93 -4
- package/pages/functions/filepath-routing.test.ts +136 -25
- package/pages/functions/filepath-routing.ts +14 -3
- package/pages/functions/routes.ts +6 -1
- package/pages/functions/template-plugin.ts +147 -0
- package/pages/functions/template-worker.ts +21 -8
- package/src/__tests__/config-cache.test.ts +36 -0
- package/src/__tests__/configuration.test.ts +1514 -367
- package/src/__tests__/dev.test.tsx +870 -84
- package/src/__tests__/guess-worker-format.test.ts +37 -18
- package/src/__tests__/helpers/mock-account-id.ts +22 -4
- package/src/__tests__/helpers/mock-cfetch.ts +8 -4
- package/src/__tests__/helpers/mock-console.ts +35 -10
- package/src/__tests__/helpers/mock-dialogs.ts +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/mock-stdin.ts +103 -0
- package/src/__tests__/helpers/run-in-tmp.ts +10 -0
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/https-options.test.ts +130 -0
- package/src/__tests__/index.test.ts +137 -747
- package/src/__tests__/init.test.ts +1557 -0
- package/src/__tests__/jest.setup.ts +28 -8
- package/src/__tests__/kv.test.ts +598 -258
- package/src/__tests__/logger.test.ts +115 -0
- package/src/__tests__/pages.test.ts +657 -0
- package/src/__tests__/parse.test.ts +8 -0
- package/src/__tests__/publish.test.ts +4003 -941
- package/src/__tests__/r2.test.ts +69 -34
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +228 -73
- package/src/__tests__/tail.test.ts +146 -20
- package/src/__tests__/user.test.ts +131 -0
- package/src/__tests__/whoami.test.tsx +26 -7
- package/src/abort.d.ts +3 -0
- package/src/bundle.ts +74 -7
- package/src/cfetch/index.ts +21 -4
- package/src/cfetch/internal.ts +20 -14
- package/src/cli.ts +5 -11
- package/src/config/README.md +7 -7
- package/src/config/config.ts +69 -100
- package/src/config/environment.ts +119 -4
- package/src/config/index.ts +177 -4
- package/src/config/validation-helpers.ts +228 -23
- package/src/config/validation.ts +687 -174
- package/src/config-cache.ts +45 -0
- package/src/{api/preview.ts → create-worker-preview.ts} +74 -36
- package/src/{api/form_data.ts → create-worker-upload-form.ts} +55 -18
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +422 -0
- package/src/dev/local.tsx +318 -0
- package/src/dev/remote.tsx +227 -0
- package/src/dev/use-esbuild.ts +118 -0
- package/src/dialogs.tsx +16 -6
- package/src/durable.ts +102 -0
- package/src/entry.ts +279 -14
- package/src/environment-variables.ts +3 -1
- package/src/errors.ts +11 -0
- package/src/https-options.ts +123 -0
- package/src/index.tsx +1268 -806
- package/src/inspect.ts +64 -11
- package/src/intl-polyfill.d.ts +139 -0
- package/src/{kv.tsx → kv.ts} +195 -62
- package/src/logger.ts +66 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/enum-keys.ts +17 -0
- package/src/miniflare-cli/index.ts +41 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +94 -6
- package/src/open-in-browser.ts +9 -3
- package/src/package-manager.ts +9 -8
- package/src/pages.tsx +1057 -75
- package/src/parse.ts +24 -5
- package/src/proxy.ts +143 -54
- package/src/publish.ts +444 -229
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +98 -44
- 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 +263 -109
- package/src/whoami.tsx +2 -1
- package/src/{api/worker.ts → worker.ts} +24 -30
- package/templates/gitignore +171 -0
- package/templates/new-worker.ts +16 -1
- package/templates/static-asset-facade.js +1 -1
- package/wrangler-dist/cli.js +55345 -69246
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/__tests__/logout.test.ts +0 -50
- package/src/__tests__/sentry.test.ts +0 -146
- package/src/dev.tsx +0 -961
- package/src/guess-worker-format.ts +0 -68
- package/src/reporting.ts +0 -115
- package/wrangler-dist/cli.js.map +0 -7
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
|
|
5
|
-
export function writeUserConfig(
|
|
6
|
-
oauth_token?: string,
|
|
7
|
-
refresh_token?: string,
|
|
8
|
-
expiration_time?: string
|
|
9
|
-
) {
|
|
10
|
-
const lines: string[] = [];
|
|
11
|
-
if (oauth_token) {
|
|
12
|
-
lines.push(`oauth_token = "${oauth_token}"`);
|
|
13
|
-
}
|
|
14
|
-
if (refresh_token) {
|
|
15
|
-
lines.push(`refresh_token = "${refresh_token}"`);
|
|
16
|
-
}
|
|
17
|
-
if (expiration_time) {
|
|
18
|
-
lines.push(`expiration_time = "${expiration_time}"`);
|
|
19
|
-
}
|
|
20
|
-
const configPath = path.join(os.homedir(), ".wrangler/config");
|
|
21
|
-
mkdirSync(configPath, { recursive: true });
|
|
22
|
-
writeFileSync(
|
|
23
|
-
path.join(configPath, "default.toml"),
|
|
24
|
-
lines.join("\n"),
|
|
25
|
-
"utf-8"
|
|
26
|
-
);
|
|
27
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { existsSync } from "node:fs";
|
|
2
|
-
import os from "node:os";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
import fetchMock from "jest-fetch-mock";
|
|
5
|
-
import { initialise } from "../user";
|
|
6
|
-
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
7
|
-
import { writeUserConfig } from "./helpers/mock-user";
|
|
8
|
-
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
9
|
-
import { runWrangler } from "./helpers/run-wrangler";
|
|
10
|
-
|
|
11
|
-
describe("wrangler", () => {
|
|
12
|
-
runInTempDir({ homedir: "./home" });
|
|
13
|
-
const std = mockConsoleMethods();
|
|
14
|
-
|
|
15
|
-
describe("logout", () => {
|
|
16
|
-
it("should exit with a message stating the user is not logged in", async () => {
|
|
17
|
-
await initialise();
|
|
18
|
-
await runWrangler("logout");
|
|
19
|
-
expect(std.out).toMatchInlineSnapshot(`"Not logged in, exiting..."`);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("should logout user that has been properly logged in", async () => {
|
|
23
|
-
writeUserConfig("some-oauth-tok", "some-refresh-tok");
|
|
24
|
-
|
|
25
|
-
// Mock out the response for a request to revoke the auth tokens,
|
|
26
|
-
// checking the form of the request is as expected.
|
|
27
|
-
fetchMock.mockResponseOnce(async (req) => {
|
|
28
|
-
expect(req.url).toEqual("https://dash.cloudflare.com/oauth2/revoke");
|
|
29
|
-
expect(req.method).toEqual("POST");
|
|
30
|
-
return "";
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
await initialise();
|
|
34
|
-
await runWrangler("logout");
|
|
35
|
-
|
|
36
|
-
expect(std.out).toMatchInlineSnapshot(`
|
|
37
|
-
"💁 Wrangler is configured with an OAuth token. The token has been successfully revoked
|
|
38
|
-
Removing ./home/.wrangler/config/default.toml.. success!"
|
|
39
|
-
`);
|
|
40
|
-
|
|
41
|
-
// Make sure that we made the request to logout.
|
|
42
|
-
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
43
|
-
|
|
44
|
-
// Make sure that logout removed the config file containing the auth tokens.
|
|
45
|
-
expect(
|
|
46
|
-
existsSync(path.join(os.homedir(), ".wrangler/config/default.toml"))
|
|
47
|
-
).toBe(false);
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
});
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import * as fs from "node:fs";
|
|
2
|
-
import * as fsp from "node:fs/promises";
|
|
3
|
-
import os from "node:os";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
import * as TOML from "@iarna/toml";
|
|
6
|
-
import * as Sentry from "@sentry/node";
|
|
7
|
-
import prompts from "prompts";
|
|
8
|
-
|
|
9
|
-
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
10
|
-
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
11
|
-
import { runWrangler } from "./helpers/run-wrangler";
|
|
12
|
-
const { reportError } = jest.requireActual("../reporting");
|
|
13
|
-
|
|
14
|
-
describe("Error Reporting", () => {
|
|
15
|
-
runInTempDir({ homedir: "./home" });
|
|
16
|
-
mockConsoleMethods();
|
|
17
|
-
const reportingTOMLPath = ".wrangler/config/reporting.toml";
|
|
18
|
-
|
|
19
|
-
const originalTTY = process.stdout.isTTY;
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
jest.mock("@sentry/node");
|
|
22
|
-
jest.spyOn(Sentry, "captureException");
|
|
23
|
-
process.stdout.isTTY = true;
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
afterEach(() => {
|
|
27
|
-
jest.unmock("@sentry/node");
|
|
28
|
-
jest.clearAllMocks();
|
|
29
|
-
process.stdout.isTTY = originalTTY;
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("should confirm user will allow error reporting usage", async () => {
|
|
33
|
-
jest.spyOn(prompts, "prompt").mockResolvedValue({ sentryDecision: true });
|
|
34
|
-
|
|
35
|
-
await reportError(new Error("test error"), "testFalse");
|
|
36
|
-
|
|
37
|
-
const { error_tracking_opt, error_tracking_opt_date } = TOML.parse(
|
|
38
|
-
await fsp.readFile(path.join(os.homedir(), reportingTOMLPath), "utf-8")
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
expect(error_tracking_opt).toBe(true);
|
|
42
|
-
expect(error_tracking_opt_date).toBeTruthy();
|
|
43
|
-
|
|
44
|
-
expect(Sentry.captureException).toHaveBeenCalledWith(
|
|
45
|
-
new Error("test error")
|
|
46
|
-
);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("should confirm user will disallow error reporting usage", async () => {
|
|
50
|
-
jest.spyOn(prompts, "prompt").mockResolvedValue({ sentryDecision: false });
|
|
51
|
-
await reportError(new Error("test error"), "testFalse");
|
|
52
|
-
|
|
53
|
-
const { error_tracking_opt, error_tracking_opt_date } = TOML.parse(
|
|
54
|
-
await fsp.readFile(path.join(os.homedir(), reportingTOMLPath), "utf-8")
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
expect(error_tracking_opt).toBe(false);
|
|
58
|
-
expect(error_tracking_opt_date).toBeTruthy();
|
|
59
|
-
|
|
60
|
-
expect(Sentry.captureException).not.toHaveBeenCalledWith(
|
|
61
|
-
new Error("test error"),
|
|
62
|
-
"testFalse"
|
|
63
|
-
);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("should confirm user will allow 'once' error reporting usage", async () => {
|
|
67
|
-
jest.spyOn(prompts, "prompt").mockResolvedValue({ sentryDecision: "once" });
|
|
68
|
-
await runWrangler();
|
|
69
|
-
await reportError(new Error("test error"), "testFalse");
|
|
70
|
-
|
|
71
|
-
expect(fs.existsSync(path.join(os.homedir(), reportingTOMLPath))).toBe(
|
|
72
|
-
false
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
expect(Sentry.captureException).not.toHaveBeenCalledWith(
|
|
76
|
-
new Error("test error"),
|
|
77
|
-
"testFalse"
|
|
78
|
-
);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it("should not prompt w/ subsequent Errors after user disallows error reporting", async () => {
|
|
82
|
-
jest.spyOn(prompts, "prompt").mockResolvedValue({ sentryDecision: false });
|
|
83
|
-
await reportError(new Error("test error"), "testFalse");
|
|
84
|
-
|
|
85
|
-
expect(Sentry.captureException).not.toHaveBeenCalledWith(
|
|
86
|
-
new Error("test error"),
|
|
87
|
-
"testFalse"
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
await reportError(new Error("second test error"), "testFalse");
|
|
91
|
-
expect(Sentry.captureException).not.toHaveBeenCalledWith(
|
|
92
|
-
new Error("second test error"),
|
|
93
|
-
"testFalse"
|
|
94
|
-
);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("should not prompt w/ subsequent Errors after user Always allows error reporting", async () => {
|
|
98
|
-
jest.spyOn(prompts, "prompt").mockResolvedValue({ sentryDecision: true });
|
|
99
|
-
await reportError(new Error("test error"), "testFalse");
|
|
100
|
-
|
|
101
|
-
expect(Sentry.captureException).toHaveBeenCalledWith(
|
|
102
|
-
new Error("test error")
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
await reportError(new Error("second test error"), "testFalse");
|
|
106
|
-
expect(Sentry.captureException).toHaveBeenCalledWith(
|
|
107
|
-
new Error("second test error")
|
|
108
|
-
);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("should prompt w/ subsequent Errors after user allows error reporting once", async () => {
|
|
112
|
-
const promptSpy = jest
|
|
113
|
-
.spyOn(prompts, "prompt")
|
|
114
|
-
.mockResolvedValue({ sentryDecision: "once" });
|
|
115
|
-
await reportError(new Error("test error"), "testFalse");
|
|
116
|
-
|
|
117
|
-
expect(Sentry.captureException).toHaveBeenCalledWith(
|
|
118
|
-
new Error("test error")
|
|
119
|
-
);
|
|
120
|
-
|
|
121
|
-
await reportError(new Error("second test error"), "testFalse");
|
|
122
|
-
expect(Sentry.captureException).toHaveBeenCalledWith(
|
|
123
|
-
new Error("second test error")
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
expect(promptSpy).toBeCalledTimes(2);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("should not prompt in non-TTY environment", async () => {
|
|
130
|
-
process.stdout.isTTY = false;
|
|
131
|
-
|
|
132
|
-
await reportError(new Error("test error"), "testFalse");
|
|
133
|
-
|
|
134
|
-
const { error_tracking_opt, error_tracking_opt_date } = TOML.parse(
|
|
135
|
-
await fsp.readFile(path.join(os.homedir(), reportingTOMLPath), "utf-8")
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
expect(error_tracking_opt).toBe(false);
|
|
139
|
-
expect(error_tracking_opt_date).toBeTruthy();
|
|
140
|
-
|
|
141
|
-
expect(Sentry.captureException).not.toHaveBeenCalledWith(
|
|
142
|
-
new Error("test error")
|
|
143
|
-
);
|
|
144
|
-
process.stdout.isTTY = originalTTY;
|
|
145
|
-
});
|
|
146
|
-
});
|