devflare 1.0.0-next.39 → 1.0.0-next.40
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/dist/_chunks/account-BtWcv3X9.js +462 -0
- package/dist/_chunks/account-resources-CsmVowJp.js +159 -0
- package/dist/_chunks/ai-CBEuLdoP.js +322 -0
- package/dist/_chunks/api-TzdliH-6.js +568 -0
- package/dist/_chunks/build-3T6O4uIg.js +24 -0
- package/dist/_chunks/build-artifacts-8TqBSQkG.js +483 -0
- package/dist/_chunks/cli-BTF1X4SG.js +1128 -0
- package/dist/_chunks/cloudflare-BaloqI3H.js +157 -0
- package/dist/_chunks/colors-DiK6wPJ5.js +13 -0
- package/dist/_chunks/command-utils-BsfkmTqh.js +45 -0
- package/dist/_chunks/compiler-uoyAQ8zW.js +424 -0
- package/dist/_chunks/config-D5u-bEkn.js +78 -0
- package/dist/_chunks/config-path-DCPto4XB.js +42 -0
- package/dist/_chunks/context-CX50Y2Kb.js +2250 -0
- package/dist/_chunks/decorators-QmV57ixr.js +19 -0
- package/dist/_chunks/dependencies-C2oxFjU_.js +57 -0
- package/dist/_chunks/deploy-DMTr6JeR.js +915 -0
- package/dist/_chunks/dev-CvRHmRFZ.js +3456 -0
- package/dist/_chunks/doctor-DIG8DoFU.js +219 -0
- package/dist/_chunks/durable-object-DMtH0XYX.js +234 -0
- package/dist/_chunks/env-S0_nMVz1.js +125 -0
- package/dist/_chunks/family-DXC5SdFK.js +143 -0
- package/dist/_chunks/generated-artifacts-dMJY4KAt.js +32 -0
- package/dist/_chunks/glob-CmQOvunB.js +56 -0
- package/dist/_chunks/init-3moXTgpb.js +165 -0
- package/dist/_chunks/loader-DLXO60RO.js +1153 -0
- package/dist/_chunks/local-dev-vars-CTSa-wvF.js +81 -0
- package/dist/_chunks/local-hyperdrive-CJ90j46O.js +119 -0
- package/dist/_chunks/local-media-bindings-DsAW4AMF.js +335 -0
- package/dist/_chunks/local-secrets-DMmEOygL.js +123 -0
- package/dist/_chunks/local-workflow-entrypoints-Wip3o1u8.js +90 -0
- package/dist/_chunks/login-BmnDzDlH.js +51 -0
- package/dist/_chunks/package-metadata-DAuCkyvK.js +39 -0
- package/dist/_chunks/preferences-BKp_7XJx.js +241 -0
- package/dist/_chunks/preview-BhqDmq8I.js +456 -0
- package/dist/_chunks/preview-registry-ClAbLTHH.js +1186 -0
- package/dist/_chunks/preview-resources-DdXj8LMM.js +358 -0
- package/dist/_chunks/previews-Dlr13x5M.js +1134 -0
- package/dist/_chunks/productions-D3AnOHac.js +411 -0
- package/dist/_chunks/ref-CYJNAAe_.js +178 -0
- package/dist/_chunks/remote-CZnP-HLJ.js +79 -0
- package/dist/_chunks/remote-config-D39BY9ji.js +132 -0
- package/dist/_chunks/resolve-package-Y84HB3Nt.js +133 -0
- package/dist/_chunks/rolldown-runtime-CvQ6eiug.js +14 -0
- package/dist/_chunks/routes-C3FqES2W.js +796 -0
- package/dist/_chunks/runtime-FvXvfuZ2.js +550 -0
- package/dist/_chunks/schema-normalization-DWVleVxo.js +477 -0
- package/dist/_chunks/secrets-70eN0Q6C.js +95 -0
- package/dist/_chunks/token-kguIDmej.js +333 -0
- package/dist/_chunks/tokens-iVcgNXi-.js +221 -0
- package/dist/_chunks/types-OrLbzv4I.js +476 -0
- package/dist/_chunks/ui-BUoZApvE.js +103 -0
- package/dist/_chunks/usage-BBTGzjon.js +272 -0
- package/dist/_chunks/vite-CsI0E-uV.js +1235 -0
- package/dist/_chunks/vite-utils-OVLMV605.js +183 -0
- package/dist/_chunks/worker-CS1jgNFE.js +410 -0
- package/dist/_chunks/worker-bundler-dTTnYU3n.js +458 -0
- package/dist/_chunks/worker-entrypoint-CQW77lG8.js +247 -0
- package/dist/_chunks/workerName-CFJsLZA-.js +23 -0
- package/dist/bridge/index.d.ts +6 -6
- package/dist/bridge/miniflare.d.ts +2 -2
- package/dist/bridge/proxy.d.ts +1 -1
- package/dist/bridge/v2/body-streams.d.ts +1 -1
- package/dist/bridge/v2/codec.d.ts +4 -4
- package/dist/bridge/v2/index.d.ts +10 -10
- package/dist/bridge/v2/serialization.d.ts +1 -1
- package/dist/bridge/v2/value-codec.d.ts +1 -1
- package/dist/bridge/v2/value-serialization.d.ts.map +1 -1
- package/dist/bridge/v2/ws-relay.d.ts +3 -3
- package/dist/browser-shim/index.d.ts +2 -2
- package/dist/browser.d.ts +70 -70
- package/dist/browser.js +74 -2462
- package/dist/bundler/do-bundler.d.ts +1 -1
- package/dist/bundler/index.d.ts +3 -3
- package/dist/bundler/rolldown-shared.d.ts +1 -1
- package/dist/bundler/worker-bundler.d.ts +1 -1
- package/dist/cli/build-manifest.d.ts +1 -1
- package/dist/cli/command-utils.d.ts +1 -1
- package/dist/cli/commands/account.d.ts +1 -1
- package/dist/cli/commands/ai.d.ts +1 -1
- package/dist/cli/commands/build-artifacts.d.ts +5 -5
- package/dist/cli/commands/build.d.ts +1 -1
- package/dist/cli/commands/config.d.ts +1 -1
- package/dist/cli/commands/deploy/prepare.d.ts +2 -2
- package/dist/cli/commands/deploy/runtime.d.ts +1 -1
- package/dist/cli/commands/deploy/verification.d.ts +1 -1
- package/dist/cli/commands/deploy.d.ts +1 -1
- package/dist/cli/commands/dev.d.ts +1 -1
- package/dist/cli/commands/doctor.d.ts +1 -1
- package/dist/cli/commands/init.d.ts +1 -1
- package/dist/cli/commands/login.d.ts +1 -1
- package/dist/cli/commands/previews-support/cleanup.d.ts +1 -1
- package/dist/cli/commands/previews-support/family.d.ts +3 -3
- package/dist/cli/commands/previews-support/render.d.ts +3 -3
- package/dist/cli/commands/previews-support/theme.d.ts +2 -2
- package/dist/cli/commands/previews-support/types.d.ts +2 -2
- package/dist/cli/commands/previews.d.ts +1 -1
- package/dist/cli/commands/productions.d.ts +1 -1
- package/dist/cli/commands/remote.d.ts +1 -1
- package/dist/cli/commands/secrets.d.ts +1 -1
- package/dist/cli/commands/token.d.ts +1 -1
- package/dist/cli/commands/type-generation/discovery.d.ts +2 -2
- package/dist/cli/commands/type-generation/generator.d.ts +3 -3
- package/dist/cli/commands/type-generation/models.d.ts +1 -1
- package/dist/cli/commands/types.d.ts +1 -1
- package/dist/cli/commands/worker.d.ts +1 -1
- package/dist/cli/deploy-strategy.d.ts +1 -1
- package/dist/cli/deploy-target.d.ts +1 -1
- package/dist/cli/help-pages/pages/account.d.ts +1 -1
- package/dist/cli/help-pages/pages/core.d.ts +1 -1
- package/dist/cli/help-pages/pages/index.d.ts +1 -1
- package/dist/cli/help-pages/pages/misc.d.ts +1 -1
- package/dist/cli/help-pages/pages/previews.d.ts +1 -1
- package/dist/cli/help-pages/pages/productions.d.ts +1 -1
- package/dist/cli/help-pages/render.d.ts +2 -2
- package/dist/cli/help-pages/shared.d.ts +1 -1
- package/dist/cli/help.d.ts +2 -2
- package/dist/cli/index.js +2 -1383
- package/dist/cli/preview-bindings.d.ts +3 -3
- package/dist/cli/preview.d.ts +1 -1
- package/dist/cli/wrangler-auth.d.ts +1 -1
- package/dist/cloudflare/account-core.d.ts +2 -2
- package/dist/cloudflare/account-resources.d.ts +2 -2
- package/dist/cloudflare/account-status.d.ts +1 -1
- package/dist/cloudflare/account-workers.d.ts +2 -2
- package/dist/cloudflare/account.d.ts +7 -7
- package/dist/cloudflare/auth.d.ts +1 -1
- package/dist/cloudflare/index.d.ts +13 -13
- package/dist/cloudflare/index.js +4 -59
- package/dist/cloudflare/kv-namespace.d.ts +1 -1
- package/dist/cloudflare/preview-registry-cache.d.ts +1 -1
- package/dist/cloudflare/preview-registry-inference.d.ts +2 -2
- package/dist/cloudflare/preview-registry-records.d.ts +3 -3
- package/dist/cloudflare/preview-registry-shape.d.ts +2 -2
- package/dist/cloudflare/preview-registry-store.d.ts +3 -3
- package/dist/cloudflare/preview-registry-transport.d.ts +2 -2
- package/dist/cloudflare/preview-registry-types.d.ts +2 -2
- package/dist/cloudflare/preview-registry.d.ts +5 -5
- package/dist/cloudflare/tokens.d.ts +2 -2
- package/dist/cloudflare/usage.d.ts +2 -2
- package/dist/config/binding-resolution-helpers.d.ts +1 -1
- package/dist/config/compiler/bindings.d.ts +2 -2
- package/dist/config/compiler/core-helpers.d.ts +2 -2
- package/dist/config/compiler/do-workers.d.ts +2 -2
- package/dist/config/compiler/paths.d.ts +1 -1
- package/dist/config/compiler.d.ts +6 -6
- package/dist/config/define.d.ts +2 -2
- package/dist/config/deploy-resources.d.ts +5 -5
- package/dist/config/env-vars.d.ts +1 -1
- package/dist/config/framework-providers.d.ts +1 -1
- package/dist/config/index.d.ts +12 -12
- package/dist/config/loader.d.ts +2 -2
- package/dist/config/local-dev-vars.d.ts +1 -1
- package/dist/config/preview-resources.d.ts +4 -4
- package/dist/config/preview.d.ts +1 -1
- package/dist/config/ref.d.ts +2 -2
- package/dist/config/resolve-phased.d.ts +4 -4
- package/dist/config/resolve.d.ts +1 -1
- package/dist/config/resource-resolution.d.ts +6 -6
- package/dist/config/schema-env.d.ts +20 -20
- package/dist/config/schema-normalization.d.ts +1 -1
- package/dist/config/schema-types-bindings.d.ts +4 -4
- package/dist/config/schema-types-build.d.ts +1 -1
- package/dist/config/schema-types.d.ts +7 -7
- package/dist/config/schema.d.ts +46 -46
- package/dist/config/service-bindings-validation.d.ts +1 -1
- package/dist/config-entry.d.ts +6 -6
- package/dist/config-entry.js +3 -8
- package/dist/decorators/index.d.ts +2 -2
- package/dist/decorators/index.js +2 -9
- package/dist/dev-server/d1-migrations.d.ts +1 -1
- package/dist/dev-server/dev-server-state.d.ts +6 -6
- package/dist/dev-server/gateway-script.d.ts +1 -1
- package/dist/dev-server/index.d.ts +1 -1
- package/dist/dev-server/miniflare-bindings.d.ts +1 -1
- package/dist/dev-server/miniflare-dev-config.d.ts +5 -5
- package/dist/dev-server/miniflare-worker-config.d.ts +3 -3
- package/dist/dev-server/server-startup-helpers.d.ts +6 -6
- package/dist/dev-server/worker-surface-paths.d.ts +2 -2
- package/dist/index.d.ts +8 -8
- package/dist/index.js +9 -22
- package/dist/runtime/context-events.d.ts +1 -1
- package/dist/runtime/context.d.ts +3 -3
- package/dist/runtime/exports.d.ts +2 -2
- package/dist/runtime/index.d.ts +10 -10
- package/dist/runtime/index.js +5 -57
- package/dist/runtime/middleware.d.ts +1 -1
- package/dist/runtime/router/index.d.ts +3 -3
- package/dist/runtime/validation.d.ts +1 -1
- package/dist/secrets/local-secrets.d.ts +1 -1
- package/dist/shims/local-media-bindings.d.ts +1 -1
- package/dist/sveltekit/index.d.ts +1 -1
- package/dist/sveltekit/index.js +327 -9
- package/dist/sveltekit/local-bindings.d.ts +1 -1
- package/dist/sveltekit/platform.d.ts +1 -1
- package/dist/test/binding-hints.d.ts +2 -2
- package/dist/test/cf.d.ts +19 -19
- package/dist/test/index.d.ts +18 -18
- package/dist/test/index.js +4495 -46
- package/dist/test/offline-bindings.d.ts +3 -3
- package/dist/test/resolve-service-bindings.d.ts +1 -1
- package/dist/test/simple-context-bindings.d.ts +1 -1
- package/dist/test/simple-context-durable-objects.d.ts +1 -1
- package/dist/test/simple-context-env.d.ts +2 -2
- package/dist/test/simple-context-handlers.d.ts +2 -2
- package/dist/test/simple-context-lifecycle.d.ts +2 -2
- package/dist/test/simple-context-mfconfig.d.ts +1 -1
- package/dist/test/simple-context-multi-worker.d.ts +2 -2
- package/dist/test/simple-context-runtime.d.ts +1 -1
- package/dist/test/simple-context-startup.d.ts +1 -1
- package/dist/test/simple-context.d.ts +1 -1
- package/dist/test/utilities/env.d.ts +3 -3
- package/dist/test/utilities.d.ts +10 -10
- package/dist/test/worker.d.ts +1 -1
- package/dist/transform/index.d.ts +2 -2
- package/dist/utils/send-email.js +163 -19
- package/dist/vite/config-file.d.ts +2 -2
- package/dist/vite/index.d.ts +3 -3
- package/dist/vite/index.js +2 -31
- package/dist/vite/plugin-config-hook.d.ts +1 -1
- package/dist/vite/plugin-context.d.ts +3 -3
- package/dist/vite/plugin-durable-objects.d.ts +2 -2
- package/dist/vite/plugin-programmatic.d.ts +1 -1
- package/dist/vite/plugin-service-bindings.d.ts +2 -2
- package/dist/vite/plugin.d.ts +3 -3
- package/dist/worker-entry/composed-worker.d.ts +1 -1
- package/dist/worker-entry/routes.d.ts +2 -2
- package/dist/worker-entry/surface-paths.d.ts +1 -1
- package/dist/workflows/local-workflow-entrypoints.d.ts +1 -1
- package/package.json +5 -3
- package/dist/account-4tgh03a8.js +0 -484
- package/dist/ai-r3zqmxan.js +0 -261
- package/dist/api-6z01z734.js +0 -33
- package/dist/build-kw625v84.js +0 -51
- package/dist/config-ghk2bxj3.js +0 -102
- package/dist/deploy-9kee65n9.js +0 -1062
- package/dist/dev-x8zr249a.js +0 -3569
- package/dist/doctor-0ng5qrr1.js +0 -258
- package/dist/durable-object-0ybmg08a.js +0 -13
- package/dist/index-04wh9bxx.js +0 -514
- package/dist/index-0cc05hzv.js +0 -74
- package/dist/index-2yv7w548.js +0 -185
- package/dist/index-37x76zdn.js +0 -4
- package/dist/index-3cpzsr47.js +0 -125
- package/dist/index-3t6rypgc.js +0 -13
- package/dist/index-4mmpccrb.js +0 -309
- package/dist/index-5dkjffqz.js +0 -25
- package/dist/index-5hy7jmv3.js +0 -890
- package/dist/index-627srx16.js +0 -45
- package/dist/index-7m557715.js +0 -283
- package/dist/index-a8pnvg3r.js +0 -52
- package/dist/index-aabgympv.js +0 -39
- package/dist/index-atwc3csp.js +0 -256
- package/dist/index-cv4cvrxe.js +0 -2046
- package/dist/index-h7r11y4a.js +0 -539
- package/dist/index-hvtd936d.js +0 -1229
- package/dist/index-kcp7y951.js +0 -136
- package/dist/index-maw0jjnn.js +0 -147
- package/dist/index-mek9msfv.js +0 -705
- package/dist/index-n4xkaymm.js +0 -236
- package/dist/index-nkk59p3y.js +0 -579
- package/dist/index-phcrvs6d.js +0 -342
- package/dist/index-se4kw8tm.js +0 -460
- package/dist/index-x8s9rwfh.js +0 -2020
- package/dist/index-y7w3x9p1.js +0 -18
- package/dist/index-z9gy8w6b.js +0 -57
- package/dist/index-zdd0d9qa.js +0 -199
- package/dist/init-tb8jqgvr.js +0 -180
- package/dist/login-4h1sfsed.js +0 -75
- package/dist/previews-qr7c5j8h.js +0 -1336
- package/dist/productions-xpmd6bw8.js +0 -505
- package/dist/remote-kqcvhnfx.js +0 -192
- package/dist/secrets-6wbdsdek.js +0 -89
- package/dist/token-yp1qa70y.js +0 -419
- package/dist/types-15yv4cj3.js +0 -701
- package/dist/worker-1yg72jxg.js +0 -510
- package/dist/worker-entrypoint-y8s9kdcx.js +0 -15
|
@@ -1,505 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
collectConfiguredWorkerFamilies
|
|
3
|
-
} from "./index-2yv7w548.js";
|
|
4
|
-
import {
|
|
5
|
-
asOptionalString,
|
|
6
|
-
resolveCloudflareAccountId,
|
|
7
|
-
resolveNamedSelection
|
|
8
|
-
} from "./index-0cc05hzv.js";
|
|
9
|
-
import {
|
|
10
|
-
account
|
|
11
|
-
} from "./index-phcrvs6d.js";
|
|
12
|
-
import"./index-atwc3csp.js";
|
|
13
|
-
import"./index-hvtd936d.js";
|
|
14
|
-
import {
|
|
15
|
-
getDependencies
|
|
16
|
-
} from "./index-z9gy8w6b.js";
|
|
17
|
-
import {
|
|
18
|
-
bold,
|
|
19
|
-
createCliTheme,
|
|
20
|
-
cyanBold,
|
|
21
|
-
dim,
|
|
22
|
-
formatLabelValue,
|
|
23
|
-
green,
|
|
24
|
-
logLine,
|
|
25
|
-
logTable,
|
|
26
|
-
red,
|
|
27
|
-
whiteDim,
|
|
28
|
-
yellow
|
|
29
|
-
} from "./index-maw0jjnn.js";
|
|
30
|
-
import"./index-3t6rypgc.js";
|
|
31
|
-
import {
|
|
32
|
-
findFiles
|
|
33
|
-
} from "./index-5dkjffqz.js";
|
|
34
|
-
import"./index-mek9msfv.js";
|
|
35
|
-
import {
|
|
36
|
-
ConfigNotFoundError,
|
|
37
|
-
loadConfig
|
|
38
|
-
} from "./index-x8s9rwfh.js";
|
|
39
|
-
import"./index-h7r11y4a.js";
|
|
40
|
-
import"./index-04wh9bxx.js";
|
|
41
|
-
import"./index-37x76zdn.js";
|
|
42
|
-
|
|
43
|
-
// src/cli/commands/productions.ts
|
|
44
|
-
var CLI_API_OPTIONS = { timeout: 1e4 };
|
|
45
|
-
var PRODUCTION_SUBCOMMANDS = ["list", "versions", "rollback", "delete"];
|
|
46
|
-
var VERSION_LIST_LIMIT = 10;
|
|
47
|
-
function isProductionSubcommand(value) {
|
|
48
|
-
return PRODUCTION_SUBCOMMANDS.includes(value);
|
|
49
|
-
}
|
|
50
|
-
function shortenVersionId(versionId, length = 12) {
|
|
51
|
-
return versionId.length <= length ? versionId : `${versionId.slice(0, length)}…`;
|
|
52
|
-
}
|
|
53
|
-
function selectDeploymentVersionId(deployment) {
|
|
54
|
-
return deployment.versions.find((version) => version.percentage === 100)?.versionId ?? deployment.versions[0]?.versionId;
|
|
55
|
-
}
|
|
56
|
-
function getWorkerVersionTimestamp(version) {
|
|
57
|
-
return version.metadata.modifiedOn ?? version.metadata.createdOn;
|
|
58
|
-
}
|
|
59
|
-
function formatRecordDate(date) {
|
|
60
|
-
return date ? date.toISOString().slice(0, 19).replace("T", " ") : "N/A";
|
|
61
|
-
}
|
|
62
|
-
function formatWorkerStatus(status, theme) {
|
|
63
|
-
switch (status) {
|
|
64
|
-
case "active":
|
|
65
|
-
return green(status, theme);
|
|
66
|
-
case "undeployed":
|
|
67
|
-
return yellow(status, theme);
|
|
68
|
-
default:
|
|
69
|
-
return red(status, theme);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
function formatVersionStatus(status, theme) {
|
|
73
|
-
switch (status) {
|
|
74
|
-
case "active":
|
|
75
|
-
return green(status, theme);
|
|
76
|
-
default:
|
|
77
|
-
return whiteDim(status, theme);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
function shouldReplaceConfiguredWorkerFamily(existing, candidate) {
|
|
81
|
-
return !existing || candidate.role === "primary" && existing.role !== "primary";
|
|
82
|
-
}
|
|
83
|
-
function mergeConfiguredWorkerFamily(families, candidate) {
|
|
84
|
-
if (shouldReplaceConfiguredWorkerFamily(families.get(candidate.baseName), candidate)) {
|
|
85
|
-
families.set(candidate.baseName, candidate);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
async function discoverProductionConfigs(cwd, configFile, environment) {
|
|
89
|
-
const families = new Map;
|
|
90
|
-
const primaryFamilyNames = new Set;
|
|
91
|
-
const accountIds = new Set;
|
|
92
|
-
let defaultWorkerName;
|
|
93
|
-
let defaultWorkerNameSource = "none";
|
|
94
|
-
const loadAndCollect = async (candidateConfigFile) => {
|
|
95
|
-
try {
|
|
96
|
-
const config = await loadConfig({ cwd, configFile: candidateConfigFile });
|
|
97
|
-
const resolvedFamilies = collectConfiguredWorkerFamilies(config, environment);
|
|
98
|
-
for (const family of resolvedFamilies) {
|
|
99
|
-
mergeConfiguredWorkerFamily(families, family);
|
|
100
|
-
if (family.role === "primary") {
|
|
101
|
-
primaryFamilyNames.add(family.baseName);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
if (config.accountId?.trim()) {
|
|
105
|
-
accountIds.add(config.accountId.trim());
|
|
106
|
-
}
|
|
107
|
-
if (!defaultWorkerName) {
|
|
108
|
-
defaultWorkerName = resolvedFamilies.find((family) => family.role === "primary")?.baseName;
|
|
109
|
-
defaultWorkerNameSource = defaultWorkerName ? "config" : "none";
|
|
110
|
-
}
|
|
111
|
-
return true;
|
|
112
|
-
} catch (error) {
|
|
113
|
-
if (error instanceof ConfigNotFoundError) {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
throw error;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
if (configFile) {
|
|
120
|
-
await loadAndCollect(configFile);
|
|
121
|
-
} else {
|
|
122
|
-
const loadedDirectly = await loadAndCollect();
|
|
123
|
-
if (!loadedDirectly) {
|
|
124
|
-
const configPaths = (await findFiles("**/devflare.config.{ts,js,mjs,cjs}", {
|
|
125
|
-
cwd,
|
|
126
|
-
absolute: true
|
|
127
|
-
})).sort((left, right) => left.localeCompare(right));
|
|
128
|
-
for (const configPath of configPaths) {
|
|
129
|
-
await loadAndCollect(configPath);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (accountIds.size > 1) {
|
|
134
|
-
throw new Error("Multiple Cloudflare account ids were discovered across local Devflare configs. Pass --account to select one account explicitly for `devflare productions`.");
|
|
135
|
-
}
|
|
136
|
-
return {
|
|
137
|
-
accountId: Array.from(accountIds)[0],
|
|
138
|
-
defaultWorkerName,
|
|
139
|
-
defaultWorkerNameSource,
|
|
140
|
-
families: Array.from(families.values()).sort((left, right) => {
|
|
141
|
-
if (left.role === "primary" && right.role !== "primary") {
|
|
142
|
-
return -1;
|
|
143
|
-
}
|
|
144
|
-
if (left.role !== "primary" && right.role === "primary") {
|
|
145
|
-
return 1;
|
|
146
|
-
}
|
|
147
|
-
return left.baseName.localeCompare(right.baseName);
|
|
148
|
-
}),
|
|
149
|
-
primaryFamilyNames: Array.from(primaryFamilyNames).sort((left, right) => left.localeCompare(right))
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
async function resolveAccountId(parsed, discovery) {
|
|
153
|
-
return resolveCloudflareAccountId({
|
|
154
|
-
explicitAccountId: asOptionalString(parsed.options.account),
|
|
155
|
-
configuredAccountId: discovery.accountId,
|
|
156
|
-
apiOptions: CLI_API_OPTIONS
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
function resolveWorkerName(parsed, discovery, fallbackArg) {
|
|
160
|
-
const selection = resolveNamedSelection({
|
|
161
|
-
explicitValue: asOptionalString(parsed.options.worker),
|
|
162
|
-
fallbackValue: fallbackArg,
|
|
163
|
-
configuredValue: discovery.defaultWorkerName
|
|
164
|
-
});
|
|
165
|
-
return {
|
|
166
|
-
workerName: selection.value,
|
|
167
|
-
source: selection.value === discovery.defaultWorkerName ? discovery.defaultWorkerNameSource : selection.source
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
async function resolveContext(parsed, options, subcommand, fallbackArg) {
|
|
171
|
-
const cwd = options.cwd ?? process.cwd();
|
|
172
|
-
const configFile = asOptionalString(parsed.options.config);
|
|
173
|
-
const environment = asOptionalString(parsed.options.env) ?? "production";
|
|
174
|
-
const explicitAccountId = asOptionalString(parsed.options.account);
|
|
175
|
-
const explicitWorkerName = asOptionalString(parsed.options.worker) ?? fallbackArg;
|
|
176
|
-
const shouldDiscoverConfigs = Boolean(configFile) || !explicitAccountId || !explicitWorkerName;
|
|
177
|
-
const discovery = shouldDiscoverConfigs ? await discoverProductionConfigs(cwd, configFile, environment) : {
|
|
178
|
-
accountId: undefined,
|
|
179
|
-
defaultWorkerName: undefined,
|
|
180
|
-
defaultWorkerNameSource: "none",
|
|
181
|
-
families: [],
|
|
182
|
-
primaryFamilyNames: []
|
|
183
|
-
};
|
|
184
|
-
const accountId = await resolveAccountId(parsed, discovery);
|
|
185
|
-
const workerSelection = resolveWorkerName(parsed, discovery, fallbackArg);
|
|
186
|
-
if (!accountId) {
|
|
187
|
-
throw new Error("No Cloudflare account could be resolved. Use --account or configure accountId in devflare.config.*.");
|
|
188
|
-
}
|
|
189
|
-
if ((subcommand === "rollback" || subcommand === "delete") && !workerSelection.workerName) {
|
|
190
|
-
throw new Error(`A worker name is required for productions ${subcommand}. Use --worker or run inside a configured package with a single primary worker.`);
|
|
191
|
-
}
|
|
192
|
-
return {
|
|
193
|
-
accountId,
|
|
194
|
-
workerName: workerSelection.workerName,
|
|
195
|
-
workerNameSource: workerSelection.source,
|
|
196
|
-
discovery
|
|
197
|
-
};
|
|
198
|
-
}
|
|
199
|
-
function getProductionUrl(workerName, workersSubdomain) {
|
|
200
|
-
if (!workersSubdomain) {
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
const normalizedSubdomain = workersSubdomain.trim().replace(/^https?:\/\//i, "").replace(/\.workers\.dev\/?$/i, "");
|
|
204
|
-
return `https://${workerName}.${normalizedSubdomain}.workers.dev`;
|
|
205
|
-
}
|
|
206
|
-
async function buildProductionRows(accountId, families, apiOptions) {
|
|
207
|
-
const [liveWorkers, workersSubdomain] = await Promise.all([
|
|
208
|
-
account.workers(accountId, apiOptions),
|
|
209
|
-
account.workersSubdomain(accountId, apiOptions)
|
|
210
|
-
]);
|
|
211
|
-
const workersByName = new Map(liveWorkers.map((worker) => [worker.name, worker]));
|
|
212
|
-
return Promise.all(families.map(async (family) => {
|
|
213
|
-
const worker = workersByName.get(family.baseName);
|
|
214
|
-
if (!worker) {
|
|
215
|
-
return {
|
|
216
|
-
workerName: family.baseName,
|
|
217
|
-
role: family.roleLabel,
|
|
218
|
-
status: "missing",
|
|
219
|
-
url: getProductionUrl(family.baseName, workersSubdomain)
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
const deployments = await account.workerDeployments(accountId, family.baseName, apiOptions);
|
|
223
|
-
const latestDeployment = [...deployments].sort((left, right) => {
|
|
224
|
-
return right.createdOn.getTime() - left.createdOn.getTime();
|
|
225
|
-
})[0];
|
|
226
|
-
const activeVersionId = latestDeployment ? selectDeploymentVersionId(latestDeployment) : undefined;
|
|
227
|
-
return {
|
|
228
|
-
workerName: family.baseName,
|
|
229
|
-
role: family.roleLabel,
|
|
230
|
-
status: latestDeployment ? "active" : "undeployed",
|
|
231
|
-
deployedAt: latestDeployment?.createdOn ?? worker.modifiedOn,
|
|
232
|
-
versionId: activeVersionId,
|
|
233
|
-
source: latestDeployment?.source,
|
|
234
|
-
url: getProductionUrl(family.baseName, workersSubdomain)
|
|
235
|
-
};
|
|
236
|
-
}));
|
|
237
|
-
}
|
|
238
|
-
function buildProductionColumns(theme) {
|
|
239
|
-
return [
|
|
240
|
-
{
|
|
241
|
-
label: "Worker",
|
|
242
|
-
width: 34,
|
|
243
|
-
value: (row) => row.workerName
|
|
244
|
-
},
|
|
245
|
-
{
|
|
246
|
-
label: "Role",
|
|
247
|
-
width: 18,
|
|
248
|
-
value: (row) => row.role
|
|
249
|
-
},
|
|
250
|
-
{
|
|
251
|
-
label: "Status",
|
|
252
|
-
width: 10,
|
|
253
|
-
value: (row) => formatWorkerStatus(row.status, theme)
|
|
254
|
-
},
|
|
255
|
-
{
|
|
256
|
-
label: "Deployed",
|
|
257
|
-
width: 19,
|
|
258
|
-
value: (row) => whiteDim(formatRecordDate(row.deployedAt), theme)
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
label: "Version",
|
|
262
|
-
width: 13,
|
|
263
|
-
value: (row) => row.versionId ? shortenVersionId(row.versionId) : dim("N/A", theme)
|
|
264
|
-
},
|
|
265
|
-
{
|
|
266
|
-
label: "Source",
|
|
267
|
-
width: 14,
|
|
268
|
-
value: (row) => row.source ?? dim("N/A", theme)
|
|
269
|
-
},
|
|
270
|
-
{
|
|
271
|
-
label: "URL",
|
|
272
|
-
value: (row) => row.url ?? "N/A"
|
|
273
|
-
}
|
|
274
|
-
];
|
|
275
|
-
}
|
|
276
|
-
function buildVersionColumns(theme) {
|
|
277
|
-
return [
|
|
278
|
-
{
|
|
279
|
-
label: "Version",
|
|
280
|
-
width: 13,
|
|
281
|
-
value: (row) => shortenVersionId(row.versionId)
|
|
282
|
-
},
|
|
283
|
-
{
|
|
284
|
-
label: "Status",
|
|
285
|
-
width: 8,
|
|
286
|
-
value: (row) => formatVersionStatus(row.status, theme)
|
|
287
|
-
},
|
|
288
|
-
{
|
|
289
|
-
label: "Updated",
|
|
290
|
-
width: 19,
|
|
291
|
-
value: (row) => whiteDim(formatRecordDate(row.updatedAt), theme)
|
|
292
|
-
},
|
|
293
|
-
{
|
|
294
|
-
label: "Last deployed",
|
|
295
|
-
width: 19,
|
|
296
|
-
value: (row) => whiteDim(formatRecordDate(row.deployedAt), theme)
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
label: "Source",
|
|
300
|
-
value: (row) => row.source ?? dim("N/A", theme)
|
|
301
|
-
}
|
|
302
|
-
];
|
|
303
|
-
}
|
|
304
|
-
async function loadWorkerVersionOverview(accountId, workerName, apiOptions) {
|
|
305
|
-
const [versions, deployments] = await Promise.all([
|
|
306
|
-
account.workerVersions(accountId, workerName, apiOptions),
|
|
307
|
-
account.workerDeployments(accountId, workerName, apiOptions)
|
|
308
|
-
]);
|
|
309
|
-
const productionVersions = versions.filter((version) => version.id).filter((version) => version.metadata.hasPreview !== true).sort((left, right) => {
|
|
310
|
-
const leftTime = getWorkerVersionTimestamp(left)?.getTime() ?? 0;
|
|
311
|
-
const rightTime = getWorkerVersionTimestamp(right)?.getTime() ?? 0;
|
|
312
|
-
return rightTime - leftTime;
|
|
313
|
-
}).slice(0, VERSION_LIST_LIMIT);
|
|
314
|
-
const activeVersionIds = new Set((deployments[0]?.versions ?? []).map((version) => version.versionId));
|
|
315
|
-
const latestDeploymentByVersionId = new Map;
|
|
316
|
-
for (const deployment of deployments) {
|
|
317
|
-
for (const version of deployment.versions) {
|
|
318
|
-
const existing = latestDeploymentByVersionId.get(version.versionId);
|
|
319
|
-
if (!existing || deployment.createdOn.getTime() > existing.getTime()) {
|
|
320
|
-
latestDeploymentByVersionId.set(version.versionId, deployment.createdOn);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
return {
|
|
325
|
-
workerName,
|
|
326
|
-
rows: productionVersions.map((version) => ({
|
|
327
|
-
versionId: version.id,
|
|
328
|
-
status: activeVersionIds.has(version.id) ? "active" : "stored",
|
|
329
|
-
updatedAt: getWorkerVersionTimestamp(version),
|
|
330
|
-
deployedAt: latestDeploymentByVersionId.get(version.id),
|
|
331
|
-
source: version.metadata.source
|
|
332
|
-
}))
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
function showProductionOverview(logger, context, rows, theme) {
|
|
336
|
-
logLine(logger);
|
|
337
|
-
if (context.discovery.primaryFamilyNames.length === 1) {
|
|
338
|
-
logLine(logger, formatLabelValue("worker family", green(context.discovery.primaryFamilyNames[0], theme), theme));
|
|
339
|
-
logLine(logger, formatLabelValue("related", whiteDim(String(Math.max(context.discovery.families.length - 1, 0)), theme), theme));
|
|
340
|
-
} else if (context.discovery.primaryFamilyNames.length > 1) {
|
|
341
|
-
logLine(logger, formatLabelValue("configured", whiteDim(`${context.discovery.primaryFamilyNames.length} primary workers`, theme), theme));
|
|
342
|
-
logLine(logger, formatLabelValue("tracked", whiteDim(`${context.discovery.families.length} workers`, theme), theme));
|
|
343
|
-
} else if (context.workerName) {
|
|
344
|
-
logLine(logger, formatLabelValue("worker", green(context.workerName, theme), theme));
|
|
345
|
-
}
|
|
346
|
-
if (rows.length === 0) {
|
|
347
|
-
logLine(logger);
|
|
348
|
-
logLine(logger, dim("No production Workers matched the current selection.", theme));
|
|
349
|
-
logLine(logger);
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
logLine(logger);
|
|
353
|
-
logTable(logger, {
|
|
354
|
-
title: "Productions",
|
|
355
|
-
rows,
|
|
356
|
-
columns: buildProductionColumns(theme),
|
|
357
|
-
theme,
|
|
358
|
-
titleAccent: "green"
|
|
359
|
-
});
|
|
360
|
-
logLine(logger);
|
|
361
|
-
logLine(logger, dim("Use `devflare productions versions` for recent production versions, or `rollback` / `delete` to mutate one Worker.", theme));
|
|
362
|
-
logLine(logger);
|
|
363
|
-
}
|
|
364
|
-
function showWorkerVersions(logger, overviews, theme) {
|
|
365
|
-
logLine(logger);
|
|
366
|
-
if (overviews.length === 0) {
|
|
367
|
-
logLine(logger, dim("No production versions were found for the current selection.", theme));
|
|
368
|
-
logLine(logger);
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
for (const [index, overview] of overviews.entries()) {
|
|
372
|
-
if (index > 0) {
|
|
373
|
-
logLine(logger);
|
|
374
|
-
}
|
|
375
|
-
logLine(logger, `${bold("worker", theme)} ${green(overview.workerName, theme)}`);
|
|
376
|
-
if (overview.rows.length === 0) {
|
|
377
|
-
logLine(logger, dim("No stored production versions were found for this Worker.", theme));
|
|
378
|
-
continue;
|
|
379
|
-
}
|
|
380
|
-
logTable(logger, {
|
|
381
|
-
title: "Versions",
|
|
382
|
-
rows: overview.rows,
|
|
383
|
-
columns: buildVersionColumns(theme),
|
|
384
|
-
theme,
|
|
385
|
-
titleAccent: "cyan"
|
|
386
|
-
});
|
|
387
|
-
}
|
|
388
|
-
logLine(logger);
|
|
389
|
-
}
|
|
390
|
-
async function runRollback(context, parsed, options, logger, theme) {
|
|
391
|
-
if (!context.workerName) {
|
|
392
|
-
logger.error("A worker name is required for production rollback.");
|
|
393
|
-
return { exitCode: 1 };
|
|
394
|
-
}
|
|
395
|
-
const versionId = asOptionalString(parsed.options.version) || asOptionalString(parsed.options["version-id"]);
|
|
396
|
-
const apply = parsed.options.apply === true;
|
|
397
|
-
if (!apply) {
|
|
398
|
-
logger.success(`Production rollback dry run complete for ${context.workerName}`);
|
|
399
|
-
logger.info(versionId ? `Would roll back ${context.workerName} to version ${versionId}` : `Would roll back ${context.workerName} to the previously deployed production version`);
|
|
400
|
-
return { exitCode: 0 };
|
|
401
|
-
}
|
|
402
|
-
const rollbackMessage = asOptionalString(parsed.options.message) ?? `Rolled back ${context.workerName} via devflare productions rollback`;
|
|
403
|
-
const rollbackArgs = ["wrangler", "rollback"];
|
|
404
|
-
if (versionId) {
|
|
405
|
-
rollbackArgs.push(versionId);
|
|
406
|
-
}
|
|
407
|
-
rollbackArgs.push("--name", context.workerName, "--message", rollbackMessage);
|
|
408
|
-
logLine(logger);
|
|
409
|
-
logLine(logger, `${cyanBold("productions rollback", theme)} ${dim(`Rolling back ${context.workerName}`, theme)}`);
|
|
410
|
-
const deps = await getDependencies();
|
|
411
|
-
const cwd = options.cwd ?? process.cwd();
|
|
412
|
-
const rollbackResult = await deps.exec.exec("bunx", rollbackArgs, {
|
|
413
|
-
cwd,
|
|
414
|
-
stdio: "inherit"
|
|
415
|
-
});
|
|
416
|
-
if (rollbackResult.exitCode !== 0) {
|
|
417
|
-
logger.error(`Rollback failed for ${context.workerName}`);
|
|
418
|
-
return { exitCode: 1 };
|
|
419
|
-
}
|
|
420
|
-
const deployments = await account.workerDeployments(context.accountId, context.workerName, CLI_API_OPTIONS);
|
|
421
|
-
const activeVersionId = deployments[0] ? selectDeploymentVersionId(deployments[0]) : undefined;
|
|
422
|
-
logger.success(`Rolled back production deployment for ${context.workerName}`);
|
|
423
|
-
if (activeVersionId) {
|
|
424
|
-
logger.info(`Active version: ${activeVersionId}`);
|
|
425
|
-
}
|
|
426
|
-
return { exitCode: 0 };
|
|
427
|
-
}
|
|
428
|
-
async function runDelete(context, parsed, logger) {
|
|
429
|
-
if (!context.workerName) {
|
|
430
|
-
logger.error("A worker name is required for production deletion.");
|
|
431
|
-
return { exitCode: 1 };
|
|
432
|
-
}
|
|
433
|
-
const apply = parsed.options.apply === true;
|
|
434
|
-
if (!apply) {
|
|
435
|
-
logger.success(`Production delete dry run complete for ${context.workerName}`);
|
|
436
|
-
logger.info(`Would delete Worker script ${context.workerName}`);
|
|
437
|
-
logger.warn("Deleting a production Worker script does not automatically delete KV, D1, R2, queue, or other account resources.");
|
|
438
|
-
return { exitCode: 0 };
|
|
439
|
-
}
|
|
440
|
-
await account.deleteWorker(context.accountId, context.workerName, CLI_API_OPTIONS);
|
|
441
|
-
logger.success(`Deleted production Worker script ${context.workerName}`);
|
|
442
|
-
logger.warn("Devflare deleted the Worker script only. Review any shared account resources separately before cleaning them up.");
|
|
443
|
-
return { exitCode: 0 };
|
|
444
|
-
}
|
|
445
|
-
async function runProductionsCommand(parsed, logger, options) {
|
|
446
|
-
const isAuth = await account.isAuthenticated();
|
|
447
|
-
if (!isAuth) {
|
|
448
|
-
logger.error("Not authenticated with Cloudflare");
|
|
449
|
-
logger.info("Run `devflare login` first.");
|
|
450
|
-
return { exitCode: 1 };
|
|
451
|
-
}
|
|
452
|
-
const rawSubcommand = parsed.args[0];
|
|
453
|
-
const fallbackWorkerArg = rawSubcommand && !isProductionSubcommand(rawSubcommand) ? rawSubcommand : parsed.args[1];
|
|
454
|
-
const subcommand = rawSubcommand && isProductionSubcommand(rawSubcommand) ? rawSubcommand : "list";
|
|
455
|
-
const theme = createCliTheme(parsed.options);
|
|
456
|
-
if (rawSubcommand && !isProductionSubcommand(rawSubcommand) && parsed.args.length > 2) {
|
|
457
|
-
logger.error(`Unknown productions subcommand: ${rawSubcommand}`);
|
|
458
|
-
logger.info(`Available productions subcommands: ${PRODUCTION_SUBCOMMANDS.join(", ")}`);
|
|
459
|
-
return { exitCode: 1 };
|
|
460
|
-
}
|
|
461
|
-
try {
|
|
462
|
-
const context = await resolveContext(parsed, options, subcommand, fallbackWorkerArg);
|
|
463
|
-
const selectedFamilies = context.discovery.families.length > 0 ? context.discovery.families : context.workerName ? [
|
|
464
|
-
{
|
|
465
|
-
baseName: context.workerName,
|
|
466
|
-
roleLabel: "selected worker",
|
|
467
|
-
role: "primary"
|
|
468
|
-
}
|
|
469
|
-
] : [];
|
|
470
|
-
switch (subcommand) {
|
|
471
|
-
case "versions": {
|
|
472
|
-
const workerNames = Array.from(new Set(context.workerName ? [context.workerName] : selectedFamilies.map((family) => family.baseName))).sort((left, right) => left.localeCompare(right));
|
|
473
|
-
if (workerNames.length === 0) {
|
|
474
|
-
logger.error("No production Workers could be resolved. Use --worker or run inside a configured package.");
|
|
475
|
-
return { exitCode: 1 };
|
|
476
|
-
}
|
|
477
|
-
const overviews = await Promise.all(workerNames.map((workerName) => loadWorkerVersionOverview(context.accountId, workerName, CLI_API_OPTIONS)));
|
|
478
|
-
showWorkerVersions(logger, overviews, theme);
|
|
479
|
-
return { exitCode: 0 };
|
|
480
|
-
}
|
|
481
|
-
case "rollback":
|
|
482
|
-
return runRollback(context, parsed, options, logger, theme);
|
|
483
|
-
case "delete":
|
|
484
|
-
return runDelete(context, parsed, logger);
|
|
485
|
-
default: {
|
|
486
|
-
if (selectedFamilies.length === 0) {
|
|
487
|
-
logger.error("No production Workers could be resolved. Use --worker, --config, or run inside a configured package.");
|
|
488
|
-
return { exitCode: 1 };
|
|
489
|
-
}
|
|
490
|
-
const rows = await buildProductionRows(context.accountId, selectedFamilies, CLI_API_OPTIONS);
|
|
491
|
-
showProductionOverview(logger, context, rows, theme);
|
|
492
|
-
return { exitCode: 0 };
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
} catch (error) {
|
|
496
|
-
if (error instanceof Error) {
|
|
497
|
-
logger.error(error.message);
|
|
498
|
-
return { exitCode: 1 };
|
|
499
|
-
}
|
|
500
|
-
throw error;
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
export {
|
|
504
|
-
runProductionsCommand
|
|
505
|
-
};
|
package/dist/remote-kqcvhnfx.js
DELETED
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BOLD,
|
|
3
|
-
DIM,
|
|
4
|
-
GREEN,
|
|
5
|
-
RED,
|
|
6
|
-
RESET,
|
|
7
|
-
YELLOW
|
|
8
|
-
} from "./index-3t6rypgc.js";
|
|
9
|
-
import"./index-37x76zdn.js";
|
|
10
|
-
|
|
11
|
-
// src/cloudflare/remote-config.ts
|
|
12
|
-
import { existsSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "fs";
|
|
13
|
-
import { homedir } from "os";
|
|
14
|
-
import { join } from "path";
|
|
15
|
-
var MIN_MINUTES = 1;
|
|
16
|
-
var MAX_MINUTES = 1440;
|
|
17
|
-
function getConfigDir() {
|
|
18
|
-
return join(homedir(), ".devflare");
|
|
19
|
-
}
|
|
20
|
-
function getConfigPath() {
|
|
21
|
-
return join(getConfigDir(), "remote.json");
|
|
22
|
-
}
|
|
23
|
-
function readConfig() {
|
|
24
|
-
const path = getConfigPath();
|
|
25
|
-
if (!existsSync(path))
|
|
26
|
-
return null;
|
|
27
|
-
try {
|
|
28
|
-
const content = readFileSync(path, "utf-8");
|
|
29
|
-
return JSON.parse(content);
|
|
30
|
-
} catch {
|
|
31
|
-
return null;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function writeConfig(config) {
|
|
35
|
-
const dir = getConfigDir();
|
|
36
|
-
if (!existsSync(dir)) {
|
|
37
|
-
mkdirSync(dir, { recursive: true });
|
|
38
|
-
}
|
|
39
|
-
writeFileSync(getConfigPath(), JSON.stringify(config, null, "\t"));
|
|
40
|
-
}
|
|
41
|
-
function deleteConfig() {
|
|
42
|
-
const path = getConfigPath();
|
|
43
|
-
if (existsSync(path)) {
|
|
44
|
-
try {
|
|
45
|
-
unlinkSync(path);
|
|
46
|
-
} catch {}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
function enableRemoteMode(minutes = 30) {
|
|
50
|
-
const validMinutes = Math.max(MIN_MINUTES, Math.min(MAX_MINUTES, Math.floor(minutes) || 30));
|
|
51
|
-
const now = Date.now();
|
|
52
|
-
writeConfig({
|
|
53
|
-
enabledAt: now,
|
|
54
|
-
expiresAt: now + validMinutes * 60 * 1000,
|
|
55
|
-
durationMinutes: validMinutes
|
|
56
|
-
});
|
|
57
|
-
return validMinutes;
|
|
58
|
-
}
|
|
59
|
-
function disableRemoteMode() {
|
|
60
|
-
deleteConfig();
|
|
61
|
-
}
|
|
62
|
-
function getRemoteModeStatus() {
|
|
63
|
-
const config = readConfig();
|
|
64
|
-
if (!config) {
|
|
65
|
-
return { isEnabled: false, remainingMinutes: 0, expiresAt: null };
|
|
66
|
-
}
|
|
67
|
-
const now = Date.now();
|
|
68
|
-
if (now >= config.expiresAt) {
|
|
69
|
-
deleteConfig();
|
|
70
|
-
return { isEnabled: false, remainingMinutes: 0, expiresAt: null };
|
|
71
|
-
}
|
|
72
|
-
const remainingMs = config.expiresAt - now;
|
|
73
|
-
const remainingMinutes = Math.ceil(remainingMs / 60000);
|
|
74
|
-
return {
|
|
75
|
-
isEnabled: true,
|
|
76
|
-
remainingMinutes,
|
|
77
|
-
expiresAt: new Date(config.expiresAt)
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
function getEffectiveRemoteModeStatus() {
|
|
81
|
-
const envValue = process.env.DEVFLARE_REMOTE ?? "";
|
|
82
|
-
const envVarSet = ["1", "true", "yes"].includes(envValue.toLowerCase());
|
|
83
|
-
if (envVarSet) {
|
|
84
|
-
return {
|
|
85
|
-
isActive: true,
|
|
86
|
-
source: "env",
|
|
87
|
-
remainingMinutes: Number.POSITIVE_INFINITY,
|
|
88
|
-
expiresAt: null,
|
|
89
|
-
envVarSet: true
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
const status = getRemoteModeStatus();
|
|
93
|
-
if (status.isEnabled) {
|
|
94
|
-
return {
|
|
95
|
-
isActive: true,
|
|
96
|
-
source: "config",
|
|
97
|
-
remainingMinutes: status.remainingMinutes,
|
|
98
|
-
expiresAt: status.expiresAt,
|
|
99
|
-
envVarSet: false
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
return {
|
|
103
|
-
isActive: false,
|
|
104
|
-
source: "none",
|
|
105
|
-
remainingMinutes: 0,
|
|
106
|
-
expiresAt: null,
|
|
107
|
-
envVarSet: false
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// src/cli/commands/remote.ts
|
|
112
|
-
function log(message = "") {
|
|
113
|
-
console.log(message);
|
|
114
|
-
}
|
|
115
|
-
function showStatus() {
|
|
116
|
-
const status = getEffectiveRemoteModeStatus();
|
|
117
|
-
log();
|
|
118
|
-
log(`${BOLD}Remote Test Mode${RESET}`);
|
|
119
|
-
log();
|
|
120
|
-
if (status.isActive) {
|
|
121
|
-
log(` ${GREEN}●${RESET} ${BOLD}Enabled${RESET}`);
|
|
122
|
-
if (status.source === "env") {
|
|
123
|
-
log(` Source: ${YELLOW}DEVFLARE_REMOTE${RESET} environment variable`);
|
|
124
|
-
log(` ${DIM}(unset the variable to disable)${RESET}`);
|
|
125
|
-
} else {
|
|
126
|
-
log(` Expires in ${status.remainingMinutes} minute(s)`);
|
|
127
|
-
log(` ${DIM}At: ${status.expiresAt?.toLocaleTimeString()}${RESET}`);
|
|
128
|
-
}
|
|
129
|
-
} else {
|
|
130
|
-
log(` ${DIM}○${RESET} Disabled`);
|
|
131
|
-
log(` ${DIM}Remote-only tests (AI, Vectorize) will be skipped${RESET}`);
|
|
132
|
-
}
|
|
133
|
-
log();
|
|
134
|
-
log(`${DIM}Commands:${RESET}`);
|
|
135
|
-
log(` devflare remote enable [minutes] Enable for N minutes (default: 30)`);
|
|
136
|
-
log(` devflare remote disable Disable immediately`);
|
|
137
|
-
log(` devflare remote status Show current status`);
|
|
138
|
-
log();
|
|
139
|
-
}
|
|
140
|
-
function enable(inputMinutes) {
|
|
141
|
-
const actualMinutes = enableRemoteMode(inputMinutes);
|
|
142
|
-
const status = getEffectiveRemoteModeStatus();
|
|
143
|
-
log();
|
|
144
|
-
if (inputMinutes !== actualMinutes) {
|
|
145
|
-
log(`${YELLOW}⚠${RESET} Invalid duration, using ${actualMinutes} minute(s)`);
|
|
146
|
-
}
|
|
147
|
-
log(`${GREEN}✓${RESET} Remote test mode ${BOLD}enabled${RESET} for ${actualMinutes} minute(s)`);
|
|
148
|
-
log(` Expires at: ${status.expiresAt?.toLocaleTimeString()}`);
|
|
149
|
-
log();
|
|
150
|
-
log(`${YELLOW}⚠${RESET} Remote tests use real Cloudflare infrastructure and may incur costs.`);
|
|
151
|
-
log(` Run ${DIM}devflare remote disable${RESET} when done.`);
|
|
152
|
-
log();
|
|
153
|
-
}
|
|
154
|
-
function disable() {
|
|
155
|
-
const statusBefore = getEffectiveRemoteModeStatus();
|
|
156
|
-
disableRemoteMode();
|
|
157
|
-
log();
|
|
158
|
-
log(`${GREEN}✓${RESET} Remote test mode ${BOLD}disabled${RESET}`);
|
|
159
|
-
if (statusBefore.envVarSet) {
|
|
160
|
-
log();
|
|
161
|
-
log(`${YELLOW}⚠${RESET} Note: ${BOLD}DEVFLARE_REMOTE${RESET} environment variable is still set.`);
|
|
162
|
-
log(` Remote mode will remain active until you unset it.`);
|
|
163
|
-
} else {
|
|
164
|
-
log(` Remote-only tests (AI, Vectorize) will now be skipped.`);
|
|
165
|
-
}
|
|
166
|
-
log();
|
|
167
|
-
}
|
|
168
|
-
function runRemoteCommand(parsed, _logger, _options) {
|
|
169
|
-
const subcommand = parsed.args[0];
|
|
170
|
-
const arg = parsed.args[1];
|
|
171
|
-
switch (subcommand) {
|
|
172
|
-
case "enable": {
|
|
173
|
-
const minutes = arg ? Number.parseInt(arg, 10) : 30;
|
|
174
|
-
enable(Number.isNaN(minutes) ? 30 : minutes);
|
|
175
|
-
return { exitCode: 0 };
|
|
176
|
-
}
|
|
177
|
-
case "disable":
|
|
178
|
-
disable();
|
|
179
|
-
return { exitCode: 0 };
|
|
180
|
-
case "status":
|
|
181
|
-
case undefined:
|
|
182
|
-
showStatus();
|
|
183
|
-
return { exitCode: 0 };
|
|
184
|
-
default:
|
|
185
|
-
log(`${RED}Unknown subcommand:${RESET} ${subcommand}`);
|
|
186
|
-
log(`Run ${DIM}devflare remote${RESET} for usage.`);
|
|
187
|
-
return { exitCode: 1 };
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
export {
|
|
191
|
-
runRemoteCommand
|
|
192
|
-
};
|