vite 2.7.0-beta.2 → 2.7.0-beta.6
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/CHANGELOG.md +48 -0
- package/dist/node/chunks/{dep-caa1572d.js → dep-0183a921.js} +424 -199
- package/dist/node/chunks/dep-0183a921.js.map +1 -0
- package/dist/node/chunks/{dep-39172335.js → dep-146e2d5f.js} +2 -2
- package/dist/node/chunks/{dep-39172335.js.map → dep-146e2d5f.js.map} +1 -1
- package/dist/node/chunks/{dep-b89007db.js → dep-1b2328e8.js} +3 -3
- package/dist/node/chunks/dep-1b2328e8.js.map +1 -0
- package/dist/node/chunks/{dep-e85c9ca9.js → dep-48461e78.js} +2 -2
- package/dist/node/chunks/{dep-e85c9ca9.js.map → dep-48461e78.js.map} +1 -1
- package/dist/node/cli.js +4 -7
- package/dist/node/cli.js.map +1 -1
- package/dist/node/index.d.ts +18 -7
- package/dist/node/index.js +1 -1
- package/dist/node/terser.js +186 -54
- package/package.json +7 -6
- package/types/commonjs.d.ts +2 -2
- package/types/shims.d.ts +2 -3
- package/dist/node/chunks/dep-b89007db.js.map +0 -1
- package/dist/node/chunks/dep-caa1572d.js.map +0 -1
|
@@ -10,7 +10,7 @@ var require$$0$a = require('events');
|
|
|
10
10
|
var require$$0$7 = require('url');
|
|
11
11
|
var require$$1$2 = require('http');
|
|
12
12
|
var require$$0$9 = require('stream');
|
|
13
|
-
var resolve$
|
|
13
|
+
var resolve$3 = require('resolve');
|
|
14
14
|
var require$$0$6 = require('module');
|
|
15
15
|
var perf_hooks = require('perf_hooks');
|
|
16
16
|
var require$$1$3 = require('https');
|
|
@@ -50,7 +50,7 @@ var require$$0__default$5 = /*#__PURE__*/_interopDefaultLegacy(require$$0$a);
|
|
|
50
50
|
var require$$0__default$6 = /*#__PURE__*/_interopDefaultLegacy(require$$0$7);
|
|
51
51
|
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
|
|
52
52
|
var require$$0__default$4 = /*#__PURE__*/_interopDefaultLegacy(require$$0$9);
|
|
53
|
-
var resolve__default = /*#__PURE__*/_interopDefaultLegacy(resolve$
|
|
53
|
+
var resolve__default = /*#__PURE__*/_interopDefaultLegacy(resolve$3);
|
|
54
54
|
var require$$0__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$0$6);
|
|
55
55
|
var require$$1__default$3 = /*#__PURE__*/_interopDefaultLegacy(require$$1$3);
|
|
56
56
|
var require$$0__default$7 = /*#__PURE__*/_interopDefaultLegacy(require$$0$8);
|
|
@@ -3387,7 +3387,7 @@ function normalizePath$5(input) {
|
|
|
3387
3387
|
/**
|
|
3388
3388
|
* Attempts to resolve `input` URL relative to `base`.
|
|
3389
3389
|
*/
|
|
3390
|
-
function resolve$
|
|
3390
|
+
function resolve$2(input, base) {
|
|
3391
3391
|
if (!base)
|
|
3392
3392
|
base = '';
|
|
3393
3393
|
// Absolute URLs are very easy to resolve right.
|
|
@@ -3455,7 +3455,7 @@ function resolve$1$1(input, base) {
|
|
|
3455
3455
|
// https://github.com/chromium/chromium/blob/da4adbb3/third_party/blink/renderer/devtools/front_end/sdk/SourceMap.js#L400-L401
|
|
3456
3456
|
if (base && !base.endsWith('/'))
|
|
3457
3457
|
base += '/';
|
|
3458
|
-
return resolve$
|
|
3458
|
+
return resolve$2(input, base);
|
|
3459
3459
|
}
|
|
3460
3460
|
|
|
3461
3461
|
/**
|
|
@@ -3958,6 +3958,7 @@ const externalRE = /^(https?:)?\/\//;
|
|
|
3958
3958
|
const isExternalUrl = (url) => externalRE.test(url);
|
|
3959
3959
|
const dataUrlRE = /^\s*data:/i;
|
|
3960
3960
|
const isDataUrl = (url) => dataUrlRE.test(url);
|
|
3961
|
+
const virtualModuleRE = /virtual-module:.*/;
|
|
3961
3962
|
const knownJsSrcRE = /\.((j|t)sx?|mjs|vue|marko|svelte|astro)($|\?)/;
|
|
3962
3963
|
const isJSRequest = (url) => {
|
|
3963
3964
|
url = cleanUrl(url);
|
|
@@ -3973,7 +3974,7 @@ const knownTsRE = /\.(ts|mts|cts|tsx)$/;
|
|
|
3973
3974
|
const knownTsOutputRE = /\.(js|mjs|cjs|jsx)$/;
|
|
3974
3975
|
const isTsRequest = (url) => knownTsRE.test(cleanUrl(url));
|
|
3975
3976
|
const isPossibleTsOutput = (url) => knownTsOutputRE.test(cleanUrl(url));
|
|
3976
|
-
const getTsSrcPath = (filename) => filename.replace(/\.([cm])?(js)(x?)
|
|
3977
|
+
const getTsSrcPath = (filename) => filename.replace(/\.([cm])?(js)(x?)(\?|$)/, '.$1ts$3');
|
|
3977
3978
|
const importQueryRE = /(\?|&)import=?(?:&|$)/;
|
|
3978
3979
|
const internalPrefixes = [
|
|
3979
3980
|
FS_PREFIX,
|
|
@@ -4276,9 +4277,6 @@ function combineSourcemaps(filename, sourcemapList) {
|
|
|
4276
4277
|
}
|
|
4277
4278
|
return map;
|
|
4278
4279
|
}
|
|
4279
|
-
function unique(arr) {
|
|
4280
|
-
return Array.from(new Set(arr));
|
|
4281
|
-
}
|
|
4282
4280
|
function resolveHostname(optionsHost) {
|
|
4283
4281
|
let host;
|
|
4284
4282
|
if (optionsHost === undefined ||
|
|
@@ -4349,9 +4347,8 @@ function createLogger(level = 'info', options = {}) {
|
|
|
4349
4347
|
const loggedErrors = new WeakSet();
|
|
4350
4348
|
const { prefix = '[vite]', allowClearScreen = true } = options;
|
|
4351
4349
|
const thresh = LogLevels[level];
|
|
4352
|
-
const
|
|
4353
|
-
|
|
4354
|
-
: () => { };
|
|
4350
|
+
const canClearScreen = allowClearScreen && process.stdout.isTTY && !process.env.CI;
|
|
4351
|
+
const clear = canClearScreen ? clearScreen : () => { };
|
|
4355
4352
|
function output(type, msg, options = {}) {
|
|
4356
4353
|
if (thresh >= LogLevels[type]) {
|
|
4357
4354
|
const method = type === 'info' ? 'log' : type;
|
|
@@ -4371,18 +4368,23 @@ function createLogger(level = 'info', options = {}) {
|
|
|
4371
4368
|
if (options.error) {
|
|
4372
4369
|
loggedErrors.add(options.error);
|
|
4373
4370
|
}
|
|
4374
|
-
if (
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
console[method](format(), source.yellow(`(x${sameCount + 1})`));
|
|
4378
|
-
}
|
|
4379
|
-
else {
|
|
4380
|
-
sameCount = 0;
|
|
4381
|
-
lastMsg = msg;
|
|
4382
|
-
lastType = type;
|
|
4383
|
-
if (options.clear) {
|
|
4371
|
+
if (canClearScreen) {
|
|
4372
|
+
if (type === lastType && msg === lastMsg) {
|
|
4373
|
+
sameCount++;
|
|
4384
4374
|
clear();
|
|
4375
|
+
console[method](format(), source.yellow(`(x${sameCount + 1})`));
|
|
4376
|
+
}
|
|
4377
|
+
else {
|
|
4378
|
+
sameCount = 0;
|
|
4379
|
+
lastMsg = msg;
|
|
4380
|
+
lastType = type;
|
|
4381
|
+
if (options.clear) {
|
|
4382
|
+
clear();
|
|
4383
|
+
}
|
|
4384
|
+
console[method](format());
|
|
4385
4385
|
}
|
|
4386
|
+
}
|
|
4387
|
+
else {
|
|
4386
4388
|
console[method](format());
|
|
4387
4389
|
}
|
|
4388
4390
|
}
|
|
@@ -19605,7 +19607,7 @@ const plugins = (config, file) => {
|
|
|
19605
19607
|
|
|
19606
19608
|
var plugins_1 = plugins;
|
|
19607
19609
|
|
|
19608
|
-
const resolve$
|
|
19610
|
+
const resolve$1 = path__default.resolve;
|
|
19609
19611
|
|
|
19610
19612
|
const config$1 = dist$2;
|
|
19611
19613
|
const yaml = yaml$1;
|
|
@@ -19744,7 +19746,7 @@ const rc = withTypeScriptLoader((ctx, path, options) => {
|
|
|
19744
19746
|
/**
|
|
19745
19747
|
* @type {String} `process.cwd()`
|
|
19746
19748
|
*/
|
|
19747
|
-
path = path ? resolve$
|
|
19749
|
+
path = path ? resolve$1(path) : process.cwd();
|
|
19748
19750
|
|
|
19749
19751
|
return config$1.lilconfig('postcss', options)
|
|
19750
19752
|
.search(path)
|
|
@@ -19766,7 +19768,7 @@ rc.sync = withTypeScriptLoader((ctx, path, options) => {
|
|
|
19766
19768
|
/**
|
|
19767
19769
|
* @type {String} `process.cwd()`
|
|
19768
19770
|
*/
|
|
19769
|
-
path = path ? resolve$
|
|
19771
|
+
path = path ? resolve$1(path) : process.cwd();
|
|
19770
19772
|
|
|
19771
19773
|
const result = config$1.lilconfigSync('postcss', options).search(path);
|
|
19772
19774
|
|
|
@@ -20383,7 +20385,7 @@ async function compileCSS(id, code, config, urlReplacer, atImportResolvers, serv
|
|
|
20383
20385
|
replacer: urlReplacer
|
|
20384
20386
|
}));
|
|
20385
20387
|
if (isModule) {
|
|
20386
|
-
postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-
|
|
20388
|
+
postcssPlugins.unshift((await Promise.resolve().then(function () { return require('./dep-48461e78.js'); }).then(function (n) { return n.index; })).default({
|
|
20387
20389
|
...modulesOptions,
|
|
20388
20390
|
getJSON(cssFileName, _modules, outputFileName) {
|
|
20389
20391
|
modules = _modules;
|
|
@@ -21348,7 +21350,7 @@ const assetAttrsConfig = {
|
|
|
21348
21350
|
const isAsyncScriptMap = new WeakMap();
|
|
21349
21351
|
async function traverseHtml(html, filePath, visitor) {
|
|
21350
21352
|
// lazy load compiler
|
|
21351
|
-
const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-
|
|
21353
|
+
const { parse, transform } = await Promise.resolve().then(function () { return require('./dep-1b2328e8.js'); }).then(function (n) { return n.compilerDom_cjs; });
|
|
21352
21354
|
// @vue/compiler-core doesn't like lowercase doctypes
|
|
21353
21355
|
html = html.replace(/<!doctype\s/i, '<!DOCTYPE ');
|
|
21354
21356
|
try {
|
|
@@ -27628,7 +27630,7 @@ function getRequireStringArg(node) {
|
|
|
27628
27630
|
function hasDynamicModuleForPath(source, id, dynamicRequireModuleSet) {
|
|
27629
27631
|
if (!/^(?:\.{0,2}[/\\]|[A-Za-z]:[/\\])/.test(source)) {
|
|
27630
27632
|
try {
|
|
27631
|
-
const resolvedPath = normalizePathSlashes(resolve$
|
|
27633
|
+
const resolvedPath = normalizePathSlashes(resolve$3.sync(source, { basedir: path$t.dirname(id) }));
|
|
27632
27634
|
if (dynamicRequireModuleSet.has(resolvedPath)) {
|
|
27633
27635
|
return true;
|
|
27634
27636
|
}
|
|
@@ -29883,7 +29885,7 @@ function toName(name, entry) {
|
|
|
29883
29885
|
* @param {string[]} [options.conditions]
|
|
29884
29886
|
* @param {boolean} [options.unsafe]
|
|
29885
29887
|
*/
|
|
29886
|
-
function resolve
|
|
29888
|
+
function resolve(pkg, entry='.', options={}) {
|
|
29887
29889
|
let { name, exports } = pkg;
|
|
29888
29890
|
|
|
29889
29891
|
if (exports) {
|
|
@@ -29972,12 +29974,11 @@ function resolvePlugin(baseOptions) {
|
|
|
29972
29974
|
isRequire,
|
|
29973
29975
|
isFromTsImporter: isTsRequest(importer !== null && importer !== void 0 ? importer : '')
|
|
29974
29976
|
};
|
|
29975
|
-
const preserveSymlinks = !!(server === null || server === void 0 ? void 0 : server.config.resolve.preserveSymlinks);
|
|
29976
29977
|
let res;
|
|
29977
29978
|
// explicit fs paths that starts with /@fs/*
|
|
29978
29979
|
if (asSrc && id.startsWith(FS_PREFIX)) {
|
|
29979
29980
|
const fsPath = fsPathFromId(id);
|
|
29980
|
-
res = tryFsResolve(fsPath, options
|
|
29981
|
+
res = tryFsResolve(fsPath, options);
|
|
29981
29982
|
isDebug$5 && debug$d(`[@fs] ${source.cyan(id)} -> ${source.dim(res)}`);
|
|
29982
29983
|
// always return here even if res doesn't exist since /@fs/ is explicit
|
|
29983
29984
|
// if the file doesn't exist it should be a 404
|
|
@@ -29987,7 +29988,7 @@ function resolvePlugin(baseOptions) {
|
|
|
29987
29988
|
// /foo -> /fs-root/foo
|
|
29988
29989
|
if (asSrc && id.startsWith('/')) {
|
|
29989
29990
|
const fsPath = path__default.resolve(root, id.slice(1));
|
|
29990
|
-
if ((res = tryFsResolve(fsPath, options
|
|
29991
|
+
if ((res = tryFsResolve(fsPath, options))) {
|
|
29991
29992
|
isDebug$5 && debug$d(`[url] ${source.cyan(id)} -> ${source.dim(res)}`);
|
|
29992
29993
|
return res;
|
|
29993
29994
|
}
|
|
@@ -30009,10 +30010,10 @@ function resolvePlugin(baseOptions) {
|
|
|
30009
30010
|
}
|
|
30010
30011
|
}
|
|
30011
30012
|
if (targetWeb &&
|
|
30012
|
-
(res = tryResolveBrowserMapping(fsPath, importer, options, true
|
|
30013
|
+
(res = tryResolveBrowserMapping(fsPath, importer, options, true))) {
|
|
30013
30014
|
return res;
|
|
30014
30015
|
}
|
|
30015
|
-
if ((res = tryFsResolve(fsPath, options
|
|
30016
|
+
if ((res = tryFsResolve(fsPath, options))) {
|
|
30016
30017
|
isDebug$5 && debug$d(`[relative] ${source.cyan(id)} -> ${source.dim(res)}`);
|
|
30017
30018
|
const pkg = importer != null && idToPkgMap.get(importer);
|
|
30018
30019
|
if (pkg) {
|
|
@@ -30026,8 +30027,7 @@ function resolvePlugin(baseOptions) {
|
|
|
30026
30027
|
}
|
|
30027
30028
|
}
|
|
30028
30029
|
// absolute fs paths
|
|
30029
|
-
if (path__default.isAbsolute(id) &&
|
|
30030
|
-
(res = tryFsResolve(id, options, preserveSymlinks))) {
|
|
30030
|
+
if (path__default.isAbsolute(id) && (res = tryFsResolve(id, options))) {
|
|
30031
30031
|
isDebug$5 && debug$d(`[fs] ${source.cyan(id)} -> ${source.dim(res)}`);
|
|
30032
30032
|
return res;
|
|
30033
30033
|
}
|
|
@@ -30052,7 +30052,7 @@ function resolvePlugin(baseOptions) {
|
|
|
30052
30052
|
return res;
|
|
30053
30053
|
}
|
|
30054
30054
|
if (targetWeb &&
|
|
30055
|
-
(res = tryResolveBrowserMapping(id, importer, options, false
|
|
30055
|
+
(res = tryResolveBrowserMapping(id, importer, options, false))) {
|
|
30056
30056
|
return res;
|
|
30057
30057
|
}
|
|
30058
30058
|
if ((res = tryNodeResolve(id, importer, options, targetWeb, server, ssr))) {
|
|
@@ -30101,7 +30101,7 @@ function resolvePlugin(baseOptions) {
|
|
|
30101
30101
|
}
|
|
30102
30102
|
};
|
|
30103
30103
|
}
|
|
30104
|
-
function tryFsResolve(fsPath, options,
|
|
30104
|
+
function tryFsResolve(fsPath, options, tryIndex = true, targetWeb = true) {
|
|
30105
30105
|
let file = fsPath;
|
|
30106
30106
|
let postfix = '';
|
|
30107
30107
|
let postfixIndex = fsPath.indexOf('?');
|
|
@@ -30115,36 +30115,36 @@ function tryFsResolve(fsPath, options, preserveSymlinks, tryIndex = true, target
|
|
|
30115
30115
|
let res;
|
|
30116
30116
|
// if we fould postfix exist, we should first try resolving file with postfix. details see #4703.
|
|
30117
30117
|
if (postfix &&
|
|
30118
|
-
(res = tryResolveFile(fsPath, '', options, false, targetWeb,
|
|
30118
|
+
(res = tryResolveFile(fsPath, '', options, false, targetWeb, options.tryPrefix, options.skipPackageJson))) {
|
|
30119
30119
|
return res;
|
|
30120
30120
|
}
|
|
30121
|
-
if ((res = tryResolveFile(file, postfix, options, false, targetWeb,
|
|
30121
|
+
if ((res = tryResolveFile(file, postfix, options, false, targetWeb, options.tryPrefix, options.skipPackageJson))) {
|
|
30122
30122
|
return res;
|
|
30123
30123
|
}
|
|
30124
30124
|
for (const ext of options.extensions || DEFAULT_EXTENSIONS$1) {
|
|
30125
30125
|
if (postfix &&
|
|
30126
|
-
(res = tryResolveFile(fsPath + ext, '', options, false, targetWeb,
|
|
30126
|
+
(res = tryResolveFile(fsPath + ext, '', options, false, targetWeb, options.tryPrefix, options.skipPackageJson))) {
|
|
30127
30127
|
return res;
|
|
30128
30128
|
}
|
|
30129
|
-
if ((res = tryResolveFile(file + ext, postfix, options, false, targetWeb,
|
|
30129
|
+
if ((res = tryResolveFile(file + ext, postfix, options, false, targetWeb, options.tryPrefix, options.skipPackageJson))) {
|
|
30130
30130
|
return res;
|
|
30131
30131
|
}
|
|
30132
30132
|
}
|
|
30133
30133
|
if (postfix &&
|
|
30134
|
-
(res = tryResolveFile(fsPath, '', options, tryIndex, targetWeb,
|
|
30134
|
+
(res = tryResolveFile(fsPath, '', options, tryIndex, targetWeb, options.tryPrefix, options.skipPackageJson))) {
|
|
30135
30135
|
return res;
|
|
30136
30136
|
}
|
|
30137
|
-
if ((res = tryResolveFile(file, postfix, options, tryIndex, targetWeb,
|
|
30137
|
+
if ((res = tryResolveFile(file, postfix, options, tryIndex, targetWeb, options.tryPrefix, options.skipPackageJson))) {
|
|
30138
30138
|
return res;
|
|
30139
30139
|
}
|
|
30140
30140
|
}
|
|
30141
|
-
function tryResolveFile(file, postfix, options, tryIndex, targetWeb,
|
|
30141
|
+
function tryResolveFile(file, postfix, options, tryIndex, targetWeb, tryPrefix, skipPackageJson) {
|
|
30142
30142
|
// #2051 if we don't have read permission on a directory, existsSync() still
|
|
30143
30143
|
// works and will result in massively slow subsequent checks (which are
|
|
30144
30144
|
// unnecessary in the first place)
|
|
30145
30145
|
if (isFileReadable(file)) {
|
|
30146
30146
|
if (!fs__default.statSync(file).isDirectory()) {
|
|
30147
|
-
return getRealPath(file, preserveSymlinks) + postfix;
|
|
30147
|
+
return getRealPath(file, options.preserveSymlinks) + postfix;
|
|
30148
30148
|
}
|
|
30149
30149
|
else if (tryIndex) {
|
|
30150
30150
|
if (!skipPackageJson) {
|
|
@@ -30152,11 +30152,11 @@ function tryResolveFile(file, postfix, options, tryIndex, targetWeb, preserveSym
|
|
|
30152
30152
|
if (fs__default.existsSync(pkgPath)) {
|
|
30153
30153
|
// path points to a node package
|
|
30154
30154
|
const pkg = loadPackageData(pkgPath);
|
|
30155
|
-
const resolved = resolvePackageEntry(file, pkg,
|
|
30155
|
+
const resolved = resolvePackageEntry(file, pkg, targetWeb, options);
|
|
30156
30156
|
return resolved;
|
|
30157
30157
|
}
|
|
30158
30158
|
}
|
|
30159
|
-
const index = tryFsResolve(file + '/index', options
|
|
30159
|
+
const index = tryFsResolve(file + '/index', options);
|
|
30160
30160
|
if (index)
|
|
30161
30161
|
return index + postfix;
|
|
30162
30162
|
}
|
|
@@ -30164,11 +30164,11 @@ function tryResolveFile(file, postfix, options, tryIndex, targetWeb, preserveSym
|
|
|
30164
30164
|
const tryTsExtension = options.isFromTsImporter && isPossibleTsOutput(file);
|
|
30165
30165
|
if (tryTsExtension) {
|
|
30166
30166
|
const tsSrcPath = getTsSrcPath(file);
|
|
30167
|
-
return tryResolveFile(tsSrcPath, postfix, options, tryIndex, targetWeb,
|
|
30167
|
+
return tryResolveFile(tsSrcPath, postfix, options, tryIndex, targetWeb, tryPrefix, skipPackageJson);
|
|
30168
30168
|
}
|
|
30169
30169
|
if (tryPrefix) {
|
|
30170
30170
|
const prefixed = `${path__default.dirname(file)}/${tryPrefix}${path__default.basename(file)}`;
|
|
30171
|
-
return tryResolveFile(prefixed, postfix, options, tryIndex, targetWeb
|
|
30171
|
+
return tryResolveFile(prefixed, postfix, options, tryIndex, targetWeb);
|
|
30172
30172
|
}
|
|
30173
30173
|
}
|
|
30174
30174
|
const idToPkgMap = new Map();
|
|
@@ -30181,11 +30181,28 @@ function tryNodeResolve(id, importer, options, targetWeb, server, ssr) {
|
|
|
30181
30181
|
const lastArrowIndex = id.lastIndexOf('>');
|
|
30182
30182
|
const nestedRoot = id.substring(0, lastArrowIndex).trim();
|
|
30183
30183
|
const nestedPath = id.substring(lastArrowIndex + 1).trim();
|
|
30184
|
-
|
|
30185
|
-
|
|
30186
|
-
|
|
30184
|
+
const possiblePkgIds = [];
|
|
30185
|
+
for (let prevSlashIndex = -1;;) {
|
|
30186
|
+
let slashIndex = nestedPath.indexOf('/', prevSlashIndex + 1);
|
|
30187
|
+
if (slashIndex < 0) {
|
|
30188
|
+
slashIndex = nestedPath.length;
|
|
30189
|
+
}
|
|
30190
|
+
const part = nestedPath.slice(prevSlashIndex + 1, (prevSlashIndex = slashIndex));
|
|
30191
|
+
if (!part) {
|
|
30192
|
+
break;
|
|
30193
|
+
}
|
|
30194
|
+
// Assume path parts with an extension are not package roots, except for the
|
|
30195
|
+
// first path part (since periods are sadly allowed in package names).
|
|
30196
|
+
// At the same time, skip the first path part if it begins with "@"
|
|
30197
|
+
// (since "@foo/bar" should be treated as the top-level path).
|
|
30198
|
+
if (possiblePkgIds.length ? path__default.extname(part) : part[0] === '@') {
|
|
30199
|
+
continue;
|
|
30200
|
+
}
|
|
30201
|
+
const possiblePkgId = nestedPath.slice(0, slashIndex);
|
|
30202
|
+
possiblePkgIds.push(possiblePkgId);
|
|
30203
|
+
}
|
|
30187
30204
|
let basedir;
|
|
30188
|
-
if (dedupe
|
|
30205
|
+
if (dedupe === null || dedupe === void 0 ? void 0 : dedupe.some((id) => possiblePkgIds.includes(id))) {
|
|
30189
30206
|
basedir = root;
|
|
30190
30207
|
}
|
|
30191
30208
|
else if (importer &&
|
|
@@ -30196,18 +30213,41 @@ function tryNodeResolve(id, importer, options, targetWeb, server, ssr) {
|
|
|
30196
30213
|
else {
|
|
30197
30214
|
basedir = root;
|
|
30198
30215
|
}
|
|
30199
|
-
const preserveSymlinks = !!(server === null || server === void 0 ? void 0 : server.config.resolve.preserveSymlinks);
|
|
30200
30216
|
// nested node module, step-by-step resolve to the basedir of the nestedPath
|
|
30201
30217
|
if (nestedRoot) {
|
|
30202
|
-
basedir = nestedResolveFrom(nestedRoot, basedir, preserveSymlinks);
|
|
30218
|
+
basedir = nestedResolveFrom(nestedRoot, basedir, options.preserveSymlinks);
|
|
30203
30219
|
}
|
|
30204
|
-
|
|
30220
|
+
let pkg;
|
|
30221
|
+
const pkgId = possiblePkgIds.reverse().find((pkgId) => {
|
|
30222
|
+
pkg = resolvePackageData(pkgId, basedir, options.preserveSymlinks);
|
|
30223
|
+
return pkg;
|
|
30224
|
+
});
|
|
30205
30225
|
if (!pkg) {
|
|
30206
30226
|
return;
|
|
30207
30227
|
}
|
|
30208
|
-
let
|
|
30209
|
-
|
|
30210
|
-
|
|
30228
|
+
let resolveId = resolvePackageEntry;
|
|
30229
|
+
let unresolvedId = pkgId;
|
|
30230
|
+
if (unresolvedId !== nestedPath) {
|
|
30231
|
+
resolveId = resolveDeepImport;
|
|
30232
|
+
unresolvedId = '.' + nestedPath.slice(pkgId.length);
|
|
30233
|
+
}
|
|
30234
|
+
let resolved;
|
|
30235
|
+
try {
|
|
30236
|
+
resolved = resolveId(unresolvedId, pkg, targetWeb, options);
|
|
30237
|
+
}
|
|
30238
|
+
catch (err) {
|
|
30239
|
+
if (!options.tryEsmOnly) {
|
|
30240
|
+
throw err;
|
|
30241
|
+
}
|
|
30242
|
+
}
|
|
30243
|
+
if (!resolved && options.tryEsmOnly) {
|
|
30244
|
+
resolved = resolveId(unresolvedId, pkg, targetWeb, {
|
|
30245
|
+
...options,
|
|
30246
|
+
isRequire: false,
|
|
30247
|
+
mainFields: DEFAULT_MAIN_FIELDS,
|
|
30248
|
+
extensions: DEFAULT_EXTENSIONS$1
|
|
30249
|
+
});
|
|
30250
|
+
}
|
|
30211
30251
|
if (!resolved) {
|
|
30212
30252
|
return;
|
|
30213
30253
|
}
|
|
@@ -30234,7 +30274,7 @@ function tryNodeResolve(id, importer, options, targetWeb, server, ssr) {
|
|
|
30234
30274
|
if (!isJsType ||
|
|
30235
30275
|
(importer === null || importer === void 0 ? void 0 : importer.includes('node_modules')) ||
|
|
30236
30276
|
(exclude === null || exclude === void 0 ? void 0 : exclude.includes(pkgId)) ||
|
|
30237
|
-
(exclude === null || exclude === void 0 ? void 0 : exclude.includes(
|
|
30277
|
+
(exclude === null || exclude === void 0 ? void 0 : exclude.includes(nestedPath)) ||
|
|
30238
30278
|
SPECIAL_QUERY_RE.test(resolved) ||
|
|
30239
30279
|
ssr) {
|
|
30240
30280
|
// excluded from optimization
|
|
@@ -30351,7 +30391,7 @@ function loadPackageData(pkgPath, cacheKey = pkgPath) {
|
|
|
30351
30391
|
packageCache.set(cacheKey, pkg);
|
|
30352
30392
|
return pkg;
|
|
30353
30393
|
}
|
|
30354
|
-
function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache },
|
|
30394
|
+
function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache }, targetWeb, options) {
|
|
30355
30395
|
var _a, _b;
|
|
30356
30396
|
const cached = getResolvedCache('.', targetWeb);
|
|
30357
30397
|
if (cached) {
|
|
@@ -30383,7 +30423,7 @@ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache
|
|
|
30383
30423
|
// the heuristics here is to actually read the browser entry when
|
|
30384
30424
|
// possible and check for hints of UMD. If it is UMD, prefer "module"
|
|
30385
30425
|
// instead; Otherwise, assume it's ESM and use it.
|
|
30386
|
-
const resolvedBrowserEntry = tryFsResolve(path__default.join(dir, browserEntry), options
|
|
30426
|
+
const resolvedBrowserEntry = tryFsResolve(path__default.join(dir, browserEntry), options);
|
|
30387
30427
|
if (resolvedBrowserEntry) {
|
|
30388
30428
|
const content = fs__default.readFileSync(resolvedBrowserEntry, 'utf-8');
|
|
30389
30429
|
if ((/typeof exports\s*==/.test(content) &&
|
|
@@ -30420,7 +30460,7 @@ function resolvePackageEntry(id, { dir, data, setResolvedCache, getResolvedCache
|
|
|
30420
30460
|
entryPoint = mapWithBrowserField(entryPoint, browserField) || entryPoint;
|
|
30421
30461
|
}
|
|
30422
30462
|
entryPoint = path__default.join(dir, entryPoint);
|
|
30423
|
-
const resolvedEntryPoint = tryFsResolve(entryPoint, options
|
|
30463
|
+
const resolvedEntryPoint = tryFsResolve(entryPoint, options);
|
|
30424
30464
|
if (resolvedEntryPoint) {
|
|
30425
30465
|
isDebug$5 &&
|
|
30426
30466
|
debug$d(`[package entry] ${source.cyan(id)} -> ${source.dim(resolvedEntryPoint)}`);
|
|
@@ -30448,13 +30488,13 @@ function resolveExports(pkg, key, options, targetWeb) {
|
|
|
30448
30488
|
if (options.conditions) {
|
|
30449
30489
|
conditions.push(...options.conditions);
|
|
30450
30490
|
}
|
|
30451
|
-
return resolve
|
|
30491
|
+
return resolve(pkg, key, {
|
|
30452
30492
|
browser: targetWeb,
|
|
30453
30493
|
require: options.isRequire,
|
|
30454
30494
|
conditions
|
|
30455
30495
|
});
|
|
30456
30496
|
}
|
|
30457
|
-
function resolveDeepImport(id, { webResolvedImports, setResolvedCache, getResolvedCache, dir, data },
|
|
30497
|
+
function resolveDeepImport(id, { webResolvedImports, setResolvedCache, getResolvedCache, dir, data }, targetWeb, options) {
|
|
30458
30498
|
const cache = getResolvedCache(id, targetWeb);
|
|
30459
30499
|
if (cache) {
|
|
30460
30500
|
return cache;
|
|
@@ -30485,7 +30525,7 @@ function resolveDeepImport(id, { webResolvedImports, setResolvedCache, getResolv
|
|
|
30485
30525
|
}
|
|
30486
30526
|
}
|
|
30487
30527
|
if (relativeId) {
|
|
30488
|
-
const resolved = tryFsResolve(path__default.join(dir, relativeId), options,
|
|
30528
|
+
const resolved = tryFsResolve(path__default.join(dir, relativeId), options, !exportsField, // try index only if no exports field
|
|
30489
30529
|
targetWeb);
|
|
30490
30530
|
if (resolved) {
|
|
30491
30531
|
isDebug$5 &&
|
|
@@ -30495,7 +30535,7 @@ function resolveDeepImport(id, { webResolvedImports, setResolvedCache, getResolv
|
|
|
30495
30535
|
}
|
|
30496
30536
|
}
|
|
30497
30537
|
}
|
|
30498
|
-
function tryResolveBrowserMapping(id, importer, options, isFilePath
|
|
30538
|
+
function tryResolveBrowserMapping(id, importer, options, isFilePath) {
|
|
30499
30539
|
let res;
|
|
30500
30540
|
const pkg = importer && idToPkgMap.get(importer);
|
|
30501
30541
|
if (pkg && isObject$3(pkg.data.browser)) {
|
|
@@ -30503,7 +30543,7 @@ function tryResolveBrowserMapping(id, importer, options, isFilePath, preserveSym
|
|
|
30503
30543
|
const browserMappedPath = mapWithBrowserField(mapId, pkg.data.browser);
|
|
30504
30544
|
if (browserMappedPath) {
|
|
30505
30545
|
const fsPath = path__default.join(pkg.dir, browserMappedPath);
|
|
30506
|
-
if ((res = tryFsResolve(fsPath, options
|
|
30546
|
+
if ((res = tryFsResolve(fsPath, options))) {
|
|
30507
30547
|
isDebug$5 &&
|
|
30508
30548
|
debug$d(`[browser mapped] ${source.cyan(id)} -> ${source.dim(res)}`);
|
|
30509
30549
|
idToPkgMap.set(res, pkg);
|
|
@@ -30553,97 +30593,117 @@ const debug$c = createDebugger('vite:ssr-external');
|
|
|
30553
30593
|
* Heuristics for determining whether a dependency should be externalized for
|
|
30554
30594
|
* server-side rendering.
|
|
30555
30595
|
*/
|
|
30556
|
-
function resolveSSRExternal(config, knownImports
|
|
30557
|
-
var _a
|
|
30558
|
-
|
|
30596
|
+
function resolveSSRExternal(config, knownImports) {
|
|
30597
|
+
var _a;
|
|
30598
|
+
const ssrConfig = config.ssr;
|
|
30599
|
+
if ((ssrConfig === null || ssrConfig === void 0 ? void 0 : ssrConfig.noExternal) === true) {
|
|
30559
30600
|
return [];
|
|
30560
30601
|
}
|
|
30561
|
-
const
|
|
30602
|
+
const ssrExternals = new Set();
|
|
30603
|
+
const seen = new Set();
|
|
30604
|
+
(_a = ssrConfig === null || ssrConfig === void 0 ? void 0 : ssrConfig.external) === null || _a === void 0 ? void 0 : _a.forEach((id) => {
|
|
30605
|
+
ssrExternals.add(id);
|
|
30606
|
+
seen.add(id);
|
|
30607
|
+
});
|
|
30608
|
+
collectExternals(config.root, config.resolve.preserveSymlinks, ssrExternals, seen);
|
|
30609
|
+
const importedDeps = knownImports.map(getNpmPackageName).filter(isDefined);
|
|
30610
|
+
for (const dep of importedDeps) {
|
|
30611
|
+
// Assume external if not yet seen
|
|
30612
|
+
// At this point, the project root and any linked packages have had their dependencies checked,
|
|
30613
|
+
// so we can safely mark any knownImports not yet seen as external. They are guaranteed to be
|
|
30614
|
+
// dependencies of packages in node_modules.
|
|
30615
|
+
if (!seen.has(dep)) {
|
|
30616
|
+
ssrExternals.add(dep);
|
|
30617
|
+
}
|
|
30618
|
+
}
|
|
30619
|
+
// ensure `vite/dynamic-import-polyfill` is bundled (issue #1865)
|
|
30620
|
+
ssrExternals.delete('vite');
|
|
30621
|
+
let externals = [...ssrExternals];
|
|
30622
|
+
if (ssrConfig === null || ssrConfig === void 0 ? void 0 : ssrConfig.noExternal) {
|
|
30623
|
+
externals = externals.filter(createFilter$1(undefined, ssrConfig.noExternal, { resolve: false }));
|
|
30624
|
+
}
|
|
30625
|
+
return externals;
|
|
30626
|
+
}
|
|
30627
|
+
// do we need to do this ahead of time or could we do it lazily?
|
|
30628
|
+
function collectExternals(root, preserveSymlinks, ssrExternals, seen) {
|
|
30629
|
+
var _a;
|
|
30562
30630
|
const pkgContent = lookupFile(root, ['package.json']);
|
|
30563
30631
|
if (!pkgContent) {
|
|
30564
|
-
return
|
|
30632
|
+
return;
|
|
30565
30633
|
}
|
|
30566
30634
|
const pkg = JSON.parse(pkgContent);
|
|
30567
|
-
const
|
|
30568
|
-
|
|
30569
|
-
...
|
|
30570
|
-
|
|
30571
|
-
...Object.keys(pkg.dependencies || {})
|
|
30572
|
-
]);
|
|
30635
|
+
const deps = {
|
|
30636
|
+
...pkg.devDependencies,
|
|
30637
|
+
...pkg.dependencies
|
|
30638
|
+
};
|
|
30573
30639
|
const resolveOptions = {
|
|
30574
30640
|
root,
|
|
30641
|
+
preserveSymlinks,
|
|
30575
30642
|
isProduction: false,
|
|
30576
30643
|
isBuild: true
|
|
30577
30644
|
};
|
|
30578
30645
|
const depsToTrace = new Set();
|
|
30579
|
-
for (const id
|
|
30580
|
-
if (seen.has(id))
|
|
30646
|
+
for (const id in deps) {
|
|
30647
|
+
if (seen.has(id))
|
|
30581
30648
|
continue;
|
|
30582
|
-
}
|
|
30583
30649
|
seen.add(id);
|
|
30584
|
-
let
|
|
30650
|
+
let esmEntry;
|
|
30585
30651
|
let requireEntry;
|
|
30586
30652
|
try {
|
|
30587
|
-
|
|
30653
|
+
esmEntry = (_a = tryNodeResolve(id, undefined, resolveOptions, true, // we set `targetWeb` to `true` to get the ESM entry
|
|
30654
|
+
undefined, true)) === null || _a === void 0 ? void 0 : _a.id;
|
|
30588
30655
|
// normalizePath required for windows. tryNodeResolve uses normalizePath
|
|
30589
30656
|
// which returns with '/', require.resolve returns with '\\'
|
|
30590
30657
|
requireEntry = normalizePath$4(require.resolve(id, { paths: [root] }));
|
|
30591
30658
|
}
|
|
30592
30659
|
catch (e) {
|
|
30660
|
+
try {
|
|
30661
|
+
// no main entry, but deep imports may be allowed
|
|
30662
|
+
const pkgPath = resolveFrom$3(`${id}/package.json`, root);
|
|
30663
|
+
if (pkgPath.includes('node_modules')) {
|
|
30664
|
+
ssrExternals.add(id);
|
|
30665
|
+
}
|
|
30666
|
+
else {
|
|
30667
|
+
depsToTrace.add(path__default.dirname(pkgPath));
|
|
30668
|
+
}
|
|
30669
|
+
continue;
|
|
30670
|
+
}
|
|
30671
|
+
catch { }
|
|
30593
30672
|
// resolve failed, assume include
|
|
30594
30673
|
debug$c(`Failed to resolve entries for package "${id}"\n`, e);
|
|
30595
30674
|
continue;
|
|
30596
30675
|
}
|
|
30597
|
-
|
|
30598
|
-
|
|
30676
|
+
// no esm entry but has require entry
|
|
30677
|
+
if (!esmEntry) {
|
|
30599
30678
|
ssrExternals.add(id);
|
|
30600
|
-
continue;
|
|
30601
30679
|
}
|
|
30602
|
-
|
|
30603
|
-
|
|
30604
|
-
|
|
30605
|
-
depsToTrace.add(
|
|
30606
|
-
continue;
|
|
30680
|
+
// trace the dependencies of linked packages
|
|
30681
|
+
else if (!esmEntry.includes('node_modules')) {
|
|
30682
|
+
const pkgPath = resolveFrom$3(`${id}/package.json`, root);
|
|
30683
|
+
depsToTrace.add(path__default.dirname(pkgPath));
|
|
30607
30684
|
}
|
|
30608
|
-
|
|
30609
|
-
|
|
30685
|
+
// has separate esm/require entry, assume require entry is cjs
|
|
30686
|
+
else if (esmEntry !== requireEntry) {
|
|
30610
30687
|
ssrExternals.add(id);
|
|
30611
30688
|
}
|
|
30612
|
-
|
|
30613
|
-
|
|
30614
|
-
|
|
30615
|
-
|
|
30616
|
-
|
|
30617
|
-
}
|
|
30618
|
-
if (pkg.type === 'module' || entry.endsWith('.mjs')) {
|
|
30689
|
+
// if we're externalizing ESM and CJS should basically just always do it?
|
|
30690
|
+
// or are there others like SystemJS / AMD that we'd need to handle?
|
|
30691
|
+
// for now, we'll just leave this as is
|
|
30692
|
+
else if (/\.m?js$/.test(esmEntry)) {
|
|
30693
|
+
if (pkg.type === 'module' || esmEntry.endsWith('.mjs')) {
|
|
30619
30694
|
ssrExternals.add(id);
|
|
30620
30695
|
continue;
|
|
30621
30696
|
}
|
|
30622
30697
|
// check if the entry is cjs
|
|
30623
|
-
const content = fs__default.readFileSync(
|
|
30698
|
+
const content = fs__default.readFileSync(esmEntry, 'utf-8');
|
|
30624
30699
|
if (/\bmodule\.exports\b|\bexports[.\[]|\brequire\s*\(/.test(content)) {
|
|
30625
30700
|
ssrExternals.add(id);
|
|
30626
30701
|
}
|
|
30627
30702
|
}
|
|
30628
30703
|
}
|
|
30629
|
-
for (const
|
|
30630
|
-
|
|
30631
|
-
resolveSSRExternal({
|
|
30632
|
-
...config,
|
|
30633
|
-
root: depRoot
|
|
30634
|
-
}, knownImports, ssrExternals, seen);
|
|
30704
|
+
for (const depRoot of depsToTrace) {
|
|
30705
|
+
collectExternals(depRoot, preserveSymlinks, ssrExternals, seen);
|
|
30635
30706
|
}
|
|
30636
|
-
if ((_c = config.ssr) === null || _c === void 0 ? void 0 : _c.external) {
|
|
30637
|
-
config.ssr.external.forEach((id) => ssrExternals.add(id));
|
|
30638
|
-
}
|
|
30639
|
-
let externals = [...ssrExternals];
|
|
30640
|
-
if ((_d = config.ssr) === null || _d === void 0 ? void 0 : _d.noExternal) {
|
|
30641
|
-
const filter = createFilter$1(undefined, config.ssr.noExternal, {
|
|
30642
|
-
resolve: false
|
|
30643
|
-
});
|
|
30644
|
-
externals = externals.filter((id) => filter(id));
|
|
30645
|
-
}
|
|
30646
|
-
return externals.filter((id) => id !== 'vite');
|
|
30647
30707
|
}
|
|
30648
30708
|
function shouldExternalizeForSSR(id, externals) {
|
|
30649
30709
|
const should = externals.some((e) => {
|
|
@@ -42246,7 +42306,7 @@ function errorMiddleware(server, allowNext = false) {
|
|
|
42246
42306
|
* https://github.com/preactjs/wmr/blob/main/packages/wmr/src/lib/rollup-plugin-container.js
|
|
42247
42307
|
*/
|
|
42248
42308
|
let parser = Parser.extend(acornClassFields, acornStaticClassFeatures);
|
|
42249
|
-
async function createPluginContainer({ plugins, logger, root, build: { rollupOptions } }, watcher) {
|
|
42309
|
+
async function createPluginContainer({ plugins, logger, root, build: { rollupOptions } }, moduleGraph, watcher) {
|
|
42250
42310
|
const isDebug = process.env.DEBUG;
|
|
42251
42311
|
const seenResolves = {};
|
|
42252
42312
|
const debugResolve = createDebugger('vite:resolve');
|
|
@@ -42257,7 +42317,6 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
|
|
|
42257
42317
|
onlyWhenFocused: 'vite:plugin'
|
|
42258
42318
|
});
|
|
42259
42319
|
// ---------------------------------------------------------------------------
|
|
42260
|
-
const MODULES = new Map();
|
|
42261
42320
|
const watchFiles = new Set();
|
|
42262
42321
|
// get rollup version
|
|
42263
42322
|
const rollupPkgPath = path$t.resolve(require.resolve('rollup'), '../../package.json');
|
|
@@ -42272,6 +42331,36 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
|
|
|
42272
42331
|
logger.warn(source.cyan(`[plugin:${plugin}] `) +
|
|
42273
42332
|
source.yellow(`context method ${source.bold(`${method}()`)} is not supported in serve mode. This plugin is likely not vite-compatible.`));
|
|
42274
42333
|
}
|
|
42334
|
+
// throw when an unsupported ModuleInfo property is accessed,
|
|
42335
|
+
// so that incompatible plugins fail in a non-cryptic way.
|
|
42336
|
+
const ModuleInfoProxy = {
|
|
42337
|
+
get(info, key) {
|
|
42338
|
+
if (key in info) {
|
|
42339
|
+
return info[key];
|
|
42340
|
+
}
|
|
42341
|
+
throw Error(`[vite] The "${key}" property of ModuleInfo is not supported.`);
|
|
42342
|
+
}
|
|
42343
|
+
};
|
|
42344
|
+
// same default value of "moduleInfo.meta" as in Rollup
|
|
42345
|
+
const EMPTY_OBJECT = Object.freeze({});
|
|
42346
|
+
function getModuleInfo(id) {
|
|
42347
|
+
const module = moduleGraph === null || moduleGraph === void 0 ? void 0 : moduleGraph.getModuleById(id);
|
|
42348
|
+
if (!module) {
|
|
42349
|
+
return null;
|
|
42350
|
+
}
|
|
42351
|
+
if (!module.info) {
|
|
42352
|
+
module.info = new Proxy({ id, meta: module.meta || EMPTY_OBJECT }, ModuleInfoProxy);
|
|
42353
|
+
}
|
|
42354
|
+
return module.info;
|
|
42355
|
+
}
|
|
42356
|
+
function updateModuleInfo(id, { meta }) {
|
|
42357
|
+
if (meta) {
|
|
42358
|
+
const moduleInfo = getModuleInfo(id);
|
|
42359
|
+
if (moduleInfo) {
|
|
42360
|
+
moduleInfo.meta = { ...moduleInfo.meta, ...meta };
|
|
42361
|
+
}
|
|
42362
|
+
}
|
|
42363
|
+
}
|
|
42275
42364
|
// we should create a new context for each async hook pipeline so that the
|
|
42276
42365
|
// active plugin in that pipeline can be tracked in a concurrency-safe manner.
|
|
42277
42366
|
// using a class to make creating new contexts more efficient
|
|
@@ -42304,19 +42393,12 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
|
|
|
42304
42393
|
return out;
|
|
42305
42394
|
}
|
|
42306
42395
|
getModuleInfo(id) {
|
|
42307
|
-
|
|
42308
|
-
if (mod)
|
|
42309
|
-
return mod.info;
|
|
42310
|
-
mod = {
|
|
42311
|
-
/** @type {import('rollup').ModuleInfo} */
|
|
42312
|
-
// @ts-ignore-next
|
|
42313
|
-
info: {}
|
|
42314
|
-
};
|
|
42315
|
-
MODULES.set(id, mod);
|
|
42316
|
-
return mod.info;
|
|
42396
|
+
return getModuleInfo(id);
|
|
42317
42397
|
}
|
|
42318
42398
|
getModuleIds() {
|
|
42319
|
-
return
|
|
42399
|
+
return moduleGraph
|
|
42400
|
+
? moduleGraph.idToModuleMap.keys()
|
|
42401
|
+
: Array.prototype[Symbol.iterator]();
|
|
42320
42402
|
}
|
|
42321
42403
|
addWatchFile(id) {
|
|
42322
42404
|
watchFiles.add(id);
|
|
@@ -42482,6 +42564,7 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
|
|
|
42482
42564
|
...options
|
|
42483
42565
|
};
|
|
42484
42566
|
})(),
|
|
42567
|
+
getModuleInfo,
|
|
42485
42568
|
async buildStart() {
|
|
42486
42569
|
await Promise.all(plugins.map((plugin) => {
|
|
42487
42570
|
if (plugin.buildStart) {
|
|
@@ -42546,6 +42629,9 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
|
|
|
42546
42629
|
ctx._activePlugin = plugin;
|
|
42547
42630
|
const result = await plugin.load.call(ctx, id, { ssr });
|
|
42548
42631
|
if (result != null) {
|
|
42632
|
+
if (isObject$3(result)) {
|
|
42633
|
+
updateModuleInfo(id, result);
|
|
42634
|
+
}
|
|
42549
42635
|
return result;
|
|
42550
42636
|
}
|
|
42551
42637
|
}
|
|
@@ -42575,9 +42661,13 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
|
|
|
42575
42661
|
isDebug &&
|
|
42576
42662
|
debugPluginTransform(timeFrom(start), plugin.name, prettifyUrl(id, root));
|
|
42577
42663
|
if (isObject$3(result)) {
|
|
42578
|
-
|
|
42579
|
-
|
|
42580
|
-
|
|
42664
|
+
if (result.code !== undefined) {
|
|
42665
|
+
code = result.code;
|
|
42666
|
+
if (result.map) {
|
|
42667
|
+
ctx.sourcemapChain.push(result.map);
|
|
42668
|
+
}
|
|
42669
|
+
}
|
|
42670
|
+
updateModuleInfo(id, result);
|
|
42581
42671
|
}
|
|
42582
42672
|
else {
|
|
42583
42673
|
code = result;
|
|
@@ -42602,6 +42692,7 @@ async function createPluginContainer({ plugins, logger, root, build: { rollupOpt
|
|
|
42602
42692
|
|
|
42603
42693
|
const debug$b = createDebugger('vite:deps');
|
|
42604
42694
|
const htmlTypesRE = /\.(html|vue|svelte|astro)$/;
|
|
42695
|
+
const setupRE = /<script\s+setup/;
|
|
42605
42696
|
// A simple regex to detect import sources. This is only used on
|
|
42606
42697
|
// <script lang="ts"> blocks in vue (setup only) or svelte files, since
|
|
42607
42698
|
// seemingly unused imports are dropped by esbuild when transpiling TS which
|
|
@@ -42691,6 +42782,7 @@ const commentRE = /<!--(.|[\r\n])*?-->/;
|
|
|
42691
42782
|
const srcRE = /\bsrc\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
|
|
42692
42783
|
const typeRE = /\btype\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
|
|
42693
42784
|
const langRE = /\blang\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
|
|
42785
|
+
const contextRE = /\bcontext\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
|
|
42694
42786
|
function esbuildScanPlugin(config, container, depImports, missing, entries) {
|
|
42695
42787
|
var _a, _b;
|
|
42696
42788
|
const seen = new Map();
|
|
@@ -42717,6 +42809,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
|
|
|
42717
42809
|
return {
|
|
42718
42810
|
name: 'vite:dep-scan',
|
|
42719
42811
|
setup(build) {
|
|
42812
|
+
const moduleScripts = {};
|
|
42720
42813
|
// external urls
|
|
42721
42814
|
build.onResolve({ filter: externalRE }, ({ path }) => ({
|
|
42722
42815
|
path,
|
|
@@ -42727,6 +42820,12 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
|
|
|
42727
42820
|
path,
|
|
42728
42821
|
external: true
|
|
42729
42822
|
}));
|
|
42823
|
+
build.onResolve({ filter: virtualModuleRE }, async ({ path, importer }) => {
|
|
42824
|
+
return {
|
|
42825
|
+
path: await resolve(path.substring('virtual-module:'.length), importer),
|
|
42826
|
+
namespace: 'html'
|
|
42827
|
+
};
|
|
42828
|
+
});
|
|
42730
42829
|
// html types: extract script contents -----------------------------------
|
|
42731
42830
|
build.onResolve({ filter: htmlTypesRE }, async ({ path, importer }) => {
|
|
42732
42831
|
return {
|
|
@@ -42734,6 +42833,9 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
|
|
|
42734
42833
|
namespace: 'html'
|
|
42735
42834
|
};
|
|
42736
42835
|
});
|
|
42836
|
+
build.onLoad({ filter: virtualModuleRE, namespace: 'html' }, async ({ path }) => {
|
|
42837
|
+
return moduleScripts[path];
|
|
42838
|
+
});
|
|
42737
42839
|
// extract scripts inside HTML-like files and treat it as a js module
|
|
42738
42840
|
build.onLoad({ filter: htmlTypesRE, namespace: 'html' }, async ({ path }) => {
|
|
42739
42841
|
let raw = fs__default.readFileSync(path, 'utf-8');
|
|
@@ -42747,10 +42849,9 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
|
|
|
42747
42849
|
let match;
|
|
42748
42850
|
while ((match = regex.exec(raw))) {
|
|
42749
42851
|
const [, openTag, content] = match;
|
|
42750
|
-
const srcMatch = openTag.match(srcRE);
|
|
42751
42852
|
const typeMatch = openTag.match(typeRE);
|
|
42752
|
-
const langMatch = openTag.match(langRE);
|
|
42753
42853
|
const type = typeMatch && (typeMatch[1] || typeMatch[2] || typeMatch[3]);
|
|
42854
|
+
const langMatch = openTag.match(langRE);
|
|
42754
42855
|
const lang = langMatch && (langMatch[1] || langMatch[2] || langMatch[3]);
|
|
42755
42856
|
// skip type="application/ld+json" and other non-JS types
|
|
42756
42857
|
if (type &&
|
|
@@ -42762,12 +42863,30 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
|
|
|
42762
42863
|
if (lang === 'ts' || lang === 'tsx' || lang === 'jsx') {
|
|
42763
42864
|
loader = lang;
|
|
42764
42865
|
}
|
|
42866
|
+
const srcMatch = openTag.match(srcRE);
|
|
42765
42867
|
if (srcMatch) {
|
|
42766
42868
|
const src = srcMatch[1] || srcMatch[2] || srcMatch[3];
|
|
42767
42869
|
js += `import ${JSON.stringify(src)}\n`;
|
|
42768
42870
|
}
|
|
42769
42871
|
else if (content.trim()) {
|
|
42770
|
-
|
|
42872
|
+
// There can be module scripts (`<script context="module">` in Svelte and `<script>` in Vue)
|
|
42873
|
+
// or local scripts (`<script>` in Svelte and `<script setup>` in Vue)
|
|
42874
|
+
// We need to handle these separately in case variable names are reused between them
|
|
42875
|
+
const contextMatch = openTag.match(contextRE);
|
|
42876
|
+
const context = contextMatch &&
|
|
42877
|
+
(contextMatch[1] || contextMatch[2] || contextMatch[3]);
|
|
42878
|
+
if ((path.endsWith('.vue') && setupRE.test(raw)) ||
|
|
42879
|
+
(path.endsWith('.svelte') && context !== 'module')) {
|
|
42880
|
+
const id = `virtual-module:${path}`;
|
|
42881
|
+
moduleScripts[id] = {
|
|
42882
|
+
loader,
|
|
42883
|
+
contents: content
|
|
42884
|
+
};
|
|
42885
|
+
js += `import '${id}';\n`;
|
|
42886
|
+
}
|
|
42887
|
+
else {
|
|
42888
|
+
js += content + '\n';
|
|
42889
|
+
}
|
|
42771
42890
|
}
|
|
42772
42891
|
}
|
|
42773
42892
|
// empty singleline & multiline comments to avoid matching comments
|
|
@@ -42776,7 +42895,7 @@ function esbuildScanPlugin(config, container, depImports, missing, entries) {
|
|
|
42776
42895
|
.replace(singlelineCommentsRE, '');
|
|
42777
42896
|
if (loader.startsWith('ts') &&
|
|
42778
42897
|
(path.endsWith('.svelte') ||
|
|
42779
|
-
(path.endsWith('.vue') &&
|
|
42898
|
+
(path.endsWith('.vue') && setupRE.test(raw)))) {
|
|
42780
42899
|
// when using TS + (Vue + <script setup>) or Svelte, imports may seem
|
|
42781
42900
|
// unused to esbuild and dropped in the build output, which prevents
|
|
42782
42901
|
// esbuild from crawling further.
|
|
@@ -43042,7 +43161,8 @@ function loadFallbackPlugin() {
|
|
|
43042
43161
|
};
|
|
43043
43162
|
}
|
|
43044
43163
|
|
|
43045
|
-
function resolveBuildOptions(raw) {
|
|
43164
|
+
function resolveBuildOptions(root, raw) {
|
|
43165
|
+
var _a;
|
|
43046
43166
|
const resolved = {
|
|
43047
43167
|
target: 'modules',
|
|
43048
43168
|
polyfillModulePreload: true,
|
|
@@ -43077,6 +43197,28 @@ function resolveBuildOptions(raw) {
|
|
|
43077
43197
|
...raw === null || raw === void 0 ? void 0 : raw.dynamicImportVarsOptions
|
|
43078
43198
|
}
|
|
43079
43199
|
};
|
|
43200
|
+
const resolve = (p) => p.startsWith('\0') ? p : path__default.resolve(root, p);
|
|
43201
|
+
resolved.outDir = resolve(resolved.outDir);
|
|
43202
|
+
let input;
|
|
43203
|
+
if ((_a = raw === null || raw === void 0 ? void 0 : raw.rollupOptions) === null || _a === void 0 ? void 0 : _a.input) {
|
|
43204
|
+
input = Array.isArray(raw.rollupOptions.input)
|
|
43205
|
+
? raw.rollupOptions.input.map(input => resolve(input))
|
|
43206
|
+
: typeof raw.rollupOptions.input === 'object'
|
|
43207
|
+
? Object.fromEntries(Object.entries(raw.rollupOptions.input).map(([key, value]) => [key, resolve(value)]))
|
|
43208
|
+
: resolve(raw.rollupOptions.input);
|
|
43209
|
+
}
|
|
43210
|
+
else {
|
|
43211
|
+
input = resolve((raw === null || raw === void 0 ? void 0 : raw.lib)
|
|
43212
|
+
? raw.lib.entry
|
|
43213
|
+
: typeof (raw === null || raw === void 0 ? void 0 : raw.ssr) === 'string'
|
|
43214
|
+
? raw.ssr
|
|
43215
|
+
: 'index.html');
|
|
43216
|
+
}
|
|
43217
|
+
if (!!(raw === null || raw === void 0 ? void 0 : raw.ssr) && typeof input === 'string' && input.endsWith('.html')) {
|
|
43218
|
+
throw new Error(`rollupOptions.input should not be an html file when building for SSR. ` +
|
|
43219
|
+
`Please specify a dedicated SSR entry.`);
|
|
43220
|
+
}
|
|
43221
|
+
resolved.rollupOptions.input = input;
|
|
43080
43222
|
// handle special build targets
|
|
43081
43223
|
if (resolved.target === 'modules') {
|
|
43082
43224
|
// Support browserslist
|
|
@@ -43155,27 +43297,18 @@ async function build(inlineConfig = {}) {
|
|
|
43155
43297
|
}
|
|
43156
43298
|
}
|
|
43157
43299
|
async function doBuild(inlineConfig = {}) {
|
|
43158
|
-
var _a, _b, _c
|
|
43300
|
+
var _a, _b, _c;
|
|
43159
43301
|
const config = await resolveConfig(inlineConfig, 'build', 'production');
|
|
43160
43302
|
const options = config.build;
|
|
43303
|
+
const input = options.rollupOptions.input;
|
|
43304
|
+
const outDir = options.outDir;
|
|
43161
43305
|
const ssr = !!options.ssr;
|
|
43162
43306
|
const libOptions = options.lib;
|
|
43163
43307
|
config.logger.info(source.cyan(`vite v${require('vite/package.json').version} ${source.green(`building ${ssr ? `SSR bundle ` : ``}for ${config.mode}...`)}`));
|
|
43164
|
-
const resolve = (p) => path__default.resolve(config.root, p);
|
|
43165
|
-
const input = libOptions
|
|
43166
|
-
? resolve(libOptions.entry)
|
|
43167
|
-
: typeof options.ssr === 'string'
|
|
43168
|
-
? resolve(options.ssr)
|
|
43169
|
-
: ((_a = options.rollupOptions) === null || _a === void 0 ? void 0 : _a.input) || resolve('index.html');
|
|
43170
|
-
if (ssr && typeof input === 'string' && input.endsWith('.html')) {
|
|
43171
|
-
throw new Error(`rollupOptions.input should not be an html file when building for SSR. ` +
|
|
43172
|
-
`Please specify a dedicated SSR entry.`);
|
|
43173
|
-
}
|
|
43174
|
-
const outDir = resolve(options.outDir);
|
|
43175
43308
|
// inject ssr arg to plugin load/transform hooks
|
|
43176
43309
|
const plugins = (ssr ? config.plugins.map((p) => injectSsrFlagToHooks(p)) : config.plugins);
|
|
43177
43310
|
// inject ssrExternal if present
|
|
43178
|
-
const userExternal = (
|
|
43311
|
+
const userExternal = (_a = options.rollupOptions) === null || _a === void 0 ? void 0 : _a.external;
|
|
43179
43312
|
let external = userExternal;
|
|
43180
43313
|
if (ssr) {
|
|
43181
43314
|
// see if we have cached deps data available
|
|
@@ -43196,7 +43329,6 @@ async function doBuild(inlineConfig = {}) {
|
|
|
43196
43329
|
}
|
|
43197
43330
|
const rollup = require('rollup');
|
|
43198
43331
|
const rollupOptions = {
|
|
43199
|
-
input,
|
|
43200
43332
|
context: 'globalThis',
|
|
43201
43333
|
preserveEntrySignatures: ssr
|
|
43202
43334
|
? 'allow-extension'
|
|
@@ -43253,7 +43385,7 @@ async function doBuild(inlineConfig = {}) {
|
|
|
43253
43385
|
};
|
|
43254
43386
|
};
|
|
43255
43387
|
// resolve lib mode outputs
|
|
43256
|
-
const outputs = resolveBuildOutputs((
|
|
43388
|
+
const outputs = resolveBuildOutputs((_b = options.rollupOptions) === null || _b === void 0 ? void 0 : _b.output, libOptions, config.logger);
|
|
43257
43389
|
// watch file changes with rollup
|
|
43258
43390
|
if (config.build.watch) {
|
|
43259
43391
|
config.logger.info(source.cyanBright(`\nwatching for file changes...`));
|
|
@@ -43276,7 +43408,7 @@ async function doBuild(inlineConfig = {}) {
|
|
|
43276
43408
|
ignored: [
|
|
43277
43409
|
'**/node_modules/**',
|
|
43278
43410
|
'**/.git/**',
|
|
43279
|
-
...(((
|
|
43411
|
+
...(((_c = watcherOptions === null || watcherOptions === void 0 ? void 0 : watcherOptions.chokidar) === null || _c === void 0 ? void 0 : _c.ignored) || [])
|
|
43280
43412
|
],
|
|
43281
43413
|
ignoreInitial: true,
|
|
43282
43414
|
ignorePermissionErrors: true,
|
|
@@ -49230,7 +49362,7 @@ function readFileIfExists(value) {
|
|
|
49230
49362
|
* https://github.com/webpack/webpack-dev-server/blob/master/LICENSE
|
|
49231
49363
|
*/
|
|
49232
49364
|
async function createCertificate() {
|
|
49233
|
-
const { generate } = await Promise.resolve().then(function () { return require('./dep-
|
|
49365
|
+
const { generate } = await Promise.resolve().then(function () { return require('./dep-146e2d5f.js'); }).then(function (n) { return n.index; });
|
|
49234
49366
|
const pems = generate(null, {
|
|
49235
49367
|
algorithm: 'sha256',
|
|
49236
49368
|
days: 30,
|
|
@@ -56541,6 +56673,10 @@ const isDebug$3 = !!process.env.DEBUG;
|
|
|
56541
56673
|
const debug$4 = createDebugger('vite:sourcemap', {
|
|
56542
56674
|
onlyWhenFocused: true
|
|
56543
56675
|
});
|
|
56676
|
+
// Virtual modules should be prefixed with a null byte to avoid a
|
|
56677
|
+
// false positive "missing source" warning. We also check for certain
|
|
56678
|
+
// prefixes used for special handling in esbuildDepPlugin.
|
|
56679
|
+
const virtualSourceRE = /^(\0|dep:|browser-external:)/;
|
|
56544
56680
|
async function injectSourcesContent(map, file, logger) {
|
|
56545
56681
|
let sourceRoot;
|
|
56546
56682
|
try {
|
|
@@ -56550,7 +56686,7 @@ async function injectSourcesContent(map, file, logger) {
|
|
|
56550
56686
|
catch { }
|
|
56551
56687
|
const missingSources = [];
|
|
56552
56688
|
map.sourcesContent = await Promise.all(map.sources.map((sourcePath) => {
|
|
56553
|
-
if (sourcePath) {
|
|
56689
|
+
if (sourcePath && !virtualSourceRE.test(sourcePath)) {
|
|
56554
56690
|
sourcePath = decodeURI(sourcePath);
|
|
56555
56691
|
if (sourceRoot) {
|
|
56556
56692
|
sourcePath = path__default.resolve(sourceRoot, sourcePath);
|
|
@@ -57010,7 +57146,7 @@ function isFileServingAllowed(url, server) {
|
|
|
57010
57146
|
return true;
|
|
57011
57147
|
const cleanedUrl = cleanUrl(url);
|
|
57012
57148
|
const file = ensureLeadingSlash(normalizePath$4(cleanedUrl));
|
|
57013
|
-
if (server.config.server.fs.deny.some((i) =>
|
|
57149
|
+
if (server.config.server.fs.deny.some((i) => micromatch_1.isMatch(file, i, _matchOptions)))
|
|
57014
57150
|
return false;
|
|
57015
57151
|
if (server.moduleGraph.safeModulesPath.has(file))
|
|
57016
57152
|
return true;
|
|
@@ -57481,13 +57617,13 @@ function invalidateSSRModule(mod, seen) {
|
|
|
57481
57617
|
mod.importers.forEach((importer) => invalidateSSRModule(importer, seen));
|
|
57482
57618
|
}
|
|
57483
57619
|
class ModuleGraph {
|
|
57484
|
-
constructor(
|
|
57620
|
+
constructor(resolveId) {
|
|
57621
|
+
this.resolveId = resolveId;
|
|
57485
57622
|
this.urlToModuleMap = new Map();
|
|
57486
57623
|
this.idToModuleMap = new Map();
|
|
57487
57624
|
// a single file may corresponds to multiple modules with different queries
|
|
57488
57625
|
this.fileToModulesMap = new Map();
|
|
57489
57626
|
this.safeModulesPath = new Set();
|
|
57490
|
-
this.container = container;
|
|
57491
57627
|
}
|
|
57492
57628
|
async getModuleByUrl(rawUrl) {
|
|
57493
57629
|
const [url] = await this.resolveUrl(rawUrl);
|
|
@@ -57509,6 +57645,7 @@ class ModuleGraph {
|
|
|
57509
57645
|
}
|
|
57510
57646
|
}
|
|
57511
57647
|
invalidateModule(mod, seen = new Set()) {
|
|
57648
|
+
mod.info = undefined;
|
|
57512
57649
|
mod.transformResult = null;
|
|
57513
57650
|
mod.ssrTransformResult = null;
|
|
57514
57651
|
invalidateSSRModule(mod, seen);
|
|
@@ -57557,10 +57694,12 @@ class ModuleGraph {
|
|
|
57557
57694
|
return noLongerImported;
|
|
57558
57695
|
}
|
|
57559
57696
|
async ensureEntryFromUrl(rawUrl) {
|
|
57560
|
-
const [url, resolvedId] = await this.resolveUrl(rawUrl);
|
|
57697
|
+
const [url, resolvedId, meta] = await this.resolveUrl(rawUrl);
|
|
57561
57698
|
let mod = this.urlToModuleMap.get(url);
|
|
57562
57699
|
if (!mod) {
|
|
57563
57700
|
mod = new ModuleNode(url);
|
|
57701
|
+
if (meta)
|
|
57702
|
+
mod.meta = meta;
|
|
57564
57703
|
this.urlToModuleMap.set(url, mod);
|
|
57565
57704
|
mod.id = resolvedId;
|
|
57566
57705
|
this.idToModuleMap.set(resolvedId, mod);
|
|
@@ -57601,15 +57740,15 @@ class ModuleGraph {
|
|
|
57601
57740
|
// 2. resolve its extension so that urls with or without extension all map to
|
|
57602
57741
|
// the same module
|
|
57603
57742
|
async resolveUrl(url) {
|
|
57604
|
-
var _a;
|
|
57605
57743
|
url = removeImportQuery(removeTimestampQuery(url));
|
|
57606
|
-
const
|
|
57744
|
+
const resolved = await this.resolveId(url);
|
|
57745
|
+
const resolvedId = (resolved === null || resolved === void 0 ? void 0 : resolved.id) || url;
|
|
57607
57746
|
const ext = path$t.extname(cleanUrl(resolvedId));
|
|
57608
57747
|
const { pathname, search, hash } = require$$0$7.parse(url);
|
|
57609
57748
|
if (ext && !pathname.endsWith(ext)) {
|
|
57610
57749
|
url = pathname + ext + (search || '') + (hash || '');
|
|
57611
57750
|
}
|
|
57612
|
-
return [url, resolvedId];
|
|
57751
|
+
return [url, resolvedId, resolved === null || resolved === void 0 ? void 0 : resolved.meta];
|
|
57613
57752
|
}
|
|
57614
57753
|
}
|
|
57615
57754
|
|
|
@@ -57623,7 +57762,8 @@ async function handleHMRUpdate(file, server) {
|
|
|
57623
57762
|
const shortFile = getShortName(file, config.root);
|
|
57624
57763
|
const isConfig = file === config.configFile;
|
|
57625
57764
|
const isConfigDependency = config.configFileDependencies.some((name) => file === path__default.resolve(name));
|
|
57626
|
-
const isEnv = config.inlineConfig.envFile !== false &&
|
|
57765
|
+
const isEnv = config.inlineConfig.envFile !== false &&
|
|
57766
|
+
(file === '.env' || file.startsWith('.env.'));
|
|
57627
57767
|
if (isConfig || isConfigDependency || isEnv) {
|
|
57628
57768
|
// auto restart server
|
|
57629
57769
|
debugHmr(`[config change] ${source.dim(shortFile)}`);
|
|
@@ -57731,7 +57871,8 @@ async function handleFileAddUnlink(file, server, isUnlink = false) {
|
|
|
57731
57871
|
for (const i in server._globImporters) {
|
|
57732
57872
|
const { module, importGlobs } = server._globImporters[i];
|
|
57733
57873
|
for (const { base, pattern } of importGlobs) {
|
|
57734
|
-
if (
|
|
57874
|
+
if (micromatch_1.isMatch(file, pattern) ||
|
|
57875
|
+
micromatch_1.isMatch(path__default.relative(base, file), pattern)) {
|
|
57735
57876
|
modules.push(module);
|
|
57736
57877
|
// We use `onFileChange` to invalidate `module.file` so that subsequent `ssrLoadModule()`
|
|
57737
57878
|
// calls get fresh glob import results with(out) the newly added(/removed) `file`.
|
|
@@ -66848,6 +66989,58 @@ function rebindErrorStacktrace(e, stacktrace) {
|
|
|
66848
66989
|
}
|
|
66849
66990
|
}
|
|
66850
66991
|
|
|
66992
|
+
/**
|
|
66993
|
+
* This plugin hooks into Node's module resolution algorithm at runtime,
|
|
66994
|
+
* so that SSR builds can benefit from `resolve.dedupe` like they do
|
|
66995
|
+
* in development.
|
|
66996
|
+
*/
|
|
66997
|
+
function ssrRequireHookPlugin(config) {
|
|
66998
|
+
var _a;
|
|
66999
|
+
if (config.command !== 'build' || !((_a = config.resolve.dedupe) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
67000
|
+
return null;
|
|
67001
|
+
}
|
|
67002
|
+
return {
|
|
67003
|
+
name: 'vite:ssr-require-hook',
|
|
67004
|
+
transform(code, id) {
|
|
67005
|
+
const moduleInfo = this.getModuleInfo(id);
|
|
67006
|
+
if (moduleInfo === null || moduleInfo === void 0 ? void 0 : moduleInfo.isEntry) {
|
|
67007
|
+
const s = new MagicString(code);
|
|
67008
|
+
s.prepend(`;(${dedupeRequire.toString()})(${JSON.stringify(config.resolve.dedupe)});\n`);
|
|
67009
|
+
return {
|
|
67010
|
+
code: s.toString(),
|
|
67011
|
+
map: s.generateMap({
|
|
67012
|
+
source: id
|
|
67013
|
+
})
|
|
67014
|
+
};
|
|
67015
|
+
}
|
|
67016
|
+
}
|
|
67017
|
+
};
|
|
67018
|
+
}
|
|
67019
|
+
/** Respect the `resolve.dedupe` option in production SSR. */
|
|
67020
|
+
function dedupeRequire(dedupe) {
|
|
67021
|
+
const Module = require('module');
|
|
67022
|
+
const resolveFilename = Module._resolveFilename;
|
|
67023
|
+
Module._resolveFilename = function (request, parent, isMain, options) {
|
|
67024
|
+
if (request[0] !== '.' && request[0] !== '/') {
|
|
67025
|
+
const parts = request.split('/');
|
|
67026
|
+
const pkgName = parts[0][0] === '@' ? parts[0] + '/' + parts[1] : parts[0];
|
|
67027
|
+
if (dedupe.includes(pkgName)) {
|
|
67028
|
+
// Use this module as the parent.
|
|
67029
|
+
parent = module;
|
|
67030
|
+
}
|
|
67031
|
+
}
|
|
67032
|
+
return resolveFilename(request, parent, isMain, options);
|
|
67033
|
+
};
|
|
67034
|
+
}
|
|
67035
|
+
function hookNodeResolve(getResolver) {
|
|
67036
|
+
const Module = require('module');
|
|
67037
|
+
const prevResolver = Module._resolveFilename;
|
|
67038
|
+
Module._resolveFilename = getResolver(prevResolver);
|
|
67039
|
+
return () => {
|
|
67040
|
+
Module._resolveFilename = prevResolver;
|
|
67041
|
+
};
|
|
67042
|
+
}
|
|
67043
|
+
|
|
66851
67044
|
const pendingModules = new Map();
|
|
66852
67045
|
const pendingImports = new Map();
|
|
66853
67046
|
async function ssrLoadModule(url, server, context = { global }, urlStack = []) {
|
|
@@ -66896,13 +67089,27 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
|
|
|
66896
67089
|
};
|
|
66897
67090
|
urlStack = urlStack.concat(url);
|
|
66898
67091
|
const isCircular = (url) => urlStack.includes(url);
|
|
67092
|
+
const { isProduction, resolve: { dedupe, preserveSymlinks }, root } = server.config;
|
|
67093
|
+
// The `extensions` and `mainFields` options are used to ensure that
|
|
67094
|
+
// CommonJS modules are preferred. We want to avoid ESM->ESM imports
|
|
67095
|
+
// whenever possible, because `hookNodeResolve` can't intercept them.
|
|
67096
|
+
const resolveOptions = {
|
|
67097
|
+
dedupe,
|
|
67098
|
+
extensions: ['.js', '.cjs', '.json'],
|
|
67099
|
+
isBuild: true,
|
|
67100
|
+
isProduction,
|
|
67101
|
+
isRequire: true,
|
|
67102
|
+
mainFields: ['main'],
|
|
67103
|
+
preserveSymlinks,
|
|
67104
|
+
root
|
|
67105
|
+
};
|
|
66899
67106
|
// Since dynamic imports can happen in parallel, we need to
|
|
66900
67107
|
// account for multiple pending deps and duplicate imports.
|
|
66901
67108
|
const pendingDeps = [];
|
|
66902
67109
|
const ssrImport = async (dep) => {
|
|
66903
67110
|
var _a, _b;
|
|
66904
67111
|
if (dep[0] !== '.' && dep[0] !== '/') {
|
|
66905
|
-
return nodeImport(dep, mod.file,
|
|
67112
|
+
return nodeImport(dep, mod.file, resolveOptions);
|
|
66906
67113
|
}
|
|
66907
67114
|
dep = unwrapId$1(dep);
|
|
66908
67115
|
if (!isCircular(dep) && !((_a = pendingImports.get(dep)) === null || _a === void 0 ? void 0 : _a.some(isCircular))) {
|
|
@@ -66962,20 +67169,53 @@ async function instantiateModule(url, server, context = { global }, urlStack = [
|
|
|
66962
67169
|
return Object.freeze(ssrModule);
|
|
66963
67170
|
}
|
|
66964
67171
|
// In node@12+ we can use dynamic import to load CJS and ESM
|
|
66965
|
-
async function nodeImport(id, importer,
|
|
67172
|
+
async function nodeImport(id, importer, resolveOptions) {
|
|
67173
|
+
// Node's module resolution is hi-jacked so Vite can ensure the
|
|
67174
|
+
// configured `resolve.dedupe` and `mode` options are respected.
|
|
67175
|
+
const viteResolve = (id, importer, options = resolveOptions) => {
|
|
67176
|
+
const resolved = tryNodeResolve(id, importer, options, false);
|
|
67177
|
+
if (!resolved) {
|
|
67178
|
+
const err = new Error(`Cannot find module '${id}' imported from '${importer}'`);
|
|
67179
|
+
err.code = 'ERR_MODULE_NOT_FOUND';
|
|
67180
|
+
throw err;
|
|
67181
|
+
}
|
|
67182
|
+
return resolved.id;
|
|
67183
|
+
};
|
|
67184
|
+
// When an ESM module imports an ESM dependency, this hook is *not* used.
|
|
67185
|
+
const unhookNodeResolve = hookNodeResolve((nodeResolve) => (id, parent, isMain, options) => {
|
|
67186
|
+
if (id[0] === '.' || isBuiltin(id)) {
|
|
67187
|
+
return nodeResolve(id, parent, isMain, options);
|
|
67188
|
+
}
|
|
67189
|
+
if (parent) {
|
|
67190
|
+
return viteResolve(id, parent.id);
|
|
67191
|
+
}
|
|
67192
|
+
// Importing a CJS module from an ESM module. In this case, the import
|
|
67193
|
+
// specifier is already an absolute path, so this is a no-op.
|
|
67194
|
+
// Options like `resolve.dedupe` and `mode` are not respected.
|
|
67195
|
+
return id;
|
|
67196
|
+
});
|
|
66966
67197
|
let url;
|
|
66967
|
-
// `resolve` doesn't handle `node:` builtins, so handle them directly
|
|
66968
67198
|
if (id.startsWith('node:') || isBuiltin(id)) {
|
|
66969
67199
|
url = id;
|
|
66970
67200
|
}
|
|
66971
67201
|
else {
|
|
66972
|
-
url =
|
|
67202
|
+
url = viteResolve(id, importer,
|
|
67203
|
+
// Non-external modules can import ESM-only modules, but only outside
|
|
67204
|
+
// of test runs, because we use Node `require` in Jest to avoid segfault.
|
|
67205
|
+
typeof jest === 'undefined'
|
|
67206
|
+
? { ...resolveOptions, tryEsmOnly: true }
|
|
67207
|
+
: resolveOptions);
|
|
66973
67208
|
if (usingDynamicImport) {
|
|
66974
67209
|
url = require$$0$7.pathToFileURL(url).toString();
|
|
66975
67210
|
}
|
|
66976
67211
|
}
|
|
66977
|
-
|
|
66978
|
-
|
|
67212
|
+
try {
|
|
67213
|
+
const mod = await dynamicImport(url);
|
|
67214
|
+
return proxyESM(id, mod);
|
|
67215
|
+
}
|
|
67216
|
+
finally {
|
|
67217
|
+
unhookNodeResolve();
|
|
67218
|
+
}
|
|
66979
67219
|
}
|
|
66980
67220
|
// rollup-style default import interop for cjs
|
|
66981
67221
|
function proxyESM(id, mod) {
|
|
@@ -66986,26 +67226,13 @@ function proxyESM(id, mod) {
|
|
|
66986
67226
|
: mod;
|
|
66987
67227
|
return new Proxy(mod, {
|
|
66988
67228
|
get(mod, prop) {
|
|
67229
|
+
var _a;
|
|
66989
67230
|
if (prop === 'default')
|
|
66990
67231
|
return defaultExport;
|
|
66991
|
-
return mod[prop];
|
|
67232
|
+
return (_a = mod[prop]) !== null && _a !== void 0 ? _a : defaultExport === null || defaultExport === void 0 ? void 0 : defaultExport[prop];
|
|
66992
67233
|
}
|
|
66993
67234
|
});
|
|
66994
67235
|
}
|
|
66995
|
-
const resolveCache = new Map();
|
|
66996
|
-
function resolve(id, importer, root, preserveSymlinks) {
|
|
66997
|
-
const key = id + importer + root;
|
|
66998
|
-
const cached = resolveCache.get(key);
|
|
66999
|
-
if (cached) {
|
|
67000
|
-
return cached;
|
|
67001
|
-
}
|
|
67002
|
-
const resolveDir = importer && fs__default.existsSync(cleanUrl(importer))
|
|
67003
|
-
? path__default.dirname(importer)
|
|
67004
|
-
: root;
|
|
67005
|
-
const resolved = resolveFrom$3(id, resolveDir, preserveSymlinks, true);
|
|
67006
|
-
resolveCache.set(key, resolved);
|
|
67007
|
-
return resolved;
|
|
67008
|
-
}
|
|
67009
67236
|
|
|
67010
67237
|
/**
|
|
67011
67238
|
* The amount to wait for requests to register newly found dependencies before triggering
|
|
@@ -67157,9 +67384,8 @@ async function createServer(inlineConfig = {}) {
|
|
|
67157
67384
|
disableGlobbing: true,
|
|
67158
67385
|
...watchOptions
|
|
67159
67386
|
});
|
|
67160
|
-
const
|
|
67161
|
-
const container = await createPluginContainer(config, watcher);
|
|
67162
|
-
const moduleGraph = new ModuleGraph(container);
|
|
67387
|
+
const moduleGraph = new ModuleGraph((url) => container.resolveId(url));
|
|
67388
|
+
const container = await createPluginContainer(config, moduleGraph, watcher);
|
|
67163
67389
|
const closeHttpServer = createServerCloseFn(httpServer);
|
|
67164
67390
|
// eslint-disable-next-line prefer-const
|
|
67165
67391
|
let exitProcess;
|
|
@@ -67181,11 +67407,9 @@ async function createServer(inlineConfig = {}) {
|
|
|
67181
67407
|
},
|
|
67182
67408
|
transformIndexHtml: null,
|
|
67183
67409
|
ssrLoadModule(url) {
|
|
67184
|
-
|
|
67185
|
-
|
|
67186
|
-
|
|
67187
|
-
: []);
|
|
67188
|
-
}
|
|
67410
|
+
server._ssrExternals || (server._ssrExternals = resolveSSRExternal(config, server._optimizeDepsMetadata
|
|
67411
|
+
? Object.keys(server._optimizeDepsMetadata.optimized)
|
|
67412
|
+
: []));
|
|
67189
67413
|
return ssrLoadModule(url, server);
|
|
67190
67414
|
},
|
|
67191
67415
|
ssrFixStacktrace(e) {
|
|
@@ -67268,7 +67492,7 @@ async function createServer(inlineConfig = {}) {
|
|
|
67268
67492
|
}
|
|
67269
67493
|
// apply server configuration hooks from plugins
|
|
67270
67494
|
const postHooks = [];
|
|
67271
|
-
for (const plugin of plugins) {
|
|
67495
|
+
for (const plugin of config.plugins) {
|
|
67272
67496
|
if (plugin.configureServer) {
|
|
67273
67497
|
postHooks.push(await plugin.configureServer(server));
|
|
67274
67498
|
}
|
|
@@ -81155,6 +81379,7 @@ async function resolvePlugins(config, prePlugins, normalPlugins, postPlugins) {
|
|
|
81155
81379
|
ssrConfig: config.ssr,
|
|
81156
81380
|
asSrc: true
|
|
81157
81381
|
}),
|
|
81382
|
+
config.build.ssr ? ssrRequireHookPlugin(config) : null,
|
|
81158
81383
|
htmlInlineScriptProxyPlugin(config),
|
|
81159
81384
|
cssPlugin(config),
|
|
81160
81385
|
config.esbuild !== false ? esbuildPlugin(config.esbuild) : null,
|
|
@@ -81445,7 +81670,7 @@ async function resolveConfig(inlineConfig, command, defaultMode = 'development')
|
|
|
81445
81670
|
}
|
|
81446
81671
|
// resolve public base url
|
|
81447
81672
|
const BASE_URL = resolveBaseUrl(config.base, command === 'build', logger);
|
|
81448
|
-
const resolvedBuildOptions = resolveBuildOptions(config.build);
|
|
81673
|
+
const resolvedBuildOptions = resolveBuildOptions(resolvedRoot, config.build);
|
|
81449
81674
|
// resolve cache directory
|
|
81450
81675
|
const pkgPath = lookupFile(resolvedRoot, [`package.json`], true /* pathOnly */);
|
|
81451
81676
|
const cacheDir = config.cacheDir
|
|
@@ -81994,4 +82219,4 @@ exports.send = send$1;
|
|
|
81994
82219
|
exports.sortUserPlugins = sortUserPlugins;
|
|
81995
82220
|
exports.source = source;
|
|
81996
82221
|
exports.transformWithEsbuild = transformWithEsbuild;
|
|
81997
|
-
//# sourceMappingURL=dep-
|
|
82222
|
+
//# sourceMappingURL=dep-0183a921.js.map
|