devflare 1.0.0-next.33 → 1.0.0-next.35
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/LICENSE +21 -0
- package/LLM.md +9 -9
- package/bin/devflare.js +1 -1
- package/dist/{account-p9eywryw.js → account-4tgh03a8.js} +4 -6
- package/dist/browser.js +2340 -19
- package/dist/{build-8bn7frg8.js → build-rh7ghrgw.js} +7 -10
- package/dist/cli/index.js +1377 -6
- package/dist/cloudflare/index.js +2 -3
- package/dist/config/resolve-phased.d.ts.map +1 -1
- package/dist/config-entry.js +1 -9
- package/dist/{config-gphd6wx7.js → config-ghk2bxj3.js} +3 -6
- package/dist/{deploy-vpcp41fw.js → deploy-6hzv76sh.js} +13 -17
- package/dist/{dev-9scy9gap.js → dev-mkhjdwh7.js} +971 -73
- package/dist/{doctor-swfeeqny.js → doctor-0ng5qrr1.js} +2 -3
- package/dist/{index-e7xn30bh.js → index-0cc05hzv.js} +1 -1
- package/dist/{index-t0r7evpw.js → index-293aqfy4.js} +7 -9
- package/dist/{index-3t0e51a0.js → index-2yv7w548.js} +1 -1
- package/dist/{index-ksqth51q.js → index-a8pnvg3r.js} +1 -1
- package/dist/{index-bhxj7ff6.js → index-e251zhns.js} +943 -117
- package/dist/{index-2xz4etye.js → index-hvtd936d.js} +3 -0
- package/dist/{index-13sfensw.js → index-kcp7y951.js} +2 -13
- package/dist/{index-w8c8tjc5.js → index-mek9msfv.js} +1 -4
- package/dist/{index-dem45895.js → index-mjvybn39.js} +1 -1
- package/dist/{index-x0wpeb3x.js → index-phcrvs6d.js} +112 -2
- package/dist/{index-b20xx2vk.js → index-se4kw8tm.js} +4 -6
- package/dist/{index-pd97hk2j.js → index-x8s9rwfh.js} +466 -19
- package/dist/index.js +1 -42
- package/dist/{login-7vyzeqy4.js → login-4h1sfsed.js} +4 -6
- package/dist/{previews-jfbectpc.js → previews-qr7c5j8h.js} +10 -14
- package/dist/{productions-49ct4kjm.js → productions-xpmd6bw8.js} +6 -9
- package/dist/{remote-6876k6mz.js → remote-kqcvhnfx.js} +100 -5
- package/dist/runtime/index.js +0 -63
- package/dist/{secrets-9ne7armr.js → secrets-6wbdsdek.js} +3 -5
- package/dist/sveltekit/index.js +0 -263
- package/dist/test/binding-hints.d.ts +2 -3
- package/dist/test/binding-hints.d.ts.map +1 -1
- package/dist/test/index.js +2 -4626
- package/dist/{types-zekmbebk.js → types-ahnnpphq.js} +6 -8
- package/dist/vite/index.js +7 -9
- package/dist/{worker-706g8qeh.js → worker-1yg72jxg.js} +6 -9
- package/package.json +5 -3
- package/dist/index-1trss579.js +0 -2299
- package/dist/index-34dejneh.js +0 -214
- package/dist/index-3z20d3kd.js +0 -1380
- package/dist/index-4xmtkg9g.js +0 -109
- package/dist/index-62b3gt2g.js +0 -12
- package/dist/index-97rfy7n2.js +0 -413
- package/dist/index-c4zd39tc.js +0 -155
- package/dist/index-dgx495pv.js +0 -1036
- package/dist/index-dm9q84c7.js +0 -360
- package/dist/index-pmnb7eke.js +0 -109
- package/dist/index-t23wq5js.js +0 -111
- package/dist/index-wxdcrzcp.js +0 -475
- package/dist/index-x2fd1361.js +0 -133
- package/dist/index-za0r01bx.js +0 -588
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
resolveServiceBindings
|
|
6
|
-
} from "./index-dgx495pv.js";
|
|
2
|
+
discoverEntrypointsSync,
|
|
3
|
+
resolvePackageSpecifier
|
|
4
|
+
} from "./index-by27mzra.js";
|
|
7
5
|
import {
|
|
8
|
-
DEFAULT_DO_PATTERN
|
|
6
|
+
DEFAULT_DO_PATTERN,
|
|
7
|
+
findFiles,
|
|
8
|
+
findFilesSync
|
|
9
9
|
} from "./index-5dkjffqz.js";
|
|
10
|
-
import {
|
|
11
|
-
SUPPORTED_WORKER_EXTENSIONS
|
|
12
|
-
} from "./index-7m557715.js";
|
|
13
10
|
import {
|
|
14
11
|
compileBuildConfig,
|
|
15
12
|
compileConfig,
|
|
@@ -17,24 +14,39 @@ import {
|
|
|
17
14
|
isolateViteBuildOutputPaths,
|
|
18
15
|
rebaseWranglerConfigPaths,
|
|
19
16
|
writeWranglerConfig
|
|
20
|
-
} from "./index-
|
|
17
|
+
} from "./index-mek9msfv.js";
|
|
21
18
|
import {
|
|
19
|
+
configSchema,
|
|
20
|
+
getLocalD1DatabaseIdentifier,
|
|
21
|
+
getLocalKVNamespaceIdentifier,
|
|
22
22
|
loadConfig,
|
|
23
|
-
|
|
23
|
+
normalizeArtifactsBinding,
|
|
24
24
|
normalizeDOBinding,
|
|
25
|
+
normalizeDispatchNamespaceBinding,
|
|
26
|
+
normalizeHyperdriveBinding,
|
|
27
|
+
normalizeImagesBinding,
|
|
28
|
+
normalizeMediaBinding,
|
|
29
|
+
normalizeMtlsCertificateBinding,
|
|
30
|
+
normalizePipelineBinding,
|
|
31
|
+
normalizeSecretsStoreBinding,
|
|
32
|
+
normalizeWorkflowBinding,
|
|
33
|
+
resolveConfigEnvVars,
|
|
25
34
|
resolveConfigForEnvironment,
|
|
26
35
|
resolveConfigPath,
|
|
27
36
|
resolveResources
|
|
28
|
-
} from "./index-
|
|
37
|
+
} from "./index-x8s9rwfh.js";
|
|
29
38
|
import {
|
|
30
|
-
|
|
31
|
-
|
|
39
|
+
SUPPORTED_WORKER_EXTENSIONS,
|
|
40
|
+
transformWorkerEntrypoint
|
|
41
|
+
} from "./index-7m557715.js";
|
|
42
|
+
import {
|
|
43
|
+
findDurableObjectClasses
|
|
44
|
+
} from "./index-p93cngdp.js";
|
|
32
45
|
import {
|
|
33
46
|
__require
|
|
34
47
|
} from "./index-37x76zdn.js";
|
|
35
|
-
|
|
36
48
|
// src/vite/plugin.ts
|
|
37
|
-
import { dirname as
|
|
49
|
+
import { dirname as dirname3, resolve as resolve6 } from "pathe";
|
|
38
50
|
|
|
39
51
|
// src/vite/plugin-config-hook.ts
|
|
40
52
|
async function tryLoadDevflareConfig(cwd, configPath, command) {
|
|
@@ -100,13 +112,897 @@ async function buildPluginConfigHookResult(cwd, options, command, existingDefine
|
|
|
100
112
|
}
|
|
101
113
|
|
|
102
114
|
// src/vite/plugin-context.ts
|
|
103
|
-
import { isAbsolute, relative as
|
|
115
|
+
import { isAbsolute, relative as relative3, resolve as resolve5 } from "pathe";
|
|
116
|
+
|
|
117
|
+
// src/test/resolve-service-bindings.ts
|
|
118
|
+
import { existsSync, readFileSync } from "fs";
|
|
119
|
+
import { dirname, join, resolve } from "path";
|
|
120
|
+
|
|
121
|
+
// src/dev-server/miniflare-bindings.ts
|
|
122
|
+
function buildQueueProducers(bindings) {
|
|
123
|
+
if (!bindings.queues?.producers) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const producers = {};
|
|
127
|
+
for (const [bindingName, queueName] of Object.entries(bindings.queues.producers)) {
|
|
128
|
+
producers[bindingName] = { queueName };
|
|
129
|
+
}
|
|
130
|
+
return producers;
|
|
131
|
+
}
|
|
132
|
+
function buildQueueConsumers(bindings) {
|
|
133
|
+
if (!bindings.queues?.consumers || bindings.queues.consumers.length === 0) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const consumers = {};
|
|
137
|
+
for (const consumer of bindings.queues.consumers) {
|
|
138
|
+
consumers[consumer.queue] = {
|
|
139
|
+
...consumer.maxBatchSize !== undefined && { maxBatchSize: consumer.maxBatchSize },
|
|
140
|
+
...consumer.maxBatchTimeout !== undefined && { maxBatchTimeout: consumer.maxBatchTimeout },
|
|
141
|
+
...consumer.maxRetries !== undefined && { maxRetries: consumer.maxRetries },
|
|
142
|
+
...consumer.deadLetterQueue && { deadLetterQueue: consumer.deadLetterQueue },
|
|
143
|
+
...consumer.maxConcurrency !== undefined && { maxConcurrency: consumer.maxConcurrency },
|
|
144
|
+
...consumer.retryDelay !== undefined && { retryDelay: consumer.retryDelay }
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
return consumers;
|
|
148
|
+
}
|
|
149
|
+
function buildRateLimitsConfig(bindings) {
|
|
150
|
+
if (!bindings.rateLimits) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
return Object.fromEntries(Object.entries(bindings.rateLimits).map(([name, binding]) => [
|
|
154
|
+
name,
|
|
155
|
+
{
|
|
156
|
+
simple: {
|
|
157
|
+
limit: binding.simple.limit,
|
|
158
|
+
period: binding.simple.period
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
]));
|
|
162
|
+
}
|
|
163
|
+
function buildVersionMetadataConfig(bindings) {
|
|
164
|
+
return bindings.versionMetadata?.binding;
|
|
165
|
+
}
|
|
166
|
+
function buildWorkerLoadersConfig(bindings) {
|
|
167
|
+
if (!bindings.workerLoaders) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
return Object.fromEntries(Object.keys(bindings.workerLoaders).map((bindingName) => [bindingName, {}]));
|
|
171
|
+
}
|
|
172
|
+
function buildMtlsCertificatesConfig(bindings) {
|
|
173
|
+
if (!bindings.mtlsCertificates) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
return Object.fromEntries(Object.entries(bindings.mtlsCertificates).map(([bindingName, binding]) => {
|
|
177
|
+
const normalized = normalizeMtlsCertificateBinding(binding);
|
|
178
|
+
return [
|
|
179
|
+
bindingName,
|
|
180
|
+
{
|
|
181
|
+
certificate_id: normalized.certificateId
|
|
182
|
+
}
|
|
183
|
+
];
|
|
184
|
+
}));
|
|
185
|
+
}
|
|
186
|
+
function buildDispatchNamespacesConfig(bindings) {
|
|
187
|
+
if (!bindings.dispatchNamespaces) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
return Object.fromEntries(Object.entries(bindings.dispatchNamespaces).map(([bindingName, binding]) => {
|
|
191
|
+
const normalized = normalizeDispatchNamespaceBinding(binding);
|
|
192
|
+
return [
|
|
193
|
+
bindingName,
|
|
194
|
+
{
|
|
195
|
+
namespace: normalized.namespace
|
|
196
|
+
}
|
|
197
|
+
];
|
|
198
|
+
}));
|
|
199
|
+
}
|
|
200
|
+
function buildWorkflowsConfig(bindings) {
|
|
201
|
+
if (!bindings.workflows) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
return Object.fromEntries(Object.entries(bindings.workflows).map(([bindingName, binding]) => {
|
|
205
|
+
const normalized = normalizeWorkflowBinding(binding);
|
|
206
|
+
return [
|
|
207
|
+
bindingName,
|
|
208
|
+
{
|
|
209
|
+
name: normalized.name,
|
|
210
|
+
className: normalized.className,
|
|
211
|
+
...normalized.scriptName && { scriptName: normalized.scriptName },
|
|
212
|
+
...normalized.limits && { stepLimit: normalized.limits.steps }
|
|
213
|
+
}
|
|
214
|
+
];
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
function buildPipelinesConfig(bindings) {
|
|
218
|
+
if (!bindings.pipelines) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
return Object.fromEntries(Object.entries(bindings.pipelines).map(([bindingName, binding]) => {
|
|
222
|
+
const normalized = normalizePipelineBinding(binding);
|
|
223
|
+
return [
|
|
224
|
+
bindingName,
|
|
225
|
+
typeof binding === "string" ? normalized.pipeline : { pipeline: normalized.pipeline }
|
|
226
|
+
];
|
|
227
|
+
}));
|
|
228
|
+
}
|
|
229
|
+
function getHyperdriveLocalConnectionString(bindingName, binding) {
|
|
230
|
+
const cloudflareEnvName = `CLOUDFLARE_HYPERDRIVE_LOCAL_CONNECTION_STRING_${bindingName}`;
|
|
231
|
+
const wranglerEnvName = `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_${bindingName}`;
|
|
232
|
+
const envValue = process.env[cloudflareEnvName] ?? process.env[wranglerEnvName];
|
|
233
|
+
if (envValue?.trim()) {
|
|
234
|
+
return envValue;
|
|
235
|
+
}
|
|
236
|
+
const normalized = normalizeHyperdriveBinding(binding);
|
|
237
|
+
return normalized.localConnectionString;
|
|
238
|
+
}
|
|
239
|
+
function buildHyperdrivesConfig(bindings) {
|
|
240
|
+
if (!bindings.hyperdrive) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const hyperdrives = Object.fromEntries(Object.entries(bindings.hyperdrive).map(([bindingName, binding]) => {
|
|
244
|
+
const localConnectionString = getHyperdriveLocalConnectionString(bindingName, binding);
|
|
245
|
+
return localConnectionString ? [bindingName, localConnectionString] : null;
|
|
246
|
+
}).filter((entry) => entry !== null));
|
|
247
|
+
return Object.keys(hyperdrives).length > 0 ? hyperdrives : undefined;
|
|
248
|
+
}
|
|
249
|
+
function buildImagesConfig(bindings) {
|
|
250
|
+
if (!bindings.images) {
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const [entry] = Object.entries(bindings.images);
|
|
254
|
+
if (!entry) {
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const [bindingName, binding] = entry;
|
|
258
|
+
const normalized = normalizeImagesBinding(bindingName, binding);
|
|
259
|
+
return {
|
|
260
|
+
binding: normalized.binding
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
function buildMediaConfig(bindings) {
|
|
264
|
+
if (!bindings.media) {
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
const [entry] = Object.entries(bindings.media);
|
|
268
|
+
if (!entry) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
const [bindingName, binding] = entry;
|
|
272
|
+
const normalized = normalizeMediaBinding(bindingName, binding);
|
|
273
|
+
return {
|
|
274
|
+
binding: normalized.binding
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
function buildArtifactsConfig(bindings) {
|
|
278
|
+
if (!bindings.artifacts) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
return Object.fromEntries(Object.entries(bindings.artifacts).map(([bindingName, binding]) => {
|
|
282
|
+
const normalized = normalizeArtifactsBinding(binding);
|
|
283
|
+
return [
|
|
284
|
+
bindingName,
|
|
285
|
+
{
|
|
286
|
+
namespace: normalized.namespace
|
|
287
|
+
}
|
|
288
|
+
];
|
|
289
|
+
}));
|
|
290
|
+
}
|
|
291
|
+
function buildAiSearchNamespacesConfig(bindings) {
|
|
292
|
+
if (!bindings.aiSearchNamespaces) {
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
return Object.fromEntries(Object.entries(bindings.aiSearchNamespaces).map(([bindingName, binding]) => [
|
|
296
|
+
bindingName,
|
|
297
|
+
{
|
|
298
|
+
namespace: binding.namespace
|
|
299
|
+
}
|
|
300
|
+
]));
|
|
301
|
+
}
|
|
302
|
+
function buildAiSearchInstancesConfig(bindings) {
|
|
303
|
+
if (!bindings.aiSearch) {
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
306
|
+
return Object.fromEntries(Object.entries(bindings.aiSearch).map(([bindingName, binding]) => [
|
|
307
|
+
bindingName,
|
|
308
|
+
{
|
|
309
|
+
instance_name: binding.instanceName
|
|
310
|
+
}
|
|
311
|
+
]));
|
|
312
|
+
}
|
|
313
|
+
function buildSecretsStoreConfig(bindings, defaultSecretsStoreId, excludedBindingNames = new Set) {
|
|
314
|
+
if (!bindings.secretsStore) {
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
const entries = Object.entries(bindings.secretsStore).flatMap(([bindingName, binding]) => {
|
|
318
|
+
if (excludedBindingNames.has(bindingName)) {
|
|
319
|
+
return [];
|
|
320
|
+
}
|
|
321
|
+
const normalized = normalizeSecretsStoreBinding(binding, defaultSecretsStoreId, bindingName);
|
|
322
|
+
return [
|
|
323
|
+
[
|
|
324
|
+
bindingName,
|
|
325
|
+
{
|
|
326
|
+
store_id: normalized.storeId,
|
|
327
|
+
secret_name: normalized.secretName
|
|
328
|
+
}
|
|
329
|
+
]
|
|
330
|
+
];
|
|
331
|
+
});
|
|
332
|
+
return entries.length > 0 ? Object.fromEntries(entries) : undefined;
|
|
333
|
+
}
|
|
334
|
+
function buildSendEmailConfig(bindings) {
|
|
335
|
+
if (!bindings.sendEmail) {
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
send_email: Object.entries(bindings.sendEmail).map(([name, binding]) => ({
|
|
340
|
+
name,
|
|
341
|
+
...binding.destinationAddress && {
|
|
342
|
+
destination_address: binding.destinationAddress
|
|
343
|
+
},
|
|
344
|
+
...binding.allowedDestinationAddresses && {
|
|
345
|
+
allowed_destination_addresses: binding.allowedDestinationAddresses
|
|
346
|
+
},
|
|
347
|
+
...binding.allowedSenderAddresses && {
|
|
348
|
+
allowed_sender_addresses: binding.allowedSenderAddresses
|
|
349
|
+
}
|
|
350
|
+
}))
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// src/test/resolve-service-bindings.ts
|
|
355
|
+
function getBunRuntime() {
|
|
356
|
+
const g = globalThis;
|
|
357
|
+
if (typeof g.Bun === "object" && g.Bun !== null) {
|
|
358
|
+
return g.Bun;
|
|
359
|
+
}
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
function discoverDOFilesSync(dir, pattern = DEFAULT_DO_PATTERN) {
|
|
363
|
+
const classToPath = new Map;
|
|
364
|
+
try {
|
|
365
|
+
const files = findFilesSync(pattern, { cwd: dir });
|
|
366
|
+
for (const filePath of files) {
|
|
367
|
+
try {
|
|
368
|
+
const code = readFileSync(filePath, "utf-8");
|
|
369
|
+
const classNames = findDurableObjectClasses(code);
|
|
370
|
+
for (const className of classNames) {
|
|
371
|
+
if (!classToPath.has(className)) {
|
|
372
|
+
classToPath.set(className, filePath);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
} catch {}
|
|
376
|
+
}
|
|
377
|
+
} catch {}
|
|
378
|
+
return classToPath;
|
|
379
|
+
}
|
|
380
|
+
var bundleCache = new Map;
|
|
381
|
+
function findDefaultServiceWorkerEntrypoint(refConfigDir) {
|
|
382
|
+
for (const candidate of ["worker.ts", "worker.js", "src/worker.ts", "src/worker.js"]) {
|
|
383
|
+
const absolutePath = resolve(refConfigDir, candidate);
|
|
384
|
+
if (existsSync(absolutePath)) {
|
|
385
|
+
return absolutePath;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
function buildRawServiceBindings(services) {
|
|
391
|
+
if (!services || Object.keys(services).length === 0) {
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
return Object.fromEntries(Object.entries(services).map(([bindingName, binding]) => [
|
|
395
|
+
bindingName,
|
|
396
|
+
{
|
|
397
|
+
name: binding.service,
|
|
398
|
+
...binding.entrypoint && { entrypoint: binding.entrypoint }
|
|
399
|
+
}
|
|
400
|
+
]));
|
|
401
|
+
}
|
|
402
|
+
function buildReferencedWorkerRuntimeConfig(config) {
|
|
403
|
+
const bindings = config.bindings ?? {};
|
|
404
|
+
const queueProducers = buildQueueProducers(bindings);
|
|
405
|
+
const queueConsumers = buildQueueConsumers(bindings);
|
|
406
|
+
const rateLimits = buildRateLimitsConfig(bindings);
|
|
407
|
+
const versionMetadata = buildVersionMetadataConfig(bindings);
|
|
408
|
+
const workerLoaders = buildWorkerLoadersConfig(bindings);
|
|
409
|
+
const mtlsCertificates = buildMtlsCertificatesConfig(bindings);
|
|
410
|
+
const dispatchNamespaces = buildDispatchNamespacesConfig(bindings);
|
|
411
|
+
const workflows = buildWorkflowsConfig(bindings);
|
|
412
|
+
const pipelines = buildPipelinesConfig(bindings);
|
|
413
|
+
const hyperdrives = buildHyperdrivesConfig(bindings);
|
|
414
|
+
const media = buildMediaConfig(bindings);
|
|
415
|
+
const artifacts = buildArtifactsConfig(bindings);
|
|
416
|
+
const aiSearchNamespaces = buildAiSearchNamespacesConfig(bindings);
|
|
417
|
+
const aiSearchInstances = buildAiSearchInstancesConfig(bindings);
|
|
418
|
+
const secretsStoreSecrets = buildSecretsStoreConfig(bindings, config.secretsStoreId);
|
|
419
|
+
const email = buildSendEmailConfig(bindings);
|
|
420
|
+
const serviceBindings = buildRawServiceBindings(bindings.services);
|
|
421
|
+
return {
|
|
422
|
+
...config.compatibilityFlags && { compatibilityFlags: config.compatibilityFlags },
|
|
423
|
+
...config.vars && { bindings: config.vars },
|
|
424
|
+
...bindings.kv && {
|
|
425
|
+
kvNamespaces: Object.fromEntries(Object.entries(bindings.kv).map(([bindingName, bindingConfig]) => [
|
|
426
|
+
bindingName,
|
|
427
|
+
getLocalKVNamespaceIdentifier(bindingConfig)
|
|
428
|
+
]))
|
|
429
|
+
},
|
|
430
|
+
...bindings.r2 && { r2Buckets: bindings.r2 },
|
|
431
|
+
...bindings.d1 && {
|
|
432
|
+
d1Databases: Object.fromEntries(Object.entries(bindings.d1).map(([bindingName, bindingConfig]) => [
|
|
433
|
+
bindingName,
|
|
434
|
+
getLocalD1DatabaseIdentifier(bindingConfig)
|
|
435
|
+
]))
|
|
436
|
+
},
|
|
437
|
+
...queueProducers && { queueProducers },
|
|
438
|
+
...queueConsumers && { queueConsumers },
|
|
439
|
+
...rateLimits && { ratelimits: rateLimits },
|
|
440
|
+
...versionMetadata && { versionMetadata },
|
|
441
|
+
...workerLoaders && { workerLoaders },
|
|
442
|
+
...mtlsCertificates && { mtlsCertificates },
|
|
443
|
+
...dispatchNamespaces && { dispatchNamespaces },
|
|
444
|
+
...workflows && { workflows },
|
|
445
|
+
...pipelines && { pipelines },
|
|
446
|
+
...hyperdrives && { hyperdrives },
|
|
447
|
+
...media && { media },
|
|
448
|
+
...artifacts && { artifacts },
|
|
449
|
+
...aiSearchNamespaces && { aiSearchNamespaces },
|
|
450
|
+
...aiSearchInstances && { aiSearchInstances },
|
|
451
|
+
...secretsStoreSecrets && { secretsStoreSecrets },
|
|
452
|
+
...email && { email },
|
|
453
|
+
...serviceBindings && { serviceBindings }
|
|
454
|
+
};
|
|
455
|
+
}
|
|
456
|
+
function normalizeReferencedConfig(config) {
|
|
457
|
+
return configSchema.parse(config);
|
|
458
|
+
}
|
|
459
|
+
function resolveReferencedConfigDir(ref, parentConfigDir) {
|
|
460
|
+
const configPath = ref.configPath;
|
|
461
|
+
if (!configPath || configPath === "<resolved>") {
|
|
462
|
+
return null;
|
|
463
|
+
}
|
|
464
|
+
return dirname(resolvePackageSpecifier(configPath, parentConfigDir));
|
|
465
|
+
}
|
|
466
|
+
async function resolveReferencedLocalDurableObjects(config, configDir, workerName, serviceBindings = {}) {
|
|
467
|
+
const doPattern = config.files?.durableObjects;
|
|
468
|
+
const dosConfig = config.bindings?.durableObjects;
|
|
469
|
+
if (typeof doPattern !== "string" || !dosConfig || Object.keys(dosConfig).length === 0) {
|
|
470
|
+
return { workers: [], bindings: {} };
|
|
471
|
+
}
|
|
472
|
+
const discoveredDOs = discoverDOFilesSync(configDir, doPattern);
|
|
473
|
+
const doClasses = [];
|
|
474
|
+
for (const [bindingName, rawDoConfig] of Object.entries(dosConfig)) {
|
|
475
|
+
const doConfig = normalizeDOBinding(rawDoConfig);
|
|
476
|
+
if (doConfig.kind !== "local") {
|
|
477
|
+
continue;
|
|
478
|
+
}
|
|
479
|
+
const scriptPath = discoveredDOs.get(doConfig.className);
|
|
480
|
+
if (!scriptPath) {
|
|
481
|
+
console.warn(`[devflare] DO "${bindingName}" (class: ${doConfig.className}) not found in files.durableObjects for "${workerName}"`);
|
|
482
|
+
continue;
|
|
483
|
+
}
|
|
484
|
+
doClasses.push({ bindingName, className: doConfig.className, scriptPath });
|
|
485
|
+
}
|
|
486
|
+
if (doClasses.length === 0) {
|
|
487
|
+
return { workers: [], bindings: {} };
|
|
488
|
+
}
|
|
489
|
+
const doWorkerName = `${workerName}-durable-objects`;
|
|
490
|
+
const script = await bundleDOClasses(doClasses, doWorkerName);
|
|
491
|
+
if (!script) {
|
|
492
|
+
return { workers: [], bindings: {} };
|
|
493
|
+
}
|
|
494
|
+
const durableObjects = Object.fromEntries(doClasses.map((do_) => [do_.bindingName, do_.className]));
|
|
495
|
+
const runtimeConfig = buildReferencedWorkerRuntimeConfig(config);
|
|
496
|
+
const doRuntimeConfig = { ...runtimeConfig };
|
|
497
|
+
delete doRuntimeConfig.queueConsumers;
|
|
498
|
+
const mergedServiceBindings = {
|
|
499
|
+
...runtimeConfig.serviceBindings ?? {},
|
|
500
|
+
...serviceBindings
|
|
501
|
+
};
|
|
502
|
+
return {
|
|
503
|
+
workers: [
|
|
504
|
+
{
|
|
505
|
+
name: doWorkerName,
|
|
506
|
+
script,
|
|
507
|
+
modules: true,
|
|
508
|
+
compatibilityDate: config.compatibilityDate,
|
|
509
|
+
...doRuntimeConfig,
|
|
510
|
+
...Object.keys(mergedServiceBindings).length > 0 && {
|
|
511
|
+
serviceBindings: mergedServiceBindings
|
|
512
|
+
},
|
|
513
|
+
durableObjects
|
|
514
|
+
}
|
|
515
|
+
],
|
|
516
|
+
bindings: Object.fromEntries(doClasses.map((do_) => [
|
|
517
|
+
do_.bindingName,
|
|
518
|
+
{
|
|
519
|
+
className: do_.className,
|
|
520
|
+
scriptName: doWorkerName
|
|
521
|
+
}
|
|
522
|
+
]))
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
async function resolveServiceBindings(config, configDir, seenWorkers = new Set) {
|
|
526
|
+
const services = config.bindings?.services;
|
|
527
|
+
if (!services) {
|
|
528
|
+
return { workers: [], primaryServiceBindings: {} };
|
|
529
|
+
}
|
|
530
|
+
const workersByName = new Map;
|
|
531
|
+
const primaryServiceBindings = {};
|
|
532
|
+
for (const [bindingName, binding] of Object.entries(services)) {
|
|
533
|
+
const workerBinding = binding;
|
|
534
|
+
const ref = workerBinding.__ref;
|
|
535
|
+
if (ref) {
|
|
536
|
+
if ("__import" in ref && typeof ref.__import === "function") {
|
|
537
|
+
await ref.resolve();
|
|
538
|
+
}
|
|
539
|
+
const workerName = ref.name;
|
|
540
|
+
const entrypoint = workerBinding.entrypoint;
|
|
541
|
+
if (!workersByName.has(workerName) && !seenWorkers.has(workerName)) {
|
|
542
|
+
const refConfig = normalizeReferencedConfig(ref.config);
|
|
543
|
+
const worker = await resolveRefWorker(ref, entrypoint, configDir, refConfig);
|
|
544
|
+
if (worker) {
|
|
545
|
+
const refConfigDir = resolveReferencedConfigDir(ref, configDir);
|
|
546
|
+
if (ref.config && refConfigDir) {
|
|
547
|
+
const nested = await resolveServiceBindings(refConfig, refConfigDir, new Set([...seenWorkers, workerName]));
|
|
548
|
+
worker.serviceBindings = {
|
|
549
|
+
...worker.serviceBindings ?? {},
|
|
550
|
+
...nested.primaryServiceBindings
|
|
551
|
+
};
|
|
552
|
+
for (const nestedWorker of nested.workers) {
|
|
553
|
+
if (!workersByName.has(nestedWorker.name)) {
|
|
554
|
+
workersByName.set(nestedWorker.name, nestedWorker);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
const localDOs = await resolveReferencedLocalDurableObjects(refConfig, refConfigDir, workerName, nested.primaryServiceBindings);
|
|
558
|
+
worker.durableObjects = {
|
|
559
|
+
...worker.durableObjects ?? {},
|
|
560
|
+
...localDOs.bindings
|
|
561
|
+
};
|
|
562
|
+
for (const doWorker of localDOs.workers) {
|
|
563
|
+
if (!workersByName.has(doWorker.name)) {
|
|
564
|
+
workersByName.set(doWorker.name, doWorker);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
workersByName.set(workerName, worker);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
primaryServiceBindings[bindingName] = {
|
|
572
|
+
name: workerName,
|
|
573
|
+
...entrypoint && { entrypoint }
|
|
574
|
+
};
|
|
575
|
+
} else {
|
|
576
|
+
primaryServiceBindings[bindingName] = {
|
|
577
|
+
name: workerBinding.service,
|
|
578
|
+
...workerBinding.entrypoint && { entrypoint: workerBinding.entrypoint }
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return {
|
|
583
|
+
workers: [...workersByName.values()],
|
|
584
|
+
primaryServiceBindings
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
async function resolveRefWorker(ref, _entrypoint, parentConfigDir, resolvedConfig) {
|
|
588
|
+
const config = resolvedConfig ?? normalizeReferencedConfig(ref.config);
|
|
589
|
+
if (!config)
|
|
590
|
+
return null;
|
|
591
|
+
const refConfigDir = resolveReferencedConfigDir(ref, parentConfigDir);
|
|
592
|
+
if (!refConfigDir) {
|
|
593
|
+
console.warn(`[devflare] Cannot resolve worker "${ref.name}" - configPath not available`);
|
|
594
|
+
return null;
|
|
595
|
+
}
|
|
596
|
+
const entrypoints = [];
|
|
597
|
+
const workerEntrypointPath = findDefaultServiceWorkerEntrypoint(refConfigDir);
|
|
598
|
+
if (workerEntrypointPath) {
|
|
599
|
+
entrypoints.push({
|
|
600
|
+
path: workerEntrypointPath,
|
|
601
|
+
className: "Worker",
|
|
602
|
+
isWorkerTs: true
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
if (config.files?.entrypoints !== false) {
|
|
606
|
+
const discoveredEntrypoints = discoverEntrypointsSync(refConfigDir, typeof config.files?.entrypoints === "string" ? config.files.entrypoints : undefined);
|
|
607
|
+
for (const ep of discoveredEntrypoints) {
|
|
608
|
+
entrypoints.push({
|
|
609
|
+
path: ep.filePath,
|
|
610
|
+
className: ep.className,
|
|
611
|
+
isWorkerTs: false
|
|
612
|
+
});
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (entrypoints.length === 0) {
|
|
616
|
+
console.warn(`[devflare] Worker "${ref.name}" has no entry points`);
|
|
617
|
+
return null;
|
|
618
|
+
}
|
|
619
|
+
const script = await bundleAllEntrypoints(entrypoints, ref.name);
|
|
620
|
+
if (!script)
|
|
621
|
+
return null;
|
|
622
|
+
return {
|
|
623
|
+
name: ref.name,
|
|
624
|
+
script,
|
|
625
|
+
modules: true,
|
|
626
|
+
compatibilityDate: config.compatibilityDate ?? "2025-01-01",
|
|
627
|
+
...buildReferencedWorkerRuntimeConfig(config)
|
|
628
|
+
};
|
|
629
|
+
}
|
|
630
|
+
async function bundleAllEntrypoints(entrypoints, workerName) {
|
|
631
|
+
const cacheKey = entrypoints.map((ep) => `${ep.path}::${ep.className}`).join("|");
|
|
632
|
+
const cached = bundleCache.get(cacheKey);
|
|
633
|
+
if (cached) {
|
|
634
|
+
return cached;
|
|
635
|
+
}
|
|
636
|
+
const bun = getBunRuntime();
|
|
637
|
+
if (!bun) {
|
|
638
|
+
console.warn("[devflare] Bun runtime required for bundling worker scripts");
|
|
639
|
+
return null;
|
|
640
|
+
}
|
|
641
|
+
try {
|
|
642
|
+
const { readFileSync: readFileSync2, writeFileSync, mkdirSync, unlinkSync } = await import("fs");
|
|
643
|
+
const imports = [];
|
|
644
|
+
const exports = [];
|
|
645
|
+
let defaultExportClass = null;
|
|
646
|
+
for (let i = 0;i < entrypoints.length; i++) {
|
|
647
|
+
const ep = entrypoints[i];
|
|
648
|
+
const sourceCode = readFileSync2(ep.path, "utf-8");
|
|
649
|
+
if (ep.isWorkerTs) {
|
|
650
|
+
const result = transformWorkerEntrypoint(sourceCode, ep.path, {
|
|
651
|
+
className: ep.className,
|
|
652
|
+
injectContext: false
|
|
653
|
+
});
|
|
654
|
+
if (result) {
|
|
655
|
+
const tempDir2 = join(dirname(ep.path), ".devflare");
|
|
656
|
+
mkdirSync(tempDir2, { recursive: true });
|
|
657
|
+
const tempPath = join(tempDir2, `__${ep.className}_${i}.ts`);
|
|
658
|
+
writeFileSync(tempPath, result.code);
|
|
659
|
+
imports.push(`import { ${ep.className} } from '${tempPath.replace(/\\/g, "/")}'`);
|
|
660
|
+
exports.push(ep.className);
|
|
661
|
+
if (!defaultExportClass) {
|
|
662
|
+
defaultExportClass = ep.className;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
} else {
|
|
666
|
+
imports.push(`import { ${ep.className} } from '${ep.path.replace(/\\/g, "/")}'`);
|
|
667
|
+
exports.push(ep.className);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
const defaultExport = defaultExportClass ? `
|
|
671
|
+
export default ${defaultExportClass}` : "";
|
|
672
|
+
const entryCode = `
|
|
673
|
+
${imports.join(`
|
|
674
|
+
`)}
|
|
675
|
+
export { ${exports.join(", ")} }${defaultExport}
|
|
676
|
+
`;
|
|
677
|
+
const tempDir = join(dirname(entrypoints[0].path), ".devflare");
|
|
678
|
+
mkdirSync(tempDir, { recursive: true });
|
|
679
|
+
const entryPath = join(tempDir, `__entry_${workerName}.ts`);
|
|
680
|
+
writeFileSync(entryPath, entryCode);
|
|
681
|
+
try {
|
|
682
|
+
const result = await bun.build({
|
|
683
|
+
entrypoints: [entryPath],
|
|
684
|
+
target: "browser",
|
|
685
|
+
format: "esm",
|
|
686
|
+
minify: false,
|
|
687
|
+
external: ["cloudflare:workers", "cloudflare:*"]
|
|
688
|
+
});
|
|
689
|
+
if (!result.success) {
|
|
690
|
+
console.warn(`[devflare] Failed to bundle worker "${workerName}": ${result.logs.join(`
|
|
691
|
+
`)}`);
|
|
692
|
+
return null;
|
|
693
|
+
}
|
|
694
|
+
const bundledCode = await result.outputs[0].text();
|
|
695
|
+
bundleCache.set(cacheKey, bundledCode);
|
|
696
|
+
return bundledCode;
|
|
697
|
+
} finally {
|
|
698
|
+
try {
|
|
699
|
+
unlinkSync(entryPath);
|
|
700
|
+
} catch {}
|
|
701
|
+
}
|
|
702
|
+
} catch (error) {
|
|
703
|
+
console.warn(`[devflare] Error bundling worker "${workerName}":`, error);
|
|
704
|
+
return null;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
async function bundleDOClasses(doClasses, workerName) {
|
|
708
|
+
const cacheKey = `do:${doClasses.map((d) => `${d.scriptPath}::${d.className}`).join("|")}`;
|
|
709
|
+
const cached = bundleCache.get(cacheKey);
|
|
710
|
+
if (cached)
|
|
711
|
+
return cached;
|
|
712
|
+
const bun = getBunRuntime();
|
|
713
|
+
if (!bun) {
|
|
714
|
+
console.warn("[devflare] Bun runtime required for bundling DO classes");
|
|
715
|
+
return null;
|
|
716
|
+
}
|
|
717
|
+
try {
|
|
718
|
+
const { writeFileSync, mkdirSync, unlinkSync } = await import("fs");
|
|
719
|
+
const imports = doClasses.map((d) => `import { ${d.className} } from '${d.scriptPath.replace(/\\/g, "/")}'`).join(`
|
|
720
|
+
`);
|
|
721
|
+
const exports = doClasses.map((d) => d.className).join(", ");
|
|
722
|
+
const entryCode = `
|
|
723
|
+
${imports}
|
|
724
|
+
|
|
725
|
+
// Re-export DO classes for Miniflare binding
|
|
726
|
+
export { ${exports} }
|
|
727
|
+
|
|
728
|
+
// Default export with fetch handler
|
|
729
|
+
export default {
|
|
730
|
+
async fetch(request, env) {
|
|
731
|
+
return new Response('DO Worker: ${workerName}')
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
`;
|
|
735
|
+
const tempDir = join(dirname(doClasses[0].scriptPath), ".devflare");
|
|
736
|
+
mkdirSync(tempDir, { recursive: true });
|
|
737
|
+
const entryPath = join(tempDir, `__do_entry_${workerName}.ts`);
|
|
738
|
+
writeFileSync(entryPath, entryCode);
|
|
739
|
+
try {
|
|
740
|
+
const result = await bun.build({
|
|
741
|
+
entrypoints: [entryPath],
|
|
742
|
+
target: "browser",
|
|
743
|
+
format: "esm",
|
|
744
|
+
minify: false,
|
|
745
|
+
external: ["cloudflare:workers", "cloudflare:*"]
|
|
746
|
+
});
|
|
747
|
+
if (!result.success) {
|
|
748
|
+
console.warn(`[devflare] Failed to bundle DO worker "${workerName}": ${result.logs.join(`
|
|
749
|
+
`)}`);
|
|
750
|
+
return null;
|
|
751
|
+
}
|
|
752
|
+
const bundledCode = await result.outputs[0].text();
|
|
753
|
+
bundleCache.set(cacheKey, bundledCode);
|
|
754
|
+
return bundledCode;
|
|
755
|
+
} finally {
|
|
756
|
+
try {
|
|
757
|
+
unlinkSync(entryPath);
|
|
758
|
+
} catch {}
|
|
759
|
+
}
|
|
760
|
+
} catch (error) {
|
|
761
|
+
console.warn(`[devflare] Error bundling DO worker "${workerName}":`, error);
|
|
762
|
+
return null;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
104
765
|
|
|
105
766
|
// src/worker-entry/composed-worker.ts
|
|
106
|
-
import { dirname, relative, resolve as
|
|
767
|
+
import { dirname as dirname2, relative as relative2, resolve as resolve4 } from "pathe";
|
|
768
|
+
|
|
769
|
+
// src/worker-entry/durable-object-discovery.ts
|
|
770
|
+
async function discoverDurableObjectFiles(cwd, pattern) {
|
|
771
|
+
const result = new Map;
|
|
772
|
+
const matchedFiles = await findFiles(pattern, { cwd });
|
|
773
|
+
const fs = await import("node:fs/promises");
|
|
774
|
+
for (const filePath of matchedFiles) {
|
|
775
|
+
try {
|
|
776
|
+
const code = await fs.readFile(filePath, "utf-8");
|
|
777
|
+
const classNames = findDurableObjectClasses(code);
|
|
778
|
+
if (classNames.length > 0) {
|
|
779
|
+
result.set(filePath, classNames);
|
|
780
|
+
}
|
|
781
|
+
} catch (error) {
|
|
782
|
+
console.warn(`[devflare] Failed to read DO file: ${filePath}`, error);
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
return result;
|
|
786
|
+
}
|
|
787
|
+
async function discoverDurableObjects(projectRoot, pattern, workerName) {
|
|
788
|
+
const files = await discoverDurableObjectFiles(projectRoot, pattern);
|
|
789
|
+
return { files, workerName };
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
// src/worker-entry/routes.ts
|
|
793
|
+
import { relative, resolve as resolve2 } from "pathe";
|
|
794
|
+
var DEFAULT_ROUTE_DIR = "src/routes";
|
|
795
|
+
var DEFAULT_ROUTE_FILE_PATTERNS = SUPPORTED_WORKER_EXTENSIONS.map((ext) => `**/*${ext}`);
|
|
796
|
+
function normalizeRoutePrefix(prefix) {
|
|
797
|
+
if (!prefix || prefix === "/") {
|
|
798
|
+
return "";
|
|
799
|
+
}
|
|
800
|
+
const normalized = prefix.startsWith("/") ? prefix : `/${prefix}`;
|
|
801
|
+
return normalized.replace(/\/+$/g, "");
|
|
802
|
+
}
|
|
803
|
+
function createStaticSegmentsFromPrefix(prefix) {
|
|
804
|
+
if (!prefix) {
|
|
805
|
+
return [];
|
|
806
|
+
}
|
|
807
|
+
return prefix.split("/").filter(Boolean).map((value) => ({
|
|
808
|
+
type: "static",
|
|
809
|
+
value
|
|
810
|
+
}));
|
|
811
|
+
}
|
|
812
|
+
function shouldIgnoreRouteFile(relativePath) {
|
|
813
|
+
return relativePath.split("/").some((segment) => segment.startsWith("_"));
|
|
814
|
+
}
|
|
815
|
+
function toRoutePath(segments) {
|
|
816
|
+
if (segments.length === 0) {
|
|
817
|
+
return "/";
|
|
818
|
+
}
|
|
819
|
+
return `/${segments.map((segment) => {
|
|
820
|
+
if (segment.type === "static") {
|
|
821
|
+
return segment.value;
|
|
822
|
+
}
|
|
823
|
+
if (segment.type === "param") {
|
|
824
|
+
return `[${segment.name}]`;
|
|
825
|
+
}
|
|
826
|
+
if (segment.type === "rest") {
|
|
827
|
+
return `[...${segment.name}]`;
|
|
828
|
+
}
|
|
829
|
+
return `[[...${segment.name}]]`;
|
|
830
|
+
}).join("/")}`;
|
|
831
|
+
}
|
|
832
|
+
function getRouteSignature(segments) {
|
|
833
|
+
if (segments.length === 0) {
|
|
834
|
+
return "/";
|
|
835
|
+
}
|
|
836
|
+
return segments.map((segment) => {
|
|
837
|
+
if (segment.type === "static") {
|
|
838
|
+
return `static:${segment.value}`;
|
|
839
|
+
}
|
|
840
|
+
if (segment.type === "param") {
|
|
841
|
+
return "param";
|
|
842
|
+
}
|
|
843
|
+
if (segment.type === "rest") {
|
|
844
|
+
return "rest";
|
|
845
|
+
}
|
|
846
|
+
return "optional-rest";
|
|
847
|
+
}).join("/");
|
|
848
|
+
}
|
|
849
|
+
function getSegmentPriority(segment) {
|
|
850
|
+
if (segment.type === "static") {
|
|
851
|
+
return 4;
|
|
852
|
+
}
|
|
853
|
+
if (segment.type === "param") {
|
|
854
|
+
return 3;
|
|
855
|
+
}
|
|
856
|
+
if (segment.type === "rest") {
|
|
857
|
+
return 1;
|
|
858
|
+
}
|
|
859
|
+
return 0;
|
|
860
|
+
}
|
|
861
|
+
function compareRoutes(a, b) {
|
|
862
|
+
const maxLength = Math.max(a.segments.length, b.segments.length);
|
|
863
|
+
for (let index = 0;index < maxLength; index += 1) {
|
|
864
|
+
const left = a.segments[index];
|
|
865
|
+
const right = b.segments[index];
|
|
866
|
+
if (!left && !right) {
|
|
867
|
+
break;
|
|
868
|
+
}
|
|
869
|
+
if (!left) {
|
|
870
|
+
return 1;
|
|
871
|
+
}
|
|
872
|
+
if (!right) {
|
|
873
|
+
return -1;
|
|
874
|
+
}
|
|
875
|
+
const priorityDifference = getSegmentPriority(right) - getSegmentPriority(left);
|
|
876
|
+
if (priorityDifference !== 0) {
|
|
877
|
+
return priorityDifference;
|
|
878
|
+
}
|
|
879
|
+
if (left.type === "static" && right.type === "static") {
|
|
880
|
+
const lexicalDifference = left.value.localeCompare(right.value);
|
|
881
|
+
if (lexicalDifference !== 0) {
|
|
882
|
+
return lexicalDifference;
|
|
883
|
+
}
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
return a.filePath.localeCompare(b.filePath);
|
|
887
|
+
}
|
|
888
|
+
function parseRouteSegments(relativePath, prefixSegments) {
|
|
889
|
+
const withoutExtension = relativePath.replace(/\.[^.]+$/u, "");
|
|
890
|
+
const rawSegments = withoutExtension.split("/").filter(Boolean);
|
|
891
|
+
const routeSegments = [...prefixSegments];
|
|
892
|
+
for (let index = 0;index < rawSegments.length; index += 1) {
|
|
893
|
+
const segment = rawSegments[index];
|
|
894
|
+
const isLastSegment = index === rawSegments.length - 1;
|
|
895
|
+
if (segment === "index" && isLastSegment) {
|
|
896
|
+
continue;
|
|
897
|
+
}
|
|
898
|
+
const optionalRestMatch = segment.match(/^\[\[\.\.\.(.+)\]\]$/u);
|
|
899
|
+
if (optionalRestMatch) {
|
|
900
|
+
if (!isLastSegment) {
|
|
901
|
+
throw new Error(`Optional rest segment must be the final segment: ${relativePath}`);
|
|
902
|
+
}
|
|
903
|
+
routeSegments.push({
|
|
904
|
+
type: "optional-rest",
|
|
905
|
+
name: optionalRestMatch[1]
|
|
906
|
+
});
|
|
907
|
+
continue;
|
|
908
|
+
}
|
|
909
|
+
const restMatch = segment.match(/^\[\.\.\.(.+)\]$/u);
|
|
910
|
+
if (restMatch) {
|
|
911
|
+
if (!isLastSegment) {
|
|
912
|
+
throw new Error(`Rest segment must be the final segment: ${relativePath}`);
|
|
913
|
+
}
|
|
914
|
+
routeSegments.push({
|
|
915
|
+
type: "rest",
|
|
916
|
+
name: restMatch[1]
|
|
917
|
+
});
|
|
918
|
+
continue;
|
|
919
|
+
}
|
|
920
|
+
const dynamicMatch = segment.match(/^\[(.+)\]$/u);
|
|
921
|
+
if (dynamicMatch) {
|
|
922
|
+
routeSegments.push({
|
|
923
|
+
type: "param",
|
|
924
|
+
name: dynamicMatch[1]
|
|
925
|
+
});
|
|
926
|
+
continue;
|
|
927
|
+
}
|
|
928
|
+
routeSegments.push({
|
|
929
|
+
type: "static",
|
|
930
|
+
value: segment
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
return routeSegments;
|
|
934
|
+
}
|
|
935
|
+
async function directoryExists(dirPath) {
|
|
936
|
+
const fs = await import("node:fs/promises");
|
|
937
|
+
try {
|
|
938
|
+
const stat = await fs.stat(dirPath);
|
|
939
|
+
return stat.isDirectory();
|
|
940
|
+
} catch {
|
|
941
|
+
return false;
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
function getRouteDirectoryCandidate(cwd, config) {
|
|
945
|
+
const routesConfig = config.files?.routes;
|
|
946
|
+
if (routesConfig === false) {
|
|
947
|
+
return null;
|
|
948
|
+
}
|
|
949
|
+
const dir = routesConfig?.dir ?? DEFAULT_ROUTE_DIR;
|
|
950
|
+
return {
|
|
951
|
+
dir,
|
|
952
|
+
absoluteDir: resolve2(cwd, dir),
|
|
953
|
+
prefix: normalizeRoutePrefix(routesConfig?.prefix)
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
async function discoverRoutes(cwd, config) {
|
|
957
|
+
const routeDirectory = getRouteDirectoryCandidate(cwd, config);
|
|
958
|
+
if (!routeDirectory) {
|
|
959
|
+
return null;
|
|
960
|
+
}
|
|
961
|
+
if (!await directoryExists(routeDirectory.absoluteDir)) {
|
|
962
|
+
return null;
|
|
963
|
+
}
|
|
964
|
+
const prefixSegments = createStaticSegmentsFromPrefix(routeDirectory.prefix);
|
|
965
|
+
const files = await findFiles(DEFAULT_ROUTE_FILE_PATTERNS, {
|
|
966
|
+
cwd: routeDirectory.absoluteDir,
|
|
967
|
+
absolute: true
|
|
968
|
+
});
|
|
969
|
+
const discoveredRoutes = [];
|
|
970
|
+
const routeSignatures = new Map;
|
|
971
|
+
for (const absolutePath of files) {
|
|
972
|
+
const relativeToRouteDir = relative(routeDirectory.absoluteDir, absolutePath).replace(/\\/g, "/");
|
|
973
|
+
if (shouldIgnoreRouteFile(relativeToRouteDir)) {
|
|
974
|
+
continue;
|
|
975
|
+
}
|
|
976
|
+
const segments = parseRouteSegments(relativeToRouteDir, prefixSegments);
|
|
977
|
+
const routePath = toRoutePath(segments);
|
|
978
|
+
const filePath = relative(cwd, absolutePath).replace(/\\/g, "/");
|
|
979
|
+
const signature = getRouteSignature(segments);
|
|
980
|
+
const existingFilePath = routeSignatures.get(signature);
|
|
981
|
+
if (existingFilePath) {
|
|
982
|
+
throw new Error(`Conflicting file routes detected for "${routePath}". Both "${existingFilePath}" and "${filePath}" resolve to the same route.`);
|
|
983
|
+
}
|
|
984
|
+
routeSignatures.set(signature, filePath);
|
|
985
|
+
discoveredRoutes.push({
|
|
986
|
+
absolutePath,
|
|
987
|
+
filePath,
|
|
988
|
+
routePath,
|
|
989
|
+
segments
|
|
990
|
+
});
|
|
991
|
+
}
|
|
992
|
+
if (discoveredRoutes.length === 0) {
|
|
993
|
+
return null;
|
|
994
|
+
}
|
|
995
|
+
discoveredRoutes.sort(compareRoutes);
|
|
996
|
+
return {
|
|
997
|
+
dir: routeDirectory.dir,
|
|
998
|
+
absoluteDir: routeDirectory.absoluteDir,
|
|
999
|
+
prefix: routeDirectory.prefix,
|
|
1000
|
+
routes: discoveredRoutes
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
107
1003
|
|
|
108
1004
|
// src/worker-entry/surface-paths.ts
|
|
109
|
-
import { resolve } from "pathe";
|
|
1005
|
+
import { resolve as resolve3 } from "pathe";
|
|
110
1006
|
var defaultEntriesFor = (surface) => SUPPORTED_WORKER_EXTENSIONS.map((ext) => `src/${surface}${ext}`);
|
|
111
1007
|
var DEFAULT_FETCH_ENTRY_FILES = defaultEntriesFor("fetch");
|
|
112
1008
|
var DEFAULT_QUEUE_ENTRY_FILES = defaultEntriesFor("queue");
|
|
@@ -135,7 +1031,7 @@ async function resolveWorkerHandlerPath(cwd, configuredPath, defaultEntries, sur
|
|
|
135
1031
|
}
|
|
136
1032
|
const fs = await import("node:fs/promises");
|
|
137
1033
|
if (typeof configuredPath === "string" && configuredPath) {
|
|
138
|
-
const absolutePath =
|
|
1034
|
+
const absolutePath = resolve3(cwd, configuredPath);
|
|
139
1035
|
try {
|
|
140
1036
|
await fs.access(absolutePath);
|
|
141
1037
|
return absolutePath;
|
|
@@ -163,7 +1059,7 @@ or move the handler to a source file that exists at config time.`);
|
|
|
163
1059
|
}
|
|
164
1060
|
}
|
|
165
1061
|
for (const defaultEntry of defaultEntries) {
|
|
166
|
-
const absolutePath =
|
|
1062
|
+
const absolutePath = resolve3(cwd, defaultEntry);
|
|
167
1063
|
try {
|
|
168
1064
|
await fs.access(absolutePath);
|
|
169
1065
|
return absolutePath;
|
|
@@ -470,7 +1366,7 @@ ${routeManifestEntries.join(`,
|
|
|
470
1366
|
return builder.toString();
|
|
471
1367
|
}
|
|
472
1368
|
function toImportSpecifier(fromFilePath, toFilePath) {
|
|
473
|
-
const specifier =
|
|
1369
|
+
const specifier = relative2(dirname2(fromFilePath), toFilePath).replace(/\\/g, "/");
|
|
474
1370
|
return specifier.startsWith(".") ? specifier : `./${specifier}`;
|
|
475
1371
|
}
|
|
476
1372
|
function createGeneratedRouteModuleImports(entryPath, routeDiscovery) {
|
|
@@ -550,7 +1446,7 @@ function needsComposedWorkerEntrypoint(cwd, surfacePaths, config, routeDiscovery
|
|
|
550
1446
|
}
|
|
551
1447
|
const assetsDirectory = config.assets?.directory;
|
|
552
1448
|
if (assetsDirectory) {
|
|
553
|
-
const generatedAssetsWorkerPath =
|
|
1449
|
+
const generatedAssetsWorkerPath = resolve4(cwd, assetsDirectory, "_worker.js");
|
|
554
1450
|
if (surfacePaths.fetch === generatedAssetsWorkerPath) {
|
|
555
1451
|
return false;
|
|
556
1452
|
}
|
|
@@ -565,7 +1461,7 @@ async function prepareComposedWorkerEntrypoint(cwd, config, environment, options
|
|
|
565
1461
|
const configuredFetch = resolvedConfig.files?.fetch;
|
|
566
1462
|
if (typeof configuredFetch === "string" && looksLikeBuildArtifactPath(configuredFetch)) {
|
|
567
1463
|
const fs2 = await import("node:fs/promises");
|
|
568
|
-
const fetchAbsolute =
|
|
1464
|
+
const fetchAbsolute = resolve4(cwd, configuredFetch);
|
|
569
1465
|
let fetchExists = true;
|
|
570
1466
|
try {
|
|
571
1467
|
await fs2.access(fetchAbsolute);
|
|
@@ -582,8 +1478,8 @@ async function prepareComposedWorkerEntrypoint(cwd, config, environment, options
|
|
|
582
1478
|
return null;
|
|
583
1479
|
}
|
|
584
1480
|
const fs = await import("node:fs/promises");
|
|
585
|
-
const entryDir =
|
|
586
|
-
const entryPath =
|
|
1481
|
+
const entryDir = resolve4(cwd, ".devflare", "worker-entrypoints");
|
|
1482
|
+
const entryPath = resolve4(entryDir, "main.ts");
|
|
587
1483
|
await fs.mkdir(entryDir, { recursive: true });
|
|
588
1484
|
const surfaceImportPaths = {
|
|
589
1485
|
fetch: surfacePaths.fetch ? toImportSpecifier(entryPath, surfacePaths.fetch) : null,
|
|
@@ -779,7 +1675,7 @@ async function buildPluginContextState(projectRoot, devflareConfig, environment,
|
|
|
779
1675
|
};
|
|
780
1676
|
const composedMainEntry = mode === "build" ? null : await prepareComposedWorkerEntrypoint(projectRoot, effectiveConfig, environment);
|
|
781
1677
|
if (composedMainEntry) {
|
|
782
|
-
const relativeMain =
|
|
1678
|
+
const relativeMain = relative3(projectRoot, composedMainEntry);
|
|
783
1679
|
wranglerConfig.main = relativeMain;
|
|
784
1680
|
cloudflareConfig.main = relativeMain;
|
|
785
1681
|
}
|
|
@@ -828,10 +1724,10 @@ async function buildPluginContextState(projectRoot, devflareConfig, environment,
|
|
|
828
1724
|
};
|
|
829
1725
|
}
|
|
830
1726
|
async function ensureGeneratedConfigDir(projectRoot) {
|
|
831
|
-
const configDir =
|
|
1727
|
+
const configDir = resolve5(projectRoot, CONFIG_DIR);
|
|
832
1728
|
const fs = await import("node:fs/promises");
|
|
833
1729
|
await fs.mkdir(configDir, { recursive: true });
|
|
834
|
-
const gitignorePath =
|
|
1730
|
+
const gitignorePath = resolve5(configDir, ".gitignore");
|
|
835
1731
|
try {
|
|
836
1732
|
await fs.access(gitignorePath);
|
|
837
1733
|
} catch {
|
|
@@ -847,7 +1743,7 @@ async function writeGeneratedWranglerConfig(projectRoot, wranglerConfig) {
|
|
|
847
1743
|
}
|
|
848
1744
|
async function resolvePluginConfigPath(projectRoot, configPath) {
|
|
849
1745
|
if (configPath) {
|
|
850
|
-
return isAbsolute(configPath) ? configPath :
|
|
1746
|
+
return isAbsolute(configPath) ? configPath : resolve5(projectRoot, configPath);
|
|
851
1747
|
}
|
|
852
1748
|
return await resolveConfigPath(projectRoot) ?? null;
|
|
853
1749
|
}
|
|
@@ -863,11 +1759,11 @@ async function runWorkerEntryTransform(code, id) {
|
|
|
863
1759
|
if (!id.endsWith("worker.ts") && !id.endsWith("worker.js")) {
|
|
864
1760
|
return null;
|
|
865
1761
|
}
|
|
866
|
-
const { shouldTransformWorker, transformWorkerEntrypoint } = await import("./worker-entrypoint-y8s9kdcx.js");
|
|
1762
|
+
const { shouldTransformWorker, transformWorkerEntrypoint: transformWorkerEntrypoint2 } = await import("./worker-entrypoint-y8s9kdcx.js");
|
|
867
1763
|
if (!shouldTransformWorker(code, id)) {
|
|
868
1764
|
return null;
|
|
869
1765
|
}
|
|
870
|
-
const result =
|
|
1766
|
+
const result = transformWorkerEntrypoint2(code, id);
|
|
871
1767
|
if (!result)
|
|
872
1768
|
return null;
|
|
873
1769
|
return {
|
|
@@ -893,74 +1789,6 @@ async function runDevflareTransform(code, id, options) {
|
|
|
893
1789
|
return await runDurableObjectTransform(code, id, options);
|
|
894
1790
|
}
|
|
895
1791
|
|
|
896
|
-
// src/vite/plugin-programmatic.ts
|
|
897
|
-
import { relative as relative3 } from "pathe";
|
|
898
|
-
async function loadProgrammaticDevflareConfig(options) {
|
|
899
|
-
const cwd = options.cwd ?? process.cwd();
|
|
900
|
-
const strategy = options.resolve ?? "offline-local";
|
|
901
|
-
const resourceResolvedConfig = strategy === "remote" ? await loadResolvedConfig({
|
|
902
|
-
cwd,
|
|
903
|
-
configFile: options.configPath,
|
|
904
|
-
environment: options.environment
|
|
905
|
-
}) : await resolveResources(await loadConfig({ cwd, configFile: options.configPath }), {
|
|
906
|
-
phase: "local",
|
|
907
|
-
environment: options.environment
|
|
908
|
-
});
|
|
909
|
-
const devflareConfig = await resolveConfigEnvVars(resourceResolvedConfig, {
|
|
910
|
-
cwd,
|
|
911
|
-
configPath: options.configPath,
|
|
912
|
-
mode: strategy === "remote" ? "build" : "dev"
|
|
913
|
-
});
|
|
914
|
-
return { cwd, devflareConfig };
|
|
915
|
-
}
|
|
916
|
-
async function buildProgrammaticArtifacts(options, mode) {
|
|
917
|
-
const { cwd, devflareConfig } = await loadProgrammaticDevflareConfig(options);
|
|
918
|
-
const composedMainEntry = await prepareComposedWorkerEntrypoint(cwd, devflareConfig);
|
|
919
|
-
const wranglerConfig = compileConfig(devflareConfig);
|
|
920
|
-
const cloudflareConfig = mode === "programmatic" ? compileToProgrammaticConfig(devflareConfig) : { ...wranglerConfig };
|
|
921
|
-
if (composedMainEntry) {
|
|
922
|
-
const relativeMain = relative3(cwd, composedMainEntry);
|
|
923
|
-
wranglerConfig.main = relativeMain;
|
|
924
|
-
cloudflareConfig.main = relativeMain;
|
|
925
|
-
}
|
|
926
|
-
const auxiliaryWorkers = [];
|
|
927
|
-
const doPatternConfig = devflareConfig.files?.durableObjects;
|
|
928
|
-
const doPattern = typeof doPatternConfig === "string" ? doPatternConfig : DEFAULT_DO_PATTERN;
|
|
929
|
-
if (doPatternConfig !== false) {
|
|
930
|
-
const doWorkerName = `${wranglerConfig.name}-do`;
|
|
931
|
-
const discovery = await discoverDurableObjects(cwd, doPattern, doWorkerName);
|
|
932
|
-
if (discovery.files.size > 0) {
|
|
933
|
-
if (cloudflareConfig.durable_objects) {
|
|
934
|
-
const doConfig = cloudflareConfig.durable_objects;
|
|
935
|
-
for (const binding of doConfig.bindings) {
|
|
936
|
-
binding.script_name = doWorkerName;
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
auxiliaryWorkers.push(createAuxiliaryWorkerConfig(wranglerConfig, discovery));
|
|
940
|
-
}
|
|
941
|
-
}
|
|
942
|
-
if (devflareConfig.bindings?.services) {
|
|
943
|
-
const serviceBindingResolution = await resolveServiceBindings(devflareConfig, cwd);
|
|
944
|
-
auxiliaryWorkers.push(...createAuxiliaryServiceWorkerConfigs(serviceBindingResolution).auxiliaryWorkers);
|
|
945
|
-
}
|
|
946
|
-
return {
|
|
947
|
-
cwd,
|
|
948
|
-
devflareConfig,
|
|
949
|
-
composedMainEntry,
|
|
950
|
-
wranglerConfig,
|
|
951
|
-
cloudflareConfig,
|
|
952
|
-
auxiliaryWorkers
|
|
953
|
-
};
|
|
954
|
-
}
|
|
955
|
-
async function getCloudflareConfig(options = {}) {
|
|
956
|
-
const { cloudflareConfig } = await buildProgrammaticArtifacts(options, "programmatic");
|
|
957
|
-
return cloudflareConfig;
|
|
958
|
-
}
|
|
959
|
-
async function getDevflareConfigs(options = {}) {
|
|
960
|
-
const { cloudflareConfig, auxiliaryWorkers } = await buildProgrammaticArtifacts(options, "wrangler");
|
|
961
|
-
return { cloudflareConfig, auxiliaryWorkers };
|
|
962
|
-
}
|
|
963
|
-
|
|
964
1792
|
// src/vite/plugin.ts
|
|
965
1793
|
var CONFIG_DIR2 = ".devflare";
|
|
966
1794
|
function createPluginState() {
|
|
@@ -984,7 +1812,7 @@ async function loadAndApplyConfig(state, options, mode, onContextUpdated) {
|
|
|
984
1812
|
cwd: state.projectRoot,
|
|
985
1813
|
configFile: options.configPath
|
|
986
1814
|
});
|
|
987
|
-
const pluginState = await buildPluginContextState(state.projectRoot, state.devflareConfig, options.environment, mode, state.resolvedPluginConfigPath ?
|
|
1815
|
+
const pluginState = await buildPluginContextState(state.projectRoot, state.devflareConfig, options.environment, mode, state.resolvedPluginConfigPath ? dirname3(state.resolvedPluginConfigPath) : state.projectRoot);
|
|
988
1816
|
Object.assign(state.context, {
|
|
989
1817
|
projectRoot: state.projectRoot,
|
|
990
1818
|
...pluginState
|
|
@@ -994,9 +1822,6 @@ async function loadAndApplyConfig(state, options, mode, onContextUpdated) {
|
|
|
994
1822
|
await writeGeneratedWranglerConfig(state.projectRoot, pluginState.wranglerConfig);
|
|
995
1823
|
}
|
|
996
1824
|
var lastPluginContext = createPluginState().context;
|
|
997
|
-
function getPluginContext() {
|
|
998
|
-
return lastPluginContext;
|
|
999
|
-
}
|
|
1000
1825
|
function devflarePlugin(options = {}) {
|
|
1001
1826
|
const {
|
|
1002
1827
|
configPath,
|
|
@@ -1063,7 +1888,7 @@ export default { fetch: () => new Response("No DOs") }`;
|
|
|
1063
1888
|
configureServer(server) {
|
|
1064
1889
|
if (!watchConfig)
|
|
1065
1890
|
return;
|
|
1066
|
-
const fullConfigPath = state.resolvedPluginConfigPath ??
|
|
1891
|
+
const fullConfigPath = state.resolvedPluginConfigPath ?? resolve6(state.projectRoot, configPath || "devflare.config.ts");
|
|
1067
1892
|
server.watcher.add(fullConfigPath);
|
|
1068
1893
|
server.watcher.on("change", async (changedPath) => {
|
|
1069
1894
|
if (changedPath === fullConfigPath) {
|
|
@@ -1088,6 +1913,7 @@ export default { fetch: () => new Response("No DOs") }`;
|
|
|
1088
1913
|
}
|
|
1089
1914
|
};
|
|
1090
1915
|
}
|
|
1916
|
+
|
|
1091
1917
|
// src/vite/config-file.ts
|
|
1092
1918
|
var CONFIG_DIR3 = ".devflare";
|
|
1093
1919
|
var GENERATED_VITE_CONFIG_FILENAME = "vite.config.mjs";
|
|
@@ -1153,10 +1979,10 @@ async function resolveViteUserConfig(configEnv, options = {}) {
|
|
|
1153
1979
|
}
|
|
1154
1980
|
async function ensureGeneratedConfigDir2(cwd) {
|
|
1155
1981
|
const fs = await import("node:fs/promises");
|
|
1156
|
-
const { resolve:
|
|
1157
|
-
const configDir =
|
|
1982
|
+
const { resolve: resolve7 } = await import("pathe");
|
|
1983
|
+
const configDir = resolve7(cwd, CONFIG_DIR3);
|
|
1158
1984
|
await fs.mkdir(configDir, { recursive: true });
|
|
1159
|
-
const gitignorePath =
|
|
1985
|
+
const gitignorePath = resolve7(configDir, ".gitignore");
|
|
1160
1986
|
try {
|
|
1161
1987
|
await fs.access(gitignorePath);
|
|
1162
1988
|
} catch {
|
|
@@ -1167,17 +1993,17 @@ async function ensureGeneratedConfigDir2(cwd) {
|
|
|
1167
1993
|
}
|
|
1168
1994
|
async function resolveDevflarePackageRoot(currentFilePath) {
|
|
1169
1995
|
const fs = await import("node:fs/promises");
|
|
1170
|
-
const { dirname:
|
|
1171
|
-
let currentDir =
|
|
1996
|
+
const { dirname: dirname4, resolve: resolve7 } = await import("pathe");
|
|
1997
|
+
let currentDir = dirname4(currentFilePath);
|
|
1172
1998
|
while (true) {
|
|
1173
|
-
const packageJsonPath =
|
|
1999
|
+
const packageJsonPath = resolve7(currentDir, "package.json");
|
|
1174
2000
|
try {
|
|
1175
2001
|
const packageJson = JSON.parse(await fs.readFile(packageJsonPath, "utf-8"));
|
|
1176
2002
|
if (packageJson.name === "devflare") {
|
|
1177
2003
|
return currentDir;
|
|
1178
2004
|
}
|
|
1179
2005
|
} catch {}
|
|
1180
|
-
const parentDir =
|
|
2006
|
+
const parentDir = dirname4(currentDir);
|
|
1181
2007
|
if (parentDir === currentDir) {
|
|
1182
2008
|
break;
|
|
1183
2009
|
}
|
|
@@ -1187,19 +2013,19 @@ async function resolveDevflarePackageRoot(currentFilePath) {
|
|
|
1187
2013
|
}
|
|
1188
2014
|
async function resolveGeneratedViteImportPath(configDir) {
|
|
1189
2015
|
const { fileURLToPath } = await import("node:url");
|
|
1190
|
-
const { extname, normalize, relative: relative4, resolve:
|
|
2016
|
+
const { extname, normalize, relative: relative4, resolve: resolve7 } = await import("pathe");
|
|
1191
2017
|
const currentFilePath = normalize(fileURLToPath(import.meta.url));
|
|
1192
2018
|
const currentExtension = extname(currentFilePath);
|
|
1193
2019
|
const packageRoot = await resolveDevflarePackageRoot(currentFilePath);
|
|
1194
|
-
const viteEntryPath = currentFilePath.includes("/dist/") ?
|
|
2020
|
+
const viteEntryPath = currentFilePath.includes("/dist/") ? resolve7(packageRoot, "dist/vite/index.js") : resolve7(packageRoot, `src/vite/index${currentExtension}`);
|
|
1195
2021
|
const relativeImportPath = relative4(configDir, viteEntryPath);
|
|
1196
2022
|
return relativeImportPath.startsWith(".") ? relativeImportPath : `./${relativeImportPath}`;
|
|
1197
2023
|
}
|
|
1198
2024
|
async function writeGeneratedViteConfig(options) {
|
|
1199
2025
|
const fs = await import("node:fs/promises");
|
|
1200
|
-
const { resolve:
|
|
2026
|
+
const { resolve: resolve7 } = await import("pathe");
|
|
1201
2027
|
const configDir = await ensureGeneratedConfigDir2(options.cwd);
|
|
1202
|
-
const generatedConfigPath =
|
|
2028
|
+
const generatedConfigPath = resolve7(configDir, GENERATED_VITE_CONFIG_FILENAME);
|
|
1203
2029
|
const viteImportPath = await resolveGeneratedViteImportPath(configDir);
|
|
1204
2030
|
const content = `import { defineConfig } from 'vite'
|
|
1205
2031
|
import { resolveViteUserConfig } from ${JSON.stringify(viteImportPath)}
|
|
@@ -1217,4 +2043,4 @@ export default defineConfig(async (env) => {
|
|
|
1217
2043
|
await fs.writeFile(generatedConfigPath, content, "utf-8");
|
|
1218
2044
|
return generatedConfigPath;
|
|
1219
2045
|
}
|
|
1220
|
-
export { DEFAULT_FETCH_ENTRY_FILES, DEFAULT_QUEUE_ENTRY_FILES, DEFAULT_SCHEDULED_ENTRY_FILES, DEFAULT_EMAIL_ENTRY_FILES, resolveWorkerSurfacePaths, hasWorkerSurfacePaths, prepareComposedWorkerEntrypoint,
|
|
2046
|
+
export { discoverDurableObjectFiles, buildQueueProducers, buildQueueConsumers, buildRateLimitsConfig, buildVersionMetadataConfig, buildWorkerLoadersConfig, buildMtlsCertificatesConfig, buildDispatchNamespacesConfig, buildWorkflowsConfig, buildPipelinesConfig, buildHyperdrivesConfig, buildImagesConfig, buildMediaConfig, buildArtifactsConfig, buildAiSearchNamespacesConfig, buildAiSearchInstancesConfig, buildSecretsStoreConfig, buildSendEmailConfig, resolveServiceBindings, getRouteDirectoryCandidate, discoverRoutes, DEFAULT_FETCH_ENTRY_FILES, DEFAULT_QUEUE_ENTRY_FILES, DEFAULT_SCHEDULED_ENTRY_FILES, DEFAULT_EMAIL_ENTRY_FILES, resolveWorkerSurfacePaths, hasWorkerSurfacePaths, prepareComposedWorkerEntrypoint, hasInlineViteConfig, resolveEffectiveViteProject, resolveViteUserConfig, writeGeneratedViteConfig, devflarePlugin2 as devflarePlugin, getPluginContext, getCloudflareConfig, getDevflareConfigs, devflarePlugin3 as devflarePlugin1 };
|