wrangler 0.0.0-e043479 → 0.0.0-e0621809
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 +181 -29
- package/kv-asset-handler.js +1 -0
- package/miniflare-dist/index.mjs +6368 -0
- package/package.json +198 -136
- 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 +4456 -2178
- package/src/__tests__/d1/d1.test.ts +82 -0
- package/src/__tests__/d1/execute.test.ts +66 -0
- package/src/__tests__/d1/migrate.test.ts +157 -0
- package/src/__tests__/d1/splitter.test.ts +255 -0
- package/src/__tests__/delete.test.ts +272 -0
- package/src/__tests__/deployments.test.ts +369 -0
- package/src/__tests__/dev.test.tsx +1605 -235
- 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 +111 -57
- package/src/__tests__/helpers/cmd-shim.d.ts +6 -6
- package/src/__tests__/helpers/end-event-loop.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +26 -22
- package/src/__tests__/helpers/mock-auth-domain.ts +20 -0
- package/src/__tests__/helpers/mock-bin.ts +20 -20
- package/src/__tests__/helpers/mock-console.ts +74 -32
- package/src/__tests__/helpers/mock-dialogs.ts +107 -33
- package/src/__tests__/helpers/mock-get-pages-upload-token.ts +25 -0
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +11 -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 +12 -0
- package/src/__tests__/helpers/mock-kv.ts +42 -36
- package/src/__tests__/helpers/mock-oauth-flow.ts +263 -0
- package/src/__tests__/helpers/mock-process.ts +34 -0
- package/src/__tests__/helpers/mock-set-timeout.ts +16 -0
- package/src/__tests__/helpers/mock-stdin.ts +82 -77
- package/src/__tests__/helpers/mock-web-socket.ts +21 -21
- 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 +160 -0
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +81 -0
- package/src/__tests__/helpers/msw/handlers/oauth.ts +31 -0
- package/src/__tests__/helpers/msw/handlers/r2.ts +60 -0
- package/src/__tests__/helpers/msw/handlers/script.ts +56 -0
- package/src/__tests__/helpers/msw/handlers/user.ts +52 -0
- package/src/__tests__/helpers/msw/handlers/zones.ts +20 -0
- package/src/__tests__/helpers/msw/index.ts +52 -0
- package/src/__tests__/helpers/msw/read-file-sync.js +61 -0
- package/src/__tests__/helpers/run-in-tmp.ts +29 -20
- package/src/__tests__/helpers/run-wrangler.ts +8 -8
- package/src/__tests__/helpers/string-dynamic-values-matcher.ts +28 -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 +11 -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 +9 -9
- package/src/__tests__/https-options.test.ts +163 -0
- package/src/__tests__/index.test.ts +264 -850
- package/src/__tests__/init.test.ts +3196 -0
- package/src/__tests__/jest.setup.ts +158 -48
- package/src/__tests__/kv.test.ts +1789 -1398
- package/src/__tests__/logger.test.ts +141 -0
- package/src/__tests__/logout.test.ts +41 -44
- package/src/__tests__/metrics.test.ts +493 -0
- package/src/__tests__/middleware.scheduled.test.ts +145 -0
- package/src/__tests__/middleware.test.ts +816 -0
- package/src/__tests__/mtls-certificates.test.ts +588 -0
- package/src/__tests__/package-manager.test.ts +312 -165
- package/src/__tests__/pages/deployment-list.test.ts +80 -0
- package/src/__tests__/pages/functions-build.test.ts +452 -0
- package/src/__tests__/pages/pages.test.ts +81 -0
- package/src/__tests__/pages/project-create.test.ts +63 -0
- package/src/__tests__/pages/project-list.test.ts +110 -0
- package/src/__tests__/pages/project-upload.test.ts +500 -0
- package/src/__tests__/pages/publish.test.ts +2820 -0
- package/src/__tests__/pages-deployment-tail.test.ts +955 -0
- package/src/__tests__/parse.test.ts +359 -245
- package/src/__tests__/paths.test.ts +39 -0
- package/src/__tests__/publish.test.ts +8373 -2089
- package/src/__tests__/pubsub.test.ts +496 -0
- package/src/__tests__/queues.test.ts +532 -0
- package/src/__tests__/r2.test.ts +369 -193
- package/src/__tests__/route.test.ts +45 -0
- package/src/__tests__/secret.test.ts +683 -415
- package/src/__tests__/tail.test.ts +838 -444
- 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 +234 -0
- package/src/__tests__/user.test.ts +118 -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 +167 -81
- package/src/__tests__/worker-namespace.test.ts +340 -0
- package/src/abort.d.ts +3 -0
- package/src/api/dev.ts +327 -0
- package/src/api/index.ts +11 -0
- package/src/api/mtls-certificate.ts +148 -0
- package/src/api/pages/create-worker-bundle-contents.ts +75 -0
- package/src/api/pages/index.ts +5 -0
- package/src/api/pages/publish.tsx +355 -0
- package/src/bundle-reporter.ts +68 -0
- package/src/bundle.ts +874 -103
- package/src/cfetch/index.ts +123 -69
- package/src/cfetch/internal.ts +217 -92
- package/src/cli.ts +23 -14
- package/src/config/README.md +7 -7
- package/src/config/config.ts +236 -224
- package/src/config/diagnostics.ts +61 -61
- package/src/config/environment.ts +545 -256
- package/src/config/index.ts +367 -34
- package/src/config/validation-helpers.ts +449 -222
- package/src/config/validation.ts +2142 -907
- package/src/config-cache.ts +85 -0
- package/src/create-worker-preview.ts +293 -0
- package/src/create-worker-upload-form.ts +342 -0
- package/src/d1/backups.tsx +219 -0
- package/src/d1/constants.ts +2 -0
- package/src/d1/create.tsx +68 -0
- package/src/d1/delete.ts +53 -0
- package/src/d1/execute.tsx +357 -0
- package/src/d1/formatTimeAgo.ts +14 -0
- package/src/d1/index.ts +100 -0
- package/src/d1/list.tsx +60 -0
- package/src/d1/migrations/apply.tsx +212 -0
- package/src/d1/migrations/create.tsx +79 -0
- package/src/d1/migrations/helpers.ts +172 -0
- package/src/d1/migrations/index.ts +3 -0
- package/src/d1/migrations/list.tsx +95 -0
- package/src/d1/migrations/options.ts +23 -0
- package/src/d1/options.ts +22 -0
- package/src/d1/splitter.ts +161 -0
- package/src/d1/types.ts +25 -0
- package/src/d1/utils.ts +49 -0
- package/src/delete.ts +100 -0
- package/src/deployments.ts +368 -0
- package/src/deprecated/index.ts +144 -0
- package/src/dev/dev-vars.ts +39 -0
- package/src/dev/dev.tsx +600 -0
- package/src/dev/get-local-persistence-path.ts +31 -0
- package/src/dev/local.tsx +920 -0
- package/src/dev/remote.tsx +632 -0
- package/src/dev/start-server.ts +540 -0
- package/src/dev/use-esbuild.ts +209 -0
- package/src/dev/validate-dev-props.ts +40 -0
- package/src/dev-registry.ts +201 -0
- package/src/dev.tsx +907 -939
- package/src/dialogs.ts +136 -0
- package/src/dispatch-namespace.ts +211 -0
- package/src/docs/index.ts +97 -0
- package/src/durable.ts +102 -0
- package/src/entry.ts +307 -37
- 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 +298 -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 +758 -0
- package/src/init.ts +1032 -0
- package/src/inspect.ts +723 -550
- 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 +594 -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 +99 -0
- package/src/miniflare-cli/README.md +30 -0
- package/src/miniflare-cli/assets.ts +251 -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 +243 -146
- package/src/mtls-certificate/cli.ts +155 -0
- package/src/open-in-browser.ts +10 -6
- package/src/package-manager.ts +183 -90
- package/src/pages/build.ts +410 -0
- package/src/pages/buildFunctions.ts +140 -0
- package/src/pages/constants.ts +18 -0
- package/src/pages/deployment-tails.ts +281 -0
- package/src/pages/deployments.tsx +84 -0
- package/src/pages/dev.ts +716 -0
- package/src/pages/errors.ts +67 -0
- package/src/pages/functions/buildPlugin.ts +112 -0
- package/src/pages/functions/buildWorker.ts +297 -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 +86 -0
- package/src/pages/hash.ts +13 -0
- package/src/pages/index.ts +102 -0
- package/src/pages/projects.tsx +159 -0
- package/src/pages/prompt-select-project.tsx +31 -0
- package/src/pages/publish.tsx +267 -0
- package/src/pages/types.ts +46 -0
- package/src/pages/upload.tsx +469 -0
- package/src/pages/utils.ts +23 -0
- package/src/parse.ts +247 -122
- package/src/paths.ts +53 -8
- package/src/proxy.ts +636 -318
- package/src/publish/index.ts +274 -0
- package/src/publish/publish.ts +1065 -0
- package/src/pubsub/index.ts +286 -0
- package/src/pubsub/pubsub-commands.ts +623 -0
- package/src/queues/cli/commands/consumer/add.ts +71 -0
- package/src/queues/cli/commands/consumer/index.ts +19 -0
- package/src/queues/cli/commands/consumer/remove.ts +31 -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 +35 -0
- package/src/queues/cli/commands/list.ts +25 -0
- package/src/queues/client.ts +136 -0
- package/src/queues/utils.ts +18 -0
- package/src/r2/constants.ts +4 -0
- package/src/r2/helpers.ts +132 -0
- package/src/r2/index.ts +289 -0
- package/src/routes.ts +140 -0
- package/src/secret/index.ts +375 -0
- package/src/selfsigned.d.ts +29 -0
- package/src/sites.ts +372 -0
- package/src/tail/createTail.ts +406 -0
- package/src/tail/filters.ts +109 -111
- package/src/tail/index.ts +208 -296
- package/src/tail/printing.ts +107 -47
- 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 +1233 -0
- package/src/utils/collectKeyValues.ts +14 -0
- package/src/utils/render.ts +93 -0
- package/src/whoami.ts +135 -0
- package/src/worker.ts +264 -0
- package/src/yargs-types.ts +37 -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 +23 -0
- package/templates/d1-beta-facade.js +244 -0
- package/templates/facade.d.ts +14 -0
- package/templates/first-party-worker-module-facade.ts +19 -0
- package/templates/format-dev-errors.ts +34 -0
- package/templates/gitignore +172 -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 +84 -0
- package/templates/middleware/loader-sw.ts +233 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +32 -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 +3 -3
- package/templates/new-worker.ts +21 -3
- 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 +180 -0
- package/templates/pages-template-worker.ts +189 -0
- package/templates/serve-static-assets.ts +66 -0
- package/templates/service-bindings-module-facade.js +55 -0
- package/templates/service-bindings-sw-facade.js +42 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +105 -0
- package/templates/tsconfig.json +6 -103
- package/templates/tsconfig.tsbuildinfo +1 -0
- package/wrangler-dist/cli.d.ts +1619 -0
- package/wrangler-dist/cli.js +141446 -128789
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/pages/functions/buildWorker.ts +0 -62
- package/pages/functions/filepath-routing.test.ts +0 -123
- package/pages/functions/filepath-routing.ts +0 -178
- package/pages/functions/identifiers.ts +0 -78
- package/pages/functions/routes.ts +0 -151
- package/pages/functions/template-worker.ts +0 -130
- package/src/__tests__/helpers/faye-websocket.d.ts +0 -6
- package/src/__tests__/helpers/mock-cfetch.ts +0 -207
- package/src/__tests__/helpers/mock-user.ts +0 -27
- package/src/__tests__/sentry.test.ts +0 -146
- package/src/api/form_data.ts +0 -217
- package/src/api/preview.ts +0 -147
- package/src/api/worker.ts +0 -186
- package/src/dialogs.tsx +0 -77
- package/src/environment-variables.ts +0 -33
- package/src/guess-worker-format.ts +0 -68
- package/src/index.tsx +0 -2302
- package/src/kv.tsx +0 -339
- package/src/pages.tsx +0 -1045
- package/src/publish.ts +0 -363
- package/src/r2.ts +0 -50
- package/src/reporting.ts +0 -115
- package/src/sites.tsx +0 -238
- package/src/user.tsx +0 -1063
- package/src/whoami.tsx +0 -69
- package/templates/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/api/form_data.ts
DELETED
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
|
-
import { FormData, File } from "undici";
|
|
3
|
-
import type {
|
|
4
|
-
CfWorkerInit,
|
|
5
|
-
CfModuleType,
|
|
6
|
-
CfDurableObjectMigrations,
|
|
7
|
-
} from "./worker.js";
|
|
8
|
-
|
|
9
|
-
export function toMimeType(type: CfModuleType): string {
|
|
10
|
-
switch (type) {
|
|
11
|
-
case "esm":
|
|
12
|
-
return "application/javascript+module";
|
|
13
|
-
case "commonjs":
|
|
14
|
-
return "application/javascript";
|
|
15
|
-
case "compiled-wasm":
|
|
16
|
-
return "application/wasm";
|
|
17
|
-
case "buffer":
|
|
18
|
-
return "application/octet-stream";
|
|
19
|
-
case "text":
|
|
20
|
-
return "text/plain";
|
|
21
|
-
default:
|
|
22
|
-
throw new TypeError("Unsupported module: " + type);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface WorkerMetadata {
|
|
27
|
-
/** The name of the entry point module. Only exists when the worker is in the ES module format */
|
|
28
|
-
main_module?: string;
|
|
29
|
-
/** The name of the entry point module. Only exists when the worker is in the Service Worker format */
|
|
30
|
-
body_part?: string;
|
|
31
|
-
compatibility_date?: string;
|
|
32
|
-
compatibility_flags?: string[];
|
|
33
|
-
usage_model?: "bundled" | "unbound";
|
|
34
|
-
migrations?: CfDurableObjectMigrations;
|
|
35
|
-
bindings: (
|
|
36
|
-
| { type: "kv_namespace"; name: string; namespace_id: string }
|
|
37
|
-
| { type: "plain_text"; name: string; text: string }
|
|
38
|
-
| { type: "json"; name: string; json: unknown }
|
|
39
|
-
| { type: "wasm_module"; name: string; part: string }
|
|
40
|
-
| { type: "text_blob"; name: string; part: string }
|
|
41
|
-
| {
|
|
42
|
-
type: "durable_object_namespace";
|
|
43
|
-
name: string;
|
|
44
|
-
class_name: string;
|
|
45
|
-
script_name?: string;
|
|
46
|
-
}
|
|
47
|
-
| { type: "r2_bucket"; name: string; bucket_name: string }
|
|
48
|
-
)[];
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Creates a `FormData` upload from a `CfWorkerInit`.
|
|
53
|
-
*/
|
|
54
|
-
export function toFormData(worker: CfWorkerInit): FormData {
|
|
55
|
-
const formData = new FormData();
|
|
56
|
-
const {
|
|
57
|
-
main,
|
|
58
|
-
bindings,
|
|
59
|
-
migrations,
|
|
60
|
-
usage_model,
|
|
61
|
-
compatibility_date,
|
|
62
|
-
compatibility_flags,
|
|
63
|
-
} = worker;
|
|
64
|
-
|
|
65
|
-
let { modules } = worker;
|
|
66
|
-
|
|
67
|
-
const metadataBindings: WorkerMetadata["bindings"] = [];
|
|
68
|
-
|
|
69
|
-
bindings.kv_namespaces?.forEach(({ id, binding }) => {
|
|
70
|
-
metadataBindings.push({
|
|
71
|
-
name: binding,
|
|
72
|
-
type: "kv_namespace",
|
|
73
|
-
namespace_id: id,
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
bindings.durable_objects?.bindings.forEach(
|
|
78
|
-
({ name, class_name, script_name }) => {
|
|
79
|
-
metadataBindings.push({
|
|
80
|
-
name,
|
|
81
|
-
type: "durable_object_namespace",
|
|
82
|
-
class_name: class_name,
|
|
83
|
-
...(script_name && { script_name }),
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
bindings.r2_buckets?.forEach(({ binding, bucket_name }) => {
|
|
89
|
-
metadataBindings.push({
|
|
90
|
-
name: binding,
|
|
91
|
-
type: "r2_bucket",
|
|
92
|
-
bucket_name,
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
Object.entries(bindings.vars || {})?.forEach(([key, value]) => {
|
|
97
|
-
if (typeof value === "string") {
|
|
98
|
-
metadataBindings.push({ name: key, type: "plain_text", text: value });
|
|
99
|
-
} else {
|
|
100
|
-
metadataBindings.push({ name: key, type: "json", json: value });
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
for (const [name, filePath] of Object.entries(bindings.wasm_modules || {})) {
|
|
105
|
-
metadataBindings.push({
|
|
106
|
-
name,
|
|
107
|
-
type: "wasm_module",
|
|
108
|
-
part: name,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
formData.set(
|
|
112
|
-
name,
|
|
113
|
-
new File([readFileSync(filePath)], filePath, {
|
|
114
|
-
type: "application/wasm",
|
|
115
|
-
})
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
for (const [name, filePath] of Object.entries(bindings.text_blobs || {})) {
|
|
120
|
-
metadataBindings.push({
|
|
121
|
-
name,
|
|
122
|
-
type: "text_blob",
|
|
123
|
-
part: name,
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
if (name !== "__STATIC_CONTENT_MANIFEST") {
|
|
127
|
-
formData.set(
|
|
128
|
-
name,
|
|
129
|
-
new File([readFileSync(filePath)], filePath, {
|
|
130
|
-
type: "text/plain",
|
|
131
|
-
})
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (main.type === "commonjs") {
|
|
137
|
-
// This is a service-worker format worker.
|
|
138
|
-
for (const module of Object.values([...(modules || [])])) {
|
|
139
|
-
if (module.name === "__STATIC_CONTENT_MANIFEST") {
|
|
140
|
-
// Add the manifest to the form data.
|
|
141
|
-
formData.set(
|
|
142
|
-
module.name,
|
|
143
|
-
new File([module.content], module.name, {
|
|
144
|
-
type: "text/plain",
|
|
145
|
-
})
|
|
146
|
-
);
|
|
147
|
-
// And then remove it from the modules collection
|
|
148
|
-
modules = modules?.filter((m) => m !== module);
|
|
149
|
-
} else if (module.type === "compiled-wasm" || module.type === "text") {
|
|
150
|
-
// Convert all wasm/text modules into `wasm_module`/`text_blob` bindings.
|
|
151
|
-
// The "name" of the module is a file path. We use it
|
|
152
|
-
// to instead be a "part" of the body, and a reference
|
|
153
|
-
// that we can use inside our source. This identifier has to be a valid
|
|
154
|
-
// JS identifier, so we replace all non alphanumeric characters
|
|
155
|
-
// with an underscore.
|
|
156
|
-
const name = module.name.replace(/[^a-zA-Z0-9_$]/g, "_");
|
|
157
|
-
metadataBindings.push({
|
|
158
|
-
name,
|
|
159
|
-
type: module.type === "compiled-wasm" ? "wasm_module" : "text_blob",
|
|
160
|
-
part: name,
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
// Add the module to the form data.
|
|
164
|
-
formData.set(
|
|
165
|
-
name,
|
|
166
|
-
new File([module.content], module.name, {
|
|
167
|
-
type:
|
|
168
|
-
module.type === "compiled-wasm"
|
|
169
|
-
? "application/wasm"
|
|
170
|
-
: "text/plain",
|
|
171
|
-
})
|
|
172
|
-
);
|
|
173
|
-
// And then remove it from the modules collection
|
|
174
|
-
modules = modules?.filter((m) => m !== module);
|
|
175
|
-
} else if (module.type === "buffer") {
|
|
176
|
-
throw new Error(
|
|
177
|
-
'The "buffer" module type is not yet supported in service worker format workers'
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
if (bindings.unsafe) {
|
|
184
|
-
// @ts-expect-error unsafe bindings don't need to match a specific type here
|
|
185
|
-
metadataBindings.push(...bindings.unsafe);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const metadata: WorkerMetadata = {
|
|
189
|
-
...(main.type !== "commonjs"
|
|
190
|
-
? { main_module: main.name }
|
|
191
|
-
: { body_part: main.name }),
|
|
192
|
-
bindings: metadataBindings,
|
|
193
|
-
...(compatibility_date && { compatibility_date }),
|
|
194
|
-
...(compatibility_flags && { compatibility_flags }),
|
|
195
|
-
...(usage_model && { usage_model }),
|
|
196
|
-
...(migrations && { migrations }),
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
formData.set("metadata", JSON.stringify(metadata));
|
|
200
|
-
|
|
201
|
-
if (main.type === "commonjs" && modules && modules.length > 0) {
|
|
202
|
-
throw new TypeError(
|
|
203
|
-
"More than one module can only be specified when type = 'esm'"
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
for (const module of [main].concat(modules || [])) {
|
|
208
|
-
formData.set(
|
|
209
|
-
module.name,
|
|
210
|
-
new File([module.content], module.name, {
|
|
211
|
-
type: toMimeType(module.type ?? main.type ?? "esm"),
|
|
212
|
-
})
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return formData;
|
|
217
|
-
}
|
package/src/api/preview.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { URL } from "node:url";
|
|
2
|
-
import { fetch } from "undici";
|
|
3
|
-
import { fetchResult } from "../cfetch";
|
|
4
|
-
import { toFormData } from "./form_data";
|
|
5
|
-
import type { CfAccount, CfWorkerContext, CfWorkerInit } from "./worker";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A preview mode.
|
|
9
|
-
*
|
|
10
|
-
* * If true, then using a `workers.dev` subdomain.
|
|
11
|
-
* * Otherwise, a list of routes under a single zone.
|
|
12
|
-
*/
|
|
13
|
-
type CfPreviewMode = { workers_dev: boolean } | { routes: string[] };
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* A preview token.
|
|
17
|
-
*/
|
|
18
|
-
export interface CfPreviewToken {
|
|
19
|
-
/**
|
|
20
|
-
* The header value required to trigger a preview.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* const headers = { 'cf-workers-preview-token': value }
|
|
24
|
-
* const response = await fetch('https://' + host, { headers })
|
|
25
|
-
*/
|
|
26
|
-
value: string;
|
|
27
|
-
/**
|
|
28
|
-
* The host where the preview is available.
|
|
29
|
-
*/
|
|
30
|
-
host: string;
|
|
31
|
-
/**
|
|
32
|
-
* A websocket url to a DevTools inspector.
|
|
33
|
-
*
|
|
34
|
-
* Workers does not have a fully-featured implementation
|
|
35
|
-
* of the Chrome DevTools protocol, but supports the following:
|
|
36
|
-
* * `console.log()` output.
|
|
37
|
-
* * `Error` stack traces.
|
|
38
|
-
* * `fetch()` events.
|
|
39
|
-
*
|
|
40
|
-
* There is no support for breakpoints, but we want to implement
|
|
41
|
-
* this eventually.
|
|
42
|
-
*
|
|
43
|
-
* @link https://chromedevtools.github.io/devtools-protocol/
|
|
44
|
-
*/
|
|
45
|
-
inspectorUrl: URL;
|
|
46
|
-
/**
|
|
47
|
-
* A url to prewarm the preview session.
|
|
48
|
-
*
|
|
49
|
-
* @example
|
|
50
|
-
* fetch(prewarmUrl, { method: 'POST' })
|
|
51
|
-
*/
|
|
52
|
-
prewarmUrl: URL;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Generates a preview session token.
|
|
57
|
-
*/
|
|
58
|
-
async function sessionToken(
|
|
59
|
-
account: CfAccount,
|
|
60
|
-
ctx: CfWorkerContext
|
|
61
|
-
): Promise<CfPreviewToken> {
|
|
62
|
-
const { accountId } = account;
|
|
63
|
-
const initUrl = ctx.zone
|
|
64
|
-
? `/zones/${ctx.zone.id}/workers/edge-preview`
|
|
65
|
-
: `/accounts/${accountId}/workers/subdomain/edge-preview`;
|
|
66
|
-
|
|
67
|
-
const { exchange_url } = await fetchResult<{ exchange_url: string }>(initUrl);
|
|
68
|
-
const { inspector_websocket, token } = (await (
|
|
69
|
-
await fetch(exchange_url)
|
|
70
|
-
).json()) as { inspector_websocket: string; token: string };
|
|
71
|
-
const { host } = new URL(inspector_websocket);
|
|
72
|
-
const query = `cf_workers_preview_token=${token}`;
|
|
73
|
-
|
|
74
|
-
return {
|
|
75
|
-
value: token,
|
|
76
|
-
host,
|
|
77
|
-
inspectorUrl: new URL(`${inspector_websocket}?${query}`),
|
|
78
|
-
prewarmUrl: new URL(
|
|
79
|
-
`https://${host}/cdn-cgi/workers/preview/prewarm?${query}`
|
|
80
|
-
),
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Credit: https://stackoverflow.com/a/2117523
|
|
85
|
-
function randomId(): string {
|
|
86
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
87
|
-
const r = (Math.random() * 16) | 0,
|
|
88
|
-
v = c == "x" ? r : (r & 0x3) | 0x8;
|
|
89
|
-
return v.toString(16);
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Creates a preview token.
|
|
95
|
-
*/
|
|
96
|
-
export async function previewToken(
|
|
97
|
-
account: CfAccount,
|
|
98
|
-
worker: CfWorkerInit,
|
|
99
|
-
ctx: CfWorkerContext
|
|
100
|
-
): Promise<CfPreviewToken> {
|
|
101
|
-
const { value, host, inspectorUrl, prewarmUrl } = await sessionToken(
|
|
102
|
-
account,
|
|
103
|
-
ctx
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const { accountId } = account;
|
|
107
|
-
const scriptId = ctx.zone ? randomId() : worker.name || host.split(".")[0];
|
|
108
|
-
const url =
|
|
109
|
-
ctx.env && !ctx.legacyEnv
|
|
110
|
-
? `/accounts/${accountId}/workers/services/${scriptId}/environments/${ctx.env}/edge-preview`
|
|
111
|
-
: `/accounts/${accountId}/workers/scripts/${scriptId}/edge-preview`;
|
|
112
|
-
|
|
113
|
-
const mode: CfPreviewMode = ctx.zone
|
|
114
|
-
? { routes: ["*/*"] } // TODO: should we support routes here? how?
|
|
115
|
-
: { workers_dev: true };
|
|
116
|
-
|
|
117
|
-
const formData = toFormData(worker);
|
|
118
|
-
formData.set("wrangler-session-config", JSON.stringify(mode));
|
|
119
|
-
|
|
120
|
-
const { preview_token } = await fetchResult<{ preview_token: string }>(url, {
|
|
121
|
-
method: "POST",
|
|
122
|
-
body: formData,
|
|
123
|
-
headers: {
|
|
124
|
-
"cf-preview-upload-config-token": value,
|
|
125
|
-
},
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
return {
|
|
129
|
-
value: preview_token,
|
|
130
|
-
host: ctx.zone
|
|
131
|
-
? ctx.zone.host
|
|
132
|
-
: worker.name
|
|
133
|
-
? `${
|
|
134
|
-
worker.name
|
|
135
|
-
// TODO: this should also probably have the env prefix
|
|
136
|
-
// but it doesn't appear to work yet, instead giving us the
|
|
137
|
-
// "There is nothing here yet" screen
|
|
138
|
-
// ctx.env && !ctx.legacyEnv
|
|
139
|
-
// ? `${ctx.env}.${worker.name}`
|
|
140
|
-
// : worker.name
|
|
141
|
-
}.${host.split(".").slice(1).join(".")}`
|
|
142
|
-
: host,
|
|
143
|
-
|
|
144
|
-
inspectorUrl,
|
|
145
|
-
prewarmUrl,
|
|
146
|
-
};
|
|
147
|
-
}
|
package/src/api/worker.ts
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { fetch } from "undici";
|
|
2
|
-
import { previewToken } from "./preview";
|
|
3
|
-
import type { CfPreviewToken } from "./preview";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* A Cloudflare account.
|
|
7
|
-
*/
|
|
8
|
-
export interface CfAccount {
|
|
9
|
-
/**
|
|
10
|
-
* An API token.
|
|
11
|
-
*
|
|
12
|
-
* @link https://api.cloudflare.com/#user-api-tokens-properties
|
|
13
|
-
*/
|
|
14
|
-
apiToken: string;
|
|
15
|
-
/**
|
|
16
|
-
* An account ID.
|
|
17
|
-
*/
|
|
18
|
-
accountId: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* The type of Worker
|
|
23
|
-
*/
|
|
24
|
-
export type CfScriptFormat = "modules" | "service-worker";
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* A module type.
|
|
28
|
-
*/
|
|
29
|
-
export type CfModuleType =
|
|
30
|
-
| "esm"
|
|
31
|
-
| "commonjs"
|
|
32
|
-
| "compiled-wasm"
|
|
33
|
-
| "text"
|
|
34
|
-
| "buffer";
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* An imported module.
|
|
38
|
-
*/
|
|
39
|
-
export interface CfModule {
|
|
40
|
-
/**
|
|
41
|
-
* The module name.
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* './src/index.js'
|
|
45
|
-
*/
|
|
46
|
-
name: string;
|
|
47
|
-
/**
|
|
48
|
-
* The module content, usually JavaScript or WASM code.
|
|
49
|
-
*
|
|
50
|
-
* @example
|
|
51
|
-
* export default {
|
|
52
|
-
* async fetch(request) {
|
|
53
|
-
* return new Response('Ok')
|
|
54
|
-
* }
|
|
55
|
-
* }
|
|
56
|
-
*/
|
|
57
|
-
content: string | Buffer;
|
|
58
|
-
/**
|
|
59
|
-
* The module type.
|
|
60
|
-
*
|
|
61
|
-
* If absent, will default to the main module's type.
|
|
62
|
-
*/
|
|
63
|
-
type?: CfModuleType;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* A map of variable names to values.
|
|
68
|
-
*/
|
|
69
|
-
interface CfVars {
|
|
70
|
-
[key: string]: unknown;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* A KV namespace.
|
|
75
|
-
*/
|
|
76
|
-
interface CfKvNamespace {
|
|
77
|
-
binding: string;
|
|
78
|
-
id: string;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* A binding to a wasm module (in service worker format)
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
interface CfWasmModuleBindings {
|
|
86
|
-
[key: string]: string;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* A binding to a text blob (in service worker format)
|
|
91
|
-
*/
|
|
92
|
-
|
|
93
|
-
interface CfTextBlobBindings {
|
|
94
|
-
[key: string]: string;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* A Durable Object.
|
|
99
|
-
*/
|
|
100
|
-
interface CfDurableObject {
|
|
101
|
-
name: string;
|
|
102
|
-
class_name: string;
|
|
103
|
-
script_name?: string;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
interface CfR2Bucket {
|
|
107
|
-
binding: string;
|
|
108
|
-
bucket_name: string;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
interface CfUnsafeBinding {
|
|
112
|
-
name: string;
|
|
113
|
-
type: string;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export interface CfDurableObjectMigrations {
|
|
117
|
-
old_tag?: string;
|
|
118
|
-
new_tag: string;
|
|
119
|
-
steps: {
|
|
120
|
-
new_classes?: string[];
|
|
121
|
-
renamed_classes?: {
|
|
122
|
-
from: string;
|
|
123
|
-
to: string;
|
|
124
|
-
}[];
|
|
125
|
-
deleted_classes?: string[];
|
|
126
|
-
}[];
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Options for creating a `CfWorker`.
|
|
131
|
-
*/
|
|
132
|
-
export interface CfWorkerInit {
|
|
133
|
-
/**
|
|
134
|
-
* The name of the worker.
|
|
135
|
-
*/
|
|
136
|
-
name: string | undefined;
|
|
137
|
-
/**
|
|
138
|
-
* The entrypoint module.
|
|
139
|
-
*/
|
|
140
|
-
main: CfModule;
|
|
141
|
-
/**
|
|
142
|
-
* The list of additional modules.
|
|
143
|
-
*/
|
|
144
|
-
modules: undefined | CfModule[];
|
|
145
|
-
/**
|
|
146
|
-
* All the bindings
|
|
147
|
-
*/
|
|
148
|
-
bindings: {
|
|
149
|
-
vars: CfVars | undefined;
|
|
150
|
-
kv_namespaces: CfKvNamespace[] | undefined;
|
|
151
|
-
wasm_modules: CfWasmModuleBindings | undefined;
|
|
152
|
-
text_blobs: CfTextBlobBindings | undefined;
|
|
153
|
-
durable_objects: { bindings: CfDurableObject[] } | undefined;
|
|
154
|
-
r2_buckets: CfR2Bucket[] | undefined;
|
|
155
|
-
unsafe: CfUnsafeBinding[] | undefined;
|
|
156
|
-
};
|
|
157
|
-
migrations: undefined | CfDurableObjectMigrations;
|
|
158
|
-
compatibility_date: string | undefined;
|
|
159
|
-
compatibility_flags: undefined | string[];
|
|
160
|
-
usage_model: undefined | "bundled" | "unbound";
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export interface CfWorkerContext {
|
|
164
|
-
env: string | undefined;
|
|
165
|
-
legacyEnv: boolean | undefined;
|
|
166
|
-
zone: { id: string; host: string } | undefined;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* A stub to create a Cloudflare Worker preview.
|
|
171
|
-
*
|
|
172
|
-
* @example
|
|
173
|
-
* const {value, host} = await createWorker(init, acct);
|
|
174
|
-
*/
|
|
175
|
-
export async function createWorker(
|
|
176
|
-
init: CfWorkerInit,
|
|
177
|
-
account: CfAccount,
|
|
178
|
-
ctx: CfWorkerContext
|
|
179
|
-
): Promise<CfPreviewToken> {
|
|
180
|
-
const token = await previewToken(account, init, ctx);
|
|
181
|
-
const response = await fetch(token.prewarmUrl.href, { method: "POST" });
|
|
182
|
-
if (!response.ok) {
|
|
183
|
-
// console.error("worker failed to prewarm: ", response.statusText);
|
|
184
|
-
}
|
|
185
|
-
return token;
|
|
186
|
-
}
|
package/src/dialogs.tsx
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { Box, Text, useInput, render } from "ink";
|
|
2
|
-
import TextInput from "ink-text-input";
|
|
3
|
-
import * as React from "react";
|
|
4
|
-
import { useState } from "react";
|
|
5
|
-
type ConfirmProps = {
|
|
6
|
-
text: string;
|
|
7
|
-
onConfirm: (answer: boolean) => void;
|
|
8
|
-
};
|
|
9
|
-
function Confirm(props: ConfirmProps) {
|
|
10
|
-
useInput((input: string) => {
|
|
11
|
-
if (input === "y") {
|
|
12
|
-
props.onConfirm(true);
|
|
13
|
-
} else if (input === "n") {
|
|
14
|
-
props.onConfirm(false);
|
|
15
|
-
} else {
|
|
16
|
-
console.log("Unrecognised input");
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
return (
|
|
20
|
-
<Box>
|
|
21
|
-
<Text>{props.text} (y/n) </Text>
|
|
22
|
-
</Box>
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function confirm(text: string): Promise<boolean> {
|
|
27
|
-
return new Promise((resolve) => {
|
|
28
|
-
const { unmount } = render(
|
|
29
|
-
<Confirm
|
|
30
|
-
text={text}
|
|
31
|
-
onConfirm={(answer: boolean) => {
|
|
32
|
-
unmount();
|
|
33
|
-
resolve(answer);
|
|
34
|
-
}}
|
|
35
|
-
/>
|
|
36
|
-
);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
type PromptProps = {
|
|
41
|
-
text: string;
|
|
42
|
-
type?: "text" | "password";
|
|
43
|
-
onSubmit: (text: string) => void;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
function Prompt(props: PromptProps) {
|
|
47
|
-
const [value, setValue] = useState("");
|
|
48
|
-
|
|
49
|
-
return (
|
|
50
|
-
<Box>
|
|
51
|
-
<Text>{props.text} </Text>
|
|
52
|
-
<Box>
|
|
53
|
-
<TextInput
|
|
54
|
-
mask={props.type === "password" ? "*" : undefined}
|
|
55
|
-
value={value}
|
|
56
|
-
onChange={setValue}
|
|
57
|
-
onSubmit={props.onSubmit}
|
|
58
|
-
/>
|
|
59
|
-
</Box>
|
|
60
|
-
</Box>
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export async function prompt(text: string, type: "text" | "password" = "text") {
|
|
65
|
-
return new Promise((resolve) => {
|
|
66
|
-
const { unmount } = render(
|
|
67
|
-
<Prompt
|
|
68
|
-
text={text}
|
|
69
|
-
type={type}
|
|
70
|
-
onSubmit={(inputText) => {
|
|
71
|
-
unmount();
|
|
72
|
-
resolve(inputText);
|
|
73
|
-
}}
|
|
74
|
-
/>
|
|
75
|
-
);
|
|
76
|
-
});
|
|
77
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Create a function used to access an environment variable.
|
|
3
|
-
*
|
|
4
|
-
* This is not memoized to allow us to change the value at runtime, such as in testing.
|
|
5
|
-
* A warning is shown if the client is using a deprecated version - but only once.
|
|
6
|
-
*/
|
|
7
|
-
export function getEnvironmentVariableFactory({
|
|
8
|
-
variableName,
|
|
9
|
-
deprecatedName,
|
|
10
|
-
defaultValue,
|
|
11
|
-
}: {
|
|
12
|
-
variableName: string;
|
|
13
|
-
deprecatedName?: string;
|
|
14
|
-
defaultValue?: string;
|
|
15
|
-
}) {
|
|
16
|
-
let hasWarned = false;
|
|
17
|
-
return () => {
|
|
18
|
-
if (process.env[variableName]) {
|
|
19
|
-
return process.env[variableName];
|
|
20
|
-
} else if (deprecatedName && process.env[deprecatedName]) {
|
|
21
|
-
if (!hasWarned) {
|
|
22
|
-
// Only show the warning once.
|
|
23
|
-
hasWarned = true;
|
|
24
|
-
console.warn(
|
|
25
|
-
`Using "${deprecatedName}" environment variable. This is deprecated. Please use "${variableName}", instead.`
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
return process.env[deprecatedName];
|
|
29
|
-
} else {
|
|
30
|
-
return defaultValue;
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
}
|