@cloudflare/vite-plugin 1.7.2 → 1.7.3
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 +1 -1
- package/dist/asset-workers/router-worker.js +1561 -57
- package/dist/index.d.ts +7 -6
- package/dist/index.js +257 -230
- package/dist/runner-worker/index.js +4 -10
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -248,17 +248,17 @@ var require_ignore = __commonJS({
|
|
|
248
248
|
var throwError = (message, Ctor) => {
|
|
249
249
|
throw new Ctor(message);
|
|
250
250
|
};
|
|
251
|
-
var checkPath = (
|
|
252
|
-
if (!isString(
|
|
251
|
+
var checkPath = (path12, originalPath, doThrow) => {
|
|
252
|
+
if (!isString(path12)) {
|
|
253
253
|
return doThrow(
|
|
254
254
|
`path must be a string, but got \`${originalPath}\``,
|
|
255
255
|
TypeError
|
|
256
256
|
);
|
|
257
257
|
}
|
|
258
|
-
if (!
|
|
258
|
+
if (!path12) {
|
|
259
259
|
return doThrow(`path must not be empty`, TypeError);
|
|
260
260
|
}
|
|
261
|
-
if (checkPath.isNotRelative(
|
|
261
|
+
if (checkPath.isNotRelative(path12)) {
|
|
262
262
|
const r2 = "`path.relative()`d";
|
|
263
263
|
return doThrow(
|
|
264
264
|
`path should be a ${r2} string, but got "${originalPath}"`,
|
|
@@ -267,7 +267,7 @@ var require_ignore = __commonJS({
|
|
|
267
267
|
}
|
|
268
268
|
return true;
|
|
269
269
|
};
|
|
270
|
-
var isNotRelative = (
|
|
270
|
+
var isNotRelative = (path12) => REGEX_TEST_INVALID_PATH.test(path12);
|
|
271
271
|
checkPath.isNotRelative = isNotRelative;
|
|
272
272
|
checkPath.convert = (p) => p;
|
|
273
273
|
var Ignore = class {
|
|
@@ -326,7 +326,7 @@ var require_ignore = __commonJS({
|
|
|
326
326
|
// setting `checkUnignored` to `false` could reduce additional
|
|
327
327
|
// path matching.
|
|
328
328
|
// @returns {TestResult} true if a file is ignored
|
|
329
|
-
_testOne(
|
|
329
|
+
_testOne(path12, checkUnignored) {
|
|
330
330
|
let ignored = false;
|
|
331
331
|
let unignored = false;
|
|
332
332
|
this._rules.forEach((rule) => {
|
|
@@ -334,7 +334,7 @@ var require_ignore = __commonJS({
|
|
|
334
334
|
if (unignored === negative && ignored !== unignored || negative && !ignored && !unignored && !checkUnignored) {
|
|
335
335
|
return;
|
|
336
336
|
}
|
|
337
|
-
const matched = rule.regex.test(
|
|
337
|
+
const matched = rule.regex.test(path12);
|
|
338
338
|
if (matched) {
|
|
339
339
|
ignored = !negative;
|
|
340
340
|
unignored = negative;
|
|
@@ -347,24 +347,24 @@ var require_ignore = __commonJS({
|
|
|
347
347
|
}
|
|
348
348
|
// @returns {TestResult}
|
|
349
349
|
_test(originalPath, cache2, checkUnignored, slices) {
|
|
350
|
-
const
|
|
350
|
+
const path12 = originalPath && checkPath.convert(originalPath);
|
|
351
351
|
checkPath(
|
|
352
|
-
|
|
352
|
+
path12,
|
|
353
353
|
originalPath,
|
|
354
354
|
this._allowRelativePaths ? RETURN_FALSE : throwError
|
|
355
355
|
);
|
|
356
|
-
return this._t(
|
|
356
|
+
return this._t(path12, cache2, checkUnignored, slices);
|
|
357
357
|
}
|
|
358
|
-
_t(
|
|
359
|
-
if (
|
|
360
|
-
return cache2[
|
|
358
|
+
_t(path12, cache2, checkUnignored, slices) {
|
|
359
|
+
if (path12 in cache2) {
|
|
360
|
+
return cache2[path12];
|
|
361
361
|
}
|
|
362
362
|
if (!slices) {
|
|
363
|
-
slices =
|
|
363
|
+
slices = path12.split(SLASH);
|
|
364
364
|
}
|
|
365
365
|
slices.pop();
|
|
366
366
|
if (!slices.length) {
|
|
367
|
-
return cache2[
|
|
367
|
+
return cache2[path12] = this._testOne(path12, checkUnignored);
|
|
368
368
|
}
|
|
369
369
|
const parent = this._t(
|
|
370
370
|
slices.join(SLASH) + SLASH,
|
|
@@ -372,24 +372,24 @@ var require_ignore = __commonJS({
|
|
|
372
372
|
checkUnignored,
|
|
373
373
|
slices
|
|
374
374
|
);
|
|
375
|
-
return cache2[
|
|
375
|
+
return cache2[path12] = parent.ignored ? parent : this._testOne(path12, checkUnignored);
|
|
376
376
|
}
|
|
377
|
-
ignores(
|
|
378
|
-
return this._test(
|
|
377
|
+
ignores(path12) {
|
|
378
|
+
return this._test(path12, this._ignoreCache, false).ignored;
|
|
379
379
|
}
|
|
380
380
|
createFilter() {
|
|
381
|
-
return (
|
|
381
|
+
return (path12) => !this.ignores(path12);
|
|
382
382
|
}
|
|
383
383
|
filter(paths) {
|
|
384
384
|
return makeArray(paths).filter(this.createFilter());
|
|
385
385
|
}
|
|
386
386
|
// @returns {TestResult}
|
|
387
|
-
test(
|
|
388
|
-
return this._test(
|
|
387
|
+
test(path12) {
|
|
388
|
+
return this._test(path12, this._testCache, true);
|
|
389
389
|
}
|
|
390
390
|
};
|
|
391
391
|
var factory = (options) => new Ignore(options);
|
|
392
|
-
var isPathValid = (
|
|
392
|
+
var isPathValid = (path12) => checkPath(path12 && checkPath.convert(path12), path12, RETURN_FALSE);
|
|
393
393
|
factory.isPathValid = isPathValid;
|
|
394
394
|
factory.default = factory;
|
|
395
395
|
module.exports = factory;
|
|
@@ -400,7 +400,7 @@ var require_ignore = __commonJS({
|
|
|
400
400
|
const makePosix = (str) => /^\\\\\?\\/.test(str) || /["<>|\u0000-\u001F]+/u.test(str) ? str : str.replace(/\\/g, "/");
|
|
401
401
|
checkPath.convert = makePosix;
|
|
402
402
|
const REGIX_IS_WINDOWS_PATH_ABSOLUTE = /^[a-z]:\//i;
|
|
403
|
-
checkPath.isNotRelative = (
|
|
403
|
+
checkPath.isNotRelative = (path12) => REGIX_IS_WINDOWS_PATH_ABSOLUTE.test(path12) || isNotRelative(path12);
|
|
404
404
|
}
|
|
405
405
|
}
|
|
406
406
|
});
|
|
@@ -443,11 +443,11 @@ var require_Mime = __commonJS({
|
|
|
443
443
|
}
|
|
444
444
|
}
|
|
445
445
|
};
|
|
446
|
-
Mime.prototype.getType = function(
|
|
447
|
-
|
|
448
|
-
let last =
|
|
446
|
+
Mime.prototype.getType = function(path12) {
|
|
447
|
+
path12 = String(path12);
|
|
448
|
+
let last = path12.replace(/^.*[/\\]/, "").toLowerCase();
|
|
449
449
|
let ext = last.replace(/^.*\./, "").toLowerCase();
|
|
450
|
-
let hasPath = last.length <
|
|
450
|
+
let hasPath = last.length < path12.length;
|
|
451
451
|
let hasDot = ext.length < last.length - 1;
|
|
452
452
|
return (hasDot || !hasPath) && this._types[ext] || null;
|
|
453
453
|
};
|
|
@@ -486,9 +486,8 @@ var require_mime = __commonJS({
|
|
|
486
486
|
|
|
487
487
|
// src/index.ts
|
|
488
488
|
import assert11 from "node:assert";
|
|
489
|
-
import * as fs6 from "node:fs";
|
|
490
489
|
import * as fsp2 from "node:fs/promises";
|
|
491
|
-
import * as
|
|
490
|
+
import * as path11 from "node:path";
|
|
492
491
|
|
|
493
492
|
// ../workers-shared/asset-worker/src/utils/rules-engine.ts
|
|
494
493
|
var ESCAPE_REGEX_CHARACTERS = /[-/\\^$*+?.()|[\]{}]/g;
|
|
@@ -1583,7 +1582,6 @@ var MagicString = class _MagicString {
|
|
|
1583
1582
|
|
|
1584
1583
|
// src/index.ts
|
|
1585
1584
|
import { Miniflare } from "miniflare";
|
|
1586
|
-
import colors4 from "picocolors";
|
|
1587
1585
|
import * as vite6 from "vite";
|
|
1588
1586
|
|
|
1589
1587
|
// src/constants.ts
|
|
@@ -1597,6 +1595,7 @@ var ADDITIONAL_MODULE_TYPES = [
|
|
|
1597
1595
|
];
|
|
1598
1596
|
var PUBLIC_DIR_PREFIX = "/__vite_public_dir__";
|
|
1599
1597
|
var DEFAULT_INSPECTOR_PORT = 9229;
|
|
1598
|
+
var DEBUG_PATH = "/__debug";
|
|
1600
1599
|
var kRequestType = Symbol("kRequestType");
|
|
1601
1600
|
|
|
1602
1601
|
// src/additional-modules.ts
|
|
@@ -1756,11 +1755,11 @@ ${invalidHeaderRulesList}`
|
|
|
1756
1755
|
}
|
|
1757
1756
|
|
|
1758
1757
|
// ../workers-shared/utils/configuration/validateURL.ts
|
|
1759
|
-
var extractPathname = (
|
|
1760
|
-
if (!
|
|
1761
|
-
|
|
1758
|
+
var extractPathname = (path12 = "/", includeSearch, includeHash) => {
|
|
1759
|
+
if (!path12.startsWith("/")) {
|
|
1760
|
+
path12 = `/${path12}`;
|
|
1762
1761
|
}
|
|
1763
|
-
const url = new URL(`//${
|
|
1762
|
+
const url = new URL(`//${path12}`, "relative://");
|
|
1764
1763
|
return `${url.pathname}${includeSearch ? url.search : ""}${includeHash ? url.hash : ""}`;
|
|
1765
1764
|
};
|
|
1766
1765
|
var URL_REGEX = /^https:\/\/+(?<host>[^/]+)\/?(?<path>.*)/;
|
|
@@ -1793,8 +1792,8 @@ var validateUrl = (token, onlyRelative = false, disallowPorts = false, includeSe
|
|
|
1793
1792
|
if (!token.startsWith("/") && onlyRelative) {
|
|
1794
1793
|
token = `/${token}`;
|
|
1795
1794
|
}
|
|
1796
|
-
const
|
|
1797
|
-
if (
|
|
1795
|
+
const path12 = PATH_REGEX.exec(token);
|
|
1796
|
+
if (path12) {
|
|
1798
1797
|
try {
|
|
1799
1798
|
return [extractPathname(token, includeSearch, includeHash), void 0];
|
|
1800
1799
|
} catch {
|
|
@@ -1855,7 +1854,7 @@ function parseHeaders(input, {
|
|
|
1855
1854
|
});
|
|
1856
1855
|
}
|
|
1857
1856
|
}
|
|
1858
|
-
const [
|
|
1857
|
+
const [path12, pathError] = validateUrl(line, false, true);
|
|
1859
1858
|
if (pathError) {
|
|
1860
1859
|
invalid.push({
|
|
1861
1860
|
line,
|
|
@@ -1866,7 +1865,7 @@ function parseHeaders(input, {
|
|
|
1866
1865
|
continue;
|
|
1867
1866
|
}
|
|
1868
1867
|
rule = {
|
|
1869
|
-
path:
|
|
1868
|
+
path: path12,
|
|
1870
1869
|
line,
|
|
1871
1870
|
headers: {},
|
|
1872
1871
|
unsetHeaders: []
|
|
@@ -2441,8 +2440,8 @@ function getErrorMap() {
|
|
|
2441
2440
|
return overrideErrorMap;
|
|
2442
2441
|
}
|
|
2443
2442
|
var makeIssue = (params) => {
|
|
2444
|
-
const { data: data2, path:
|
|
2445
|
-
const fullPath = [...
|
|
2443
|
+
const { data: data2, path: path12, errorMaps, issueData } = params;
|
|
2444
|
+
const fullPath = [...path12, ...issueData.path || []];
|
|
2446
2445
|
const fullIssue = {
|
|
2447
2446
|
...issueData,
|
|
2448
2447
|
path: fullPath
|
|
@@ -2541,11 +2540,11 @@ var errorUtil;
|
|
|
2541
2540
|
errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
2542
2541
|
})(errorUtil || (errorUtil = {}));
|
|
2543
2542
|
var ParseInputLazyPath = class {
|
|
2544
|
-
constructor(parent, value,
|
|
2543
|
+
constructor(parent, value, path12, key) {
|
|
2545
2544
|
this._cachedPath = [];
|
|
2546
2545
|
this.parent = parent;
|
|
2547
2546
|
this.data = value;
|
|
2548
|
-
this._path =
|
|
2547
|
+
this._path = path12;
|
|
2549
2548
|
this._key = key;
|
|
2550
2549
|
}
|
|
2551
2550
|
get path() {
|
|
@@ -5826,6 +5825,12 @@ var RouterConfigSchema = z.object({
|
|
|
5826
5825
|
has_user_worker: z.boolean().optional(),
|
|
5827
5826
|
...InternalConfigSchema.shape
|
|
5828
5827
|
});
|
|
5828
|
+
var EyeballRouterConfigSchema = z.union([
|
|
5829
|
+
z.object({
|
|
5830
|
+
limitedAssetsOnly: z.boolean().optional()
|
|
5831
|
+
}),
|
|
5832
|
+
z.null()
|
|
5833
|
+
]);
|
|
5829
5834
|
var MetadataStaticRedirectEntry = z.object({
|
|
5830
5835
|
status: z.number(),
|
|
5831
5836
|
to: z.string(),
|
|
@@ -11633,17 +11638,17 @@ function withTrailingSlash(input = "", respectQueryAndFragment) {
|
|
|
11633
11638
|
if (hasTrailingSlash(input, true)) {
|
|
11634
11639
|
return input || "/";
|
|
11635
11640
|
}
|
|
11636
|
-
let
|
|
11641
|
+
let path12 = input;
|
|
11637
11642
|
let fragment = "";
|
|
11638
11643
|
const fragmentIndex = input.indexOf("#");
|
|
11639
11644
|
if (fragmentIndex >= 0) {
|
|
11640
|
-
|
|
11645
|
+
path12 = input.slice(0, fragmentIndex);
|
|
11641
11646
|
fragment = input.slice(fragmentIndex);
|
|
11642
|
-
if (!
|
|
11647
|
+
if (!path12) {
|
|
11643
11648
|
return fragment;
|
|
11644
11649
|
}
|
|
11645
11650
|
}
|
|
11646
|
-
const [s0, ...s] =
|
|
11651
|
+
const [s0, ...s] = path12.split("?");
|
|
11647
11652
|
return s0 + "/" + (s.length > 0 ? `?${s.join("?")}` : "") + fragment;
|
|
11648
11653
|
}
|
|
11649
11654
|
function isNonEmptyURL(url) {
|
|
@@ -11677,8 +11682,8 @@ import path3, { dirname as dirname3 } from "node:path";
|
|
|
11677
11682
|
import v8 from "node:v8";
|
|
11678
11683
|
import { format as format2, inspect } from "node:util";
|
|
11679
11684
|
var BUILTIN_MODULES = new Set(builtinModules);
|
|
11680
|
-
function normalizeSlash(
|
|
11681
|
-
return
|
|
11685
|
+
function normalizeSlash(path12) {
|
|
11686
|
+
return path12.replace(/\\/g, "/");
|
|
11682
11687
|
}
|
|
11683
11688
|
var own$1 = {}.hasOwnProperty;
|
|
11684
11689
|
var classRegExp = /^([A-Z][a-z\d]*)+$/;
|
|
@@ -11791,8 +11796,8 @@ codes.ERR_INVALID_PACKAGE_CONFIG = createError(
|
|
|
11791
11796
|
* @param {string} [base]
|
|
11792
11797
|
* @param {string} [message]
|
|
11793
11798
|
*/
|
|
11794
|
-
(
|
|
11795
|
-
return `Invalid package config ${
|
|
11799
|
+
(path12, base, message) => {
|
|
11800
|
+
return `Invalid package config ${path12}${base ? ` while importing ${base}` : ""}${message ? `. ${message}` : ""}`;
|
|
11796
11801
|
},
|
|
11797
11802
|
Error
|
|
11798
11803
|
);
|
|
@@ -11824,8 +11829,8 @@ codes.ERR_MODULE_NOT_FOUND = createError(
|
|
|
11824
11829
|
* @param {string} base
|
|
11825
11830
|
* @param {boolean} [exactUrl]
|
|
11826
11831
|
*/
|
|
11827
|
-
(
|
|
11828
|
-
return `Cannot find ${exactUrl ? "module" : "package"} '${
|
|
11832
|
+
(path12, base, exactUrl = false) => {
|
|
11833
|
+
return `Cannot find ${exactUrl ? "module" : "package"} '${path12}' imported from ${base}`;
|
|
11829
11834
|
},
|
|
11830
11835
|
Error
|
|
11831
11836
|
);
|
|
@@ -11876,8 +11881,8 @@ codes.ERR_UNKNOWN_FILE_EXTENSION = createError(
|
|
|
11876
11881
|
* @param {string} extension
|
|
11877
11882
|
* @param {string} path
|
|
11878
11883
|
*/
|
|
11879
|
-
(extension,
|
|
11880
|
-
return `Unknown file extension "${extension}" for ${
|
|
11884
|
+
(extension, path12) => {
|
|
11885
|
+
return `Unknown file extension "${extension}" for ${path12}`;
|
|
11881
11886
|
},
|
|
11882
11887
|
TypeError
|
|
11883
11888
|
);
|
|
@@ -12249,9 +12254,9 @@ Default "index" lookups for the main are deprecated for ES modules.`,
|
|
|
12249
12254
|
);
|
|
12250
12255
|
}
|
|
12251
12256
|
}
|
|
12252
|
-
function tryStatSync(
|
|
12257
|
+
function tryStatSync(path12) {
|
|
12253
12258
|
try {
|
|
12254
|
-
return statSync(
|
|
12259
|
+
return statSync(path12);
|
|
12255
12260
|
} catch {
|
|
12256
12261
|
}
|
|
12257
12262
|
}
|
|
@@ -13056,8 +13061,8 @@ function isNodeAls(workerConfig) {
|
|
|
13056
13061
|
workerConfig.compatibility_flags ?? []
|
|
13057
13062
|
).mode === "als";
|
|
13058
13063
|
}
|
|
13059
|
-
function isNodeAlsModule(
|
|
13060
|
-
return /^(node:)?async_hooks$/.test(
|
|
13064
|
+
function isNodeAlsModule(path12) {
|
|
13065
|
+
return /^(node:)?async_hooks$/.test(path12);
|
|
13061
13066
|
}
|
|
13062
13067
|
var injectsByModule = /* @__PURE__ */ new Map();
|
|
13063
13068
|
var virtualModulePathToSpecifier = /* @__PURE__ */ new Map();
|
|
@@ -13190,7 +13195,6 @@ var VITE_DEV_METADATA_HEADER = "__VITE_DEV_METADATA__";
|
|
|
13190
13195
|
// src/utils.ts
|
|
13191
13196
|
import * as path5 from "node:path";
|
|
13192
13197
|
import { createRequest, sendResponse } from "@mjackson/node-fetch-server";
|
|
13193
|
-
import getPort, { portNumbers } from "get-port";
|
|
13194
13198
|
import {
|
|
13195
13199
|
Request as MiniflareRequest,
|
|
13196
13200
|
Response as MiniflareResponse
|
|
@@ -13203,11 +13207,8 @@ var postfixRE = /[?#].*$/;
|
|
|
13203
13207
|
function cleanUrl(url) {
|
|
13204
13208
|
return url.replace(postfixRE, "");
|
|
13205
13209
|
}
|
|
13206
|
-
function
|
|
13207
|
-
return
|
|
13208
|
-
}
|
|
13209
|
-
function withTrailingSlash2(path11) {
|
|
13210
|
-
return path11.endsWith("/") ? path11 : `${path11}/`;
|
|
13210
|
+
function withTrailingSlash2(path12) {
|
|
13211
|
+
return path12.endsWith("/") ? path12 : `${path12}/`;
|
|
13211
13212
|
}
|
|
13212
13213
|
function createRequestHandler(handler) {
|
|
13213
13214
|
return async (req, res, next) => {
|
|
@@ -13296,14 +13297,13 @@ var CloudflareDevEnvironment = class extends vite2.DevEnvironment {
|
|
|
13296
13297
|
});
|
|
13297
13298
|
this.#webSocketContainer = webSocketContainer;
|
|
13298
13299
|
}
|
|
13299
|
-
async initRunner(worker,
|
|
13300
|
+
async initRunner(worker, workerConfig) {
|
|
13300
13301
|
this.#worker = worker;
|
|
13301
13302
|
const response = await this.#worker.fetch(
|
|
13302
13303
|
new URL(INIT_PATH, UNKNOWN_HOST),
|
|
13303
13304
|
{
|
|
13304
13305
|
headers: {
|
|
13305
13306
|
[VITE_DEV_METADATA_HEADER]: JSON.stringify({
|
|
13306
|
-
root,
|
|
13307
13307
|
entryPath: workerConfig.main
|
|
13308
13308
|
}),
|
|
13309
13309
|
upgrade: "websocket"
|
|
@@ -13386,14 +13386,11 @@ function createCloudflareEnvironmentOptions(workerConfig, userConfig, environmen
|
|
|
13386
13386
|
};
|
|
13387
13387
|
}
|
|
13388
13388
|
function initRunners(resolvedPluginConfig, viteDevServer, miniflare2) {
|
|
13389
|
-
if (resolvedPluginConfig.type === "assets-only") {
|
|
13390
|
-
return;
|
|
13391
|
-
}
|
|
13392
13389
|
return Promise.all(
|
|
13393
13390
|
Object.entries(resolvedPluginConfig.workers).map(
|
|
13394
13391
|
async ([environmentName, workerConfig]) => {
|
|
13395
13392
|
const worker = await miniflare2.getWorker(workerConfig.name);
|
|
13396
|
-
return viteDevServer.environments[environmentName].initRunner(worker,
|
|
13393
|
+
return viteDevServer.environments[environmentName].initRunner(worker, workerConfig);
|
|
13397
13394
|
}
|
|
13398
13395
|
)
|
|
13399
13396
|
);
|
|
@@ -13401,8 +13398,39 @@ function initRunners(resolvedPluginConfig, viteDevServer, miniflare2) {
|
|
|
13401
13398
|
|
|
13402
13399
|
// src/debugging.ts
|
|
13403
13400
|
import assert5 from "node:assert";
|
|
13401
|
+
import getPort, { portNumbers } from "get-port";
|
|
13404
13402
|
import colors2 from "picocolors";
|
|
13405
|
-
|
|
13403
|
+
async function getInputInspectorPortOption(resolvedPluginConfig, viteServer, miniflare2) {
|
|
13404
|
+
if (resolvedPluginConfig.inspectorPort === void 0 || resolvedPluginConfig.inspectorPort === 0) {
|
|
13405
|
+
const resolvedInspectorPort = await getResolvedInspectorPort(
|
|
13406
|
+
resolvedPluginConfig,
|
|
13407
|
+
miniflare2
|
|
13408
|
+
);
|
|
13409
|
+
if (resolvedInspectorPort !== null) {
|
|
13410
|
+
return resolvedInspectorPort;
|
|
13411
|
+
}
|
|
13412
|
+
}
|
|
13413
|
+
const inputInspectorPort = resolvedPluginConfig.inspectorPort ?? await getFirstAvailablePort(DEFAULT_INSPECTOR_PORT);
|
|
13414
|
+
if (resolvedPluginConfig.inspectorPort === void 0 && inputInspectorPort !== DEFAULT_INSPECTOR_PORT) {
|
|
13415
|
+
viteServer.config.logger.warn(
|
|
13416
|
+
colors2.dim(
|
|
13417
|
+
`Default inspector port ${DEFAULT_INSPECTOR_PORT} not available, using ${inputInspectorPort} instead
|
|
13418
|
+
`
|
|
13419
|
+
)
|
|
13420
|
+
);
|
|
13421
|
+
}
|
|
13422
|
+
return inputInspectorPort;
|
|
13423
|
+
}
|
|
13424
|
+
async function getResolvedInspectorPort(resolvedPluginConfig, miniflare2) {
|
|
13425
|
+
if (miniflare2 && resolvedPluginConfig.inspectorPort !== false) {
|
|
13426
|
+
const miniflareInspectorUrl = await miniflare2.getInspectorURL();
|
|
13427
|
+
return Number.parseInt(miniflareInspectorUrl.port);
|
|
13428
|
+
}
|
|
13429
|
+
return null;
|
|
13430
|
+
}
|
|
13431
|
+
function getFirstAvailablePort(start) {
|
|
13432
|
+
return getPort({ port: portNumbers(start, 65535) });
|
|
13433
|
+
}
|
|
13406
13434
|
function addDebugToVitePrintUrls(server) {
|
|
13407
13435
|
const originalPrintUrls = server.printUrls;
|
|
13408
13436
|
server.printUrls = () => {
|
|
@@ -13416,7 +13444,7 @@ function addDebugToVitePrintUrls(server) {
|
|
|
13416
13444
|
)
|
|
13417
13445
|
);
|
|
13418
13446
|
server.config.logger.info(
|
|
13419
|
-
` ${colors2.green("\u279C")} ${colors2.bold("Debug")}: ${colorDebugUrl(`${protocol}//${hostname}:${port}${
|
|
13447
|
+
` ${colors2.green("\u279C")} ${colors2.bold("Debug")}: ${colorDebugUrl(`${protocol}//${hostname}:${port}${DEBUG_PATH}`)}`
|
|
13420
13448
|
);
|
|
13421
13449
|
}
|
|
13422
13450
|
};
|
|
@@ -13424,11 +13452,11 @@ function addDebugToVitePrintUrls(server) {
|
|
|
13424
13452
|
function getDebugPathHtml(workerNames, inspectorPort) {
|
|
13425
13453
|
assert5(workerNames.length >= 1, "no workers present to debug");
|
|
13426
13454
|
const workerDevtoolsUrls = workerNames.map((workerName) => {
|
|
13427
|
-
const
|
|
13455
|
+
const localhost = `localhost:${inspectorPort}/${workerName}`;
|
|
13428
13456
|
const searchParams = new URLSearchParams({
|
|
13429
13457
|
theme: "systemPreferred",
|
|
13430
13458
|
debugger: "true",
|
|
13431
|
-
ws:
|
|
13459
|
+
ws: localhost,
|
|
13432
13460
|
domain: workerName
|
|
13433
13461
|
});
|
|
13434
13462
|
const devtoolsFrontendUrl = `https://devtools.devprod.cloudflare.dev/js_app?${searchParams}`;
|
|
@@ -13533,11 +13561,39 @@ function writeDeployConfig(resolvedPluginConfig, resolvedViteConfig) {
|
|
|
13533
13561
|
}
|
|
13534
13562
|
}
|
|
13535
13563
|
|
|
13564
|
+
// src/dev-vars.ts
|
|
13565
|
+
import * as fs4 from "node:fs";
|
|
13566
|
+
import * as path7 from "node:path";
|
|
13567
|
+
function getDotDevDotVarsContent(configPath, cloudflareEnv) {
|
|
13568
|
+
const configDir = path7.dirname(configPath);
|
|
13569
|
+
const defaultDotDevDotVarsPath = `${configDir}/.dev.vars`;
|
|
13570
|
+
const inputDotDevDotVarsPath = `${defaultDotDevDotVarsPath}${cloudflareEnv ? `.${cloudflareEnv}` : ""}`;
|
|
13571
|
+
const targetPath = fs4.existsSync(inputDotDevDotVarsPath) ? inputDotDevDotVarsPath : fs4.existsSync(defaultDotDevDotVarsPath) ? defaultDotDevDotVarsPath : null;
|
|
13572
|
+
if (targetPath) {
|
|
13573
|
+
const dotDevDotVarsContent = fs4.readFileSync(targetPath);
|
|
13574
|
+
return dotDevDotVarsContent;
|
|
13575
|
+
}
|
|
13576
|
+
return null;
|
|
13577
|
+
}
|
|
13578
|
+
function hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) {
|
|
13579
|
+
return [...resolvedPluginConfig.configPaths].some((configPath) => {
|
|
13580
|
+
const dotDevDotVars = path7.join(path7.dirname(configPath), ".dev.vars");
|
|
13581
|
+
if (dotDevDotVars === changedFilePath) {
|
|
13582
|
+
return true;
|
|
13583
|
+
}
|
|
13584
|
+
if (resolvedPluginConfig.cloudflareEnv) {
|
|
13585
|
+
const dotDevDotVarsForEnv = `${dotDevDotVars}.${resolvedPluginConfig.cloudflareEnv}`;
|
|
13586
|
+
return dotDevDotVarsForEnv === changedFilePath;
|
|
13587
|
+
}
|
|
13588
|
+
return false;
|
|
13589
|
+
});
|
|
13590
|
+
}
|
|
13591
|
+
|
|
13536
13592
|
// src/miniflare-options.ts
|
|
13537
13593
|
import assert7 from "node:assert";
|
|
13538
|
-
import * as
|
|
13594
|
+
import * as fs5 from "node:fs";
|
|
13539
13595
|
import * as fsp from "node:fs/promises";
|
|
13540
|
-
import * as
|
|
13596
|
+
import * as path8 from "node:path";
|
|
13541
13597
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
13542
13598
|
import {
|
|
13543
13599
|
getDefaultDevRegistryPath,
|
|
@@ -13559,7 +13615,7 @@ function getPersistenceRoot(root, persistState) {
|
|
|
13559
13615
|
return;
|
|
13560
13616
|
}
|
|
13561
13617
|
const defaultPersistPath = ".wrangler/state";
|
|
13562
|
-
const persistPath =
|
|
13618
|
+
const persistPath = path8.resolve(
|
|
13563
13619
|
root,
|
|
13564
13620
|
typeof persistState === "object" ? persistState.path : defaultPersistPath,
|
|
13565
13621
|
"v3"
|
|
@@ -13688,8 +13744,8 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13688
13744
|
modules: [
|
|
13689
13745
|
{
|
|
13690
13746
|
type: "ESModule",
|
|
13691
|
-
path:
|
|
13692
|
-
contents:
|
|
13747
|
+
path: path8.join(miniflareModulesRoot, ROUTER_WORKER_PATH),
|
|
13748
|
+
contents: fs5.readFileSync(
|
|
13693
13749
|
fileURLToPath2(new URL(ROUTER_WORKER_PATH, import.meta.url))
|
|
13694
13750
|
)
|
|
13695
13751
|
}
|
|
@@ -13711,8 +13767,8 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13711
13767
|
modules: [
|
|
13712
13768
|
{
|
|
13713
13769
|
type: "ESModule",
|
|
13714
|
-
path:
|
|
13715
|
-
contents:
|
|
13770
|
+
path: path8.join(miniflareModulesRoot, ASSET_WORKER_PATH),
|
|
13771
|
+
contents: fs5.readFileSync(
|
|
13716
13772
|
fileURLToPath2(new URL(ASSET_WORKER_PATH, import.meta.url))
|
|
13717
13773
|
)
|
|
13718
13774
|
}
|
|
@@ -13732,8 +13788,8 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13732
13788
|
if (publicDirInRoot && pathname.startsWith(publicPath)) {
|
|
13733
13789
|
return MiniflareResponse2.json(null);
|
|
13734
13790
|
}
|
|
13735
|
-
const publicDirFilePath =
|
|
13736
|
-
const rootDirFilePath =
|
|
13791
|
+
const publicDirFilePath = path8.join(publicDir, pathname);
|
|
13792
|
+
const rootDirFilePath = path8.join(root, pathname);
|
|
13737
13793
|
for (const resolvedPath of [publicDirFilePath, rootDirFilePath]) {
|
|
13738
13794
|
try {
|
|
13739
13795
|
const stats = await fsp.stat(resolvedPath);
|
|
@@ -13752,7 +13808,7 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13752
13808
|
const { pathname } = new URL(request.url);
|
|
13753
13809
|
const { root, publicDir } = resolvedViteConfig;
|
|
13754
13810
|
const isInPublicDir = pathname.startsWith(PUBLIC_DIR_PREFIX);
|
|
13755
|
-
const resolvedPath = isInPublicDir ?
|
|
13811
|
+
const resolvedPath = isInPublicDir ? path8.join(publicDir, pathname.slice(PUBLIC_DIR_PREFIX.length)) : path8.join(root, pathname);
|
|
13756
13812
|
try {
|
|
13757
13813
|
let html = await fsp.readFile(resolvedPath, "utf-8");
|
|
13758
13814
|
if (!isInPublicDir) {
|
|
@@ -13925,13 +13981,13 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13925
13981
|
modules: [
|
|
13926
13982
|
{
|
|
13927
13983
|
type: "ESModule",
|
|
13928
|
-
path:
|
|
13984
|
+
path: path8.join(miniflareModulesRoot, WRAPPER_PATH),
|
|
13929
13985
|
contents: wrappers.join("\n")
|
|
13930
13986
|
},
|
|
13931
13987
|
{
|
|
13932
13988
|
type: "ESModule",
|
|
13933
|
-
path:
|
|
13934
|
-
contents:
|
|
13989
|
+
path: path8.join(miniflareModulesRoot, RUNNER_PATH),
|
|
13990
|
+
contents: fs5.readFileSync(
|
|
13935
13991
|
fileURLToPath2(new URL(RUNNER_PATH, import.meta.url))
|
|
13936
13992
|
)
|
|
13937
13993
|
}
|
|
@@ -13985,8 +14041,8 @@ async function getDevMiniflareOptions(resolvedPluginConfig, viteDevServer, inspe
|
|
|
13985
14041
|
}
|
|
13986
14042
|
function getPreviewModules(main, modulesRules) {
|
|
13987
14043
|
assert7(modulesRules, `Unexpected error: 'modulesRules' is undefined`);
|
|
13988
|
-
const rootPath =
|
|
13989
|
-
const entryPath =
|
|
14044
|
+
const rootPath = path8.dirname(main);
|
|
14045
|
+
const entryPath = path8.basename(main);
|
|
13990
14046
|
return {
|
|
13991
14047
|
rootPath,
|
|
13992
14048
|
modules: [
|
|
@@ -13995,21 +14051,21 @@ function getPreviewModules(main, modulesRules) {
|
|
|
13995
14051
|
path: entryPath
|
|
13996
14052
|
},
|
|
13997
14053
|
...modulesRules.flatMap(
|
|
13998
|
-
({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((
|
|
14054
|
+
({ type, include }) => globSync(include, { cwd: rootPath, ignore: entryPath }).map((path12) => ({
|
|
13999
14055
|
type,
|
|
14000
|
-
path:
|
|
14056
|
+
path: path12
|
|
14001
14057
|
}))
|
|
14002
14058
|
)
|
|
14003
14059
|
]
|
|
14004
14060
|
};
|
|
14005
14061
|
}
|
|
14006
|
-
async function getPreviewMiniflareOptions(
|
|
14062
|
+
async function getPreviewMiniflareOptions(resolvedPluginConfig, vitePreviewServer, inspectorPort) {
|
|
14007
14063
|
const resolvedViteConfig = vitePreviewServer.config;
|
|
14008
14064
|
const workers = (await Promise.all(
|
|
14009
|
-
|
|
14065
|
+
resolvedPluginConfig.workers.map(async (workerConfig, i) => {
|
|
14010
14066
|
const bindings = unstable_convertConfigBindingsToStartWorkerBindings(workerConfig);
|
|
14011
14067
|
const preExistingRemoteProxySessionData = workerConfig.configPath ? remoteProxySessionsDataMap.get(workerConfig.configPath) : void 0;
|
|
14012
|
-
const remoteProxySessionData =
|
|
14068
|
+
const remoteProxySessionData = resolvedPluginConfig.experimental.remoteBindings ? await experimental_maybeStartOrUpdateRemoteProxySession(
|
|
14013
14069
|
{
|
|
14014
14070
|
name: workerConfig.name,
|
|
14015
14071
|
bindings: bindings ?? {}
|
|
@@ -14027,14 +14083,14 @@ async function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, pers
|
|
|
14027
14083
|
void 0,
|
|
14028
14084
|
{
|
|
14029
14085
|
remoteProxyConnectionString: remoteProxySessionData?.session?.remoteProxyConnectionString,
|
|
14030
|
-
remoteBindingsEnabled
|
|
14086
|
+
remoteBindingsEnabled: resolvedPluginConfig.experimental.remoteBindings
|
|
14031
14087
|
}
|
|
14032
14088
|
);
|
|
14033
14089
|
const { externalWorkers } = miniflareWorkerOptions;
|
|
14034
14090
|
const { ratelimits, modulesRules, ...workerOptions } = miniflareWorkerOptions.workerOptions;
|
|
14035
14091
|
logUnknownTails(
|
|
14036
14092
|
workerOptions.tails,
|
|
14037
|
-
|
|
14093
|
+
resolvedPluginConfig.workers,
|
|
14038
14094
|
vitePreviewServer.config.logger.warn
|
|
14039
14095
|
);
|
|
14040
14096
|
return [
|
|
@@ -14068,7 +14124,7 @@ async function getPreviewMiniflareOptions(vitePreviewServer, workerConfigs, pers
|
|
|
14068
14124
|
},
|
|
14069
14125
|
defaultPersistRoot: getPersistenceRoot(
|
|
14070
14126
|
resolvedViteConfig.root,
|
|
14071
|
-
persistState
|
|
14127
|
+
resolvedPluginConfig.persistState
|
|
14072
14128
|
),
|
|
14073
14129
|
workers
|
|
14074
14130
|
};
|
|
@@ -14107,7 +14163,7 @@ function miniflareLogLevelFromViteLogLevel(level = "info") {
|
|
|
14107
14163
|
|
|
14108
14164
|
// src/plugin-config.ts
|
|
14109
14165
|
import assert9 from "node:assert";
|
|
14110
|
-
import * as
|
|
14166
|
+
import * as path10 from "node:path";
|
|
14111
14167
|
|
|
14112
14168
|
// ../workers-shared/utils/configuration/parseStaticRouting.ts
|
|
14113
14169
|
function parseStaticRouting(input) {
|
|
@@ -14190,8 +14246,8 @@ import * as vite5 from "vite";
|
|
|
14190
14246
|
|
|
14191
14247
|
// src/workers-configs.ts
|
|
14192
14248
|
import assert8 from "node:assert";
|
|
14193
|
-
import * as
|
|
14194
|
-
import * as
|
|
14249
|
+
import * as fs6 from "node:fs";
|
|
14250
|
+
import * as path9 from "node:path";
|
|
14195
14251
|
import { unstable_readConfig as unstable_readConfig2 } from "wrangler";
|
|
14196
14252
|
var nonApplicableWorkerConfigs = {
|
|
14197
14253
|
/**
|
|
@@ -14286,7 +14342,7 @@ function getWarningForWorkersConfigs(configs) {
|
|
|
14286
14342
|
const lines2 = [
|
|
14287
14343
|
`
|
|
14288
14344
|
|
|
14289
|
-
\x1B[43mWARNING\x1B[0m: your worker config${configs.entryWorker.config.configPath ? ` (at \`${
|
|
14345
|
+
\x1B[43mWARNING\x1B[0m: your worker config${configs.entryWorker.config.configPath ? ` (at \`${path9.relative("", configs.entryWorker.config.configPath)}\`)` : ""} contains the following configuration options which are ignored since they are not applicable when using Vite:`
|
|
14290
14346
|
];
|
|
14291
14347
|
nonApplicableLines.forEach((line) => lines2.push(line));
|
|
14292
14348
|
lines2.push("");
|
|
@@ -14300,7 +14356,7 @@ function getWarningForWorkersConfigs(configs) {
|
|
|
14300
14356
|
);
|
|
14301
14357
|
if (nonApplicableLines.length > 0) {
|
|
14302
14358
|
lines.push(
|
|
14303
|
-
` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${
|
|
14359
|
+
` - (${isEntryWorker ? "entry" : "auxiliary"}) worker${workerConfig.config.name ? ` "${workerConfig.config.name}"` : ""}${workerConfig.config.configPath ? ` (config at \`${path9.relative("", workerConfig.config.configPath)}\`)` : ""}`
|
|
14304
14360
|
);
|
|
14305
14361
|
nonApplicableLines.forEach((line) => lines.push(line));
|
|
14306
14362
|
}
|
|
@@ -14381,7 +14437,7 @@ function getWorkerConfig(configPath, env2, remoteBindingsEnabled, opts) {
|
|
|
14381
14437
|
if (!config.main) {
|
|
14382
14438
|
throw new Error(missingFieldErrorMessage(`'main'`, configPath, env2));
|
|
14383
14439
|
}
|
|
14384
|
-
const mainStat =
|
|
14440
|
+
const mainStat = fs6.statSync(config.main, { throwIfNoEntry: false });
|
|
14385
14441
|
if (!mainStat) {
|
|
14386
14442
|
throw new Error(
|
|
14387
14443
|
`The provided Wrangler config main field (${config.main}) doesn't point to an existing file`
|
|
@@ -14405,17 +14461,17 @@ function getWorkerConfig(configPath, env2, remoteBindingsEnabled, opts) {
|
|
|
14405
14461
|
}
|
|
14406
14462
|
function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliaryWorker = false) {
|
|
14407
14463
|
if (requestedConfigPath) {
|
|
14408
|
-
const configPath2 =
|
|
14464
|
+
const configPath2 = path9.resolve(root, requestedConfigPath);
|
|
14409
14465
|
const forAuxiliaryWorkerErrorMessage = isForAuxiliaryWorker ? " requested for one of your auxiliary workers" : "";
|
|
14410
14466
|
const errorMessagePrefix = `The provided configPath (${configPath2})${forAuxiliaryWorkerErrorMessage}`;
|
|
14411
|
-
const fileExtension =
|
|
14467
|
+
const fileExtension = path9.extname(configPath2).slice(1);
|
|
14412
14468
|
if (!allowedWranglerConfigExtensions.includes(fileExtension)) {
|
|
14413
14469
|
const foundExtensionMessage = !fileExtension ? "no extension found" : `"${fileExtension}" found`;
|
|
14414
14470
|
throw new Error(
|
|
14415
14471
|
`${errorMessagePrefix} doesn't point to a file with the correct file extension. It should point to a jsonc, json or toml file (${foundExtensionMessage} instead)`
|
|
14416
14472
|
);
|
|
14417
14473
|
}
|
|
14418
|
-
const mainStat =
|
|
14474
|
+
const mainStat = fs6.statSync(configPath2, { throwIfNoEntry: false });
|
|
14419
14475
|
if (!mainStat) {
|
|
14420
14476
|
throw new Error(
|
|
14421
14477
|
`${errorMessagePrefix} doesn't point to an existing file`
|
|
@@ -14442,8 +14498,8 @@ function getValidatedWranglerConfigPath(root, requestedConfigPath, isForAuxiliar
|
|
|
14442
14498
|
}
|
|
14443
14499
|
function findWranglerConfig(root) {
|
|
14444
14500
|
for (const extension of allowedWranglerConfigExtensions) {
|
|
14445
|
-
const configPath =
|
|
14446
|
-
if (
|
|
14501
|
+
const configPath = path9.join(root, `wrangler.${extension}`);
|
|
14502
|
+
if (fs6.existsSync(configPath)) {
|
|
14447
14503
|
return configPath;
|
|
14448
14504
|
}
|
|
14449
14505
|
}
|
|
@@ -14455,10 +14511,23 @@ function workerNameToEnvironmentName(workerName) {
|
|
|
14455
14511
|
return workerName.replaceAll("-", "_");
|
|
14456
14512
|
}
|
|
14457
14513
|
function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
14514
|
+
const shared = {
|
|
14515
|
+
persistState: pluginConfig.persistState ?? true,
|
|
14516
|
+
inspectorPort: pluginConfig.inspectorPort,
|
|
14517
|
+
experimental: pluginConfig.experimental ?? {}
|
|
14518
|
+
};
|
|
14519
|
+
const root = userConfig.root ? path10.resolve(userConfig.root) : process.cwd();
|
|
14520
|
+
if (viteEnv.isPreview) {
|
|
14521
|
+
return {
|
|
14522
|
+
...shared,
|
|
14523
|
+
type: "preview",
|
|
14524
|
+
workers: getWorkerConfigs(
|
|
14525
|
+
root,
|
|
14526
|
+
shared.experimental.remoteBindings ?? false
|
|
14527
|
+
)
|
|
14528
|
+
};
|
|
14529
|
+
}
|
|
14458
14530
|
const configPaths = /* @__PURE__ */ new Set();
|
|
14459
|
-
const persistState = pluginConfig.persistState ?? true;
|
|
14460
|
-
const experimental = pluginConfig.experimental ?? {};
|
|
14461
|
-
const root = userConfig.root ? path9.resolve(userConfig.root) : process.cwd();
|
|
14462
14531
|
const { CLOUDFLARE_ENV: cloudflareEnv } = vite5.loadEnv(
|
|
14463
14532
|
viteEnv.mode,
|
|
14464
14533
|
root,
|
|
@@ -14480,15 +14549,14 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14480
14549
|
);
|
|
14481
14550
|
if (entryWorkerResolvedConfig.type === "assets-only") {
|
|
14482
14551
|
return {
|
|
14552
|
+
...shared,
|
|
14483
14553
|
type: "assets-only",
|
|
14554
|
+
cloudflareEnv,
|
|
14484
14555
|
config: entryWorkerResolvedConfig.config,
|
|
14485
14556
|
configPaths,
|
|
14486
|
-
persistState,
|
|
14487
14557
|
rawConfigs: {
|
|
14488
14558
|
entryWorker: entryWorkerResolvedConfig
|
|
14489
|
-
}
|
|
14490
|
-
cloudflareEnv,
|
|
14491
|
-
experimental
|
|
14559
|
+
}
|
|
14492
14560
|
};
|
|
14493
14561
|
}
|
|
14494
14562
|
const entryWorkerConfig = entryWorkerResolvedConfig.config;
|
|
@@ -14532,20 +14600,31 @@ function resolvePluginConfig(pluginConfig, userConfig, viteEnv) {
|
|
|
14532
14600
|
workers[workerEnvironmentName] = workerConfig;
|
|
14533
14601
|
}
|
|
14534
14602
|
return {
|
|
14603
|
+
...shared,
|
|
14535
14604
|
type: "workers",
|
|
14605
|
+
cloudflareEnv,
|
|
14536
14606
|
configPaths,
|
|
14537
|
-
persistState,
|
|
14538
14607
|
workers,
|
|
14539
14608
|
entryWorkerEnvironmentName,
|
|
14540
14609
|
staticRouting,
|
|
14541
14610
|
rawConfigs: {
|
|
14542
14611
|
entryWorker: entryWorkerResolvedConfig,
|
|
14543
14612
|
auxiliaryWorkers: auxiliaryWorkersResolvedConfigs
|
|
14544
|
-
}
|
|
14545
|
-
cloudflareEnv,
|
|
14546
|
-
experimental
|
|
14613
|
+
}
|
|
14547
14614
|
};
|
|
14548
14615
|
}
|
|
14616
|
+
function assertIsNotPreview(resolvedPluginConfig) {
|
|
14617
|
+
assert9(
|
|
14618
|
+
resolvedPluginConfig.type !== "preview",
|
|
14619
|
+
`Expected "assets-only" or "workers" plugin config`
|
|
14620
|
+
);
|
|
14621
|
+
}
|
|
14622
|
+
function assertIsPreview(resolvedPluginConfig) {
|
|
14623
|
+
assert9(
|
|
14624
|
+
resolvedPluginConfig.type === "preview",
|
|
14625
|
+
`Expected "preview" plugin config`
|
|
14626
|
+
);
|
|
14627
|
+
}
|
|
14549
14628
|
|
|
14550
14629
|
// src/websockets.ts
|
|
14551
14630
|
import { createHeaders } from "@mjackson/node-fetch-server";
|
|
@@ -14649,14 +14728,14 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14649
14728
|
// This only applies to this plugin so is safe to use while other plugins migrate to the Environment API
|
|
14650
14729
|
sharedDuringBuild: true,
|
|
14651
14730
|
config(userConfig, env2) {
|
|
14652
|
-
if (env2.isPreview) {
|
|
14653
|
-
return { appType: "custom" };
|
|
14654
|
-
}
|
|
14655
14731
|
resolvedPluginConfig = resolvePluginConfig(
|
|
14656
14732
|
pluginConfig,
|
|
14657
14733
|
userConfig,
|
|
14658
14734
|
env2
|
|
14659
14735
|
);
|
|
14736
|
+
if (resolvedPluginConfig.type === "preview") {
|
|
14737
|
+
return { appType: "custom" };
|
|
14738
|
+
}
|
|
14660
14739
|
if (!workersConfigsWarningShown) {
|
|
14661
14740
|
workersConfigsWarningShown = true;
|
|
14662
14741
|
const workersConfigsWarning = getWarningForWorkersConfigs(
|
|
@@ -14713,7 +14792,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14713
14792
|
},
|
|
14714
14793
|
configResolved(config) {
|
|
14715
14794
|
resolvedViteConfig = config;
|
|
14716
|
-
if (resolvedPluginConfig
|
|
14795
|
+
if (resolvedPluginConfig.type === "workers") {
|
|
14717
14796
|
validateWorkerEnvironmentsResolvedConfigs(
|
|
14718
14797
|
resolvedPluginConfig,
|
|
14719
14798
|
resolvedViteConfig
|
|
@@ -14721,6 +14800,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14721
14800
|
}
|
|
14722
14801
|
},
|
|
14723
14802
|
generateBundle(_, bundle) {
|
|
14803
|
+
assertIsNotPreview(resolvedPluginConfig);
|
|
14724
14804
|
let config;
|
|
14725
14805
|
if (resolvedPluginConfig.type === "workers") {
|
|
14726
14806
|
const workerConfig = resolvedPluginConfig.workers[this.environment.name];
|
|
@@ -14745,9 +14825,9 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14745
14825
|
);
|
|
14746
14826
|
workerConfig.assets = {
|
|
14747
14827
|
...workerConfig.assets,
|
|
14748
|
-
directory:
|
|
14749
|
-
|
|
14750
|
-
|
|
14828
|
+
directory: path11.relative(
|
|
14829
|
+
path11.resolve(resolvedViteConfig.root, workerOutputDirectory),
|
|
14830
|
+
path11.resolve(resolvedViteConfig.root, clientOutputDirectory)
|
|
14751
14831
|
)
|
|
14752
14832
|
};
|
|
14753
14833
|
} else {
|
|
@@ -14795,12 +14875,14 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14795
14875
|
});
|
|
14796
14876
|
},
|
|
14797
14877
|
writeBundle() {
|
|
14798
|
-
|
|
14878
|
+
assertIsNotPreview(resolvedPluginConfig);
|
|
14879
|
+
if (this.environment.name === (resolvedPluginConfig.type === "workers" ? resolvedPluginConfig.entryWorkerEnvironmentName : "client")) {
|
|
14799
14880
|
writeDeployConfig(resolvedPluginConfig, resolvedViteConfig);
|
|
14800
14881
|
}
|
|
14801
14882
|
},
|
|
14802
14883
|
hotUpdate(options) {
|
|
14803
|
-
|
|
14884
|
+
assertIsNotPreview(resolvedPluginConfig);
|
|
14885
|
+
const changedFilePath = path11.resolve(options.file);
|
|
14804
14886
|
if (resolvedPluginConfig.configPaths.has(changedFilePath) || hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) || hasAssetsConfigChanged(
|
|
14805
14887
|
resolvedPluginConfig,
|
|
14806
14888
|
resolvedViteConfig,
|
|
@@ -14811,9 +14893,11 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14811
14893
|
}
|
|
14812
14894
|
},
|
|
14813
14895
|
async configureServer(viteDevServer) {
|
|
14896
|
+
assertIsNotPreview(resolvedPluginConfig);
|
|
14814
14897
|
const inputInspectorPort = await getInputInspectorPortOption(
|
|
14815
|
-
|
|
14816
|
-
viteDevServer
|
|
14898
|
+
resolvedPluginConfig,
|
|
14899
|
+
viteDevServer,
|
|
14900
|
+
miniflare
|
|
14817
14901
|
);
|
|
14818
14902
|
const miniflareDevOptions = await getDevMiniflareOptions(
|
|
14819
14903
|
resolvedPluginConfig,
|
|
@@ -14825,9 +14909,9 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14825
14909
|
} else {
|
|
14826
14910
|
await miniflare.setOptions(miniflareDevOptions);
|
|
14827
14911
|
}
|
|
14828
|
-
await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
|
|
14829
14912
|
let preMiddleware;
|
|
14830
14913
|
if (resolvedPluginConfig.type === "workers") {
|
|
14914
|
+
await initRunners(resolvedPluginConfig, viteDevServer, miniflare);
|
|
14831
14915
|
const entryWorkerConfig = getWorkerConfig2(
|
|
14832
14916
|
resolvedPluginConfig.entryWorkerEnvironmentName
|
|
14833
14917
|
);
|
|
@@ -14901,30 +14985,26 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
14901
14985
|
};
|
|
14902
14986
|
},
|
|
14903
14987
|
async configurePreviewServer(vitePreviewServer) {
|
|
14904
|
-
|
|
14905
|
-
vitePreviewServer.config.root,
|
|
14906
|
-
pluginConfig.experimental?.remoteBindings ?? false
|
|
14907
|
-
);
|
|
14988
|
+
assertIsPreview(resolvedPluginConfig);
|
|
14908
14989
|
const inputInspectorPort = await getInputInspectorPortOption(
|
|
14909
|
-
|
|
14990
|
+
resolvedPluginConfig,
|
|
14910
14991
|
vitePreviewServer
|
|
14911
14992
|
);
|
|
14912
|
-
|
|
14993
|
+
miniflare = new Miniflare(
|
|
14913
14994
|
await getPreviewMiniflareOptions(
|
|
14995
|
+
resolvedPluginConfig,
|
|
14914
14996
|
vitePreviewServer,
|
|
14915
|
-
workerConfigs,
|
|
14916
|
-
pluginConfig.persistState ?? true,
|
|
14917
|
-
!!pluginConfig.experimental?.remoteBindings,
|
|
14918
14997
|
inputInspectorPort
|
|
14919
14998
|
)
|
|
14920
14999
|
);
|
|
14921
|
-
handleWebSocket(
|
|
14922
|
-
|
|
14923
|
-
|
|
14924
|
-
);
|
|
15000
|
+
handleWebSocket(vitePreviewServer.httpServer, () => {
|
|
15001
|
+
assert11(miniflare, `Miniflare not defined`);
|
|
15002
|
+
return miniflare.dispatchFetch;
|
|
15003
|
+
});
|
|
14925
15004
|
vitePreviewServer.middlewares.use(
|
|
14926
15005
|
createRequestHandler((request) => {
|
|
14927
|
-
|
|
15006
|
+
assert11(miniflare, `Miniflare not defined`);
|
|
15007
|
+
return miniflare.dispatchFetch(request, { redirect: "manual" });
|
|
14928
15008
|
})
|
|
14929
15009
|
);
|
|
14930
15010
|
}
|
|
@@ -15016,13 +15096,13 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
15016
15096
|
}
|
|
15017
15097
|
const referenceId = this.emitFile({
|
|
15018
15098
|
type: "asset",
|
|
15019
|
-
name:
|
|
15099
|
+
name: path11.basename(modulePath),
|
|
15020
15100
|
originalFileName: modulePath,
|
|
15021
15101
|
source
|
|
15022
15102
|
});
|
|
15023
15103
|
const emittedFileName = this.getFileName(referenceId);
|
|
15024
15104
|
const relativePath = vite6.normalizePath(
|
|
15025
|
-
|
|
15105
|
+
path11.relative(path11.dirname(chunk.fileName), emittedFileName)
|
|
15026
15106
|
);
|
|
15027
15107
|
const importPath = relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
15028
15108
|
magicString.update(
|
|
@@ -15042,9 +15122,6 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
15042
15122
|
// Plugin that can provide Node.js compatibility support for Vite Environments that are hosted in Cloudflare Workers.
|
|
15043
15123
|
{
|
|
15044
15124
|
name: "vite-plugin-cloudflare:nodejs-compat",
|
|
15045
|
-
apply(_config, env2) {
|
|
15046
|
-
return !env2.isPreview;
|
|
15047
|
-
},
|
|
15048
15125
|
configEnvironment(name) {
|
|
15049
15126
|
if (isNodeCompat(getWorkerConfig2(name))) {
|
|
15050
15127
|
return {
|
|
@@ -15141,10 +15218,7 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
15141
15218
|
// Plugin that handles Node.js Async Local Storage (ALS) compatibility support for Vite Environments that are hosted in Cloudflare Workers.
|
|
15142
15219
|
{
|
|
15143
15220
|
name: "vite-plugin-cloudflare:nodejs-als",
|
|
15144
|
-
|
|
15145
|
-
return !env2.isPreview;
|
|
15146
|
-
},
|
|
15147
|
-
configEnvironment(name, config) {
|
|
15221
|
+
configEnvironment(name) {
|
|
15148
15222
|
if (isNodeAls(getWorkerConfig2(name))) {
|
|
15149
15223
|
return {
|
|
15150
15224
|
resolve: {
|
|
@@ -15164,51 +15238,54 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
15164
15238
|
// the preview middleware here can take precedence
|
|
15165
15239
|
enforce: "pre",
|
|
15166
15240
|
configureServer(viteDevServer) {
|
|
15241
|
+
assertIsNotPreview(resolvedPluginConfig);
|
|
15167
15242
|
if (resolvedPluginConfig.type === "workers" && pluginConfig.inspectorPort !== false) {
|
|
15168
15243
|
addDebugToVitePrintUrls(viteDevServer);
|
|
15169
15244
|
}
|
|
15170
|
-
const workerNames = resolvedPluginConfig.type === "
|
|
15245
|
+
const workerNames = resolvedPluginConfig.type === "workers" ? Object.values(resolvedPluginConfig.workers).map(
|
|
15171
15246
|
(worker) => worker.name
|
|
15172
|
-
);
|
|
15173
|
-
viteDevServer.middlewares.use(async (
|
|
15174
|
-
const resolvedInspectorPort = await getResolvedInspectorPort(
|
|
15175
|
-
|
|
15247
|
+
) : [];
|
|
15248
|
+
viteDevServer.middlewares.use(DEBUG_PATH, async (_, res, next) => {
|
|
15249
|
+
const resolvedInspectorPort = await getResolvedInspectorPort(
|
|
15250
|
+
resolvedPluginConfig,
|
|
15251
|
+
miniflare
|
|
15252
|
+
);
|
|
15253
|
+
if (resolvedInspectorPort) {
|
|
15176
15254
|
const html = getDebugPathHtml(workerNames, resolvedInspectorPort);
|
|
15177
15255
|
res.setHeader("Content-Type", "text/html");
|
|
15178
|
-
|
|
15256
|
+
res.end(html);
|
|
15257
|
+
} else {
|
|
15258
|
+
next();
|
|
15179
15259
|
}
|
|
15180
|
-
next();
|
|
15181
15260
|
});
|
|
15182
15261
|
},
|
|
15183
15262
|
async configurePreviewServer(vitePreviewServer) {
|
|
15184
|
-
|
|
15185
|
-
|
|
15186
|
-
pluginConfig.experimental?.remoteBindings ?? false
|
|
15187
|
-
);
|
|
15188
|
-
if (workerConfigs.length >= 1 && pluginConfig.inspectorPort !== false) {
|
|
15263
|
+
assertIsPreview(resolvedPluginConfig);
|
|
15264
|
+
if (resolvedPluginConfig.workers.length >= 1 && resolvedPluginConfig.inspectorPort !== false) {
|
|
15189
15265
|
addDebugToVitePrintUrls(vitePreviewServer);
|
|
15190
15266
|
}
|
|
15191
|
-
const workerNames =
|
|
15267
|
+
const workerNames = resolvedPluginConfig.workers.map((worker) => {
|
|
15192
15268
|
assert11(worker.name, "Expected the Worker to have a name");
|
|
15193
15269
|
return worker.name;
|
|
15194
15270
|
});
|
|
15195
|
-
vitePreviewServer.middlewares.use(async (
|
|
15196
|
-
const resolvedInspectorPort = await getResolvedInspectorPort(
|
|
15197
|
-
|
|
15271
|
+
vitePreviewServer.middlewares.use(DEBUG_PATH, async (_, res, next) => {
|
|
15272
|
+
const resolvedInspectorPort = await getResolvedInspectorPort(
|
|
15273
|
+
resolvedPluginConfig,
|
|
15274
|
+
miniflare
|
|
15275
|
+
);
|
|
15276
|
+
if (resolvedInspectorPort) {
|
|
15198
15277
|
const html = getDebugPathHtml(workerNames, resolvedInspectorPort);
|
|
15199
15278
|
res.setHeader("Content-Type", "text/html");
|
|
15200
|
-
|
|
15279
|
+
res.end(html);
|
|
15280
|
+
} else {
|
|
15281
|
+
next();
|
|
15201
15282
|
}
|
|
15202
|
-
next();
|
|
15203
15283
|
});
|
|
15204
15284
|
}
|
|
15205
15285
|
},
|
|
15206
15286
|
// Plugin to warn if Node.js APIs are being used without nodejs_compat turned on
|
|
15207
15287
|
{
|
|
15208
15288
|
name: "vite-plugin-cloudflare:nodejs-compat-warnings",
|
|
15209
|
-
apply(_config, env2) {
|
|
15210
|
-
return !env2.isPreview;
|
|
15211
|
-
},
|
|
15212
15289
|
// We must ensure that the `resolveId` hook runs before the built-in ones.
|
|
15213
15290
|
// Otherwise we never see the Node.js built-in imports since they get handled by default Vite behavior.
|
|
15214
15291
|
enforce: "pre",
|
|
@@ -15224,13 +15301,13 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
15224
15301
|
setup(build) {
|
|
15225
15302
|
build.onResolve(
|
|
15226
15303
|
{ filter: NODEJS_MODULES_RE },
|
|
15227
|
-
({ path:
|
|
15228
|
-
if (isNodeAls(workerConfig) && isNodeAlsModule(
|
|
15304
|
+
({ path: path12, importer }) => {
|
|
15305
|
+
if (isNodeAls(workerConfig) && isNodeAlsModule(path12)) {
|
|
15229
15306
|
return;
|
|
15230
15307
|
}
|
|
15231
15308
|
const nodeJsCompatWarnings = nodeJsCompatWarningsMap.get(workerConfig);
|
|
15232
|
-
nodeJsCompatWarnings?.registerImport(
|
|
15233
|
-
return { path:
|
|
15309
|
+
nodeJsCompatWarnings?.registerImport(path12, importer);
|
|
15310
|
+
return { path: path12, external: true };
|
|
15234
15311
|
}
|
|
15235
15312
|
);
|
|
15236
15313
|
}
|
|
@@ -15273,59 +15350,9 @@ function cloudflare2(pluginConfig = {}) {
|
|
|
15273
15350
|
}
|
|
15274
15351
|
];
|
|
15275
15352
|
function getWorkerConfig2(environmentName) {
|
|
15276
|
-
|
|
15277
|
-
return resolvedPluginConfig.type !== "assets-only" ? resolvedPluginConfig.workers[environmentName] : void 0;
|
|
15353
|
+
return resolvedPluginConfig.type === "workers" ? resolvedPluginConfig.workers[environmentName] : void 0;
|
|
15278
15354
|
}
|
|
15279
15355
|
}
|
|
15280
|
-
async function getInputInspectorPortOption(pluginConfig, viteServer) {
|
|
15281
|
-
if (pluginConfig.inspectorPort === void 0 || pluginConfig.inspectorPort === 0) {
|
|
15282
|
-
const resolvedInspectorPort = await getResolvedInspectorPort(pluginConfig);
|
|
15283
|
-
if (resolvedInspectorPort !== null) {
|
|
15284
|
-
return resolvedInspectorPort;
|
|
15285
|
-
}
|
|
15286
|
-
}
|
|
15287
|
-
const inputInspectorPort = pluginConfig.inspectorPort ?? await getFirstAvailablePort(DEFAULT_INSPECTOR_PORT);
|
|
15288
|
-
if (pluginConfig.inspectorPort === void 0 && inputInspectorPort !== DEFAULT_INSPECTOR_PORT) {
|
|
15289
|
-
viteServer.config.logger.warn(
|
|
15290
|
-
colors4.dim(
|
|
15291
|
-
`Default inspector port ${DEFAULT_INSPECTOR_PORT} not available, using ${inputInspectorPort} instead
|
|
15292
|
-
`
|
|
15293
|
-
)
|
|
15294
|
-
);
|
|
15295
|
-
}
|
|
15296
|
-
return inputInspectorPort;
|
|
15297
|
-
}
|
|
15298
|
-
async function getResolvedInspectorPort(pluginConfig) {
|
|
15299
|
-
if (miniflare && pluginConfig.inspectorPort !== false) {
|
|
15300
|
-
const miniflareInspectorUrl = await miniflare.getInspectorURL();
|
|
15301
|
-
return Number.parseInt(miniflareInspectorUrl.port);
|
|
15302
|
-
}
|
|
15303
|
-
return null;
|
|
15304
|
-
}
|
|
15305
|
-
function getDotDevDotVarsContent(configPath, cloudflareEnv) {
|
|
15306
|
-
const configDir = path10.dirname(configPath);
|
|
15307
|
-
const defaultDotDevDotVarsPath = `${configDir}/.dev.vars`;
|
|
15308
|
-
const inputDotDevDotVarsPath = `${defaultDotDevDotVarsPath}${cloudflareEnv ? `.${cloudflareEnv}` : ""}`;
|
|
15309
|
-
const targetPath = fs6.existsSync(inputDotDevDotVarsPath) ? inputDotDevDotVarsPath : fs6.existsSync(defaultDotDevDotVarsPath) ? defaultDotDevDotVarsPath : null;
|
|
15310
|
-
if (targetPath) {
|
|
15311
|
-
const dotDevDotVarsContent = fs6.readFileSync(targetPath);
|
|
15312
|
-
return dotDevDotVarsContent;
|
|
15313
|
-
}
|
|
15314
|
-
return null;
|
|
15315
|
-
}
|
|
15316
|
-
function hasDotDevDotVarsFileChanged(resolvedPluginConfig, changedFilePath) {
|
|
15317
|
-
return [...resolvedPluginConfig.configPaths].some((configPath) => {
|
|
15318
|
-
const dotDevDotVars = path10.join(path10.dirname(configPath), ".dev.vars");
|
|
15319
|
-
if (dotDevDotVars === changedFilePath) {
|
|
15320
|
-
return true;
|
|
15321
|
-
}
|
|
15322
|
-
if (resolvedPluginConfig.cloudflareEnv) {
|
|
15323
|
-
const dotDevDotVarsForEnv = `${dotDevDotVars}.${resolvedPluginConfig.cloudflareEnv}`;
|
|
15324
|
-
return dotDevDotVarsForEnv === changedFilePath;
|
|
15325
|
-
}
|
|
15326
|
-
return false;
|
|
15327
|
-
});
|
|
15328
|
-
}
|
|
15329
15356
|
export {
|
|
15330
15357
|
cloudflare2 as cloudflare
|
|
15331
15358
|
};
|