@cloudflare/vite-plugin 0.0.0-b7ac367fe → 0.0.0-b834f46f7
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 +5512 -1967
- package/dist/asset-workers/router-worker.js +4277 -1611
- package/dist/index.d.ts +2 -0
- package/dist/index.js +335 -183
- package/dist/runner-worker/index.js +12 -10
- package/package.json +10 -11
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
|
|
@@ -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
|
|
@@ -5784,7 +5785,8 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
5784
5785
|
// ../workers-shared/utils/types.ts
|
|
5785
5786
|
var InternalConfigSchema = z.object({
|
|
5786
5787
|
account_id: z.number().optional(),
|
|
5787
|
-
script_id: z.number().optional()
|
|
5788
|
+
script_id: z.number().optional(),
|
|
5789
|
+
debug: z.boolean().optional()
|
|
5788
5790
|
});
|
|
5789
5791
|
var RouterConfigSchema = z.object({
|
|
5790
5792
|
invoke_user_worker_ahead_of_assets: z.boolean().optional(),
|
|
@@ -5832,14 +5834,14 @@ var AssetConfigSchema = z.object({
|
|
|
5832
5834
|
});
|
|
5833
5835
|
|
|
5834
5836
|
// src/asset-config.ts
|
|
5835
|
-
function hasAssetsConfigChanged(resolvedPluginConfig, resolvedViteConfig,
|
|
5837
|
+
function hasAssetsConfigChanged(resolvedPluginConfig, resolvedViteConfig, changedFilePath) {
|
|
5836
5838
|
if (!resolvedPluginConfig.experimental?.headersAndRedirectsDevModeSupport) {
|
|
5837
5839
|
return false;
|
|
5838
5840
|
}
|
|
5839
5841
|
return [
|
|
5840
5842
|
getRedirectsConfigPath(resolvedViteConfig),
|
|
5841
5843
|
getHeadersConfigPath(resolvedViteConfig)
|
|
5842
|
-
].includes(
|
|
5844
|
+
].includes(changedFilePath);
|
|
5843
5845
|
}
|
|
5844
5846
|
function getAssetsConfig(resolvedPluginConfig, entryWorkerConfig, resolvedConfig) {
|
|
5845
5847
|
const assetsConfig = resolvedPluginConfig.type === "assets-only" ? resolvedPluginConfig.config.assets : entryWorkerConfig?.assets;
|
|
@@ -12647,8 +12649,8 @@ function packageResolve(specifier, base, conditions) {
|
|
|
12647
12649
|
let packageJsonPath = fileURLToPath$1(packageJsonUrl);
|
|
12648
12650
|
let lastPath;
|
|
12649
12651
|
do {
|
|
12650
|
-
const
|
|
12651
|
-
if (!
|
|
12652
|
+
const stat2 = tryStatSync(packageJsonPath.slice(0, -13));
|
|
12653
|
+
if (!stat2 || !stat2.isDirectory()) {
|
|
12652
12654
|
lastPath = packageJsonPath;
|
|
12653
12655
|
packageJsonUrl = new URL$1(
|
|
12654
12656
|
(isScoped ? "../../../../node_modules/" : "../../../node_modules/") + packageName + "/package.json",
|
|
@@ -12778,8 +12780,8 @@ function _resolve(id, options = {}) {
|
|
|
12778
12780
|
}
|
|
12779
12781
|
if (isAbsolute(id)) {
|
|
12780
12782
|
try {
|
|
12781
|
-
const
|
|
12782
|
-
if (
|
|
12783
|
+
const stat2 = statSync(id);
|
|
12784
|
+
if (stat2.isFile()) {
|
|
12783
12785
|
return pathToFileURL(id);
|
|
12784
12786
|
}
|
|
12785
12787
|
} catch (error) {
|
|
@@ -12880,6 +12882,15 @@ function isNodeCompat(workerConfig) {
|
|
|
12880
12882
|
}
|
|
12881
12883
|
return false;
|
|
12882
12884
|
}
|
|
12885
|
+
function isNodeAls(workerConfig) {
|
|
12886
|
+
return workerConfig !== void 0 && getNodeCompat(
|
|
12887
|
+
workerConfig.compatibility_date,
|
|
12888
|
+
workerConfig.compatibility_flags ?? []
|
|
12889
|
+
).mode === "als";
|
|
12890
|
+
}
|
|
12891
|
+
function isNodeAlsModule(path10) {
|
|
12892
|
+
return /^(node:)?async_hooks$/.test(path10);
|
|
12893
|
+
}
|
|
12883
12894
|
function injectGlobalCode(id, code) {
|
|
12884
12895
|
const injectedCode = Object.entries(env.inject).map(([globalName, globalInject]) => {
|
|
12885
12896
|
if (typeof globalInject === "string") {
|
|
@@ -12983,7 +12994,7 @@ var NodeJsCompatWarnings = class {
|
|
|
12983
12994
|
// src/shared.ts
|
|
12984
12995
|
var UNKNOWN_HOST = "http://localhost";
|
|
12985
12996
|
var INIT_PATH = "/__vite_plugin_cloudflare_init__";
|
|
12986
|
-
var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)
|
|
12997
|
+
var ADDITIONAL_MODULE_PATTERN = `__CLOUDFLARE_MODULE__(${ADDITIONAL_MODULE_TYPES.join("|")})__(.*?)__CLOUDFLARE_MODULE__`;
|
|
12987
12998
|
var additionalModuleRE = new RegExp(ADDITIONAL_MODULE_PATTERN);
|
|
12988
12999
|
var additionalModuleGlobalRE = new RegExp(
|
|
12989
13000
|
ADDITIONAL_MODULE_PATTERN,
|
|
@@ -13000,9 +13011,6 @@ function getOutputDirectory(userConfig, environmentName) {
|
|
|
13000
13011
|
const rootOutputDirectory = userConfig.build?.outDir ?? "dist";
|
|
13001
13012
|
return userConfig.environments?.[environmentName]?.build?.outDir ?? path4.join(rootOutputDirectory, environmentName);
|
|
13002
13013
|
}
|
|
13003
|
-
function getRouterWorker(miniflare2) {
|
|
13004
|
-
return miniflare2.getWorker(ROUTER_WORKER_NAME);
|
|
13005
|
-
}
|
|
13006
13014
|
function toMiniflareRequest(request) {
|
|
13007
13015
|
const host = request.headers.get("Host");
|
|
13008
13016
|
if (host) {
|
|
@@ -13019,19 +13027,6 @@ function toMiniflareRequest(request) {
|
|
|
13019
13027
|
duplex: "half"
|
|
13020
13028
|
});
|
|
13021
13029
|
}
|
|
13022
|
-
function nodeHeadersToWebHeaders(nodeHeaders) {
|
|
13023
|
-
const headers = new Headers();
|
|
13024
|
-
for (const [key, value] of Object.entries(nodeHeaders)) {
|
|
13025
|
-
if (typeof value === "string") {
|
|
13026
|
-
headers.append(key, value);
|
|
13027
|
-
} else if (Array.isArray(value)) {
|
|
13028
|
-
for (const item of value) {
|
|
13029
|
-
headers.append(key, item);
|
|
13030
|
-
}
|
|
13031
|
-
}
|
|
13032
|
-
}
|
|
13033
|
-
return headers;
|
|
13034
|
-
}
|
|
13035
13030
|
var postfixRE = /[?#].*$/;
|
|
13036
13031
|
function cleanUrl(url) {
|
|
13037
13032
|
return url.replace(postfixRE, "");
|
|
@@ -13260,7 +13255,7 @@ import { unstable_readConfig } from "wrangler";
|
|
|
13260
13255
|
function getDeployConfigPath(root) {
|
|
13261
13256
|
return path5.resolve(root, ".wrangler", "deploy", "config.json");
|
|
13262
13257
|
}
|
|
13263
|
-
function getWorkerConfigs(root) {
|
|
13258
|
+
function getWorkerConfigs(root, mixedModeEnabled) {
|
|
13264
13259
|
const deployConfigPath = getDeployConfigPath(root);
|
|
13265
13260
|
const deployConfig = JSON.parse(
|
|
13266
13261
|
fs2.readFileSync(deployConfigPath, "utf-8")
|
|
@@ -13273,7 +13268,10 @@ function getWorkerConfigs(root) {
|
|
|
13273
13268
|
path5.dirname(deployConfigPath),
|
|
13274
13269
|
configPath
|
|
13275
13270
|
);
|
|
13276
|
-
return unstable_readConfig(
|
|
13271
|
+
return unstable_readConfig(
|
|
13272
|
+
{ config: resolvedConfigPath },
|
|
13273
|
+
{ experimental: { mixedModeEnabled } }
|
|
13274
|
+
);
|
|
13277
13275
|
});
|
|
13278
13276
|
}
|
|
13279
13277
|
function getRelativePathToWorkerConfig(deployConfigDirectory, root, outputDirectory) {
|
|
@@ -13340,17 +13338,24 @@ import * as fsp from "node:fs/promises";
|
|
|
13340
13338
|
import * as path6 from "node:path";
|
|
13341
13339
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
13342
13340
|
import {
|
|
13341
|
+
getDefaultDevRegistryPath,
|
|
13343
13342
|
kCurrentWorker,
|
|
13344
13343
|
Log,
|
|
13345
13344
|
LogLevel,
|
|
13346
13345
|
Response as MiniflareResponse
|
|
13347
13346
|
} from "miniflare";
|
|
13347
|
+
import colors2 from "picocolors";
|
|
13348
13348
|
import { globSync } from "tinyglobby";
|
|
13349
13349
|
import "vite";
|
|
13350
|
-
import {
|
|
13351
|
-
|
|
13350
|
+
import {
|
|
13351
|
+
experimental_pickRemoteBindings,
|
|
13352
|
+
experimental_startMixedModeSession,
|
|
13353
|
+
unstable_convertConfigBindingsToStartWorkerBindings,
|
|
13354
|
+
unstable_getMiniflareWorkerOptions
|
|
13355
|
+
} from "wrangler";
|
|
13356
|
+
function getPersistenceRoot(root, persistState) {
|
|
13352
13357
|
if (persistState === false) {
|
|
13353
|
-
return
|
|
13358
|
+
return;
|
|
13354
13359
|
}
|
|
13355
13360
|
const defaultPersistPath = ".wrangler/state";
|
|
13356
13361
|
const persistPath = path6.resolve(
|
|
@@ -13358,14 +13363,7 @@ function getPersistence(root, persistState) {
|
|
|
13358
13363
|
typeof persistState === "object" ? persistState.path : defaultPersistPath,
|
|
13359
13364
|
"v3"
|
|
13360
13365
|
);
|
|
13361
|
-
return
|
|
13362
|
-
cachePersist: path6.join(persistPath, "cache"),
|
|
13363
|
-
d1Persist: path6.join(persistPath, "d1"),
|
|
13364
|
-
durableObjectsPersist: path6.join(persistPath, "do"),
|
|
13365
|
-
kvPersist: path6.join(persistPath, "kv"),
|
|
13366
|
-
r2Persist: path6.join(persistPath, "r2"),
|
|
13367
|
-
workflowsPersist: path6.join(persistPath, "workflows")
|
|
13368
|
-
};
|
|
13366
|
+
return persistPath;
|
|
13369
13367
|
}
|
|
13370
13368
|
function missingWorkerErrorMessage(workerName) {
|
|
13371
13369
|
return `${workerName} does not match a worker name.`;
|
|
@@ -13449,7 +13447,29 @@ function getEntryWorkerConfig(resolvedPluginConfig) {
|
|
|
13449
13447
|
}
|
|
13450
13448
|
return resolvedPluginConfig.workers[resolvedPluginConfig.entryWorkerEnvironmentName];
|
|
13451
13449
|
}
|
|
13452
|
-
function
|
|
13450
|
+
function logUnknownTails(tails, userWorkers, log) {
|
|
13451
|
+
for (const tailService of tails ?? []) {
|
|
13452
|
+
let name;
|
|
13453
|
+
if (typeof tailService === "string") {
|
|
13454
|
+
name = tailService;
|
|
13455
|
+
} else if (typeof tailService === "object" && "name" in tailService && typeof tailService.name === "string") {
|
|
13456
|
+
name = tailService.name;
|
|
13457
|
+
} else {
|
|
13458
|
+
continue;
|
|
13459
|
+
}
|
|
13460
|
+
const found = userWorkers.some((w) => w.name === name);
|
|
13461
|
+
if (!found) {
|
|
13462
|
+
log(
|
|
13463
|
+
colors2.dim(
|
|
13464
|
+
colors2.yellow(
|
|
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
|
+
)
|
|
13467
|
+
)
|
|
13468
|
+
);
|
|
13469
|
+
}
|
|
13470
|
+
}
|
|
13471
|
+
}
|
|
13472
|
+
async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPort) {
|
|
13453
13473
|
const resolvedViteConfig = viteDevServer.config;
|
|
13454
13474
|
const entryWorkerConfig = getEntryWorkerConfig(resolvedPluginConfig);
|
|
13455
13475
|
const assetsConfig = getAssetsConfig(
|
|
@@ -13500,12 +13520,14 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13500
13520
|
serviceBindings: {
|
|
13501
13521
|
__VITE_ASSET_EXISTS__: async (request) => {
|
|
13502
13522
|
const { pathname } = new URL(request.url);
|
|
13503
|
-
|
|
13504
|
-
|
|
13505
|
-
|
|
13506
|
-
|
|
13507
|
-
|
|
13508
|
-
|
|
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
|
+
}
|
|
13509
13531
|
}
|
|
13510
13532
|
return MiniflareResponse.json(exists);
|
|
13511
13533
|
},
|
|
@@ -13519,59 +13541,75 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13519
13541
|
headers: { "Content-Type": "text/html" }
|
|
13520
13542
|
});
|
|
13521
13543
|
} catch (error) {
|
|
13522
|
-
throw new Error(`Unexpected error. Failed to load ${pathname}
|
|
13544
|
+
throw new Error(`Unexpected error. Failed to load "${pathname}".`);
|
|
13523
13545
|
}
|
|
13524
13546
|
}
|
|
13525
13547
|
}
|
|
13526
13548
|
}
|
|
13527
13549
|
];
|
|
13528
|
-
const workersFromConfig = resolvedPluginConfig.type === "workers" ?
|
|
13529
|
-
(
|
|
13530
|
-
|
|
13531
|
-
|
|
13532
|
-
|
|
13533
|
-
|
|
13534
|
-
|
|
13535
|
-
|
|
13536
|
-
|
|
13537
|
-
|
|
13538
|
-
|
|
13539
|
-
|
|
13540
|
-
|
|
13541
|
-
|
|
13542
|
-
|
|
13543
|
-
|
|
13544
|
-
|
|
13545
|
-
|
|
13546
|
-
|
|
13547
|
-
|
|
13548
|
-
...workerOptions
|
|
13549
|
-
|
|
13550
|
-
|
|
13551
|
-
|
|
13552
|
-
|
|
13553
|
-
|
|
13554
|
-
|
|
13555
|
-
|
|
13556
|
-
|
|
13557
|
-
|
|
13558
|
-
|
|
13559
|
-
|
|
13560
|
-
|
|
13561
|
-
|
|
13562
|
-
|
|
13563
|
-
|
|
13564
|
-
|
|
13565
|
-
|
|
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);
|
|
13566
13607
|
}
|
|
13567
|
-
const devEnvironment = viteDevServer.environments[environmentName];
|
|
13568
|
-
const result = await devEnvironment.hot.handleInvoke(payload);
|
|
13569
|
-
return MiniflareResponse.json(result);
|
|
13570
13608
|
}
|
|
13571
13609
|
}
|
|
13572
|
-
}
|
|
13573
|
-
}
|
|
13574
|
-
|
|
13610
|
+
};
|
|
13611
|
+
}
|
|
13612
|
+
)
|
|
13575
13613
|
) : [];
|
|
13576
13614
|
const userWorkers = workersFromConfig.map((options) => options.worker);
|
|
13577
13615
|
const externalWorkers = workersFromConfig.flatMap(
|
|
@@ -13583,8 +13621,10 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13583
13621
|
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
13584
13622
|
return {
|
|
13585
13623
|
log: logger,
|
|
13624
|
+
logRequests: false,
|
|
13586
13625
|
inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
|
|
13587
13626
|
unsafeInspectorProxy: inspectorPort !== false,
|
|
13627
|
+
unsafeDevRegistryPath: getDefaultDevRegistryPath(),
|
|
13588
13628
|
handleRuntimeStdio(stdout, stderr) {
|
|
13589
13629
|
const decoder = new TextDecoder();
|
|
13590
13630
|
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
@@ -13592,7 +13632,7 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13592
13632
|
(error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
|
|
13593
13633
|
);
|
|
13594
13634
|
},
|
|
13595
|
-
|
|
13635
|
+
defaultPersistRoot: getPersistenceRoot(
|
|
13596
13636
|
resolvedViteConfig.root,
|
|
13597
13637
|
resolvedPluginConfig.persistState
|
|
13598
13638
|
),
|
|
@@ -13638,6 +13678,11 @@ function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspectorPo
|
|
|
13638
13678
|
`export const ${className} = createWorkflowEntrypointWrapper('${className}');`
|
|
13639
13679
|
);
|
|
13640
13680
|
}
|
|
13681
|
+
logUnknownTails(
|
|
13682
|
+
workerOptions.tails,
|
|
13683
|
+
userWorkers,
|
|
13684
|
+
viteDevServer.config.logger.warn
|
|
13685
|
+
);
|
|
13641
13686
|
return {
|
|
13642
13687
|
...workerOptions,
|
|
13643
13688
|
modules: [
|
|
@@ -13721,27 +13766,48 @@ function getPreviewModules(main, modulesRules) {
|
|
|
13721
13766
|
]
|
|
13722
13767
|
};
|
|
13723
13768
|
}
|
|
13724
|
-
function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistState, inspectorPort) {
|
|
13769
|
+
async function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistState, mixedModeEnabled, inspectorPort) {
|
|
13725
13770
|
const resolvedViteConfig = vitePreviewServer.config;
|
|
13726
|
-
const workers =
|
|
13727
|
-
|
|
13728
|
-
|
|
13729
|
-
|
|
13730
|
-
|
|
13731
|
-
|
|
13732
|
-
|
|
13733
|
-
|
|
13734
|
-
|
|
13735
|
-
|
|
13736
|
-
|
|
13737
|
-
|
|
13738
|
-
|
|
13739
|
-
|
|
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();
|
|
13740
13805
|
const logger = new ViteMiniflareLogger(resolvedViteConfig);
|
|
13741
13806
|
return {
|
|
13742
13807
|
log: logger,
|
|
13743
13808
|
inspectorPort: inspectorPort === false ? void 0 : inspectorPort,
|
|
13744
13809
|
unsafeInspectorProxy: inspectorPort !== false,
|
|
13810
|
+
unsafeDevRegistryPath: getDefaultDevRegistryPath(),
|
|
13745
13811
|
handleRuntimeStdio(stdout, stderr) {
|
|
13746
13812
|
const decoder = new TextDecoder();
|
|
13747
13813
|
stdout.forEach((data2) => logger.info(decoder.decode(data2)));
|
|
@@ -13749,11 +13815,13 @@ function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, persistSta
|
|
|
13749
13815
|
(error) => logger.logWithLevel(LogLevel.ERROR, decoder.decode(error))
|
|
13750
13816
|
);
|
|
13751
13817
|
},
|
|
13752
|
-
|
|
13818
|
+
defaultPersistRoot: getPersistenceRoot(
|
|
13819
|
+
resolvedViteConfig.root,
|
|
13820
|
+
persistState
|
|
13821
|
+
),
|
|
13753
13822
|
workers
|
|
13754
13823
|
};
|
|
13755
13824
|
}
|
|
13756
|
-
var removedMessages = [/^Ready on http/, /^Updated and ready on http/];
|
|
13757
13825
|
var ViteMiniflareLogger = class extends Log {
|
|
13758
13826
|
logger;
|
|
13759
13827
|
constructor(config) {
|
|
@@ -13761,11 +13829,6 @@ var ViteMiniflareLogger = class extends Log {
|
|
|
13761
13829
|
this.logger = config.logger;
|
|
13762
13830
|
}
|
|
13763
13831
|
logWithLevel(level, message) {
|
|
13764
|
-
for (const removedMessage of removedMessages) {
|
|
13765
|
-
if (removedMessage.test(message)) {
|
|
13766
|
-
return;
|
|
13767
|
-
}
|
|
13768
|
-
}
|
|
13769
13832
|
switch (level) {
|
|
13770
13833
|
case LogLevel.ERROR:
|
|
13771
13834
|
return this.logger.error(message);
|
|
@@ -13775,6 +13838,8 @@ var ViteMiniflareLogger = class extends Log {
|
|
|
13775
13838
|
return this.logger.info(message);
|
|
13776
13839
|
}
|
|
13777
13840
|
}
|
|
13841
|
+
logReady() {
|
|
13842
|
+
}
|
|
13778
13843
|
};
|
|
13779
13844
|
function miniflareLogLevelFromViteLogLevel(level = "info") {
|
|
13780
13845
|
switch (level) {
|
|
@@ -13788,6 +13853,24 @@ function miniflareLogLevelFromViteLogLevel(level = "info") {
|
|
|
13788
13853
|
return LogLevel.NONE;
|
|
13789
13854
|
}
|
|
13790
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
|
+
}
|
|
13791
13874
|
|
|
13792
13875
|
// src/plugin-config.ts
|
|
13793
13876
|
import assert8 from "node:assert";
|
|
@@ -13842,12 +13925,15 @@ var nullableNonApplicable = [
|
|
|
13842
13925
|
"site",
|
|
13843
13926
|
"tsconfig"
|
|
13844
13927
|
];
|
|
13845
|
-
function readWorkerConfig(configPath, env2) {
|
|
13928
|
+
function readWorkerConfig(configPath, env2, mixedModeEnabled) {
|
|
13846
13929
|
const nonApplicable = {
|
|
13847
13930
|
replacedByVite: /* @__PURE__ */ new Set(),
|
|
13848
13931
|
notRelevant: /* @__PURE__ */ new Set()
|
|
13849
13932
|
};
|
|
13850
|
-
const config = unstable_readConfig2(
|
|
13933
|
+
const config = unstable_readConfig2(
|
|
13934
|
+
{ config: configPath, env: env2 },
|
|
13935
|
+
{ experimental: { mixedModeEnabled } }
|
|
13936
|
+
);
|
|
13851
13937
|
const raw = structuredClone(config);
|
|
13852
13938
|
nullableNonApplicable.forEach((prop) => {
|
|
13853
13939
|
if (config[prop] !== void 0) {
|
|
@@ -13942,11 +14028,15 @@ function isNotRelevant(configName) {
|
|
|
13942
14028
|
function missingFieldErrorMessage(field, configPath, env2) {
|
|
13943
14029
|
return `No ${field} field provided in '${configPath}'${env2 ? ` for '${env2}' environment` : ""}`;
|
|
13944
14030
|
}
|
|
13945
|
-
function getWorkerConfig(configPath, env2, opts) {
|
|
14031
|
+
function getWorkerConfig(configPath, env2, mixedModeEnabled, opts) {
|
|
13946
14032
|
if (opts?.visitedConfigPaths?.has(configPath)) {
|
|
13947
14033
|
throw new Error(`Duplicate Wrangler config path found: ${configPath}`);
|
|
13948
14034
|
}
|
|
13949
|
-
const { raw, config, nonApplicable } = readWorkerConfig(
|
|
14035
|
+
const { raw, config, nonApplicable } = readWorkerConfig(
|
|
14036
|
+
configPath,
|
|
14037
|
+
env2,
|
|
14038
|
+
mixedModeEnabled
|
|
14039
|
+
);
|
|
13950
14040
|
opts?.visitedConfigPaths?.add(configPath);
|
|
13951
14041
|
if (!config.name) {
|
|
13952
14042
|
throw new Error(missingFieldErrorMessage(`'name'`, configPath, env2));
|
|
@@ -14071,6 +14161,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14071
14161
|
const entryWorkerResolvedConfig = getWorkerConfig(
|
|
14072
14162
|
entryWorkerConfigPath,
|
|
14073
14163
|
cloudflareEnv,
|
|
14164
|
+
pluginConfig.experimental?.mixedMode ?? false,
|
|
14074
14165
|
{
|
|
14075
14166
|
visitedConfigPaths: configPaths,
|
|
14076
14167
|
isEntryWorker: true
|
|
@@ -14104,6 +14195,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14104
14195
|
const workerResolvedConfig = getWorkerConfig(
|
|
14105
14196
|
workerConfigPath,
|
|
14106
14197
|
cloudflareEnv,
|
|
14198
|
+
pluginConfig.experimental?.mixedMode ?? false,
|
|
14107
14199
|
{
|
|
14108
14200
|
visitedConfigPaths: configPaths
|
|
14109
14201
|
}
|
|
@@ -14138,6 +14230,7 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14138
14230
|
}
|
|
14139
14231
|
|
|
14140
14232
|
// src/websockets.ts
|
|
14233
|
+
import { createHeaders } from "@mjackson/node-fetch-server";
|
|
14141
14234
|
import { coupleWebSocket } from "miniflare";
|
|
14142
14235
|
import { WebSocketServer } from "ws";
|
|
14143
14236
|
function handleWebSocket(httpServer, getFetcher) {
|
|
@@ -14149,7 +14242,7 @@ function handleWebSocket(httpServer, getFetcher) {
|
|
|
14149
14242
|
if (request.headers["sec-websocket-protocol"]?.startsWith("vite")) {
|
|
14150
14243
|
return;
|
|
14151
14244
|
}
|
|
14152
|
-
const headers =
|
|
14245
|
+
const headers = createHeaders(request);
|
|
14153
14246
|
const fetcher = await getFetcher();
|
|
14154
14247
|
const response = await fetcher(url, {
|
|
14155
14248
|
headers,
|
|
@@ -14181,12 +14274,15 @@ function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolve
|
|
|
14181
14274
|
for (const envName of workersEnvironmentNames) {
|
|
14182
14275
|
const workerEnvConfig = resolvedViteConfig.environments[envName];
|
|
14183
14276
|
assert9(workerEnvConfig, `Missing environment config for "${envName}"`);
|
|
14184
|
-
const { optimizeDeps, resolve:
|
|
14277
|
+
const { optimizeDeps, resolve: resolve7 } = workerEnvConfig;
|
|
14185
14278
|
const disallowedConfig = {};
|
|
14186
14279
|
const disallowedOptimizeDepsExcludeEntries = (optimizeDeps.exclude ?? []).filter((entry) => {
|
|
14187
14280
|
if (cloudflareBuiltInModules.includes(entry)) {
|
|
14188
14281
|
return false;
|
|
14189
14282
|
}
|
|
14283
|
+
if (isNodeAlsModule(entry) && isNodeAls(resolvedPluginConfig.workers[envName])) {
|
|
14284
|
+
return false;
|
|
14285
|
+
}
|
|
14190
14286
|
if (NODEJS_MODULES_RE.test(entry) && isNodeCompat(resolvedPluginConfig.workers[envName])) {
|
|
14191
14287
|
return false;
|
|
14192
14288
|
}
|
|
@@ -14195,8 +14291,8 @@ function validateWorkerEnvironmentsResolvedConfigs(resolvedPluginConfig, resolve
|
|
|
14195
14291
|
if (disallowedOptimizeDepsExcludeEntries.length > 0) {
|
|
14196
14292
|
disallowedConfig.optimizeDepsExclude = disallowedOptimizeDepsExcludeEntries;
|
|
14197
14293
|
}
|
|
14198
|
-
if (
|
|
14199
|
-
disallowedConfig.resolveExternal =
|
|
14294
|
+
if (resolve7.external === true || resolve7.external.length > 0) {
|
|
14295
|
+
disallowedConfig.resolveExternal = resolve7.external;
|
|
14200
14296
|
}
|
|
14201
14297
|
if (Object.keys(disallowedConfig).length > 0) {
|
|
14202
14298
|
disallowedEnvsConfigs.set(envName, disallowedConfig);
|
|
@@ -14402,95 +14498,104 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14402
14498
|
}
|
|
14403
14499
|
},
|
|
14404
14500
|
hotUpdate(options) {
|
|
14405
|
-
|
|
14406
|
-
|
|
14407
|
-
resolvedPluginConfig
|
|
14408
|
-
|
|
14409
|
-
|
|
14410
|
-
|
|
14411
|
-
)
|
|
14412
|
-
) {
|
|
14501
|
+
const changedFilePath = path9.resolve(options.file);
|
|
14502
|
+
if (resolvedPluginConfig.configPaths.has(changedFilePath) || hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) || hasAssetsConfigChanged(
|
|
14503
|
+
resolvedPluginConfig,
|
|
14504
|
+
resolvedViteConfig,
|
|
14505
|
+
changedFilePath
|
|
14506
|
+
)) {
|
|
14413
14507
|
options.server.restart();
|
|
14414
14508
|
return [];
|
|
14415
14509
|
}
|
|
14416
14510
|
},
|
|
14417
14511
|
async configureServer(viteDevServer) {
|
|
14418
|
-
|
|
14419
|
-
|
|
14420
|
-
|
|
14512
|
+
const inputInspectorPort = await getInputInspectorPortOption(
|
|
14513
|
+
pluginConfig,
|
|
14514
|
+
viteDevServer
|
|
14515
|
+
);
|
|
14516
|
+
const miniflareDevOptions = await getDevMiniflareOptions(
|
|
14517
|
+
resolvedPluginConfig,
|
|
14518
|
+
viteDevServer,
|
|
14519
|
+
inputInspectorPort
|
|
14421
14520
|
);
|
|
14422
14521
|
if (!miniflare) {
|
|
14423
|
-
|
|
14424
|
-
pluginConfig,
|
|
14425
|
-
viteDevServer
|
|
14426
|
-
);
|
|
14427
|
-
miniflare = new Miniflare(
|
|
14428
|
-
getDevMiniflareOptions(
|
|
14429
|
-
resolvedPluginConfig,
|
|
14430
|
-
viteDevServer,
|
|
14431
|
-
inputInspectorPort
|
|
14432
|
-
)
|
|
14433
|
-
);
|
|
14522
|
+
miniflare = new Miniflare(miniflareDevOptions);
|
|
14434
14523
|
} else {
|
|
14435
|
-
|
|
14436
|
-
await miniflare.setOptions(
|
|
14437
|
-
getDevMiniflareOptions(
|
|
14438
|
-
resolvedPluginConfig,
|
|
14439
|
-
viteDevServer,
|
|
14440
|
-
resolvedInspectorPort ?? false
|
|
14441
|
-
)
|
|
14442
|
-
);
|
|
14524
|
+
await miniflare.setOptions(miniflareDevOptions);
|
|
14443
14525
|
}
|
|
14444
14526
|
await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
|
|
14445
|
-
|
|
14446
|
-
async (
|
|
14527
|
+
if (viteDevServer.httpServer) {
|
|
14528
|
+
handleWebSocket(viteDevServer.httpServer, async () => {
|
|
14447
14529
|
assert10(miniflare, `Miniflare not defined`);
|
|
14448
|
-
const routerWorker = await
|
|
14449
|
-
return routerWorker.fetch
|
|
14450
|
-
|
|
14451
|
-
|
|
14452
|
-
},
|
|
14453
|
-
{ alwaysCallNext: false }
|
|
14454
|
-
);
|
|
14455
|
-
handleWebSocket(viteDevServer.httpServer, async () => {
|
|
14456
|
-
assert10(miniflare, `Miniflare not defined`);
|
|
14457
|
-
const routerWorker = await getRouterWorker(miniflare);
|
|
14458
|
-
return routerWorker.fetch;
|
|
14459
|
-
});
|
|
14530
|
+
const routerWorker = await miniflare.getWorker(ROUTER_WORKER_NAME);
|
|
14531
|
+
return routerWorker.fetch;
|
|
14532
|
+
});
|
|
14533
|
+
}
|
|
14460
14534
|
return () => {
|
|
14461
|
-
viteDevServer.middlewares.use((req, res, next) => {
|
|
14462
|
-
|
|
14535
|
+
viteDevServer.middlewares.use(async (req, res, next) => {
|
|
14536
|
+
try {
|
|
14537
|
+
assert10(miniflare, `Miniflare not defined`);
|
|
14538
|
+
const request = createRequest(req, res);
|
|
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
|
+
}
|
|
14553
|
+
if (req.httpVersionMajor === 2) {
|
|
14554
|
+
response.headers.delete("transfer-encoding");
|
|
14555
|
+
}
|
|
14556
|
+
await sendResponse(res, response);
|
|
14557
|
+
} catch (error) {
|
|
14558
|
+
next(error);
|
|
14559
|
+
}
|
|
14463
14560
|
});
|
|
14464
14561
|
};
|
|
14465
14562
|
},
|
|
14466
14563
|
async configurePreviewServer(vitePreviewServer) {
|
|
14467
|
-
const workerConfigs = getWorkerConfigs(
|
|
14564
|
+
const workerConfigs = getWorkerConfigs(
|
|
14565
|
+
vitePreviewServer.config.root,
|
|
14566
|
+
pluginConfig.experimental?.mixedMode ?? false
|
|
14567
|
+
);
|
|
14468
14568
|
const inputInspectorPort = await getInputInspectorPortOption(
|
|
14469
14569
|
pluginConfig,
|
|
14470
14570
|
vitePreviewServer
|
|
14471
14571
|
);
|
|
14472
14572
|
const miniflare2 = new Miniflare(
|
|
14473
|
-
getPreviewMiniflareOptions(
|
|
14573
|
+
await getPreviewMiniflareOptions(
|
|
14474
14574
|
vitePreviewServer,
|
|
14475
14575
|
workerConfigs,
|
|
14476
14576
|
pluginConfig.persistState ?? true,
|
|
14577
|
+
!!pluginConfig.experimental?.mixedMode,
|
|
14477
14578
|
inputInspectorPort
|
|
14478
14579
|
)
|
|
14479
14580
|
);
|
|
14480
|
-
const middleware = createMiddleware(
|
|
14481
|
-
({ request }) => {
|
|
14482
|
-
return miniflare2.dispatchFetch(toMiniflareRequest(request), {
|
|
14483
|
-
redirect: "manual"
|
|
14484
|
-
});
|
|
14485
|
-
},
|
|
14486
|
-
{ alwaysCallNext: false }
|
|
14487
|
-
);
|
|
14488
14581
|
handleWebSocket(
|
|
14489
14582
|
vitePreviewServer.httpServer,
|
|
14490
14583
|
() => miniflare2.dispatchFetch
|
|
14491
14584
|
);
|
|
14492
|
-
vitePreviewServer.middlewares.use((req, res, next) => {
|
|
14493
|
-
|
|
14585
|
+
vitePreviewServer.middlewares.use(async (req, res, next) => {
|
|
14586
|
+
try {
|
|
14587
|
+
const request = createRequest(req, res);
|
|
14588
|
+
const response = await miniflare2.dispatchFetch(
|
|
14589
|
+
toMiniflareRequest(request),
|
|
14590
|
+
{ redirect: "manual" }
|
|
14591
|
+
);
|
|
14592
|
+
if (req.httpVersionMajor === 2) {
|
|
14593
|
+
response.headers.delete("transfer-encoding");
|
|
14594
|
+
}
|
|
14595
|
+
await sendResponse(res, response);
|
|
14596
|
+
} catch (error) {
|
|
14597
|
+
next(error);
|
|
14598
|
+
}
|
|
14494
14599
|
});
|
|
14495
14600
|
}
|
|
14496
14601
|
},
|
|
@@ -14683,6 +14788,25 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14683
14788
|
);
|
|
14684
14789
|
}
|
|
14685
14790
|
},
|
|
14791
|
+
// Plugin that handles Node.js Async Local Storage (ALS) compatibility support for Vite Environments that are hosted in Cloudflare Workers.
|
|
14792
|
+
{
|
|
14793
|
+
name: "vite-plugin-cloudflare:nodejs-als",
|
|
14794
|
+
apply(_config, env2) {
|
|
14795
|
+
return !env2.isPreview;
|
|
14796
|
+
},
|
|
14797
|
+
configEnvironment(name, config) {
|
|
14798
|
+
if (isNodeAls(getWorkerConfig2(name))) {
|
|
14799
|
+
return {
|
|
14800
|
+
resolve: {
|
|
14801
|
+
builtins: ["async_hooks", "node:async_hooks"]
|
|
14802
|
+
},
|
|
14803
|
+
optimizeDeps: {
|
|
14804
|
+
exclude: ["async_hooks", "node:async_hooks"]
|
|
14805
|
+
}
|
|
14806
|
+
};
|
|
14807
|
+
}
|
|
14808
|
+
}
|
|
14809
|
+
},
|
|
14686
14810
|
// Plugin that provides an __debug path for debugging the Cloudflare Workers.
|
|
14687
14811
|
{
|
|
14688
14812
|
name: "vite-plugin-cloudflare:debug",
|
|
@@ -14707,7 +14831,10 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14707
14831
|
});
|
|
14708
14832
|
},
|
|
14709
14833
|
async configurePreviewServer(vitePreviewServer) {
|
|
14710
|
-
const workerConfigs = getWorkerConfigs(
|
|
14834
|
+
const workerConfigs = getWorkerConfigs(
|
|
14835
|
+
vitePreviewServer.config.root,
|
|
14836
|
+
pluginConfig.experimental?.mixedMode ?? false
|
|
14837
|
+
);
|
|
14711
14838
|
if (workerConfigs.length >= 1 && pluginConfig.inspectorPort !== false) {
|
|
14712
14839
|
addDebugToVitePrintUrls(vitePreviewServer);
|
|
14713
14840
|
}
|
|
@@ -14748,6 +14875,9 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14748
14875
|
build.onResolve(
|
|
14749
14876
|
{ filter: NODEJS_MODULES_RE },
|
|
14750
14877
|
({ path: path10, importer }) => {
|
|
14878
|
+
if (isNodeAls(workerConfig) && isNodeAlsModule(path10)) {
|
|
14879
|
+
return;
|
|
14880
|
+
}
|
|
14751
14881
|
const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
|
|
14752
14882
|
nodeJsCompatWarnings?.registerImport(path10, importer);
|
|
14753
14883
|
return { path: path10, external: true };
|
|
@@ -14777,6 +14907,9 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14777
14907
|
async resolveId(source, importer) {
|
|
14778
14908
|
const workerConfig = getWorkerConfig2(this.environment.name);
|
|
14779
14909
|
if (workerConfig && !isNodeCompat(workerConfig)) {
|
|
14910
|
+
if (isNodeAls(workerConfig) && isNodeAlsModule(source)) {
|
|
14911
|
+
return;
|
|
14912
|
+
}
|
|
14780
14913
|
const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
|
|
14781
14914
|
if (nodejsBuiltins.has(source)) {
|
|
14782
14915
|
nodeJsCompatWarnings?.registerImport(source, importer);
|
|
@@ -14795,10 +14928,16 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14795
14928
|
}
|
|
14796
14929
|
}
|
|
14797
14930
|
async function getInputInspectorPortOption(pluginConfig, viteServer) {
|
|
14931
|
+
if (pluginConfig.inspectorPort === void 0 || pluginConfig.inspectorPort === 0) {
|
|
14932
|
+
const resolvedInspectorPort = await getResolvedInspectorPort(pluginConfig);
|
|
14933
|
+
if (resolvedInspectorPort !== null) {
|
|
14934
|
+
return resolvedInspectorPort;
|
|
14935
|
+
}
|
|
14936
|
+
}
|
|
14798
14937
|
const inputInspectorPort = pluginConfig.inspectorPort ?? await getFirstAvailablePort(DEFAULT_INSPECTOR_PORT);
|
|
14799
14938
|
if (pluginConfig.inspectorPort === void 0 && inputInspectorPort !== DEFAULT_INSPECTOR_PORT) {
|
|
14800
14939
|
viteServer.config.logger.warn(
|
|
14801
|
-
|
|
14940
|
+
colors3.dim(
|
|
14802
14941
|
`Default inspector port ${DEFAULT_INSPECTOR_PORT} not available, using ${inputInspectorPort} instead
|
|
14803
14942
|
`
|
|
14804
14943
|
)
|
|
@@ -14824,6 +14963,19 @@ function getDotDevDotVarsContent(configPath, cloudflareEnv) {
|
|
|
14824
14963
|
}
|
|
14825
14964
|
return null;
|
|
14826
14965
|
}
|
|
14966
|
+
function hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) {
|
|
14967
|
+
return [...resolvedPluginConfig.configPaths].some((configPath) => {
|
|
14968
|
+
const dotDevDotVars = path9.join(path9.dirname(configPath), ".dev.vars");
|
|
14969
|
+
if (dotDevDotVars === changedFilePath) {
|
|
14970
|
+
return true;
|
|
14971
|
+
}
|
|
14972
|
+
if (resolvedPluginConfig.cloudflareEnv) {
|
|
14973
|
+
const dotDevDotVarsForEnv = `${dotDevDotVars}.${resolvedPluginConfig.cloudflareEnv}`;
|
|
14974
|
+
return dotDevDotVarsForEnv === changedFilePath;
|
|
14975
|
+
}
|
|
14976
|
+
return false;
|
|
14977
|
+
});
|
|
14978
|
+
}
|
|
14827
14979
|
export {
|
|
14828
14980
|
cloudflare2 as cloudflare
|
|
14829
14981
|
};
|