vite 5.4.6 → 5.4.18
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/LICENSE.md +1 -1
- package/README.md +4 -4
- package/dist/client/client.mjs +9 -5
- package/dist/node/chunks/{dep-CxMW8ntG.js → dep-75Pw0qnz.js} +1 -1
- package/dist/node/chunks/{dep-DyBnyoVI.js → dep-DbT5NFX0.js} +379 -104
- package/dist/node/chunks/{dep-Due-rusG.js → dep-nOVVHa2_.js} +267 -106
- package/dist/node/cli.js +7 -6
- package/dist/node/constants.js +2 -1
- package/dist/node/index.d.ts +47 -0
- package/dist/node/index.js +4 -3
- package/index.cjs +1 -1
- package/index.d.cts +1 -1
- package/package.json +4 -4
@@ -6,10 +6,11 @@ import { fileURLToPath, URL as URL$3, parse as parse$h, pathToFileURL } from 'no
|
|
6
6
|
import { promisify as promisify$4, format as format$2, inspect } from 'node:util';
|
7
7
|
import { performance as performance$1 } from 'node:perf_hooks';
|
8
8
|
import { createRequire as createRequire$1, builtinModules } from 'node:module';
|
9
|
+
import crypto$2, { createHash as createHash$2 } from 'node:crypto';
|
9
10
|
import require$$0$3 from 'tty';
|
10
11
|
import require$$0$4, { win32, posix, isAbsolute, resolve as resolve$3, relative as relative$1, basename as basename$1, extname, dirname as dirname$1, join as join$1, sep as sep$1, normalize as normalize$1 } from 'path';
|
11
12
|
import esbuild, { transform as transform$1, formatMessages, build as build$3 } from 'esbuild';
|
12
|
-
import { CLIENT_ENTRY, OPTIMIZABLE_ENTRY_RE, wildcardHosts, loopbackHosts, FS_PREFIX, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, DEFAULT_ASSETS_INLINE_LIMIT, CSS_LANGS_RE, ESBUILD_MODULES_TARGET, SPECIAL_QUERY_RE, ENV_ENTRY, DEP_VERSION_RE, DEFAULT_MAIN_FIELDS, DEFAULT_EXTENSIONS, KNOWN_ASSET_TYPES, JS_TYPES_RE, METADATA_FILENAME, VITE_PACKAGE_DIR, DEFAULT_DEV_PORT, CLIENT_DIR, VERSION, DEFAULT_PREVIEW_PORT, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES } from '../constants.js';
|
13
|
+
import { CLIENT_ENTRY, OPTIMIZABLE_ENTRY_RE, wildcardHosts, loopbackHosts, FS_PREFIX, CLIENT_PUBLIC_PATH, ENV_PUBLIC_PATH, DEFAULT_ASSETS_INLINE_LIMIT, CSS_LANGS_RE, ESBUILD_MODULES_TARGET, SPECIAL_QUERY_RE, ENV_ENTRY, DEP_VERSION_RE, DEFAULT_MAIN_FIELDS, DEFAULT_EXTENSIONS, KNOWN_ASSET_TYPES, JS_TYPES_RE, METADATA_FILENAME, VITE_PACKAGE_DIR, defaultAllowedOrigins, DEFAULT_DEV_PORT, CLIENT_DIR, VERSION, DEFAULT_PREVIEW_PORT, DEFAULT_ASSETS_RE, DEFAULT_CONFIG_FILES } from '../constants.js';
|
13
14
|
import * as require$$0$2 from 'fs';
|
14
15
|
import require$$0__default, { lstatSync, readdir as readdir$4, readdirSync, readlinkSync, realpathSync as realpathSync$1, existsSync, readFileSync, statSync as statSync$1 } from 'fs';
|
15
16
|
import { EventEmitter as EventEmitter$4 } from 'node:events';
|
@@ -27,7 +28,6 @@ import require$$0$6 from 'stream';
|
|
27
28
|
import require$$2 from 'os';
|
28
29
|
import require$$2$1 from 'child_process';
|
29
30
|
import os$5 from 'node:os';
|
30
|
-
import { createHash as createHash$2 } from 'node:crypto';
|
31
31
|
import { promises } from 'node:dns';
|
32
32
|
import require$$3$1 from 'crypto';
|
33
33
|
import require$$0$8, { createRequire as createRequire$2 } from 'module';
|
@@ -42,6 +42,7 @@ import zlib$1 from 'zlib';
|
|
42
42
|
import require$$0$a from 'buffer';
|
43
43
|
import require$$1$1 from 'https';
|
44
44
|
import require$$4$2 from 'tls';
|
45
|
+
import net$1 from 'node:net';
|
45
46
|
import require$$4$3 from 'assert';
|
46
47
|
import { gzip } from 'node:zlib';
|
47
48
|
|
@@ -16864,10 +16865,10 @@ function removeImportQuery(url) {
|
|
16864
16865
|
function removeDirectQuery(url) {
|
16865
16866
|
return url.replace(directRequestRE$1, "$1").replace(trailingSeparatorRE, "");
|
16866
16867
|
}
|
16867
|
-
const urlRE = /(\?|&)url(?:&|$)/;
|
16868
|
-
const rawRE = /(\?|&)raw(?:&|$)/;
|
16868
|
+
const urlRE$1 = /(\?|&)url(?:&|$)/;
|
16869
|
+
const rawRE$1 = /(\?|&)raw(?:&|$)/;
|
16869
16870
|
function removeUrlQuery(url) {
|
16870
|
-
return url.replace(urlRE, "$1").replace(trailingSeparatorRE, "");
|
16871
|
+
return url.replace(urlRE$1, "$1").replace(trailingSeparatorRE, "");
|
16871
16872
|
}
|
16872
16873
|
const replacePercentageRE = /%/g;
|
16873
16874
|
function injectQuery(url, queryToInject) {
|
@@ -18221,13 +18222,35 @@ function isGlobMatch(filename, dir, patterns, allowJs) {
|
|
18221
18222
|
// filename must end with part of pattern that comes after last wildcard
|
18222
18223
|
let lastWildcardIndex = pattern.length;
|
18223
18224
|
let hasWildcard = false;
|
18225
|
+
let hasExtension = false;
|
18226
|
+
let hasSlash = false;
|
18227
|
+
let lastSlashIndex = -1;
|
18224
18228
|
for (let i = pattern.length - 1; i > -1; i--) {
|
18225
|
-
|
18226
|
-
|
18227
|
-
|
18229
|
+
const c = pattern[i];
|
18230
|
+
if (!hasWildcard) {
|
18231
|
+
if (c === '*' || c === '?') {
|
18232
|
+
lastWildcardIndex = i;
|
18233
|
+
hasWildcard = true;
|
18234
|
+
}
|
18235
|
+
}
|
18236
|
+
if (!hasSlash) {
|
18237
|
+
if (c === '.') {
|
18238
|
+
hasExtension = true;
|
18239
|
+
} else if (c === '/') {
|
18240
|
+
lastSlashIndex = i;
|
18241
|
+
hasSlash = true;
|
18242
|
+
}
|
18243
|
+
}
|
18244
|
+
if (hasWildcard && hasSlash) {
|
18228
18245
|
break;
|
18229
18246
|
}
|
18230
18247
|
}
|
18248
|
+
if (!hasExtension && (!hasWildcard || lastWildcardIndex < lastSlashIndex)) {
|
18249
|
+
// add implicit glob
|
18250
|
+
pattern += `${pattern.endsWith('/') ? '' : '/'}${GLOB_ALL_PATTERN}`;
|
18251
|
+
lastWildcardIndex = pattern.length - 1;
|
18252
|
+
hasWildcard = true;
|
18253
|
+
}
|
18231
18254
|
|
18232
18255
|
// if pattern does not end with wildcard, filename must end with pattern after last wildcard
|
18233
18256
|
if (
|
@@ -18265,11 +18288,18 @@ function isGlobMatch(filename, dir, patterns, allowJs) {
|
|
18265
18288
|
return false;
|
18266
18289
|
}
|
18267
18290
|
|
18268
|
-
// if no wildcard in pattern, filename must be equal to resolved pattern
|
18269
18291
|
if (!hasWildcard) {
|
18292
|
+
// no wildcard in pattern, filename must be equal to resolved pattern
|
18270
18293
|
return filename === resolvedPattern;
|
18294
|
+
} else if (
|
18295
|
+
firstWildcardIndex + GLOB_ALL_PATTERN.length ===
|
18296
|
+
resolvedPattern.length - (pattern.length - 1 - lastWildcardIndex) &&
|
18297
|
+
resolvedPattern.slice(firstWildcardIndex, firstWildcardIndex + GLOB_ALL_PATTERN.length) ===
|
18298
|
+
GLOB_ALL_PATTERN
|
18299
|
+
) {
|
18300
|
+
// singular glob-all pattern and we already validated prefix and suffix matches
|
18301
|
+
return true;
|
18271
18302
|
}
|
18272
|
-
|
18273
18303
|
// complex pattern, use regex to check it
|
18274
18304
|
if (PATTERN_REGEX_CACHE.has(resolvedPattern)) {
|
18275
18305
|
return PATTERN_REGEX_CACHE.get(resolvedPattern).test(filename);
|
@@ -20272,7 +20302,7 @@ function assetPlugin(config) {
|
|
20272
20302
|
moduleGraph = server.moduleGraph;
|
20273
20303
|
},
|
20274
20304
|
resolveId(id) {
|
20275
|
-
if (!config.assetsInclude(cleanUrl(id)) && !urlRE.test(id)) {
|
20305
|
+
if (!config.assetsInclude(cleanUrl(id)) && !urlRE$1.test(id)) {
|
20276
20306
|
return;
|
20277
20307
|
}
|
20278
20308
|
const publicFile = checkPublicFile(id, config);
|
@@ -20284,14 +20314,14 @@ function assetPlugin(config) {
|
|
20284
20314
|
if (id[0] === "\0") {
|
20285
20315
|
return;
|
20286
20316
|
}
|
20287
|
-
if (rawRE.test(id)) {
|
20317
|
+
if (rawRE$1.test(id)) {
|
20288
20318
|
const file = checkPublicFile(id, config) || cleanUrl(id);
|
20289
20319
|
this.addWatchFile(file);
|
20290
20320
|
return `export default ${JSON.stringify(
|
20291
20321
|
await fsp.readFile(file, "utf-8")
|
20292
20322
|
)}`;
|
20293
20323
|
}
|
20294
|
-
if (!urlRE.test(id) && !config.assetsInclude(cleanUrl(id))) {
|
20324
|
+
if (!urlRE$1.test(id) && !config.assetsInclude(cleanUrl(id))) {
|
20295
20325
|
return;
|
20296
20326
|
}
|
20297
20327
|
id = removeUrlQuery(id);
|
@@ -20605,7 +20635,7 @@ function dataURIPlugin() {
|
|
20605
20635
|
resolved = /* @__PURE__ */ new Map();
|
20606
20636
|
},
|
20607
20637
|
resolveId(id) {
|
20608
|
-
if (!
|
20638
|
+
if (!id.trimStart().startsWith("data:")) {
|
20609
20639
|
return;
|
20610
20640
|
}
|
20611
20641
|
const uri = new URL$3(id);
|
@@ -36032,7 +36062,7 @@ const directRequestRE = /[?&]direct\b/;
|
|
36032
36062
|
const htmlProxyRE = /[?&]html-proxy\b/;
|
36033
36063
|
const htmlProxyIndexRE = /&index=(\d+)/;
|
36034
36064
|
const commonjsProxyRE = /\?commonjs-proxy/;
|
36035
|
-
const inlineRE$
|
36065
|
+
const inlineRE$2 = /[?&]inline\b/;
|
36036
36066
|
const inlineCSSRE = /[?&]inline-css\b/;
|
36037
36067
|
const styleAttrRE = /[?&]style-attr\b/;
|
36038
36068
|
const functionCallRE = /^[A-Z_][\w-]*\(/i;
|
@@ -36081,7 +36111,7 @@ function cssPlugin(config) {
|
|
36081
36111
|
},
|
36082
36112
|
async load(id) {
|
36083
36113
|
if (!isCSSRequest(id)) return;
|
36084
|
-
if (urlRE.test(id)) {
|
36114
|
+
if (urlRE$1.test(id)) {
|
36085
36115
|
if (isModuleCSSRequest(id)) {
|
36086
36116
|
throw new Error(
|
36087
36117
|
`?url is not supported with CSS modules. (tried to import ${JSON.stringify(
|
@@ -36215,7 +36245,7 @@ function cssPostPlugin(config) {
|
|
36215
36245
|
);
|
36216
36246
|
return `export default ''`;
|
36217
36247
|
}
|
36218
|
-
const inlined = inlineRE$
|
36248
|
+
const inlined = inlineRE$2.test(id);
|
36219
36249
|
const modules = cssModulesCache.get(config).get(id);
|
36220
36250
|
const modulesCode = modules && !inlined && dataToEsm(modules, { namedExports: true, preferConst: true });
|
36221
36251
|
if (config.command === "serve") {
|
@@ -36564,6 +36594,14 @@ function cssPostPlugin(config) {
|
|
36564
36594
|
delete bundle[`${fileName}.map`];
|
36565
36595
|
});
|
36566
36596
|
}
|
36597
|
+
const cssAssets = Object.values(bundle).filter(
|
36598
|
+
(asset) => asset.type === "asset" && asset.fileName.endsWith(".css")
|
36599
|
+
);
|
36600
|
+
for (const cssAsset of cssAssets) {
|
36601
|
+
if (typeof cssAsset.source === "string") {
|
36602
|
+
cssAsset.source = cssAsset.source.replace(viteHashUpdateMarkerRE, "");
|
36603
|
+
}
|
36604
|
+
}
|
36567
36605
|
}
|
36568
36606
|
};
|
36569
36607
|
}
|
@@ -36582,7 +36620,7 @@ function cssAnalysisPlugin(config) {
|
|
36582
36620
|
const { moduleGraph } = server;
|
36583
36621
|
const thisModule = moduleGraph.getModuleById(id);
|
36584
36622
|
if (thisModule) {
|
36585
|
-
const isSelfAccepting = !cssModulesCache.get(config)?.get(id) && !inlineRE$
|
36623
|
+
const isSelfAccepting = !cssModulesCache.get(config)?.get(id) && !inlineRE$2.test(id) && !htmlProxyRE.test(id);
|
36586
36624
|
const pluginImports = this._addedImports;
|
36587
36625
|
if (pluginImports) {
|
36588
36626
|
const depModules = /* @__PURE__ */ new Set();
|
@@ -36953,8 +36991,8 @@ function createCachedImport(imp) {
|
|
36953
36991
|
return cached;
|
36954
36992
|
};
|
36955
36993
|
}
|
36956
|
-
const importPostcssImport = createCachedImport(() => import('./dep-
|
36957
|
-
const importPostcssModules = createCachedImport(() => import('./dep-
|
36994
|
+
const importPostcssImport = createCachedImport(() => import('./dep-75Pw0qnz.js').then(function (n) { return n.i; }));
|
36995
|
+
const importPostcssModules = createCachedImport(() => import('./dep-nOVVHa2_.js').then(function (n) { return n.i; }));
|
36958
36996
|
const importPostcss = createCachedImport(() => import('postcss'));
|
36959
36997
|
const preprocessorWorkerControllerCache = /* @__PURE__ */ new WeakMap();
|
36960
36998
|
let alwaysFakeWorkerWorkerControllerCache;
|
@@ -36992,6 +37030,8 @@ function combineSourcemapsIfExists(filename, map1, map2) {
|
|
36992
37030
|
map2
|
36993
37031
|
]) : map1;
|
36994
37032
|
}
|
37033
|
+
const viteHashUpdateMarker = "/*$vite$:1*/";
|
37034
|
+
const viteHashUpdateMarkerRE = /\/\*\$vite\$:\d+\*\//;
|
36995
37035
|
async function finalizeCss(css, minify, config) {
|
36996
37036
|
if (css.includes("@import") || css.includes("@charset")) {
|
36997
37037
|
css = await hoistAtRules(css);
|
@@ -36999,6 +37039,7 @@ async function finalizeCss(css, minify, config) {
|
|
36999
37039
|
if (config.build.cssMinify) {
|
37000
37040
|
css = await minifyCSS(css, config, false);
|
37001
37041
|
}
|
37042
|
+
css += viteHashUpdateMarker;
|
37002
37043
|
return css;
|
37003
37044
|
}
|
37004
37045
|
async function resolvePostcssConfig(config) {
|
@@ -37416,7 +37457,7 @@ const makeModernScssWorker = (resolvers, alias, maxWorkers) => {
|
|
37416
37457
|
fileURLToPath2(canonicalUrl),
|
37417
37458
|
options.filename
|
37418
37459
|
);
|
37419
|
-
return { contents, syntax };
|
37460
|
+
return { contents, syntax, sourceMapUrl: canonicalUrl };
|
37420
37461
|
}
|
37421
37462
|
};
|
37422
37463
|
sassOptions.importers = [
|
@@ -37446,11 +37487,12 @@ const makeModernScssWorker = (resolvers, alias, maxWorkers) => {
|
|
37446
37487
|
return worker;
|
37447
37488
|
};
|
37448
37489
|
const makeModernCompilerScssWorker = (resolvers, alias, _maxWorkers) => {
|
37449
|
-
let
|
37490
|
+
let compilerPromise;
|
37450
37491
|
const worker = {
|
37451
37492
|
async run(sassPath, data, options) {
|
37452
37493
|
const sass = (await import(pathToFileURL(sassPath).href)).default;
|
37453
|
-
|
37494
|
+
compilerPromise ??= sass.initAsyncCompiler();
|
37495
|
+
const compiler = await compilerPromise;
|
37454
37496
|
const sassOptions = { ...options };
|
37455
37497
|
sassOptions.url = pathToFileURL(options.filename);
|
37456
37498
|
sassOptions.sourceMap = options.enableSourcemap;
|
@@ -37476,7 +37518,7 @@ const makeModernCompilerScssWorker = (resolvers, alias, _maxWorkers) => {
|
|
37476
37518
|
resolvers.sass
|
37477
37519
|
);
|
37478
37520
|
const contents = result2.contents ?? await fsp.readFile(result2.file, "utf-8");
|
37479
|
-
return { contents, syntax };
|
37521
|
+
return { contents, syntax, sourceMapUrl: canonicalUrl };
|
37480
37522
|
}
|
37481
37523
|
};
|
37482
37524
|
sassOptions.importers = [
|
@@ -37493,8 +37535,8 @@ const makeModernCompilerScssWorker = (resolvers, alias, _maxWorkers) => {
|
|
37493
37535
|
};
|
37494
37536
|
},
|
37495
37537
|
async stop() {
|
37496
|
-
|
37497
|
-
|
37538
|
+
(await compilerPromise)?.dispose();
|
37539
|
+
compilerPromise = void 0;
|
37498
37540
|
}
|
37499
37541
|
};
|
37500
37542
|
return worker;
|
@@ -37962,7 +38004,10 @@ async function compileLightningCSS(id, src, config, urlReplacer) {
|
|
37962
38004
|
}
|
37963
38005
|
deps.add(dep.url);
|
37964
38006
|
if (urlReplacer) {
|
37965
|
-
const replaceUrl = await urlReplacer(
|
38007
|
+
const replaceUrl = await urlReplacer(
|
38008
|
+
dep.url,
|
38009
|
+
toAbsolute(dep.loc.filePath)
|
38010
|
+
);
|
37966
38011
|
css = css.replace(dep.placeholder, () => replaceUrl);
|
37967
38012
|
} else {
|
37968
38013
|
css = css.replace(dep.placeholder, () => dep.url);
|
@@ -45061,14 +45106,21 @@ var linux = {
|
|
45061
45106
|
codium: 'codium',
|
45062
45107
|
emacs: 'emacs',
|
45063
45108
|
gvim: 'gvim',
|
45109
|
+
idea: 'idea',
|
45064
45110
|
'idea.sh': 'idea',
|
45111
|
+
phpstorm: 'phpstorm',
|
45065
45112
|
'phpstorm.sh': 'phpstorm',
|
45113
|
+
pycharm: 'pycharm',
|
45066
45114
|
'pycharm.sh': 'pycharm',
|
45115
|
+
rubymine: 'rubymine',
|
45067
45116
|
'rubymine.sh': 'rubymine',
|
45068
45117
|
sublime_text: 'subl',
|
45069
45118
|
vim: 'vim',
|
45119
|
+
webstorm: 'webstorm',
|
45070
45120
|
'webstorm.sh': 'webstorm',
|
45121
|
+
goland: 'goland',
|
45071
45122
|
'goland.sh': 'goland',
|
45123
|
+
rider: 'rider',
|
45072
45124
|
'rider.sh': 'rider'
|
45073
45125
|
};
|
45074
45126
|
|
@@ -45378,36 +45430,6 @@ function launchEditor (file, specifiedEditor, onErrorCallback) {
|
|
45378
45430
|
fileName = path$5.relative('', fileName);
|
45379
45431
|
}
|
45380
45432
|
|
45381
|
-
// cmd.exe on Windows is vulnerable to RCE attacks given a file name of the
|
45382
|
-
// form "C:\Users\myusername\Downloads\& curl 172.21.93.52". Use a safe file
|
45383
|
-
// name pattern to validate user-provided file names. This doesn't cover the
|
45384
|
-
// entire range of valid file names but should cover almost all of them in practice.
|
45385
|
-
// (Backport of
|
45386
|
-
// https://github.com/facebook/create-react-app/pull/4866
|
45387
|
-
// and
|
45388
|
-
// https://github.com/facebook/create-react-app/pull/5431)
|
45389
|
-
|
45390
|
-
// Allows alphanumeric characters, periods, dashes, slashes, underscores, plus and space.
|
45391
|
-
const WINDOWS_CMD_SAFE_FILE_NAME_PATTERN = /^([A-Za-z]:[/\\])?[\p{L}0-9/.\-\\_+ ]+$/u;
|
45392
|
-
if (
|
45393
|
-
process.platform === 'win32' &&
|
45394
|
-
!WINDOWS_CMD_SAFE_FILE_NAME_PATTERN.test(fileName.trim())
|
45395
|
-
) {
|
45396
|
-
console.log();
|
45397
|
-
console.log(
|
45398
|
-
colors.red('Could not open ' + path$5.basename(fileName) + ' in the editor.')
|
45399
|
-
);
|
45400
|
-
console.log();
|
45401
|
-
console.log(
|
45402
|
-
'When running on Windows, file names are checked against a safe file name ' +
|
45403
|
-
'pattern to protect against remote code execution attacks. File names ' +
|
45404
|
-
'may consist only of alphanumeric characters (all languages), periods, ' +
|
45405
|
-
'dashes, slashes, and underscores.'
|
45406
|
-
);
|
45407
|
-
console.log();
|
45408
|
-
return
|
45409
|
-
}
|
45410
|
-
|
45411
45433
|
if (lineNumber) {
|
45412
45434
|
const extraArgs = getArgumentsForPosition(editor, fileName, lineNumber, columnNumber);
|
45413
45435
|
args.push.apply(args, extraArgs);
|
@@ -45423,13 +45445,55 @@ function launchEditor (file, specifiedEditor, onErrorCallback) {
|
|
45423
45445
|
}
|
45424
45446
|
|
45425
45447
|
if (process.platform === 'win32') {
|
45426
|
-
// On Windows,
|
45427
|
-
//
|
45428
|
-
|
45429
|
-
|
45430
|
-
|
45431
|
-
|
45432
|
-
|
45448
|
+
// On Windows, we need to use `exec` with the `shell: true` option,
|
45449
|
+
// and some more sanitization is required.
|
45450
|
+
|
45451
|
+
// However, CMD.exe on Windows is vulnerable to RCE attacks given a file name of the
|
45452
|
+
// form "C:\Users\myusername\Downloads\& curl 172.21.93.52".
|
45453
|
+
// `create-react-app` used a safe file name pattern to validate user-provided file names:
|
45454
|
+
// - https://github.com/facebook/create-react-app/pull/4866
|
45455
|
+
// - https://github.com/facebook/create-react-app/pull/5431
|
45456
|
+
// But that's not a viable solution for this package because
|
45457
|
+
// it's depended on by so many meta frameworks that heavily rely on
|
45458
|
+
// special characters in file names for filesystem-based routing.
|
45459
|
+
// We need to at least:
|
45460
|
+
// - Support `+` because it's used in SvelteKit and Vike
|
45461
|
+
// - Support `$` because it's used in Remix
|
45462
|
+
// - Support `(` and `)` because they are used in Analog, SolidStart, and Vike
|
45463
|
+
// - Support `@` because it's used in Vike
|
45464
|
+
// - Support `[` and `]` because they are widely used for [slug]
|
45465
|
+
// So here we choose to use `^` to escape special characters instead.
|
45466
|
+
|
45467
|
+
// According to https://ss64.com/nt/syntax-esc.html,
|
45468
|
+
// we can use `^` to escape `&`, `<`, `>`, `|`, `%`, and `^`
|
45469
|
+
// I'm not sure if we have to escape all of these, but let's do it anyway
|
45470
|
+
function escapeCmdArgs (cmdArgs) {
|
45471
|
+
return cmdArgs.replace(/([&|<>,;=^])/g, '^$1')
|
45472
|
+
}
|
45473
|
+
|
45474
|
+
// Need to double quote the editor path in case it contains spaces;
|
45475
|
+
// If the fileName contains spaces, we also need to double quote it in the arguments
|
45476
|
+
// However, there's a case that it's concatenated with line number and column number
|
45477
|
+
// which is separated by `:`. We need to double quote the whole string in this case.
|
45478
|
+
// Also, if the string contains the escape character `^`, it needs to be quoted, too.
|
45479
|
+
function doubleQuoteIfNeeded(str) {
|
45480
|
+
if (str.includes('^')) {
|
45481
|
+
// If a string includes an escaped character, not only does it need to be quoted,
|
45482
|
+
// but the quotes need to be escaped too.
|
45483
|
+
return `^"${str}^"`
|
45484
|
+
} else if (str.includes(' ')) {
|
45485
|
+
return `"${str}"`
|
45486
|
+
}
|
45487
|
+
return str
|
45488
|
+
}
|
45489
|
+
const launchCommand = [editor, ...args.map(escapeCmdArgs)]
|
45490
|
+
.map(doubleQuoteIfNeeded)
|
45491
|
+
.join(' ');
|
45492
|
+
|
45493
|
+
_childProcess = childProcess$1.exec(launchCommand, {
|
45494
|
+
stdio: 'inherit',
|
45495
|
+
shell: true
|
45496
|
+
});
|
45433
45497
|
} else {
|
45434
45498
|
_childProcess = childProcess$1.spawn(editor, args, { stdio: 'inherit' });
|
45435
45499
|
}
|
@@ -45553,7 +45617,7 @@ function setClientErrorHandler(server, logger) {
|
|
45553
45617
|
msg = "431 Request Header Fields Too Large";
|
45554
45618
|
logger.warn(
|
45555
45619
|
colors$1.yellow(
|
45556
|
-
"Server responded with status code 431. See https://
|
45620
|
+
"Server responded with status code 431. See https://vite.dev/guide/troubleshooting.html#_431-request-header-fields-too-large."
|
45557
45621
|
)
|
45558
45622
|
);
|
45559
45623
|
}
|
@@ -46168,7 +46232,7 @@ function resolvePlugin(resolveOptions) {
|
|
46168
46232
|
);
|
46169
46233
|
} else if (isProduction) {
|
46170
46234
|
this.warn(
|
46171
|
-
`Module "${id}" has been externalized for browser compatibility, imported by "${importer}". See https://
|
46235
|
+
`Module "${id}" has been externalized for browser compatibility, imported by "${importer}". See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.`
|
46172
46236
|
);
|
46173
46237
|
}
|
46174
46238
|
return isProduction ? browserExternalId : `${browserExternalId}:${id}`;
|
@@ -46185,7 +46249,7 @@ function resolvePlugin(resolveOptions) {
|
|
46185
46249
|
id = id.slice(browserExternalId.length + 1);
|
46186
46250
|
return `export default new Proxy({}, {
|
46187
46251
|
get(_, key) {
|
46188
|
-
throw new Error(\`Module "${id}" has been externalized for browser compatibility. Cannot access "${id}.\${key}" in client code. See https://
|
46252
|
+
throw new Error(\`Module "${id}" has been externalized for browser compatibility. Cannot access "${id}.\${key}" in client code. See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.\`)
|
46189
46253
|
}
|
46190
46254
|
})`;
|
46191
46255
|
}
|
@@ -46924,7 +46988,7 @@ function esbuildDepPlugin(qualified, external, config, ssr) {
|
|
46924
46988
|
key !== 'constructor' &&
|
46925
46989
|
key !== 'splice'
|
46926
46990
|
) {
|
46927
|
-
console.warn(\`Module "${path2}" has been externalized for browser compatibility. Cannot access "${path2}.\${key}" in client code. See https://
|
46991
|
+
console.warn(\`Module "${path2}" has been externalized for browser compatibility. Cannot access "${path2}.\${key}" in client code. See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.\`)
|
46928
46992
|
}
|
46929
46993
|
}
|
46930
46994
|
}))`
|
@@ -47433,8 +47497,9 @@ function clientInjectionsPlugin(config) {
|
|
47433
47497
|
const hmrTimeoutReplacement = escapeReplacement(timeout);
|
47434
47498
|
const hmrEnableOverlayReplacement = escapeReplacement(overlay);
|
47435
47499
|
const hmrConfigNameReplacement = escapeReplacement(hmrConfigName);
|
47500
|
+
const wsTokenReplacement = escapeReplacement(config.webSocketToken);
|
47436
47501
|
injectConfigValues = (code) => {
|
47437
|
-
return code.replace(`__MODE__`, modeReplacement).replace(/__BASE__/g, baseReplacement).replace(`__DEFINES__`, definesReplacement).replace(`__SERVER_HOST__`, serverHostReplacement).replace(`__HMR_PROTOCOL__`, hmrProtocolReplacement).replace(`__HMR_HOSTNAME__`, hmrHostnameReplacement).replace(`__HMR_PORT__`, hmrPortReplacement).replace(`__HMR_DIRECT_TARGET__`, hmrDirectTargetReplacement).replace(`__HMR_BASE__`, hmrBaseReplacement).replace(`__HMR_TIMEOUT__`, hmrTimeoutReplacement).replace(`__HMR_ENABLE_OVERLAY__`, hmrEnableOverlayReplacement).replace(`__HMR_CONFIG_NAME__`, hmrConfigNameReplacement);
|
47502
|
+
return code.replace(`__MODE__`, modeReplacement).replace(/__BASE__/g, baseReplacement).replace(`__DEFINES__`, definesReplacement).replace(`__SERVER_HOST__`, serverHostReplacement).replace(`__HMR_PROTOCOL__`, hmrProtocolReplacement).replace(`__HMR_HOSTNAME__`, hmrHostnameReplacement).replace(`__HMR_PORT__`, hmrPortReplacement).replace(`__HMR_DIRECT_TARGET__`, hmrDirectTargetReplacement).replace(`__HMR_BASE__`, hmrBaseReplacement).replace(`__HMR_TIMEOUT__`, hmrTimeoutReplacement).replace(`__HMR_ENABLE_OVERLAY__`, hmrEnableOverlayReplacement).replace(`__HMR_CONFIG_NAME__`, hmrConfigNameReplacement).replace(`__WS_TOKEN__`, wsTokenReplacement);
|
47438
47503
|
};
|
47439
47504
|
},
|
47440
47505
|
async transform(code, id, options) {
|
@@ -47462,6 +47527,7 @@ function escapeReplacement(value) {
|
|
47462
47527
|
}
|
47463
47528
|
|
47464
47529
|
const wasmHelperId = "\0vite/wasm-helper.js";
|
47530
|
+
const wasmInitRE = /(?<![?#].*)\.wasm\?init/;
|
47465
47531
|
const wasmHelper = async (opts = {}, url) => {
|
47466
47532
|
let result;
|
47467
47533
|
if (url.startsWith("data:")) {
|
@@ -47506,7 +47572,7 @@ const wasmHelperPlugin = (config) => {
|
|
47506
47572
|
if (id === wasmHelperId) {
|
47507
47573
|
return `export default ${wasmHelperCode}`;
|
47508
47574
|
}
|
47509
|
-
if (!
|
47575
|
+
if (!wasmInitRE.test(id)) {
|
47510
47576
|
return;
|
47511
47577
|
}
|
47512
47578
|
const url = await fileToUrl$1(id, config, this);
|
@@ -47525,7 +47591,7 @@ const wasmFallbackPlugin = () => {
|
|
47525
47591
|
return;
|
47526
47592
|
}
|
47527
47593
|
throw new Error(
|
47528
|
-
'"ESM integration proposal for Wasm" is not supported currently. Use vite-plugin-wasm or other community plugins to handle this. Alternatively, you can use `.wasm?init` or `.wasm?url`. See https://
|
47594
|
+
'"ESM integration proposal for Wasm" is not supported currently. Use vite-plugin-wasm or other community plugins to handle this. Alternatively, you can use `.wasm?init` or `.wasm?url`. See https://vite.dev/guide/features.html#webassembly for more details.'
|
47529
47595
|
);
|
47530
47596
|
}
|
47531
47597
|
};
|
@@ -47533,7 +47599,7 @@ const wasmFallbackPlugin = () => {
|
|
47533
47599
|
|
47534
47600
|
const workerOrSharedWorkerRE = /(?:\?|&)(worker|sharedworker)(?:&|$)/;
|
47535
47601
|
const workerFileRE = /(?:\?|&)worker_file&type=(\w+)(?:&|$)/;
|
47536
|
-
const inlineRE = /[?&]inline\b/;
|
47602
|
+
const inlineRE$1 = /[?&]inline\b/;
|
47537
47603
|
const WORKER_FILE_ID = "worker_file";
|
47538
47604
|
const workerCache = /* @__PURE__ */ new WeakMap();
|
47539
47605
|
function saveEmitWorkerAsset(config, asset) {
|
@@ -47731,7 +47797,7 @@ function webWorkerPlugin(config) {
|
|
47731
47797
|
if (isBuild) {
|
47732
47798
|
if (isWorker && config.bundleChain.at(-1) === cleanUrl(id)) {
|
47733
47799
|
urlCode = "self.location.href";
|
47734
|
-
} else if (inlineRE.test(id)) {
|
47800
|
+
} else if (inlineRE$1.test(id)) {
|
47735
47801
|
const chunk = await bundleWorkerEntry(config, id);
|
47736
47802
|
const encodedJs = `const encodedJs = "${Buffer.from(
|
47737
47803
|
chunk.code
|
@@ -47786,7 +47852,7 @@ function webWorkerPlugin(config) {
|
|
47786
47852
|
url = injectQuery(url, `${WORKER_FILE_ID}&type=${workerType}`);
|
47787
47853
|
urlCode = JSON.stringify(url);
|
47788
47854
|
}
|
47789
|
-
if (urlRE.test(id)) {
|
47855
|
+
if (urlRE$1.test(id)) {
|
47790
47856
|
return {
|
47791
47857
|
code: `export default ${urlCode}`,
|
47792
47858
|
map: { mappings: "" }
|
@@ -48423,7 +48489,7 @@ function parseDynamicImportPattern(strings) {
|
|
48423
48489
|
let globParams = null;
|
48424
48490
|
if (search) {
|
48425
48491
|
search = "?" + search;
|
48426
|
-
if (workerOrSharedWorkerRE.test(search) || urlRE.test(search) || rawRE.test(search)) {
|
48492
|
+
if (workerOrSharedWorkerRE.test(search) || urlRE$1.test(search) || rawRE$1.test(search)) {
|
48427
48493
|
globParams = {
|
48428
48494
|
query: search,
|
48429
48495
|
import: "*"
|
@@ -51575,7 +51641,7 @@ function servePublicMiddleware(server, publicFiles) {
|
|
51575
51641
|
};
|
51576
51642
|
return function viteServePublicMiddleware(req, res, next) {
|
51577
51643
|
if (publicFiles && !publicFiles.has(toFilePath(req.url)) || isImportRequest(req.url) || isInternalRequest(req.url) || // for `/public-file.js?url` to be transformed
|
51578
|
-
urlRE.test(req.url)) {
|
51644
|
+
urlRE$1.test(req.url)) {
|
51579
51645
|
return next();
|
51580
51646
|
}
|
51581
51647
|
serve(req, res, next);
|
@@ -51671,7 +51737,7 @@ function ensureServingAccess(url, server, res, next) {
|
|
51671
51737
|
const hintMessage = `
|
51672
51738
|
${server.config.server.fs.allow.map((i) => `- ${i}`).join("\n")}
|
51673
51739
|
|
51674
|
-
Refer to docs https://
|
51740
|
+
Refer to docs https://vite.dev/config/server-options.html#server-fs-allow for configurations and more details.`;
|
51675
51741
|
server.config.logger.error(urlMessage);
|
51676
51742
|
server.config.logger.warnOnce(hintMessage + "\n");
|
51677
51743
|
res.statusCode = 403;
|
@@ -51699,6 +51765,7 @@ function renderRestrictedErrorHTML(msg) {
|
|
51699
51765
|
|
51700
51766
|
const ERR_LOAD_URL = "ERR_LOAD_URL";
|
51701
51767
|
const ERR_LOAD_PUBLIC_URL = "ERR_LOAD_PUBLIC_URL";
|
51768
|
+
const ERR_DENIED_ID = "ERR_DENIED_ID";
|
51702
51769
|
const debugLoad = createDebugger("vite:load");
|
51703
51770
|
const debugTransform = createDebugger("vite:transform");
|
51704
51771
|
const debugCache$1 = createDebugger("vite:cache");
|
@@ -51800,6 +51867,11 @@ async function loadAndTransform(id, url, server, options, timestamp, mod, resolv
|
|
51800
51867
|
const prettyUrl = debugLoad || debugTransform ? prettifyUrl(url, config.root) : "";
|
51801
51868
|
const ssr = !!options.ssr;
|
51802
51869
|
const file = cleanUrl(id);
|
51870
|
+
if (options.allowId && !options.allowId(id)) {
|
51871
|
+
const err = new Error(`Denied ID ${id}`);
|
51872
|
+
err.code = ERR_DENIED_ID;
|
51873
|
+
throw err;
|
51874
|
+
}
|
51803
51875
|
let code = null;
|
51804
51876
|
let map = null;
|
51805
51877
|
const loadStart = debugLoad ? performance$1.now() : 0;
|
@@ -52512,18 +52584,13 @@ Object.defineProperty(${ssrModuleExportsKey}, "default", { enumerable: true, con
|
|
52512
52584
|
}
|
52513
52585
|
});
|
52514
52586
|
let map = s.generateMap({ hires: "boundary" });
|
52587
|
+
map.sources = [path$n.basename(url)];
|
52588
|
+
map.sourcesContent = [originalCode];
|
52515
52589
|
if (inMap && inMap.mappings && "sources" in inMap && inMap.sources.length > 0) {
|
52516
52590
|
map = combineSourcemaps(url, [
|
52517
|
-
|
52518
|
-
...map,
|
52519
|
-
sources: inMap.sources,
|
52520
|
-
sourcesContent: inMap.sourcesContent
|
52521
|
-
},
|
52591
|
+
map,
|
52522
52592
|
inMap
|
52523
52593
|
]);
|
52524
|
-
} else {
|
52525
|
-
map.sources = [path$n.basename(url)];
|
52526
|
-
map.sourcesContent = [originalCode];
|
52527
52594
|
}
|
52528
52595
|
return {
|
52529
52596
|
code: s.toString(),
|
@@ -59117,6 +59184,107 @@ function abortHandshakeOrEmitwsClientError(server, req, socket, code, message) {
|
|
59117
59184
|
|
59118
59185
|
var WebSocketServerRaw_ = /*@__PURE__*/getDefaultExportFromCjs(websocketServer);
|
59119
59186
|
|
59187
|
+
const allowedHostsServerCache = /* @__PURE__ */ new WeakMap();
|
59188
|
+
const allowedHostsPreviewCache = /* @__PURE__ */ new WeakMap();
|
59189
|
+
const isFileOrExtensionProtocolRE = /^(?:file|.+-extension):/i;
|
59190
|
+
function getAdditionalAllowedHosts(resolvedServerOptions, resolvedPreviewOptions) {
|
59191
|
+
const list = [];
|
59192
|
+
if (typeof resolvedServerOptions.host === "string" && resolvedServerOptions.host) {
|
59193
|
+
list.push(resolvedServerOptions.host);
|
59194
|
+
}
|
59195
|
+
if (typeof resolvedServerOptions.hmr === "object" && resolvedServerOptions.hmr.host) {
|
59196
|
+
list.push(resolvedServerOptions.hmr.host);
|
59197
|
+
}
|
59198
|
+
if (typeof resolvedPreviewOptions.host === "string" && resolvedPreviewOptions.host) {
|
59199
|
+
list.push(resolvedPreviewOptions.host);
|
59200
|
+
}
|
59201
|
+
if (resolvedServerOptions.origin) {
|
59202
|
+
try {
|
59203
|
+
const serverOriginUrl = new URL(resolvedServerOptions.origin);
|
59204
|
+
list.push(serverOriginUrl.hostname);
|
59205
|
+
} catch {
|
59206
|
+
}
|
59207
|
+
}
|
59208
|
+
return list;
|
59209
|
+
}
|
59210
|
+
function isHostAllowedWithoutCache(allowedHosts, additionalAllowedHosts, host) {
|
59211
|
+
if (isFileOrExtensionProtocolRE.test(host)) {
|
59212
|
+
return true;
|
59213
|
+
}
|
59214
|
+
const trimmedHost = host.trim();
|
59215
|
+
if (trimmedHost[0] === "[") {
|
59216
|
+
const endIpv6 = trimmedHost.indexOf("]");
|
59217
|
+
if (endIpv6 < 0) {
|
59218
|
+
return false;
|
59219
|
+
}
|
59220
|
+
return net$1.isIP(trimmedHost.slice(1, endIpv6)) === 6;
|
59221
|
+
}
|
59222
|
+
const colonPos = trimmedHost.indexOf(":");
|
59223
|
+
const hostname = colonPos === -1 ? trimmedHost : trimmedHost.slice(0, colonPos);
|
59224
|
+
if (net$1.isIP(hostname) === 4) {
|
59225
|
+
return true;
|
59226
|
+
}
|
59227
|
+
if (hostname === "localhost" || hostname.endsWith(".localhost")) {
|
59228
|
+
return true;
|
59229
|
+
}
|
59230
|
+
for (const additionalAllowedHost of additionalAllowedHosts) {
|
59231
|
+
if (additionalAllowedHost === hostname) {
|
59232
|
+
return true;
|
59233
|
+
}
|
59234
|
+
}
|
59235
|
+
for (const allowedHost of allowedHosts) {
|
59236
|
+
if (allowedHost === hostname) {
|
59237
|
+
return true;
|
59238
|
+
}
|
59239
|
+
if (allowedHost[0] === "." && (allowedHost.slice(1) === hostname || hostname.endsWith(allowedHost))) {
|
59240
|
+
return true;
|
59241
|
+
}
|
59242
|
+
}
|
59243
|
+
return false;
|
59244
|
+
}
|
59245
|
+
function isHostAllowed(config, isPreview, host) {
|
59246
|
+
const allowedHosts = isPreview ? config.preview.allowedHosts : config.server.allowedHosts;
|
59247
|
+
if (allowedHosts === true) {
|
59248
|
+
return true;
|
59249
|
+
}
|
59250
|
+
const cache = isPreview ? allowedHostsPreviewCache : allowedHostsServerCache;
|
59251
|
+
if (!cache.has(config)) {
|
59252
|
+
cache.set(config, /* @__PURE__ */ new Set());
|
59253
|
+
}
|
59254
|
+
const cachedAllowedHosts = cache.get(config);
|
59255
|
+
if (cachedAllowedHosts.has(host)) {
|
59256
|
+
return true;
|
59257
|
+
}
|
59258
|
+
const result = isHostAllowedWithoutCache(
|
59259
|
+
allowedHosts ?? [],
|
59260
|
+
config.additionalAllowedHosts,
|
59261
|
+
host
|
59262
|
+
);
|
59263
|
+
if (result) {
|
59264
|
+
cachedAllowedHosts.add(host);
|
59265
|
+
}
|
59266
|
+
return result;
|
59267
|
+
}
|
59268
|
+
function hostCheckMiddleware(config, isPreview) {
|
59269
|
+
return function viteHostCheckMiddleware(req, res, next) {
|
59270
|
+
const hostHeader = req.headers.host;
|
59271
|
+
if (!hostHeader || !isHostAllowed(config, isPreview, hostHeader)) {
|
59272
|
+
const hostname = hostHeader?.replace(/:\d+$/, "");
|
59273
|
+
const hostnameWithQuotes = JSON.stringify(hostname);
|
59274
|
+
const optionName = `${isPreview ? "preview" : "server"}.allowedHosts`;
|
59275
|
+
res.writeHead(403, {
|
59276
|
+
"Content-Type": "text/plain"
|
59277
|
+
});
|
59278
|
+
res.end(
|
59279
|
+
`Blocked request. This host (${hostnameWithQuotes}) is not allowed.
|
59280
|
+
To allow this host, add ${hostnameWithQuotes} to \`${optionName}\` in vite.config.js.`
|
59281
|
+
);
|
59282
|
+
return;
|
59283
|
+
}
|
59284
|
+
return next();
|
59285
|
+
};
|
59286
|
+
}
|
59287
|
+
|
59120
59288
|
const WebSocketServerRaw = process.versions.bun ? (
|
59121
59289
|
// @ts-expect-error: Bun defines `import.meta.require`
|
59122
59290
|
import.meta.require("ws").WebSocketServer
|
@@ -59131,6 +59299,19 @@ const wsServerEvents = [
|
|
59131
59299
|
];
|
59132
59300
|
function noop$1() {
|
59133
59301
|
}
|
59302
|
+
function hasValidToken(config, url) {
|
59303
|
+
const token = url.searchParams.get("token");
|
59304
|
+
if (!token) return false;
|
59305
|
+
try {
|
59306
|
+
const isValidToken = crypto$2.timingSafeEqual(
|
59307
|
+
Buffer.from(token),
|
59308
|
+
Buffer.from(config.webSocketToken)
|
59309
|
+
);
|
59310
|
+
return isValidToken;
|
59311
|
+
} catch {
|
59312
|
+
}
|
59313
|
+
return false;
|
59314
|
+
}
|
59134
59315
|
function createWebSocketServer(server, config, httpsOptions) {
|
59135
59316
|
if (config.server.ws === false) {
|
59136
59317
|
return {
|
@@ -59146,7 +59327,6 @@ function createWebSocketServer(server, config, httpsOptions) {
|
|
59146
59327
|
send: noop$1
|
59147
59328
|
};
|
59148
59329
|
}
|
59149
|
-
let wss;
|
59150
59330
|
let wsHttpServer = void 0;
|
59151
59331
|
const hmr = isObject$1(config.server.hmr) && config.server.hmr;
|
59152
59332
|
const hmrServer = hmr && hmr.server;
|
@@ -59158,18 +59338,37 @@ function createWebSocketServer(server, config, httpsOptions) {
|
|
59158
59338
|
const clientsMap = /* @__PURE__ */ new WeakMap();
|
59159
59339
|
const port = hmrPort || 24678;
|
59160
59340
|
const host = hmr && hmr.host || void 0;
|
59341
|
+
const shouldHandle = (req) => {
|
59342
|
+
const hostHeader = req.headers.host;
|
59343
|
+
if (!hostHeader || !isHostAllowed(config, false, hostHeader)) {
|
59344
|
+
return false;
|
59345
|
+
}
|
59346
|
+
if (config.legacy?.skipWebSocketTokenCheck) {
|
59347
|
+
return true;
|
59348
|
+
}
|
59349
|
+
if (req.headers.origin) {
|
59350
|
+
const parsedUrl = new URL(`http://example.com${req.url}`);
|
59351
|
+
return hasValidToken(config, parsedUrl);
|
59352
|
+
}
|
59353
|
+
return true;
|
59354
|
+
};
|
59355
|
+
const handleUpgrade = (req, socket, head, _isPing) => {
|
59356
|
+
wss.handleUpgrade(req, socket, head, (ws) => {
|
59357
|
+
wss.emit("connection", ws, req);
|
59358
|
+
});
|
59359
|
+
};
|
59360
|
+
const wss = new WebSocketServerRaw({ noServer: true });
|
59361
|
+
wss.shouldHandle = shouldHandle;
|
59161
59362
|
if (wsServer) {
|
59162
59363
|
let hmrBase = config.base;
|
59163
59364
|
const hmrPath = hmr ? hmr.path : void 0;
|
59164
59365
|
if (hmrPath) {
|
59165
59366
|
hmrBase = path$n.posix.join(hmrBase, hmrPath);
|
59166
59367
|
}
|
59167
|
-
wss = new WebSocketServerRaw({ noServer: true });
|
59168
59368
|
hmrServerWsListener = (req, socket, head) => {
|
59169
|
-
|
59170
|
-
|
59171
|
-
|
59172
|
-
});
|
59369
|
+
const parsedUrl = new URL(`http://example.com${req.url}`);
|
59370
|
+
if (req.headers["sec-websocket-protocol"] === HMR_HEADER && parsedUrl.pathname === hmrBase) {
|
59371
|
+
handleUpgrade(req, socket, head);
|
59173
59372
|
}
|
59174
59373
|
};
|
59175
59374
|
wsServer.on("upgrade", hmrServerWsListener);
|
@@ -59190,7 +59389,23 @@ function createWebSocketServer(server, config, httpsOptions) {
|
|
59190
59389
|
} else {
|
59191
59390
|
wsHttpServer = createServer$3(route);
|
59192
59391
|
}
|
59193
|
-
|
59392
|
+
wsHttpServer.on("upgrade", (req, socket, head) => {
|
59393
|
+
handleUpgrade(req, socket, head);
|
59394
|
+
});
|
59395
|
+
wsHttpServer.on("error", (e) => {
|
59396
|
+
if (e.code === "EADDRINUSE") {
|
59397
|
+
config.logger.error(
|
59398
|
+
colors$1.red(`WebSocket server error: Port is already in use`),
|
59399
|
+
{ error: e }
|
59400
|
+
);
|
59401
|
+
} else {
|
59402
|
+
config.logger.error(
|
59403
|
+
colors$1.red(`WebSocket server error:
|
59404
|
+
${e.stack || e.message}`),
|
59405
|
+
{ error: e }
|
59406
|
+
);
|
59407
|
+
}
|
59408
|
+
});
|
59194
59409
|
}
|
59195
59410
|
wss.on("connection", (socket) => {
|
59196
59411
|
socket.on("message", (raw) => {
|
@@ -61720,6 +61935,14 @@ function send(req, res, content, type, options) {
|
|
61720
61935
|
|
61721
61936
|
const debugCache = createDebugger("vite:cache");
|
61722
61937
|
const knownIgnoreList = /* @__PURE__ */ new Set(["/", "/favicon.ico"]);
|
61938
|
+
const trailingQuerySeparatorsRE = /[?&]+$/;
|
61939
|
+
const urlRE = /[?&]url\b/;
|
61940
|
+
const rawRE = /[?&]raw\b/;
|
61941
|
+
const inlineRE = /[?&]inline\b/;
|
61942
|
+
const svgRE = /\.svg\b/;
|
61943
|
+
function deniedServingAccessForTransform(url, server, res, next) {
|
61944
|
+
return (rawRE.test(url) || urlRE.test(url) || inlineRE.test(url) || svgRE.test(url)) && !ensureServingAccess(url, server, res, next);
|
61945
|
+
}
|
61723
61946
|
function cachedTransformMiddleware(server) {
|
61724
61947
|
return function viteCachedTransformMiddleware(req, res, next) {
|
61725
61948
|
const ifNoneMatch = req.headers["if-none-match"];
|
@@ -61803,7 +62026,16 @@ function transformMiddleware(server) {
|
|
61803
62026
|
if (publicDirInRoot && url.startsWith(publicPath)) {
|
61804
62027
|
warnAboutExplicitPublicPathInUrl(url);
|
61805
62028
|
}
|
61806
|
-
|
62029
|
+
const urlWithoutTrailingQuerySeparators = url.replace(
|
62030
|
+
trailingQuerySeparatorsRE,
|
62031
|
+
""
|
62032
|
+
);
|
62033
|
+
if (deniedServingAccessForTransform(
|
62034
|
+
urlWithoutTrailingQuerySeparators,
|
62035
|
+
server,
|
62036
|
+
res,
|
62037
|
+
next
|
62038
|
+
)) {
|
61807
62039
|
return;
|
61808
62040
|
}
|
61809
62041
|
if (isJSRequest(url) || isImportRequest(url) || isCSSRequest(url) || isHTMLProxy(url)) {
|
@@ -61821,7 +62053,10 @@ function transformMiddleware(server) {
|
|
61821
62053
|
}
|
61822
62054
|
}
|
61823
62055
|
const result = await transformRequest(url, server, {
|
61824
|
-
html: req.headers.accept?.includes("text/html")
|
62056
|
+
html: req.headers.accept?.includes("text/html"),
|
62057
|
+
allowId(id) {
|
62058
|
+
return !deniedServingAccessForTransform(id, server, res, next);
|
62059
|
+
}
|
61825
62060
|
});
|
61826
62061
|
if (result) {
|
61827
62062
|
const depsOptimizer = getDepsOptimizer(server.config, false);
|
@@ -61873,6 +62108,9 @@ function transformMiddleware(server) {
|
|
61873
62108
|
if (e?.code === ERR_LOAD_URL) {
|
61874
62109
|
return next();
|
61875
62110
|
}
|
62111
|
+
if (e?.code === ERR_DENIED_ID) {
|
62112
|
+
return;
|
62113
|
+
}
|
61876
62114
|
return next(e);
|
61877
62115
|
}
|
61878
62116
|
next();
|
@@ -62374,7 +62612,7 @@ class ModuleGraph {
|
|
62374
62612
|
mod.ssrError = null;
|
62375
62613
|
mod.importers.forEach((importer) => {
|
62376
62614
|
if (!importer.acceptedHmrDeps.has(mod)) {
|
62377
|
-
const shouldSoftInvalidateImporter = importer.staticImportedUrls?.has(mod.url) || softInvalidate;
|
62615
|
+
const shouldSoftInvalidateImporter = (importer.staticImportedUrls?.has(mod.url) || softInvalidate) && importer.type !== "css";
|
62378
62616
|
this.invalidateModule(
|
62379
62617
|
importer,
|
62380
62618
|
seen,
|
@@ -62693,6 +62931,17 @@ function mapFiles(files, root) {
|
|
62693
62931
|
});
|
62694
62932
|
}
|
62695
62933
|
|
62934
|
+
function rejectInvalidRequestMiddleware() {
|
62935
|
+
return function viteRejectInvalidRequestMiddleware(req, res, next) {
|
62936
|
+
if (req.url?.includes("#")) {
|
62937
|
+
res.writeHead(400);
|
62938
|
+
res.end();
|
62939
|
+
return;
|
62940
|
+
}
|
62941
|
+
return next();
|
62942
|
+
};
|
62943
|
+
}
|
62944
|
+
|
62696
62945
|
function createServer(inlineConfig = {}) {
|
62697
62946
|
return _createServer(inlineConfig, { hotListen: true });
|
62698
62947
|
}
|
@@ -63024,9 +63273,18 @@ async function _createServer(inlineConfig = {}, options) {
|
|
63024
63273
|
if (process.env.DEBUG) {
|
63025
63274
|
middlewares.use(timeMiddleware(root));
|
63026
63275
|
}
|
63276
|
+
middlewares.use(rejectInvalidRequestMiddleware());
|
63027
63277
|
const { cors } = serverConfig;
|
63028
63278
|
if (cors !== false) {
|
63029
|
-
middlewares.use(
|
63279
|
+
middlewares.use(
|
63280
|
+
corsMiddleware(
|
63281
|
+
typeof cors === "boolean" ? {} : cors ?? { origin: defaultAllowedOrigins }
|
63282
|
+
)
|
63283
|
+
);
|
63284
|
+
}
|
63285
|
+
const { allowedHosts } = serverConfig;
|
63286
|
+
if (allowedHosts !== true && !serverConfig.https) {
|
63287
|
+
middlewares.use(hostCheckMiddleware(config, false));
|
63030
63288
|
}
|
63031
63289
|
middlewares.use(cachedTransformMiddleware(server));
|
63032
63290
|
const { proxy } = serverConfig;
|
@@ -64104,7 +64362,7 @@ function importAnalysisPlugin(config) {
|
|
64104
64362
|
if (specifier === clientPublicPath) {
|
64105
64363
|
return;
|
64106
64364
|
}
|
64107
|
-
if (specifier[0] === "/" && !(config.assetsInclude(cleanUrl(specifier)) || urlRE.test(specifier)) && checkPublicFile(specifier, config)) {
|
64365
|
+
if (specifier[0] === "/" && !(config.assetsInclude(cleanUrl(specifier)) || urlRE$1.test(specifier)) && checkPublicFile(specifier, config)) {
|
64108
64366
|
throw new Error(
|
64109
64367
|
`Cannot import non-asset file ${specifier} which is inside /public. JS/CSS files inside /public are copied as-is on build and can only be referenced via <script src> or <link href> in html. If you want to get the URL of that file, use ${injectQuery(
|
64110
64368
|
specifier,
|
@@ -64450,7 +64708,7 @@ function __vite__injectQuery(url, queryToInject) {
|
|
64450
64708
|
return url;
|
64451
64709
|
}
|
64452
64710
|
const pathname = url.replace(/[?#].*$/, "");
|
64453
|
-
const { search, hash } = new URL(url, "http://
|
64711
|
+
const { search, hash } = new URL(url, "http://vite.dev");
|
64454
64712
|
return `${pathname}?${queryToInject}${search ? `&` + search.slice(1) : ""}${hash || ""}`;
|
64455
64713
|
}
|
64456
64714
|
|
@@ -65885,6 +66143,7 @@ function resolvePreviewOptions(preview2, server) {
|
|
65885
66143
|
port: preview2?.port,
|
65886
66144
|
strictPort: preview2?.strictPort ?? server.strictPort,
|
65887
66145
|
host: preview2?.host ?? server.host,
|
66146
|
+
allowedHosts: preview2?.allowedHosts ?? server.allowedHosts,
|
65888
66147
|
https: preview2?.https ?? server.https,
|
65889
66148
|
open: preview2?.open ?? server.open,
|
65890
66149
|
proxy: preview2?.proxy ?? server.proxy,
|
@@ -65953,7 +66212,15 @@ async function preview(inlineConfig = {}) {
|
|
65953
66212
|
}
|
65954
66213
|
const { cors } = config.preview;
|
65955
66214
|
if (cors !== false) {
|
65956
|
-
app.use(
|
66215
|
+
app.use(
|
66216
|
+
corsMiddleware(
|
66217
|
+
typeof cors === "boolean" ? {} : cors ?? { origin: defaultAllowedOrigins }
|
66218
|
+
)
|
66219
|
+
);
|
66220
|
+
}
|
66221
|
+
const { allowedHosts } = config.preview;
|
66222
|
+
if (allowedHosts !== true && !config.preview.https) {
|
66223
|
+
app.use(hostCheckMiddleware(config, true));
|
65957
66224
|
}
|
65958
66225
|
const { proxy } = config.preview;
|
65959
66226
|
if (proxy) {
|
@@ -66271,6 +66538,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = "development",
|
|
66271
66538
|
rollupOptions: config.worker?.rollupOptions || {}
|
66272
66539
|
};
|
66273
66540
|
const base = withTrailingSlash(resolvedBase);
|
66541
|
+
const preview = resolvePreviewOptions(config.preview, server);
|
66274
66542
|
resolved = {
|
66275
66543
|
configFile: configFile ? normalizePath$3(configFile) : void 0,
|
66276
66544
|
configFileDependencies: configFileDependencies.map(
|
@@ -66299,7 +66567,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = "development",
|
|
66299
66567
|
},
|
66300
66568
|
server,
|
66301
66569
|
build: resolvedBuildOptions,
|
66302
|
-
preview
|
66570
|
+
preview,
|
66303
66571
|
envDir,
|
66304
66572
|
env: {
|
66305
66573
|
...userEnv,
|
@@ -66329,6 +66597,13 @@ async function resolveConfig(inlineConfig, command, defaultMode = "development",
|
|
66329
66597
|
hmrPartialAccept: false,
|
66330
66598
|
...config.experimental
|
66331
66599
|
},
|
66600
|
+
// random 72 bits (12 base64 chars)
|
66601
|
+
// at least 64bits is recommended
|
66602
|
+
// https://owasp.org/www-community/vulnerabilities/Insufficient_Session-ID_Length
|
66603
|
+
webSocketToken: Buffer.from(
|
66604
|
+
crypto$2.getRandomValues(new Uint8Array(9))
|
66605
|
+
).toString("base64url"),
|
66606
|
+
additionalAllowedHosts: getAdditionalAllowedHosts(server, preview),
|
66332
66607
|
getSortedPlugins: void 0,
|
66333
66608
|
getSortedPluginHooks: void 0
|
66334
66609
|
};
|
@@ -66430,7 +66705,7 @@ function resolveBaseUrl(base = "/", isBuild, logger) {
|
|
66430
66705
|
);
|
66431
66706
|
}
|
66432
66707
|
if (!isBuild || !isExternal) {
|
66433
|
-
base = new URL(base, "http://
|
66708
|
+
base = new URL(base, "http://vite.dev").pathname;
|
66434
66709
|
if (base[0] !== "/") {
|
66435
66710
|
base = "/" + base;
|
66436
66711
|
}
|
@@ -66468,7 +66743,7 @@ async function loadConfigFromFile(configEnv, configFile, configRoot = process.cw
|
|
66468
66743
|
debug?.("no config file found.");
|
66469
66744
|
return null;
|
66470
66745
|
}
|
66471
|
-
const isESM = isFilePathESM(resolvedPath);
|
66746
|
+
const isESM = typeof process.versions.deno === "string" || isFilePathESM(resolvedPath);
|
66472
66747
|
try {
|
66473
66748
|
const bundled = await bundleConfigFile(resolvedPath, isESM);
|
66474
66749
|
const userConfig = await loadConfigFromBundledFile(
|
@@ -66573,7 +66848,7 @@ async function bundleConfigFile(fileName, isESM) {
|
|
66573
66848
|
throw new Error(
|
66574
66849
|
`Failed to resolve ${JSON.stringify(
|
66575
66850
|
id
|
66576
|
-
)}. This package is ESM only but it was tried to load by \`require\`. See https://
|
66851
|
+
)}. This package is ESM only but it was tried to load by \`require\`. See https://vite.dev/guide/troubleshooting.html#this-package-is-esm-only for more details.`
|
66577
66852
|
);
|
66578
66853
|
}
|
66579
66854
|
}
|
@@ -66586,7 +66861,7 @@ async function bundleConfigFile(fileName, isESM) {
|
|
66586
66861
|
throw new Error(
|
66587
66862
|
`${JSON.stringify(
|
66588
66863
|
id
|
66589
|
-
)} resolved to an ESM file. ESM file cannot be loaded by \`require\`. See https://
|
66864
|
+
)} resolved to an ESM file. ESM file cannot be loaded by \`require\`. See https://vite.dev/guide/troubleshooting.html#this-package-is-esm-only for more details.`
|
66590
66865
|
);
|
66591
66866
|
}
|
66592
66867
|
return {
|