@cloudflare/vite-plugin 0.0.0-8c3cdc34e → 0.0.0-8c7ce7728
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 +5503 -1978
- package/dist/asset-workers/router-worker.js +4277 -1611
- package/dist/index.d.ts +2 -0
- package/dist/index.js +211 -157
- package/dist/runner-worker/index.js +1 -1
- package/package.json +8 -8
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
|
|
@@ -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,6 +13340,7 @@ 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,
|
|
@@ -13358,10 +13349,15 @@ import {
|
|
|
13358
13349
|
import colors2 from "picocolors";
|
|
13359
13350
|
import { globSync } from "tinyglobby";
|
|
13360
13351
|
import "vite";
|
|
13361
|
-
import {
|
|
13362
|
-
|
|
13352
|
+
import {
|
|
13353
|
+
experimental_pickRemoteBindings,
|
|
13354
|
+
experimental_startMixedModeSession,
|
|
13355
|
+
unstable_convertConfigBindingsToStartWorkerBindings,
|
|
13356
|
+
unstable_getMiniflareWorkerOptions
|
|
13357
|
+
} from "wrangler";
|
|
13358
|
+
function getPersistenceRoot(root, persistState) {
|
|
13363
13359
|
if (persistState === false) {
|
|
13364
|
-
return
|
|
13360
|
+
return;
|
|
13365
13361
|
}
|
|
13366
13362
|
const defaultPersistPath = ".wrangler/state";
|
|
13367
13363
|
const persistPath = path6.resolve(
|
|
@@ -13369,14 +13365,7 @@ function getPersistence(root, persistState) {
|
|
|
13369
13365
|
typeof persistState === "object" ? persistState.path : defaultPersistPath,
|
|
13370
13366
|
"v3"
|
|
13371
13367
|
);
|
|
13372
|
-
return
|
|
13373
|
-
cachePersist: path6.join(persistPath, "cache"),
|
|
13374
|
-
d1Persist: path6.join(persistPath, "d1"),
|
|
13375
|
-
durableObjectsPersist: path6.join(persistPath, "do"),
|
|
13376
|
-
kvPersist: path6.join(persistPath, "kv"),
|
|
13377
|
-
r2Persist: path6.join(persistPath, "r2"),
|
|
13378
|
-
workflowsPersist: path6.join(persistPath, "workflows")
|
|
13379
|
-
};
|
|
13368
|
+
return persistPath;
|
|
13380
13369
|
}
|
|
13381
13370
|
function missingWorkerErrorMessage(workerName) {
|
|
13382
13371
|
return `${workerName} does not match a worker name.`;
|
|
@@ -13460,30 +13449,29 @@ function getEntryWorkerConfig(resolvedPluginConfig) {
|
|
|
13460
13449
|
}
|
|
13461
13450
|
return resolvedPluginConfig.workers[resolvedPluginConfig.entryWorkerEnvironmentName];
|
|
13462
13451
|
}
|
|
13463
|
-
function
|
|
13464
|
-
|
|
13452
|
+
function logUnknownTails(tails, userWorkers, log) {
|
|
13453
|
+
for (const tailService of tails ?? []) {
|
|
13465
13454
|
let name;
|
|
13466
13455
|
if (typeof tailService === "string") {
|
|
13467
13456
|
name = tailService;
|
|
13468
13457
|
} else if (typeof tailService === "object" && "name" in tailService && typeof tailService.name === "string") {
|
|
13469
13458
|
name = tailService.name;
|
|
13470
13459
|
} else {
|
|
13471
|
-
|
|
13460
|
+
continue;
|
|
13472
13461
|
}
|
|
13473
13462
|
const found = userWorkers.some((w) => w.name === name);
|
|
13474
13463
|
if (!found) {
|
|
13475
13464
|
log(
|
|
13476
13465
|
colors2.dim(
|
|
13477
13466
|
colors2.yellow(
|
|
13478
|
-
`Tail consumer "${name}" was not found in your config. Make sure you add it if you'd like to simulate receiving tail events locally.`
|
|
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.`
|
|
13479
13468
|
)
|
|
13480
13469
|
)
|
|
13481
13470
|
);
|
|
13482
13471
|
}
|
|
13483
|
-
|
|
13484
|
-
});
|
|
13472
|
+
}
|
|
13485
13473
|
}
|
|
13486
|
-
function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPort) {
|
|
13474
|
+
async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPort) {
|
|
13487
13475
|
const resolvedViteConfig = viteDevServer.config;
|
|
13488
13476
|
const entryWorkerConfig = getEntryWorkerConfig(resolvedPluginConfig);
|
|
13489
13477
|
const assetsConfig = getAssetsConfig(
|
|
@@ -13559,53 +13547,64 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13559
13547
|
}
|
|
13560
13548
|
}
|
|
13561
13549
|
];
|
|
13562
|
-
const workersFromConfig = resolvedPluginConfig.type === "workers" ?
|
|
13563
|
-
(
|
|
13564
|
-
|
|
13565
|
-
|
|
13566
|
-
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
|
|
13570
|
-
|
|
13571
|
-
|
|
13572
|
-
|
|
13573
|
-
|
|
13574
|
-
|
|
13575
|
-
|
|
13576
|
-
|
|
13577
|
-
|
|
13578
|
-
|
|
13579
|
-
|
|
13580
|
-
|
|
13581
|
-
|
|
13582
|
-
...workerOptions
|
|
13583
|
-
|
|
13584
|
-
|
|
13585
|
-
|
|
13586
|
-
|
|
13587
|
-
|
|
13588
|
-
|
|
13589
|
-
|
|
13590
|
-
|
|
13591
|
-
|
|
13592
|
-
|
|
13593
|
-
|
|
13594
|
-
|
|
13595
|
-
|
|
13596
|
-
|
|
13597
|
-
|
|
13598
|
-
|
|
13599
|
-
|
|
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);
|
|
13600
13602
|
}
|
|
13601
|
-
const devEnvironment = viteDevServer.environments[environmentName];
|
|
13602
|
-
const result = await devEnvironment.hot.handleInvoke(payload);
|
|
13603
|
-
return MiniflareResponse.json(result);
|
|
13604
13603
|
}
|
|
13605
13604
|
}
|
|
13606
|
-
}
|
|
13607
|
-
}
|
|
13608
|
-
|
|
13605
|
+
};
|
|
13606
|
+
}
|
|
13607
|
+
)
|
|
13609
13608
|
) : [];
|
|
13610
13609
|
const userWorkers = workersFromConfig.map((options) => options.worker);
|
|
13611
13610
|
const externalWorkers = workersFromConfig.flatMap(
|
|
@@ -13617,8 +13616,10 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13617
13616
|
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
13618
13617
|
return {
|
|
13619
13618
|
log: logger,
|
|
13619
|
+
logRequests: false,
|
|
13620
13620
|
inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
|
|
13621
13621
|
unsafeInspectorProxy: inspectorPort !== false,
|
|
13622
|
+
unsafeDevRegistryPath: getDefaultDevRegistryPath(),
|
|
13622
13623
|
handleRuntimeStdio(stdout, stderr) {
|
|
13623
13624
|
const decoder = new TextDecoder();
|
|
13624
13625
|
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
@@ -13626,7 +13627,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13626
13627
|
(error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
|
|
13627
13628
|
);
|
|
13628
13629
|
},
|
|
13629
|
-
|
|
13630
|
+
defaultPersistRoot: getPersistenceRoot(
|
|
13630
13631
|
resolvedViteConfig.root,
|
|
13631
13632
|
resolvedPluginConfig.persistState
|
|
13632
13633
|
),
|
|
@@ -13672,13 +13673,13 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13672
13673
|
`export const ${className} = createWorkflowEntrypointWrapper('${className}');`
|
|
13673
13674
|
);
|
|
13674
13675
|
}
|
|
13676
|
+
logUnknownTails(
|
|
13677
|
+
workerOptions.tails,
|
|
13678
|
+
userWorkers,
|
|
13679
|
+
viteDevServer.config.logger.warn
|
|
13680
|
+
);
|
|
13675
13681
|
return {
|
|
13676
13682
|
...workerOptions,
|
|
13677
|
-
tails: filterTails(
|
|
13678
|
-
workerOptions.tails,
|
|
13679
|
-
userWorkers,
|
|
13680
|
-
viteDevServer.config.logger.warn
|
|
13681
|
-
),
|
|
13682
13683
|
modules: [
|
|
13683
13684
|
{
|
|
13684
13685
|
type: "ESModule",
|
|
@@ -13760,32 +13761,48 @@ function getPreviewModules(main, modulesRules) {
|
|
|
13760
13761
|
]
|
|
13761
13762
|
};
|
|
13762
13763
|
}
|
|
13763
|
-
function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistState, inspectorPort) {
|
|
13764
|
+
async function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistState, mixedModeEnabled, inspectorPort) {
|
|
13764
13765
|
const resolvedViteConfig = vitePreviewServer.config;
|
|
13765
|
-
const workers =
|
|
13766
|
-
|
|
13767
|
-
|
|
13768
|
-
|
|
13769
|
-
|
|
13770
|
-
|
|
13771
|
-
|
|
13772
|
-
|
|
13773
|
-
|
|
13774
|
-
|
|
13775
|
-
|
|
13776
|
-
|
|
13777
|
-
|
|
13778
|
-
|
|
13779
|
-
|
|
13780
|
-
|
|
13781
|
-
|
|
13782
|
-
|
|
13783
|
-
|
|
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();
|
|
13784
13800
|
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
13785
13801
|
return {
|
|
13786
13802
|
log: logger,
|
|
13787
13803
|
inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
|
|
13788
13804
|
unsafeInspectorProxy: inspectorPort !== false,
|
|
13805
|
+
unsafeDevRegistryPath: getDefaultDevRegistryPath(),
|
|
13789
13806
|
handleRuntimeStdio(stdout, stderr) {
|
|
13790
13807
|
const decoder = new TextDecoder();
|
|
13791
13808
|
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
@@ -13793,11 +13810,13 @@ function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistSta
|
|
|
13793
13810
|
(error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
|
|
13794
13811
|
);
|
|
13795
13812
|
},
|
|
13796
|
-
|
|
13813
|
+
defaultPersistRoot: getPersistenceRoot(
|
|
13814
|
+
resolvedViteConfig.root,
|
|
13815
|
+
persistState
|
|
13816
|
+
),
|
|
13797
13817
|
workers
|
|
13798
13818
|
};
|
|
13799
13819
|
}
|
|
13800
|
-
var removedMessages = [/^Ready on http/, /^Updated and ready on http/];
|
|
13801
13820
|
var ViteMiniflareLogger = class extends Log {
|
|
13802
13821
|
logger;
|
|
13803
13822
|
constructor(config) {
|
|
@@ -13805,11 +13824,6 @@ var ViteMiniflareLogger = class extends Log {
|
|
|
13805
13824
|
this.logger = config.logger;
|
|
13806
13825
|
}
|
|
13807
13826
|
logWithLevel(level, message) {
|
|
13808
|
-
for (const removedMessage of removedMessages) {
|
|
13809
|
-
if (removedMessage.test(message)) {
|
|
13810
|
-
return;
|
|
13811
|
-
}
|
|
13812
|
-
}
|
|
13813
13827
|
switch (level) {
|
|
13814
13828
|
case LogLevel.ERROR:
|
|
13815
13829
|
return this.logger.error(message);
|
|
@@ -13819,6 +13833,8 @@ var ViteMiniflareLogger = class extends Log {
|
|
|
13819
13833
|
return this.logger.info(message);
|
|
13820
13834
|
}
|
|
13821
13835
|
}
|
|
13836
|
+
logReady() {
|
|
13837
|
+
}
|
|
13822
13838
|
};
|
|
13823
13839
|
function miniflareLogLevelFromViteLogLevel(level = "info") {
|
|
13824
13840
|
switch (level) {
|
|
@@ -13832,6 +13848,24 @@ function miniflareLogLevelFromViteLogLevel(level = "info") {
|
|
|
13832
13848
|
return LogLevel.NONE;
|
|
13833
13849
|
}
|
|
13834
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
|
+
}
|
|
13835
13869
|
|
|
13836
13870
|
// src/plugin-config.ts
|
|
13837
13871
|
import assert8 from "node:assert";
|
|
@@ -13886,12 +13920,15 @@ var nullableNonApplicable = [
|
|
|
13886
13920
|
"site",
|
|
13887
13921
|
"tsconfig"
|
|
13888
13922
|
];
|
|
13889
|
-
function readWorkerConfig(configPath, env2) {
|
|
13923
|
+
function readWorkerConfig(configPath, env2, mixedModeEnabled) {
|
|
13890
13924
|
const nonApplicable = {
|
|
13891
13925
|
replacedByVite: /* @__PURE__ */ new Set(),
|
|
13892
13926
|
notRelevant: /* @__PURE__ */ new Set()
|
|
13893
13927
|
};
|
|
13894
|
-
const config = unstable_readConfig2(
|
|
13928
|
+
const config = unstable_readConfig2(
|
|
13929
|
+
{ config: configPath, env: env2 },
|
|
13930
|
+
{ experimental: { mixedModeEnabled } }
|
|
13931
|
+
);
|
|
13895
13932
|
const raw = structuredClone(config);
|
|
13896
13933
|
nullableNonApplicable.forEach((prop) => {
|
|
13897
13934
|
if (config[prop] !== void 0) {
|
|
@@ -13986,11 +14023,15 @@ function isNotRelevant(configName) {
|
|
|
13986
14023
|
function missingFieldErrorMessage(field, configPath, env2) {
|
|
13987
14024
|
return `No ${field} field provided in '${configPath}'${env2 ? ` for '${env2}' environment` : ""}`;
|
|
13988
14025
|
}
|
|
13989
|
-
function getWorkerConfig(configPath, env2, opts) {
|
|
14026
|
+
function getWorkerConfig(configPath, env2, mixedModeEnabled, opts) {
|
|
13990
14027
|
if (opts?.visitedConfigPaths?.has(configPath)) {
|
|
13991
14028
|
throw new Error(`Duplicate Wrangler config path found: ${configPath}`);
|
|
13992
14029
|
}
|
|
13993
|
-
const { raw, config, nonApplicable } = readWorkerConfig(
|
|
14030
|
+
const { raw, config, nonApplicable } = readWorkerConfig(
|
|
14031
|
+
configPath,
|
|
14032
|
+
env2,
|
|
14033
|
+
mixedModeEnabled
|
|
14034
|
+
);
|
|
13994
14035
|
opts?.visitedConfigPaths?.add(configPath);
|
|
13995
14036
|
if (!config.name) {
|
|
13996
14037
|
throw new Error(missingFieldErrorMessage(`'name'`, configPath, env2));
|
|
@@ -14115,6 +14156,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14115
14156
|
const entryWorkerResolvedConfig = getWorkerConfig(
|
|
14116
14157
|
entryWorkerConfigPath,
|
|
14117
14158
|
cloudflareEnv,
|
|
14159
|
+
pluginConfig.experimental?.mixedMode ?? false,
|
|
14118
14160
|
{
|
|
14119
14161
|
visitedConfigPaths: configPaths,
|
|
14120
14162
|
isEntryWorker: true
|
|
@@ -14148,6 +14190,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14148
14190
|
const workerResolvedConfig = getWorkerConfig(
|
|
14149
14191
|
workerConfigPath,
|
|
14150
14192
|
cloudflareEnv,
|
|
14193
|
+
pluginConfig.experimental?.mixedMode ?? false,
|
|
14151
14194
|
{
|
|
14152
14195
|
visitedConfigPaths: configPaths
|
|
14153
14196
|
}
|
|
@@ -14182,6 +14225,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14182
14225
|
}
|
|
14183
14226
|
|
|
14184
14227
|
// src/websockets.ts
|
|
14228
|
+
import { createHeaders } from "@mjackson/node-fetch-server";
|
|
14185
14229
|
import { coupleWebSocket } from "miniflare";
|
|
14186
14230
|
import { WebSocketServer } from "ws";
|
|
14187
14231
|
function handleWebSocket(httpServer, getFetcher) {
|
|
@@ -14193,7 +14237,7 @@ function handleWebSocket(httpServer, getFetcher) {
|
|
|
14193
14237
|
if (request.headers["sec-websocket-protocol"]?.startsWith("vite")) {
|
|
14194
14238
|
return;
|
|
14195
14239
|
}
|
|
14196
|
-
const headers =
|
|
14240
|
+
const headers = createHeaders(request);
|
|
14197
14241
|
const fetcher = await getFetcher();
|
|
14198
14242
|
const response = await fetcher(url, {
|
|
14199
14243
|
headers,
|
|
@@ -14464,34 +14508,17 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14464
14508
|
pluginConfig,
|
|
14465
14509
|
viteDevServer
|
|
14466
14510
|
);
|
|
14511
|
+
const miniflareDevOptions = await getDevMiniflareOptions(
|
|
14512
|
+
resolvedPluginConfig,
|
|
14513
|
+
viteDevServer,
|
|
14514
|
+
inputInspectorPort
|
|
14515
|
+
);
|
|
14467
14516
|
if (!miniflare) {
|
|
14468
|
-
miniflare = new Miniflare(
|
|
14469
|
-
getDevMiniflareOptions(
|
|
14470
|
-
resolvedPluginConfig,
|
|
14471
|
-
viteDevServer,
|
|
14472
|
-
inputInspectorPort
|
|
14473
|
-
)
|
|
14474
|
-
);
|
|
14517
|
+
miniflare = new Miniflare(miniflareDevOptions);
|
|
14475
14518
|
} else {
|
|
14476
|
-
await miniflare.setOptions(
|
|
14477
|
-
getDevMiniflareOptions(
|
|
14478
|
-
resolvedPluginConfig,
|
|
14479
|
-
viteDevServer,
|
|
14480
|
-
inputInspectorPort
|
|
14481
|
-
)
|
|
14482
|
-
);
|
|
14519
|
+
await miniflare.setOptions(miniflareDevOptions);
|
|
14483
14520
|
}
|
|
14484
14521
|
await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
|
|
14485
|
-
const middleware = createMiddleware(
|
|
14486
|
-
async ({ request }) => {
|
|
14487
|
-
assert10(miniflare, `Miniflare not defined`);
|
|
14488
|
-
const routerWorker = await getRouterWorker(miniflare);
|
|
14489
|
-
return routerWorker.fetch(toMiniflareRequest(request), {
|
|
14490
|
-
redirect: "manual"
|
|
14491
|
-
});
|
|
14492
|
-
},
|
|
14493
|
-
{ alwaysCallNext: false }
|
|
14494
|
-
);
|
|
14495
14522
|
if (viteDevServer.httpServer) {
|
|
14496
14523
|
handleWebSocket(viteDevServer.httpServer, async () => {
|
|
14497
14524
|
assert10(miniflare, `Miniflare not defined`);
|
|
@@ -14500,39 +14527,63 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14500
14527
|
});
|
|
14501
14528
|
}
|
|
14502
14529
|
return () => {
|
|
14503
|
-
viteDevServer.middlewares.use((req, res, next) => {
|
|
14504
|
-
|
|
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
|
+
}
|
|
14505
14548
|
});
|
|
14506
14549
|
};
|
|
14507
14550
|
},
|
|
14508
14551
|
async configurePreviewServer(vitePreviewServer) {
|
|
14509
|
-
const workerConfigs = getWorkerConfigs(
|
|
14552
|
+
const workerConfigs = getWorkerConfigs(
|
|
14553
|
+
vitePreviewServer.config.root,
|
|
14554
|
+
pluginConfig.experimental?.mixedMode ?? false
|
|
14555
|
+
);
|
|
14510
14556
|
const inputInspectorPort = await getInputInspectorPortOption(
|
|
14511
14557
|
pluginConfig,
|
|
14512
14558
|
vitePreviewServer
|
|
14513
14559
|
);
|
|
14514
14560
|
const miniflare2 = new Miniflare(
|
|
14515
|
-
getPreviewMiniflareOptions(
|
|
14561
|
+
await getPreviewMiniflareOptions(
|
|
14516
14562
|
vitePreviewServer,
|
|
14517
14563
|
workerConfigs,
|
|
14518
14564
|
pluginConfig.persistState ?? true,
|
|
14565
|
+
!!pluginConfig.experimental?.mixedMode,
|
|
14519
14566
|
inputInspectorPort
|
|
14520
14567
|
)
|
|
14521
14568
|
);
|
|
14522
|
-
const middleware = createMiddleware(
|
|
14523
|
-
({ request }) => {
|
|
14524
|
-
return miniflare2.dispatchFetch(toMiniflareRequest(request), {
|
|
14525
|
-
redirect: "manual"
|
|
14526
|
-
});
|
|
14527
|
-
},
|
|
14528
|
-
{ alwaysCallNext: false }
|
|
14529
|
-
);
|
|
14530
14569
|
handleWebSocket(
|
|
14531
14570
|
vitePreviewServer.httpServer,
|
|
14532
14571
|
() => miniflare2.dispatchFetch
|
|
14533
14572
|
);
|
|
14534
|
-
vitePreviewServer.middlewares.use((req, res, next) => {
|
|
14535
|
-
|
|
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
|
+
}
|
|
14536
14587
|
});
|
|
14537
14588
|
}
|
|
14538
14589
|
},
|
|
@@ -14768,7 +14819,10 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14768
14819
|
});
|
|
14769
14820
|
},
|
|
14770
14821
|
async configurePreviewServer(vitePreviewServer) {
|
|
14771
|
-
const workerConfigs = getWorkerConfigs(
|
|
14822
|
+
const workerConfigs = getWorkerConfigs(
|
|
14823
|
+
vitePreviewServer.config.root,
|
|
14824
|
+
pluginConfig.experimental?.mixedMode ?? false
|
|
14825
|
+
);
|
|
14772
14826
|
if (workerConfigs.length >= 1 && pluginConfig.inspectorPort !== false) {
|
|
14773
14827
|
addDebugToVitePrintUrls(vitePreviewServer);
|
|
14774
14828
|
}
|
|
@@ -15,7 +15,7 @@ var ADDITIONAL_MODULE_TYPES = [
|
|
|
15
15
|
// src/shared.ts
|
|
16
16
|
var UNKNOWN_HOST = "http://localhost";
|
|
17
17
|
var INIT_PATH = "/__vite_plugin_cloudflare_init__";
|
|
18
|
-
var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)
|
|
18
|
+
var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)__CLOUDFLARE_MODULE__`;
|
|
19
19
|
var additionalModuleRE = new RegExp(ADDITIONAL_MODULE_PATTERN);
|
|
20
20
|
var additionalModuleGlobalRE = new RegExp(
|
|
21
21
|
ADDITIONAL_MODULE_PATTERN,
|