wrangler 0.0.0-e928f94 → 0.0.0-e93063e9
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/Cloudflare_CA.pem +18 -0
- package/README.md +47 -14
- package/bin/wrangler.js +180 -28
- package/kv-asset-handler.js +1 -0
- package/miniflare-dist/index.mjs +6364 -0
- package/package.json +194 -113
- 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__/config-cache-without-cache-dir.test.ts +38 -0
- package/src/__tests__/config-cache.test.ts +42 -0
- package/src/__tests__/configuration.test.ts +4163 -0
- package/src/__tests__/d1/d1.test.ts +123 -0
- package/src/__tests__/d1/splitter.test.ts +255 -0
- package/src/__tests__/delete.test.ts +266 -0
- package/src/__tests__/deployments.test.ts +105 -0
- package/src/__tests__/dev.test.tsx +1586 -0
- package/src/__tests__/generate.test.ts +238 -0
- package/src/__tests__/get-host-from-url.test.ts +16 -0
- package/src/__tests__/guess-worker-format.test.ts +85 -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/mock-account-id.ts +48 -0
- package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-bin.ts +36 -0
- package/src/__tests__/helpers/mock-cfetch.ts +278 -0
- package/src/__tests__/helpers/mock-console.ts +106 -0
- package/src/__tests__/helpers/mock-dialogs.ts +137 -0
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +8 -0
- package/src/__tests__/helpers/mock-http-server.ts +46 -0
- package/src/__tests__/helpers/mock-istty.ts +74 -0
- package/src/__tests__/helpers/mock-known-routes.ts +7 -0
- package/src/__tests__/helpers/mock-kv.ts +33 -0
- package/src/__tests__/helpers/mock-oauth-flow.ts +271 -0
- package/src/__tests__/helpers/mock-process.ts +34 -0
- package/src/__tests__/helpers/mock-stdin.ts +108 -0
- package/src/__tests__/helpers/mock-web-socket.ts +29 -0
- package/src/__tests__/helpers/msw/blob-worker.cjs +19 -0
- 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/msw/read-file-sync.js +61 -0
- package/src/__tests__/helpers/run-in-tmp.ts +38 -0
- package/src/__tests__/helpers/run-wrangler.ts +16 -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__/helpers/write-worker-source.ts +31 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
- package/src/__tests__/https-options.test.ts +163 -0
- package/src/__tests__/index.test.ts +264 -149
- package/src/__tests__/init.test.ts +3147 -0
- package/src/__tests__/jest.setup.ts +198 -0
- package/src/__tests__/kv.test.ts +1788 -0
- package/src/__tests__/logger.test.ts +141 -0
- package/src/__tests__/logout.test.ts +47 -0
- package/src/__tests__/metrics.test.ts +493 -0
- package/src/__tests__/middleware.scheduled.test.ts +145 -0
- package/src/__tests__/middleware.test.ts +750 -0
- package/src/__tests__/package-manager.test.ts +353 -0
- package/src/__tests__/pages-deployment-tail.test.ts +884 -0
- package/src/__tests__/pages.test.ts +2899 -0
- package/src/__tests__/parse.test.ts +330 -0
- package/src/__tests__/paths.test.ts +39 -0
- package/src/__tests__/publish.test.ts +7769 -0
- package/src/__tests__/pubsub.test.ts +490 -0
- package/src/__tests__/queues.test.ts +522 -0
- package/src/__tests__/r2.test.ts +393 -0
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +701 -0
- package/src/__tests__/tail.test.ts +905 -0
- package/src/__tests__/test-old-node-version.js +31 -0
- 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 +129 -0
- package/src/__tests__/utils-collectKeyValues.test.ts +47 -0
- package/src/__tests__/validate-dev-props.test.ts +56 -0
- package/src/__tests__/version.test.ts +35 -0
- package/src/__tests__/whoami.test.tsx +183 -0
- package/src/__tests__/worker-namespace.test.ts +326 -0
- package/src/abort.d.ts +3 -0
- package/src/api/dev.ts +247 -0
- package/src/api/index.ts +2 -0
- package/src/bundle-reporter.ts +68 -0
- package/src/bundle.ts +823 -0
- package/src/cfetch/index.ts +158 -0
- package/src/cfetch/internal.ts +261 -0
- package/src/cli.ts +26 -8
- package/src/config/README.md +107 -0
- package/src/config/config.ts +275 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +577 -0
- package/src/config/index.ts +358 -0
- package/src/config/validation-helpers.ts +597 -0
- package/src/config/validation.ts +2151 -0
- package/src/config-cache.ts +85 -0
- package/src/create-worker-preview.ts +282 -0
- package/src/create-worker-upload-form.ts +325 -0
- 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.ts +56 -0
- package/src/d1/execute.tsx +323 -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 +197 -0
- package/src/d1/migrations/create.tsx +77 -0
- package/src/d1/migrations/helpers.ts +147 -0
- package/src/d1/migrations/index.ts +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/splitter.ts +161 -0
- package/src/d1/types.ts +24 -0
- package/src/d1/utils.ts +48 -0
- package/src/delete.ts +103 -0
- package/src/deployments.ts +83 -0
- package/src/deprecated/index.ts +145 -0
- package/src/dev/dev-vars.ts +39 -0
- package/src/dev/dev.tsx +614 -0
- package/src/dev/get-local-persistence-path.ts +31 -0
- package/src/dev/local.tsx +932 -0
- package/src/dev/remote.tsx +630 -0
- package/src/dev/start-server.ts +543 -0
- package/src/dev/use-esbuild.ts +204 -0
- package/src/dev/validate-dev-props.ts +31 -0
- package/src/dev-registry.ts +201 -0
- package/src/dev.tsx +929 -704
- package/src/dialogs.ts +136 -0
- package/src/dispatch-namespace.ts +207 -0
- package/src/docs/index.ts +97 -0
- package/src/durable.ts +102 -0
- package/src/entry.ts +329 -0
- package/src/environment-variables/factory.ts +88 -0
- package/src/environment-variables/misc-variables.ts +30 -0
- package/src/errors.ts +11 -0
- package/src/generate/index.ts +300 -0
- package/src/git-client.ts +135 -0
- package/src/global-wrangler-config-path.ts +26 -0
- package/src/https-options.ts +127 -0
- package/src/index.ts +694 -0
- package/src/init.ts +1023 -0
- package/src/inspect.ts +767 -0
- package/src/intl-polyfill.d.ts +139 -0
- package/src/is-ci.ts +14 -0
- package/src/is-interactive.ts +16 -0
- package/src/jest.d.ts +4 -0
- package/src/kv/helpers.ts +430 -0
- package/src/kv/index.ts +596 -0
- package/src/logger.ts +104 -0
- package/src/metrics/index.ts +5 -0
- package/src/metrics/metrics-config.ts +239 -0
- package/src/metrics/metrics-dispatcher.ts +96 -0
- package/src/metrics/metrics-usage-headers.ts +24 -0
- package/src/metrics/send-event.ts +97 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/assets.ts +250 -0
- package/src/miniflare-cli/index.ts +210 -0
- package/src/miniflare-cli/request-context.ts +40 -0
- 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 +256 -53
- package/src/open-in-browser.ts +17 -0
- package/src/package-manager.ts +219 -0
- package/src/pages/build.ts +270 -0
- package/src/pages/constants.ts +18 -0
- package/src/pages/deployment-tails.ts +284 -0
- package/src/pages/deployments.tsx +84 -0
- package/src/pages/dev.ts +711 -0
- package/src/pages/errors.ts +66 -0
- package/src/pages/functions/buildPlugin.ts +107 -0
- package/src/pages/functions/buildWorker.ts +166 -0
- package/src/pages/functions/filepath-routing.test.ts +234 -0
- package/src/pages/functions/filepath-routing.ts +189 -0
- package/src/pages/functions/identifiers.ts +78 -0
- 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/routes.ts +151 -0
- package/src/pages/functions/tsconfig.json +8 -0
- package/src/pages/functions/tsconfig.tsbuildinfo +1 -0
- package/src/pages/functions.ts +82 -0
- package/src/pages/hash.ts +13 -0
- package/src/pages/index.ts +102 -0
- package/src/pages/projects.tsx +167 -0
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +462 -0
- package/src/pages/types.ts +41 -0
- package/src/pages/upload.tsx +447 -0
- package/src/pages/utils.ts +23 -0
- package/src/parse.ts +286 -0
- package/src/paths.ts +71 -0
- package/src/proxy.ts +694 -0
- package/src/publish/index.ts +270 -0
- package/src/publish/publish.ts +1038 -0
- package/src/pubsub/index.ts +286 -0
- package/src/pubsub/pubsub-commands.ts +624 -0
- 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/selfsigned.d.ts +29 -0
- package/src/sites.ts +372 -0
- package/src/tail/createTail.ts +379 -0
- package/src/tail/filters.ts +277 -0
- package/src/tail/index.ts +213 -0
- package/src/tail/printing.ts +107 -0
- package/src/tsconfig-sanity.ts +16 -0
- package/src/type-generation.ts +181 -0
- package/src/update-check.ts +19 -0
- package/src/user/access.ts +68 -0
- package/src/user/auth-variables.ts +113 -0
- package/src/user/choose-account.tsx +39 -0
- package/src/user/generate-auth-url.ts +33 -0
- package/src/user/generate-random-state.ts +16 -0
- package/src/user/index.ts +2 -0
- package/src/user/user.ts +1232 -0
- package/src/utils/collectKeyValues.ts +14 -0
- package/src/whoami.ts +135 -0
- package/src/worker.ts +251 -0
- package/src/yargs-types.ts +24 -0
- package/src/zones.ts +191 -0
- 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/checked-fetch.js +17 -0
- package/templates/d1-beta-facade.js +241 -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/gitignore +171 -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-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.js +15 -0
- package/templates/new-worker.ts +30 -0
- package/templates/no-op-worker.js +10 -0
- package/templates/pages-dev-pipeline.ts +31 -0
- package/templates/pages-dev-util.ts +52 -0
- package/templates/pages-shim.ts +12 -0
- package/templates/pages-template-plugin.ts +176 -0
- package/templates/pages-template-worker.ts +189 -0
- package/templates/serve-static-assets.ts +65 -0
- 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 +8 -0
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +906 -0
- package/wrangler-dist/cli.js +133533 -113146
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/src/__tests__/fixtures/init/.gitkeep +0 -0
- package/src/__tests__/mock-cfetch.js +0 -46
- package/src/api/form_data.ts +0 -141
- package/src/api/inspect.ts +0 -441
- package/src/api/preview.ts +0 -128
- package/src/api/worker.ts +0 -161
- package/src/cfetch.ts +0 -72
- package/src/config.ts +0 -122
- package/src/dialogs.tsx +0 -85
- package/src/index.tsx +0 -1858
- package/src/kv.tsx +0 -211
- package/src/pages.tsx +0 -843
- package/src/publish.ts +0 -346
- package/src/sites.tsx +0 -115
- package/src/tail.tsx +0 -71
- package/src/user.tsx +0 -1029
- package/static-asset-facade.js +0 -47
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
- package/wrangler-dist/cli.js.map +0 -7
package/src/dialogs.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import prompts from "prompts";
|
|
3
|
+
import { CI } from "./is-ci";
|
|
4
|
+
import isInteractive from "./is-interactive";
|
|
5
|
+
import { logger } from "./logger";
|
|
6
|
+
|
|
7
|
+
// TODO: Use this function across the codebase.
|
|
8
|
+
function isNonInteractiveOrCI(): boolean {
|
|
9
|
+
return !isInteractive() || CI.isCI();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class NoDefaultValueProvided extends Error {
|
|
13
|
+
constructor() {
|
|
14
|
+
// This is user-facing, so make the message something understandable
|
|
15
|
+
// It _should_ always be caught and replaced with a more descriptive error
|
|
16
|
+
// but this is fine as a fallback.
|
|
17
|
+
super("This command cannot be run in a non-interactive context");
|
|
18
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface ConfirmOptions {
|
|
23
|
+
defaultValue?: boolean;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function confirm(
|
|
27
|
+
text: string,
|
|
28
|
+
{ defaultValue = true }: ConfirmOptions = {}
|
|
29
|
+
): Promise<boolean> {
|
|
30
|
+
if (isNonInteractiveOrCI()) {
|
|
31
|
+
logger.log(`? ${text}`);
|
|
32
|
+
logger.log(
|
|
33
|
+
`🤖 ${chalk.dim(
|
|
34
|
+
"Using default value in non-interactive context:"
|
|
35
|
+
)} ${chalk.white.bold(defaultValue ? "yes" : "no")}`
|
|
36
|
+
);
|
|
37
|
+
return defaultValue;
|
|
38
|
+
}
|
|
39
|
+
const { value } = await prompts({
|
|
40
|
+
type: "confirm",
|
|
41
|
+
name: "value",
|
|
42
|
+
message: text,
|
|
43
|
+
initial: defaultValue,
|
|
44
|
+
onState: (state) => {
|
|
45
|
+
if (state.aborted) {
|
|
46
|
+
process.nextTick(() => {
|
|
47
|
+
process.exit(1);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
return value;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface PromptOptions {
|
|
56
|
+
defaultValue?: string;
|
|
57
|
+
isSecret?: boolean;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export async function prompt(
|
|
61
|
+
text: string,
|
|
62
|
+
options: PromptOptions = {}
|
|
63
|
+
): Promise<string> {
|
|
64
|
+
if (isNonInteractiveOrCI()) {
|
|
65
|
+
if (options?.defaultValue === undefined) {
|
|
66
|
+
throw new NoDefaultValueProvided();
|
|
67
|
+
}
|
|
68
|
+
logger.log(`? ${text}`);
|
|
69
|
+
logger.log(
|
|
70
|
+
`🤖 ${chalk.dim(
|
|
71
|
+
"Using default value in non-interactive context:"
|
|
72
|
+
)} ${chalk.white.bold(options.defaultValue)}`
|
|
73
|
+
);
|
|
74
|
+
return options.defaultValue;
|
|
75
|
+
}
|
|
76
|
+
const { value } = await prompts({
|
|
77
|
+
type: "text",
|
|
78
|
+
name: "value",
|
|
79
|
+
message: text,
|
|
80
|
+
initial: options?.defaultValue,
|
|
81
|
+
style: options?.isSecret ? "password" : "default",
|
|
82
|
+
onState: (state) => {
|
|
83
|
+
if (state.aborted) {
|
|
84
|
+
process.nextTick(() => {
|
|
85
|
+
process.exit(1);
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface SelectOptions<Values> {
|
|
94
|
+
choices: SelectOption<Values>[];
|
|
95
|
+
defaultOption?: number;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
interface SelectOption<Values> {
|
|
99
|
+
title: string;
|
|
100
|
+
description?: string;
|
|
101
|
+
value: Values;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export async function select<Values extends string>(
|
|
105
|
+
text: string,
|
|
106
|
+
options: SelectOptions<Values>
|
|
107
|
+
): Promise<Values> {
|
|
108
|
+
if (isNonInteractiveOrCI()) {
|
|
109
|
+
if (options?.defaultOption === undefined) {
|
|
110
|
+
throw new NoDefaultValueProvided();
|
|
111
|
+
}
|
|
112
|
+
logger.log(`? ${text}`);
|
|
113
|
+
logger.log(
|
|
114
|
+
`🤖 ${chalk.dim(
|
|
115
|
+
"Using default value in non-interactive context:"
|
|
116
|
+
)} ${chalk.white.bold(options.choices[options.defaultOption].title)}`
|
|
117
|
+
);
|
|
118
|
+
return options.choices[options.defaultOption].value;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const { value } = await prompts({
|
|
122
|
+
type: "select",
|
|
123
|
+
name: "value",
|
|
124
|
+
message: text,
|
|
125
|
+
choices: options.choices,
|
|
126
|
+
initial: options.defaultOption,
|
|
127
|
+
onState: (state) => {
|
|
128
|
+
if (state.aborted) {
|
|
129
|
+
process.nextTick(() => {
|
|
130
|
+
process.exit(1);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
});
|
|
135
|
+
return value;
|
|
136
|
+
}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { fetchResult } from "./cfetch";
|
|
2
|
+
import { readConfig } from "./config";
|
|
3
|
+
import { logger } from "./logger";
|
|
4
|
+
import * as metrics from "./metrics";
|
|
5
|
+
import { requireAuth } from "./user";
|
|
6
|
+
import { printWranglerBanner } from ".";
|
|
7
|
+
import type { ConfigPath } from ".";
|
|
8
|
+
import type { CommonYargsOptions } from "./yargs-types";
|
|
9
|
+
import type { Argv, CommandModule } from "yargs";
|
|
10
|
+
|
|
11
|
+
type Namespace = {
|
|
12
|
+
namespace_id: string;
|
|
13
|
+
namespace_name: string;
|
|
14
|
+
created_on: string;
|
|
15
|
+
created_by: string;
|
|
16
|
+
modified_on: string;
|
|
17
|
+
modified_by: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Supporting Workers For Platforms
|
|
21
|
+
// More details at https://blog.cloudflare.com/workers-for-platforms/
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Create a dynamic dispatch namespace.
|
|
25
|
+
*/
|
|
26
|
+
async function createWorkerNamespace(accountId: string, name: string) {
|
|
27
|
+
const namespace = await fetchResult<Namespace>(
|
|
28
|
+
`/accounts/${accountId}/workers/dispatch/namespaces`,
|
|
29
|
+
{
|
|
30
|
+
method: "POST",
|
|
31
|
+
headers: {
|
|
32
|
+
"Content-Type": "application/json",
|
|
33
|
+
},
|
|
34
|
+
body: JSON.stringify({ name }),
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
logger.log(
|
|
38
|
+
`Created dispatch namespace "${name}" with ID "${namespace.namespace_id}"`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Delete a dynamic dispatch namespace.
|
|
44
|
+
*/
|
|
45
|
+
async function deleteWorkerNamespace(accountId: string, name: string) {
|
|
46
|
+
await fetchResult(
|
|
47
|
+
`/accounts/${accountId}/workers/dispatch/namespaces/${name}`,
|
|
48
|
+
{ method: "DELETE" }
|
|
49
|
+
);
|
|
50
|
+
logger.log(`Deleted dispatch namespace "${name}"`);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* List all created dynamic dispatch namespaces for an account
|
|
55
|
+
*/
|
|
56
|
+
async function listWorkerNamespaces(accountId: string) {
|
|
57
|
+
logger.log(
|
|
58
|
+
await fetchResult<Namespace>(
|
|
59
|
+
`/accounts/${accountId}/workers/dispatch/namespaces`,
|
|
60
|
+
{
|
|
61
|
+
headers: {
|
|
62
|
+
"Content-Type": "application/json",
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get info for a specific dynamic dispatch namespace
|
|
71
|
+
*/
|
|
72
|
+
async function getWorkerNamespaceInfo(accountId: string, name: string) {
|
|
73
|
+
logger.log(
|
|
74
|
+
await fetchResult<Namespace>(
|
|
75
|
+
`/accounts/${accountId}/workers/dispatch/namespaces/${name}`,
|
|
76
|
+
{
|
|
77
|
+
headers: {
|
|
78
|
+
"Content-Type": "application/json",
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
)
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Rename a dynamic dispatch namespace
|
|
87
|
+
*/
|
|
88
|
+
async function renameWorkerNamespace(
|
|
89
|
+
accountId: string,
|
|
90
|
+
oldName: string,
|
|
91
|
+
newName: string
|
|
92
|
+
) {
|
|
93
|
+
void printWranglerBanner();
|
|
94
|
+
|
|
95
|
+
await fetchResult(
|
|
96
|
+
`/accounts/${accountId}/workers/dispatch/namespaces/${oldName}`,
|
|
97
|
+
{
|
|
98
|
+
method: "PUT",
|
|
99
|
+
headers: {
|
|
100
|
+
"Content-Type": "application/json",
|
|
101
|
+
},
|
|
102
|
+
body: JSON.stringify({ name: newName }),
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
logger.log(`Renamed dispatch namespace "${oldName}" to "${newName}"`);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function workerNamespaceCommands(
|
|
109
|
+
workerNamespaceYargs: Argv<CommonYargsOptions>,
|
|
110
|
+
subHelp: CommandModule<CommonYargsOptions, CommonYargsOptions>
|
|
111
|
+
) {
|
|
112
|
+
return workerNamespaceYargs
|
|
113
|
+
.command(subHelp)
|
|
114
|
+
.command("list", "List all dispatch namespaces", {}, async (args) => {
|
|
115
|
+
const config = readConfig(args.config as ConfigPath, args);
|
|
116
|
+
const accountId = await requireAuth(config);
|
|
117
|
+
await listWorkerNamespaces(accountId);
|
|
118
|
+
await metrics.sendMetricsEvent("list dispatch namespaces", {
|
|
119
|
+
sendMetrics: config.send_metrics,
|
|
120
|
+
});
|
|
121
|
+
})
|
|
122
|
+
.command(
|
|
123
|
+
"get <name>",
|
|
124
|
+
"Get information about a dispatch namespace",
|
|
125
|
+
(yargs) => {
|
|
126
|
+
return yargs.positional("name", {
|
|
127
|
+
describe: "Name of the dispatch namespace",
|
|
128
|
+
type: "string",
|
|
129
|
+
demandOption: true,
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
async (args) => {
|
|
133
|
+
const config = readConfig(args.config as ConfigPath, args);
|
|
134
|
+
const accountId = await requireAuth(config);
|
|
135
|
+
await getWorkerNamespaceInfo(accountId, args.name);
|
|
136
|
+
await metrics.sendMetricsEvent("view dispatch namespace", {
|
|
137
|
+
sendMetrics: config.send_metrics,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
)
|
|
141
|
+
.command(
|
|
142
|
+
"create <name>",
|
|
143
|
+
"Create a dispatch namespace",
|
|
144
|
+
(yargs) => {
|
|
145
|
+
return yargs.positional("name", {
|
|
146
|
+
describe: "Name of the dispatch namespace",
|
|
147
|
+
type: "string",
|
|
148
|
+
demandOption: true,
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
async (args) => {
|
|
152
|
+
await printWranglerBanner();
|
|
153
|
+
const config = readConfig(args.config as ConfigPath, args);
|
|
154
|
+
const accountId = await requireAuth(config);
|
|
155
|
+
await createWorkerNamespace(accountId, args.name);
|
|
156
|
+
await metrics.sendMetricsEvent("create dispatch namespace", {
|
|
157
|
+
sendMetrics: config.send_metrics,
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
)
|
|
161
|
+
.command(
|
|
162
|
+
"delete <name>",
|
|
163
|
+
"Delete a dispatch namespace",
|
|
164
|
+
(yargs) => {
|
|
165
|
+
return yargs.positional("name", {
|
|
166
|
+
describe: "Name of the dispatch namespace",
|
|
167
|
+
type: "string",
|
|
168
|
+
demandOption: true,
|
|
169
|
+
});
|
|
170
|
+
},
|
|
171
|
+
async (args) => {
|
|
172
|
+
await printWranglerBanner();
|
|
173
|
+
const config = readConfig(args.config as ConfigPath, args);
|
|
174
|
+
const accountId = await requireAuth(config);
|
|
175
|
+
await deleteWorkerNamespace(accountId, args.name);
|
|
176
|
+
await metrics.sendMetricsEvent("delete dispatch namespace", {
|
|
177
|
+
sendMetrics: config.send_metrics,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
)
|
|
181
|
+
.command(
|
|
182
|
+
"rename <old-name> <new-name>",
|
|
183
|
+
"Rename a dispatch namespace",
|
|
184
|
+
(yargs) => {
|
|
185
|
+
return yargs
|
|
186
|
+
.positional("old-name", {
|
|
187
|
+
describe: "Name of the dispatch namespace",
|
|
188
|
+
type: "string",
|
|
189
|
+
demandOption: true,
|
|
190
|
+
})
|
|
191
|
+
.positional("new-name", {
|
|
192
|
+
describe: "New name of the dispatch namespace",
|
|
193
|
+
type: "string",
|
|
194
|
+
demandOption: true,
|
|
195
|
+
});
|
|
196
|
+
},
|
|
197
|
+
async (args) => {
|
|
198
|
+
await printWranglerBanner();
|
|
199
|
+
const config = readConfig(args.config as ConfigPath, args);
|
|
200
|
+
const accountId = await requireAuth(config);
|
|
201
|
+
await renameWorkerNamespace(accountId, args.oldName, args.newName);
|
|
202
|
+
await metrics.sendMetricsEvent("rename dispatch namespace", {
|
|
203
|
+
sendMetrics: config.send_metrics,
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
);
|
|
207
|
+
}
|
|
@@ -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/durable.ts
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { fetchResult } from "./cfetch";
|
|
3
|
+
import { logger } from "./logger";
|
|
4
|
+
import type { Config } from "./config";
|
|
5
|
+
import type { CfWorkerInit } from "./worker";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* For a given Worker + migrations config, figure out which migrations
|
|
9
|
+
* to upload based on the current migration tag of the deployed Worker.
|
|
10
|
+
*/
|
|
11
|
+
export async function getMigrationsToUpload(
|
|
12
|
+
scriptName: string,
|
|
13
|
+
props: {
|
|
14
|
+
accountId: string | undefined;
|
|
15
|
+
config: Config;
|
|
16
|
+
legacyEnv: boolean | undefined;
|
|
17
|
+
env: string | undefined;
|
|
18
|
+
}
|
|
19
|
+
): Promise<CfWorkerInit["migrations"]> {
|
|
20
|
+
const { config, accountId } = props;
|
|
21
|
+
|
|
22
|
+
assert(accountId, "Missing accountId");
|
|
23
|
+
// if config.migrations
|
|
24
|
+
let migrations;
|
|
25
|
+
if (config.migrations.length > 0) {
|
|
26
|
+
// get current migration tag
|
|
27
|
+
type ScriptData = { id: string; migration_tag?: string };
|
|
28
|
+
let script: ScriptData | undefined;
|
|
29
|
+
if (!props.legacyEnv) {
|
|
30
|
+
try {
|
|
31
|
+
if (props.env) {
|
|
32
|
+
const scriptData = await fetchResult<{
|
|
33
|
+
script: ScriptData;
|
|
34
|
+
}>(
|
|
35
|
+
`/accounts/${accountId}/workers/services/${scriptName}/environments/${props.env}`
|
|
36
|
+
);
|
|
37
|
+
script = scriptData.script;
|
|
38
|
+
} else {
|
|
39
|
+
const scriptData = await fetchResult<{
|
|
40
|
+
default_environment: {
|
|
41
|
+
script: ScriptData;
|
|
42
|
+
};
|
|
43
|
+
}>(`/accounts/${accountId}/workers/services/${scriptName}`);
|
|
44
|
+
script = scriptData.default_environment.script;
|
|
45
|
+
}
|
|
46
|
+
} catch (err) {
|
|
47
|
+
if (
|
|
48
|
+
![
|
|
49
|
+
10090, // corresponds to workers.api.error.service_not_found, so the script wasn't previously published at all
|
|
50
|
+
10092, // workers.api.error.environment_not_found, so the script wasn't published to this environment yet
|
|
51
|
+
].includes((err as { code: number }).code)
|
|
52
|
+
) {
|
|
53
|
+
throw err;
|
|
54
|
+
}
|
|
55
|
+
// else it's a 404, no script found, and we can proceed
|
|
56
|
+
}
|
|
57
|
+
} else {
|
|
58
|
+
const scripts = await fetchResult<ScriptData[]>(
|
|
59
|
+
`/accounts/${accountId}/workers/scripts`
|
|
60
|
+
);
|
|
61
|
+
script = scripts.find(({ id }) => id === scriptName);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (script?.migration_tag) {
|
|
65
|
+
// was already published once
|
|
66
|
+
const scriptMigrationTag = script.migration_tag;
|
|
67
|
+
const foundIndex = config.migrations.findIndex(
|
|
68
|
+
(migration) => migration.tag === scriptMigrationTag
|
|
69
|
+
);
|
|
70
|
+
if (foundIndex === -1) {
|
|
71
|
+
logger.warn(
|
|
72
|
+
`The published script ${scriptName} has a migration tag "${script.migration_tag}, which was not found in wrangler.toml. You may have already deleted it. Applying all available migrations to the script...`
|
|
73
|
+
);
|
|
74
|
+
migrations = {
|
|
75
|
+
old_tag: script.migration_tag,
|
|
76
|
+
new_tag: config.migrations[config.migrations.length - 1].tag,
|
|
77
|
+
steps: config.migrations.map(({ tag: _tag, ...rest }) => rest),
|
|
78
|
+
};
|
|
79
|
+
} else {
|
|
80
|
+
if (foundIndex !== config.migrations.length - 1) {
|
|
81
|
+
// there are new migrations to send up
|
|
82
|
+
migrations = {
|
|
83
|
+
old_tag: script.migration_tag,
|
|
84
|
+
new_tag: config.migrations[config.migrations.length - 1].tag,
|
|
85
|
+
steps: config.migrations
|
|
86
|
+
.slice(foundIndex + 1)
|
|
87
|
+
.map(({ tag: _tag, ...rest }) => rest),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
// else, we're up to date, no migrations to send
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
// first time publishing durable objects to this script,
|
|
94
|
+
// so we send all the migrations
|
|
95
|
+
migrations = {
|
|
96
|
+
new_tag: config.migrations[config.migrations.length - 1].tag,
|
|
97
|
+
steps: config.migrations.map(({ tag: _tag, ...rest }) => rest),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return migrations;
|
|
102
|
+
}
|