@cloudflare/vite-plugin 1.3.1 → 1.4.0
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 +5502 -1977
- package/dist/asset-workers/router-worker.js +4277 -1611
- package/dist/index.js +58 -27
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -13257,7 +13257,7 @@ import { unstable_readConfig } from "wrangler";
|
|
|
13257
13257
|
function getDeployConfigPath(root) {
|
|
13258
13258
|
return path5.resolve(root, ".wrangler", "deploy", "config.json");
|
|
13259
13259
|
}
|
|
13260
|
-
function getWorkerConfigs(root) {
|
|
13260
|
+
function getWorkerConfigs(root, mixedModeEnabled) {
|
|
13261
13261
|
const deployConfigPath = getDeployConfigPath(root);
|
|
13262
13262
|
const deployConfig = JSON.parse(
|
|
13263
13263
|
fs2.readFileSync(deployConfigPath, "utf-8")
|
|
@@ -13270,7 +13270,10 @@ function getWorkerConfigs(root) {
|
|
|
13270
13270
|
path5.dirname(deployConfigPath),
|
|
13271
13271
|
configPath
|
|
13272
13272
|
);
|
|
13273
|
-
return unstable_readConfig(
|
|
13273
|
+
return unstable_readConfig(
|
|
13274
|
+
{ config: resolvedConfigPath },
|
|
13275
|
+
{ experimental: { mixedModeEnabled } }
|
|
13276
|
+
);
|
|
13274
13277
|
});
|
|
13275
13278
|
}
|
|
13276
13279
|
function getRelativePathToWorkerConfig(deployConfigDirectory, root, outputDirectory) {
|
|
@@ -13337,6 +13340,7 @@ import * as fsp from "node:fs/promises";
|
|
|
13337
13340
|
import * as path6 from "node:path";
|
|
13338
13341
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
13339
13342
|
import {
|
|
13343
|
+
getDefaultDevRegistryPath,
|
|
13340
13344
|
kCurrentWorker,
|
|
13341
13345
|
Log,
|
|
13342
13346
|
LogLevel,
|
|
@@ -13445,28 +13449,27 @@ function getEntryWorkerConfig(resolvedPluginConfig) {
|
|
|
13445
13449
|
}
|
|
13446
13450
|
return resolvedPluginConfig.workers[resolvedPluginConfig.entryWorkerEnvironmentName];
|
|
13447
13451
|
}
|
|
13448
|
-
function
|
|
13449
|
-
|
|
13452
|
+
function logUnknownTails(tails, userWorkers, log) {
|
|
13453
|
+
for (const tailService of tails ?? []) {
|
|
13450
13454
|
let name;
|
|
13451
13455
|
if (typeof tailService === "string") {
|
|
13452
13456
|
name = tailService;
|
|
13453
13457
|
} else if (typeof tailService === "object" && "name" in tailService && typeof tailService.name === "string") {
|
|
13454
13458
|
name = tailService.name;
|
|
13455
13459
|
} else {
|
|
13456
|
-
|
|
13460
|
+
continue;
|
|
13457
13461
|
}
|
|
13458
13462
|
const found = userWorkers.some((w) => w.name === name);
|
|
13459
13463
|
if (!found) {
|
|
13460
13464
|
log(
|
|
13461
13465
|
colors2.dim(
|
|
13462
13466
|
colors2.yellow(
|
|
13463
|
-
`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.`
|
|
13464
13468
|
)
|
|
13465
13469
|
)
|
|
13466
13470
|
);
|
|
13467
13471
|
}
|
|
13468
|
-
|
|
13469
|
-
});
|
|
13472
|
+
}
|
|
13470
13473
|
}
|
|
13471
13474
|
async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPort) {
|
|
13472
13475
|
const resolvedViteConfig = viteDevServer.config;
|
|
@@ -13555,7 +13558,8 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13555
13558
|
},
|
|
13556
13559
|
resolvedPluginConfig.cloudflareEnv,
|
|
13557
13560
|
{
|
|
13558
|
-
mixedModeConnectionString: mixedModeSession?.mixedModeConnectionString
|
|
13561
|
+
mixedModeConnectionString: mixedModeSession?.mixedModeConnectionString,
|
|
13562
|
+
mixedModeEnabled: resolvedPluginConfig.experimental.mixedMode
|
|
13559
13563
|
}
|
|
13560
13564
|
);
|
|
13561
13565
|
const { externalWorkers: externalWorkers2 } = miniflareWorkerOptions;
|
|
@@ -13566,6 +13570,10 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13566
13570
|
...workerOptions,
|
|
13567
13571
|
name: workerOptions.name ?? workerConfig.name,
|
|
13568
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
|
+
) : [],
|
|
13569
13577
|
modulesRoot: miniflareModulesRoot,
|
|
13570
13578
|
unsafeEvalBinding: "__VITE_UNSAFE_EVAL__",
|
|
13571
13579
|
serviceBindings: {
|
|
@@ -13611,6 +13619,7 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13611
13619
|
logRequests: false,
|
|
13612
13620
|
inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
|
|
13613
13621
|
unsafeInspectorProxy: inspectorPort !== false,
|
|
13622
|
+
unsafeDevRegistryPath: getDefaultDevRegistryPath(),
|
|
13614
13623
|
handleRuntimeStdio(stdout, stderr) {
|
|
13615
13624
|
const decoder = new TextDecoder();
|
|
13616
13625
|
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
@@ -13664,13 +13673,13 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13664
13673
|
`export const ${className} = createWorkflowEntrypointWrapper('${className}');`
|
|
13665
13674
|
);
|
|
13666
13675
|
}
|
|
13676
|
+
logUnknownTails(
|
|
13677
|
+
workerOptions.tails,
|
|
13678
|
+
userWorkers,
|
|
13679
|
+
viteDevServer.config.logger.warn
|
|
13680
|
+
);
|
|
13667
13681
|
return {
|
|
13668
13682
|
...workerOptions,
|
|
13669
|
-
tails: filterTails(
|
|
13670
|
-
workerOptions.tails,
|
|
13671
|
-
userWorkers,
|
|
13672
|
-
viteDevServer.config.logger.warn
|
|
13673
|
-
),
|
|
13674
13683
|
modules: [
|
|
13675
13684
|
{
|
|
13676
13685
|
type: "ESModule",
|
|
@@ -13755,27 +13764,33 @@ function getPreviewModules(main, modulesRules) {
|
|
|
13755
13764
|
async function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistState, mixedModeEnabled, inspectorPort) {
|
|
13756
13765
|
const resolvedViteConfig = vitePreviewServer.config;
|
|
13757
13766
|
const workers = (await Promise.all(
|
|
13758
|
-
workerConfigs.map(async (workerConfig) => {
|
|
13767
|
+
workerConfigs.map(async (workerConfig, i) => {
|
|
13759
13768
|
const mixedModeSession = mixedModeEnabled ? await maybeStartOrUpdateMixedModeSession(workerConfig) : void 0;
|
|
13760
13769
|
const miniflareWorkerOptions = unstable_getMiniflareWorkerOptions(
|
|
13761
13770
|
workerConfig,
|
|
13762
13771
|
void 0,
|
|
13763
13772
|
{
|
|
13764
|
-
mixedModeConnectionString: mixedModeSession?.mixedModeConnectionString
|
|
13773
|
+
mixedModeConnectionString: mixedModeSession?.mixedModeConnectionString,
|
|
13774
|
+
mixedModeEnabled
|
|
13765
13775
|
}
|
|
13766
13776
|
);
|
|
13767
13777
|
const { externalWorkers } = miniflareWorkerOptions;
|
|
13768
13778
|
const { ratelimits, modulesRules, ...workerOptions } = miniflareWorkerOptions.workerOptions;
|
|
13779
|
+
logUnknownTails(
|
|
13780
|
+
workerOptions.tails,
|
|
13781
|
+
workerConfigs,
|
|
13782
|
+
vitePreviewServer.config.logger.warn
|
|
13783
|
+
);
|
|
13769
13784
|
return [
|
|
13770
13785
|
{
|
|
13771
13786
|
...workerOptions,
|
|
13772
|
-
tails: filterTails(
|
|
13773
|
-
workerOptions.tails,
|
|
13774
|
-
workerConfigs,
|
|
13775
|
-
vitePreviewServer.config.logger.warn
|
|
13776
|
-
),
|
|
13777
13787
|
name: workerOptions.name ?? workerConfig.name,
|
|
13778
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
|
+
),
|
|
13779
13794
|
...miniflareWorkerOptions.main ? getPreviewModules(miniflareWorkerOptions.main, modulesRules) : { modules: true, script: "" }
|
|
13780
13795
|
},
|
|
13781
13796
|
...externalWorkers
|
|
@@ -13787,6 +13802,7 @@ async function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, pers
|
|
|
13787
13802
|
log: logger,
|
|
13788
13803
|
inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
|
|
13789
13804
|
unsafeInspectorProxy: inspectorPort !== false,
|
|
13805
|
+
unsafeDevRegistryPath: getDefaultDevRegistryPath(),
|
|
13790
13806
|
handleRuntimeStdio(stdout, stderr) {
|
|
13791
13807
|
const decoder = new TextDecoder();
|
|
13792
13808
|
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
@@ -13904,12 +13920,15 @@ var nullableNonApplicable = [
|
|
|
13904
13920
|
"site",
|
|
13905
13921
|
"tsconfig"
|
|
13906
13922
|
];
|
|
13907
|
-
function readWorkerConfig(configPath, env2) {
|
|
13923
|
+
function readWorkerConfig(configPath, env2, mixedModeEnabled) {
|
|
13908
13924
|
const nonApplicable = {
|
|
13909
13925
|
replacedByVite: /* @__PURE__ */ new Set(),
|
|
13910
13926
|
notRelevant: /* @__PURE__ */ new Set()
|
|
13911
13927
|
};
|
|
13912
|
-
const config = unstable_readConfig2(
|
|
13928
|
+
const config = unstable_readConfig2(
|
|
13929
|
+
{ config: configPath, env: env2 },
|
|
13930
|
+
{ experimental: { mixedModeEnabled } }
|
|
13931
|
+
);
|
|
13913
13932
|
const raw = structuredClone(config);
|
|
13914
13933
|
nullableNonApplicable.forEach((prop) => {
|
|
13915
13934
|
if (config[prop] !== void 0) {
|
|
@@ -14004,11 +14023,15 @@ function isNotRelevant(configName) {
|
|
|
14004
14023
|
function missingFieldErrorMessage(field, configPath, env2) {
|
|
14005
14024
|
return `No ${field} field provided in '${configPath}'${env2 ? ` for '${env2}' environment` : ""}`;
|
|
14006
14025
|
}
|
|
14007
|
-
function getWorkerConfig(configPath, env2, opts) {
|
|
14026
|
+
function getWorkerConfig(configPath, env2, mixedModeEnabled, opts) {
|
|
14008
14027
|
if (opts?.visitedConfigPaths?.has(configPath)) {
|
|
14009
14028
|
throw new Error(`Duplicate Wrangler config path found: ${configPath}`);
|
|
14010
14029
|
}
|
|
14011
|
-
const { raw, config, nonApplicable } = readWorkerConfig(
|
|
14030
|
+
const { raw, config, nonApplicable } = readWorkerConfig(
|
|
14031
|
+
configPath,
|
|
14032
|
+
env2,
|
|
14033
|
+
mixedModeEnabled
|
|
14034
|
+
);
|
|
14012
14035
|
opts?.visitedConfigPaths?.add(configPath);
|
|
14013
14036
|
if (!config.name) {
|
|
14014
14037
|
throw new Error(missingFieldErrorMessage(`'name'`, configPath, env2));
|
|
@@ -14133,6 +14156,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14133
14156
|
const entryWorkerResolvedConfig = getWorkerConfig(
|
|
14134
14157
|
entryWorkerConfigPath,
|
|
14135
14158
|
cloudflareEnv,
|
|
14159
|
+
pluginConfig.experimental?.mixedMode ?? false,
|
|
14136
14160
|
{
|
|
14137
14161
|
visitedConfigPaths: configPaths,
|
|
14138
14162
|
isEntryWorker: true
|
|
@@ -14166,6 +14190,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14166
14190
|
const workerResolvedConfig = getWorkerConfig(
|
|
14167
14191
|
workerConfigPath,
|
|
14168
14192
|
cloudflareEnv,
|
|
14193
|
+
pluginConfig.experimental?.mixedMode ?? false,
|
|
14169
14194
|
{
|
|
14170
14195
|
visitedConfigPaths: configPaths
|
|
14171
14196
|
}
|
|
@@ -14524,7 +14549,10 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14524
14549
|
};
|
|
14525
14550
|
},
|
|
14526
14551
|
async configurePreviewServer(vitePreviewServer) {
|
|
14527
|
-
const workerConfigs = getWorkerConfigs(
|
|
14552
|
+
const workerConfigs = getWorkerConfigs(
|
|
14553
|
+
vitePreviewServer.config.root,
|
|
14554
|
+
pluginConfig.experimental?.mixedMode ?? false
|
|
14555
|
+
);
|
|
14528
14556
|
const inputInspectorPort = await getInputInspectorPortOption(
|
|
14529
14557
|
pluginConfig,
|
|
14530
14558
|
vitePreviewServer
|
|
@@ -14791,7 +14819,10 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14791
14819
|
});
|
|
14792
14820
|
},
|
|
14793
14821
|
async configurePreviewServer(vitePreviewServer) {
|
|
14794
|
-
const workerConfigs = getWorkerConfigs(
|
|
14822
|
+
const workerConfigs = getWorkerConfigs(
|
|
14823
|
+
vitePreviewServer.config.root,
|
|
14824
|
+
pluginConfig.experimental?.mixedMode ?? false
|
|
14825
|
+
);
|
|
14795
14826
|
if (workerConfigs.length >= 1 && pluginConfig.inspectorPort !== false) {
|
|
14796
14827
|
addDebugToVitePrintUrls(vitePreviewServer);
|
|
14797
14828
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/vite-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "Cloudflare plugin for Vite",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"tinyglobby": "^0.2.12",
|
|
42
42
|
"unenv": "2.0.0-rc.17",
|
|
43
43
|
"ws": "8.18.0",
|
|
44
|
-
"
|
|
45
|
-
"
|
|
44
|
+
"wrangler": "4.19.0",
|
|
45
|
+
"miniflare": "4.20250525.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@cloudflare/workers-types": "^4.20250525.0",
|