wrangler 0.0.0-fb43821 → 0.0.0-fb53fda
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 +1 -1
- package/bin/wrangler.js +12 -3
- package/miniflare-dist/index.mjs +79 -0
- package/miniflare-dist/index.mjs.map +7 -0
- package/package.json +46 -17
- package/pages/functions/buildWorker.ts +62 -0
- package/pages/functions/filepath-routing.test.ts +223 -0
- package/pages/functions/filepath-routing.ts +181 -0
- package/pages/functions/identifiers.ts +78 -0
- package/pages/functions/routes.ts +151 -0
- package/pages/functions/template-worker.ts +130 -0
- package/src/__tests__/configuration.test.ts +2790 -0
- package/src/__tests__/dev.test.tsx +532 -0
- package/src/__tests__/guess-worker-format.test.ts +68 -0
- package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
- package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
- package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +48 -0
- package/src/__tests__/helpers/mock-bin.ts +36 -0
- package/src/__tests__/helpers/mock-cfetch.ts +207 -0
- package/src/__tests__/helpers/mock-console.ts +70 -0
- package/src/__tests__/helpers/mock-dialogs.ts +65 -0
- package/src/__tests__/helpers/mock-kv.ts +33 -0
- package/src/__tests__/helpers/mock-stdin.ts +103 -0
- package/src/__tests__/helpers/mock-web-socket.ts +29 -0
- package/src/__tests__/helpers/run-in-tmp.ts +32 -0
- package/src/__tests__/helpers/run-wrangler.ts +16 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
- package/src/__tests__/https-options.test.ts +127 -0
- package/src/__tests__/index.test.ts +770 -209
- package/src/__tests__/jest.setup.ts +69 -0
- package/src/__tests__/kv.test.ts +1380 -0
- package/src/__tests__/logout.test.ts +52 -0
- package/src/__tests__/package-manager.test.ts +206 -0
- package/src/__tests__/pages.test.ts +82 -0
- package/src/__tests__/parse.test.ts +322 -0
- package/src/__tests__/publish.test.ts +3431 -0
- package/src/__tests__/r2.test.ts +198 -0
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +425 -0
- package/src/__tests__/sentry.test.ts +146 -0
- package/src/__tests__/tail.test.ts +562 -0
- package/src/__tests__/whoami.test.tsx +100 -0
- package/src/bundle.ts +142 -0
- package/src/cfetch/index.ts +104 -0
- package/src/cfetch/internal.ts +139 -0
- package/src/cli.ts +16 -7
- package/src/config/README.md +107 -0
- package/src/config/config.ts +218 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +366 -0
- package/src/config/index.ts +62 -0
- package/src/config/validation-helpers.ts +554 -0
- package/src/config/validation.ts +1191 -0
- package/src/{api/preview.ts → create-worker-preview.ts} +63 -25
- package/src/create-worker-upload-form.ts +217 -0
- package/src/dev/dev.tsx +390 -0
- package/src/dev/local.tsx +232 -0
- package/src/dev/remote.tsx +203 -0
- package/src/dev/use-esbuild.ts +100 -0
- package/src/dialogs.tsx +4 -4
- package/src/entry.ts +237 -0
- package/src/environment-variables.ts +33 -0
- package/src/https-options.ts +122 -0
- package/src/index.tsx +1417 -915
- package/src/inspect.ts +617 -0
- package/src/intl-polyfill.d.ts +139 -0
- package/src/kv.ts +319 -0
- 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 +229 -35
- package/src/open-in-browser.ts +25 -0
- package/src/package-manager.ts +126 -0
- package/src/pages.tsx +470 -227
- package/src/parse.ts +183 -0
- package/src/paths.ts +26 -0
- package/src/proxy.ts +440 -0
- package/src/publish.ts +292 -290
- package/src/r2.ts +50 -0
- package/src/reporting.ts +131 -0
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.tsx +224 -59
- package/src/tail/filters.ts +279 -0
- package/src/tail/index.ts +299 -0
- package/src/tail/printing.ts +62 -0
- package/src/user.tsx +301 -203
- package/src/whoami.tsx +69 -0
- package/src/worker.ts +163 -0
- package/templates/new-worker.js +15 -0
- package/templates/new-worker.ts +15 -0
- package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.js +134241 -116339
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/mock-cfetch.js +0 -42
- package/src/api/form_data.ts +0 -141
- package/src/api/inspect.ts +0 -430
- package/src/api/worker.ts +0 -161
- package/src/cfetch.ts +0 -72
- package/src/config.ts +0 -122
- package/src/dev.tsx +0 -776
- package/src/kv.tsx +0 -211
- package/src/tail.tsx +0 -71
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { getHttpsOptions } from "../https-options";
|
|
5
|
+
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
6
|
+
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
7
|
+
|
|
8
|
+
describe("getHttpsOptions()", () => {
|
|
9
|
+
runInTempDir({ homedir: "./home" });
|
|
10
|
+
const std = mockConsoleMethods();
|
|
11
|
+
|
|
12
|
+
it("should use cached values if they have not expired", async () => {
|
|
13
|
+
fs.mkdirSync(resolve(os.homedir(), ".wrangler/local-cert"), {
|
|
14
|
+
recursive: true,
|
|
15
|
+
});
|
|
16
|
+
fs.writeFileSync(
|
|
17
|
+
resolve(os.homedir(), ".wrangler/local-cert/key.pem"),
|
|
18
|
+
"PRIVATE KEY"
|
|
19
|
+
);
|
|
20
|
+
fs.writeFileSync(
|
|
21
|
+
resolve(os.homedir(), ".wrangler/local-cert/cert.pem"),
|
|
22
|
+
"PUBLIC KEY"
|
|
23
|
+
);
|
|
24
|
+
const result = await getHttpsOptions();
|
|
25
|
+
expect(result.key).toEqual("PRIVATE KEY");
|
|
26
|
+
expect(result.cert).toEqual("PUBLIC KEY");
|
|
27
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
28
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
29
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("should generate and cache new keys if none are cached", async () => {
|
|
33
|
+
const result = await getHttpsOptions();
|
|
34
|
+
const key = fs.readFileSync(
|
|
35
|
+
resolve(os.homedir(), ".wrangler/local-cert/key.pem"),
|
|
36
|
+
"utf8"
|
|
37
|
+
);
|
|
38
|
+
const cert = fs.readFileSync(
|
|
39
|
+
resolve(os.homedir(), ".wrangler/local-cert/cert.pem"),
|
|
40
|
+
"utf8"
|
|
41
|
+
);
|
|
42
|
+
expect(result.key).toEqual(key);
|
|
43
|
+
expect(result.cert).toEqual(cert);
|
|
44
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
45
|
+
`"Generating new self-signed certificate..."`
|
|
46
|
+
);
|
|
47
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
48
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("should generate and cache new keys if cached files have expired", async () => {
|
|
52
|
+
fs.mkdirSync(resolve(os.homedir(), ".wrangler/local-cert"), {
|
|
53
|
+
recursive: true,
|
|
54
|
+
});
|
|
55
|
+
const ORIGINAL_KEY = "EXPIRED PRIVATE KEY";
|
|
56
|
+
const ORIGINAL_CERT = "EXPIRED PUBLIC KEY";
|
|
57
|
+
fs.writeFileSync(
|
|
58
|
+
resolve(os.homedir(), ".wrangler/local-cert/key.pem"),
|
|
59
|
+
ORIGINAL_KEY
|
|
60
|
+
);
|
|
61
|
+
fs.writeFileSync(
|
|
62
|
+
resolve(os.homedir(), ".wrangler/local-cert/cert.pem"),
|
|
63
|
+
ORIGINAL_CERT
|
|
64
|
+
);
|
|
65
|
+
mockStatSync(/\.pem$/, { mtimeMs: new Date(2000).valueOf() });
|
|
66
|
+
|
|
67
|
+
const result = await getHttpsOptions();
|
|
68
|
+
const key = fs.readFileSync(
|
|
69
|
+
resolve(os.homedir(), ".wrangler/local-cert/key.pem"),
|
|
70
|
+
"utf8"
|
|
71
|
+
);
|
|
72
|
+
const cert = fs.readFileSync(
|
|
73
|
+
resolve(os.homedir(), ".wrangler/local-cert/cert.pem"),
|
|
74
|
+
"utf8"
|
|
75
|
+
);
|
|
76
|
+
expect(key).not.toEqual(ORIGINAL_KEY);
|
|
77
|
+
expect(cert).not.toEqual(ORIGINAL_CERT);
|
|
78
|
+
expect(result.key).toEqual(key);
|
|
79
|
+
expect(result.cert).toEqual(cert);
|
|
80
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
81
|
+
`"Generating new self-signed certificate..."`
|
|
82
|
+
);
|
|
83
|
+
expect(std.warn).toMatchInlineSnapshot(`""`);
|
|
84
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("should warn if not able to write to the cache", async () => {
|
|
88
|
+
mockWriteFileSyncThrow(/\.pem$/);
|
|
89
|
+
await getHttpsOptions();
|
|
90
|
+
expect(
|
|
91
|
+
fs.existsSync(resolve(os.homedir(), ".wrangler/local-cert/key.pem"))
|
|
92
|
+
).toBe(false);
|
|
93
|
+
expect(
|
|
94
|
+
fs.existsSync(resolve(os.homedir(), ".wrangler/local-cert/cert.pem"))
|
|
95
|
+
).toBe(false);
|
|
96
|
+
expect(std.out).toMatchInlineSnapshot(
|
|
97
|
+
`"Generating new self-signed certificate..."`
|
|
98
|
+
);
|
|
99
|
+
expect(std.warn).toMatchInlineSnapshot(`
|
|
100
|
+
"Unable to cache generated self-signed certificate in home/.wrangler/local-cert.
|
|
101
|
+
ERROR: Cannot write file"
|
|
102
|
+
`);
|
|
103
|
+
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
function mockStatSync(matcher: RegExp, stats: Partial<fs.Stats>) {
|
|
108
|
+
const originalStatSync = jest.requireActual("node:fs").statSync;
|
|
109
|
+
jest.spyOn(fs, "statSync").mockImplementation((statPath, options) => {
|
|
110
|
+
return matcher.test(statPath.toString())
|
|
111
|
+
? (stats as fs.Stats)
|
|
112
|
+
: originalStatSync(statPath, options);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function mockWriteFileSyncThrow(matcher: RegExp) {
|
|
117
|
+
const originalWriteFileSync = jest.requireActual("node:fs").writeFileSync;
|
|
118
|
+
jest
|
|
119
|
+
.spyOn(fs, "writeFileSync")
|
|
120
|
+
.mockImplementation((filePath, data, options) => {
|
|
121
|
+
if (matcher.test(filePath.toString())) {
|
|
122
|
+
throw new Error("ERROR: Cannot write file");
|
|
123
|
+
} else {
|
|
124
|
+
return originalWriteFileSync(filePath, data, options);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|