wrangler 0.0.0-e2b7352 → 0.0.0-e2f9bb2
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 +24 -13
- package/bin/wrangler.js +3 -0
- package/miniflare-dist/index.mjs +4828 -21
- package/package.json +29 -22
- package/pages/functions/buildPlugin.ts +92 -0
- package/pages/functions/buildWorker.ts +80 -4
- package/pages/functions/filepath-routing.test.ts +11 -0
- package/pages/functions/filepath-routing.ts +8 -0
- package/pages/functions/routes.ts +6 -1
- package/pages/functions/template-plugin.ts +146 -0
- package/pages/functions/template-worker.ts +21 -8
- package/src/__tests__/config-cache.test.ts +36 -0
- package/src/__tests__/configuration.test.ts +386 -81
- package/src/__tests__/dev.test.tsx +242 -21
- package/src/__tests__/guess-worker-format.test.ts +18 -1
- package/src/__tests__/helpers/mock-cfetch.ts +5 -1
- package/src/__tests__/helpers/mock-console.ts +20 -3
- package/src/__tests__/helpers/mock-dialogs.ts +24 -0
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +27 -0
- package/src/__tests__/helpers/mock-oauth-flow.ts +255 -0
- package/src/__tests__/helpers/run-in-tmp.ts +7 -0
- package/src/__tests__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/https-options.test.ts +5 -2
- package/src/__tests__/index.test.ts +25 -759
- package/src/__tests__/init.test.ts +1042 -0
- package/src/__tests__/jest.setup.ts +4 -4
- package/src/__tests__/kv.test.ts +130 -56
- package/src/__tests__/logger.test.ts +115 -0
- package/src/__tests__/pages.test.ts +290 -43
- package/src/__tests__/publish.test.ts +1699 -333
- package/src/__tests__/r2.test.ts +24 -8
- package/src/__tests__/route.test.ts +4 -4
- package/src/__tests__/secret.test.ts +55 -34
- package/src/__tests__/tail.test.ts +97 -45
- package/src/__tests__/user.test.ts +131 -0
- package/src/__tests__/whoami.test.tsx +14 -9
- package/src/bundle.ts +15 -1
- package/src/cfetch/internal.ts +0 -2
- package/src/cli.ts +5 -11
- package/src/config/README.md +1 -1
- package/src/config/config.ts +20 -4
- package/src/config/environment.ts +26 -3
- package/src/config/index.ts +2 -1
- package/src/config/validation-helpers.ts +26 -5
- package/src/config/validation.ts +233 -41
- package/src/config-cache.ts +45 -0
- package/src/create-worker-preview.ts +22 -13
- package/src/create-worker-upload-form.ts +32 -9
- package/src/dev/dev-vars.ts +36 -0
- package/src/dev/dev.tsx +60 -34
- package/src/dev/local.tsx +101 -21
- package/src/dev/remote.tsx +23 -13
- package/src/dev/use-esbuild.ts +19 -5
- package/src/dialogs.tsx +16 -6
- package/src/entry.ts +38 -11
- package/src/environment-variables.ts +3 -1
- package/src/errors.ts +11 -0
- package/src/https-options.ts +3 -2
- package/src/index.tsx +529 -303
- package/src/inspect.ts +17 -11
- package/src/logger.ts +66 -0
- package/src/miniflare-cli/index.ts +4 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- package/src/module-collection.ts +7 -7
- package/src/open-in-browser.ts +5 -4
- package/src/package-manager.ts +9 -8
- package/src/pages.tsx +860 -55
- package/src/parse.ts +1 -1
- package/src/proxy.ts +25 -11
- package/src/publish.ts +260 -141
- package/src/sites.tsx +27 -14
- package/src/tail/index.ts +1 -1
- package/src/tail/printing.ts +13 -8
- package/src/update-check.ts +19 -0
- package/src/user.tsx +104 -38
- package/src/whoami.tsx +2 -1
- package/src/worker.ts +15 -6
- package/templates/gitignore +171 -0
- package/templates/static-asset-facade.js +1 -1
- package/wrangler-dist/cli.js +20948 -50169
- package/miniflare-dist/index.mjs.map +0 -7
- package/src/__tests__/logout.test.ts +0 -52
- package/src/__tests__/sentry.test.ts +0 -146
- package/src/reporting.ts +0 -131
- package/wrangler-dist/cli.js.map +0 -7
package/src/dialogs.tsx
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
1
2
|
import { Box, Text, useInput, render } from "ink";
|
|
2
3
|
import TextInput from "ink-text-input";
|
|
3
4
|
import * as React from "react";
|
|
4
5
|
import { useState } from "react";
|
|
6
|
+
import { logger } from "./logger";
|
|
5
7
|
type ConfirmProps = {
|
|
6
8
|
text: string;
|
|
7
9
|
onConfirm: (answer: boolean) => void;
|
|
8
10
|
};
|
|
9
11
|
function Confirm(props: ConfirmProps) {
|
|
10
|
-
useInput((input: string) => {
|
|
11
|
-
if (input === "y") {
|
|
12
|
+
useInput((input: string, key) => {
|
|
13
|
+
if (input === "y" || key.return === true) {
|
|
12
14
|
props.onConfirm(true);
|
|
13
15
|
} else if (input === "n") {
|
|
14
16
|
props.onConfirm(false);
|
|
15
17
|
} else {
|
|
16
|
-
|
|
18
|
+
logger.warn("Unrecognised input:", input);
|
|
17
19
|
}
|
|
18
20
|
});
|
|
19
21
|
return (
|
|
20
22
|
<Box>
|
|
21
|
-
<Text>
|
|
23
|
+
<Text>
|
|
24
|
+
{props.text} ({chalk.bold("y")}/n)
|
|
25
|
+
</Text>
|
|
22
26
|
</Box>
|
|
23
27
|
);
|
|
24
28
|
}
|
|
@@ -39,12 +43,13 @@ export function confirm(text: string): Promise<boolean> {
|
|
|
39
43
|
|
|
40
44
|
type PromptProps = {
|
|
41
45
|
text: string;
|
|
46
|
+
defaultValue?: string;
|
|
42
47
|
type?: "text" | "password";
|
|
43
48
|
onSubmit: (text: string) => void;
|
|
44
49
|
};
|
|
45
50
|
|
|
46
51
|
function Prompt(props: PromptProps) {
|
|
47
|
-
const [value, setValue] = useState("");
|
|
52
|
+
const [value, setValue] = useState(props.defaultValue || "");
|
|
48
53
|
|
|
49
54
|
return (
|
|
50
55
|
<Box>
|
|
@@ -61,11 +66,16 @@ function Prompt(props: PromptProps) {
|
|
|
61
66
|
);
|
|
62
67
|
}
|
|
63
68
|
|
|
64
|
-
export async function prompt(
|
|
69
|
+
export async function prompt(
|
|
70
|
+
text: string,
|
|
71
|
+
type: "text" | "password" = "text",
|
|
72
|
+
defaultValue?: string
|
|
73
|
+
): Promise<string> {
|
|
65
74
|
return new Promise((resolve) => {
|
|
66
75
|
const { unmount } = render(
|
|
67
76
|
<Prompt
|
|
68
77
|
text={text}
|
|
78
|
+
defaultValue={defaultValue}
|
|
69
79
|
type={type}
|
|
70
80
|
onSubmit={(inputText) => {
|
|
71
81
|
unmount();
|
package/src/entry.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { existsSync } from "node:fs";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import * as esbuild from "esbuild";
|
|
5
5
|
import { execaCommand } from "execa";
|
|
6
|
+
import { logger } from "./logger";
|
|
6
7
|
import type { Config } from "./config";
|
|
7
8
|
import type { CfScriptFormat } from "./worker";
|
|
8
9
|
import type { Metafile } from "esbuild";
|
|
@@ -28,9 +29,17 @@ export async function getEntry(
|
|
|
28
29
|
// If the script name comes from the command line it is relative to the current working directory.
|
|
29
30
|
file = path.resolve(args.script);
|
|
30
31
|
} else if (config.main === undefined) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
if (config.site?.["entry-point"]) {
|
|
33
|
+
directory = path.resolve(path.dirname(config.configPath ?? "."));
|
|
34
|
+
file = path.extname(config.site?.["entry-point"])
|
|
35
|
+
? path.resolve(config.site?.["entry-point"])
|
|
36
|
+
: // site.entry-point could be a directory
|
|
37
|
+
path.resolve(config.site?.["entry-point"], "index.js");
|
|
38
|
+
} else {
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Missing entry-point: The entry-point should be specified via the command line (e.g. \`wrangler ${command} path/to/script\`) or the \`main\` config field.`
|
|
41
|
+
);
|
|
42
|
+
}
|
|
34
43
|
} else {
|
|
35
44
|
directory = path.resolve(path.dirname(config.configPath ?? "."));
|
|
36
45
|
file = path.resolve(directory, config.main);
|
|
@@ -54,8 +63,8 @@ export async function getEntry(
|
|
|
54
63
|
partitionDurableObjectBindings(config);
|
|
55
64
|
|
|
56
65
|
if (command === "dev" && remoteBindings.length > 0) {
|
|
57
|
-
|
|
58
|
-
"WARNING: You have Durable Object bindings
|
|
66
|
+
logger.warn(
|
|
67
|
+
"WARNING: You have Durable Object bindings that are not defined locally in the worker being developed.\n" +
|
|
59
68
|
"Be aware that changes to the data stored in these Durable Objects will be permanent and affect the live instances.\n" +
|
|
60
69
|
"Remote Durable Objects that are affected:\n" +
|
|
61
70
|
remoteBindings.map((b) => `- ${JSON.stringify(b)}`).join("\n")
|
|
@@ -64,7 +73,7 @@ export async function getEntry(
|
|
|
64
73
|
|
|
65
74
|
if (format === "service-worker" && localBindings.length > 0) {
|
|
66
75
|
const errorMessage =
|
|
67
|
-
"You seem to be trying to use Durable Objects in a Worker written
|
|
76
|
+
"You seem to be trying to use Durable Objects in a Worker written as a service-worker.";
|
|
68
77
|
const addScriptName =
|
|
69
78
|
"You can use Durable Objects defined in other Workers by specifying a `script_name` in your wrangler.toml, where `script_name` is the name of the Worker that implements that Durable Object. For example:";
|
|
70
79
|
const addScriptNameExamples = generateAddScriptNameExamples(localBindings);
|
|
@@ -86,12 +95,13 @@ export async function runCustomBuild(
|
|
|
86
95
|
) {
|
|
87
96
|
if (build?.command) {
|
|
88
97
|
// TODO: add a deprecation message here?
|
|
89
|
-
|
|
98
|
+
logger.log("Running custom build:", build.command);
|
|
90
99
|
await execaCommand(build.command, {
|
|
91
100
|
shell: true,
|
|
101
|
+
// we keep these two as "inherit" so that
|
|
102
|
+
// logs are still visible.
|
|
92
103
|
stdout: "inherit",
|
|
93
104
|
stderr: "inherit",
|
|
94
|
-
timeout: 1000 * 30,
|
|
95
105
|
...(build.cwd && { cwd: build.cwd }),
|
|
96
106
|
});
|
|
97
107
|
|
|
@@ -126,6 +136,7 @@ export default async function guessWorkerFormat(
|
|
|
126
136
|
metafile: true,
|
|
127
137
|
bundle: false,
|
|
128
138
|
format: "esm",
|
|
139
|
+
target: "es2020",
|
|
129
140
|
write: false,
|
|
130
141
|
loader: {
|
|
131
142
|
".js": "jsx",
|
|
@@ -150,14 +161,30 @@ export default async function guessWorkerFormat(
|
|
|
150
161
|
"More than one entry-point found for generated bundle." +
|
|
151
162
|
listEntryPoints(entryPoints)
|
|
152
163
|
);
|
|
153
|
-
|
|
154
|
-
|
|
164
|
+
|
|
165
|
+
let guessedWorkerFormat: CfScriptFormat;
|
|
166
|
+
const scriptExports = entryPoints[0][1].exports;
|
|
167
|
+
if (scriptExports.length > 0) {
|
|
168
|
+
if (scriptExports.includes("default")) {
|
|
169
|
+
guessedWorkerFormat = "modules";
|
|
170
|
+
} else {
|
|
171
|
+
logger.warn(
|
|
172
|
+
`The entrypoint ${path.relative(
|
|
173
|
+
process.cwd(),
|
|
174
|
+
entryFile
|
|
175
|
+
)} has exports like an ES Module, but hasn't defined a default export like a module worker normally would. Building the worker using "service-worker" format...`
|
|
176
|
+
);
|
|
177
|
+
guessedWorkerFormat = "service-worker";
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
guessedWorkerFormat = "service-worker";
|
|
181
|
+
}
|
|
155
182
|
|
|
156
183
|
if (hint) {
|
|
157
184
|
if (hint !== guessedWorkerFormat) {
|
|
158
185
|
if (hint === "service-worker") {
|
|
159
186
|
throw new Error(
|
|
160
|
-
"You configured this worker to be a 'service-worker', but the file you are trying to build appears to have
|
|
187
|
+
"You configured this worker to be a 'service-worker', but the file you are trying to build appears to have a `default` export like a module worker. Please pass `--format modules`, or simply remove the configuration."
|
|
161
188
|
);
|
|
162
189
|
} else {
|
|
163
190
|
throw new Error(
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { logger } from "./logger";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Create a function used to access an environment variable.
|
|
3
5
|
*
|
|
@@ -21,7 +23,7 @@ export function getEnvironmentVariableFactory({
|
|
|
21
23
|
if (!hasWarned) {
|
|
22
24
|
// Only show the warning once.
|
|
23
25
|
hasWarned = true;
|
|
24
|
-
|
|
26
|
+
logger.warn(
|
|
25
27
|
`Using "${deprecatedName}" environment variable. This is deprecated. Please use "${variableName}", instead.`
|
|
26
28
|
);
|
|
27
29
|
}
|
package/src/errors.ts
ADDED
package/src/https-options.ts
CHANGED
|
@@ -2,6 +2,7 @@ import * as fs from "node:fs";
|
|
|
2
2
|
import { homedir, networkInterfaces } from "node:os";
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
|
+
import { logger } from "./logger";
|
|
5
6
|
import type { Attributes, Options } from "selfsigned";
|
|
6
7
|
|
|
7
8
|
// Most of this file has been borrowed from the implementation in Miniflare.
|
|
@@ -26,7 +27,7 @@ export async function getHttpsOptions() {
|
|
|
26
27
|
hasCertificateExpired(keyPath, certPath);
|
|
27
28
|
|
|
28
29
|
if (regenerate) {
|
|
29
|
-
|
|
30
|
+
logger.log("Generating new self-signed certificate...");
|
|
30
31
|
const { key, cert } = await generateCertificate();
|
|
31
32
|
try {
|
|
32
33
|
// Write certificate files so we can reuse them later.
|
|
@@ -35,7 +36,7 @@ export async function getHttpsOptions() {
|
|
|
35
36
|
fs.writeFileSync(certPath, cert, "utf8");
|
|
36
37
|
} catch (e) {
|
|
37
38
|
const message = e instanceof Error ? e.message : `${e}`;
|
|
38
|
-
|
|
39
|
+
logger.warn(
|
|
39
40
|
`Unable to cache generated self-signed certificate in ${certDirectory}.\n${message}`
|
|
40
41
|
);
|
|
41
42
|
}
|