@cloudflare/vite-plugin 0.0.0-e34d19867 → 0.0.0-e3b3ef51c
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 +5505 -1979
- package/dist/asset-workers/router-worker.js +4277 -1611
- package/dist/index.d.ts +2 -0
- package/dist/index.js +210 -142
- package/dist/runner-worker/index.js +2 -1
- package/package.json +5 -6
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
|
@@ -1571,6 +1571,7 @@ var ADDITIONAL_MODULE_TYPES = [
|
|
|
1571
1571
|
"Text"
|
|
1572
1572
|
];
|
|
1573
1573
|
var DEFAULT_INSPECTOR_PORT = 9229;
|
|
1574
|
+
var kRequestType = Symbol("kRequestType");
|
|
1574
1575
|
|
|
1575
1576
|
// src/additional-modules.ts
|
|
1576
1577
|
var moduleRules = [
|
|
@@ -1589,7 +1590,7 @@ function matchAdditionalModule(source) {
|
|
|
1589
1590
|
return null;
|
|
1590
1591
|
}
|
|
1591
1592
|
function createModuleReference(type, id) {
|
|
1592
|
-
return `__CLOUDFLARE_MODULE__${type}__${id}
|
|
1593
|
+
return `__CLOUDFLARE_MODULE__${type}__${id}__CLOUDFLARE_MODULE__`;
|
|
1593
1594
|
}
|
|
1594
1595
|
|
|
1595
1596
|
// src/asset-config.ts
|
|
@@ -12648,8 +12649,8 @@ function packageResolve(specifier, base, conditions) {
|
|
|
12648
12649
|
let packageJsonPath = fileURLToPath$1(packageJsonUrl);
|
|
12649
12650
|
let lastPath;
|
|
12650
12651
|
do {
|
|
12651
|
-
const
|
|
12652
|
-
if (!
|
|
12652
|
+
const stat2 = tryStatSync(packageJsonPath.slice(0, -13));
|
|
12653
|
+
if (!stat2 || !stat2.isDirectory()) {
|
|
12653
12654
|
lastPath = packageJsonPath;
|
|
12654
12655
|
packageJsonUrl = new URL$1(
|
|
12655
12656
|
(isScoped ? "../../../../node_modules/" : "../../../node_modules/") + packageName + "/package.json",
|
|
@@ -12779,8 +12780,8 @@ function _resolve(id, options = {}) {
|
|
|
12779
12780
|
}
|
|
12780
12781
|
if (isAbsolute(id)) {
|
|
12781
12782
|
try {
|
|
12782
|
-
const
|
|
12783
|
-
if (
|
|
12783
|
+
const stat2 = statSync(id);
|
|
12784
|
+
if (stat2.isFile()) {
|
|
12784
12785
|
return pathToFileURL(id);
|
|
12785
12786
|
}
|
|
12786
12787
|
} catch (error) {
|
|
@@ -12993,7 +12994,7 @@ var NodeJsCompatWarnings = class {
|
|
|
12993
12994
|
// src/shared.ts
|
|
12994
12995
|
var UNKNOWN_HOST = "http://localhost";
|
|
12995
12996
|
var INIT_PATH = "/__vite_plugin_cloudflare_init__";
|
|
12996
|
-
var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)
|
|
12997
|
+
var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)__CLOUDFLARE_MODULE__`;
|
|
12997
12998
|
var additionalModuleRE = new RegExp(ADDITIONAL_MODULE_PATTERN);
|
|
12998
12999
|
var additionalModuleGlobalRE = new RegExp(
|
|
12999
13000
|
ADDITIONAL_MODULE_PATTERN,
|
|
@@ -13010,9 +13011,6 @@ function getOutputDirectory(userConfig, environmentName) {
|
|
|
13010
13011
|
const rootOutputDirectory = userConfig.build?.outDir ?? "dist";
|
|
13011
13012
|
return userConfig.environments?.[environmentName]?.build?.outDir ?? path4.join(rootOutputDirectory, environmentName);
|
|
13012
13013
|
}
|
|
13013
|
-
function getRouterWorker(miniflare2) {
|
|
13014
|
-
return miniflare2.getWorker(ROUTER_WORKER_NAME);
|
|
13015
|
-
}
|
|
13016
13014
|
function toMiniflareRequest(request) {
|
|
13017
13015
|
const host = request.headers.get("Host");
|
|
13018
13016
|
if (host) {
|
|
@@ -13257,7 +13255,7 @@ import { unstable_readConfig } from "wrangler";
|
|
|
13257
13255
|
function getDeployConfigPath(root) {
|
|
13258
13256
|
return path5.resolve(root, ".wrangler", "deploy", "config.json");
|
|
13259
13257
|
}
|
|
13260
|
-
function getWorkerConfigs(root) {
|
|
13258
|
+
function getWorkerConfigs(root, mixedModeEnabled) {
|
|
13261
13259
|
const deployConfigPath = getDeployConfigPath(root);
|
|
13262
13260
|
const deployConfig = JSON.parse(
|
|
13263
13261
|
fs2.readFileSync(deployConfigPath, "utf-8")
|
|
@@ -13270,7 +13268,10 @@ function getWorkerConfigs(root) {
|
|
|
13270
13268
|
path5.dirname(deployConfigPath),
|
|
13271
13269
|
configPath
|
|
13272
13270
|
);
|
|
13273
|
-
return unstable_readConfig(
|
|
13271
|
+
return unstable_readConfig(
|
|
13272
|
+
{ config: resolvedConfigPath },
|
|
13273
|
+
{ experimental: { mixedModeEnabled } }
|
|
13274
|
+
);
|
|
13274
13275
|
});
|
|
13275
13276
|
}
|
|
13276
13277
|
function getRelativePathToWorkerConfig(deployConfigDirectory, root, outputDirectory) {
|
|
@@ -13337,6 +13338,7 @@ import * as fsp from "node:fs/promises";
|
|
|
13337
13338
|
import * as path6 from "node:path";
|
|
13338
13339
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
13339
13340
|
import {
|
|
13341
|
+
getDefaultDevRegistryPath,
|
|
13340
13342
|
kCurrentWorker,
|
|
13341
13343
|
Log,
|
|
13342
13344
|
LogLevel,
|
|
@@ -13345,10 +13347,15 @@ import {
|
|
|
13345
13347
|
import colors2 from "picocolors";
|
|
13346
13348
|
import { globSync } from "tinyglobby";
|
|
13347
13349
|
import "vite";
|
|
13348
|
-
import {
|
|
13349
|
-
|
|
13350
|
+
import {
|
|
13351
|
+
experimental_pickRemoteBindings,
|
|
13352
|
+
experimental_startMixedModeSession,
|
|
13353
|
+
unstable_convertConfigBindingsToStartWorkerBindings,
|
|
13354
|
+
unstable_getMiniflareWorkerOptions
|
|
13355
|
+
} from "wrangler";
|
|
13356
|
+
function getPersistenceRoot(root, persistState) {
|
|
13350
13357
|
if (persistState === false) {
|
|
13351
|
-
return
|
|
13358
|
+
return;
|
|
13352
13359
|
}
|
|
13353
13360
|
const defaultPersistPath = ".wrangler/state";
|
|
13354
13361
|
const persistPath = path6.resolve(
|
|
@@ -13356,14 +13363,7 @@ function getPersistence(root, persistState) {
|
|
|
13356
13363
|
typeof persistState === "object" ? persistState.path : defaultPersistPath,
|
|
13357
13364
|
"v3"
|
|
13358
13365
|
);
|
|
13359
|
-
return
|
|
13360
|
-
cachePersist: path6.join(persistPath, "cache"),
|
|
13361
|
-
d1Persist: path6.join(persistPath, "d1"),
|
|
13362
|
-
durableObjectsPersist: path6.join(persistPath, "do"),
|
|
13363
|
-
kvPersist: path6.join(persistPath, "kv"),
|
|
13364
|
-
r2Persist: path6.join(persistPath, "r2"),
|
|
13365
|
-
workflowsPersist: path6.join(persistPath, "workflows")
|
|
13366
|
-
};
|
|
13366
|
+
return persistPath;
|
|
13367
13367
|
}
|
|
13368
13368
|
function missingWorkerErrorMessage(workerName) {
|
|
13369
13369
|
return `${workerName} does not match a worker name.`;
|
|
@@ -13447,30 +13447,29 @@ function getEntryWorkerConfig(resolvedPluginConfig) {
|
|
|
13447
13447
|
}
|
|
13448
13448
|
return resolvedPluginConfig.workers[resolvedPluginConfig.entryWorkerEnvironmentName];
|
|
13449
13449
|
}
|
|
13450
|
-
function
|
|
13451
|
-
|
|
13450
|
+
function logUnknownTails(tails, userWorkers, log) {
|
|
13451
|
+
for (const tailService of tails ?? []) {
|
|
13452
13452
|
let name;
|
|
13453
13453
|
if (typeof tailService === "string") {
|
|
13454
13454
|
name = tailService;
|
|
13455
13455
|
} else if (typeof tailService === "object" && "name" in tailService && typeof tailService.name === "string") {
|
|
13456
13456
|
name = tailService.name;
|
|
13457
13457
|
} else {
|
|
13458
|
-
|
|
13458
|
+
continue;
|
|
13459
13459
|
}
|
|
13460
13460
|
const found = userWorkers.some((w) => w.name === name);
|
|
13461
13461
|
if (!found) {
|
|
13462
13462
|
log(
|
|
13463
13463
|
colors2.dim(
|
|
13464
13464
|
colors2.yellow(
|
|
13465
|
-
`Tail consumer "${name}" was not found in your config. Make sure you add it if you'd like to simulate receiving tail events locally.`
|
|
13465
|
+
`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.`
|
|
13466
13466
|
)
|
|
13467
13467
|
)
|
|
13468
13468
|
);
|
|
13469
13469
|
}
|
|
13470
|
-
|
|
13471
|
-
});
|
|
13470
|
+
}
|
|
13472
13471
|
}
|
|
13473
|
-
function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPort) {
|
|
13472
|
+
async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPort) {
|
|
13474
13473
|
const resolvedViteConfig = viteDevServer.config;
|
|
13475
13474
|
const entryWorkerConfig = getEntryWorkerConfig(resolvedPluginConfig);
|
|
13476
13475
|
const assetsConfig = getAssetsConfig(
|
|
@@ -13521,12 +13520,14 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13521
13520
|
serviceBindings: {
|
|
13522
13521
|
__VITE_ASSET_EXISTS__: async (request) => {
|
|
13523
13522
|
const { pathname } = new URL(request.url);
|
|
13524
|
-
|
|
13525
|
-
|
|
13526
|
-
|
|
13527
|
-
|
|
13528
|
-
|
|
13529
|
-
|
|
13523
|
+
let exists = false;
|
|
13524
|
+
if (pathname.endsWith(".html")) {
|
|
13525
|
+
try {
|
|
13526
|
+
const filePath = path6.join(resolvedViteConfig.root, pathname);
|
|
13527
|
+
const stats = await fsp.stat(filePath);
|
|
13528
|
+
exists = stats.isFile();
|
|
13529
|
+
} catch (error) {
|
|
13530
|
+
}
|
|
13530
13531
|
}
|
|
13531
13532
|
return MiniflareResponse.json(exists);
|
|
13532
13533
|
},
|
|
@@ -13540,59 +13541,75 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13540
13541
|
headers: { "Content-Type": "text/html" }
|
|
13541
13542
|
});
|
|
13542
13543
|
} catch (error) {
|
|
13543
|
-
throw new Error(`Unexpected error. Failed to load ${pathname}
|
|
13544
|
+
throw new Error(`Unexpected error. Failed to load "${pathname}".`);
|
|
13544
13545
|
}
|
|
13545
13546
|
}
|
|
13546
13547
|
}
|
|
13547
13548
|
}
|
|
13548
13549
|
];
|
|
13549
|
-
const workersFromConfig = resolvedPluginConfig.type === "workers" ?
|
|
13550
|
-
(
|
|
13551
|
-
|
|
13552
|
-
|
|
13553
|
-
|
|
13554
|
-
|
|
13555
|
-
|
|
13556
|
-
|
|
13557
|
-
|
|
13558
|
-
|
|
13559
|
-
|
|
13560
|
-
|
|
13561
|
-
|
|
13562
|
-
|
|
13563
|
-
|
|
13564
|
-
|
|
13565
|
-
|
|
13566
|
-
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
...workerOptions
|
|
13570
|
-
|
|
13571
|
-
|
|
13572
|
-
|
|
13573
|
-
|
|
13574
|
-
|
|
13575
|
-
|
|
13576
|
-
|
|
13577
|
-
|
|
13578
|
-
|
|
13579
|
-
|
|
13580
|
-
|
|
13581
|
-
|
|
13582
|
-
|
|
13583
|
-
|
|
13584
|
-
|
|
13585
|
-
|
|
13586
|
-
|
|
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]: {
|
|
13583
|
+
node: (req, res) => {
|
|
13584
|
+
req[kRequestType] = "asset";
|
|
13585
|
+
viteDevServer.middlewares(req, res);
|
|
13586
|
+
}
|
|
13587
|
+
}
|
|
13588
|
+
} : {},
|
|
13589
|
+
__VITE_INVOKE_MODULE__: async (request) => {
|
|
13590
|
+
const payload = await request.json();
|
|
13591
|
+
const invokePayloadData = payload.data;
|
|
13592
|
+
assert6(
|
|
13593
|
+
invokePayloadData.name === "fetchModule",
|
|
13594
|
+
`Invalid invoke event: ${invokePayloadData.name}`
|
|
13595
|
+
);
|
|
13596
|
+
const [moduleId] = invokePayloadData.data;
|
|
13597
|
+
if (additionalModuleRE.test(moduleId)) {
|
|
13598
|
+
const result2 = {
|
|
13599
|
+
externalize: moduleId,
|
|
13600
|
+
type: "module"
|
|
13601
|
+
};
|
|
13602
|
+
return MiniflareResponse.json({ result: result2 });
|
|
13603
|
+
}
|
|
13604
|
+
const devEnvironment = viteDevServer.environments[environmentName];
|
|
13605
|
+
const result = await devEnvironment.hot.handleInvoke(payload);
|
|
13606
|
+
return MiniflareResponse.json(result);
|
|
13587
13607
|
}
|
|
13588
|
-
const devEnvironment = viteDevServer.environments[environmentName];
|
|
13589
|
-
const result = await devEnvironment.hot.handleInvoke(payload);
|
|
13590
|
-
return MiniflareResponse.json(result);
|
|
13591
13608
|
}
|
|
13592
13609
|
}
|
|
13593
|
-
}
|
|
13594
|
-
}
|
|
13595
|
-
|
|
13610
|
+
};
|
|
13611
|
+
}
|
|
13612
|
+
)
|
|
13596
13613
|
) : [];
|
|
13597
13614
|
const userWorkers = workersFromConfig.map((options) => options.worker);
|
|
13598
13615
|
const externalWorkers = workersFromConfig.flatMap(
|
|
@@ -13604,8 +13621,10 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13604
13621
|
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
13605
13622
|
return {
|
|
13606
13623
|
log: logger,
|
|
13624
|
+
logRequests: false,
|
|
13607
13625
|
inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
|
|
13608
13626
|
unsafeInspectorProxy: inspectorPort !== false,
|
|
13627
|
+
unsafeDevRegistryPath: getDefaultDevRegistryPath(),
|
|
13609
13628
|
handleRuntimeStdio(stdout, stderr) {
|
|
13610
13629
|
const decoder = new TextDecoder();
|
|
13611
13630
|
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
@@ -13613,7 +13632,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13613
13632
|
(error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
|
|
13614
13633
|
);
|
|
13615
13634
|
},
|
|
13616
|
-
|
|
13635
|
+
defaultPersistRoot: getPersistenceRoot(
|
|
13617
13636
|
resolvedViteConfig.root,
|
|
13618
13637
|
resolvedPluginConfig.persistState
|
|
13619
13638
|
),
|
|
@@ -13659,13 +13678,13 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13659
13678
|
`export const ${className} = createWorkflowEntrypointWrapper('${className}');`
|
|
13660
13679
|
);
|
|
13661
13680
|
}
|
|
13681
|
+
logUnknownTails(
|
|
13682
|
+
workerOptions.tails,
|
|
13683
|
+
userWorkers,
|
|
13684
|
+
viteDevServer.config.logger.warn
|
|
13685
|
+
);
|
|
13662
13686
|
return {
|
|
13663
13687
|
...workerOptions,
|
|
13664
|
-
tails: filterTails(
|
|
13665
|
-
workerOptions.tails,
|
|
13666
|
-
userWorkers,
|
|
13667
|
-
viteDevServer.config.logger.warn
|
|
13668
|
-
),
|
|
13669
13688
|
modules: [
|
|
13670
13689
|
{
|
|
13671
13690
|
type: "ESModule",
|
|
@@ -13747,32 +13766,48 @@ function getPreviewModules(main, modulesRules) {
|
|
|
13747
13766
|
]
|
|
13748
13767
|
};
|
|
13749
13768
|
}
|
|
13750
|
-
function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistState, inspectorPort) {
|
|
13769
|
+
async function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistState, mixedModeEnabled, inspectorPort) {
|
|
13751
13770
|
const resolvedViteConfig = vitePreviewServer.config;
|
|
13752
|
-
const workers =
|
|
13753
|
-
|
|
13754
|
-
|
|
13755
|
-
|
|
13756
|
-
|
|
13757
|
-
|
|
13758
|
-
|
|
13759
|
-
|
|
13760
|
-
|
|
13761
|
-
|
|
13762
|
-
|
|
13763
|
-
|
|
13764
|
-
|
|
13765
|
-
|
|
13766
|
-
|
|
13767
|
-
|
|
13768
|
-
|
|
13769
|
-
|
|
13770
|
-
|
|
13771
|
+
const workers = (await Promise.all(
|
|
13772
|
+
workerConfigs.map(async (workerConfig, i) => {
|
|
13773
|
+
const mixedModeSession = mixedModeEnabled ? await maybeStartOrUpdateMixedModeSession(workerConfig) : void 0;
|
|
13774
|
+
const miniflareWorkerOptions = unstable_getMiniflareWorkerOptions(
|
|
13775
|
+
workerConfig,
|
|
13776
|
+
void 0,
|
|
13777
|
+
{
|
|
13778
|
+
mixedModeConnectionString: mixedModeSession?.mixedModeConnectionString,
|
|
13779
|
+
mixedModeEnabled
|
|
13780
|
+
}
|
|
13781
|
+
);
|
|
13782
|
+
const { externalWorkers } = miniflareWorkerOptions;
|
|
13783
|
+
const { ratelimits, modulesRules, ...workerOptions } = miniflareWorkerOptions.workerOptions;
|
|
13784
|
+
logUnknownTails(
|
|
13785
|
+
workerOptions.tails,
|
|
13786
|
+
workerConfigs,
|
|
13787
|
+
vitePreviewServer.config.logger.warn
|
|
13788
|
+
);
|
|
13789
|
+
return [
|
|
13790
|
+
{
|
|
13791
|
+
...workerOptions,
|
|
13792
|
+
name: workerOptions.name ?? workerConfig.name,
|
|
13793
|
+
unsafeInspectorProxy: inspectorPort !== false,
|
|
13794
|
+
unsafeDirectSockets: (
|
|
13795
|
+
// This exposes the default entrypoint of the entry worker on the dev registry
|
|
13796
|
+
// Assuming that the first worker config to be the entry worker.
|
|
13797
|
+
i === 0 ? [{ entrypoint: void 0, proxy: true }] : []
|
|
13798
|
+
),
|
|
13799
|
+
...miniflareWorkerOptions.main ? getPreviewModules(miniflareWorkerOptions.main, modulesRules) : { modules: true, script: "" }
|
|
13800
|
+
},
|
|
13801
|
+
...externalWorkers
|
|
13802
|
+
];
|
|
13803
|
+
})
|
|
13804
|
+
)).flat();
|
|
13771
13805
|
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
13772
13806
|
return {
|
|
13773
13807
|
log: logger,
|
|
13774
13808
|
inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
|
|
13775
13809
|
unsafeInspectorProxy: inspectorPort !== false,
|
|
13810
|
+
unsafeDevRegistryPath: getDefaultDevRegistryPath(),
|
|
13776
13811
|
handleRuntimeStdio(stdout, stderr) {
|
|
13777
13812
|
const decoder = new TextDecoder();
|
|
13778
13813
|
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
@@ -13780,11 +13815,13 @@ function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistSta
|
|
|
13780
13815
|
(error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
|
|
13781
13816
|
);
|
|
13782
13817
|
},
|
|
13783
|
-
|
|
13818
|
+
defaultPersistRoot: getPersistenceRoot(
|
|
13819
|
+
resolvedViteConfig.root,
|
|
13820
|
+
persistState
|
|
13821
|
+
),
|
|
13784
13822
|
workers
|
|
13785
13823
|
};
|
|
13786
13824
|
}
|
|
13787
|
-
var removedMessages = [/^Ready on http/, /^Updated and ready on http/];
|
|
13788
13825
|
var ViteMiniflareLogger = class extends Log {
|
|
13789
13826
|
logger;
|
|
13790
13827
|
constructor(config) {
|
|
@@ -13792,11 +13829,6 @@ var ViteMiniflareLogger = class extends Log {
|
|
|
13792
13829
|
this.logger = config.logger;
|
|
13793
13830
|
}
|
|
13794
13831
|
logWithLevel(level, message) {
|
|
13795
|
-
for (const removedMessage of removedMessages) {
|
|
13796
|
-
if (removedMessage.test(message)) {
|
|
13797
|
-
return;
|
|
13798
|
-
}
|
|
13799
|
-
}
|
|
13800
13832
|
switch (level) {
|
|
13801
13833
|
case LogLevel.ERROR:
|
|
13802
13834
|
return this.logger.error(message);
|
|
@@ -13806,6 +13838,8 @@ var ViteMiniflareLogger = class extends Log {
|
|
|
13806
13838
|
return this.logger.info(message);
|
|
13807
13839
|
}
|
|
13808
13840
|
}
|
|
13841
|
+
logReady() {
|
|
13842
|
+
}
|
|
13809
13843
|
};
|
|
13810
13844
|
function miniflareLogLevelFromViteLogLevel(level = "info") {
|
|
13811
13845
|
switch (level) {
|
|
@@ -13819,6 +13853,24 @@ function miniflareLogLevelFromViteLogLevel(level = "info") {
|
|
|
13819
13853
|
return LogLevel.NONE;
|
|
13820
13854
|
}
|
|
13821
13855
|
}
|
|
13856
|
+
var mixedModeSessionsMap = /* @__PURE__ */ new Map();
|
|
13857
|
+
async function maybeStartOrUpdateMixedModeSession(workerConfig) {
|
|
13858
|
+
const workerRemoteBindings = experimental_pickRemoteBindings(
|
|
13859
|
+
unstable_convertConfigBindingsToStartWorkerBindings(workerConfig) ?? {}
|
|
13860
|
+
);
|
|
13861
|
+
assert6(workerConfig.name, "Found workerConfig without a name");
|
|
13862
|
+
let mixedModeSession = mixedModeSessionsMap.get(workerConfig.name);
|
|
13863
|
+
if (mixedModeSession === void 0) {
|
|
13864
|
+
if (Object.keys(workerRemoteBindings).length > 0) {
|
|
13865
|
+
mixedModeSession = await experimental_startMixedModeSession(workerRemoteBindings);
|
|
13866
|
+
mixedModeSessionsMap.set(workerConfig.name, mixedModeSession);
|
|
13867
|
+
}
|
|
13868
|
+
} else {
|
|
13869
|
+
await mixedModeSession.updateBindings(workerRemoteBindings);
|
|
13870
|
+
}
|
|
13871
|
+
await mixedModeSession?.ready;
|
|
13872
|
+
return mixedModeSession;
|
|
13873
|
+
}
|
|
13822
13874
|
|
|
13823
13875
|
// src/plugin-config.ts
|
|
13824
13876
|
import assert8 from "node:assert";
|
|
@@ -13873,12 +13925,15 @@ var nullableNonApplicable = [
|
|
|
13873
13925
|
"site",
|
|
13874
13926
|
"tsconfig"
|
|
13875
13927
|
];
|
|
13876
|
-
function readWorkerConfig(configPath, env2) {
|
|
13928
|
+
function readWorkerConfig(configPath, env2, mixedModeEnabled) {
|
|
13877
13929
|
const nonApplicable = {
|
|
13878
13930
|
replacedByVite: /* @__PURE__ */ new Set(),
|
|
13879
13931
|
notRelevant: /* @__PURE__ */ new Set()
|
|
13880
13932
|
};
|
|
13881
|
-
const config = unstable_readConfig2(
|
|
13933
|
+
const config = unstable_readConfig2(
|
|
13934
|
+
{ config: configPath, env: env2 },
|
|
13935
|
+
{ experimental: { mixedModeEnabled } }
|
|
13936
|
+
);
|
|
13882
13937
|
const raw = structuredClone(config);
|
|
13883
13938
|
nullableNonApplicable.forEach((prop) => {
|
|
13884
13939
|
if (config[prop] !== void 0) {
|
|
@@ -13973,11 +14028,15 @@ function isNotRelevant(configName) {
|
|
|
13973
14028
|
function missingFieldErrorMessage(field, configPath, env2) {
|
|
13974
14029
|
return `No ${field} field provided in '${configPath}'${env2 ? ` for '${env2}' environment` : ""}`;
|
|
13975
14030
|
}
|
|
13976
|
-
function getWorkerConfig(configPath, env2, opts) {
|
|
14031
|
+
function getWorkerConfig(configPath, env2, mixedModeEnabled, opts) {
|
|
13977
14032
|
if (opts?.visitedConfigPaths?.has(configPath)) {
|
|
13978
14033
|
throw new Error(`Duplicate Wrangler config path found: ${configPath}`);
|
|
13979
14034
|
}
|
|
13980
|
-
const { raw, config, nonApplicable } = readWorkerConfig(
|
|
14035
|
+
const { raw, config, nonApplicable } = readWorkerConfig(
|
|
14036
|
+
configPath,
|
|
14037
|
+
env2,
|
|
14038
|
+
mixedModeEnabled
|
|
14039
|
+
);
|
|
13981
14040
|
opts?.visitedConfigPaths?.add(configPath);
|
|
13982
14041
|
if (!config.name) {
|
|
13983
14042
|
throw new Error(missingFieldErrorMessage(`'name'`, configPath, env2));
|
|
@@ -14102,6 +14161,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14102
14161
|
const entryWorkerResolvedConfig = getWorkerConfig(
|
|
14103
14162
|
entryWorkerConfigPath,
|
|
14104
14163
|
cloudflareEnv,
|
|
14164
|
+
pluginConfig.experimental?.mixedMode ?? false,
|
|
14105
14165
|
{
|
|
14106
14166
|
visitedConfigPaths: configPaths,
|
|
14107
14167
|
isEntryWorker: true
|
|
@@ -14135,6 +14195,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14135
14195
|
const workerResolvedConfig = getWorkerConfig(
|
|
14136
14196
|
workerConfigPath,
|
|
14137
14197
|
cloudflareEnv,
|
|
14198
|
+
pluginConfig.experimental?.mixedMode ?? false,
|
|
14138
14199
|
{
|
|
14139
14200
|
visitedConfigPaths: configPaths
|
|
14140
14201
|
}
|
|
@@ -14452,28 +14513,21 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14452
14513
|
pluginConfig,
|
|
14453
14514
|
viteDevServer
|
|
14454
14515
|
);
|
|
14516
|
+
const miniflareDevOptions = await getDevMiniflareOptions(
|
|
14517
|
+
resolvedPluginConfig,
|
|
14518
|
+
viteDevServer,
|
|
14519
|
+
inputInspectorPort
|
|
14520
|
+
);
|
|
14455
14521
|
if (!miniflare) {
|
|
14456
|
-
miniflare = new Miniflare(
|
|
14457
|
-
getDevMiniflareOptions(
|
|
14458
|
-
resolvedPluginConfig,
|
|
14459
|
-
viteDevServer,
|
|
14460
|
-
inputInspectorPort
|
|
14461
|
-
)
|
|
14462
|
-
);
|
|
14522
|
+
miniflare = new Miniflare(miniflareDevOptions);
|
|
14463
14523
|
} else {
|
|
14464
|
-
await miniflare.setOptions(
|
|
14465
|
-
getDevMiniflareOptions(
|
|
14466
|
-
resolvedPluginConfig,
|
|
14467
|
-
viteDevServer,
|
|
14468
|
-
inputInspectorPort
|
|
14469
|
-
)
|
|
14470
|
-
);
|
|
14524
|
+
await miniflare.setOptions(miniflareDevOptions);
|
|
14471
14525
|
}
|
|
14472
14526
|
await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
|
|
14473
14527
|
if (viteDevServer.httpServer) {
|
|
14474
14528
|
handleWebSocket(viteDevServer.httpServer, async () => {
|
|
14475
14529
|
assert10(miniflare, `Miniflare not defined`);
|
|
14476
|
-
const routerWorker = await
|
|
14530
|
+
const routerWorker = await miniflare.getWorker(ROUTER_WORKER_NAME);
|
|
14477
14531
|
return routerWorker.fetch;
|
|
14478
14532
|
});
|
|
14479
14533
|
}
|
|
@@ -14481,14 +14535,21 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14481
14535
|
viteDevServer.middlewares.use(async (req, res, next) => {
|
|
14482
14536
|
try {
|
|
14483
14537
|
assert10(miniflare, `Miniflare not defined`);
|
|
14484
|
-
const routerWorker = await getRouterWorker(miniflare);
|
|
14485
14538
|
const request = createRequest(req, res);
|
|
14486
|
-
|
|
14487
|
-
|
|
14488
|
-
|
|
14489
|
-
|
|
14490
|
-
|
|
14491
|
-
|
|
14539
|
+
let response;
|
|
14540
|
+
if (req[kRequestType] === "asset") {
|
|
14541
|
+
const assetWorker = await miniflare.getWorker(ASSET_WORKER_NAME);
|
|
14542
|
+
response = await assetWorker.fetch(
|
|
14543
|
+
toMiniflareRequest(request),
|
|
14544
|
+
{ redirect: "manual" }
|
|
14545
|
+
);
|
|
14546
|
+
} else {
|
|
14547
|
+
const routerWorker = await miniflare.getWorker(ROUTER_WORKER_NAME);
|
|
14548
|
+
response = await routerWorker.fetch(
|
|
14549
|
+
toMiniflareRequest(request),
|
|
14550
|
+
{ redirect: "manual" }
|
|
14551
|
+
);
|
|
14552
|
+
}
|
|
14492
14553
|
if (req.httpVersionMajor === 2) {
|
|
14493
14554
|
response.headers.delete("transfer-encoding");
|
|
14494
14555
|
}
|
|
@@ -14500,16 +14561,20 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14500
14561
|
};
|
|
14501
14562
|
},
|
|
14502
14563
|
async configurePreviewServer(vitePreviewServer) {
|
|
14503
|
-
const workerConfigs = getWorkerConfigs(
|
|
14564
|
+
const workerConfigs = getWorkerConfigs(
|
|
14565
|
+
vitePreviewServer.config.root,
|
|
14566
|
+
pluginConfig.experimental?.mixedMode ?? false
|
|
14567
|
+
);
|
|
14504
14568
|
const inputInspectorPort = await getInputInspectorPortOption(
|
|
14505
14569
|
pluginConfig,
|
|
14506
14570
|
vitePreviewServer
|
|
14507
14571
|
);
|
|
14508
14572
|
const miniflare2 = new Miniflare(
|
|
14509
|
-
getPreviewMiniflareOptions(
|
|
14573
|
+
await getPreviewMiniflareOptions(
|
|
14510
14574
|
vitePreviewServer,
|
|
14511
14575
|
workerConfigs,
|
|
14512
14576
|
pluginConfig.persistState ?? true,
|
|
14577
|
+
!!pluginConfig.experimental?.mixedMode,
|
|
14513
14578
|
inputInspectorPort
|
|
14514
14579
|
)
|
|
14515
14580
|
);
|
|
@@ -14766,7 +14831,10 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14766
14831
|
});
|
|
14767
14832
|
},
|
|
14768
14833
|
async configurePreviewServer(vitePreviewServer) {
|
|
14769
|
-
const workerConfigs = getWorkerConfigs(
|
|
14834
|
+
const workerConfigs = getWorkerConfigs(
|
|
14835
|
+
vitePreviewServer.config.root,
|
|
14836
|
+
pluginConfig.experimental?.mixedMode ?? false
|
|
14837
|
+
);
|
|
14770
14838
|
if (workerConfigs.length >= 1 && pluginConfig.inspectorPort !== false) {
|
|
14771
14839
|
addDebugToVitePrintUrls(vitePreviewServer);
|
|
14772
14840
|
}
|
|
@@ -11,11 +11,12 @@ var ADDITIONAL_MODULE_TYPES = [
|
|
|
11
11
|
"Data",
|
|
12
12
|
"Text"
|
|
13
13
|
];
|
|
14
|
+
var kRequestType = Symbol("kRequestType");
|
|
14
15
|
|
|
15
16
|
// src/shared.ts
|
|
16
17
|
var UNKNOWN_HOST = "http://localhost";
|
|
17
18
|
var INIT_PATH = "/__vite_plugin_cloudflare_init__";
|
|
18
|
-
var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)
|
|
19
|
+
var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)__CLOUDFLARE_MODULE__`;
|
|
19
20
|
var additionalModuleRE = new RegExp(ADDITIONAL_MODULE_PATTERN);
|
|
20
21
|
var additionalModuleGlobalRE = new RegExp(
|
|
21
22
|
ADDITIONAL_MODULE_PATTERN,
|