wrangler 0.0.0-bce731a → 0.0.0-bfedc58
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/package.json +3 -1
- package/pages/functions/filepath-routing.test.ts +103 -46
- package/pages/functions/filepath-routing.ts +3 -1
- package/src/__tests__/dev.test.tsx +33 -2
- package/src/__tests__/guess-worker-format.test.ts +19 -4
- package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
- package/src/__tests__/helpers/mock-bin.ts +4 -1
- package/src/__tests__/helpers/run-wrangler.ts +5 -3
- package/src/__tests__/helpers/write-wrangler-toml.ts +20 -0
- package/src/__tests__/index.test.ts +2 -2
- package/src/__tests__/kv.test.ts +4 -2
- package/src/__tests__/package-manager.test.ts +2 -2
- package/src/__tests__/publish.test.ts +213 -21
- package/src/__tests__/secret.test.ts +3 -3
- package/src/__tests__/sentry.test.ts +7 -15
- package/src/api/form_data.ts +9 -0
- package/src/api/worker.ts +15 -6
- package/src/bundle.ts +14 -6
- package/src/cfetch/internal.ts +8 -3
- package/src/config.ts +98 -76
- package/src/dev.tsx +37 -23
- package/src/guess-worker-format.ts +5 -3
- package/src/index.tsx +149 -63
- package/src/inspect.ts +16 -3
- package/src/kv.tsx +14 -16
- package/src/pages.tsx +6 -5
- package/src/publish.ts +72 -65
- package/src/reporting.ts +7 -6
- package/src/sites.tsx +1 -1
- package/src/tail.tsx +179 -9
- package/src/user.tsx +39 -25
- package/wrangler-dist/cli.js +321 -144
- package/wrangler-dist/cli.js.map +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-bfedc58",
|
|
4
4
|
"author": "wrangler@cloudflare.com",
|
|
5
5
|
"description": "Command-line interface for all things Cloudflare Workers",
|
|
6
6
|
"bin": {
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"@sentry/cli": "^1.71.0",
|
|
52
52
|
"@sentry/integrations": "^6.17.6",
|
|
53
53
|
"@sentry/node": "^6.17.6",
|
|
54
|
+
"@types/command-exists": "^1.2.0",
|
|
54
55
|
"@types/estree": "^0.0.50",
|
|
55
56
|
"@types/mime": "^2.0.3",
|
|
56
57
|
"@types/prompts": "^2.0.14",
|
|
@@ -104,6 +105,7 @@
|
|
|
104
105
|
"check:type": "tsc",
|
|
105
106
|
"bundle": "node -r esbuild-register scripts/bundle.ts",
|
|
106
107
|
"build": "npm run clean && npm run bundle",
|
|
108
|
+
"prepublishOnly": "npm run build",
|
|
107
109
|
"start": "npm run bundle && NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
|
|
108
110
|
"test": "jest --silent=false --verbose=true",
|
|
109
111
|
"test-watch": "npm run test -- --runInBand --testTimeout=50000 --watch"
|
|
@@ -1,60 +1,117 @@
|
|
|
1
|
+
import { writeFileSync } from "fs";
|
|
2
|
+
import { runInTempDir } from "../../src/__tests__/helpers/run-in-tmp";
|
|
1
3
|
import { toUrlPath } from "../../src/paths";
|
|
2
|
-
import { compareRoutes } from "./filepath-routing";
|
|
4
|
+
import { compareRoutes, generateConfigFromFileTree } from "./filepath-routing";
|
|
5
|
+
import type { UrlPath } from "../../src/paths";
|
|
3
6
|
import type { HTTPMethod, RouteConfig } from "./routes";
|
|
4
7
|
|
|
5
|
-
describe("
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
describe("filepath-routing", () => {
|
|
9
|
+
describe("compareRoutes()", () => {
|
|
10
|
+
test("routes / last", () => {
|
|
11
|
+
expect(
|
|
12
|
+
compareRoutes(routeConfig("/"), routeConfig("/foo"))
|
|
13
|
+
).toBeGreaterThanOrEqual(1);
|
|
14
|
+
expect(
|
|
15
|
+
compareRoutes(routeConfig("/"), routeConfig("/:foo"))
|
|
16
|
+
).toBeGreaterThanOrEqual(1);
|
|
17
|
+
expect(
|
|
18
|
+
compareRoutes(routeConfig("/"), routeConfig("/:foo*"))
|
|
19
|
+
).toBeGreaterThanOrEqual(1);
|
|
20
|
+
});
|
|
17
21
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
test("routes with fewer segments come after those with more segments", () => {
|
|
23
|
+
expect(
|
|
24
|
+
compareRoutes(routeConfig("/foo"), routeConfig("/foo/bar"))
|
|
25
|
+
).toBeGreaterThanOrEqual(1);
|
|
26
|
+
expect(
|
|
27
|
+
compareRoutes(routeConfig("/foo"), routeConfig("/foo/bar/cat"))
|
|
28
|
+
).toBeGreaterThanOrEqual(1);
|
|
29
|
+
});
|
|
26
30
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
test("routes with wildcard segments come after those without", () => {
|
|
32
|
+
expect(compareRoutes(routeConfig("/:foo*"), routeConfig("/foo"))).toBe(1);
|
|
33
|
+
expect(compareRoutes(routeConfig("/:foo*"), routeConfig("/:foo"))).toBe(
|
|
34
|
+
1
|
|
35
|
+
);
|
|
36
|
+
});
|
|
31
37
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
test("routes with dynamic segments come after those without", () => {
|
|
39
|
+
expect(compareRoutes(routeConfig("/:foo"), routeConfig("/foo"))).toBe(1);
|
|
40
|
+
});
|
|
35
41
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
42
|
+
test("routes with dynamic segments occurring earlier come after those with dynamic segments in later positions", () => {
|
|
43
|
+
expect(
|
|
44
|
+
compareRoutes(routeConfig("/foo/:id/bar"), routeConfig("/foo/bar/:id"))
|
|
45
|
+
).toBe(1);
|
|
46
|
+
});
|
|
41
47
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
48
|
+
test("routes with no HTTP method come after those specifying a method", () => {
|
|
49
|
+
expect(
|
|
50
|
+
compareRoutes(routeConfig("/foo"), routeConfig("/foo", "GET"))
|
|
51
|
+
).toBe(1);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("two equal routes are sorted according to their original position in the list", () => {
|
|
55
|
+
expect(
|
|
56
|
+
compareRoutes(routeConfig("/foo", "GET"), routeConfig("/foo", "GET"))
|
|
57
|
+
).toBe(0);
|
|
58
|
+
});
|
|
47
59
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
60
|
+
test("it returns -1 if the first argument should appear first in the list", () => {
|
|
61
|
+
expect(
|
|
62
|
+
compareRoutes(routeConfig("/foo", "GET"), routeConfig("/foo"))
|
|
63
|
+
).toBe(-1);
|
|
64
|
+
});
|
|
52
65
|
});
|
|
53
66
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
)
|
|
67
|
+
describe("generateConfigFromFileTree", () => {
|
|
68
|
+
runInTempDir();
|
|
69
|
+
|
|
70
|
+
it("should generate a route entry for each file in the tree", async () => {
|
|
71
|
+
writeFileSync(
|
|
72
|
+
"foo.ts",
|
|
73
|
+
`
|
|
74
|
+
export function onRequestGet() {}
|
|
75
|
+
export function onRequestPost() {}
|
|
76
|
+
`
|
|
77
|
+
);
|
|
78
|
+
writeFileSync(
|
|
79
|
+
"bar.ts",
|
|
80
|
+
`
|
|
81
|
+
export function onRequestPut() {}
|
|
82
|
+
export function onRequestDelete() {}
|
|
83
|
+
`
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
const entries = await generateConfigFromFileTree({
|
|
87
|
+
baseDir: ".",
|
|
88
|
+
baseURL: "/base" as UrlPath,
|
|
89
|
+
});
|
|
90
|
+
expect(entries).toEqual({
|
|
91
|
+
routes: [
|
|
92
|
+
{
|
|
93
|
+
method: "PUT",
|
|
94
|
+
module: ["bar.ts:onRequestPut"],
|
|
95
|
+
routePath: "/base/bar",
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
method: "DELETE",
|
|
99
|
+
module: ["bar.ts:onRequestDelete"],
|
|
100
|
+
routePath: "/base/bar",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
method: "GET",
|
|
104
|
+
module: ["foo.ts:onRequestGet"],
|
|
105
|
+
routePath: "/base/foo",
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
method: "POST",
|
|
109
|
+
module: ["foo.ts:onRequestPost"],
|
|
110
|
+
routePath: "/base/foo",
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
});
|
|
114
|
+
});
|
|
58
115
|
});
|
|
59
116
|
});
|
|
60
117
|
|
|
@@ -127,7 +127,9 @@ export async function generateConfigFromFileTree({
|
|
|
127
127
|
routeEntries = routeEntries.reduce(
|
|
128
128
|
(acc: typeof routeEntries, { routePath, ...rest }) => {
|
|
129
129
|
const existingRouteEntry = acc.find(
|
|
130
|
-
(routeEntry) =>
|
|
130
|
+
(routeEntry) =>
|
|
131
|
+
routeEntry.routePath === routePath &&
|
|
132
|
+
routeEntry.method === rest.method
|
|
131
133
|
);
|
|
132
134
|
if (existingRouteEntry !== undefined) {
|
|
133
135
|
Object.assign(existingRouteEntry, rest);
|
|
@@ -2,12 +2,16 @@ import { render } from "ink-testing-library";
|
|
|
2
2
|
import patchConsole from "patch-console";
|
|
3
3
|
import React from "react";
|
|
4
4
|
import Dev from "../dev";
|
|
5
|
+
import { mockConsoleMethods } from "./helpers/mock-console";
|
|
6
|
+
import { runWrangler } from "./helpers/run-wrangler";
|
|
7
|
+
import writeWranglerToml from "./helpers/write-wrangler-toml";
|
|
5
8
|
import type { DevProps } from "../dev";
|
|
6
9
|
|
|
7
10
|
describe("Dev component", () => {
|
|
8
11
|
let restoreConsole: ReturnType<typeof patchConsole>;
|
|
9
12
|
beforeEach(() => (restoreConsole = patchConsole(() => {})));
|
|
10
13
|
afterEach(() => restoreConsole());
|
|
14
|
+
const std = mockConsoleMethods();
|
|
11
15
|
|
|
12
16
|
// This test needs to be rewritten because the error now throws asynchronously
|
|
13
17
|
// and the Ink framework does not yet have async testing support.
|
|
@@ -23,6 +27,26 @@ describe("Dev component", () => {
|
|
|
23
27
|
Error: You cannot use the service worker format with a \`public\` directory."
|
|
24
28
|
`);
|
|
25
29
|
});
|
|
30
|
+
|
|
31
|
+
describe("entry-points", () => {
|
|
32
|
+
it("should error if there is no entry-point specified", async () => {
|
|
33
|
+
writeWranglerToml();
|
|
34
|
+
|
|
35
|
+
await expect(
|
|
36
|
+
runWrangler("dev")
|
|
37
|
+
).rejects.toThrowErrorMatchingInlineSnapshot(
|
|
38
|
+
`"Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler dev path/to/script\`) or the \`build.upload.main\` config field."`
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
expect(std.out).toMatchInlineSnapshot(`""`);
|
|
42
|
+
expect(std.err).toMatchInlineSnapshot(`
|
|
43
|
+
"Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler dev path/to/script\`) or the \`build.upload.main\` config field.
|
|
44
|
+
|
|
45
|
+
[32m%s[0m
|
|
46
|
+
If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new."
|
|
47
|
+
`);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
26
50
|
});
|
|
27
51
|
|
|
28
52
|
/**
|
|
@@ -32,14 +56,21 @@ describe("Dev component", () => {
|
|
|
32
56
|
*/
|
|
33
57
|
function renderDev({
|
|
34
58
|
name,
|
|
35
|
-
entry = "some/entry.ts",
|
|
59
|
+
entry = { file: "some/entry.ts", directory: process.cwd() },
|
|
36
60
|
port,
|
|
37
61
|
format,
|
|
38
62
|
accountId,
|
|
39
63
|
initialMode = "local",
|
|
40
64
|
jsxFactory,
|
|
41
65
|
jsxFragment,
|
|
42
|
-
bindings = {
|
|
66
|
+
bindings = {
|
|
67
|
+
kv_namespaces: [],
|
|
68
|
+
vars: {},
|
|
69
|
+
durable_objects: { bindings: [] },
|
|
70
|
+
r2_buckets: [],
|
|
71
|
+
wasm_modules: {},
|
|
72
|
+
unsafe: [],
|
|
73
|
+
},
|
|
43
74
|
public: publicDir,
|
|
44
75
|
assetPaths,
|
|
45
76
|
compatibilityDate,
|
|
@@ -10,7 +10,10 @@ describe("guess worker format", () => {
|
|
|
10
10
|
// Note that this isn't actually a valid worker, because it's missing
|
|
11
11
|
// a fetch handler. Regardless, our heuristic is simply to check for exports.
|
|
12
12
|
const guess = await guessWorkerFormat(
|
|
13
|
-
|
|
13
|
+
{
|
|
14
|
+
file: path.join(process.cwd(), "./index.ts"),
|
|
15
|
+
directory: process.cwd(),
|
|
16
|
+
},
|
|
14
17
|
undefined
|
|
15
18
|
);
|
|
16
19
|
expect(guess).toBe("modules");
|
|
@@ -22,7 +25,10 @@ describe("guess worker format", () => {
|
|
|
22
25
|
// a fetch listener. Regardless, our heuristic is simply to check for
|
|
23
26
|
// the lack of exports.
|
|
24
27
|
const guess = await guessWorkerFormat(
|
|
25
|
-
|
|
28
|
+
{
|
|
29
|
+
file: path.join(process.cwd(), "./index.ts"),
|
|
30
|
+
directory: process.cwd(),
|
|
31
|
+
},
|
|
26
32
|
undefined
|
|
27
33
|
);
|
|
28
34
|
expect(guess).toBe("service-worker");
|
|
@@ -32,7 +38,10 @@ describe("guess worker format", () => {
|
|
|
32
38
|
await writeFile("./index.ts", "export default {};");
|
|
33
39
|
await expect(
|
|
34
40
|
guessWorkerFormat(
|
|
35
|
-
|
|
41
|
+
{
|
|
42
|
+
file: path.join(process.cwd(), "./index.ts"),
|
|
43
|
+
directory: process.cwd(),
|
|
44
|
+
},
|
|
36
45
|
"service-worker"
|
|
37
46
|
)
|
|
38
47
|
).rejects.toThrow(
|
|
@@ -43,7 +52,13 @@ describe("guess worker format", () => {
|
|
|
43
52
|
it("should throw an error when the hint doesn't match the guess (service-worker - modules)", async () => {
|
|
44
53
|
await writeFile("./index.ts", "");
|
|
45
54
|
await expect(
|
|
46
|
-
guessWorkerFormat(
|
|
55
|
+
guessWorkerFormat(
|
|
56
|
+
{
|
|
57
|
+
file: path.join(process.cwd(), "./index.ts"),
|
|
58
|
+
directory: process.cwd(),
|
|
59
|
+
},
|
|
60
|
+
"modules"
|
|
61
|
+
)
|
|
47
62
|
).rejects.toThrow(
|
|
48
63
|
"You configured this worker to be 'modules', but the file you are trying to build doesn't export a handler. Please pass `--format service-worker`, or simply remove the configuration."
|
|
49
64
|
);
|
|
@@ -7,7 +7,10 @@ const nodeShebang = "#!/usr/bin/env node";
|
|
|
7
7
|
/**
|
|
8
8
|
* Create a binary file in a temp directory and make it available on the PATH.
|
|
9
9
|
*/
|
|
10
|
-
export async function mockBinary(
|
|
10
|
+
export async function mockBinary(
|
|
11
|
+
binaryName: string,
|
|
12
|
+
code: string
|
|
13
|
+
): Promise<() => void> {
|
|
11
14
|
// Ensure there is a directory to put the mock binary in.
|
|
12
15
|
const tmpDir = resolve(mkdtempSync(".mock-binary-"));
|
|
13
16
|
|
|
@@ -7,8 +7,10 @@ import { normalizeSlashes, stripTimings } from "./mock-console";
|
|
|
7
7
|
export async function runWrangler(cmd?: string) {
|
|
8
8
|
try {
|
|
9
9
|
await main(cmd?.split(" ") ?? []);
|
|
10
|
-
} catch (
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
} catch (err) {
|
|
11
|
+
if (err instanceof Error) {
|
|
12
|
+
err.message = normalizeSlashes(stripTimings(err.message));
|
|
13
|
+
}
|
|
14
|
+
throw err;
|
|
13
15
|
}
|
|
14
16
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import * as fs from "fs";
|
|
2
|
+
import TOML from "@iarna/toml";
|
|
3
|
+
import type { Config } from "../../config";
|
|
4
|
+
|
|
5
|
+
/** Write a mock wrangler.toml file to disk. */
|
|
6
|
+
export default function writeWranglerToml(config: Omit<Config, "env"> = {}) {
|
|
7
|
+
// We Omit `env` from config because TOML.stringify() appears to
|
|
8
|
+
// have a weird type signature that appears to fail. We'll revisit this
|
|
9
|
+
// when we write tests for publishing environments
|
|
10
|
+
fs.writeFileSync(
|
|
11
|
+
"./wrangler.toml",
|
|
12
|
+
TOML.stringify({
|
|
13
|
+
compatibility_date: "2022-01-12",
|
|
14
|
+
name: "test-name",
|
|
15
|
+
...(config as TOML.JsonMap),
|
|
16
|
+
}),
|
|
17
|
+
|
|
18
|
+
"utf-8"
|
|
19
|
+
);
|
|
20
|
+
}
|
|
@@ -33,7 +33,7 @@ describe("wrangler", () => {
|
|
|
33
33
|
Commands:
|
|
34
34
|
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
35
35
|
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
36
|
-
wrangler dev
|
|
36
|
+
wrangler dev [script] 👂 Start a local server for developing your worker
|
|
37
37
|
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
38
38
|
wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker.
|
|
39
39
|
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
|
|
@@ -71,7 +71,7 @@ describe("wrangler", () => {
|
|
|
71
71
|
Commands:
|
|
72
72
|
wrangler init [name] 📥 Create a wrangler.toml configuration file
|
|
73
73
|
wrangler whoami 🕵️ Retrieve your user info and test your auth config
|
|
74
|
-
wrangler dev
|
|
74
|
+
wrangler dev [script] 👂 Start a local server for developing your worker
|
|
75
75
|
wrangler publish [script] 🆙 Publish your Worker to Cloudflare.
|
|
76
76
|
wrangler tail [name] 🦚 Starts a log tailing session for a deployed Worker.
|
|
77
77
|
wrangler secret 🤫 Generate a secret that can be referenced in the worker script
|
package/src/__tests__/kv.test.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { mockConsoleMethods } from "./helpers/mock-console";
|
|
|
10
10
|
import { mockKeyListRequest } from "./helpers/mock-kv";
|
|
11
11
|
import { runInTempDir } from "./helpers/run-in-tmp";
|
|
12
12
|
import { runWrangler } from "./helpers/run-wrangler";
|
|
13
|
-
import type { KVNamespaceInfo } from "../kv";
|
|
13
|
+
import type { KVNamespaceInfo, NamespaceKeyInfo } from "../kv";
|
|
14
14
|
|
|
15
15
|
describe("wrangler", () => {
|
|
16
16
|
mockAccountId();
|
|
@@ -839,7 +839,9 @@ describe("wrangler", () => {
|
|
|
839
839
|
"kv:key list --namespace-id some-namespace-id --limit 100"
|
|
840
840
|
);
|
|
841
841
|
expect(std.err).toMatchInlineSnapshot(`""`);
|
|
842
|
-
expect(
|
|
842
|
+
expect(
|
|
843
|
+
JSON.parse(std.out).map((k: NamespaceKeyInfo) => k.name)
|
|
844
|
+
).toEqual(keys);
|
|
843
845
|
expect(requests.count).toEqual(6);
|
|
844
846
|
});
|
|
845
847
|
});
|
|
@@ -151,7 +151,7 @@ describe("getPackageManager()", () => {
|
|
|
151
151
|
* Create a fake yarn binary
|
|
152
152
|
*/
|
|
153
153
|
function mockYarn(succeed: boolean): void {
|
|
154
|
-
let unMock;
|
|
154
|
+
let unMock: () => void;
|
|
155
155
|
beforeEach(async () => {
|
|
156
156
|
unMock = await mockBinary("yarn", `process.exit(${succeed ? 0 : 1})`);
|
|
157
157
|
});
|
|
@@ -162,7 +162,7 @@ function mockYarn(succeed: boolean): void {
|
|
|
162
162
|
* Create a fake npm binary
|
|
163
163
|
*/
|
|
164
164
|
function mockNpm(succeed: boolean): void {
|
|
165
|
-
let unMock;
|
|
165
|
+
let unMock: () => void;
|
|
166
166
|
beforeEach(async () => {
|
|
167
167
|
unMock = await mockBinary("npm", `process.exit(${succeed ? 0 : 1})`);
|
|
168
168
|
});
|