vite 5.0.3 → 5.0.5
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 +22 -0
- package/client.d.ts +4 -1
- package/dist/client/client.mjs +198 -168
- package/dist/client/client.mjs.map +1 -1
- package/dist/node/chunks/{dep-m-h4L35S.js → dep-IrrVD4is.js} +1 -1
- package/dist/node/chunks/{dep-vyqc0_aB.js → dep-MF_y65BT.js} +304 -231
- package/dist/node/chunks/{dep-_rppyaaB.js → dep-mpgFWQ-7.js} +1 -1
- package/dist/node/cli.js +5 -5
- package/dist/node/constants.js +1 -0
- package/dist/node/index.d.ts +2 -3
- package/dist/node/index.js +2 -2
- package/dist/node-cjs/publicUtils.cjs +6 -12
- package/package.json +6 -6
|
@@ -2769,7 +2769,17 @@ function serialize(obj, indent, baseIndent) {
|
|
|
2769
2769
|
return `${obj}n`;
|
|
2770
2770
|
return stringify$8(obj);
|
|
2771
2771
|
}
|
|
2772
|
+
// isWellFormed exists from Node.js 20
|
|
2773
|
+
const hasStringIsWellFormed = 'isWellFormed' in String.prototype;
|
|
2774
|
+
function isWellFormedString(input) {
|
|
2775
|
+
// @ts-expect-error String::isWellFormed exists from ES2024. tsconfig lib is set to ES6
|
|
2776
|
+
if (hasStringIsWellFormed)
|
|
2777
|
+
return input.isWellFormed();
|
|
2778
|
+
// https://github.com/tc39/proposal-is-usv-string/blob/main/README.md#algorithm
|
|
2779
|
+
return !/\p{Surrogate}/u.test(input);
|
|
2780
|
+
}
|
|
2772
2781
|
const dataToEsm = function dataToEsm(data, options = {}) {
|
|
2782
|
+
var _a, _b;
|
|
2773
2783
|
const t = options.compact ? '' : 'indent' in options ? options.indent : '\t';
|
|
2774
2784
|
const _ = options.compact ? '' : ' ';
|
|
2775
2785
|
const n = options.compact ? '' : '\n';
|
|
@@ -2784,8 +2794,17 @@ const dataToEsm = function dataToEsm(data, options = {}) {
|
|
|
2784
2794
|
const magic = _ || (/^[{[\-\/]/.test(code) ? '' : ' '); // eslint-disable-line no-useless-escape
|
|
2785
2795
|
return `export default${magic}${code};`;
|
|
2786
2796
|
}
|
|
2797
|
+
let maxUnderbarPrefixLength = 0;
|
|
2798
|
+
for (const key of Object.keys(data)) {
|
|
2799
|
+
const underbarPrefixLength = (_b = (_a = key.match(/^(_+)/)) === null || _a === void 0 ? void 0 : _a[0].length) !== null && _b !== void 0 ? _b : 0;
|
|
2800
|
+
if (underbarPrefixLength > maxUnderbarPrefixLength) {
|
|
2801
|
+
maxUnderbarPrefixLength = underbarPrefixLength;
|
|
2802
|
+
}
|
|
2803
|
+
}
|
|
2804
|
+
const arbitraryNamePrefix = `${'_'.repeat(maxUnderbarPrefixLength + 1)}arbitrary`;
|
|
2787
2805
|
let namedExportCode = '';
|
|
2788
2806
|
const defaultExportRows = [];
|
|
2807
|
+
const arbitraryNameExportRows = [];
|
|
2789
2808
|
for (const [key, value] of Object.entries(data)) {
|
|
2790
2809
|
if (key === makeLegalIdentifier(key)) {
|
|
2791
2810
|
if (options.objectShorthand)
|
|
@@ -2796,9 +2815,18 @@ const dataToEsm = function dataToEsm(data, options = {}) {
|
|
|
2796
2815
|
}
|
|
2797
2816
|
else {
|
|
2798
2817
|
defaultExportRows.push(`${stringify$8(key)}:${_}${serialize(value, options.compact ? null : t, '')}`);
|
|
2818
|
+
if (options.includeArbitraryNames && isWellFormedString(key)) {
|
|
2819
|
+
const variableName = `${arbitraryNamePrefix}${arbitraryNameExportRows.length}`;
|
|
2820
|
+
namedExportCode += `${declarationType} ${variableName}${_}=${_}${serialize(value, options.compact ? null : t, '')};${n}`;
|
|
2821
|
+
arbitraryNameExportRows.push(`${variableName} as ${JSON.stringify(key)}`);
|
|
2822
|
+
}
|
|
2799
2823
|
}
|
|
2800
2824
|
}
|
|
2801
|
-
|
|
2825
|
+
const arbitraryExportCode = arbitraryNameExportRows.length > 0
|
|
2826
|
+
? `export${_}{${n}${t}${arbitraryNameExportRows.join(`,${n}${t}`)}${n}};${n}`
|
|
2827
|
+
: '';
|
|
2828
|
+
const defaultExportCode = `export default${_}{${n}${t}${defaultExportRows.join(`,${n}${t}`)}${n}};${n}`;
|
|
2829
|
+
return `${namedExportCode}${arbitraryExportCode}${defaultExportCode}`;
|
|
2802
2830
|
};
|
|
2803
2831
|
|
|
2804
2832
|
var path$l = require$$0$4;
|
|
@@ -12069,7 +12097,7 @@ function normalizePath$3(id) {
|
|
|
12069
12097
|
}
|
|
12070
12098
|
function fsPathFromId(id) {
|
|
12071
12099
|
const fsPath = normalizePath$3(id.startsWith(FS_PREFIX) ? id.slice(FS_PREFIX.length) : id);
|
|
12072
|
-
return fsPath[0] === '/' ||
|
|
12100
|
+
return fsPath[0] === '/' || VOLUME_RE.test(fsPath) ? fsPath : `/${fsPath}`;
|
|
12073
12101
|
}
|
|
12074
12102
|
function fsPathFromUrl(url) {
|
|
12075
12103
|
return fsPathFromId(cleanUrl(url));
|
|
@@ -12955,6 +12983,15 @@ function getPackageManagerCommand(type = 'install') {
|
|
|
12955
12983
|
function isDevServer(server) {
|
|
12956
12984
|
return 'pluginContainer' in server;
|
|
12957
12985
|
}
|
|
12986
|
+
function promiseWithResolvers() {
|
|
12987
|
+
let resolve;
|
|
12988
|
+
let reject;
|
|
12989
|
+
const promise = new Promise((_resolve, _reject) => {
|
|
12990
|
+
resolve = _resolve;
|
|
12991
|
+
reject = _reject;
|
|
12992
|
+
});
|
|
12993
|
+
return { promise, resolve, reject };
|
|
12994
|
+
}
|
|
12958
12995
|
|
|
12959
12996
|
/* eslint no-console: 0 */
|
|
12960
12997
|
const LogLevels = {
|
|
@@ -14602,7 +14639,7 @@ const buildEsbuildPlugin = (config) => {
|
|
|
14602
14639
|
// the headers don't modify the sourcemap
|
|
14603
14640
|
const esbuildCode = res.code;
|
|
14604
14641
|
const contentIndex = opts.format === 'iife'
|
|
14605
|
-
? esbuildCode.
|
|
14642
|
+
? Math.max(esbuildCode.search(IIFE_BEGIN_RE), 0)
|
|
14606
14643
|
: opts.format === 'umd'
|
|
14607
14644
|
? esbuildCode.indexOf(`(function(`) // same for minified or not
|
|
14608
14645
|
: 0;
|
|
@@ -17106,32 +17143,43 @@ const debug$g = createDebugger('vite:sourcemap', {
|
|
|
17106
17143
|
// false positive "missing source" warning. We also check for certain
|
|
17107
17144
|
// prefixes used for special handling in esbuildDepPlugin.
|
|
17108
17145
|
const virtualSourceRE = /^(?:dep:|browser-external:|virtual:)|\0/;
|
|
17109
|
-
async function
|
|
17146
|
+
async function computeSourceRoute(map, file) {
|
|
17110
17147
|
let sourceRoot;
|
|
17111
17148
|
try {
|
|
17112
17149
|
// The source root is undefined for virtual modules and permission errors.
|
|
17113
17150
|
sourceRoot = await fsp.realpath(path$o.resolve(path$o.dirname(file), map.sourceRoot || ''));
|
|
17114
17151
|
}
|
|
17115
17152
|
catch { }
|
|
17153
|
+
return sourceRoot;
|
|
17154
|
+
}
|
|
17155
|
+
async function injectSourcesContent(map, file, logger) {
|
|
17156
|
+
let sourceRootPromise;
|
|
17116
17157
|
const missingSources = [];
|
|
17117
17158
|
const sourcesContent = map.sourcesContent || [];
|
|
17118
|
-
|
|
17119
|
-
|
|
17120
|
-
|
|
17121
|
-
|
|
17122
|
-
|
|
17123
|
-
|
|
17124
|
-
|
|
17125
|
-
|
|
17126
|
-
|
|
17127
|
-
|
|
17128
|
-
|
|
17129
|
-
|
|
17130
|
-
|
|
17131
|
-
|
|
17159
|
+
const sourcesContentPromises = [];
|
|
17160
|
+
for (let index = 0; index < map.sources.length; index++) {
|
|
17161
|
+
const sourcePath = map.sources[index];
|
|
17162
|
+
if (!sourcesContent[index] &&
|
|
17163
|
+
sourcePath &&
|
|
17164
|
+
!virtualSourceRE.test(sourcePath)) {
|
|
17165
|
+
sourcesContentPromises.push((async () => {
|
|
17166
|
+
// inject content from source file when sourcesContent is null
|
|
17167
|
+
sourceRootPromise ??= computeSourceRoute(map, file);
|
|
17168
|
+
const sourceRoot = await sourceRootPromise;
|
|
17169
|
+
let resolvedSourcePath = decodeURI(sourcePath);
|
|
17170
|
+
if (sourceRoot) {
|
|
17171
|
+
resolvedSourcePath = path$o.resolve(sourceRoot, resolvedSourcePath);
|
|
17172
|
+
}
|
|
17173
|
+
sourcesContent[index] = await fsp
|
|
17174
|
+
.readFile(resolvedSourcePath, 'utf-8')
|
|
17175
|
+
.catch(() => {
|
|
17176
|
+
missingSources.push(resolvedSourcePath);
|
|
17177
|
+
return null;
|
|
17178
|
+
});
|
|
17179
|
+
})());
|
|
17132
17180
|
}
|
|
17133
|
-
|
|
17134
|
-
|
|
17181
|
+
}
|
|
17182
|
+
await Promise.all(sourcesContentPromises);
|
|
17135
17183
|
map.sourcesContent = sourcesContent;
|
|
17136
17184
|
// Use this command…
|
|
17137
17185
|
// DEBUG="vite:sourcemap" vite build
|
|
@@ -17141,11 +17189,6 @@ async function injectSourcesContent(map, file, logger) {
|
|
|
17141
17189
|
debug$g?.(`Missing sources:\n ` + missingSources.join(`\n `));
|
|
17142
17190
|
}
|
|
17143
17191
|
}
|
|
17144
|
-
async function getOriginalContent(filepath) {
|
|
17145
|
-
if (virtualSourceRE.test(filepath))
|
|
17146
|
-
return undefined;
|
|
17147
|
-
return await fsp.readFile(filepath, 'utf-8').catch(() => undefined);
|
|
17148
|
-
}
|
|
17149
17192
|
function genSourceMapUrl(map) {
|
|
17150
17193
|
if (typeof map !== 'string') {
|
|
17151
17194
|
map = JSON.stringify(map);
|
|
@@ -28492,7 +28535,7 @@ function resolvePlugin(resolveOptions) {
|
|
|
28492
28535
|
// Optimized files could not yet exist in disk, resolve to the full path
|
|
28493
28536
|
// Inject the current browserHash version if the path doesn't have one
|
|
28494
28537
|
if (!resolveOptions.isBuild &&
|
|
28495
|
-
!
|
|
28538
|
+
!DEP_VERSION_RE.test(normalizedFsPath)) {
|
|
28496
28539
|
const browserHash = optimizedDepInfoFromFile(depsOptimizer.metadata, normalizedFsPath)?.browserHash;
|
|
28497
28540
|
if (browserHash) {
|
|
28498
28541
|
return injectQuery(normalizedFsPath, `v=${browserHash}`);
|
|
@@ -28651,7 +28694,7 @@ function ensureVersionQuery(resolved, id, options, depsOptimizer) {
|
|
|
28651
28694
|
// Use the original id to do the check as the resolved id may be the real
|
|
28652
28695
|
// file path after symlinks resolution
|
|
28653
28696
|
const isNodeModule = isInNodeModules$1(id) || isInNodeModules$1(resolved);
|
|
28654
|
-
if (isNodeModule && !
|
|
28697
|
+
if (isNodeModule && !DEP_VERSION_RE.test(resolved)) {
|
|
28655
28698
|
const versionHash = depsOptimizer.metadata.browserHash;
|
|
28656
28699
|
if (versionHash && isOptimizable(resolved, depsOptimizer.options)) {
|
|
28657
28700
|
resolved = injectQuery(resolved, `v=${versionHash}`);
|
|
@@ -28986,49 +29029,18 @@ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache
|
|
|
28986
29029
|
if (data.exports) {
|
|
28987
29030
|
entryPoint = resolveExportsOrImports(data, '.', options, targetWeb, 'exports');
|
|
28988
29031
|
}
|
|
28989
|
-
// handle edge case with browser and module field semantics
|
|
28990
|
-
if (!entryPoint && targetWeb && options.mainFields.includes('browser')) {
|
|
28991
|
-
// check browser field
|
|
28992
|
-
// https://github.com/defunctzombie/package-browser-field-spec
|
|
28993
|
-
const browserEntry = typeof data.browser === 'string'
|
|
28994
|
-
? data.browser
|
|
28995
|
-
: isObject$1(data.browser) && data.browser['.'];
|
|
28996
|
-
if (browserEntry) {
|
|
28997
|
-
// check if the package also has a "module" field.
|
|
28998
|
-
if (!options.isRequire &&
|
|
28999
|
-
options.mainFields.includes('module') &&
|
|
29000
|
-
typeof data.module === 'string' &&
|
|
29001
|
-
data.module !== browserEntry) {
|
|
29002
|
-
// if both are present, we may have a problem: some package points both
|
|
29003
|
-
// to ESM, with "module" targeting Node.js, while some packages points
|
|
29004
|
-
// "module" to browser ESM and "browser" to UMD/IIFE.
|
|
29005
|
-
// the heuristics here is to actually read the browser entry when
|
|
29006
|
-
// possible and check for hints of ESM. If it is not ESM, prefer "module"
|
|
29007
|
-
// instead; Otherwise, assume it's ESM and use it.
|
|
29008
|
-
const resolvedBrowserEntry = tryFsResolve(path$o.join(dir, browserEntry), options);
|
|
29009
|
-
if (resolvedBrowserEntry) {
|
|
29010
|
-
const content = fs$l.readFileSync(resolvedBrowserEntry, 'utf-8');
|
|
29011
|
-
if (hasESMSyntax(content)) {
|
|
29012
|
-
// likely ESM, prefer browser
|
|
29013
|
-
entryPoint = browserEntry;
|
|
29014
|
-
}
|
|
29015
|
-
else {
|
|
29016
|
-
// non-ESM, UMD or IIFE or CJS(!!! e.g. firebase 7.x), prefer module
|
|
29017
|
-
entryPoint = data.module;
|
|
29018
|
-
}
|
|
29019
|
-
}
|
|
29020
|
-
}
|
|
29021
|
-
else {
|
|
29022
|
-
entryPoint = browserEntry;
|
|
29023
|
-
}
|
|
29024
|
-
}
|
|
29025
|
-
}
|
|
29026
29032
|
// fallback to mainFields if still not resolved
|
|
29027
29033
|
if (!entryPoint) {
|
|
29028
29034
|
for (const field of options.mainFields) {
|
|
29029
|
-
if (field === 'browser')
|
|
29030
|
-
|
|
29031
|
-
|
|
29035
|
+
if (field === 'browser') {
|
|
29036
|
+
if (targetWeb) {
|
|
29037
|
+
entryPoint = tryResolveBrowserEntry(dir, data, options);
|
|
29038
|
+
if (entryPoint) {
|
|
29039
|
+
break;
|
|
29040
|
+
}
|
|
29041
|
+
}
|
|
29042
|
+
}
|
|
29043
|
+
else if (typeof data[field] === 'string') {
|
|
29032
29044
|
entryPoint = data[field];
|
|
29033
29045
|
break;
|
|
29034
29046
|
}
|
|
@@ -29187,6 +29199,43 @@ function tryResolveBrowserMapping(id, importer, options, isFilePath, externalize
|
|
|
29187
29199
|
}
|
|
29188
29200
|
}
|
|
29189
29201
|
}
|
|
29202
|
+
function tryResolveBrowserEntry(dir, data, options) {
|
|
29203
|
+
// handle edge case with browser and module field semantics
|
|
29204
|
+
// check browser field
|
|
29205
|
+
// https://github.com/defunctzombie/package-browser-field-spec
|
|
29206
|
+
const browserEntry = typeof data.browser === 'string'
|
|
29207
|
+
? data.browser
|
|
29208
|
+
: isObject$1(data.browser) && data.browser['.'];
|
|
29209
|
+
if (browserEntry) {
|
|
29210
|
+
// check if the package also has a "module" field.
|
|
29211
|
+
if (!options.isRequire &&
|
|
29212
|
+
options.mainFields.includes('module') &&
|
|
29213
|
+
typeof data.module === 'string' &&
|
|
29214
|
+
data.module !== browserEntry) {
|
|
29215
|
+
// if both are present, we may have a problem: some package points both
|
|
29216
|
+
// to ESM, with "module" targeting Node.js, while some packages points
|
|
29217
|
+
// "module" to browser ESM and "browser" to UMD/IIFE.
|
|
29218
|
+
// the heuristics here is to actually read the browser entry when
|
|
29219
|
+
// possible and check for hints of ESM. If it is not ESM, prefer "module"
|
|
29220
|
+
// instead; Otherwise, assume it's ESM and use it.
|
|
29221
|
+
const resolvedBrowserEntry = tryFsResolve(path$o.join(dir, browserEntry), options);
|
|
29222
|
+
if (resolvedBrowserEntry) {
|
|
29223
|
+
const content = fs$l.readFileSync(resolvedBrowserEntry, 'utf-8');
|
|
29224
|
+
if (hasESMSyntax(content)) {
|
|
29225
|
+
// likely ESM, prefer browser
|
|
29226
|
+
return browserEntry;
|
|
29227
|
+
}
|
|
29228
|
+
else {
|
|
29229
|
+
// non-ESM, UMD or IIFE or CJS(!!! e.g. firebase 7.x), prefer module
|
|
29230
|
+
return data.module;
|
|
29231
|
+
}
|
|
29232
|
+
}
|
|
29233
|
+
}
|
|
29234
|
+
else {
|
|
29235
|
+
return browserEntry;
|
|
29236
|
+
}
|
|
29237
|
+
}
|
|
29238
|
+
}
|
|
29190
29239
|
/**
|
|
29191
29240
|
* given a relative path in pkg dir,
|
|
29192
29241
|
* return a relative path in pkg dir,
|
|
@@ -37848,7 +37897,7 @@ function loadEnv(mode, envDir, prefixes = 'VITE_') {
|
|
|
37848
37897
|
}
|
|
37849
37898
|
function resolveEnvPrefix({ envPrefix = 'VITE_', }) {
|
|
37850
37899
|
envPrefix = arraify(envPrefix);
|
|
37851
|
-
if (envPrefix.
|
|
37900
|
+
if (envPrefix.includes('')) {
|
|
37852
37901
|
throw new Error(`envPrefix option contains value '', which could lead unexpected exposure of sensitive information.`);
|
|
37853
37902
|
}
|
|
37854
37903
|
return envPrefix;
|
|
@@ -37927,7 +37976,9 @@ function polyfill() {
|
|
|
37927
37976
|
const htmlProxyRE$1 = /\?html-proxy=?(?:&inline-css)?(?:&style-attr)?&index=(\d+)\.(js|css)$/;
|
|
37928
37977
|
const inlineCSSRE$1 = /__VITE_INLINE_CSS__([a-z\d]{8}_\d+)__/g;
|
|
37929
37978
|
// Do not allow preceding '.', but do allow preceding '...' for spread operations
|
|
37930
|
-
const inlineImportRE =
|
|
37979
|
+
const inlineImportRE =
|
|
37980
|
+
// eslint-disable-next-line regexp/no-unused-capturing-group -- https://github.com/ota-meshi/eslint-plugin-regexp/issues/675
|
|
37981
|
+
/(?<!(?<!\.\.)\.)\bimport\s*\(("(?:[^"]|(?<=\\)")*"|'(?:[^']|(?<=\\)')*')\)/dg;
|
|
37931
37982
|
const htmlLangRE = /\.(?:html|htm)$/;
|
|
37932
37983
|
const importMapRE = /[ \t]*<script[^>]*type\s*=\s*(?:"importmap"|'importmap'|importmap)[^>]*>.*?<\/script>/is;
|
|
37933
37984
|
const moduleScriptRE = /[ \t]*<script[^>]*type\s*=\s*(?:"module"|'module'|module)[^>]*>/i;
|
|
@@ -38549,10 +38600,9 @@ function extractImportExpressionFromClassicScript(scriptTextNode) {
|
|
|
38549
38600
|
let match;
|
|
38550
38601
|
inlineImportRE.lastIndex = 0;
|
|
38551
38602
|
while ((match = inlineImportRE.exec(cleanCode))) {
|
|
38552
|
-
const
|
|
38553
|
-
const
|
|
38554
|
-
const
|
|
38555
|
-
const end = start + url.length - 2;
|
|
38603
|
+
const [, [urlStart, urlEnd]] = match.indices;
|
|
38604
|
+
const start = urlStart + 1;
|
|
38605
|
+
const end = urlEnd - 1;
|
|
38556
38606
|
scriptUrls.push({
|
|
38557
38607
|
start: start + startOffset,
|
|
38558
38608
|
end: end + startOffset,
|
|
@@ -38563,11 +38613,11 @@ function extractImportExpressionFromClassicScript(scriptTextNode) {
|
|
|
38563
38613
|
}
|
|
38564
38614
|
function preImportMapHook(config) {
|
|
38565
38615
|
return (html, ctx) => {
|
|
38566
|
-
const importMapIndex = html.
|
|
38567
|
-
if (importMapIndex
|
|
38616
|
+
const importMapIndex = html.search(importMapRE);
|
|
38617
|
+
if (importMapIndex < 0)
|
|
38568
38618
|
return;
|
|
38569
|
-
const importMapAppendIndex = html.
|
|
38570
|
-
if (importMapAppendIndex
|
|
38619
|
+
const importMapAppendIndex = html.search(importMapAppendRE);
|
|
38620
|
+
if (importMapAppendIndex < 0)
|
|
38571
38621
|
return;
|
|
38572
38622
|
if (importMapAppendIndex < importMapIndex) {
|
|
38573
38623
|
const relativeHtml = normalizePath$3(path$o.relative(config.root, ctx.filename));
|
|
@@ -39653,8 +39703,8 @@ function createCachedImport(imp) {
|
|
|
39653
39703
|
return cached;
|
|
39654
39704
|
};
|
|
39655
39705
|
}
|
|
39656
|
-
const importPostcssImport = createCachedImport(() => import('./dep-
|
|
39657
|
-
const importPostcssModules = createCachedImport(() => import('./dep-
|
|
39706
|
+
const importPostcssImport = createCachedImport(() => import('./dep-mpgFWQ-7.js').then(function (n) { return n.i; }));
|
|
39707
|
+
const importPostcssModules = createCachedImport(() => import('./dep-IrrVD4is.js').then(function (n) { return n.i; }));
|
|
39658
39708
|
const importPostcss = createCachedImport(() => import('postcss'));
|
|
39659
39709
|
/**
|
|
39660
39710
|
* @experimental
|
|
@@ -39662,12 +39712,12 @@ const importPostcss = createCachedImport(() => import('postcss'));
|
|
|
39662
39712
|
async function preprocessCSS(code, filename, config) {
|
|
39663
39713
|
return await compileCSS(filename, code, config);
|
|
39664
39714
|
}
|
|
39665
|
-
const postcssReturnsVirtualFilesRE = /^<.+>$/;
|
|
39666
39715
|
async function formatPostcssSourceMap(rawMap, file) {
|
|
39667
39716
|
const inputFileDir = path$o.dirname(file);
|
|
39668
39717
|
const sources = rawMap.sources.map((source) => {
|
|
39669
39718
|
const cleanSource = cleanUrl(decodeURIComponent(source));
|
|
39670
|
-
|
|
39719
|
+
// postcss virtual files
|
|
39720
|
+
if (cleanSource[0] === '<' && cleanSource[cleanSource.length - 1] === '>') {
|
|
39671
39721
|
return `\0${cleanSource}`;
|
|
39672
39722
|
}
|
|
39673
39723
|
return normalizePath$3(path$o.resolve(inputFileDir, cleanSource));
|
|
@@ -39719,7 +39769,7 @@ async function resolvePostcssConfig(config) {
|
|
|
39719
39769
|
else {
|
|
39720
39770
|
const searchPath = typeof inlineOptions === 'string' ? inlineOptions : config.root;
|
|
39721
39771
|
result = postcssrc({}, searchPath).catch((e) => {
|
|
39722
|
-
if (
|
|
39772
|
+
if (!e.message.includes('No PostCSS Config found')) {
|
|
39723
39773
|
if (e instanceof Error) {
|
|
39724
39774
|
const { name, message, stack } = e;
|
|
39725
39775
|
e.name = 'Failed to load PostCSS config';
|
|
@@ -39933,6 +39983,8 @@ function resolveMinifyCssEsbuildOptions(options) {
|
|
|
39933
39983
|
return { ...base, minify: true };
|
|
39934
39984
|
}
|
|
39935
39985
|
}
|
|
39986
|
+
const atImportRE = /@import(?:\s*(?:url\([^)]*\)|"(?:[^"]|(?<=\\)")*"|'(?:[^']|(?<=\\)')*').*?|[^;]*);/g;
|
|
39987
|
+
const atCharsetRE = /@charset(?:\s*(?:"(?:[^"]|(?<=\\)")*"|'(?:[^']|(?<=\\)')*').*?|[^;]*);/g;
|
|
39936
39988
|
async function hoistAtRules(css) {
|
|
39937
39989
|
const s = new MagicString(css);
|
|
39938
39990
|
const cleanCss = emptyCssComments(css);
|
|
@@ -39941,7 +39993,7 @@ async function hoistAtRules(css) {
|
|
|
39941
39993
|
// CSS @import can only appear at top of the file. We need to hoist all @import
|
|
39942
39994
|
// to top when multiple files are concatenated.
|
|
39943
39995
|
// match until semicolon that's not in quotes
|
|
39944
|
-
|
|
39996
|
+
atImportRE.lastIndex = 0;
|
|
39945
39997
|
while ((match = atImportRE.exec(cleanCss))) {
|
|
39946
39998
|
s.remove(match.index, match.index + match[0].length);
|
|
39947
39999
|
// Use `appendLeft` instead of `prepend` to preserve original @import order
|
|
@@ -39949,7 +40001,7 @@ async function hoistAtRules(css) {
|
|
|
39949
40001
|
}
|
|
39950
40002
|
// #6333
|
|
39951
40003
|
// CSS @charset must be the top-first in the file, hoist the first to top
|
|
39952
|
-
|
|
40004
|
+
atCharsetRE.lastIndex = 0;
|
|
39953
40005
|
let foundCharset = false;
|
|
39954
40006
|
while ((match = atCharsetRE.exec(cleanCss))) {
|
|
39955
40007
|
s.remove(match.index, match.index + match[0].length);
|
|
@@ -40460,8 +40512,8 @@ const convertTargets = (esbuildTarget) => {
|
|
|
40460
40512
|
for (const entry of entriesWithoutES) {
|
|
40461
40513
|
if (entry === 'esnext')
|
|
40462
40514
|
continue;
|
|
40463
|
-
const index = entry.
|
|
40464
|
-
if (index) {
|
|
40515
|
+
const index = entry.search(versionRE);
|
|
40516
|
+
if (index >= 0) {
|
|
40465
40517
|
const browser = map[entry.slice(0, index)];
|
|
40466
40518
|
if (browser === false)
|
|
40467
40519
|
continue; // No mapping available
|
|
@@ -40883,16 +40935,24 @@ function jsonPlugin(options = {}, isBuild) {
|
|
|
40883
40935
|
};
|
|
40884
40936
|
}
|
|
40885
40937
|
catch (e) {
|
|
40886
|
-
const
|
|
40887
|
-
const position = errorMessageList && parseInt(errorMessageList[0], 10);
|
|
40938
|
+
const position = extractJsonErrorPosition(e.message, json.length);
|
|
40888
40939
|
const msg = position
|
|
40889
|
-
? `, invalid JSON syntax found at
|
|
40940
|
+
? `, invalid JSON syntax found at position ${position}`
|
|
40890
40941
|
: `.`;
|
|
40891
|
-
this.error(`Failed to parse JSON file` + msg,
|
|
40942
|
+
this.error(`Failed to parse JSON file` + msg, position);
|
|
40892
40943
|
}
|
|
40893
40944
|
},
|
|
40894
40945
|
};
|
|
40895
40946
|
}
|
|
40947
|
+
function extractJsonErrorPosition(errorMessage, inputLength) {
|
|
40948
|
+
if (errorMessage.startsWith('Unexpected end of JSON input')) {
|
|
40949
|
+
return inputLength - 1;
|
|
40950
|
+
}
|
|
40951
|
+
const errorMessageList = /at position (\d+)/.exec(errorMessage);
|
|
40952
|
+
return errorMessageList
|
|
40953
|
+
? Math.max(parseInt(errorMessageList[1], 10) - 1, 0)
|
|
40954
|
+
: undefined;
|
|
40955
|
+
}
|
|
40896
40956
|
|
|
40897
40957
|
const ERR_OPTIMIZE_DEPS_PROCESSING_ERROR = 'ERR_OPTIMIZE_DEPS_PROCESSING_ERROR';
|
|
40898
40958
|
const ERR_OUTDATED_OPTIMIZED_DEP = 'ERR_OUTDATED_OPTIMIZED_DEP';
|
|
@@ -51363,6 +51423,8 @@ function bindCLIShortcuts(server, opts) {
|
|
|
51363
51423
|
if (loggedKeys.has(shortcut.key))
|
|
51364
51424
|
continue;
|
|
51365
51425
|
loggedKeys.add(shortcut.key);
|
|
51426
|
+
if (shortcut.action == null)
|
|
51427
|
+
continue;
|
|
51366
51428
|
server.config.logger.info(colors$1.dim(' press ') +
|
|
51367
51429
|
colors$1.bold(`${shortcut.key} + enter`) +
|
|
51368
51430
|
colors$1.dim(` to ${shortcut.description}`));
|
|
@@ -51370,7 +51432,7 @@ function bindCLIShortcuts(server, opts) {
|
|
|
51370
51432
|
return;
|
|
51371
51433
|
}
|
|
51372
51434
|
const shortcut = shortcuts.find((shortcut) => shortcut.key === input);
|
|
51373
|
-
if (!shortcut)
|
|
51435
|
+
if (!shortcut || shortcut.action == null)
|
|
51374
51436
|
return;
|
|
51375
51437
|
actionRunning = true;
|
|
51376
51438
|
await shortcut.action(server);
|
|
@@ -58388,9 +58450,7 @@ function send(req, res, content, type, options) {
|
|
|
58388
58450
|
}
|
|
58389
58451
|
// inject fallback sourcemap for js for improved debugging
|
|
58390
58452
|
// https://github.com/vitejs/vite/pull/13514#issuecomment-1592431496
|
|
58391
|
-
|
|
58392
|
-
// because it indicates generating a sourcemap is meaningless
|
|
58393
|
-
else if (type === 'js' && map == null) {
|
|
58453
|
+
else if (type === 'js' && (!map || map.mappings !== '')) {
|
|
58394
58454
|
const code = content.toString();
|
|
58395
58455
|
// if the code has existing inline sourcemap, assume it's correct and skip
|
|
58396
58456
|
if (convertSourceMap.mapFileCommentRegex.test(code)) {
|
|
@@ -58399,15 +58459,11 @@ function send(req, res, content, type, options) {
|
|
|
58399
58459
|
else {
|
|
58400
58460
|
const urlWithoutTimestamp = removeTimestampQuery(req.url);
|
|
58401
58461
|
const ms = new MagicString(code);
|
|
58402
|
-
|
|
58462
|
+
content = getCodeWithSourcemap(type, code, ms.generateMap({
|
|
58403
58463
|
source: path$o.basename(urlWithoutTimestamp),
|
|
58404
58464
|
hires: 'boundary',
|
|
58405
|
-
includeContent:
|
|
58406
|
-
});
|
|
58407
|
-
if (options.originalContent != null) {
|
|
58408
|
-
map.sourcesContent = [options.originalContent];
|
|
58409
|
-
}
|
|
58410
|
-
content = getCodeWithSourcemap(type, code, map);
|
|
58465
|
+
includeContent: true,
|
|
58466
|
+
}));
|
|
58411
58467
|
}
|
|
58412
58468
|
}
|
|
58413
58469
|
res.statusCode = 200;
|
|
@@ -58543,19 +58599,12 @@ function transformMiddleware(server) {
|
|
|
58543
58599
|
const depsOptimizer = getDepsOptimizer(server.config, false); // non-ssr
|
|
58544
58600
|
const type = isDirectCSSRequest(url) ? 'css' : 'js';
|
|
58545
58601
|
const isDep = DEP_VERSION_RE.test(url) || depsOptimizer?.isOptimizedDepUrl(url);
|
|
58546
|
-
let originalContent;
|
|
58547
|
-
if (type === 'js' && result.map == null) {
|
|
58548
|
-
const filepath = (await server.moduleGraph.getModuleByUrl(url, false))?.file;
|
|
58549
|
-
originalContent =
|
|
58550
|
-
filepath != null ? await getOriginalContent(filepath) : undefined;
|
|
58551
|
-
}
|
|
58552
58602
|
return send(req, res, result.code, type, {
|
|
58553
58603
|
etag: result.etag,
|
|
58554
58604
|
// allow browser to cache npm deps!
|
|
58555
58605
|
cacheControl: isDep ? 'max-age=31536000,immutable' : 'no-cache',
|
|
58556
58606
|
headers: server.config.server.headers,
|
|
58557
58607
|
map: result.map,
|
|
58558
|
-
originalContent,
|
|
58559
58608
|
});
|
|
58560
58609
|
}
|
|
58561
58610
|
}
|
|
@@ -58685,7 +58734,6 @@ const processNodeUrl = (url, useSrcSetReplacer, config, htmlPath, originalUrl, s
|
|
|
58685
58734
|
const devHtmlHook = async (html, { path: htmlPath, filename, server, originalUrl }) => {
|
|
58686
58735
|
const { config, moduleGraph, watcher } = server;
|
|
58687
58736
|
const base = config.base || '/';
|
|
58688
|
-
htmlPath = decodeURI(htmlPath);
|
|
58689
58737
|
let proxyModulePath;
|
|
58690
58738
|
let proxyModuleUrl;
|
|
58691
58739
|
const trailingSlash = htmlPath.endsWith('/');
|
|
@@ -58705,7 +58753,9 @@ const devHtmlHook = async (html, { path: htmlPath, filename, server, originalUrl
|
|
|
58705
58753
|
}
|
|
58706
58754
|
const s = new MagicString(html);
|
|
58707
58755
|
let inlineModuleIndex = -1;
|
|
58708
|
-
|
|
58756
|
+
// The key to the proxyHtml cache is decoded, as it will be compared
|
|
58757
|
+
// against decoded URLs by the HTML plugins.
|
|
58758
|
+
const proxyCacheUrl = decodeURI(cleanUrl(proxyModulePath).replace(normalizePath$3(config.root), ''));
|
|
58709
58759
|
const styleUrl = [];
|
|
58710
58760
|
const inlineStyles = [];
|
|
58711
58761
|
const addInlineModule = (node, ext) => {
|
|
@@ -58876,7 +58926,13 @@ function preTransformRequest(server, url, base) {
|
|
|
58876
58926
|
if (!server.config.server.preTransformRequests)
|
|
58877
58927
|
return;
|
|
58878
58928
|
// transform all url as non-ssr as html includes client-side assets only
|
|
58879
|
-
|
|
58929
|
+
try {
|
|
58930
|
+
url = unwrapId(stripBase(decodeURI(url), base));
|
|
58931
|
+
}
|
|
58932
|
+
catch {
|
|
58933
|
+
// ignore
|
|
58934
|
+
return;
|
|
58935
|
+
}
|
|
58880
58936
|
server.warmupRequest(url);
|
|
58881
58937
|
}
|
|
58882
58938
|
|
|
@@ -59944,25 +60000,37 @@ async function restartServer(server) {
|
|
|
59944
60000
|
},
|
|
59945
60001
|
});
|
|
59946
60002
|
}
|
|
59947
|
-
|
|
59948
|
-
|
|
59949
|
-
|
|
59950
|
-
|
|
59951
|
-
|
|
59952
|
-
|
|
59953
|
-
|
|
59954
|
-
|
|
59955
|
-
|
|
59956
|
-
|
|
59957
|
-
|
|
60003
|
+
// Reinit the server by creating a new instance using the same inlineConfig
|
|
60004
|
+
// This will triger a reload of the config file and re-create the plugins and
|
|
60005
|
+
// middlewares. We then assign all properties of the new server to the existing
|
|
60006
|
+
// server instance and set the user instance to be used in the new server.
|
|
60007
|
+
// This allows us to keep the same server instance for the user.
|
|
60008
|
+
{
|
|
60009
|
+
let newServer = null;
|
|
60010
|
+
try {
|
|
60011
|
+
// delay ws server listen
|
|
60012
|
+
newServer = await _createServer(inlineConfig, { ws: false });
|
|
60013
|
+
}
|
|
60014
|
+
catch (err) {
|
|
60015
|
+
server.config.logger.error(err.message, {
|
|
60016
|
+
timestamp: true,
|
|
60017
|
+
});
|
|
60018
|
+
server.config.logger.error('server restart failed', { timestamp: true });
|
|
60019
|
+
return;
|
|
60020
|
+
}
|
|
60021
|
+
await server.close();
|
|
60022
|
+
// Assign new server props to existing server instance
|
|
60023
|
+
const middlewares = server.middlewares;
|
|
60024
|
+
newServer._configServerPort = server._configServerPort;
|
|
60025
|
+
newServer._currentServerPort = server._currentServerPort;
|
|
60026
|
+
Object.assign(server, newServer);
|
|
60027
|
+
// Keep the same connect instance so app.use(vite.middlewares) works
|
|
60028
|
+
// after a restart in middlewareMode (.route is always '/')
|
|
60029
|
+
middlewares.stack = newServer.middlewares.stack;
|
|
60030
|
+
server.middlewares = middlewares;
|
|
60031
|
+
// Rebind internal server variable so functions reference the user server
|
|
60032
|
+
newServer._setInternalServer(server);
|
|
59958
60033
|
}
|
|
59959
|
-
await server.close();
|
|
59960
|
-
// Assign new server props to existing server instance
|
|
59961
|
-
newServer._configServerPort = server._configServerPort;
|
|
59962
|
-
newServer._currentServerPort = server._currentServerPort;
|
|
59963
|
-
Object.assign(server, newServer);
|
|
59964
|
-
// Rebind internal server variable so functions reference the user server
|
|
59965
|
-
newServer._setInternalServer(server);
|
|
59966
60034
|
const { logger, server: { port, middlewareMode }, } = server.config;
|
|
59967
60035
|
if (!middlewareMode) {
|
|
59968
60036
|
await server.listen(port, true);
|
|
@@ -59973,7 +60041,7 @@ async function restartServer(server) {
|
|
|
59973
60041
|
logger.info('server restarted.', { timestamp: true });
|
|
59974
60042
|
if (shortcutsOptions) {
|
|
59975
60043
|
shortcutsOptions.print = false;
|
|
59976
|
-
bindCLIShortcuts(
|
|
60044
|
+
bindCLIShortcuts(server, shortcutsOptions);
|
|
59977
60045
|
}
|
|
59978
60046
|
}
|
|
59979
60047
|
/**
|
|
@@ -60257,6 +60325,11 @@ function isNodeWithinCircularImports(node, nodeChain, currentChain = [node], tra
|
|
|
60257
60325
|
// Node may import itself which is safe
|
|
60258
60326
|
if (importer === node)
|
|
60259
60327
|
continue;
|
|
60328
|
+
// a PostCSS plugin like Tailwind JIT may register
|
|
60329
|
+
// any file as a dependency to a CSS file.
|
|
60330
|
+
// But in that case, the actual dependency chain is separate.
|
|
60331
|
+
if (isCSSRequest(importer.url))
|
|
60332
|
+
continue;
|
|
60260
60333
|
// Check circular imports
|
|
60261
60334
|
const importerIndex = nodeChain.indexOf(importer);
|
|
60262
60335
|
if (importerIndex > -1) {
|
|
@@ -60474,15 +60547,12 @@ function definePlugin(config) {
|
|
|
60474
60547
|
const isBuildLib = isBuild && config.build.lib;
|
|
60475
60548
|
// ignore replace process.env in lib build
|
|
60476
60549
|
const processEnv = {};
|
|
60477
|
-
const processNodeEnv = {};
|
|
60478
60550
|
if (!isBuildLib) {
|
|
60479
60551
|
const nodeEnv = process.env.NODE_ENV || config.mode;
|
|
60480
60552
|
Object.assign(processEnv, {
|
|
60481
60553
|
'process.env': `{}`,
|
|
60482
60554
|
'global.process.env': `{}`,
|
|
60483
60555
|
'globalThis.process.env': `{}`,
|
|
60484
|
-
});
|
|
60485
|
-
Object.assign(processNodeEnv, {
|
|
60486
60556
|
'process.env.NODE_ENV': JSON.stringify(nodeEnv),
|
|
60487
60557
|
'global.process.env.NODE_ENV': JSON.stringify(nodeEnv),
|
|
60488
60558
|
'globalThis.process.env.NODE_ENV': JSON.stringify(nodeEnv),
|
|
@@ -60515,11 +60585,10 @@ function definePlugin(config) {
|
|
|
60515
60585
|
function generatePattern(ssr) {
|
|
60516
60586
|
const replaceProcessEnv = !ssr || config.ssr?.target === 'webworker';
|
|
60517
60587
|
const define = {
|
|
60518
|
-
...(replaceProcessEnv ?
|
|
60588
|
+
...(replaceProcessEnv ? processEnv : {}),
|
|
60519
60589
|
...importMetaKeys,
|
|
60520
60590
|
...userDefine,
|
|
60521
60591
|
...importMetaFallbackKeys,
|
|
60522
|
-
...(replaceProcessEnv ? processEnv : {}),
|
|
60523
60592
|
};
|
|
60524
60593
|
// Additional define fixes based on `ssr` value
|
|
60525
60594
|
if ('import.meta.env.SSR' in define) {
|
|
@@ -60925,7 +60994,8 @@ function webWorkerPlugin(config) {
|
|
|
60925
60994
|
: null,
|
|
60926
60995
|
});
|
|
60927
60996
|
};
|
|
60928
|
-
|
|
60997
|
+
workerAssetUrlRE.lastIndex = 0;
|
|
60998
|
+
if (workerAssetUrlRE.test(code)) {
|
|
60929
60999
|
const toRelativeRuntime = createToImportMetaURLBasedRelativeRuntime(outputOptions.format, config.isWorker);
|
|
60930
61000
|
let match;
|
|
60931
61001
|
s = new MagicString(code);
|
|
@@ -61083,9 +61153,8 @@ function importAnalysisPlugin(config) {
|
|
|
61083
61153
|
return null;
|
|
61084
61154
|
}
|
|
61085
61155
|
const ssr = options?.ssr === true;
|
|
61086
|
-
const prettyImporter = prettifyUrl(importer, root);
|
|
61087
61156
|
if (canSkipImportAnalysis(importer)) {
|
|
61088
|
-
debug$4?.(colors$1.dim(`[skipped] ${
|
|
61157
|
+
debug$4?.(colors$1.dim(`[skipped] ${prettifyUrl(importer, root)}`));
|
|
61089
61158
|
return null;
|
|
61090
61159
|
}
|
|
61091
61160
|
const start = performance.now();
|
|
@@ -61115,7 +61184,7 @@ function importAnalysisPlugin(config) {
|
|
|
61115
61184
|
}
|
|
61116
61185
|
if (!imports.length && !this._addedImports) {
|
|
61117
61186
|
importerModule.isSelfAccepting = false;
|
|
61118
|
-
debug$4?.(`${timeFrom(start)} ${colors$1.dim(`[no imports] ${
|
|
61187
|
+
debug$4?.(`${timeFrom(start)} ${colors$1.dim(`[no imports] ${prettifyUrl(importer, root)}`)}`);
|
|
61119
61188
|
return source;
|
|
61120
61189
|
}
|
|
61121
61190
|
let hasHMR = false;
|
|
@@ -61197,7 +61266,7 @@ function importAnalysisPlugin(config) {
|
|
|
61197
61266
|
// query can break 3rd party plugin's extension checks.
|
|
61198
61267
|
if ((isRelative || isSelfImport) &&
|
|
61199
61268
|
!hasImportInQueryParamsRE.test(url) &&
|
|
61200
|
-
!
|
|
61269
|
+
!DEP_VERSION_RE.test(url)) {
|
|
61201
61270
|
const versionMatch = importer.match(DEP_VERSION_RE);
|
|
61202
61271
|
if (versionMatch) {
|
|
61203
61272
|
url = injectQuery(url, versionMatch[1]);
|
|
@@ -61315,7 +61384,7 @@ function importAnalysisPlugin(config) {
|
|
|
61315
61384
|
if (url !== specifier) {
|
|
61316
61385
|
let rewriteDone = false;
|
|
61317
61386
|
if (depsOptimizer?.isOptimizedDepFile(resolvedId) &&
|
|
61318
|
-
!
|
|
61387
|
+
!optimizedDepChunkRE$1.test(resolvedId)) {
|
|
61319
61388
|
// for optimized cjs deps, support named imports by rewriting named imports to const assignments.
|
|
61320
61389
|
// internal optimized chunks don't need es interop and are excluded
|
|
61321
61390
|
// The browserHash in resolvedId could be stale in which case there will be a full
|
|
@@ -61326,7 +61395,7 @@ function importAnalysisPlugin(config) {
|
|
|
61326
61395
|
// Non-entry dynamic imports from dependencies will reach here as there isn't
|
|
61327
61396
|
// optimize info for them, but they don't need es interop. If the request isn't
|
|
61328
61397
|
// a dynamic import, then it is an internal Vite error
|
|
61329
|
-
if (!
|
|
61398
|
+
if (!optimizedDepDynamicRE$1.test(file)) {
|
|
61330
61399
|
config.logger.error(colors$1.red(`Vite Error, ${url} optimized info should be defined`));
|
|
61331
61400
|
}
|
|
61332
61401
|
}
|
|
@@ -61422,7 +61491,7 @@ function importAnalysisPlugin(config) {
|
|
|
61422
61491
|
? `[accepts-exports]`
|
|
61423
61492
|
: acceptedUrls.size
|
|
61424
61493
|
? `[accepts-deps]`
|
|
61425
|
-
: `[detected api usage]`} ${
|
|
61494
|
+
: `[detected api usage]`} ${prettifyUrl(importer, root)}`);
|
|
61426
61495
|
// inject hot context
|
|
61427
61496
|
str().prepend(`import { createHotContext as __vite__createHotContext } from "${clientPublicPath}";` +
|
|
61428
61497
|
`import.meta.hot = __vite__createHotContext(${JSON.stringify(normalizeHmrUrl(importerModule.url))});`);
|
|
@@ -61472,7 +61541,7 @@ function importAnalysisPlugin(config) {
|
|
|
61472
61541
|
handlePrunedModules(prunedImports, server);
|
|
61473
61542
|
}
|
|
61474
61543
|
}
|
|
61475
|
-
debug$4?.(`${timeFrom(start)} ${colors$1.dim(`[${importedUrls.size} imports rewritten] ${
|
|
61544
|
+
debug$4?.(`${timeFrom(start)} ${colors$1.dim(`[${importedUrls.size} imports rewritten] ${prettifyUrl(importer, root)}`)}`);
|
|
61476
61545
|
if (s) {
|
|
61477
61546
|
return transformStableResult(s, importer, config);
|
|
61478
61547
|
}
|
|
@@ -61992,20 +62061,19 @@ function workerImportMetaUrlPlugin(config) {
|
|
|
61992
62061
|
const query = parseRequest(id);
|
|
61993
62062
|
let s;
|
|
61994
62063
|
const cleanString = stripLiteral(code);
|
|
61995
|
-
const workerImportMetaUrlRE =
|
|
62064
|
+
const workerImportMetaUrlRE =
|
|
62065
|
+
// eslint-disable-next-line regexp/no-unused-capturing-group -- https://github.com/ota-meshi/eslint-plugin-regexp/issues/675
|
|
62066
|
+
/\bnew\s+(?:Worker|SharedWorker)\s*\(\s*(new\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*\))/dg;
|
|
61996
62067
|
let match;
|
|
61997
62068
|
while ((match = workerImportMetaUrlRE.exec(cleanString))) {
|
|
61998
|
-
const
|
|
61999
|
-
const urlIndex = allExp.indexOf(exp) + index;
|
|
62000
|
-
const urlStart = cleanString.indexOf(emptyUrl, index);
|
|
62001
|
-
const urlEnd = urlStart + emptyUrl.length;
|
|
62069
|
+
const [[, endIndex], [expStart, expEnd], [urlStart, urlEnd]] = match.indices;
|
|
62002
62070
|
const rawUrl = code.slice(urlStart, urlEnd);
|
|
62003
62071
|
// potential dynamic template string
|
|
62004
62072
|
if (rawUrl[0] === '`' && rawUrl.includes('${')) {
|
|
62005
|
-
this.error(`\`new URL(url, import.meta.url)\` is not supported in dynamic template string.`,
|
|
62073
|
+
this.error(`\`new URL(url, import.meta.url)\` is not supported in dynamic template string.`, expStart);
|
|
62006
62074
|
}
|
|
62007
62075
|
s ||= new MagicString(code);
|
|
62008
|
-
const workerType = getWorkerType(code, cleanString,
|
|
62076
|
+
const workerType = getWorkerType(code, cleanString, endIndex);
|
|
62009
62077
|
const url = rawUrl.slice(1, -1);
|
|
62010
62078
|
let file;
|
|
62011
62079
|
if (url[0] === '.') {
|
|
@@ -62034,7 +62102,7 @@ function workerImportMetaUrlPlugin(config) {
|
|
|
62034
62102
|
builtUrl = injectQuery(builtUrl, WORKER_FILE_ID);
|
|
62035
62103
|
builtUrl = injectQuery(builtUrl, `type=${workerType}`);
|
|
62036
62104
|
}
|
|
62037
|
-
s.update(
|
|
62105
|
+
s.update(expStart, expEnd,
|
|
62038
62106
|
// add `'' +` to skip vite:asset-import-meta-url plugin
|
|
62039
62107
|
`new URL('' + ${JSON.stringify(builtUrl)}, import.meta.url)`);
|
|
62040
62108
|
}
|
|
@@ -62078,13 +62146,13 @@ function assetImportMetaUrlPlugin(config) {
|
|
|
62078
62146
|
code.includes('new URL') &&
|
|
62079
62147
|
code.includes(`import.meta.url`)) {
|
|
62080
62148
|
let s;
|
|
62081
|
-
const assetImportMetaUrlRE =
|
|
62149
|
+
const assetImportMetaUrlRE =
|
|
62150
|
+
// eslint-disable-next-line regexp/no-unused-capturing-group -- https://github.com/ota-meshi/eslint-plugin-regexp/issues/675
|
|
62151
|
+
/\bnew\s+URL\s*\(\s*('[^']+'|"[^"]+"|`[^`]+`)\s*,\s*import\.meta\.url\s*(?:,\s*)?\)/dg;
|
|
62082
62152
|
const cleanString = stripLiteral(code);
|
|
62083
62153
|
let match;
|
|
62084
62154
|
while ((match = assetImportMetaUrlRE.exec(cleanString))) {
|
|
62085
|
-
const
|
|
62086
|
-
const urlStart = cleanString.indexOf(emptyUrl, index);
|
|
62087
|
-
const urlEnd = urlStart + emptyUrl.length;
|
|
62155
|
+
const [[startIndex, endIndex], [urlStart, urlEnd]] = match.indices;
|
|
62088
62156
|
const rawUrl = code.slice(urlStart, urlEnd);
|
|
62089
62157
|
if (!s)
|
|
62090
62158
|
s = new MagicString(code);
|
|
@@ -62113,7 +62181,7 @@ function assetImportMetaUrlPlugin(config) {
|
|
|
62113
62181
|
// A hack to allow 'as' & 'query' exist at the same time
|
|
62114
62182
|
query: injectQuery(queryString, 'url'),
|
|
62115
62183
|
};
|
|
62116
|
-
s.update(
|
|
62184
|
+
s.update(startIndex, endIndex, `new URL((import.meta.glob(${JSON.stringify(pattern)}, ${JSON.stringify(globOptions)}))[${pureUrl}], import.meta.url)`);
|
|
62117
62185
|
continue;
|
|
62118
62186
|
}
|
|
62119
62187
|
}
|
|
@@ -62154,11 +62222,11 @@ function assetImportMetaUrlPlugin(config) {
|
|
|
62154
62222
|
}
|
|
62155
62223
|
}
|
|
62156
62224
|
if (!builtUrl) {
|
|
62157
|
-
const rawExp = code.slice(
|
|
62225
|
+
const rawExp = code.slice(startIndex, endIndex);
|
|
62158
62226
|
config.logger.warnOnce(`\n${rawExp} doesn't exist at build time, it will remain unchanged to be resolved at runtime`);
|
|
62159
62227
|
builtUrl = url;
|
|
62160
62228
|
}
|
|
62161
|
-
s.update(
|
|
62229
|
+
s.update(startIndex, endIndex, `new URL(${JSON.stringify(builtUrl)}, import.meta.url)`);
|
|
62162
62230
|
}
|
|
62163
62231
|
if (s) {
|
|
62164
62232
|
return transformStableResult(s, id, config);
|
|
@@ -63428,9 +63496,10 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
|
|
|
63428
63496
|
'@vite/client',
|
|
63429
63497
|
'@vite/env',
|
|
63430
63498
|
];
|
|
63499
|
+
const isUnlessEntry = (path) => !entries.includes(path);
|
|
63431
63500
|
const externalUnlessEntry = ({ path }) => ({
|
|
63432
63501
|
path,
|
|
63433
|
-
external:
|
|
63502
|
+
external: isUnlessEntry(path),
|
|
63434
63503
|
});
|
|
63435
63504
|
const doTransformGlobImport = async (contents, id, loader) => {
|
|
63436
63505
|
let transpiledContents;
|
|
@@ -63635,19 +63704,32 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
|
|
|
63635
63704
|
// should be faster than doing it in the catch-all via js
|
|
63636
63705
|
// they are done after the bare import resolve because a package name
|
|
63637
63706
|
// may end with these extensions
|
|
63707
|
+
const setupExternalize = (filter, doExternalize) => {
|
|
63708
|
+
build.onResolve({ filter }, ({ path }) => {
|
|
63709
|
+
return {
|
|
63710
|
+
path,
|
|
63711
|
+
external: doExternalize(path),
|
|
63712
|
+
};
|
|
63713
|
+
});
|
|
63714
|
+
// onResolve is not called for glob imports.
|
|
63715
|
+
// we need to add that here as well until esbuild calls onResolve for glob imports.
|
|
63716
|
+
// https://github.com/evanw/esbuild/issues/3317
|
|
63717
|
+
build.onLoad({ filter, namespace: 'file' }, () => {
|
|
63718
|
+
const externalOnLoadResult = {
|
|
63719
|
+
loader: 'js',
|
|
63720
|
+
contents: 'export default {}',
|
|
63721
|
+
};
|
|
63722
|
+
return externalOnLoadResult;
|
|
63723
|
+
});
|
|
63724
|
+
};
|
|
63638
63725
|
// css
|
|
63639
|
-
|
|
63726
|
+
setupExternalize(CSS_LANGS_RE, isUnlessEntry);
|
|
63640
63727
|
// json & wasm
|
|
63641
|
-
|
|
63728
|
+
setupExternalize(/\.(json|json5|wasm)$/, isUnlessEntry);
|
|
63642
63729
|
// known asset types
|
|
63643
|
-
|
|
63644
|
-
filter: new RegExp(`\\.(${KNOWN_ASSET_TYPES.join('|')})$`),
|
|
63645
|
-
}, externalUnlessEntry);
|
|
63730
|
+
setupExternalize(new RegExp(`\\.(${KNOWN_ASSET_TYPES.join('|')})$`), isUnlessEntry);
|
|
63646
63731
|
// known vite query types: ?worker, ?raw
|
|
63647
|
-
|
|
63648
|
-
path,
|
|
63649
|
-
external: true,
|
|
63650
|
-
}));
|
|
63732
|
+
setupExternalize(SPECIAL_QUERY_RE, () => true);
|
|
63651
63733
|
// catch all -------------------------------------------------------------
|
|
63652
63734
|
build.onResolve({
|
|
63653
63735
|
filter: /.*/,
|
|
@@ -63952,7 +64034,7 @@ async function createDepsOptimizer(config, server) {
|
|
|
63952
64034
|
newDepsToLog = [];
|
|
63953
64035
|
}
|
|
63954
64036
|
};
|
|
63955
|
-
let depOptimizationProcessing =
|
|
64037
|
+
let depOptimizationProcessing = promiseWithResolvers();
|
|
63956
64038
|
let depOptimizationProcessingQueue = [];
|
|
63957
64039
|
const resolveEnqueuedProcessingPromises = () => {
|
|
63958
64040
|
// Resolve all the processings (including the ones which were delayed)
|
|
@@ -64047,7 +64129,7 @@ async function createDepsOptimizer(config, server) {
|
|
|
64047
64129
|
depOptimizationProcessingQueue.push(depOptimizationProcessing);
|
|
64048
64130
|
// Create a new promise for the next rerun, discovered missing
|
|
64049
64131
|
// dependencies will be assigned this promise from this point
|
|
64050
|
-
depOptimizationProcessing =
|
|
64132
|
+
depOptimizationProcessing = promiseWithResolvers();
|
|
64051
64133
|
}
|
|
64052
64134
|
function prepareKnownDeps() {
|
|
64053
64135
|
const knownDeps = {};
|
|
@@ -64770,7 +64852,7 @@ function runOptimizeDeps(resolvedConfig, depsInfo, ssr = resolvedConfig.command
|
|
|
64770
64852
|
});
|
|
64771
64853
|
}
|
|
64772
64854
|
for (const o of Object.keys(meta.outputs)) {
|
|
64773
|
-
if (!
|
|
64855
|
+
if (!jsMapExtensionRE.test(o)) {
|
|
64774
64856
|
const id = path$o
|
|
64775
64857
|
.relative(processingCacheDirOutputPath, o)
|
|
64776
64858
|
.replace(jsExtensionRE, '');
|
|
@@ -64954,13 +65036,6 @@ async function addManuallyIncludedOptimizeDeps(deps, config, ssr, extra = [], fi
|
|
|
64954
65036
|
}
|
|
64955
65037
|
}
|
|
64956
65038
|
}
|
|
64957
|
-
function newDepOptimizationProcessing() {
|
|
64958
|
-
let resolve;
|
|
64959
|
-
const promise = new Promise((_resolve) => {
|
|
64960
|
-
resolve = _resolve;
|
|
64961
|
-
});
|
|
64962
|
-
return { promise, resolve: resolve };
|
|
64963
|
-
}
|
|
64964
65039
|
// Convert to { id: src }
|
|
64965
65040
|
function depsFromOptimizedDepInfo(depsInfo) {
|
|
64966
65041
|
const obj = {};
|
|
@@ -65327,7 +65402,6 @@ var index = {
|
|
|
65327
65402
|
initDepsOptimizerMetadata: initDepsOptimizerMetadata,
|
|
65328
65403
|
initDevSsrDepsOptimizer: initDevSsrDepsOptimizer,
|
|
65329
65404
|
loadCachedDepOptimizationMetadata: loadCachedDepOptimizationMetadata,
|
|
65330
|
-
newDepOptimizationProcessing: newDepOptimizationProcessing,
|
|
65331
65405
|
optimizeDeps: optimizeDeps,
|
|
65332
65406
|
optimizeServerSsrDeps: optimizeServerSsrDeps,
|
|
65333
65407
|
optimizedDepInfoFromFile: optimizedDepInfoFromFile,
|
|
@@ -65346,7 +65420,7 @@ const isModernFlag = `__VITE_IS_MODERN__`;
|
|
|
65346
65420
|
const preloadMethod = `__vitePreload`;
|
|
65347
65421
|
const preloadMarker = `__VITE_PRELOAD__`;
|
|
65348
65422
|
const preloadHelperId = '\0vite/preload-helper.js';
|
|
65349
|
-
const preloadMarkerWithQuote = new RegExp(`['"]${preloadMarker}['"]
|
|
65423
|
+
const preloadMarkerWithQuote = new RegExp(`['"]${preloadMarker}['"]`, 'g');
|
|
65350
65424
|
const dynamicImportPrefixRE = /import\s*\(/;
|
|
65351
65425
|
// TODO: abstract
|
|
65352
65426
|
const optimizedDepChunkRE = /\/chunk-[A-Z\d]{8}\.js/;
|
|
@@ -65356,11 +65430,9 @@ function toRelativePath(filename, importer) {
|
|
|
65356
65430
|
return relPath[0] === '.' ? relPath : `./${relPath}`;
|
|
65357
65431
|
}
|
|
65358
65432
|
function indexOfMatchInSlice(str, reg, pos = 0) {
|
|
65359
|
-
|
|
65360
|
-
|
|
65361
|
-
|
|
65362
|
-
const matcher = str.match(reg);
|
|
65363
|
-
return matcher?.index !== undefined ? matcher.index + pos : -1;
|
|
65433
|
+
reg.lastIndex = pos;
|
|
65434
|
+
const result = reg.exec(str);
|
|
65435
|
+
return result?.index ?? -1;
|
|
65364
65436
|
}
|
|
65365
65437
|
/**
|
|
65366
65438
|
* Helper for preloading CSS and direct imports of async chunks in parallel to
|
|
@@ -65373,51 +65445,52 @@ function detectScriptRel() {
|
|
|
65373
65445
|
: 'preload';
|
|
65374
65446
|
}
|
|
65375
65447
|
function preload(baseModule, deps, importerUrl) {
|
|
65448
|
+
let promise = Promise.resolve();
|
|
65376
65449
|
// @ts-expect-error __VITE_IS_MODERN__ will be replaced with boolean later
|
|
65377
|
-
if (
|
|
65378
|
-
|
|
65379
|
-
|
|
65380
|
-
|
|
65381
|
-
|
|
65382
|
-
|
|
65383
|
-
|
|
65384
|
-
|
|
65385
|
-
|
|
65386
|
-
|
|
65387
|
-
|
|
65388
|
-
|
|
65389
|
-
|
|
65390
|
-
|
|
65391
|
-
|
|
65392
|
-
|
|
65393
|
-
|
|
65394
|
-
|
|
65395
|
-
|
|
65396
|
-
|
|
65397
|
-
|
|
65398
|
-
|
|
65399
|
-
return;
|
|
65450
|
+
if (__VITE_IS_MODERN__ && deps && deps.length > 0) {
|
|
65451
|
+
const links = document.getElementsByTagName('link');
|
|
65452
|
+
promise = Promise.all(deps.map((dep) => {
|
|
65453
|
+
// @ts-expect-error assetsURL is declared before preload.toString()
|
|
65454
|
+
dep = assetsURL(dep, importerUrl);
|
|
65455
|
+
if (dep in seen)
|
|
65456
|
+
return;
|
|
65457
|
+
seen[dep] = true;
|
|
65458
|
+
const isCss = dep.endsWith('.css');
|
|
65459
|
+
const cssSelector = isCss ? '[rel="stylesheet"]' : '';
|
|
65460
|
+
const isBaseRelative = !!importerUrl;
|
|
65461
|
+
// check if the file is already preloaded by SSR markup
|
|
65462
|
+
if (isBaseRelative) {
|
|
65463
|
+
// When isBaseRelative is true then we have `importerUrl` and `dep` is
|
|
65464
|
+
// already converted to an absolute URL by the `assetsURL` function
|
|
65465
|
+
for (let i = links.length - 1; i >= 0; i--) {
|
|
65466
|
+
const link = links[i];
|
|
65467
|
+
// The `links[i].href` is an absolute URL thanks to browser doing the work
|
|
65468
|
+
// for us. See https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#reflecting-content-attributes-in-idl-attributes:idl-domstring-5
|
|
65469
|
+
if (link.href === dep && (!isCss || link.rel === 'stylesheet')) {
|
|
65470
|
+
return;
|
|
65471
|
+
}
|
|
65400
65472
|
}
|
|
65401
65473
|
}
|
|
65402
|
-
|
|
65403
|
-
|
|
65404
|
-
|
|
65405
|
-
|
|
65406
|
-
|
|
65407
|
-
|
|
65408
|
-
|
|
65409
|
-
|
|
65410
|
-
|
|
65411
|
-
|
|
65412
|
-
|
|
65413
|
-
|
|
65414
|
-
|
|
65415
|
-
|
|
65416
|
-
|
|
65417
|
-
|
|
65418
|
-
}
|
|
65419
|
-
}
|
|
65420
|
-
}
|
|
65474
|
+
else if (document.querySelector(`link[href="${dep}"]${cssSelector}`)) {
|
|
65475
|
+
return;
|
|
65476
|
+
}
|
|
65477
|
+
const link = document.createElement('link');
|
|
65478
|
+
link.rel = isCss ? 'stylesheet' : scriptRel;
|
|
65479
|
+
if (!isCss) {
|
|
65480
|
+
link.as = 'script';
|
|
65481
|
+
link.crossOrigin = '';
|
|
65482
|
+
}
|
|
65483
|
+
link.href = dep;
|
|
65484
|
+
document.head.appendChild(link);
|
|
65485
|
+
if (isCss) {
|
|
65486
|
+
return new Promise((res, rej) => {
|
|
65487
|
+
link.addEventListener('load', res);
|
|
65488
|
+
link.addEventListener('error', () => rej(new Error(`Unable to preload CSS for ${dep}`)));
|
|
65489
|
+
});
|
|
65490
|
+
}
|
|
65491
|
+
}));
|
|
65492
|
+
}
|
|
65493
|
+
return promise
|
|
65421
65494
|
.then(() => baseModule())
|
|
65422
65495
|
.catch((err) => {
|
|
65423
65496
|
const e = new Event('vite:preloadError', { cancelable: true });
|
|
@@ -65568,7 +65641,7 @@ function buildImportAnalysisPlugin(config) {
|
|
|
65568
65641
|
const [url, resolvedId] = await normalizeUrl(specifier, start);
|
|
65569
65642
|
if (url !== specifier) {
|
|
65570
65643
|
if (depsOptimizer.isOptimizedDepFile(resolvedId) &&
|
|
65571
|
-
!
|
|
65644
|
+
!optimizedDepChunkRE.test(resolvedId)) {
|
|
65572
65645
|
const file = cleanUrl(resolvedId); // Remove ?v={hash}
|
|
65573
65646
|
const needsInterop = await optimizedDepNeedsInterop(depsOptimizer.metadata, file, config, ssr);
|
|
65574
65647
|
let rewriteDone = false;
|
|
@@ -65576,7 +65649,7 @@ function buildImportAnalysisPlugin(config) {
|
|
|
65576
65649
|
// Non-entry dynamic imports from dependencies will reach here as there isn't
|
|
65577
65650
|
// optimize info for them, but they don't need es interop. If the request isn't
|
|
65578
65651
|
// a dynamic import, then it is an internal Vite error
|
|
65579
|
-
if (!
|
|
65652
|
+
if (!optimizedDepDynamicRE.test(file)) {
|
|
65580
65653
|
config.logger.error(colors$1.red(`Vite Error, ${url} optimized info should be defined`));
|
|
65581
65654
|
}
|
|
65582
65655
|
}
|
|
@@ -66398,7 +66471,7 @@ function onRollupWarning(warning, warn, config) {
|
|
|
66398
66471
|
const id = warning.id;
|
|
66399
66472
|
const exporter = warning.exporter;
|
|
66400
66473
|
// throw unless it's commonjs external...
|
|
66401
|
-
if (!id ||
|
|
66474
|
+
if (!id || !id.endsWith('?commonjs-external')) {
|
|
66402
66475
|
throw new Error(`[vite]: Rollup failed to resolve import "${exporter}" from "${id}".\n` +
|
|
66403
66476
|
`This is most likely unintended because it can break your application at runtime.\n` +
|
|
66404
66477
|
`If you do want to externalize this module explicitly add it to\n` +
|