vite 4.3.0-beta.7 → 4.3.0-beta.8
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.
Potentially problematic release.
This version of vite might be problematic. Click here for more details.
- package/dist/client/client.mjs.map +1 -1
- package/dist/node/chunks/{dep-1a577c21.js → dep-4190ce4e.js} +1 -1
- package/dist/node/chunks/{dep-f1f8facc.js → dep-c7e79736.js} +549 -545
- package/dist/node/cli.js +5 -5
- package/dist/node/index.d.ts +5 -0
- package/dist/node/index.js +2 -2
- package/dist/node-cjs/publicUtils.cjs +53 -4
- package/package.json +3 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs$l, { promises as promises$2 } from 'node:fs';
|
|
2
2
|
import fsp from 'node:fs/promises';
|
|
3
|
-
import path$o, {
|
|
3
|
+
import path$o, { dirname as dirname$2, join as join$2, posix as posix$1, isAbsolute as isAbsolute$2, relative as relative$2, basename as basename$2, extname as extname$1 } from 'node:path';
|
|
4
4
|
import { fileURLToPath, URL as URL$3, URLSearchParams, parse as parse$i, pathToFileURL } from 'node:url';
|
|
5
5
|
import { performance as performance$1 } from 'node:perf_hooks';
|
|
6
6
|
import { createRequire as createRequire$1, builtinModules } from 'node:module';
|
|
@@ -11562,7 +11562,9 @@ function resolvePackageData(pkgName, basedir, preserveSymlinks = false, packageC
|
|
|
11562
11562
|
return packageCache.get(cacheKey);
|
|
11563
11563
|
let pkg;
|
|
11564
11564
|
try {
|
|
11565
|
-
pkg = pnp.resolveToUnqualified(pkgName, basedir
|
|
11565
|
+
pkg = pnp.resolveToUnqualified(pkgName, basedir, {
|
|
11566
|
+
considerBuiltins: false,
|
|
11567
|
+
});
|
|
11566
11568
|
}
|
|
11567
11569
|
catch {
|
|
11568
11570
|
return null;
|
|
@@ -13632,6 +13634,63 @@ var TSConfckParseError = class extends Error {
|
|
|
13632
13634
|
}
|
|
13633
13635
|
};
|
|
13634
13636
|
|
|
13637
|
+
// https://github.com/vitejs/vite/issues/2820#issuecomment-812495079
|
|
13638
|
+
const ROOT_FILES = [
|
|
13639
|
+
// '.git',
|
|
13640
|
+
// https://pnpm.io/workspaces/
|
|
13641
|
+
'pnpm-workspace.yaml',
|
|
13642
|
+
// https://rushjs.io/pages/advanced/config_files/
|
|
13643
|
+
// 'rush.json',
|
|
13644
|
+
// https://nx.dev/latest/react/getting-started/nx-setup
|
|
13645
|
+
// 'workspace.json',
|
|
13646
|
+
// 'nx.json',
|
|
13647
|
+
// https://github.com/lerna/lerna#lernajson
|
|
13648
|
+
'lerna.json',
|
|
13649
|
+
];
|
|
13650
|
+
// npm: https://docs.npmjs.com/cli/v7/using-npm/workspaces#installing-workspaces
|
|
13651
|
+
// yarn: https://classic.yarnpkg.com/en/docs/workspaces/#toc-how-to-use-it
|
|
13652
|
+
function hasWorkspacePackageJSON(root) {
|
|
13653
|
+
const path = join$2(root, 'package.json');
|
|
13654
|
+
if (!isFileReadable(path)) {
|
|
13655
|
+
return false;
|
|
13656
|
+
}
|
|
13657
|
+
const content = JSON.parse(fs$l.readFileSync(path, 'utf-8')) || {};
|
|
13658
|
+
return !!content.workspaces;
|
|
13659
|
+
}
|
|
13660
|
+
function hasRootFile(root) {
|
|
13661
|
+
return ROOT_FILES.some((file) => fs$l.existsSync(join$2(root, file)));
|
|
13662
|
+
}
|
|
13663
|
+
function hasPackageJSON(root) {
|
|
13664
|
+
const path = join$2(root, 'package.json');
|
|
13665
|
+
return fs$l.existsSync(path);
|
|
13666
|
+
}
|
|
13667
|
+
/**
|
|
13668
|
+
* Search up for the nearest `package.json`
|
|
13669
|
+
*/
|
|
13670
|
+
function searchForPackageRoot(current, root = current) {
|
|
13671
|
+
if (hasPackageJSON(current))
|
|
13672
|
+
return current;
|
|
13673
|
+
const dir = dirname$2(current);
|
|
13674
|
+
// reach the fs root
|
|
13675
|
+
if (!dir || dir === current)
|
|
13676
|
+
return root;
|
|
13677
|
+
return searchForPackageRoot(dir, root);
|
|
13678
|
+
}
|
|
13679
|
+
/**
|
|
13680
|
+
* Search up for the nearest workspace root
|
|
13681
|
+
*/
|
|
13682
|
+
function searchForWorkspaceRoot(current, root = searchForPackageRoot(current)) {
|
|
13683
|
+
if (hasRootFile(current))
|
|
13684
|
+
return current;
|
|
13685
|
+
if (hasWorkspacePackageJSON(current))
|
|
13686
|
+
return current;
|
|
13687
|
+
const dir = dirname$2(current);
|
|
13688
|
+
// reach the fs root
|
|
13689
|
+
if (!dir || dir === current)
|
|
13690
|
+
return root;
|
|
13691
|
+
return searchForWorkspaceRoot(dir, root);
|
|
13692
|
+
}
|
|
13693
|
+
|
|
13635
13694
|
const debug$f = createDebugger('vite:esbuild');
|
|
13636
13695
|
const INJECT_HELPERS_IIFE_RE = /^(.*?)((?:const|var)\s+\S+\s*=\s*function\s*\([^)]*\)\s*\{.*?"use strict";)/s;
|
|
13637
13696
|
const INJECT_HELPERS_UMD_RE = /^(.*?)(\(function\([^)]*\)\s*\{.+?amd.+?function\([^)]*\)\s*\{.*?"use strict";)/s;
|
|
@@ -38505,7 +38564,7 @@ function createCachedImport(imp) {
|
|
|
38505
38564
|
};
|
|
38506
38565
|
}
|
|
38507
38566
|
const importPostcssImport = createCachedImport(() => import('./dep-e3f470e2.js').then(function (n) { return n.i; }));
|
|
38508
|
-
const importPostcssModules = createCachedImport(() => import('./dep-
|
|
38567
|
+
const importPostcssModules = createCachedImport(() => import('./dep-4190ce4e.js').then(function (n) { return n.i; }));
|
|
38509
38568
|
const importPostcss = createCachedImport(() => import('postcss'));
|
|
38510
38569
|
/**
|
|
38511
38570
|
* @experimental
|
|
@@ -45565,61 +45624,489 @@ function send$2(req, res, content, type, options) {
|
|
|
45565
45624
|
return;
|
|
45566
45625
|
}
|
|
45567
45626
|
|
|
45568
|
-
|
|
45569
|
-
|
|
45570
|
-
|
|
45571
|
-
|
|
45572
|
-
|
|
45573
|
-
|
|
45574
|
-
|
|
45575
|
-
|
|
45576
|
-
|
|
45577
|
-
|
|
45578
|
-
|
|
45579
|
-
'lerna.json',
|
|
45580
|
-
];
|
|
45581
|
-
// npm: https://docs.npmjs.com/cli/v7/using-npm/workspaces#installing-workspaces
|
|
45582
|
-
// yarn: https://classic.yarnpkg.com/en/docs/workspaces/#toc-how-to-use-it
|
|
45583
|
-
function hasWorkspacePackageJSON(root) {
|
|
45584
|
-
const path = join$2(root, 'package.json');
|
|
45585
|
-
if (!isFileReadable(path)) {
|
|
45586
|
-
return false;
|
|
45587
|
-
}
|
|
45588
|
-
const content = JSON.parse(fs$l.readFileSync(path, 'utf-8')) || {};
|
|
45589
|
-
return !!content.workspaces;
|
|
45627
|
+
function totalist(dir, callback, pre='') {
|
|
45628
|
+
dir = resolve$3('.', dir);
|
|
45629
|
+
let arr = readdirSync(dir);
|
|
45630
|
+
let i=0, abs, stats;
|
|
45631
|
+
for (; i < arr.length; i++) {
|
|
45632
|
+
abs = join$1(dir, arr[i]);
|
|
45633
|
+
stats = statSync$1(abs);
|
|
45634
|
+
stats.isDirectory()
|
|
45635
|
+
? totalist(abs, callback, join$1(pre, arr[i]))
|
|
45636
|
+
: callback(join$1(pre, arr[i]), abs, stats);
|
|
45637
|
+
}
|
|
45590
45638
|
}
|
|
45591
|
-
|
|
45592
|
-
|
|
45639
|
+
|
|
45640
|
+
/**
|
|
45641
|
+
* @typedef ParsedURL
|
|
45642
|
+
* @type {import('.').ParsedURL}
|
|
45643
|
+
*/
|
|
45644
|
+
|
|
45645
|
+
/**
|
|
45646
|
+
* @typedef Request
|
|
45647
|
+
* @property {string} url
|
|
45648
|
+
* @property {ParsedURL} _parsedUrl
|
|
45649
|
+
*/
|
|
45650
|
+
|
|
45651
|
+
/**
|
|
45652
|
+
* @param {Request} req
|
|
45653
|
+
* @returns {ParsedURL|void}
|
|
45654
|
+
*/
|
|
45655
|
+
function parse$8(req) {
|
|
45656
|
+
let raw = req.url;
|
|
45657
|
+
if (raw == null) return;
|
|
45658
|
+
|
|
45659
|
+
let prev = req._parsedUrl;
|
|
45660
|
+
if (prev && prev.raw === raw) return prev;
|
|
45661
|
+
|
|
45662
|
+
let pathname=raw, search='', query;
|
|
45663
|
+
|
|
45664
|
+
if (raw.length > 1) {
|
|
45665
|
+
let idx = raw.indexOf('?', 1);
|
|
45666
|
+
|
|
45667
|
+
if (idx !== -1) {
|
|
45668
|
+
search = raw.substring(idx);
|
|
45669
|
+
pathname = raw.substring(0, idx);
|
|
45670
|
+
if (search.length > 1) {
|
|
45671
|
+
query = qs.parse(search.substring(1));
|
|
45672
|
+
}
|
|
45673
|
+
}
|
|
45674
|
+
}
|
|
45675
|
+
|
|
45676
|
+
return req._parsedUrl = { pathname, search, query, raw };
|
|
45593
45677
|
}
|
|
45594
|
-
|
|
45595
|
-
|
|
45596
|
-
|
|
45678
|
+
|
|
45679
|
+
const noop$2 = () => {};
|
|
45680
|
+
|
|
45681
|
+
function isMatch(uri, arr) {
|
|
45682
|
+
for (let i=0; i < arr.length; i++) {
|
|
45683
|
+
if (arr[i].test(uri)) return true;
|
|
45684
|
+
}
|
|
45685
|
+
}
|
|
45686
|
+
|
|
45687
|
+
function toAssume(uri, extns) {
|
|
45688
|
+
let i=0, x, len=uri.length - 1;
|
|
45689
|
+
if (uri.charCodeAt(len) === 47) {
|
|
45690
|
+
uri = uri.substring(0, len);
|
|
45691
|
+
}
|
|
45692
|
+
|
|
45693
|
+
let arr=[], tmp=`${uri}/index`;
|
|
45694
|
+
for (; i < extns.length; i++) {
|
|
45695
|
+
x = extns[i] ? `.${extns[i]}` : '';
|
|
45696
|
+
if (uri) arr.push(uri + x);
|
|
45697
|
+
arr.push(tmp + x);
|
|
45698
|
+
}
|
|
45699
|
+
|
|
45700
|
+
return arr;
|
|
45701
|
+
}
|
|
45702
|
+
|
|
45703
|
+
function viaCache(cache, uri, extns) {
|
|
45704
|
+
let i=0, data, arr=toAssume(uri, extns);
|
|
45705
|
+
for (; i < arr.length; i++) {
|
|
45706
|
+
if (data = cache[arr[i]]) return data;
|
|
45707
|
+
}
|
|
45597
45708
|
}
|
|
45709
|
+
|
|
45710
|
+
function viaLocal(dir, isEtag, uri, extns, shouldServe) {
|
|
45711
|
+
let i=0, arr=toAssume(uri, extns);
|
|
45712
|
+
let abs, stats, name, headers;
|
|
45713
|
+
for (; i < arr.length; i++) {
|
|
45714
|
+
abs = normalize(join$1(dir, name=arr[i]));
|
|
45715
|
+
if (abs.startsWith(dir) && require$$0$2.existsSync(abs)) {
|
|
45716
|
+
stats = require$$0$2.statSync(abs);
|
|
45717
|
+
if (stats.isDirectory()) continue;
|
|
45718
|
+
if (shouldServe && !shouldServe(abs)) continue;
|
|
45719
|
+
headers = toHeaders(name, stats, isEtag);
|
|
45720
|
+
headers['Cache-Control'] = isEtag ? 'no-cache' : 'no-store';
|
|
45721
|
+
return { abs, stats, headers };
|
|
45722
|
+
}
|
|
45723
|
+
}
|
|
45724
|
+
}
|
|
45725
|
+
|
|
45726
|
+
function is404(req, res) {
|
|
45727
|
+
return (res.statusCode=404,res.end());
|
|
45728
|
+
}
|
|
45729
|
+
|
|
45730
|
+
function send$1(req, res, file, stats, headers) {
|
|
45731
|
+
let code=200, tmp, opts={};
|
|
45732
|
+
headers = { ...headers };
|
|
45733
|
+
|
|
45734
|
+
for (let key in headers) {
|
|
45735
|
+
tmp = res.getHeader(key);
|
|
45736
|
+
if (tmp) headers[key] = tmp;
|
|
45737
|
+
}
|
|
45738
|
+
|
|
45739
|
+
if (tmp = res.getHeader('content-type')) {
|
|
45740
|
+
headers['Content-Type'] = tmp;
|
|
45741
|
+
}
|
|
45742
|
+
|
|
45743
|
+
if (req.headers.range) {
|
|
45744
|
+
code = 206;
|
|
45745
|
+
let [x, y] = req.headers.range.replace('bytes=', '').split('-');
|
|
45746
|
+
let end = opts.end = parseInt(y, 10) || stats.size - 1;
|
|
45747
|
+
let start = opts.start = parseInt(x, 10) || 0;
|
|
45748
|
+
|
|
45749
|
+
if (start >= stats.size || end >= stats.size) {
|
|
45750
|
+
res.setHeader('Content-Range', `bytes */${stats.size}`);
|
|
45751
|
+
res.statusCode = 416;
|
|
45752
|
+
return res.end();
|
|
45753
|
+
}
|
|
45754
|
+
|
|
45755
|
+
headers['Content-Range'] = `bytes ${start}-${end}/${stats.size}`;
|
|
45756
|
+
headers['Content-Length'] = (end - start + 1);
|
|
45757
|
+
headers['Accept-Ranges'] = 'bytes';
|
|
45758
|
+
}
|
|
45759
|
+
|
|
45760
|
+
res.writeHead(code, headers);
|
|
45761
|
+
require$$0$2.createReadStream(file, opts).pipe(res);
|
|
45762
|
+
}
|
|
45763
|
+
|
|
45764
|
+
const ENCODING = {
|
|
45765
|
+
'.br': 'br',
|
|
45766
|
+
'.gz': 'gzip',
|
|
45767
|
+
};
|
|
45768
|
+
|
|
45769
|
+
function toHeaders(name, stats, isEtag) {
|
|
45770
|
+
let enc = ENCODING[name.slice(-3)];
|
|
45771
|
+
|
|
45772
|
+
let ctype = lookup(name.slice(0, enc && -3)) || '';
|
|
45773
|
+
if (ctype === 'text/html') ctype += ';charset=utf-8';
|
|
45774
|
+
|
|
45775
|
+
let headers = {
|
|
45776
|
+
'Content-Length': stats.size,
|
|
45777
|
+
'Content-Type': ctype,
|
|
45778
|
+
'Last-Modified': stats.mtime.toUTCString(),
|
|
45779
|
+
};
|
|
45780
|
+
|
|
45781
|
+
if (enc) headers['Content-Encoding'] = enc;
|
|
45782
|
+
if (isEtag) headers['ETag'] = `W/"${stats.size}-${stats.mtime.getTime()}"`;
|
|
45783
|
+
|
|
45784
|
+
return headers;
|
|
45785
|
+
}
|
|
45786
|
+
|
|
45787
|
+
function sirv (dir, opts={}) {
|
|
45788
|
+
dir = resolve$3(dir || '.');
|
|
45789
|
+
|
|
45790
|
+
let isNotFound = opts.onNoMatch || is404;
|
|
45791
|
+
let setHeaders = opts.setHeaders || noop$2;
|
|
45792
|
+
|
|
45793
|
+
let extensions = opts.extensions || ['html', 'htm'];
|
|
45794
|
+
let gzips = opts.gzip && extensions.map(x => `${x}.gz`).concat('gz');
|
|
45795
|
+
let brots = opts.brotli && extensions.map(x => `${x}.br`).concat('br');
|
|
45796
|
+
|
|
45797
|
+
const FILES = {};
|
|
45798
|
+
|
|
45799
|
+
let fallback = '/';
|
|
45800
|
+
let isEtag = !!opts.etag;
|
|
45801
|
+
let isSPA = !!opts.single;
|
|
45802
|
+
if (typeof opts.single === 'string') {
|
|
45803
|
+
let idx = opts.single.lastIndexOf('.');
|
|
45804
|
+
fallback += !!~idx ? opts.single.substring(0, idx) : opts.single;
|
|
45805
|
+
}
|
|
45806
|
+
|
|
45807
|
+
let ignores = [];
|
|
45808
|
+
if (opts.ignores !== false) {
|
|
45809
|
+
ignores.push(/[/]([A-Za-z\s\d~$._-]+\.\w+){1,}$/); // any extn
|
|
45810
|
+
if (opts.dotfiles) ignores.push(/\/\.\w/);
|
|
45811
|
+
else ignores.push(/\/\.well-known/);
|
|
45812
|
+
[].concat(opts.ignores || []).forEach(x => {
|
|
45813
|
+
ignores.push(new RegExp(x, 'i'));
|
|
45814
|
+
});
|
|
45815
|
+
}
|
|
45816
|
+
|
|
45817
|
+
let cc = opts.maxAge != null && `public,max-age=${opts.maxAge}`;
|
|
45818
|
+
if (cc && opts.immutable) cc += ',immutable';
|
|
45819
|
+
else if (cc && opts.maxAge === 0) cc += ',must-revalidate';
|
|
45820
|
+
|
|
45821
|
+
if (!opts.dev) {
|
|
45822
|
+
totalist(dir, (name, abs, stats) => {
|
|
45823
|
+
if (/\.well-known[\\+\/]/.test(name)) ; // keep
|
|
45824
|
+
else if (!opts.dotfiles && /(^\.|[\\+|\/+]\.)/.test(name)) return;
|
|
45825
|
+
|
|
45826
|
+
let headers = toHeaders(name, stats, isEtag);
|
|
45827
|
+
if (cc) headers['Cache-Control'] = cc;
|
|
45828
|
+
|
|
45829
|
+
FILES['/' + name.normalize().replace(/\\+/g, '/')] = { abs, stats, headers };
|
|
45830
|
+
});
|
|
45831
|
+
}
|
|
45832
|
+
|
|
45833
|
+
let lookup = opts.dev ? viaLocal.bind(0, dir, isEtag) : viaCache.bind(0, FILES);
|
|
45834
|
+
|
|
45835
|
+
return function (req, res, next) {
|
|
45836
|
+
let extns = [''];
|
|
45837
|
+
let pathname = parse$8(req).pathname;
|
|
45838
|
+
let val = req.headers['accept-encoding'] || '';
|
|
45839
|
+
if (gzips && val.includes('gzip')) extns.unshift(...gzips);
|
|
45840
|
+
if (brots && /(br|brotli)/i.test(val)) extns.unshift(...brots);
|
|
45841
|
+
extns.push(...extensions); // [...br, ...gz, orig, ...exts]
|
|
45842
|
+
|
|
45843
|
+
if (pathname.indexOf('%') !== -1) {
|
|
45844
|
+
try { pathname = decodeURIComponent(pathname); }
|
|
45845
|
+
catch (err) { /* malform uri */ }
|
|
45846
|
+
}
|
|
45847
|
+
|
|
45848
|
+
let data = lookup(pathname, extns, opts.shouldServe) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns, opts.shouldServe);
|
|
45849
|
+
if (!data) return next ? next() : isNotFound(req, res);
|
|
45850
|
+
|
|
45851
|
+
if (isEtag && req.headers['if-none-match'] === data.headers['ETag']) {
|
|
45852
|
+
res.writeHead(304);
|
|
45853
|
+
return res.end();
|
|
45854
|
+
}
|
|
45855
|
+
|
|
45856
|
+
if (gzips || brots) {
|
|
45857
|
+
res.setHeader('Vary', 'Accept-Encoding');
|
|
45858
|
+
}
|
|
45859
|
+
|
|
45860
|
+
setHeaders(res, pathname, data.stats);
|
|
45861
|
+
send$1(req, res, data.abs, data.stats, data.headers);
|
|
45862
|
+
};
|
|
45863
|
+
}
|
|
45864
|
+
|
|
45865
|
+
/*!
|
|
45866
|
+
* escape-html
|
|
45867
|
+
* Copyright(c) 2012-2013 TJ Holowaychuk
|
|
45868
|
+
* Copyright(c) 2015 Andreas Lubbe
|
|
45869
|
+
* Copyright(c) 2015 Tiancheng "Timothy" Gu
|
|
45870
|
+
* MIT Licensed
|
|
45871
|
+
*/
|
|
45872
|
+
|
|
45598
45873
|
/**
|
|
45599
|
-
*
|
|
45874
|
+
* Module variables.
|
|
45875
|
+
* @private
|
|
45600
45876
|
*/
|
|
45601
|
-
|
|
45602
|
-
|
|
45603
|
-
|
|
45604
|
-
|
|
45605
|
-
|
|
45606
|
-
|
|
45607
|
-
|
|
45608
|
-
|
|
45877
|
+
|
|
45878
|
+
var matchHtmlRegExp = /["'&<>]/;
|
|
45879
|
+
|
|
45880
|
+
/**
|
|
45881
|
+
* Module exports.
|
|
45882
|
+
* @public
|
|
45883
|
+
*/
|
|
45884
|
+
|
|
45885
|
+
var escapeHtml_1 = escapeHtml$1;
|
|
45886
|
+
|
|
45887
|
+
/**
|
|
45888
|
+
* Escape special characters in the given string of html.
|
|
45889
|
+
*
|
|
45890
|
+
* @param {string} string The string to escape for inserting into HTML
|
|
45891
|
+
* @return {string}
|
|
45892
|
+
* @public
|
|
45893
|
+
*/
|
|
45894
|
+
|
|
45895
|
+
function escapeHtml$1(string) {
|
|
45896
|
+
var str = '' + string;
|
|
45897
|
+
var match = matchHtmlRegExp.exec(str);
|
|
45898
|
+
|
|
45899
|
+
if (!match) {
|
|
45900
|
+
return str;
|
|
45901
|
+
}
|
|
45902
|
+
|
|
45903
|
+
var escape;
|
|
45904
|
+
var html = '';
|
|
45905
|
+
var index = 0;
|
|
45906
|
+
var lastIndex = 0;
|
|
45907
|
+
|
|
45908
|
+
for (index = match.index; index < str.length; index++) {
|
|
45909
|
+
switch (str.charCodeAt(index)) {
|
|
45910
|
+
case 34: // "
|
|
45911
|
+
escape = '"';
|
|
45912
|
+
break;
|
|
45913
|
+
case 38: // &
|
|
45914
|
+
escape = '&';
|
|
45915
|
+
break;
|
|
45916
|
+
case 39: // '
|
|
45917
|
+
escape = ''';
|
|
45918
|
+
break;
|
|
45919
|
+
case 60: // <
|
|
45920
|
+
escape = '<';
|
|
45921
|
+
break;
|
|
45922
|
+
case 62: // >
|
|
45923
|
+
escape = '>';
|
|
45924
|
+
break;
|
|
45925
|
+
default:
|
|
45926
|
+
continue;
|
|
45927
|
+
}
|
|
45928
|
+
|
|
45929
|
+
if (lastIndex !== index) {
|
|
45930
|
+
html += str.substring(lastIndex, index);
|
|
45931
|
+
}
|
|
45932
|
+
|
|
45933
|
+
lastIndex = index + 1;
|
|
45934
|
+
html += escape;
|
|
45935
|
+
}
|
|
45936
|
+
|
|
45937
|
+
return lastIndex !== index
|
|
45938
|
+
? html + str.substring(lastIndex, index)
|
|
45939
|
+
: html;
|
|
45940
|
+
}
|
|
45941
|
+
|
|
45942
|
+
const knownJavascriptExtensionRE = /\.[tj]sx?$/;
|
|
45943
|
+
const sirvOptions = ({ headers, shouldServe, }) => {
|
|
45944
|
+
return {
|
|
45945
|
+
dev: true,
|
|
45946
|
+
etag: true,
|
|
45947
|
+
extensions: [],
|
|
45948
|
+
setHeaders(res, pathname) {
|
|
45949
|
+
// Matches js, jsx, ts, tsx.
|
|
45950
|
+
// The reason this is done, is that the .ts file extension is reserved
|
|
45951
|
+
// for the MIME type video/mp2t. In almost all cases, we can expect
|
|
45952
|
+
// these files to be TypeScript files, and for Vite to serve them with
|
|
45953
|
+
// this Content-Type.
|
|
45954
|
+
if (knownJavascriptExtensionRE.test(pathname)) {
|
|
45955
|
+
res.setHeader('Content-Type', 'application/javascript');
|
|
45956
|
+
}
|
|
45957
|
+
if (headers) {
|
|
45958
|
+
for (const name in headers) {
|
|
45959
|
+
res.setHeader(name, headers[name]);
|
|
45960
|
+
}
|
|
45961
|
+
}
|
|
45962
|
+
},
|
|
45963
|
+
shouldServe,
|
|
45964
|
+
};
|
|
45965
|
+
};
|
|
45966
|
+
function servePublicMiddleware(dir, headers) {
|
|
45967
|
+
const serve = sirv(dir, sirvOptions({
|
|
45968
|
+
headers,
|
|
45969
|
+
shouldServe: (filePath) => shouldServeFile(filePath, dir),
|
|
45970
|
+
}));
|
|
45971
|
+
// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
|
|
45972
|
+
return function viteServePublicMiddleware(req, res, next) {
|
|
45973
|
+
// skip import request and internal requests `/@fs/ /@vite-client` etc...
|
|
45974
|
+
if (isImportRequest(req.url) || isInternalRequest(req.url)) {
|
|
45975
|
+
return next();
|
|
45976
|
+
}
|
|
45977
|
+
serve(req, res, next);
|
|
45978
|
+
};
|
|
45979
|
+
}
|
|
45980
|
+
function serveStaticMiddleware(dir, server) {
|
|
45981
|
+
const serve = sirv(dir, sirvOptions({
|
|
45982
|
+
headers: server.config.server.headers,
|
|
45983
|
+
}));
|
|
45984
|
+
// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
|
|
45985
|
+
return function viteServeStaticMiddleware(req, res, next) {
|
|
45986
|
+
// only serve the file if it's not an html request or ends with `/`
|
|
45987
|
+
// so that html requests can fallthrough to our html middleware for
|
|
45988
|
+
// special processing
|
|
45989
|
+
// also skip internal requests `/@fs/ /@vite-client` etc...
|
|
45990
|
+
const cleanedUrl = cleanUrl(req.url);
|
|
45991
|
+
if (cleanedUrl[cleanedUrl.length - 1] === '/' ||
|
|
45992
|
+
path$o.extname(cleanedUrl) === '.html' ||
|
|
45993
|
+
isInternalRequest(req.url)) {
|
|
45994
|
+
return next();
|
|
45995
|
+
}
|
|
45996
|
+
const url = new URL(req.url, 'http://example.com');
|
|
45997
|
+
const pathname = decodeURIComponent(url.pathname);
|
|
45998
|
+
// apply aliases to static requests as well
|
|
45999
|
+
let redirectedPathname;
|
|
46000
|
+
for (const { find, replacement } of server.config.resolve.alias) {
|
|
46001
|
+
const matches = typeof find === 'string'
|
|
46002
|
+
? pathname.startsWith(find)
|
|
46003
|
+
: find.test(pathname);
|
|
46004
|
+
if (matches) {
|
|
46005
|
+
redirectedPathname = pathname.replace(find, replacement);
|
|
46006
|
+
break;
|
|
46007
|
+
}
|
|
46008
|
+
}
|
|
46009
|
+
if (redirectedPathname) {
|
|
46010
|
+
// dir is pre-normalized to posix style
|
|
46011
|
+
if (redirectedPathname.startsWith(dir)) {
|
|
46012
|
+
redirectedPathname = redirectedPathname.slice(dir.length);
|
|
46013
|
+
}
|
|
46014
|
+
}
|
|
46015
|
+
const resolvedPathname = redirectedPathname || pathname;
|
|
46016
|
+
let fileUrl = path$o.resolve(dir, removeLeadingSlash(resolvedPathname));
|
|
46017
|
+
if (resolvedPathname[resolvedPathname.length - 1] === '/' &&
|
|
46018
|
+
fileUrl[fileUrl.length - 1] !== '/') {
|
|
46019
|
+
fileUrl = fileUrl + '/';
|
|
46020
|
+
}
|
|
46021
|
+
if (!ensureServingAccess(fileUrl, server, res, next)) {
|
|
46022
|
+
return;
|
|
46023
|
+
}
|
|
46024
|
+
if (redirectedPathname) {
|
|
46025
|
+
url.pathname = encodeURIComponent(redirectedPathname);
|
|
46026
|
+
req.url = url.href.slice(url.origin.length);
|
|
46027
|
+
}
|
|
46028
|
+
serve(req, res, next);
|
|
46029
|
+
};
|
|
46030
|
+
}
|
|
46031
|
+
function serveRawFsMiddleware(server) {
|
|
46032
|
+
const serveFromRoot = sirv('/', sirvOptions({ headers: server.config.server.headers }));
|
|
46033
|
+
// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
|
|
46034
|
+
return function viteServeRawFsMiddleware(req, res, next) {
|
|
46035
|
+
const url = new URL(req.url, 'http://example.com');
|
|
46036
|
+
// In some cases (e.g. linked monorepos) files outside of root will
|
|
46037
|
+
// reference assets that are also out of served root. In such cases
|
|
46038
|
+
// the paths are rewritten to `/@fs/` prefixed paths and must be served by
|
|
46039
|
+
// searching based from fs root.
|
|
46040
|
+
if (url.pathname.startsWith(FS_PREFIX)) {
|
|
46041
|
+
const pathname = decodeURIComponent(url.pathname);
|
|
46042
|
+
// restrict files outside of `fs.allow`
|
|
46043
|
+
if (!ensureServingAccess(slash$1(path$o.resolve(fsPathFromId(pathname))), server, res, next)) {
|
|
46044
|
+
return;
|
|
46045
|
+
}
|
|
46046
|
+
let newPathname = pathname.slice(FS_PREFIX.length);
|
|
46047
|
+
if (isWindows$4)
|
|
46048
|
+
newPathname = newPathname.replace(/^[A-Z]:/i, '');
|
|
46049
|
+
url.pathname = encodeURIComponent(newPathname);
|
|
46050
|
+
req.url = url.href.slice(url.origin.length);
|
|
46051
|
+
serveFromRoot(req, res, next);
|
|
46052
|
+
}
|
|
46053
|
+
else {
|
|
46054
|
+
next();
|
|
46055
|
+
}
|
|
46056
|
+
};
|
|
45609
46057
|
}
|
|
45610
46058
|
/**
|
|
45611
|
-
*
|
|
46059
|
+
* Check if the url is allowed to be served, via the `server.fs` config.
|
|
45612
46060
|
*/
|
|
45613
|
-
function
|
|
45614
|
-
if (
|
|
45615
|
-
return
|
|
45616
|
-
|
|
45617
|
-
|
|
45618
|
-
|
|
45619
|
-
|
|
45620
|
-
|
|
45621
|
-
|
|
45622
|
-
|
|
46061
|
+
function isFileServingAllowed(url, server) {
|
|
46062
|
+
if (!server.config.server.fs.strict)
|
|
46063
|
+
return true;
|
|
46064
|
+
const file = fsPathFromUrl(url);
|
|
46065
|
+
if (server._fsDenyGlob(file))
|
|
46066
|
+
return false;
|
|
46067
|
+
if (server.moduleGraph.safeModulesPath.has(file))
|
|
46068
|
+
return true;
|
|
46069
|
+
if (server.config.server.fs.allow.some((dir) => isParentDirectory(dir, file)))
|
|
46070
|
+
return true;
|
|
46071
|
+
return false;
|
|
46072
|
+
}
|
|
46073
|
+
function ensureServingAccess(url, server, res, next) {
|
|
46074
|
+
if (isFileServingAllowed(url, server)) {
|
|
46075
|
+
return true;
|
|
46076
|
+
}
|
|
46077
|
+
if (isFileReadable(cleanUrl(url))) {
|
|
46078
|
+
const urlMessage = `The request url "${url}" is outside of Vite serving allow list.`;
|
|
46079
|
+
const hintMessage = `
|
|
46080
|
+
${server.config.server.fs.allow.map((i) => `- ${i}`).join('\n')}
|
|
46081
|
+
|
|
46082
|
+
Refer to docs https://vitejs.dev/config/server-options.html#server-fs-allow for configurations and more details.`;
|
|
46083
|
+
server.config.logger.error(urlMessage);
|
|
46084
|
+
server.config.logger.warnOnce(hintMessage + '\n');
|
|
46085
|
+
res.statusCode = 403;
|
|
46086
|
+
res.write(renderRestrictedErrorHTML(urlMessage + '\n' + hintMessage));
|
|
46087
|
+
res.end();
|
|
46088
|
+
}
|
|
46089
|
+
else {
|
|
46090
|
+
// if the file doesn't exist, we shouldn't restrict this path as it can
|
|
46091
|
+
// be an API call. Middlewares would issue a 404 if the file isn't handled
|
|
46092
|
+
next();
|
|
46093
|
+
}
|
|
46094
|
+
return false;
|
|
46095
|
+
}
|
|
46096
|
+
function renderRestrictedErrorHTML(msg) {
|
|
46097
|
+
// to have syntax highlighting and autocompletion in IDE
|
|
46098
|
+
const html = String.raw;
|
|
46099
|
+
return html `
|
|
46100
|
+
<body>
|
|
46101
|
+
<h1>403 Restricted</h1>
|
|
46102
|
+
<p>${escapeHtml_1(msg).replace(/\n/g, '<br/>')}</p>
|
|
46103
|
+
<style>
|
|
46104
|
+
body {
|
|
46105
|
+
padding: 1em 2em;
|
|
46106
|
+
}
|
|
46107
|
+
</style>
|
|
46108
|
+
</body>
|
|
46109
|
+
`;
|
|
45623
46110
|
}
|
|
45624
46111
|
|
|
45625
46112
|
function resolveBuildOptions(raw, logger, root) {
|
|
@@ -47213,83 +47700,6 @@ function encodeUrl$1 (url) {
|
|
|
47213
47700
|
.replace(ENCODE_CHARS_REGEXP, encodeURI)
|
|
47214
47701
|
}
|
|
47215
47702
|
|
|
47216
|
-
/*!
|
|
47217
|
-
* escape-html
|
|
47218
|
-
* Copyright(c) 2012-2013 TJ Holowaychuk
|
|
47219
|
-
* Copyright(c) 2015 Andreas Lubbe
|
|
47220
|
-
* Copyright(c) 2015 Tiancheng "Timothy" Gu
|
|
47221
|
-
* MIT Licensed
|
|
47222
|
-
*/
|
|
47223
|
-
|
|
47224
|
-
/**
|
|
47225
|
-
* Module variables.
|
|
47226
|
-
* @private
|
|
47227
|
-
*/
|
|
47228
|
-
|
|
47229
|
-
var matchHtmlRegExp = /["'&<>]/;
|
|
47230
|
-
|
|
47231
|
-
/**
|
|
47232
|
-
* Module exports.
|
|
47233
|
-
* @public
|
|
47234
|
-
*/
|
|
47235
|
-
|
|
47236
|
-
var escapeHtml_1 = escapeHtml$1;
|
|
47237
|
-
|
|
47238
|
-
/**
|
|
47239
|
-
* Escape special characters in the given string of html.
|
|
47240
|
-
*
|
|
47241
|
-
* @param {string} string The string to escape for inserting into HTML
|
|
47242
|
-
* @return {string}
|
|
47243
|
-
* @public
|
|
47244
|
-
*/
|
|
47245
|
-
|
|
47246
|
-
function escapeHtml$1(string) {
|
|
47247
|
-
var str = '' + string;
|
|
47248
|
-
var match = matchHtmlRegExp.exec(str);
|
|
47249
|
-
|
|
47250
|
-
if (!match) {
|
|
47251
|
-
return str;
|
|
47252
|
-
}
|
|
47253
|
-
|
|
47254
|
-
var escape;
|
|
47255
|
-
var html = '';
|
|
47256
|
-
var index = 0;
|
|
47257
|
-
var lastIndex = 0;
|
|
47258
|
-
|
|
47259
|
-
for (index = match.index; index < str.length; index++) {
|
|
47260
|
-
switch (str.charCodeAt(index)) {
|
|
47261
|
-
case 34: // "
|
|
47262
|
-
escape = '"';
|
|
47263
|
-
break;
|
|
47264
|
-
case 38: // &
|
|
47265
|
-
escape = '&';
|
|
47266
|
-
break;
|
|
47267
|
-
case 39: // '
|
|
47268
|
-
escape = ''';
|
|
47269
|
-
break;
|
|
47270
|
-
case 60: // <
|
|
47271
|
-
escape = '<';
|
|
47272
|
-
break;
|
|
47273
|
-
case 62: // >
|
|
47274
|
-
escape = '>';
|
|
47275
|
-
break;
|
|
47276
|
-
default:
|
|
47277
|
-
continue;
|
|
47278
|
-
}
|
|
47279
|
-
|
|
47280
|
-
if (lastIndex !== index) {
|
|
47281
|
-
html += str.substring(lastIndex, index);
|
|
47282
|
-
}
|
|
47283
|
-
|
|
47284
|
-
lastIndex = index + 1;
|
|
47285
|
-
html += escape;
|
|
47286
|
-
}
|
|
47287
|
-
|
|
47288
|
-
return lastIndex !== index
|
|
47289
|
-
? html + str.substring(lastIndex, index)
|
|
47290
|
-
: html;
|
|
47291
|
-
}
|
|
47292
|
-
|
|
47293
47703
|
var onFinishedExports = {};
|
|
47294
47704
|
var onFinished$2 = {
|
|
47295
47705
|
get exports(){ return onFinishedExports; },
|
|
@@ -47604,7 +48014,7 @@ var parseurl$1 = {
|
|
|
47604
48014
|
*/
|
|
47605
48015
|
|
|
47606
48016
|
var url$3 = require$$0$9;
|
|
47607
|
-
var parse$
|
|
48017
|
+
var parse$7 = url$3.parse;
|
|
47608
48018
|
var Url = url$3.Url;
|
|
47609
48019
|
|
|
47610
48020
|
/**
|
|
@@ -47683,7 +48093,7 @@ function originalurl (req) {
|
|
|
47683
48093
|
|
|
47684
48094
|
function fastparse (str) {
|
|
47685
48095
|
if (typeof str !== 'string' || str.charCodeAt(0) !== 0x2f /* / */) {
|
|
47686
|
-
return parse$
|
|
48096
|
+
return parse$7(str)
|
|
47687
48097
|
}
|
|
47688
48098
|
|
|
47689
48099
|
var pathname = str;
|
|
@@ -47710,7 +48120,7 @@ function fastparse (str) {
|
|
|
47710
48120
|
case 0x23: /* # */
|
|
47711
48121
|
case 0xa0:
|
|
47712
48122
|
case 0xfeff:
|
|
47713
|
-
return parse$
|
|
48123
|
+
return parse$7(str)
|
|
47714
48124
|
}
|
|
47715
48125
|
}
|
|
47716
48126
|
|
|
@@ -48123,7 +48533,7 @@ function finalhandler$1 (req, res, options) {
|
|
|
48123
48533
|
}
|
|
48124
48534
|
|
|
48125
48535
|
// send response
|
|
48126
|
-
send
|
|
48536
|
+
send(req, res, status, headers, msg);
|
|
48127
48537
|
}
|
|
48128
48538
|
}
|
|
48129
48539
|
|
|
@@ -48262,7 +48672,7 @@ function headersSent (res) {
|
|
|
48262
48672
|
* @private
|
|
48263
48673
|
*/
|
|
48264
48674
|
|
|
48265
|
-
function send
|
|
48675
|
+
function send (req, res, status, headers, message) {
|
|
48266
48676
|
function write () {
|
|
48267
48677
|
// response body
|
|
48268
48678
|
var body = createHtmlDocument(message);
|
|
@@ -48780,7 +49190,7 @@ function append (header, field) {
|
|
|
48780
49190
|
|
|
48781
49191
|
// get fields array
|
|
48782
49192
|
var fields = !Array.isArray(field)
|
|
48783
|
-
? parse$
|
|
49193
|
+
? parse$6(String(field))
|
|
48784
49194
|
: field;
|
|
48785
49195
|
|
|
48786
49196
|
// assert on invalid field names
|
|
@@ -48797,7 +49207,7 @@ function append (header, field) {
|
|
|
48797
49207
|
|
|
48798
49208
|
// enumerate current values
|
|
48799
49209
|
var val = header;
|
|
48800
|
-
var vals = parse$
|
|
49210
|
+
var vals = parse$6(header.toLowerCase());
|
|
48801
49211
|
|
|
48802
49212
|
// unspecified vary
|
|
48803
49213
|
if (fields.indexOf('*') !== -1 || vals.indexOf('*') !== -1) {
|
|
@@ -48827,7 +49237,7 @@ function append (header, field) {
|
|
|
48827
49237
|
* @private
|
|
48828
49238
|
*/
|
|
48829
49239
|
|
|
48830
|
-
function parse$
|
|
49240
|
+
function parse$6 (header) {
|
|
48831
49241
|
var end = 0;
|
|
48832
49242
|
var list = [];
|
|
48833
49243
|
var start = 0;
|
|
@@ -52079,7 +52489,7 @@ for (var i = 0; i < 4; i++) {
|
|
|
52079
52489
|
}
|
|
52080
52490
|
|
|
52081
52491
|
shellQuote$1.parse = function (s, env, opts) {
|
|
52082
|
-
var mapped = parse$
|
|
52492
|
+
var mapped = parse$5(s, env, opts);
|
|
52083
52493
|
if (typeof env !== 'function') return mapped;
|
|
52084
52494
|
return mapped.reduce(function (acc, s) {
|
|
52085
52495
|
if (typeof s === 'object') return acc.concat(s);
|
|
@@ -52094,7 +52504,7 @@ shellQuote$1.parse = function (s, env, opts) {
|
|
|
52094
52504
|
}, []);
|
|
52095
52505
|
};
|
|
52096
52506
|
|
|
52097
|
-
function parse$
|
|
52507
|
+
function parse$5 (s, env, opts) {
|
|
52098
52508
|
var chunker = new RegExp([
|
|
52099
52509
|
'(' + CONTROL + ')', // control chars
|
|
52100
52510
|
'(' + BAREWORD + '|' + SINGLE_QUOTE + '|' + DOUBLE_QUOTE + ')*'
|
|
@@ -52762,411 +53172,6 @@ function setClientErrorHandler(server, logger) {
|
|
|
52762
53172
|
});
|
|
52763
53173
|
}
|
|
52764
53174
|
|
|
52765
|
-
function totalist(dir, callback, pre='') {
|
|
52766
|
-
dir = resolve$3('.', dir);
|
|
52767
|
-
let arr = readdirSync(dir);
|
|
52768
|
-
let i=0, abs, stats;
|
|
52769
|
-
for (; i < arr.length; i++) {
|
|
52770
|
-
abs = join$1(dir, arr[i]);
|
|
52771
|
-
stats = statSync$1(abs);
|
|
52772
|
-
stats.isDirectory()
|
|
52773
|
-
? totalist(abs, callback, join$1(pre, arr[i]))
|
|
52774
|
-
: callback(join$1(pre, arr[i]), abs, stats);
|
|
52775
|
-
}
|
|
52776
|
-
}
|
|
52777
|
-
|
|
52778
|
-
/**
|
|
52779
|
-
* @typedef ParsedURL
|
|
52780
|
-
* @type {import('.').ParsedURL}
|
|
52781
|
-
*/
|
|
52782
|
-
|
|
52783
|
-
/**
|
|
52784
|
-
* @typedef Request
|
|
52785
|
-
* @property {string} url
|
|
52786
|
-
* @property {ParsedURL} _parsedUrl
|
|
52787
|
-
*/
|
|
52788
|
-
|
|
52789
|
-
/**
|
|
52790
|
-
* @param {Request} req
|
|
52791
|
-
* @returns {ParsedURL|void}
|
|
52792
|
-
*/
|
|
52793
|
-
function parse$5(req) {
|
|
52794
|
-
let raw = req.url;
|
|
52795
|
-
if (raw == null) return;
|
|
52796
|
-
|
|
52797
|
-
let prev = req._parsedUrl;
|
|
52798
|
-
if (prev && prev.raw === raw) return prev;
|
|
52799
|
-
|
|
52800
|
-
let pathname=raw, search='', query;
|
|
52801
|
-
|
|
52802
|
-
if (raw.length > 1) {
|
|
52803
|
-
let idx = raw.indexOf('?', 1);
|
|
52804
|
-
|
|
52805
|
-
if (idx !== -1) {
|
|
52806
|
-
search = raw.substring(idx);
|
|
52807
|
-
pathname = raw.substring(0, idx);
|
|
52808
|
-
if (search.length > 1) {
|
|
52809
|
-
query = qs.parse(search.substring(1));
|
|
52810
|
-
}
|
|
52811
|
-
}
|
|
52812
|
-
}
|
|
52813
|
-
|
|
52814
|
-
return req._parsedUrl = { pathname, search, query, raw };
|
|
52815
|
-
}
|
|
52816
|
-
|
|
52817
|
-
const noop$2 = () => {};
|
|
52818
|
-
|
|
52819
|
-
function isMatch(uri, arr) {
|
|
52820
|
-
for (let i=0; i < arr.length; i++) {
|
|
52821
|
-
if (arr[i].test(uri)) return true;
|
|
52822
|
-
}
|
|
52823
|
-
}
|
|
52824
|
-
|
|
52825
|
-
function toAssume(uri, extns) {
|
|
52826
|
-
let i=0, x, len=uri.length - 1;
|
|
52827
|
-
if (uri.charCodeAt(len) === 47) {
|
|
52828
|
-
uri = uri.substring(0, len);
|
|
52829
|
-
}
|
|
52830
|
-
|
|
52831
|
-
let arr=[], tmp=`${uri}/index`;
|
|
52832
|
-
for (; i < extns.length; i++) {
|
|
52833
|
-
x = extns[i] ? `.${extns[i]}` : '';
|
|
52834
|
-
if (uri) arr.push(uri + x);
|
|
52835
|
-
arr.push(tmp + x);
|
|
52836
|
-
}
|
|
52837
|
-
|
|
52838
|
-
return arr;
|
|
52839
|
-
}
|
|
52840
|
-
|
|
52841
|
-
function viaCache(cache, uri, extns) {
|
|
52842
|
-
let i=0, data, arr=toAssume(uri, extns);
|
|
52843
|
-
for (; i < arr.length; i++) {
|
|
52844
|
-
if (data = cache[arr[i]]) return data;
|
|
52845
|
-
}
|
|
52846
|
-
}
|
|
52847
|
-
|
|
52848
|
-
function viaLocal(dir, isEtag, uri, extns, shouldServe) {
|
|
52849
|
-
let i=0, arr=toAssume(uri, extns);
|
|
52850
|
-
let abs, stats, name, headers;
|
|
52851
|
-
for (; i < arr.length; i++) {
|
|
52852
|
-
abs = normalize(join$1(dir, name=arr[i]));
|
|
52853
|
-
if (abs.startsWith(dir) && require$$0$2.existsSync(abs)) {
|
|
52854
|
-
stats = require$$0$2.statSync(abs);
|
|
52855
|
-
if (stats.isDirectory()) continue;
|
|
52856
|
-
if (shouldServe && !shouldServe(abs)) continue;
|
|
52857
|
-
headers = toHeaders(name, stats, isEtag);
|
|
52858
|
-
headers['Cache-Control'] = isEtag ? 'no-cache' : 'no-store';
|
|
52859
|
-
return { abs, stats, headers };
|
|
52860
|
-
}
|
|
52861
|
-
}
|
|
52862
|
-
}
|
|
52863
|
-
|
|
52864
|
-
function is404(req, res) {
|
|
52865
|
-
return (res.statusCode=404,res.end());
|
|
52866
|
-
}
|
|
52867
|
-
|
|
52868
|
-
function send(req, res, file, stats, headers) {
|
|
52869
|
-
let code=200, tmp, opts={};
|
|
52870
|
-
headers = { ...headers };
|
|
52871
|
-
|
|
52872
|
-
for (let key in headers) {
|
|
52873
|
-
tmp = res.getHeader(key);
|
|
52874
|
-
if (tmp) headers[key] = tmp;
|
|
52875
|
-
}
|
|
52876
|
-
|
|
52877
|
-
if (tmp = res.getHeader('content-type')) {
|
|
52878
|
-
headers['Content-Type'] = tmp;
|
|
52879
|
-
}
|
|
52880
|
-
|
|
52881
|
-
if (req.headers.range) {
|
|
52882
|
-
code = 206;
|
|
52883
|
-
let [x, y] = req.headers.range.replace('bytes=', '').split('-');
|
|
52884
|
-
let end = opts.end = parseInt(y, 10) || stats.size - 1;
|
|
52885
|
-
let start = opts.start = parseInt(x, 10) || 0;
|
|
52886
|
-
|
|
52887
|
-
if (start >= stats.size || end >= stats.size) {
|
|
52888
|
-
res.setHeader('Content-Range', `bytes */${stats.size}`);
|
|
52889
|
-
res.statusCode = 416;
|
|
52890
|
-
return res.end();
|
|
52891
|
-
}
|
|
52892
|
-
|
|
52893
|
-
headers['Content-Range'] = `bytes ${start}-${end}/${stats.size}`;
|
|
52894
|
-
headers['Content-Length'] = (end - start + 1);
|
|
52895
|
-
headers['Accept-Ranges'] = 'bytes';
|
|
52896
|
-
}
|
|
52897
|
-
|
|
52898
|
-
res.writeHead(code, headers);
|
|
52899
|
-
require$$0$2.createReadStream(file, opts).pipe(res);
|
|
52900
|
-
}
|
|
52901
|
-
|
|
52902
|
-
const ENCODING = {
|
|
52903
|
-
'.br': 'br',
|
|
52904
|
-
'.gz': 'gzip',
|
|
52905
|
-
};
|
|
52906
|
-
|
|
52907
|
-
function toHeaders(name, stats, isEtag) {
|
|
52908
|
-
let enc = ENCODING[name.slice(-3)];
|
|
52909
|
-
|
|
52910
|
-
let ctype = lookup(name.slice(0, enc && -3)) || '';
|
|
52911
|
-
if (ctype === 'text/html') ctype += ';charset=utf-8';
|
|
52912
|
-
|
|
52913
|
-
let headers = {
|
|
52914
|
-
'Content-Length': stats.size,
|
|
52915
|
-
'Content-Type': ctype,
|
|
52916
|
-
'Last-Modified': stats.mtime.toUTCString(),
|
|
52917
|
-
};
|
|
52918
|
-
|
|
52919
|
-
if (enc) headers['Content-Encoding'] = enc;
|
|
52920
|
-
if (isEtag) headers['ETag'] = `W/"${stats.size}-${stats.mtime.getTime()}"`;
|
|
52921
|
-
|
|
52922
|
-
return headers;
|
|
52923
|
-
}
|
|
52924
|
-
|
|
52925
|
-
function sirv (dir, opts={}) {
|
|
52926
|
-
dir = resolve$3(dir || '.');
|
|
52927
|
-
|
|
52928
|
-
let isNotFound = opts.onNoMatch || is404;
|
|
52929
|
-
let setHeaders = opts.setHeaders || noop$2;
|
|
52930
|
-
|
|
52931
|
-
let extensions = opts.extensions || ['html', 'htm'];
|
|
52932
|
-
let gzips = opts.gzip && extensions.map(x => `${x}.gz`).concat('gz');
|
|
52933
|
-
let brots = opts.brotli && extensions.map(x => `${x}.br`).concat('br');
|
|
52934
|
-
|
|
52935
|
-
const FILES = {};
|
|
52936
|
-
|
|
52937
|
-
let fallback = '/';
|
|
52938
|
-
let isEtag = !!opts.etag;
|
|
52939
|
-
let isSPA = !!opts.single;
|
|
52940
|
-
if (typeof opts.single === 'string') {
|
|
52941
|
-
let idx = opts.single.lastIndexOf('.');
|
|
52942
|
-
fallback += !!~idx ? opts.single.substring(0, idx) : opts.single;
|
|
52943
|
-
}
|
|
52944
|
-
|
|
52945
|
-
let ignores = [];
|
|
52946
|
-
if (opts.ignores !== false) {
|
|
52947
|
-
ignores.push(/[/]([A-Za-z\s\d~$._-]+\.\w+){1,}$/); // any extn
|
|
52948
|
-
if (opts.dotfiles) ignores.push(/\/\.\w/);
|
|
52949
|
-
else ignores.push(/\/\.well-known/);
|
|
52950
|
-
[].concat(opts.ignores || []).forEach(x => {
|
|
52951
|
-
ignores.push(new RegExp(x, 'i'));
|
|
52952
|
-
});
|
|
52953
|
-
}
|
|
52954
|
-
|
|
52955
|
-
let cc = opts.maxAge != null && `public,max-age=${opts.maxAge}`;
|
|
52956
|
-
if (cc && opts.immutable) cc += ',immutable';
|
|
52957
|
-
else if (cc && opts.maxAge === 0) cc += ',must-revalidate';
|
|
52958
|
-
|
|
52959
|
-
if (!opts.dev) {
|
|
52960
|
-
totalist(dir, (name, abs, stats) => {
|
|
52961
|
-
if (/\.well-known[\\+\/]/.test(name)) ; // keep
|
|
52962
|
-
else if (!opts.dotfiles && /(^\.|[\\+|\/+]\.)/.test(name)) return;
|
|
52963
|
-
|
|
52964
|
-
let headers = toHeaders(name, stats, isEtag);
|
|
52965
|
-
if (cc) headers['Cache-Control'] = cc;
|
|
52966
|
-
|
|
52967
|
-
FILES['/' + name.normalize().replace(/\\+/g, '/')] = { abs, stats, headers };
|
|
52968
|
-
});
|
|
52969
|
-
}
|
|
52970
|
-
|
|
52971
|
-
let lookup = opts.dev ? viaLocal.bind(0, dir, isEtag) : viaCache.bind(0, FILES);
|
|
52972
|
-
|
|
52973
|
-
return function (req, res, next) {
|
|
52974
|
-
let extns = [''];
|
|
52975
|
-
let pathname = parse$5(req).pathname;
|
|
52976
|
-
let val = req.headers['accept-encoding'] || '';
|
|
52977
|
-
if (gzips && val.includes('gzip')) extns.unshift(...gzips);
|
|
52978
|
-
if (brots && /(br|brotli)/i.test(val)) extns.unshift(...brots);
|
|
52979
|
-
extns.push(...extensions); // [...br, ...gz, orig, ...exts]
|
|
52980
|
-
|
|
52981
|
-
if (pathname.indexOf('%') !== -1) {
|
|
52982
|
-
try { pathname = decodeURIComponent(pathname); }
|
|
52983
|
-
catch (err) { /* malform uri */ }
|
|
52984
|
-
}
|
|
52985
|
-
|
|
52986
|
-
let data = lookup(pathname, extns, opts.shouldServe) || isSPA && !isMatch(pathname, ignores) && lookup(fallback, extns, opts.shouldServe);
|
|
52987
|
-
if (!data) return next ? next() : isNotFound(req, res);
|
|
52988
|
-
|
|
52989
|
-
if (isEtag && req.headers['if-none-match'] === data.headers['ETag']) {
|
|
52990
|
-
res.writeHead(304);
|
|
52991
|
-
return res.end();
|
|
52992
|
-
}
|
|
52993
|
-
|
|
52994
|
-
if (gzips || brots) {
|
|
52995
|
-
res.setHeader('Vary', 'Accept-Encoding');
|
|
52996
|
-
}
|
|
52997
|
-
|
|
52998
|
-
setHeaders(res, pathname, data.stats);
|
|
52999
|
-
send(req, res, data.abs, data.stats, data.headers);
|
|
53000
|
-
};
|
|
53001
|
-
}
|
|
53002
|
-
|
|
53003
|
-
const knownJavascriptExtensionRE = /\.[tj]sx?$/;
|
|
53004
|
-
const sirvOptions = ({ headers, shouldServe, }) => {
|
|
53005
|
-
return {
|
|
53006
|
-
dev: true,
|
|
53007
|
-
etag: true,
|
|
53008
|
-
extensions: [],
|
|
53009
|
-
setHeaders(res, pathname) {
|
|
53010
|
-
// Matches js, jsx, ts, tsx.
|
|
53011
|
-
// The reason this is done, is that the .ts file extension is reserved
|
|
53012
|
-
// for the MIME type video/mp2t. In almost all cases, we can expect
|
|
53013
|
-
// these files to be TypeScript files, and for Vite to serve them with
|
|
53014
|
-
// this Content-Type.
|
|
53015
|
-
if (knownJavascriptExtensionRE.test(pathname)) {
|
|
53016
|
-
res.setHeader('Content-Type', 'application/javascript');
|
|
53017
|
-
}
|
|
53018
|
-
if (headers) {
|
|
53019
|
-
for (const name in headers) {
|
|
53020
|
-
res.setHeader(name, headers[name]);
|
|
53021
|
-
}
|
|
53022
|
-
}
|
|
53023
|
-
},
|
|
53024
|
-
shouldServe,
|
|
53025
|
-
};
|
|
53026
|
-
};
|
|
53027
|
-
function servePublicMiddleware(dir, headers) {
|
|
53028
|
-
const serve = sirv(dir, sirvOptions({
|
|
53029
|
-
headers,
|
|
53030
|
-
shouldServe: (filePath) => shouldServeFile(filePath, dir),
|
|
53031
|
-
}));
|
|
53032
|
-
// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
|
|
53033
|
-
return function viteServePublicMiddleware(req, res, next) {
|
|
53034
|
-
// skip import request and internal requests `/@fs/ /@vite-client` etc...
|
|
53035
|
-
if (isImportRequest(req.url) || isInternalRequest(req.url)) {
|
|
53036
|
-
return next();
|
|
53037
|
-
}
|
|
53038
|
-
serve(req, res, next);
|
|
53039
|
-
};
|
|
53040
|
-
}
|
|
53041
|
-
function serveStaticMiddleware(dir, server) {
|
|
53042
|
-
const serve = sirv(dir, sirvOptions({
|
|
53043
|
-
headers: server.config.server.headers,
|
|
53044
|
-
}));
|
|
53045
|
-
// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
|
|
53046
|
-
return function viteServeStaticMiddleware(req, res, next) {
|
|
53047
|
-
// only serve the file if it's not an html request or ends with `/`
|
|
53048
|
-
// so that html requests can fallthrough to our html middleware for
|
|
53049
|
-
// special processing
|
|
53050
|
-
// also skip internal requests `/@fs/ /@vite-client` etc...
|
|
53051
|
-
const cleanedUrl = cleanUrl(req.url);
|
|
53052
|
-
if (cleanedUrl[cleanedUrl.length - 1] === '/' ||
|
|
53053
|
-
path$o.extname(cleanedUrl) === '.html' ||
|
|
53054
|
-
isInternalRequest(req.url)) {
|
|
53055
|
-
return next();
|
|
53056
|
-
}
|
|
53057
|
-
const url = new URL(req.url, 'http://example.com');
|
|
53058
|
-
const pathname = decodeURIComponent(url.pathname);
|
|
53059
|
-
// apply aliases to static requests as well
|
|
53060
|
-
let redirectedPathname;
|
|
53061
|
-
for (const { find, replacement } of server.config.resolve.alias) {
|
|
53062
|
-
const matches = typeof find === 'string'
|
|
53063
|
-
? pathname.startsWith(find)
|
|
53064
|
-
: find.test(pathname);
|
|
53065
|
-
if (matches) {
|
|
53066
|
-
redirectedPathname = pathname.replace(find, replacement);
|
|
53067
|
-
break;
|
|
53068
|
-
}
|
|
53069
|
-
}
|
|
53070
|
-
if (redirectedPathname) {
|
|
53071
|
-
// dir is pre-normalized to posix style
|
|
53072
|
-
if (redirectedPathname.startsWith(dir)) {
|
|
53073
|
-
redirectedPathname = redirectedPathname.slice(dir.length);
|
|
53074
|
-
}
|
|
53075
|
-
}
|
|
53076
|
-
const resolvedPathname = redirectedPathname || pathname;
|
|
53077
|
-
let fileUrl = path$o.resolve(dir, removeLeadingSlash(resolvedPathname));
|
|
53078
|
-
if (resolvedPathname[resolvedPathname.length - 1] === '/' &&
|
|
53079
|
-
fileUrl[fileUrl.length - 1] !== '/') {
|
|
53080
|
-
fileUrl = fileUrl + '/';
|
|
53081
|
-
}
|
|
53082
|
-
if (!ensureServingAccess(fileUrl, server, res, next)) {
|
|
53083
|
-
return;
|
|
53084
|
-
}
|
|
53085
|
-
if (redirectedPathname) {
|
|
53086
|
-
url.pathname = encodeURIComponent(redirectedPathname);
|
|
53087
|
-
req.url = url.href.slice(url.origin.length);
|
|
53088
|
-
}
|
|
53089
|
-
serve(req, res, next);
|
|
53090
|
-
};
|
|
53091
|
-
}
|
|
53092
|
-
function serveRawFsMiddleware(server) {
|
|
53093
|
-
const serveFromRoot = sirv('/', sirvOptions({ headers: server.config.server.headers }));
|
|
53094
|
-
// Keep the named function. The name is visible in debug logs via `DEBUG=connect:dispatcher ...`
|
|
53095
|
-
return function viteServeRawFsMiddleware(req, res, next) {
|
|
53096
|
-
const url = new URL(req.url, 'http://example.com');
|
|
53097
|
-
// In some cases (e.g. linked monorepos) files outside of root will
|
|
53098
|
-
// reference assets that are also out of served root. In such cases
|
|
53099
|
-
// the paths are rewritten to `/@fs/` prefixed paths and must be served by
|
|
53100
|
-
// searching based from fs root.
|
|
53101
|
-
if (url.pathname.startsWith(FS_PREFIX)) {
|
|
53102
|
-
const pathname = decodeURIComponent(url.pathname);
|
|
53103
|
-
// restrict files outside of `fs.allow`
|
|
53104
|
-
if (!ensureServingAccess(slash$1(path$o.resolve(fsPathFromId(pathname))), server, res, next)) {
|
|
53105
|
-
return;
|
|
53106
|
-
}
|
|
53107
|
-
let newPathname = pathname.slice(FS_PREFIX.length);
|
|
53108
|
-
if (isWindows$4)
|
|
53109
|
-
newPathname = newPathname.replace(/^[A-Z]:/i, '');
|
|
53110
|
-
url.pathname = encodeURIComponent(newPathname);
|
|
53111
|
-
req.url = url.href.slice(url.origin.length);
|
|
53112
|
-
serveFromRoot(req, res, next);
|
|
53113
|
-
}
|
|
53114
|
-
else {
|
|
53115
|
-
next();
|
|
53116
|
-
}
|
|
53117
|
-
};
|
|
53118
|
-
}
|
|
53119
|
-
function isFileServingAllowed(url, server) {
|
|
53120
|
-
if (!server.config.server.fs.strict)
|
|
53121
|
-
return true;
|
|
53122
|
-
const file = fsPathFromUrl(url);
|
|
53123
|
-
if (server._fsDenyGlob(file))
|
|
53124
|
-
return false;
|
|
53125
|
-
if (server.moduleGraph.safeModulesPath.has(file))
|
|
53126
|
-
return true;
|
|
53127
|
-
if (server.config.server.fs.allow.some((dir) => isParentDirectory(dir, file)))
|
|
53128
|
-
return true;
|
|
53129
|
-
return false;
|
|
53130
|
-
}
|
|
53131
|
-
function ensureServingAccess(url, server, res, next) {
|
|
53132
|
-
if (isFileServingAllowed(url, server)) {
|
|
53133
|
-
return true;
|
|
53134
|
-
}
|
|
53135
|
-
if (isFileReadable(cleanUrl(url))) {
|
|
53136
|
-
const urlMessage = `The request url "${url}" is outside of Vite serving allow list.`;
|
|
53137
|
-
const hintMessage = `
|
|
53138
|
-
${server.config.server.fs.allow.map((i) => `- ${i}`).join('\n')}
|
|
53139
|
-
|
|
53140
|
-
Refer to docs https://vitejs.dev/config/server-options.html#server-fs-allow for configurations and more details.`;
|
|
53141
|
-
server.config.logger.error(urlMessage);
|
|
53142
|
-
server.config.logger.warnOnce(hintMessage + '\n');
|
|
53143
|
-
res.statusCode = 403;
|
|
53144
|
-
res.write(renderRestrictedErrorHTML(urlMessage + '\n' + hintMessage));
|
|
53145
|
-
res.end();
|
|
53146
|
-
}
|
|
53147
|
-
else {
|
|
53148
|
-
// if the file doesn't exist, we shouldn't restrict this path as it can
|
|
53149
|
-
// be an API call. Middlewares would issue a 404 if the file isn't handled
|
|
53150
|
-
next();
|
|
53151
|
-
}
|
|
53152
|
-
return false;
|
|
53153
|
-
}
|
|
53154
|
-
function renderRestrictedErrorHTML(msg) {
|
|
53155
|
-
// to have syntax highlighting and autocompletion in IDE
|
|
53156
|
-
const html = String.raw;
|
|
53157
|
-
return html `
|
|
53158
|
-
<body>
|
|
53159
|
-
<h1>403 Restricted</h1>
|
|
53160
|
-
<p>${msg.replace(/\n/g, '<br/>')}</p>
|
|
53161
|
-
<style>
|
|
53162
|
-
body {
|
|
53163
|
-
padding: 1em 2em;
|
|
53164
|
-
}
|
|
53165
|
-
</style>
|
|
53166
|
-
</body>
|
|
53167
|
-
`;
|
|
53168
|
-
}
|
|
53169
|
-
|
|
53170
53175
|
const ERR_LOAD_URL = 'ERR_LOAD_URL';
|
|
53171
53176
|
const ERR_LOAD_PUBLIC_URL = 'ERR_LOAD_PUBLIC_URL';
|
|
53172
53177
|
const debugLoad = createDebugger('vite:load');
|
|
@@ -63650,8 +63655,7 @@ var index = {
|
|
|
63650
63655
|
__proto__: null,
|
|
63651
63656
|
_createServer: _createServer,
|
|
63652
63657
|
createServer: createServer,
|
|
63653
|
-
resolveServerOptions: resolveServerOptions
|
|
63654
|
-
searchForWorkspaceRoot: searchForWorkspaceRoot
|
|
63658
|
+
resolveServerOptions: resolveServerOptions
|
|
63655
63659
|
};
|
|
63656
63660
|
|
|
63657
63661
|
/* eslint-disable */
|
|
@@ -64487,4 +64491,4 @@ function isDepsOptimizerEnabled(config, ssr) {
|
|
|
64487
64491
|
(command === 'serve' && disabled === 'dev'));
|
|
64488
64492
|
}
|
|
64489
64493
|
|
|
64490
|
-
export {
|
|
64494
|
+
export { loadEnv as A, resolveEnvPrefix as B, picocolorsExports as C, bindShortcuts as D, commonjsGlobal as E, index$1 as F, build$1 as G, index as H, preview$1 as I, preprocessCSS as a, build as b, createServer as c, resolvePackageData as d, buildErrorMessage as e, formatPostcssSourceMap as f, defineConfig as g, resolveConfig as h, isInNodeModules as i, resolveBaseUrl as j, getDepOptimizationConfig as k, loadConfigFromFile as l, isDepsOptimizerEnabled as m, normalizePath$3 as n, optimizeDeps as o, preview as p, mergeConfig as q, resolvePackageEntry as r, sortUserPlugins as s, transformWithEsbuild as t, mergeAlias as u, createFilter as v, send$2 as w, createLogger as x, searchForWorkspaceRoot as y, isFileServingAllowed as z };
|