wrangler 0.0.0-e178d6fb → 0.0.0-e1c2f5b9
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 +16 -2
- package/bin/wrangler.js +31 -11
- package/miniflare-dist/index.mjs +1340 -330
- package/package.json +40 -13
- package/src/__tests__/access.test.ts +25 -0
- package/src/__tests__/api-dev.test.ts +238 -0
- package/src/__tests__/api-devregistry.test.js +64 -0
- package/src/__tests__/api.test.ts +80 -0
- package/src/__tests__/configuration.test.ts +683 -470
- package/src/__tests__/d1.test.ts +123 -0
- package/src/__tests__/delete.test.ts +263 -0
- package/src/__tests__/deployments.test.ts +105 -0
- package/src/__tests__/dev.test.tsx +453 -70
- package/src/__tests__/dialogs.test.tsx +40 -0
- package/src/__tests__/generate.test.ts +235 -0
- package/src/__tests__/get-host-from-url.test.ts +16 -0
- package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-cfetch.ts +92 -26
- package/src/__tests__/helpers/mock-console.ts +11 -2
- package/src/__tests__/helpers/mock-dialogs.ts +1 -1
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
- package/src/__tests__/helpers/mock-known-routes.ts +7 -0
- package/src/__tests__/helpers/mock-kv.ts +1 -1
- package/src/__tests__/helpers/mock-oauth-flow.ts +74 -53
- package/src/__tests__/helpers/mock-process.ts +8 -13
- package/src/__tests__/helpers/msw/handlers/access.ts +13 -0
- package/src/__tests__/helpers/msw/handlers/deployments.ts +59 -0
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +104 -0
- package/src/__tests__/helpers/msw/handlers/oauth.ts +31 -0
- package/src/__tests__/helpers/msw/handlers/r2.ts +80 -0
- package/src/__tests__/helpers/msw/handlers/script.ts +75 -0
- package/src/__tests__/helpers/msw/handlers/user.ts +63 -0
- package/src/__tests__/helpers/msw/handlers/zones.ts +22 -0
- package/src/__tests__/helpers/msw/index.ts +21 -0
- package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +1 -0
- package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +5 -0
- package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +1 -0
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +8 -0
- package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +5 -0
- package/src/__tests__/index.test.ts +103 -97
- package/src/__tests__/init.test.ts +1484 -382
- package/src/__tests__/jest.setup.ts +88 -5
- package/src/__tests__/kv.test.ts +655 -540
- package/src/__tests__/logout.test.ts +47 -0
- package/src/__tests__/metrics.test.ts +95 -45
- package/src/__tests__/middleware.scheduled.test.ts +145 -0
- package/src/__tests__/middleware.test.ts +750 -0
- package/src/__tests__/pages-deployment-tail.test.ts +884 -0
- package/src/__tests__/pages.test.ts +1301 -119
- package/src/__tests__/paths.test.ts +39 -0
- package/src/__tests__/publish.test.ts +2266 -1180
- package/src/__tests__/pubsub.test.ts +211 -88
- package/src/__tests__/queues.test.ts +522 -0
- package/src/__tests__/r2.test.ts +363 -203
- package/src/__tests__/secret.test.ts +261 -59
- package/src/__tests__/tail.test.ts +352 -151
- package/src/__tests__/test-old-node-version.js +3 -3
- package/src/__tests__/tsconfig-sanity.ts +12 -0
- package/src/__tests__/tsconfig.json +8 -0
- package/src/__tests__/tsconfig.tsbuildinfo +1 -0
- package/src/__tests__/type-generation.test.ts +233 -0
- package/src/__tests__/user.test.ts +59 -73
- package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
- package/src/__tests__/validate-dev-props.test.ts +56 -0
- package/src/__tests__/whoami.test.tsx +114 -66
- package/src/__tests__/worker-namespace.test.ts +154 -155
- package/src/api/dev.ts +170 -38
- package/src/api/index.ts +1 -0
- package/src/bundle-reporter.tsx +41 -2
- package/src/bundle.ts +668 -81
- package/src/cfetch/index.ts +40 -3
- package/src/cfetch/internal.ts +144 -32
- package/src/cli.ts +4 -3
- package/src/config/config.ts +27 -3
- package/src/config/environment.ts +131 -7
- package/src/config/index.ts +128 -8
- package/src/config/validation-helpers.ts +19 -6
- package/src/config/validation.ts +411 -14
- package/src/config-cache.ts +3 -2
- package/src/create-worker-preview.ts +31 -6
- package/src/create-worker-upload-form.ts +84 -22
- package/src/d1/backups.tsx +223 -0
- package/src/d1/constants.ts +2 -0
- package/src/d1/create.tsx +63 -0
- package/src/d1/delete.tsx +56 -0
- package/src/d1/execute.tsx +352 -0
- package/src/d1/formatTimeAgo.ts +14 -0
- package/src/d1/index.ts +101 -0
- package/src/d1/list.tsx +48 -0
- package/src/d1/migrations/apply.tsx +196 -0
- package/src/d1/migrations/create.tsx +77 -0
- package/src/d1/migrations/helpers.ts +147 -0
- package/src/d1/migrations/index.tsx +3 -0
- package/src/d1/migrations/list.tsx +79 -0
- package/src/d1/migrations/options.ts +18 -0
- package/src/d1/options.ts +22 -0
- package/src/d1/types.tsx +24 -0
- package/src/d1/utils.ts +48 -0
- package/src/delete.ts +108 -0
- package/src/deployments.ts +83 -0
- package/src/deprecated/index.ts +145 -0
- package/src/dev/dev-vars.ts +11 -8
- package/src/dev/dev.tsx +220 -58
- package/src/dev/get-local-persistence-path.tsx +31 -0
- package/src/dev/local.tsx +740 -181
- package/src/dev/remote.tsx +340 -123
- package/src/dev/start-server.ts +543 -0
- package/src/dev/use-esbuild.ts +61 -7
- package/src/dev/validate-dev-props.ts +31 -0
- package/src/dev-registry.tsx +201 -0
- package/src/dev.tsx +614 -258
- package/src/dialogs.tsx +41 -8
- package/src/{worker-namespace.ts → dispatch-namespace.ts} +23 -22
- package/src/docs/index.ts +97 -0
- package/src/entry.ts +3 -2
- package/src/environment-variables/factory.ts +88 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/generate/index.ts +300 -0
- package/src/git-client.ts +100 -7
- package/src/index.tsx +249 -1560
- package/src/init.ts +626 -150
- package/src/inspect.ts +137 -32
- package/src/{metrics/is-ci.ts → is-ci.ts} +0 -0
- package/src/is-interactive.ts +4 -0
- package/src/jest.d.ts +4 -0
- package/src/{kv.ts → kv/helpers.ts} +3 -3
- package/src/kv/index.ts +596 -0
- package/src/logger.ts +27 -8
- package/src/metrics/index.ts +1 -0
- package/src/metrics/metrics-config.ts +4 -4
- package/src/metrics/metrics-dispatcher.ts +1 -0
- package/src/metrics/metrics-usage-headers.ts +24 -0
- package/src/metrics/send-event.ts +13 -8
- package/src/miniflare-cli/assets.ts +172 -465
- package/src/miniflare-cli/index.ts +149 -24
- package/src/miniflare-cli/tsconfig.json +9 -0
- package/src/miniflare-cli/tsconfig.tsbuildinfo +1 -0
- package/src/miniflare-cli/types.ts +11 -0
- package/src/module-collection.ts +12 -3
- package/src/pages/build.tsx +108 -42
- package/src/pages/constants.ts +11 -0
- package/src/pages/deployment-tails.tsx +284 -0
- package/src/pages/deployments.tsx +9 -31
- package/src/pages/dev.tsx +417 -108
- package/src/pages/errors.ts +66 -0
- package/src/pages/functions/buildPlugin.ts +86 -84
- package/src/pages/functions/buildWorker.ts +121 -106
- package/src/pages/functions/routes-consolidation.test.ts +250 -0
- package/src/pages/functions/routes-consolidation.ts +73 -0
- package/src/pages/functions/routes-transformation.test.ts +282 -0
- package/src/pages/functions/routes-transformation.ts +115 -0
- package/src/pages/functions/routes-validation.test.ts +403 -0
- package/src/pages/functions/routes-validation.ts +202 -0
- package/src/pages/functions/tsconfig.json +8 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
- package/src/pages/functions.tsx +82 -0
- package/src/pages/hash.tsx +13 -0
- package/src/pages/index.tsx +73 -55
- package/src/pages/projects.tsx +9 -3
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +183 -60
- package/src/pages/types.ts +1 -0
- package/src/pages/upload.tsx +107 -56
- package/src/pages/utils.ts +13 -2
- package/src/paths.ts +49 -4
- package/src/proxy.ts +375 -157
- package/src/publish/index.ts +270 -0
- package/src/{publish.ts → publish/publish.ts} +431 -188
- package/src/pubsub/pubsub-commands.tsx +4 -3
- package/src/queues/cli/commands/consumer/add.ts +71 -0
- package/src/queues/cli/commands/consumer/index.ts +22 -0
- package/src/queues/cli/commands/consumer/remove.ts +38 -0
- package/src/queues/cli/commands/create.ts +25 -0
- package/src/queues/cli/commands/delete.ts +26 -0
- package/src/queues/cli/commands/index.ts +36 -0
- package/src/queues/cli/commands/list.ts +25 -0
- package/src/queues/client.ts +135 -0
- package/src/queues/utils.ts +18 -0
- package/src/r2/constants.ts +4 -0
- package/src/r2/helpers.ts +131 -0
- package/src/r2/index.ts +289 -0
- package/src/routes.ts +140 -0
- package/src/secret/index.ts +379 -0
- package/src/sites.tsx +3 -3
- package/src/tail/createTail.ts +379 -0
- package/src/tail/filters.ts +4 -6
- package/src/tail/index.ts +199 -284
- package/src/tail/printing.ts +43 -3
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +181 -0
- package/src/user/access.ts +68 -0
- package/src/user/auth-variables.ts +113 -0
- package/src/user/choose-account.tsx +1 -1
- package/src/user/index.ts +0 -1
- package/src/user/user.tsx +116 -49
- package/src/utils/collectKeyValues.ts +14 -0
- package/src/whoami.tsx +80 -2
- package/src/worker.ts +69 -9
- package/src/yargs-types.ts +24 -0
- package/src/zones.ts +124 -9
- package/templates/__tests__/pages-dev-util.test.ts +128 -0
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/__tests__/tsconfig.tsbuildinfo +1 -0
- package/templates/d1-beta-facade.js +205 -0
- package/templates/facade.d.ts +14 -0
- package/templates/first-party-worker-module-facade.ts +19 -0
- package/templates/format-dev-errors.ts +33 -0
- package/templates/init-tests/test-jest-new-worker.js +23 -0
- package/templates/init-tests/test-vitest-new-worker.js +24 -0
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/common.ts +62 -0
- package/templates/middleware/loader-modules.ts +82 -0
- package/templates/middleware/loader-sw.ts +233 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +20 -0
- package/templates/middleware/middleware-pretty-error.ts +40 -0
- package/templates/middleware/middleware-scheduled.ts +15 -0
- package/templates/new-worker.js +1 -1
- package/templates/pages-dev-pipeline.ts +31 -0
- package/templates/pages-dev-util.ts +52 -0
- package/templates/pages-shim.ts +4 -1
- package/templates/pages-template-plugin.ts +21 -5
- package/templates/pages-template-worker.ts +37 -9
- package/templates/{static-asset-facade.js → serve-static-assets.ts} +23 -7
- package/templates/service-bindings-module-facade.js +54 -0
- package/templates/service-bindings-sw-facade.js +42 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +106 -0
- package/templates/tsconfig.json +5 -102
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +621 -42
- package/wrangler-dist/cli.js +144441 -102606
- package/src/environment-variables.ts +0 -35
- package/src/faye-websocket.d.ts +0 -6
- package/src/generate.ts +0 -33
- package/src/miniflare-cli/enum-keys.ts +0 -17
- package/src/preview.ts +0 -31
- package/src/r2.ts +0 -50
- package/src/user/env-vars.ts +0 -46
package/src/dialogs.tsx
CHANGED
|
@@ -4,7 +4,11 @@ import SelectInput from "ink-select-input";
|
|
|
4
4
|
import TextInput from "ink-text-input";
|
|
5
5
|
import * as React from "react";
|
|
6
6
|
import { useState } from "react";
|
|
7
|
+
|
|
8
|
+
import { CI } from "./is-ci";
|
|
9
|
+
import isInteractive from "./is-interactive";
|
|
7
10
|
import { logger } from "./logger";
|
|
11
|
+
|
|
8
12
|
type ConfirmProps = {
|
|
9
13
|
text: string;
|
|
10
14
|
onConfirm: (answer: boolean) => void;
|
|
@@ -28,16 +32,22 @@ function Confirm(props: ConfirmProps) {
|
|
|
28
32
|
);
|
|
29
33
|
}
|
|
30
34
|
|
|
31
|
-
export function confirm(
|
|
35
|
+
export function confirm(
|
|
36
|
+
text: string,
|
|
37
|
+
beforeConfirm?: JSX.Element
|
|
38
|
+
): Promise<boolean> {
|
|
32
39
|
return new Promise((resolve) => {
|
|
33
40
|
const { unmount } = render(
|
|
34
|
-
<
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
<Box flexDirection="column">
|
|
42
|
+
{beforeConfirm}
|
|
43
|
+
<Confirm
|
|
44
|
+
text={text}
|
|
45
|
+
onConfirm={(answer: boolean) => {
|
|
46
|
+
unmount();
|
|
47
|
+
resolve(answer);
|
|
48
|
+
}}
|
|
49
|
+
/>
|
|
50
|
+
</Box>
|
|
41
51
|
);
|
|
42
52
|
});
|
|
43
53
|
}
|
|
@@ -133,3 +143,26 @@ export function select(
|
|
|
133
143
|
);
|
|
134
144
|
});
|
|
135
145
|
}
|
|
146
|
+
|
|
147
|
+
export function logDim(msg: string) {
|
|
148
|
+
console.log(chalk.gray(msg));
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export async function fromDashMessagePrompt(
|
|
152
|
+
deploySource: "dash" | "wrangler" | "api"
|
|
153
|
+
): Promise<boolean | void> {
|
|
154
|
+
if (deploySource === "dash") {
|
|
155
|
+
logger.warn(
|
|
156
|
+
`You are about to publish a Workers Service that was last published via the Cloudflare Dashboard.\nEdits that have been made via the dashboard will be overridden by your local code and config.`
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
if (!isInteractive() || CI.isCI()) return true;
|
|
160
|
+
|
|
161
|
+
return await confirm("Would you like to continue?");
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
export async function tailDOLogPrompt(): Promise<boolean | void> {
|
|
165
|
+
if (!isInteractive() || CI.isCI()) return true;
|
|
166
|
+
|
|
167
|
+
return await confirm("Would you like to continue?");
|
|
168
|
+
}
|
|
@@ -5,6 +5,7 @@ import * as metrics from "./metrics";
|
|
|
5
5
|
import { requireAuth } from "./user";
|
|
6
6
|
import { printWranglerBanner } from ".";
|
|
7
7
|
import type { ConfigPath } from ".";
|
|
8
|
+
import type { CommonYargsOptions } from "./yargs-types";
|
|
8
9
|
import type { Argv, CommandModule } from "yargs";
|
|
9
10
|
|
|
10
11
|
type Namespace = {
|
|
@@ -34,7 +35,7 @@ async function createWorkerNamespace(accountId: string, name: string) {
|
|
|
34
35
|
}
|
|
35
36
|
);
|
|
36
37
|
logger.log(
|
|
37
|
-
`Created
|
|
38
|
+
`Created dispatch namespace "${name}" with ID "${namespace.namespace_id}"`
|
|
38
39
|
);
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -46,7 +47,7 @@ async function deleteWorkerNamespace(accountId: string, name: string) {
|
|
|
46
47
|
`/accounts/${accountId}/workers/dispatch/namespaces/${name}`,
|
|
47
48
|
{ method: "DELETE" }
|
|
48
49
|
);
|
|
49
|
-
logger.log(`Deleted
|
|
50
|
+
logger.log(`Deleted dispatch namespace "${name}"`);
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
/**
|
|
@@ -89,7 +90,7 @@ async function renameWorkerNamespace(
|
|
|
89
90
|
oldName: string,
|
|
90
91
|
newName: string
|
|
91
92
|
) {
|
|
92
|
-
printWranglerBanner();
|
|
93
|
+
void printWranglerBanner();
|
|
93
94
|
|
|
94
95
|
await fetchResult(
|
|
95
96
|
`/accounts/${accountId}/workers/dispatch/namespaces/${oldName}`,
|
|
@@ -101,29 +102,29 @@ async function renameWorkerNamespace(
|
|
|
101
102
|
body: JSON.stringify({ name: newName }),
|
|
102
103
|
}
|
|
103
104
|
);
|
|
104
|
-
logger.log(`Renamed
|
|
105
|
+
logger.log(`Renamed dispatch namespace "${oldName}" to "${newName}"`);
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
export function workerNamespaceCommands(
|
|
108
|
-
workerNamespaceYargs: Argv
|
|
109
|
-
subHelp: CommandModule
|
|
110
|
-
)
|
|
109
|
+
workerNamespaceYargs: Argv<CommonYargsOptions>,
|
|
110
|
+
subHelp: CommandModule<CommonYargsOptions, CommonYargsOptions>
|
|
111
|
+
) {
|
|
111
112
|
return workerNamespaceYargs
|
|
112
113
|
.command(subHelp)
|
|
113
|
-
.command("list", "List all
|
|
114
|
+
.command("list", "List all dispatch namespaces", {}, async (args) => {
|
|
114
115
|
const config = readConfig(args.config as ConfigPath, args);
|
|
115
116
|
const accountId = await requireAuth(config);
|
|
116
117
|
await listWorkerNamespaces(accountId);
|
|
117
|
-
await metrics.sendMetricsEvent("list
|
|
118
|
+
await metrics.sendMetricsEvent("list dispatch namespaces", {
|
|
118
119
|
sendMetrics: config.send_metrics,
|
|
119
120
|
});
|
|
120
121
|
})
|
|
121
122
|
.command(
|
|
122
123
|
"get <name>",
|
|
123
|
-
"Get information about a
|
|
124
|
+
"Get information about a dispatch namespace",
|
|
124
125
|
(yargs) => {
|
|
125
126
|
return yargs.positional("name", {
|
|
126
|
-
describe: "Name of the
|
|
127
|
+
describe: "Name of the dispatch namespace",
|
|
127
128
|
type: "string",
|
|
128
129
|
demandOption: true,
|
|
129
130
|
});
|
|
@@ -132,17 +133,17 @@ export function workerNamespaceCommands(
|
|
|
132
133
|
const config = readConfig(args.config as ConfigPath, args);
|
|
133
134
|
const accountId = await requireAuth(config);
|
|
134
135
|
await getWorkerNamespaceInfo(accountId, args.name);
|
|
135
|
-
await metrics.sendMetricsEvent("view
|
|
136
|
+
await metrics.sendMetricsEvent("view dispatch namespace", {
|
|
136
137
|
sendMetrics: config.send_metrics,
|
|
137
138
|
});
|
|
138
139
|
}
|
|
139
140
|
)
|
|
140
141
|
.command(
|
|
141
142
|
"create <name>",
|
|
142
|
-
"Create a
|
|
143
|
+
"Create a dispatch namespace",
|
|
143
144
|
(yargs) => {
|
|
144
145
|
return yargs.positional("name", {
|
|
145
|
-
describe: "Name of the
|
|
146
|
+
describe: "Name of the dispatch namespace",
|
|
146
147
|
type: "string",
|
|
147
148
|
demandOption: true,
|
|
148
149
|
});
|
|
@@ -152,17 +153,17 @@ export function workerNamespaceCommands(
|
|
|
152
153
|
const config = readConfig(args.config as ConfigPath, args);
|
|
153
154
|
const accountId = await requireAuth(config);
|
|
154
155
|
await createWorkerNamespace(accountId, args.name);
|
|
155
|
-
await metrics.sendMetricsEvent("create
|
|
156
|
+
await metrics.sendMetricsEvent("create dispatch namespace", {
|
|
156
157
|
sendMetrics: config.send_metrics,
|
|
157
158
|
});
|
|
158
159
|
}
|
|
159
160
|
)
|
|
160
161
|
.command(
|
|
161
162
|
"delete <name>",
|
|
162
|
-
"Delete a
|
|
163
|
+
"Delete a dispatch namespace",
|
|
163
164
|
(yargs) => {
|
|
164
165
|
return yargs.positional("name", {
|
|
165
|
-
describe: "Name of the
|
|
166
|
+
describe: "Name of the dispatch namespace",
|
|
166
167
|
type: "string",
|
|
167
168
|
demandOption: true,
|
|
168
169
|
});
|
|
@@ -172,23 +173,23 @@ export function workerNamespaceCommands(
|
|
|
172
173
|
const config = readConfig(args.config as ConfigPath, args);
|
|
173
174
|
const accountId = await requireAuth(config);
|
|
174
175
|
await deleteWorkerNamespace(accountId, args.name);
|
|
175
|
-
await metrics.sendMetricsEvent("delete
|
|
176
|
+
await metrics.sendMetricsEvent("delete dispatch namespace", {
|
|
176
177
|
sendMetrics: config.send_metrics,
|
|
177
178
|
});
|
|
178
179
|
}
|
|
179
180
|
)
|
|
180
181
|
.command(
|
|
181
182
|
"rename <old-name> <new-name>",
|
|
182
|
-
"Rename a
|
|
183
|
+
"Rename a dispatch namespace",
|
|
183
184
|
(yargs) => {
|
|
184
185
|
return yargs
|
|
185
186
|
.positional("old-name", {
|
|
186
|
-
describe: "Name of the
|
|
187
|
+
describe: "Name of the dispatch namespace",
|
|
187
188
|
type: "string",
|
|
188
189
|
demandOption: true,
|
|
189
190
|
})
|
|
190
191
|
.positional("new-name", {
|
|
191
|
-
describe: "New name of the
|
|
192
|
+
describe: "New name of the dispatch namespace",
|
|
192
193
|
type: "string",
|
|
193
194
|
demandOption: true,
|
|
194
195
|
});
|
|
@@ -198,7 +199,7 @@ export function workerNamespaceCommands(
|
|
|
198
199
|
const config = readConfig(args.config as ConfigPath, args);
|
|
199
200
|
const accountId = await requireAuth(config);
|
|
200
201
|
await renameWorkerNamespace(accountId, args.oldName, args.newName);
|
|
201
|
-
await metrics.sendMetricsEvent("rename
|
|
202
|
+
await metrics.sendMetricsEvent("rename dispatch namespace", {
|
|
202
203
|
sendMetrics: config.send_metrics,
|
|
203
204
|
});
|
|
204
205
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { printWranglerBanner } from "..";
|
|
2
|
+
import { readConfig } from "../config";
|
|
3
|
+
import { logger } from "../logger";
|
|
4
|
+
import * as metrics from "../metrics";
|
|
5
|
+
import openInBrowser from "../open-in-browser";
|
|
6
|
+
|
|
7
|
+
import type {
|
|
8
|
+
CommonYargsOptions,
|
|
9
|
+
YargsOptionsToInterface,
|
|
10
|
+
} from "../yargs-types";
|
|
11
|
+
import type { ArgumentsCamelCase, Argv } from "yargs";
|
|
12
|
+
|
|
13
|
+
const argToUrlHash = {
|
|
14
|
+
docs: "docs",
|
|
15
|
+
init: "init",
|
|
16
|
+
generate: "generate",
|
|
17
|
+
dev: "dev",
|
|
18
|
+
publish: "publish",
|
|
19
|
+
delete: "delete",
|
|
20
|
+
"kv:namespace": "kvnamespace",
|
|
21
|
+
"kv:key": "kvkey",
|
|
22
|
+
"kv:bulk": "kvbulk",
|
|
23
|
+
"r2 bucket": "r2-bucket",
|
|
24
|
+
"r2 object": "r2-object",
|
|
25
|
+
secret: "secret",
|
|
26
|
+
"secret:bulk": "secretbulk",
|
|
27
|
+
tail: "tail",
|
|
28
|
+
pages: "pages",
|
|
29
|
+
login: "login",
|
|
30
|
+
logout: "logout",
|
|
31
|
+
whoami: "whoami",
|
|
32
|
+
types: "types",
|
|
33
|
+
deployments: "deployments",
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function docsOptions(yargs: Argv<CommonYargsOptions>) {
|
|
37
|
+
return yargs.positional("command", {
|
|
38
|
+
describe: "Enter the wrangler command you want to know more about",
|
|
39
|
+
type: "string",
|
|
40
|
+
// requiresArg: true,
|
|
41
|
+
choices: [
|
|
42
|
+
"docs",
|
|
43
|
+
"init",
|
|
44
|
+
"generate",
|
|
45
|
+
"dev",
|
|
46
|
+
"publish",
|
|
47
|
+
"delete",
|
|
48
|
+
"tail",
|
|
49
|
+
"secret",
|
|
50
|
+
"secret:bulk",
|
|
51
|
+
"kv:namespace",
|
|
52
|
+
"kv:key",
|
|
53
|
+
"kv:bulk",
|
|
54
|
+
"pages",
|
|
55
|
+
// "queues", //TODO: Undocumented
|
|
56
|
+
"r2 object",
|
|
57
|
+
"r2 bucket",
|
|
58
|
+
// "dispatch-namespace", // TODO: Undocumented - Workers for Platforms
|
|
59
|
+
// "d1", //TODO: Undocumented
|
|
60
|
+
// "pubsub", //TODO: Undocumented
|
|
61
|
+
"login",
|
|
62
|
+
"logout",
|
|
63
|
+
"whoami",
|
|
64
|
+
"types",
|
|
65
|
+
"deployments",
|
|
66
|
+
"api",
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
type DocsArgs = YargsOptionsToInterface<typeof docsOptions>;
|
|
72
|
+
|
|
73
|
+
function isValidParam(k: string): k is keyof typeof argToUrlHash {
|
|
74
|
+
return k in argToUrlHash;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export async function docsHandler(args: ArgumentsCamelCase<DocsArgs>) {
|
|
78
|
+
let urlToOpen =
|
|
79
|
+
"https://developers.cloudflare.com/workers/wrangler/commands/";
|
|
80
|
+
|
|
81
|
+
if (args.command === "api") {
|
|
82
|
+
//if api, take them to the API docs
|
|
83
|
+
urlToOpen = "https://developers.cloudflare.com/workers/wrangler/api/";
|
|
84
|
+
} else if (args.command && isValidParam(args.command)) {
|
|
85
|
+
//otherwise, they get the wrangler commands page
|
|
86
|
+
urlToOpen += `#${argToUrlHash[args.command]}`;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
await printWranglerBanner();
|
|
90
|
+
|
|
91
|
+
logger.log(`Opening a link in your default browser: ${urlToOpen}`);
|
|
92
|
+
await openInBrowser(urlToOpen);
|
|
93
|
+
const config = readConfig(undefined, {});
|
|
94
|
+
await metrics.sendMetricsEvent("view docs", {
|
|
95
|
+
sendMetrics: config.send_metrics,
|
|
96
|
+
});
|
|
97
|
+
}
|
package/src/entry.ts
CHANGED
|
@@ -4,6 +4,7 @@ import path from "node:path";
|
|
|
4
4
|
import * as esbuild from "esbuild";
|
|
5
5
|
import { execaCommand } from "execa";
|
|
6
6
|
import { logger } from "./logger";
|
|
7
|
+
import { getBasePath } from "./paths";
|
|
7
8
|
import type { Config } from "./config";
|
|
8
9
|
import type { CfScriptFormat } from "./worker";
|
|
9
10
|
import type { Metafile } from "esbuild";
|
|
@@ -25,7 +26,7 @@ export async function getEntry(
|
|
|
25
26
|
assets?: string | undefined;
|
|
26
27
|
},
|
|
27
28
|
config: Config,
|
|
28
|
-
command: "dev" | "publish"
|
|
29
|
+
command: "dev" | "publish" | "types"
|
|
29
30
|
): Promise<Entry> {
|
|
30
31
|
let file: string;
|
|
31
32
|
let directory = process.cwd();
|
|
@@ -40,7 +41,7 @@ export async function getEntry(
|
|
|
40
41
|
: // site.entry-point could be a directory
|
|
41
42
|
path.resolve(config.site?.["entry-point"], "index.js");
|
|
42
43
|
} else if (args.assets || config.assets) {
|
|
43
|
-
file = path.resolve(
|
|
44
|
+
file = path.resolve(getBasePath(), "templates/no-op-worker.js");
|
|
44
45
|
} else {
|
|
45
46
|
throw new Error(
|
|
46
47
|
`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.`
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { logger } from "../logger";
|
|
2
|
+
|
|
3
|
+
type VariableNames =
|
|
4
|
+
| "CLOUDFLARE_ACCOUNT_ID"
|
|
5
|
+
| "CLOUDFLARE_API_TOKEN"
|
|
6
|
+
| "CLOUDFLARE_API_KEY"
|
|
7
|
+
| "CLOUDFLARE_EMAIL"
|
|
8
|
+
| "WRANGLER_SEND_METRICS"
|
|
9
|
+
| "CLOUDFLARE_API_BASE_URL"
|
|
10
|
+
| "WRANGLER_LOG"
|
|
11
|
+
| "WRANGLER_API_ENVIRONMENT"
|
|
12
|
+
| "WRANGLER_CLIENT_ID"
|
|
13
|
+
| "WRANGLER_AUTH_DOMAIN"
|
|
14
|
+
| "WRANGLER_AUTH_URL"
|
|
15
|
+
| "WRANGLER_TOKEN_URL"
|
|
16
|
+
| "WRANGLER_REVOKE_URL"
|
|
17
|
+
| "WRANGLER_CF_AUTHORIZATION_TOKEN";
|
|
18
|
+
|
|
19
|
+
type DeprecatedNames =
|
|
20
|
+
| "CF_ACCOUNT_ID"
|
|
21
|
+
| "CF_API_TOKEN"
|
|
22
|
+
| "CF_API_KEY"
|
|
23
|
+
| "CF_EMAIL"
|
|
24
|
+
| "CF_API_BASE_URL";
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Create a function used to access an environment variable.
|
|
28
|
+
*
|
|
29
|
+
* This is not memoized to allow us to change the value at runtime, such as in testing.
|
|
30
|
+
* A warning is shown if the client is using a deprecated version - but only once.
|
|
31
|
+
*/
|
|
32
|
+
export function getEnvironmentVariableFactory({
|
|
33
|
+
variableName,
|
|
34
|
+
deprecatedName,
|
|
35
|
+
}: {
|
|
36
|
+
variableName: VariableNames;
|
|
37
|
+
deprecatedName?: DeprecatedNames;
|
|
38
|
+
}): () => string | undefined;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Create a function used to access an environment variable, with a default value.
|
|
42
|
+
*
|
|
43
|
+
* This is not memoized to allow us to change the value at runtime, such as in testing.
|
|
44
|
+
* A warning is shown if the client is using a deprecated version - but only once.
|
|
45
|
+
*/
|
|
46
|
+
export function getEnvironmentVariableFactory({
|
|
47
|
+
variableName,
|
|
48
|
+
deprecatedName,
|
|
49
|
+
defaultValue,
|
|
50
|
+
}: {
|
|
51
|
+
variableName: VariableNames;
|
|
52
|
+
deprecatedName?: DeprecatedNames;
|
|
53
|
+
defaultValue: () => string;
|
|
54
|
+
}): () => string;
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Create a function used to access an environment variable.
|
|
58
|
+
*
|
|
59
|
+
* This is not memoized to allow us to change the value at runtime, such as in testing.
|
|
60
|
+
* A warning is shown if the client is using a deprecated version - but only once.
|
|
61
|
+
*/
|
|
62
|
+
export function getEnvironmentVariableFactory({
|
|
63
|
+
variableName,
|
|
64
|
+
deprecatedName,
|
|
65
|
+
defaultValue,
|
|
66
|
+
}: {
|
|
67
|
+
variableName: VariableNames;
|
|
68
|
+
deprecatedName?: DeprecatedNames;
|
|
69
|
+
defaultValue?: () => string;
|
|
70
|
+
}): () => string | undefined {
|
|
71
|
+
let hasWarned = false;
|
|
72
|
+
return () => {
|
|
73
|
+
if (process.env[variableName]) {
|
|
74
|
+
return process.env[variableName];
|
|
75
|
+
} else if (deprecatedName && process.env[deprecatedName]) {
|
|
76
|
+
if (!hasWarned) {
|
|
77
|
+
// Only show the warning once.
|
|
78
|
+
hasWarned = true;
|
|
79
|
+
logger.warn(
|
|
80
|
+
`Using "${deprecatedName}" environment variable. This is deprecated. Please use "${variableName}", instead.`
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
return process.env[deprecatedName];
|
|
84
|
+
} else {
|
|
85
|
+
return defaultValue?.();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getEnvironmentVariableFactory } from "./factory";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* `WRANGLER_SEND_METRICS` can override whether we attempt to send metrics information to Sparrow.
|
|
5
|
+
*/
|
|
6
|
+
export const getWranglerSendMetricsFromEnv = getEnvironmentVariableFactory({
|
|
7
|
+
variableName: "WRANGLER_SEND_METRICS",
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Set `WRANGLER_API_ENVIRONMENT` environment variable to "staging" to tell Wrangler to hit the staging APIs rather than production.
|
|
12
|
+
*/
|
|
13
|
+
export const getCloudflareApiEnvironmentFromEnv = getEnvironmentVariableFactory(
|
|
14
|
+
{
|
|
15
|
+
variableName: "WRANGLER_API_ENVIRONMENT",
|
|
16
|
+
defaultValue: () => "production",
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* `CLOUDFLARE_API_BASE_URL` specifies the URL to the Cloudflare API.
|
|
22
|
+
*/
|
|
23
|
+
export const getCloudflareApiBaseUrl = getEnvironmentVariableFactory({
|
|
24
|
+
variableName: "CLOUDFLARE_API_BASE_URL",
|
|
25
|
+
deprecatedName: "CF_API_BASE_URL",
|
|
26
|
+
defaultValue: () =>
|
|
27
|
+
getCloudflareApiEnvironmentFromEnv() === "staging"
|
|
28
|
+
? "https://api.staging.cloudflare.com/client/v4"
|
|
29
|
+
: "https://api.cloudflare.com/client/v4",
|
|
30
|
+
});
|