@cloudflare/deploy-helpers 0.27.1 → 0.28.0

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.
@@ -0,0 +1,212 @@
1
+ import { BuiltContainerImage, BuiltImage, ContainerNormalizedConfig } from "@cloudflare/containers-shared";
2
+ import { CfModule, CfModuleType, CfWorkerSourceMap, Config, ContainerApp, DurableObjectCodeUpdateStrategy, Entry, FetchKVGetValueFetcher, FetchListResultFetcher, FetchPagedListResultFetcher, FetchResultFetcher, LegacyAssetPaths, Logger, Route, ValidatedAssetsOptions } from "@cloudflare/workers-utils";
3
+ //#region src/shared/types.d.ts
4
+ /** API, logging, and prompt implementations supplied by the consumer. */
5
+ type DeployHelpersContext = {
6
+ fetchResult: FetchResultFetcher;
7
+ fetchListResult: FetchListResultFetcher;
8
+ fetchPagedListResult: FetchPagedListResultFetcher;
9
+ fetchKVGetValue: FetchKVGetValueFetcher;
10
+ logger: Logger;
11
+ confirm: (text: string, options?: {
12
+ defaultValue?: boolean;
13
+ fallbackValue?: boolean;
14
+ }) => Promise<boolean>;
15
+ prompt: (text: string, options?: {
16
+ defaultValue?: string;
17
+ }) => Promise<string>;
18
+ select: <Values extends string>(text: string, options: {
19
+ choices: {
20
+ title: string;
21
+ description?: string;
22
+ value: Values;
23
+ }[];
24
+ defaultOption?: number;
25
+ fallbackOption?: number;
26
+ }) => Promise<Values>;
27
+ };
28
+ type ContainerlessConfig = Omit<Config, "containers">;
29
+ type BuiltDurableObjectContainerImage = BuiltImage & {
30
+ className: string;
31
+ imageName: string;
32
+ };
33
+ type ContainerDeployConfig = {
34
+ /** Original resolved container configuration. */
35
+ source: ContainerApp[] | undefined;
36
+ standard: {
37
+ /** Normalized non-Durable-Object container applications. */
38
+ normalized: ContainerNormalizedConfig[];
39
+ /** Locally built images awaiting deployment or cleanup. */
40
+ builtImages: BuiltContainerImage[];
41
+ };
42
+ durableObjects: {
43
+ /** Locally built named images awaiting upload or cleanup. */
44
+ builtImages: BuiltDurableObjectContainerImage[];
45
+ };
46
+ };
47
+ /**
48
+ * Shared fields produced by merging CLI args with wrangler config.
49
+ * After this point, no raw config/arg merging should happen.
50
+ *
51
+ * Use props for all resolved/merged values. Only access config directly
52
+ * for raw values that aren't merged with CLI args (e.g., config.durable_objects,
53
+ * config.unsafe, config.tail_consumers).
54
+ */
55
+ type SharedDeployVersionsProps = {
56
+ /** Merged from args.script/config.main/config.site.entry-point/config.assets. */
57
+ entry: Entry;
58
+ /** Merged: --name arg ?? config.name, with CI override applied. Validated as required separately. */
59
+ name: string | undefined;
60
+ /** Merged: --compatibility-date arg ?? config.compatibility_date. Still optional — validated as required later. */
61
+ compatibilityDate: string | undefined;
62
+ /** Merged: --compatibility-flags arg ?? config.compatibility_flags. */
63
+ compatibilityFlags: string[];
64
+ /**
65
+ * Validated/resolved assets directory, merged from --assets arg and
66
+ * config.assets. The full AssetsOptions are resolved later via
67
+ * `resolveAssetOptions`.
68
+ */
69
+ assetsDir: ValidatedAssetsOptions | undefined;
70
+ /**
71
+ * The user Worker entry, merged: --script arg ?? config.main. Undefined for
72
+ * assets-only Workers. Drives `has_user_worker` when resolving assets.
73
+ */
74
+ main: string | undefined;
75
+ /** Merged: --keep-vars arg || config.keep_vars. */
76
+ keepVars: boolean;
77
+ /** Merged from --site arg and config.site. */
78
+ isWorkersSite: boolean;
79
+ /** From --dry-run arg. */
80
+ dryRun: boolean;
81
+ /** From --env arg. */
82
+ env: string | undefined;
83
+ /** From --outfile arg. */
84
+ outfile: string | undefined;
85
+ /** From --tag arg. */
86
+ tag: string | undefined;
87
+ /** From --message arg. */
88
+ message: string | undefined;
89
+ /** From --secrets-file arg. */
90
+ secretsFile: string | undefined;
91
+ /** From collectKeyValues(--var arg). CLI-only vars; config vars flow separately via getBindings(config). */
92
+ cliVars: Record<string, string>;
93
+ /** From --experimental-auto-create arg. */
94
+ experimentalAutoCreate: boolean;
95
+ /** Resolved from requireAuth() before calling deploy-helpers. undefined only in dry-run. */
96
+ accountId: string | undefined;
97
+ /** Resolved from getMetricsUsageHeaders() / config.send_metrics. Controls whether usage metrics headers are sent with upload requests. */
98
+ sendMetrics: boolean;
99
+ /** Resolved from getFlag("RESOURCES_PROVISION"). Controls whether bindings are auto-provisioned before upload. */
100
+ resourcesProvision: boolean;
101
+ /** Controls whether provisioned resource IDs are written back to the config file. */
102
+ skipProvisioningConfigWriteback: boolean;
103
+ /** From --strict arg. In strict mode, conflicting pre-upload checks abort instead of auto-continuing. */
104
+ strict: boolean;
105
+ /** Optional consumer-specific message shown when strict mode aborts in a non-interactive session. */
106
+ strictModeAbortMessage?: string;
107
+ /** Container configuration and locally built image state. */
108
+ containers: ContainerDeployConfig;
109
+ /** Whether the resolved Worker name differs from the pre-merge config/args name. */
110
+ workerNameOverridden?: boolean;
111
+ };
112
+ type DeployProps = SharedDeployVersionsProps & {
113
+ /** Discriminant for DeployProps vs VersionsUploadProps */
114
+ command: "deploy";
115
+ /** If set, automatically register this `workers.dev` account subdomain when the account has none. */
116
+ autoRegisterWorkersDevSubdomain?: string;
117
+ /** Merged from --site arg and config.site. */
118
+ legacyAssetPaths: LegacyAssetPaths | undefined;
119
+ /** Merged: --triggers arg ?? config.triggers.crons. */
120
+ triggers: string[] | undefined;
121
+ /** Merged: --routes arg ?? config.routes ?? config.route. AND --domains and custom_domains*/
122
+ routes: Route[];
123
+ /** Merged: --logpush arg ?? config.logpush. */
124
+ logpush: boolean | undefined;
125
+ /** From --dispatch-namespace arg. Deploy-only (Workers for Platforms). */
126
+ dispatchNamespace: string | undefined;
127
+ /** From --old-asset-ttl arg. Deploy-only. */
128
+ oldAssetTtl: number | undefined;
129
+ /** From --containers-rollout arg. Deploy-only. */
130
+ containersRollout: "immediate" | "gradual" | "none" | undefined;
131
+ /** Controls how Durable Object code updates are applied. */
132
+ durableObjectsCodeUpdateStrategy?: DurableObjectCodeUpdateStrategy;
133
+ /**
134
+ * When true, an existing Worker with the same name aborts the deploy instead
135
+ * of updating it, because this run cannot confirm the local project owns the
136
+ * remote Worker. Set for non-interactive deploys with no pre-existing config
137
+ * file when either the name was generated automatically (no user-supplied
138
+ * name) or the deploy is the Pages-to-Workers delegation (where the name is a
139
+ * Pages project name carried across, not proof of Worker ownership). Deploys
140
+ * that carry a config file naming the Worker leave this false and update it as
141
+ * normal.
142
+ */
143
+ failIfWorkerNameTaken?: boolean;
144
+ };
145
+ type VersionsUploadProps = SharedDeployVersionsProps & {
146
+ /** Discriminant for DeployProps vs VersionsUploadProps */
147
+ command: "versions upload";
148
+ /** CLI-only (--preview-alias), or auto-generated from CI branch name. */
149
+ previewAlias: string | undefined;
150
+ };
151
+ type WorkerBuildResult = {
152
+ modules: CfModule[];
153
+ sourceMaps: CfWorkerSourceMap[] | undefined;
154
+ dependencies: Record<string, {
155
+ bytesInOutput: number;
156
+ }>;
157
+ resolvedEntryPointPath: string;
158
+ bundleType: CfModuleType;
159
+ content: string;
160
+ };
161
+ interface TriggerDeployment {
162
+ targets: string[];
163
+ changed?: boolean;
164
+ category?: string;
165
+ resource?: string;
166
+ error?: Error;
167
+ }
168
+ type TriggerProps = {
169
+ config: Config;
170
+ accountId: string | undefined;
171
+ scriptName: string;
172
+ workerTag?: string | null;
173
+ crons: string[] | undefined;
174
+ routes: Route[];
175
+ firstDeploy: boolean;
176
+ dryRun: boolean;
177
+ validated: boolean;
178
+ queueCreateCommand: (queueName: string) => string;
179
+ workersDevConfigFieldName: string;
180
+ workersDevConfigAssignment: (value: boolean) => string;
181
+ previewUrlsConfigFieldName: string;
182
+ previewUrlsConfigAssignment: (value: boolean) => string;
183
+ };
184
+ //#endregion
185
+ //#region src/shared/context.d.ts
186
+ /**
187
+ * Module-level context globals for deploy-helpers.
188
+ *
189
+ * These are typed as non-nullable but are undefined until initDeployHelpersContext()
190
+ * is called. Consumers must import the live binding directly (e.g. `import { logger }`)
191
+ * and NOT destructure or cache the value at module-load time, otherwise they will
192
+ * capture `undefined` before init runs.
193
+ *
194
+ * Example:
195
+ * import { logger } from "./context"; // correct: live binding
196
+ * const { logger } = await import("./context"); // WRONG: captures undefined
197
+ */
198
+ declare let logger: Logger;
199
+ declare let fetchResult: FetchResultFetcher;
200
+ declare let fetchListResult: FetchListResultFetcher;
201
+ declare let fetchPagedListResult: FetchPagedListResultFetcher;
202
+ declare let fetchKVGetValue: FetchKVGetValueFetcher;
203
+ declare let confirm: DeployHelpersContext["confirm"];
204
+ declare let prompt: DeployHelpersContext["prompt"];
205
+ declare let select: DeployHelpersContext["select"];
206
+ /**
207
+ * Set the global context for deploy-helpers. Must be called once at
208
+ * startup before any deploy-helpers function that needs these values.
209
+ */
210
+ declare function initDeployHelpersContext(ctx: DeployHelpersContext): void;
211
+ //#endregion
212
+ export { TriggerProps as _, fetchResult as a, prompt as c, ContainerDeployConfig as d, ContainerlessConfig as f, TriggerDeployment as g, SharedDeployVersionsProps as h, fetchPagedListResult as i, select as l, DeployProps as m, fetchKVGetValue as n, initDeployHelpersContext as o, DeployHelpersContext as p, fetchListResult as r, logger as s, confirm as t, BuiltDurableObjectContainerImage as u, VersionsUploadProps as v, WorkerBuildResult as y };
@@ -1,3 +1,2 @@
1
- export { d as confirm, f as fetchKVGetValue, e as fetchListResult, g as fetchPagedListResult, h as fetchResult, i as initDeployHelpersContext, l as logger, p as prompt, s as select } from './context-BY_xpg-t.mjs';
2
- import '@cloudflare/workers-utils';
3
- import '@cloudflare/containers-shared';
1
+ import { a as fetchResult, c as prompt, i as fetchPagedListResult, l as select, n as fetchKVGetValue, o as initDeployHelpersContext, r as fetchListResult, s as logger, t as confirm } from "./context-DOE6X8vr.mjs";
2
+ export { confirm, fetchKVGetValue, fetchListResult, fetchPagedListResult, fetchResult, initDeployHelpersContext, logger, prompt, select };
package/dist/context.mjs CHANGED
@@ -1,5 +1,38 @@
1
- import { createRequire } from 'node:module';
2
- export { confirm, fetchKVGetValue, fetchListResult, fetchPagedListResult, fetchResult, initDeployHelpersContext, logger, prompt, select } from './chunk-Y4VATABS.mjs';
3
- import './chunk-U6NEESU5.mjs';
4
-
5
- createRequire(import.meta.url || (typeof __filename === "string" ? __filename : "/"));
1
+ import "./rolldown-runtime-BMUeFane.mjs";
2
+ //#region src/shared/context.ts
3
+ /**
4
+ * Module-level context globals for deploy-helpers.
5
+ *
6
+ * These are typed as non-nullable but are undefined until initDeployHelpersContext()
7
+ * is called. Consumers must import the live binding directly (e.g. `import { logger }`)
8
+ * and NOT destructure or cache the value at module-load time, otherwise they will
9
+ * capture `undefined` before init runs.
10
+ *
11
+ * Example:
12
+ * import { logger } from "./context"; // correct: live binding
13
+ * const { logger } = await import("./context"); // WRONG: captures undefined
14
+ */
15
+ let logger;
16
+ let fetchResult;
17
+ let fetchListResult;
18
+ let fetchPagedListResult;
19
+ let fetchKVGetValue;
20
+ let confirm;
21
+ let prompt;
22
+ let select;
23
+ /**
24
+ * Set the global context for deploy-helpers. Must be called once at
25
+ * startup before any deploy-helpers function that needs these values.
26
+ */
27
+ function initDeployHelpersContext(ctx) {
28
+ logger = ctx.logger;
29
+ fetchResult = ctx.fetchResult;
30
+ fetchListResult = ctx.fetchListResult;
31
+ fetchPagedListResult = ctx.fetchPagedListResult;
32
+ fetchKVGetValue = ctx.fetchKVGetValue;
33
+ confirm = ctx.confirm;
34
+ prompt = ctx.prompt;
35
+ select = ctx.select;
36
+ }
37
+ //#endregion
38
+ export { confirm, fetchKVGetValue, fetchListResult, fetchPagedListResult, fetchResult, initDeployHelpersContext, logger, prompt, select };