@cloudflare/vite-plugin 0.0.0-cd542dfb2 → 0.0.0-ce4ac684d
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 +236 -150
- 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
|
|
@@ -12993,7 +12993,7 @@ var NodeJsCompatWarnings = class {
|
|
|
12993
12993
|
// src/shared.ts
|
|
12994
12994
|
var UNKNOWN_HOST = "http://localhost";
|
|
12995
12995
|
var INIT_PATH = "/__vite_plugin_cloudflare_init__";
|
|
12996
|
-
var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)
|
|
12996
|
+
var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)__CLOUDFLARE_MODULE__`;
|
|
12997
12997
|
var additionalModuleRE = new RegExp(ADDITIONAL_MODULE_PATTERN);
|
|
12998
12998
|
var additionalModuleGlobalRE = new RegExp(
|
|
12999
12999
|
ADDITIONAL_MODULE_PATTERN,
|
|
@@ -13029,19 +13029,6 @@ function toMiniflareRequest(request) {
|
|
|
13029
13029
|
duplex: "half"
|
|
13030
13030
|
});
|
|
13031
13031
|
}
|
|
13032
|
-
function nodeHeadersToWebHeaders(nodeHeaders) {
|
|
13033
|
-
const headers = new Headers();
|
|
13034
|
-
for (const [key, value] of Object.entries(nodeHeaders)) {
|
|
13035
|
-
if (typeof value === "string") {
|
|
13036
|
-
headers.append(key, value);
|
|
13037
|
-
} else if (Array.isArray(value)) {
|
|
13038
|
-
for (const item of value) {
|
|
13039
|
-
headers.append(key, item);
|
|
13040
|
-
}
|
|
13041
|
-
}
|
|
13042
|
-
}
|
|
13043
|
-
return headers;
|
|
13044
|
-
}
|
|
13045
13032
|
var postfixRE = /[?#].*$/;
|
|
13046
13033
|
function cleanUrl(url) {
|
|
13047
13034
|
return url.replace(postfixRE, "");
|
|
@@ -13270,7 +13257,7 @@ import { unstable_readConfig } from "wrangler";
|
|
|
13270
13257
|
function getDeployConfigPath(root) {
|
|
13271
13258
|
return path5.resolve(root, ".wrangler", "deploy", "config.json");
|
|
13272
13259
|
}
|
|
13273
|
-
function getWorkerConfigs(root) {
|
|
13260
|
+
function getWorkerConfigs(root, mixedModeEnabled) {
|
|
13274
13261
|
const deployConfigPath = getDeployConfigPath(root);
|
|
13275
13262
|
const deployConfig = JSON.parse(
|
|
13276
13263
|
fs2.readFileSync(deployConfigPath, "utf-8")
|
|
@@ -13283,7 +13270,10 @@ function getWorkerConfigs(root) {
|
|
|
13283
13270
|
path5.dirname(deployConfigPath),
|
|
13284
13271
|
configPath
|
|
13285
13272
|
);
|
|
13286
|
-
return unstable_readConfig(
|
|
13273
|
+
return unstable_readConfig(
|
|
13274
|
+
{ config: resolvedConfigPath },
|
|
13275
|
+
{ experimental: { mixedModeEnabled } }
|
|
13276
|
+
);
|
|
13287
13277
|
});
|
|
13288
13278
|
}
|
|
13289
13279
|
function getRelativePathToWorkerConfig(deployConfigDirectory, root, outputDirectory) {
|
|
@@ -13350,17 +13340,24 @@ import * as fsp from "node:fs/promises";
|
|
|
13350
13340
|
import * as path6 from "node:path";
|
|
13351
13341
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
13352
13342
|
import {
|
|
13343
|
+
getDefaultDevRegistryPath,
|
|
13353
13344
|
kCurrentWorker,
|
|
13354
13345
|
Log,
|
|
13355
13346
|
LogLevel,
|
|
13356
13347
|
Response as MiniflareResponse
|
|
13357
13348
|
} from "miniflare";
|
|
13349
|
+
import colors2 from "picocolors";
|
|
13358
13350
|
import { globSync } from "tinyglobby";
|
|
13359
13351
|
import "vite";
|
|
13360
|
-
import {
|
|
13361
|
-
|
|
13352
|
+
import {
|
|
13353
|
+
experimental_pickRemoteBindings,
|
|
13354
|
+
experimental_startMixedModeSession,
|
|
13355
|
+
unstable_convertConfigBindingsToStartWorkerBindings,
|
|
13356
|
+
unstable_getMiniflareWorkerOptions
|
|
13357
|
+
} from "wrangler";
|
|
13358
|
+
function getPersistenceRoot(root, persistState) {
|
|
13362
13359
|
if (persistState === false) {
|
|
13363
|
-
return
|
|
13360
|
+
return;
|
|
13364
13361
|
}
|
|
13365
13362
|
const defaultPersistPath = ".wrangler/state";
|
|
13366
13363
|
const persistPath = path6.resolve(
|
|
@@ -13368,14 +13365,7 @@ function getPersistence(root, persistState) {
|
|
|
13368
13365
|
typeof persistState === "object" ? persistState.path : defaultPersistPath,
|
|
13369
13366
|
"v3"
|
|
13370
13367
|
);
|
|
13371
|
-
return
|
|
13372
|
-
cachePersist: path6.join(persistPath, "cache"),
|
|
13373
|
-
d1Persist: path6.join(persistPath, "d1"),
|
|
13374
|
-
durableObjectsPersist: path6.join(persistPath, "do"),
|
|
13375
|
-
kvPersist: path6.join(persistPath, "kv"),
|
|
13376
|
-
r2Persist: path6.join(persistPath, "r2"),
|
|
13377
|
-
workflowsPersist: path6.join(persistPath, "workflows")
|
|
13378
|
-
};
|
|
13368
|
+
return persistPath;
|
|
13379
13369
|
}
|
|
13380
13370
|
function missingWorkerErrorMessage(workerName) {
|
|
13381
13371
|
return `${workerName} does not match a worker name.`;
|
|
@@ -13459,7 +13449,29 @@ function getEntryWorkerConfig(resolvedPluginConfig) {
|
|
|
13459
13449
|
}
|
|
13460
13450
|
return resolvedPluginConfig.workers[resolvedPluginConfig.entryWorkerEnvironmentName];
|
|
13461
13451
|
}
|
|
13462
|
-
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) {
|
|
13463
13475
|
const resolvedViteConfig = viteDevServer.config;
|
|
13464
13476
|
const entryWorkerConfig = getEntryWorkerConfig(resolvedPluginConfig);
|
|
13465
13477
|
const assetsConfig = getAssetsConfig(
|
|
@@ -13535,53 +13547,64 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13535
13547
|
}
|
|
13536
13548
|
}
|
|
13537
13549
|
];
|
|
13538
|
-
const workersFromConfig = resolvedPluginConfig.type === "workers" ?
|
|
13539
|
-
(
|
|
13540
|
-
|
|
13541
|
-
|
|
13542
|
-
|
|
13543
|
-
|
|
13544
|
-
|
|
13545
|
-
|
|
13546
|
-
|
|
13547
|
-
|
|
13548
|
-
|
|
13549
|
-
|
|
13550
|
-
|
|
13551
|
-
|
|
13552
|
-
|
|
13553
|
-
|
|
13554
|
-
|
|
13555
|
-
|
|
13556
|
-
|
|
13557
|
-
|
|
13558
|
-
...workerOptions
|
|
13559
|
-
|
|
13560
|
-
|
|
13561
|
-
|
|
13562
|
-
|
|
13563
|
-
|
|
13564
|
-
|
|
13565
|
-
|
|
13566
|
-
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
|
|
13570
|
-
|
|
13571
|
-
|
|
13572
|
-
|
|
13573
|
-
|
|
13574
|
-
|
|
13575
|
-
|
|
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);
|
|
13576
13602
|
}
|
|
13577
|
-
const devEnvironment = viteDevServer.environments[environmentName];
|
|
13578
|
-
const result = await devEnvironment.hot.handleInvoke(payload);
|
|
13579
|
-
return MiniflareResponse.json(result);
|
|
13580
13603
|
}
|
|
13581
13604
|
}
|
|
13582
|
-
}
|
|
13583
|
-
}
|
|
13584
|
-
|
|
13605
|
+
};
|
|
13606
|
+
}
|
|
13607
|
+
)
|
|
13585
13608
|
) : [];
|
|
13586
13609
|
const userWorkers = workersFromConfig.map((options) => options.worker);
|
|
13587
13610
|
const externalWorkers = workersFromConfig.flatMap(
|
|
@@ -13593,8 +13616,10 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13593
13616
|
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
13594
13617
|
return {
|
|
13595
13618
|
log: logger,
|
|
13619
|
+
logRequests: false,
|
|
13596
13620
|
inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
|
|
13597
13621
|
unsafeInspectorProxy: inspectorPort !== false,
|
|
13622
|
+
unsafeDevRegistryPath: getDefaultDevRegistryPath(),
|
|
13598
13623
|
handleRuntimeStdio(stdout, stderr) {
|
|
13599
13624
|
const decoder = new TextDecoder();
|
|
13600
13625
|
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
@@ -13602,7 +13627,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13602
13627
|
(error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
|
|
13603
13628
|
);
|
|
13604
13629
|
},
|
|
13605
|
-
|
|
13630
|
+
defaultPersistRoot: getPersistenceRoot(
|
|
13606
13631
|
resolvedViteConfig.root,
|
|
13607
13632
|
resolvedPluginConfig.persistState
|
|
13608
13633
|
),
|
|
@@ -13648,6 +13673,11 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13648
13673
|
`export const ${className} = createWorkflowEntrypointWrapper('${className}');`
|
|
13649
13674
|
);
|
|
13650
13675
|
}
|
|
13676
|
+
logUnknownTails(
|
|
13677
|
+
workerOptions.tails,
|
|
13678
|
+
userWorkers,
|
|
13679
|
+
viteDevServer.config.logger.warn
|
|
13680
|
+
);
|
|
13651
13681
|
return {
|
|
13652
13682
|
...workerOptions,
|
|
13653
13683
|
modules: [
|
|
@@ -13731,27 +13761,48 @@ function getPreviewModules(main, modulesRules) {
|
|
|
13731
13761
|
]
|
|
13732
13762
|
};
|
|
13733
13763
|
}
|
|
13734
|
-
function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistState, inspectorPort) {
|
|
13764
|
+
async function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistState, mixedModeEnabled, inspectorPort) {
|
|
13735
13765
|
const resolvedViteConfig = vitePreviewServer.config;
|
|
13736
|
-
const workers =
|
|
13737
|
-
|
|
13738
|
-
|
|
13739
|
-
|
|
13740
|
-
|
|
13741
|
-
|
|
13742
|
-
|
|
13743
|
-
|
|
13744
|
-
|
|
13745
|
-
|
|
13746
|
-
|
|
13747
|
-
|
|
13748
|
-
|
|
13749
|
-
|
|
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();
|
|
13750
13800
|
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
13751
13801
|
return {
|
|
13752
13802
|
log: logger,
|
|
13753
13803
|
inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
|
|
13754
13804
|
unsafeInspectorProxy: inspectorPort !== false,
|
|
13805
|
+
unsafeDevRegistryPath: getDefaultDevRegistryPath(),
|
|
13755
13806
|
handleRuntimeStdio(stdout, stderr) {
|
|
13756
13807
|
const decoder = new TextDecoder();
|
|
13757
13808
|
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
@@ -13759,11 +13810,13 @@ function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistSta
|
|
|
13759
13810
|
(error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
|
|
13760
13811
|
);
|
|
13761
13812
|
},
|
|
13762
|
-
|
|
13813
|
+
defaultPersistRoot: getPersistenceRoot(
|
|
13814
|
+
resolvedViteConfig.root,
|
|
13815
|
+
persistState
|
|
13816
|
+
),
|
|
13763
13817
|
workers
|
|
13764
13818
|
};
|
|
13765
13819
|
}
|
|
13766
|
-
var removedMessages = [/^Ready on http/, /^Updated and ready on http/];
|
|
13767
13820
|
var ViteMiniflareLogger = class extends Log {
|
|
13768
13821
|
logger;
|
|
13769
13822
|
constructor(config) {
|
|
@@ -13771,11 +13824,6 @@ var ViteMiniflareLogger = class extends Log {
|
|
|
13771
13824
|
this.logger = config.logger;
|
|
13772
13825
|
}
|
|
13773
13826
|
logWithLevel(level, message) {
|
|
13774
|
-
for (const removedMessage of removedMessages) {
|
|
13775
|
-
if (removedMessage.test(message)) {
|
|
13776
|
-
return;
|
|
13777
|
-
}
|
|
13778
|
-
}
|
|
13779
13827
|
switch (level) {
|
|
13780
13828
|
case LogLevel.ERROR:
|
|
13781
13829
|
return this.logger.error(message);
|
|
@@ -13785,6 +13833,8 @@ var ViteMiniflareLogger = class extends Log {
|
|
|
13785
13833
|
return this.logger.info(message);
|
|
13786
13834
|
}
|
|
13787
13835
|
}
|
|
13836
|
+
logReady() {
|
|
13837
|
+
}
|
|
13788
13838
|
};
|
|
13789
13839
|
function miniflareLogLevelFromViteLogLevel(level = "info") {
|
|
13790
13840
|
switch (level) {
|
|
@@ -13798,6 +13848,24 @@ function miniflareLogLevelFromViteLogLevel(level = "info") {
|
|
|
13798
13848
|
return LogLevel.NONE;
|
|
13799
13849
|
}
|
|
13800
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
|
+
}
|
|
13801
13869
|
|
|
13802
13870
|
// src/plugin-config.ts
|
|
13803
13871
|
import assert8 from "node:assert";
|
|
@@ -13852,12 +13920,15 @@ var nullableNonApplicable = [
|
|
|
13852
13920
|
"site",
|
|
13853
13921
|
"tsconfig"
|
|
13854
13922
|
];
|
|
13855
|
-
function readWorkerConfig(configPath, env2) {
|
|
13923
|
+
function readWorkerConfig(configPath, env2, mixedModeEnabled) {
|
|
13856
13924
|
const nonApplicable = {
|
|
13857
13925
|
replacedByVite: /* @__PURE__ */ new Set(),
|
|
13858
13926
|
notRelevant: /* @__PURE__ */ new Set()
|
|
13859
13927
|
};
|
|
13860
|
-
const config = unstable_readConfig2(
|
|
13928
|
+
const config = unstable_readConfig2(
|
|
13929
|
+
{ config: configPath, env: env2 },
|
|
13930
|
+
{ experimental: { mixedModeEnabled } }
|
|
13931
|
+
);
|
|
13861
13932
|
const raw = structuredClone(config);
|
|
13862
13933
|
nullableNonApplicable.forEach((prop) => {
|
|
13863
13934
|
if (config[prop] !== void 0) {
|
|
@@ -13952,11 +14023,15 @@ function isNotRelevant(configName) {
|
|
|
13952
14023
|
function missingFieldErrorMessage(field, configPath, env2) {
|
|
13953
14024
|
return `No ${field} field provided in '${configPath}'${env2 ? ` for '${env2}' environment` : ""}`;
|
|
13954
14025
|
}
|
|
13955
|
-
function getWorkerConfig(configPath, env2, opts) {
|
|
14026
|
+
function getWorkerConfig(configPath, env2, mixedModeEnabled, opts) {
|
|
13956
14027
|
if (opts?.visitedConfigPaths?.has(configPath)) {
|
|
13957
14028
|
throw new Error(`Duplicate Wrangler config path found: ${configPath}`);
|
|
13958
14029
|
}
|
|
13959
|
-
const { raw, config, nonApplicable } = readWorkerConfig(
|
|
14030
|
+
const { raw, config, nonApplicable } = readWorkerConfig(
|
|
14031
|
+
configPath,
|
|
14032
|
+
env2,
|
|
14033
|
+
mixedModeEnabled
|
|
14034
|
+
);
|
|
13960
14035
|
opts?.visitedConfigPaths?.add(configPath);
|
|
13961
14036
|
if (!config.name) {
|
|
13962
14037
|
throw new Error(missingFieldErrorMessage(`'name'`, configPath, env2));
|
|
@@ -14081,6 +14156,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14081
14156
|
const entryWorkerResolvedConfig = getWorkerConfig(
|
|
14082
14157
|
entryWorkerConfigPath,
|
|
14083
14158
|
cloudflareEnv,
|
|
14159
|
+
pluginConfig.experimental?.mixedMode ?? false,
|
|
14084
14160
|
{
|
|
14085
14161
|
visitedConfigPaths: configPaths,
|
|
14086
14162
|
isEntryWorker: true
|
|
@@ -14114,6 +14190,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14114
14190
|
const workerResolvedConfig = getWorkerConfig(
|
|
14115
14191
|
workerConfigPath,
|
|
14116
14192
|
cloudflareEnv,
|
|
14193
|
+
pluginConfig.experimental?.mixedMode ?? false,
|
|
14117
14194
|
{
|
|
14118
14195
|
visitedConfigPaths: configPaths
|
|
14119
14196
|
}
|
|
@@ -14148,6 +14225,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14148
14225
|
}
|
|
14149
14226
|
|
|
14150
14227
|
// src/websockets.ts
|
|
14228
|
+
import { createHeaders } from "@mjackson/node-fetch-server";
|
|
14151
14229
|
import { coupleWebSocket } from "miniflare";
|
|
14152
14230
|
import { WebSocketServer } from "ws";
|
|
14153
14231
|
function handleWebSocket(httpServer, getFetcher) {
|
|
@@ -14159,7 +14237,7 @@ function handleWebSocket(httpServer, getFetcher) {
|
|
|
14159
14237
|
if (request.headers["sec-websocket-protocol"]?.startsWith("vite")) {
|
|
14160
14238
|
return;
|
|
14161
14239
|
}
|
|
14162
|
-
const headers =
|
|
14240
|
+
const headers = createHeaders(request);
|
|
14163
14241
|
const fetcher = await getFetcher();
|
|
14164
14242
|
const response = await fetcher(url, {
|
|
14165
14243
|
headers,
|
|
@@ -14426,81 +14504,86 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14426
14504
|
}
|
|
14427
14505
|
},
|
|
14428
14506
|
async configureServer(viteDevServer) {
|
|
14429
|
-
assert10(
|
|
14430
|
-
viteDevServer.httpServer,
|
|
14431
|
-
"Unexpected error: No Vite HTTP server"
|
|
14432
|
-
);
|
|
14433
14507
|
const inputInspectorPort = await getInputInspectorPortOption(
|
|
14434
14508
|
pluginConfig,
|
|
14435
14509
|
viteDevServer
|
|
14436
14510
|
);
|
|
14511
|
+
const miniflareDevOptions = await getDevMiniflareOptions(
|
|
14512
|
+
resolvedPluginConfig,
|
|
14513
|
+
viteDevServer,
|
|
14514
|
+
inputInspectorPort
|
|
14515
|
+
);
|
|
14437
14516
|
if (!miniflare) {
|
|
14438
|
-
miniflare = new Miniflare(
|
|
14439
|
-
getDevMiniflareOptions(
|
|
14440
|
-
resolvedPluginConfig,
|
|
14441
|
-
viteDevServer,
|
|
14442
|
-
inputInspectorPort
|
|
14443
|
-
)
|
|
14444
|
-
);
|
|
14517
|
+
miniflare = new Miniflare(miniflareDevOptions);
|
|
14445
14518
|
} else {
|
|
14446
|
-
await miniflare.setOptions(
|
|
14447
|
-
getDevMiniflareOptions(
|
|
14448
|
-
resolvedPluginConfig,
|
|
14449
|
-
viteDevServer,
|
|
14450
|
-
inputInspectorPort
|
|
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
|
}
|
|
@@ -14839,7 +14925,7 @@ async function getInputInspectorPortOption(pluginConfig, viteServer) {
|
|
|
14839
14925
|
const inputInspectorPort = pluginConfig.inspectorPort ?? await getFirstAvailablePort(DEFAULT_INSPECTOR_PORT);
|
|
14840
14926
|
if (pluginConfig.inspectorPort === void 0 && inputInspectorPort !== DEFAULT_INSPECTOR_PORT) {
|
|
14841
14927
|
viteServer.config.logger.warn(
|
|
14842
|
-
|
|
14928
|
+
colors3.dim(
|
|
14843
14929
|
`Default inspector port ${DEFAULT_INSPECTOR_PORT} not available, using ${inputInspectorPort} instead
|
|
14844
14930
|
`
|
|
14845
14931
|
)
|