@cloudflare/vite-plugin 0.0.0-4cc036d46 → 0.0.0-4d2235829
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/asset-workers/asset-worker.js +5510 -1966
- package/dist/asset-workers/router-worker.js +4277 -1611
- package/dist/index.d.ts +2 -0
- package/dist/index.js +247 -155
- package/dist/runner-worker/index.js +11 -10
- package/package.json +9 -9
package/dist/index.d.ts
CHANGED
|
@@ -21,6 +21,8 @@ interface PluginConfig extends EntryWorkerConfig {
|
|
|
21
21
|
experimental?: {
|
|
22
22
|
/** Experimental support for handling the _headers and _redirects files during Vite dev mode. */
|
|
23
23
|
headersAndRedirectsDevModeSupport?: boolean;
|
|
24
|
+
/** Experimental support for mixed mode (where bindings configured with `remote: true` access remote resources). */
|
|
25
|
+
mixedMode?: boolean;
|
|
24
26
|
};
|
|
25
27
|
}
|
|
26
28
|
|
package/dist/index.js
CHANGED
|
@@ -489,7 +489,7 @@ import assert10 from "node:assert";
|
|
|
489
489
|
import * as fs5 from "node:fs";
|
|
490
490
|
import * as fsp2 from "node:fs/promises";
|
|
491
491
|
import * as path9 from "node:path";
|
|
492
|
-
import {
|
|
492
|
+
import { createRequest, sendResponse } from "@mjackson/node-fetch-server";
|
|
493
493
|
import replace from "@rollup/plugin-replace";
|
|
494
494
|
|
|
495
495
|
// ../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.0/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
|
|
@@ -1558,7 +1558,7 @@ var MagicString = class _MagicString {
|
|
|
1558
1558
|
|
|
1559
1559
|
// src/index.ts
|
|
1560
1560
|
import { Miniflare } from "miniflare";
|
|
1561
|
-
import
|
|
1561
|
+
import colors3 from "picocolors";
|
|
1562
1562
|
import * as vite7 from "vite";
|
|
1563
1563
|
|
|
1564
1564
|
// src/constants.ts
|
|
@@ -1589,7 +1589,7 @@ function matchAdditionalModule(source) {
|
|
|
1589
1589
|
return null;
|
|
1590
1590
|
}
|
|
1591
1591
|
function createModuleReference(type, id) {
|
|
1592
|
-
return `__CLOUDFLARE_MODULE__${type}__${id}
|
|
1592
|
+
return `__CLOUDFLARE_MODULE__${type}__${id}__CLOUDFLARE_MODULE__`;
|
|
1593
1593
|
}
|
|
1594
1594
|
|
|
1595
1595
|
// src/asset-config.ts
|
|
@@ -5784,7 +5784,8 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
5784
5784
|
// ../workers-shared/utils/types.ts
|
|
5785
5785
|
var InternalConfigSchema = z.object({
|
|
5786
5786
|
account_id: z.number().optional(),
|
|
5787
|
-
script_id: z.number().optional()
|
|
5787
|
+
script_id: z.number().optional(),
|
|
5788
|
+
debug: z.boolean().optional()
|
|
5788
5789
|
});
|
|
5789
5790
|
var RouterConfigSchema = z.object({
|
|
5790
5791
|
invoke_user_worker_ahead_of_assets: z.boolean().optional(),
|
|
@@ -12992,7 +12993,7 @@ var NodeJsCompatWarnings = class {
|
|
|
12992
12993
|
// src/shared.ts
|
|
12993
12994
|
var UNKNOWN_HOST = "http://localhost";
|
|
12994
12995
|
var INIT_PATH = "/__vite_plugin_cloudflare_init__";
|
|
12995
|
-
var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)
|
|
12996
|
+
var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)__CLOUDFLARE_MODULE__`;
|
|
12996
12997
|
var additionalModuleRE = new RegExp(ADDITIONAL_MODULE_PATTERN);
|
|
12997
12998
|
var additionalModuleGlobalRE = new RegExp(
|
|
12998
12999
|
ADDITIONAL_MODULE_PATTERN,
|
|
@@ -13028,19 +13029,6 @@ function toMiniflareRequest(request) {
|
|
|
13028
13029
|
duplex: "half"
|
|
13029
13030
|
});
|
|
13030
13031
|
}
|
|
13031
|
-
function nodeHeadersToWebHeaders(nodeHeaders) {
|
|
13032
|
-
const headers = new Headers();
|
|
13033
|
-
for (const [key, value] of Object.entries(nodeHeaders)) {
|
|
13034
|
-
if (typeof value === "string") {
|
|
13035
|
-
headers.append(key, value);
|
|
13036
|
-
} else if (Array.isArray(value)) {
|
|
13037
|
-
for (const item of value) {
|
|
13038
|
-
headers.append(key, item);
|
|
13039
|
-
}
|
|
13040
|
-
}
|
|
13041
|
-
}
|
|
13042
|
-
return headers;
|
|
13043
|
-
}
|
|
13044
13032
|
var postfixRE = /[?#].*$/;
|
|
13045
13033
|
function cleanUrl(url) {
|
|
13046
13034
|
return url.replace(postfixRE, "");
|
|
@@ -13269,7 +13257,7 @@ import { unstable_readConfig } from "wrangler";
|
|
|
13269
13257
|
function getDeployConfigPath(root) {
|
|
13270
13258
|
return path5.resolve(root, ".wrangler", "deploy", "config.json");
|
|
13271
13259
|
}
|
|
13272
|
-
function getWorkerConfigs(root) {
|
|
13260
|
+
function getWorkerConfigs(root, mixedModeEnabled) {
|
|
13273
13261
|
const deployConfigPath = getDeployConfigPath(root);
|
|
13274
13262
|
const deployConfig = JSON.parse(
|
|
13275
13263
|
fs2.readFileSync(deployConfigPath, "utf-8")
|
|
@@ -13282,7 +13270,10 @@ function getWorkerConfigs(root) {
|
|
|
13282
13270
|
path5.dirname(deployConfigPath),
|
|
13283
13271
|
configPath
|
|
13284
13272
|
);
|
|
13285
|
-
return unstable_readConfig(
|
|
13273
|
+
return unstable_readConfig(
|
|
13274
|
+
{ config: resolvedConfigPath },
|
|
13275
|
+
{ experimental: { mixedModeEnabled } }
|
|
13276
|
+
);
|
|
13286
13277
|
});
|
|
13287
13278
|
}
|
|
13288
13279
|
function getRelativePathToWorkerConfig(deployConfigDirectory, root, outputDirectory) {
|
|
@@ -13349,17 +13340,24 @@ import * as fsp from "node:fs/promises";
|
|
|
13349
13340
|
import * as path6 from "node:path";
|
|
13350
13341
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
13351
13342
|
import {
|
|
13343
|
+
getDefaultDevRegistryPath,
|
|
13352
13344
|
kCurrentWorker,
|
|
13353
13345
|
Log,
|
|
13354
13346
|
LogLevel,
|
|
13355
13347
|
Response as MiniflareResponse
|
|
13356
13348
|
} from "miniflare";
|
|
13349
|
+
import colors2 from "picocolors";
|
|
13357
13350
|
import { globSync } from "tinyglobby";
|
|
13358
13351
|
import "vite";
|
|
13359
|
-
import {
|
|
13360
|
-
|
|
13352
|
+
import {
|
|
13353
|
+
experimental_pickRemoteBindings,
|
|
13354
|
+
experimental_startMixedModeSession,
|
|
13355
|
+
unstable_convertConfigBindingsToStartWorkerBindings,
|
|
13356
|
+
unstable_getMiniflareWorkerOptions
|
|
13357
|
+
} from "wrangler";
|
|
13358
|
+
function getPersistenceRoot(root, persistState) {
|
|
13361
13359
|
if (persistState === false) {
|
|
13362
|
-
return
|
|
13360
|
+
return;
|
|
13363
13361
|
}
|
|
13364
13362
|
const defaultPersistPath = ".wrangler/state";
|
|
13365
13363
|
const persistPath = path6.resolve(
|
|
@@ -13367,14 +13365,7 @@ function getPersistence(root, persistState) {
|
|
|
13367
13365
|
typeof persistState === "object" ? persistState.path : defaultPersistPath,
|
|
13368
13366
|
"v3"
|
|
13369
13367
|
);
|
|
13370
|
-
return
|
|
13371
|
-
cachePersist: path6.join(persistPath, "cache"),
|
|
13372
|
-
d1Persist: path6.join(persistPath, "d1"),
|
|
13373
|
-
durableObjectsPersist: path6.join(persistPath, "do"),
|
|
13374
|
-
kvPersist: path6.join(persistPath, "kv"),
|
|
13375
|
-
r2Persist: path6.join(persistPath, "r2"),
|
|
13376
|
-
workflowsPersist: path6.join(persistPath, "workflows")
|
|
13377
|
-
};
|
|
13368
|
+
return persistPath;
|
|
13378
13369
|
}
|
|
13379
13370
|
function missingWorkerErrorMessage(workerName) {
|
|
13380
13371
|
return `${workerName} does not match a worker name.`;
|
|
@@ -13458,7 +13449,29 @@ function getEntryWorkerConfig(resolvedPluginConfig) {
|
|
|
13458
13449
|
}
|
|
13459
13450
|
return resolvedPluginConfig.workers[resolvedPluginConfig.entryWorkerEnvironmentName];
|
|
13460
13451
|
}
|
|
13461
|
-
function
|
|
13452
|
+
function logUnknownTails(tails, userWorkers, log) {
|
|
13453
|
+
for (const tailService of tails ?? []) {
|
|
13454
|
+
let name;
|
|
13455
|
+
if (typeof tailService === "string") {
|
|
13456
|
+
name = tailService;
|
|
13457
|
+
} else if (typeof tailService === "object" && "name" in tailService && typeof tailService.name === "string") {
|
|
13458
|
+
name = tailService.name;
|
|
13459
|
+
} else {
|
|
13460
|
+
continue;
|
|
13461
|
+
}
|
|
13462
|
+
const found = userWorkers.some((w) => w.name === name);
|
|
13463
|
+
if (!found) {
|
|
13464
|
+
log(
|
|
13465
|
+
colors2.dim(
|
|
13466
|
+
colors2.yellow(
|
|
13467
|
+
`Tail consumer "${name}" was not found in your config. Make sure you add it to the config or run it in another dev session if you'd like to simulate receiving tail events locally.`
|
|
13468
|
+
)
|
|
13469
|
+
)
|
|
13470
|
+
);
|
|
13471
|
+
}
|
|
13472
|
+
}
|
|
13473
|
+
}
|
|
13474
|
+
async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPort) {
|
|
13462
13475
|
const resolvedViteConfig = viteDevServer.config;
|
|
13463
13476
|
const entryWorkerConfig = getEntryWorkerConfig(resolvedPluginConfig);
|
|
13464
13477
|
const assetsConfig = getAssetsConfig(
|
|
@@ -13534,53 +13547,64 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13534
13547
|
}
|
|
13535
13548
|
}
|
|
13536
13549
|
];
|
|
13537
|
-
const workersFromConfig = resolvedPluginConfig.type === "workers" ?
|
|
13538
|
-
(
|
|
13539
|
-
|
|
13540
|
-
|
|
13541
|
-
|
|
13542
|
-
|
|
13543
|
-
|
|
13544
|
-
|
|
13545
|
-
|
|
13546
|
-
|
|
13547
|
-
|
|
13548
|
-
|
|
13549
|
-
|
|
13550
|
-
|
|
13551
|
-
|
|
13552
|
-
|
|
13553
|
-
|
|
13554
|
-
|
|
13555
|
-
|
|
13556
|
-
|
|
13557
|
-
...workerOptions
|
|
13558
|
-
|
|
13559
|
-
|
|
13560
|
-
|
|
13561
|
-
|
|
13562
|
-
|
|
13563
|
-
|
|
13564
|
-
|
|
13565
|
-
|
|
13566
|
-
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
|
|
13570
|
-
|
|
13571
|
-
|
|
13572
|
-
|
|
13573
|
-
|
|
13574
|
-
|
|
13550
|
+
const workersFromConfig = resolvedPluginConfig.type === "workers" ? await Promise.all(
|
|
13551
|
+
Object.entries(resolvedPluginConfig.workers).map(
|
|
13552
|
+
async ([environmentName, workerConfig]) => {
|
|
13553
|
+
const mixedModeSession = resolvedPluginConfig.experimental.mixedMode ? await maybeStartOrUpdateMixedModeSession(workerConfig) : void 0;
|
|
13554
|
+
const miniflareWorkerOptions = unstable_getMiniflareWorkerOptions(
|
|
13555
|
+
{
|
|
13556
|
+
...workerConfig,
|
|
13557
|
+
assets: void 0
|
|
13558
|
+
},
|
|
13559
|
+
resolvedPluginConfig.cloudflareEnv,
|
|
13560
|
+
{
|
|
13561
|
+
mixedModeConnectionString: mixedModeSession?.mixedModeConnectionString,
|
|
13562
|
+
mixedModeEnabled: resolvedPluginConfig.experimental.mixedMode
|
|
13563
|
+
}
|
|
13564
|
+
);
|
|
13565
|
+
const { externalWorkers: externalWorkers2 } = miniflareWorkerOptions;
|
|
13566
|
+
const { ratelimits, ...workerOptions } = miniflareWorkerOptions.workerOptions;
|
|
13567
|
+
return {
|
|
13568
|
+
externalWorkers: externalWorkers2,
|
|
13569
|
+
worker: {
|
|
13570
|
+
...workerOptions,
|
|
13571
|
+
name: workerOptions.name ?? workerConfig.name,
|
|
13572
|
+
unsafeInspectorProxy: inspectorPort !== false,
|
|
13573
|
+
unsafeDirectSockets: environmentName === resolvedPluginConfig.entryWorkerEnvironmentName ? (
|
|
13574
|
+
// Expose the default entrypoint of the entry worker on the dev registry
|
|
13575
|
+
[{ entrypoint: void 0, proxy: true }]
|
|
13576
|
+
) : [],
|
|
13577
|
+
modulesRoot: miniflareModulesRoot,
|
|
13578
|
+
unsafeEvalBinding: "__VITE_UNSAFE_EVAL__",
|
|
13579
|
+
serviceBindings: {
|
|
13580
|
+
...workerOptions.serviceBindings,
|
|
13581
|
+
...environmentName === resolvedPluginConfig.entryWorkerEnvironmentName && workerConfig.assets?.binding ? {
|
|
13582
|
+
[workerConfig.assets.binding]: ASSET_WORKER_NAME
|
|
13583
|
+
} : {},
|
|
13584
|
+
__VITE_INVOKE_MODULE__: async (request) => {
|
|
13585
|
+
const payload = await request.json();
|
|
13586
|
+
const invokePayloadData = payload.data;
|
|
13587
|
+
assert6(
|
|
13588
|
+
invokePayloadData.name === "fetchModule",
|
|
13589
|
+
`Invalid invoke event: ${invokePayloadData.name}`
|
|
13590
|
+
);
|
|
13591
|
+
const [moduleId] = invokePayloadData.data;
|
|
13592
|
+
if (additionalModuleRE.test(moduleId)) {
|
|
13593
|
+
const result2 = {
|
|
13594
|
+
externalize: moduleId,
|
|
13595
|
+
type: "module"
|
|
13596
|
+
};
|
|
13597
|
+
return MiniflareResponse.json({ result: result2 });
|
|
13598
|
+
}
|
|
13599
|
+
const devEnvironment = viteDevServer.environments[environmentName];
|
|
13600
|
+
const result = await devEnvironment.hot.handleInvoke(payload);
|
|
13601
|
+
return MiniflareResponse.json(result);
|
|
13575
13602
|
}
|
|
13576
|
-
const devEnvironment = viteDevServer.environments[environmentName];
|
|
13577
|
-
const result = await devEnvironment.hot.handleInvoke(payload);
|
|
13578
|
-
return MiniflareResponse.json(result);
|
|
13579
13603
|
}
|
|
13580
13604
|
}
|
|
13581
|
-
}
|
|
13582
|
-
}
|
|
13583
|
-
|
|
13605
|
+
};
|
|
13606
|
+
}
|
|
13607
|
+
)
|
|
13584
13608
|
) : [];
|
|
13585
13609
|
const userWorkers = workersFromConfig.map((options) => options.worker);
|
|
13586
13610
|
const externalWorkers = workersFromConfig.flatMap(
|
|
@@ -13592,8 +13616,10 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13592
13616
|
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
13593
13617
|
return {
|
|
13594
13618
|
log: logger,
|
|
13619
|
+
logRequests: false,
|
|
13595
13620
|
inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
|
|
13596
13621
|
unsafeInspectorProxy: inspectorPort !== false,
|
|
13622
|
+
unsafeDevRegistryPath: getDefaultDevRegistryPath(),
|
|
13597
13623
|
handleRuntimeStdio(stdout, stderr) {
|
|
13598
13624
|
const decoder = new TextDecoder();
|
|
13599
13625
|
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
@@ -13601,7 +13627,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13601
13627
|
(error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
|
|
13602
13628
|
);
|
|
13603
13629
|
},
|
|
13604
|
-
|
|
13630
|
+
defaultPersistRoot: getPersistenceRoot(
|
|
13605
13631
|
resolvedViteConfig.root,
|
|
13606
13632
|
resolvedPluginConfig.persistState
|
|
13607
13633
|
),
|
|
@@ -13647,6 +13673,11 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13647
13673
|
`export const ${className} = createWorkflowEntrypointWrapper('${className}');`
|
|
13648
13674
|
);
|
|
13649
13675
|
}
|
|
13676
|
+
logUnknownTails(
|
|
13677
|
+
workerOptions.tails,
|
|
13678
|
+
userWorkers,
|
|
13679
|
+
viteDevServer.config.logger.warn
|
|
13680
|
+
);
|
|
13650
13681
|
return {
|
|
13651
13682
|
...workerOptions,
|
|
13652
13683
|
modules: [
|
|
@@ -13730,27 +13761,48 @@ function getPreviewModules(main, modulesRules) {
|
|
|
13730
13761
|
]
|
|
13731
13762
|
};
|
|
13732
13763
|
}
|
|
13733
|
-
function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistState, inspectorPort) {
|
|
13764
|
+
async function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistState, mixedModeEnabled, inspectorPort) {
|
|
13734
13765
|
const resolvedViteConfig = vitePreviewServer.config;
|
|
13735
|
-
const workers =
|
|
13736
|
-
|
|
13737
|
-
|
|
13738
|
-
|
|
13739
|
-
|
|
13740
|
-
|
|
13741
|
-
|
|
13742
|
-
|
|
13743
|
-
|
|
13744
|
-
|
|
13745
|
-
|
|
13746
|
-
|
|
13747
|
-
|
|
13748
|
-
|
|
13766
|
+
const workers = (await Promise.all(
|
|
13767
|
+
workerConfigs.map(async (workerConfig, i) => {
|
|
13768
|
+
const mixedModeSession = mixedModeEnabled ? await maybeStartOrUpdateMixedModeSession(workerConfig) : void 0;
|
|
13769
|
+
const miniflareWorkerOptions = unstable_getMiniflareWorkerOptions(
|
|
13770
|
+
workerConfig,
|
|
13771
|
+
void 0,
|
|
13772
|
+
{
|
|
13773
|
+
mixedModeConnectionString: mixedModeSession?.mixedModeConnectionString,
|
|
13774
|
+
mixedModeEnabled
|
|
13775
|
+
}
|
|
13776
|
+
);
|
|
13777
|
+
const { externalWorkers } = miniflareWorkerOptions;
|
|
13778
|
+
const { ratelimits, modulesRules, ...workerOptions } = miniflareWorkerOptions.workerOptions;
|
|
13779
|
+
logUnknownTails(
|
|
13780
|
+
workerOptions.tails,
|
|
13781
|
+
workerConfigs,
|
|
13782
|
+
vitePreviewServer.config.logger.warn
|
|
13783
|
+
);
|
|
13784
|
+
return [
|
|
13785
|
+
{
|
|
13786
|
+
...workerOptions,
|
|
13787
|
+
name: workerOptions.name ?? workerConfig.name,
|
|
13788
|
+
unsafeInspectorProxy: inspectorPort !== false,
|
|
13789
|
+
unsafeDirectSockets: (
|
|
13790
|
+
// This exposes the default entrypoint of the entry worker on the dev registry
|
|
13791
|
+
// Assuming that the first worker config to be the entry worker.
|
|
13792
|
+
i === 0 ? [{ entrypoint: void 0, proxy: true }] : []
|
|
13793
|
+
),
|
|
13794
|
+
...miniflareWorkerOptions.main ? getPreviewModules(miniflareWorkerOptions.main, modulesRules) : { modules: true, script: "" }
|
|
13795
|
+
},
|
|
13796
|
+
...externalWorkers
|
|
13797
|
+
];
|
|
13798
|
+
})
|
|
13799
|
+
)).flat();
|
|
13749
13800
|
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
13750
13801
|
return {
|
|
13751
13802
|
log: logger,
|
|
13752
13803
|
inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
|
|
13753
13804
|
unsafeInspectorProxy: inspectorPort !== false,
|
|
13805
|
+
unsafeDevRegistryPath: getDefaultDevRegistryPath(),
|
|
13754
13806
|
handleRuntimeStdio(stdout, stderr) {
|
|
13755
13807
|
const decoder = new TextDecoder();
|
|
13756
13808
|
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
@@ -13758,11 +13810,13 @@ function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistSta
|
|
|
13758
13810
|
(error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
|
|
13759
13811
|
);
|
|
13760
13812
|
},
|
|
13761
|
-
|
|
13813
|
+
defaultPersistRoot: getPersistenceRoot(
|
|
13814
|
+
resolvedViteConfig.root,
|
|
13815
|
+
persistState
|
|
13816
|
+
),
|
|
13762
13817
|
workers
|
|
13763
13818
|
};
|
|
13764
13819
|
}
|
|
13765
|
-
var removedMessages = [/^Ready on http/, /^Updated and ready on http/];
|
|
13766
13820
|
var ViteMiniflareLogger = class extends Log {
|
|
13767
13821
|
logger;
|
|
13768
13822
|
constructor(config) {
|
|
@@ -13770,11 +13824,6 @@ var ViteMiniflareLogger = class extends Log {
|
|
|
13770
13824
|
this.logger = config.logger;
|
|
13771
13825
|
}
|
|
13772
13826
|
logWithLevel(level, message) {
|
|
13773
|
-
for (const removedMessage of removedMessages) {
|
|
13774
|
-
if (removedMessage.test(message)) {
|
|
13775
|
-
return;
|
|
13776
|
-
}
|
|
13777
|
-
}
|
|
13778
13827
|
switch (level) {
|
|
13779
13828
|
case LogLevel.ERROR:
|
|
13780
13829
|
return this.logger.error(message);
|
|
@@ -13784,6 +13833,8 @@ var ViteMiniflareLogger = class extends Log {
|
|
|
13784
13833
|
return this.logger.info(message);
|
|
13785
13834
|
}
|
|
13786
13835
|
}
|
|
13836
|
+
logReady() {
|
|
13837
|
+
}
|
|
13787
13838
|
};
|
|
13788
13839
|
function miniflareLogLevelFromViteLogLevel(level = "info") {
|
|
13789
13840
|
switch (level) {
|
|
@@ -13797,6 +13848,24 @@ function miniflareLogLevelFromViteLogLevel(level = "info") {
|
|
|
13797
13848
|
return LogLevel.NONE;
|
|
13798
13849
|
}
|
|
13799
13850
|
}
|
|
13851
|
+
var mixedModeSessionsMap = /* @__PURE__ */ new Map();
|
|
13852
|
+
async function maybeStartOrUpdateMixedModeSession(workerConfig) {
|
|
13853
|
+
const workerRemoteBindings = experimental_pickRemoteBindings(
|
|
13854
|
+
unstable_convertConfigBindingsToStartWorkerBindings(workerConfig) ?? {}
|
|
13855
|
+
);
|
|
13856
|
+
assert6(workerConfig.name, "Found workerConfig without a name");
|
|
13857
|
+
let mixedModeSession = mixedModeSessionsMap.get(workerConfig.name);
|
|
13858
|
+
if (mixedModeSession === void 0) {
|
|
13859
|
+
if (Object.keys(workerRemoteBindings).length > 0) {
|
|
13860
|
+
mixedModeSession = await experimental_startMixedModeSession(workerRemoteBindings);
|
|
13861
|
+
mixedModeSessionsMap.set(workerConfig.name, mixedModeSession);
|
|
13862
|
+
}
|
|
13863
|
+
} else {
|
|
13864
|
+
await mixedModeSession.updateBindings(workerRemoteBindings);
|
|
13865
|
+
}
|
|
13866
|
+
await mixedModeSession?.ready;
|
|
13867
|
+
return mixedModeSession;
|
|
13868
|
+
}
|
|
13800
13869
|
|
|
13801
13870
|
// src/plugin-config.ts
|
|
13802
13871
|
import assert8 from "node:assert";
|
|
@@ -13851,12 +13920,15 @@ var nullableNonApplicable = [
|
|
|
13851
13920
|
"site",
|
|
13852
13921
|
"tsconfig"
|
|
13853
13922
|
];
|
|
13854
|
-
function readWorkerConfig(configPath, env2) {
|
|
13923
|
+
function readWorkerConfig(configPath, env2, mixedModeEnabled) {
|
|
13855
13924
|
const nonApplicable = {
|
|
13856
13925
|
replacedByVite: /* @__PURE__ */ new Set(),
|
|
13857
13926
|
notRelevant: /* @__PURE__ */ new Set()
|
|
13858
13927
|
};
|
|
13859
|
-
const config = unstable_readConfig2(
|
|
13928
|
+
const config = unstable_readConfig2(
|
|
13929
|
+
{ config: configPath, env: env2 },
|
|
13930
|
+
{ experimental: { mixedModeEnabled } }
|
|
13931
|
+
);
|
|
13860
13932
|
const raw = structuredClone(config);
|
|
13861
13933
|
nullableNonApplicable.forEach((prop) => {
|
|
13862
13934
|
if (config[prop] !== void 0) {
|
|
@@ -13951,11 +14023,15 @@ function isNotRelevant(configName) {
|
|
|
13951
14023
|
function missingFieldErrorMessage(field, configPath, env2) {
|
|
13952
14024
|
return `No ${field} field provided in '${configPath}'${env2 ? ` for '${env2}' environment` : ""}`;
|
|
13953
14025
|
}
|
|
13954
|
-
function getWorkerConfig(configPath, env2, opts) {
|
|
14026
|
+
function getWorkerConfig(configPath, env2, mixedModeEnabled, opts) {
|
|
13955
14027
|
if (opts?.visitedConfigPaths?.has(configPath)) {
|
|
13956
14028
|
throw new Error(`Duplicate Wrangler config path found: ${configPath}`);
|
|
13957
14029
|
}
|
|
13958
|
-
const { raw, config, nonApplicable } = readWorkerConfig(
|
|
14030
|
+
const { raw, config, nonApplicable } = readWorkerConfig(
|
|
14031
|
+
configPath,
|
|
14032
|
+
env2,
|
|
14033
|
+
mixedModeEnabled
|
|
14034
|
+
);
|
|
13959
14035
|
opts?.visitedConfigPaths?.add(configPath);
|
|
13960
14036
|
if (!config.name) {
|
|
13961
14037
|
throw new Error(missingFieldErrorMessage(`'name'`, configPath, env2));
|
|
@@ -14080,6 +14156,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14080
14156
|
const entryWorkerResolvedConfig = getWorkerConfig(
|
|
14081
14157
|
entryWorkerConfigPath,
|
|
14082
14158
|
cloudflareEnv,
|
|
14159
|
+
pluginConfig.experimental?.mixedMode ?? false,
|
|
14083
14160
|
{
|
|
14084
14161
|
visitedConfigPaths: configPaths,
|
|
14085
14162
|
isEntryWorker: true
|
|
@@ -14113,6 +14190,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14113
14190
|
const workerResolvedConfig = getWorkerConfig(
|
|
14114
14191
|
workerConfigPath,
|
|
14115
14192
|
cloudflareEnv,
|
|
14193
|
+
pluginConfig.experimental?.mixedMode ?? false,
|
|
14116
14194
|
{
|
|
14117
14195
|
visitedConfigPaths: configPaths
|
|
14118
14196
|
}
|
|
@@ -14147,6 +14225,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14147
14225
|
}
|
|
14148
14226
|
|
|
14149
14227
|
// src/websockets.ts
|
|
14228
|
+
import { createHeaders } from "@mjackson/node-fetch-server";
|
|
14150
14229
|
import { coupleWebSocket } from "miniflare";
|
|
14151
14230
|
import { WebSocketServer } from "ws";
|
|
14152
14231
|
function handleWebSocket(httpServer, getFetcher) {
|
|
@@ -14158,7 +14237,7 @@ function handleWebSocket(httpServer, getFetcher) {
|
|
|
14158
14237
|
if (request.headers["sec-websocket-protocol"]?.startsWith("vite")) {
|
|
14159
14238
|
return;
|
|
14160
14239
|
}
|
|
14161
|
-
const headers =
|
|
14240
|
+
const headers = createHeaders(request);
|
|
14162
14241
|
const fetcher = await getFetcher();
|
|
14163
14242
|
const response = await fetcher(url, {
|
|
14164
14243
|
headers,
|
|
@@ -14425,82 +14504,86 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14425
14504
|
}
|
|
14426
14505
|
},
|
|
14427
14506
|
async configureServer(viteDevServer) {
|
|
14428
|
-
|
|
14429
|
-
|
|
14430
|
-
|
|
14507
|
+
const inputInspectorPort = await getInputInspectorPortOption(
|
|
14508
|
+
pluginConfig,
|
|
14509
|
+
viteDevServer
|
|
14510
|
+
);
|
|
14511
|
+
const miniflareDevOptions = await getDevMiniflareOptions(
|
|
14512
|
+
resolvedPluginConfig,
|
|
14513
|
+
viteDevServer,
|
|
14514
|
+
inputInspectorPort
|
|
14431
14515
|
);
|
|
14432
14516
|
if (!miniflare) {
|
|
14433
|
-
|
|
14434
|
-
pluginConfig,
|
|
14435
|
-
viteDevServer
|
|
14436
|
-
);
|
|
14437
|
-
miniflare = new Miniflare(
|
|
14438
|
-
getDevMiniflareOptions(
|
|
14439
|
-
resolvedPluginConfig,
|
|
14440
|
-
viteDevServer,
|
|
14441
|
-
inputInspectorPort
|
|
14442
|
-
)
|
|
14443
|
-
);
|
|
14517
|
+
miniflare = new Miniflare(miniflareDevOptions);
|
|
14444
14518
|
} else {
|
|
14445
|
-
|
|
14446
|
-
await miniflare.setOptions(
|
|
14447
|
-
getDevMiniflareOptions(
|
|
14448
|
-
resolvedPluginConfig,
|
|
14449
|
-
viteDevServer,
|
|
14450
|
-
resolvedInspectorPort ?? false
|
|
14451
|
-
)
|
|
14452
|
-
);
|
|
14519
|
+
await miniflare.setOptions(miniflareDevOptions);
|
|
14453
14520
|
}
|
|
14454
14521
|
await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
|
|
14455
|
-
|
|
14456
|
-
async (
|
|
14522
|
+
if (viteDevServer.httpServer) {
|
|
14523
|
+
handleWebSocket(viteDevServer.httpServer, async () => {
|
|
14457
14524
|
assert10(miniflare, `Miniflare not defined`);
|
|
14458
14525
|
const routerWorker = await getRouterWorker(miniflare);
|
|
14459
|
-
return routerWorker.fetch
|
|
14460
|
-
|
|
14461
|
-
|
|
14462
|
-
},
|
|
14463
|
-
{ alwaysCallNext: false }
|
|
14464
|
-
);
|
|
14465
|
-
handleWebSocket(viteDevServer.httpServer, async () => {
|
|
14466
|
-
assert10(miniflare, `Miniflare not defined`);
|
|
14467
|
-
const routerWorker = await getRouterWorker(miniflare);
|
|
14468
|
-
return routerWorker.fetch;
|
|
14469
|
-
});
|
|
14526
|
+
return routerWorker.fetch;
|
|
14527
|
+
});
|
|
14528
|
+
}
|
|
14470
14529
|
return () => {
|
|
14471
|
-
viteDevServer.middlewares.use((req, res, next) => {
|
|
14472
|
-
|
|
14530
|
+
viteDevServer.middlewares.use(async (req, res, next) => {
|
|
14531
|
+
try {
|
|
14532
|
+
assert10(miniflare, `Miniflare not defined`);
|
|
14533
|
+
const routerWorker = await getRouterWorker(miniflare);
|
|
14534
|
+
const request = createRequest(req, res);
|
|
14535
|
+
const response = await routerWorker.fetch(
|
|
14536
|
+
toMiniflareRequest(request),
|
|
14537
|
+
{
|
|
14538
|
+
redirect: "manual"
|
|
14539
|
+
}
|
|
14540
|
+
);
|
|
14541
|
+
if (req.httpVersionMajor === 2) {
|
|
14542
|
+
response.headers.delete("transfer-encoding");
|
|
14543
|
+
}
|
|
14544
|
+
await sendResponse(res, response);
|
|
14545
|
+
} catch (error) {
|
|
14546
|
+
next(error);
|
|
14547
|
+
}
|
|
14473
14548
|
});
|
|
14474
14549
|
};
|
|
14475
14550
|
},
|
|
14476
14551
|
async configurePreviewServer(vitePreviewServer) {
|
|
14477
|
-
const workerConfigs = getWorkerConfigs(
|
|
14552
|
+
const workerConfigs = getWorkerConfigs(
|
|
14553
|
+
vitePreviewServer.config.root,
|
|
14554
|
+
pluginConfig.experimental?.mixedMode ?? false
|
|
14555
|
+
);
|
|
14478
14556
|
const inputInspectorPort = await getInputInspectorPortOption(
|
|
14479
14557
|
pluginConfig,
|
|
14480
14558
|
vitePreviewServer
|
|
14481
14559
|
);
|
|
14482
14560
|
const miniflare2 = new Miniflare(
|
|
14483
|
-
getPreviewMiniflareOptions(
|
|
14561
|
+
await getPreviewMiniflareOptions(
|
|
14484
14562
|
vitePreviewServer,
|
|
14485
14563
|
workerConfigs,
|
|
14486
14564
|
pluginConfig.persistState ?? true,
|
|
14565
|
+
!!pluginConfig.experimental?.mixedMode,
|
|
14487
14566
|
inputInspectorPort
|
|
14488
14567
|
)
|
|
14489
14568
|
);
|
|
14490
|
-
const middleware = createMiddleware(
|
|
14491
|
-
({ request }) => {
|
|
14492
|
-
return miniflare2.dispatchFetch(toMiniflareRequest(request), {
|
|
14493
|
-
redirect: "manual"
|
|
14494
|
-
});
|
|
14495
|
-
},
|
|
14496
|
-
{ alwaysCallNext: false }
|
|
14497
|
-
);
|
|
14498
14569
|
handleWebSocket(
|
|
14499
14570
|
vitePreviewServer.httpServer,
|
|
14500
14571
|
() => miniflare2.dispatchFetch
|
|
14501
14572
|
);
|
|
14502
|
-
vitePreviewServer.middlewares.use((req, res, next) => {
|
|
14503
|
-
|
|
14573
|
+
vitePreviewServer.middlewares.use(async (req, res, next) => {
|
|
14574
|
+
try {
|
|
14575
|
+
const request = createRequest(req, res);
|
|
14576
|
+
const response = await miniflare2.dispatchFetch(
|
|
14577
|
+
toMiniflareRequest(request),
|
|
14578
|
+
{ redirect: "manual" }
|
|
14579
|
+
);
|
|
14580
|
+
if (req.httpVersionMajor === 2) {
|
|
14581
|
+
response.headers.delete("transfer-encoding");
|
|
14582
|
+
}
|
|
14583
|
+
await sendResponse(res, response);
|
|
14584
|
+
} catch (error) {
|
|
14585
|
+
next(error);
|
|
14586
|
+
}
|
|
14504
14587
|
});
|
|
14505
14588
|
}
|
|
14506
14589
|
},
|
|
@@ -14736,7 +14819,10 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14736
14819
|
});
|
|
14737
14820
|
},
|
|
14738
14821
|
async configurePreviewServer(vitePreviewServer) {
|
|
14739
|
-
const workerConfigs = getWorkerConfigs(
|
|
14822
|
+
const workerConfigs = getWorkerConfigs(
|
|
14823
|
+
vitePreviewServer.config.root,
|
|
14824
|
+
pluginConfig.experimental?.mixedMode ?? false
|
|
14825
|
+
);
|
|
14740
14826
|
if (workerConfigs.length >= 1 && pluginConfig.inspectorPort !== false) {
|
|
14741
14827
|
addDebugToVitePrintUrls(vitePreviewServer);
|
|
14742
14828
|
}
|
|
@@ -14830,10 +14916,16 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14830
14916
|
}
|
|
14831
14917
|
}
|
|
14832
14918
|
async function getInputInspectorPortOption(pluginConfig, viteServer) {
|
|
14919
|
+
if (pluginConfig.inspectorPort === void 0 || pluginConfig.inspectorPort === 0) {
|
|
14920
|
+
const resolvedInspectorPort = await getResolvedInspectorPort(pluginConfig);
|
|
14921
|
+
if (resolvedInspectorPort !== null) {
|
|
14922
|
+
return resolvedInspectorPort;
|
|
14923
|
+
}
|
|
14924
|
+
}
|
|
14833
14925
|
const inputInspectorPort = pluginConfig.inspectorPort ?? await getFirstAvailablePort(DEFAULT_INSPECTOR_PORT);
|
|
14834
14926
|
if (pluginConfig.inspectorPort === void 0 && inputInspectorPort !== DEFAULT_INSPECTOR_PORT) {
|
|
14835
14927
|
viteServer.config.logger.warn(
|
|
14836
|
-
|
|
14928
|
+
colors3.dim(
|
|
14837
14929
|
`Default inspector port ${DEFAULT_INSPECTOR_PORT} not available, using ${inputInspectorPort} instead
|
|
14838
14930
|
`
|
|
14839
14931
|
)
|