devflare 1.0.0-next.21 → 1.0.0-next.23
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/LLM.md +144 -5
- package/dist/account-j8nfggg4.js +475 -0
- package/dist/account-qhe8vtds.js +475 -0
- package/dist/bridge/gateway-runtime.d.ts +1 -1
- package/dist/bridge/gateway-runtime.d.ts.map +1 -1
- package/dist/bridge/miniflare.d.ts +1 -1
- package/dist/bridge/miniflare.d.ts.map +1 -1
- package/dist/bridge/proxy.d.ts +2 -0
- package/dist/bridge/proxy.d.ts.map +1 -1
- package/dist/bridge/server.d.ts.map +1 -1
- package/dist/browser.d.ts +13 -13
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +5 -3
- package/dist/build-qsgnme4z.js +54 -0
- package/dist/build-vy95gy3f.js +54 -0
- package/dist/build-yzx0gsaj.js +54 -0
- package/dist/cli/commands/build-artifacts.d.ts.map +1 -1
- package/dist/cli/commands/config.d.ts.map +1 -1
- package/dist/cli/commands/type-generation/generator.d.ts +4 -2
- package/dist/cli/commands/type-generation/generator.d.ts.map +1 -1
- package/dist/cli/commands/types.d.ts.map +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/config/compiler/types.d.ts +1 -1
- package/dist/config/compiler/types.d.ts.map +1 -1
- package/dist/config/define.d.ts +7 -4
- package/dist/config/define.d.ts.map +1 -1
- package/dist/config/env-vars.d.ts +309 -0
- package/dist/config/env-vars.d.ts.map +1 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/local-dev-vars.d.ts +2 -2
- package/dist/config/local-dev-vars.d.ts.map +1 -1
- package/dist/config/schema-env.d.ts +6 -6
- package/dist/config/schema-types-bindings-platform.d.ts +378 -0
- package/dist/config/schema-types-bindings-platform.d.ts.map +1 -0
- package/dist/config/schema-types-bindings-resources.d.ts +551 -0
- package/dist/config/schema-types-bindings-resources.d.ts.map +1 -0
- package/dist/config/schema-types-bindings.d.ts +254 -0
- package/dist/config/schema-types-bindings.d.ts.map +1 -0
- package/dist/config/schema-types-build.d.ts +86 -0
- package/dist/config/schema-types-build.d.ts.map +1 -0
- package/dist/config/schema-types-runtime.d.ts +882 -0
- package/dist/config/schema-types-runtime.d.ts.map +1 -0
- package/dist/config/schema-types.d.ts +377 -0
- package/dist/config/schema-types.d.ts.map +1 -0
- package/dist/config/schema.d.ts +14 -15
- package/dist/config/schema.d.ts.map +1 -1
- package/dist/config-entry.d.ts +2 -0
- package/dist/config-entry.d.ts.map +1 -1
- package/dist/config-entry.js +3 -1
- package/dist/config-gq5jh4cx.js +105 -0
- package/dist/config-vec13050.js +105 -0
- package/dist/deploy-01j0ep5n.js +1055 -0
- package/dist/deploy-nh5tbv45.js +1055 -0
- package/dist/deploy-tjypkhg7.js +1055 -0
- package/dist/dev-bh581ew3.js +2597 -0
- package/dist/dev-cme5de75.js +2551 -0
- package/dist/dev-gn5y93z9.js +2597 -0
- package/dist/dev-server/server.d.ts.map +1 -1
- package/dist/doctor-h5q28qt1.js +259 -0
- package/dist/doctor-khk550tw.js +259 -0
- package/dist/env.d.ts +10 -0
- package/dist/env.d.ts.map +1 -1
- package/dist/index-0bv2qjs1.js +1555 -0
- package/dist/index-35bmgpfw.js +573 -0
- package/dist/index-3tkzn06q.js +413 -0
- package/dist/index-4se6krdj.js +574 -0
- package/dist/index-8fyz6gcm.js +699 -0
- package/dist/index-97z629zr.js +109 -0
- package/dist/index-b28c4yr4.js +1205 -0
- package/dist/index-c1cj9085.js +2250 -0
- package/dist/index-c8p4njqy.js +479 -0
- package/dist/index-cr06zrgw.js +1033 -0
- package/dist/index-cwjjdtgn.js +74 -0
- package/dist/index-dref9ecb.js +476 -0
- package/dist/index-e151t4ge.js +895 -0
- package/dist/index-e7kakw0j.js +1033 -0
- package/dist/index-f1g5jdm8.js +1426 -0
- package/dist/index-f46984zs.js +1554 -0
- package/dist/index-grk8pzhr.js +185 -0
- package/dist/index-hbxkmb1q.js +1426 -0
- package/dist/index-hzmpecq9.js +52 -0
- package/dist/index-j1csb7gb.js +581 -0
- package/dist/index-j7x7f72h.js +185 -0
- package/dist/index-jkqbjwt2.js +476 -0
- package/dist/index-jwd3fanx.js +412 -0
- package/dist/index-mh5renra.js +895 -0
- package/dist/index-p9xq83p7.js +147 -0
- package/dist/index-q15nj71j.js +52 -0
- package/dist/index-qqp65pyv.js +699 -0
- package/dist/index-s0fmwxbk.js +74 -0
- package/dist/index-s9q605sq.js +1033 -0
- package/dist/index-stzx8nc4.js +111 -0
- package/dist/index-th4vrnbk.js +1205 -0
- package/dist/index-vtcmsgaf.js +581 -0
- package/dist/index-w36q6819.js +895 -0
- package/dist/index-x2k3awjs.js +147 -0
- package/dist/index-x8x547tz.js +1426 -0
- package/dist/index-xp0qkkxf.js +68 -0
- package/dist/index-xxxd0mvw.js +109 -0
- package/dist/index-zawn5tte.js +109 -0
- package/dist/index-zpy9caxn.js +1193 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -7
- package/dist/login-280p2cm9.js +77 -0
- package/dist/login-4n266whq.js +77 -0
- package/dist/previews-3m3ffpaw.js +1337 -0
- package/dist/previews-tr8sm03d.js +1337 -0
- package/dist/productions-62y489ff.js +505 -0
- package/dist/productions-cgn3fz7d.js +505 -0
- package/dist/runtime/exports.d.ts +23 -0
- package/dist/runtime/exports.d.ts.map +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +6 -4
- package/dist/secrets-4050kqf5.js +91 -0
- package/dist/secrets-p112cajt.js +91 -0
- package/dist/sveltekit/index.js +8 -7
- package/dist/sveltekit/local-bindings.d.ts.map +1 -1
- package/dist/test/index.js +24 -12
- package/dist/test/resolve-service-bindings.d.ts +1 -1
- package/dist/test/resolve-service-bindings.d.ts.map +1 -1
- package/dist/test/simple-context-lifecycle.d.ts.map +1 -1
- package/dist/types-apmt10yj.js +705 -0
- package/dist/types-ttrrgdfj.js +705 -0
- package/dist/vite/index.js +5 -5
- package/dist/vite/plugin-context.d.ts.map +1 -1
- package/dist/vite/plugin-programmatic.d.ts.map +1 -1
- package/dist/worker-2k1jyr6p.js +513 -0
- package/dist/worker-jqgn6jyj.js +513 -0
- package/package.json +1 -1
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
import {
|
|
2
|
+
browserBindingSchema,
|
|
3
|
+
getSingleBrowserBindingName,
|
|
4
|
+
normalizeArtifactsBinding,
|
|
5
|
+
normalizeCompatibilityFlags,
|
|
6
|
+
normalizeD1Binding,
|
|
7
|
+
normalizeDOBinding,
|
|
8
|
+
normalizeDispatchNamespaceBinding,
|
|
9
|
+
normalizeHyperdriveBinding,
|
|
10
|
+
normalizeImagesBinding,
|
|
11
|
+
normalizeKVBinding,
|
|
12
|
+
normalizeMediaBinding,
|
|
13
|
+
normalizeMtlsCertificateBinding,
|
|
14
|
+
normalizePipelineBinding,
|
|
15
|
+
normalizeSecretsStoreBinding,
|
|
16
|
+
normalizeWorkflowBinding,
|
|
17
|
+
resolveConfigForEnvironment
|
|
18
|
+
} from "./index-0bv2qjs1.js";
|
|
19
|
+
import {
|
|
20
|
+
__require
|
|
21
|
+
} from "./index-37x76zdn.js";
|
|
22
|
+
|
|
23
|
+
// src/config/compiler/paths.ts
|
|
24
|
+
import { basename, isAbsolute, relative, resolve } from "pathe";
|
|
25
|
+
function stringifyConfig(config) {
|
|
26
|
+
const header = `// Generated by devflare — Do not edit directly
|
|
27
|
+
// Edit devflare.config.ts instead
|
|
28
|
+
|
|
29
|
+
`;
|
|
30
|
+
return header + JSON.stringify(config, null, "\t");
|
|
31
|
+
}
|
|
32
|
+
function rebasePathForConfigDir(projectRoot, configDir, pathValue) {
|
|
33
|
+
const absolutePath = isAbsolute(pathValue) ? pathValue : resolve(projectRoot, pathValue);
|
|
34
|
+
return relative(configDir, absolutePath).replace(/\\/g, "/");
|
|
35
|
+
}
|
|
36
|
+
function isLocalContainerPath(pathValue) {
|
|
37
|
+
return pathValue === "Dockerfile" || pathValue.startsWith(".") || pathValue.startsWith("/") || pathValue.startsWith("\\") || isAbsolute(pathValue) || pathValue.endsWith("/Dockerfile") || pathValue.endsWith("\\Dockerfile");
|
|
38
|
+
}
|
|
39
|
+
function pathIsInsideDirectory(directoryPath, candidatePath) {
|
|
40
|
+
const normalizedDirectoryPath = directoryPath.replace(/\\/g, "/");
|
|
41
|
+
const normalizedCandidatePath = candidatePath.replace(/\\/g, "/");
|
|
42
|
+
return normalizedCandidatePath === normalizedDirectoryPath || normalizedCandidatePath.startsWith(`${normalizedDirectoryPath}/`);
|
|
43
|
+
}
|
|
44
|
+
function isolateViteBuildOutputPaths(projectRoot, config) {
|
|
45
|
+
const assetsDirectory = config.assets?.directory;
|
|
46
|
+
if (!assetsDirectory) {
|
|
47
|
+
return config;
|
|
48
|
+
}
|
|
49
|
+
const isolatedAssetsDirectoryPath = resolve(projectRoot, ".devflare", "vite-build-output", basename(assetsDirectory));
|
|
50
|
+
const isolatedAssetsDirectory = relative(projectRoot, isolatedAssetsDirectoryPath).replace(/\\/g, "/");
|
|
51
|
+
const isolatedConfig = {
|
|
52
|
+
...config,
|
|
53
|
+
assets: config.assets ? {
|
|
54
|
+
...config.assets,
|
|
55
|
+
directory: isolatedAssetsDirectory
|
|
56
|
+
} : config.assets
|
|
57
|
+
};
|
|
58
|
+
if (!config.main) {
|
|
59
|
+
return isolatedConfig;
|
|
60
|
+
}
|
|
61
|
+
const originalAssetsDirectoryPath = resolve(projectRoot, assetsDirectory);
|
|
62
|
+
const originalMainEntryPath = resolve(projectRoot, config.main);
|
|
63
|
+
if (!pathIsInsideDirectory(originalAssetsDirectoryPath, originalMainEntryPath)) {
|
|
64
|
+
return isolatedConfig;
|
|
65
|
+
}
|
|
66
|
+
const relativeMainEntryPath = relative(originalAssetsDirectoryPath, originalMainEntryPath);
|
|
67
|
+
const isolatedMainEntryPath = resolve(isolatedAssetsDirectoryPath, relativeMainEntryPath);
|
|
68
|
+
return {
|
|
69
|
+
...isolatedConfig,
|
|
70
|
+
main: relative(projectRoot, isolatedMainEntryPath).replace(/\\/g, "/")
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function rebaseWranglerConfigPaths(projectRoot, configDir, config) {
|
|
74
|
+
return {
|
|
75
|
+
...config,
|
|
76
|
+
...config.main ? { main: rebasePathForConfigDir(projectRoot, configDir, config.main) } : {},
|
|
77
|
+
...config.assets?.directory ? {
|
|
78
|
+
assets: {
|
|
79
|
+
...config.assets,
|
|
80
|
+
directory: rebasePathForConfigDir(projectRoot, configDir, config.assets.directory)
|
|
81
|
+
}
|
|
82
|
+
} : {},
|
|
83
|
+
...config.containers ? {
|
|
84
|
+
containers: config.containers.map((container) => ({
|
|
85
|
+
...container,
|
|
86
|
+
image: isLocalContainerPath(container.image) ? rebasePathForConfigDir(projectRoot, configDir, container.image) : container.image,
|
|
87
|
+
...container.image_build_context && {
|
|
88
|
+
image_build_context: rebasePathForConfigDir(projectRoot, configDir, container.image_build_context)
|
|
89
|
+
}
|
|
90
|
+
}))
|
|
91
|
+
} : {}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
async function writeWranglerConfig(cwd, config, filename = "wrangler.jsonc") {
|
|
95
|
+
const { resolve: resolve2 } = await import("pathe");
|
|
96
|
+
const fs = await import("node:fs/promises");
|
|
97
|
+
try {
|
|
98
|
+
await fs.mkdir(cwd, { recursive: true });
|
|
99
|
+
} catch {}
|
|
100
|
+
const content = stringifyConfig(config);
|
|
101
|
+
const wranglerPath = resolve2(cwd, filename);
|
|
102
|
+
await fs.writeFile(wranglerPath, content, "utf-8");
|
|
103
|
+
return wranglerPath;
|
|
104
|
+
}
|
|
105
|
+
async function readWranglerConfig(filePath) {
|
|
106
|
+
const fs = await import("node:fs/promises");
|
|
107
|
+
const { parse } = await import("jsonc-parser");
|
|
108
|
+
const content = await fs.readFile(filePath, "utf-8");
|
|
109
|
+
const parsedConfig = parse(content);
|
|
110
|
+
if (!parsedConfig || typeof parsedConfig !== "object") {
|
|
111
|
+
throw new Error(`Could not parse Wrangler config at ${filePath}.`);
|
|
112
|
+
}
|
|
113
|
+
return parsedConfig;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/config/compiler/bindings.ts
|
|
117
|
+
function getWranglerD1DatabaseBinding(bindingName, bindingConfig, options = {}) {
|
|
118
|
+
const normalized = normalizeD1Binding(bindingConfig);
|
|
119
|
+
if (normalized.databaseId) {
|
|
120
|
+
return {
|
|
121
|
+
binding: bindingName,
|
|
122
|
+
database_id: normalized.databaseId
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
if (options.preserveNamedBindings && normalized.name) {
|
|
126
|
+
return {
|
|
127
|
+
binding: bindingName,
|
|
128
|
+
database_name: normalized.name
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
throw new Error(`D1 binding "${bindingName}" is configured by name (${normalized.name}) and must be resolved before compiling Wrangler config. Use loadResolvedConfig() or resolveConfigResources() for build/deploy/automation flows.`);
|
|
132
|
+
}
|
|
133
|
+
function getWranglerKVNamespaceBinding(bindingName, bindingConfig, options = {}) {
|
|
134
|
+
const normalized = normalizeKVBinding(bindingConfig);
|
|
135
|
+
if (normalized.namespaceId) {
|
|
136
|
+
return {
|
|
137
|
+
binding: bindingName,
|
|
138
|
+
id: normalized.namespaceId
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
if (options.preserveNamedBindings && normalized.name) {
|
|
142
|
+
return {
|
|
143
|
+
binding: bindingName,
|
|
144
|
+
name: normalized.name
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
throw new Error(`KV binding "${bindingName}" is configured by name (${normalized.name}) and must be resolved before compiling Wrangler config. Use loadResolvedConfig() or resolveConfigResources() for build/deploy/automation flows.`);
|
|
148
|
+
}
|
|
149
|
+
function getWranglerHyperdriveBinding(bindingName, bindingConfig, options = {}) {
|
|
150
|
+
const normalized = normalizeHyperdriveBinding(bindingConfig);
|
|
151
|
+
if (normalized.configurationId) {
|
|
152
|
+
return {
|
|
153
|
+
binding: bindingName,
|
|
154
|
+
id: normalized.configurationId,
|
|
155
|
+
...normalized.localConnectionString && {
|
|
156
|
+
localConnectionString: normalized.localConnectionString
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
if (options.preserveNamedBindings && normalized.name) {
|
|
161
|
+
return {
|
|
162
|
+
binding: bindingName,
|
|
163
|
+
name: normalized.name,
|
|
164
|
+
...normalized.localConnectionString && {
|
|
165
|
+
localConnectionString: normalized.localConnectionString
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
throw new Error(`Hyperdrive binding "${bindingName}" is configured by name (${normalized.name}) and must be resolved before compiling Wrangler config. Use loadResolvedConfig() or resolveConfigResources() for build/deploy/automation flows.`);
|
|
170
|
+
}
|
|
171
|
+
function getWranglerBrowserBinding(browserBindings) {
|
|
172
|
+
if (!browserBindings) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const parsed = browserBindingSchema.parse(browserBindings);
|
|
176
|
+
const bindingName = getSingleBrowserBindingName(parsed);
|
|
177
|
+
if (!bindingName) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
const bindingConfig = parsed[bindingName];
|
|
181
|
+
return {
|
|
182
|
+
binding: bindingName,
|
|
183
|
+
...typeof bindingConfig === "object" && bindingConfig.remote !== undefined && {
|
|
184
|
+
remote: bindingConfig.remote
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function compileBindings(bindings, result, options = {}, defaultSecretsStoreId) {
|
|
189
|
+
if (bindings.kv) {
|
|
190
|
+
result.kv_namespaces = Object.entries(bindings.kv).map(([binding, namespace]) => {
|
|
191
|
+
return getWranglerKVNamespaceBinding(binding, namespace, options);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if (bindings.d1) {
|
|
195
|
+
result.d1_databases = Object.entries(bindings.d1).map(([binding, database_id]) => {
|
|
196
|
+
return getWranglerD1DatabaseBinding(binding, database_id, options);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
if (bindings.r2) {
|
|
200
|
+
result.r2_buckets = Object.entries(bindings.r2).map(([binding, bucket_name]) => ({
|
|
201
|
+
binding,
|
|
202
|
+
bucket_name
|
|
203
|
+
}));
|
|
204
|
+
}
|
|
205
|
+
if (bindings.durableObjects) {
|
|
206
|
+
result.durable_objects = {
|
|
207
|
+
bindings: Object.entries(bindings.durableObjects).map(([name, config]) => {
|
|
208
|
+
const normalized = normalizeDOBinding(config);
|
|
209
|
+
const binding = {
|
|
210
|
+
name,
|
|
211
|
+
class_name: normalized.className
|
|
212
|
+
};
|
|
213
|
+
if (normalized.kind === "cross-worker" && normalized.scriptName) {
|
|
214
|
+
binding.script_name = normalized.scriptName;
|
|
215
|
+
}
|
|
216
|
+
return binding;
|
|
217
|
+
})
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
if (bindings.queues) {
|
|
221
|
+
result.queues = {};
|
|
222
|
+
if (bindings.queues.producers) {
|
|
223
|
+
result.queues.producers = Object.entries(bindings.queues.producers).map(([binding, queue]) => ({ binding, queue }));
|
|
224
|
+
}
|
|
225
|
+
if (bindings.queues.consumers) {
|
|
226
|
+
result.queues.consumers = bindings.queues.consumers.map((consumer) => ({
|
|
227
|
+
queue: consumer.queue,
|
|
228
|
+
...consumer.maxBatchSize && { max_batch_size: consumer.maxBatchSize },
|
|
229
|
+
...consumer.maxBatchTimeout && { max_batch_timeout: consumer.maxBatchTimeout },
|
|
230
|
+
...consumer.maxRetries && { max_retries: consumer.maxRetries },
|
|
231
|
+
...consumer.deadLetterQueue && { dead_letter_queue: consumer.deadLetterQueue },
|
|
232
|
+
...consumer.maxConcurrency && { max_concurrency: consumer.maxConcurrency },
|
|
233
|
+
...consumer.retryDelay && { retry_delay: consumer.retryDelay }
|
|
234
|
+
}));
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (bindings.rateLimits) {
|
|
238
|
+
result.ratelimits = Object.entries(bindings.rateLimits).map(([name, config]) => ({
|
|
239
|
+
name,
|
|
240
|
+
namespace_id: config.namespaceId,
|
|
241
|
+
simple: {
|
|
242
|
+
limit: config.simple.limit,
|
|
243
|
+
period: config.simple.period
|
|
244
|
+
}
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
247
|
+
if (bindings.versionMetadata) {
|
|
248
|
+
result.version_metadata = {
|
|
249
|
+
binding: bindings.versionMetadata.binding
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
if (bindings.workerLoaders) {
|
|
253
|
+
result.worker_loaders = Object.keys(bindings.workerLoaders).map((binding) => ({ binding }));
|
|
254
|
+
}
|
|
255
|
+
if (bindings.mtlsCertificates) {
|
|
256
|
+
result.mtls_certificates = Object.entries(bindings.mtlsCertificates).map(([binding, config]) => {
|
|
257
|
+
const normalized = normalizeMtlsCertificateBinding(config);
|
|
258
|
+
return {
|
|
259
|
+
binding,
|
|
260
|
+
certificate_id: normalized.certificateId,
|
|
261
|
+
...normalized.remote !== undefined && { remote: normalized.remote }
|
|
262
|
+
};
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
if (bindings.dispatchNamespaces) {
|
|
266
|
+
result.dispatch_namespaces = Object.entries(bindings.dispatchNamespaces).map(([binding, config]) => {
|
|
267
|
+
const normalized = normalizeDispatchNamespaceBinding(config);
|
|
268
|
+
return {
|
|
269
|
+
binding,
|
|
270
|
+
namespace: normalized.namespace,
|
|
271
|
+
...normalized.outbound && { outbound: normalized.outbound },
|
|
272
|
+
...normalized.remote !== undefined && { remote: normalized.remote }
|
|
273
|
+
};
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
if (bindings.workflows) {
|
|
277
|
+
result.workflows = Object.entries(bindings.workflows).map(([binding, config]) => {
|
|
278
|
+
const normalized = normalizeWorkflowBinding(config);
|
|
279
|
+
return {
|
|
280
|
+
binding,
|
|
281
|
+
name: normalized.name,
|
|
282
|
+
class_name: normalized.className,
|
|
283
|
+
...normalized.scriptName && { script_name: normalized.scriptName },
|
|
284
|
+
...normalized.remote !== undefined && { remote: normalized.remote },
|
|
285
|
+
...normalized.limits && { limits: normalized.limits }
|
|
286
|
+
};
|
|
287
|
+
});
|
|
288
|
+
}
|
|
289
|
+
if (bindings.pipelines) {
|
|
290
|
+
result.pipelines = Object.entries(bindings.pipelines).map(([binding, config]) => {
|
|
291
|
+
const normalized = normalizePipelineBinding(config);
|
|
292
|
+
return {
|
|
293
|
+
binding,
|
|
294
|
+
pipeline: normalized.pipeline,
|
|
295
|
+
...normalized.remote !== undefined && { remote: normalized.remote }
|
|
296
|
+
};
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
if (bindings.images) {
|
|
300
|
+
const [entry] = Object.entries(bindings.images);
|
|
301
|
+
if (entry) {
|
|
302
|
+
const [binding, config] = entry;
|
|
303
|
+
const normalized = normalizeImagesBinding(binding, config);
|
|
304
|
+
result.images = {
|
|
305
|
+
binding: normalized.binding,
|
|
306
|
+
...normalized.remote !== undefined && { remote: normalized.remote }
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
if (bindings.media) {
|
|
311
|
+
const [entry] = Object.entries(bindings.media);
|
|
312
|
+
if (entry) {
|
|
313
|
+
const [binding, config] = entry;
|
|
314
|
+
const normalized = normalizeMediaBinding(binding, config);
|
|
315
|
+
result.media = {
|
|
316
|
+
binding: normalized.binding,
|
|
317
|
+
...normalized.remote !== undefined && { remote: normalized.remote }
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
if (bindings.artifacts) {
|
|
322
|
+
result.artifacts = Object.entries(bindings.artifacts).map(([binding, config]) => {
|
|
323
|
+
const normalized = normalizeArtifactsBinding(config);
|
|
324
|
+
return {
|
|
325
|
+
binding,
|
|
326
|
+
namespace: normalized.namespace,
|
|
327
|
+
...normalized.remote !== undefined && { remote: normalized.remote }
|
|
328
|
+
};
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
if (bindings.secretsStore) {
|
|
332
|
+
result.secrets_store_secrets = Object.entries(bindings.secretsStore).map(([binding, config]) => {
|
|
333
|
+
const normalized = normalizeSecretsStoreBinding(config, defaultSecretsStoreId, binding);
|
|
334
|
+
return {
|
|
335
|
+
binding,
|
|
336
|
+
store_id: normalized.storeId,
|
|
337
|
+
secret_name: normalized.secretName
|
|
338
|
+
};
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
if (bindings.services) {
|
|
342
|
+
result.services = Object.entries(bindings.services).map(([binding, config]) => ({
|
|
343
|
+
binding,
|
|
344
|
+
service: config.service,
|
|
345
|
+
...config.entrypoint && { entrypoint: config.entrypoint },
|
|
346
|
+
...config.environment && { environment: config.environment }
|
|
347
|
+
}));
|
|
348
|
+
}
|
|
349
|
+
if (bindings.ai?.binding) {
|
|
350
|
+
result.ai = {
|
|
351
|
+
binding: bindings.ai.binding,
|
|
352
|
+
...bindings.ai.remote !== undefined && { remote: bindings.ai.remote },
|
|
353
|
+
...bindings.ai.staging !== undefined && { staging: bindings.ai.staging }
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
if (bindings.aiSearchNamespaces) {
|
|
357
|
+
result.ai_search_namespaces = Object.entries(bindings.aiSearchNamespaces).map(([binding, config]) => ({
|
|
358
|
+
binding,
|
|
359
|
+
namespace: config.namespace,
|
|
360
|
+
...config.remote !== undefined && { remote: config.remote }
|
|
361
|
+
}));
|
|
362
|
+
}
|
|
363
|
+
if (bindings.aiSearch) {
|
|
364
|
+
result.ai_search = Object.entries(bindings.aiSearch).map(([binding, config]) => ({
|
|
365
|
+
binding,
|
|
366
|
+
instance_name: config.instanceName,
|
|
367
|
+
...config.remote !== undefined && { remote: config.remote }
|
|
368
|
+
}));
|
|
369
|
+
}
|
|
370
|
+
if (bindings.vectorize) {
|
|
371
|
+
result.vectorize = Object.entries(bindings.vectorize).map(([binding, config]) => ({
|
|
372
|
+
binding,
|
|
373
|
+
index_name: config.indexName,
|
|
374
|
+
...config.remote !== undefined && { remote: config.remote }
|
|
375
|
+
}));
|
|
376
|
+
}
|
|
377
|
+
if (bindings.hyperdrive) {
|
|
378
|
+
result.hyperdrive = Object.entries(bindings.hyperdrive).map(([binding, config]) => {
|
|
379
|
+
return getWranglerHyperdriveBinding(binding, config, options);
|
|
380
|
+
});
|
|
381
|
+
}
|
|
382
|
+
const browserBinding = getWranglerBrowserBinding(bindings.browser);
|
|
383
|
+
if (browserBinding) {
|
|
384
|
+
result.browser = browserBinding;
|
|
385
|
+
}
|
|
386
|
+
if (bindings.analyticsEngine) {
|
|
387
|
+
result.analytics_engine_datasets = Object.entries(bindings.analyticsEngine).map(([binding, config]) => ({
|
|
388
|
+
binding,
|
|
389
|
+
dataset: config.dataset
|
|
390
|
+
}));
|
|
391
|
+
}
|
|
392
|
+
if (bindings.sendEmail) {
|
|
393
|
+
result.send_email = Object.entries(bindings.sendEmail).map(([name, config]) => ({
|
|
394
|
+
name,
|
|
395
|
+
...config.destinationAddress && {
|
|
396
|
+
destination_address: config.destinationAddress
|
|
397
|
+
},
|
|
398
|
+
...config.allowedDestinationAddresses && {
|
|
399
|
+
allowed_destination_addresses: config.allowedDestinationAddresses
|
|
400
|
+
},
|
|
401
|
+
...config.allowedSenderAddresses && {
|
|
402
|
+
allowed_sender_addresses: config.allowedSenderAddresses
|
|
403
|
+
}
|
|
404
|
+
}));
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// src/config/compiler/core-helpers.ts
|
|
409
|
+
function compileWranglerMigrations(migrations) {
|
|
410
|
+
return migrations.map((migration) => ({
|
|
411
|
+
tag: migration.tag,
|
|
412
|
+
...migration.new_classes && { new_classes: migration.new_classes },
|
|
413
|
+
...migration.renamed_classes && {
|
|
414
|
+
renamed_classes: migration.renamed_classes.map((renamedClass) => ({
|
|
415
|
+
from: renamedClass.from,
|
|
416
|
+
to: renamedClass.to
|
|
417
|
+
}))
|
|
418
|
+
},
|
|
419
|
+
...migration.deleted_classes && { deleted_classes: migration.deleted_classes },
|
|
420
|
+
...migration.new_sqlite_classes && { new_sqlite_classes: migration.new_sqlite_classes }
|
|
421
|
+
}));
|
|
422
|
+
}
|
|
423
|
+
function compileModuleOptions(config, result) {
|
|
424
|
+
if (config.rules && config.rules.length > 0) {
|
|
425
|
+
result.rules = config.rules;
|
|
426
|
+
}
|
|
427
|
+
if (config.findAdditionalModules !== undefined) {
|
|
428
|
+
result.find_additional_modules = config.findAdditionalModules;
|
|
429
|
+
}
|
|
430
|
+
if (config.baseDir) {
|
|
431
|
+
result.base_dir = config.baseDir;
|
|
432
|
+
}
|
|
433
|
+
if (config.preserveFileNames !== undefined) {
|
|
434
|
+
result.preserve_file_names = config.preserveFileNames;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
function compileContainers(config, result) {
|
|
438
|
+
if (!config.containers || config.containers.length === 0) {
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
result.containers = config.containers.map((container) => ({
|
|
442
|
+
class_name: container.className,
|
|
443
|
+
image: container.image,
|
|
444
|
+
...container.maxInstances !== undefined && { max_instances: container.maxInstances },
|
|
445
|
+
...container.instanceType && { instance_type: container.instanceType },
|
|
446
|
+
...container.name && { name: container.name },
|
|
447
|
+
...container.imageBuildContext && { image_build_context: container.imageBuildContext },
|
|
448
|
+
...container.imageVars && { image_vars: container.imageVars },
|
|
449
|
+
...container.rolloutActiveGracePeriod !== undefined && {
|
|
450
|
+
rollout_active_grace_period: container.rolloutActiveGracePeriod
|
|
451
|
+
},
|
|
452
|
+
...container.rolloutStepPercentage !== undefined && {
|
|
453
|
+
rollout_step_percentage: container.rolloutStepPercentage
|
|
454
|
+
}
|
|
455
|
+
}));
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// src/config/local-dev-vars.ts
|
|
459
|
+
import { readFile } from "node:fs/promises";
|
|
460
|
+
import { resolve as resolve2 } from "pathe";
|
|
461
|
+
function parseEnvValue(value) {
|
|
462
|
+
const trimmed = value.trim();
|
|
463
|
+
const quote = trimmed[0];
|
|
464
|
+
if ((quote === '"' || quote === "'" || quote === "`") && trimmed.endsWith(quote) && trimmed.length >= 2) {
|
|
465
|
+
const inner = trimmed.slice(1, -1);
|
|
466
|
+
return quote === '"' ? inner.replace(/\\n/g, `
|
|
467
|
+
`).replace(/\\r/g, "\r").replace(/\\t/g, "\t").replace(/\\"/g, '"').replace(/\\\\/g, "\\") : inner;
|
|
468
|
+
}
|
|
469
|
+
const commentIndex = trimmed.search(/\s+#/);
|
|
470
|
+
return (commentIndex >= 0 ? trimmed.slice(0, commentIndex) : trimmed).trimEnd();
|
|
471
|
+
}
|
|
472
|
+
function parseEnvFile(contents) {
|
|
473
|
+
const vars = {};
|
|
474
|
+
for (const line of contents.split(/\r?\n/)) {
|
|
475
|
+
const trimmed = line.trim();
|
|
476
|
+
if (!trimmed || trimmed.startsWith("#")) {
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
const assignment = trimmed.startsWith("export ") ? trimmed.slice("export ".length).trimStart() : trimmed;
|
|
480
|
+
const equalsIndex = assignment.indexOf("=");
|
|
481
|
+
if (equalsIndex <= 0) {
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
const key = assignment.slice(0, equalsIndex).trim();
|
|
485
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) {
|
|
486
|
+
continue;
|
|
487
|
+
}
|
|
488
|
+
vars[key] = parseEnvValue(assignment.slice(equalsIndex + 1));
|
|
489
|
+
}
|
|
490
|
+
return vars;
|
|
491
|
+
}
|
|
492
|
+
async function readOptionalEnvFile(filePath) {
|
|
493
|
+
try {
|
|
494
|
+
return parseEnvFile(await readFile(filePath, "utf8"));
|
|
495
|
+
} catch (error) {
|
|
496
|
+
if (error.code === "ENOENT") {
|
|
497
|
+
return null;
|
|
498
|
+
}
|
|
499
|
+
throw error;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
async function loadWranglerCompatibleLocalVars(cwd, environment) {
|
|
503
|
+
const environmentDevVars = environment ? await readOptionalEnvFile(resolve2(cwd, `.dev.vars.${environment}`)) : null;
|
|
504
|
+
if (environmentDevVars) {
|
|
505
|
+
return environmentDevVars;
|
|
506
|
+
}
|
|
507
|
+
const devVars = await readOptionalEnvFile(resolve2(cwd, ".dev.vars"));
|
|
508
|
+
if (devVars) {
|
|
509
|
+
return devVars;
|
|
510
|
+
}
|
|
511
|
+
const envFiles = [
|
|
512
|
+
".env",
|
|
513
|
+
".env.local",
|
|
514
|
+
...environment ? [`.env.${environment}`, `.env.${environment}.local`] : []
|
|
515
|
+
];
|
|
516
|
+
const merged = {};
|
|
517
|
+
for (const fileName of envFiles) {
|
|
518
|
+
const values = await readOptionalEnvFile(resolve2(cwd, fileName));
|
|
519
|
+
if (values) {
|
|
520
|
+
Object.assign(merged, values);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
return merged;
|
|
524
|
+
}
|
|
525
|
+
function toWranglerSecretsConfig(secrets) {
|
|
526
|
+
if (!secrets) {
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
const required = Object.entries(secrets).filter(([, config]) => config.required !== false).map(([name]) => name).sort();
|
|
530
|
+
return required.length > 0 ? { required } : undefined;
|
|
531
|
+
}
|
|
532
|
+
async function loadLocalDevVars(options) {
|
|
533
|
+
const activeEnvironment = options.environment ?? process.env.CLOUDFLARE_ENV;
|
|
534
|
+
const localVars = await loadWranglerCompatibleLocalVars(options.cwd, activeEnvironment);
|
|
535
|
+
const secretNames = toWranglerSecretsConfig(options.secrets)?.required;
|
|
536
|
+
const filteredLocalVars = secretNames ? Object.fromEntries(Object.entries(localVars).filter(([name]) => secretNames.includes(name))) : localVars;
|
|
537
|
+
return {
|
|
538
|
+
...options.vars ?? {},
|
|
539
|
+
...filteredLocalVars
|
|
540
|
+
};
|
|
541
|
+
}
|
|
542
|
+
async function applyLocalDevVarsToConfig(config, options) {
|
|
543
|
+
const vars = await loadLocalDevVars({
|
|
544
|
+
...options,
|
|
545
|
+
vars: config.vars,
|
|
546
|
+
secrets: config.secrets
|
|
547
|
+
});
|
|
548
|
+
if (Object.keys(vars).length === 0) {
|
|
549
|
+
return config;
|
|
550
|
+
}
|
|
551
|
+
return {
|
|
552
|
+
...config,
|
|
553
|
+
vars
|
|
554
|
+
};
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
// src/config/compiler/do-workers.ts
|
|
558
|
+
import { resolve as resolve3 } from "pathe";
|
|
559
|
+
|
|
560
|
+
// src/config/compiler.ts
|
|
561
|
+
function compileConfig(config, environment) {
|
|
562
|
+
return compileConfigInternal(config, environment);
|
|
563
|
+
}
|
|
564
|
+
function compileBuildConfig(config, environment, options = {}) {
|
|
565
|
+
return compileConfigInternal(config, environment, {
|
|
566
|
+
preserveNamedBindings: true,
|
|
567
|
+
alreadyResolved: options.alreadyResolved
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
function compileConfigInternal(config, environment, options = {}) {
|
|
571
|
+
const resolvedConfig = options.alreadyResolved ? config : resolveConfigForEnvironment(config, environment);
|
|
572
|
+
const mergedConfig = {
|
|
573
|
+
...resolvedConfig,
|
|
574
|
+
compatibilityFlags: normalizeCompatibilityFlags(resolvedConfig.compatibilityFlags)
|
|
575
|
+
};
|
|
576
|
+
const result = {
|
|
577
|
+
name: mergedConfig.name,
|
|
578
|
+
compatibility_date: mergedConfig.compatibilityDate,
|
|
579
|
+
preview_urls: true,
|
|
580
|
+
workers_dev: true
|
|
581
|
+
};
|
|
582
|
+
if (mergedConfig.accountId) {
|
|
583
|
+
result.account_id = mergedConfig.accountId;
|
|
584
|
+
}
|
|
585
|
+
const mainEntry = mergedConfig.files?.fetch;
|
|
586
|
+
if (typeof mainEntry === "string") {
|
|
587
|
+
result.main = mainEntry;
|
|
588
|
+
}
|
|
589
|
+
compileModuleOptions(mergedConfig, result);
|
|
590
|
+
if (mergedConfig.compatibilityFlags && mergedConfig.compatibilityFlags.length > 0) {
|
|
591
|
+
result.compatibility_flags = mergedConfig.compatibilityFlags;
|
|
592
|
+
}
|
|
593
|
+
if (mergedConfig.bindings) {
|
|
594
|
+
compileBindings(mergedConfig.bindings, result, options, mergedConfig.secretsStoreId);
|
|
595
|
+
}
|
|
596
|
+
if (mergedConfig.triggers?.crons && mergedConfig.triggers.crons.length > 0) {
|
|
597
|
+
result.triggers = { crons: mergedConfig.triggers.crons };
|
|
598
|
+
}
|
|
599
|
+
if (mergedConfig.tailConsumers && mergedConfig.tailConsumers.length > 0) {
|
|
600
|
+
result.tail_consumers = mergedConfig.tailConsumers.map((consumer) => typeof consumer === "string" ? { service: consumer } : {
|
|
601
|
+
service: consumer.service,
|
|
602
|
+
...consumer.environment && { environment: consumer.environment }
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
if (mergedConfig.vars && Object.keys(mergedConfig.vars).length > 0) {
|
|
606
|
+
result.vars = mergedConfig.vars;
|
|
607
|
+
}
|
|
608
|
+
const secrets = toWranglerSecretsConfig(mergedConfig.secrets);
|
|
609
|
+
if (secrets) {
|
|
610
|
+
result.secrets = secrets;
|
|
611
|
+
}
|
|
612
|
+
if (mergedConfig.routes && mergedConfig.routes.length > 0) {
|
|
613
|
+
result.routes = mergedConfig.routes.map((route) => ({
|
|
614
|
+
pattern: route.pattern,
|
|
615
|
+
...route.zone_name && { zone_name: route.zone_name },
|
|
616
|
+
...route.zone_id && { zone_id: route.zone_id },
|
|
617
|
+
...route.custom_domain !== undefined && { custom_domain: route.custom_domain }
|
|
618
|
+
}));
|
|
619
|
+
}
|
|
620
|
+
if (mergedConfig.assets?.directory) {
|
|
621
|
+
result.assets = {
|
|
622
|
+
directory: mergedConfig.assets.directory,
|
|
623
|
+
...mergedConfig.assets.binding && { binding: mergedConfig.assets.binding },
|
|
624
|
+
...mergedConfig.assets.html_handling && {
|
|
625
|
+
html_handling: mergedConfig.assets.html_handling
|
|
626
|
+
},
|
|
627
|
+
...mergedConfig.assets.not_found_handling && {
|
|
628
|
+
not_found_handling: mergedConfig.assets.not_found_handling
|
|
629
|
+
},
|
|
630
|
+
...mergedConfig.assets.run_worker_first !== undefined && {
|
|
631
|
+
run_worker_first: mergedConfig.assets.run_worker_first
|
|
632
|
+
}
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
if (mergedConfig.placement) {
|
|
636
|
+
result.placement = mergedConfig.placement;
|
|
637
|
+
}
|
|
638
|
+
if (mergedConfig.observability) {
|
|
639
|
+
result.observability = mergedConfig.observability;
|
|
640
|
+
}
|
|
641
|
+
if (mergedConfig.limits) {
|
|
642
|
+
result.limits = mergedConfig.limits;
|
|
643
|
+
}
|
|
644
|
+
compileContainers(mergedConfig, result);
|
|
645
|
+
if (mergedConfig.migrations && mergedConfig.migrations.length > 0) {
|
|
646
|
+
result.migrations = compileWranglerMigrations(mergedConfig.migrations);
|
|
647
|
+
}
|
|
648
|
+
if (mergedConfig.wrangler?.passthrough) {
|
|
649
|
+
Object.assign(result, mergedConfig.wrangler.passthrough);
|
|
650
|
+
}
|
|
651
|
+
return result;
|
|
652
|
+
}
|
|
653
|
+
function compileToProgrammaticConfig(config, environment, options = {}) {
|
|
654
|
+
return options.preserveNamedBindings ? compileBuildConfig(config, environment) : compileConfig(config, environment);
|
|
655
|
+
}
|
|
656
|
+
// src/config/service-bindings-validation.ts
|
|
657
|
+
class ServiceBindingValidationError extends Error {
|
|
658
|
+
code = "SERVICE_BINDING_VALIDATION_ERROR";
|
|
659
|
+
missing;
|
|
660
|
+
constructor(missing, accountId) {
|
|
661
|
+
super(`Service binding(s) reference worker(s) that do not exist in Cloudflare account ${accountId}: ` + missing.join(", ") + `. Check the 'services' map in devflare.config.ts for typos or deploy the target worker(s) first.`);
|
|
662
|
+
this.name = "ServiceBindingValidationError";
|
|
663
|
+
this.missing = missing;
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
function collectReferencedServiceNames(config) {
|
|
667
|
+
const services = config.bindings?.services;
|
|
668
|
+
if (!services) {
|
|
669
|
+
return [];
|
|
670
|
+
}
|
|
671
|
+
const names = new Set;
|
|
672
|
+
for (const binding of Object.values(services)) {
|
|
673
|
+
if (binding && typeof binding === "object" && typeof binding.service === "string") {
|
|
674
|
+
const name = binding.service.trim();
|
|
675
|
+
if (name.length > 0) {
|
|
676
|
+
names.add(name);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
return [...names];
|
|
681
|
+
}
|
|
682
|
+
async function validateServiceBindings(config, accountId, options) {
|
|
683
|
+
const referenced = collectReferencedServiceNames(config);
|
|
684
|
+
if (referenced.length === 0) {
|
|
685
|
+
return;
|
|
686
|
+
}
|
|
687
|
+
const selfName = options.selfWorkerName?.trim();
|
|
688
|
+
const toValidate = selfName ? referenced.filter((name) => name !== selfName) : referenced;
|
|
689
|
+
if (toValidate.length === 0) {
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
const workers = await options.listWorkers(accountId);
|
|
693
|
+
const workerNames = new Set(workers.map((worker) => worker.name));
|
|
694
|
+
const missing = toValidate.filter((name) => !workerNames.has(name));
|
|
695
|
+
if (missing.length > 0) {
|
|
696
|
+
throw new ServiceBindingValidationError(missing, accountId);
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
export { applyLocalDevVarsToConfig, stringifyConfig, isolateViteBuildOutputPaths, rebaseWranglerConfigPaths, writeWranglerConfig, readWranglerConfig, compileConfig, compileBuildConfig, compileToProgrammaticConfig, ServiceBindingValidationError, validateServiceBindings };
|