wrangler 0.0.0-ece06ea → 0.0.0-ed4f2ef
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 +12 -3
- package/miniflare-dist/index.mjs +79 -0
- package/miniflare-dist/index.mjs.map +7 -0
- package/package.json +49 -22
- 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 +2874 -0
- package/src/__tests__/dev.test.tsx +588 -0
- package/src/__tests__/guess-worker-format.test.ts +83 -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-oauth-flow.ts +178 -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 +953 -119
- package/src/__tests__/jest.setup.ts +74 -0
- package/src/__tests__/kv.test.ts +1380 -0
- package/src/__tests__/package-manager.test.ts +206 -0
- package/src/__tests__/pages.test.ts +180 -0
- package/src/__tests__/parse.test.ts +322 -0
- package/src/__tests__/publish.test.ts +3946 -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 +638 -0
- package/src/__tests__/user.test.ts +83 -0
- package/src/__tests__/whoami.test.tsx +95 -0
- package/src/bundle.ts +155 -0
- package/src/cfetch/index.ts +104 -0
- package/src/cfetch/internal.ts +139 -0
- package/src/cli.ts +18 -7
- package/src/config/README.md +107 -0
- package/src/config/config.ts +229 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +371 -0
- package/src/config/index.ts +62 -0
- package/src/config/validation-helpers.ts +557 -0
- package/src/config/validation.ts +1240 -0
- package/src/create-worker-preview.ts +173 -0
- package/src/create-worker-upload-form.ts +240 -0
- package/src/dev/dev.tsx +413 -0
- package/src/dev/local.tsx +287 -0
- package/src/dev/remote.tsx +209 -0
- package/src/dev/use-esbuild.ts +109 -0
- package/src/dialogs.tsx +6 -14
- package/src/entry.ts +256 -0
- package/src/environment-variables.ts +33 -0
- package/src/errors.ts +11 -0
- package/src/https-options.ts +122 -0
- package/src/index.tsx +1503 -959
- package/src/inspect.ts +624 -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 +38 -0
- package/src/module-collection.ts +257 -0
- package/src/open-in-browser.ts +25 -0
- package/src/package-manager.ts +126 -0
- package/src/pages.tsx +1074 -212
- package/src/parse.ts +183 -0
- package/src/paths.ts +26 -0
- package/src/proxy.ts +455 -0
- package/src/publish.ts +326 -295
- 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 +340 -203
- package/src/whoami.tsx +69 -0
- package/src/worker.ts +172 -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} +1 -1
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.js +136988 -131174
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/fixtures/init/.gitkeep +0 -0
- package/src/__tests__/mock-cfetch.js +0 -46
- package/src/api/form_data.ts +0 -158
- package/src/api/inspect.ts +0 -441
- package/src/api/preview.ts +0 -123
- package/src/api/worker.ts +0 -161
- package/src/cfetch.ts +0 -72
- package/src/config.ts +0 -124
- package/src/dev.tsx +0 -736
- package/src/kv.tsx +0 -211
- package/src/tail.tsx +0 -71
- package/src/util/fetch.ts +0 -74
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
const ORIGINAL_STDIN = process.stdin;
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Mock process.stdin so that we can pipe in text for non-interactive mode tests.
|
|
5
|
+
*/
|
|
6
|
+
export function useMockStdin({ isTTY }: { isTTY: boolean }) {
|
|
7
|
+
const mockStdin = new MockStdIn(isTTY);
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
mockStdin.reset();
|
|
11
|
+
Object.defineProperty(process, "stdin", {
|
|
12
|
+
value: mockStdin,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: false,
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
Object.defineProperty(process, "stdin", {
|
|
20
|
+
value: ORIGINAL_STDIN,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: false,
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
return mockStdin;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const failCallback: (value: unknown) => void = () => {
|
|
30
|
+
throw new Error(
|
|
31
|
+
"TEST FAILURE: stdin callback called before being initialized."
|
|
32
|
+
);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A mock version of `process.std`, which can be used to simulate piping data
|
|
37
|
+
* into the wrangler process in non-interactive mode.
|
|
38
|
+
*/
|
|
39
|
+
class MockStdIn {
|
|
40
|
+
private endCallback = failCallback;
|
|
41
|
+
private errorCallback = failCallback;
|
|
42
|
+
private chunks: string[] = [];
|
|
43
|
+
private error: Error | undefined;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Set this to true if you want the stdin stream to error.
|
|
47
|
+
*/
|
|
48
|
+
throwError(error: Error) {
|
|
49
|
+
this.error = error;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Call this to clean out the chunks that are queued for sending.
|
|
54
|
+
*/
|
|
55
|
+
reset() {
|
|
56
|
+
this.chunks.length = 0;
|
|
57
|
+
this.error = undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Queue up some chunks to be sent.
|
|
62
|
+
*/
|
|
63
|
+
send(...chunks: string[]) {
|
|
64
|
+
this.chunks.push(...chunks);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
constructor(
|
|
68
|
+
/**
|
|
69
|
+
* Used by wrangler to check whether stdin is interactive.
|
|
70
|
+
*/
|
|
71
|
+
readonly isTTY: boolean
|
|
72
|
+
) {}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Used by wrangler to add event listeners.
|
|
76
|
+
*/
|
|
77
|
+
on(eventName: string, callback: () => void) {
|
|
78
|
+
switch (eventName) {
|
|
79
|
+
case "readable":
|
|
80
|
+
setImmediate(callback);
|
|
81
|
+
break;
|
|
82
|
+
case "end":
|
|
83
|
+
this.endCallback = callback;
|
|
84
|
+
break;
|
|
85
|
+
case "error":
|
|
86
|
+
this.errorCallback = callback;
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Used by wrangler to get the next chunk of data in the stream.
|
|
93
|
+
*/
|
|
94
|
+
read() {
|
|
95
|
+
if (this.error) {
|
|
96
|
+
setImmediate(() => this.errorCallback(this.error));
|
|
97
|
+
}
|
|
98
|
+
if (this.chunks.length === 0) {
|
|
99
|
+
setImmediate(this.endCallback);
|
|
100
|
+
}
|
|
101
|
+
return this.chunks.shift() ?? null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { WebSocket } from "mock-socket";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A version of the mock WebSocket that supports the methods that we use.
|
|
5
|
+
*/
|
|
6
|
+
export class MockWebSocket extends WebSocket {
|
|
7
|
+
on(event: string | symbol, listener: (...args: unknown[]) => void): this {
|
|
8
|
+
switch (event) {
|
|
9
|
+
case "message":
|
|
10
|
+
this.onmessage = ({ data }) => {
|
|
11
|
+
listener(data);
|
|
12
|
+
};
|
|
13
|
+
break;
|
|
14
|
+
case "open":
|
|
15
|
+
this.onopen = listener;
|
|
16
|
+
break;
|
|
17
|
+
case "close":
|
|
18
|
+
this.onclose = listener;
|
|
19
|
+
break;
|
|
20
|
+
default:
|
|
21
|
+
throw new Error("Unknown event type: " + event.toString());
|
|
22
|
+
}
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
terminate() {
|
|
27
|
+
this.close();
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
import * as path from "node:path";
|
|
4
|
+
import { reinitialiseAuthTokens } from "../../user";
|
|
5
|
+
|
|
6
|
+
const originalCwd = process.cwd();
|
|
7
|
+
|
|
8
|
+
export function runInTempDir({ homedir }: { homedir?: string } = {}) {
|
|
9
|
+
let tmpDir: string;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "wrangler-tests"));
|
|
13
|
+
process.chdir(tmpDir);
|
|
14
|
+
if (homedir !== undefined) {
|
|
15
|
+
// Override where the home directory is so that we can write our own user config,
|
|
16
|
+
// without destroying the real thing.
|
|
17
|
+
fs.mkdirSync(homedir);
|
|
18
|
+
// Note it is very important that we use the "default" value from "node:os" (e.g. `import os from "node:os";`)
|
|
19
|
+
// rather than an alias to the module (e.g. `import * as os from "node:os";`).
|
|
20
|
+
// This is because the module gets transpiled so that the "method" `homedir()` gets converted to a
|
|
21
|
+
// getter that is not configurable (and so cannot be spied upon).
|
|
22
|
+
jest.spyOn(os, "homedir").mockReturnValue(homedir);
|
|
23
|
+
// Now that we have changed the home directory location, we must reinitialize the user auth state
|
|
24
|
+
reinitialiseAuthTokens();
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
process.chdir(originalCwd);
|
|
30
|
+
fs.rmSync(tmpDir, { recursive: true });
|
|
31
|
+
});
|
|
32
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { main } from "../../index";
|
|
2
|
+
import { normalizeSlashes, stripTimings } from "./mock-console";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A helper to 'run' wrangler commands for tests.
|
|
6
|
+
*/
|
|
7
|
+
export async function runWrangler(cmd?: string) {
|
|
8
|
+
try {
|
|
9
|
+
await main(cmd?.split(" ") ?? []);
|
|
10
|
+
} catch (err) {
|
|
11
|
+
if (err instanceof Error) {
|
|
12
|
+
err.message = normalizeSlashes(stripTimings(err.message));
|
|
13
|
+
}
|
|
14
|
+
throw err;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import TOML from "@iarna/toml";
|
|
3
|
+
import type { RawConfig } from "../../config";
|
|
4
|
+
|
|
5
|
+
/** Write a mock wrangler.toml file to disk. */
|
|
6
|
+
export default function writeWranglerToml(config: RawConfig = {}) {
|
|
7
|
+
fs.writeFileSync(
|
|
8
|
+
"./wrangler.toml",
|
|
9
|
+
TOML.stringify({
|
|
10
|
+
compatibility_date: "2022-01-12",
|
|
11
|
+
name: "test-name",
|
|
12
|
+
...(config as TOML.JsonMap),
|
|
13
|
+
}),
|
|
14
|
+
|
|
15
|
+
"utf-8"
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -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
|
+
}
|